ramar.work

Arch

I’m an Arch fan. It’s always been there. It’s easy to install, light on space and light on intrusion. I’ve come a long way since picking it up almost 8 years ago, but how would I go about doing it now? I probably wouldn’t do a whole lot differently, but I’ll run through a basic install.

First, we should think about why you would want to install Arch. My reasons are needing a testing box for Myst. For that reason, I’m going to write this guide in such a way that users of a virtualization software will find it the most useful. This is not to say that you can’t follow this and set up on a bare metal machine, but it might not be the best option.\

Second, let’s boot it. We should see a screen like the following.

If your native language is not English, you’ll want to test that the correct keycode is loaded.

Third, and possibly most important, we’ll need to check for an internet connection. For those who have done this before, this would usually be done via something like ifconfig to check for and setup a new internet connection. However, Arch now uses the iproute2 library to handle networking by default.

In the following example, I’m using ip addr to check for the current connections.

The first interface, lo, is the symbolic name and information for the local loopback interface. If you do any web development or have ever had to access an internet service from your own machine, you’ll realize that this is localhost.

The second interface, enp0s3, is my virtual machine’s primary internet connection. I have three interfaces total, but this is the interface that communicates with the outside world. Arch, by default, will use the first available interface it can with DHCP.

The third interface, enp0s8, is one way to administer machines created with VirtualBox. I keep this interface open specifically for SSH traffic. When using VirtualBox, this last interface is bound to a Host-Only interface. Provided that this interface was created before boot, something like ssh root@192.168.56.101 will work if you would like to test connectivity on this port from your host system.

To test for connectivity from the guest to the outside world, use ping (or dig) to check that you can access something.

$ ping www.google.com

If the connection is successful, you should see something like the following.

PING www.google.com (142.250.176.68) 56(84) bytes of data.
64 bytes from atl26s26-in-f4.1e100.net (142.250.176.68): icmp_seq=1 ttl=110 time=10.4 ms
64 bytes from atl26s26-in-f4.1e100.net (142.250.176.68): icmp_seq=2 ttl=110 time=9.80 ms
64 bytes from atl26s26-in-f4.1e100.net (142.250.176.68): icmp_seq=3 ttl=110 time=9.88 ms
64 bytes from atl26s26-in-f4.1e100.net (142.250.176.68): icmp_seq=4 ttl=110 time=9.88 ms
64 bytes from atl26s26-in-f4.1e100.net (142.250.176.68): icmp_seq=5 ttl=110 time=9.78 ms

But check the final lines. Specifically check how many packets were transmitted and received. If you get something like 100% packet loss, then you probably don’t have a connection.

You can also set the system time as well via:

$ timedatectl set-ntp true

Partitioning

To list the partitions, this command will show what’s currently on the system. Most likely if this is a new box, there is nothing else.

fdisk -l

Since, I’m just planning for VirtualBox, I’m only planning on using one partition to house everything. There are a ton of different schemes that can be used, and these will vary depending on what kind of setup you’re looking for.

cfdisk is the easiest way to do this from the live disk. fdisk is bit tougher to use if not experienced with it, but it is probably going to be what you want if the idea is to create a box in a scripted fashion.

// Partitioning with CFDisk
$ cfdisk /dev/sda1
// Partitioning with fdisk
fdisk /dev/sda1 --id=82 (linux swap/solaris) --start 2048 --end 411647 --size 200M
fdisk /dev/sda2 --id=83 (linux) --start 411648 --end 16777215 --size 7.8G 

Filesystems

Let’s assume that you want a swap space and a big full disk.

$ mkswap /dev/sda1
$ swapon /dev/sda1
$ mkfs.ext4 /dev/sda2

A swap space is not always needed. But depending on the type of box used, it is more or less important.

Mounting and Prepping for Install

So, now we need to mount our newly formatted drive to the environment’s /mnt directory.

mount /dev/sda1 /mnt

It’s worth mentioning that other setups will probably need to mount more than just the one drive.

Arch has some real useful tooling to make installation to a totally new drive fairly easy. The pacstrap tool will download about 300MB of useful base packages. This takes about 5 minutes or so.

pacstrap /mnt base

Now, we have to tell our new OS where everything is mounted.

genfstab -U /mnt >> /mnt/etc/fstab

Completing the Install

Now, we’ll be changing root and jumping into the actual system. Since we’re no longer in the Live disk’s environment, some things will be missing. (For example, I’m used to working with Vim as a text editor, but when I change root, it will no longer be there.)

$ arch-chroot /mnt
$ ln -sf /usr/share/zoneinfo/America/New_York /etc/localtime
$ hwclock --systohc
$ printf "en_US.UTF-8 UTF-8\n" > /etc/locale.gen && locale-gen
$ printf "LANG=en_US.UTF-8\n" > /etc/locale.conf
$ export HOSTNAME=headbussa && printf "$HOSTNAME\n" > /etc/hostname
$ printf "127.0.0.1\tlocalhost\n127.0.1.1\t$HOSTNAME\n" >> /etc/hosts
$ mkinitcpio -p linux

So, what’s going on here? We change into /mnt and the new environment now becomes our root. We need to setup a locale, set the hardware clock, generate locale specific files, set up a hostname and add the record to /etc/hosts. Finally, we build the Linux boot image for use with our bootloader.

One thing that is not covered in the guide, is setting up a persistent network. If you’re on a wired connection, you’ll have little trouble. If not, eh.

$ netctl
$ pacman -Sy wpa_supplicant
$ printf "Description='DHCP internet connection.'\nInterface=enp0s3\nIP=dhcp\n" \
    > /etc/netctl/interfaces/enp0s3
$ printf "Description='SSH interface.'\nInterface=enp0s8\nIP=192.168.56.101\n" \
    > /etc/netctl/interfaces/enp0s8
$ netctl enable interfaces/enp0s3
$ netctl enable interfaces/enp0s8

Since we’re already root, we’ll need to setup a root password here.

$ passwd

// Just answer the prompts...

And now we’re about one step from finishing the install. So, let’s set up our bootloader. Most of the time, Grub serves our needs.

$ pacman -Sy grub
$ grub-mkconfig -o /boot/grub/grub.cfg
$ grub-install --target=i386-pc /dev/sda

Notice that there was no disk number after /dev/sda. When installing a bootloader to a system’s Master Boot Record, it’s like putting a piece of data before the actual start of a partition. In other words, do not use a number here.

Now we can restart, and go.

//the grub screen //the prompt