The Hand-Crafted Linux Server
Anyone can grab a pre-built server off the shelf. Not you. You’re an artisan. A digital blacksmith.
You will hand-craft a server from scratch using Arch Linux (the ‘some assembly required’ of operating systems). You will hammer out the partitions, smelt the base packages, and temper the network settings until you have a lean, mean, command-line machine, built by you and for you. There are no GUIs in this dojo.
In this lab, we’ll install and configure Arch Linux on a hypervisor. Arch Linux is very configurable and includes nothing but what you manually specify. It’s a hobbyist’s dream, and you’ll like the tiny distro it produces.
Before You Start
Section titled “Before You Start”-
Download the Arch Linux ISO
Visit the Arch Linux website and download the latest
.isoimage for thex86_64architecture. You can also download it from the OSU Open Source Lab Mirrors. -
Research networking service
What is the name of the service you will use to allow your system to get an IP address? Two different answers are acceptable. (2 points)
Supplies Needed
Section titled “Supplies Needed”- Personal laptop with a hypervisor installed
- The Arch Linux
.isofile - Enough disk space: the VM will take up an additional 1.4 GB
Questions
Section titled “Questions”Watch for the answers to these questions as you follow the tutorial below. Answering all questions will require finishing the tutorial and some research online; please cite working references.
- What is a protective MBR and why is it used in GPT systems? (3 points)
- What is a Secondary GPT Header? Where is it located? When would you expect it to be utilized? (3 points)
- What are some differences between the EXT4 file system we used for our root partition and the FAT32 filesystem that used to prevail? (3 points)
- Get the TA’s initials, showing that you can ping a website or server on the internet. (22 points)
- What is the IP address of your VM? (3 points)
- What is the name of your ethernet adapter? (3 points)
- What are three types of platforms other than “i386-pc” that grub-install can target? (3 points)
Tutorial
Section titled “Tutorial”To get Arch installed, the first step is to create a Virtual Machine (VM) to hold it. We can then proceed to install Arch Linux on that VM.
VM Creation
Section titled “VM Creation”Each hypervisor will do things a little bit differently. If you are using something other than VirtualBox or UTM, please look online for a tutorial to create an empty virtual machine.
VirtualBox
Section titled “VirtualBox”-
Create a new VM with these settings:
- Type: Linux
- Version: Arch Linux (64-bit)
- 1GB RAM
- Dynamic-sized HD with an 8GB size limit, normal .VDI format
-
Once the VM has been created (but before the Arch image is booted for the first time), configure these settings:
System category:
- Uncheck Floppy from the Boot Order
- Select all three Extended Features: “Enable I/O APIC”, “Enable EFI (special OSes only)”, “Hardware Clock in UTC Time”
- 2 CPUs (or more)
- Enable PAE/NX (if available)
Display category:
- Video Memory 128 MB
-
In the Settings controls for your new VM, on the Storage tab, insert the .iso into the Optical Drive.
-
Create a new Emulated (if Apple Silicon) or Virtual (if Intel-based) VM that is not preconfigured (OS = Other).
-
Select your Arch Linux ISO image.
-
Configure the VM:
- Leave architecture and system as is
- Adjust memory to 1024 MB
- Choose at least 2 CPU Cores
- Set the drive size to 8GB
- No shared directory
-
Choose a name for your VM and save.
Arch Installation
Section titled “Arch Installation”-
Start the VM
Choose the first option, “Arch Linux install medium (x86_64, UEFI)”. The boot process will probably take about 30 seconds. This will get you into a virtual console (i.e. a RAM-based Linux install called archiso) that you can use to install Arch on the hard drive.
-
Test internet connection
Because you didn’t change the network settings for the VM, the settings are configured to NAT this VM, which means it piggybacks on the networking of your Host laptop. Check your internet connection:
Terminal window ping google.com -
Partition the hard drive using GPT
We need to partition the hard drive using the GPT scheme. Our goal is to create three partitions: an EFI system partition, a swap partition, and a root partition.
Start the partitioning program:
Terminal window gdisk /dev/sdaYou’ll now be at the
gdiskprompt. Our hard disk space is currently empty and we need to create some partitions to use for the installation. Enter?to view possible commands:Terminal window Command (? for help): ?b back up GPT data to a filec change a partition's named delete a partitioni show detailed information on a partitionl list known partition typesn add a new partitiono create a new empty GUID partition table (GPT)p print the partition tableq quit without saving changesr recovery and transformation options (experts only)s sort partitionst change a partition's type codev verify diskw write table to disk and exitx extra functionality (experts only)? print this menu -
Create the EFI system partition
Enter
nto begin creating a new partition:Terminal window Command (? for help): nFeel free to use the default starting sector, and type “+300MB” for the last sector. When prompted for the hex code (which identifies the purpose of the partition) enter “ef00”. This is the GUID corresponding to an EFI system partition.
Partition number (1-128, default 1): [Enter]First sector (34-16777182, default = 2048) or {+-}size{KMGTP}: [Enter]Last sector (2048-16777182, default = 16777182) or {+-}size{KMGTP}: +300MBCurrent type is 8300 (Linux filesystem)Hex code or GUID (L to show codes, Enter = 8300): ef00 -
Create the swap partition
Repeat the process to create a 400MB swap partition, which has the hex code “8200”:
Terminal window Command (? for help): nPartition number (2-128, default 2): [Enter]First sector: [Enter]Last sector: +400MBHex code or GUID: 8200 -
Create the root partition
Create a root partition using all remaining space:
Terminal window Command (? for help): nRather than specifying the partition’s last sector, simply use the default value provided by
gdisk. This will automatically configure the partition to use all remaining space on the disk. The hex code for a root partition is “8300”:Partition number (3-128, default 3): [Enter]First sector: [Enter]Last sector: [Enter] (use default to fill remaining space)Hex code or GUID: [Enter] (8300 is default) -
Verify and write the partition table
Print the proposed partition table to verify:
Terminal window Command (? for help): pYour configuration should resemble:
Number Start (sector) End (sector) Size Code Name1 2048 616447 300.0 MiB EF00 EFI system partition2 616448 1435647 400.0 MiB 8200 Linux swap3 1435648 16777182 7.3 GiB 8300 Linux filesystemWrite the changes to disk:
Terminal window Command (? for help): wFinal checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING PARTITIONS!!Do you want to proceed? (Y/N): yOK; writing new GUID partition table (GPT) to /dev/sda.The operation has completed successfully.We’ve now got partitions: physical spaces to install files on. These partitions need to be formatted with the appropriate filesystem before we can actually put files onto them.
-
Format the partitions
Format the EFI system partition with FAT32:
Terminal window mkfs.fat -F32 /dev/sda1Format the root partition as EXT4:
Terminal window mkfs.ext4 -F /dev/sda3Create and activate swap space:
Terminal window mkswap /dev/sda2swapon /dev/sda2Now, we’ll mount the root directory file system so that we can create directories in it and copy files to it. We’ll be positioning this at
/mnt. -
Mount the file systems
Mount the root directory file system:
Terminal window mount /dev/sda3 /mntIt’s a common convention to mount the ESP (EFI System Partition) at
/boot/efi. Since our new root partition is (temporarily) placed at/mntwe will mount the ESP at/mnt/boot/efi.Mount the ESP (EFI System Partition):
Terminal window mkdir -p /mnt/boot/efimount /dev/sda1 /mnt/boot/efi -
Install Arch Linux
With the disk all nicely partitioned, we can install Arch. We’ll start the installation with the dedicated tool called
pacstrapto install Arch into our/mntdirectory. Note that this uses an internet connection to download files, so make sure you have a network connection withpingfirst.Terminal window pacstrap /mnt base linux vim -
Generate the file system table
We now need to create a way for the OS to keep track of all the mount points and UUIDs (the
-Uswitch, below) created in the installation process that we just went through. This is called a “file system table”, orfstab.Terminal window genfstab -U /mnt > /mnt/etc/fstab -
Enter the chroot environment
In order to configure our new installation, we need to create a “chroot jail”. This is essentially a mapping that makes it so the changes we are about to make are applied to the OS we’re installing, not the OS that’s actually currently booted (which is the one from the
.isoimage). It also prevents commands from being used anywhere outside of this/mntdirectory: the/mntwill become our newrootdirectory.Terminal window arch-chroot /mntVerify that we’re in the jail by printing out the current working directory. Note that it now thinks we’re in
/.Terminal window pwd -
Configure locale settings
First, we need to copy (
cp) the configuration of the “Los Angeles” area to where the OS looks for timezones. Then, check the time. It should be the current time in our timezoneTerminal window cp /usr/share/zoneinfo/America/Los_Angeles /etc/localtimeTerminal window dateNow we need to generate a set of locales the system can use. We’ll set the language and character set we want to use, and lastly make them available to the system while this install process is happening. Edit the locale configuration with
vimsince we installed it with the base packages.Terminal window vim /etc/locale.genInside that file, uncomment these two options by removing the hashtags:
#en_US.UTF-8 UTF-8#en_US ISO-8859-1Save and exit the file. In
vim, you first press ESC and then type the characters:wqand pressEnter.Apply your locale changes:
Terminal window locale-genecho LANG=en_US.UTF-8 > /etc/locale.confexport LANG=en_US.UTF-8Now we are going to install the bootloader that boots Arch Linux when the system turns on. We’ve installed Arch on the OS, but it currently won’t be booted when the VM is started! Let’s fix that by installing a bootloader called the GRand Unified Bootloader (GRUB).
-
Install and configure the bootloader
Here’s how we use the Arch package manager
pacmanto installgruband some EFI tools (this will take a minute or two).Terminal window pacman -S grub efibootmgr dosfstools mtoolsNow we need to tell grub to position itself in our root partition
/dev/sda.Terminal window grub-install --target=x86_64-efi --bootloader-id=arch --recheckFinally, grub needs to write its own configuration file so it knows how to operate.
Terminal window grub-mkconfig -o /boot/grub/grub.cfgArch is installed! Now we’re going to do some configuration on it to make it more usable.
-
Configure package manager
Edit the
pacmanconfiguration to allow 32-bit software:Terminal window vim /etc/pacman.confFind and uncomment these lines:
#[multilib]#Include = /etc/pacman.d/mirrorlistRe-sync
pacmanwith its new configuration (takes 1 or 2 minutes).Terminal window pacman -Syu -
Install and configure
sudoNow we’re going to install
sudo. Up until now, we’ve been operating solely as the superuser root (identified by the#in your terminal): this is handy for administrative work, but dangerous in production. Thissudotool allows us to run one-shot configuration commands as if we were root (or another user) while remaining as a lesser-privileged user.Install
sudo:Terminal window pacman -S sudoWe now need to modify the
sudoconfig file to allow a security group called “wheel” to be authorized to usesudo. With this done, any user in the “wheel” group will be set up to usesudofrom all terminals, acting as any user, and run any commands with it. This config file is edited in a strange way. Instead of editing the config file directly, we use a command that loads an editor to go work on the file.Terminal window visudoUncomment this line and save and exit the file:
#%wheel ALL=(ALL) ALLNow we’re going to add a new user: this will be who we want to log in as normally.
-
Create a user account
Create the user with the following command, which will create the home directory (
-m), add it to the additional group (-G) wheel which will give itsudoaccess, set the shell (-s) tobash, and name the new userarchuser.Terminal window useradd -m -G wheel -s /bin/bash archuserSet the password for this new user (you will be prompted to provide a password). Note that you have to type it twice.
Terminal window passwd archuserNow, we can reboot!
-
Complete the installation
Exit the chroot environment:
Terminal window exitEject the
.isofrom the Virtual Machine.Reboot the VM:
Terminal window reboot
Post-Installation Configuration
Section titled “Post-Installation Configuration”After rebooting, log in with your new user account and configure networking. You’ll find that many, many, most, many, practically all things are not installed. That’s Arch! For example, you probably don’t have a network interface turned on, so ping will fail. Continue on!
Note that we’re using the bash shell now, so the prompt symbol is the traditional $ (instead of #) which means we’re a normal user, not the superuser root. If you need to run a command as root, you can use sudo before the command.
-
Create a hostname
The first thing we need to do is create a hostname for our system. This name is used to identify this machine on the network, and is required for it to get an address. We’ll need to create a file in this location with this name
Terminal window sudo vim /etc/hostnameInside that file, put just a word with no spaces. Consider “RefArch”, for example. Save and exit.
-
Configure the hosts file
Now we need to configure the networking hosts file to know about our name. This file tracks several memorized network locations, including our own.
Terminal window sudo vim /etc/hostsAdd these lines (replace “RefArch” with your chosen hostname):
127.0.0.1 localhost127.0.1.1 RefArch.localdomain RefArch -
Configure network interface
List the interfaces to see what you have:
Terminal window ip linkThe first one, “lo”, is the loop device, or the loopback identifier. This isn’t used for actual communication. The second one is the actual ethernet connection we care about. It will probably show up with a name like “enp0s3”. If yours is slightly different, just substitute that below.
Query your specific interface (replace “enp0s3” with your interface name):
Terminal window ip link ls dev enp0s3The state should be DOWN initially. That’s right: Arch’s networking starts in a down state so that it doesn’t automatically reach out and join the network. That allows you to be explicit about when you’re ready to connect.
-
Configure DHCP
Let’s configure our interface to obtain an IP address via DHCP using a new
systemdconfiguration file.Terminal window sudo vim /etc/systemd/network/wan.networkInsert this content (changing the interface name if needed), then save and close the file:
[Match]Name=enp0s3[Network]DHCP=yes -
Enable and start networking service
Now let’s enable the corresponding system service (
systemd-networkd) so that it starts on boot.Terminal window sudo systemctl enable systemd-networkdWe don’t want to wait for a reboot, so we’ll manually start the service.
Terminal window sudo systemctl start systemd-networkd -
Verify network configuration
Check if your interface got an IP address:
Terminal window ip addr lsLook for an “inet” field showing an IP address like 10.0.X.Y/24. It can also start with 192 or 172, as those are reserved for private networks.
-
Configure DNS
We need DNS in order for our internet connection to be useful.
Terminal window sudo vim /etc/resolv.confAdd these Google public DNS servers:
nameserver 8.8.8.8nameserver 8.8.4.4 -
Test internet connectivity
You should now have a working connection:
Terminal window ping archlinux.org -
Shutdown when complete
When you’re done, shut down your VM:
Terminal window sudo shutdown -h now
You’re done! To receive credit for this lab, you must turn in your answer sheet with your names listed.