MM

Disk Management in Linux - In Depth Notes

Introduction to Disk Management

Understanding the basic concepts of disk management is essential for new Linux administrators. This includes partitioning, naming conventions, partition types, file systems, and tools used for managing disks effectively.

Disk Partitioning

Definition:
Disk partitioning is the process of dividing a single hard drive into multiple logical drives using tools like fdisk and parted.

Partitions allow for better organization of files and directories, making it easier to manage data efficiently across a system. It also enhances system performance and can provide security by isolating files.

Typical Partitioning:
New Linux administrators often create just two partitions on the entire hard drive:

  • / (root)

  • Swap

The root partition (/) serves as the main directory for all system files, while the swap partition is used as virtual memory when the physical RAM is full. Other directories such as /usr, /var, and /bin are created under the root partition. Over time, there may be a need to create additional partitions for these directories or for other mount points to optimize disk usage and organization.

Device Representation:
In Linux, partitions are represented by device files located in the /dev directory.

Example of output listing:
```bash
[root@node1-]# ls /dev/
b
brw-rw-

**Block Devices:**  
The first character in the listing indicates block devices:  
- e.g., hda, sda (IDE and SCSI drives respectively).  

### Naming Conventions  
**IDE Drives:**  
Identified with /dev/hd followed by a letter:  
- `/dev/hda` - First IDE drive  
- `/dev/hdb` - Second IDE drive  
- `/dev/hdc` - Third IDE drive  
- `/dev/hdd` - Fourth IDE drive  

**SCSI Drives:**  
Identified with /dev/sd followed by a letter:  
- `/dev/sda` - First SCSI drive  
- `/dev/sdb` - Second SCSI drive  

**Partition Representation:**  
Once a drive is partitioned, partitions are labeled with numbers:  
- `/dev/hda1` - First partition of first IDE drive  
- `/dev/hda2` - Second partition of first IDE drive  

### Partition Types  
**3. Primary Partitions:**  
Limited to four primary partitions on a disk, essential partitions required for the OS to function without disruption.  

**5. Extended Partitions:**  
Used to circumvent the limitation of four primary partitions. An extended partition can contain multiple logical partitions within it, allowing more flexible partitioning schemes.  

**7. Logical Partitions:**  
A partition created within an extended partition, offering more flexibility for disk management as needs grow.  

### Filesystem  
**Definition:**  
A filesystem is a method and data structure an operating system uses to manage files on a disk. It determines how files are organized, stored, and retrieved.  

**Types of Filesystems:**  
Examples include:  
- **ext3, ext4:** common Linux filesystems that offer journaling capabilities for improved data integrity.  
- **Linux Swap:** used for swap partitions to supplement RAM.  

**Partition Type Codes:**  
Each filesystem type is represented by a numerical code:  
- **Linux filesystem:** 0x83  
- **Linux swap:** 0x82  
To view partition types and codes, use the command:  

bash
/sbin/sfdisk -T
```

Conclusion:

The article provides foundational knowledge of disk management in Linux, enabling administrators to manage disk space efficiently, optimize system performance, and enhance security of stored data.