CHAPTER 3. File System
Linux’s file system is outstanding when it comes to flexibility. Its design allows it to support regular, as well as special types of file formats. It can support text, programs, images, services, output, and input devices. Therefore, since it supports a variety of file formats, it can coexist with another OS.
Moreover, in the system, there is hardly a distinguishable factor between a file and a directory. It follows that directions are simply locations of file stacks.
Categorization of Files
To ensure a better understanding of the Linux file system, files are categorized. While it is considered safe to assume, knowing more information about a particular file allows programmers and system administrators to avoid complexities when using Linux. This also prevents them from performing long listings.
File categories:
The Art of Partitioning
Partitioning in Linux began when power failures threatened the majority of Linux users. There were days when an outage meant serious damages to a system.
Moreover, the primary reason for partitioning is to achieve a much higher data security level. The hard disk’s division allows safe grouping and protection.
Due to successful partitioning, you can prioritize data groups with more importance. When part of a hard disk is compromised, only that part of the disk is affected. The rest that is stored in other partitions remains untouched.
Two major partitions in a Linux system:
-
Swap – refers to extra memory or an expansion
-
Data – refers to normal data; refers to the necessities for starting and running a system
Recommended partitions:
-
A partition for necessary data
-
A partition for server programs and configuration data
-
A partition for programs and applications
-
At least one partition for user mails, archives, and database tables
-
At least one partition for specific files
-
At least one partition for virtual memory
Common partitions:
-
A partition that contains personal data
-
A partition that stores temporary files
-
A partition that stores third-party data
-
A partition that is solely for programs
Directories: The Root Directory & Subdirectories
In Linux, there is a directory called The Root Directory. It serves as the main directory and as programmers and system administrators would refer to it, it is the directory of all directories.
With The Root Directory come the subdirectories. These subdirectories manage files according to their assigned tasks.
Subdirectories and their content:
-
/home – home directory
-
/boot – the kernel and startup files; files that attempt to eliminate unnecessary bootloaders
-
/initrd – data regarding booting information
-
/dev – contains references to all CPU hardware peripherals
-
/bin – common shared system programs
-
/etc – important systems configuration data
-
/lib – library files
-
/lost+found – retrieved data from failures
-
/opt – files from third-party sources
-
/net – remote file systems’ standard mount point
-
/misc – miscellaneous data
-
/proc – information regarding system resources
-
/mnt – external file systems’ standard mount point
The Role of an Inode
In a Linux file system, an inode represents a file. An inode is a type of serial number that contains important information. Its primary role revolves around defining the number of files in a partition.
Throughout a Linux file system, especially one with multiple partitions, there are files with similar inode. To avoid complications, each partition is assigned its own inode.
Moreover, an assigned inode provides a description of a hard disk’s data structure. Once a hard disk’s initialization is finished, it can accept data storage during two points. One, data storage is acceptable during the installation process. Two, data storage is acceptable upon the addition of storage space to an existing system.
Information contained in an inode:
-
File type
-
File size
-
Owner or group owner of the file
-
Date and time of the creation
-
Date and time of the latest modification
-
Permissions
-
Number of links
-
Data address
What Is The Superblock?
In Linux’s file system, the information about basic file size and shape is called The Superblock. It allows a file system manager to peruse and maintain a file system’s quality.
Information in The Superblock:
-
Free blocks – displays the number of a system’s free blocks
-
Free inode – shows the original inode assignment
-
Free inodes – displays the number of a system’s free inodes
-
Block group number – refers to a number assigned to The superblock
-
Blocks per group - displays a group’s number of blocks
-
Block size – refers to a system’s block size; information is shown in bytes
-
Magic number – refers to the permission granted to mounting software for assessment
-
Mount count – refers to a system’s allowance for assessment
-
Revision level – refers to a system’s allowance for revision level confirmation
What Is a Group Descriptor?
A group descriptor is in charge of labeling a file’s data structure. It contains details to avoid duplication of data. Due to its role, a system’s possibility of corruption is minimal.
Information in a group descriptor:
-
Blocks bitmap
-
Free blocks count
-
Free inodes count
-
Inode bitmap
-
Inode table
-
Used directory count
File Modification: Finding, Mounting & Changing Sizes
A Linux file is usually easy to locate. Just search for a directory and the name that succeeds a “/” or a forward slash might be your preferred file.
Sample:
/home/lp.txt
As the sample shows, “/home/” is the directory and “lp.txt” is a file.
You can then start mounting. When mounting a file, the availability of a Linux kernel is necessary to check the standards. Its presence allows the validation of all of a system’s passed arguments.
Sample:
# mount
iso898 /dev/rom /dev/cdrom
As the sample shows, you are mounting three kinds of information. “iso898”, “/dev/rom”, and “/dev/cdrom”.
Apart from finding and mounting a file, you have the option to change a file’s size. This is done due to the occurrence of a file’s fragmentation.
Since files become inefficient during fragmentation, changing a file’s size allows the allocation of files. Consequently, the system becomes more stable.
You are introduced to the commands “truncate” and “fallocate”. Both commands allow you to create a file with a preferred size.
Sample:
# truncate -s 19MB mop1.txt
# fallocate -l 19000000 mop2.txt
# ls -ls mop.txt
0 -rw-rw--r-- 2 trs trs 19000000 Aug 12 02:44 mop1.txt
14819 -rw-rw--r-- 2 trs trs 19000000 Aug 12 02:45 mop2.txt
As the sample shows, you created a “19MB” file called “mop” on “Aug 12”.