[libvirt-users] Insert/eject USB

Daniel P. Berrange berrange at redhat.com
Wed Mar 8 09:47:56 UTC 2017

On Sat, Mar 04, 2017 at 01:14:39AM -0600, Leroy Tennison wrote:
> Is it possible to insert and eject a USB image in kvm/qemu/libvirt or are
> the only dynamically changeable devices cdroms and floppies?  I've searched
> the web and I'm either not looking for the right terms or it's obscure.  I
> should mention that I'm not talking about a connecting a physical host USB
> drive to a guest image, I want to be able to use a qcow image as the source.

It depends on what kind of USB device you attach. If you attach a USB hard
disk, then to dynamically change the backing store image, you would need to
do USB hotunplug+hotplug to remove the "old" drive & add a "new" drive. If
you were to attacha USB cdrom, then you have the choice of simply ejecting
the media, but can still also do hotunplug+hotplug.

> The context is that I want to be able to revert a VM image back to a prior
> state (internal snapshot) when testing but be able to retain some data
> without having to go to the effort of transferring it across the network.
> I've excluded cdroms as an option because they are read-only (correct me if
> I'm wrong on this) and require some effort to (re)build.  Floppy drives
> appear to be limited to 1.44M which makes sense but is very limiting.

Correct wrt cdroms & floppies.

> Network mounts (NFS, Samba, etc.) require a server supporting the selected
> style of filesystem sharing over the network.  I'm not sure I want to find
> out what happens to filesystem passthrough when a revert is done (unless
> someone knows and it's beneficial).
> I tried creating a partition associated with the VM but not auto-mounted,
> even if I unmounted the partition before reverting its state was rolled
> back.  I possibly could get exotic here by setting the immutable attribute
> after unmounting the partition but, again, I'm hoping for something a little
> simpler and more straightforward.  If there's a workable option I haven't
> considered I'm open to that.

It sounds like you should want to be using qcow2 internals snapshots to
capture memory+disk state, or if you wnt to get more advanced libvirt has
APIs to allow fine grained creation of snapshots in standalone files.

|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://entangle-photo.org       -o-    http://search.cpan.org/~danberr/ :|

More information about the libvirt-users mailing list