Skip to main content

Raymii.org Logo (IEC resistor symbol)logo

Quis custodiet ipsos custodes?
Home | About | All pages | RSS Feed | Gopher

Build a Flexible and Powerful System with Arch Linux

Published: 09-03-2015 | Author: Graham Morrison | Text only version of this article


Table of Contents


This article was originaly published in Linux Voice, issue 1, April 2014.This issue is now available under a Creative Commons BY-SA license. In anutshell: you can modify and share all content from the magazine (apart fromadverts), even for commercial purposes, providing you credit Linux Voice as theoriginal source, and retain the same license.

This remix is converted manually to Markdown and HTML for ease of archiving andcopy-pasting.

If you like this article, consider sponsoring me by trying out a Digital OceanVPS. With this link you'll get $100 credit for 60 days). (referral link)

Other converted Linux Voice articles can be found here.


Build a Flexible and Powerful System with Arch Linux

Install the rolling release distro of the moment and you'll never have to waitfor a package upgrade again.

Installing Arch is the Linux equivalent of base jumping. You organise yourself.Surround yourself with everything you need, stick the installation media on to aUSB stick and jump. You never know how an installation is going to go until youtry it, and it will always involve a bit of ad-hoc hacking, Googling andtroubleshooting. But that's the fun of it, and that's what makes Arch different.

With Arch, you're on your own. In a world where where technology is taking yourpersonal responsibility and giving it to the cloud, or to an internet searchfilter or the device manufacturers, getting your hands dirty with an operatingsystem can be a revelation. Not only will you learn a great deal about how Linuxworks and what holds the whole thing together, you'll get a system youunderstand from the inside-out, and one that can be instantly upgraded to allthe latest packages. You may also learn something about yourself in the process.And despite its reputation, it's not that difficult.

If you're a complete beginner, you may need to hold on to your hat, becauseinstalling Arch is an uncompromising adventure in core tools and functions. It'sa jump into the unknown.

Create the install media

We'll start with the ISO, which you can either find on our cover DVD or downloadfrom your local Arch mirror (see https://www.archlinux.org/download).

If you're going to install Arch onto a machine with a DVD/CD drive, you couldsimply burn the ISO to a blank CD, but we're going to write the ISO file to aUSB thumb drive as this saves wasting a disc. You'll only need a 1GB thumb drivebut this process will remove all data from the device, so make sure there'snothing on there you want to keep first.

There are many ways of transferring aBuild a Flexible and Powerful System withArch Linuxn ISO image to a USB drive, although copying the ISO onto thefilesystem isn't one of them. Normally, our preferred method is to use thegraphical tool UnetBootin, which is available for nearly all distributions,including those two alien environments, OS X and Windows.

Sadly, Unetbootin won't work with Arch unless you manually edit the syslinux.cfgfile afterwards, as this is overwritten in the transfer process. This leaves youto the mercy of dd, a crude command that copies the raw data from one deviceto another. It works, but there's no sanity checking of the output device youchoose, so you have to make sure you're writing to your USB stick. If you getthis wrong, you'll copy the raw bits and bytes of the Arch ISO to anotherstorage device on your system, overwriting any data that might have been therebefore.

Here's our system for getting the correct device:

You'll see several lines appear as your system negotiates with the new USBdevice and, all output will include the characters 'sd'. What you need to lookfor is the letter that comes after 'sd', as this is the device node of the USBstick after it's connected to your system, and we need this device name for thenext command, which is going to write the Arch ISO image to the USB stick.

arch1

Whenever a new USB drive is connected, you system logs become a hive ofactivity.

Also be aware that this device node can change, if you come back to this processafter adding or removing another USB device. Here's the dd command for writingthe ISO:

sudo dd bs=4M if=/path/to/arch.iso of=/dev/sdx

Replace the x in /dev/sdx with the letter for your device and press return.You should see the activity LED on your USB stick start to flicker as data iswritten. If not, press Ctrl+C immediately to stop the process and double-checkeverything (such as whether your USB stick has an activity LED).

After the process has completed, which should only take a few moments on amodern machine, type sync to make sure the write buffers are flushed, andremove the stick. It's now ready to be used to install Arch.

