Reputation: 3954
I want to mount a existing image (file.vhd
) to a running guest:
<!-- attach.xml -->
<disk type='file' device='disk'>
<driver name='qemu' type='vpc' cache='none' io='native' dataplane='on' />
<source file='/path/to/file.vhd'/>
<target dev='vdf'/>
</disk>
then
# virsh attach-device guest1 attach.xml
here, I want to mount file.vhd
to guest1
and under /dev/vdf
, but when there is only two device existed on guest1
, file.vhd
will mount to /dev/vdc
(/dev/vda
and /dev/vbd
has been occupied by existing 2 disk), so I can't know where file.vhd
will be mounted without login into guest1
for checking.
How to make it possible to know the mount point before I mount file.vhd
?
By the way, at the same time, there may be other client attach some.vhd
to guest1
, so just check the next mount point on guest1
remotely may not work.
I know the lsblk
can list device's UUID like this:
# lsblk -nio NAME,UUID
I don't know if the UUID is existed within the file.vhd
before I attached to guest1
or only generated by guest1
. If the UUID is existed within file.vhd
, how to get it?
I have tried mount the same file.vhd
file to guest1
multiple times (with different /dev/vd*
), it seems that the UUID of them are the same, so I think the UUID may existed within file.vhd
, but I still not sure definitely.
Upvotes: 1
Views: 7888
Reputation: 2816
libguestfs provides a set of tools for manipulating / inspecting disk images. This is capable of reporting the label & UUID associated with any filesystems inside a guest disk image. e.g. http://libguestfs.org/virt-filesystems.1.html
$ virt-filesystems -a win.img --all --long --uuid -h
Name Type VFS Label Size Parent UUID
/dev/sda1 filesystem ntfs System Reserved 100M - F81C92571C92112C
/dev/sda2 filesystem ntfs - 20G - F2E8996AE8992E3B
/dev/sda1 partition - - 100M /dev/sda -
/dev/sda2 partition - - 20G /dev/sda -
/dev/sda device - - 20G - -
A possibly simpler alternative to this though (particularly if you just have a single partition in the disk), is to specify a unique serial string in the disk XML e.g.
<disk type='file' device='disk'>
<driver name='qemu' type='vpc' cache='none' io='native' dataplane='on' />
<source file='/path/to/file.vhd'/>
<serial>XXXXXXXXXX</serial>
<target dev='vdf'/>
</disk>
The text in the serial field gets included in the /dev/disk/by-path symlinks, allowing you to have a predictable device name to mount it with.
Upvotes: 3