Linuxgraphy by Strabo

Custom assets

🔗

Presented at

🔗
BG Unofficial FMI class Discord server   22.01.2023 || 18:00 - 21:00
In front of a tiny audience of other uni students

Linuxgraphy by Strabo

Made by Syndamia

2000 years ago Strabo published Geography, in which he laid out the world as it was known to the Romans and Greeks.
Today, I’ll lay out Linux as it is known to me.

Contents

  1. Historical context
  2. Structure of UNIX-likes
    1. Shell
    2. UNIX-style file system
    3. Kernel
  3. Linux from the inside
    1. Shells
    2. Files and directories
    3. Common configuration files
    4. System management
  4. Software licensing
  1. What makes up a useful OS
    1. Bootloader
    2. Init system
    3. Package manager
    4. Desktop manager
  2. War on distros
  3. Demo - setup from zero

1. Historical context

1945 - 1955

🔗

You directly loaded instructions into memory and let it execute your “code” (processor instructions). Nothing else ran on the machine.

This process was labor intensive: a qualified operator loaded your program, dumped the memory contents, remove any external media, reset the machine and load the next job.

1956 - 1959

🔗

Computers became faster, but a lot of time was spend on managing jobs.

resident monitors: very small programs, which always resided in memory, and monitored what the state of the current job was.
Jobs were loaded in series (batches). When the current job finished, memory would be dumped and the next one would automatically be loaded and started.

1960s

🔗

Peripherals (tapes, punch cards, …) were extremely slow.
Multiprogramming: the current job is waiting for a peripheral, another job would be started.

Travel reservation system by American Airlines: where travel agents would search, price and book services. A computer system now had to support:

More and more business started using computers, thanks to minicomputers, so demand for OS software increased.

1964 - 1969

🔗

IBM’s System/360 line of computers, each with expansion capabilities, backwards compatibility, all under one instruction set and operating system.

Multics, an influential operating system that was designed for a General Electric mainframe. Some of it’s novel ideas include, but are not limited to:

1969: Death of Multics and birth of UNIX

🔗

Ultimately Multics grew too large and became unusable, unmaintainable and unchangeable.
In the beginning, programming was done mostly by Bell Labs, with Ken Thompson as one of the developers.


Ken Thompson image by National Inventors Hall of Fame
Ken Thompson and Dennis Ritchie in 1973

Thompson still had some desire to work on operating systems, after Bell Labs pulled out. The tools he made while rewriting a video game he made on a PDP-7 lead to a whole operating system: UNIX.

Based, expanded on and improved upon many of Multic’s ideas, UNIX became the father of modern OSs.

2. Structure of UNIX-likes

Ignoring standards and specifications, in my opinion, from the point of a user, a UNIX-like OS has the following components:

  1. shell: A programmable replaceable command-line interpreter, with utilities for managing the whole system and support for pipelines and I/O redirection
  2. UNIX-style file system: Filesystem as a single rooted tree, objects (nodes) in the file system are inodes and an inode can be (at least) either a regular file, directory or devices. Permissions per users and group.
  3. kernel: Program that manages all communication and operations between the hardware and software
For now we’ll generally just look over some of the common stuff and go into detail later, while in Linux.

2.1. shell

🔗
The operating system is divided into layers, like an onion.
Only the kernel has access to the hardware.
shells and executables (binaries) have access to the kernel.

shells provide user interfaces, both command-line and graphical. While on the topic of UNIX, we’ll only discuss the former.

Command-line shells operate solely with text, usually with only ASCII characters. There are usually two terms used when talking about connecting to a computer (to the shell), those are “terminal” (“console”) and “teleprinter” (“teletype”).

Video displays became widely available in the late 1970s, so before that access was done with a “teleprinter”, a typewriter-printer combo.


Teletype Model 33 by Arnold Reinhold

With the advent of computer displays, teleprinters were replaced with terminals, video display-keyboard combo. Thanks to the widely popular VT100, almost all terminals support ANSI escape codes.


