Understanding LVM
In the early days of Linux servers, storage management relied on creating fixed partitions on disks. However, partitions posed limitations due to their lack of flexibility. When disk space needed adjustment, partitions could not be easily resized, leading to inefficiencies. To address this, Logical Volume Manager (LVM) was introduced, offering significant advantages in storage management.
LVM Architecture
LVM operates through several layers within its architecture. At the base layer, various storage devices such as disks, partitions, or LUNs (Logical Unit Numbers) from SANs are utilized. Best practice recommends using partitions as physical volumes (PVs) within LVM. This allows other tools to recognize pre-configured storage on the block device, minimizing configuration errors.
Physical volumes are designated as part of a volume group (VG), which represents an abstracted pool of available storage. Unlike fixed allocations, volume groups are dynamic and can expand as needed by adding more physical volumes. This flexibility enables seamless adjustments to logical volumes (LVs) that are built upon the volume group. LVs do not interact directly with disks but draw storage from available space within the volume group. This setup permits a single logical volume to span multiple physical volumes, enhancing storage flexibility.
File Systems and Flexibility
Logical volumes host file systems, leveraging their flexibility to adjust file system sizes as needed. File systems associated with logical volumes can easily be extended or, if supported, reduced in size to optimize disk space usage. This dynamic resizing capability depends on the file system’s inherent features and support for size adjustments.
LVM Features
LVM offers several compelling features that simplify storage management. Foremost among these is its ability to adapt to changing storage needs without the constraints of physical hard drives. By adding new physical volumes to a volume group, administrators can seamlessly expand logical volumes to meet increased storage demands. Moreover, LVM supports snapshots, which capture the current state of a logical volume, facilitating data recovery or backups without disrupting ongoing operations.
Administrators appreciate LVM’s capability to replace failing hardware efficiently. By using commands like pvmove
, data can be transferred within the volume group, enabling the removal of faulty disks and adding new ones dynamically, all without downtime for the logical volumes.
Creating LVM Logical Volumes
Creating LVM logical volumes involves a systematic approach to establish the necessary layers: converting physical devices into physical volumes (PVs), aggregating PVs into volume groups (VGs), and creating logical volumes (LVs). Command-line utilities, which are universally accessible, provide straightforward tools for these operations.
Tip for RHCSA Exam
For those preparing for the RHCSA exam, familiarity with LVM commands—specifically pv
, vg
, and lv
—is essential. These commands simplify management tasks and can be easily accessed via the command line. Using the --help
option with any LVM command provides a concise summary of its usage, ensuring efficient execution of necessary operations.
By understanding LVM’s architecture and leveraging its features, administrators gain a robust framework for managing storage effectively across diverse Linux environments.
Creating Physical Volumes for LVM
To effectively utilize LVM tools for managing storage, begin by preparing partitions designated as LVM type. This process resembles typical partitioning methods outlined in before, with a crucial distinction: partitions must be flagged as LVM type before committing changes to disk.
In utilities like fdisk and gdisk, use the t command from the menu to modify partition types. For MBR disks, set the type to 8e; for GUID disks, use 8e00. Alternatively, newer versions of fdisk support using lvm as a direct alias for LVM type.
If using parted, within its interface, execute set n lvm on to mark a partition (where n denotes the partition number) for LVM use.
After creating and marking the partition as LVM type, employ pvcreate to initialize it as a physical volume. This step writes essential metadata to the partition, enabling its integration into a volume group for subsequent storage management tasks.
Exercise: Creating a Physical Volume
To practice creating a physical volume, ensure your system has a hard disk with available unpartitioned space. Follow these steps, using /dev/sdd as an example:
- Open a root shell and execute fdisk /dev/sdd.
- Enter p to display the current partition table, confirming no partitions exist.
- Type g to initialize a GPT partition table.
- Press n to create a new partition, accepting defaults for partition number and sectors.
- Specify +1G when prompted for the last sector, creating a 1 GiB partition.
- Use t to change the partition type to lvm.
- Verify the partition creation with p.
- Repeat steps 4-7 to create additional 1 GiB LVM partitions if needed.
- Save changes and exit fdisk with w.
- Use lsblk to confirm the new partitions are created successfully.
- Execute pvcreate /dev/sdd1 to initialize /dev/sdd1 as an LVM physical volume.
- Verify the creation with pvs.
Example: Creating an LVM Partition in fdisk
[root@server1 ~]# fdisk /dev/sdd
Welcome to fdisk (util-linux 2.37.4).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help): g
Created a new GPT disklabel (GUID: 3BCE8E49-EFDF-9144-ACD5-290F4FCCDA07).
Command (m for help): n
Partition number (1-128, default 1):
First sector (2048-41943006, default 2048):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-41943006, default 41943006): +1G
Created a new partition 1 of type ‘Linux filesystem’ and of size 1 GiB.
Command (m for help): t
Selected partition 1
Partition type or alias (type L to list all): lvm
Changed type of partition ‘Linux filesystem’ to ‘Linux LVM’.
Command (m for help): p
Disk /dev/sdd: 20 GiB, 21474836480 bytes, 41943040 sectors
Disk model: VMware Virtual S
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: 3BCE8E49-EFDF-9144-ACD5-290F4FCCDA07
Device Start End Sectors Size Type
/dev/sdd1 2048 2099199 2097152 1G Linux LVM
Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
Example: Verifying the Physical Volume
[root@server1 ~]# pvcreate /dev/sdd1
Physical volume “/dev/sdd1” successfully created.
[root@server1 ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sda2 rhel lvm2 a– <19.00g 0
/dev/sdd1 lvm2 — 1.00g 1.00g
For a detailed view, you can use pvdisplay as demonstrated in Example, or utilize lsblk (as shown in Example ) for a comprehensive overview of the current storage configuration on your server.
Creating Volume Groups in LVM
Once you’ve established a physical volume, the next step is to assign it to a volume group (VG). While you can incorporate a physical volume into an existing volume group (discussed later here), here you’ll learn how to forge a new volume group and integrate the physical volume into it. This process is straightforward and executes in a single command. Simply use vgcreate followed by your chosen volume group name and the physical device name. For instance, if your physical volume is named /dev/sdd1, the command would be vgcreate vgdata /dev/sdd1. You have the liberty to select any name for your volume group. I recommend starting each volume group name with vg, facilitating easy identification when managing multiple groups.
Earlier, you learned a two-step approach: creating the physical volume using pvcreate and subsequently integrating it via vgcreate. Alternatively, you can streamline this into a one-step procedure (useful when assigning an entire disk device). For example, to add the disk /dev/sdc directly, execute vgcreate vgdata /dev/sdc. If the device isn’t already marked as a physical volume, vgcreate will automatically designate it as such, allowing visibility via the pvs command.
When establishing volume groups, consider the physical extent size. This parameter dictates the size of the foundational units utilized for creating logical volumes (LVs). LVs are always sized in multiples of the physical extent size. Opting for a larger physical extent size is advantageous when crafting sizable LVs. By default, the physical extent size is set at 4 MiB, customizable up to a maximum of 128 MiB. Use the -s option with vgcreate to specify your preferred physical extent size, always a multiple of 2 MiB.
Note: When working with LVM, it’s crucial to understand the physical extent size, as it defines the fundamental units used in your storage configuration. This differs from logical extents utilized within file systems.
Post creation of the volume group, employ vgs for a concise overview or vgdisplay for detailed insights into its properties. Example showcases a sample output from vgdisplay.
Example: Displaying Volume Group Properties
[root@server1 ~]# vgdisplay vgdata
— Volume group —
VG Name vgdata
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 1
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 0
Open LV 0
Max PV 0
Cur PV 1
Act PV 1
VG Size 1020.00 MiB
PE Size 4.00 MiB
Total PE 255
Alloc PE / Size 0 / 0
Free PE / Size 255 / 1020.00 MiB
VG UUID KrzkCo-QUFs-quJm-Z6pM-qMh0-ZchJ-c677c2
Creating Logical Volumes and File Systems
With the volume group established, you’re set to create one or more logical volumes (LVs). This process involves more choices than setting up physical volumes or volume groups. When crafting a logical volume, specify its name and size. Size can be absolute (e.g., -L 5G for a 5 GiB LV) or relative (-l 50%FREE to utilize half of available space). Additionally, you can define size in extents using -l, alongside specifying the target volume group with -n (optional but recommended). For instance, lvcreate -n lvdata -l 100 vgdata creates an LV named lvdata spanning 100 extents within the vgdata group. Once created, employ mkfs to initialize a file system on the LV.
Understanding LVM Device Naming
Upon creating a logical volume, access it using device names. LVM volumes are addressable via several methods. A straightforward approach is /dev/vgname/lvname (e.g., /dev/vgdata/lvdata). Additionally, LVM utilizes the device mapper interface for naming, generating symbolic links in /dev/mapper (e.g., /dev/mapper/vgdata-lvdata corresponds to /dev/vgdata/lvdata).
Example provides an overview of these naming conventions:
Example : LVM Device Name Overview
[root@server1 ~]# ls -l /dev/mapper/vgdata-lvdata /dev/vgdata/lvdata
lrwxrwxrwx. 1 root root 7 Sep 16 11:34 /dev/mapper/vgdata-lvdata -> ../dm-2
lrwxrwxrwx. 1 root root 7 Sep 16 11:34 /dev/vgdata/lvdata -> ../dm-2
Exercise: Creating Volume Group and Logical Volumes
Building upon Exercise (where a physical volume was established), proceed to assign it to a volume group and craft logical volumes. Ensure completion of Exercise before undertaking this task:
- Launch a root shell and verify physical volumes using pvs (confirming presence of /dev/sdd1).
- Execute vgcreate vgdata /dev/sdd1 to form the volume group and integrate the physical volume.
- Use vgs to confirm successful volume group creation. Re-check with pvs to see physical volumes listed under their respective groups.
- Utilize lvcreate -n lvdata -l 50%FREE vgdata to generate an LV named lvdata consuming 50% of available space in vgdata.
- Validate creation with lvs.
- Proceed to establish a file system atop the logical volume using mkfs.ext4 /dev/vgdata/lvdata.
- Construct a directory for mounting: mkdir /files.
- Append /etc/fstab with: /dev/vgdata/lvdata /files ext4 defaults 0 0.
- Execute mount -a to validate mounting and file system operation.
- Verify status using lsblk to ensure successful partition mounting.
Table summarizes key commands essential for managing logical volumes in LVM.
This comprehensive approach empowers efficient management and utilization of LVM for storage configurations.
Resizing LVM Logical Volumes
LVM offers significant flexibility in resizing logical volumes (LVs), which is particularly valuable for managing disk space effectively. This section covers how to increase the size of an LVM logical volume and manage associated file systems.
Resizing Volume Groups
The cornerstone of LVM’s flexibility lies in its ability to resize volume groups (VGs) seamlessly. The vgextend command allows you to add storage to a VG, while vgreduce removes physical volumes from a VG when needed. Here’s how you can extend a volume group:
- Ensure Availability: Confirm that there’s a physical volume or device ready to be added to the volume group.
- Extend Volume Group: Use vgextend to incorporate additional storage into the volume group. The new space becomes immediately available for allocation within the VG.
After extending a volume group, use vgs to verify the addition of the new physical volume, as illustrated in Example:
[root@server1 ~]# vgs
VG #PV #LV #SN Attr VSize VFree
centos 1 2 0 wz–n- <19.00g 0
vgdata 2 1 0 wz–n- 1020.00m 512.00m
Resizing Logical Volumes and File Systems
Just as volume groups can be extended, logical volumes (LVs) can be expanded using the lvextend command. This command includes an important -r option that allows simultaneous resizing of the file system on the logical volume. It’s recommended to use this option rather than resizing them separately.
To increase the logical volume size, use lvextend or lvresize followed by -r to resize the file system accordingly. Here are different ways to resize a logical volume:
- Absolute Size: Use -L followed by + and the amount of space to add. For instance, lvresize -L +1G -r /dev/vgdata/lvdata adds 1GB to lvdata.
- Percentage of VG or Free Space: Utilize the -l option with either %VG or %FREE to specify the amount of space relative to the volume group or available free space.
Examples of lvresize commands:
lvresize -r -l 75%VG /dev/vgdata/lvdata # Resizes LV to 75% of total VG size
lvresize -r -l +75%VG /dev/vgdata/lvdata # Adds 75% of VG size to LV
lvresize -r -l +75%FREE /dev/vgdata/lvdata # Adds 75% of available free space to LV
lvresize -r -l 75%FREE /dev/vgdata/lvdata # Resizes LV to 75% of available free space
Logical extents, the building blocks of logical volumes, must align with physical extents defined during volume group creation. Resizing operations will adjust to these extents, sometimes rounding up or down as necessary.
Exercise provides hands-on experience in resizing logical volumes and their file systems.
Note: XFS file systems can only be increased in size, not decreased. For file systems that need to shrink, use Ext4.
Reducing Volume Groups
If necessary, a physical volume (PV) can be removed from a volume group (VG) if remaining PVs have adequate free space to accommodate the extents it currently uses. This process involves using pvmove to migrate data off the PV to be removed, followed by vgreduce to finalize its removal from the VG.
Exercise demonstrates the steps involved in removing a PV from a VG.
Configuring Stratis
In Red Hat Enterprise Linux (RHEL) 9, Stratis offers advanced storage management capabilities, akin to volume-managing file systems like Btrfs and ZFS. It introduces features such as thin provisioning, snapshots, and a programmatic API for flexible storage configuration.
Understanding Stratis Architecture
Stratis operates with a layered architecture starting with pools, analogous to LVM volume groups, and using XFS for file systems. Each Stratis file system is automatically thin provisioned, growing dynamically with data addition.
Creating Stratis Storage
Creating Stratis volumes involves several steps:
- Software Installation: Install Stratis using dnf with packages stratis-cli and stratisd.
- Daemon Activation: Start and enable the Stratis daemon using systemctl enable –now stratisd.
- Pool Creation: Use stratis pool create to establish a pool with one or more block devices. Additional devices can be added later with stratis pool add-data.
- File System Creation: Once the pool is set up, create a file system using stratis fs create.
- Verification: Confirm successful creation using stratis fs list. Mount the Stratis file system via /etc/fstab using UUID and include xsystemd.requires=stratisd.service to ensure proper Systemd handling.
Exercise guides you through the process of creating Stratis storage.
By understanding and applying these concepts, you can effectively manage disk space with LVM and explore advanced storage solutions with Stratis in RHEL 9.
Managing Stratis
Once you’ve set up your Stratis file system, there are several management tasks you can perform to ensure efficient usage and maintenance. Here’s how you can extend pools dynamically, monitor volumes, handle snapshots, and manage automatic mounting:
Extending Stratis Pools
To expand the storage capacity of your Stratis pool dynamically, use the stratis pool add-data command. This allows you to incorporate additional block devices into your existing pool as needed.
Monitoring Stratis Volumes
Traditional Linux tools aren’t optimized for handling thin-provisioned volumes created by Stratis. Instead, utilize Stratis-specific commands to monitor and manage your storage effectively:
- stratis blockdev: Displays information about all block devices used by Stratis.
- stratis pool: Provides details about Stratis pools, including crucial metrics like Physical Used and Physical Size, which should be monitored to prevent pool exhaustion.
- stratis filesystem: Enables monitoring and management of individual file systems within Stratis.
Managing Snapshots
Snapshots in Stratis capture a point-in-time state of a file system, allowing modifications without affecting the original data. Unlike LVM snapshots, Stratis snapshots remain independent of their original file systems, allowing them to persist even if the source file system is removed.
Exercise: Managing Stratis Volumes
To practice managing Stratis volumes effectively, follow these steps using a dedicated disk (e.g., /dev/sde):
- Install Required Packages: Use dnf install stratisd stratis-cli to install necessary Stratis packages.
- Enable Stratis Daemon: Start and enable the Stratis daemon with systemctl enable –now stratisd.
- Create Stratis Pool: Initialize a Stratis pool named mypool using stratis pool create mypool /dev/sde.
- Verify Pool Creation: Confirm the creation of the pool by listing all pools with stratis pool list.
- Create Stratis File System: Create a new Stratis file system named stratis1 within mypool using stratis fs create mypool stratis1.
- Verify File System Creation: Check the successful creation of the file system with stratis fs list.
- Prepare Mount Point: Create a directory for mounting the Stratis file system, for example, mkdir /stratis1.
- Edit /etc/fstab: Add an entry to /etc/fstab using the UUID of your Stratis volume for automatic mounting:
UUID=xxx /stratis1 xfs defaults,x-systemd.requires=stratisd.service 0 0
- Mount Stratis Volume: Apply changes in /etc/fstab using mount -a and verify successful mounting with mount.
- Copy Files: Copy files to the mounted Stratis volume for testing, e.g., cp /etc/[a-f]* /stratis1.
- Create Snapshot: Generate a snapshot of stratis1 using stratis filesystem snapshot mypool stratis1 stratis1-snap.
- Monitor Usage: Check current file system statistics with stratis filesystem list.
- Modify Files: Remove selected files from the Stratis volume, e.g., rm -f /stratis1/a*.
- Access Snapshot: Mount the snapshot for verification using mount /dev/stratis/mypool/stratis1-snap /mnt and confirm file availability.
- Reboot Verification: Reboot your server and confirm that the Stratis volume automatically remounts as configured in /etc/fstab.
By following these steps, you can effectively manage Stratis volumes, perform essential tasks like extending pools and creating snapshots, and ensure seamless operation through automatic mounting configurations.
Exercise: Managing Stratis Volumes
In this exercise, you will practice setting up and managing Stratis volumes on a dedicated disk. Follow the steps below to familiarize yourself with creating Stratis pools, file systems, snapshots, and ensuring automatic mounting.
Requirements
- One dedicated disk with a minimum size of 5 GiB (e.g., /dev/sde).
Steps
- Install Required Packages: Install the necessary Stratis packages using the following command:
dnf install stratisd stratis-cli
- Enable Stratis Daemon: Start and enable the Stratis daemon to manage Stratis volumes:
systemctl enable –now stratisd
- Create Stratis Pool: Add the entire disk (/dev/sde) to a new Stratis pool named mypool:
stratis pool create mypool /dev/sde
- Verify Pool Creation: Confirm that the Stratis pool mypool has been successfully created:
stratis pool list
- Create Stratis File System: Create a Stratis file system named stratis1 within the mypool:
stratis fs create mypool stratis1
- Verify File System Creation: Check that the file system stratis1 has been created:
stratis fs list
- Prepare Mount Point: Create a directory /stratis1 to serve as the mount point for the Stratis file system:
mkdir /stratis1
- Configure Automatic Mounting: Retrieve the UUID of the Stratis volume stratis1 and add an entry to /etc/fstab for automatic mounting:
UUID=xxx /stratis1 xfs defaults,x-systemd.requires=stratisd.service 0 0
- Mount Stratis Volume: Apply changes made in /etc/fstab to mount the Stratis volume stratis1:
mount -a
- Copy Files to Stratis Volume: Copy some files (e.g., /etc/[a-f]*) to the mounted Stratis volume /stratis1 for testing:
cp /etc/[a-f]* /stratis1
- Create Stratis Snapshot: Create a snapshot named stratis1-snap of the stratis1 file system within mypool:
stratis filesystem snapshot mypool stratis1 stratis1-snap
- Monitor File System Usage: View current file system statistics to monitor usage within the Stratis pool:
Copy code
stratis filesystem list
- Modify Files on Stratis Volume: Remove selected files (e.g., files starting with ‘a’) from the Stratis volume /stratis1:
rm -f /stratis1/a*
- Access Snapshot Data: Mount the created snapshot stratis1-snap to /mnt and verify the presence of files starting with ‘a’:
mount /dev/stratis/mypool/stratis1-snap /mnt
ls /mnt
- Reboot Verification: Reboot the server and ensure that the Stratis volume stratis1 is automatically remounted as configured in /etc/fstab.
Conclusion
By completing this exercise, you have gained practical experience in managing Stratis volumes, including creating pools, file systems, snapshots, and configuring automatic mounting. This knowledge will help you effectively utilize Stratis for storage management in Linux environments.
Revision
1. Introduction
Local storage management in RHEL involves various tasks such as partitioning disks, managing filesystems, configuring swap space, and handling advanced storage technologies like LVM and RAID. These skills are essential for optimizing the performance, reliability, and scalability of RHEL systems.
2. Understanding Local Storage
Local storage refers to the physical disks and partitions directly attached to the system. In RHEL, storage management includes creating and managing partitions, filesystems, and logical volumes.
3. Partitioning Disks
Partitioning a disk involves dividing it into distinct sections that can be managed separately. Common tools for partitioning in RHEL include fdisk
, gdisk
, and parted
.
Using fdisk
fdisk
is used for managing MBR (Master Boot Record) partitions.
# List available disks
fdisk -l
# Open a disk for partitioning (e.g., /dev/sda)
fdisk /dev/sda
# Interactive commands:
# n - create a new partition
# p - print the partition table
# d - delete a partition
# w - write changes and exit
Using parted
parted
is a more advanced tool supporting GPT (GUID Partition Table).
# Open a disk for partitioning
parted /dev/sda
# Interactive commands:
# mklabel gpt - create a new GPT partition table
# mkpart primary ext4 1MiB 100MiB - create a new partition
# print - print the partition table
# quit – exit
4. Managing Filesystems
After partitioning, the next step is to create filesystems on these partitions. Common filesystems in RHEL include ext4, xfs, and btrfs.
Creating a Filesystem
# Create an ext4 filesystem
mkfs.ext4 /dev/sda1
# Create an xfs filesystem
mkfs.xfs /dev/sda1
Checking and Repairing Filesystems
# Check an ext4 filesystem
e2fsck /dev/sda1
# Check an xfs filesystem
xfs_repair /dev/sda1
5. Configuring Swap Space
Swap space is used to extend the virtual memory of the system.
Creating a Swap Partition
# Create a swap partition
mkswap /dev/sda2
# Enable the swap partition
swapon /dev/sda2
# Verify swap status
swapon -s
Creating a Swap File
# Create a swap file
ddif=/dev/zero of=/swapfile bs=1M count=1024
# Set the correct permissions
chmod 600 /swapfile
# Format the file as swap
mkswap /swapfile
# Enable the swap file
swapon /swapfile
# Add the swap file to /etc/fstab for persistence
echo'/swapfile none swap sw 0 0' >> /etc/fstab
6. Mounting and Unmounting Filesystems
Mounting attaches a filesystem to the directory tree, while unmounting detaches it.
Mounting a Filesystem
# Create a mount point
mkdir /mnt/data
# Mount the filesystem
mount /dev/sda1 /mnt/data
# Verify the mount
df -h
Unmounting a Filesystem
# Unmount the filesystem
umount /mnt/data
# Verify the unmount
df -h
7. Persistent Mounts
To make mounts persistent across reboots, add entries to /etc/fstab
.
Editing /etc/fstab
# Example entry in /etc/fstab
/dev/sda1 /mnt/data ext4 defaults 0 0
# Mount all filesystems in /etc/fstab
mount -a
8. Managing LVM (Logical Volume Management)
LVM provides flexibility for managing disk space by abstracting physical storage into logical volumes.
Creating LVM
- Initialize Physical Volume (PV)
pvcreate /dev/sda3
- Create Volume Group (VG)
vgcreate myvg /dev/sda3
- Create Logical Volume (LV)
lvcreate -L 10G -n mylv myvg
- Create Filesystem on LV
mkfs.ext4 /dev/myvg/mylv
- Mount the LV
mount /dev/myvg/mylv /mnt/data
9. Resizing Filesystems
Extending an LVM Logical Volume
- Extend the Logical Volume
lvextend -L +5G /dev/myvg/mylv
- Resize the Filesystem
resize2fs /dev/myvg/mylv
xfs_growfs /mnt/data
Reducing an LVM Logical Volume
- Unmount the Filesystem
umount /mnt/data
- Resize the Filesystem
resize2fs /dev/myvg/mylv 10G
- Reduce the Logical Volume
bash
Copy code
lvreduce -L 10G /dev/myvg/mylv
- Remount the Filesystem
mount /dev/myvg/mylv /mnt/data
10. Creating and Managing RAID
RAID (Redundant Array of Independent Disks) provides data redundancy and performance improvements.
Creating a RAID Array
- Install mdadm
yum install mdadm
- Create a RAID 1 Array
mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sda1 /dev/sdb1
- Create a Filesystem on the RAID Array
mkfs.ext4 /dev/md0
- Mount the RAID Array
mount /dev/md0 /mnt/raid
11. Storage Quotas
Quotas manage disk space usage for users and groups.
Setting Up Quotas
- Enable Quotas on a Filesystem
mount -o remount,usrquota,grpquota /dev/sda1
- Initialize Quota Files
quotacheck -cug /mnt/data
- Assign Quotas
edquota -u username
- View Quota Reports
repquota /mnt/data
12. Conclusion
Managing local storage in RHEL involves understanding various tools and techniques to efficiently partition disks, create and manage filesystems, configure swap space, and use advanced storage solutions like LVM and RAID. Mastering these skills is essential for any system administrator, ensuring robust and scalable storage solutions for enterprise environments.
This guide provides a comprehensive overview of managing local storage in RHEL, covering essential commands and procedures aligned with the topic. Regular practice and hands-on experience with these tools will enhance your proficiency and prepare you for real-world system administration challenges.
MBR (Master Boot Record) and GPT (GUID Partition Table)
MBR (Master Boot Record)
Overview:
- MBR is a traditional partitioning scheme used since the early days of computing.
- It is located in the first sector of a storage device and contains the bootloader and partition table.
Structure:
- The MBR contains:
- Bootloader: A small program that loads the operating system.
- Partition Table: Information about the partitions on the disk, allowing up to four primary partitions.
- Disk Signature: A unique identifier for the disk.
Limitations:
- Supports a maximum disk size of 2 TB.
- Allows up to four primary partitions. If more partitions are needed, one must be an extended partition containing additional logical partitions.
- Not as robust against corruption because the MBR stores only one copy of the partition table.
Compatibility:
- Widely supported by various operating systems, making it suitable for older systems and certain compatibility scenarios.
GPT (GUID Partition Table)
Overview:
- GPT is a modern partitioning scheme that is part of the UEFI (Unified Extensible Firmware Interface) standard.
- It overcomes many limitations of MBR.
Structure:
- The GPT contains:
- Primary GPT Header: Located at the beginning of the disk, contains partition table and CRC32 checksums.
- Partition Entries: Stores detailed information about each partition, with support for up to 128 partitions by default.
- Backup GPT Header: Located at the end of the disk, provides redundancy against corruption.
Advantages:
- Supports disks larger than 2 TB and partitions of virtually any size.
- Allows up to 128 primary partitions without needing extended or logical partitions.
- Stores multiple copies of partition data, enhancing data integrity and recovery capabilities.
Compatibility:
- Required for booting from drives larger than 2 TB and supported by most modern operating systems.
File Systems in RHEL (Red Hat Enterprise Linux)
EXT2, EXT3, EXT4
EXT2 (Second Extended File System):
- Overview: The EXT2 file system is a non-journaling file system used primarily in the early days of Linux.
- Features: Supports large file sizes and large numbers of files, but lacks journaling, meaning recovery after crashes is slower.
- Use Cases: Suitable for flash drives and environments where write operations need to be minimized to prolong device life.
EXT3 (Third Extended File System):
- Overview: EXT3 is an extension of EXT2, adding journaling for improved reliability.
- Features:
- Journaling: Helps in quicker recovery after crashes by keeping a log (journal) of changes.
- Backward Compatibility: Can be mounted as EXT2 if journaling is disabled.
- Use Cases: Widely used in server environments for its balance of performance and reliability.
EXT4 (Fourth Extended File System):
- Overview: EXT4 is an advanced version of EXT3, with several performance and scalability enhancements.
- Features:
- Extent-based Storage: Improves large file performance by using contiguous blocks.
- Delayed Allocation: Improves performance by delaying block allocation until data is actually written.
- Faster File System Checking: Uses checksums to speed up the file system check process.
- Larger File and Volume Sizes: Supports volumes up to 1 EB and files up to 16 TB.
- Use Cases: Default file system in many Linux distributions, suitable for a wide range of applications from desktops to large servers.
Creating, Modifying, and Resizing EXT2/EXT3/EXT4 File Systems
Creating File Systems:
- EXT2:
mkfs.ext2 /dev/sdX1
- EXT3:
mkfs.ext3 /dev/sdX1
- EXT4:
mkfs.ext4 /dev/sdX1
Mounting File Systems:
mount /dev/sdX1 /mnt/mydisk
Changing File Systems:
- Convert EXT3/4 to EXT2:
tune2fs -O ^has_journal /dev/sdX1
- Convert EXT2 to EXT3:
tune2fs -j /dev/sdX1
Resizing File Systems:
- Resizing an EXT2/3/4 file system:
resize2fs /dev/sdX1
Checking and Repairing File Systems:
- EXT2:
fsck.ext2 /dev/sdX1
- EXT3:
fsck.ext3 /dev/sdX1
- EXT4:
fsck.ext4 /dev/sdX1
VFAT (Virtual File Allocation Table)
Overview:
- VFAT is an extension of the FAT16 and FAT32 file systems that supports long filenames and is commonly used for compatibility across different operating systems.
Creating VFAT File Systems:
mkfs.vfat /dev/sdX1
Mounting VFAT File Systems:
mount -t vfat /dev/sdX1 /mnt/mydisk
Checking and Repairing VFAT File Systems:
fsck.vfat /dev/sdX1
LVM (Logical Volume Manager)
Overview:
- LVM provides a flexible and powerful way to manage disk storage in Linux. It abstracts the physical storage devices into logical volumes, allowing for easier resizing and management.
Components:
- Physical Volume (PV): The underlying physical storage device (e.g., HDD, SSD, or a partition).
- Volume Group (VG): A pool of storage created from one or more physical volumes. It acts as a container from which logical volumes are allocated.
- Logical Volume (LV): A virtual partition created from a volume group, which can be easily resized and managed.
Creating LVM Components:
Creating PV:
pvcreate /dev/sdX
Creating VG:
vgcreate my_vg /dev/sdX
Creating LV:
lvcreate -n my_lv -L 10G my_vg
Managing LVM Components:
Resizing LV:
- Increase Size:
lvresize -L +5G /dev/my_vg/my_lv
resize2fs /dev/my_vg/my_lv # Resize file system
- Decrease Size:
resize2fs /dev/my_vg/my_lv # Resize file system before reducing size
lvresize -L -5G /dev/my_vg/my_lv
Removing LVM Components:
- Remove LV:
lvremove /dev/my_vg/my_lv
- Remove VG:
vgremove my_vg
- Remove PV:
pvremove /dev/sdX
Gdisk (GPT fdisk)
Overview:
- Gdisk is a command-line tool for creating and managing GPT partition tables. It is similar to the fdisk tool but supports GPT instead of MBR.
Basic Gdisk Commands:
Creating a New Partition:
gdisk /dev/sdX
# Follow the prompts to create a new partition
Listing Partitions:
gdisk -l /dev/sdX
Deleting a Partition:
gdisk /dev/sdX
# Use the ‘d’ command followed by the partition number
Converting MBR to GPT:
gdisk /dev/sdX
# Use the ‘w’ command to write the changes
Summary
Partitioning Schemes:
- MBR: Traditional, limited to 2 TB disks and four primary partitions.
- GPT: Modern, supports larger disks and more partitions, part of UEFI.
File Systems in RHEL:
- EXT2: Simple, non-journaling, used in specific scenarios.
- EXT3: Adds journaling to EXT2 for improved reliability.
- EXT4: Enhanced version with better performance and scalability.
- VFAT: Compatible across multiple operating systems, supports long filenames.
LVM:
- Provides a flexible way to manage storage.
- Components include PV, VG, and LV.
- Allows dynamic resizing and management of storage volumes.
Gdisk:
- Tool for managing GPT partitions.
- Offers features similar to fdisk but for GPT.
Each of these components and tools plays a crucial role in managing and utilizing storage in a Linux environment, providing flexibility, reliability, and compatibility for various use cases.
Introduction to gdisk
gdisk
is a command-line tool used for partitioning disks, specifically designed for GUID Partition Table (GPT) disks on Linux systems. It is a variant of fdisk
but optimized for modern GPT-based partitioning schemes. gdisk
offers a robust set of features for creating, modifying, and managing partitions on GPT disks, which are necessary for systems that require more than the traditional Master Boot Record (MBR) partitioning scheme allows.
Key Features of gdisk
- GPT Support:
gdisk
fully supports GPT partition tables, which are necessary for disks larger than 2TB and for systems that require more than four primary partitions. - Advanced Partitioning Options:
gdisk
provides more flexibility compared to MBR-based tools likefdisk
. It supports:
- Creation of up to 128 partitions.
- Large partition sizes exceeding 2TB.
- GUID (Globally Unique Identifier) assignment for partitions.
- Backup and Restore:
gdisk
allows you to save and restore partition table data, providing a safety net against accidental data loss. - Interactive Command-Line Interface: It offers an interactive mode where you can view, modify, and confirm changes before applying them to the disk.
Installing gdisk
On Red Hat Enterprise Linux (RHEL) or CentOS, you can install gdisk
using the package manager:
sudo yum install gdisk
Using gdisk
Launching gdisk
To launch gdisk
for a specific disk (e.g., /dev/sdb
), run:
sudo gdisk /dev/sdb
gdisk
Command Structure
Once inside gdisk
, the command structure is similar to other disk partitioning tools:
- Command:
m
: Print the help menu.p
: Print the partition table.n
: Create a new partition.d
: Delete a partition.w
: Write changes to disk and exit.
Partitioning with gdisk
- Creating a New Partition (
n
command): - Specify partition number, starting sector, ending sector, and partition type.
Example:
Command (? for help): n
Partition number (1-128): 1
First sector (2048-41943039, default = 2048): [Press Enter]
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-41943039, default = 41943039): [Press Enter]
- Deleting a Partition (
d
command):
- Select the partition number to delete.
Example:
Command (? for help): d
Partition number (1-128): 1
- Saving Changes (
w
command):
- Write the changes to the disk and exit
gdisk
.
Example:
Command (? for help): w
Advanced gdisk
Operations
- Changing Partition Type:
- Use the
t
command followed by the partition number to change the partition type GUID.
Example:
Command (? for help): t
Partition number (1-128): 1
Hex code or GUID (L to show codes, Enter = AF00): 8300 # Linux filesystem type
- Backing Up and Restoring Partition Table:
- Use the
b
command to save the current partition table to a file. - Use the
l
command to load a partition table from a file.
Example:
Command (? for help): b
Enter backup filename to save: backup.gpt
Command (? for help): l
Enter name of backup file to load: backup.gpt
- Viewing Detailed Partition Information:
- Use the
i
command followed by the partition number to view detailed information about a partition.
Example:
Command (? for help): i
Partition number (1-128): 1
Tips and Best Practices
- Backup: Always back up important data before making changes to disk partitions.
- Double-check: Verify partition sizes and types before confirming changes with
gdisk
. - Read Documentation: Refer to the
gdisk
manual (man gdisk
) for detailed explanations and additional options.
Conclusion
gdisk
is a powerful tool for managing partitions on GPT disks in Linux systems. Understanding its command structure and capabilities allows administrators to effectively partition disks, manage storage resources, and optimize system performance. By following best practices and exercising caution, you can confidently use gdisk
to configure disks according to your system requirements.