RHCE8之文件系统

RHCE8之文件系统

  • 文件系统,顾名思义,是一个组织文件的“系统(system)”,file system,文件系统是用来组织文件的,通俗一点理解的话,文件系统是用来存储文件的。
  • 硬盘是不能直接存放文件或数据。
  • 我们通过将硬盘格式化之后,指定格式化后的文件系统,才可以存放数据。
  • 不同的文件系统存放文件的方式也不相同,算法以及优化方式也可能不同,所以如果一个操作系统不支持某个文件系统,那么这个文件系统上的数据,也就无法被这个操作系统识别。

目录:

  • 在linux系统中,格式化文件系统的原理是什么?
  • 挂载文件系统(分区格式化之后才是文件系统)
  • 持续性挂载
    • /etc/fstab文件说明:
  • 逻辑卷
    • pv的创建,pv的删除(向pv里面加入新的块设备就相当于于扩容pv,从pv里面删除块设备,就相当于缩容pv)
    • vg的创建,vg的删除,vg的扩容,vg的缩容
    • lv的创建,lv的删除,lv的扩容,lv的缩容
  • swap
  • 网络文件系统(nfs)
  • VDO
  • autofs(按需挂载)

在linux系统中,格式化文件系统的原理是什么?

  • 分区的最小单位是sector(扇区),一个扇区是512B,

做个假设:
假如分区可以直接使用,那么存储一个20MB的文件需要多少个扇区呢?答案是40960个,也就是说存储一个20MB大小的文件需要40960个扇区,那么读取这个20MB大小的文件就需要读40960次,可见效率太低了;

上面只是我们不能直接使用分区的一个原因,还有其他原因,自行了解。

  • 当我们的分区进行格式化之后,会将磁盘的读和写的粒度放大

格式化的详细操作:

  1. 会立即分配一部分空间作为inode节点空间
  2. 刨除inode节点占用的空间,剩下的空间用作划分block,block包含了多个扇区,1个block等于2^n个扇区,如果n=0,那么一个block就等于1个扇区的大小,如果n=1那么一个block就等于2个扇区的大小,依次类推,单个block越大,就意味着粒度越大。
  • block大小选取
  1. 划分block的目的是要将文件以block的数量来存放,block越大对磁盘的读取效果越好,block大了,一次读取的空间变多了,这样你的读效率就会提升。
  2. 当时block并不是越大越好,如果block太大了,但是你存放的文件特征是小文件,那么就会造成大量磁盘空间的浪费
  3. 所以格式化文件系统的时候,block的大小要选对
  • inode节点
  1. block是用来存放文件的内容,inode节点是用来存放文件元数据的
  2. 文件的属性就是文件的元数据,描述文件的部分,都指的是文件的元数据,比如文件的大小、文件的权限,文件的拥有者,文件的所属组、文件的名字,文件的selinux安全上下文等。
  3. inode节点除了记录了我们文件的元数据之外,还记录了该文件的block所在位置
  4. 因为inode节点的格式是固定的,所以存放的信息是固定的
  5. 每个文件都有一个inode节点,如果一个文件系统的inode节点数量使用完了,剩余block空间也将无法继续使用,因为没有inode节点来标记文件的属性。

挂载文件系统(分区格式化之后才是文件系统)

  • linux的mount命令就是挂载文件系统的
    mount命令的格式:
    mount -t 文件系统类型 文件系统所在的分区路径 文件系统的挂载点路径
    mount -t fstype 分区路径 挂载点路径
  • 如果一个是一个原生的linux文件系统,那么linux是可以识别出这个文件系统的,所以如果是原生的linux文件系统,那么可以不加-t参数来指定文件系统的类型,ext系列,xfs就属于linux原生的文件系统。
  • 挂载点你可随意指定,取决于你的需求。
  • 一般来说在linux上的应用如果使用了某个path,那么这个路径你就可以挂载合适的文件系统。

持续性挂载

  • mount命令只是临时挂载,重启就没有了
  • 如果你想要你的文件系统永久的挂载那么就需要将挂载信息写入/etc/fstab
  • /etc/fstab这个文件非常重要,一旦这个文件被误删了,或者里面的某些行被错误的删除或者修改了,甚至写法的错误都会导致系统无法正常启动。

注意:编辑/etc/fstab之前记得先备份。

/etc/fstab文件说明:
  1. 第一列:文件系统的所在的分区路径
  2. 第二列:文件系统的挂载点
  3. 第三列:文件系统的类型
  4. 第四列:挂载参数
  5. 第五列和第六列分别写0,只有在一些特殊的文件系统,后两列才需要改成非0

当fstab编辑完成之后,使用mount -a命令,mount -a命令会让我们的文件系统按照fstab里面自动挂载,但是注意,如果某个文件系统已经挂载了,且fstab里面被记录,那么mount -a并不会将该文件系统卸载,再重新挂载,mount -a会自动忽略该文件系统。

逻辑卷

  • 生产环境中使用率是极高的

我们之前使用磁盘,步骤是:

  • 安装磁盘
  • 分区
  • 格式化
  • 挂载
  • 使用

注意:如果对磁盘直接使用fdisk分区,那么这种分区叫做linux的标准分区,linux的标准分区如果格式化成文件系统之后,挂载使用,那么一旦文件系统的空间满了,是无法扩容的。
如果一定要“扩容”,需要将数据备份出来,在换一个更大的文件系统,再将数据还原回去,但是这种方法效率特别低,逻辑卷可以有效的解决这些问题

逻辑卷是个抽象的概念,会有很多新的专有名词

  • pv(physical volume)物理卷
    • 如果pv已经被某个vg使用,那么无法删除
    • pv可以直接指定一块硬盘
  • vg(volume group)卷组
    • 如果在vg上有逻辑卷在使用,那么vg无法删除
  • lv(logical volume)逻辑卷
    • 逻辑卷创建完成之后,可以直接格式化成为文件系统使用
    • 如果卷组下面创建了一个新的逻辑卷,那么该逻辑卷就会自动在设备文件路径出现/dev/vgname/lvname
    • dm设备表示的是逻辑卷的本尊,dm全拼是device mapper

1. pv的创建,pv的删除(向pv里面加入新的块设备就相当于于扩容pv,从pv里面删除块设备,就相当于缩容pv)

//pv的创建
[root@localhost ~]# pvcreate /dev/sdb1
WARNING: ext2 signature detected on /dev/sdb1 at offset 1080. Wipe it? [y/n]: y
  Wiping ext2 signature on /dev/sdb1.
  Physical volume "/dev/sdb1" successfully created.

//pv的删除
[root@localhost ~]# pvremove /dev/sdb1
  Labels on physical volume "/dev/sdb1" successfully wiped.

//查看pv的详细信息
[root@localhost ~]# pvdisplay /dev/sdb1 /dev/sdb2
  "/dev/sdb1" is a new physical volume of "2.00 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/sdb1
  VG Name               
  PV Size               2.00 GiB
  Allocatable           NO
  PE Size               0   
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               aXonYj-HxYj-yvmC-8YK9-S76j-2UGS-DWH8ZF
   
  "/dev/sdb2" is a new physical volume of "3.00 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/sdb2
  VG Name               
  PV Size               3.00 GiB
  Allocatable           NO
  PE Size               0   
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               3EQXYe-yr3r-FKbF-2OZh-gTnM-fugu-hKIen2

[root@localhost ~]# vgs
  VG     #PV #LV #SN Attr   VSize   VFree 
  fedora   1   2   0 wz--n- <19.00g <2.00g
  vg1      1   0   0 wz--n-  <2.00g <2.00g
[root@localhost ~]# pvs
  PV         VG     Fmt  Attr PSize   PFree 
  /dev/sda2  fedora lvm2 a--  <19.00g <2.00g
  /dev/sdb1         lvm2 a--   <2.00g <2.00g
  /dev/sdb2         lvm2 ---    3.00g  3.00g

2. vg的创建,vg的删除,vg的扩容,vg的缩容

//vg的创建
[root@localhost ~]# vgcreate vg1 /dev/sdb1
  Volume group "vg1" successfully created

//查看vg
[root@localhost ~]# vgs
  VG     #PV #LV #SN Attr   VSize   VFree 
  fedora   1   2   0 wz--n- <19.00g <2.00g
  vg1      1   0   0 wz--n-  <2.00g <2.00g

