很多時候,在linux我們源碼編譯庫代碼時候會自定義安裝路徑,這使得man查詢的時候無法找到庫文檔,預設的man搜索路徑可以使用下麵命令查看: $ man -w /usr/local/share/man:/usr/share/man 我們可以通過修改man的命令搜索配置文件/etc/man_db.c ...
源文檔地址:https://www.2daygeek.com/create-lvm-storage-logical-volume-manager-in-linux/
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