Arch Linux install guide (long version)

0
Arch Linux install guide (long version)

Introduction

I’m not sure if you’ve read my previous post about why I chose Arch Linux. If you didn’t and you really want to know what I’m talking about then this is for you.
  So either you are like me and want to jump in where is hurts the most, or you are a semi-experienced Linux user who wants some change of scenery. Either way you are looking at this article because you thought about installing Arch Linux. You’ve probably heard that it is pretty hard. Well, it’s not hard – it’s just harder. I personally had a few installs before I got it right. Moreover, I didn’t really feel like reading all too much, and how hard could it be? I guess I’m more a visual kinda of guy. So I looked at Youtube videos for hours. Sure it helped somewhat but if I had read the guides/manuals I would have been able to get it right much earlier. I guess the main problem was that many manuals cover too much or too little for me to get a complete understanding of the process. But then again, when I look down this post, I’m not sure if this covers too much or too little – alas it consists of the information which I would give to a person if he/she asked how to install Arch Linux. Anyway, it’s sad Arch has this reputation because it’s actually not that complicated even for a n00b such as myself.

So what do you need?

1. Almost any computer will do. However, it preferable 64-bit.
2. Internet (cable, wifi, or even a smartphone)
3. An immense urge to learn a lot
4. An USB-stick
5. Persistence and patience
6. A cold beer (make that 3)

What I’ll cover in this guide

1. Preamble – A word of advice
2. Creating the Arch Linux USB-stick
3. Getting ready to install
4. Understanding UEFI and BIOS
5. Partitioning
6. Configuring the install in chroot
7. Postamble – Good luck

Preamble – A word of advice

It’s worth noting that Linux is kinda unforgiving. Therefore, I would like to advice you to check what you are writing in your commands. My first few attempts failed because I shrugged at error messages or didn’t get the commands right. So, check your commands and if there are any errors, please google them.
  This guide works, but only if you are paying attention. Before you start this venture note that Arch Linux can be annoying, and you could lose all hope one or two times but I promise it’s worth the effort. Moreover, I know that this is a very long post, but that does not mean that the install process takes hours. When you have tried this a couple of times it takes about 15 minutes or less. Okay. Let’s do this!

2. Creating the Arch Linux USB-stick

First you need to download the Arch Linux image here. Place the downloaded file somewhere where you can find it again! Second, you need an USB-stick. Found it? Cool. Lets proceed. Now, there are like a million different ways to do this and many of them are clearly explained several places on the internet, so I’ll explain a simple approach to get you started. This approach requires Linux and a terminal. Plug in the USB-stick and start a terminal. List your devices:
lsblk

Note that the drive “base” is called something like sdX where X represents a letter assigned by your system. It could be sdb or sdc ect. Rule of thumb – check the size of the drive to determine which one is the USB. Found your drive? Great! Notice that the coming command still has the X which you need to replace with your own correct letter. “path/to/archlinux.iso” should also be replaced with the location where you downloaded the archlinux.iso:
dd bs=4M if=/path/to/archlinux.iso of=/dev/sdx status=progress sync

There you go! Now you have a working bootable USB-stick full of Arch. Easy. If you want to read more about the subject then check out this link which also will explain how to create the USB in Windows or OSX.

Getting ready to install

So plug in the USB-stick and reboot your computer. When the computer boots you need to be sure, that it has USB-boot enabled. Therefore, you should check the bios-config. The shortcut key to enter the bios could be anything, so you have to do your own research on this. E.g. on my Thinkpad, I need to press F12 to enter bios at boot. However, often the key you need to press is shown somewhere on the screen when your pc starts. When you have enabled USB-boot and the computer starts, you should be greeted with a simple Arch Linux screen. Congrats – you have made it quite far already! Choose the first option on the black and blue Arch Linux-boot screen.
  So, the first “surprise” is that there is no Graphical User Interface (GUI). Only a black empty console. No help, no hints – no nothing! First, I start by setting up the right layout for my keyboard since Arch expects you to be American. Well, I’m not, so I have a different keyboard layout. Therefore my first command is:
