DEV Community

Ray Harris
Ray Harris

Posted on

Day 6: Making rEFInd Look Good

Today, we're styling rEFInd to look kewl. In this post, I'll cover setting up rEFInd on my PC as well as creating and applying a custom style. I've already set it up on my Macbook in a previous post, so look back for that if you want to see how to do that. Originally, I thought to use the native apple Startup Manager & PC BIOS startup disk selection. But there are some problems with that:

  1. The PC startup disk selection is ugly AF
  2. I couldn't get the Mac Startup Manager to work right
  3. I want more consistency across my devices

So let's get into it!

BEFORE:
Image description

AFTER:
Image description

Intro to rEFInd

rEFInd is a "boot manager" which helps you manage booting up your computer into the operating system you want to run. rEFInd is a tried and true open-source boot manager with over a decade of appreciated existence. The author, oderick W. Smith, manages the code and handles feedback on sourceforge and maintains a webpage with more details. It's not polished for typical consumer use and requires some patience to fully understand, but for the most part you can just use it and not worry too much.

Managing rEFInd

Once installed, rEFInd works by scanning a few commonly used places on your drives for boot files and listing them on a menu. When installed in the normal way, rEFInd takes priority over all the boot options and gets itself launched when the machine turns on. It immediately displays its menu of boot options and bows out once you select the one you want. There is a configuration file called which should be found at /EFI/refind/refind.conf on the EFI partition.

The file handles a few settings, but most importantly allows for the creation of custom boot "stanzas" which represent the options that will be presented. To fully customize the appearance, we'll want to create a custom stanza for each OS we're booting.

Installing and configuring rEFInd on Macbook

I already have rEFInd installed from my prior days' work, but you can install it by booting into recovery mode with CMD+R, disabling SIP with the terminal in recovery mode with csrutil disable, booting back into normal mode, and running the install script you get from unzipping the binary file linked on this page.

With modern Macbooks, managing the boot option is a bit more difficult. Normally, all booting happens from an EFI partition on the main drive. This was once true for OSX as well. With macOS and APFS, the boot is now initiated from within the preboot volume of the main APFS container. Meanwhile, our linux boot will still be in the EFI partition.

First, check your APFS volumes and their unique identifiers

diskutil apfs list
Enter fullscreen mode Exit fullscreen mode

Which should give you something like this:
Image description

With that still open, open a new Finder window and CMD+UP all the way to the top where you'll see your mounted drives and Network. Now dive down into Macintosh HD/System/Volumes/Preboot. Here you should find at least one folder with a UID as the name, plus a com.apple.security.cryptexd folder and a Crpytexes folder, both of which we can ignore. What we care about here is the name of the correct UID folder. I have two, I don't know why. You might just have one. One of them will help us the other won't. The good one will have a string that matches one of the APFS volumes you saw when running diskutil apfs list. Looks like this:

Image description

In my case, the match is 38F253E9-6CF0-4612-8D51-383D68564E12. Plz don't hack me. Kidding, this should be fine.

With this information, we can now construct our rEFInd boot stanza. Using that string we can create an entry that looks like the code below.

menuentry "My macOS TEST" {
    icon \EFI\refind\icons\os_mac.png
    volume "Preboot"
    loader \38F253E9-6CF0-4612-8D51-383D68564E12\System\Library\CoreServices\boot.efi
    enabled
}
Enter fullscreen mode Exit fullscreen mode

We need to add this to our refind.conf file which is in the EFI partition. To access it, first find that disk identifer with diskutil list. Mine is disk0s1 and yours probably is too. Mount it with another command, diskutil mount disk0s1.

Now when you navigate all the way up, you'll see EFI listed.

Image description

The file we want to modify is at EFI/EFI/refind/refind.conf. You can paste your stanza down at the bottom of the file after all the example stanzas (note they are all marked disabled).

Save it, shut down, boot up, and see if your new bootable entry shows up alongside your normal options. Remember, adding a stanza to your config can only add options to your rEFInd boot menu, it will never remove or overwrite an existing boot option. I tested and mine worked, so now let's add the NixOS stanza.

My boot file turns out to be located at EFI/EFI/systemd/systemd-bootx64.efi. I'm not sure if it's it'll always be there if NixOS was installed another way, but the good news is that I found it simply by reading the option that rEFInd presented to me. I added this stanza to the refind.conf file below the macOS entry:

menuentry "My NixOS TEST" {
    icon \EFI\refind\icons\os_mac.png
    loader \EFI\systemd\systemd-bootx64.efi
    enabled
}
Enter fullscreen mode Exit fullscreen mode

I rebooted and tested out the new entry to confirm that it booted NixOS as expected*. Woot! Now all that's left is styling which I'll do at the same time for both machines.

