7.2. Adding additional storage devices to a guest

7.2. Adding additional storage devices to a guest

After your guests are installed and configured you can add additional storage to your virtualization machines. You can use multiple different types of storage in your guests, these include:

Adding a file based container as additional storage to a guest

To add a file based container to a guest you must perform the following steps:

  1. Create an empty container file or using an existing file container (such as an ISO file).

    • to create a sparse file use the following command (note that using sparse files is not recommended due to data integrity and performance issues, they may be used for testing but not in a production environment)

      dd if=/dev/zero of=FileName.img bs=1M seek=4096 count=0
      
    • or if you want to create a non-sparse file (recommended) just use the command

      dd if=/dev/zero of=FileName.img bs=1M count=4096
      

      The command above will create a 400MB file

  2. Once you have created or identified the file you want to assign to your virtual machine you can add it to the virtual machine's configuration file.

  3. Edit the virtual machine's configuration in /etc/xen/VirtualMachineName and look for an entry starting with disk=. A sample entry will look like the following:

    disk = [ 'tap:aio:/var/lib/xen/images/rhel5vm01.dsk,xvda,w', ]
    
  4. To add the additional storage, add a new file based container entry in the disk= section of the configuration file. Ensure you have specified a device name for the virtual block device (xvd) which has not yet been used by other storage devices. The following is an example configuration entry adding a file called oracle.dsk:

    disk = [ 'tap:aio:/var/lib/xen/images/rhel5vm01.dsk,xvda,w',\
    'tap:aio:/xen/images/oracle.dsk,xvdb,w', ]
    
  5. Using the above entry your virtual machine will see file oracle.dsk as the device /dev/xvdb inside the guest.

Adding a block device as additional storage to a guest

To present a block device from your host to a guest you must perform the following steps:

  1. Make the block device available to the host and configure for your guests needs (that is, the name, persistence, multipath and so on).

  2. Edit the virtual machine's configuration in /etc/xen/VirtualMachineName and look for an entry starting with disk=. A sample entry will look like the following:

    disk = [ 'tap:aio:/var/lib/xen/images/rhel5vm01.dsk,xvda,w', ]
    
  3. To add the additional storage, add a new file based container entry in the disk= section of the configuration file. Ensure you specify the type phy and use a virtual block device name for the new virtual block device (xvd) which has not yet been used by other storage devices. The following is an example configuration entry which adds a file called /dev/sdb1:

    disk = [ 'tap:aio:/var/lib/xen/images/rhel5vm01.dsk,xvda,w',\
    'phy:/dev/sdb1,xvdb,w', ]
    
  4. Using the above entry your virtual machine will see the file oracle.dsk as the device /dev/xvdb inside the guest

The same procedure can be used to allow a guest machine access to other physical block devices, for example a CD-ROM or DVD drive.

Dynamically adding storage to a virtual machine

In some cases one may want to add additional storage to a virtual machine without the need to reboot it. Red Hat Enterprise Linux 5/Virt provides this capability using the command line toolset xm. In order to dynamically add storage to a virtual machine/domain you need to perform the following steps:

  1. Identify the block device or image file you want to make available to the virtual machine (for our example we use /dev/sdb1)

  2. After you have selected the storage you want to present to the guest you can use the xm block-attach command to assign it to your virtual machine. The syntax for xm block-attach is:

    • xm block-attach domain backdev frontdev mode

    • an example would look like the following:

      xm block-attach MyVirtualMachine phy:/dev/sdb1 xvdb w
      

      The above command will attach /dev/sdb1 to the virtual machine MyVirtualMachine and the device would be seen as /dev/xvdb inside the virtual machine.


Note: This documentation is provided {and copyrighted} by Red Hat®, Inc. and is released via the Open Publication License. The copyright holder has added the further requirement that Distribution of substantively modified versions of this document is prohibited without the explicit permission of the copyright holder. The CentOS project redistributes these original works (in their unmodified form) as a reference for CentOS-5 because CentOS-5 is built from publicly available, open source SRPMS. The documentation is unmodified to be compliant with upstream distribution policy. Neither CentOS-5 nor the CentOS Project are in any way affiliated with or sponsored by Red Hat®, Inc.