Disk management is a crucial aspect of system administration. It involves managing disk space, partitions, file systems, and ensuring data integrity. This section will cover the following key topics:
- Understanding Disk Partitions
- Creating and Managing Partitions
- File Systems and Formatting
- Mounting and Unmounting File Systems
- Disk Usage and Quotas
- Practical Exercises
- Understanding Disk Partitions
Disk partitions are subdivisions of a physical disk drive. Each partition can be managed separately and can contain different file systems. Understanding partitions is essential for organizing data and optimizing disk usage.
Key Concepts:
- Primary Partitions: The main partitions on a disk. A disk can have up to four primary partitions.
- Extended Partitions: A type of primary partition that can contain multiple logical partitions.
- Logical Partitions: Partitions within an extended partition.
Example:
|-------------------------| | Primary | Primary | Extended | |-------------------------| | Logical | Logical | Logical | |-------------------------|
- Creating and Managing Partitions
Tools:
- fdisk: A command-line utility for managing disk partitions.
- parted: A more advanced tool for managing partitions.
Example: Using fdisk
- Command Explanation:
n
: Create a new partition.p
: Print the partition table.d
: Delete a partition.w
: Write changes to disk and exit.
Example: Using parted
- Command Explanation:
mklabel gpt
: Create a new GPT partition table.mkpart primary ext4 1MiB 100%
: Create a new primary partition with ext4 file system.print
: Display the partition table.
- File Systems and Formatting
Common File Systems:
- ext4: The default file system for many Linux distributions.
- xfs: A high-performance file system.
- btrfs: A modern file system with advanced features.
Formatting a Partition:
- Command Explanation:
mkfs.ext4
: Format the partition with the ext4 file system./dev/sda1
: The partition to format.
- Mounting and Unmounting File Systems
Mounting:
- Command Explanation:
mount
: Mount a file system./dev/sda1
: The partition to mount./mnt
: The directory to mount the partition to.
Unmounting:
- Command Explanation:
umount
: Unmount a file system./mnt
: The directory where the file system is mounted.
Persistent Mounts:
To make mounts persistent across reboots, add entries to /etc/fstab
.
Example /etc/fstab
Entry:
- Disk Usage and Quotas
Checking Disk Usage:
- Command Explanation:
df
: Display disk space usage.-h
: Human-readable format.
Setting Up Quotas:
-
Install Quota Tools:
sudo apt-get install quota
-
Edit
/etc/fstab
: Addusrquota
and/orgrpquota
to the relevant partition./dev/sda1 /mnt ext4 defaults,usrquota,grpquota 0 2
-
Remount the File System:
sudo mount -o remount /mnt
-
Initialize Quota Database:
sudo quotacheck -cug /mnt
-
Enable Quotas:
sudo quotaon /mnt
-
Set Quotas:
sudo edquota -u username
- Practical Exercises
Exercise 1: Create and Format a Partition
- Use
fdisk
to create a new partition on/dev/sdb
. - Format the partition with the ext4 file system.
- Mount the partition to
/mnt/data
.
Solution:
sudo fdisk /dev/sdb # Follow prompts to create a new partition sudo mkfs.ext4 /dev/sdb1 sudo mount /dev/sdb1 /mnt/data
Exercise 2: Set Up Disk Quotas
- Install quota tools.
- Edit
/etc/fstab
to enable user quotas on/mnt/data
. - Initialize and enable quotas.
- Set a quota for a user.
Solution:
sudo apt-get install quota sudo nano /etc/fstab # Add usrquota to the relevant partition sudo mount -o remount /mnt/data sudo quotacheck -cug /mnt/data sudo quotaon /mnt/data sudo edquota -u username
Conclusion
In this section, we covered the essentials of disk management, including understanding partitions, creating and managing partitions, formatting file systems, mounting and unmounting file systems, and setting up disk quotas. Mastering these skills is crucial for effective system administration and ensuring optimal disk usage and data integrity. In the next section, we will delve into package management, another critical aspect of maintaining a Linux system.
Linux Mastery: From Beginner to Advanced
Module 1: Introduction to Linux
Module 2: Basic Linux Commands
- Introduction to the Command Line
- Navigating the File System
- File and Directory Operations
- Viewing and Editing Files
- File Permissions and Ownership
Module 3: Advanced Command Line Skills
- Using Wildcards and Regular Expressions
- Piping and Redirection
- Process Management
- Scheduling Tasks with Cron
- Networking Commands
Module 4: Shell Scripting
- Introduction to Shell Scripting
- Variables and Data Types
- Control Structures
- Functions and Libraries
- Debugging and Error Handling
Module 5: System Administration
- User and Group Management
- Disk Management
- Package Management
- System Monitoring and Performance Tuning
- Backup and Restore
Module 6: Networking and Security
- Network Configuration
- Firewall and Security
- SSH and Remote Access
- Intrusion Detection Systems
- Securing Linux Systems
Module 7: Advanced Topics
- Virtualization with Linux
- Linux Containers and Docker
- Automating with Ansible
- Linux Kernel Tuning
- High Availability and Load Balancing