Hello, this is my second blog post. In this blog i will be giving a tutorial on how to install ArchLinux. What im going to do is create a bash shell script with all the nessasary commands needed to install arch, then i will test and trouble shoot it using a virtual mashine until it works smoothly. I will mostly follow the pecedure layed out by Archlinux installation guide wehn creating this script. I will do my best to make it as simple as possible, I also plan on making a youtube video explaining everything typed here.
1. Step One.
I would recommend creating a directory(folder) or a git repo for this project. If you are in linux and want to create a directory use the following command, just replace “my_new_directory” with what you want to call it.
The file layout for this project is as follows, Just create these files.
NOTE: make sure that your text editor of choice is set to LF (unix line endings) and UTF-8 this will mostly not be a problem if your writing this on linux, however if your using Windows to write this I’d recommend using Atom or Notepad ++.
Open both base.sh and post.sh to initialise the script using a Shebang as follows, i will also add set -e this option makes the shell script error out whenever a command errors out. It’s generally a good idea to have it enabled most of the time. but this is optional.
Just to give a bit more explaining on the shebang above which is the #!, this tells the script where to find the bash interpreter, typically people use #!/bin/bash but using #!/usr/bin/env bash lends you some extra flexibility on different systems.
we need to guarantee that the system is in UEFI mode as the rest of this script depends on it. If the archiso is ran in UEFI there will be a efi directory in the /sys/firmware, example the following path must be true for it to me UEFI,
To test this in our script we can use the operator -d to test if it exists and use an IF statmemt to allow to program to run or not. You can just copy the following piece of code and add it on to the base.sh,
2. Step Two.
Lets now continue editing the base.sh and create a few variables. in case you don’t know hwo to crate a variable in bash it works like the following,
So the variables we will need to add to the base.sh are as follows,
In the above variables you can set them all to suit your own preference. This in IMPORTANT, the DRIVE variable has being assigned to “/dev/sda” above, you can change this if you want, but i recommend not, although the script that we are making will wipe all the contents on the “/dev/sda” drive, i would also recommend disconnecting any other drives in the computer when doing this install, no need to worrie about that just yet, the following will show you how you can see what drives are which.
Heres an example of the output of the lsblk command.
I will also give a closer look at the PKG variable, all the packages that assigned are optional, i have picked these as they are what i wanted, you can check out your options here, if you dont understand this dont worry too much, just use what i have provided above.
We must set up a few last things before moving on to step three, now lets sync the clocks to the systems local time using the following commands,
Also we must set up the keyboard to match the variable up above, its done as simple as this,
3. Step Three.
We will create three Partitions out of the DRIVE,
I am going to use a tool called sgdisk. First we must wipe the drive and reformate it using the following,
And now segergste the drive,
So that might be alot to take in at first so ill give little explaination on how sgdisk works, operators im using and what they do,
Zap all, this is used to destroy GPT and MBR data stuctures and then exit, basically wipping and formatting the disk
set alignment, aligns the start of the partitions to sectors that are multiples of this value, this allows obtain optimum performance with SSD drives
clear, Clears out all Partition data
typecode, change a single partitions typecode, uses two-byte hexadecimal number
new partition, Create a new partition, you enter a partition number, starting sector, and an ending sector
change name, changes the GPT name of a partition, this is encoded as a UTF-16,
Also after the EFI and ROOT partitions i use the command mkfs.fs which means make file system and then tell it what file system you want to make e.g ext4 for stangered partitions like root or if you wanted to make home a seperate partition to root, only use vfat for the EFI partition
before we move onto the next part we must mount the partions to there relevant locations as follows,
Notice how the ROOT and EFI partitions are mounted to /mnt, this is short for mount, this allows you to use the tools on the existing system to setup the file structure for the new system before using it. Also you have to manually create the /mnt/boot/efi as seen above.
4. Step Four.
Downloading packages and installing,
First we will install reflector, this will allow us to download from the most efficient mirrors for the fastest download,
Also in ArchLinux the default package manager is Pacman as seen above. Now its time to install the main system,
The most important package to install is the base, we have that in the PKG variable up above. Now lets create the Fstab, which is what tell arch what drives to mount when it starts up, installing fstab is done by the following,
5. Step Five.
Final Configuration for base.sh,
To finish off the base.sh script we must do some configurations and then arch-chroot (this means change root) to the new root ROOT directory we created, But now we must configure the network settings,
Now we must set a console keymap by adding youe KEYMAP settings to /mnt/etc/vconsole.conf,
We can set the hostname now by adding the HOSTNAME variable to the /mnt/etc/hostname,
To set the loaction to your own country you will have to follow my example, it come defaultly set to US but im my example i show how to change it to ireland, its the same for everyother country, im using a editor called sed in this and using the operator -i to insert text,
To learn more about locale go here Now to set the time zone, this example used ireland again,
Next i will enable the network services with systemctl to that it starts on startup,
We must also install grub with the following,
Lets now go a head and add in the arch-chroot and make it run post.sh and we must aslso copy these files over to the new ROOT,
In the post.sh we will be configuring the root password and username and password so thats why we are carrying these variables over. Now to finish off the base.sh we must unmount our drives and give a finnishing note to tell the user that they are to restart there pc.
And now for a simple finishing note,
Finally, we have the base.sh script finished.
6. Step Five.
Configuration on the post.sh,
Now open your post.sh that you have make earlyier and aslready initialised, first we must take in the variables we sent to it in the base.sh, make sure to have them at the same order that your put them in, like this,
Lets do some updating,
Add this to give a splash of colour,
Now we will set up the user details and passwords for both user and root,
Add this for creating missing directorys,
Now lets give user sudo access,
Next build directorys and set there permissions, the chmod is used to set permissions, the chgrp is used to change the group and setfacl modifies the access control list (ACL),the operator -m modifies the ACL specified by the EntryOrFile,
Finally we will edit the sudoers.d again and allow wheel group access to sudo with password,
Yay!! we have just finished creating the scripts needed to install ArchLinux,