Formatting a Boot Partition in Ubuntu in Azure with GPT
After resizing the VM with growfs
disabled, create and format the new partition. The following example creates a GPT
partition and formats it with ext4
.
# gdisk /dev/sda
GPT fdisk (gdisk) version 1.0.3
Partition table scan:
MBR: protective
BSD: not present
APM: not present
GPT: present
Found valid GPT with protective MBR; using GPT.
Command (? for help): x
Expert command (? for help): e
Relocating backup data structures to the end of the disk
Expert command (? for help): m
Command (? for help): p
Disk /dev/sda: 65011712 sectors, 31.0 GiB
Model: Virtual Disk
Sector size (logical/physical): 512/4096 bytes
Disk identifier (GUID): 4BE72FBF-27EC-46C1-AA51-D9AB03EFC2B6
Partition table holds up to 128 entries
Main partition table begins at sector 2 and ends at sector 33
First usable sector is 34, last usable sector is 65011678
Partitions will be aligned on 2048-sector boundaries
Total free space is 2099166 sectors (1025.0 MiB)
Number Start (sector) End (sector) Size Code Name
1 227328 62914526 29.9 GiB 8300
14 2048 10239 4.0 MiB EF02
15 10240 227327 106.0 MiB EF00
The new boot partition should start at least 1 sector after the first partition ends. In this example, the new partition should start on sector 62914527 or higher.
Command (? for help): n
Partition number (2-128, default 2):
First sector (34-65011678, default = 62914560) or {+-}size{KMGTP}:
In this example the default is acceptable because it is higher than 62914527 and it is aligned on a 2048-sector boundary. If the system default for the first sector is not valid, enter a sector number one higher than the end of the first partition. The system will automatically increase that value to align on the proper sector boundary if required.
After the first sector is configured correctly, you can accept the default for the last sector.
Last sector (62914560-65011678, default = 65011678) or {+-}size{KMGTP}:
Current type is 'Linux filesystem'
Hex code or GUID (L to show codes, Enter = 8300): 0700
Changed type of partition to 'Microsoft basic data'
Command (? for help): p
Disk /dev/sda: 65011712 sectors, 31.0 GiB
Model: Virtual Disk
Sector size (logical/physical): 512/4096 bytes
Disk identifier (GUID): 4BE72FBF-27EC-46C1-AA51-D9AB03EFC2B6
Partition table holds up to 128 entries
Main partition table begins at sector 2 and ends at sector 33
First usable sector is 34, last usable sector is 65011678
Partitions will be aligned on 2048-sector boundaries
Total free space is 2047 sectors (1023.5 KiB)
Number Start (sector) End (sector) Size Code Name
1 227328 62914526 29.9 GiB 8300
2 62914560 65011678 1024.0 MiB 0700 Microsoft basic data
14 2048 10239 4.0 MiB EF02
15 10240 227327 106.0 MiB EF00
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/sda.
Warning: The kernel is still using the old partition table.
The new table will be used at the next reboot or after you
run partprobe(8) or kpartx(8)
The operation has completed successfully.
# reboot
After VM has rebooted, you can format the new partition with ext3
or ext4
. The following example uses ext4
.
# mkfs.ext4 /dev/sda2
The files from the /boot
directory should be copied to the new boot partition:
# mkdir -p /tmp/sda2 # mount /dev/sda2 /tmp/sda2 # umount /boot/efi # cp -a /boot/* /tmp/sda2
Find the UUID of the new boot partition:
# blkid -o list /dev/sda2 device fs_type label mount point UUID -------------------------------------------------------------- /dev/sda2 ext4 (not mounted) b425c93b-533d-4e73-\ 8c2b-dbca05b9a8f1 # umount /tmp/sda2
Add an entry to /etc/fstab
to mount the new boot partition, like this:
UUID=b425c93b-533d-4e73-8c2b-dbca05b9a8f1
/boot
ext4
defaults,discard
0 0
Important: Mount the /boot
partition. For example:
# mount /boot
Re-install grub on the current boot device. The following command copies the GRUB files to /boot
:
# grub-install /dev/sda
Linux has a new BootLoaderSpec system which prevents "grub2-mkconfig" from auto-generating the boot loader config file. To prevent this, disable the BLS config by changing the following line in /etc/default/grub, before running grub2-mkconfig:
GRUB_ENABLE_BLSCFG=true
to GRUB_ENABLE_BLSCFG=false
Note that GRUB is being installed on /dev/sda
but the boot directory comes from /dev/sda2
. Update your GRUB configuration to take this change into account:
# grub-mkconfig -o /boot/grub/grub.cfg
Reboot the system and make sure that it boots properly from the new boot partition.