| technology | system admin - Team Nuggets
How to Manage Linux Devices: A Primer
If you're a newly aspiring Linux practitioner, you may be looking to gain some deeper knowledge of how Linux devices are managed within the larger Linux ecosystem. In particular, you may be looking to add or manage Linux devices and have found the process to be quite different from other operating systems such as Windows. The reason for this difference, and a major foundational aspect of Linux, comes down to the fact that everything in Linux is a file.
To better understand this, and to build a stronger understanding of how to manage Linux devices, let's start by better understanding the foundation of how Linux operating systems are designed.
How is a Linux Operating System Different from Windows?
As mentioned above, one of the major differences between a Linux-based operating system and a Windows-based operating system is the fact that everything in a Linux operating system is constructed of files. Yes, when we say everything, we mean everything. From the Master Boot Record to Linux devices, everything in a Linux operating system is a file.
And in reality, this unique design approach provides a lot of benefits to Linux administrators that administrators of other environments simply do not have. Specifically, while a Windows environment has specific drives where applications are installed and dedicated folders such as program files to store application executables, data, and other files, it's the Linux file-based system that offers extreme flexibility in the design approach.
In the following sections, we'll investigate how Linux devices are managed within a Linux environment, dig into some of the foundational differences between a Linux-based file system and a Windows-based environment and provide a bit of a pros-and-cons list to becoming acquainted with Linux. Let's jump in.
Managing Devices in Linux
When a Linux administrator connects a physical device to a Linux operating system for the first time, a device file will be created in the /dev directory. This /dev directory can be thought of as a virtual filesystem that is created by the Linux kernel to support device file configuration and management. These device files allow the Linux operating system and users within the Linux environment to interface with the actual physical device. Importantly to note, these device files are not device drivers, but rather act as an intermediary file that supports the transmission of data between the operating system and the device. So, any time you add a new device to your Linux-based system, you'll be sure to find an accompanying device file in the /dev directory.
Common Device Types within Linux
Without digging into the weeds and addressing all of the various device file types in Linux (because there are a lot of them) let's focus on the more common Linux device files that you may come across. In particular, you'll find two common Linux device files in the /dev folder: Character devices and block devices. These device file types are defined by how data is transmitted. Let's take a look at character devices and block devices to better understand the differences and understand what types of devices utilize each device file type.
As noted, character devices are defined by how the device in question transmits data. Specifically, in this case, character devices transmit data character by character or in series. Common character devices include the mouse, keyboards, serial ports, and sound cards.
A Block device, on the other hand, is a device that transmits information by sending blocks of data rather than sending single characters in a serial fashion. Common block devices include hard drives and USB devices.
Other Common Device Files Found in Linux
Aside from the common device types listed above, there are also a host of other common device files found in a Linux /dev directory. Let's take a deeper look at some of the common Linux files that you will find in a Linux directory.
The dev/null file is a very special device file that is located within even Linux device directory independent of the distribution of Linux. The dev/null file is unique in the sense that it is a file used for writing to rather than reading from. Furthermore, the dev/null file is designed to discard any information that is written to it. Why in the world would we want that?
Well, without digging into too much detail, when using commands like stdout which will write outputs based on certain commands, it can often be useful to discard certain pieces of information output from stdout. Take for example, if we are parsing certain data, where some data output is needed whereas other data is junk. In this case, directing the parsed junk data to write to null will effectively discard that unneeded data! As you dig into more advanced Linux practices, you'll find some other great uses for the dev/null file.
dev/sda, dev/sdb, dev/sdc
Another common device file is the sd'x' file. Sd files represent mass storage devices such as hard drives and USB drives. In short, the sd file simply denotes devices that have been detected by the computer. However, it's important to note that the following alphanumeric character that follows the sd file represents how the mass storage device was identified. In particular, sda represents a mass storage device that was detected by the Linux system before sdb and so on. So next time you see a variety of device files starting with sd, you'll know that these are simply mass storage devices detected by your Linux machine.
dev/hda, dev/hdb, dev/hdc
In comparison to SATA-based mass storage devices, PATA-based drives are going to follow a similar convention, however, in the device directory, you'll see hd'x' where x indicates the order of how the Linux system identified PATA-based drives were connected to the machine.
dev/sdx, and dev/hdx partitions
Another important attribute of the Linux /dev directory is how storage devices are partitioned. If you see a device file defined as dev/sda1 or dev/sda2 this simply indicates the different partitions that are available on that SATA storage device. In this scenario, dev/sd1 would denote a primary partition, whereas, dev/sda2 would denote a secondary partition on the drive. Likewise, with PATA-based storage, dev/hda1 and dev/hda2 denote partitions on the
PATA-based storage device.
What Commands to Avoid
Let's conclude with a few commands to steer away from. It's our guess that if you're looking to get more familiarized with Linux devices, you also want to keep your Linux environment in safe, good working order. So as you explore the /dev directory remember that some commands can pose some serious problems, like overwriting the hard drive with junk. This one's obviously important.
With a few simple commands, a Linux practitioner can quickly cause some serious problems within their environment. By using the following commands:
Any command > /dev/hda
This simple command will effectively overwrite everything within that selected drive. Not good!
Remember the dev/null device file we discussed earlier? Well, by using the following command, a user will send all of the drive's data to null, effectively wiping the Linux environment.
mv / / dev/null
The reason we share some of these examples is only to point out that you wield some incredible power when working in Linux and that power needs to be handled with great responsibility. So, move forward with caution and arm yourself with knowledge along the way!
As you move forward to gain a deeper understanding of Linux devices, be sure to leverage all of the resources available at CBT Nuggets to ensure you are honing those skills as a top-notch Linux practitioner. And hopefully, by simply scraping the surface of what's available in the world of Linux, you'll have a new founded appreciation for how Linux environments are configured and the importance of Linux device files.