Moving the /boot partition

If none of the more specific forums is the right place to ask

Moving the /boot partition

Postby stef70 » 2020-10-14 14:07

I made a stupid mistake when I installed Debian on my x86 laptop a few years ago. I made a /boot partition of size 244MB.
Initially, that was enough to install 2 kernels but now the kernels+initrd are over 75MB and I get disk space errors during upgrades (because apt adds the new files before removing the old ones). I cannot easily grow the /boot partition because it is immediately followed by a large encrypted+LVM partition. Fortunately, I noticed that before /boot there is a large 512MB partition /boot/efi that is mostly empty. I was able to shrink the EFI partition thus leaving a hole of 479MB before /boot

# fdisk -l /dev/sdb
...
/dev/sdb1 2048 67968 65921 32.2M EFI System
/dev/sdb2 1050624 1550335 499712 244M Linux filesystem
/dev/sdb3 1550336 488396799 486846464 232.2G Linux filesystem


So my plan is to move /boot into that large hole. This is the easy part but then my problem will be that I do not know how EFI and grub are interacting.

I assume that the EFI bios is simply running the GRUB executable in /boot/efi/EFI/debian/grubx64.efi

Will GRUB be able to find the new /boot partition?
Do I need to run update-grub?
Do I need to run grub-install and if so with some argument?

So what I have in mind is:

  • remount /boot as /oldboot
  • create the new /boot partition and copy files from /oldboot
  • edit the UUID of /boot in /etc/fstab
  • execute update-grub
  • execute grub-install (with some options?)
Does that seem reasonable?
stef70
 
Posts: 4
Joined: 2014-02-07 13:12

Re: Moving the /boot partition

Postby Bulkley » 2020-10-14 15:11

Many years ago I used Gparted (I think) on a live-CD to solve that problem. It was a slow operation in which the equivalent of your /dev/sdb3 was shrunk a bit, /dev/sdb2 was moved over to take up the slack and /dev/sdb1 expanded to fill up the vacated space.

Stop right now and back up everything of value on another media. If you screw up you don't want to lose the important stuff.

Consider doing a fresh install.
Bulkley
 
Posts: 6004
Joined: 2006-02-11 18:35

Re: Moving the /boot partition

Postby stef70 » 2020-10-14 15:25

A fresh install is effectively the easiest solution but trying to fix the system is a lot more fun.
stef70
 
Posts: 4
Joined: 2014-02-07 13:12

Re: Moving the /boot partition

Postby Head_on_a_Stick » 2020-10-14 15:58

stef70 wrote:I assume that the EFI bios is simply running the GRUB executable in /boot/efi/EFI/debian/grubx64.efi

Not quite. Debian buster supports Secure Boot so it now runs /EFI/debian/shimx64.efi on the EFI system partition, this then loads grubx64.efi

stef70 wrote:Will GRUB be able to find the new /boot partition?

Only if grubx64.efi is reinstalled after creating the new /boot partition.

stef70 wrote:Do I need to run update-grub?

Yes (after mounting the new /boot partition).

stef70 wrote:Do I need to run grub-install and if so with some argument?

Mount the new /boot partition then run
Code: Select all
# dpkg-reconfigure grub-efi-amd64

^ That presumes you have a 64-bit UEFI implementation and that the EFI system partition is mounted under /boot/efi
Black Lives Matter

Debian buster-backports ISO image: for new hardware support
User avatar
Head_on_a_Stick
 
Posts: 12650
Joined: 2014-06-01 17:46
Location: /dev/chair

Re: Moving the /boot partition

Postby LE_746F6D617A7A69 » 2020-10-14 16:08

It's sufficient to just just move and resize the partition (without re-formatting) using f.e. gparted - no changes in the configuration are required in such case (because the UUID stays unchanged).
The partition is small, so it shouldn't take much time.
Bill Gates: "(...) In my case, I went to the garbage cans at the Computer Science Center and I fished out listings of their operating system."
The_full_story and Nothing_have_changed
LE_746F6D617A7A69
 
Posts: 395
Joined: 2020-05-03 14:16

Re: Moving the /boot partition

Postby stef70 » 2020-10-14 19:24

Thanks, I followed the previous comments and everything worked fine.
So for anyone in the same situation, I did the following. This is assuming /boot/efi is sda1 and /boot is sda2

Code: Select all
# Shrink /boot/efi
umount /boot/efi
fatresize -s 33735168 /dev/sda1
# move and resize /boot using gparted
umount /boot
gparted /dev/sdb
# restore the mounts 
mount /boot
mount /boot/efi
# reconfigure grub & efi
dpkg-reconfigure grub-efi-amd64
# remark: I used the default for all questions.
# cross fingers and
reboot
stef70
 
Posts: 4
Joined: 2014-02-07 13:12

Re: Moving the /boot partition

Postby p.H » 2020-10-15 19:47

If you have the signed GRUB for UEFI secure boot (with shimx64.efi), it looks for the UUID of the /boot filesystem in /boot/efi/EFI/debian/grub.cfg. The signed core image embeds most modules including normal.mod, so it does not need modules in /boot/grub/x86_64 and you will not see "grub rescue" even if /boot/grub cannot be found.
-> If the /boot filesystem UUID does not change, then you do not need to reinstall GRUB not run update-grub.

If you have the unsigned GRUB (without shimx64.efi), then things are different. If the /boot filesystem is in a plain partition on the same disk as the core image, then the core image records the partition number.
-> If the /boot partition number changes, then you need to run grub-install. If the filesystem UUID also changes, you need to run update-grub.
If the /boot filesystem is on a different disk or a "complex" device (md RAID, LVM...), then the core image records the filesystem UUID.
-> If the /boot filesystem UUID changes then you need to run grub-install and update-grub.
In both cases, the core image embeds only the required modules to read the /boot filesystem and needs to load additional modules from /boot/grub to enable normal mode. (beyond rescue mode).
-> If the /boot device type (partition, RAID, LVM...) changes, you have to run grub-install.

In you case, resizing the existing /boot partition did not change the UUID so it did not require to run grub-install nor update-grub.
p.H
 
Posts: 1489
Joined: 2017-09-17 07:12

Re: Moving the /boot partition

Postby sickpig » 2020-10-16 09:34

p.H wrote:In you case,

It's in your case.
p.H wrote:In you case, resizing the existing /boot partition did not change the UUID so it did not require to run grub-install nor update-grub.

That's exactly what LE_746F6D617A7A69 posted so how is your reply different?

edit - added ' to its
User avatar
sickpig
 
Posts: 575
Joined: 2019-01-23 10:34

Re: Moving the /boot partition

Postby Head_on_a_Stick » 2020-10-16 14:07

sickpig wrote:how is your reply different?

Read p.H's reply again, it includes a lot of very useful information. I've certainly learned some new things from it.
Black Lives Matter

Debian buster-backports ISO image: for new hardware support
User avatar
Head_on_a_Stick
 
Posts: 12650
Joined: 2014-06-01 17:46
Location: /dev/chair

Re: Moving the /boot partition

Postby sickpig » 2020-10-16 18:34

I doubt the utility of responses made to posts wherein the OP has confirmed issue resolution. If the intention is knowledge impartation then howto section is the best place for it. However if the intention is I will showboat then the present approach works.
User avatar
sickpig
 
Posts: 575
Joined: 2019-01-23 10:34


Return to General Questions

Who is online

Users browsing this forum: No registered users and 21 guests

fashionable