04 File System and Storage Management


  • .

A file system is a method for storing and organizing data on storage devices. Examples of popular file systems in Linux:

  • ext4: The default file system in many Linux distributions. Supports large file sizes and journaling.

  • XFS: Designed for high performance on large files. Suitable for servers.

  • Btrfs: Supports modern features such as snapshots, compression, and data integrity checks.

Creating and Managing Partitions

  1. Tools for partition management:

    • fdisk: For storage devices based on MBR.

    • parted: For storage devices based on GPT.

  2. Creating a Partition with fdisk:

    • Display storage devices:

      sudo fdisk -l
  3. Run fdisk for the device:

    sudo fdisk /dev/sdX
  4. Create a new partition:

    • Press n to create a new partition.
    • Select the partition type (primary/logical).
    • Save changes with w.
  5. Creating a File System:

    Use the following command after creating a partition:

    • ext4 :

       sudo mkfs.ext4 /dev/sdX1
    • XFS :

      sudo mkfs.xfs /dev/sdX1
    • Btrfs :

      sudo mkfs.btrfs /dev/sdX1

Logical Volume Manager (LVM)

LVM allows flexible storage management by using logical volumes instead of physical partitions.

  • Main components of LVM:

    1. Physical Volume (PV): Physical devices (disks or partitions).

    2. Volume Group (VG): A collection of PVs.

    3. Logical Volume (LV): Volumes used for the file system.

LVM Configuration Steps

  1. Create a Physical Volume (PV):

    sudo pvcreate /dev/sdX1
  2. Create a Volume Group (VG):

    sudo vgcreate my_vg /dev/sdX1
  3. Create a Logical Volume (LV):

    sudo lvcreate -L 10G -n my_lv my_vg
  4. Create a File System on the LV:

    sudo mkfs.ext4 /dev/my_vg/my_lv
  5. Mount the LV to a Directory:

    sudo mount /dev/my_vg/my_lv /mnt

Software RAID Configuration

RAID (Redundant Array of Independent Disks) is a technology for combining multiple disks into a single logical unit to improve performance or redundancy.

  • Common RAID types:

    • RAID 0: Striping, improves performance without redundancy.

    • RAID 1: Mirroring, duplicates data for redundancy.

    • RAID 5: Parity, redundancy with storage efficiency.

    • RAID 10: Combination of RAID 1 and RAID 0.

Membuat RAID dengan mdadm

  1. Install mdadm :

    sudo zypper install mdadm
  2. Create a RAID array:

    • Example of RAID 1:

      sudo mdadm --create --verbose /dev/md0 --level=1 --raid-devices=2 /dev/sdX1 /dev/sdY1
  3. Create a file system on RAID:

    sudo mkfs.ext4 /dev/md0
  4. Mount RAID :

    sudo mount /dev/md0 /mnt
  5. Save RAID configuration:

    sudo mdadm --detail --scan >> /etc/mdadm.conf

Mounting File Systems and fstab

Mounting File Systems

Mounting is the process of connecting a file system to a directory.

  • Manual Mounting Command:

    sudo mount /dev/sdX1 /mnt
  • Viewing Mounted File Systems:

    df -h

fstab

fstab is a configuration file for automatic mounting at boot. File location:/etc/fstab

  • fstab Format:

    < device >  < mount_point >  < file_system >  < options>  < dump >  < pass >
  • Example fstab:

    /dev/sdX1  /mnt  ext4  defaults  0  2
  • Apply fstab changes without rebooting:

    sudo mount -a

Disk Quota

Disk quota limits storage usage for specific users or groups.

Mengaktifkan Quota Disk

  1. Edit the /etc/fstab file to add quota options:

    /dev/sdX1  /mnt  ext4  defaults,usrquota,grpquota  0  2
  2. Remount the file system:

    sudo mount -o remount /mnt
  3. Create a quota file:

    sudo quotacheck -cug /mnt
    sudo quotaon /mnt

Managing Quota

  1. Assign Quota to a User:

    sudo edquota -u username
    Add soft and hard limits in the opened file.
  2. Check Quota Usage:

    quota -u username
  3. Disable Quota:

    sudo quotaoff /mnt