loadkeys dk

“dk” is for Denmark, and since I’m Danish this makes sense. Now my keyboard is working as expected and I can proceed to the next step – setting up the partitions for Arch Linux.

Setting up internet access

Now the next thing killed me a few times. If you don’t have internet access then it’s impossible to install Arch since the whole system will be downloaded during the installation. Therefore, we need to make sure, that we have some of that sweet internet-sauce
ping -c 3 google.dk

Cabled

This command should reply with 3 successful pings. If it does not, then run the command
systemctl start dhcpcd

Wifi

This will turn on DHCPCD which could enable your cabled internet. If you are on wifi, then you need to connect by typing
wifi-menu

Find your network and connect with the correct password

Smartphone as a last resort

If all fails, then you could still tether with your mobile. This is not the best solution, but it is possible. Turn internet sharing on and plug in the USB to your computer. I have never used this but it works. Trust me. However, I would rather connect a cable from my modem or router.

Understanding UEFI and BIOS

Now, here is our first Arch Linux “problem”. You need to find out if your computer has and old BIOS or if you have a newer UEFI/EFI. Yeah, I know right, but this will influence how you need to setup your harddrive. There are several ways of finding out. Either google your motherboard/laptop or run this command:
ls /sys/firmware/efi

This command above will show if Arch has booted with UEFI, if the command returns anything it means that the computer has booted in UEFI-mode. This means that you have UEFI/EFI – congrats. If nothing happens then you are probably using a computer with BIOS. Note if you are on a Mac, then you have UEFI for sure. If you want to know more about this then check out this link.
  Now for what it will mean for you. When your computer starts, it asks: “so.. What operating system should I choose” and here you need a bootloader to redirect it to Arch, Windows, Ubuntu, or something else. There are several different bootloaders. You need to choose the bootloader depending on what you have and what you want to do. So, if you have a Mac and you want to dualboot with OSX then you’ll need refind-bootloader. If you have BIOS then you need to use GRUB but if you have UEFI then you could use systemd-boot instead which is faster – but you could also use GRUB. This confused me a lot in the beginning but I started by ditching all other operating systems and only had Linux on my Thinkpad. Moreover I just wanted it to work and then later focus on speed – which is the easier choice. Therefore, this guide will not explain how to dualboot with windows or OSX – but note that it can be done. No worries. However, if this is your thing, Arch is not the easiest solution – I would recommend e.g. Manjaro, which takes care of some of the more complicated settings. Note that there are some additional complications with dualbooting. I can’t go into much detail since I ditched everything else and just went with Arch. However, there have been some problems with bootloaders if either Windows or Arch have an update which changes something in the bootloader. The more you know.

Partitioning

Now I know that this next paragraph is kinda long and boring, but stay with me and it’ll be much simpler later on. You remember that part about the UEFI? Well if you found something, then you need a small boot drive, a swap and root. If your system has a BIOS then you don’t need to create a boot partition but swap and root will suffice. Wait a minute. What is this “swap” and “root”?
  Swap is space on your harddrive where the pc can offload the RAM if there is too much going on or if you want to hibernate your system. My system has 8GB of RAM and I have never seen my system utilizing all of it and therefore, I only keep my swap to ensure that I can hibernate my laptop. Actually, currently Arch is chugging along with about 2.4GB RAM in use, but most of it is probably for Chromium. First time i booted Arch was using around 50MB of RAM and curently without any browser it’s about 150MB with GUI and Vim. When hibernating, all of the data from your RAM is written to the swap on the harddrive and then the computer can shut down and not use any power at all. This means that even if it runs out of power you can return where you left off when you are able to power the laptop again. So, if you have less than 2GB of ram or want to hibernate your computer – you need swap. If you have more than 4GB and never want to hibernate – then don’t create a swap. How large should the swap be? Well, there is no clear answer. Since my RAM never exceeds 3GB, there is no need to have a swap of more than say 4GB – but I choose to allocate the same size as my RAM – 8Gb – just to be on the safe side. So what about root?
  Root is your main harddrive. If you open “My Computer” on windows this would be equivalent to C:\. So this is where you store everthing. Some prefer to make additional partitions so they can delete the OS but keep their personal files, which are all located in /home/. But let’s not go into that. We want to keep it simple – yeah!

