源文档地址:https://www.2daygeek.com/create-lvm-storage-logical-volume-manager-in-linux/

image-20230315140428820

1. 创建PV

创建前/dev/sdb不能分区,如果已经分区,使用fdisk /dev/sdb 删除分区
    [root@O-Friday ~]# pvcreate /dev/sdb /dev/sdc
    WARNING: dos signature detected on /dev/sdb at offset 510. Wipe it? [y/n]: y
      Wiping dos signature on /dev/sdb.
    WARNING: dos signature detected on /dev/sdc at offset 510. Wipe it? [y/n]: y
      Wiping dos signature on /dev/sdc.
      Physical volume "/dev/sdb" successfully created.
      Physical volume "/dev/sdc" successfully created.
    [root@O-Friday ~]# pvdisplay
      --- Physical volume ---
      PV Name               /dev/sda2
      VG Name               openeuler
      PV Size               <98.00 GiB / not usable 3.00 MiB
      Allocatable           yes (but full)
      PE Size               4.00 MiB
      Total PE              25087
      Free PE               0
      Allocated PE          25087
      PV UUID               Yv3d0c-OjcH-8s93-MsfZ-1JUu-XwU3-NYyPYD
    
      "/dev/sdb" is a new physical volume of "10.00 GiB"
      --- NEW Physical volume ---
      PV Name               /dev/sdb
      VG Name
      PV Size               10.00 GiB
      Allocatable           NO
      PE Size               0
      Total PE              0
      Free PE               0
      Allocated PE          0
      PV UUID               AxdYk0-Giiv-kF4Z-QOIj-yA6j-Rsf0-BI7S2o
    
      "/dev/sdc" is a new physical volume of "10.00 GiB"
      --- NEW Physical volume ---
      PV Name               /dev/sdc
      VG Name
      PV Size               10.00 GiB
      Allocatable           NO
      PE Size               0
      Total PE              0
      Free PE               0
      Allocated PE          0
      PV UUID               Nz06rK-h4FH-Jy2v-hXuE-hiws-6SRW-PSMQez
2. 创建VG

vgname = openeuler是系统安装时自动创建
    [root@O-Friday ~]# vgcreate vg01 /dev/sdb /dev/sdc
      Volume group "vg01" successfully created
    [root@O-Friday ~]# vgdisplay
      --- Volume group ---
      VG Name               vg01
      System ID
      Format                lvm2
      Metadata Areas        2
      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                2
      Act PV                2
      VG Size               19.99 GiB
      PE Size               4.00 MiB
      Total PE              5118
      Alloc PE / Size       0 / 0
      Free  PE / Size       5118 / 19.99 GiB
      VG UUID               oAbeGg-j8U2-kCuO-tcmW-HQWv-MqbT-kQdipr
    
      --- Volume group ---
      VG Name               openeuler
      System ID
      Format                lvm2
      Metadata Areas        1
      Metadata Sequence No  3
      VG Access             read/write
      VG Status             resizable
      MAX LV                0
      Cur LV                2
      Open LV               2
      Max PV                0
      Cur PV                1
      Act PV                1
      VG Size               <98.00 GiB
      PE Size               4.00 MiB
      Total PE              25087
      Alloc PE / Size       25087 / <98.00 GiB
      Free  PE / Size       0 / 0
      VG UUID               I7kRIn-4XeX-0agf-OxRq-ehSi-hqJf-nvkmtU
    
3. 查看vg
    [root@O-Friday ~]# vgs vg01
      VG   #PV #LV #SN Attr   VSize  VFree
      vg01   2   0   0 wz--n- 19.99g 19.99g
4. 扩展VG
    [root@O-Friday ~]# vgextend vg01 /dev/sdd
    WARNING: dos signature detected on /dev/sdd at offset 510. Wipe it? [y/n]: y
      Wiping dos signature on /dev/sdd.
      Physical volume "/dev/sdd" successfully created.
      Volume group "vg01" successfully extended
    
5. 创建LV

