Skip to content

bkahlert/libguestfs

Repository files navigation

bkahlert/libguestfs Build Status Repository Size Repository Size

  • Containerized libguestfs including virt-customize, guestfish, etc.
  • Runs as non-root user
  • Multi-platform image
  • Helper scripts
    • guestfish — Opens the raw image disk file using guestfish.
    • virt-customize — Opens the raw image disk using libguestfs' virt-customize.
    • pi — Opens the raw image disk using a dockerized ARM emulator that emulates a Raspberry Pi.
    • copy-out — Copies whole file trees out of a raw image.

Build locally

git clone https://github.com/bkahlert/libguestfs.git
cd libguestfs

# Build image and output to docker (default)
docker buildx bake

# Build multi-platform image
docker buildx bake image-all

Image

Following platforms for this image are available:

  • linux/amd64
  • linux/arm/v7
  • linux/arm64/v8
  • linux/ppc64le
  • linux/riscv64
  • linux/s390x

Environment variables

  • TZ: The timezone assigned to the container (default UTC)
  • PUID: The user id to use (default 1000)
  • PGID: The group id to use (default 1000)
  • LIBGUESTFS_DEBUG: Set this to 1 in order to enable massive amounts of debug messages. If you think there is some problem inside the libguestfs appliance, then you should use this option. (default: 0)
  • LIBGUESTFS_TRACE: Set this to 1 and libguestfs will print out each command / API call in a format which is similar to guestfish commands. (default: 0)

Usage

Interactively

docker run -it --rm \
  -v "$(pwd)/data:/data" \
  -v "$(pwd)/disk.img:/disk.img" \
  bkahlert/libguestfs:edge \
  guestfish

><fs> add /disk.img
><fs> launch
><fs> mount /dev/sda /
><fs> ls /
><fs> copy-out /boot data
><fs> umount-all
><fs> exit

Automatically

docker run --rm \
  -v "$(pwd)/data:/data" \
  -v "$(pwd)/disk.img:/disk.img" \
  bkahlert/libguestfs:edge \
  guestfish \
  --ro \
  --add /disk.img \
  --mount /dev/sda:/ \
<<COMMANDS
ls /
-copy-out /boot data
umount-all
exit
COMMANDS

The command requires disk.img in this directory, mounts it with the guestfish tool and executes all guestfish commands enclosed by COMMANDS on the mounted disk.img.

In this case the directory /boot and its contents is copied to data.

💡 Did you notice the leading dash in front of the copy-out command? Running guestfish non-interactively the first command that gives an error causes the whole shell to exit. By prefixing a command with - guestfish will not exit if an error is encountered.

💡 If you prefix a command with ! (e.g. !id) the command will run on the host instead of the mounted guest. Since the libguestfs tools are containerized themselves, "host" signifies the containerized libguestfs hosting Ubuntu installation — and not you actual OS.

Troubleshooting

If you run into problems, try running your intended steps interactively with verbose logging turned on:

docker run -it --rm \
  -e "LIBGUESTFS_DEBUG=1" \
  -e "LIBGUESTFS_TRACE=1" \
  -v "$(pwd)/data:/data" \
  -v "$(pwd)/disk.img:/disk.img" \
  bkahlert/libguestfs:edge \
  guestfish

Contributing

Want to contribute? Awesome! The most basic way to show your support is to star the project, or to raise issues. You can also support this project by making a Paypal donation to ensure this journey continues indefinitely!

Thanks again for your support, it is much appreciated! 🙏

License

MIT. See LICENSE for more details.

About

Containerized libguestfs including virt-customize, guestfish, etc.

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

Packages

 
 
 

Contributors 2

  •  
  •