“Christian, your post so far has not helped my setting up Arch Linux at all. So far it has only confused me further!”. Yeah I know, and I’m sorry. Most of the stuff I’m explaining is things that I would have liked to know, when I started out, so maybe it’ll get you through faster. Moreover, I’ll specify in the following what you should do, whether you have BIOS or UEFI which would have made my life way easier during my first attempts. You’re welcome.

Partitioning for BIOS ONLY

First we need to partition our drives. I suggest you create 2 partitions to get up and running. 1 drive will be for the swap and the rest will be for root. First you need to chose a disk to install to, and the following command will show all disks in your system:
lsblk

Note that your drives are labeled “sda, sdb, sdc” and so on. As I explained earlier this is the “base name” of your drives. When we start to make additional partitions then they will be called “sda1, sda2” and so on. I’ll write “sda-number” for the rest of this article and you have to put in the right letter instead of “a” if you need to. If you are not contemplating a dualboot then the numbering should be the same as my examples. Let’s roll.

Start parted (note that the console will change to “parted”)
parted /dev/sda

See what’s on your disk by printing an output
print

If you have any partitions then they are numbered, so in the following command replace X with the number which you want to delete. Please delete all of them. Notice this will remove EVERYTHING from your drive. It’s only Arch from now on!
rm X

Create a swap-drive (chose the size of your ram)
mkpart primary linux-swap 1MiB 8GiB

Create root-partition (The 100% means that you chose the rest of your disk)
mkpart primary ext4 8GiB 100%

Set the boot-flag on for the root-partition
set 2 boot on

Ask for a print of everything to ensure it’s as expected
print

Seems alright? Cool. Quit out of parted
quit

Again let’s check that the drives are set up correct. Note that the drives have gained two partitions “sda1 and sda2”
lsblk

Now we need to format the swap drive
mkswap /dev/sda1

And start the swap
swapon /dev/sda1

Then the root partition
mkfs.ext4 /dev/sdX2

Now lets mount the root-partition in the /mnt.
mount /dev/sda2 /mnt

The next section is only for UEFI, so jump to “Configuring the install in chroot”.

Partitioning for UEFI ONLY

I’ll keeps this shorter than the latter, since most of the same logic applies. In this case we need three partitions. First a boot, then swap and lastly root.

Start parted (note that the console will change to “parted”)
parted /dev/sda

See what’s on your disk by printing an output
print

Delete all partitions on your selected disk.
rm X

Create a boot partition. 100MB should be enough, but we wont take any chances.
mkpart boot fat32 1MiB 256MiB

Make it bootable
set 1 boot on

Create a swap-drive (chose the size of your ram – in this case it’s 8GB)
mkpart primary linux-swap 256MiB 8256MiB

Create root-partition (The 100% means that you chose the rest of your disk)
mkpart primary ext4 8256MiB 100%

Ask for a print of everything to ensure it’s as expected
print

Seems alright? Cool. Quit out of parted
quit

Again let’s check that the drives are set up correct. Note that the drives have gained three partitions “sda1, sda2, and sda3”
lsblk

First format the boot partition
mkfs.fat -F32 /dev/sda1

Now we need to format the swap drive
mkswap /dev/sda2

And start the swap
swapon /dev/sda2

Then the root partition
mkfs.ext4 /dev/sda3

Now lets mount the root-partition in the /mnt.
mount /dev/sda3 /mnt

Create a directory for your boot partition
mkdir /mnt/boot

