Skip to content

fs/ufs: add read-only FreeBSD UFS2 file reader - #24

Closed
bradfitz wants to merge 1 commit into
mainfrom
bradfitz/ufs
Closed

bradfitz wants to merge 1 commit into
mainfrom
bradfitz/ufs

Conversation

@bradfitz

Copy link
Copy Markdown
Member

Package ufs reads files out of a cleanly unmounted FreeBSD UFS2 file
system over an io.ReaderAt, optionally locating it by label in a GPT
partition table (e.g. "rootfs", as in /dev/gpt/rootfs).

It supports only what's needed to pull files from a CI VM image: the
superblock, inode lookup across cylinder groups, directory traversal,
fragment-sized tail blocks, holes, and the direct and single, double,
and triple indirect block maps. It doesn't support writes, UFS1, soft
updates journals, snapshots, extended attributes, or symlinks.

The motivating use is booting FreeBSD CI VMs directly with QEMU's
-kernel flag, skipping SeaBIOS and FreeBSD's loader: the VM manager can
extract /boot/kernel/kernel from the VM's qcow2 disk image (via
github.com/bradfitz/qcow2) at boot time, so the kernel never drifts from
the image's /boot/kernel modules and needs no separate build artifact.
Against the FreeBSD 15.0 cloud image, extracting the 29MB kernel takes
~37ms, and its bytes match those read through Linux's UFS driver.

The tests use a 38KB image built by FreeBSD's makefs(8), covering
directories spanning several blocks, partial tail blocks, and single
indirect blocks, plus a synthetic in-memory disk with 512-byte blocks to
cover double and triple indirect blocks, holes, and inodes in later
cylinder groups without a large fixture.

Updates tailscale/corp#52010

Package ufs reads files out of a cleanly unmounted FreeBSD UFS2 file
system over an io.ReaderAt, optionally locating it by label in a GPT
partition table (e.g. "rootfs", as in /dev/gpt/rootfs).

It supports only what's needed to pull files from a CI VM image: the
superblock, inode lookup across cylinder groups, directory traversal,
fragment-sized tail blocks, holes, and the direct and single, double,
and triple indirect block maps. It doesn't support writes, UFS1, soft
updates journals, snapshots, extended attributes, or symlinks.

The motivating use is booting FreeBSD CI VMs directly with QEMU's
-kernel flag, skipping SeaBIOS and FreeBSD's loader: the VM manager can
extract /boot/kernel/kernel from the VM's qcow2 disk image (via
github.com/bradfitz/qcow2) at boot time, so the kernel never drifts from
the image's /boot/kernel modules and needs no separate build artifact.
Against the FreeBSD 15.0 cloud image, extracting the 29MB kernel takes
~37ms, and its bytes match those read through Linux's UFS driver.

The tests use a 38KB image built by FreeBSD's makefs(8), covering
directories spanning several blocks, partial tail blocks, and single
indirect blocks, plus a synthetic in-memory disk with 512-byte blocks to
cover double and triple indirect blocks, holes, and inodes in later
cylinder groups without a large fixture.

Updates tailscale/corp#52010
@bradfitz
bradfitz requested a review from a team November 23, 2026 15:14
@winckler

Copy link
Copy Markdown

Had you considered an alternative design, closer to the linux flow: Could the FreeBSD image build copy /boot/kernel/kernel out over its SSH session into the image directory, so vmimage would resolve it as it does for Linux? This way we don't need to make any assumptions about the disk/fs setup and don't need to support FS code...

@bradfitz

Copy link
Copy Markdown
Member Author

I did consider that, but after seeing how simple it was to just copy the kernel out of the filesystem image, it seemed to be just as easy or easier to do this rather than having more artifacts.

But if you feel strongly, I can change to that model.

@winckler

Copy link
Copy Markdown

I did consider that, but after seeing how simple it was to just copy the kernel out of the filesystem image, it seemed to be just as easy or easier to do this rather than having more artifacts.

But if you feel strongly, I can change to that model.

I do. I think would be better to get the kernel when we build. My concern is that this setup might be too brittle to any changes to the disk partitioning or FS features, as there are many valid setups that this implementation doesn't support (and we shouldn't re-implement).

@bradfitz bradfitz closed this Nov 23, 2026
@bradfitz

Copy link
Copy Markdown
Member Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants