分类: 虚拟化
2013-05-30 11:23:17
Talked to someone today who was confused by how to get files in and out of a virtual machine disk image. , , , , and offer several ways to do this, and in this article I’m going to summarize all these different ways.
First of all, answer these questions:
I should note as usual that uploading or modifying a guest is only safe if the guest is shut off. If you try to modify a live guest you’ll get disk corruption, so watch out.
Downloading a single file
Easiest way is with virt-cat:
virt-cat GuestName /path/to/file > file
An alternative is to use :
guestfish -i --ro -d GuestName \ download /path/to/file ./localfile
Uploading a single file
If the file exists and it’s a text file that you want to edit, the easiest way is to use virt-edit:
virt-edit GuestName /path/to/file
To upload a single file in general, use :
guestfish -i -d GuestName \ upload ./localfile /path/to/file
Downloading multiple files
Easiest way is probably to use the command:
guestfish -i --ro -d GuestName \ copy-out /directory ./localdir
Uploading multiple files
Use command:
guestfish -i -d GuestName <If you want to quickly upload lots of files, the fastest method is to prepare an ISO (mkisofs) or squashfs containing the files and attach it as an extra disk. You can then copy files quickly to where you need them, eg:
guestfish -i -d GuestName -a my.iso <Downloading or uploading a tarball
There is a high level tool called which automates this. You can also do it semi-manually using the guestfish commands , , , (and more, see the guestfish documentation).
Listing files
Finally to list out files, use the high level tool, or the low level guestfish commands (flat list of a single directory) or (recursive listing of subdirectories).