Skip to content

Instantly share code, notes, and snippets.

@jonas-schievink
Created November 15, 2018 17:57
Show Gist options
  • Save jonas-schievink/84f0ef7352879c0dae739ef5a4227450 to your computer and use it in GitHub Desktop.
Save jonas-schievink/84f0ef7352879c0dae739ef5a4227450 to your computer and use it in GitHub Desktop.
chroot into an initramfs with a single command
#!/bin/bash
set -e
if [[ $# -ne 1 ]]; then
echo "usage: ramfs-chroot <ramfs_image>"
exit 1
fi
RAMFS=$1
DIR=$(mktemp -d)
trap "rm -rf '$DIR'" EXIT
trap "exit" SIGINT SIGTERM
echo "-> unpacking $1 to $DIR"
unmkinitramfs "$1" "$DIR"
echo -n "-> "
ls "$DIR/main"
echo "-> changing root"
fakechroot chroot "$DIR/main" "/bin/sh"
echo "" # add linebreak after last sh prompt
@jonas-schievink
Copy link
Author

note that this keeps the host's environment variables, which should be fixed at some point (how exactly do the initramfs environment variables look? are there any?)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment