Step-by-step guide on how to repartition a drive, set up LVM (Logical Volume Management), and create an ext4 file system on a new logical volume in Linux:
fdisk
Start fdisk on Your Disk
sudo fdisk /dev/nvme0n1
View Current Partitions
Command (m for help): p
Delete Existing Partitions (if needed)
Command (m for help): d
Enter the partition number to delete.
Create a New Partition
Command (m for help): n
Select (default p): p
Select partition number (default 1): 1
First sector (default is fine, just press Enter):
Last sector (use default to allocate the entire disk, just press Enter):
Change Partition Type to Linux LVM
Command (m for help): t
Selected partition 1
Hex code (type L to list all codes): 8e
Write Changes to Disk
Command (m for help): w
Create a Physical Volume (PV)
sudo pvcreate /dev/nvme0n1p1
Create a Volume Group (VG)
sudo vgcreate new-disk /dev/nvme0n1p1
Create a Logical Volume (LV)
sudo lvcreate -l+100%FREE -n data new-disk
sudo mkfs.ext4 /dev/mapper/new--disk-data
Create a Mount Point
sudo mkdir /mnt/newdisk
Mount the Logical Volume
sudo mount /dev/mapper/new--disk-data /mnt/newdisk
Automatically Mount at Boot (Optional)
blkid /dev/mapper/new--disk-data
/etc/fstab
and add an entry for the logical volume:UUID=your-uuid-here /mnt/newdisk ext4 defaults 0 2
your-uuid-here
with the UUID you obtained from blkid
.sudo
for commands that require root privileges.lsblk
to list all block devices and their mount points, which is useful for verifying the disk layout before and after the changes.