Convert MBR to GPT and Resize Linux Partitions Without Data Loss
This guide walks you through checking the current partition layout, converting an MBR‑styled disk to GPT using fdisk and GNU Parted, recreating the partition, formatting it with ext4, mounting it, and finally expanding the filesystem to utilize the full cloud‑disk capacity, all while preserving existing data.
1. Check current partition status
Run fdisk -lu to list disks and verify the partition table type. Example output shows /dev/vda with a dos label (MBR) and /dev/vdb also using dos .
2. Convert MBR to GPT
Because the disk is mounted and contains data, first unmount it: umount /dev/vdb1 Delete the existing partition with fdisk /dev/vdb and the d command, then write changes with w. After the partition table is altered, call ioctl() to re‑read it.
Now create a GPT label using GNU Parted:
parted /dev/vdb mklabel gptConfirm the warning about data loss, answer y, then create a primary partition covering the whole disk:
mkpart primary 1 100% align-check optimal 1Verify with print that the partition table is now gpt .
3. Create filesystem and mount
Format the new partition: mkfs.ext4 /dev/vdb1 Mount it to /mnt and list contents to confirm the lost+found directory:
mount /dev/vdb1 /mnt ls /mnt4. Expand the cloud disk
After the cloud provider has enlarged the underlying block device, verify the new size with fdisk -lu. The disk now shows a larger capacity but still has an MBR label.
Repeat the GPT conversion steps: delete the old GPT partition with rm 1, accept the backup‑GPT fix prompts (choose F), then recreate the partition covering the full space as before.
Mount the partition again, then resize the filesystem online: resize2fs /dev/vdb1 The command reports the new block count and confirms the filesystem now spans the entire disk.
5. Verify final layout
Run df -Th to see the updated sizes. The /dev/vdb1 mount point now shows the expanded size (e.g., 59 GB total, 57 GB available) while the original /dev/vda1 remains unchanged.
Practical DevOps Architecture
Hands‑on DevOps operations using Docker, K8s, Jenkins, and Ansible—empowering ops professionals to grow together through sharing, discussion, knowledge consolidation, and continuous improvement.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
