To convert your Ubuntu instance's default MBR partitioning scheme to GPT, complete the following steps:
-
Open the Amazon EC2 console.
-
Launch an instance from an Amazon Machine Image (AMI) that runs Ubuntu.
-
Launch a second instance from the same Ubuntu AMI with a 3 TiB root volume in the same Availability Zone .
-
Stop the second instance.
-
Detach the /dev/xvda or /dev/sda1 root volume from the second instance. Then, attach the root volume as /dev/sdf to the first instance.
-
Use SSH to connect to the first instance.
-
To view the root partition of /dev/sdf, run the following lsblk command:
sudo lsblk
Example output:
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
(snip)
xvdf 202:80 0 3T 0 disk
└─xvdf1 202:81 0 2T 0 part
(snip)
Note: In the preceding example, the root partition of /dev/sdf is 2 terabytes (TB). On Nitro instance types, the block device name is similar to /dev/nvme1n1.
-
To convert the partition table from MBR to GPT, use the gdisk tool to run the following command:
sudo gdisk /dev/xvdf
Note: If you enter incorrect commands in gdisk, then press q or Ctrl-C to quit from gdisk and not save the changes.
Example output:
GPT fdisk (gdisk) version 1.0.1
Partition table scan:
MBR: MBR only
BSD: not present
APM: not present
GPT: not present
***************************************************************
Found invalid GPT and valid MBR; converting MBR to GPT format
in memory. THIS OPERATION IS POTENTIALLY
DESTRUCTIVE! Exit by
typing 'q' if you don't want to convert your MBR partitions
to GPT format!
-
To enter Expert mode and set the sector alignment value, enter the following values at the prompts:
Command (? for help): x
Expert command (? for help): l
Enter the sector alignment value (1-65536, default = 2048): 1
Expert command (? for help): m
Note: Press Enter after each prompt. The preceding configuration changes the sector alignment value from the default 8 to 1. If you use the 8-byte (B) alignment, then you might experience issues when you create the GPT partition.
-
To create a GPT partition, enter the following values at the prompts:
Command (? for help): n
Partition number (2-128, default 2): 128
First sector (34-6291455966, default = 4294967296) or {+-}size{KMGTP}: 34
Last sector (34-2047, default = 2047) or {+-}size{KMGTP}:
Hex code or GUID (L to show codes, Enter = 8300): ef02
Note: Press Enter after each prompt. When you press Enter for the Last sector prompt, you receive the Current type is 'Linux filesystem' output. In the preceding example, ef02 is the BIOS boot partition number.
Example output:
Changed type of partition to 'BIOS boot partition'
-
To delete the root partition, enter the following values at the prompts:
Command (? for help): d
Partition number (1-128): 1
Note: Press Enter after each prompt.
-
To recreate the root partition to 3 TiB, enter the following values at the prompts:
Command (? for help): n
Partition number (1-128, default 1): 1
First sector (2048-6291455966, default = 2048) or {+-}size{KMGTP}:
Last sector (2048-6291455966, default = 6291455966) or {+-}size{KMGTP}:
Hex code or GUID (L to show codes, Enter = 8300):
Note: Press Enter after each prompt. When you press Enter for the Last sector prompt, you receive the Current type is 'Linux filesystem' output. To use the default settings, enter Enter for the First sector, Last sector, and Hex code or GUID prompts.
Example output:
Changed type of partition to 'Linux filesystem'
-
To save the GPT partition table, enter the following values at the prompts:
Command (? for help): w
Do you want to proceed? (Y/N): y
Important: This action overwrites existing partitions.
Example output:
OK; writing new GUID partition table (GPT) to /dev/xvdf.
The operation has completed successfully.
-
To view the new volume information, run the following lsblk command:
sudo lsblk
Example output:
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
xvdf 202:80 0 3T 0 disk
└─xvdf1 202:81 0 3T 0 part
-
To check whether the file system of the /dev/xvdf1 device is correct, use the fsck tool to run the following command:
sudo e2fsck -f /dev/xvdf1
Note: To respond yes to all questions, add a -y switch to the e2fsck command. For more information about the fsck tool, see fsck.8.gz on the Ubuntu website.
Example output:
e2fsck 1.42.13 (17-May-2015)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
cloudimg-rootfs: 57524/262144000 files (0.0% non-contiguous), 16648272/536870655 blocks
-
To resize the file system to 3 TiB, run the following resize command:
sudo resize2fs /dev/xvdf1
Note: It might take 10-20 seconds to resize the file system.
Example output:
resize2fs 1.42.13 (17-May-2015)
Resizing the filesystem on /dev/xvdf1 to 786431739 (4k) blocks.
The filesystem on /dev/xvdf1 is now 786431739 (4k) blocks long.
-
Install Grub on the /dev/xvdf1 device, and then use the following commands to configure Grub based on your Ubuntu version:
Ubuntu 16.04 or 18.04:
sudo mount /dev/xvdf1 /mnt
sudo mount --bind /proc /mnt/proc
sudo mount --bind /sys /mnt/sys
sudo mount --bind /dev /mnt/dev
sudo chroot /mnt /bin/bash
grub-install /dev/xvdf
grub-mkdevicemap
update-grub
exit
sudo umount -l /mnt/dev
sudo umount -l /mnt/sys
sudo umount -l /mnt/proc
sudo umount -l /mnt
Ubuntu 20.04:
sudo mount /dev/xvdf1 /mnt
sudo mount --bind /proc /mnt/proc
sudo mount --bind /sys /mnt/sys
sudo mount --bind /dev /mnt/dev
sudo chroot /mnt /bin/bash
grub-install /dev/xvdf
grub-mkdevicemap
echo "GRUB_DISABLE_OS_PROBER=true" >> /etc/default/grub
echo "GRUB_FORCE_PARTUUID=" >> /etc/default/grub.d/40-force-partuuid.cfg
update-grub
exit
sudo umount -l /mnt/dev
sudo umount -l /mnt/sys
sudo umount -l /mnt/proc
sudo umount -l /mnt
-
Detach the /dev/xvdf volume from the running instance.
-
Attach the /dev/xvdf volume back to the first instance as /dev/xvda or /dev/sda1.
-
Use SSH to connect to the first instance, and then start the instance.
-
To verify that the root volume on your original instance now has 3 TiB of space, run the lsblk command:
sudo lsblk