Booting from the inside

※ a USB stick going between the Mac and the Booklet, a long night

Until this week the Booklet started Rime from a USB stick. Limine loaded the kernel and a 77 MB image of the whole system, the kernel mapped the image read only, and the filesystem server mounted it as the root. It worked, but the image sat in RAM from boot to shutdown on a machine with 1 GB, and every new build meant pulling the stick out, writing it on the Mac and putting it back. I wanted to build on the Mac, copy the result over SSH, restart, and find the new system running.

The SSD inside the Booklet had a single partition across its 122 GB, encrypted with cryptvol, Rime's own volume encryption, and unlocked when I log on. Neither the BIOS nor Limine can read that, and the key only exists after I type my password, so the boot had to come from somewhere else on the same disk.


I kept the encrypted HOME in the first slot of the MBR and put three new partitions at the end of the disk. An MBR's slot numbers don't have to follow the order on the disk, so HOME is still /Media/Disk0Partition1, and nothing that points into it, from the web server's root to the logs, had to change.

Slot  Start LBA   Sectors     MiB   Type  Active
   1       2048  247838720  121015   0x7f
   2  247840768     131072      64   0x83  yes
   3  247971840    1048576     512   0x7e
   4  249020416    1048576     512   0x7e

Slot 2 is a small ext2 partition for Limine and the kernels. Slots 3 and 4 are System A and System B, and each holds the system image as raw bytes, the same MFS image that used to be the initrd. The kernel learns its root from the command line, root=mbr:3043053f:3, which names the disk signature and the slot. The filesystem server mounts that slot read only and reads it through its block cache like any other volume. A deploy writes the slot that isn't running and tells Limine to start it, and the other one stays a menu entry away in case something goes bad.

My first idea had been to keep the kernels and the image as files on a FAT32 partition, which Limine also reads. Rime's FAT32 driver keeps one sector of the FAT in its cache and follows a file's cluster chain from the start for every read, and I had watched it crawl through large files before. With raw slots, MFS is the only Rime filesystem a normal read goes through, and Limine reads the ext2 partition with its own driver.


The first test was meant to be a cheap one. I partitioned my spare USB stick from the Booklet, formatted it with Rime's own mkfs.ext2, and copied the files over. The kernel and Limine's files went through, but the system image stopped after 1.2 MB the first time and 1.7 MB the second:

ehci: bulk OUT to address 6 endpoint 1 failed, token 0x10008c80

The EHCI driver gave a write to the stick one second. Cheap flash can take longer than that to erase a block, and the driver then cancelled the transfer halfway, after which the stick ignored everything until I pulled it out. That bug got its own fix later. For this test it didn't matter, because the real layout keeps only the kernel on ext2, and the kernel's 426 KB had copied fine. I wrote Limine onto the stick with a port of limine-deploy that runs on Rime, booted it, and got a blue screen:

STOP: A system server has ended, and Rime cannot go on without it.
Server: fs
Reason: it ended with status 1

It was the result I had hoped for. Limine had found the kernel on a filesystem Rime made, the kernel had started, and the filesystem server had stopped because the root slot on its command line didn't exist yet.

Along the way Rime also got reboot and shutdown commands, since a deploy over SSH is of little use if the machine has to be restarted by hand. The power server turned out never to have synced the disks before a restart. Only the Shut Down dialog did that, before it asked.


Before anything touched the SSD I copied HOME to the Mac with scp. 919 MB took 12 minutes, which says more about Rime's SSH server than about my network, and a sha256 of every file on both sides matched, apart from four logs the Booklet had gone on writing in the meantime.

The plan for the repartition was a second image with HOME pointed at the RAM disk, so that nothing would hold the SSD open. It booted straight to the desktop without asking for a password, since a HOME in RAM has nothing to unlock, and for the same reason the old volume stayed locked. That was fine for the repartition, but I couldn't make a fresh snapshot from there, so I made it from the normal system onto the SD card, 8635 files in about 12 minutes, and checked it the same way. The repartition itself was five fdisk commands, a cryptvol format with two new passwords and an mkfs.ext2, and none of them complained.


The first logon on the new volume never came back. I typed my password, the box closed after a few seconds, and the screen said "Waiting for logon...", then a minute later that HOME was unavailable. The logon in the text console opened the same volume with the same password at once, so the volume was fine, and the trouble was somewhere in the graphical path. A boot that hangs before HOME leaves no log anywhere, so I built an image that copied the system log onto the ext2 partition as it went, let it hang once more, and read the result from a text console boot:

[    1.968] I: init: HOME is encrypted, waiting for logon
[   21.506] I: volmgr: /Device/Disk1/Partition1 mounted on /Media/Disk1Partition1
[   22.532] I: volmgr: /Device/Disk2/Partition1 has no filesystem Rime reads
[   62.034] I: init: HOME unavailable: /Media/Disk0Partition1/User
[   79.749] I: power: power button pressed

My password went in somewhere in the middle of that, and there is no line from logond about it, and nothing from the volume manager about an unlock. The last line is me giving up.

The SD card held the 919 MB snapshot by then, and it now mounted 21 seconds after boot, where it used to take 4.5. The filesystem server checks an MFS volume in full when it mounts it, every directory and every node, and with 8635 files on a slow card that took 20 seconds, while the volume manager waited for it and answered nobody. Before the graphical logon decides what to do with a password, it asks logond whether HOME is locked, and logond asks the volume manager. After 5 seconds with no answer, the logon took the silence to mean that HOME wasn't encrypted. So it checked my password the way the lock screen does, found it correct, closed the box, and never asked anyone to open the volume. The text logon asks the same question again at every prompt, and I had used it a minute after boot, long after the card had mounted.

The logon now says that the service is busy and asks for the password again. For that evening I deleted the snapshot from the card, and with 8635 files on a slow card that took longer than pulling the card out would have.


The first boot of System A, with the kernel still coming from the stick, gave me the same blue screen, this time without my asking for it. I had told the filesystem server to look for the MFS superblock 2048 sectors into the slot, because the code that mounts the initrd from memory sets its start to sector 2048. That code also subtracts the same number again on every read, so the image has its superblock at byte 0. With that fixed, the next boot reached the logon screen less than a second after Limine, which no longer had to read 80 MB from a USB stick first.

[    0.039] I: initrd: 0 bytes at 0x00000000
[    1.356] I: fs: root mounted from the System slot

After the logon the Booklet used 46 MB of its 1014, and the 77 MB the image used to hold were free from the first second.


Writing Limine to the SSD ran into one more check. The port of limine-deploy refuses a boot sector that still holds another boot record's fields, and the SSD's had bytes left in the two places Limine wants clear, from whatever formatted it before me. limine-deploy has --force-mbr for this, so my port got a --force that clears those bytes and leaves the signature and the table alone. Then I took the stick out, and the Booklet started from its own disk.

The keyring didn't follow and decided to complain. It keeps a copy of its key locked with a key derived from the HOME volume, and the new volume had a new key, so I expected to type the keyring's master password once. It asked again on the next boot, and on the one after. keyringd only wrote a new logon copy when the vault had none, and mine still had the old one, which no longer opened anything. Now keyringd notes when the logon's key fails, and the next unlock with the master password replaces the stale copy.

That fix was also the first real deploy. I built a new system image on the Mac, copied it into my HOME on the Booklet, wrote it into System B while System A was running, pointed Limine at B and restarted:

Image SHA-256:     041144fd0ef4544407761ef39815744f7fbd82e3afab7bea3ab8b3b6076ee93c
Read back SHA-256: 041144fd0ef4544407761ef39815744f7fbd82e3afab7bea3ab8b3b6076ee93c
Slot 4 holds the image. Its root is root=mbr:3043053f:4
keyring: the logon slot holds the new logon key now
keyring: unlocked
wireguard: tunnel ready

On the boot after that, WireGuard came up without asking for anything.


That left the 20 seconds on the SD card. MFS had no way to record that a volume had been stopped cleanly, so the filesystem server walked every volume at every mount, the root slot included, which cost 1.26 seconds on every boot. MFS now keeps a state word in a spare part of its superblock. An unmount writes it as clean, and so does a sync of every volume that a program asks for on purpose, as the power server does before a restart. The first change after that writes the word back to zero and flushes it before anything else reaches the disk, so a crash still leaves a volume that gets the full check. The system image is clean from the moment it is built. Two restarts later:

root slot      1.256 s  ->  0.019 s
SD card        mounted at 4.66 s  ->  at 2.32 s
HOME           checked after the password  ->  open as the password is accepted

The unlock at logon now feels instant.


A deploy is now a build on the Mac, one scp of about 80 MB, sysinstall slot into the slot that isn't running, a new limine.cfg and a restart, and the previous system stays one entry down in the Limine menu. The stick lives in a drawer with a rescue image on it. The volume manager still answers nobody while a large volume mounts, which happens far less often now, and there's no installer yet, so the next disk will be partitioned by hand, the same way this one was.

Written by främling on Nov 25, 2026.

Text may be shared, with credit, and not for commercial use (CC BY-NC-SA).

A chapter of the Building Rime fragment.