/swap 与 /root为安装系统时自动创建
    [root@O-Friday ~]# lvcreate -n lv001 -L 15G vg01
      Logical volume "lv001" created.
    [root@O-Friday ~]# lvdisplay
      --- Logical volume ---
      LV Path                /dev/vg01/lv001
      LV Name                lv001
      VG Name                vg01
      LV UUID                0TdOKB-PDI3-LWDv-X2nb-lBVV-kfLJ-jVOVBy
      LV Write Access        read/write
      LV Creation host, time O-Friday, 2023-03-15 14:24:07 +0800
      LV Status              available
      # open                 0
      LV Size                15.00 GiB
      Current LE             3840
      Segments               2
      Allocation             inherit
      Read ahead sectors     auto
      - currently set to     8192
      Block device           253:2
    
      --- Logical volume ---
      LV Path                /dev/openeuler/swap
      LV Name                swap
      VG Name                openeuler
      LV UUID                xNBLth-zrQf-HY8L-fSrA-jrrU-qERF-xfDafa
      LV Write Access        read/write
      LV Creation host, time O-Friday, 2023-03-05 10:52:53 +0800
      LV Status              available
      # open                 2
      LV Size                6.00 GiB
      Current LE             1536
      Segments               1
      Allocation             inherit
      Read ahead sectors     auto
      - currently set to     8192
      Block device           253:1
    
      --- Logical volume ---
      LV Path                /dev/openeuler/root
      LV Name                root
      VG Name                openeuler
      LV UUID                i3ZktA-EN9t-HJB3-y1Ok-Or1X-z0uq-3ixcbG
      LV Write Access        read/write
      LV Creation host, time O-Friday, 2023-03-05 10:52:54 +0800
      LV Status              available
      # open                 1
      LV Size                <92.00 GiB
      Current LE             23551
      Segments               1
      Allocation             inherit
      Read ahead sectors     auto
      - currently set to     8192
      Block device           253:0
    
6. 查看lv
    [root@O-Friday ~]# lvs /dev/vg01/lv001
      LV    VG   Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
      lv001 vg01 -wi-a----- 15.00g
    
7. 使用PE size 创建lv
    15GB = 15360MB / 4MB (PE Size) = 3840 PEs
    
    lvcreate -n lv001 -l 3840 vg01
8. 使用比例创建
     lvcreate -n lv001 -l 100%FREE vg01
     
9. 创建File system
    mkfs -t ext4 /dev/vg01/lv001
    mkfs -t xfs /dev/vg01/lv001
    
    两种文件系统格式创建,下面使用ext4
    
    [root@O-Friday ~]# lvs /dev/vg01/lv001
      LV    VG   Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
      lv001 vg01 -wi-a----- 15.00g
    [root@O-Friday ~]# mkfs -t ext4 /dev/vg01/lv001
    mke2fs 1.46.4 (18-Aug-2021)
    Creating filesystem with 3932160 4k blocks and 983040 inodes
    Filesystem UUID: 81d59fcc-ebac-430e-8eca-c36ed3155160
    Superblock backups stored on blocks:
            32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208
    
    Allocating group tables: done
    Writing inode tables: done
    Creating journal (16384 blocks): done
    Writing superblocks and filesystem accounting information: done
    
    
    
10. 从lvm中移除物理卷

 要移除的物理卷,used必须为0,如果要移除/dev/sdd首先通过pvmove将数据移动到其他物理卷

 如果没有空闲的空间来移动数据,需要添加新的物理卷后,再移除原物理卷
     [root@O-Friday ~]# pvs -o+pv_used
       PV         VG        Fmt  Attr PSize   PFree   Used
       /dev/sda2  openeuler lvm2 a--  <98.00g      0  <98.00g
       /dev/sdb   vg01      lvm2 a--  <10.00g      0  <10.00g
       /dev/sdc   vg01      lvm2 a--  <10.00g <10.00g      0
       /dev/sdd   vg01      lvm2 a--  <10.00g   4.99g   5.00g
       
     [root@O-Friday ~]# pvmove /dev/sdd
       /dev/sdd: Moved: 1.72%
       /dev/sdd: Moved: 100.00%
     [root@O-Friday ~]# pvs -o+pv_used
       PV         VG        Fmt  Attr PSize   PFree   Used
       /dev/sda2  openeuler lvm2 a--  <98.00g      0  <98.00g
       /dev/sdb   vg01      lvm2 a--  <10.00g      0  <10.00g
       /dev/sdc   vg01      lvm2 a--  <10.00g   4.99g   5.00g
       /dev/sdd   vg01      lvm2 a--  <10.00g <10.00g      0
     
     [root@O-Friday ~]# pvremove /dev/sdd
       PV /dev/sdd is used by VG vg01 so please use vgreduce first.
       (If you are certain you need pvremove, then confirm by using --force twice.)
       /dev/sdd: physical volume label not removed.
     
     此时依然不能移除,因为pv在vg中已经使用,需要先用vgreduce删除
     [root@O-Friday ~]# vgreduce vg01 /dev/sdd
       Removed "/dev/sdd" from volume group "vg01"
     [root@O-Friday ~]# pvremove /dev/sdd
       Labels on physical volume "/dev/sdd" successfully wiped.
     