DEC VT100 by Jason Scott

Today we don’t usually use such specialised hardware, but the names persist with slightly different meanings.

Virtual Terminal (Console): on some modern UNIX-likes (like Linux), the kernel/OS provide special devices, where a console is directly implemented/simulated with the connected computer and display. Sometimes could be called “tty”.

Terminal Emulator: a special program that emulates a virtual terminal (within another display system)

Pseudoterminal (pty): a device that behaves, from the point of a user, like a terminal (emulator), but could do other additional things

Most commands are regular programs, which exist in any folder (specified inside the variable “PATH”). Each command can be given parameters, separated by spaces, each (by convention) being either text values or options (switches).

Options usually start with a hyphen - (like -c or -current-time) and often support abbreviations (-a -b -c to -abc). Newer conventions also allow start with two hyphens -- (--current-time), though if shown as-is indicate the rest is a string. More rarely you might see --OPTION=VALUE or just OPTION=VALUE.

UNIX shells always have at least these additional functionalities:

  • pipelines: being able to redirect the output from one command to another without limit

    command1 [args...] | command 2 [args...] | ...
    
  • I/O redirection: redirection of input and output, allowing insertion of input from a file or storage of output into a file:

    command [args...] < filepath
    command [args...] > filepath
    

2.2. UNIX-style file system

🔗

The main attributes that every inode has are as follows:

  • file type: Each inode represents some sort of file (data), but a “file” can also be a directory or device, so we need to know how to handle it.
    There are 7 main types (but there can exist more, depending on OS):
    • regular: just a plain old file
    • directory: as explained, a file containing hard links to other files. Each directory is allowed to appear only once in a single parent.
    • symbolic link: points to any file (or directory). It contains the (relative) path to that object (as a simple string), so a symlink could even not be valid.
    • FIFO special: aka named pipe, a special type of regular file, where at any moment only one process can read from it and one can write to it. It takes the concept of shell pipes to inter-process communication.
    • block special: a device which is randomly accessible, like a hard drive or cdrom drive.
    • character special: devices which are accessed via serial streams of input or output, like keyboards, mice, graphics cards and teletypes
    • sockets: file for inter-process communication. Compared to FIFO specials, they can be used by more than two processes, used in both direction and support file descriptors and packets

Side-step into users and groups

🔗

A user in UNIX is essentially a small collection of data, most important of it being a unique ID (number), a name (string), a group id (number; files created by the user are in that group) and a password.

Groups are also small collections of data, but much simpler, comprised only of a unique ID (number), a name (string) and a list of users that are “in” the group. Their main purpose is to simplify access control.

User with ID 0 is called root, it is the “system administrator”, all actions made by the system itself are done as that user. Every user has their own “home” folder (under “/home/USERNAME/”, except for root, which is “/root/”), in which they store personal files, as well as user-specific configuration files.

2.3. Kernel

🔗

The kernel has the core functionality of the operating system and bridges the gap between programs and hardware. Some important subsystems include scheduling, file, device, process and memory management.

To preserve the everything is a file methodology, devices and processes can be handled as files (inside /dev and /proc). They (often, in modern kernels) aren’t actual files on a hard drive, but “virtual” files, where operations on them are handled in a different manner than normal by the kernel.

Linux is not an operating system, it is a kernel!!!

3. Linux from the inside

Enough theory, time to have some fun and learn Linux!

We’ll be using Linux Minimal Live (just a bootable ISO) because:

  • very small, comprised of only the Linux kernel, GNU C library and Busybox
  • made by a fellow Bulgarian BG

We’re going to explore and look around the following stuff:

  • Shells: What a modern shell would often support on a Linux based OS
  • Files and directories: Naming conventions and commands to work with them
  • Common configuration files: Relevant configuration files, their purpose and syntax
  • System management: Other commands with which to modify your system

If you’re following at home

🔗

