Menu

Create semi-{data, diskless} system

Overview

This guide presumes you are booted into a fresh install media (no stored configuration). It further presumes that neither the pure diskless configuration from the Alpine wiki, the data configuration from the Alpine wiki, nor the system disk (classic) configuration from the Alpine wiki suits your situation.

This configuration is like diskless mode except that home, parts of /var, and others are mounted for persistence. It is also like data install except that only parts of /var are made persistent.

Note that with diskless, data, and our hybrid install, lbu commit only stores changes that are used after the ‘boot’ runlevel completes and cannot modify the ‘boot’ or ‘sysinit’ runlevels. While there are ways (if using a writable boot medium) to make modification in those early stages, doing so is out of scope for this documentation.

Organize and configure storage on the system

We don’t cover using encrypted storage here, yet. In the meantime, if you want to try adding it yourself, install the dmcrypt package and configure appropriately. There are some ‘gotchas’ with checking and mounting filesystems due not being able to modify the ‘boot’ or ‘sysinit’ runlevels that require using advanced features of OpenRC to manage the initscripts.

Create a ‘diskless’ install as base and boot into it

For Raspberry Pi systems

If you followed Installation on Raspberry Pi the diskless part is already the default, so skip to add a config partition.

For x86_64 or x86 systems

Create the boot partition on the system’s storage
Copy boot files to the boot partition

Sample session when /dev/sdb has been identified as the boot USB stick (or /dev/sr0 for CD-ROM) and /dev/sda is your target disk formatted as discussed.

setup-bootable /dev/sdb1 /dev/sda1
Configure boot loader (extras)

See hardware specific tweaks & configuration.

Reboot

The rest of this guide is now in sync regardless of whether you are starting with a Pi (or other ARM) install, or an x86_64/x86 system.

Add a ‘config’ partition

‘Config’ partition options

Using f2fs
Using ext4
Using FAT 32

Create and enable ‘config’ partition

Possibly add a swap partition

All other partitions

Options for other partitions

For large non-flash storage use LVM and ext4 or on x86_64 always
For small storage (<= 8 GB)

Don’t use additional partitions just use boot, config, and maybe swap (non-flash).

For large flash storage (including SD cards), use f2fs directly

Mount (or bind mount) /home

Small storage or only flash storage

That means you have configured one ‘boot’ partition an one ‘config’ on the storage, so in order to make more than what you ‘commit’ via LBU persistent you need to point the directory (or directories) each to a corresponding directory on the ‘config’ partition.

Example with ‘config’ mounted on /media/mmcblk0p2

  1. Make sure /home exists and is empty

  2. mkdir -p /media/mmcblk0p2/data/home

  3. Edit /etc/fstab to add

    /media/mmcblk0p2/data/home /home none bind,rw 0 0
    
  4. mount /home to activate the bind mount

  5. Issue df -h; it should list the new mount

  6. Issue mount | grep /home; it should also list the new mount

  7. /home is now ready for storing you user home directories.

Large non-flash storage

In this case you should create a volume, add to /etc/fstab, and mount as you would for any command line Linux system.

Bind mount some /var/lib sub-directories (base install)

You may need to repeat this procedure for directories for some packages you install.

It is only useful to do this for packages that need to preserve data for use across reboot and which don’t need the preserved data until after the ‘sysinit’ and ‘boot’ phases have completed, since the ‘config’ partition will not be available until then.

Network time client ‘drift’

Assuming you have used the default NTP client (chronyd):

The directory to preserve is /var/lib/chrony. One could create /media/mmcblk0p2/data/var/lib/chrony and have an fstab with

/media/mmcblk0p2/data/var/lib/chrony /var/lib/chrony none bind,rw 0 0
Randomness for seeding next boot

This is needed during boot so doesn’t make sense unless you are modifying the initramfs.

The directory to preserve is /var/lib/seedrng. One could create /media/mmcblk0p2/data/var/lib/seedrng and have an fstab with

/media/mmcblk0p2/data/var/lib/seedrng /var/lib/seedrng none bind,rw 0 0
DHCP client lease and other preferably persistent data

This is needed during boot so doesn’t make sense unless you are modifying the initramfs.

The directory to preserve is /var/lib/udhcpd. One could create /media/mmcblk0p2/data/var/lib/udhcpd and have an fstab with

/media/mmcblk0p2/data/var/lib/uhdcpd /var/lib/udhcpd none bind,rw 0 0

Mount /var/log on non-flash storage, if available

Keeping /var/log persistent is sometimes required, but logging usually involves much writing to storage and quickly uses flash write cycles. In addition having /var/log as a separate partition limits the damage that can occur when some process start spamming the logs. If the logs are in their own partition, it avoids all of /var (or the entire filesystem if you only have one big partition) becoming full and bringing the system to its knees.

If you do not have non-flash storage available you should prefer sending the logs to another system (remote syslog) to using even a limited log partition.

If you want a separate /var/log, you should create a volume on non-flash storage, add to /etc/fstab, and mount as you would for any command line Linux system.

However, before doing mount you probably want to move the current /var/log contents to the new location (by temporarily mounting the new location on /mnt, halting any logging processes, doing mv /var/log/* /mnt/, and umount /mnt).

Remove partitioning tools

In the interests of saving space on the system during normal use and reducing chances of human error, remove parted if you used that for partitioning.

apk del parted