Make Alpine Linux boot dance to your tune (Part 1) - Everything in usr folder

Some questions answered here.

  1. How to install all packages in /usr folder without modifying individual packages?

Method 1 (DISK - RAM boot)

  1. Method described below is presently meant for ram-based installs. It may not be effective on other methods of installs.
  2. Method assumes you have a basic internet ready ram-based install/setup up and running.
  1. Create a ram based basic bootable disk. [2] [3] [4] [5]

Whenever I read about /usr merge logics and the need for it, I have this thinking always coming up as what is actual reason to move to /usr, now I think having everything in /usr is more important than /bin /usr/bin ..etc merged

  • Method below only makes kernel or apk think every folder structure is same as before.
  • There are still some quirks in this method, including its usage or purpose.
  • Consider this more of fun with Alpine Linux installations and things that can be changed.

Here a sidekick solution - somewhat non-standard approach with modified initramfs code.

Create folders in /usr/system

1. Create dir in /usr/system

(1)
/
`-- usr
    `-- system
        |-- bin
        |-- etc
        |-- lib
        `-- sbin

Link or bind these folders

2. Link or bind these folder as in 1 above on /bin, /sbin, /lib, /etc

(2)
/
|-- bin -> /usr/system/bin
|-- etc -> /usr/system/etc
|-- lib -> /usr/system/lib
|-- sbin -> /usr/system/sbin
`-- usr
    `-- system
        |-- bin
        |-- etc
        |-- lib
        `-- sbin

Modify initramfs scripts

3. init

879a880,889
> # Move all binary installations + /etc to /usr/system/ and symlink to /
> SDIR="$sysroot/usr/system"; mkdir -p $SDIR
> S="bin sbin lib etc"; _PD=$PWD
> for d in $S; do
> 	$MOCK mkdir -p $sysroot/$d
> 	# Careful as only relative paths would work
> 	$MOCK mv "$sysroot/$d" $SDIR && cd $sysroot && ln -s "usr/system/$d" ./
> done
> cd $_PD
> 

Attach:init.patch.txt ->

patch init init.patch
sha1sum init.patch init init.patched
 1c973f9ce017941df7ce59785709d7c7ff189d6d  init.patch
 57ef7d9bc90b9afd550669d5beacb26fc2f1a97c  init         (orig, VERSION=3.12.0-r0)
 96cc1a0ea8a33ea280bdfee4462a4de165895057  init.patched (modified)

Quirks

Fix confused lbu, create:

vi /etc/local.d/00.bindetc.start
 #!/bin/sh
 cd /; rm -f etc && mkdir /etc && mount -o bind /usr/system/etc /etc
chmod +x /etc/local.d/00.bindetc.start
sh /etc/local.d/00.bindetc.start # run it if already booted in modified initramfs-lts
rc-update add local
lbu ci

GOALS ACHIEVED

  1. With folder structure as 2 above, everything would get installed in /usr.
  2. Modified initramfs scripts, that can be booted to a folder structure as 2 above.

Things not there yet

Full /usr merged, as envisioned in https://alpinelinux.org/posts/2025-10-01-usr-merge.html

Possibilities

  • Setup to start/migrate gradually to a true usr-merge.
    • Hard-coded exceptions like - /bin/sh, musl libs, firmwares, can still be left to be handled by /usr/system folders.
  • Experiment with this method and come-up with a method/code to make (before official usr-merge gets fully implemented).
    1. /usr read-only(squashfs) (user'blobs merrymium ~HP)
    2. or encrypted (user'merry encryptium ~HP)

How was it done and tested !

  1. Using ram-image, boot-able qemu image was created.
  2. alpine-extended-3.22.0-x86_64.iso was used to create above image.
  3. Image was booted using qemu.
  4. init in /media/sda1/boot/initramfs-lts was modified after unpacking it using gzip,cpio.
  5. Repacked it back to /media/sda1/boot/initramfs-lts.

Author

V.Krishn


Resources


Edit - History - Print - Recent Changes - Search
Page last modified on November 02, 2025, at 06:41 PM