Ubuntu 16.04 Virtual Machine / XenServer Storage Extend Issue
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).
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:
- Increase the disk size available to a VM in XenCenter.
- Increase the size of the VM partition in the VM’s partition table.
- Grow the size of the ext3 filesystem in the 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):
# fdisk /dev/xvda
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
switch off the mode (command 'c') and change display units to
sectors (command 'u').
Command (m for help): p
Disk /dev/xvda: 12.9 GB, 12884901888 bytes
255 heads, 63 sectors/track, 1566 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000928ad
Device Boot Start End Blocks Id System
/dev/xvda1 * 1 26 204800 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/xvda2 26 281 2048000 82 Linux swap / Solaris
Partition 2 does not end on cylinder boundary.
/dev/xvda3 281 1045 6134784 83 Linux
Command (m for help): d
Partition number (1-4): 3
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 3
First cylinder (281-1566, default 281): 281
Last cylinder, +cylinders or +size{K,M,G} (281-1566, default 1566): 1566
Command (m for help): p
Disk /dev/xvda: 12.9 GB, 12884901888 bytes
255 heads, 63 sectors/track, 1566 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000928ad
Device Boot Start End Blocks Id System
/dev/xvda1 * 1 26 204800 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/xvda2 26 281 2048000 82 Linux swap / Solaris
Partition 2 does not end on cylinder boundary.
/dev/xvda3 281 1566 10325071 83 Linux
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
#
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:
# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/xvda3 5.8G 829M 4.7G 15% /
tmpfs 497M 0 497M 0% /dev/shm
/dev/xvda1 194M 45M 140M 25% /boot
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:
# resize2fs /dev/xvda3
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/xvda3 is mounted on /; on-line resizing required
old desc_blocks = 1, new_desc_blocks = 1
Performing an on-line resize of /dev/xvda3 to 2581267 (4k) blocks.
The filesystem on /dev/xvda3 is now 2581267 blocks long.
# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/xvda3 9.7G 830M 8.4G 9% /
tmpfs 497M 0 497M 0% /dev/shm
/dev/xvda1 194M 45M 140M 25% /boot
#
Special Thanks to http://www.simonhiggs.com/articles/xenserver-6.2-extending-disk-on-a-linux-vm.html
Before start resize2fs you should do some additional actions... After you resized partition, do these steps:
Resize physical-volume on your resized partition:
sudo lvm pvresize /dev/xvda3
Rescan your volume-group:
sudo lvm vgscan
Activate virtual-group:
sudo lvm vgchange -ay
Show logical-volumes:
sudo lvdisplay
Store name of your root-volume. It should be like this: /dev/vm-name-vg/root
Resize logical-volume to all additional free space (don't forget to replace "/dev/vm-name-vg/root" with your real volume-name from previous command):
sudo lvm lvresize /dev/vm-name-vg/root -l +100%FREE
Then you can do
resize2fs /dev/xvda3
it should work now.