linux_introduction/essential/readme.md

19 KiB

Essential Linux

Introduction to Linux

Where does Linux originate from?

Who is behind this project?

What is the deal with 'GNU-slash-Linux'?

Linux kernel

Where can you get some Linux?

  • You probably already have a Linux computer running at home!

Timeline

Debian

How to create a virtual machine

Step by step walk-through of a VM creation in virtualbox with some notes on each step with best practice pointers.

virtualbox setup virtualbox setup virtualbox setup virtualbox setup virtualbox setup virtualbox setup virtualbox setup virtualbox setup

Breakdown of the Debian installation

All right, enough talking, let's get started! I'll install a full blown and modern graphical Debian machine and I would like you to not do it yourself but take notes on each step so you'll be able to reference your notes later when I ask you to install a machine yourself.

  • step by step installation instructions
    • don't set a root password, use sudo instead
    • stress the graphical/minimal difference

Debian installation Debian installation Debian installation Debian installation Debian installation Debian installation Debian installation Debian installation Debian installation Debian installation Debian installation Debian installation Debian installation Debian installation Debian installation Debian installation Debian installation Debian installation Debian installation Debian installation Debian installation Debian installation Debian installation Debian installation Debian installation Debian installation Debian installation Debian installation Debian installation Debian installation Debian installation Debian installation

Exercise

OK, now it's up to you! Please install a Debian machine with the default graphical environment. Once installed, take some time out to explore the system. Which software is installed by default? How can you tweak the system settings such as language, keyboard, networking? Can you install extra software?

Quick look at an idle system

Debian installation Debian installation Debian installation

Package managers

Graphical installation

Debian installation Debian installation Debian installation Debian installation Debian installation Debian installation

Command line installation

waldek@hellodebian:~$ htop
-bash: htop: command not found
waldek@hellodebian:~$ apt install htop
E: Could not open lock file /var/lib/dpkg/lock-frontend - open (13: Permission denied)
E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), are you root?
waldek@hellodebian:~$ sudo apt install htop
[sudo] password for waldek: 
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Suggested packages:
  lm-sensors strace
The following NEW packages will be installed:
  htop
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 127 kB of archives.
After this operation, 328 kB of additional disk space will be used.
Get:1 http://deb.debian.org/debian bullseye/main amd64 htop amd64 3.0.5-7 [127 kB]
Fetched 127 kB in 0s (2,030 kB/s)
Selecting previously unselected package htop.
(Reading database ... 141359 files and directories currently installed.)
Preparing to unpack .../htop_3.0.5-7_amd64.deb ...
Unpacking htop (3.0.5-7) ...
Setting up htop (3.0.5-7) ...
Processing triggers for mailcap (3.69) ...
Processing triggers for desktop-file-utils (0.26-1) ...
Processing triggers for hicolor-icon-theme (0.17-2) ...
Processing triggers for gnome-menus (3.36.0-1) ...
Processing triggers for man-db (2.9.4-2) ...
waldek@hellodebian:~$ 

htop htop

The menu bar at the bottom shows you can press F10 to quit. This does not work because of a shortcut of gnome-terminal! You can deactivate this shortcut in the preferences though. But pressing q also exits the program.

htop bug with gnome-terminal

Adding a secondary desktop environment

During the initial installation we where offered a choice of desktop environments to install. This menu was an actual program called tasksel we can run again to add different ones! As it's a program that can heavily modify the system, we need administrator privileges.

waldek@hellodebian:~$ sudo tasksel
[sudo] password for waldek: 

tasksel tasksel tasksel tasksel

Changing the runlevel

The first process started by the kernel can be discover by htop and is /usr/sbin/init. This is rather vague but we can find out a bit more about this program via ls which we'll get into more detail later. For now just have a look at the output of the following commmand.

waldek@hellodebian:~$ ls -l /usr/sbin/init 
lrwxrwxrwx 1 root root 20 Jul 13  2021 /usr/sbin/init -> /lib/systemd/systemd
waldek@hellodebian:~$ 

Now, what is this systemd? And more importantly, how do we interact with it? For now just accept that the main program to communicate with systemd is systemctl. A quick look at the man pages gives us the following.

SYSTEMCTL(1)                                                         systemctl                                                         SYSTEMCTL(1)

NAME
       systemctl - Control the systemd system and service manager

