Skip to content

Instantly share code, notes, and snippets.

@mikeslattery
Created April 30, 2020 15:37
Show Gist options
  • Save mikeslattery/20a2007d46b0f180d7eca217773e68b1 to your computer and use it in GitHub Desktop.
Save mikeslattery/20a2007d46b0f180d7eca217773e68b1 to your computer and use it in GitHub Desktop.
Create a temporary Alpine chroo
#!/bin/sh
# Create and launch an alpine chroot
# If /tmp is not tmpfs, change this to /dev/shm
rootfs=/tmp/alpine
set -eu
if ! [ -f $rootfs/etc/resolv.conf ]; then
if ! [ -f ~/Downloads/alpine.tar.gz ]; then
curl -Lf -o ~/Downloads/alpine.tar.gz http://dl-cdn.alpinelinux.org/alpine/v3.11/releases/x86_64/alpine-minirootfs-3.11.6-x86_64.tar.gz
fi
mkdir -p $rootfs
sudo tar -C $rootfs -xf ~/Downloads/alpine.tar.gz
if ! [ -d $rootfs/dev/stdout ]; then
echo dev proc run sys | xargs -d' ' -I% sudo mount /%/ $rootfs/%/ --bind
fi
sudo cp -a /etc/resolv.conf $rootfs/etc/.
fi
sudo chroot $rootfs /bin/sh -i
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment