1、新添加一块硬盘,大小为5g,给这块硬盘分一个mbr格式的主分区(大小为g),给此主分区创建ext2的文件系统,挂载到/guazai目录,并写入文件内容为"this is first disk"文件名为1.txt的文件。
添加硬盘:在虚拟机关机状态下,点击编辑虚拟机设置,创建硬盘,只修改大小即可。
[root@xiaokeai ~]# fdisk /dev/nvme0n3
Command (m for help): p
Disk /dev/nvme0n3: 5 GiB, 5368709120 bytes, 10485760 sectors
。。。。。。
Disklabel type: dos
Disk identifier: 0xbb00ecc9Command (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): +1gCreated a new partition 1 of type 'Linux' and of size 1 GiB.
Command (m for help): p #打印
Disk /dev/nvme0n3: 5 GiB, 5368709120 bytes, 10485760 sectors。。。。。。
/dev/nvme0n3p1 2048 2099199 2097152 1G 83 Linux #添加成功Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.[root@xiaokeai ~]# lsblk -p
NAME。。。。。。
└─/dev/nvme0n3p1 259:7 0 1G 0 part
[root@xiaokeai ~]# mkfs.ext2 /dev/nvme0n3p1
mke2fs 1.46.5 (30-Dec-2021)。。。。。。
/dev/nvme0n3p1 on /guazai type ext2 (rw,relatime,seclabel)
[root@xiaokeai ~]# cd /guazai
[root@xiaokeai guazai]# echo this is first disk >1.txt
[root@xiaokeai guazai]# cat 1.txt
this is first disk
2、新添加一块硬盘,大小为10g,给这块硬盘分一个mbr 格式的主分区(大小为4g),分一个扩展分区为(大小为5g),一个逻辑分区(大小为1g),给此主分区创建ext3的文件系统,挂载到/guazai2目录,并写入文件内容为"The first primary partition on the second disk"文件名为2.txt的文件,给此逻辑分区创建ext4的文件系统,挂载到/guazai3目录,并写入文件内容为"Logical partition on the second disk"文件名为3.tXt的文件。
[root@xiaokeai ~]# lsblk -p
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
。。。。。。
/dev/nvme0n2 259:4 0 10G 0 disk
[root@xiaokeai ~]# fdisk /dev/nvme0n2Command (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-20971519, default 2048):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-20971519, default 20971519): +4gCreated a new partition 1 of type 'Linux' and of size 4 GiB.
Command (m for help): n
Partition type
p primary (1 primary, 0 extended, 3 free)
e extended (container for logical partitions)
Select (default p): e
Partition number (2-4, default 2):
First sector (8390656-20971519, default 8390656):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (8390656-20971519, default 20971519): +5gCreated a new partition 2 of type 'Extended' and of size 5 GiB.
Command (m for help): n
Partition type
p primary (1 primary, 1 extended, 2 free)
l logical (numbered from 5)
Select (default p): lAdding logical partition 5
First sector (8392704-18876415, default 8392704):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (8392704-18876415, default 18876415): +1gCreated a new partition 5 of type 'Linux' and of size 1 GiB.
Command (m for help): p
Disk /dev/nvme0n2: 10 GiB, 10737418240 bytes, 20971520 sectors。。。。。。
/dev/nvme0n2p1 2048 8390655 8388608 4G 83 Linux
/dev/nvme0n2p2 8390656 18876415 10485760 5G 5 Extended
/dev/nvme0n2p5 8392704 10489855 2097152 1G 83 LinuxCommand (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.[root@xiaokeai ~]# mkfs.ext3 /dev/nvme0n2p1
[root@xiaokeai ~]# mkdir /guazai2
[root@xiaokeai ~]# mount /dev/nvme0n2p1 /guazai2
[root@xiaokeai ~]# cd /guazai
[root@xiaokeai guazai]# echo The first primary partition on the second disk >2.txt[root@xiaokeai guazai]# cat 2.txt
The first primary partition on the second disk
[root@xiaokeai guazai]# cd[root@xiaokeai ~]# mkfs.ext4 /dev/nvme0n2p5
[root@xiaokeai ~]# mkdir /guazai3
[root@xiaokeai ~]# mount /dev/nvme0n2p5 /guazai3
[root@xiaokeai ~]# cd /guazai3
[root@xiaokeai guazai3]# echo Logical partition on the second disk >3.txt[root@xiaokeai guazai3]# cat 3.txt
Logical partition on the second disk
3、新添加一块硬盘,大小为15g,给这块硬盘分一个gpt 格式的主分区(大小为6g),给此主分区创建xfs的文件系统,挂载到/guazai4目录,并写入文件内容为"This is a partition formatted in GPT (GUIDPartition Table) format. 件名为4.tXt的文件。
[root@xxx~]# fdisk /dev/nvmeOn3
Disk /dev/nvme0n3: 5 GiB, 5368709120 bytes, 10485760 sectors
。。。。。。
Disklabel type: dos
Disk identifier: 0xbb00ecc9
Command (m for help):g #创建gpt格式分区
created a new GPT disklabel (GUID:317F64E5-AE7A-FF4A-8DD1-BF52D70E4F73).
Command (m for help):p
Disklabel type:gpt
Command (m for help):n
Partition number (1-128, default 1):First sector (2048-41943006, default2048):
Last sector, +/-sectors or +/-size{K,M,G,T, P} (2048-41943006, default 41943006): +6g
Created a new partition 1of type 'Linux filesystem'and of size 6 GiB.
Command (m for help):p
[root@xxx-]# lsblk -p
/dev/nvme0n3259:4 15G 0 disk└─/dev/nvme0n3p1 259:5 6G 0 part
[root@xiaokeai ~]# mkfs.xfs /dev/nvme0n3p1
[root@xiaokeai ~]# mkdir /guazai4
[root@xiaokeai ~]# mount /dev/nvme0n3p1 /guazai4
[root@xiaokeai ~]# cd /guazai4
[root@xiaokeai guazai4]# echo This is a partition formatted in GPT (GUIDPartition Table) format > 4.txt[root@xiaokeai guazai4]# cat 4.txt
This is a partition formatted in GPT (GUIDPartition Table) format