Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

Moving the /boot partition

If none of the specific sub-forums seem right for your thread, ask here.
Post Reply
Message
Author
stef70
Posts: 4
Joined: 2014-02-07 13:12

Moving the /boot partition

#1 Post by stef70 »

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?

Bulkley
Posts: 6383
Joined: 2006-02-11 18:35
Has thanked: 2 times
Been thanked: 39 times

Re: Moving the /boot partition

#2 Post by Bulkley »

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.

stef70
Posts: 4
Joined: 2014-02-07 13:12

Re: Moving the /boot partition

#3 Post by stef70 »

A fresh install is effectively the easiest solution but trying to fix the system is a lot more fun.

User avatar
Head_on_a_Stick
Posts: 14114
Joined: 2014-06-01 17:46
Location: London, England
Has thanked: 81 times
Been thanked: 132 times

Re: Moving the /boot partition

#4 Post by Head_on_a_Stick »

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
deadbang

LE_746F6D617A7A69
Posts: 932
Joined: 2020-05-03 14:16
Has thanked: 7 times
Been thanked: 65 times

Re: Moving the /boot partition

#5 Post by LE_746F6D617A7A69 »

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

stef70
Posts: 4
Joined: 2014-02-07 13:12

Re: Moving the /boot partition

#6 Post by stef70 »

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

p.H
Global Moderator
Global Moderator
Posts: 3049
Joined: 2017-09-17 07:12
Has thanked: 5 times
Been thanked: 132 times

Re: Moving the /boot partition

#7 Post by p.H »

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.

User avatar
sickpig
Posts: 589
Joined: 2019-01-23 10:34

Re: Moving the /boot partition

#8 Post by sickpig »

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
Head_on_a_Stick
Posts: 14114
Joined: 2014-06-01 17:46
Location: London, England
Has thanked: 81 times
Been thanked: 132 times

Re: Moving the /boot partition

#9 Post by Head_on_a_Stick »

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.
deadbang

User avatar
sickpig
Posts: 589
Joined: 2019-01-23 10:34

Re: Moving the /boot partition

#10 Post by sickpig »

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.

Post Reply