How to Create, Extend, and Remove LVM on Debian 12
- 00:48 cat /etc/os-release
- 01:01 lsblk
- 01:10 pvcreate /dev/sdb /dev/sdc
- 01:31 pvs
- 01:36 vgcreate volumegroup /dev/sdb /dev/sdc
- 02:10 vgs
- 02:20 lsblk
- 02:31 pvcreate /dev/sda
- 02:50 pvs
- 03:01 vgextend volumegroup /dev/sda
- 03:41 vgs
- 03:52 lvcreate -L +1G -n logicalvolume volumegroup
- 05:40 lvs
- 05:51 mkfs -t ext4 /dev/volumegroup/logicalvolume
- 06:07 mkdir lvolume
- 06:31 mount /dev/volumegroup/logicalvolume /root/lvolume
- 07:17 df -h
- 07:41 vim /etc/fstab
- 08:42 umount /root/lvolume
- 09:04 mount -a
- 09:12 df -h
- 09:23 lvs
- 09:37 lvextend -L +2G /dev/volumegroup/logicalvolume
- 10:10 lvs
- 10:21 df -h
- 10:31 resize2fs /dev/volumegroup/logicalvolume
- 11:04 df -h
- 11:17 lvcreate -i 3 -I128k -L +2G -n stripedlv volumegroup
- 12:12 lvs
- 12:26 lvcreate -m1 -L +2G -n mirrorlv volumegroup
- 13:17 lvs
- 13:21 umount /root/lvolume
- 13:43 lvremove /dev/volumegroup/logicalvolume
- 13:51 lvremove /dev/volumegroup/stripedlv
- 14:26 lvs
- 14:44 vgreduce volumegroup /dev/sda
- 14:55 vgreduce volumegroup /dev/sdb
- 15:15 vgs
- 15:47 vgremove /dev/volumegroup
- 16:07 pvs
- 16:10 pvremove /dev/sda
- 16:21 pvremove /dev/sdb /dev/sdc
To Create, Extend, Remove LVM On Debian 12
Introduction
Logical Volume Management (LVM) is a disk management solution used in Linux systems, offering advanced features for efficient disk storage management. It acts as a buffer between physical storage devices (e.g., hard drives, solid-state drives, or partitions) and the filesystems they contain. LVM enables system administrators to easily allocate, resize, and relocate storage capacity without interrupting data access or services, making it a valuable tool for both desktop and server environments.
Procedure Steps
Step 1: Check the OS version by using the below command.
root@linuxhelp:~# cat /etc/os-release
PRETTY_NAME="Debian GNU/Linux 12 (bookworm)"
NAME="Debian GNU/Linux"
VERSION_ID="12"
VERSION="12 (bookworm)"
VERSION_CODENAME=bookworm
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL=https://bugs.debian.org/
Step 2: Check disks by using the below command
root@linuxhelp:~# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
sda 8:0 0 10G 0 disk
sdb 8:16 0 5G 0 disk
sdc 8:32 0 5G 0 disk
sdd 8:48 0 60G 0 disk
├─sdd1 8:49 0 1.9G 0 part /boot
├─sdd2 8:50 0 3.7G 0 part [SWAP]
└─sdd3 8:51 0 54.4G 0 part /
sr0 11:0 1 1024M 0 rom
Step 3: Create physical volumes by using the below command
root@linuxhelp:~# pvcreate /dev/sdb /dev/sdc
Physical volume "/dev/sdb" successfully created.
Physical volume "/dev/sdc" successfully created.
Step 4: Check the physical volumes by using the below command
root@linuxhelp:~# pvs
PV VG Fmt Attr PSize PFree
/dev/sdb lvm2 --- 5.00g 5.00g
/dev/sdc lvm2 --- 5.00g 5.00g
Step 5: Create volume group by using the below command
root@linuxhelp:~# vgcreate volumegroup /dev/sdb /dev/sdc
Volume group "volumegroup" successfully created
Step 6: Check the volume group by using following command.
root@linuxhelp:~# vgs
VG #PV #LV #SN Attr VSize VFree
volumegroup 2 0 0 wz--n- 9.99g 9.99g
Step 7: Check disks by using following command for extend volume group size.
root@linuxhelp:~# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
sda 8:0 0 10G 0 disk
sdb 8:16 0 5G 0 disk
sdc 8:32 0 5G 0 disk
sdd 8:48 0 60G 0 disk
├─sdd1 8:49 0 1.9G 0 part /boot
├─sdd2 8:50 0 3.7G 0 part [SWAP]
└─sdd3 8:51 0 54.4G 0 part /
sr0 11:0 1 1024M 0 rom
Step 8: Create a raw disk to physical volume to extend volume group size by using the below command.
root@linuxhelp:~# pvcreate /dev/sda
Physical volume "/dev/sda" successfully created.
Step 9: Check the physical volumes by using following command.
root@linuxhelp:~# pvs
PV VG Fmt Attr PSize PFree
/dev/sda lvm2 --- 10.00g 10.00g
/dev/sdb volumegroup lvm2 a-- <5.00g <5.00g
/dev/sdc volumegroup lvm2 a-- <5.00g <5.00g
Step 10: Extend the volume group size by using the below command.
root@linuxhelp:~# vgextend volumegroup /dev/sda
Volume group "volumegroup" successfully extended
Step 11: Check volume group size by using following command.
root@linuxhelp:~# vgs
VG #PV #LV #SN Attr VSize VFree
volumegroup 3 0 0 wz--n- <19.99g <19.99g
Step 12: Create linear logical volume by using the below command.
root@linuxhelp:~# lvcreate -L +1G -n logicalvolume volumegroup
Logical volume "logicalvolume" created.
Step 13: Check the logical volume by using the below command.
root@linuxhelp:~# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
logicalvolume volumegroup -wi-a----- 1.00g
Step 14: Make the file system for logical volume by using the below command
root@linuxhelp:~# mkfs -t ext4 /dev/volumegroup/logicalvolume
mke2fs 1.47.0 (5-Feb-2023)
Creating filesystem with 262144 4k blocks and 65536 inodes
Filesystem UUID: 35382189-25bd-4c42-b61b-4655168fe29f
Superblock backups stored on blocks:
32768, 98304, 163840, 229376
Allocating group tables: done
Writing inode tables: done
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done
Step 15: Create a directory to mount file system by using the below command.
root@linuxhelp:~# mkdir lvolume
Step 16: Mount the file system temporarily by using the below command.
root@linuxhelp:~# mount /dev/volumegroup/logicalvolume /root/lvolume
Step 17: Check the file system size and mount point by using the below command.
root@linuxhelp:~# df -h
Filesystem Size Used Avail Use% Mounted on
udev 1.4G 0 1.4G 0% /dev
tmpfs 291M 1.5M 289M 1% /run
/dev/sdd3 54G 13G 38G 25% /
tmpfs 1.5G 0 1.5G 0% /dev/shm
tmpfs 5.0M 8.0K 5.0M 1% /run/lock
/dev/sdd1 1.8G 140M 1.6G 9% /boot
tmpfs 291M 88K 291M 1% /run/user/1000
/dev/mapper/volumegroup-logicalvolume 974M 24K 907M 1% /root/lvolume
Step 18: Mount the file system permanently by using the below command.
root@linuxhelp:~# vim /etc/fstab
/dev/mapper/volumegroup-logicalvolume /root/lvolume ext4 defaults 0 1
Step 19: Unmount the file system for checking permanently mount by using the below command.
root@linuxhelp:~# umount /root/lvolume
Step 20: Apply all permanent mount by using the below command.
root@linuxhelp:~# mount -a
Step 21: Check the file system size and mount point by using the below command
root@linuxhelp:~# df -h
Filesystem Size Used Avail Use% Mounted on
udev 1.4G 0 1.4G 0% /dev
tmpfs 291M 1.5M 289M 1% /run
/dev/sdd3 54G 13G 38G 25% /
tmpfs 1.5G 0 1.5G 0% /dev/shm
tmpfs 5.0M 8.0K 5.0M 1% /run/lock
/dev/sdd1 1.8G 140M 1.6G 9% /boot
tmpfs 291M 88K 291M 1% /run/user/1000
/dev/mapper/volumegroup-logicalvolume 974M 24K 907M 1% /root/lvolume
Step 22: Check the logical volume by using the below command.
root@linuxhelp:~# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
logicalvolume volumegroup -wi-ao---- 1.00g
Step 23: Extend the logical volume by using the below command.
root@linuxhelp:~# lvextend -L +2G /dev/volumegroup/logicalvolume
Size of logical volume volumegroup/logicalvolume changed from 1.00 GiB (256 extents) to 3.00 GiB (768 extents).
Logical volume volumegroup/logicalvolume successfully resized.
Step 24: Check the logical volume by using the below command.
root@linuxhelp:~# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
logicalvolume volumegroup -wi-ao---- 3.00g
Step 25: Check the file system size by using the below command.
root@linuxhelp:~# df -h
Filesystem Size Used Avail Use% Mounted on
udev 1.4G 0 1.4G 0% /dev
tmpfs 291M 1.5M 289M 1% /run
/dev/sdd3 54G 13G 38G 25% /
tmpfs 1.5G 0 1.5G 0% /dev/shm
tmpfs 5.0M 8.0K 5.0M 1% /run/lock
/dev/sdd1 1.8G 140M 1.6G 9% /boot
tmpfs 291M 88K 291M 1% /run/user/1000
/dev/mapper/volumegroup-logicalvolume 974M 24K 907M 1% /root/lvolume
Step 26: Extend the file system size by using the below command.
root@linuxhelp:~# resize2fs /dev/volumegroup/logicalvolume
resize2fs 1.47.0 (5-Feb-2023)
Filesystem at /dev/volumegroup/logicalvolume is mounted on /root/lvolume; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 1
The filesystem on /dev/volumegroup/logicalvolume is now 786432 (4k) blocks long.
Step 27: Check the file system size by using the below command.
root@linuxhelp:~# df -h
Filesystem Size Used Avail Use% Mounted on
udev 1.4G 0 1.4G 0% /dev
tmpfs 291M 1.5M 289M 1% /run
/dev/sdd3 54G 13G 38G 25% /
tmpfs 1.5G 0 1.5G 0% /dev/shm
tmpfs 5.0M 8.0K 5.0M 1% /run/lock
/dev/sdd1 1.8G 140M 1.6G 9% /boot
tmpfs 291M 88K 291M 1% /run/user/1000
/dev/mapper/volumegroup-logicalvolume 3.0G 24K 2.8G 1% /root/lvolume
Step 28: Create striped logical volume by using the below command.
root@linuxhelp:~# lvcreate -i 3 -I128k -L +2G -n stripedlv volumegroup
Rounding size 2.00 GiB (512 extents) up to stripe boundary size 2.00 GiB (513 extents).
Logical volume "stripedlv" created.
Step 29: Check the logical volume by using the below command.
root@linuxhelp:~# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
logicalvolume volumegroup -wi-ao---- 3.00g
stripedlv volumegroup -wi-a----- 2.00g
Step 30: Create mirror logical volume by using the below command.
root@linuxhelp:~# lvcreate -m1 -L +2G -n mirrorlv volumegroup
Logical volume "mirrorlv" created.
Step 31: Check the logical volume by using the below command.
root@linuxhelp:~# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
logicalvolume volumegroup -wi-ao---- 3.00g
mirrorlv volumegroup rwi-a-r--- 2.00g 100.00
stripedlv volumegroup -wi-a----- 2.00g
Step 32: unmount the logical volume file system by using the below command.
root@linuxhelp:~# umount /root/lvolume
Step 33: Remove the logical volumes by using the below command.
root@linuxhelp:~# lvremove /dev/volumegroup/logicalvolume
Do you really want to remove active logical volume volumegroup/logicalvolume? [y/n]: y
Logical volume "logicalvolume" successfully removed.
root@linuxhelp:~# lvremove /dev/volumegroup/stripedlv
Do you really want to remove active logical volume volumegroup/stripedlv? [y/n]: y
Logical volume "stripedlv" successfully removed.
root@linuxhelp:~# lvremove /dev/volumegroup/mirrorlv
Do you really want to remove active logical volume volumegroup/mirrorlv? [y/n]: y
Logical volume "mirrorlv" successfully removed.
Step 34: Check the logical volume by using the below command.
root@linuxhelp:~# lvs
Step 35: Remove the physical volumes from volume group by using the below command.
root@linuxhelp:~# vgreduce volumegroup /dev/sda
Removed "/dev/sda" from volume group "volumegroup"
root@linuxhelp:~# vgreduce volumegroup /dev/sdb
Removed "/dev/sdb" from volume group "volumegroup"
Step 36: Check the volume group by using the below command.
root@linuxhelp:~# vgs
VG #PV #LV #SN Attr VSize VFree
volumegroup 1 0 0 wz--n- <5.00g <5.00g
Step 37: Remove the volume group by using the below command.
root@linuxhelp:~# vgremove /dev/volumegroup
Volume group "volumegroup" successfully removed
Step 38: Check the physical volumes by using the below command.
root@linuxhelp:~# pvs
PV VG Fmt Attr PSize PFree
/dev/sda lvm2 --- 10.00g 10.00g
/dev/sdb lvm2 --- 5.00g 5.00g
/dev/sdc lvm2 --- 5.00g 5.00g
Step 39: Remove the physical volumes by using the below command.
root@linuxhelp:~# pvremove /dev/sda
Labels on physical volume "/dev/sda" successfully wiped.
root@linuxhelp:~# pvremove /dev/sdb /dev/sdc
Labels on physical volume "/dev/sdb" successfully wiped.
Labels on physical volume "/dev/sdc" successfully wiped.
Conclusion:
We have reached the end of this article. In this guide, we have walked you through the steps required to Create, Extend, Remove LVM on Debian 12. Your feedback is much welcome
Comments ( 0 )
No comments available