lvm基本操作
安装
$ yum install -y lvm2
创建
创建pv并查看
$ pvcreate /dev/sda3
Physical volume "/dev/sda3" successfully created.
$ pvdisplay /dev/sda3
"/dev/sda3" is a new physical volume of "<206.38 GiB"
--- NEW Physical volume ---
PV Name /dev/sda3
VG Name
PV Size <206.38 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID OKDd2t-4iMt-J2T3-hzN4-Z3YX-TXFJ-jMOMoh
提前创建好分区
创建vg并查看
$ vgcreate vg01 /dev/sda3
Volume group "vg01" successfully created
$ vgdisplay vg01
--- Volume group ---
VG Name vg01
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 <206.38 GiB
PE Size 4.00 MiB
Total PE 52832
Alloc PE / Size 0 / 0
Free PE / Size 52832 / <206.38 GiB
VG UUID zTQM1F-oEK0-NxbR-bNCP-je4K-cY2q-QsbnC1
扩容vg
$ sudo pvcreate /dev/nvme0n1
Physical volume "/dev/nvme0n1" successfully created.
创建lv并查看
# 指定容量
$ lvcreate -L +16G -n app vg01
Logical volume "app" created.
# 指定vg百分比
$ lvcreate -l 100%VG -n app vg01
WARNING: xfs signature detected on /dev/vg01/app at offset 0. Wipe it? [y/n]: y
Wiping xfs signature on /dev/vg01/app.
Logical volume "app" created.
$ lvdisplay /dev/vg01/app
--- Logical volume ---
LV Path /dev/vg01/app
LV Name app
VG Name vg01
LV UUID 5QKnpz-ozqJ-C51c-oB6A-jJ4O-oDeq-yyAQTW
LV Write Access read/write
LV Creation host, time kvm.ecloud.com, 2022-03-21 16:57:46 +0800
LV Status available
$ open 0
LV Size 16.00 GiB
Current LE 4096
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:2
挂载
# 格式化xfs文件系统
$ mkfs.xfs -f /dev/vg01/app
meta-data=/dev/vg01/app isize=512 agcount=4, agsize=1048576 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=4194304, 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
$ cat << EOF | sudo tee -a /etc/fstab > /dev/null
/dev/vg01/app /app ext4 defaults 0 0
EOF
$ mount -a
# 格式化ext4文件系统
$ mkfs.ext4 /dev/vg01/app
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
1048576 inodes, 4194304 blocks
209715 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2151677952
128 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000
Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
$ cat << EOF | sudo tee -a /etc/fstab > /dev/null
/dev/vg01/app /app xfs defaults 0 0
EOF
$ mount -a

浙公网安备 33010602011771号