CLI Guideļ¼Managing Partitions in Linux
š CLI Guide: Managing Partitions in Linux
As a fan of local music player, my partition for Music is full. In order to create a bigger partition to fit my developing music taste, I copied my music collection to backup; deleted the original music paritition; compressed its previous partition; created a new partition out of the free space. This is how I did it, thanks GPT.
ā ļø Partitioning can destroy data. Always double-check device names and back up important files before deleting or creating partitions.
1. List disks and partitions
To see all devices, filesystems, and mount points:
1 | lsblk -f |
Shows:
NAME
ā device (e.g.,nvme0n1p5
)FSTYPE
ā filesystem (ext4, ntfs, exfat, etc.)LABEL
andUUID
ā useful for identifying in/etc/fstab
MOUNTPOINTS
ā where itās mounted
To also check partition numbers and sizes:
1 | sudo fdisk -l |
2. Show free space on the disk
Use parted
:
1 | sudo parted /dev/nvme0n1 unit s print free |
This shows sectors (Start
ā End
) and highlights Free Space areas.
3. Unmount before changes
If a partition is mounted:
1 | sudo umount /dev/nvme0n1pX |
Confirm:
1 | mount | grep nvme0n1pX # should show nothing |
4. Delete a partition
Use parted
or fdisk
.
With parted:
1 | sudo parted -s /dev/nvme0n1 rm 9 |
5. Create a new partition in free space
Find the free space start/end from parted print free
. Example:
1 | 1414328320s 1556498431s Free Space |
Then create:
1 | sudo parted -s -a optimal /dev/nvme0n1 mkpart Music ext4 1414328320s 1556498431s |
Confirm it exists:
1 | lsblk -f |
6. Format the partition
Format as ext4 and give it a label:
1 | sudo mkfs.ext4 -L Music /dev/nvme0n1p9 |
7. Mount it
1 | sudo mkdir -p /mnt/music |
Check:
1 | df -h | grep music |
8. Give ownership to your user
1 | sudo chown -R $USER:$USER /mnt/music |
After those, I can enjoy music again, with greater space.