Linux磁盤管理練習題(習題+演示)

可以先看看這裏Linux磁盤管理(概念+演示)

小試牛刀

1、新建兩個分區,它們的大小分別爲1G,分別將它們掛載在/apple和/orange目錄下。

2、添加一塊10G的硬盤,如果我想將該硬盤暫時分爲4個分區,同時還有其他的剩餘容量可以讓我在未來的時候進行規劃,我應該如何分區?

3、我要將大小爲5G的/dev/sdc劃分爲6個分區,我應該如何分區?

 

實戰練習

1.添加一塊10G大小的磁盤,將該磁盤分爲兩個主分區,大小爲1G、2G。將剩餘的空間全部劃分爲擴展分區。劃分一個邏輯分區,大小爲3G。(主分區文件系統類型爲ext4,邏輯分區文件系統類型爲xfs)

2. 將三個分區分別掛載到/haha、/wuwu、/hehe。

3.在第一個主分區中創建一個文件爲file1,內容爲this is partition1。在第二個分區中創建一個文件爲file2,內容爲this is partition2。在第三個分區中創建一個文件爲file3,內容爲this is partition3。


 

小試牛刀

第一題

思路:

首先創建一個擴展分區,然後在其下創建兩個邏輯分區大小分別爲1G,保存退出,內核更新,格式化,然後在指定目錄進行掛載

演示:

1.創建擴展分區,並在其下創建邏輯分區

Sda4擴展分區,sda5 sda6是邏輯分區

1048576/1024/1024 = 1

2.保存退出,內核識別,格式化分區

這裏提示的是光盤的只讀權限,與新創建的兩個分區無關

3.手動掛載

第二題:

思路:

       使用擴展分區,可以將前三個或第一個作爲主分區,最後一個配置成擴展分區,後期想要使用剩餘的容量時,直接創建邏輯分區即可

演示:

首先添加一個10G大小的擴展分區,然後在其下創建三個主分區和一個擴展分區,前三個主分區大小都是1G,如果後期還想要使用剩餘容量時,直接創建邏輯分區即可

 

 

 

創建完成後打開虛擬機,可以看到有一個名爲/dev/sdb的新磁盤

前三個分區是主分區,第四個分區是擴展分區,目前10G磁盤還有7G沒有使用,想要用的話,就創建邏輯分區即可

第三題

思路:

       與第二題相同,即使用擴展分區,基於擴展分區來創建邏輯分區,進而實現需求,注意這裏時sdc 意思時第三塊磁盤,具體參考這篇文章的磁盤命名介紹即可

 

實戰練習

首先,添加一個10G的磁盤,用的是小試牛刀中的磁盤(先將磁盤中原本的分區刪除),然後添加主分區與擴展分區即可,sdb1 2是主分區大小分別爲1G、2G sdb5是邏輯分區,大小是3G

[root@localhost ~]# fdisk /dev/sdb
Command (m for help): p

Disk /dev/sdb: 10.7 GB, 10737418240 bytes, 20971520 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0xbd290ff9

   Device Boot      Start         End      Blocks   Id  System

Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): 
Using default response p
Partition number (1-4, default 1): 
First sector (2048-20971519, default 2048): 
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519): +1G
Partition 1 of type Linux and of size 1 GiB is set

Command (m for help): n
Partition type:
   p   primary (1 primary, 0 extended, 3 free)
   e   extended
Select (default p): 
Using default response p
Partition number (2-4, default 2): 
First sector (2099200-20971519, default 2099200): 
Using default value 2099200
Last sector, +sectors or +size{K,M,G} (2099200-20971519, default 20971519): +2G
Partition 2 of type Linux and of size 2 GiB is set

Command (m for help): n
Partition type:
   p   primary (2 primary, 0 extended, 2 free)
   e   extended
Select (default p): e
Partition number (3,4, default 3): 
First sector (6293504-20971519, default 6293504): 
Using default value 6293504
Last sector, +sectors or +size{K,M,G} (6293504-20971519, default 20971519): 
Using default value 20971519
Partition 3 of type Extended and of size 7 GiB is set

Command (m for help): p

Disk /dev/sdb: 10.7 GB, 10737418240 bytes, 20971520 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0xbd290ff9

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048     2099199     1048576   83  Linux
/dev/sdb2         2099200     6293503     2097152   83  Linux
/dev/sdb3         6293504    20971519     7339008    5  Extended

Command (m for help): n
Partition type:
   p   primary (2 primary, 1 extended, 1 free)
   l   logical (numbered from 5)
Select (default p): l
Adding logical partition 5
First sector (6295552-20971519, default 6295552): 
Using default value 6295552
Last sector, +sectors or +size{K,M,G} (6295552-20971519, default 20971519): +3G
Partition 5 of type Linux and of size 3 GiB is set

Command (m for help): p

Disk /dev/sdb: 10.7 GB, 10737418240 bytes, 20971520 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0xbd290ff9

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048     2099199     1048576   83  Linux
/dev/sdb2         2099200     6293503     2097152   83  Linux
/dev/sdb3         6293504    20971519     7339008    5  Extended
/dev/sdb5         6295552    12587007     3145728   83  Linux

 

接下來保存退出,是內核識別,然後格式化分區

[root@localhost ~]# mkfs.ext4 /dev/sdb1
[root@localhost ~]# mkfs.ext4 /dev/sdb2
[root@localhost ~]# mkfs.xfs /dev/sdb5

查看:

根據題中要求,創建掛載點目錄,進行掛載

[root@localhost /]# mkdir /haha
[root@localhost /]# mkdir /wuwu
[root@localhost /]# mkdir /hehe
[root@localhost /]# mount /dev/sdb1 /haha
[root@localhost /]# mount /dev/sdb2 /wuwu
[root@localhost /]# mount /dev/sdb5 /hehe
[root@localhost /]# mount |  grep /dev/sdb

在分區內創建文件

[root@localhost ~]# echo this is partition1 > /haha/file1 
[root@localhost ~]# echo this is partition2 > /wuwu/file2 
[root@localhost ~]# echo this is partition3 > /hehe/file3


 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章