Published on

Configure a new SSD disk on Ubuntu 24.04 and use it with LVM

Authors
  • avatar
    Name
    Marcio Moreira Junior

Are you looking to enhance your Ubuntu system's performance by configuring a new SSD? Managing storage with SSDs can significantly improve read and write speeds. In this guide, we delve into setting up a new SSD on Ubuntu 24.04 with LVM, providing flexibility in managing your disk space effectively. Let's get started!


Prerequisites

Before we proceed, ensure you have:

  • A new SSD installed on your system.
  • Ubuntu 24.04 operating system.
  • Basic familiarity with the terminal and administrative rights.

Step 1: Identify the New SSD

First, you need to identify the new SSD. Open your terminal and run:

lsblk

This command lists all block devices attached to your system. Look for your new SSD, which should appear as something like /dev/sdb or /dev/nvme0n1.

Expected Output

NAME       MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda          8:0    0 476.9G  0 disk /
sdb          8:16   0 931.5G  0 disk
nvme0n1     259:0    0  1.0T  0 disk

Step 2: Prepare the SSD for LVM

Next, we need to create a physical volume on the new SSD. You can do this with the command:

sudo pvcreate /dev/sdb

Replace /dev/sdb with the correct identifier for your SSD.

Expected Output

Physical volume "dev/sdb" successfully created.

Step 3: Create a Volume Group

Once the physical volume is ready, you can create a volume group (VG). Let’s name it vg_ssd:

sudo vgcreate vg_ssd /dev/sdb

This command groups your SSD under the specified VG name, allowing for efficient allocation of logical volumes (LVs).

Expected Output

Volume group "vg_ssd" successfully created

Step 4: Create Logical Volumes

Now, let’s create a logical volume. You can specify the size while creating LVs. For example, to create a logical volume of 100GB:

sudo lvcreate -L 100G -n lv_data vg_ssd

This command creates a logical volume named lv_data within the vg_ssd volume group.

Expected Output

Logical volume "lv_data" created.

Step 5: Format the Logical Volume

You need to format your newly created logical volume before use:

sudo mkfs.ext4 /dev/vg_ssd/lv_data

This command formats the logical volume with the EXT4 filesystem, which is commonly used in Linux systems.

Expected Output

Creating filesystem with 26214400 4k blocks and 6553600 inodes

Step 6: Mounting the Logical Volume

To use the logical volume, you’ll need to mount it. First, create a mount point:

sudo mkdir /mnt/my_ssd

Then mount the volume:

sudo mount /dev/vg_ssd/lv_data /mnt/my_ssd

You can check if the volume is mounted successfully by:

df -h

Expected Output

Filesystem               Size  Used Avail Use% Mounted on
/dev/vg_ssd/lv_data      100G   0   100G   0% /mnt/my_ssd

Step 7: Making the Mount Permanent

To ensure that your logical volume mounts automatically at boot, add it to /etc/fstab. Open this file with a text editor:

sudo nano /etc/fstab

Add the following line at the end:

/dev/vg_ssd/lv_data /mnt/my_ssd ext4 defaults 0 2

Save and exit the file.

Troubleshooting Common Issues

  • SSD Not Recognized: Ensure that the SSD is properly connected and check BIOS/UEFI settings.
  • Insufficient Permissions: Run commands with sudo if you encounter permission errors.

Conclusion

In this guide, you've learned how to set up a new SSD on Ubuntu 24.04 using LVM. Managing your disk space effectively allows for improved flexibility and efficiency in handling your data. By following these steps, you're now equipped to leverage the full potential of your new SSD in a logical volume management setup.