SYNOPSIS
       systemctl [OPTIONS...] COMMAND [UNIT...]

DESCRIPTION
       systemctl may be used to introspect and control the state of the "systemd" system and service manager. Please refer to systemd(1) for an
       introduction into the basic concepts and functionality this tool manages.

waldek@hellodebian:~$ sudo systemctl set-default multi-user.target
[sudo] password for waldek: 
Removed /etc/systemd/system/default.target.
Created symlink /etc/systemd/system/default.target → /lib/systemd/system/multi-user.target.
waldek@hellodebian:~$ sudo reboot now

After the reboot you'll be confronted with the following screen. Don't stress, your machine is not broken! It's just running in a more minimal mode. You can log in just as with the graphical login window but you'll only have a command line to interact with the machine. A quick look at htop tells us not a lot of stuff is running, just the bare minimum.

minimal runlevel minimal runlevel

To undo this change and regain the graphical interface again you can run the following commands.

waldek@hellodebian:~$ sudo systemctl set-default graphical.target
[sudo] password for waldek: 
Removed /etc/systemd/system/default.target.
Created symlink /etc/systemd/system/default.target → /lib/systemd/system/graphical.target.
waldek@hellodebian:~$ sudo reboot now

Exercise

Please create a second virtual machine and install a minimal Debian. Minimal means no graphical environment. I advise you to not set a root password. Once this machine is up and running, install a few programs. The only one we saw up until now is htop but maybe try out bmon, elinks and/or ranger.

Guest additions

Let's make our user experience a bit nicer. Virtual machines can integrate with the host machine more fluently when you install the guest additions in the VM. It's a three step process.

  1. install the required packages to build the guest additions in you VM
  2. insert the guest additions CD into your VM
  3. run the correct script from the CD

The dependencies can be installed as follows. First you update your package list, next you install three packages.

  • build-essential
  • dkms
  • linux-headers-$(uname -r)

The third package name is a bit weird looking no? This is a bit of command line kung fu. The actual name of the package is as follows.

waldek@hellodebian:~$ echo linux-headers-$(uname -r)
linux-headers-5.10.0-11-amd64
waldek@hellodebian:~$ 

The $(uname -r) is a call to a program called uname with the option -r. We'll go more into detail on this later.

waldek@hellodebian:~$ sudo apt update
Hit:1 http://deb.debian.org/debian bullseye InRelease
Hit:2 http://deb.debian.org/debian bullseye-updates InRelease
Hit:3 http://security.debian.org/debian-security bullseye-security InRelease
Reading package lists... Done                 
Building dependency tree... Done
Reading state information... Done
All packages are up to date.
waldek@hellodebian:~$ sudo apt install build-essential dkms linux-headers-$(uname -r)
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
  binutils binutils-common binutils-x86-64-linux-gnu dctrl-tools dpkg-dev fakeroot g++ g++-10 gcc gcc-10 libalgorithm-diff-perl
  libalgorithm-diff-xs-perl libalgorithm-merge-perl libasan6 libatomic1 libbinutils libc-dev-bin libc-devtools libc6-dev libcc1-0 libcrypt-dev
  libctf-nobfd0 libctf0 libfakeroot libgcc-10-dev libitm1 liblsan0 libnsl-dev libstdc++-10-dev libtirpc-dev libtsan0 libubsan1
  linux-compiler-gcc-10-x86 linux-headers-5.10.0-11-common linux-headers-amd64 linux-kbuild-5.10 linux-libc-dev make manpages-dev patch
Suggested packages:
  binutils-doc debtags debian-keyring g++-multilib g++-10-multilib gcc-10-doc gcc-multilib autoconf automake libtool flex bison gdb gcc-doc
  gcc-10-multilib gcc-10-locales glibc-doc libstdc++-10-doc make-doc ed diffutils-doc
The following NEW packages will be installed:
  binutils binutils-common binutils-x86-64-linux-gnu build-essential dctrl-tools dkms dpkg-dev fakeroot g++ g++-10 gcc gcc-10 libalgorithm-diff-perl
  libalgorithm-diff-xs-perl libalgorithm-merge-perl libasan6 libatomic1 libbinutils libc-dev-bin libc-devtools libc6-dev libcc1-0 libcrypt-dev
  libctf-nobfd0 libctf0 libfakeroot libgcc-10-dev libitm1 liblsan0 libnsl-dev libstdc++-10-dev libtirpc-dev libtsan0 libubsan1
  linux-compiler-gcc-10-x86 linux-headers-5.10.0-11-amd64 linux-headers-5.10.0-11-common linux-headers-amd64 linux-kbuild-5.10 linux-libc-dev make
  manpages-dev patch
