6

I have to make a configuration file available to guest OS running on top of KVM hyper-visor.

I have already read about folder sharing options between host and guest in KVM with 'qemu' and 9P virtio support. I would like to know about any simple procedure which can help in one time file transfer from host to guest.

Please let me know, how to transfer file while guest OS is running as well as a possible way to make the file available to guest OS by the time it starts running(like packaging the file and integrating with the disk-image if possible).

Host OS will be linux.

6

Just hit upon two different ways:

  • Transfer files via network. For example you can run httpd on the host and use any web browser or wget/curl to download files. Probably most easy and handy.
  • Build ISO image on the host with files you want to transfer. Then attach it to the guest's CD drive.

    genisoimage -o image.iso -r /path/to/dir
    virsh attach-disk guest image.iso hdc --driver file --type cdrom --mode readonly
    
    • You can use mkisofs instead of genisoimage.
    • You can use GUI like virt-manager instead of virsh CUI to attach an ISO image to the guest.
    • You need to create a VM beforehand, supply that VM's ID as guest. You can see existing VMs by virsh list --all.
7
  • Any standard network file transfer protocol should work, such as setting up an FTP or NFS server on the host. – bgvaughan Jun 2 '15 at 10:41
  • 2
    Consider using scp or rsync which are often already available on both host and guest. – Lambert Jun 2 '15 at 10:47
  • @bgvaughan I cannot access guest OS to run commands. I have to make those files available. So, I just cannot make host as a server to keep files in host and give access to guest. Thanks. – MVSR Jun 2 '15 at 10:47
  • 1
    @MVSR You need to create a VM beforehand, supply that VM's ID as guest. You can see existing VMs by virsh list --all. – yaegashi Jun 2 '15 at 10:52
  • @yaegashi Thanks. I ll look into it. I just figured it out and deleted the earlier comment. Please add the additional info in the answer and I will accept it. – MVSR Jun 2 '15 at 10:56
1

Another easy way to do it before you start the guest is to simply mount the guest filesystem on the host, see here. Then you can just copy the files over to the mounted filesystem. For QCOW2 image for example you can do:

sudo modprobe nbd max_part=63
sudo qemu-nbd -c /dev/nbd0 <image_filename>.cow

then you can mount it by opening it up in a graphical file manager, or with the mount command.

1
  • Alternatively $ guestmount file.qcow2 /mnt/tmp – Michał Leon Jun 7 at 16:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.