If you want to run [https://www.gnu.org/software/libc/ glibc] programs in Alpine Linux, there are a few ways of doing so. You can install the [https://git.adelielinux.org/adelie/gcompat gcompat] compatibility layer, you can install glibc alongside [https://musl.libc.org/ musl] (manually, as it isn't packaged), or you could do it the easy way and use either Flatpak (the easiest), containers or a chroot.<br>
If you want to run [https://www.gnu.org/software/libc/ glibc] programs in Alpine Linux, there are a few ways of doing so. You could install glibc as additional to [https://uclibc.org/about.html uclibc] (you would have to do this manually), or you could do it the easy way and use a chroot.<br>
Because there are different use cases, this is just a slight overview about what's possible and what's sensible.<br>
Because there are different use cases, this is just a slight overview about what's possible and what's intelligent.<br>
= Your options =
== gcompat ==
= Your options =
gcompat is the go-to compatibility layer for Alpine users.
== Using BusyBox ==
{{cmd|apk add {{pkg|gcompat}}}}
First, the most simple approach for setting up a chroot is by using a glibc build of [https://www.busybox.net/about.html BusyBox].
After that you run your binaries as normal.
This approach has just a few downsides:-
== Flatpak ==
* You have to link most <code>/bin/</code> and <code>/usr/bin</code> programs against <code>/bin/busybox</code>, and some BusyBox builds break if you don't configure them correctly.
* You have to manually download every library you need for your program manually.
However, if you want a small environment for one simple use case, then this is the solution you want.
Flatpak is by far the easiest method of running any graphical glibc program on Alpine.
Firstly install it.
== Using a live CD ==
{{cmd|apk add {{pkg|flatpak}}}}
If you prefer using any special distro, you can always download and extract a live CD and use it as a chroot enviroment.
Then you can run any Flatpak application:
== Using an image ==
{{cmd|flatpak run <flatpak name>}}
For Gentoo, it is the slowest approach especially on slow machines since it is not binary distribution, but you have the advantage of controlling the package version of whichever library you will install. A drawback would be a a big build. You have to install a Portage tree, which uses up a lot of space. (It's not 100% necessary if you don't have to install any additional content that you won't need.)
It is recommended to enable [https://flathub.org Flathub] using its instructions [https://flatpak.org/setup/Alpine/ here], as most glibc programs you might need will be packaged there.
For Arch or Debian, it is recommended since packages are precompiled. This approach isn't as easily executed as the other alternatives, but this may be the cleanest and most recommended one for the every day user.
You can then install applications from it, for example:
= How to do it =
{{cmd|flatpak install com.valvesoftware.Steam}}
This is just a quick draft, so here it comes.
== Chroot ==
== Using BusyBox ==
An option that's easier to generalize to other glibc applications is installing a glibc-based distribution into a chroot. You can then either chroot into it, or use a symlink and some configuration to make its glibc (and associated libraries) usable from Alpine.
First, we need to download BusyBox. You can choose any of your favourite distros to download a prebuilt version. For instance, you could use Arch Linux [https://www.archlinux.org/packages/?q=busybox packages], as follows:
After setting up a chroot using any of the methods described below, the loader can be set up in Alpine like so (these instructions are for a Debian chroot in /var/chroots/debian, on x86_64, but can be adapted to other systems by using the appropriate paths):
This creates a simple chroot enviroment, which we will expand through all the commands included in BusyBox:
=== Gentoo Linux ===
for i in $(busybox --list);do ln -s /bin/busybox /usr/bin/$i;done
Select a stage3 from [https://www.gentoo.org/downloads/ here] and portage latest from [https://www.gentoo.org/downloads/mirrors/ here] at gentoo/snapshots/portage-latest.tar.xz.
First,
== Using a live CD ==
{{cmd|doas apk add {{pkg|xz}}}}
{{Draft|Contributions welcome}}
Enter the chroot:
{{cmd|mkdir ~/chroot
cd ~/chroot
tar -xvf stage3-*.tar.xz
tar -xvf portage-latest.tar.xz
mv portage usr
doas mount --bind /dev dev
doas mount --bind /sys sys
doas mount -t proc proc proc
cp /etc/resolv.conf etc
doas chroot . /bin/bash}}
== Using an image ==
And voilà, you have your working Gentoo chroot!<br>
=== Gentoo Linux ===
You can now take a look at [https://wiki.gentoo.org/wiki/Handbook:Main_Page Gentoo's Handbook] to find out how you can configure and install your system, or simply extract/copy the program you need to run in your chroot enviroment and execute it.
Select a stage3 from [https://www.gentoo.org/downloads/ here] and portage latest from [https://www.gentoo.org/downloads/mirrors/ here] at gentoo/snapshots/portage-latest.tar.xz.
Here is a wrapper script that is similar to <code>arch-chroot</code> when you frequently reuse this chroot:
Enter the chroot:
Also, create an account with the same user name as host current user to the chroot or make changes to the userspec option to chroot line.
mkdir ~/chroot
cd ~/chroot
tar -xvf stage3-*.tar.xz
tar -xvf portage-latest.tar.xz
mv portage usr
mount --bind /dev dev
mount --bind /sys sys
mount -t proc proc proc
cp /etc/resolv.conf etc
sudo chroot . /bin/bash
And voilà, you have your working Gentoo chroot!<br>
{{Cat|gentoo-chroot.sh|<nowiki>!/bin/bash
CHROOT_PATH="/home/$USER/chroot"
cd $CHROOT_PATH
mount | grep $CHROOT_PATH/dev || doas mount --bind /dev dev
mount | grep $CHROOT_PATH/sys || doas mount --bind /sys sys
mount | grep $CHROOT_PATH/proc || doas mount -t proc proc proc
cp /etc/resolv.conf etc
doas chroot --userspec=$USER:users . /bin/bash
echo "You must manually unmount $CHROOT_PATH/dev, $CHROOT_PATH/sys, $CHROOT_PATH/proc."
</nowiki>
}}
You can now take a look at [https://wiki.gentoo.org/wiki/Handbook:Main_Page Gentoo's Handbook] to find out how you can configure and install your system, or simply extract/copy the program you need to run in your chroot enviroment and execute it.
Do at <code>chmod +x gentoo-chroot.sh</code> to get it to work.
=== Arch Linux ===
=== Arch Linux ===
Although '''pacstrap''' is included with the arch-install-scripts package, it will not work unless the target directory is a mountpoint, so the Arch bootstrap image must be used instead (the image is updated every month, so change the date in the link as required):
Either use '''pacstrap''' (included with the arch-install-scripts package) or an Arch bootstrap image:
for i in /proc/sys/kernel/grsecurity/chroot_*; do echo 1 | sudo tee $i; done
for i in /proc/sys/kernel/grsecurity/chroot_*; do echo 1 | sudo tee $i; done
sudo chroot ~/chroot /bin/bash
sudo chroot ~/chroot /bin/bash
Line 110:
Line 116:
You can now use <code>apt-get</code> to install needed packages.
You can now use <code>apt-get</code> to install needed packages.
== Examples ==
== Containers ==
=== Source dedicated server ===
Here is an easy example of how you can run [http://www.srcds.com srcds] in a simple BusyBox chroot.
For this server, you will only need the basic chroot and an advanced tar version (the BusyBox version is not sufficient because of the missing -U command):
cp /bin/tar . #right now executing programs from $PATH is buggy, soon to be fixed (no bug in BusyBox, but in my script)
./hdsupdatetool.bin #you can accept it or not ;)
./steam
./steam
...and you should have a working chroot with '''srcds''' installed in it.
If you think you are clever or elegant, you can use the server with a bash script:
#!/bin/bash
chroot ~/chroot /root/work/steam $@
Just save it (in your Alpine installation) under <code>/usr/bin/steam</code>, do a <code>chmod +x /usr/bin/steam</code> and have fun!
{{Warning|This script would let '''Steam''' run with root priviliges. This is not recommended.}}
It's also possible to use Docker or Podman containers with a helper like Distrobox. This allows using graphical programs easily and doesn't require root privileges once set up.
=== MegaCli ===
{{cmd|# apk add {{pkg|distrobox}}}}
So let's run [https://wikitech.wikimedia.org/wiki/MegaCli MegaCli] in a chroot too, shall we? ;)
=== Distrobox + Podman ===
First we set up a uclibc chroot :)
{{cmd|# apk add {{pkg|podman}}}}
'''MegaCli''' needs more than just glibc. It needs [https://www.gnu.org/software/ncurses/ ncurses] and the gcc-libs:
Then set up rootless Podman, following [[Podman|these steps]].
You'll need to mount your root as shared for Distrobox to function.
After this, we visit [http://www.lsi.com/downloads/Public/MegaRAID%20Common%20Files/8.02.16_MegaCLI.zip this] site and download '''8.02.16_MegaCLI.zip'''.
{{cmd|#!/bin/sh
mount --make-rshared /}}
mkdir tmp
Mark it as executable.
cd tmp
unzip ../8.02.16_MegaCLI.zip
cd LINUX
unzip MegaCliLin.zip
#Now comes code stolen from rpm2cpio
o=`expr 96 + 8`
set `od -j $o -N 8 -t u1 MegaCli-8.02.16-1.i386.rpm`
As with '''srcds''', we do not want to operate from inside the chroot, so here is a little script that should ease you up (use at your own risk):
Then autostart its service.
#!/bin/bash
{{cmd|# rc-update add local default
user=$(whoami)
# rc-service local start}}
if [ "$user" != "root" ];then
echo "This script needs root access"
exit
fi
mount -t proc proc ~/chroot/proc/
mount --bind /dev/ ~/chroot/dev/
mount --bind /sys/ ~/chroot/sys/
#we may need dev and maybe proc too to use this program
chroot ~/chroot /opt/MegaRAID/MegaCli/MegaCli $@
umount ~/chroot/proc
umount ~/chroot/dev
umount ~/chroot/sys
Save it under <code>/usr/bin/MegaCli</code>. Do a <code>chmod +x /usr/bin/MegaCli</code> and good luck.
Finally you can create a container using your chosen image.
Note: This method takes around 50mb. If you need something smaller, then you can strip a few files from glibc (not recommended), or work on a squashfs.
With the following, you can create a squashfs that is around 15mb small:
It may also be necessary to allow X authorization for GUI programs to work.
mksquashfs ~/chroot/ /chroot.sfs -b 65536
When you add a [https://en.wikipedia.org/wiki/UnionFS unionfs] layer, you can even use it with write access, or you can bind some directories to the writeable directories before you chroot into it.
{{cmd|$ xhost +si:localuser:$USER}}
I will look into it later on.
== Chroot + Bubblewrap ==
You can save the chroot in another directory than your home directory, and you can even install a chroot through an APKBUILD (after someone wrote it).
It's also possible to use a Debian system chroot with Bubblewrap. This allows running programs without root.
With this, you could use many glibc-dependent programs through one chroot, but be aware that running programs like this should not be standard. This should only be used in extreme situations, as in _closed source_ tools linked against glibc.
Mount needed directories in the chroot read-only to limit access to the system devices.
Give write access to <code>/dev/v4l</code> and to <code>/dev/snd</code> in order to let Skype use the webcam device: Skype is not compatible with Alsa anymore and requires Pulseaudio to be running.
sudo mount -o bind /proc ~/chroot/proc
sudo mount -o bind,ro,remount /proc ~/chroot/proc
sudo mount -o bind /sys ~/chroot/sys
sudo mount -o bind,ro,remount /sys ~/chroot/sys
sudo mount -o bind /dev ~/chroot/dev
sudo mount -o bind,ro,remount /dev ~/chroot/dev
sudo mount -o bind /dev/v4l ~/chroot/dev/v4l
sudo mount -t tmpfs -o nodev,nosuid,noexec shm $CHROOT_PATH/dev/shm
A separate user can also be created to run the game, if preferred.
=== Spotify ===
==== Docker method ====
Read the [[Docker]] page to install it. Then clone the repository, as shown below. It will automate the process of pulling all the dependencies, and '''PaX''' marks it for the hardened kernel. The advantage of this container is that it is ready-to-use and has stripped down many of the <code>/usr/bin</code> executables. The downside is that is unstable.
Follow the instructions in the <code>README.md</code>
==== Chroot method ====
The Chroot method the preferred method; it doesn't have the black screen bug and is more stable. Just translate the [https://github.com/orsonteodoro/docker-arch-spotify-PaXmarked/blob/master/Dockerfile Dockerfile instructions] into native '''sh''' (Bourne shell). The trick again is to run Spotify as root with sudo inside the chroot – not as regular user.
Use <code>sudo aplay -l</code> to verify that the soundcard is detected. When you use either this or the Docker method, which relies on ALSA, there could be a conflict depending on who grabs the sound card. Stop all browsers or programs using the sound device outside of the chroot or the docker image so that Spotify can use it.
I did some translation. You may need to make changes.
To update, just delete it and call <code>alpine-spotify-installer.sh</code> again. You will still need the Arch Linux bootstrap image. Extract the image. Next, copy and paste the code shown below into root.x86_64; <code>chmod +x alpine-spotify-installer.sh</code>. Then, run <code>sudo arch-chroot root.x86_64</code>. Then, run <code>./alpine-spotify-installer.sh</code>.
For updating the Chroot or installing dependencies we can mount it and then login as root:
{{cmd|# mount --bind /dev /var/chroots/debian/dev
# mount --bind /proc /var/chroots/debian/proc
# chroot /var/chroots/debian /bin/bash
# apt update && apt upgrade}}
You may want to look at [https://github.com/orsonteodoro/docker-arch-spotify-PaXmarked/blob/master/deflate.sh this script] to learn how to lock it down by removing the unnecessary cruft in your chroot collections that may be abused.
After installing what you might want to umount the binds for dev and proc to avoid issues.
{{cmd|# umount /var/chroots/debian/dev}}
{{cmd|# umount /var/chroots/debian/proc}}
[[Category:Development]]
[[Category:Development]]
[[Category:Installation]]
[[Category:Installation]]
Latest revision as of 14:11, 30 October 2024
If you want to run glibc programs in Alpine Linux, there are a few ways of doing so. You can install the gcompat compatibility layer, you can install glibc alongside musl (manually, as it isn't packaged), or you could do it the easy way and use either Flatpak (the easiest), containers or a chroot.
Because there are different use cases, this is just a slight overview about what's possible and what's sensible.
Your options
gcompat
gcompat is the go-to compatibility layer for Alpine users.
It is recommended to enable Flathub using its instructions here, as most glibc programs you might need will be packaged there.
You can then install applications from it, for example:
flatpak install com.valvesoftware.Steam
Chroot
An option that's easier to generalize to other glibc applications is installing a glibc-based distribution into a chroot. You can then either chroot into it, or use a symlink and some configuration to make its glibc (and associated libraries) usable from Alpine.
After setting up a chroot using any of the methods described below, the loader can be set up in Alpine like so (these instructions are for a Debian chroot in /var/chroots/debian, on x86_64, but can be adapted to other systems by using the appropriate paths):
mkdir ~/chroot
cd ~/chroot
tar -xvf stage3-*.tar.xz
tar -xvf portage-latest.tar.xz
mv portage usr
doas mount --bind /dev dev
doas mount --bind /sys sys
doas mount -t proc proc proc
cp /etc/resolv.conf etc
doas chroot . /bin/bash
And voilà, you have your working Gentoo chroot!
You can now take a look at Gentoo's Handbook to find out how you can configure and install your system, or simply extract/copy the program you need to run in your chroot enviroment and execute it.
Here is a wrapper script that is similar to arch-chroot when you frequently reuse this chroot:
Also, create an account with the same user name as host current user to the chroot or make changes to the userspec option to chroot line.
Contents of gentoo-chroot.sh
!/bin/bash
CHROOT_PATH="/home/$USER/chroot"
cd $CHROOT_PATH
mount | grep $CHROOT_PATH/dev || doas mount --bind /dev dev
mount | grep $CHROOT_PATH/sys || doas mount --bind /sys sys
mount | grep $CHROOT_PATH/proc || doas mount -t proc proc proc
cp /etc/resolv.conf etc
doas chroot --userspec=$USER:users . /bin/bash
echo "You must manually unmount $CHROOT_PATH/dev, $CHROOT_PATH/sys, $CHROOT_PATH/proc."
Do at chmod +x gentoo-chroot.sh to get it to work.
Arch Linux
Either use pacstrap (included with the arch-install-scripts package) or an Arch bootstrap image:
doas apk add arch-install-scripts
mkdir ~/chroot && cd ~/chroot
curl -O https://mirrors.edge.kernel.org/archlinux/iso/latest/archlinux-bootstrap-x86_64.tar.gz
doas tar xzf archlinux-bootstrap-x86_64.tar.gz && rm archlinux-bootstrap-x86_64.tar.gz
doas sed -i '/evowise/s/^#//' root.x86_64/etc/pacman.d/mirrorlist
doas sed -i '/CheckSpace/s/^/#/' root.x86_64/etc/pacman.conf
doas arch-chroot root.x86_64
[chroot]# pacman-key --init
[chroot]# pacman-key --populate archlinux
Once that is done, update the system and install the desired package(s) (denoted by "foo" in this example):
[chroot]# pacman -Syu foo
Debian
Todo: gresec referencs need to be cleanly removed from this section.
Use the provided debootstrap package to create the Debian chroot. --arch is optional, depending of your needs.
On the linux-grsec kernel, you will need to relax chroot limitations:
sudo apk add debootstrap
for i in /proc/sys/kernel/grsecurity/chroot_*; do echo 0 | sudo tee $i; done
mkdir ~/chroot
sudo debootstrap --arch=i386 wheezy ~/chroot https://deb.debian.org/debian/
for i in /proc/sys/kernel/grsecurity/chroot_*; do echo 1 | sudo tee $i; done
sudo chroot ~/chroot /bin/bash
You can now use apt-get to install needed packages.
Containers
It's also possible to use Docker or Podman containers with a helper like Distrobox. This allows using graphical programs easily and doesn't require root privileges once set up.