Linux 101: Filesystem
In Linux, everything is considered a file, including devices and system resources.
Linux vs Windows vs Mac
Let's start by taking a look at how the Linux filesystem differs from Windows and Mac. In Linux, everything is considered a file, including devices and system resources. Imagine a big, happy family where everyone has a place to fit in. Each file and directory has an inode
, which is like its unique identification number. Devices are accessible under the /dev
directory (e.g., /dev/sda
for the first hard drive). System resources are represented as files in the /proc
and /sys
directories.
On the other hand, Windows uses a drive letter system to separate partitions and devices (e.g., C:
for the primary drive, D:
for an optical drive). The NTFS filesystem is feature-rich, providing journaling and security. However, it's less unified than Linux filesystems. Think of it more like a neighborhood where each house is separate.
Lastly, Mac systems used HFS+
(Hierarchical File System) in the past, but now they use the Apple File System (APFS), which was introduced in 2017. APFS has cool features like snapshots and cloning. It's a blend of Linux's unity and Windows' organization, making it similar to a tight-knit apartment complex.
Structure of Linux Filesystems
The root directory (/) is the beginning of the Linux filesystem hierarchy, like the trunk of a tree with branches spreading out. It contains all other directories and files.
Here are some key directories and their functions:
- /bin and /sbin contain essential system executables.
/bin
has basic user commands like ls, cp, and mv, while/sbin
holds system administration commands likefdisk
andifconfig
. It's like the kitchen in a house, where all the cooking takes place. - /usr is the secondary hierarchy for read-only user data. It contains additional applications and libraries in
/usr/bin
,/usr/sbin
,/usr/lib
, and/usr/share.
/usr/local
is the location for locally installed software, separate from system-wide packages. - /etc is the configuration central, storing system-wide configuration files like
/etc/fstab
for filesystem mounting info. User-specific configurations are stored in hidden files and directories within each user's home directory (e.g.,~/.bashrc
). It's like the command center of your Linux "house." - /var stores variable data like log files and databases. It's like a garage where things change over time.
/var/log
contains system and application logs, while/var/spool
holds temporary files like print queues and mail queues. - /home is where each user's personal files, settings, and customizations reside, like their bedroom in a house.
- /tmp stores temporary files created by applications and users, and files are often deleted upon system reboot. It's like a mudroom where you leave your dirty shoes before entering the house.
Linux Filesystem Types
- ext4 is the default for many Linux distributions. It supports journaling, large file sizes, and is backward compatible with ext2 and ext3.
- XFS is a high-performance filesystem suitable for large-scale data storage. It supports journaling, online defragmentation, and rapid recovery from crashes.
- Btrfs is neat features, designed to address the scaling challenges in storage systems. It supports copy-on-write, snapshots, and RAID-like configurations for data protection. Think of it as a promising newcomer, like the hot new artist everyone's talking about.
- ZFS is the feature-packed powerhouse, initially developed by Sun Microsystems for the Solaris operating system. It has robust features like data integrity checks, snapshots, and built-in RAID functionality. ZFS is like the Swiss Army knife of filesystems, with a tool for every occasion.
- F2FS (Flash-Friendly File System) is built for speed on flash storage. It's specifically designed for SSDs and other flash-based storage devices. F2FS is like a speed demon, optimized to take advantage of the unique characteristics of flash storage.
Mounting: Connecting Filesystems
Mounting is the process of making a filesystem accessible to the operating system. It's like plugging in a power strip to extend your electrical outlets. When you mount a filesystem, you're connecting it to the directory tree, allowing users and applications to access the files within.
The /etc/fstab
file is the mount point master list. It contains information about each filesystem and its mounting options. When the system boots, it reads the /etc/fstab file to know which filesystems to mount and where to mount them.
Mounting devices in Linux is like plug and play. When you insert a USB drive, the system detects it and mounts the device to a directory, usually under /media
or /mnt
, making the files accessible. You can also manually mount devices using the mount
command. For example, to mount a USB drive with a FAT32 filesystem, you can run:
~$ sudo mount -t vfat /dev/sdb1 /mnt/usb
Mounting network shares allows you to access files from remote systems, promoting collaboration and resource sharing. Protocols like NFS (Network File System) and Samba (for Windows file sharing) enable mounting network shares. To mount an NFS share, you can run:
~$ sudo mount -t nfs server:/shared/directory /mnt/nfs
About 8grams
We are a small DevOps Consulting Firm that has a mission to empower businesses with modern DevOps practices and technologies, enabling them to achieve digital transformation, improve efficiency, and drive growth.
Ready to transform your IT Operations and Software Development processes? Let's join forces and create innovative solutions that drive your business forward.
Subscribe to our newsletter for cutting-edge DevOps practices, tips, and insights delivered straight to your inbox!