11. 如何删除逻辑卷
     如果已经挂载分区先执行umount /data
     如果已经/etc/fstab设置了自动挂载, 要先删除
     
     Disable the “lv001” logical volume
     
     执行后查看lv status 已经是 not available状态
     
     [root@O-Friday ~]# lvchange -an /dev/vg01/lv001
     [root@O-Friday ~]# lvdisplay
       --- Logical volume ---
       LV Path                /dev/vg01/lv001
       LV Name                lv001
       VG Name                vg01
       LV UUID                0TdOKB-PDI3-LWDv-X2nb-lBVV-kfLJ-jVOVBy
       LV Write Access        read/write
       LV Creation host, time O-Friday, 2023-03-15 14:24:07 +0800
       LV Status              NOT available
       LV Size                15.00 GiB
       Current LE             3840
       Segments               2
       Allocation             inherit
       Read ahead sectors     auto
     
       --- Logical volume ---
       LV Path                /dev/openeuler/swap
       LV Name                swap
       VG Name                openeuler
       LV UUID                xNBLth-zrQf-HY8L-fSrA-jrrU-qERF-xfDafa
       LV Write Access        read/write
       LV Creation host, time O-Friday, 2023-03-05 10:52:53 +0800
       LV Status              available
       # open                 2
       LV Size                6.00 GiB
       Current LE             1536
       Segments               1
       Allocation             inherit
       Read ahead sectors     auto
       - currently set to     8192
       Block device           253:1
     
       --- Logical volume ---
       LV Path                /dev/openeuler/root
       LV Name                root
       VG Name                openeuler
       LV UUID                i3ZktA-EN9t-HJB3-y1Ok-Or1X-z0uq-3ixcbG
       LV Write Access        read/write
       LV Creation host, time O-Friday, 2023-03-05 10:52:54 +0800
       LV Status              available
       # open                 1
       LV Size                <92.00 GiB
       Current LE             23551
       Segments               1
       Allocation             inherit
       Read ahead sectors     auto
       - currently set to     8192
       Block device           253:0
     	
12. 删除VG

 If there are no logical volumes associated with the volume group(VG) and if the VG is no longer required, then remove that as well.
     [root@O-Friday ~]# vgchange -an vg01
       0 logical volume(s) in volume group "vg01" now active
     [root@O-Friday ~]# vgdisplay
       --- Volume group ---
       VG Name               vg01
       System ID
       Format                lvm2
       Metadata Areas        2
       Metadata Sequence No  11
       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               19.99 GiB
       PE Size               4.00 MiB
       Total PE              5118
       Alloc PE / Size       0 / 0
       Free  PE / Size       5118 / 19.99 GiB
       VG UUID               oAbeGg-j8U2-kCuO-tcmW-HQWv-MqbT-kQdipr
     
       --- Volume group ---
       VG Name               openeuler
       System ID
       Format                lvm2
       Metadata Areas        1
       Metadata Sequence No  3
       VG Access             read/write
       VG Status             resizable
       MAX LV                0
       Cur LV                2
       Open LV               2
       Max PV                0
       Cur PV                1
       Act PV                1
       VG Size               <98.00 GiB
       PE Size               4.00 MiB
       Total PE              25087
       Alloc PE / Size       25087 / <98.00 GiB
       Free  PE / Size       0 / 0
       VG UUID               I7kRIn-4XeX-0agf-OxRq-ehSi-hqJf-nvkmtU
     
     [root@O-Friday ~]# vgremove vg01
       Volume group "vg01" successfully removed
     [root@O-Friday ~]# vgdisplay
       --- Volume group ---
       VG Name               openeuler
       System ID
       Format                lvm2
       Metadata Areas        1
       Metadata Sequence No  3
       VG Access             read/write
       VG Status             resizable
       MAX LV                0
       Cur LV                2
       Open LV               2
       Max PV                0
       Cur PV                1
       Act PV                1
       VG Size               <98.00 GiB
       PE Size               4.00 MiB
       Total PE              25087
       Alloc PE / Size       25087 / <98.00 GiB
       Free  PE / Size       0 / 0
       VG UUID               I7kRIn-4XeX-0agf-OxRq-ehSi-hqJf-nvkmtU
     
