Linux Disk Management

Prepared by: Anwer Sadath Abdul Muttaliff

Project Overview

This project demonstrates Linux disk management using tools like lsblk, fdisk, LVM, and mount. The goal is to:

Step 1: Verify Existing Disks

List Block Devices

Use the lsblk command to list all block devices and their partitions.

$ lsblk
lsblk Output

Step 2: Add a New 30GB Disk

Add Disk in Virtual Machine

Add a new 30GB hard disk to the virtual machine and restart to detect it.

VM Settings

Step 3: Verify Disk Addition

Check New Disk

Verify the new disk using lsblk and fdisk.

$ lsblk
$ sudo fdisk -l
fdisk Output

Step 4: Partition the New Disk

Use fdisk to Partition

Use fdisk to partition the new disk (/dev/sdb).

$ sudo fdisk /dev/sdb
fdisk Partition Table

Step 5: Reload Partition Table

Reload Partitions

Reload the partition table to apply changes.

$ sudo partprobe

Step 6: Create Physical Volumes

Initialize LVM Partitions

Initialize the LVM partitions as physical volumes.

$ sudo pvcreate /dev/sdb6 /dev/sdb7 /dev/sdb8

Step 7: Create Volume Groups

Create HR and Finance Volume Groups

Create two volume groups: hr_vg and finance_vg.

$ sudo vgcreate hr_vg /dev/sdb6
$ sudo vgcreate finance_vg /dev/sdb7

Step 8: Extend Volume Groups

Extend hr_vg

Extend hr_vg with an additional partition.

$ sudo vgextend hr_vg /dev/sdb8

Step 9: Create Logical Volumes

Create HR and Finance Logical Volumes

Create logical volumes for HR and finance.

$ sudo lvcreate -L 5G -n hr_lv hr_vg
$ sudo lvcreate -L 5G -n finance_lv finance_vg

Step 10: Format Partitions

Format with ext4

Format the partitions with the ext4 filesystem.

$ sudo mkfs.ext4 /dev/sdb5
$ sudo mkfs.ext4 /dev/hr_vg/hr_lv
$ sudo mkfs.ext4 /dev/finance_vg/finance_lv

Step 11: Create Mount Points

Create Directories

Create directories for mounting the partitions.

$ sudo mkdir -p /mnt/hr /mnt/finance /mnt/data

Step 12: Mount Partitions

Mount Partitions

Mount the partitions to their respective directories.

$ sudo mount /dev/sdb5 /mnt/data
$ sudo mount /dev/hr_vg/hr_lv /mnt/hr
$ sudo mount /dev/finance_vg/finance_lv /mnt/finance

Step 13: Configure Swap Space

Enable Swap

Initialize and enable the swap partition.

$ sudo mkswap /dev/sdb9
$ sudo swapon /dev/sdb9

Step 14: Persist Configurations in /etc/fstab

Update /etc/fstab

Add entries to /etc/fstab to ensure partitions mount on boot.

$ echo '/dev/sdb5 /mnt/data ext4 defaults 0 2' | sudo tee -a /etc/fstab
$ echo '/dev/hr_vg/hr_lv /mnt/hr ext4 defaults 0 2' | sudo tee -a /etc/fstab
$ echo '/dev/finance_vg/finance_lv /mnt/finance ext4 defaults 0 2' | sudo tee -a /etc/fstab
$ echo '/dev/sdb9 none swap sw 0 0' | sudo tee -a /etc/fstab

Step 15: Verify Setup

Check Mounted Partitions

Check mounted partitions and swap usage.

$ df -h
$ free -m
df -h final output
Back to Top Back to Home