Linux用lvm格式挂载磁盘
本次目标是将磁盘/dev/sdd以lvm格式挂载到/backup目录作为备份盘来用
1、查看当前磁盘
[root@quentin ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 300G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 299G 0 part
├─rhel-root 253:0 0 267G 0 lvm /
└─rhel-swap 253:1 0 32G 0 lvm [SWAP]
sdd 8:48 0 500G 0 disk
2、创建物理卷(PV)
首先,确保 /dev/sdb
作为物理卷(Physical Volume)可用。执行以下命令:
[root@quentin ~]# pvcreate /dev/sdd
Physical volume "/dev/sdd" successfully created.
3、创建卷组(VG)
接下来,创建一个卷组(Volume Group),你可以为其指定一个名字(例如 test
)。执行以下命令:
[root@quentin ~]# vgcreate test /dev/sdd
Volume group "test" successfully created
[root@quentin ~]#
[root@quentin ~]# vgs
VG #PV #LV #SN Attr VSize VFree
test 1 0 0 wz--n- <500.00g <500.00g
rhel 1 2 0 wz--n- <299.00g 0
4、创建逻辑卷(LV)
然后,你可以在卷组中创建逻辑卷(Logical Volume)。例如,创建一个名为 backup
的逻辑卷,大小为 500G:
[root@quentin ~]# lvcreate -t -L +500G -n backup test
TEST MODE: Metadata will NOT be updated and volumes will not be (de)activated.
Volume group "test" has insufficient free space (127999 extents): 128000 required.
[root@quentin ~]# lvcreate -l +127999 -n backup test
[root@quentin ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
backup test -wi-a----- <500.00g
root rhel -wi-ao---- <267.00g
swap rhel -wi-ao---- 32.00g
5、格式化lvm逻辑卷
[root@quentin ~]# mkfs.xfs /dev/mapper/test-backup
meta-data=/dev/mapper/test-backup isize=512 agcount=4, agsize=32767744 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=131070976, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal log bsize=4096 blocks=63999, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
6、创建挂载点并挂载逻辑卷
[root@quentin ~]# mkdir /backup
[root@quentin ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 300G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 299G 0 part
├─rhel-root 253:0 0 267G 0 lvm /
└─rhel-swap 253:1 0 32G 0 lvm [SWAP]
sdd 8:48 0 500G 0 disk
└─test-backup 253:4 0 500G 0 lvm
[root@quentin ~]# mount /dev/mapper/test-backup /backup/
[root@quentin ~]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 63G 0 63G 0% /dev
tmpfs 126G 2.1G 124G 2% /dev/shm
tmpfs 63G 459M 63G 1% /run
tmpfs 63G 0 63G 0% /sys/fs/cgroup
/dev/mapper/rhel-root 267G 105G 163G 40% /
/dev/sda1 1014M 170M 845M 17% /boot
tmpfs 13G 40K 13G 1% /run/user/0
tmpfs 13G 0 13G 0% /run/user/11012
/dev/mapper/test-backup 500G 33M 500G 1% /backup
7、配置开机自动挂载
[root@quentin ~]# cat /etc/fstab
#
# /etc/fstab
# Created by anaconda on Mon Aug 28 12:36:44 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
#
/dev/mapper/rhel-root / xfs defaults 0 0
UUID=c5e1a05f-b1a3-4334-878d-8cd7a1ccceea /boot xfs defaults 0 0
/dev/mapper/rhel-swap swap swap defaults 0 0
tmpfs /dev/shm tmpfs size=132033780k 0 0
/dev/mapper/test-backup /backup xfs defaults 0 0
[root@quentin ~]#