First Boot

Before you plug the USB stick into the machine on which you're going to installArch, make sure you know which hard drive you're going to use. If your machinehas several drives, make a note of the capacity and model of the drive you wantto use, and make sure you don't have an identical drive. If you're going to usea partition on a drive, or use up free space, we'd recommend using GPartedfrom a live CD to set up your partitions first, or at least resize otherpartitions to leave enough space.

Along with a 200MB EFI partition for GUID, you'll need at least a root partitionand a small swap partition. It may also help to have a separate home partition,as this makes upgrades to the root filesystem easier to handle.

Most machines will boot off the USB drive by selecting the custom boot menu fromyour machine's boot flash screen. It's usually done by pressing the F12 key.This will present you with a list of connected drives, and you should be able toselect the USB device from there.

If all goes well, a moment later you'll see the Arch boot menu and you need toselect the first option, Arch Linux archiso.

arch2

We used GParted to create a GPT partition scheme and a 200MB EFI parition(type ef00, labelled "EFI"), but it might be easier to stick with old-schoolMBR and Grub.

Networking

Your first mission is to get to the internet. We'd recommend installing thesystem using a wired connection if at all possible. With the system up andrunning, it's then much easier to configure your wireless device, but if youneed to configure wireless now, check out the excellent Arch Beginners'Guide.

With a bit of luck wired internet should be working already, because Arch runsthe dhcpd daemon at startup, which in turn attempts to get an IP address fromwhatever router your kernel-configured network interface can find. Try typing

ping linuxvoice.com 

to see if any packets are returned. If this doesn't work - and it didn't for us- first get the name of your interface by typing ip link. It's usually thesecond device listed, because you should ignore the first one called lo (this isa system loopback device).

Our PC's network device is called enp7s0, which you'll need to replace in thecommands below. To get it working, we stop the non-functioning DHCP service,bring up the Ethernet interface, manually assign this to a valid IP address onour network and add the router as a default gateway.

If you know your router's IP address, you can normally connect to its webinterface to check which IP ranges are suitable for your machine, and use its IPaddress as the router IP address. Here are the three commands to do what we justexplained - replace IP addresses to suit your own network.

ip link set enp7s0 upip addr add 192.168.1.2/24 dev enp7s0ip route add default via 192.168.1.1

The final step is to type

nano /etc/resolv.conf 

and add the line nameserver 8.8.8.8 to add one of Google's nameservers to themix. This will convert the alphanumeric URLs we normally use to the IPaddressees used by the network, and you should now find that pinging a domainname works.

Formatting

You should now have a fair idea at how Arch does things. It basically leaves youto do your own research and make your own decisions while creating the mostcommon-sense environment it can. We're going to assume you've alreadypartitioned the drive, so the first step is to make sure you know which drive totarget.

The best command to achieve this is fdisk -l. This lists all your drives,their partitions and the filesystems they're using, alongside their devicenodes. Unless you've got two identical drives, you should be able to work outwhich one to use without too much difficulty. And if you haven't formatted yournew partitions yet, they should stick out like a sore thumb.

If you're only using a single drive, you'll have even fewer problems. We do knowpeople who disconnect all other drives whilst installing Linux so that they canbe absolutely sure they won't get the wrong drive and overwrite their 500-hourSkyrim save position on Windows 7.

Choose your filesystem

You should now format the partition. The safest and most sensible filesystem touse is ext4, and you can format your chosen partition by typing mkfs.ext4/dev/sdx2 - again, replace /dev/sx2 with your own partition. You should dothis for your home partition too, and you will also want to format and defineyour swap partition.

The command to do this is mkswap /dev/sdx3. You can turn this on with swaponfollowed by the device node. If you created an EFI partition yourself, ratherthan another OS doing this, you can format it with the command mkfs.fat -F32/dev/sdx.

Now mount the partitions by typing:

mount /dev/sdx2/ /mntmount /dev/sdx3 /mnt/home

arch3

Our automatically generated fstab file didn't need any further edits.

With GUID and an EFI system (rather than using the old BIOS), you'll also needto mount the EFI partition:

mount /dev/sdx1 /mnt/boot

