How to add a secondary hard disk to Xen DomU

Last updated on September 27, 2020 by Dan Nanni

There are cases where you would like to add an additional disk to a Xen guest VM (i.e., domU), and make the newly added storage available to the VM. For example, as you install additional packages on the VM, they outgrow available disk space in the VM. If you would like to add a secondary hard disk to a guest VM, you can do the following.

On dom0, create a disk image for the secondary hard disk. In this example, I'll create a 10GB disk.

$ sudo dd if=/dev/zero of=/vm/dfs2-disk2.img bs=1024k count=10240

Then edit a Xen configuration file for the domU guest VM to include the hard disk.

$ vi DomU-config-file
disk = ['file:/vm/dfs1.img,xvda,w','file:/vm/dfs1-disk2.img,xvdb,w']

Next, power on and boot into the guest VM. The VM should see a new block device /dev/xvdb.

Finally, you need to make the newly attached hard disk available to the guest VM by formatting and mounting it at a local mount point (e.g., /mnt).

$ sudo mkfs.ext3 /dev/xvdb
$ sudo mkdir /mnt
$ sudo vi /etc/fstab
/dev/xvdb /mnt ext3 defaults 0 0
$ sudo mount -a 

At this point, the secondary disk will automatically be mounted every time you boot the VM.

Support Xmodulo

This website is made possible by minimal ads and your gracious donation via PayPal or credit card

Please note that this article is published by Xmodulo.com under a Creative Commons Attribution-ShareAlike 3.0 Unported License. If you would like to use the whole or any part of this article, you need to cite this web page at Xmodulo.com as the original source.

Xmodulo © 2021 ‒ AboutWrite for UsFeed ‒ Powered by DigitalOcean