Knowledgebase
Knowledgebase
CentOS 6 - move /boot to larger partition
Posted by Ilya Vasilenko on 12 November 2020 10:26 AM

Sometimes old systems are set up with small /boot partition at the beginning of partition table.

In this case it is impossible to expand boot partition and ones face the issue when there is not enough space to hold even 2 kernels.

The solution is to create a new partition at the end of drive and move /boot there.

First you need to expand your virtual disk so there is unpartitioned space. This is done in the virtualization system by your host.

Example below uses following defaults:

- the drive is GPT

- boot partition is /dev/sda1

- new boot partition is /dev/sda5

  1. Create new Linux partition at the end of drive with desired size. If your drive is GPT use gdisk, if MBR and less then 4 partitions exist you can use fdisk, otherwise convert drive to GPT first.
  2. Probe the new partition: partx -v -a /dev/sda
  3. If you get the error: Not enough space to build proposed filesystem while setting up superblock
    You need to reboot the server.
  4. Format the new drive: mkfs.ext4 /dev/sda5
  5. Copy everything from /dev/sda1 to /dev/sda5 in "dd" way using:
    dd if=/dev/sda1 of=/dev/sda5 bs=1M
  6. Do the /dev/sda5 partition FS check and FS resize (as after "dd" it inherits size from /dev/sda1):
    e2fsck -fy /dev/sda5
    resize2fs /dev/sda5
    e2fsck -fy /dev/sda5
  7. Un-mount /dev/sda1:
    umount /dev/sda1
  8. Mount /dev/sda5 to /boot:
    mount /dev/sda5 /boot

Now we need to tell GRUB to use /dev/sda5 as /boot (/boot is root for GRUB in this case).

Run "grub-install --recheck /dev/sda".

After that check the file /boot/grub/grub.conf (ensure that /dev/sda5 mounted on /boot) and replace all entries of hd(0,0) with hd(0,4)

Change the UUID of the original /dev/sda1: tune2fs /dev/sda1 -U random

Also, check /etc/fstab file that the new device UUID (or partition listed) is correct (whatever is being used there) for /boot mount point device.

You can find new UUID for /dev/sda5 by the command "blkid".

Reboot.

 

 

Some manual commands for information, although the above should work without issue:

All commands for copy paste assuming sda8

partx -v -a /dev/sda
mkfs.ext4 /dev/sda8
dd if=/dev/sda1 of=/dev/sda8 bs=1M
e2fsck -fy /dev/sda8
resize2fs /dev/sda8
e2fsck -fy /dev/sda8
umount /dev/sda1
mount /dev/sda8 /boot
grub-install --recheck /dev/sda
tune2fs /dev/sda1 -U random
vi /boot/grub/grub.conf
mkfs.ext4 /dev/sda1

 

 

If you just run "grub-install /dev/sda" it may still catch old /boot partition at /dev/sda1 as all data and headers are still existing there.

Instead of deleting /dev/sda1 and hoping it works we need to explicitly tell grub to use /dev/sda5 as our /boot partition.

In the shell run the command "grub"

Then follow the log below:

grub> find /grub/stage1
find /grub/stage1
(hd0,0)
(hd0,4)
grub> root (hd0,4)
root (hd0,4)
Filesystem type is ext2fs, partition type 0x83
grub> setup (hd0)
setup (hd0)
Checking if "/boot/grub/stage1" exists... no
Checking if "/grub/stage1" exists... yes
Checking if "/grub/stage2" exists... yes
Checking if "/grub/e2fs_stage1_5" exists... yes
Running "embed /grub/e2fs_stage1_5 (hd0)"... failed (this is not fatal)
Running "embed /grub/e2fs_stage1_5 (hd0,4)"... failed (this is not fatal)
Running "install /grub/stage1 (hd0) /grub/stage2 p /grub/grub.conf "... succeeded
Done.
grub> quit

Please note:

  1. hd(0,0) is actually the first partition (/dev/sda1)
  2. hd(0,4) is 5th partition (/dev/sda5)
  3. We tell Grub to find "stage1" section and it shows two partitions: the old and new /boot
  4. We choose to use /dev/sda5, in this case it is hd(0,4)
  5. You can ignore those two failures reported by grub.
(1 vote(s))
Helpful
Not helpful