I rebooted and tested out the new entry to confirm that it booted NixOS as expected*. Woot! Now all that's left is styling which I'll do at the same time for both machines.

*Note: Something weird happened here for me. I tested a few times and saw inconsistent activation of the keyboard and trackpad in the rEFInd environment. What's more is that a couple times I booted into the command line instead of KDE Plasma. It seems to work intermittently though, so I will ignore and return to this later.

Installing and configuring rEFInd on PC

To install, I'm following the steps here:

I'll be installing rEFInd on my nvme drive which is where Windows is located, so I'll start by booting into Windows and mounting the EFI partition:

mountvol R: /S 
Enter fullscreen mode Exit fullscreen mode

This makes Local Disk (R:) appear in Explorer, but we'll need to run Explorer as an admin to get access to the contents. To do that, open task manager and end explorer.exe so we can reopen it as an admin.

Image description

And to reopen it, go to File>Run new task and enter explorer.exe /nouaccheck with the admin checkbox selected. Hit OK.

Image description

Now open an explorer window and find the R drive. Woot!

Next I downloaded rEFInd and extracted the files to my desktop. Then I opened command prompt as an administrator (right click) and navigated to the refind folder with cd C:\Users\raymo\Desktop\refind-bin-0.14.0.2\refind-bin-0.14.0.2. Then to copy files into places, I ran the following:

xcopy /E refind R:\EFI\refind\
Enter fullscreen mode Exit fullscreen mode

A list of copied files appeared so we know it worked. Next, let's go into the drive. Enter R: into CMD to switch to that partition. Followed by cd EFI\refind to get into the refind folder.

Now rename the config file:

rename refind.conf-sample refind.conf
Enter fullscreen mode Exit fullscreen mode

And perhaps most importantly, run the following to make refind the default boot program.

bcdedit /set "{bootmgr}" path \EFI\refind\refind_x64.efi
Enter fullscreen mode Exit fullscreen mode

Let's go ahead and rename as well to make life easy:

bcdedit /set "{bootmgr}" description "rEFInd"
Enter fullscreen mode Exit fullscreen mode

In Explorer, let's now go in and remove some unnecessary drivers that will slow us down. There are 3 driver folders: aa64, ia32, and x64. I created a new folder at that same level called extra drivers and dragged the aa64 and ia32 folders into it. Then in the drivers_x64 folder, I think the only thing I need is the ext4 driver. Windows will bring its own ntfs driver and I'm not using the other file system formats on the list. However, I'll just keep everything there for now.

Now reboot and get into rEFInd! Since my PC at this point had the Linux drive as the priority, I still needed to hit del when booting up to select my boot option, but once I selected the rEFInd option, it loaded and presented me with a couple options including my Windows and NixOS intalls.

Now we want to create manual boot stanzas to give us full control and flexibility. Let's go into NixOS and get the EFI partition's UUID. To do so, run

sudo blkid
Enter fullscreen mode Exit fullscreen mode

Which returned all my partitions and their UUIDs including /dev/sda1 which is the EFI partition with my NixOS bootloader.

/dev/sda1: UUID="0B3F-2C1E" BLOCK_SIZE="512" TYPE="vfat" PARTUUID="b329461d-b3af-b446-9209-1e79653206ea"

Enter fullscreen mode Exit fullscreen mode

Now to add the menu entry for NixOS. First, mount the first drive's EFI partition. Add a connection point first:

sudo mkdir /mnt
Enter fullscreen mode Exit fullscreen mode

Then mount it. Note, your partition may be elsewhere, so nvme0n1p1 might not be what you need. Run lsblk to check.

sudo mount /dev/nvme0n1p1 /mnt
Enter fullscreen mode Exit fullscreen mode

Then find /mnt/EFI/refind/refind.conf and edit it. Add the following to the bottom:

menuentry "NixOS" {
    icon \EFI\refind\icons\os_unknown.png
    volume b329461d-b3af-b446-9209-1e79653206ea
    loader \EFI\systemd\systemd-bootx64.efi
    enabled
}
Enter fullscreen mode Exit fullscreen mode

Save, exit, and reboot to test! It worked for me, so now let's add a manual boot menuentry for windows too. This should be easy and for the most part consistent across devices. I have Windows 10 so I'm adding this:

menuentry "Windows 10" {
    icon /EFI/refind/icons/os_win.png
    loader /EFI/Microsoft/Boot/bootmgfw.efi
    enabled
}
Enter fullscreen mode Exit fullscreen mode

Styling

Now we'll style both Mac and PC at the same time. There are a few things I'd like to do.

  1. Make the rEFInd background black
  2. Use custom icons for NixOS, Windows 10, and macOS
  3. Hide the text labels for each boot option
  4. Hide the non-customized boot options
  5. Replace the extra options icons with consistent minimal icons
  6. Hide or modify the help text

One of the first things to do is to check the maximum resolution rEFInd can support. To do this, add a line to your refind.conf file with your monitor resolution like this:

resolution 2560 1440
Enter fullscreen mode Exit fullscreen mode

Booting into rEFInd will now look really clear or you'll get an error like I did. Apparently the my firmware only supports 4 graphics modes before an OS loads more drivers. I'm not sure how to add more, but I did see my Motherboard has had a few firmware revisions since I bought it, but I don't want to mess with that and risk my entire setup right now. Maybe another day!

Here's what I have available:

Mode 0: 800 x 600
Mode 1: 1024 x 760
Mode 2: 1280 x 1024
Mode 3: 1600 x 1200
Enter fullscreen mode Exit fullscreen mode

Unfortunately, none of these aspect ratios match my monitor. So I'm going to design my icons with the expectation that they'll be stretched out across my 16:9 aspect ratio. I'll set mode 3 since it's the highest resolution with resolution 1600 1200.

To get from 1600 to 2560 we multiply by 1.6
To get from 1200 to 1440 we multiply by 1.2

So if we have a 128x128 icon being stretched 1.6 wider and 1.2 taller, it will end up looking like a 204.8x153.6 image which will be stretched wide. Therefore, to have something appear like 128x128, I need icons that are 128/1.6 x 128/1.2, or 80x106.66.

I opened photoshop an created a PSD template to help me build the images I needed. The image dimensions need to remain 144x144 and 128x128, but the content inside needs to be reverse-scaled in proportion. My template looked like this:

Image description

And my actual icons ended up like this (You're on dev.to/forem dark mode right?):

Image description
Image description
Image description

For the background, I got a neato abstract image by asking dall-e for a logo featuring a wild splattering of 2 dimensional shapes of groovy neon colors, centered on a black background, with a few stylish pixelated defects arranged to imply a high forward velocity into the image. I stretched it out to two different sizes for my two displays and named it computer_.png (the first draft of my background image had a techno font of the word computer_ and I just kept the file name after scrapping that idea).

Here are the settings I needed to add to refind.conf:

For best screen resolution on PC:

resolution 1600 1200
Enter fullscreen mode Exit fullscreen mode

(Note: On mac, I didn't need to do this. I just made sure my background image was 3360x2100 since my retina display was 1680x1050).

For my black background and neato banner

banner icons_skewed/computer_.png
Enter fullscreen mode Exit fullscreen mode

To hide all the other non-OS boot option stuff

showtools
Enter fullscreen mode Exit fullscreen mode

To hide the hard drive icons and helper text

hideui badges,label,hints
Enter fullscreen mode Exit fullscreen mode

To add a white dot under the OS currently selected

selection_small selection_small.png
selection_big icons_skewed/selection_big.png
Enter fullscreen mode Exit fullscreen mode

And that's about it. On my mac, the resolution was different with retina display and all. So I have the line resolution xxx yyy there, but otherwise it's all the same.

Done!

That was honestly a lot more work than I expected. I also did a bit of research into patching my gigabyte mobo bios to support higher resolutions and found a very little guidance online on how to do that. In the end, I think the design is nice enough and I'm happy to be rid of that 90s web look. Now as long as none of my OS updates stage a "boot coup", I should be good to go.

Top comments (3)

Collapse
 
rubensibon profile image
Ruben Sibon

Hi Ray Harris, I would love to learn if you're still using this install six months later and if so, what your experiences are. I have the same 2019 MacBook Pro and also would like to dual-boot NixOS (+ GNOME). Is it something you can recommend?

Collapse
 
raymondgh profile image
Ray Harris

Hi Ruben. I'm still very excited about NixOS, but I can't say I've been using it much. I still have it set up on my desktop and personal laptop, but just haven't been on anything besides my work laptop lately. I've recently built a new gaming PC and am hoping to put a 2nd drive with NixOS on it to run some proton games there. As for the MacBook, I would NOT recommend pursuing a dual boot solution. I am actually starting my notes today on a blog post on how to clean up the whole mess and reset the mac to factory settings.

Basically Apple is working against us at every turn. They really don't want us dual booting. It's such a hassle too, especially with the touchbar (no more escape key), bad audio quality (not sure if there's a solution by now), and for me especially because my battery dies between uses, inability to boot osx without running disk 'first aid' all the time. I think I'm going to focus first on getting comfortable with a single NixOS environment on easy mode (my desktop) before branching out again to multiple devices

Collapse
 
rubensibon profile image
Ruben Sibon

Hi Ray, thanks for coming back to this! Good to know that you wouldn't recommend it at all. I already had a feeling that Linux on Mac was just never going to work with Apple's stance. I'll explore nixOS on other hardware and VMs.