13. 删除pv

 Delete physical volumes used for volume group **“vg01”**:
     [root@O-Friday ~]# pvremove /dev/sdb /dev/sdc
       Labels on physical volume "/dev/sdb" successfully wiped.
       Labels on physical volume "/dev/sdc" successfully wiped.
     [root@O-Friday ~]# pvdisplay
       --- Physical volume ---
       PV Name               /dev/sda2
       VG Name               openeuler
       PV Size               <98.00 GiB / not usable 3.00 MiB
       Allocatable           yes (but full)
       PE Size               4.00 MiB
       Total PE              25087
       Free PE               0
       Allocated PE          25087
       PV UUID               Yv3d0c-OjcH-8s93-MsfZ-1JUu-XwU3-NYyPYD
     
14. 缩减逻辑卷大小

 如果已经挂载, 先umount
     [root@O-Friday mapper]# resize2fs /dev/mapper/vg01-lv001 20G
     resize2fs 1.46.4 (18-Aug-2021)
     Please run 'e2fsck -f /dev/mapper/vg01-lv001' first.
     
     [root@O-Friday mapper]# e2fsck -f /dev/mapper/vg01-lv001
     e2fsck 1.46.4 (18-Aug-2021)
     Pass 1: Checking inodes, blocks, and sizes
     Pass 2: Checking directory structure
     Pass 3: Checking directory connectivity
     Pass 4: Checking reference counts
     Pass 5: Checking group summary information
     /dev/mapper/vg01-lv001: 11/1966080 files (0.0% non-contiguous), 167453/7861248 blocks
     [root@O-Friday mapper]# resize2fs /dev/mapper/vg01-lv001 20G
     resize2fs 1.46.4 (18-Aug-2021)
     Resizing the filesystem on /dev/mapper/vg01-lv001 to 5242880 (4k) blocks.
     The filesystem on /dev/mapper/vg01-lv001 is now 5242880 (4k) blocks long.
     
     [root@O-Friday mapper]# lvreduce -L 20G /dev/mapper/vg01-lv001
       WARNING: Reducing active logical volume to 20.00 GiB.
       THIS MAY DESTROY YOUR DATA (filesystem etc.)
     Do you really want to reduce vg01/lv001? [y/n]: y
       Size of logical volume vg01/lv001 changed from <29.99 GiB (7677 extents) to 20.00 GiB (5120 extents).
       Logical volume vg01/lv001 successfully resized.
     [root@O-Friday mapper]# lsblk
     NAME               MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTS
     sda                  8:0    0  100G  0 disk
     ├─sda1               8:1    0    2G  0 part /boot
     └─sda2               8:2    0   98G  0 part
       ├─openeuler-root 253:0    0   92G  0 lvm  /
       └─openeuler-swap 253:1    0    6G  0 lvm  [SWAP]
     sdb                  8:16   0   10G  0 disk
     └─vg01-lv001       253:2    0   20G  0 lvm
     sdc                  8:32   0   10G  0 disk
     └─vg01-lv001       253:2    0   20G  0 lvm
     sdd                  8:48   0   10G  0 disk
     └─vg01-lv001       253:2    0   20G  0 lvm
     sr0                 11:0    1  3.5G  0 rom
     [root@O-Friday mapper]# e2fsck -f /dev/mapper/vg01-lv001
     e2fsck 1.46.4 (18-Aug-2021)
     Pass 1: Checking inodes, blocks, and sizes
     Pass 2: Checking directory structure
     Pass 3: Checking directory connectivity
     Pass 4: Checking reference counts
     Pass 5: Checking group summary information
     /dev/mapper/vg01-lv001: 11/1310720 files (0.0% non-contiguous), 126322/5242880 blocks
     
