Extend the size of LV backed virtual drive in domU

From MyWiki

Jump to: navigation, search

Recently I needed to expand the size of /data partition on a running domU without downtime. The partition occupies the whole drive and pretty easy to un-mount and mess around with.

Note: the domU name here is vm1 and the name of the virtual drive is vm1-data. I use LV-based virtual drives for all the domU's, so the notation I use on the dom0 level is domU_name-partition_name_inside_domU.

Here is what I did:

  • inside the domU after I stooped all processes using it I could un-mount /data safely
[root@vm1 ~]# umount /data 
  • On dom0 level list the existing virtual drives of the domU in question, so I can see devID of the drive:
[root@dom0 ~]# xm block-list vm1
Vdev  BE handle state evt-ch ring-ref BE-path
51712    0    0     4      9      8     /local/domain/0/backend/vbd/8/51712   
51728    0    0     4      10     364   /local/domain/0/backend/vbd/8/51728  

The last line of the above output (51728) is the xvdb disk. This was easy to figure out as there is only two drives and the system one has the lowest number. Would be a bit tricky, if I had 2+ drives. Xen numbers them in the order of appearance in domU's configuration file (disk directive). But if you did play around attaching and detaching drives, there is no guarantee that the ID stay the same (at least I haven't found any doc that says it would).

  • Detaching the virtual drive we want to extand:
[root@dom0 ~]# xm block-detach vm1 51728
  • On dom0 level extend it. It doesn't hurt to run checks after you do lvextend and just before you resize the filesystem:
[root@dom0 ~]# lvextend -L +5G /dev/rootvg_dom0/vm1-data
[root@dom0 ~]# e2fsck -f /dev/rootvg_dom0/vm1-data
[root@dom0 ~]# resize2fs /dev/rootvg_dom0/vm1-data
  • Now we are good attach the drive back:
[root@dom0 ~]# xm block-attach vm1 phy:/dev/rootvg_dom0/vm1-data /dev/xvdb w
  • Go back inside the domU
[root@dom0 ~]# xm console back into domU

and mount /data

[root@vm1 ~]# mount /data

If you do it in the right sequence (umount, then detach), then it's OK. I reckon xen may allow you to detach it w/o checking if it's mounted or not and then you are in trouble.

Personal tools