DEV Community

lostghost
lostghost

Posted on • Edited on

Linux from the user's perspective - Part1: Installing Linux

This blog is the first in a series, more here

Linux is a kernel and an OS - let's get a working copy, to experience it for ourselves. This will take installing it - either on a real computer, or on a virtual machine. I chose the latter, firstly, so that you can have an easier time retracing my steps, secondly, for my own convenience.

There are many emulators to choose from. My recommendations are:

  • QEMU with LibVirt GUI - what I will be using. An excellent choice for an existing Linux installation, does what it should, and no more, gets out of your way.

  • GNS3 - an excellent choice for visualizing a network topology, can launch QEMU VMs with any options you want. Supports overlay QEMU images. I won't use it, as I will only ever work with one VM.

  • VirtualBox - a good enough solution for Windows.

  • Xen + CloudStack - you'll know if you need it.

Next comes the choice of a particular Linux distribution. I prefer ArchLinux, because there is no magic (not more than there already is on Linux), but if you want to go the extra mile, LFS may be for you. Debian Sid is a respectable option.

Get the latest ArchLinux ISO from here.

Make sure to select UEFI and not BIOS - BIOS is an obsolete technology at this point. BIOS can only bring the motherboard into a correct state, read the primary bootloader from MBR and jump to it - while UEFI can do much, much more. Secure boot, network boot, GUI with mouse support, launching PE EXE files from a FAT32 volume, bytecode and VM, all of which make it an OS in it's own right - you could argue it's too powerful at this point. If you need a firmware image - look into OVMF.

When it comes to storage, I suggest creating a base qcow2 image, and then making overlays from it - see "BACKING_FILE" option here.

As for networking, I recommend creating two interfaces - one for NAT, and thus connection to the Internet, another - for the local network, and thus talking to your host computer.

Of course, booting from a disk is not the only option. If you want to automate installs across servers - you have to boot from the network. That is something you could play around with, in GNS3 for example, using FAI or your own system based on SaltStack. You could skip the installation altogether, and use a Live Image, or a Thin Client.

Time to start the VM. On a real computer, UEFI code would be copied into RAM and jumped to, which would configure the hardware, select a disk, read through the GPT, find the FAT32 filesystem marked "EFI", and load the bootloader executable - be it a bootloader, or the kernel itself, compiled with the "EFI Stub" option.

We are greeted with the bootloader, SystemD-Boot.

Image description

Select the first option, and wait for the shell to appear.

When it comes to bootloaders, there are options such as GRUB, LILO, rEFInd, u-boot. Personally, I prefer systemd-boot - it is minimal, and gets the job done. Still, it is useful to know the trick of changing the root password from GRUB - link.

For easy copying of commands, you could log in with SSH - for that, get an SSH client, set the password for the root user on the VM with the command passwd, check the IP addresses on the host and the VM with ip a, ipconfig or ifconfig commands, and login from the host onto the correct IP and password you just set up - ssh root@<IP>.

In doing so, you will be typing commands into a shell, running in a terminal.

A terminal is a text-based interface to a server - you type in text, you get text in return. Terminals have went from teletypes, in which you could only edit one line of text (an example of a program from that era is ed), to terminals, in which you could edit characters anywhere on the screen (example of a corresponding program - vi), to emulated terminals - which are just a window on desktop. Yet on linux the name remains - TTY for teletype. You can test that by typing the command echo 1 > /dev/tty, which will send the character "1" to the current terminal.

Image description

In fact, this terminal is most likely graphical and not character based - it only emulates characters. Instead, it uses a framebuffer for rendering. You can test that by typing the command cat /dev/urandom > /dev/fb0

Image description

Clear the screen with the command clear or "Ctrl+L".

Next let's ensure we have an Internet connection. Test it with a command ping 8.8.8.8 - sending ICMP Echo requests to the Google public DNS servers. If the network is unreachable - you will need to configure it with dhcpcd or manually with the ip command. For dhcpcd, first list all the network interfaces with ip a command - and for each one that isn't "lo" - for example, "enp1s0" on my system - run dhcpcd <interface>. Test the network again.

Now time to partition the disk into physical volumes (as opposed to logical volumes, that LVM provides you with). Launch the "cfdisk" program on the first virtual disk - cfdisk /dev/vda

We are installing with UEFI, so we need the "gpt" label type. The minimal setup is two volumes - a FAT32 EFI volume for the bootloader, and an Ext4 volume for the system. My results:

Image description

Now let's create the filesystems.

root@archiso ~ # mkfs.vfat /dev/vda1 mkfs.fat 4.2 (2021-01-31) root@archiso ~ # mkfs.ext4 /dev/vda2 mke2fs 1.47.2 (1-Jan-2025) Discarding device blocks: done Creating filesystem with 51904000 4k blocks and 12976128 inodes Filesystem UUID: b7780fc6-cf72-44c3-bb9b-febaf20a581c Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 4096000, 7962624, 11239424, 20480000, 23887872 Allocating group tables: done Writing inode tables: done Creating journal (262144 blocks): done Writing superblocks and filesystem accounting information: done 
Enter fullscreen mode Exit fullscreen mode

Mount the filesystems.

root@archiso ~ # mount /dev/vda2 /mnt root@archiso ~ # cd /mnt root@archiso /mnt # mkdir -p boot root@archiso /mnt # mount /dev/vda1 boot 
Enter fullscreen mode Exit fullscreen mode

And install Archlinux!

root@archiso /mnt # pacstrap . base linux dhcpcd 
Enter fullscreen mode Exit fullscreen mode

(dhcpcd will be necessary for network config)

Only two things left to configure - the root password, and the bootloader. For the root password, run the command chroot /mnt passwd. For the bootloader, do the following:

root@archiso ~ # bootctl install --root=/mnt root@archiso ~ # nano /mnt/boot/loader/entries/linux.conf 
Enter fullscreen mode Exit fullscreen mode

Write the following:

title Linux linux vmlinuz-linux initrd initramfs-linux.img options root=/dev/vda2 
Enter fullscreen mode Exit fullscreen mode

Screenshot:

Image description

Ctrl+S to save, Ctrl+X to exit.

Now type

root@archiso ~ # nano /mnt/boot/loader/loader.conf 
Enter fullscreen mode Exit fullscreen mode

Remove the leading "#", and increase the timeout to "10".

That's it. Reboot!

root@archiso ~ # systemctl reboot 
Enter fullscreen mode Exit fullscreen mode

You will be greeted with a familiar menu

Image description

Select the first option. Login under "root" and your password.

Image description

That's it. We installed Linux!

Top comments (1)

Some comments may only be visible to logged-in visitors. Sign in to view all comments.