Devices and drives in linux

This post and this website contains affiliate links. See my disclosure about affiliate links.

how to list all hard disks in linux from command line

Hard Disk, Hard Drive, Disk Drive or Hard Disk Drive are all names for a data storage device (hardware device) for storing and retrieving digital information usually in a computer. A computer can have multiple hard disks attached to it, both internal and external.

Now these hard disks can be further divided to multiple logical containers in order to host different file systems or to keep file systems/files separate. These are called partitions and they can then mounted independently with out affecting the other disks and partitions. At a high level abstraction, you can view partition as separate disks as well.

Hard disks on a system are detected and/or identified by various device drivers in the kernel and then assigned an unique device id at boot time, enabling it to be mounted and read later (yeah, this is an over simplification of how it all works but it should suffice for this post). We will see later in the post how you can list disks that have been identified by the system.

The hard disks can be differentiated based on the interface used to interact with them. Some of the commonly used types of disk are SCSI (Small Computer System Interface), ATA or IDE (Advanced Technology Attachment), SATA (Serial ATA), SAS (Serial Attached SCSI) among others. As I mentioned, the physical hard disk is assigned an unique id at startup. This can configured (using udev among others) so that you can assign it pretty much id, but usually most systems follow some universally accepted conventions when naming devices.

By convention, the IDE disks use the device id prefixed with hd and the SCSI (and SATA) disks prefix their device id with sd. So, an IDE disk would be located at /dev/hd(*). eg: /dev/hda, /dev/hdb etc. Similarly, the SCSI disks would be /dev/sda, /dev/sdb etc or in general of the format /dev/sd(*).

Источник

How to Manage Linux Devices: A Primer

How to Manage Linux Devices: A Primer picture: A

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.

Читайте также:  Kali linux network nat

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.

How to Run Basic Linux File Commands

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.

Читайте также:  Что такое линукс демон

Character Devices

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.

Block Devices

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.

dev/null

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.

Читайте также:  Проверить версию приложения linux

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

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:

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.

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!

Final Thoughts

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.

Источник

Оцените статью
Adblock
detector