题目要求
1) 添加一块10G大小的磁盘,将该磁盘分为两个主分区,大小为1G、2G。将剩余的空间全部划分为扩
展分区。划分一个逻辑分区,大小为3G。(主分区文件系统类型为ext4,逻辑分区文件系统类型为
xfs)
2) 将三个分区分别挂载到/dir1、/dir2、/dir3。
3) 在第一个主分区中创建一个文件为file1,内容为this is partition1。在第二个分区中创建一个文件为
file2,内容为this is partition2。在第三个分区中创建一个文件为file3,内容为this is partition3。
添加磁盘
进入虚拟机查看磁盘分区情况
(查看硬盘是否添加成功)
列出块设备
[root@servera ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sr0 11:0 1 10.2G 0 rom
nvme0n1 259:0 0 20G 0 disk
├─nvme0n1p1 259:1 0 1G 0 part /boot
└─nvme0n1p2 259:2 0 19G 0 part
├─rhel-root 253:0 0 17G 0 lvm /
└─rhel-swap 253:1 0 2G 0 lvm [SWAP]
nvme0n2 259:3 0 10G 0 disk
或者
显示所有支持的分区类型
[root@servera ~]# fdisk -l
对磁盘分区
[root@servera ~]# fdisk /dev/nvme0n2
查看nvme0n2分区情况
对分区指定文件系统类型(格式化)
对主分区p1选择文件系统类型为ext4
[root@servera ~]# mkfs.ext4 /dev/nvme0n2p1
mke2fs 1.45.6 (20-Mar-2020)
Creating filesystem with 262144 4k blocks and 65536 inodes
Filesystem UUID: b0cc4daa-57f6-4eed-94ec-51c421e77ca4
Superblock backups stored on blocks:
32768, 98304, 163840, 229376
Allocating group tables: done
Writing inode tables: done
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done
主分区p2选择文件系统类型为ext4
[root@servera ~]# mkfs.ext4 /dev/nvme0n2p2
mke2fs 1.45.6 (20-Mar-2020)
Creating filesystem with 524288 4k blocks and 131072 inodes
Filesystem UUID: 5279daa0-eac8-47c0-8290-54cbcc9c5b04
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912
Allocating group tables: done
Writing inode tables: done
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: done
逻辑分区p5选择文件系统类型xfs
[root@servera ~]# mkfs.xfs /dev/nvme0n2p5
meta-data=/dev/nvme0n2p5 isize=512 agcount=4, agsize=196608 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=1, sparse=1, rmapbt=0
= reflink=1
data = bsize=4096 blocks=786432, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0, ftype=1
log =internal log bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
创建挂载点目录
[root@servera ~]# mkdir /dir{1..3}
挂载
临时挂载
[root@servera ~]# mount /dev/nvme0n2p1 /dir1
[root@servera ~]# mount /dev/nvme0n2p2 /dir2
[root@servera ~]# mount /dev/nvme0n2p5 /dir3
永久挂载
文件目录挂载
编辑文件系统配置文件/etc/fstab
[root@servera dir3]# vim /etc/fstab
/dev/nvme0n2p1 /dir1 ext4 defaults 0 0
/dev/nvme0n2p2 /dir2 ext4 defaults 0 0
UUID挂载
(全局唯一标识符)
查看 /dev/nvme0n2p5的UUID
[root@servera dir3]# blkid /dev/nvme0n2p5
/dev/nvme0n2p5: UUID="99224aeb-f722-4b01-bdd7-b3581531adb7" BLOCK_SIZE="512" TYPE="xfs" PARTUUID="97988063-05"
编辑文件系统配置文件/etc/fstab
[root@servera dir3]# vim /etc/fstab
UUID=99224aeb-f722-4b01-bdd7-b3581531adb7 /dir3 xfs defaults 0 0
(第一个0的位置:开机是否备份;第二个0的位置:开机是否检测)
文件系统的配置文件生效
[root@servera dir3]# mount -o
在分区里创建并编辑文件
[root@servera ~]# cd /dir1
创建文件file1
[root@servera dir1]# touch file1
编辑文件内容file1
[root@servera dir1]# echo this is partition1 > file1
查看文件file1
[root@servera dir1]# cat file1
this is partition1
[root@servera dir1]# cd /dir2
[root@servera dir2]# touch file2
[root@servera dir2]# echo this is partition2 > file2
查看文件fle2
[root@servera dir2]# cat file2
this is partition2
[root@servera dir2]# cd /dir3
[root@servera dir3]# touch file3
[root@servera dir3]# echo this is partition3 > file3
查看文件file3
[root@servera dir3]# cat file3
this is partition3