Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Mail Systems
Eclipse Documentation

How To Guides
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Problem Solutions
Privacy Policy




Red Hat Enterprise Linux 9 Essentials Book now available.

Purchase a copy of Red Hat Enterprise Linux 9 (RHEL 9) Essentials

Red Hat Enterprise Linux 9 Essentials Print and eBook (PDF) editions contain 34 chapters and 298 pages

Preview Book

7.2. Adding storage devices to guests

This section covers adding storage devices to to virtual guest machine. Additional storage can only be added after guests are created. The supported storage devices and protocol include:
  • local hard drive partitions,
  • logical volumes,
  • Fibre Channel or iSCSI directly connected to the host.
  • File containers residing in a file system on the host.
  • NFS file systems mounted directly by the virtual machine.
  • iSCSI storage directly accessed by the guest.
  • Cluster File Systems ( GFS ).
Adding file based storage to a guest
File-based storage or file-based containers are files on the hosts file system which act as virtualized hard drives for virtualized guests. To add a file-based container perform the following steps:
  1. Create an empty container file or using an existing file container (such as an ISO file).
    1. Create a sparse file using the dd command. Sparse files are not recommended due to data integrity and performance issues. Sparse files are created much faster and can used for testing but should not be used in production environments.
      $ sudo dd if=/dev/zero of=/xen/images/FileName.img bs=1M seek=4096 count=0
    2. Non-sparse, pre-allocated files are recommended for file based storage containers. Create a non-sparse file, execute:
      $ sudo dd if=/dev/zero of=/xen/images/FileName.img bs=1M count=4096
    Both commands create a 400MB file which can be used as additional storage for a virtualized guest.
  2. Dump the configuration for the guest. In this example the guest is called Guest1 and the file is saved in the users home directory.
    $ sudo virsh dumpxml 
     > ~/
  3. Open the configuration file ( Guest1.xml in this example) in a text editor. Find the entries starting with "disk=". This entry resembles:
    >disk type='file' device='disk'<
            >driver name='tap' type='aio'/<
            >source file='/var/lib/libvirt/images/Guest1.img'/<
            >target dev='xvda'/<
  4. Add the additional storage by modifying the end of disk= entry. Ensure you specify a device name for the virtual block device which is not used already in the configuration file. The following example entry adds file, named FileName.img, as a file based storage container:
    >disk type='file' device='disk'<
            >driver name='tap' type='aio'/<
            >source file='/var/lib/libvirt/images/Guest1.img'/<
            >target dev='xvda'/<
    >disk type='file' device='disk'<
            >driver name='tap' type='aio'/<
            >source file='/xen/images/FileName.img'/<
            >target dev='hda'/<
  5. Restart the guest from the updated configuration file.
    $ sudo virsh create Guest1.xml
  6. The following steps are Linux guest specific. Other operating systems handle new storage devices in different ways. For non Linux systems refer to your guest operating systems documentation.
    The guest now uses the file FileName.img as the device called /dev/hdb. This device requires formatting from the guest. On the guest, partition the device into one primary partition for the entire device then format the device.
    1. Press n for a new partition.
      # fdisk /dev/hdb
      Command (m for help):
    2. Press p for a primary partition.
      Command action
         e   extended
         p   primary partition (1-4)
    3. Choose an available partition number. In this example the first partition is chosen by entering 1 .
      Partition number (1-4): 
    4. Enter the default first cylinder by pressing Enter .
      First cylinder (1-400, default 1):
    5. Select the size of the partition. In this example the entire disk is allocated by pressing Enter .
      Last cylinder or +size or +sizeM or +sizeK (2-400, default 400):
    6. Set the type of partition by pressing t .
      Command (m for help): 
    7. Choose the partition you created in the previous steps. In this example it's partition 1 .
      Partition number (1-4): 
    8. Enter 83 for a linux partition.
      Hex code (type L to list codes): 
    9. write changes to disk and quit.
      Command (m for help): 
      Command (m for help): 
    10. Format the new partition with the ext3 file system.
      # mke2fs -j /dev/hdb
  7. Mount the disk on the guest.
    # mount /dev/hdb1 
The guest now has an additional virtualized file-based storage device.
Adding hard drives and other block devices to a guest
System administrators use additional hard drives for to provide more storage space or to separate system data from user data. This procedure, Adding physical block devices to virtualized guests, describes how to add a hard drive on the host to a virtualized guest.
The procedure works for all physical block devices, this includes CD-ROM, DVD and floppy devices.
Procedure 7.1. Adding physical block devices to virtualized guests
  1. Physically attach the hard disk device to the host. Configure the host if the drive is not accessible by default.
  2. Configure the device with multipath and persistence on the host if required.
  3. Use the virsh attach command. Replace: myguest with your guest's name, /dev/hdb1 with the device to add, and hdc with the location for the device on the guest. The hdc must be an unused device name. Use the hd* notation for Windows guests as well, the guest will recognize the device correctly.
    Append the --type hdd parameter to the command for CD-ROM or DVD devices.
    Append the --type floppy parameter to the command for floppy devices.
    # virsh attach-disk 
     --driver tap --mode readonly
  4. The guest now has a new hard disk device called /dev/hdb on Linux or D: drive, or similar, on Windows. This device may require formatting.

  Published under the terms of the GNU General Public License Design by Interspire