Post

Linux pt 3: Software Packages, Filesystem, and Storage (90 Days of DevOps)

Linux pt 3: Software Packages, Filesystem, and Storage (90 Days of DevOps)

So far in this blog’s coverage of the Linux portion of the “90 Days of DevOps” challenge:

In this post, we will look at some of the core system administration tasks to be familiar with on a Debian-based Linux OS.

Managing Debian software packages

First, if necessary, we start up and reconnect to our Linux VM using Vagrant. From the same directory where the Vagrantfile is stored, we run:

1
2
$ vagrant up
$ vagrant ssh

Updating the installed packages

Software packaging is handled differently across different distributions of Linux. There are a number of package management tools available in Debian Linux, the distribution installed on our virtual machine. The one we’ll use to check for updates is apt.

First, we make sure our system is aware of any package updates that are available for installation.

1
2
3
4
5
6
7
8
$ sudo apt update
Get:1 https://security.debian.org/debian-security bookworm-security InRelease [48.0 kB]
Hit:2 https://deb.debian.org/debian bookworm InRelease  
Get:3 https://deb.debian.org/debian bookworm-updates InRelease [55.4 kB]
...

Fetched 795 kB in 2s (424 kB/s)    
Reading package lists... Done

Since we’re running the “stable” version of the Debian Linux distribution, it is not too surprising that there are no new updates available.

If there were new updates available to any of our currently installed packages, we could apply them all by running:

1
$ sudo apt full-upgrade

Alternatively, if we wanted to do the same thing while ignoring any package updates that would require the installation of additional software packages (i.e. to avoid installing any new dependencies), we could run:

1
$ sudo apt upgrade

Installing a new package

Next we use apt to install a software package.

The command below installs a package named figlet, which is a small program used to generate ASCII banners.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
$ sudo apt install figlet
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following NEW packages will be installed:
  figlet
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 137 kB of archives.
After this operation, 757 kB of additional disk space will be used.
Get:1 https://deb.debian.org/debian bookworm/main amd64 figlet amd64 2.2.5-3+b1 [137 kB]
Fetched 137 kB in 0s (302 kB/s)
Selecting previously unselected package figlet.
(Reading database ... 30471 files and directories currently installed.)
Preparing to unpack .../figlet_2.2.5-3+b1_amd64.deb ...
Unpacking figlet (2.2.5-3+b1) ...
Setting up figlet (2.2.5-3+b1) ...
update-alternatives: using /usr/bin/figlet-figlet to provide /usr/bin/figlet (figlet) in auto 
mode
Processing triggers for man-db (2.11.2-2) ...

With the command now installed, we use figlet to generate a quick banner:

1
2
3
4
5
6
7
8
$ figlet 90DaysOfDevOps
  ___   ___  ____                   ___   __ ____              ___            
 / _ \ / _ \|  _ \  __ _ _   _ ___ / _ \ / _|  _ \  _____   __/ _ \ _ __  ___ 