0 upgraded, 43 newly installed, 0 to remove and 0 not upgraded.
Need to get 62.0 MB of archives.
After this operation, 258 MB of additional disk space will be used.
Do you want to continue? [Y/n] y

Once this is done we can insert the CD. You can verify the disk's content via the files explorer in gnome.

CD

Now, open a terminal and run the following.

waldek@hellodebian:~$ cd /media/cdrom0/
waldek@hellodebian:/media/cdrom0$ ls
AUTORUN.INF  NT3x          TRANS.TBL                          VBoxLinuxAdditions.run          VBoxWindowsAdditions.exe
autorun.sh   OS2           VBoxDarwinAdditions.pkg            VBoxSolarisAdditions.pkg        VBoxWindowsAdditions-x86.exe
cert         runasroot.sh  VBoxDarwinAdditionsUninstall.tool  VBoxWindowsAdditions-amd64.exe
waldek@hellodebian:/media/cdrom0$ sudo bash VBoxLinuxAdditions.run 
Verifying archive integrity... All good.
Uncompressing VirtualBox 6.1.28 Guest Additions for Linux........
VirtualBox Guest Additions installer
Copying additional installer modules ...
Installing additional modules ...
VirtualBox Guest Additions: Starting.
VirtualBox Guest Additions: Building the VirtualBox Guest Additions kernel 
modules.  This may take a while.
VirtualBox Guest Additions: To build modules for other installed kernels, run
VirtualBox Guest Additions:   /sbin/rcvboxadd quicksetup <version>
VirtualBox Guest Additions: or
VirtualBox Guest Additions:   /sbin/rcvboxadd quicksetup all
VirtualBox Guest Additions: Building the modules for kernel 5.10.0-11-amd64.
update-initramfs: Generating /boot/initrd.img-5.10.0-11-amd64
VirtualBox Guest Additions: Running kernel modules will not be replaced until 
the system is restarted
waldek@hellodebian:/media/cdrom0$ sudo reboot now

Once the machine is rebooted you'll can resize the window and the screen resolution will adapt automatically! You can also enable copy/paste and drag and drop between your host and VM now.

full screen

Introduction to the command line

We'll be using a few new words to reference the command line such as shell, bash and terminal through out the course. They all pretty much mean the same thing but with some small, and not so important, differences between them. Essentially a command line is a textual interface for humans to operate a computer. What is very important to understand is that textual command and graphical actions operate on the same computer. For example, if you create a file via the command line, it will show up in you file explorer and vice versa. The graphical and textual interfaces are just different representations of the same machine.

Now open up a terminal and you'll see the following.

waldek@hellodebian:~$ 

This is what we call a prompt. It's not much but it's our window into the computer. As with most things in life you can question it's who, where, what and when. This information is actually embedded in the prompt. Let's break it down.

  • waldek is who I am on this computer
  • hellodebian is the what, as in what computer I'm operating on
  • ~ is where I am located on this computer

What about the when then? Let's type in date and see what happens.

waldek@hellodebian:~$ date
Fri 18 Feb 2022 03:46:59 PM CET
waldek@hellodebian:~$ 

There we see our when! But this miniscule operation illustrates us the fundamental operation of a command line!

  1. we have a prompt where we can run a program
  2. the program runs and outputs it's information on the terminal
  3. once the program finishes we can run an other program

I'm deliberately saying program here but is date really a program? It's a bit basic no? Well, it is a program and most commands you'll type into your terminal are actually programs. We can illustrate this as follows.

waldek@hellodebian:~$ vlc
VLC media player 3.0.16 Vetinari (revision 3.0.13-8-g41878ff4f2)
[0000559c46ee95b0] main libvlc: Running vlc with the default interface. Use 'cvlc' to use vlc without interface.
[0000559c46f89790] main playlist: playlist is empty

Vlc is now running and the terminal is blocked meaning we can't run other programs or commands in it. If you try to run the date command again, or ls or htop, it won't work! Try it out if you don't believe me. But what happens if you close vlc? The commands you typed get executed! This is an illustration of the sequential nature of a command line.