Firstly, I should say that I am newbie at server management and virtualization area. After checking several tutorials about it, I tried to extend storage of virtual machine which is created in XenServer with taken snapshot from another VM. First, I shutdowned VM and extended storage from 40 GB to 80 GB via XenCenter. Then I started VM and enter fdisk with:
sudo fdisk /dev/xvda
Then I printed partition table:
Device Boot Start End Sectors Size Id Type
/dev/xvda1 2048 999423 997376 487M 83 Linux
/dev/xvda2 1001470 83884031 82882562 39.5G 5 Extended
/dev/xvda5 1001472 83884031 82882560 39.5G 8e Linux LVM
I didn't see similar partition table on any tutorial. That's why I tried to create new partition table similar to this table. First I delete 5 and 2, then I created a new extended partition (2) and I created a Linux type partition (5). Lastly, I changed type of 5 to Linux LVM. Final partition table is like below:
Device Boot Start End Sectors Size Id Type
/dev/xvda1 2048 999423 997376 487M 83 Linux
/dev/xvda2 999424 167772159 166772736 79.5G 5 Extended
/dev/xvda5 1001472 167772159 166770688 79.5G 8e Linux LVM
After checking table, I wrote table to disk and rebooted the VM. VM is started without any problem. I checked disk space with sudo df -h
, here is the output:
Filesystem Size Used Avail Use% Mounted on
udev 12G 0 12G 0% /dev
tmpfs 2.4G 8.7M 2.4G 1% /run
/dev/mapper/dbvmviduio--vg-root 35G 1.7G 32G 6% /
tmpfs 12G 0 12G 0% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 12G 0 12G 0% /sys/fs/cgroup
/dev/xvda1 472M 101M 347M 23% /boot
tmpfs 100K 0 100K 0% /run/lxcfs/controllers
tmpfs 2.4G 0 2.4G 0% /run/user/1000
After all, I tried to run resize2fs
like written in tutorials. First I didn't know run resize2fs on xvda2 or xvda5, I tried both of them and I got these errors.
sudo resize2fs /dev/xvda2
resize2fs 1.42.13 (17-May-2015)
resize2fs: Attempt to read block from filesystem resulted in short read while trying to open /dev/xvda2
Couldn't find valid filesystem superblock.
sudo resize2fs /dev/xvda5
resize2fs 1.42.13 (17-May-2015)
resize2fs: Device or resource busy while trying to open /dev/xvda5
Couldn't find valid filesystem superblock.
Is there any problem with partition table? How can I get over these issues?
Note: When I couldn't get over these issues, I tried to create just a Linux type partition (without extended), VM isn't started after reboot. (I reverted to snapshot after this).
Best Answer
I am not sure exactly what steps you followed, But below three things need to happen to increase the disk available to a Linux VM:
Below are the steps involved in a given example.
Step 1: Increase Disk Space in XenCenter
You have done it already.
Step 2: Change the Partition Table in the VM
Next, start up the VM, as you'll need to increase the size of the linux / partition using fdisk. The utility parted should allow you to resize partitions as well and be much smarter about it and let you move filesystem data around as well, but parted does not allow you to edit running partitions. In this case since we want to edit for eg: /dev/xvda3 which is our / partition and it is at the end of the virtual disk so i only need to extend the size of the partition and not move it around. On the running VM use fdisk to increase the / partition (/dev/xvda3):
Step 3: Reboot the VM
Now that last warning is accurate, you need to reboot the VM again in order for the kernel to pickup the changes to the partition geometry. However, rebooting does not change the available disk space size of the / partition:
You can fix this by running resize2fs in the running VM which will automatically notice the difference between the partition geometry and the size of the filesystem and will extend the filesystem to its maximum size:
Special Thanks to http://www.simonhiggs.com/articles/xenserver-6.2-extending-disk-on-a-linux-vm.html