Filesystem
The Filesystem Hierarchy Standard (FHS) defines the main directories and their contents in Linux operating systems.
/The root directory. It is the top-level directory of the hierarchy and must contain all files necessary to boot the system in single-user mode./bin- Essential command binaries that must be available in single-user mode for all users (e.g.,
cat,ls,cp). /bootStatic files of the boot loader, including the Kernel executable and initrd/devDevice files representing hardware components and virtual devices/etcHost-specific system configuration files. This directory does not contain binary executables/homeUser home directories containing personal settings and data/libEssential shared libraries and kernel modules required by binaries in/binand/sbin/mediaMount points for removable media like USB drives or CD-ROMs/mntA directory for temporarily mounted filesystems/optAdd-on application software packages that are not part of the default distribution/rootThe home directory for the root user/sbinEssential system binaries used for administration and root-level tasks (e.g., iptables, fdisk)/tmpTemporary files often cleared at boot; it often uses the #tmpfs (RAM-backed) filesystem/usrSecondary hierarchy for read-only user data, containing the majority of user utilities and applications/varVariable data files that change during system operation, such as logs (/var/log) and spool files
File System Management
Managing file systems on Linux involves organizing, storing, and maintaining data on disks and other storage devices. Linux supports many file systems, including ext2, ext3, ext4, XFS, Btrfs, and NTFS. The best choice depends on performance, data integrity, compatibility, and storage needs.
- ext2: no journaling, low overhead, useful for simple or removable storage.
- ext3/ext4: journaling; ext4 is the default on many systems and balances performance and reliability.
- Btrfs: snapshots and data integrity checks; good for advanced storage setups.
- XFS: high performance with large files and heavy I/O.
- NTFS: Windows compatibility for dual-boot or shared external drives.
Inodes and the Inode Table
Linux file system architecture uses inodes to store metadata (permissions, ownership, size, timestamps). Inodes do not store file names or data; they point to data blocks on disk. The inode table is the system’s index of all inodes. A disk can run out of inodes before it runs out of space. Linux/Kernel/Filesystem/Inodes
File Types
Linux stores files as:
- Regular files
- Directories
- Symbolic links (symlinks) Regular files contain text (ASCII) and/or binary data. They can live anywhere in the hierarchy. Directories are special files that contain other files and directories. Symlinks are references to other files or directories and help organize complex structures.
Permissions by User Class
Permissions are set independently for owner, group, and others. Changing one class does not affect the others.
$ ls -il
total 0
10678872 -rw-r--r-- 1 cry0l1t3 htb 234123 Feb 14 19:30 myscript.py
10678869 -rw-r--r-- 1 cry0l1t3 htb 43230 Feb 14 11:52 notes.txt
Disks and Drives
Disk management includes physical devices and partitions. The fdisk tool creates, deletes, and inspects partitions and their types.
$ sudo fdisk -l
Mounting
Partitions are attached to directories (mount points). Manual mounting uses mount. Automatic mounting is configured in /etc/fstab.
$ cat /etc/fstab
List mounted file systems:
$ mount
Mount a USB drive:
$ sudo mount /dev/sdb1 /mnt/usb
$ cd /mnt/usb && ls -l
Unmount:
$ sudo umount /mnt/usb
If a filesystem is busy, use lsof to find processes using it:
$ lsof | grep cry0l1t3
To prevent auto-mount at boot, add noauto in /etc/fstab:
/dev/sda1 / ext4 defaults 0 0
/dev/sda2 /home ext4 defaults 0 0
/dev/sdb1 /mnt/usb ext4 rw,noauto,user 0 0
192.168.1.100:/nfs /mnt/nfs nfs defaults 0 0
Swap
Swap extends RAM by moving inactive pages to disk when memory is low. It is also used for hibernation. Swap can be created with mkswap and enabled with swapon. Size depends on RAM and workload. For performance and security, use a dedicated partition or file and consider encrypting swap.