Last active
February 5, 2025 09:13
-
-
Save farosas/789abe0df29707e2c69b828d40a44265 to your computer and use it in GitHub Desktop.
Script to use qemu-nbd to edit a locked image (cloud-init)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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