--- title: 01 Base description: published: true date: 2024-02-23T15:26:55.562Z tags: editor: markdown dateCreated: 2023-04-28T05:21:30.128Z --- # Creating the Bootable USB First we need to download the latest version of the Arch installation media Open a webbrowser and go to https://www.archlinux.org/download/ Here you can download the latest image, I recommend using the Torrent or Magnet link, But if you don't have a torrent client you can scroll down for HTTP downloads. Wait for the download to finish. Next we need to burn the ISO file to an empty USB If you are already on Linux you probably know how to flash an image to USB, if not try to right click the .ISO file and open with image writer, Just select the right drive and click write/flash/revert If you are on Windows I recommend downloading Etcher https://www.balena.io/etcher/ Just download the portable version or install the normal version and open the program Select the .ISO file as the image, The USB as the drive and click flash After it is finished you should have a bootable Arch USB. # Booting the USB Next we need to boot the USB drive, We need to get in the BIOS for that. Turn off the device and put the USB in the device and keep pressing f2/Del/etc while turning it on to get into your BIOS, Most of the times you will get a screen where it tells you which button you need to press to enter the BIOS When you are in the BIOS Navigate to the boot screen and make sure the USB is on top. In most cases you can change their priority with F5/F6 or +/-. Press F10, select yes and press enter to save the settings and reboot, Now you just have to wait untill you are logged in as the root user on the arch iso # Check your boot mode Run the following command to see if you are running in UEFI mode ls /sys/firmware/efi/efivars If it shows you a bunch of filenames you are in UEFI mode. If you get an error you are in BIOS mode. If you are sure your system has UEFI disable legacy boot mode or force UEFI in the BIOS. If you can not get the USB to boot into UEFI you can use the legacy mode. Remember which boot mode you use, It will be important later on. # Set your Keyboard Layout for the installation If you use US International as your keyboard layout you can skip this step. To list all available keyboard layouts run localectl list-keymaps navigate with the arrow keys to choose the right keyboard layout for your keyboard when you made your choice press q to quit and run the following command with your keyboard layout loadkeys layout for Turkey layout would be replaced with trq for German it would be replaced with de-latin1 If you have set a custom layout remember which layout you set, It will be important later on. # Make sure you have a network connection If you are wired you can skip the WiFi step But test the connection either way. If you use Wifi or have no option to connect a cable run the following command iwctl You should spawn in an alternative prompt, run the following command to check for devices device list Remember the name of the device and use it in the following command to let it scan for networks station wlan0 scan Then run the following command to display the scan results station wlan0 get-networks And finally you should be able to connect using the Device name and the Network Name (SSID) station wlan0 connect SSID Simply enter the password of your wifi if it asks for it. then exit the alternative prompt with the following command exit run the following command to test your network connection. ping archlinux.org If you get a ping back hit CTRL + C and go to the next step It your network device is powered down it is probably soft blocked, in that case run the following command rfkill unblock all # Make sure the time is set correctly Not having the right time will prevent your system from installing anything so run the following command timedatectl set-ntp true Check which disk you want to install Arch on Run the following command to list all connected drives fdisk -l Check which disk you want to install on, **/dev/sda** or **/dev/nvme0n1** for example, I am going to use **/dev/nvme0n1** from this point on, Remember or write down the drive you want to install on and always replace **/dev/nvme0n1** with the right drive. # Partitioning the disk (UEFI) **Only do this part if you are in UEFI boot mode.** Start fdisk with the drive of your choice. fdisk /dev/nvme0n1 Now we are in fdisk, you can press m for help in the program, But if you do exactly as below everything should be alright #### Disk Options 1. Hit d and then enter untill there are no more partitions left. 2. Hit g Then press enter, This will make it a gpt disk #### Boot Partition 1. Press n and then enter to make our first partition 2. press 2 and press enter to give it partition number 2 3. just press enter to put it in the beginning of the disk 4. type +2G to give it 2GB for the boot partition and press enter 5. press t and press enter to set the type 6. skip this step if 2 is preselected otherwise, press 2 and press enter to select the second partition 7. type 1 and hit enter this will make the second partition an EFI partition. #### Swap Partition 1. press n and press enter to create our swap partition 2. press 3 and press enter to give it partition number 3 3. press enter again to put it next to the previous partition 4. type +8G to give it 8GB swap, If you have less ram I would recommend making it equal to your ram, So +4G if you have 4GB Ram. 5. press t and press enter to set the type 6. press 3 and press enter to select the third partition 7. type 19 and hit enter this will make the third partition a Swap partition. #### Root Partition 1. press n to create our final root partition 2. press 1 and press enter to give it partition number 1 3. press enter again to put it next to the previous partition 4. press enter again to give it the remaining space on the disk. 5. press t and press enter to set the type 6. press 1 and press enter to select the first partition 7. type 20 and press enter this will make the first partition a Linux filesystem. #### Apply changes 1. Finally hit w and press enter to write all changes to disk # Partitioning the disk (BIOS) **Only do this part if you are in BIOS boot mode.** Start fdisk with the drive of your choice. fdisk /dev/nvme0n1 Now we are in fdisk, you can press m for help in the program, But if you do exactly as below everything should be alright #### Disk Options 1. Hit d and then enter untill there are no more partitions left. 2. Hit o Then press enter, This will make it a mbr disk #### Boot Partition 1. Press n and then enter to make our first partition 2. press p and press enter to make it a primary partition 3. press 2 and press enter to give it partition number 2 4. just press enter to put it in the beginning of the disk 5. type +2G to give it 2GB for the boot partition 6. press t and press enter to set the type 7. press 2 and press enter to select the second partition 8. type 83 and hit enter this will make the second partition an EFI partition. #### Swap Partition 1. press n and press enter to create our swap partition 2. press p and press enter to make it a primary partition 3. press 3 and press enter to give it partition number 3 4. press enter again to put it next to the previous partition 5. type +8G to give it 8GB swap, If you have less ram I would recommend making it equal to your ram, So +4G if you have 4GB Ram. 6. press t and press enter to set the type 7. press 3 and press enter to select the third partition 8. type a and hit enter this will make the third partition a Swap partition. #### Root Partition 1. press n to create our final root partition 2. press p and press enter to make it a primary partition 3. press 1 and press enter to give it partition number 1 4. press enter again to put it next to the previous partition 5. press enter again to give it the remaining space on the disk. 6. press t and press enter to set the type 7. press 1 and press enter to select the first partition 8. type 82 and press enter this will make the first partition a Linux filesystem. #### Apply changes 1. Finally hit w and press enter to write all changes to disk # Format Partitions Now we have set the partitions and the labels now we are going to format them all Be sure that you replace /dev/nvme0n1p# with the correct drive and partition If if is /dev/sda be sure to include the partition number /dev/sda1, /dev/sda2 and /dev/sda3. For the /dev/nvme0n1 you need to add a p and then the partition number so /dev/nvme0n1p1, /dev/nvme0n1p2 and /dev/nvme0n1p3 First we need to give the root partition a filesystem You can opt for btrfs, f2fs or ext4. btrfs is a newer filesystem with a lot of very cool features, It is not great for databases tho, so if you plan to go for a server it is not the best choice if your database is going to be on your root partition. I have not tested this one with encryption. But let me know how it goes :) f2fs is made with SSDs in mind, it might be the best choice for SSDs. Also not tested this one with encryption, But let me know how it goes :) ext4 is very stable and thourogly tested, you can't really go wrong with this one. So pick a single one of the following options mkfs.btrfs /dev/nvme0n1p1 mkfs.f2fs /dev/nvme0n1p1 mkfs.ext4 /dev/nvme0n1p1 Then we make the boot partition fat 32 mkfs.fat -F32 /dev/nvme0n1p2 Make partition 3 swap mkswap /dev/nvme0n1p3 Then enable swap on partition 3 swapon /dev/nvme0n1p3 # Full Disk Encryption (Optional) Encryption is completely optional, If you don't want it, just skip this step completely. Many things can go wrong, and if you forget your password the data is lost, Nothing you can do to recover it. Use it at your own risk. I would recommend Encryption for Mobile devices that hold sensitive data, Laptops you take with you for example. I would not recommend Encryption for desktops, unless you are worried someone can get physical access. make the root partition an LUKS partition cryptsetup -y -v luksFormat /dev/nvme0n1p1 Mount the encrypted partition to cryptroot cryptsetup open /dev/nvme0n1p1 cryptroot Create a ext4 filesystem on the encrypted partition mkfs.ext4 /dev/mapper/cryptroot You can also encrypt swap if you want to swapoff /dev/nvme0n1p3 cryptsetup -y -v luksFormat /dev/nvme0n1p3 cryptsetup open /dev/nvme0n1p3 cryptswap mkswap /dev/mapper/cryptswap swapon /dev/mapper/cryptswap You can encrypt any partition you want, just don't encrypt the boot partition because this guide doesn't cover that, and it is pretty useless imho. # Mounting the partitions now we are going to mount the 2 partitions and create the /boot directory Be sure that you replace /dev/nvme0n1p# with the correct drive and partition If it is /dev/sda be sure to include the partition number /dev/sda1 and /dev/sda2. If it is /dev/nvme0n1 you need to add a p and then the partition number so /dev/nvme0n1p1 and /dev/nvme0n1p2. mount the first partition to /mnt, if you use encryption you mount /dev/mapper/cryptroot here mount /dev/nvme0n1p1 /mnt create the /boot directory mkdir /mnt/boot mount the second partition to /mnt/boot mount /dev/nvme0n1p2 /mnt/boot # Install the base system The following command will install the base system and a text editor we need later on. pacstrap /mnt base base-devel vim # Install a Kernel You can stick to the normal kernel, but you have options For Desktop use I would recommend the zen kernel For A Server I would recommend the hardened kernel so install the kernel you want with one of the following commands pacstrap /mnt linux linux-headers pacstrap /mnt linux-zen linux-zen-headers pacstrap /mnt linux-hardened linux-hardened-headers # Generate the fstab file Generating the fstab file will take all mounted partitions and add them to a file so they mount at boot so if you have any more drives you want to mount at boot mount it before you run the command. Run the following command genfstab -U /mnt > /mnt/etc/fstab # chroot into the new system chroot is a tool to treat any directory as its root directory, In a way we "break" into the system from the live image, So we will switch from USB to your drive with the following command. arch-chroot /mnt # Set your timezone and time If you are unsure about your timezone you can list all timezones with the following command. timedatectl list-timezones go up and down with the arrows look for your timezone and hit q to exit. Next we are going to change the timezone to the one you selected ln -sf /usr/share/zoneinfo/your/timezone /etc/localtime Replace your/timezone with your correct timezone Europe/Amsterdam for example Finally run hwclock to generate the time file hwclock --systohc # Generate the locale and set the language run the following command and remove the # in front of en_US.UTF-8 UTF-8 and any other locales you need. vim /etc/locale.gen Hit esc then :wq and enter to save and exit Run the following command to generate the locales locale-gen Next we are going to set the language run the following command vim /etc/locale.conf The language you want your system to be should be in this file in this form, if you want it Dutch for example you change en_US.UTF-8 to nl_NL.UTF-8 ``` LANG=en_US.UTF-8 ``` Hit esc then :wq and enter to save and quit If you have not set a different keyboard layout in the earlier part "Set your keyboard layout for installation" you can skip the rest of the commands in this step. If you have set a different layout back in the earlier part "Set your keyboard layout for installation" run the following command vim /etc/vconsole.conf add the keyboard layout you set in the beginning. ``` KEYMAP=layout ``` layout should be trq for Turkish and de-latin1 for German Hit esc then :wq and enter to save and quit # Set the hostname and hosts file Next we are going to set the hostname, This is the name of your device in the local network. vim /etc/hostname enter a good name for your device without any capital letters or spaces. You can just call it laptop or personal-computer ``` coolcomputername ``` Hit esc then :wq and enter to save and quit Now we have to create a file, run vim /etc/hosts Type exactly whats below replacing yourdevicename with the name you just gave your device in /etc/hostname You can use the tab key for the spaces to make it lign up properly ``` 127.0.0.1 localhost ::1 localhost 127.0.1.1 yourdevicename.localdomain yourdevicename ``` Hit esc then :wq and enter to save and quit # Set the root password now we have to set a root password The root user is like the superuser or administrator account, You will need this password to update your system or change anything outside your personal home folder. run the following command then type your new password, hit enter, then again to confirm. passwd # Configure Pacman Pacman is the PACkage MANager of Arch Linux, It is great, but we can make it even better :) First we are going to open the pacman.conf file to make some adjustments vim /etc/pacman.conf Under Misc Options uncomment UseSysLog, Color and Parallel Downloads You can also up the number. And add ILoveCandy to get the other Pacman to appear too :) ``` # Misc options UseSyslog Color #NoProgressBar CheckSpace #VerbosePkgLists ParallelDownloads = 16 ILoveCandy ``` Also add base and grub after HoldPkg ``` HoldPkg = pacman glibc base grub ``` Hit esc then :wq and enter to save and quit Next up are the mirrors, The defaults are okay and this takes a while, but for faster speeds I would seriously recommend this step. So go ahead and install reflector pacman -S reflector then just run reflector with the following command reflector --latest 200 --protocol https --sort rate --save /etc/pacman.d/mirrorlist You will see a bunch of errors but that is normal, just let it run and wait untill the prompt shows up again. # Install Microcode (Optional) PROPRIETARY Now we are going to install the microcode, this is PROPRIETARY but it will improve stability, choose the right one for your CPU, you can install none if you are in doubt or don't want any non free software on your machine. AMD pacman -S amd-ucode Intel pacman -S intel-ucode # install and configure grub grub stands for GRand Unified Bootloader just so you know. Now we are going to install grub, only do UEFI or BIOS depending on your system UEFI pacman -S grub efibootmgr grub-install --target=x86_64-efi --efi-directory=/boot --bootloader-id=Arch grub-mkconfig -o /boot/grub/grub.cfg BIOS pacman -S grub grub-install --target=i386-pc /dev/nvme0n1 grub-mkconfig -o /boot/grub/grub.cfg # Full Disk Encryption (Optional) if you did the first Encryption part you can NOT skip this step If you did not go for disk encryption after formatting the disks you MUST skip this step First we need to get the UUID of the root partition of /dev/nvme0n1p1 in this case and remember it blkid We need to include it in the grub config so open the grub file vim /etc/default/grub Look for the following GRUB_CMDLINE_LINUX_DEFAULT somewhere at the top ``` GRUB_CMDLINE_LINUX_DEFAULT="loglevel=3 quiet" ``` Adjust it so the line looks like this remember that you have to replace UUID with the correct UUID. ``` GRUB_CMDLINE_LINUX_DEFAULT="loglevel=3 quiet rd.luks.name=UUID=root root=/dev/mapper/root" ``` Now let grub generate a new config file grub-mkconfig -o /boot/grub/grub.cfg Open the mkinitcpio.conf file vim /etc/mkinitcpio.conf Look for the following HOOKS line, it should be somewhere at the bottom ``` HOOKS=(base udev autodetect modconf block filesystems fsck) ``` Make it look like this (order is important) ``` HOOKS=(base systemd autodetect keyboard modconf block sd-encrypt filesystems fsck) ``` finally run the following command to generate the new image mkinitcpio -p linux # Creating the user Now it is time to create a user account, This is where you log into, It can do almost everything except install software or change things outside of your personal folder. you need to remember your username and you can not have capital letters in your username useradd -m yourusername Set a password for the user, You will log into the device with this password, You can make it the same as the root account. passwd yourusername enter a new password and press enter twice # install and configure sudo Sudo allows you to do root stuff while logged in as a user, It will probably become your most used command so install it. pacman -S sudo Now we need to add your username to the sudoers file, run the following command vim /etc/sudoers Look for the lines under User Privilege Specification There should be a line root ALL=(ALL) ALL Add your username in the exact same manner one line below it so that part looks like this. ``` root ALL=(ALL:ALL) ALL yourusername ALL=(ALL:ALL) ALL ``` You can also make your computer try to insult you if you enter a wrong password, Just add a line with the following content under the Defaults Specification ``` Defaults insults ``` Hit esc then :wq and Enter to save and quit # Reboot into your Installation Now you can exit the chroot exit Reboot the system and remove the USB drive when the screen turns black reboot # Next Next up depends on you, Do you want a desktop environment? or do you want a server? This guide expects you only to do one of the next steps, so choose between GNOME, KDE or Server. Installing GNOME and KDE and the Server all on one machine is possible, I wouldn't recommend it, but this guide doesn't expect that and several components will collide which might result in some unexpected behavior.