Created
November 15, 2018 17:57
-
-
Save jonas-schievink/84f0ef7352879c0dae739ef5a4227450 to your computer and use it in GitHub Desktop.
chroot into an initramfs with a single command
This file contains 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 | |
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 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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?)