26-10-2016, 09:35 AM
1461202009-UnderstandingFileSystemSuperblockinLinux.pdf (Size: 776.29 KB / Downloads: 26)
Extended Filesystem being the default file system in Linux, we
will be focusing ext file system in this article to understand
superblocks.
Before we get to understanding Superblocks in a file system,
let’s understand some common terminologies and building blocks of a file system
Blocks in File System
When a partition or disk is formatted, the sectors in the hardisk is
first divided into small groups. This groups of sectors is called as
blocks. The block size is something that can be specified when a
user formats a partition using the command line parameters
available.
In the above command we have specified block size while
formatting /dev/sda1 partition. The size specified is in bytes. So
basically one block will be of 4096 bytes.
Block Size for Ext2 can be 1Kb, 2Kb, 4Kb, 8Kb
Block Size for Ext3 can be 1Kb, 2Kb, 4Kb, 8Kb
Block Size for Ext4 can be 1Kb to 64Kb
The block size you select will impact the following things
Maximum File Size
Maximum File System Size
Performance
Related: Linux Read and Write Performance Test
(http://www.slashroot.in/linuxfilesyste...rmancetest)
The reason block size has an impact on performance is
because, the file system driver sends block size ranges to the
underlying drive, while reading and writing things to file system.
Just imagine if you have a large file, reading smaller blocks
(which combined together makes the file size) one by one will
take longer. So the basic idea is to keep bigger block size, if your
intention is to store large files on the file system.
Hard disk sector is nothing but a basic storage unit of
the drive, which can be addressed. Most physical drives
have a sector size of 512 bytes. Please keep the fact in
mind that hard disk sector is the property of the drive.
Block size of file systems (that we just discussed above)
is a software construct, and is not to be confused with
the hard disk sector.
A linux Kernal performs all its operations on a file
system using block size of the file system. The main
important thing to understand here is that the block size
can never be smaller than the hard disk's sector size,
and will always be in multiple of the hard disk sector
size. The linux Kernel also requires the file system block
size to be smaller or equal to the system page size.
Linux system page size can be checked by using the
below command
Block Groups in File System
The blocks that we discussed in the previous section are further
grouped together to form block groups for ease of access during
read and writes. This is primarily done to reduce the amount of
time taken while reading or writing large amounts of data.
The ext file system divides the entire space of the partition to
equal sized block groups(these block groups are arranged one
after the other in a sequential manner).
A typical partition layout looks something like the below at a very
high level.
What is File System Superblock?
The most simplest definition of Superblock is that, its the
metadata of the file system. Similar to how inodes stores
metadata of files, Superblocks store metadata of the file system.
As it stores critical information about the file system, preventing
corruption of superblocks is of utmost importance.
If the superblock of a file system is corrupted, then you
will face issues while mounting that file system. The
system verifies and modifies superblock each time you
mount the file system.
Superblocks also stores configuration of the file system. Some
higher level details that is stored in superblock is mentioned
below.
Blocks in the file system
No of free blocks in the file system
Inodes per block group
Blocks per block group
No of times the file system was mounted since last fsck.
Mount time
UUID of the file system
Write time
File System State (ie: was it cleanly unounted, errors
detected etc)
The file system type etc(ie: whether its ext2,3 or 4).
The operating system in which the file system was
formatted
The primary copy of superblock is stored in the very first
block group. This is called primary superblock, because
this is the superblock that is read by the system when
you mount the file system. As block groups are counted
from 0, we can say that the primary superblock is stored
at the beginning of block group 0.
As superblock is a very critical component of the file
system, a backup redundant copy is placed at each
"block group".
In other words, every "block group" in the file system will
have the backup superblock. This is basically done to
recover the superblock if the primary one gets
corrupted.