dotfiles/setup/fedora-install.md
DuckDuckWhale 8d214518ff
Misc: update packages & apps, ROCm, SSH, ...
Framework LED Matrix, over amplication, Mac fnmode for Fedora, OBS CQ,
Python config for Helix and yapf3
2024-12-08 22:31:32 -08:00

8.3 KiB

Fedora Installation

Here is how I installed Fedora. I chose to migrate from ext4 to btrfs, the default file system for Fedora. I also bought a new disk, which means that I needed to create everything from scratch.

Note: This document details the installation only. For setup, see Fedora System Setup or Fedora User Setup. This is originally written for Fedora 39 and updated to Fedora 40.

By following these steps, you will be able to install Fedora with:

  • / as a btrfs subvolume using xxhash as the checksum function on LUKS2 (an encryption layer)
  • /home as another subvolume on the same btrfs (which means it's also encrypted)
  • /boot as ext4
  • /boot/efi as System EFI Partition

A disk password will be required upon boot and a separate user password will be required. /boot is not encrypted because it contains only the kernel files and are public and the same for all Fedora installations -- there's nothing worth encrypting here. Benchmarking shows that there's a negligible performance overhead.

After extensive benchmarking, I found SHA-256 to be too slow for practical use even with the sha_ni kernel module for acceleration. Without acceleration the speed was ~400 MB/s, and with acceleration the speed was ~1500 MB/s, but my disk is capable of ~6000 MB/s. crc32c gave me ~5000 MB/s, and xxhash gave me ~4500 MB/s, which I found acceptable, so that's what I went with.

Making a Fedora Live USB

Simply go to the Fedora project website and download the ISO. I opted not to use the Fedora Media Writer because I like collecting Linux ISOs. It shouldn't impact the result.

After the download you may find the GPG-signed SHA256 checksum file from the icon next to the ISO download. You may find the GPG key fingerprints and instructions to verify via the links there.

Simply dd it to the disk and sync before pulling the USB out. Make sure you have backups and are using the right disk! A friend of mine didn't and corrupted his disk.

Preparing the SSD

Boot the USB. Open gparted by typing its name and pressing enter. Make a GPT partition table.

(If you have paintext data on the drive, you really should do a NVME sanitize. You may find instructions on doing that by looking up the man page for the nvme command.)

Make a large empty partition with no file system (choose "unformatted") leaving 10240 MiB at the end of the drive. You may find a calculator to be handy here.

Make a 1024 MiB partition at the very end of the drive and format with ext4, then make another one right before it and also format with ext4. Formatting here really isn't necessary if not for the Fedora installer graying out all the fields when it doesn't detect a file system (bug?).

I assume that you are using an UEFI system as almost all modern x86_64 systems have that, but you could verify that with [ -d /sys/firmware/efi ] && echo UEFI || echo BIOS.

Now, make the LUKS2 layer by opening a terminal and typing:

sudo cryptsetup luksFormat --hash sha512 --use-random /dev/<root-partition>

...where <root-partition> is the big partition you made first and should look something like /dev/nvme0n1p1. There are some sane defaults that I didn't include in this command as all new systems should have them by default, but you could spell it out if you want to be extra certain: `--type luks2 --key-size 512

  • --cipher aes-xts-plain64 --iter-time 2000 --verify-passphrase`

Then, unlock this encrypted partition by typing: sudo cryptsetup open /dev/ <root-partition> <mapper>, where <mapper> is the name for the mapper file and doesn't matter for our install. You could just use luks.

Now, make the btrfs file system with xxhash as the checksum function: sudo mkfs.btrfs --csum xxhash <mapper>. I didn't use LVM here as btrfs snapshots are much better and support RAID0/1 well. btrfs snapshots doesn't have LVM snapshots' heavy performance penalty, doesn't require preallocation of space which is often wasted, and doesn't become invalid later when its space is used up.

Then, close the LUKS layer as the installer requires the password to it for installation. If you skip this step, you would be forced to rescan in the installer which closes it after you've already selected your configuration.

Installing Fedora

Now, start the installer. Choose your keyboard layout and timezone. Then click into storage configuration.

I have some commands for unlocking the LUKS in my Ubuntu install guide, but here you can simply unlock the LUKS volume and the installer does all the work for you setting that up.

Click the + button to make a new root subvolume. Anaconda, the Fedora installer, requires you to create a new btrfs subvolume at the time of writing. You may simply select the storage as btrfs.<some-number>. Maybe <some-number> is for disambiguation when you have multiple btrfs file systems (smh my head)? Then do the same for the home subvolume. The default names are fine and the mount points are / and /home, respectively.

  • Format <boot-partition> (e.g. /dev/nvme0n1p3) as ext4 and mount to / boot. (Check the format checkbox.)
  • Format <efi-partition> (e.g. /dev/nvme0n1p2) as System EFI Partition and mount to /boot/efi.
  • Format /dev/mapper/<machine name>-root as ext4 and mount to /.
  • Format /dev/mapper/<machine name>-home as ext4 and mount to /home.
  • No need for swap as Fedora uses zram by default.

Now click "Done" and start your install! It took only ten minutes for me.

Now, reboot into your newly installed system and test it out. Make sure it works before migrating your data as that may take a long time, so you don't want to do it again.

Migrating all the data

Open up your retired machine, pop up the SSD, put it in a NVME enclosure, and plug it in.

Now, if you'd like, take a snapshot: sudo mkdir /snapshots && sudo btrfs subvolume snapshot /home /snapshots/home-default

My install is quite old and is from Ubuntu so it contains lots of files past their shelf life. I hit Ctrl+h to unhide all hidden files and compared the two file trees side-by-side and removed all conflicting or obsolete files. Now, start the copy: time sudo cp -a -T <old-path> ~ where <old-path> is path to your old home directory. This took 22 minutes for me.

Now, reboot again to load these files.

After the install

Congratulations! You've reached the end of this guide. After the install, check out my configuration guide and see if you'd like to pull some bits from that.

Some interesting notes

btrfs uses zstd level 1 compression by default. This saves substantially for /, and a little bit for /home:

$ sudo compsize -x /
Processed 121050 files, 95144 regular extents (114629 refs), 60336 inline.
Type       Perc     Disk Usage   Uncompressed Referenced
TOTAL       55%      3.6G         6.6G         8.4G
none       100%      2.1G         2.1G         2.3G
zstd        35%      1.5G         4.5G         6.0G
prealloc   100%      1.2M         1.2M          11M
$ sudo compsize /home
Processed 1178463 files, 1863614 regular extents (1907988 refs), 519681 inline.
Type       Perc     Disk Usage   Uncompressed Referenced
TOTAL       94%      1.2T         1.2T         1.2T
none       100%      1.1T         1.1T         1.1T
zstd        36%       40G         110G         113G
prealloc   100%      1.2M         1.2M         1.1M

In my testing I managed to reach 91% by forcing compression, but I didn't use it as I don't think 3% is worth the performance hit. (The default options has negligible performance overhead.)

After using it for a while:

$ sudo compsize -x /
Processed 356866 files, 228300 regular extents (347966 refs), 187319 inline.
Type       Perc     Disk Usage   Uncompressed Referenced
TOTAL       56%       11G          19G          30G
none       100%      6.9G         6.9G         9.8G
zstd        32%      4.1G          12G          20G
prealloc   100%      1.2M         1.2M          22M
$ sudo compsize /home
Processed 1204163 files, 2035560 regular extents (2142558 refs), 501390 inline.
Type       Perc     Disk Usage   Uncompressed Referenced
TOTAL       95%      1.3T         1.4T         1.4T
none       100%      1.3T         1.3T         1.3T
zstd        35%       38G         107G         111G
prealloc   100%      215M         215M         115M