Installing a bootloader in arch

Sacha
5 min readAug 27, 2018

--

If you are like me, and take joy in installing a new Linux distro every now and then chances are you may have found yourself wanting to install arch. Which is a really nice experience for learning how a lot of stuff works down in your system and having a fun time in general.

Pulling the bootstraps

If you are, also, like me then chances are you may have never before installed an operative system by only using the command prompt, even less a bootloader and panicked when you saw this at the installation guide:

But fear not, as I have already stumbled upon many errors, redone this process at least four times and am now writing this so you won’t have to suffer like I have. I’ll tell you a tale about how to install some nice bootloader.

Preparation

First things first, we need to create our boot partition, which is where the bootloader will reside for that I have a simple five steps plan to get into action:

Disclaimer: I know a lot of this stuff is in the arch installation guide but to make this guide complete I felt like I needed to add it.

Step1: Find the hdd name on the directory tree.

We must first identify our hdd’s location in the directory tree, we can do so by using fdisk -l if you have more than one hdd then all of them will have a different name.

In my case /dev/sda/ will be the drive to partition, it is a very common name so it might as well be yours too.

Step2: Check the partition table

We’ll access the disk’s partition table by running the next command fdisk /dev/sda which will send us into the fdisk console. You can have a MBR or a GPT partition table, for this example I’ll be creating a new GTP

Step 3: Create the EFI or BIOS partition.

To add a partition just input the command n , an EFI partition should be 512M long to add and reside within the first 2.2T of your disk. Leaving the default for partition number and first sector should suffice.

Creating the partition

Step 4: Change the partition type

Now this thing is easy to overlook, but it’s a rather important part, see this message?

right here

That thing right there, it’s important, we don’t need a Linux filesystem, we need an EFI partition. You can see all the different types of partitions with the l command.

These types differ whether you are using GPT or MBR.

Knowing that we need a partition type 1 we can now change it by using the command t :

All set

Step 5: Write the partition table and hope for everything to work.

After these four steps you should be a master partitioner by now, so you can add as many partitions as you like or think you will need ( you’ll need at least one more for the root directory). When you are done you simply input the command w and cross your fingers.

This covers the UEFI way of doing it, if you need to do it the BIOS way you need a BIOS partition which is 1M long and has “BIOS boot” partition type in GPT or “Empty” in MBR.

Now that the partition table is up and running, we need to format our new shiny EFI partition with a FAT32 filesystem mkfs.fat -F32 /dev/sda1 , I’ve created a new partition for the root directory and mounted them this way:

/dev/sda2 -> mnt/
/dev/sda1 -> mnt/boot/

If you are happy with your configuration you can now proceed with all the installation stuff, getting the base packages, chrooting, configuring the fstab, etcetera etcetera. When you are done with that it’s time for actually installing the bootloader.

Doing the thing

Everything you have don until now was just a preparation (and the actual installation of the OS (which is not explained here but is a must do)), now’s time for the real deal, and the real deal is rather easy just a series of commands that, if executed right, will do the job:

pacman -S grub os-prober

Fetches grub (our bootloader of choice) and os-prober. Os-prober is used for scanning the disk for other OS and adding them to the grub configuration so it’ll not interfere with them and make it easy for you to boot other previously installed OS if they exists.

Edit: if you are running a 64-bit system, you may want to install efibootmgr, as grub-install may not work there

grub-mkconfig > /boot/grub/grub.cfg
grub-install --target=i368-efi --efi-directory=/boot/ --bootloader-id=GRUB

The first one basically creates the configuration file for grub, nevermind if you get a warning like “failed to connect to lvmetad”. The other is the actual installation ,efi-directory=/boot/ is where the efi partition is mounted, and --target=i386is the target system, in this case I have a i386 architecture with efi configuration, you can check all the options available with ls /usr/lib/grub .

That should be all, congrats.

I hope you have some nice boots from now on

Afterword

You may argue that anyone willing to install arch by themselves is capable enough of investigating and finding about all this stuff on their own( wich is part of the appeal of arch in the first place ), and anyone really needing a basic guide like this wouldn’t even think about installing an OS like arch. I just felt like this was a part of the process I struggled with and wanted to share it, maybe it’ll be useful to someone who overlooked one of these tiny steps and stumbles upon this very specific article.

Anyhow I hope you’ve had a good read, any inputs are welcome.

See you next time :DD

--

--

Sacha

Fullstack developer, computer science enthusiast and part time doodler.