Demystifying Linux System Management: Navigating Filesystem and Storage
Tags: 120daysofdevops, linuxfile, linuxstorage
Published: 2023-06-16 19:13:58

_Step into a World of Discovery: Unveiling the Wonders of Linux System Management. Delve into the Secrets of Linux File Management during my exhilarating #120daysofdevops adventure. Come along as we navigate the vast realms of the filesystem and storage, honing our skills in efficient system control. Together, let's dive into the captivating world of Linux file management_

## Introduction
So far, we have gained valuable insights into Linux and DevOps. We began by providing a concise introduction to Linux and DevOps, and subsequently delved into the fundamental concepts of Linux Architecture on [Day 4.](https://dev.to/codebyuwabor/demystifying-linux-architecture-unravelling-the-inner-workings-of-the-operating-system-1fjn) In addition, we explored a subset of essential commands that form the foundation of your everyday toolkit in the terminal for efficient task completion on [Day 3](https://dev.to/codebyuwabor/beyond-basics-exploring-fundamental-concepts-of-linux-administration-techniques-31i0).

Now, let's delve into three pivotal aspects of managing your Linux systems effectively: system updates, software installation, and comprehending the purpose of system folders. Furthermore, we will explore the topic of storage, enabling you to develop a comprehensive understanding of its significance in Linux system administration.

## Ubuntu Software Management Decoded: Best Approaches and Techniques

The first thing we are going to look at is how we update our operating system. Most of you will be familiar with this process in a Windows OS and macOS, this looks slightly different on a Linux desktop and server.

We are going to be looking at the apt package manager, this is what we are going to use on our Ubuntu VM for updates and software installation.

Generally, at least on dev workstations, I run this command to make sure that I have the latest available updates from the central repositories, before any software installation.

```
sudo apt-get update
```

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2v53qmcs851mpbzxk533.png)


We have successfully updated our Ubuntu VM, ensuring that it is equipped with the latest operating system updates. Now, our next objective is to install additional software on the system.

For this demonstration, let's install a program called "`figlet`," which generates text banners.

Upon entering the command "`figlet`" in the terminal, you will notice that it is not currently installed on our system.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qwfsw2wj0k08xw3jnq33.png)

As you can see from the previous output, there are several `apt` install options available for us to consider. This is because the default repositories contain a program called figlet. To proceed with the installation, let's execute the following command:
`sudo apt install figlet`


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4otrqueg846yte9id6i8.png)

We can now use our `figlet `app as you can see below.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hpg8gq090kw655p8ijqf.png)

## File System Explained
Linux systems consist of various configuration files that govern the behavior and settings of the operating system and applications. If you wish to modify any aspect of the system, these configuration files are where you make the necessary changes.

In contrast to Windows, which has the C: drive as its root, Linux employs the symbol "/" to represent the root directory. This is the starting point from which we navigate the Linux file system. The root directory encompasses essential folders that play crucial roles in the Linux system's functioning.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0uflc18sa1xufeyasze5.png)

- The `/bin directory`, derived from the term "binary," serves as a location for storing essential binaries, executables, and tools that are crucial for your system's operation. It houses a variety of executables and commands that enable various functions and operations within your Linux system.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1h0v2l6y2xqm9d3h178o.png)

- `The /boot` directory holds all the critical files required for booting up your system. It contains essential components that determine how the system boots and which drive or partition it boots from.
Within the /boot directory, you will find configuration files, such as bootloader configurations (e.g., GRUB or LILO), kernel images, initial RAM disk (initrd) files, and other necessary files related to the boot process. These files are responsible for initiating the system startup, loading the kernel, and establishing the initial environment required for the operating system to begin functioning.

In summary, the /boot directory contains the necessary files and configurations that facilitate the booting process and dictate the boot device or partition used by your Linux system.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o3j14lvbmczf7yweodm6.png)

- `The /dev `directory serves as a repository for device-related information in Linux. It contains special files known as device nodes that act as interfaces to physical and virtual devices connected to the system.

Within the /dev directory, you can access and manage various devices, including disk drives, through the device nodes. For instance, your primary operating system disk is typically represented as "sda" in the /dev directory. Other devices, such as external storage drives, input/output devices, and network interfaces, also have corresponding device nodes in this directory.

By interacting with the device nodes in /dev, you can access and manipulate the connected hardware devices, enabling tasks such as reading from or writing to disks, managing input/output operations, and configuring device-specific settings.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l4bwvqk03ozypa18ip1x.png)

- `/etc` Likely the most important folder on your Linux system, this is where the majority of your configuration files are.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g8opxcl8dny5mxy59hmu.png)

- `/home `- this is where you will find your user folders and files. We have our vagrant user folder. This is where you will find your Documents and Desktop folders that we worked in for the commands section.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/blf0ypyt7rtq5xi3n7dc.png)

- `The /lib` directory plays a crucial role in the Linux system by housing shared libraries that are essential for the proper functioning of the binaries and executables located in the /bin directory.
Shared libraries, often denoted by file extensions like .so (shared object), contain code and resources that are shared across multiple programs. These libraries provide common functionality, such as system calls, input/output operations, and other essential functionalities that programs rely on.

In` /lib`, you will find a collection of these shared libraries, which are dynamically linked to the binaries residing in /bin and other directories. When a program is executed, it dynamically links to the required shared libraries from /lib to access the necessary functions and resources.

Therefore, the `/lib` directory serves as a vital repository for shared libraries, enabling efficient resource sharing and reducing redundancy across the Linux system's executables and binaries.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ztavj5ilnpexcxi5f0b4.png)

- `/media` - This is where we will find removable devices.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mqmpwt5t29qniv8eznjo.png)

