lvm walkthrough

Most of this is taken from the linux handbook

the setup

Host

host

distribution

version

disk

size

geidi

rocky linux

9.4

disk

931.5G

Physical Volume

[ddp@geidi ~]$ lsblk
NAME        MAJ:MIN RM   SIZE RO TYPE MOUNTPOINTS
sda           8:0    0  55.9G  0 disk
  sda1        8:1    0     1G  0 part /boot
  sda2        8:2    0  54.9G  0 part
    rl-root 253:0    0  33.1G  0 lvm  /
    rl-swap 253:1    0   5.6G  0 lvm  [SWAP]
    rl-home 253:2    0  16.2G  0 lvm  /home
sdb           8:16   0 465.8G  0 disk
  sdb1        8:17   0 465.8G  0 part
nvme0n1     259:0    0 931.5G  0 disk

fdisk
^^^^^

.. code-block:: bash

   [root@geidi ddp]# fdisk /dev/nvme0n1

   Welcome to fdisk (util-linux 2.37.4).
   Changes will remain in memory only, until you decide to write them.
   Be careful before using the write command.

   Device does not contain a recognized partition table.
   Created a new DOS disklabel with disk identifier 0x74c9c12b.

   Command (m for help): p

   Disk /dev/nvme0n1: 931.51 GiB, 1000204886016 bytes, 1953525168 sectors
   Disk model: CT1000P3SSD8
   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: 0x74c9c12b

   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-1953525167, default 2048):
   Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-1953525167, default 1953525167): +900G

   Created a new partition 1 of type 'Linux' and of size 900 GiB.

   Command (m for help): p
   Disk /dev/nvme0n1: 931.51 GiB, 1000204886016 bytes, 1953525168 sectors
   Disk model: CT1000P3SSD8
   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: 0x74c9c12b

   Device         Boot Start        End    Sectors  Size Id Type
   /dev/nvme0n1p1       2048 1887438847 1887436800  900G 83 Linux

   Command (m for help): t

   Selected partition 1
   Hex code or alias (type L to list all): 8E
   Changed type of partition 'Linux' to 'Linux LVM'.

   Command (m for help): p
   Disk /dev/nvme0n1: 931.51 GiB, 1000204886016 bytes, 1953525168 sectors
   Disk model: CT1000P3SSD8
   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: 0x74c9c12b

   Device         Boot Start        End    Sectors  Size Id Type
   /dev/nvme0n1p1       2048 1887438847 1887436800  900G 8e Linux LVM

   Command (m for help): w
   The partition table has been altered.
   Calling ioctl() to re-read partition table.
   Syncing disks.

   This adds `nvme0n1p1 259:1    0   900G  0 part` to the `lsblk` output.

pvcreate
^^^^^^^^

Create a Physical Volume.

.. code-block:: console

   [root@geidi ddp]# pvcreate /dev/nvme0n1p1
   [root@geidi ddp]# pvdisplay

     PV Name               /dev/sda2
     VG Name               rl
     PV Size               <54.90 GiB / not usable 4.00 MiB
     Allocatable           yes (but full)
     PE Size               4.00 MiB
     Total PE              14053
     Free PE               0
     Allocated PE          14053
     PV UUID               ij2tAT-FqGx-jF3U-ulh5-tmnL-VL4v-0RPZSR

     "/dev/nvme0n1p1" is a new physical volume of "900.00 GiB"
     --- NEW Physical volume ---
     PV Name               /dev/nvme0n1p1
     VG Name
     PV Size               900.00 GiB
     Allocatable           NO
     PE Size               0
     Total PE              0
     Free PE               0
     Allocated PE          0
     PV UUID               ralfG7-8lMd-noQY-MDZM-ORD3-uWcP-oJBWN7

   [root@geidi ddp]# pvscan

     PV /dev/nvme0n1p1           lvm2 [900.00 GiB]
     Total: 2 [954.89 GiB] / in use: 1 [54.89 GiB] / in no VG: 1 [900.00 GiB]
   [root@geidi ddp]# pvs

     /dev/nvme0n1p1    lvm2 ---  900.00g 900.00g
     /dev/sda2      rl lvm2 a--   54.89g      0

Volume Groups

Use vgcreate to create a Virtual Group

[root@geidi ddp]# vgcreate iscsi_stuff /dev/nvme0n1p1

[root@geidi ddp]# vgs

  iscsi_stuff   1   0   0 wz--n- <900.00g <900.00g
  rl            1   3   0 wz--n-   54.89g       0
