Today I got a requirement to share large amount of data with Virtual machine. I came to know about that command virt-make-fs is suitable for this task. In this article, I am going to show you the usage of same command.
From man page of virt-make-fs which is provided by libguestfs-tools.
virt-make-fs – Make a filesystem from a tar archive or files
Step 1 : I created an image from the data.tar file which I want to access from VM. Image name is test.img.
[root@host Downloads]# virt-make-fs data.tar /home/host/VirtualMachines/test.img
[root@host Downloads]# cd /home/host/VirtualMachines/
[root@host VirtualMachines]# ll test.img
-rw-r–r–. 1 root root 69550694 Dec 29 21:35 test.img
Step 2 : Attached the same image to Virtual machine.
[root@host VirtualMachines]# virsh list
Id Name State
14 idmserver1 running
[root@host VirtualMachines]# virsh domblklist 17
Step 3 : Inside the virtual machine I can see that new image is detected.
[root@guest ]# file /dev/sda
/dev/sda: block special
Created loopback device to mount that image inside VM.
[root@guest ]# losetup /dev/loop0 /dev/sda
[root@guest ]# losetup -a
/dev/loop0: :6211 (/dev/sda)
Mounted it successfully.
[root@guest ]# mount /dev/loop0 /mnt
[root@guest ]# df -Ph /mnt
Filesystem Size Used Avail Use% Mounted on
/dev/loop0 65M 62M 0 100% /mnt
I am able to access the content of the tar file from inside the VM.
[root@guest ~]# cd /mnt
[root@guest mnt]# ls
By default filesystem is created of type ext2 but you can specify the filesystem while creating the image. Please refer the man page for the same.