How to create partitions using LVM on Linux Mint 20

To create partitions using LVM on Linux Mint 20

Intoduction:

LVM is the Logical Volume Management tool that comprises allocating disks, segmenting, replication, and resize the logical volumes. It is used to allocate a hard drive or set of hard drives to one or more physical volumes which can be placed on other block devices that might span two or more disks.

Installation Procedure:

First Check the version of the Linux mint

root@LinuxHelp:~# lsb_release -a
No LSB modules are available.
Distributor ID:	Linuxmint
Description:	Linux Mint 20
Release:	20
Codename:	ulyana

List the disk by executing the following command

root@LinuxHelp:~# fdisk -l
Disk /dev/sda: 20 GiB, 21474836480 bytes, 41943040 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
Disklabel type: dos
Disk identifier: 0x749a518b
Device     Boot   Start      End  Sectors  Size Id Type
/dev/sda1  *       2048  1050623  1048576  512M  b W95 FAT32
/dev/sda2       1052670 41940991 40888322 19.5G  5 Extended
/dev/sda5       1052672 41940991 40888320 19.5G 83 Linux
Disk /dev/sdb: 30 GiB, 32212254720 bytes, 62914560 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

Now Create partitions by executing the following command

root@LinuxHelp:~# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.34).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
The old ext4 signature will be removed by a write command.
Device does not contain a recognized partition table.
Created a new DOS disklabel with disk identifier 0x4b24993c.
Command (m for help): n
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p): p
Partition number (1-4, default 1): 
First sector (2048-62914559, default 2048): 
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-62914559, default 62914559): +10G
Created a new partition 1 of type 'Linux' and of size 10 GiB.
Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.

Syncing disks.

root@LinuxHelp:~# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.34).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): n       
Partition type
   p   primary (1 primary, 0 extended, 3 free)
   e   extended (container for logical partitions)
Select (default p): p
Partition number (2-4, default 2): 
First sector (20973568-62914559, default 20973568): 
Last sector, +/-sectors or +/-size{K,M,G,T,P} (20973568-62914559, default 62914559): +10G
Created a new partition 2 of type 'Linux' and of size 10 GiB.
Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

After the partitions is created. List the disk by executing the following command

root@LinuxHelp:~# fdisk -l
Disk /dev/sda: 20 GiB, 21474836480 bytes, 41943040 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
Disklabel type: dos
Disk identifier: 0x749a518b
Device     Boot   Start      End  Sectors  Size Id Type
/dev/sda1  *       2048  1050623  1048576  512M  b W95 FAT32
/dev/sda2       1052670 41940991 40888322 19.5G  5 Extended
/dev/sda5       1052672 41940991 40888320 19.5G 83 Linux
Disk /dev/sdb: 30 GiB, 32212254720 bytes, 62914560 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
Disklabel type: dos
Disk identifier: 0x4b24993c
Device     Boot    Start      End  Sectors Size Id Type
/dev/sdb1           2048 20973567 20971520  10G 83 Linux
/dev/sdb2       20973568 41945087 20971520  10G 83 Linux

Change the type of the partitions by executing the following command

root@LinuxHelp:~# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.34).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help): t
Partition number (1,2, default 2): 1
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'.
Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
root@LinuxHelp:~# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.34).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help): t
Partition number (1,2, default 2): 2
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'.
Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

Check the disk by executing the following command

root@LinuxHelp:~# fdisk -l
Disk /dev/sda: 20 GiB, 21474836480 bytes, 41943040 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
Disklabel type: dos
Disk identifier: 0x749a518b
Device     Boot   Start      End  Sectors  Size Id Type
/dev/sda1  *       2048  1050623  1048576  512M  b W95 FAT32
/dev/sda2       1052670 41940991 40888322 19.5G  5 Extended
/dev/sda5       1052672 41940991 40888320 19.5G 83 Linux


Disk /dev/sdb: 30 GiB, 32212254720 bytes, 62914560 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
Disklabel type: dos
Disk identifier: 0x4b24993c
Device     Boot    Start      End  Sectors Size Id Type
/dev/sdb1           2048 20973567 20971520  10G 8e Linux LVM
/dev/sdb2       20973568 41945087 20971520  10G 8e Linux LVM

Create the physical volume by executing the following command

root@LinuxHelp:~# pvcreate pv /dev/sdb1 
  Device pv not found.
WARNING: ext4 signature detected on /dev/sdb1 at offset 1080. Wipe it? [y/n]: y
  Wiping ext4 signature on /dev/sdb1.
  Physical volume "/dev/sdb1" successfully created.
root@LinuxHelp:~# pvcreate pv1 /dev/sdb2
  Device pv1 not found.
WARNING: ext4 signature detected on /dev/sdb2 at offset 1080. Wipe it? [y/n]: y
  Wiping ext4 signature on /dev/sdb2.
  Physical volume "/dev/sdb2" successfully created.

Now list the physical volume

root@LinuxHelp:~# pvs
  PV         VG Fmt  Attr PSize  PFree 
  /dev/sdb1     lvm2 ---  10.00g 10.00g
  /dev/sdb2     lvm2 ---  10.00g 10.00g

Now create the volume groups by executing the following command

root@LinuxHelp:~# vgcreate vg /dev/sdb1 /dev/sdb2 
  Volume group "vg" successfully created

List the volume groups by executing the following command

root@LinuxHelp:~# vgs
  VG #PV #LV #SN Attr   VSize  VFree 
  vg   2   0   0 wz--n- 19.99g 19.99g

Now create the logical volume by execute the following commnd

root@LinuxHelp:~# lvcreate -L +5G -n lv vg
  Logical volume "lv" created.
