Sunday, February 5, 2023

Learning Linux - Configure Local Storage(Part-4)

In Part 3 of the Learning Linux blog series, We have learned how to operate running Linux systems. 

In part 4, We will explore and try to construct daily usage commands to manage the local storage in the Linux systems.

- List, create, delete, and modify physical storage partitions

    Lsblk - Display the list of block devices, 

    cfdisk - display or manipulate disk partition table, 

    fdisk - manipulate disk partition table

- Configure and manage swap space 

    Create and manage swap space

  1. swapon --list ( Show the list of swap partition), 
  2. mkswap /dev/sdb3 - format the disk as swap partition, 
  3. swapoff/swapon /dev/sdb3 - enable/disable devices and files for paging and swapping

    Use a file for swap

  1. sudo dd if=/dev/zero of=/swap bs=1M count=1024 (Create a zerod file for 1 GB), 
  2. sudo chmod 600 /swap ( Change the swap file permission to allow only to root user), 
  3. mkswap /swap, swapon /swap

- Manage and configure LVM storage

    lvmdiskscan(check the LVM disk/volumes), 

    Adding Physical Volumes:

  • pvcreate /dev/sdb /dev/sdc(create the Physical Volumes), pvs(show the list of PVs),  

    Adding Volume Group and Extending

  1. sudo vgcreate my_volume /dev/sdb /dev/sdc (create VG), 
  2. sudo vgextend my_volume /dev/sdd (Extending the Volume Group by adding another Physical volume), 
  3. sudo vgs (shows the volume group), 

    Reduce VG:

  • sudo vgreduce my_volume /dev/sdd (Remove PV from existing VG), sudo pvremove /dev/sdd (Remove PV)

    Create Logical Volume:

  • sudo lvcreate --size 2G --name partition1 my_volume( my_volume = VG), sudo lvs (show the list of LVs),

    Extending or Resizing the LV:

  1. sudo lvresize --extents 100%VG my_volume/partition1(Extend partion1 by 100%), 
  2. sudo lvresize --size 2G my_volume/partition1(resize the partion1 to 2GB), 
  3. sudo lvresize --resizefs --size 3G my_volume/partition1(!!! Resize the lv using resizefs parameter if  lv is holding the file system)

    Format the lv by using filesystem(xfs):

  • sudo mkfs.xfs /dev/my_volume/partition1(format lv by xfs)

  - Create and configure encrypted storage

    Encrypted Storage:

        PlainMode:

  1. sudo cryptsetup --verify-passphrase open --type plain /dev/sdd mysecuredisk
  2. sudo mkfs.xfs /dev/mapper/mysecuredisk (Format the encrypted disk with xfs filesystem)

        LuksEncryption:

  1. sudo cryptsetup luksFormat /dev/sdd (format disk with luks)
  2. sudo cryptsetup luksChangeKey /dev/sdd (Change Encryption key)
  3. sudo cryptsetup open /dev/sdd mysecuredisk(Open the encrypted disk)

- Create and manage RAID devices

    Create and manage RAID Devices

  1. sudo mdadm --create /dev/md0 --level=1 --raid-devices=3 /dev/sdb /dev/sdc /dev/sdd (Create RAID 1 using 3 disks)
  2. sudo mdadm --manage /dev/md0 --add /dev/vde (Add disk to existing raid 1 array)
  3. sudo mkfs.xfs /dev/md0 (Format raid disk-md0 to xfs)

  • sudo mdadm --stop /dev/md0 (You may stop raid disk - md0)
  • sudo mdadm --zero-superblock /dev/sdb /dev/sdc /dev/sdd(Zeroed (remove) the disks)

  • sudo mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sdb /dev/sdc --spare-devices=1 /dev/sdd(Create RAID 1 with Spare disk)
  • cat /proc/mdstat (Check the RAID Status)
  • sudo mdadm --manage /dev/md0 --add /dev/sdd (Add additional disk to existing RAID Disk - md0)
  • sudo mdadm --manage /dev/md0 --remove /dev/sdd(remove disk from RAID Array)

- Create, manage, and diagnose advanced file system permissions

  • getfacl, setfacl 
    • Example: sudo setfacl --modify user:aaron:rw examplefile (Assigning special permission to user aaron)
  • getfacl examplefile, 
  • sudo setfacl --remove user:john specialfile(Remove ACL Permission)
  • sudo setfacl --recursive --modify user:john:rwx collection/ (Set adv permission on directory)
  • sudo setfacl --modify mask:r examplefile (Assigning mask permission to read-only, Mask limit the permission),
  • Chattr (Making file attributes)
    • Example:
      • chattr +a newfile (Making file append for new content only)
      • chattr +i newfile (Making file Immutable)
      • lsattr newfile (Checking if file has immutable attr enabled)

- Setup user and group disk quotas for filesystems

    User and group filesystem Quotas

  1. dnf install quota ( install the quota app), 
  2. Enable Quota on xfs filesystem:
  3. sudo vim /etc/fstab, 
      • /dev/vdb1 /mybackups xfs defaults, usrquota, grpquota,  0 2 
  4. sudo systemctl reboot

    Enable quota for ext4 file system:

  1. sudo quotacheck --create-files --user --group /dev/vdb2
  2. sudo quotaon /mnt/

        Check user quota:
  • sudo edquota --user aaron (Checking quota for user edit mode, replace user with group if required)
  • sudo quota --user aaron (Checking quota for user)
  • sudo quota --edit-period (Change the grace period)


-> echo "Thank you :)"