site  contact  subhomenews

Alpine x86_64 chrootable rootfs

April 09, 2017 — BarryK
I wanted to create chrootable filesystems for ARM and x86_64, using uClibc or MUSL, for the purpose of compiling some utilities statically.

Unfortunately, uClibc support is waning. It still remains my favourite though. My experience with MUSL has not been 100% positive, but anyway, Alpine Linux offers a superb way to create chrootable rootfs's.

Some time ago, I played with Sabotage, a MUSL-based distro, and had an awful time to get SeaMonkey to compile -- got there, but SM was partly broken. I have just noticed that SM 2.46 is in Alpine, that is good news, gives me some confidence to consider MUSL again.

Um, but Alpine's "armhf" binaries are only armv6. Not what I want. But maybe I will move onto the "aarch64", which is apparently armv8 -- considering that Raspberry Pi2 boards now have the 64-bit CPU, same as the Pi3.

I found this excellent wiki page, explains how to create a chrootable rootfs:

I am running Quirky x86_64 version 8.1.6, on my baby laptop (with 1TB USB drive hanging off it).

I followed the wiki instructions, and created a script, named 'chroot-x86_64':


cp /etc/resolv.conf ${chroot_dir}/etc/
mkdir -p ${chroot_dir}/root

mkdir -p ${chroot_dir}/etc/apk
echo "${mirror}/${branch}/main" > ${chroot_dir}/etc/apk/repositories

mount -o bind /dev ${chroot_dir}/dev
mount -t proc none ${chroot_dir}/proc
mount -o bind /sys ${chroot_dir}/sys

chroot ${chroot_dir} /bin/sh -l

umount ${chroot_dir}/sys
umount ${chroot_dir}/proc
umount ${chroot_dir}/dev

Another script inside the rootfs, named 'rootfs-run-once', is run just once, after doing the chroot:

rc-update add devfs sysinit
rc-update add dmesg sysinit
rc-update add mdev sysinit
rc-update add hwclock boot
rc-update add modules boot
rc-update add sysctl boot
rc-update add hostname boot
rc-update add bootmisc boot
rc-update add syslog boot
rc-update add mount-ro shutdown
rc-update add killprocs shutdown
rc-update add savecache shutdown

apk update
apk add alpine-sdk

echo 'kernel.grsecurity.chroot_deny_chmod = 0' >> /etc/sysctl.conf
sysctl -p

I have uploaded the result to ibiblio, it has the scripts inside it (65MB):

OK, what I want to do next is compile busybox statically. As I recall, patches are required for MUSL, but that info should be somewhere in the Alpine developer repos -- just getting started with Alpine, don't know where to find things yet, nor do I know anything about the package management.

...if anyone reading this is familiar with Alpine, you are welcome to send me a PM on the Puppy Forum, I am "BarryK". Any of your thoughts and insights about Alpine are welcome. Forum:

Alpine Linux home page:


I have also created x86 armhf rootfs's:

Tags: linux