wesupport

25% off on first invoice for all services*

SPRING SALE

Use coupon

*Offer valid for new customers only

25% off on first invoice for all services*

SPRING SALE

Use coupon

*Offer valid for new customers only

Need help?

Our experts have had an average response time of 11.43 minutes in March 2024 to fix urgent issues.

We will keep your servers stable, secure, and fast at all times for one fixed price.

Convert EC2 CentOS instance’s default partitioning scheme to GPT

by | Aug 16, 2021

Wondering how to convert EC2 CentOS instance’s default partitioning scheme to GPT? We can help you!

Here, at Bobcares, we often receive similar requests from our AWS customers as a part of our AWS Support Services.

Today, let’s see the steps followed by our Support Techs to help our customers to convert the EC2 CentOS instance’s default partitioning scheme to GPT.
 

Convert EC2 CentOS instance’s default partitioning scheme to GPT

 
It is always better to take a backup of your EBS volume before beginning the task.
 
Now let’s see the steps to convert the Amazon EC2 CentOS instance’s default partitioning scheme to a GPT partitioning scheme.
 

  1. Firstly, log in to the AWS Management Console and open the AWS EC2 console.

2. Then launch an instance from an Amazon Machine Image running centOS.

3. Then we need to launch another instance from the same AMI and in the same Availablity zone of the first instance with 3 TiB root volume.

4. Stop the instance with 3 TiB root volume and also stop the first created instance.

5.Then detach the root volume from this stopped instance (/dev/xvda or /dev/sda1).

6. And attach that volume as /dev/sdf to the instance that we launched first at step 2.

7. Then start the instance we launched first and access the running instance via SSH.

8. Run the lsblk command to see the root partition of /dev/sdf.

# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
(snip)
xvdf 202:80 0 3T 0 disk
└─xvdf1 202:81 0 2T 0 part
Here the root partition is only 2T.

Sometimes /dev/xvdf1 may mount as the root file system “/“instead of /dev/xvda1.  So stop and start the instance a few times until /dev/xvda1 mounts as the root file system.

# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
xvda 202:0 0 8G 0 disk
└─xvda1 202:1 0 8G 0 part /
xvdf 202:80 0 3T 0 disk
└─xvdf1 202:81 0 2T 0 part

9. Now, to convert the partition table from MBR to GPT, we can use gdisk tool.

# sudo gdisk /dev/xvdf
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!

10. Then we need to enter the following commands to create a GPT partition. Type enter at the Last sector prompt to use the default sector number 2047. Also, note that ef02 is the BIOS boot partition number.

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}:
Current type is 'Linux filesystem'
Hex code or GUID (L to show codes, Enter = 8300): ef02
Changed type of partition to 'BIOS boot partition'

11. Now enter the following commands to delete the root partition:

Command (? for help): d
Partition number (1-128): 1

12. Then enter the following commands to recreate the root partition to 3 TB.

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}:
Current type is 'Linux filesystem'
Hex code or GUID (L to show codes, Enter = 8300):
Changed type of partition to 'Linux filesystem'

Type ‘enter’ in the First sector, Last sector, and Hex code or GUID to use the default settings.

13. Give the following commands at the prompt to save the GPT partition table:

Command (? for help): w
Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!
Do you want to proceed? (Y/N): y
OK; writing new GUID partition table (GPT) to /dev/xvdf.
The operation has completed successfully.

14. To see the details of the new partition, use gdisk command:

$ sudo gdisk -l /dev/xvdf
GPT fdisk (gdisk) version 0.8.10
Partition table scan:
MBR: protective
BSD: not present
APM: not present
GPT: present

Found valid GPT with protective MBR; using GPT.
Disk /dev/xvda: 6291456000 sectors, 2.9 TiB
Logical sector size: 512 bytes
Disk identifier (GUID): 35D6B819-1C79-4EC0-920F-4D1191609505
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 6291455966
Partitions will be aligned on 8-sector boundaries
Total free space is 0 sectors (0 bytes)

Number Start (sector) End (sector) Size Code Name
1 2048 6291455966 2.9 TiB 8300 Linux filesystem
128 34 2047 1007.0 KiB EF02 BIOS boot partition

15. To check that the file system of device /dev/xvdf1 is correct we can use file system check and repair tool:

CentOS 6:

# sudo e2fsck -f /dev/xvdf1
e2fsck 1.41.12 (17-May-2010)
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
/dev/xvdf1: 18734/524288 files (0.2% non-contiguous), 284948/2096896 blocks

CentOS 7:

# sudo xfs_repair /dev/xvdf1
Phase 1 - find and verify superblock...
- reporting progress in intervals of 15 minutes
Phase 2 - using internal log
- zero log...
- scan filesystem freespace and inode maps...
- 05:27:07: scanning filesystem freespace - 1025 of 1025 allocation groups done
- found root inode chunk
Phase 3 - for each AG...
- scan and clear agi unlinked lists...
- 05:27:07: scanning agi unlinked lists - 1025 of 1025 allocation groups done
- process known inodes and perform inode discovery...
- agno = 960
- agno = 0
- agno = 240
- agno = 480

(snip)
- agno = 238
- agno = 239
- 05:27:08: process known inodes and inode discovery - 25856 of 25856 inodes done
- process newly discovered inodes...
- 05:27:08: process newly discovered inodes - 1025 of 1025 allocation groups done
Phase 4 - check for duplicate blocks...
- setting up duplicate extent list...
- 05:27:08: setting up duplicate extent list - 1025 of 1025 allocation groups done
- check for inodes claiming duplicate blocks...
- agno = 0
- agno = 1
- agno = 2
- agno = 3
- agno = 4

(snip)
- agno = 1021
- agno = 1022
- agno = 1023
- agno = 1024
- 05:27:08: check for inodes claiming duplicate blocks - 25856 of 25856 inodes done
Phase 5 - rebuild AG headers and trees...
- 05:27:08: rebuild AG headers and trees - 1025 of 1025 allocation groups done
- reset superblock...
Phase 6 - check inode connectivity...
- resetting contents of realtime bitmap and summary inodes
- traversing filesystem ...
- traversal finished ...
- moving disconnected inodes to lost+found ...
Phase 7 - verify and correct link counts...
- 05:27:08: verify and correct link counts - 1025 of 1025 allocation groups done
done

16. To expand the partition to 3TB, we can use either xfs_growfs or resize2fs command.

CentOS 6:
# sudo resize2fs /dev/xvdf1
resize2fs 1.41.12 (17-May-2010)
Resizing the filesystem on /dev/xvdf1 to 786531938 (4k) blocks.

The filesystem on /dev/xvdf1 is now 786531938 blocks long.

CentOS 7:

# sudo mount -o nouuid /dev/xvdf1 /mnt

# sudo xfs_growfs /dev/xvdf1
meta-data=/dev/xvdf1 isize=512 agcount=1025, agsize=524224 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=536870656, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 536870656 to 786431739

17. Now install Grub on the device /dev/xvdf1 and then configure it using the following commands.

sudo mount --bind /proc /mnt/proc
sudo mount --bind /sys /mnt/sys
sudo mount --bind /dev /mnt/dev
sudo chroot /mnt /bin/bash
grub2-install /dev/xvdf
exit
sudo umount -l /mnt/dev
sudo umount -l /mnt/sys
sudo umount -l /mnt/proc
sudo umount -l /mnt

Grub installation is not needed for CentOS 6.

18. Then stop the instance.

19. Now we need to detach the volume /dev/xvdf from the stopped instance.

20. And attach the volume /dev/xvdf back to its original instance as /dev/xvda or /dev/sda1.

21. Then start the original instance using SSH.

22. Access the instance via SSH and use the lsblk command to check and verify that the root volume on the original instance has 3 TiB of space.

$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
xvda 202:0 0 3T 0 disk
└─xvda1 202:1 0 3T 0 part /
Important points:

Here in this task, we need to stop and start our instance, so before doing this, be sure to understand the following points:

  • The data will be lost while stoping the instance if our instance is instance store-backed or has instance store volumes containing data. So make sure to back up any data that want to keep on the instance store volume.
  • Also, note that stopping and restarting the instance changes the public IP address of the instance. So it is always better to use an Elastic IP address instead of a public IP address when routing external traffic to the instance.
  • If the instance is part of an Amazon EC2 Auto Scaling group then stopping the instance could terminate the instance. Also, if the instance is launched by services that use AWS Auto Scaling, such as Amazon EMR, AWS CloudFormation, etc., then stopping the instance could lead to its termination. In these cases, the instance termination depends on the instance scale-in protection settings for the Auto Scaling group. So If the instance is a part of an Auto Scaling group, remove the instance temporarily from the Auto Scaling group first. Then we can proceed with the recovery.

[Need help with more AWS queries? We’d be happy to assist]
 

Conclusion

 
To conclude, today we discussed the steps followed by our Support Engineers to help our customers convert EC2 CentOS instances default partitioning scheme to GPT.

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

GET STARTED

var google_conversion_label = "owonCMyG5nEQ0aD71QM";

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Categories

Tags