[root@localhost ~]# pvs
  PV         VG     Fmt  Attr PSize   PFree 
  /dev/sda2  fedora lvm2 a--  <19.00g <2.00g
  /dev/sdb1  vg1    lvm2 a--   <2.00g <2.00g
  /dev/sdb2         lvm2 ---    3.00g  3.00g

[root@localhost ~]# vgdisplay vg1
  --- Volume group ---
  VG Name               vg1
  System ID             
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  2
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                0
  Open LV               0
  Max PV                0
  Cur PV                2
  Act PV                2
  VG Size               4.99 GiB
  PE Size               4.00 MiB
  Total PE              1278
  Alloc PE / Size       0 / 0   
  Free  PE / Size       1278 / 4.99 GiB
  VG UUID               Be452Q-aQu6-6MQF-Jeom-bF4R-Bu4T-dMhopK

//vg的删除
[root@localhost ~]# vgremove vg1
  Volume group "vg1" successfully removed
[root@localhost ~]# vgs
  VG     #PV #LV #SN Attr   VSize   VFree 
  fedora   1   2   0 wz--n- <19.00g <2.00g
[root@localhost ~]# pvs
  PV         VG     Fmt  Attr PSize   PFree 
  /dev/sda2  fedora lvm2 a--  <19.00g <2.00g
  /dev/sdb1         lvm2 ---    2.00g  2.00g
  /dev/sdb2         lvm2 ---    3.00g  3.00g

//vg的扩容
[root@localhost ~]# vgs
  VG     #PV #LV #SN Attr   VSize   VFree 
  fedora   1   2   0 wz--n- <19.00g <2.00g
  vg1      1   0   0 wz--n-  <2.00g <2.00g
[root@localhost ~]# vgextend vg1 /dev/sdb2
  Volume group "vg1" successfully extended
[root@localhost ~]# vgs
  VG     #PV #LV #SN Attr   VSize   VFree 
  fedora   1   2   0 wz--n- <19.00g <2.00g
  vg1      2   0   0 wz--n-   4.99g  4.99g

//-s指定PE的大小
[root@localhost ~]# vgcreate vg2 /dev/sdb3 -s 20M
  Physical volume "/dev/sdb3" successfully created.
  Volume group "vg2" successfully created
[root@localhost ~]# vgdisplay vg2
  --- Volume group ---
  VG Name               vg2
  System ID             
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  1
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                0
  Open LV               0
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               3.98 GiB
  PE Size               20.00 MiB
  Total PE              204
  Alloc PE / Size       0 / 0   
  Free  PE / Size       204 / 3.98 GiB
  VG UUID               zaArNm-KVZ2-RJz4-D1Pf-a1yJ-QI3R-b30yEt

3. lv的创建,lv的删除,lv的扩容,lv的缩容

//lv的创建:
//-n参数表示逻辑卷的名字
//-L参数表示逻辑卷的大小
//vg2 表示使用卷组vg2创建该逻辑卷
[root@localhost ~]# lvcreate -n lv1 -L 300M vg2
  Logical volume "lv1" created.
[root@localhost ~]# ls /dev/vg1/lv2 -ld
lrwxrwxrwx. 1 root root 7 Nov 27 06:35 /dev/vg1/lv2 -> ../dm-3

//lv的查看
[root@localhost ~]# lvs
  LV   VG     Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  root fedora -wi-ao----  15.00g                                                    
  swap fedora -wi-ao----   2.00g                                                    
  lv1  vg2    -wi-a----- 300.00m

[root@localhost ~]# lvdisplay /dev/vg2/lv1 
  --- Logical volume ---
  LV Path                /dev/vg2/lv1
  LV Name                lv1
  VG Name                vg2
  LV UUID                0RTQ42-aHLh-lo0t-dRlY-DD22-bvh8-nmbnk9
  LV Write Access        read/write
  LV Creation host, time localhost.localdomain, 2020-11-27 06:31:05 -0500
  LV Status              available
  # open                 0
  LV Size                300.00 MiB
  Current LE             15
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:2

