Lesson 1, Topic 1
In Progress

Configuring Local Storage

1. Partitions: MBR vs GPT

a. MBR (Master Boot Record)

  • MBR is an older partitioning scheme.
  • It can only support disks up to 2TB.
  • Can only have 4 primary partitions or 3 primary and 1 extended partition with multiple logical partitions.

b. GPT (GUID Partition Table)

  • Modern partitioning scheme.
  • Supports disks larger than 2TB.
  • Can have up to 128 partitions without the need for extended/logical partitions.

Example

# To list partitions on a disk
fdisk -l /dev/sda


Practical Exercise

  1. Identify if your system uses MBR or GPT. Use fdisk or lsblk.

2. Creating and Deleting Partitions

Using fdisk (for MBR) and gdisk (for GPT).

Example:

# Create a partition on an MBR disk
fdisk /dev/sda

# Create a partition on a GPT disk
gdisk /dev/sda


Practical Exercise

  1. Add and then remove a partition on a test system or virtual machine.

3. Physical Volumes in LVM

Physical volumes (PVs) are storage devices or partitions that can be used in LVM (Logical Volume Manager).

Example:

# To create a PV
pvcreate /dev/sda1

# To remove a PV
pvremove /dev/sda1


Practical Exercise

  1. Convert a partition into a PV and then revert it.

4. Volume Groups and Logical Volumes

a. Volume Groups (VG) A VG consists of one or more PVs grouped together.

Example:

# To create a VG named "myvg" vgcreate myvg /dev/sda1 # Assign additional PVs to VG vgextend myvg /dev/sdb1 # Remove a PV from VG vgreduce myvg /dev/sda1

b. Logical Volumes (LV) An LV is a section of a VG that is allocated for a specific purpose, such as a filesystem or a swap space.

Example:

# To create a VG named "myvg"
vgcreate myvg /dev/sda1

# Assign additional PVs to VG
vgextend myvg /dev/sdb1

# Remove a PV from VG
vgreduce myvg /dev/sda1


Practical Exercise

  1. Create a VG, add a PV to it, create an LV, and then remove them.

5. Mounting File Systems by UUID or Label

Each storage device has a Universally Unique Identifier (UUID). This ensures the system mounts the correct device, even if their order changes.

Example:

# To find UUIDs
blkid

# To edit the `/etc/fstab` file to mount by UUID
UUID=[UUID_VALUE] /mount/point ext4 defaults 0 0

Alternatively, you can use labels.

Example:

# To set a label
e2label /dev/sda1 mylabel

# To mount by label in `/etc/fstab`
LABEL=mylabel /mount/point ext4 defaults 0 0


Practical Exercise

  1. Mount a filesystem using its UUID, then try using its label.

6. Adding Storage Non-Destructively

One of the benefits of LVM is the ability to expand storage without data loss.

Example:

# Add new partition as a PV
pvcreate /dev/sdb2

# Extend VG with the new PV
vgextend myvg /dev/sdb2

# Extend the LV
lvextend -l +100%FREE /dev/myvg/mylv

# Resize the filesystem
resize2fs /dev/myvg/mylv

For adding swap:

Example:

# Create an LV for swap
lvcreate -L 4G -n myswap myvg

# Format it as swap
mkswap /dev/myvg/myswap

# Enable swap
swapon /dev/myvg/myswap

# Add to /etc/fstab for persistence
/dev/myvg/myswap swap swap defaults 0 0


Practical Exercise

  1. Add additional storage to an LV. Check before and after storage with df -h.
  2. Add an additional swap space to your system.

Summary

Local storage configuration is essential in ensuring data integrity, optimal performance, and efficient space utilization. The principles and practices introduced here ensure flexibility, scalability, and resilience in storage management.

Key Points

  1. MBR and GPT are two partitioning schemes with distinct advantages and limitations.
  2. LVM provides a flexible storage management system, allowing for easy expansion and contraction of storage.
  3. Always use UUIDs or labels for mounting to ensure consistency across reboots or changes.