20161105-arch_linux_install.md (9810B)
1 The first distro I ever installed was OpenSUSE, many years ago. At the time I didn't really understand what the different distros meant and so I just installed from a free disk I received with a magazine. 2 3 I quickly started playing around with a number of other distros including Fedora, Ubuntu, and Debian. Quickly I realised there was no "right" distro and it was all about choice. Fedora was the distro I ended up using for a number of years... until the introduction of Gnome3 and the GnomeShell. Straight away this wasn't for me, so I sought out alternative Desktop Environments. It was also at this opportunity that I decided to give Arch a try. 4 5 Even in the few short years I had used Linux I knew for certain this was for me and therefore I wanted to know more about it. Arch was a good choice because it enables you to get much more hands on. 6 7 Arch is not recommended for absolute beginners, but if you want to improve your understanding of how the OS works it is a good distro to play around with. Things may (will) break, but that is all part of the fun! 8 9 This guide details the steps I take to quickly run up an Arch install. Security is always something I consider and therefore I encrypt my root filesystem. A lot of the steps detailed below are taken straight out of the [official install guide](https://wiki.archlinux.org/index.php/Installation_guide). These steps are not intended to replace the information on the Arch wiki, this is merely my adoption of the process. 10 11 Pre-reqs: 12 13 - You should be comfortable with using the Linux command line as there is no GUI for this installation 14 - I use vi for editing the files in this guide. Feel free to use nano if you prefer 15 - Grab the latest [Arch ISO](https://www.archlinux.org/download/) 16 - Internet connection< 17 18 Boot from the ISO and select "Boot Arch Linux (x86_64)" 19 20 After the ISO has loaded you will be presented with a prompt 21 ``` 22 root@archiso ~ # 23 ``` 24 The first thing I tend to do is load the keymap for my UK keyboard. This is an optional step, but will help if you use certain characters when setting passwords (#, @, /, \, etc). 25 26 First show a list of all available QWERTY keymaps, then load the desired map 27 ``` 28 ls -l /usr/share/kbd/keymaps/i386/qwerty/ 29 loadkeys uk 30 ``` 31 The next step is to ensure you have a working internet connection. While this step is also optional I will be using an internet connection later on 32 ``` 33 systemctl start dhcpcd 34 ip a 35 ping -c 3 archlinux.org 36 ``` 37 _If you are unsure how to get wifi working check out my guide [here]()_ 38 39 It is advised to enable ntp (Network Time Protocol) to ensure the system clock is accurate 40 ``` 41 timedatectl set-ntp true 42 timedatectl status 43 ``` 44 I am only using one disk in this guide. Be careful when there are multiple disks attached to you system, make sure you specify the correct device, e.g. sda 45 ``` 46 lsblk 47 ``` 48 As mentioned security is pretty important. Before we continue we will write lots of random data to the disk so that it is completely wiped clean. This may take a while, so grab a brew! 49 ``` 50 dd if=/dev/urandom of=/dev/sda bs=1M 51 ``` 52 Once that is completed we need to create the partition table. We are only going to create two partitions, one for the boot partition and one for the rest of the disk. Later on we will use LVM ([Logical Volume Manager](https://en.wikipedia.org/wiki/Logical_Volume_Manager_%28Linux%29)) to break the disk down further 53 ``` 54 fdisk /dev/sda 55 ``` 56 You will now be in the fdisk utility, and you will see the prompt has changed 57 ``` 58 Command (? for help): 59 p (should be empty) 60 n 61 p 62 1 63 [return] 64 +512M 65 t 66 L 67 83 68 n 69 p 70 2 71 [return] 72 [return] 73 t 74 2 75 8e 76 p 77 w 78 ``` 79 Make sure the device now shows the two partitions, sda1 and sda2 80 ``` 81 lsblk 82 ``` 83 Format /boot partition 84 ``` 85 mkfs.ext3 /dev/sda1 86 ``` 87 Before we set up LVM on the second partition we need to encrypt it. We will be using LUKS (Linux Unified Key Setup) 88 89 First make sure the module is loaded 90 ``` 91 modprobe dm-crypt 92 ``` 93 The encryption setup is fairly standed. We are using "aes-xts-plain64" cipher for LUKS. We'll include the `-y` option to verify the passphrase (by asking twice) and we set the key size to 512 bits (this argument must be a multiple of 8) 94 ``` 95 cryptsetup -c aes-xts-plain64 -y -s 512 luksFormat /dev/sda2 96 YES 97 (enter passphrase twice) 98 ``` 99 Now we open the encrypted partition under `/dev/mapper/lvm`. Then add it as a physical volume group on the whole partition 100 ``` 101 cryptsetup luksOpen /dev/sda2 lvm 102 (enter passphrase) 103 pvcreate /dev/mapper/lvm 104 pvs 105 vgcreate vg_arch /dev/mapper/lvm 106 vgs 107 ``` 108 For my logical volumes I have sized the partitions based on various best practice rules that I have picked up over the years. This is by no means a strict rule, but it is advised to split up `/boot`, `/var`, and `/home`. The `/boot` directory has been placed on a separate partition due to the encryption we're going to use. We will also create some [swap space](http://linuxjournal.com/article/10678). In this example I am using a 64GB disk 109 110 - /boot = 512MB 111 - /var = 10GB 112 - swap = 8GB 113 - / = 20GB 114 - /home = 25.49GB 115 116 Create the logical volumes, create filesystems on each volume and ensure the swap space is active 117 ``` 118 lvcreate -L 20GB -n lv_root vg_arch 119 lvcreate -L 10GB -n lv_var vg_arch 120 lvcreate -L 8GB -n lv_swap vg_arch 121 lcreate -l +100%FREE -n lv_home vg_arch 122 lvs 123 mkfs.ext4 /dev/mapper/vg_arch-lv_root 124 mkfs.ext4 /dev/mapper/vg_arch-lv_var 125 mkfs.ext4 /dev/mapper/vg_arch-lv_home 126 mkswap /dev/mapper/vg_arch-lv_swap 127 swapon /dev/mapper/vg_arch-lv_swap 128 ``` 129 We are going to mount the root filesystem under `/mnt` then create a few directories for the other volumes 130 ``` 131 mount /dev/mapper/vg_arch-lv_root /mnt 132 mkdir /mnt/{boot,var,home} 133 mount /dev/sda1 /mnt/boot 134 mount /dev/mapper/vg_arch-lv_var /mnt/var 135 mount /dev/mapper/vg_arch-lv_home /mnt/home 136 df -ah 137 ``` 138 Before we install Arch we need to configure the mirrorlist. As I am currently in the UK I will generate a relevant mirrorlist. This is where an internet connection comes in useful. We will use the Arch [mirrorlist generator](https://www.archlinux.org/mirrorlist/) and `wget` to pull it onto our system. By default the lines are all commented out so we'll use `sed` to uncomment the correct lines. Then we will switch the current mirrorlist with our new one, it is good practice to always make backup copies of configuration files before replacing or modifying them 139 ``` 140 wget -O mirrorlist "https://www.archlinux.org/mirrorlist/?country=GB&protocol=http&protocol=https&ip_version=4&use_mirror_status=on" 141 cat mirrorlist 142 sed -i 's/^#S/S/g' mirrorlist 143 mv /etc/pacman.d/mirrorlist /etc/pacman.d/mirrorlist.bak 144 mv mirrorlist /etc/pacman.d/mirrorlist 145 ``` 146 Now we can install the base Arch packages 147 ``` 148 pacstrap /mnt base base-devel 149 ``` 150 Generate fstab, setting the `-U` option to use UUIDs. The `-p` excludes pseudofs mounts 151 ``` 152 genfstab -p -U /mnt > /mnt/etc/fstab 153 cat /mnt/etc/fstab 154 ``` 155 To configure the rest of the system we're going to use [chroot](https://en.wikipedia.org/wiki/Chroot) to change the root directory. This makes it easier to configure 156 ``` 157 arch-chroot /mnt 158 ``` 159 You will notice that the prompt has now changed 160 ``` 161 [root@archiso /]# 162 ``` 163 Set a symbolic link to the timezone file for your city, in this case London 164 ``` 165 ln -sf /usr/share/zoneinfo/Europe/London /etc/localtime 166 ``` 167 Set up the locale settings, in this case we are using en_GB 168 ``` 169 vi /etc/locale.gen 170 ``` 171 Remove the # at the start of the "en_GB.UTF-8 UTF-8" line 172 Save and quit 173 ``` 174 locale-gen 175 echo LANG=en_GB.UTF-8 > /etc/locale.conf 176 export LANG=en_GB.UTF-8 177 ``` 178 We need to set the keymap so that it sets on boot 179 ``` 180 echo 'KEYMAP="gb"' > /etc/vconsole.conf 181 ``` 182 Pick a hostname that is relevant, or clever, or funny 183 ``` 184 echo gibson > /etc/hostname 185 vi /etc/hosts 186 ``` 187 Navigate to line beginning with "127.0.0.1" and append your hostname to the end 188 Save and quit 189 Ensure dhcpcd is enabled on boot 190 ``` 191 systemctl enable dhcpcd 192 ``` 193 Next we need to install and configure the [GRUB](https://en.wikipedia.org/wiki/GNU_GRUB) bootloader 194 ``` 195 pacman -S grub 196 y 197 grub-install --target=i386-pc /dev/sda 198 vi /etc/default/grub 199 ``` 200 Navigate to line GRUB_CMDLINE_LINUX="" 201 Change to the following (replacing `vg_arch` with your volume group name) 202 ``` 203 GRUB_CMDLINE_LINUX="cryptdevice=/dev/sda2:vg_arch" 204 ``` 205 Save and quit 206 ``` 207 grub-mkconfig -o /boot/grub/grub.cfg 208 vi /etc/mkinitcpio.conf 209 ``` 210 Navigate to the following line 211 ``` 212 HOOKS="base udev autodetect modconf block filesystems keyboard fsck" 213 ``` 214 Add in the hooks "encrypt" and "lvm2" after "block" 215 ``` 216 HOOKS="base udev autodetect modconf block encrypt lvm2 filesystems keyboard fsck" 217 ``` 218 Now we generate the initial ramdisk 219 ``` 220 mkinitcpio -p linux 221 ``` 222 We must set the root password - make sure it's secure! 223 ``` 224 passwd 225 (no visual output - don't worry!) 226 vi /etc/sudoers 227 ``` 228 Navigate to the following line and remove the # at the start 229 ``` 230 # %wheel ALL=(ALL) PASSWD: ALL 231 ``` 232 Save and quit - you may need to force write with `:wq!` (in vi) as the file is read-only. 233 234 Finally we need to add a standard user. This command will create a "users" group for the user and also add them into the "wheel" group so that they can run the `sudo` command. Don't forget to set a strong password! 235 ``` 236 useradd -m -g users -G wheel -s /bin/bash pyratebeard 237 passwd pyratebeard 238 exit 239 ``` 240 That's it, all done. We have exited back to the ISO and you should see the prompt change. All that is left is to unmount the system and reboot 241 ``` 242 umount /mnt/{boot,var,home} 243 umount /mnt 244 reboot 245 ``` 246 Remove the ISO media and the system should boot off your new Arch Linux install. 247 248 Enter the encryption passphrase we set when prompted. 249 250 Login as your user account. 251 252 Congratulations, you've successfully installed Arch Linux with an encrypted root filesystem. 253 254 I will be doing another log soon which details how I set up my system, including the Window Manager, various applications, and the all important dotfiles! 255