//lv的删除
[root@localhost ~]# lvs
  LV   VG     Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  root fedora -wi-ao----  15.00g                                                    
  swap fedora -wi-ao----   2.00g                                                    
  lv2  vg1    -wi-a----- 200.00m                                                    
  lv1  vg2    -wi-a----- 300.00m

[root@localhost ~]# lvremove /dev/vg2/lv1 
Do you really want to remove active logical volume vg2/lv1? [y/n]: y
  Logical volume "lv1" successfully removed
[root@localhost ~]# lvs
  LV   VG     Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  root fedora -wi-ao----  15.00g                                                    
  swap fedora -wi-ao----   2.00g                                                    
  lv2  vg1    -wi-a----- 200.00m 

//lv的格式化(lv是直接格式化,之后进行挂载)
[root@localhost ~]# mkfs.ext4 /dev/vg1/lv2 
mke2fs 1.43.5 (04-Aug-2017)
Creating filesystem with 204800 1k blocks and 51200 inodes
Filesystem UUID: 31933a12-7102-4cd5-bf61-56cefb309a3c
Superblock backups stored on blocks: 
	8193, 24577, 40961, 57345, 73729

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done

//格式化完成后查看uuid
[root@localhost ~]# ls /dev/vg1/lv2 -ld
lrwxrwxrwx. 1 root root 7 Nov 27 06:35 /dev/vg1/lv2 -> ../dm-3
[root@localhost ~]# ls -l /dev/disk/by-uuid/
total 0
lrwxrwxrwx. 1 root root  9 Nov 27 06:07 2017-11-05-07-22-07-00 -> ../../sr0
lrwxrwxrwx. 1 root root 10 Nov 27 06:46 31933a12-7102-4cd5-bf61-56cefb309a3c -> ../../dm-3
lrwxrwxrwx. 1 root root 10 Nov 27 06:07 398aba5e-4a40-4fcb-863f-858ae708e4da -> ../../dm-0
lrwxrwxrwx. 1 root root 10 Nov 27 06:07 899888b7-f277-46e1-93f7-6940bb63b14d -> ../../dm-1
lrwxrwxrwx. 1 root root 10 Nov 27 06:07 e3ed774d-021f-46d0-aa72-6bb5916a6f22 -> ../../sda1

//格式化完成之后就进行挂载,进而使用
[root@localhost ~]# lvs
  LV   VG     Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  root fedora -wi-ao----  15.00g                                                    
  swap fedora -wi-ao----   2.00g                                                    
  lv2  vg1    -wi-ao---- 200.00m                                                    
  lv1  vg2    -wi-a----- 300.00m        
[root@localhost ~]# mkfs.xfs /dev/vg2/lv1
meta-data=/dev/vg2/lv1           isize=512    agcount=4, agsize=19200 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=1, sparse=0, rmapbt=0, reflink=0
data     =                       bsize=4096   blocks=76800, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal log           bsize=4096   blocks=855, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
[root@localhost ~]# lvs
  LV   VG     Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  root fedora -wi-ao----  15.00g                                                    
  swap fedora -wi-ao----   2.00g                                                    
  lv2  vg1    -wi-ao---- 200.00m                                                    
  lv1  vg2    -wi-a----- 300.00m   
[root@localhost ~]# df -Th /dev/vg1/lv2 /dev/vg2/lv1 
Filesystem          Type  Size  Used Avail Use% Mounted on
/dev/mapper/vg1-lv2 ext4  190M  1.6M  175M   1% /ext4-test
/dev/mapper/vg2-lv1 xfs   297M   16M  282M   6% /xfs-test

//lv的扩容
//在线扩容,在线扩容指的是文件系统不能卸载
//将lv1 扩容到500M
//将lv2扩容到1000M
[root@localhost ~]# lvs
  LV   VG     Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  root fedora -wi-ao----  15.00g                                                    
  swap fedora -wi-ao----   2.00g                                                    
  lv2  vg1    -wi-ao---- 200.00m                                                    
  lv1  vg2    -wi-ao---- 300.00m
[root@localhost ~]# lvextend /dev/vg1/lv2 -L 1000M
  Size of logical volume vg1/lv2 changed from 200.00 MiB (50 extents) to 1000.00 MiB (250 extents).
  Logical volume vg1/lv2 successfully resized.