root@LinuxHelp:~# lvcreate -L +5G -n lv1 vg
  Logical volume "lv1" created.

Now list the logical volume

root@LinuxHelp:~# lvs
  LV   VG Attr       LSize Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  lv   vg -wi-a----- 5.00g                                                    
  lv1  vg -wi-a----- 5.00g         

Now list the disk

root@LinuxHelp:~# fdisk -l
Disk /dev/sda: 20 GiB, 21474836480 bytes, 41943040 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
Disklabel type: dos
Disk identifier: 0x749a518b
Device     Boot   Start      End  Sectors  Size Id Type
/dev/sda1  *       2048  1050623  1048576  512M  b W95 FAT32
/dev/sda2       1052670 41940991 40888322 19.5G  5 Extended
/dev/sda5       1052672 41940991 40888320 19.5G 83 Linux
Disk /dev/sdb: 30 GiB, 32212254720 bytes, 62914560 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
Disklabel type: dos
Disk identifier: 0x4b24993c
Device     Boot    Start      End  Sectors Size Id Type
.
.
.

Now extend the size of the logical volume

root@LinuxHelp:~# lvextend -L +1G /dev/mapper/vg-lv
  Size of logical volume vg/lv changed from 5.00 GiB (1280 extents) to 6.00 GiB (1536 extents).
  Logical volume vg/lv successfully resized.

Now list the logical volume

root@LinuxHelp:~# fdisk -l
Disk /dev/sda: 20 GiB, 21474836480 bytes, 41943040 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
Disklabel type: dos
Disk identifier: 0x749a518b
Device     Boot   Start      End  Sectors  Size Id Type
/dev/sda1  *       2048  1050623  1048576  512M  b W95 FAT32
/dev/sda2       1052670 41940991 40888322 19.5G  5 Extended
/dev/sda5       1052672 41940991 40888320 19.5G 83 Linux
Disk /dev/sdb: 30 GiB, 32212254720 bytes, 62914560 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
Disklabel type: dos
Disk identifier: 0x4b24993c
Device     Boot    Start      End  Sectors Size Id Type
/dev/sdb1           2048 20973567 20971520  10G 8e Linux LVM
/dev/sdb2       20973568 41945087 20971520  10G 8e Linux LVM
Disk /dev/mapper/vg-lv: 6 GiB, 6442450944 bytes, 12582912 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk /dev/mapper/vg-lv1: 5 GiB, 5368709120 bytes, 10485760 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

Now list the logical volume

root@LinuxHelp:~# lvs
  LV   VG Attr       LSize Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  lv   vg -wi-a----- 6.00g                                                    
  lv1  vg -wi-a----- 5.00g        

Before mount the logical volume, format the partitions

root@LinuxHelp:~# mkfs.ext4 /dev/mapper/vg-lv
mke2fs 1.45.5 (07-Jan-2020)
Creating filesystem with 1572864 4k blocks and 393216 inodes
Filesystem UUID: 3607368c-4105-4b33-a526-539b9adc8b8d
Superblock backups stored on blocks: 
	32768, 98304, 163840, 229376, 294912, 819200, 884736
Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: done 
root@LinuxHelp:~# mkfs.ext4 /dev/mapper/vg-lv1
mke2fs 1.45.5 (07-Jan-2020)
Creating filesystem with 1310720 4k blocks and 327680 inodes
Filesystem UUID: ab479b62-04f6-4324-b7b2-8c3674438dd8
Superblock backups stored on blocks: 
	32768, 98304, 163840, 229376, 294912, 819200, 884736
Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: done 

Now list the logical volumes

root@LinuxHelp:~# lvs
  LV   VG Attr       LSize Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  lv   vg -wi-a----- 6.00g                                                    
  lv1  vg -wi-a----- 5.00g              

Now mount the logical volumes to the local disk by execute the following command

root@LinuxHelp:~# mount /dev/mapper/vg-lv /home/user /Downloads/

Check the disk by executing the following command

root@LinuxHelp:~# df -h
Filesystem          Size  Used Avail Use% Mounted on
udev                1.9G     0  1.9G   0% /dev
tmpfs               391M  1.6M  390M   1% /run
/dev/sda5            20G  6.9G   12G  39% /
tmpfs               2.0G     0  2.0G   0% /dev/shm
tmpfs               5.0M  4.0K  5.0M   1% /run/lock
tmpfs               2.0G     0  2.0G   0% /sys/fs/cgroup
/dev/sda1           511M  4.0K  511M   1% /boot/efi
tmpfs               391M   20K  391M   1% /run/user/1000
/dev/sr0            1.9G  1.9G     0 100% /media/netaxis/Linux Mint 20 Cinnamon 64-bit
/dev/mapper/vg-lv   5.9G   24M  5.6G   1% /home/user/Downloads
/dev/mapper/vg-lv1  4.9G   20M  4.6G   1% /home/user/Documents

With this method, to create partitions using LVM on Linux mint 20 is comes to an end.

FAQ
Q
What are the steps to the LVM?
A
1. Physical volume
2. Volume Group
3. Logical Volume
Q
How do we list out the volume group?
A
The following command is # lvs
Q
How do we list the physical volume?
A
Use the following command # pvs
Q
How to create physical volume?
A
The command is # pvcreate (name) /dev/sdb1(Physycal volume Path)
Q
What is Logical Volume Management tool?
A
LVM is the Logical Volume Management tool that comprises allocating disks, segmenting, replication, and resize the logical volumes. It is used to allocate a hard drive or set of hard drives to one or more physical volumes which can be placed on other block devices that might span two or more disks.