#Day6 AWS & DevOps Challenge : Understanding Storage Management in Linux: Partitions, File Systems, and Storage Types
Introduction
Managing storage in a Linux system involves several important tasks, including partitioning, formatting, and mounting storage devices. Additionally, understanding various storage types and partitioning schemes such as MBR and GPT is essential. In this article, we'll delve into these topics and also touch on Direct-Attached Storage (DAS), Network-Attached Storage (NAS), and Storage Area Networks (SAN). We'll also briefly explain NFS and LVM.
Partitioning in Linux
Partitioning is the process of dividing a storage device into distinct sections, each behaving as an independent unit. In Linux, common tools for partitioning are fdisk
and gdisk
. Here's how to use them:
Identify Devices: Use
fdisk -l
orlsblk
to list available storage devices. For instance,fdisk -l
displays information about all disks and partitions.Create Partitions: To create a new partition, run
fdisk
with the device name (e.g.,/dev/sdX
) as an argument. Usen
to create a new partition, specify the partition type (primary, extended, or logical), and set the size.gdisk /dev/sdb GPT fdisk (gdisk) version 1.0.1 Partition table scan: MBR: protective BSD: not present APM: not present GPT: present Found valid GPT with protective MBR; using GPT. Command (? for help): ? b back up GPT data to a file c change a partitions name d delete a partition i show detailed information on a partition l list known partition types n add a new partition o create a new empty GUID partition table (GPT) p print the partition table q quit without saving changes r recovery and transformation options (experts only) s sort partitions t change a partitions type code v verify disk w write table to disk and exit x extra functionality (experts only) ? print this menu Command (? for help): n Partition number (1-128, default 1): 1 First sector (34-41943006, default = 2048) or {+-}size{KMGTP}: 2048 Information: Moved requested sector from 34 to 2048 in order to align on 2048-sector boundaries. Use 'l' on the experts menu to adjust alignment Last sector (2048-41943006, default = 41943006) or {+-}size{KMGTP}: 41943006 Current type is 'Linux filesystem' Hex code or GUID (L to show codes, Enter = 8300): Changed type of partition to 'Linux filesystem' Command (? for help): w Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING PARTITIONS!! Do you want to proceed? (Y/N): Y OK; writing new GUID partition table (GPT) to /dev/vdb. The operation has completed successfully.
Primary, Extended, and Logical Partitions: In the Master Boot Record (MBR) partitioning scheme, you can create up to four primary partitions. If you need more partitions, one of them can be an extended partition. Inside an extended partition, you can create multiple logical partitions. Extended partitions are used to overcome the limitation of only four primary partitions in MBR.
Formatting Partitions: Once partitions are created, format them with file systems using
mkfs
(e.g.,mkfs.ext4 /dev/sdXY
for ext4). Choose an appropriate file system based on your requirements.
MBR vs. GPT Partition Scheme
MBR (Master Boot Record): MBR is an older partitioning scheme that supports up to four primary partitions. It uses a 32-bit addressing system, which limits the total disk size to 2TB. MBR is compatible with most operating systems and BIOS-based systems.
GPT (GUID Partition Table): GPT is a modern partitioning scheme with support for larger disks and more partitions. It uses a 64-bit addressing system, allowing for disks larger than 2TB. GPT is required for UEFI-based systems and is becoming more common for data storage.
Mounting Storage Devices
To access and use partitions, you need to mount them:
Temporary Mounting: Use the
mount
command to temporarily attach a partition to a directory. For example,mount /dev/sdXY /mnt/mountpoint
Permanent Mounting: To make mounts persistent across reboots, add entries to the
/etc/fstab
file. Use theUUID
of the partition for reliability. For example:echo "/dev/sdb1 /mnt/ext4 ext4 rw 0 0" >> /etc/fstab
Storage Types: DAS, NAS, and SAN
Direct-Attached Storage (DAS): DAS refers to storage directly connected to a single server or computer. It includes internal hard drives, external drives, and RAID arrays. DAS is suitable for small-scale environments.
Network-Attached Storage (NAS): NAS devices are standalone servers that provide shared storage accessible over a network. They are ideal for file sharing, backup, and data storage. NFS (Network File System) is commonly used for sharing files in a NAS environment.
Storage Area Network (SAN): SANs are dedicated networks that provide block-level access to storage devices. SANs are highly scalable and used in enterprise environments. One important concept in SANs is the LUN (Logical Unit Number), which represents a logical portion of storage space presented to a server.
NFS (Network File System)
NFS is a protocol for sharing files across a network. It allows remote systems to access shared directories as if they were local. NFS is commonly used in NAS setups for efficient file sharing. It follows a client-server model.
The IPs of the clients that can access the NFS are mentioned in an access file i.e.
/etc/export
To insert the client's IP manually use the command:
exportfs -o <<ip of the client>>:/software/repos
and later to mount the device use the command:
mount <<ip>>:/software/repos /mnt/software/repos
LVM (Logical Volume Manager)
LVM is a powerful tool for managing storage in Linux. It allows you to create and manage logical volumes, which can span multiple physical disks. This provides flexibility in resizing and moving storage space without the need to reformat or repartition i.e. it is resizable dynamically.
To install the package:
sudo apt-get install lvm2
Conclusion
Understanding storage management in Linux involves mastering the concepts of partitioning, file systems, and storage types. Additionally, knowing the differences between MBR and GPT partition schemes, as well as the roles of DAS, NAS, and SAN, is essential for effective storage management in various environments. Finally, NFS and LVM are important tools for efficiently managing and sharing storage resources in Linux systems.