[root@localhost ~]# lvs
  LV   VG     Attr       LSize    Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  root fedora -wi-ao----   15.00g                                                    
  swap fedora -wi-ao----    2.00g                                                    
  lv2  vg1    -wi-ao---- 1000.00m                                                    
  lv1  vg2    -wi-ao----  500.00m 

//但是此时我们df -Tf,可以看到扩容的内存未生效到文件系统中,需要resize一下
[root@localhost ~]# df -Th
Filesystem              Type      Size  Used Avail Use% Mounted on
devtmpfs                devtmpfs  977M     0  977M   0% /dev
tmpfs                   tmpfs     990M     0  990M   0% /dev/shm
tmpfs                   tmpfs     990M  1.9M  988M   1% /run
tmpfs                   tmpfs     990M     0  990M   0% /sys/fs/cgroup
/dev/mapper/fedora-root xfs        15G  1.6G   14G  11% /
tmpfs                   tmpfs     990M  4.0K  990M   1% /tmp
/dev/sda1               ext4      976M  117M  793M  13% /boot
tmpfs                   tmpfs     198M     0  198M   0% /run/user/1000
/dev/mapper/vg1-lv2     ext4      190M  1.6M  175M   1% /ext4-test
/dev/mapper/vg2-lv1     xfs       297M   16M  282M   6% /xfs-test

//resize操作
[root@localhost ~]# resize2fs /dev/vg1/lv2 
resize2fs 1.43.5 (04-Aug-2017)
Filesystem at /dev/vg1/lv2 is mounted on /ext4-test; on-line resizing required
old_desc_blocks = 2, new_desc_blocks = 8
The filesystem on /dev/vg1/lv2 is now 1024000 (1k) blocks long.

//xfs需要指定的是挂载点
[root@localhost ~]# xfs_growfs /xfs-test/
meta-data=/dev/mapper/vg2-lv1    isize=512    agcount=4, agsize=19200 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=1 spinodes=0 rmapbt=0
         =                       reflink=0
data     =                       bsize=4096   blocks=76800, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal               bsize=4096   blocks=855, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 76800 to 128000
[root@localhost ~]# df -Th
Filesystem              Type      Size  Used Avail Use% Mounted on
devtmpfs                devtmpfs  977M     0  977M   0% /dev
tmpfs                   tmpfs     990M     0  990M   0% /dev/shm
tmpfs                   tmpfs     990M  1.9M  988M   1% /run
tmpfs                   tmpfs     990M     0  990M   0% /sys/fs/cgroup
/dev/mapper/fedora-root xfs        15G  1.6G   14G  11% /
tmpfs                   tmpfs     990M  4.0K  990M   1% /tmp
/dev/sda1               ext4      976M  117M  793M  13% /boot
tmpfs                   tmpfs     198M     0  198M   0% /run/user/1000
/dev/mapper/vg1-lv2     ext4      965M  2.5M  916M   1% /ext4-test
/dev/mapper/vg2-lv1     xfs       497M   16M  481M   4% /xfs-test

swap

  • 分区、格式化、挂载、卸载、重新挂载
//swap分区
[root@localhost ~]# fdisk /dev/nvme0n2

Welcome to fdisk (util-linux 2.32.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table.
Created a new DOS disklabel with disk identifier 0xfbb49adc.

Command (m for help): n
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p): 

Using default response p.
Partition number (1-4, default 1): 
First sector (2048-41943039, default 2048): 
Last sector, +sectors or +size{K,M,G,T,P} (2048-41943039, default 41943039): +g^H
Last sector, +sectors or +size{K,M,G,T,P} (2048-41943039, default 41943039): +g
Last sector, +sectors or +size{K,M,G,T,P} (2048-41943039, default 41943039): +3g

Created a new partition 1 of type 'Linux' and of size 3 GiB.

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

[root@localhost ~]# ls /dev/nv*
/dev/nvme0  /dev/nvme0n1  /dev/nvme0n1p1  /dev/nvme0n1p2  /dev/nvme0n2  /dev/nvme0n2p1  /dev/nvram
[root@localhost ~]# mkswap /dev/nv
nvme0      nvme0n1    nvme0n1p1  nvme0n1p2  nvme0n2    nvme0n2p1  nvram      

