Skip to content

Instantly share code, notes, and snippets.

@farosas
Last active February 5, 2025 09:13
Show Gist options
  • Select an option

  • Save farosas/789abe0df29707e2c69b828d40a44265 to your computer and use it in GitHub Desktop.

Select an option

Save farosas/789abe0df29707e2c69b828d40a44265 to your computer and use it in GitHub Desktop.
Script to use qemu-nbd to edit a locked image (cloud-init)
#!/bin/bash
MOUNTPOINT=/mnt/tmp_nbd
IMAGE=$1
PARTITION=${2:-/dev/nbd0p1}
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root"
exit 1
fi
modprobe nbd max_part=4
qemu-nbd --connect=/dev/nbd0 $1
sleep 2
mkdir -p $MOUNTPOINT
mount $PARTITION $MOUNTPOINT
chroot $MOUNTPOINT
umount $MOUNTPOINT
qemu-nbd --disconnect /dev/nbd0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment