hostnamectl; # tested on Operating System: Debian GNU/Linux 12 (bookworm) Kernel: Linux 6.1.0-53-amd64 Architecture: x86-64 su - root modprobe nbd max_part=16 # create thin provision new kvm harddisk file of size 1024GBytes qemu-img create -f qcow2 /home/user/vms/transfer_host_guest.qcow2.qcow2 1024G # connect to kvm host qemu-nbd --connect=/dev/nbd0 /home/user/vms/transfer_host_guest.qcow2.qcow2 udevadm settle lsblk /dev/nbd0 mkdir /media/user/nbd0 mount /dev/nbd0 /media/user/nbd0/ mkfs.ext4 -L "transfer" /dev/nbd0 mount /dev/nbd0 /media/user/nbd0/ chown -R user:user /media/user/nbd0/ # write files cp -rv /home/user/thisfile /media/user/nbd0/ sync # unmount and discconect from host umount /media/user/nbd0/ qemu-nbd --disconnect /dev/nbd0 # attach to running vm virsh attach-disk debian13_packettracer /home/user/vms/transfer_host_guest.qcow2.qcow2 vdb --targetbus virtio --driver qemu --subdriver qcow2 --persistent
if the spice tools are installed, clipboard sharing between host and guest (copy & pasting text and even images (!)) should (!) work 😀
What is not working virtualbox-easy-style (yet) is easy-host-to-guest-and-vice-versa-file-transfer (which IS VERY ANNOYING (RedHat are you listening? no?) having to “hack around” the problem with iso images)
hostnamectl; # tested with
Operating System: Debian GNU/Linux 11 (bullseye)
Kernel: Linux 5.10.0-22-amd64
Architecture: x86-64
two possibilities:
- first:
- generate a iso image (but this is a bit cumbersome)
-
su - root apt update && apt install genisoimage genisoimage -o name-of-iso-file.iso ./add-this-file-to-the-iso.tar.gz # if more than 4GB needs to be transfered genisoimage -allow-limited-size -l -J -r -iso-level 3 -o <output.iso> <source file or directory> # or mkisofs -allow-limited-size -l -J -r -iso-level 3 -o <output.iso> <source file or directory>
- then mount iso image via virt-manager
- powerdown vm
- edit vm details
- add storage device DVD
- click on new storage device and select just created image.iso
- second: (also not very conveniant as the user usually wants to exchange files online not offline, RedHat are you listening? no?)
- shutdown the kvm guest
- mount the qcow2 into the host filesystem like this:
- third: setup a vm as samba file server (only on trusted networks! currently the best option for online file transfer)
# to mount a kvm.qcow2 harddisk image su - root modprobe nbd max_part=63 qemu-nbd -c /dev/nbd0 /home/user/vms/kvm/harddisk.image.qcow2 # non-gui way # find mountable partitions # with these two very helpful overview-harddisk alias no problem # run this alias harddisks='lsblk -o '\''NAME,MAJ:MIN,RM,SIZE,RO,FSTYPE,MOUNTPOINT,UUID'\''' # run that alias loop_df='while true; do (clear; echo '\''===== hostname:'\''; hostnamectl; echo '\''===== looped harddisk info '\''; datum; dmesg|tail -n20; echo '\''===== where is what'\''; harddisks; echo '\''===== harddisk usage'\''; df -Th;) ; sleep 1 ; done' # then run loop_df # mount the root-partition of the guest mount /dev/nbd0p1 /media/user/kvm_guest_mount/ # transfer files, then umount when done umount /dev/nbd0p1 # gui-way: open up a filemanager (caja etc.) # and click on the newly available virtual harddisk # it will ask for password to mount it # to umount a kvm.qcow2 harddisk image qemu-nbd -d /dev/nbd0
manpages:
liked this article?
- only together we can create a truly free world
- plz support dwaves to keep it up & running!
- (yes the info on the internet is (mostly) free but beer is still not free (still have to work on that))
- really really hate advertisement
- contribute: whenever a solution was found, blog about it for others to find!
- talk about, recommend & link to this blog and articles
- thanks to all who contribute!