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
$ sudo dd if=/dev/zero of=/xen/images/FileName.img bs=1M count=4096
Guest1 and the file is saved in the users home directory.
$ sudo virsh xmldumpGuest1> ~/Guest1.xml
Guest1.xml in this example) in a text editor. Find the entries starting with "disk=". This entry resembles:
disk = [ 'tap:aio:/var/lib/xen/images/Guest1.dsk,xvda,w' ] TODO
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 = [ 'tap:aio:/var/lib/xen/images/Guest1.dsk,xvda,w', 'tap:aio:/xen/images/FileName.img,hdb,w', ] TODO
$ sudo virsh create Guest1.xml
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.
n for a new partition.
# fdisk /dev/hdb Command (m for help):
p for a primary partition.
Command action e extended p primary partition (1-4)
1.
Partition number (1-4): 1
Enter.
First cylinder (1-400, default 1):
Enter.
Last cylinder or +size or +sizeM or +sizeK (2-400, default 400):
t.
Command (m for help): t
1.
Partition number (1-4): 1
83 for a linux partition.
Hex code (type L to list codes): 83
Command (m for help):wCommand (m for help):q
ext3 file system.
# mke2fs -j /dev/hdb
# mount /dev/hdb1 /myfiles
multipath and persistence on the host if required.
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.
--type hdd parameter to the command for CD-ROM or DVD devices.
--type floppy parameter to the command for floppy devices.
# virsh attach-diskmyguest/dev/hdb1hdc--driver tap --mode readonly
/dev/hdb on Linux or D: drive, or similar, on Windows. This device may require formatting.