15. 扩展逻辑卷大小

 与14是相反操作
     三种扩展方式
     lvextend -l +40%FREE /dev/mapper/vg01-lv002
     lvextend -l +2560 /dev/mapper/vg01-lv002
     lvextend -L +10G /dev/mapper/vg01-lv002
     
     [root@O-Friday ~]# lvextend -l +100%FREE /dev/mapper/vg01-lv001
       Size of logical volume vg01/lv001 changed from 20.00 GiB (5120 extents) to <29.99 GiB (7677 extents).
       Logical volume vg01/lv001 successfully resized.
     
     此时,只是扩展了逻辑卷,分区大小并没有变化
     扩展分区:
     如果是ext4类型
     resize2fs /dev/mapper/vg01-lv001
     如果是xfs类型
     xfs_growfs /dev/mapper/vg01-lv001
     
     [root@O-Friday ~]# resize2fs /dev/mapper/vg01-lv001
     resize2fs 1.46.4 (18-Aug-2021)
     Please run 'e2fsck -f /dev/mapper/vg01-lv001' first.
     
     [root@O-Friday ~]# e2fsck -f /dev/mapper/vg01-lv001
     e2fsck 1.46.4 (18-Aug-2021)
     Pass 1: Checking inodes, blocks, and sizes
     Pass 2: Checking directory structure
     Pass 3: Checking directory connectivity
     Pass 4: Checking reference counts
     Pass 5: Checking group summary information
     /dev/mapper/vg01-lv001: 11/1310720 files (0.0% non-contiguous), 126322/5242880 blocks
     [root@O-Friday ~]# resize2fs /dev/mapper/vg01-lv001
     resize2fs 1.46.4 (18-Aug-2021)
     Resizing the filesystem on /dev/mapper/vg01-lv001 to 7861248 (4k) blocks.
     The filesystem on /dev/mapper/vg01-lv001 is now 7861248 (4k) blocks long.
     
     重新挂载分区,查看,已经是30G
     
     [root@O-Friday ~]# mount /dev/vg01/lv001 /data
     [root@O-Friday ~]# df -h
     Filesystem                  Size  Used Avail Use% Mounted on
     devtmpfs                    4.0M     0  4.0M   0% /dev
     tmpfs                       1.7G   12K  1.7G   1% /dev/shm
     tmpfs                       676M  9.2M  667M   2% /run
     tmpfs                       4.0M     0  4.0M   0% /sys/fs/cgroup
     /dev/mapper/openeuler-root   90G  2.5G   83G   3% /
     tmpfs                       1.7G     0  1.7G   0% /tmp
     /dev/sda1                   2.0G  251M  1.6G  14% /boot
     /dev/mapper/vg01-lv001       30G   24K   28G   1% /data
     