//格式化
[root@localhost ~]# mkswap /dev/nvme0n2p1 
Setting up swapspace version 1, size = 3 GiB (3221221376 bytes)
no label, UUID=1e328032-cc6d-4a8a-a9d1-0fa155cb774d

//查看详细信息
[root@localhost ~]# blkid
/dev/nvme0n1: PTUUID="b09c4790" PTTYPE="dos"
/dev/nvme0n1p1: UUID="74a30f2d-76ad-4a94-8f48-a9ffc2e2b299" TYPE="xfs" PARTUUID="b09c4790-01"
/dev/nvme0n1p2: UUID="HA02XF-4Oou-IdAs-mD3n-CU1E-i75p-d6GkuQ" TYPE="LVM2_member" PARTUUID="b09c4790-02"
/dev/nvme0n2: PTUUID="fbb49adc" PTTYPE="dos"
/dev/nvme0n2p1: UUID="1e328032-cc6d-4a8a-a9d1-0fa155cb774d" TYPE="swap" PARTUUID="fbb49adc-01"
/dev/sr0: UUID="2019-04-04-08-40-23-00" LABEL="RHEL-8-0-0-BaseOS-x86_64" TYPE="iso9660" PTUUID="0da1aba4" PTTYPE="dos"
/dev/sda1: UUID="6546cca9-084f-4d29-b103-7739a9f67966" TYPE="xfs" PARTUUID="7aecb195-01"
/dev/sda2: UUID="us4gzI-xyOC-Ri9h-GjEt-LB84-HkAc-b0n4v3" TYPE="LVM2_member" PARTUUID="7aecb195-02"
/dev/mapper/rhel00-root: UUID="8d2681d3-5e20-46e9-8a8a-0c62d20d4539" TYPE="xfs"
/dev/mapper/rhel00-swap: UUID="f1d5d1a6-a8c0-48ad-ba45-09ea8dc99f18" TYPE="swap"
/dev/mapper/rhel-swap: UUID="49b659a8-4259-4216-a75d-6920d9d4f9cd" TYPE="swap"
/dev/mapper/rhel-root: UUID="c722af9b-51f2-40d9-b7f9-013ed22fd5ef" TYPE="xfs"

//swap分区挂载
[root@localhost ~]# vi /etc/fstab 
[root@localhost ~]# cat /etc/fstab 

#
# /etc/fstab
# Created by anaconda on Thu Nov 26 08:14:40 2020
#
# Accessible filesystems, by reference, are maintained under '/dev/disk/'.
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info.
#
# After editing this file, run 'systemctl daemon-reload' to update systemd
# units generated from this file.
#
/dev/mapper/rhel00-root /                       xfs     defaults        0 0
UUID=6546cca9-084f-4d29-b103-7739a9f67966 /boot                   xfs     defaults        0 0
/dev/mapper/rhel00-swap swap                    swap    defaults        0 0
/dev/nvme0n2p1 swap swap default 0 0
[root@localhost ~]# swapon -a

//之前是2g,挂载过来之后就加了3g了
[root@localhost ~]# free -h
              total        used        free      shared  buff/cache   available
Mem:          1.8Gi       698Mi       659Mi       9.0Mi       447Mi       938Mi
Swap:         5.0Gi          0B       5.0Gi

//swap卸载
[root@localhost ~]# free -h
              total        used        free      shared  buff/cache   available
Mem:          1.8Gi       698Mi       659Mi       9.0Mi       447Mi       938Mi
Swap:         5.0Gi          0B       5.0Gi
[root@localhost ~]# swapoff /dev/nvme0n2p1 
[root@localhost ~]# free -h
              total        used        free      shared  buff/cache   available
Mem:          1.8Gi       697Mi       643Mi       9.0Mi       465Mi       938Mi
Swap:         2.0Gi          0B       2.0Gi

//重新挂载
[root@localhost ~]# free -h
              total        used        free      shared  buff/cache   available
Mem:          1.8Gi       697Mi       643Mi       9.0Mi       465Mi       938Mi
Swap:         2.0Gi          0B       2.0Gi
[root@localhost ~]# swapon /dev/nvme0n2p1 
[root@localhost ~]# free -h
              total        used        free      shared  buff/cache   available