If you're not using a separate home partition, type mkdir /mnt/home to createa home folder in the root partition. These are the fragile beginnings of yourArch installation. We're going to make more of an impact with the next command:

pacstrap -i /mnt base base-devel

This command installs a basic Arch system to your drive. We leave the installerat its default settings so it can grab and install all the default packages, andyou'll be left with all the packages you need. However, unlike with otherdistributions, that doesn't mean it's actually usable for anything yet.

Following the Arch Beginners' Guide, we'll next create the fstab file, asthis tells the distribution where to find its dependent filesystems.

In the old days, we'd use labels to represent partitions, but labels can bechanged or duplicated and break an fstab file, so we now use UUIDs. These arebasically hashes derived from partition data, so Arch should never get confusedunless something changes with the partition scheme.

The correct file with the correct mount points and UUIDs can be generatedautomatically by typing:

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

You can see that this file is created in your new root filesystem, and as thefile was generated automatically, you should check it's not complete insanity(try cat /mnt/etc/fstab).

It will show your mounted filesystem along with the EFI partition we mounted on/boot - this should be formatted and listed as vfat, as per our formattingcommand earlier.

With all that set up, we're now going to teleport ourselves into the new Archsystem using 'chroot' with the following command:

arch-chroot /mnt /usr/bin/bash

Post-config

How does it look inside your new Arch installation? Not that different than fromthe USB stick, except for now you're executing code from your hard drive.

There's obviously lots we can do here, but we're mostly interested in gettingthe system up and running as quickly as possible. It's worth giving your machinea hostname, which can be done with a command like echo linuxvoice >/etc/hostname.

Networking too should be solved in exactly the same way we got networkingworking earlier. If DHCP worked, just type systemctl enable dhcpcd.service tomake the required link to get it running at boot.

Enable network profiles

An alternative to this generic solution, which didn't work for us, is to enablenetwork profiles, such as the ones mainstream distributions use to quicklyswitch between network settings.

First copy the /etc/netctl/examples/ethernet-dhcp file to the /etc/netctl/directory, open your new file with nano and change the device from eth0 towhatever your machine uses (take a look at the output from ip link), thenenable the connection for your next boot with netctl enable ethernet-dhcp.

If you want to do the same with a static IP address, use the static Ethernetexample configuration. But for this, you have to make sure DHCP isn't runningwhen the system starts. To remove it, and any other service you no longerrequire, the command is systemctl disable dhcpcd.service.

Arch now uses systemd, which is why this syntax may look unfamiliar. You cancheck the service isn't started automatically by typing systemct | grep dhcpwhen you next boot.

If you want netctl to automatically bring up a connection for your interface,whether you've configured it for a static or dynamic connection, type thefollowing, but replace enp7s0 with the name of your device:

systemctl enable netctl-auto@enp7s0.service 

Before leaving the chroot environment, set a password by typing passwd, thenexit and reboot.

arch4

We had to create a static networking configuration file and remove the DCHPservice to get networking working.

We've now got to the state where we've got enough installed and configured thatwe can finally breathe some native life into our distribution. But before we canreboot, we need to install a bootloader.

If you've already got Linux installed, or you're sharing an installation withWindows, you'll need to be careful. Installing a bootloader over a part of thedisk used by another operating system will stop that other operating system frombooting.

If you've dedicated a new single drive to Arch, which is what we'd recommend,you can install the bootloader onto this drive only - whether that's old-schoolMBR or newer GUID. This way, you won't break anything; your drive will boot ifit's the first boot device, and it will boot if you use your system's BIOS bootmenu and select an alternative drive.

If you want to add your Arch installation to another Grub installation, you'llneed to boot into that system and re-generate the configuration - manydistributions, such as Ubuntu, can do this with a minimal of effort.

Install a bootloader

As we're using a modern system with EFI and GUID partitioning, we're going toinstall a simple EFI bootloader rather than the more commonly used Grub. If youare using older partition, however, Grub can be installed with the following twocommand after changing /dev/sdx to your device:

pacman -S grubgrub-install --target=i386-pc --recheck /dev/sdx