16. lvm中添加新磁盘
     --查询新增磁盘的名称
     fdisk -l 
     
     Disk /dev/sde: 10 GiB, 10737418240 bytes, 20971520 sectors
     Disk model: VMware Virtual S
     Units: sectors of 1 * 512 = 512 bytes
     Sector size (logical/physical): 512 bytes / 512 bytes
     I/O size (minimum/optimal): 512 bytes / 512 bytes
     
     --将/dev/sde加入到vg中
     
     [root@O-Friday ~]# vgextend vg01 /dev/sde
       Physical volume "/dev/sde" successfully created.
       Volume group "vg01" successfully extended
     
     --pv中已经添加了 /dev/sde
     [root@O-Friday ~]# pvdisplay
       --- Physical volume ---
       PV Name               /dev/sdb
       VG Name               vg01
       PV Size               10.00 GiB / not usable 4.00 MiB
       Allocatable           yes (but full)
       PE Size               4.00 MiB
       Total PE              2559
       Free PE               0
       Allocated PE          2559
       PV UUID               G3VQkg-izg2-8hNm-9bw4-Ex5r-a0ec-YBEpPr
     
       --- Physical volume ---
       PV Name               /dev/sdc
       VG Name               vg01
       PV Size               10.00 GiB / not usable 4.00 MiB
       Allocatable           yes (but full)
       PE Size               4.00 MiB
       Total PE              2559
       Free PE               0
       Allocated PE          2559
       PV UUID               16j3C2-lPOn-KdR4-R1By-NoJS-UZ8S-xj9jyy
     
       --- Physical volume ---
       PV Name               /dev/sdd
       VG Name               vg01
       PV Size               10.00 GiB / not usable 4.00 MiB
       Allocatable           yes (but full)
       PE Size               4.00 MiB
       Total PE              2559
       Free PE               0
       Allocated PE          2559
       PV UUID               YHoxPb-fDi5-P8By-dzXh-7LPz-a4BO-j6um2R
     
       --- Physical volume ---
       PV Name               /dev/sde
       VG Name               vg01
       PV Size               10.00 GiB / not usable 4.00 MiB
       Allocatable           yes
       PE Size               4.00 MiB
       Total PE              2559
       Free PE               2559
       Allocated PE          0
       PV UUID               PaMgdp-4VS7-u7Nv-m7Zg-FUPK-uTBA-yDHmkE
     
       --- Physical volume ---
       PV Name               /dev/sda2
       VG Name               openeuler
       PV Size               <98.00 GiB / not usable 3.00 MiB
       Allocatable           yes (but full)
       PE Size               4.00 MiB
       Total PE              25087
       Free PE               0
       Allocated PE          25087
       PV UUID               Yv3d0c-OjcH-8s93-MsfZ-1J
     
     --添加后查看vg, 已有10G free空间
     [root@O-Friday ~]# vgdisplay vg01
       --- Volume group ---
       VG Name               vg01
       System ID
       Format                lvm2
       Metadata Areas        4
       Metadata Sequence No  5
       VG Access             read/write
       VG Status             resizable
       MAX LV                0
       Cur LV                1
       Open LV               0
       Max PV                0
       Cur PV                4
       Act PV                4
       VG Size               39.98 GiB
       PE Size               4.00 MiB
       Total PE              10236
       Alloc PE / Size       7677 / <29.99 GiB
       Free  PE / Size       2559 / <10.00 GiB
       VG UUID               PEANLD-I1ET-hpk1-jN9V-CxZ6-ktRB-veif7v
     
     --扩展lv,扩展所有FREE
     [root@O-Friday ~]# lvextend -l +100%FREE /dev/mapper/vg01-lv001
       Size of logical volume vg01/lv001 changed from <29.99 GiB (7677 extents) to 39.98 GiB (10236 extents).
       Logical volume vg01/lv001 successfully resized.
     
     --扩展分区, 需要先执行e2fsck
     
     [root@O-Friday ~]# resize2fs /dev/mapper/vg01-lv001
     resize2fs 1.46.4 (18-Aug-2021)
     Please run 'e2fsck -f /dev/mapper/vg01-lv001' first.
     
     [root@O-Friday ~]# e2fsck -f /dev/mapper/vg01-lv001
     e2fsck 1.46.4 (18-Aug-2021)
     Pass 1: Checking inodes, blocks, and sizes
     Pass 2: Checking directory structure
     Pass 3: Checking directory connectivity
     Pass 4: Checking reference counts
     Pass 5: Checking group summary information
     /dev/mapper/vg01-lv001: 11/1966080 files (0.0% non-contiguous), 167442/7861248 blocks
     [root@O-Friday ~]# resize2fs /dev/mapper/vg01-lv001
     resize2fs 1.46.4 (18-Aug-2021)
     Resizing the filesystem on /dev/mapper/vg01-lv001 to 10481664 (4k) blocks.
     The filesystem on /dev/mapper/vg01-lv001 is now 10481664 (4k) blocks long.
     
     --重新挂载分区,查看
     [root@O-Friday ~]# mount /dev/vg01/lv001 /data
     [root@O-Friday ~]# df -h
     Filesystem                  Size  Used Avail Use% Mounted on
     devtmpfs                    4.0M     0  4.0M   0% /dev
     tmpfs                       1.7G   12K  1.7G   1% /dev/shm
     tmpfs                       676M  9.2M  667M   2% /run
     tmpfs                       4.0M     0  4.0M   0% /sys/fs/cgroup
     /dev/mapper/openeuler-root   90G  2.5G   83G   3% /
     tmpfs                       1.7G     0  1.7G   0% /tmp
     /dev/sda1                   2.0G  251M  1.6G  14% /boot
     /dev/mapper/vg01-lv001       40G   24K   38G   1% /data
     
