Part 1 – Installation and Basic Terminology
GNU / Linux is a multiuser and a multitasking general purpose operating system. A lot of people shy away from using its desktop version since it demands that the user knows some technical things in order to use it properly. However it’s not very difficult once you grasp some of the very basic concepts which are used in all popular Desktop versions of other operating systems as well.
GNU / Linux provides complete transparency when it comes to usage. What this means is not only you get to see the good things but also the bad things viz errors, warnings in a full blown technical manner. But once you understand how it all works there’s no going back to anything else since GNU / Linux is better in most things than everything else out there.
Learning Topics
Topic | Description |
---|---|
Installation | Understanding how to install a GNU / Linux distribution, the terms used and what they mean to make the correct decisions at the time of installation. |
File System Layout | Understanding the File System Layout and File System Hierarchy Standard. |
Linux Commands | Learning to use the Linux Command line. |
Automating tasks with Scripts. | Learning how to write Linux Shell Scripts. |
Installing Linux
GNU / Linux is made up of several components of software and there are many distributions out there which make the installation quite easier. In a nutshell there are two major components
The software which can be run on the Operating System. These software programs are generally open sourced GNU versions (GNU Not Unix) of popular programs found in the Unix systems, in addition several other Linux specific programs are also available.
The kernel which helps in running programs and also provides device management viz files, devices etc.
In order to have a functional Operating System we need both, the software and the kernel. Since the software part mostly comes from GNU and kernel is Linux kernel, the Operating System itself is known as GNU / Linux however the distributions are free to label their version of the bundle, for example some popular distributions are Ubuntu, RedHat, SuSE, Fedora, Kali, Android (though not directly usable as a desktop system).
Booting From an USB / Optical drive
Usually the distribution would be available as bootable ISO image from the respective distribution website. However some distributions might not be able to boot on newer machines which have Secure Boot (EFI / UEFI) enabled in their BIOS. An UEFI enabled machine requires that the operating system which is being booted is signed digitally (well actually the boot loader needs to be signed) by the signer available on your board’s (Mother Board) firmware.
Some Linux distributions are able to boot with UEFI enabled however if you choose one that doesn’t work then you’ll have to disable UEFI in BIOS and choose instead legacy boot option.
Setting up a Dual Boot / Multi boot
If you want to have a Dual boot system. Say Windows and Linux both installed on the same machine, you’ll probably want to use a distribution which supports UEFI. Also the order of installation is extremely important, the boot loader for Linux for x86 / x86_64 systems is GRUB which is capable of detecting and co-existing with previously installed boot loaders. It does this through chain loading which works like below,
First GRUB gets control and checks if it has earlier recorded any other Operating System boot loaders.
Then it presents the user with a selection screen which shows which other operating systems are present.
It then uses the boot loader of the selected entry to boot into.
Note that it transfer control to the boot loader of the selected operating system but doesn’t boot the OS itself unless it had an entry to boot it.
With the above concept out of the way it’s straight forward to know that any boot loaders (operating systems) which can’t co-exist with other need to be installed first. Thus to make your machine dual bootable
- Install Windows First
- Install Linux Distro(s)
However note that if you upgrade your Windows it might re-write the MBR(Master Boot Record) and you won’t be able to boot the Linux distributions then. To fix this you’ll have to re-install GRUB and configure it for Dual Boot again.
This is the first installation screen, once you select Installation a Linux kernel is loaded first and then installation process is started beginning with probing the hardware and loading the necessary device drivers. The device drivers are loaded as kernel modules which can be thought of as a plugin to the kernel. Once loaded these become part of the running kernel and if a module behaves badly then it can crash the system.
In case you’re facing an issue with a particular module while installing, for example your WiFI hardware isn’t fully supported by the open sourced driver and requires a binary
blob or a firmware update then you might want to disable that particular module during installation. For example machines that have a NVIDIA graphics card, the driver is proprietary and made available for free by NVIDIA and needs to be installed separately post installation.
Terminology Used
Term Used Description
Frame Buffer or Frame Buffer device Your graphics output device. Could be a monitor / TV or a dedicated Graphics card.
Desktop Environment The work environment, it could be a GUI or console only. The GUI ones are called Desktop environments and multiple desktop environments available, some are extremely graphics heavy while others are extremely light. Two of the most popular ones are GNOME and KDE. If you’re planning to also use a VNC connection it’s recommended to go with GNOME though.
X Window System This is the original Windowing system and was the de-facto Windowing system for Linux but some distributions have adopted a new Windowing system now.
Wayland – Weston This is a relatively new Windowing system found mostly with KDE environment.
Hard drives / SATA disks The parallel ATA drives (ATA) drives appear as /dev/hd* while the serial ATA drives (SATA) drives appear as /dev/ sd*. The * is replaced by an alphabet for a disk and for a partition it also appends the partition number. For example
These devices are also known as block devices since they operate on chunks of blocks of bytes rather than individual bytes.
Disk Paritions As shown in the example above Disk Partitions appear as just separate devices and not as any labels. There are 2 formats available
RAID and Logical Volumes / Logical Volume Mangar (LVM) This is mostly used where data needs to have a fail safe switch and is done using multiple disks. In this case two or more physical disks are combined together to be viewed as a single disk. More physical storage can be added / removed at any time.
Swap Partition When running Linux on a system with lesser memory this can come useful. The Swap partition is a specific area of disk used entirely by the kernel for storing live contents of RAM when memory is required for the kernel to operate properly.
Ideally it should be twice the size of your RAM, however if there’s enough RAM available you may not require it at all or give it lesser space since it won’t be available to user.
It can also be turned on / off dynamically using swapon and swapoff commands.
File System A file system is what is used by user programs to store and retrieve files. There are numerous file systems available for the Linux kernel and all are available as loadable kernel modules. Major file system modules available are ext4, btrfs, squashfs, nfs , xfs etc.
To load a specific kernel module you can use the command modprobe or insmod.
To create a file system we can use mkfs.<fs_type> <block device>
For example
File Systems are always made on either logical volumes or partitions but never directly on the whole disk as such without the proper alignment options in place.
Mount point A block device which has been properly formatted with a file system needs to be mounted first before it can be used.
A mount point is a directory where a block device is mounted under. It can also be thought of attaching the file system present on the block device under the directory so it can be usable.
For example: Consider we’ve a directory named /mnt and a block device /dev/sda1 and we would like to mount (attach) the file system on this block device to /mnt. So we can do that using
mount -t <fs_type> /dev/sda1 /mnt
Now the files on the block device can be accessed under
the /mnt directory.
NOTE that the module of fs_type must be loaded before we can mount since that module is actually the file system driver which understands the particular file system.
Mount Boundary Some operations are allowed only on one block device. For example let’s consider there are two block devices /dev/sda1 and /dev/sda2 and these are mounted on /mnt1 and /mnt2 respectively.
Now if we wanted to create a soft link of a file from /mnt1/ file1 to /mnt2/file2 that wouldn’t be possible since these are two separate file system instances.
The image to the left shows the expert partitioning mode. You might not want to do this on your first try though!
You can control how much space you want and how many partitions you want. No need to configure RAID if you’re not using at least 3 “real physical disks”.
Packages and Package Database
Each software is called as a “package” and these packages are available as an installable unit. Unlike other Operating Systems where an executable takes over and installs the files, most Linux distributions bundle a tool to install packages. Most popular installable units are .deb and .rpm with .rpm being the most widely available. RPM (RPM Package Manager) packages are installed via rpm tool while .deb packages are installed via dpkg tools.
When a package is installed via any of the above, it’s meta-data, is stored in a system-wide database which can be looked up later using the same tools. The meta-data includes information about what files does a package provides, where has it been installed, version, license etc. However it’s not required to install any package to use it, if you can compile it you can always use it without system- wide installation
Package Repositories (“repos”)
Package repositories are stores from where you can lookup and install any software available. These repositories could either be via internet or they could be setup using a local media or a directory. The repositories available via internet could be either official repositories or you can also have non- official repositories, however if you choose to use any un-official repository then you might not get the support from your distribution vendor for the same. An example is shown below
As can be seen in the image, multiple repositories can be configured for a system and if they’re enabled they would be searched for a package if not already installed on the system. The official packages are usually signed with a gpg signature and SuSE by default doesn’t allow a non- signed package to be installed. If you still need to install such a package use the – – no-gpg-checks option from the command line tool zypper to install such a package.
Device Types
Linux classifies every device as a file. This is an abstraction presented to the user space programs implying that you can open / read / write to a device in pretty much the same way as a regular file. Not all devices are same and thus need to be identified using their characteristics. The device file supported by Linux are
Device Types
Device Type | Classification |
---|---|
Symbolic Links | A symbolic link is a disk based pointer which needs to point to a real file somewhere on the disk. The contents of a symbolic link is the path to the real file. These files show up with the letter l in front when ls -l is used. An example is shown belowlr-xr-xr-x 1 root wheel 0 Dec 1 09:12 stderr -> fd/2 |
Unix Domain Sockets | One way of communication is through the use of sockets. Sockets have the same abstraction as other device files however Unix Domain sockets can actually be seen through file listing (not TCP/IP or UDP). These appear with the symbol s in front when ls -l is used. An example is shown belowsrw-r--r-- 1 root wheel 0 Dec 1 09:13 /var/tmp/ filesystemui.socket |
Directories | These are special entries which can hold other file system entries. Sort of a container, these appear with the letter d when ls -l is used. An example is shown belowdrwxr-xr-x 3 root wheel 96 Dec 11 19:49 Volumes |
Block Device | A block device is typically a storage device for example a hard drive, a zip drive etc. These show up the a letter b in front when ls -l is used. An example is shown belowbrw-r----- 1 root operator 1, 0 Dec 1 09:12 disk0 |
Character Device | These really are general purpose devices and at times doesn’t even represent a physical device. These could be a frame buffer device, a clock , random number generator etc. These can be identified with a letter c in front when ls -l is used. An example is shown belowcrw-rw-rw- 1 root wheel 14, 0 Dec 11 19:29 /dev/random |
Regular Files | These are files anything not from the above options. These can be binary or text. These files appear with no letter when -rwxr-xr-x 1 root wheel 1331248 Jan 1 2020 zsh |
Kernel Modules
A kernel module is an extension code for the kernel which, when loaded, becomes part of the running kernel code. Since it’s not possible to compile kernel every time a new device is added to the system, kernel modules are used to provide “extra” functionality much like a plugin to an application software.
Most kernel modules provide drivers viz file system drivers, device drivers or some core kernel extensions viz SELinux. You can even write an extremely simple “hello world” kernel module and load it, we’ll do this later in this series. The kernel modules or “kernel objects” usually end up with an extension “ko” post compilation.
Loading a kernel module
Most devices would work out of the box with Linux as most distributions include a lot of drivers, even when the device isn’t present on the system. However since most of the source code is available for the drivers nothing stops you from tweaking it and using that tweaked driver instead.
When you plugin a USB device, the USB hooks allow the driver to be loaded automatically without your intervention. However if that USB device class isn’t present in the hook or you’re adding a new USB device to your system then it might need to be loaded by yourself. For this purpose there are actually two commands, however you’ll need superuser access to run these commands
Loading Kernel Modules
Command | Description |
---|---|
insmod | This command loads a kernel module. It requires the path where the kernel module is present and doesn’t check if any required dependent modules are already loaded or not. An example invocation is shown belowinsmod <path_to_my_kernel_module> |
modprobe | This command loads the kernel module from a pre- configured standard location on the system by default (/lib/modules/`uname -r`) It also checks for dependencies for a module generated using depmod and attempts to load them first before loading the dependent module. An example invocation is shown below modprobe <module_name> The module name is the name of “ko” file not the path to the file itself. |