Disk and Partition Usage Commands

List Block Devices and Partitions

lsblk

Check Disk Space Usage

df -h

Extend Root Partition

Extend Logical Volume

sudo lvextend -l +100%FREE /dev/ubuntu-vg/ubuntu-lv

Resize Filesystem

sudo resize2fs /dev/ubuntu-vg/ubuntu-lv

Verify New Size and Free Space

df -h

To create and format new partition on a new disk (e.g., /dev/sdb)

Create a New Partition

sudo fdisk /dev/sdb

Inside fdisk, enter the following commands:
- n - new partition
- p - primary partition
- 1 - partition number
- [ENTER] - accept default first sector
- [ENTER] - accept default last sector (use full disk)
- w - write changes and exit

Format Partition with ext4 Filesystem

sudo mkfs.ext4 /dev/sdb1

Create Mount Directory

sudo mkdir -p /mnt/hdd

Mount the New Partition

sudo mount /dev/sdb1 /mnt/hdd

Get the UUID of the Partition

sudo blkid /dev/sdb1

Copy the UUID output, example:
- UUID="xxxx-xxxx-xxxx-xxxx"

Edit /etc/fstab to Mount at Boot

sudo nano /etc/fstab

Add this line (replace xxxx-xxxx-xxxx-xxxx with your actual UUID):

UUID=xxxx-xxxx-xxxx-xxxx /mnt/hdd ext4 defaults 0 2

Save and exit nano (Ctrl+O, Enter, Ctrl+X).

Test fstab and Mounts

sudo mount -a

Verify Mount

df -h /mnt/hdd