“Everything is a file” at Linux

Let’s look at how disk drive partition and files look in Linux:

Script body:

#!/usr/bin/env bash
ls -l /dev/sda5
ls -l just_a_file

script body in yellow rectangle, the output is next to the rectangle

ls is the command to list selected files by names: /dev/sda5 is a special file associated with disk drive partition and just_a_file is a file at files system displayed by console. What is the difference in the output? The first letter “b” shows that /dev/sda5 is a block device file – not just a file. Let’s look from the inside of Linux: the global conception of data storage and manipulation at Linux is – “everything is the file”. It means that even devices a Linux point of view can be represented as files. In the deep of OS code you can find that file is an abstract instance that has several well-structured functions specific for the date it holds:

  • read function
  • write function
  • open function (to make correct data access on several readers/writers)
  • close function
  • ioctl function (very specific actions function for device driver files)

In this conception – the hard disk drive is represented as a file at /dev/ folder. As a file, this HDD has a read function defined. This read acts like any read of file data at any application layer program. So – we can read the HDD entry. We will be in logic if this file has a write function defined also.

Disk cloning in Linux using dd command

Everyone likes to have a copy of the disk drive to have a chance to recover. Even If you don’t want a copy now – you will want when your first HDD will be broken. It is used to clone all of the data from the initial etalon dump disk to several hosts disks. It will save you a huge portion-time. But what is the action options to clone the disk – let’s look:

  • have disk drive big enough to store your host disk drive dump in the file at this drive
  • connect several disk drives to your localhost and copy it set by set
  • connect several disk drives to remote hosts and transmit your host disk drive data over the network to remote hosts disk drives

All of these options are available at the Linux command line and are easy to establish and understand. “Everything is a file” at Linux: from disk driver to file at application layer point of view 

Similar Reads

“Everything is a file” at Linux

Let’s look at how disk drive partition and files look in Linux:...

How to detect disk drive files?

Reasonable question is – how to detect the file and the “file size” for a copy. It is possible by using “lsblk” and “df” Linux utilities. First utility list of block devices files of the system. The second utility shows the size of the device in blocks....

Using dd to store disk dump at file:

Now we go one by one to use cases to look at how to use “dd“. First, let’s look at storing disk images to file. In our case, we will copy cdrom device disk image clone to the file that we will specify....

Using dd to store raw disk image at other disk connected to host:

As mentioned before it is very useful to clone the main disk as it is: from one disk drive to another. “dd” is useful for this case also....

Store disk dump at another network-connected host disk

In this example, we will translate the dump of our disk over the network by using nc utility. This utility will be run at our host to put data in network and get it from the network. It will be run local – but you can write both of the sending and receiving scripts at different hosts....