How to add an additional hard drive to Xen VM

There are cases where you would like to add an additional disk to a Xen guest VM, and make the newly added storage available to the VM. In order to add an additional hard drive to Xen VM, do the following.

On Dom0, create an image file for a new hard drive, and edit the Xen DomU config file for the VM to include the drive. In this example, I'll create a 10GB disk.

$ sudo dd if=/dev/zero of=/vm/myvm-disk2.img bs=1M count=10240
$ sudo vi /etc/xen/myvm.cfg
disk = ['file:/vm/myvm-disk1.img,xvda,w','file:/vm/myvm-disk2.img,xvdb,w'] 

Now start the Xen VM. The Xen VM should now see a new block device /dev/xvdb.

On Xen VM, configure the newly added disk as follows.

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

Subscribe to Xmodulo

Do you want to receive Linux FAQs, detailed tutorials and tips published at Xmodulo? Enter your email address below, and we will deliver our Linux posts straight to your email box, for free. Delivery powered by Google Feedburner.


Support Xmodulo

Did you find this tutorial helpful? Then please be generous and support Xmodulo!

The following two tabs change content below.
Dan Nanni is the founder and also a regular contributor of Xmodulo.com. He is a Linux/FOSS enthusiast who loves to get his hands dirty with his Linux box. He likes to procrastinate when he is supposed to be busy and productive. When he is otherwise free, he likes to watch movies and shop for the coolest gadgets.

Leave a comment

Your email address will not be published. Required fields are marked *