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:
https://wiki.alpinelinux.org/wiki/Installing_Alpine_Linux_in_a_chroot

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':
#!/bin/sh

mirror=http://dl-cdn.alpinelinux.org/alpine
chroot_dir=alpine-rootfs-x86_64
branch=v3.5

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

sync
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:
#!/bin/sh


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):
http://distro.ibiblio.org/quirky/alpine/x86_64/developer/alpine-rootfs-x86_64.tar.gz

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:
http://murga-linux.com/puppy/

Alpine Linux home page:
https://alpinelinux.org/


Comments

I have also created x86 armhf rootfs's:

http://distro.ibiblio.org/quirky/alpine/x86/

http://distro.ibiblio.org/quirky/alpine/armhf/

http://murga-linux.com/puppy/viewtopic.php?p=950736&search_id=583013688#950736

Tags: linux