I’m going to go through how to install Arch Linux on an encrypted disk. Arch is a simple, lightweight [Linux] distribution
that leaves you with nothing more than a terminal, and disk encryption is something everyone should utilize to protect their data.
To better explain why you should use disk encryption—without it, anyone who gets their hands on your computer will have access to everything stored on it. This is more realistic than it seems because most of us have laptops that we take everywhere and it’s quite easy to forget it in public places.
With disk encryption, the data on a harddrive will look like random noise, unless it’s decrypted with a password. We should first write over the entire harddrive with random noise, effectively making it impossible to tell if there’s even legitimate data on the disk. This guide explains how to do that.
Next, download and prepare the installation media, then boot into it and log in.
If this doesn’t look like Linux to you then it’s because it’s not.
I’m connected to the computer that I want to install Arch on through ssh on my MacBook Pro, ergo it looks like I’m on a Mac, but everything within the screen should be just as you see it.
First, the harddrive needs to be partitioned. Type cfdisk and press enter.
You’ll use it to make two primary partitions: an unencrypted boot partition at the beginning of the disk, and an LVM partition that we’ll further partition and encrypt later. The boot partition doesn’t need to be big, just 100 MB will do. Be sure to toggle the bootable flag, and set the type to 83 (Linux). The other partition should not be set as bootable, and the type should be set as 8E (Linux LVM). Write the partition table to disk and then quit the program.
Back at the prompt, encrypt the LVM partition with the following commands:
$ modprobe dm_mod
$ cryptsetup -c aes-xts-plain -y -s 512 luksFormat /dev/sda2
The first command loads the encryption module and the second encrypts the LVM partition. You’ll be asked to choose a password, the same one you’ll use to decrypt your harddrive with. It is important to pick a good password and to not lose it as there is absolutely no way to recover data from your harddrive if you lose this password.
Once encrypted, it needs to be opened so that (logical) partitions for Linux can be set up. There are many ways to partition for Linux, but for now just make three partitions: root (10 GB), swap (8 GB), and home (the rest). I chose 10 GB for root because that should be more than enough, and 8 GB for swap because I just doubled the size of my RAM (a general guideline).
Enter the commands:
$ cryptsetup luksOpen /dev/sda2 lvm
$ lvm pvcreate /dev/mapper/lvm
$ lvm vgcreate vgroup /dev/mapper/lvm
$ lvm lvcreate -L 10G -n root vgroup
$ lvm lvcreate -L 8G -n swap vgroup
$ lvm lvcreate -l 100%FREE -n home vgroup
Now that this is done, start the Arch installer by entering /arch/setup into the prompt.
First, select a source by choosing a mirror within your country.
The next screen asks you to setup your network (I hope you’re not using WLAN because I don’t know what to tell you if you are). Choose eth0 as your interface and say yes to DHCP.
Then you’ll be asked to choose a text editor. I chose vi because I use Vim. If you’ve never used Vi or Vim before, choose nano.
Once a text editor is chosen, you can setup your date and time. This one is simple—just choose your region/timezone and select UTC when asked. You’ll be asked to confirm the time.
The next step, prepare hard drive(s), is where you have to start paying attention. Select the option to manually configure block devices and chose to do so by dev.
Start by choosing the first partition, /dev/sda1 raw. This is the boot partition that you made, so select /boot at the next window.
It’ll ask you if you want to (re)create the filesystem—say yes and choose ext2.
Enter boot
as a label (without the quotation marks) and enter nothing for additional options and you’ll return back to the first screen.
Now, setup the other three drives in a similar fashion with the following exceptions: for the root and home drives use ext4 and for the swap drive use swap.
Return to the main menu and start selecting packages.
Choose grub as your bootloader, then just press OK at the next screen. The screen after that shows you all the packages that are available. Feel free to look around and read the descriptions, but I suggest you don’t choose anything here and just press OK to install the default packages.
Now, the system needs to be configured.
These are all configuration files that control how Arch operates. Take a look through all of them, but the important ones are /etc/rc.conf and /etc/mkinitcpio.conf.
In /etc/rc.conf, change USELVM="no" to USELVM="yes", and then choose a hostname for your computer. I chose godunov.
In /etc/mkinitcpio.conf, add encrypt lvm2 to the HOOKS line before filesystems.
In /etc/pacman.d/mirrorlist, uncomment out some more mirrors in your country and move on to installing the bootloader. It’ll ask you to edit a file—this is the most important step, otherwise your computer will not boot.
There are two lines that begin with kernel. You need to add cryptdevice=/dev/sda2:vgroup right after vgroup-root, in both instances.
Choose to install the bootloader onto /dev/sda and exit. Arch is now installed (finally), but there’s some more housekeeping to do.
Back at the terminal, type reboot to reboot your computer. If you did the system encryption properly, it should stop and ask you for a password. This is the system password that you choose.
Log in as root with the root password that you made during installation. It’s very dangerous to log in as operate as root, so make a new user with the following command:
$ useradd -m -g users -G audio,optical,storage,video,wheel,power -s /bin/bash username
This will create a new user called username and add him to the group users
and the additional groups listed (audio, optical, and so on). The -s /bin/bash option sets bash as the default shell for this new user. By default, a password isn’t set, so type passwd username to set a password. Now you can log out of root and log back in with your new username and password.
Finished.
Although Arch is now installed, this is just the beginning. There’s still obviously so much more that can be done that I won’t get into, because this guide is just menat to be a starting point. For more information, read the ArchWiki.