Creating True-diskless-boot (Part 1) - simple
This article explores the possibilities/methods of implementing true disk-less boot in Alpine Linux.
Some questions answered here.
How can I tell if the OS is really booted into RAM?
Tough question, try command:
# df -h
If you see disk mounted that you have not explicitly mounted or disk that you cannot unmount, its likely your setup is using that disk for running your current system.
True Disk-less explained
Its not a new method/concept, some existing distributions already use these technique(aka copytoram) in some way or another.
Eg. Knoppix, System-rescue cd
True diskless usually employs methods where one can boot an OS and remove any attached boot-media(disk or cdrom), post-boot, leaving the device completely running from Ram.
Simple method as below, is meant for end users who can achieve the goal by usual disk (un)mounting operations. Save the method/script using lbu and thereon reboot again to a true-diskless.
Current methodologies
- Copy iso to ram.
- Copy full or portion of boot disk onto ram.
Category - Boot from RAM
Method 1 - Cdrom
$ ISO=/home/vkrishn/alpine/v3.22/releases/alpine-standard-3.22.0-x86_64.iso
$ qemu-system-x86_64 -enable-kvm -m 1024 -cdrom $ISO -boot d
localhost:~# df -h
Filesystem Size Used Available Use% Mounted on devtmpfs 10.0M 0 10.0M 0% /dev shm 483.1M 0 483.1M 0% /dev/shm /dev/sr0 1.1G 1.1G 0 100% /media/cdrom tmpfs 483.1M 11.2M 472.0M 2% / tmpfs 193.3M 44.0K 193.2M 0% /run /dev/loop0 233.0M 233.0M 0 100% /.modloop
localhost:~# ls -lah /dev/cdrom
lrwxrwxrwx 1 root root 3 Oct 23 15:05 /dev/cdrom -> sr0
localhost:~# ls -lah /media/cdrom/
total 9K dr-xr-xr-x 1 root root 2.0K May 30 12:22 . drwxr-xr-x 5 root root 100 Oct 23 12:49 .. -r--r--r-- 1 root root 30 May 30 12:22 .alpine-release dr-xr-xr-x 1 root root 2.0K May 30 12:22 apks dr-xr-xr-x 1 root root 2.0K May 30 12:22 boot dr-xr-xr-x 1 root root 2.0K May 30 12:22 efi
1. File: 00.remount.start
#!/bin/sh
ISO=alpine-standard-3.22.0-x86_64.iso
cd /media
cat /dev/cdrom > /media/$ISO
umount /media/usb 2>/dev/null # chicken egg issue
mkdir -p /media/usb
umount /.modloop
umount /media/cdrom
mount /media/$ISO /media/cdrom -t iso9660
mount /media/cdrom/boot/modloop-lts /.modloop
# On subsequent boots mount and copy media.usb.img to /media
# this file can also reside on users' network
# add your mount/copy code here.
# ...
if [ -f "/media/media.usb.img" ]; then
echo '>>> pre-saved configs image found, mounting it now'
else
# To be done on first boot only, then store it somewhere,
# on subsequent boots see above.
apk add e2fsprogs
mkfs.ext3 media.usb.img 100M
fi
mount -t ext3 media.usb.img /media/usb
From booted terminal edit/save to a file(/tmp/mountdisks.sh) with script(1) above. Run it.
vi /tmp/mountdisks.sh
sh /tmp/mountdisks.sh
localhost:~# df -h
Filesystem Size Used Available Use% Mounted on devtmpfs 10.0M 0 10.0M 0% /dev shm 483.1M 0 483.1M 0% /dev/shm tmpfs 483.1M 280.8M 202.4M 58% / tmpfs 193.3M 44.0K 193.2M 0% /run /dev/loop0 268.0M 268.0M 0 100% /media/cdrom /dev/loop1 209.9M 209.9M 0 100% /.modloop /dev/loop2 88.2M 31.0K 83.2M 0% /media/usb
- Now mounted media cdrom can be ejected safely, as system is running completely from files on ram.
- From hereon setup-alpine can be run and later lbu to save configs in /media/usb.
Remember files below can reside elsewhere, feel free to explore possibilities.
- alpine-standard-3.22.0-x86_64.iso or alpine-extended-3.22.0-x86_64.iso(pre/post boot)
- media.usb.img(post-boot)
- Overlay file localhost.apkovl.tar.gz can also be added to boot cmd-line during boot.
NOTE:
- Alpine Linux also provides host of options for boot cmd line.
- If booting from an ISO, Alpine Linux also tries to find/locate overlay file aka,
localhost.apkovl.tar.gzon any attached disks during boot.
Method 2 - Disk
Directory/files structures - of alpine boot disk
(2)
/media/sda1/ <- can be /media/usb /media/sda
|-- alpine
| `-- v3.22
| `-- releases
| `-- alpine-extended-3.22.0-x86_64.iso
|-- apks <- installed from alpine-extended-3.22.0-x86_64.iso
| `-- x86_64
| |-- APKINDEX.tar.gz
| |-- acct-6.6.4-r2.apk
| |-- ....
| |-- modloop-lts
| |-- syslinux
| `-- zstd-libs-1.5.7-r0.apk
|-- boot
| |-- System.map-lts
| |-- ....
| `-- vmlinuz-lts
|-- cache
| `-- installed
|-- efi
| `-- boot
| `-- bootx64.efi
|-- localhost.20251005011539.tar.gz
|-- localhost.apkovl.tar.gz
`-- lost+found
localhost:~# df -h
Filesystem Size Used Available Use% Mounted on devtmpfs 10.0M 0 10.0M 0% /dev shm 734.4M 0 734.4M 0% /dev/shm /dev/sda1 1.5G 1.1G 396.9M 74% /media/sda1 tmpfs 734.4M 11.2M 723.2M 2% / tmpfs 293.8M 44.0K 293.7M 0% /run /dev/loop0 233.0M 233.0M 0 100% /.modloop
localhost:~# cat /etc/fstab
/dev/cdrom /media/cdrom iso9660 noauto,ro 0 0 /dev/usbdisk /media/usb vfat noauto,ro 0 0
localhost:~# cat /etc/apk/repositories
/media/sda1/apks
2. File: 00.remount2.start
#!/bin/sh
BOOTDSK=/media/sda1 # can be /media/usb, /media/sda
ISO=alpine-extended-3.22.0-x86_64.iso
ISOFILE=${BOOTDSK}/alpine/v3.22/releases/${ISO}
cd /media
cp "${ISOFILE}" /media/
umount /media/usb 2>/dev/null # chicken egg issue
mkdir -p /media/usb
mount /media/$ISO /media/cdrom -t iso9660
umount /.modloop
umount /media/usb 2>/dev/null
mount /media/cdrom/boot/modloop-lts /.modloop
# On subsequent boots mount and copy media.usb.img to /media
# this file can also reside on users' network
# add your mount/copy code here.
# ...
if [ -f "/media/media.usb.img" ]; then
echo '>>> pre-saved configs image found, mounting it now'
else
# To be done on first boot only, then store it somewhere,
# on subsequent boots see above.
apk add e2fsprogs
mkfs.ext3 media.usb.img 100M
fi
mount -t ext3 media.usb.img /media/usb
cp -f ${BOOTDSK}/localhost.*.tar.gz /media/usb 2>/dev/null
cd /media/usb && ln -s /media/cdrom/apks ./
cd /; sleep 3 && umount -lfd ${BOOTDSK}
From booted terminal edit/save to a file(/tmp/mountdisks.sh) with script(2) above. Run it.
vi /tmp/mountdisks.sh
sh /tmp/mountdisks.sh
localhost:~# df -h
Filesystem Size Used Available Use% Mounted on devtmpfs 10.0M 0 10.0M 0% /dev shm 483.1M 0 483.1M 0% /dev/shm tmpfs 483.1M 280.8M 202.4M 58% / tmpfs 193.3M 44.0K 193.2M 0% /run /dev/loop1 268.0M 268.0M 0 100% /media/cdrom /dev/loop0 209.9M 209.9M 0 100% /.modloop /dev/loop2 88.2M 31.0K 83.2M 0% /media/usb
- In above test setup alpine-standard-3.22.0-x86_64.iso was used.
About cache
Common to both methods above.
setup-apkcache- /media/usb/cache (till v3.18), now in /var/cache/apk/
- cache link to above folder is created in /etc/apk
Remember these are Disk-less boots, changes made would be unavailable in next reboot, unless you have figured out how to preserve and use those changes(not difficult, just do some documentation reading).
Where and how are these kind of setups useful?
With these methods one can boot series of devices like in schools/colleges without having presence of cdrom on each device or multiple boot medias. User-data saving/sharing can be done online.
Author experience
- I have been using these methods for years now without any major issues so far. Albeit sometimes I think diskless installs offered by Alpine Linux may be more useful than /sys installs.
- I only use disk-less installs, and by few re-mountings I can simulate /sys like installs(disk-based).
Author
V.Krishn
Resources