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.
# dd if=/dev/zero of=/var/lib/libvirt/images/FileName.img bs=1M seek=4096 count=0
# dd if=/dev/zero of=/var/lib/libvirt/images/FileName.img bs=1M count=4096
Guest1
and the file is saved in the users home directory.
# virsh dumpxmlGuest1
> ~/Guest1
.xml
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'/< >/disk<
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< >disk type='file' device='disk'< >driver name='tap' type='aio'/< >source file='/var/lib/libvirt/images/FileName.img'/< >target dev='hda'/< >/disk<
# 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):w
Command (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/hdb1
hdc
--driver tap --mode readonly
/dev/hdb
on Linux or D: drive
, or similar, on Windows. This device may require formatting.