- `The /mnt` directory serves as a temporary mount point in Linux. It is specifically designed to be a location for manually mounting external or temporary file systems.

When you need to access or work with external storage devices, such as USB drives, external hard disks, or network shares, you can mount them to specific directories under /mnt. By doing so, you make the contents of the mounted file system accessible within that directory.

In the upcoming storage section, we will explore this concept further and discuss various aspects related to mounting, managing, and working with storage devices in Linux. Stay tuned for more detailed information on utilizing the /mnt directory as a temporary mount point.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ddm7unse0papjir052jy.png)

- `/opt` - Optional software packages. You will notice here that we have some vagrant and virtual box software stored here.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1dff2arv1f0i5gzqv0k0.png)

- `The /proc `directory serves as a virtual file system that provides kernel and process-related information in Linux. It offers a structured interface for accessing real-time data about the system's running processes and the kernel itself.

Within the /proc directory, you can find a collection of numbered directories, each representing a running process on the system. These directories contain detailed information about each process, including its ID (PID), memory usage, CPU utilization, file descriptors, and more.

Additionally, the /proc directory contains various system-related files and directories that offer insights into the kernel's configuration, hardware devices, and system statistics. You can access information about CPU, memory, network interfaces, interrupts, and other kernel-related details through these files.

Similar to the /dev directory, which provides access to device information, the /proc directory acts as an interface to kernel and process information, offering a dynamic and informative view of the system's inner workings.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tp8ldtmau51sxkv2bn5n.png)

- `/root` - To gain access you will need to sudo into this folder. The home folder for root.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2ek9nxxm7kokt1gvub6p.png)

## `The /run` directory serves as a placeholder for application states in Linux. It provides a location where applications can store temporary files, runtime data, and other information related to their current state.

This directory is particularly useful for applications that require a location to store data that needs to persist across reboots but should be cleaned up during each system start up. It allows applications to store runtime files and information without relying on specific storage locations that may vary between different systems or configurations.

The `/run` directory is typically used by daemons, services, and other background processes to store their runtime files, such as process IDs (PIDs), socket files, lock files, and other temporary data. By utilizing the `/run `directory, applications can maintain their state across system reboots and ensure proper initialization and coordination with other components.

In summary, the `/run` directory acts as a convenient location for applications to store temporary files and runtime data, facilitating proper handling of application states in a consistent and system-independent manner.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2ucuykp9jd3d6sqcbo9d.png)

- `/sbin` - Sudo bin, similar to the bin folder but these tools are intended for elevated superuser privileges on the system.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ri5vtzsll48pkrs1newm.png)

- `/tmp` - temporary files.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yoy4qhxpt1ncmbw7w3q2.png)

- `The /usr` directory plays a significant role in Linux as it houses user-specific files and resources. When standard users install software packages on their systems, these packages are typically installed in the `/usr/bin` location.

Within `/usr/bin`, you will find executable files for various user-installed software applications. These binaries are readily accessible to users, allowing them to execute the installed programs conveniently.

Moreover, the `/usr` directory encompasses additional subdirectories such as `/usr/lib`, which contains libraries specific to user-installed software, and `/usr/share`, which holds architecture-independent data shared among applications. These subdirectories provide a structured organization for user-specific resources and ensure compatibility and consistency across installed software packages.

By separating user-installed software into the `/usr` directory, the Linux system maintains a clear distinction between system-wide files and user-specific files, promoting better management and control over installed software packages.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9sf1bq0tcv2qjkacvqlr.png)

- `/var` - Our applications get installed in a bin folder. We need somewhere to store all of the log files this is `/var`

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/inkepeoojn4hwmfno31b.png)

## Storage
When working with a Linux system or any other system, it is essential to identify the available disks and understand the amount of free space on those disks. The following commands will assist us in recognizing, utilizing, and managing storage effectively.

The first command, "`lsblk,`" allows us to list the block devices on our system. By executing this command, we can obtain information about the available disks and their associated partitions. For instance, the disk labelled "`sda`" represents our physical disk, while "sda1," "sda2," and "`sda3`" denote the partitions on that particular disk.

Using the output of the "`lsblk`" command, we can gather a clear overview of the disks and partitions present in our system, which is crucial for storage management and allocation.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lxqfl50iwwclssdciup8.png)

- `df` gives us a little more detail about those partitions, total, used and available. You can parse other flags here I generally use `df -h` to give us a human output of the data.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/74tvo9y4unsaab895ssl.png)

If you are adding a new disk to your Linux system, the process is similar to how it is done in Windows. In Linux, you can format the disk in the terminal using the command "sudo mkfs -t ext4 /dev/sdb," where "sdb" corresponds to the newly added disk. This command will format the disk with the ext4 file system, but you can choose a different file system if desired.

After formatting, the next step is to mount the newly formatted disk to make it usable. You can achieve this by creating a directory in the `/mnt` folder, such as "`sudo mkdir NewDisk`," and then using the command "`sudo mount /dev/sdb newdisk`" to mount the disk to that location.

When it comes to removing storage from your system safely, it is important to unmount it first rather than simply pulling it from the configuration. You can unmount the disk using the command "sudo unmount `/dev/sdb`."

If you intend to use the disk persistently, such as for a database or other long-term use cases, you will want the disk to be automatically mounted upon system reboot. To accomplish this, you need to add the disk to the `/etc/fstab` configuration file. Without adding the disk to this file, it won't be automatically mounted upon system restart, and you would need to manually go through the above process again. The data will still remain on the disk, but it won't be accessible unless the configuration is added.

After editing the `fstab` configuration file, you can validate your changes by using the command "`sudo mount -a`." If there are no errors, your changes will persist across restarts.

In my tomorrow session, I will cover how to edit files using a text editor.

Thanks for Reading, hope to see you tomorrow.