Step-by-Step Instructions for Creating and Mounting an LVM

Create an LVM-based RAID 0 using all available NVMe drives.

Steps to Create and Mount an LVM

Step 1: Update the System

Update the list of packages for your system to ensure you have access to the most current packages:

sudo apt update

Step 2: Install the LVM2 Package

Install the lvm2 package, which contains commands such as pvcreate, vgcreate, and lvcreate:

sudo apt install -y lvm2

Step 3: Verify that LVM2 has been properly installed

Assure yourself that LVM2 has been correctly installed by checking that the pvcreate command is present:

which pvcreate

Step 4: List Available Disks Identify which disks you want to use in the LVM setup. To list all your disks, you can use the following command:

lsblk

In this case, we are using the following disks:

  • /dev/nvme1n1

  • /dev/nvme2n1

  • /dev/nvme3n1

  • /dev/nvme4n1

  • /dev/nvme5n1

  • /dev/nvme6n1

Step 5: Initialize Physical Volumes (PV)

Use the pvcreate command to initialize each of the disks as a physical volume (PV). Run the following commands one by one:

sudo pvcreate /dev/nvme1n1
sudo pvcreate /dev/nvme2n1
sudo pvcreate /dev/nvme3n1
sudo pvcreate /dev/nvme4n1
sudo pvcreate /dev/nvme5n1
sudo pvcreate /dev/nvme6n1

Step 6: Create a Volume Group (VG)

From the physical volumes, we are going to create a volume group. We'll name it as nvme_vg:

sudo vgcreate nvme_vg /dev/nvme1n1 /dev/nvme2n1 /dev/nvme3n1 /dev/nvme4n1 /dev/nvme5n1 /dev/nvme6n1

Step 7: Create a Logical Volume (LV)

From the space available in the volume group, create a logical volume. The name for our LV will be nvme_lv.

sudo lvcreate -l 100%FREE -n nvme_lv nvme_vg

Step 8: Format the Logical Volume Format the new logical volume to the ext4 filesystem:

sudo mkfs.ext4 /dev/nvme_vg/nvme_lv

Step 9: Create a Mount Point Create the mount point directory (/mnt/data), in case it does not exist:

sudo mkdir -p /mnt/LVMNVME

Step 10: Mount the Logical Volume Mount the logical volume to the /mnt/data directory:

sudo mount /dev/nvme_vg/nvme_lv /mnt/LVMNVME
sudo ln -s /mnt/data /home/ubuntu/LVMNVME

Step 12: Make the Mount Persistent Get the UUID of the new logical volume for persistence across reboots:

sudo blkid -s UUID -o value /dev/nvme_vg/nvme_lv

Now, add the following line to /etc/fstab, replacing <UUID> with the actual UUID obtained from the previous command:

echo "UUID=<UUID> /mnt/LVMNVME ext4 defaults 0 0" | sudo tee -a /etc/fstab

Step 13: Verify the Mount

Verify that the mount is set up correctly and will persist after reboot:

sudo mount -a

Step 14: Validate the Directories

List the contents of both the /mnt/data and the /home/ubuntu/data directories just for validation that all is working properly:

ls /mnt/LVMNVME
ls /home/ubuntu/LVMNVME

Step 15: Reboot - Optional

To make the change survive rebooting you should reboot your system.

sudo reboot