Linux Disk Management Commands Overview

  1. fdisk: Used for creating, deleting, and modifying disk partitions.
  2. mkfs: Used for creating file systems.
  3. mount: Used for mounting file systems.
  4. umount: Used for unmounting file systems.
  5. df: Used to view disk usage.
  6. du: Used to view the disk usage of files or directories.
  7. parted: Used for creating, deleting, and modifying disk partitions (supports GPT partition tables).
  8. lsblk: Used to list all block devices on the system.
  9. blkid: Used to display information such as UUID and file system type for block devices.
  10. hdparm: Used to view and set hard drive parameters.
  11. smartctl: Used to view SMART information for hard drives.
  12. badblocks: Used to check for bad blocks on a disk.
  13. dd: Used for data backup and disk cloning.
  14. gparted: A graphical disk partitioning tool.
  15. LVM (Logical Volume Management): Provides logical volume management functions, such as creating, deleting, and extending logical volumes.

Detailed Introduction

Common disk management commands in Linux:

  1. fdisk

    • Introduction: fdisk is a disk partitioning tool used for creating, deleting, and modifying disk partitions. It is primarily used to manage the MBR partition table.
    • Syntax: fdisk [options] <device>
      • Common Options:
        • -l: List disk partition information
        • -u: Use sectors as the unit of measurement
    • Examples:
      • fdisk /dev/sda: Enter the interactive partitioning interface for the /dev/sda disk
      • fdisk -l: List partition information for all disks
  2. parted

    • Introduction: parted is a more powerful disk partitioning tool that supports GPT partition tables.
    • Syntax: parted [options] [device [command [options...]]]
      • Common Options:
        • -l: List disk partition information
        • -s: Run in script mode
    • Examples:
      • parted /dev/sdb: Enter the interactive partitioning interface for the /dev/sdb disk
      • parted -l: List partition information for all disks
  3. mkfs

    • Introduction: The mkfs command is used to create file systems.
    • Syntax: mkfs -t <type> [options] <device>
      • Common Options:
        • -t <type>: Specify the file system type, such as ext4, xfs, etc.
    • Examples:
      • mkfs -t ext4 /dev/sda1: Create an ext4 file system on the /dev/sda1 partition
  4. mount

    • Introduction: The mount command is used to mount file systems.
    • Syntax: mount [-t <type>] [-o options] <device> <dir>
      • Common Options:
        • -t <type>: Specify the file system type
        • -o <options>: Specify mount options
    • Examples:
      • mount /dev/sda1 /mnt: Mount the /dev/sda1 partition to the /mnt directory
      • mount -t ext4 /dev/sda1 /mnt: Mount the ext4 file system to the /mnt directory
  5. umount

    • Introduction: The umount command is used to unmount file systems.
    • Syntax: umount <device> or umount <mount_point>
    • Examples:
      • umount /dev/sda1
      • umount /mnt
  6. df

    • Introduction: The df command is used to view disk usage.
    • Syntax: df [options] [file|directory]
      • Common Options:
        • -h: Display disk capacity and usage in a human-readable format
        • -i: Display inode usage
    • Examples:
      • df -h: Display available space for all mounted file systems
      • df -h /home: Display available space for the file system containing the /home directory
  7. du

    • Introduction: The du command is used to view the disk usage of files or directories.
    • Syntax: du [options] [file|directory]
      • Common Options:
        • -h: Display disk space in a human-readable format
        • -s: Show only the total
    • Examples:
      • du -h /home: Display the disk space occupied by the /home directory and its subdirectories
      • du -sh /home: Display only the total disk space occupied by the /home directory itself
  8. dd

    • Introduction: The dd command is used for data backup and disk cloning.
    • Syntax: dd [options] [input_file=input] [output_file=output]
      • Common Options:
        • if=<file>: Specify the input file
        • of=<file>: Specify the output file
        • bs=<bytes>: Specify the input/output block size
        • count=<blocks>: Copy only a specified number of blocks
    • Examples:
      • dd if=/dev/sda of=/dev/sdb: Completely clone the data from the /dev/sda disk to the /dev/sdb disk
      • dd if=/dev/zero of=/swapfile bs=1M count=2048: Create a 2GB swap file in the current directory