Linux LVM
Linux Logical Volume Manager
Linux Logical Volume Manager
lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTsdd 8:48 0 20G 0 disk /mnt/AHFsdb 8:16 0 50G 0 disk /mnt/u01sdc 8:32 0 50G 0 disk /mnt/u02sda 8:0 0 50G 0 disk ├─sda2 8:2 0 19G 0 part │ ├─ol-swap 252:1 0 2G 0 lvm [SWAP]│ └─ol-root 252:0 0 17G 0 lvm /└─sda1 8:1 0 1G 0 part /bootIn the TYPE column of lsblk...
disk = Disks (sda)
part = Partition (sda2)
lvm = Logical Volume (ol-root)
Identify device...
lsblk
Our device is shown as...sdb 8:16 0 50G 0 disk .. therefore the device will be /dev/sdbCreate the Physical Volume...
pvcreate /dev/sdb
Create Volume Group...
(called myvg using just the /dev/sdb device.. note, you can span multiple devices)vgcreate myvg /dev/sdb
Create Logical Volume...
(called mylv, size 49GB in the myvg Volume Group)lvcreate -n mylv -L 49G myvg
If you try to create a 50GB Logical Volume, you will get this error...Volume group "myvg" has insufficient free space (12799 extents): 12800 required.Create Filesystem...
(in this case an ext4 filesystem. Use the LV Path from the lvdisplay command. The filesystem will be the same size as the underlying Logical Volume)mkfs.ext4 /dev/myvg/mylv
Create a mount point...
mkdir /mysql
Mount the filesystem...
mount /dev/myvg/mylv /mysql
Give the device a Label...
e2label /dev/myvg/mylv mysql
For other filesystem types use appropriate alternative commands like xfs_admin or fatlabelAdd a line to /etc/fstab if you want it to mount automatically at boot time...
LABEL=mysql /mysql ext4 defaults 0 2
You can use a device node (/dev/myvg/mylv) but using a Label is now the recommended method.Alternatively...
fdisk -l
Check with...
pvs
pvdisplay
vgs
vgdisplay myvg
lvs
lvdisplay myvg
(note we're passing the VG not the LV)lvdisplay /dev/myvg/mylv
mount | grep "^/dev" | column -t
df -h
Bibliography
Bibliography