This guide will explain how to increase the size of a disk in Xen. I used XenServer 7.2, XenCenter 7.2 and an old CentOS 6 VM.
-
If you wish to use the XenCenter GUI:
- shutdown vm
- increase hard disk from within XenCenter
- boot
-
If you wish to use the XenServer command line:
- Find the disk with
xe vm-disk-list vm="myVM"
- You can try to resize with the VM online:
xe vdi-resize uuid=<UUID HERE> disk-size=50GiB online=true
- If this does not work, your guest OS does not support online resizing. Shut down the VM and try again, without the online=true parameter.
- Find the disk with
-
Make sure to have a few free bytes (e.g. remove some logs)
-
sudo bash
-
Check that the disk is larger than the volumes with fdisk. Here
/dev/xvda
shows 53.7 GB, while/dev/mapper/vg_root-lv_root
shows 11.3 GBfdisk -l
Disk /dev/xvda: 53.7 GB, 53687091200 bytes
255 heads, 63 sectors/track, 6527 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: 0x0009e177
Device Boot Start End Blocks Id System
/dev/xvda1 * 1 64 512000 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/xvda2 64 1567 12069888 8e Linux LVM
Disk /dev/mapper/vg_root-lv_swap: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 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: 0x00000000
Disk /dev/mapper/vg_root-lv_root: 11.3 GB, 11274289152 bytes
255 heads, 63 sectors/track, 1370 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: 0x00000000
-
Now the dangerous part: we resize the partition of the disk.
-
Note: press
[enter]
after every single letter command.fdisk /dev/xvda
- If it shows the DOS-compatible mode warning:
c
u
- Then change the partition table:
p
- If it shows the DOS-compatible mode warning:
Disk /dev/xvda: 53.7 GB, 53687091200 bytes
255 heads, 63 sectors/track, 6527 cylinders, total 104857600 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0009e177
Device Boot Start End Blocks Id System
/dev/xvda1 * 2048 1026047 512000 83 Linux
/dev/xvda2 1026048 25165823 12069888 8e Linux LVM
- First delete partition 2 on xvda.
d
Partition number (1-4):
- Select partition, 2 in our case.
2
- Now create a new partition which starts at the same cylinder, but extends to the whole new drive. You can normally use the default values.
n
p
2
First sector (1026048-104857599, default 1026048):
- Use default
[enter]
Using default value 1026048
Last sector, +sectors or +size{K,M,G} (1026048-104857599, default 104857599):
- Use default
[enter]
Using default value 104857599
Command (m for help):
- Then set the type to Linux LVM again.
t
Partition number (1-4):
- Select partition, 2 in our case.
2
Hex code (type L to list codes):
- Set type to Linux LVM
8e
Changed system type of partition 2 to 8e (Linux LVM)
- Check the new partition:
p
Disk /dev/xvda: 53.7 GB, 53687091200 bytes
255 heads, 63 sectors/track, 6527 cylinders, total 104857600 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0009e177
Device Boot Start End Blocks Id System
/dev/xvda1 * 2048 1026047 512000 83 Linux
/dev/xvda2 1026048 104857599 51915776 8e Linux LVM
- If everything is correct, write changes to disk.
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.
-
reboot and again make sure there are some bytes available
-
Now we can use the lvm tools to resize the logical volume.
lvm pvresize /dev/xvda2
Physical volume "/dev/xvda2" changed
1 physical volume(s) resized / 0 physical volume(s) not resized
-
Now we use lvextend to resize the disk,
-r
automatically runs resize2fs doing an online resize.-l +100%FREE
extends the disk to the new fulle size.lvm lvextend -r -l +100%FREE /dev/mapper/vg_root-lv_root
Size of logical volume vg_root/lv_root unchanged from 48.50 GiB (1552 extents).
Logical volume lv_root successfully resized
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/mapper/vg_root-lv_root is mounted on /; on-line resizing required
old desc_blocks = 1, new_desc_blocks = 4
Performing an on-line resize of /dev/mapper/vg_root-lv_root to 12713984 (4k) blocks.
The filesystem on /dev/mapper/vg_root-lv_root is now 12713984 blocks long.
- Check the size of the local disk:
df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_root-lv_root
48G 11G 36G 23% /
tmpfs 936M 0 936M 0% /dev/shm
/dev/xvda1 477M 51M 401M 12% /boot
Profit.