Mem:          1.8Gi       700Mi       640Mi       9.0Mi       465Mi       935Mi
Swap:         5.0Gi          0B       5.0Gi

网络文件系统(nfs)

  • 这里便于演示,nfs的服务端和客户端是同一个机器
  • nfs服务器端:
//安装nfs-utils
[root@localhost ~]# yum -y install nfs-utils

//挂载
[root@localhost ~]# mount /dev/nvme0n1p3 /nfs-share
[root@localhost ~]# df -Th
Filesystem            Type      Size  Used Avail Use% Mounted on
devtmpfs              devtmpfs  889M     0  889M   0% /dev
tmpfs                 tmpfs     904M     0  904M   0% /dev/shm
tmpfs                 tmpfs     904M  9.7M  894M   2% /run
tmpfs                 tmpfs     904M     0  904M   0% /sys/fs/cgroup
/dev/mapper/rhel-root xfs        10G  3.7G  6.4G  37% /
/dev/mapper/rhel-opt  xfs       3.0G   54M  3.0G   2% /opt
/dev/nvme0n1p1        xfs       295M  147M  148M  50% /boot
/dev/mapper/rhel-var  xfs       2.0G  202M  1.8G  10% /var
tmpfs                 tmpfs     181M   20K  181M   1% /run/user/42
tmpfs                 tmpfs     181M  3.5M  178M   2% /run/user/1000
/dev/sr0              iso9660   6.7G  6.7G     0 100% /mnt
/dev/nvme0n1p3        ext4       93M  1.6M   85M   2% /nfs-share

//修改/etc/nfs-share进行共享(这里作为例子是共享给192.168.190.0/24这个网络)
[root@localhost ~]# vim /etc/exports
[root@localhost ~]# cat /etc/exports
/nfs-share 192.168.190.0/24(rw)

//重启nfs-server
[root@localhost ~]# systemctl restart nfs-server
  • nfs客户端:
[root@localhost ~]# mkdir /nfs-mountpoint
[root@localhost ~]# mount -t nfs 192.168.190.137:/nfs-share /nfs-mountpoint
[root@localhost ~]# df -Th
Filesystem                 Type      Size  Used Avail Use% Mounted on
devtmpfs                   devtmpfs  889M     0  889M   0% /dev
tmpfs                      tmpfs     904M     0  904M   0% /dev/shm
tmpfs                      tmpfs     904M  9.7M  894M   2% /run
tmpfs                      tmpfs     904M     0  904M   0% /sys/fs/cgroup
/dev/mapper/rhel-root      xfs        10G  3.7G  6.4G  37% /
/dev/mapper/rhel-opt       xfs       3.0G   54M  3.0G   2% /opt
/dev/nvme0n1p1             xfs       295M  147M  148M  50% /boot
/dev/mapper/rhel-var       xfs       2.0G  202M  1.8G  10% /var
tmpfs                      tmpfs     181M   20K  181M   1% /run/user/42
tmpfs                      tmpfs     181M  3.5M  178M   2% /run/user/1000
/dev/sr0                   iso9660   6.7G  6.7G     0 100% /mnt
/dev/nvme0n1p3             ext4       93M  1.6M   85M   2% /nfs-share
192.168.190.137:/nfs-share nfs4       93M  1.5M   85M   2% /nfs-mountpoint

[root@localhost ~]# cd /nfs-mountpoint/
[root@localhost nfs-mountpoint]# ls
lost+found
[root@localhost nfs-mountpoint]# exportfs
/nfs-share    	192.168.190.0/24

//实现持续挂载
[root@localhost nfs-mountpoint]# vim /etc/fstab
[root@localhost nfs-mountpoint]# cat /etc/fstab

#
# /etc/fstab
# Created by anaconda on Fri Nov 27 16:38:55 2020
#
# Accessible filesystems, by reference, are maintained under '/dev/disk/'.
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info.
#
# After editing this file, run 'systemctl daemon-reload' to update systemd
# units generated from this file.
#
/dev/mapper/rhel-root   /                       xfs     defaults        0 0
UUID=bd16835f-d654-4dc4-907c-ff15724ac1d2 /boot                   xfs     defaults        0 0
/dev/mapper/rhel-opt    /opt                    xfs     defaults        0 0
/dev/mapper/rhel-var    /var                    xfs     defaults        0 0
192.168.190.137:/nfs-share /nfs-mountpoint nfs default 0 0

