为你的虚拟机添加一块磁盘,并且新建六个分区,六个分区要求如下: sdb1为主分区,500M的容量,文件格式为ext3; sdb2为主分区,容量不限,文件格式为FAT; sdb3为主分区,容量不限,文件格式为FAT; sdb4为扩展
时间: 2023-08-15 07:06:41 浏览: 134
分区,容量不限,包含两个逻辑分区; 逻辑分区sdb5的容量为1G,文件格式为ext4; 逻辑分区sdb6的容量为2G,文件格式为NTFS。
首先,你需要将虚拟机关机,然后在虚拟机管理软件(如VMware)中添加一块磁盘,这里假设添加的是/dev/sdb。
接下来,你需要使用fdisk或parted工具对新添加的磁盘进行分区。
1. 使用fdisk对/dev/sdb进行分区:
```
sudo fdisk /dev/sdb
```
输入`n`创建新分区,按照提示输入分区编号(1-4)和分区大小(500M),然后设置文件系统类型为ext3。
```
Command (m for help): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended (container for logical partitions)
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-10485759, default 2048):
Last sector, +sectors or +size{K,M,G,T,P} (2048-10485759, default 10485759): +500M
Created a new partition 1 of type 'Linux' and of size 500 MiB.
Command (m for help): t
Selected partition 1
Partition type (type L to list all types): 83
Command (m for help): n
Partition type:
p primary (1 primary, 0 extended, 3 free)
e extended (container for logical partitions)
Select (default p): p
Partition number (2-4, default 2): 2
First sector (1026048-10485759, default 1026048):
Last sector, +sectors or +size{K,M,G,T,P} (1026048-10485759, default 10485759):
Created a new partition 2 of type 'Linux' and of size 4.5 GiB.
Command (m for help): t
Selected partition 2
Partition type (type L to list all types): b
Command (m for help): n
Partition type:
p primary (2 primary, 0 extended, 2 free)
e extended (container for logical partitions)
Select (default p): p
Partition number (3,4, default 3): 3
First sector (9435136-10485759, default 9435136):
Last sector, +sectors or +size{K,M,G,T,P} (9435136-10485759, default 10485759):
Created a new partition 3 of type 'Linux' and of size 1.1 GiB.
Command (m for help): t
Partition number (1-3, default 3): 3
Hex code (type L to list all codes): c
Command (m for help): n
Partition type:
p primary (2 primary, 0 extended, 1 free)
e extended (container for logical partitions)
Select (default p): e
Selected partition 4
First sector (10485760-20971519, default 10485760):
Last sector, +sectors or +size{K,M,G,T,P} (10485760-20971519, default 20971519):
Created a new partition 4 of type 'Extended' and of size 5 GiB.
Command (m for help): n
Partition type:
l logical (numbered from 5)
Select (default l): l
Adding logical partition 5
First sector (10508416-20971519, default 10508416):
Last sector, +sectors or +size{K,M,G,T,P} (10508416-20971519, default 20971519): +1G
Created a new partition 5 of type 'Linux' and of size 1 GiB.
Command (m for help): t
Partition number (1-5, default 5): 5
Hex code (type L to list all codes): 83
Command (m for help): n
Partition type:
l logical (numbered from 5)
Select (default l): l
Adding logical partition 6
First sector (11534336-20971519, default 11534336):
Last sector, +sectors or +size{K,M,G,T,P} (11534336-20971519, default 20971519): +2G
Created a new partition 6 of type 'NTFS' and of size 2 GiB.
Command (m for help): p
Disk /dev/sdb: 10 GiB, 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
Disklabel type: dos
Disk identifier: 0x00000000
Device Boot Start End Sectors Size Id Type
/dev/sdb1 2048 1026047 1024000 500M 83 Linux
/dev/sdb2 1026048 9435135 8409088 4.5G b W95 FAT32
/dev/sdb3 9435136 10485759 1040608 508M c W95 FAT32 (LBA)
/dev/sdb4 10485760 20971519 10485760 5G extended
/dev/sdb5 10508416 12582911 2074496 1013M 83 Linux
/dev/sdb6 12584960 14659455 2074496 2G 7 HPFS/NTFS/exFAT
```
2. 使用parted对/dev/sdb进行分区:
```
sudo parted /dev/sdb
```
输入`mklabel msdos`创建MBR分区表,然后使用`mkpart`命令创建分区。
```
(parted) mklabel msdos
(parted) mkpart primary ext3 1M 501M
(parted) mkpart primary fat32 501M 100%
(parted) mkpart primary fat32 100% 100%
(parted) mkpart extended 100% 100%
(parted) mkpart logical ext4 100% 25%
(parted) mkpart logical ntfs 25% 75%
(parted) quit
```
3. 格式化分区:
```
sudo mkfs.ext3 /dev/sdb1
sudo mkfs.vfat /dev/sdb2
sudo mkfs.vfat /dev/sdb3
sudo mkfs.ext4 /dev/sdb5
sudo mkfs.ntfs /dev/sdb6
```
4. 挂载分区:
```
sudo mkdir /mnt/sdb1
sudo mkdir /mnt/sdb2
sudo mkdir /mnt/sdb3
sudo mkdir /mnt/sdb5
sudo mkdir /mnt/sdb6
sudo mount /dev/sdb1 /mnt/sdb1
sudo mount /dev/sdb2 /mnt/sdb2
sudo mount /dev/sdb3 /mnt/sdb3
sudo mount /dev/sdb5 /mnt/sdb5
sudo mount /dev/sdb6 /mnt/sdb6
```
至此,你已经成功的为虚拟机添加了一个磁盘,并且新建了六个分区。
阅读全文