“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
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