You know you can run libguestfs / guestfish on anything, right? This question came up at one of the Summit parties, so maybe some people don’t know. But it works on USB keys, CDs, hard disks, partitions, and files (and more).
There is a practical benefit to using libguestfs on USB keys, because it adds a layer of isolation between the unknown contents of the USB key and your host kernel. Mounting random disks on your host kernel is deeply insecure.
In the example below, I’ve stuck in a random USB key (empty and safe as it happens, but how was I to know?) and I ran guestfish on the first partition directly:
$ guestfish -a /dev/sdb1 Welcome to guestfish, the libguestfs filesystem interactive shell for editing virtual machine filesystems. Type: 'help' for help on commands 'man' to read the manual 'quit' to quit the shell ><fs> run 100% ⟦▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉⟧ 00:00 ><fs> mount-options "" /dev/vda / ><fs> ll / total 36 drwxr-xr-x 2 root root 32768 Jan 1 1970 . drwxr-xr-x 24 500 500 4096 Jul 9 17:11 .. ><fs> df-h Filesystem Size Used Avail Use% Mounted on /dev/vda 3.7G 32K 3.7G 1% /sysroot
(I don’t need to be root, because I’ve added myself to the “disk” group, which means I can access any block device.)
Above, I ran guestfish on the USB key’s first partition (
/dev/sdb1, so that inside libguestfs the partition appears as a whole device (
/dev/vda). Equally I could have run guestfish on the whole USB key (
/dev/sdb), in which case libguestfs would see and be able to manipulate the partition table too.