Notes

Filesystem

The Filesystem Hierarchy Standard (FHS) defines the main directories and their contents in Linux operating systems.

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.

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:

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.

Pages