[root@geidi ddp]# pvs

  /dev/nvme0n1p1 iscsi_stuff lvm2 a--  <900.00g <900.00g
  /dev/sda2      rl          lvm2 a--    54.89g       0
[root@geidi ddp]# vgdisplay

  VG Name               rl
  System ID
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  4
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                3
  Open LV               3
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               54.89 GiB
  PE Size               4.00 MiB
  Total PE              14053
  Alloc PE / Size       14053 / 54.89 GiB
  Free  PE / Size       0 / 0
  VG UUID               5C2Xt5-PtII-zwTG-oOpr-5oWv-YefG-R4Qwb8

  --- Volume group ---
  VG Name               iscsi_stuff
  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               <900.00 GiB
  PE Size               4.00 MiB
  Total PE              230399
  Alloc PE / Size       0 / 0
  Free  PE / Size       230399 / <900.00 GiB
  VG UUID               zkknRU-lyNr-Nv3W-nWEn-fRjm-yBow-bVF88g

[root@geidi ddp]# pvdisplay -S vgname=iscsi_stuff -C -p pv_name

  Error during parsing of command line.
[root@geidi ddp]# pvdisplay -S vgname=iscsi_stuff -C -o pv_name

  /dev/nvme0n1p1

Logical Volumes

Logical Volumes

[root@geidi ddp]# lvcreate -L 10G -n test_lv iscsi_stuff

[root@geidi ddp]# lvs

  test_lv iscsi_stuff -wi-a-----  10.00g
  home    rl          -wi-ao----  16.17g
  root    rl          -wi-ao---- <33.13g
  swap    rl          -wi-ao----   5.59g
[root@geidi ddp]# lvdisplay

  LV Path                /dev/rl/swap
  LV Name                swap
  VG Name                rl
  LV UUID                0BTcSh-13vI-y0Xh-xfpy-mStv-d5St-MpaYb5
  LV Write Access        read/write
  LV Creation host, time localhost.localdomain, 2025-02-05 18:49:01 -0500
  LV Status              available
  # open                 2
  LV Size                5.59 GiB
  Current LE             1432
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:1

  --- Logical volume ---
  LV Path                /dev/rl/home
  LV Name                home
  VG Name                rl
  LV UUID                9I2jGK-CweU-AS6u-1ADT-cRCy-qaWc-8Wb5D4
  LV Write Access        read/write
  LV Creation host, time localhost.localdomain, 2025-02-05 18:49:01 -0500
  LV Status              available
  # open                 1
  LV Size                16.17 GiB
  Current LE             4140
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:2

  --- Logical volume ---
  LV Path                /dev/rl/root
  LV Name                root
  VG Name                rl
  LV UUID                sbhI2C-bABg-7LBS-0wGi-e94H-XGQQ-t8XHzH
  LV Write Access        read/write
  LV Creation host, time localhost.localdomain, 2025-02-05 18:49:01 -0500
  LV Status              available
  # open                 1
  LV Size                <33.13 GiB
  Current LE             8481
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0

  --- Logical volume ---
  LV Path                /dev/iscsi_stuff/test_lv
  LV Name                test_lv
  VG Name                iscsi_stuff
  LV UUID                dcEF7Q-7r1D-X4gy-wJMb-8Qze-DHHO-ijBqAq
  LV Write Access        read/write
  LV Creation host, time geidi, 2025-03-26 16:02:41 -0400
  LV Status              available
  # open                 0
  LV Size                10.00 GiB
  Current LE             2560
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:3

[root@geidi ddp]# lvcreate -L 100G -n elasticsearch0 iscsi_stuff

[root@geidi ddp]# lvcreate -L 100G -n elasticsearch1 iscsi_stuff

[root@geidi ddp]# lvcreate -L 100G -n elasticsearch2 iscsi_stuff

[root@geidi ddp]# mkfs.ext4 /dev/iscsi_stuff/
elasticsearch0  elasticsearch1  elasticsearch2  test_lv
[root@geidi ddp]# mkfs.ext4 /dev/iscsi_stuff/test_lv
Discarding device blocks: done
Creating filesystem with 2621440 4k blocks and 655360 inodes
Filesystem UUID: db2bdc13-c636-42b7-8bd8-792b60e309a5
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632

Allocating group tables: done
Writing inode tables: done
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: done

[root@geidi ddp]# mount -t ext4 /dev/iscsi_stuff/test_lv /mnt
[root@geidi ddp]# df -h /mnt

/dev/mapper/iscsi_stuff-test_lv  9.8G   24K  9.3G   1% /mnt
[root@geidi ddp]# umount /mnt