目录
1、添加一块10G大小的磁盘,将该磁盘分为两个主分区,大小为1G、2G。将剩余的空间全部划分为扩展分区。划分一个逻辑分区,大小为3G。(主分区文件系统类型为ext4,逻辑分区文件系统类型为xfs)
2、将三个分区分别挂载到/dir1、/dir2、/dir3。
一、思维导图
二、基本存储配置
1、添加一块10G大小的磁盘,将该磁盘分为两个主分区,大小为1G、2G。将剩余的空间全部划分为扩展分区。划分一个逻辑分区,大小为3G。(主分区文件系统类型为ext4,逻辑分区文件系统类型为xfs)
//进入fdisk交互界面
[root@localhost ~]# fdisk /dev/sda
//创建大小为1G的主分区
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-20971519, default 2048):
Last sector, +sectors or +size{K,M,G,T,P} (2048-20971519, default 20971519): +1G
Created a new partition 1 of type 'Linux' and of size 1 GiB.
//创建大小为2G的主分区
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 (2099200-20971519, default 2099200):
Last sector, +sectors or +size{K,M,G,T,P} (2099200-20971519, default 20971519): +2G
Created a new partition 2 of type 'Linux' and of size 2 GiB.
//将剩余的空间全部划分为扩展分区
Command (m for help): n
Partition type
p primary (2 primary, 0 extended, 2 free)
e extended (container for logical partitions)
Select (default p): e
Partition number (3,4, default 3):
First sector (6293504-20971519, default 6293504):
Last sector, +sectors or +size{K,M,G,T,P} (6293504-20971519, default 20971519):
Created a new partition 3 of type 'Extended' and of size 7 GiB.
//划分大小为3G的逻辑分区
Command (m for help): n
All space for primary partitions is in use.
Adding logical partition 5
First sector (6295552-20971519, default 6295552):
Last sector, +sectors or +size{K,M,G,T,P} (6295552-20971519, default 20971519): +3G
Created a new partition 5 of type 'Linux' and of size 3 GiB.
//格式化
[root@localhost ~]# mkfs.ext4 /dev/sda1
mke2fs 1.45.6 (20-Mar-2020)
Creating filesystem with 262144 4k blocks and 65536 inodes
Filesystem UUID: d0f614a7-6210-419d-b995-c5315afb126a
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
[root@localhost ~]# mkfs.ext4 /dev/sda2
mke2fs 1.45.6 (20-Mar-2020)
Creating filesystem with 524288 4k blocks and 131072 inodes
Filesystem UUID: ec1719b8-1bdf-4b7d-8a59-b31c822556e4
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
[root@localhost ~]# mkfs.xfs /dev/sda5
meta-data=/dev/sda5 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@localhost ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 10G 0 disk
├─sda1 8:1 0 1G 0 part
├─sda2 8:2 0 2G 0 part
├─sda3 8:3 0 1K 0 part
└─sda5 8:5 0 3G 0 part
sr0 11:0 1 10.2G 0 rom /run/media/root/RHEL-8-5-0-BaseOS-x86_64
nvme0n1 259:0 0 50G 0 disk
├─nvme0n1p1 259:1 0 500M 0 part /boot
├─nvme0n1p2 259:2 0 1G 0 part [SWAP]
└─nvme0n1p3 259:3 0 40G 0 part /
2、将三个分区分别挂载到/dir1、/dir2、/dir3。
//创建挂载点目录
[root@localhost ~]# mkdir /dir{1,2,3}
//挂载
[root@localhost ~]# mount /dev/sda1 /dir1
[root@localhost ~]# mount /dev/sda2 /dir2
[root@localhost ~]# mount /dev/sda5 /dir3
//查看挂载信息
[root@localhost ~]# mount | grep /dev/sda
/dev/sda1 on /dir1 type ext4 (rw,relatime,seclabel)
/dev/sda2 on /dir2 type ext4 (rw,relatime,seclabel)
/dev/sda5 on /dir3 type xfs (rw,relatime,seclabel,attr2,inode64,logbufs=8,logbsize=32k,noquota)
3、在第一个主分区中创建一个文件为file1,内容为this is partition1。在第二个分区中创建一个文件为file2,内容为this is partition2。在第三个分区中创建一个文件为file3,内容为this is partition3。
//创建文件,并将内容追加到文件中
[root@localhost ~]# echo "this is partition1" >> /dir1/file1
[root@localhost ~]# echo "this is partition2" >> /dir2/file2
[root@localhost ~]# echo "this is partition3" >> /dir3/file3
//查看文件内容
[root@localhost ~]# cat /dir1/file1 /dir2/file2 /dir3/file3
this is partition1
this is partition2
this is partition3