| (_) | | | | | | |/ _` | | | / __| | | | |_| | | |/ _ \ \ / / | | | '_ \/ __|
 \__, | |_| | |_| | (_| | |_| \__ \ |_| |  _| |_| |  __/\ V /| |_| | |_) \__ \
   /_/ \___/|____/ \__,_|\__, |___/\___/|_| |____/ \___| \_/  \___/| .__/|___/
                         |___/                                     |_|        

Removing a package

Removing an installed package using apt is straightforward:

1
2
3
4
5
6
7
8
9
10
11
12
$ sudo apt remove figlet
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages will be REMOVED:
  figlet
0 upgraded, 0 newly installed, 1 to remove and 0 not upgraded.
After this operation, 757 kB disk space will be freed.
Do you want to continue? [Y/n] Y
(Reading database ... 30550 files and directories currently installed.)
Removing figlet (2.2.5-3+b1) ...
Processing triggers for man-db (2.11.2-2) ...

Using third-party repositories

By default in Debian Linux, apt will only install and update software contained in the official Debian repositories. In addition to those official repositories, many unofficial repositories exist as well.

As mentioned in the link, there are a variety of reasons why these repositories are kept separate from the official ones, including differences in license agreements.

Companies often provide instructions for adding their third-party repository as an installation source on a Linux system (for example, HashiCorp with their vagrant repository).

The act of adding unofficial repositories to a system makes them trusted install sources as far as apt is concerned. For that reason, it is important to only add third-party repositories that you trust with the security and stability of your system.

The Linux Filesystem

The Linux filesystem is organized based on the filesystem hierarchy:

1
$ man hier

The filesystem hierarchy man page conveniently details the conventional purpose of many important directories on a Linux system.

  • Some examples:
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    
    /      This is the root directory. This is where the whole tree starts.
    /boot  Contains static files for the boot loader. This directory holds only the
           files which are needed during the boot process.
    /dev   Special or device files, which refer to physical devices.
    /etc   Contains configuration files which are local to the machine.
    /home  On machines with home directories for users, these are usually beneath this
           directory, directly or not
    /mnt   This directory is a mount point for a  temporarily mounted filesystem.
    /proc  This is a mount point for the proc  filesystem, which provides information
           about running processes and the kernel. This pseudo-filesystem is described
           in more detail in proc(5).
    /root  This directory is usually the home directory for the root user
    /usr/bin
           This is the primary directory for executable programs.
    /usr/sbin
           This directory contains program binaries for system administration
    /var   This directory contains files which may change in size, such as spool and
           log files.
    /var/log
           Miscellaneous log files.
    

Storage

Below are some commands we can use to identify and manage storage on a Linux machine.

lsblk - list block devices

1
2
3
4
$ lsblk
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTS
sda      8:0    0  100G  0 disk 
└─sda1   8:1    0  100G  0 part /

We see from the above that:

  • There is one block device attached to this system
  • The block device maps to a partition of disk device sda named sda1.
  • The block’s filesystem is 100GiB in size, and is mounted to the / directory on this Linux system.

Sometimes running lsblk with the --fs (“filesystems”) option can be helpful. Here is what the output looks like:

1
2
3
4
$ lsblk --fs
NAME  FSTYPE FSVER LABEL UUID                                 FSAVAIL FSUSE% MOUNTPOINTS
sda1  ext4   1.0         6d2244fa-cb7d-4406-b194-8aa4f498553b   91.3G     2% /
└─sda                                                                        

Notice how this format adds our block device’s file system type (ext4) and total usage of that filesystem (2%), along with the block’s UUID. The UUID is especially useful when we need to add a volume to the file systems table (/etc/fstab).

df - report file system space usage

The man page for df might not mention the fact, but df is short for “disk free”, as in “free space available on the disk.” It is commonly run with the -h option, which shows the storage measurements in “human-readable” format.

1
2
3
4
5
6
7
8
9
$ df -h
Filesystem      Size  Used Avail Use% Mounted on
udev            3.9G     0  3.9G   0% /dev
tmpfs           785M  448K  785M   1% /run
/dev/sda1        98G  1.6G   92G   2% /
tmpfs           3.9G     0  3.9G   0% /dev/shm
tmpfs           5.0M     0  5.0M   0% /run/lock
vagrant         1.4T  186G  1.2T  14% /vagrant
tmpfs           785M     0  785M   0% /run/user/1000

mkfs - build a Linux filesystem

If we had an unformatted second partition on sda named sda2, and we wanted to create an xfs filesystem on it, we could run:

1
$ sudo mkfs -t xfs /dev/sda2

mount - mount a filesystem

With that new filesystem created, we could access it using the mount command.

1
$ sudo mount -t xfs /dev/sda2 /<mountpoint>

where <mountpoint> is replaced with an actual path such as /mnt/newfilesystem.

umount - unmount filesystems

Similarly, we could unmount the filesystem if we no longer needed it. Both syntaxes below should work.

1
$ sudo umount /dev/sda2
1
$ sudo umount /<mountpoint>

Persistent mounts

Neither the mount nor the umount commands are remembered by the Linux machine after it reboots. In order to persistently mount specific filesystems across system boots, we can add entries to the /etc/fstab file.

After editing this file, it is a good idea to verify that it contains a valid configuration by forcing a mount of all the filesystems it lists (sudo mount -a).

If the command completes with no errors, then the configuration is valid. If not, the error should be fixed or the file restored to its previous state to prevent possible issues during the system’s next boot.

See you in the next post!

<< Back to 90 Days of DevOps posts

<<< Back to all posts

This post is licensed under CC BY-NC-SA 4.0 by the author.