Managing the filesystem and storage devices is a critical part of Linux administration. This chapter covers how to view, configure, and maintain storage devices, partitions, and filesystems effectively.
- ext4: Default filesystem for most Linux distributions.
- xfs: High-performance journaling filesystem.
- btrfs: Advanced filesystem with features like snapshots and compression.
- ntfs: Commonly used on Windows systems, supported in Linux for compatibility.
- vfat: Used for USB drives and older Windows systems.
- Displays information about block devices such as disks and partitions.
lsblk
- Shows disk space usage for mounted filesystems.
df -h
- Displays the space used by files and directories.
du -sh /path/to/directory
- Mount and unmount filesystems.
- Mount a device:
sudo mount /dev/sdX1 /mnt
- Unmount a device:
sudo umount /mnt
- Interactive utility for creating and managing partitions.
- Open the disk for partitioning:
sudo fdisk /dev/sdX
- Common commands inside
fdisk
:n
: Create a new partition.d
: Delete a partition.p
: Print the partition table.w
: Write changes and exit.
- Used for creating and managing GPT and MBR partitions.
sudo parted /dev/sdX
lsblk -f
- Used to format partitions with a specific filesystem.
- Create an ext4 filesystem:
sudo mkfs.ext4 /dev/sdX1
- Create an xfs filesystem:
sudo mkfs.xfs /dev/sdX1
- Used to identify and fix filesystem errors.
sudo fsck /dev/sdX1
- Modify parameters for ext-based filesystems.
sudo tune2fs -c 10 /dev/sdX1
- Create the partition using
fdisk
orparted
. - Format the partition as swap:
sudo mkswap /dev/sdX2
- Enable the swap partition:
sudo swapon /dev/sdX2
- Make the swap persistent by adding it to
/etc/fstab
:/dev/sdX2 none swap sw 0 0
free -h
- Defines how and where filesystems are mounted automatically.
/dev/sdX1 /mnt ext4 defaults 0 2
- After modifying
/etc/fstab
, test the configuration:sudo mount -a
- Add quota options to
/etc/fstab
:/dev/sdX1 /mnt ext4 defaults,usrquota,grpquota 0 2
- Remount the filesystem:
sudo mount -o remount /mnt
- Create the quota database:
sudo quotacheck -cum /mnt sudo quotaon /mnt
sudo edquota -u username
By the end of this chapter, you should be able to:
- View and analyze storage devices and filesystems.
- Manage partitions and format them with various filesystems.
- Mount, unmount, and configure filesystems using
/etc/fstab
. - Create and manage swap partitions and disk quotas.
- Move to Chapter 11: The Logging System to learn about managing logs and monitoring system activities in Linux.
- Create a new ext4 partition, format it, and mount it to
/mnt/newdrive
. - View the disk space usage of
/home
usingdu
anddf
. - Check and repair an ext4 filesystem using
fsck
. - Add a swap partition and verify it is active using
free
. - Configure a user quota on a mounted filesystem and test it.