Logical volume management LVM
1. Prepare a USB disk consisting of 3 empty partitions:
> lsblk
...
sdb 8:16 1 28.9G 0 disk
├─sdb1 8:17 1 500M 0 part
├─sdb2 8:18 1 600M 0 part
└─sdb3 8:19 1 700M 0 part
2. Create physical volumes (pv) for each one of the partitions:
> sudo pvcreate /dev/sdb{1,2,3}
Physical volume "/dev/sdb1" successfully created.
Physical volume "/dev/sdb2" successfully created.
Physical volume "/dev/sdb3" successfully created.
> lsblk
...
sdb 8:16 1 28.9G 0 disk
├─sdb1 8:17 1 500M 0 part
├─sdb2 8:18 1 600M 0 part
└─sdb3 8:19 1 700M 0 part
2. Create physical volumes (pv) for each one of the partitions:
> sudo pvcreate /dev/sdb{1,2,3}
Physical volume "/dev/sdb1" successfully created.
Physical volume "/dev/sdb2" successfully created.
Physical volume "/dev/sdb3" successfully created.
3. Verify the creation with pvscan:
>sudo pvscan
PV /dev/sda7 VG centos lvm2 [96.65 GiB / 4.00 MiB free]
PV /dev/sdb1 lvm2 [500.00 MiB]
PV /dev/sdb3 lvm2 [700.00 MiB]
PV /dev/sdb2 lvm2 [600.00 MiB]
Total: 4 [98.41 GiB] / in use: 1 [96.65 GiB] / in no VG: 3 [<1.76 GiB]
3. Create a volume group (vg) consisting 2 physical volumes:
> sudo vgcreate myvg /dev/sdb{1,2}
Volume group "myvg" successfully created
4. Verify the creation with vgscan:
> sudo vgscan
Reading volume groups from cache.
...
Found volume group "myvg" using metadata type lvm2
5. Do pvscan again, verify that the two physical volumes are now inside the volume group:
> sudo pvscan
...
PV /dev/sdb1 VG myvg lvm2 [496.00 MiB / 496.00 MiB free]
PV /dev/sdb2 VG myvg lvm2 [596.00 MiB / 596.00 MiB free]
PV /dev/sdb3 lvm2 [700.00 MiB]
6. Create a logical volume:
To create a logical volume name "mylv" with size of 1G on the volume group of "myvg"
> sudo lvcreate -L 1G -n mylv myvg
7. Do a lvscan to verify the lv creation:
>sudo lvscan
...
ACTIVE '/dev/myvg/mylv' [1.00 GiB] inherit
8. Now you can format the logical volume with the file system type you want.
For example, the xfs file system. And them mount it to the system.
> sudo mkfs.xfs /dev/myvg/mylv
> sudo mount /dev/myvg/mylv /mnt/mylvm
9. Extend the size of volume group and the logical volume on top of it:
> sudo vgextend myvg /dev/sdb3
> sudo lvextend -L +500M /dev/myvg/mylv
This will extend the logical volume of mylv by the size of 500Mb
10. Extend the file system on top of the logical volume:
Show file system information before extending
> xfs_info /mnt/mylvm
meta-data=/dev/mapper/myvg-mylv isize=512 agcount=4, agsize=65536 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=262144, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
Grow the file system:
> sudo xfs_growfs /mnt/mylvm
Verify the result:
> xfs_info /mnt/mylvm
meta-data=/dev/mapper/myvg-mylv isize=512 agcount=6, agsize=65536 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=390144, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
Reference:
留言
張貼留言