For EFI systems, type pacman -S gummiboot to install the EFI bootloaderpackage, and gummiboot install to run the simple setup procedure. It will failif an EFI-compatible partition can't be found, or isn't mounted. If thathappens, you should install Grub.

The only other step to getting gummiboot to work is to create a simpleconfiguration file called /boot/loader/entries/arch.conf. It should containthe following information:

title         Arch Linuxlinux         /vmlinuz-linuxinitrd        /initramfs-linux.imgoptions       root=/dev/sda2 rw

Replace the /dev/sda2 part with the device node for your root partition andyour new system should work. If it doesn't (and we don't want to be negative,but this is Arch we're talking about), the great thing about the Arch USBinstaller is that you can easily use it to troubleshoot your installation usingthe skills you've already learnt.

Just reboot from the USB stick, mount the drive and chroot into your new Archinstallation. Many serious problems can be solved this way, and it's muchquicker than using a live CD.

Remember this as you type exit to quit the chroot environment and reboot torestart your machine, because if your new Arch installation doesn't appear,you'll need to boot again from the USB stick and check the configuration.

Build your own home

You now need to log in as root, and you should check that networking is working.If not, you need to go through the same steps we went through with the USBinstaller.

At its most basic level, Arch is now installed and ready for you to sculpt intoyour perfect distribution.

There are many ways to do this - you may even want to remain on the commandline, but we're going to assume you'll want a graphical environment and yourhardware working. Xorg, the graphical display server, can be installed with thefollowing command:

pacman -S xorg-server xorg-server-utils xorg-xinit xterm mesa

As long as you're happy using open source drivers for your graphics hardware,this is all you need for a working X session. Many of the open source driversare good enough for desktop work, and only lack 3D performance.

A simple test to make sure all this auto configuration is going to work is totype startx to bring up the most basic of X sessions. Unfortunately for us, itdidn't work and we got a no screens found error. This is probably because ourscreen is rubbish and isn't communicating its capabilities back to the graphicshardware.

The solution is to create your own X.org config file. We're using Nvidiahardware and are happy to use Nvidia's proprietary drivers. The drivers for anymodern Nvidia GPU can be installed by simply typing pacman -S nvidia, andrebooting your system.

Nvidia's drivers are also better at detecting displays, so it might be worthtrying startx again to see if anything has changed. You can quit the Xenvironment by exiting all of the terminal sessions.

With X running, it's now time to install a graphical environment. Obviously thisis a contentious issue, but here's the basic procedure. KDE, for example, can beinstalled by typing:

pacman -S plasma-meta

Meta packages encapsulate other package collections, so you can fine-tune yourinstallation. A basic KDE installation can be accomplished by grabbing the kde-base package, for example. kde-meta on the other hand downloads over 700MB ofdata and installs over 2GB from 558 packages. It takes a while.

For Gnome, gnome-shell contains the basics, gnome has the desktopenvironment and the applications, while gnome-extra contains all the tools.

The final steps to Arch nirvana are to create a new user with useradd -mUSERNAME, give them a password with passwd USERNAME and then to launch theKDE/Gnome login manager by typing kdm or gdm.

You'll get a fully functional login and desktop. But as you'll soon discover,this is only the end of the very beginning. With Arch, you've only just gotstarted.

Pro Tip: EFI/MBR

In this tutorial we've chosen EFI booting and the GUID partitioning scheme, asthis is likely to be compatible with most hardware available now, and morefuture proof than MBR partitioning.

Pro Tip: Documentation

Arch's own docs are absolutely excellent. They're also very comprehensive,so don't allow them to put you off.

Pro Tip: Check Twitter before an upgrade

Despite updates being easy to apply on the command line, it's always worthchecking that nothing requires your intervention before you do the upgrade. Thebest way we've found to stay in touch is to peruse Arch's Twitter account:@archlinux

Pro tip: Pacman

Pacman is Arch's package manager, and is relatively straightforward to use.pacman -S will search for and install packages.

pacman -Ss will search for package names and their descriptions.

pacman -R will remove them and pacman -Syu will perform a system upgrade

Tags: arch, linux, linux-voice, linux-voice-issue-1-2014, pacman, tutorials