Montare Immagini Disco Virtuali in Fedora

Easiest method using libguestfs-tools

Install libguestfs-tools:

$ sudo dnf install libguestfs-tools

Being that we now have libguestfs-tools, we have the virt-* suite at our disposal. Let’s take a look at what partitions are available to mount on a test qcow2 image.

$ sudo -i
# cd /var/lib/libvirt/images
# virt-filesystems -a fedora25.qcow2
/dev/sda1
btrfsvol:/dev/sda3/root
btrfsvol:/dev/sda3/home
/dev/sda3

We can see here that our mountable options are sda1 and sda3 - and we’re probably after sda3 since that contains our important data. Let’s mount it with guestmount:

# guestmount -r -a fedora25.qcow2 -m /dev/sda3 /mnt/point
# ls -l /mnt/point
total 0
drwxr-xr-x. 1 root root 12 Jun 3 18:12 home
dr-xr-xr-x. 1 root root 132 Jun 3 19:38 root

Where -r is to mount the image read-only, -m is the internal partition you want to mount, and /mnt/point is a directory on the host filesystem that you want to mount the internal partition to.

Here we see home and root directories that contain the btrfs home and root subvolumes. That’s because we mounted /dev/sda3 directly and the default subvolume to mount on a btrfs filesystem is subvol=/ aka subvolid=5. If that’s not relevant or doesn’t make sense to you, just note that this would ordinarily be the root of the filesystem (i.e. / where home, var, usr, etc, etc live) were it not btrfs.

That’s it! Now, when you’re done, simply use guestunmount to un-mount the device much in the same way you would use umount:

# exit
$ cd # in case we're in /mnt/point
$ sudo guestunmount /mnt/point

Collegamenti: