Fathom-OS Build Series: Chapter 2.6 and 2.7 - Setting $LFS and Mounting the Partition

Part of the Fathom-OS Project Log.


Chapters 2.6 and 2.7 are short but important. Every build command from this point forward depends on the $LFS variable being set correctly, and the partition needs to be confirmed mounted with the right options before anything else happens. Covering both in a single post since they are tightly related and neither is long on its own.

References:


Chapter 2.6: Setting the $LFS Variable and the Umask

The $LFS environment variable is used throughout the entire LFS build. Every command that touches the build directory references it. If it is not set, or set to the wrong path, commands will either fail or write to the wrong place. The umask needs to be 022 to ensure newly created files and directories have the right permissions. Too permissive leaves security holes, too restrictive causes build failures.

The LFS partition on this build is mounted at /lfs, so that is what $LFS is set to.

Making It Persistent

The variable does not survive across sessions, user switches, or sudo calls unless it is written to the shell profile files. Since this machine is accessed via SSH as dayotte with key authentication, the exports need to go into both the user and root profile files to cover all cases.

echo 'export LFS=/lfs' >> ~/.bash_profile
echo 'umask 022' >> ~/.bash_profile
echo 'export LFS=/lfs' >> ~/.bashrc
echo 'umask 022' >> ~/.bashrc
sudo bash -c "echo 'export LFS=/lfs' >> /root/.bash_profile"
sudo bash -c "echo 'umask 022' >> /root/.bash_profile"
sudo bash -c "echo 'export LFS=/lfs' >> /root/.bashrc"
sudo bash -c "echo 'umask 022' >> /root/.bashrc"

Both .bash_profile and .bashrc are covered because Ubuntu may use either depending on whether the shell is a login shell or an interactive non-login shell.

Set and Verify the Current Session

export LFS=/lfs
umask 022
echo $LFS
umask
sudo bash -c "echo $LFS && umask"

Output:

/lfs
0022
/lfs
0022

Both the user session and root confirmed. $LFS resolves to /lfs and the umask is 0022 in both contexts.


Chapter 2.7: Mounting the New Partition

With $LFS set, the partition can be confirmed mounted and the ownership and permissions verified.

sudo mkdir -pv $LFS
sudo mount -v -t ext4 /dev/sda4 $LFS
sudo chown root:root $LFS
sudo chmod 755 $LFS
mount | grep sda4
tail -5 /etc/fstab

Output:

mount: /lfs: /dev/sda4 already mounted on /lfs.
       dmesg(1) may have more information after failed mount system call.
/dev/sda4 on /lfs type ext4 (rw,relatime)
/dev/disk/by-uuid/ea656df5-934f-4340-b59a-9e2c2c5ae895 none swap sw 0 0
# /lfs was on /dev/sda4 during curtin installation
/dev/disk/by-uuid/6cccdf14-39d9-458b-971b-a278f7200c85 /lfs ext4 defaults 0 1
# /boot/efi was on /dev/sda1 during curtin installation
/dev/disk/by-uuid/8D5A-91A9 /boot/efi vfat defaults 0 1

What the Output Tells Us

Already mounted: The mount command returned an error saying /dev/sda4 is already mounted at /lfs. This is not a problem. The Ubuntu Curtin installer mounted the partition during setup and it has been mounted ever since. The error is just the mount command reporting it had nothing to do.

Mount options: The mount | grep sda4 line confirmed the partition is mounted rw,relatime. No nosuid or nodev flags are present, which the book specifically warns about. No remount needed.

fstab: The partition is already in /etc/fstab by UUID from the Curtin installer. The line /dev/disk/by-uuid/6cccdf14.../lfs ext4 defaults 0 1 means the partition mounts automatically on every reboot. No manual fstab entry was needed.


What Is Next

Chapter 2 is complete. The next step is Chapter 3, which covers downloading the source packages and patches needed for the build.


More updates to follow as each build phase completes.

Previous: Chapter 2.4 and 2.5: Partition and Filesystem Setup | Next: Chapter 3: Packages and Patches


All session notes and build logs are committed to the private repository at github.com/QuietWireDev/fathom-os.