Software & AppsOperating SystemLinux

Expanding Ubuntu Server Disk Inside Hyper-V Using LVM

Ubuntu 12

In this article, we will walk you through the process of expanding an Ubuntu Server disk inside Hyper-V using Logical Volume Management (LVM). This process is crucial when you need to increase the storage capacity of your virtual machine.

Prerequisites

Before we start, ensure that you have:

  • A running Ubuntu Server inside Hyper-V.
  • LVM installed and configured on your Ubuntu Server.
  • Administrative access to both Hyper-V and the Ubuntu Server.

Step 1: Expanding the Virtual Disk in Hyper-V

The first step is to expand the virtual disk using the Hyper-V GUI or CLI tools.

  1. Open the settings of your virtual machine in Hyper-V.
  2. Select the hard drive under the SCSI controller.
  3. Click on “Edit” and then “Expand”.
  4. Input the new size of the disk and apply the changes.

In this example, we have added an extra 100GB to the disk.

Step 2: Rescanning the Block Device

After expanding the virtual disk in Hyper-V, we need to make the Ubuntu Server recognize the added space. This can be done by rescanning the block device. Run the following command as root:

echo 1 > /sys/block/sda/device/rescan

This command writes ‘1’ to the rescan file of the block device, which triggers a rescan of the device.

Step 3: Resizing the Partition

We will use the parted command-line tool to resize the partition. Run the following commands as root:

parted /dev/sda
resizepart 5 100%
quit

The parted command opens the partition editor for the device /dev/sda. The resizepart command resizes partition number 5 to use 100% of the available space. The quit command exits the parted tool.

Step 4: Expanding the Physical and Logical Volumes

If you are using LVM, you need to expand both the physical volume and the logical volume. Run the following commands as root:

pvresize /dev/sda5
lvextend -l +100%FREE /dev/mapper/ubuntu--vg-root

The pvresize command resizes the physical volume on /dev/sda5 to use all available space. The lvextend command extends the logical volume to use all the free space in the volume group.

Step 5: Resizing the Filesystem

Finally, we need to resize the filesystem to use the newly allocated space. Run the following command as root:

resize2fs /dev/mapper/ubuntu--vg-root

The resize2fs command resizes the ext4 filesystem on the logical volume to use all available space.

Verifying the Changes

After completing these steps, you should have successfully expanded the disk and partitions in your Ubuntu server. You can verify the changes by running df -h to check the available space on the filesystems.

Conclusion

In this article, we have covered the process of expanding an Ubuntu Server disk inside Hyper-V using LVM. Remember to always take a backup of your data before performing any disk or partition modifications. If you encounter any issues or need more detailed instructions, you can refer to the official documentation for the tools used (e.g., parted, LVM, resize2fs).

Can I expand the disk of an Ubuntu Server inside Hyper-V without using LVM?

Yes, you can expand the disk of an Ubuntu Server inside Hyper-V without using LVM. However, the process will be different and may involve resizing the partition and filesystem directly. It is recommended to use LVM for easier management and flexibility.

What is Logical Volume Management (LVM)?

Logical Volume Management (LVM) is a disk management system that allows for easy management of disk space by creating logical volumes that span across multiple physical disks. LVM provides features such as dynamic resizing, snapshots, and easy management of storage volumes.

Do I need to have administrative access to both Hyper-V and the Ubuntu Server to expand the disk using LVM?

Yes, you need administrative access to both Hyper-V and the Ubuntu Server to expand the disk using LVM. Administrative access is required to perform tasks such as expanding the virtual disk in Hyper-V, rescanning the block device, resizing the partition, and expanding the physical and logical volumes.

Is it necessary to take a backup of my data before expanding the disk using LVM?

Yes, it is highly recommended to take a backup of your data before expanding the disk using LVM or making any disk or partition modifications. While the process is generally safe, there is always a risk of data loss or corruption during disk operations. Taking a backup ensures that you can restore your data in case of any unforeseen issues.

How can I verify the changes after expanding the disk and partitions?

You can verify the changes by running the command df -h in the terminal of your Ubuntu Server. This command will display the available space on the filesystems, allowing you to check if the disk and partitions have been successfully expanded.

Leave a Comment

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