Software & AppsOperating SystemLinux

Creating Custom Partition /boot + LVM on Ubuntu Server 20.04

Ubuntu 14

In this article, we will be discussing how to create a custom partition setup with a separate /boot partition and Logical Volume Manager (LVM) on a single disk in Ubuntu Server 20.04. This guide assumes you have basic knowledge of partitioning and LVM.

Quick Answer

To create a custom partition setup with a separate /boot partition and Logical Volume Manager (LVM) on Ubuntu Server 20.04, you will need to manually create the /boot partition during the installation process and then set up LVM after the installation is complete. This involves using commands like fdisk, pvcreate, vgcreate, lvcreate, and formatting and mounting the logical volumes. For a detailed step-by-step guide, please refer to the full article.

Introduction to LVM

LVM, or Logical Volume Manager, is a storage device management technology that gives users the power to pool and abstract the physical layout of disk drives. It’s a method of allocating space on mass-storage devices that is more flexible than conventional partitioning methods.

The Installation Process

Start the Ubuntu “live” Server 20.04 installation process. At the “Storage Configuration” step, select the “local disk” and choose “Use As Boot Device”. This will create the /boot partition.

To create the /boot partition, select “Add GPT Partition”. Set the size to 1G, format it as ext4, and mount it at /boot.

After creating the /boot partition, you will notice that the option to create a volume group (LVM) or RAID disappears. To work around this, you can proceed with the installation and create the LVM setup manually after the installation completes.

Complete the installation process, making sure to leave the root partition unformatted and unmounted.

Setting Up LVM After Installation

Once the installation is finished and you have booted into the newly installed system, open a terminal. Install the LVM tools if they are not already installed by running the following command:

sudo apt-get install lvm2

The sudo command is used to run the following command as a superuser, or root user. apt-get is the package handling utility in Ubuntu. install tells apt-get to install the following package, in this case lvm2, which is the LVM toolset.

Next, use the fdisk command to create a partition for the LVM setup. Run the following command to start the partitioning process:

sudo fdisk /dev/sda

Inside fdisk, create a new partition by selecting the available free space and choosing “New”. Set the partition size to the desired size for the LVM setup (e.g., 23G for a 30G disk). Make sure to set the partition type to Linux LVM (type code 8e).

Write the changes to the disk and exit fdisk.

Creating the Physical Volume

Now, create the physical volume for LVM by running the following command, replacing /dev/sdaX with the partition you created in the previous step:

sudo pvcreate /dev/sdaX

The pvcreate command initializes /dev/sdaX for use by LVM. It’s a prerequisite to adding an LVM partition to a volume group.

Creating the Volume Group

Next, create the volume group by running the following command, replacing vgname with the desired name for your volume group and /dev/sdaX with the partition you created:

sudo vgcreate vgname /dev/sdaX

The vgcreate command creates a new volume group named vgname and adds the initialized disk /dev/sdaX to the group.

Creating Logical Volumes

Now, create the logical volumes within the volume group. Run the following commands to create the desired logical volumes, replacing lvname with the desired names and sizes:

sudo lvcreate -L 4G -n lvname vgname
sudo lvcreate -L 2G -n lvname vgname
sudo lvcreate -L 1G -n lvname vgname
sudo lvcreate -L 1G -n lvname vgname
sudo lvcreate -L 1G -n lvname vgname

The lvcreate command creates a logical volume within a volume group. -L specifies the size of the logical volume, -n specifies the name of the logical volume, and vgname is the name of the volume group.

Formatting and Mounting Logical Volumes

Format the logical volumes as ext4 and mount them at the desired locations. Run the following commands, replacing lvname with the logical volume name and /mount/point with the desired mount point:

sudo mkfs.ext4 /dev/vgname/lvname
sudo mount /dev/vgname/lvname /mount/point

The mkfs.ext4 command creates an ext4 filesystem on the logical volume, and the mount command mounts the logical volume at the specified mount point.

Updating /etc/fstab

Finally, update the /etc/fstab file to ensure the logical volumes are mounted at boot. Add the following lines, replacing lvname and /mount/point with the appropriate values:

/dev/vgname/lvname /mount/point ext4 defaults 0 0

The /etc/fstab file is used to define how disk partitions, various other block devices, or remote filesystems should be mounted into the filesystem.

Reboot the system to verify that the LVM setup is working correctly.

Conclusion

Creating a custom partition setup with a separate /boot partition and LVM on Ubuntu Server 20.04 can be a bit complex, but it offers a lot of flexibility in terms of disk management. Remember to adapt the commands and partition names to match your specific setup. If you follow the steps in this guide, you should have a working LVM setup on your Ubuntu Server 20.04 installation.

For more information on LVM, you can visit the Ubuntu LVM Guide.

What is the purpose of creating a separate /boot partition?

Creating a separate /boot partition is useful in situations where the bootloader or kernel files need to be stored outside of the LVM setup. This can help prevent issues during system upgrades or if the LVM setup becomes corrupted.

Can I resize the logical volumes after creating them?

Yes, you can resize logical volumes using the lvresize command. However, it’s important to note that the underlying file system should also be resized accordingly to avoid data loss or corruption.

Can I create multiple volume groups on a single disk?

No, a single disk can only be part of one volume group. If you want to create multiple volume groups, you will need to use multiple disks or partitions.

Can I use LVM with RAID?

Yes, LVM can be used in combination with RAID to provide redundancy and improve data integrity. You can create a RAID array with multiple physical volumes and then use LVM to manage the logical volumes on top of the RAID array.

How can I remove a logical volume?

To remove a logical volume, you can use the lvremove command followed by the name of the logical volume. Make sure to back up any important data before removing a logical volume, as the action is irreversible and will result in data loss.

Can I use LVM on an existing installation?

Yes, you can set up LVM on an existing installation, but it requires more advanced steps and caution. It’s recommended to backup your data before attempting to convert an existing installation to use LVM.

Can I use LVM with other filesystems besides ext4?

Yes, LVM can be used with various filesystems such as ext4, XFS, and Btrfs. The choice of filesystem depends on your specific needs and preferences.

How can I extend a volume group to include additional physical volumes?

To extend a volume group, you can use the vgextend command followed by the name of the volume group and the path to the additional physical volume. This will add the new physical volume to the existing volume group, increasing the available storage capacity.

Leave a Comment

Your email address will not be published. Required fields are marked *