Now, we need to mount our boot partition.
mount /dev/sda1 /mnt/boot

For both BIOS and UEFI

Now we can install the Arch Linux distribution
pacstrap /mnt base base-devel

Let this run for a while. This could take some time (First beer)

Completed? Faster than expected then. Good! Let’s move on. We now have the base system installed and we need to configure a few things before we can boot into our new install. First let’s tell Arch how we have set up our drives
genfstab -U /mnt >> /mnt/etc/fstab

If you want to make sure that your partitions are correctly set up in Arch run this preview command:
cat /mnt/etc/fstab

It will show you the contents of the textfile that we just created. I know this looks kinda odd, but it lists all your new partitions and if you have BIOS then there should be two and for UEFI you should have three. It’s all good? Great!

Configure the install in chroot

Now we can chroot into our installation and setup a few things. Don’t know what chroot is? Me neither but think of it as you have a fully working system on your USB-stick and that is the only thing that you have used this far. Now we need to jump from the USB-stick and into the installation which we downloaded through pacstrap (the matrix-thing).
arch-chroot /mnt

Okay. You’re doing great. Hang in there! Now we need to set a few simple things. First we need to set the language for our installation. Now, this also confused me, so let me explain. The language which you will choose in a moment will be the language that all messages in the terminal is displayed as. This means that if I choose Danish and get an error, it will be in Danish. Same thing with any other language. Moreover, there is also some other regional stuff which I’m not really clear on. However, I like my language to be English because it soo much easier to google if you know the exact error message, but the regional stuff still matters. And that’s what confused me – the language files consist of more than one language. Yeah. Let’s open the file and maybe it’ll make more sense.
nano /etc/locale.gen

There is a lot of languages and some of you may want your own language. In my case that would be da_DK.UTF-8. However as I want to the language to remain as English and my region to be Danish I choose en_DK.UTF-8. To select a language you simple delete the hashtag “#” in the left side of the screen and save by pressing ctrl+o. Please do so now. Then ctrl+x to quit.

Then run the following command
locale-gen

And tell the system to acknowledge your chosen language. Note I’m using the English-Danish in this instance.
echo LANG=en_DK.UTF-8
export LANG=en_DK.UTF-8

Now you need to tell the system which timezone you are in. The easiest is to use this command
tzselect

Now, if you used wifi to install Arch you will need some additional applications when you boot up again. Therefore, you should install the following
pacman -S wpa_supplicant wifi-menu dialog

You should be all good now for wifi.

Now for the bootloader
pacman -S grub

This part is only for BIOS

To install and configure GRUB give Arch the following commands. Notice that the o is an o as is OH MY ARCH!
grub-install --recheck --target=i386-pc /dev/sda
grub-mkconfig -o /boot/grub/grub.cfg

This part is only for UEFI

To install and configure GRUB
grub-install --taget=x86_64-efi --efi-directory=/boot --bootloader-id=grub
grub-mkconfig -o boot/grub/grub.cfg

Setup the hostname (name of your computer)
echo arch-box > /etc/hostname

Set the password for the root user (the admin)
passwd

All done!

Okay. All we need to do is get out of chroot and boot the machine. We are sooo close
exit

Unmount the /mnt
umount -R /mnt

Then shutdown your computer
shutdown now

Postamble – Good luck

Now you can unplug the USB-stick and you can start your computer again. Hopefully this guide has helped you install Arch Linux. Phew, what a ride! I know it has been a long guide. Sorry about that, but I had soo much trouble with this stuff that I really wanted to explain in detail what goes on. Maybe I should make a shorter guide?
  My next post will cover what you need to do to get a working GUI plus a few applications to get you started. Hopefully you’ll, like me, also feel a bit out of place when a GUI is installed – after all that time in the terminal – right? The terminal is really a strong tool and we’ll need I would advice you not to use it as much as possible.
  Okay. That’s it! Please drink the remaining two beers.

LEAVE A REPLY