VDO

//安装软件
[root@localhost nfs-mountpoint]# rpm -qa | grep kvdo
kmod-kvdo-6.2.0.293-50.el8.x86_64
[root@localhost nfs-mountpoint]# rpm -qa | grep vdo
vdo-6.2.0.293-10.el8.x86_64
kmod-kvdo-6.2.0.293-50.el8.x86_64
[root@localhost nfs-mountpoint]# yum -y install vdo kmod-kvdo

//创建vdo
[root@localhost nfs-mountpoint]# vdo create --name=testvdo --device=/dev/nvme0n1 --vdoLogicalSize=100G

//格式化
[root@localhost nfs-mountpoint]# mkfs.ext4 /dev/mapper/testvdo

//挂载
[root@localhost nfs-mountpoint]# mount /dev/mapper/testvdo /vdotest

//持续性挂载
[root@localhost nfs-mountpoint]# vi /etc/fstab 
[root@localhost nfs-mountpoint]# cat /etc/fstab 

#
# /etc/fstab
# Created by anaconda on Fri Nov 27 16:38:55 2020
#
# Accessible filesystems, by reference, are maintained under '/dev/disk/'.
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info.
#
# After editing this file, run 'systemctl daemon-reload' to update systemd
# units generated from this file.
#
/dev/mapper/rhel-root   /                       xfs     defaults        0 0
UUID=bd16835f-d654-4dc4-907c-ff15724ac1d2 /boot                   xfs     defaults        0 0
/dev/mapper/rhel-opt    /opt                    xfs     defaults        0 0
/dev/mapper/rhel-var    /var                    xfs     defaults        0 0
192.168.190.137:/nfs-share /nfs-mountpoint nfs defaults 0 0
/dev/mapper/testvdo /vdotest ext4 defaults,_netdev 0 0

autofs(按需挂载)

//autofs安装
[root@localhost ~]# yum list | grep autofs
libsss_autofs.x86_64                                 2.0.0-43.el8                                         @anaconda 
autofs.x86_64                                        1:5.1.4-29.el8                                       baseos    
[root@localhost ~]# yum -y install autofs

//配置文件
[root@localhost ~]# cat /etc/auto.master
#
# Sample auto.master file
# This is a 'master' automounter map and it has the following format:
# mount-point [map-type[,format]:]map [options]
# For details of the format look at auto.master(5).
#
/misc	/etc/auto.misc
#
# NOTE: mounts done from a hosts map will be mounted with the
#	"nosuid" and "nodev" options unless the "suid" and "dev"
#	options are explicitly given.
#
/net	-hosts
#
# Include /etc/auto.master.d/*.autofs
# The included files must conform to the format of this file.
#
+dir:/etc/auto.master.d
#
# If you have fedfs set up and the related binaries, either
# built as part of autofs or installed from another package,
# uncomment this line to use the fedfs program map to access
# your fedfs mounts.
#/nfs4  /usr/sbin/fedfs-map-nfs4 nobind
#
# Include central master map if it can be found using
# nsswitch sources.
#
# Note that if there are entries for /net or /misc (as
# above) in the included master map any keys that are the
# same will not be seen as the first read key seen takes
# precedence.
#
+auto.master
[root@localhost ~]# cat /etc/auto.misc 
#
# This is an automounter map and it has the following format
# key [ -mount-options-separated-by-comma ] location
# Details may be found in the autofs(5) manpage

cd		-fstype=iso9660,ro,nosuid,nodev	:/dev/cdrom

# the following entries are samples to pique your imagination
#linux		-ro,soft,intr		ftp.example.org:/pub/linux
#boot		-fstype=ext2		:/dev/hda1
#floppy		-fstype=auto		:/dev/fd0
#floppy		-fstype=ext2		:/dev/fd0
#e2floppy	-fstype=ext2		:/dev/fd0
#jaz		-fstype=ext2		:/dev/sdc1
#removable	-fstype=ext2		:/dev/hdd



已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 深蓝海洋 设计师:CSDN官方博客 返回首页