[Novalug] linux fundamentals (VEQ)

Stuart D. Gathman stuart@gathman.org
Tue Mar 10 16:03:32 EDT 2015


On Tue, 10 Mar 2015, Beartooth via Novalug wrote:

> 	Very Elementary Question (VEQ): What is a block is a file is a 
> partition is a sector is data? And how do the differences square with the 
> (perhaps outdated) principle that "in Linux =everything= [sic] is a file"?

Let me expand Dereks explanation with an example.

A disk drive becomes the device file /dev/sda.  You can read and write
it like a file.  Physical reads and writes are in multiples of blocks
and aligned accordingly.

Using the kpartx utility, you can create additional device files for
slices (range of blocks) of the disk.  By convention, these are named 
/dev/sda1, /dev/sda2...  If the device has a recognizable partition
table, these will be created automatically.  But you can always do it
manually (e.g. if the partition table got trashed, but you can
reconstruct the block ranges some other way).

Kpartx actually uses device-mapper, which can map any sequence of slices
of one or more block device files to another block device file.  LVM2
uses this to map arbitrary collections of physical partitions to logical
volumes.  This is much more flexible than old fashioned single slice 
partitions, allowing growing and shrinking, even while mounted and in 
operation.  At the end of the day, however, you still have a block
device.

The md driver maps collections of block devices to another block
device, using RAID algorithms.  This can add redundancy or improve
performance or both.  At the end of the day, however, you
still have a block device.

A file system driver maps a block device to a collection of inodes which
are either files or directories.  This provides the hierarchical
filesystem and "regular" files.  There are many filesystem drivers to
pick from, like ext3, ext4, btrfs, xfs, zfs, ...

Any regular file can be treated as a block device file using the loop
driver.  So you can copy a disk to a regular file, and then create a
block device for it using losetup.

Other filesystem drivers construct their inode collection from network
connections to other servers in addition to local block devices or other
filesystems.  This provides a distributed filesystem, that can retain
data even when some nodes are wiped out.

All these transformations of block devices can be applied recursively 
to any demented level desired.  Performance may suffer when you get too
carried away.



More information about the Novalug mailing list