- Storage Management in Linux
- Explore and Identify Block Devices
- Create and Modify Partitions
- Create, Modify, and Mount File Systems
- Create and Mount an Encrypted Partition
- Configure Disk Mounting
- Mount Volumes on Demand
- Reconfigure Swap Space
- Create Redundant Storage with RAID
- Logical Volume Management (LVM)
- Disk Quotas
- Conclusion
Storage Management in Linux
Explore and Identify Block Devices
- Check block device info:
blkid
- Show all block devices:
lsblk
- Get I/O information:
blkid -i /dev/sdc1
Create and Modify Partitions
Partitioning Tools:
- parted
- fdisk
- gparted
- cfdisk
Create, Modify, and Mount File Systems
Common File Systems in Linux:
- ext2 (standard)
- ext3 (journaling support)
- ext4 (supports large files)
- xfs (developed by Sun)
- btrfs (B-tree file system)
- FAT32 (compatible with Windows and macOS)
Create a File System:
mkfs.ext4 /dev/sdc1
Mounting a File System:
mkdir /mnt/storage
mount /dev/sdc1 /mnt/storage
Verify and Review:
tune2fs -l /dev/sdc1
Unmounting a File System:
umount /mnt/storage
Create and Mount an Encrypted Partition
Encryption Tools:
- dm-crypt
- LUKS (Linux Unified Key Setup)
- Available via the cryptsetup package
Encrypt a Partition:
cryptsetup luksFormat /dev/sdc2
Decrypt a Partition:
cryptsetup open /dev/sdc2 secret
Close an Encrypted Partition:
cryptsetup close secret
Configure Disk Mounting
- View mount information:
/etc/fstab
- Mount all file systems from fstab:
mount -a
- Check mounted filesystems:
df -h
Mount Volumes on Demand
Install Autofs:
sudo apt install autofs
Check Autofs Status:
sudo systemctl status autofs
Autofs Configuration File:
/etc/auto.master
Reconfigure Swap Space
Swap Basics:
- When RAM is low, pages of memory move to disk
- Swap space can be a partition or a file
- 2x RAM if <2GB, at least 4GB if >2GB
Check Swap Usage:
cat /proc/swaps
Create a New Swap File:
swapoff /dev/sda5
dd if=/dev/zero of=/var/swapfile bs=1G count=8
chmod 600 /var/swapfile
mkswap /var/swapfile
swapon /var/swapfile
Persist Swap in /etc/fstab
Create Redundant Storage with RAID
RAID Levels:
- RAID 0 - Striped volume (performance)
- RAID 1 - Mirrored volume (redundancy)
- RAID 5 - Distributed parity (3+ disks)
- RAID 6 - Dual parity (4+ disks)
Configure RAID with mdadm
:
sudo apt install mdadm
mdadm --create --level=1 --raid-devices=2 /dev/md0 /dev/sdb1 /dev/sdb2
Check RAID Status:
mdadm --detail /dev/md0
Add a File System:
mkfs.ext4 /dev/md0
mkdir /mnt/myraid
mount /dev/md0 /mnt/myraid
Manage RAID Disks:
mdadm --fail /dev/md0 /dev/sdb1
mdadm --remove /dev/md0 /dev/sdb1
mdadm --add /dev/md0 /dev/sdb3
Stop and Remove RAID:
umount /mnt/myraid
mdadm --stop /dev/md0
mdadm --remove /dev/md0
mdadm --zero-superblock /dev/sdb1 /dev/sdb2 /dev/sdb3
Logical Volume Management (LVM)
Install LVM Tools:
sudo apt install lvm2
Create a Physical Volume:
pvcreate /dev/sdb1
pvdisplay
Create a Volume Group:
vgcreate my_group /dev/sdb1
vgdisplay
Create a Logical Volume:
lvcreate -L 100G -n my_volume my_group
lvdisplay
Extend a Volume Group:
pvcreate /dev/sdc1
vgextend my_group /dev/sdc1
lvextend -l+100%FREE /dev/my_group/my_volume
resize2fs /dev/my_group/my_volume
Disk Quotas
Install Quota Tools:
sudo apt install quota
Enable Quotas:
quotacheck -c /mnt/storage
quotaon -pa
quotaon /mnt/storage
Set User Quota:
edquota username
Conclusion
This guide covers Linux storage management, including partitioning, file systems, RAID, LVM, encryption, and quotas. Understanding these concepts ensures efficient and secure storage management on Linux systems.