Owing to it’s size, not everything we need comes out of the box, so I created a script which installs what’s needed. If you want to try it out yourself, after booting up Minimal Linux Live, type out and run:

wget -q https://syndamia.com/talks/linuxgraphy-by-strabo/mll-set.sh && chmod +x mll-set.sh && ./mll-set.sh

If you get the message TLS certificate validation not implemented, ignore it.

In summary, it installs bash, coreutils and shadow “packages” (from http://s.minos.io/archive/bifrost/x86_64) to /usr/local/bin, creates /etc/passwd, /etc/bashrc and /etc/profile with some values in them and starts bash.

3.1. Shells

🔗
  • continuation

    • Every job is identified with a Job ID (number), which you can use by prepending a percentage sign. Example, to resume the job with JID 4:
    fg %4
    
    • For managing everything, usually there is a job table. Upon shell termination, the shell tells all jobs in that table to terminate and waits for them.
      disown: remove a job from the job table
    • kill: send a signal to the process or job. Then that process will have to handle it accordingly.
      Common ones are -KILL to immediately stop the process, -QUIT to quit it, -ABRT to cancel the current action, -TERM shut down (orderly), -STOP shut down (forcefully)
  • heredoc: File literal, meaning it is a user “string” which is interpreted as a file

    • start with << NAME, where NAME can be anything you want, it is used to mark the beginning and end of a heredoc. << is also a redirection symbol
    • on every new line write out your text, all characters will be preserved
    • to end it, write out NAME on the beginning of a new empty line. Example:
    cat << MYFILE
    This is
    some
        text
    MYFILE
    
  • control operators: Control what command is executed, depending on exit status

    • expr1 && expr2: Run expr2, only if expr1 exited successfully
    • expr1 || expr2: Run expr2 if expr1 exited unsuccessfully
    • expr1 ; expr2: Run expr2 after expr1 finished (no matter how)
    • Every program returns an exit status (number) to the shell, zero being a successful closing, and all others indicating failure.
  • redirection: Outside of having < and > for I/O redirection, often there is also

    • >>: Acts like >, putting text into a file, but rather than overwriting everything, it appends it
    • <<: As explained, for heredocs
    • <<<: To the right is a string (herestring), and it is interpreted as a file
    cat <<< "Hello World!"
    
    • Standard input, standard output and standard error are all files with which the shell works. Typing text in the shell puts it into stdin, command output are put into stdout (and shown to the user) and errors are put into stderr (also shown to the user).
      Each one of them is numbered from 0 to 2, and you can specify redirection by appending or prepending it to the redirection symbol.
    • N>outputfile: redirects the output from standard stream N into outputfile
    • N>&M: redirects the output from standard stream N into standard stream M
    • N<inputfile: redirects input file contents to standard stream N
    • N<&M: redirects standard stream M to standard stream N
  • built-in test command: With test you can do conditional expressions. You can also often use brackets [ args... ] instead of test args...
    • Some of the available file checks
    • -e FILENAME: FILENAME exists
    • -d FILENAME: if FILENAME is a directory
    • -h FILENAME: if FILENAME is a symbolic link
    • -w FILENAME: you can write in FILENAME
    • Some of the available string checks
    • -n STR: string STR has nonzero length
    • -z STR: string STR has length zero
    • STR1 = STR2 and STR1 != STR2: self explanatory
    • Some of the available number checks
    • INT1 -eq INT2: equal integers
    • INT1 -gt INT2: INT1 > INT2
    • INT1 -gt INT2: INT1 >= INT2
    • Operators: ! - negation, -a - binary AND, -o - binary OR, parentheses for grouping (escaped with \)

3.2. Files and directories

🔗

General file system commands

🔗

Working with text (files)

🔗

Working with devices

🔗

3.3 Common configuration files

🔗
  • /etc/fstab: mountings of devices to the file system, read on boot by mount
  • /etc/hosts: list of host names (domain names) and their corresponding IP address, when a DNS server doesn’t do the job
  • /etc/bashrc: global defaults and aliases used by the bash shell

3.4. System management

🔗
  • Users and groups
    • useradd: creates a new user (with a password)
    • userdel: remove a user and all of his files
    • usermod: modify a user account, including his name and groups
    • passwd: change password of a user. With -l user could be locked (impossible to log in)
    • groupadd: create a new group
    • groupdel: remove a group
    • groupmod: modify an existing group
    • w: show who is logged in and what they are doing
    • who: show who is logged in
    • whomai: print username
    • login: establish a new connection to the system

4. Software licensing

It is important to note that most software in Linux, including the kernel itself, is under a variety of open licenses. An open license is a license which allows others to reuse the original work, under some restrictions.

For software, such a license is applied to the source code from which the original application was made. Some commonly used ones, with a (NON-LEGALLY BINDING) summary include:

This is important, since pretty much everything can be freely modified by anyone (for the better or worse, but generally better).

5. What makes up a useful OS

We talked about the modularity of a Linux-based operating system. Overall, these are the main elements that make up a desktop operating system you might want to use:

  1. Bootloader: load the kernel and operating system
  2. Init system: well managed way to start everything inside the OS
  3. Package manager: way to manage our binaries
  4. Desktop manager: graphical shell

5.1. Bootloader

🔗

When a computer boots, it needs to start an operating system, but you can’t expect it to know how to boot any operating system. Skipping over the details, the computer starts a small program called the bootloader, which handles loading the OS.

On Linux, the most used one is called GRUB. With it you can also specify which kernel to load, with which parameters to load the kernel and which OS to start.

5.2. Init system

🔗

In Minimal Linux Live, the whole system is started by some hard written scripts, this isn’t very modular and extensible, that is why we need a special system.

Generally, the init system loads a series of services, where each service is just a file that specifies what and how something needs to be ran.

The most common init systems are

5.3. Package manager

🔗

Running a program is as simple as putting the executable in a nice folder, like /usr/bin. However this process isn’t very convenient if you’re only using a shell and more tedious if using a graphical shell.

The solution is to have all programs in one location, where you can download, install and potentially update a program with one simple command, just using the program’s name. Other good features include installing dependencies and checking if a package is tampered with.

There is another “type” of package managers, those similar to portage, where packages are actually instructions on how to download and compile a specific version of the program.

5.4. Window systems

🔗

A widow system is your graphical shell: the graphical way to interact with your computer (the kernel). It’s main components are:

6. War on distros

A distribution is a complete set of of all applications that we’ve talked so far.

Overall, there are five distributions from which 90% of all other distros are based upon:

  1. Slackware: as the oldest still maintained distro, it served as inspiration for a lot of other distros. It aims to be as simple and as close to UNIX as possible.
  2. Debian (and Ubuntu): it is the most popular distribution (if we also include Ubuntu, since they’re so similar). Ubuntu aims to be modern and fancy, while Debian aims to be as stable as possible, which makes it the most popular in server usage.
  3. Gentoo: the distribution which defined non-binary software distribution
  4. Arch Linux: a very popular and modern distribution with the goal of providing the latest and greatest software.

We haven’t touched too much, but Linux distributions aren’t limited to desktop or server computers. Two more uncommon ones are:

  1. AOSP: the base of the whole Android operating system
  2. OpenWRT: a router operating system

7. Demo - setup from zero

Now for the best part: we’ll be installing a Linux distribution from a laptop running Windows 10!

I’ve chosen to install Linux Mint, since it is generally targeted towards newcomers and will feel familiar enough to Windows users.

Currently there won’t be an official recording of the process, you should’ve been here live!

Thank you for your time

Sources

All of these contain, at most, small paraphrased sentences in the slides. They mostly served as personal educational/reference tools.

Licensing

Images on slides “2.1. shell” and “2.2. UNIX-style file system” are made by me and licensed as content.
The script mll-set.sh is licensed under MIT (though I don’t see it as substatial enough to be licensed under anything).

^