17. /etc/fstab

 在Linux系统中,`/etc/fstab`文件用于定义系统挂载文件系统的方式,包括本地磁盘、网络共享、CD-ROM等等。

 每一行代表一个文件系统,每个字段用制表符分隔。以下是每个字段的含义:

 1. **文件系统**: 这个字段表示要挂载的文件系统的设备名或者UUID。例如:`/dev/sda1`或`UUID=4b5324c4-2b8a-4f06-9b6c-bb5f5d5d5b9a`。也可以用LABEL来指定设备名称,例如:`LABEL=MyDisk`。注意:如果使用UUID或LABEL方式指定设备名称,则不受分区名的影响。
 2. **挂载点**: 这个字段指定文件系统的挂载点,即文件系统要挂载到哪个目录下。例如:`/` 或 `/home`。
 3. **文件系统类型**: 这个字段指定文件系统的类型。例如:ext4、ntfs、vfat等。如果不知道文件系统类型,可以在终端中使用 `blkid` 命令查看。
 4. **选项**: 这个字段指定了文件系统的挂载选项,例如是否允许读写、是否允许执行程序、是否允许设备文件、是否自动挂载等等。多个选项之间用逗号分隔。
    - `defaults`:默认选项,包括读取和写入权限、执行权限以及自动挂载。
    - `ro`:只读选项,只允许读取文件系统中的内容,禁止修改。
    - `noauto`:禁止自动挂载选项,文件系统不会在系统启动时自动挂载。
    - `user`:允许普通用户挂载选项,通常只有超级用户才有挂载权限。
    - `noexec`:禁止执行选项,防止在文件系统中执行程序和脚本文件。
    - `nosuid`:禁止设置用户ID和组ID选项,防止在文件系统中执行 SUID 和 SGID 程序。
    - `nodev`:禁止创建设备文件选项,防止在文件系统中创建设备文件。
    - `noatime`:禁止更新访问时间选项,不更新最后一次访问时间,以提高性能。
    - `nodiratime`:禁止更新目录访问时间选项,不更新目录最后一次访问时间,以提高性能。
    - `relatime`:相对更新访问时间选项,只在访问时间落后于修改时间或创建时间时更新访问时间。
    - `async`:异步选项,允许异步读取和写入,以提高性能。但是这样可能会导致数据丢失,因为写入操作不会立即写入磁盘。
 5. **备份频率**: 这个字段指定了备份频率。在 Linux 中,`0` 表示不备份,`1` 表示每天备份一次,`2` 表示每周备份一次,`3` 表示每月备份一次。如果不需要备份,则可以将此字段设置为 0。
 6. **检查顺序**: 这个字段用于指定系统引导时,需要检查哪些文件系统。默认情况下,根文件系统(/)的检查顺序为 1,其他文件系统为 2。可以将此字段设置为 0,表示不进行检查。
     [root@O-Friday ~]# cat /etc/fstab
     
     #
     # /etc/fstab
     # Created by anaconda on Sun Mar  5 02:52:57 2023
     #
     # 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/openeuler-root /                       ext4    defaults        1 1
     UUID=3ee8700a-3e9c-4c83-9336-87fa08836b84 /boot                   ext4    defaults        1 2
     /dev/mapper/openeuler-swap none                    swap    defaults        0 0