Fully Move Grub to New Partition
How do you fully move Grub to a new partition? When I installed Ubuntu (Kubuntu) I only allocated 256 MiB for the /boot
partition which doesn't appear to be enough. Every time a new kernel is installed the install fails part way through due to there not being enough space so I have to manually intervene. So I'm trying to move grub from my old boot partition, /dev/sdb5
, to my new 512 MiB partition, /dev/sdb7
.
I edited /etc/fstab
to point use the new boot partition.
# /boot was on /dev/sdb5 during installation
#UUID=f1fcbfbe-7943-4e48-9796-8d0c42076c0b /boot ext4 defaults 0 2
# /boot is now on /dev/sdb7
UUID=70d8be3a-6b6c-4722-ab0d-e79d93e6dd1c /boot ext4 defaults 0 2
I unmounted /boot/efi
(/dev/sdb2
), and /boot
(/dev/sdb5
). And then mounted /dev/sdb7
as /boot
, remounted /boot/efi
, and remounted /dev/sdb5
as /mnt/boot
.
I ran:
$ sudo grub-install /dev/sdb7
Installing for x86_64-efi platform.
Installation finished. No error reported.
And:
$ sudo update-grub
Generating grub configuration file ...
Found Windows Boot Manager on /dev/sdb2@/EFI/Microsoft/Boot/bootmgfw.efi
Adding boot menu entry for EFI firmware configuration
done
However, the Linux image is missing from /boot
:
$ ls -1 /boot
efi
grub
lost+found
While the old /boot
has:
$ ls -1 /mnt/boot/
abi-4.15.0-32-generic
abi-4.15.0-33-generic
config-4.15.0-32-generic
config-4.15.0-33-generic
efi
grub
initrd.img-4.15.0-33-generic
lost+found
memtest86+.bin
memtest86+.elf
memtest86+_multiboot.bin
retpoline-4.15.0-32-generic
retpoline-4.15.0-33-generic
System.map-4.15.0-32-generic
System.map-4.15.0-33-generic
vmlinuz-4.15.0-33-generic
I must be missing a step. What is the proper process to do this? Is there a command I'm missing to rebuild the Linux image?
NOTE: The reason I want /boot
to be a separate partition from /
is because /
is a LUKS encrypted ext4 partition.
Output from sudo fdisk -l
:
Disk /dev/sda: 931.5 GiB, 1000204886016 bytes, 1953525168 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: gpt
Disk identifier: CFE364AE-6B98-4A85-BE10-7E8A8833426F
Device Start End Sectors Size Type
/dev/sda1 2048 976762879 976760832 465.8G Microsoft basic data
/dev/sda2 976762880 977287167 524288 256M Linux filesystem
Disk /dev/sdb: 931.5 GiB, 1000204886016 bytes, 1953525168 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: 1AB601E6-CACA-4A3F-828A-A334CC3564DF
Device Start End Sectors Size Type
/dev/sdb1 2048 923647 921600 450M Windows recovery environment
/dev/sdb2 923648 1128447 204800 100M EFI System
/dev/sdb3 1128448 1161215 32768 16M Microsoft reserved
/dev/sdb4 1161216 1534093311 1532932096 731G Microsoft basic data
/dev/sdb5 1534093312 1534617599 524288 256M Linux filesystem
/dev/sdb6 1534617600 1952475135 417857536 199.3G Linux filesystem
/dev/sdb7 1952475136 1953523711 1048576 512M Linux filesystem
Disk /dev/mapper/sdb6_crypt: 199.3 GiB, 213940961280 bytes, 417853440 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Output from lsblk -lf
:
NAME FSTYPE LABEL UUID MOUNTPOINT
sda
sda1 ntfs Extra Disk 54186D8E186D7042
sda2 ext4 fae6b821-6644-4883-a2f1-da5c42485431
sdb
sdb1 ntfs Recovery 44F21BC7F21BBC5C
sdb2 vfat 941C-5A1E /boot/efi
sdb3
sdb4 ntfs 6C32289F3228706E
sdb5 ext4 Linux Boot Old f1fcbfbe-7943-4e48-9796-8d0c42076c0b /boot
sdb6 crypto_LUKS b2d73541-783b-4336-a62c-1e11d0cc2b47
sdb7 ext4 Linux Boot 70d8be3a-6b6c-4722-ab0d-e79d93e6dd1c
sr0
sdb6_crypt ext4 Linux Root 1e8b2b29-1857-4b38-84ee-d3c386f5085e /
Solution 1:
I could achieve it by doing it in the following way.
Below is the actual command lines view when I changed /boot
partition from sda7 to sda9
kubuntu@kubuntu:~$ sudo blkid
/dev/sda2: UUID="BCB3-3DA0" TYPE="vfat" PARTLABEL="EFI system partition" PARTUUID="e5db3aba-af70-4112-8858-1aff620887a0"
/dev/sda3: UUID="F2B6E7A8B6E76C13" TYPE="ntfs" PARTLABEL="Basic data partition" PARTUUID="02c16852-6715-42db-ac16-c9007d86934a"
/dev/sda4: UUID="2d2846e3-4382-4dec-bad3-ec27c9f3311d" TYPE="ext4" PARTUUID="67dd28fb-4a80-4deb-aa25-8f1b93f1a4ba"
/dev/sda5: LABEL="SAS DI" UUID="605EEA015EE9D038" TYPE="ntfs" PARTLABEL="Basic data partition" PARTUUID="82da16ec-8c57-41b8-9f8b-e2d2bdc3b183"
/dev/sda6: LABEL="MADURI" UUID="C4F8CC63F8CC54F8" TYPE="ntfs" PARTLABEL="Basic data partition" PARTUUID="6c75ef1c-376c-4ede-9072-3a888b0bf94d"
/dev/sda7: UUID="4eab37c8-7d22-4580-b53e-47e8768318c8" TYPE="ext4" PARTUUID="8d49090a-7495-4f10-a83d-3e4f4abca525"
/dev/sda8: UUID="e569a993-a701-4b1f-acc1-ba0e862ba0de" TYPE="ext4" PARTLABEL="Kubuntu 18.04" PARTUUID="af772c38-570b-4e9b-a5ce-ca26b28bec1a"
/dev/sda9: UUID="360b1c4c-b6f8-49fd-93e2-c9c086e95e4c" TYPE="ext4" PARTUUID="3327a153-0c8a-46c1-a23d-ef4774564875"
/dev/loop0: TYPE="squashfs"
/dev/sda1: PARTLABEL="Microsoft reserved partition" PARTUUID="c2ca0fe9-67db-468a-bf0f-8d9ce78cf129"
/dev/sdb1: UUID="2018-07-25-03-28-48-00" LABEL="Kubuntu 18.04.1 LTS amd64" TYPE="iso9660" PTUUID="418c5dc0" PTTYPE="dos" PARTUUID="418c5dc0-01"
/dev/sdb2: SEC_TYPE="msdos" UUID="0D5F-1DB6" TYPE="vfat" PARTUUID="418c5dc0-02"
kubuntu@kubuntu:~$ sudo mount /dev/sda8 /mnt
kubuntu@kubuntu:~$ sudo mount /dev/sda9 /mnt/boot
kubuntu@kubuntu:~$ sudo chroot /mnt
root@kubuntu:/# sudo nano /etc/fstab
sudo: unable to resolve host kubuntu: Resource temporarily unavailable
root@kubuntu:/# exit
exit
kubuntu@kubuntu:~$ sudo mkdir /mnt/home/OBP
kubuntu@kubuntu:~$ sudo mount /dev/sda7 /mnt/home/OBP
kubuntu@kubuntu:~$ sudo cp -r /mnt/home/OBP/* /mnt/boot/
kubuntu@kubuntu:~$ sudo mount /dev/sda2 /mnt/boot/efi
kubuntu@kubuntu:~$ for i in /sys /proc /dev /run; do sudo mount --bind "$i" "/mnt$i"; done
kubuntu@kubuntu:~$ sudo chroot /mnt
root@kubuntu:/# update-grub
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-4.15.0-29-generic
Found initrd image: /boot/initrd.img-4.15.0-29-generic
grub-probe: error: cannot find a GRUB drive for /dev/sdb1. Check your device.map.
Found Windows Boot Manager on /dev/sda2@/EFI/Microsoft/Boot/bootmgfw.efi
Found Ubuntu 18.10 (18.10) on /dev/sda4
Adding boot menu entry for EFI firmware configuration
done
root@kubuntu:/# grub-install /dev/sda
Installing for x86_64-efi platform.
Installation finished. No error reported.
root@kubuntu:/# update-grub
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-4.15.0-29-generic
Found initrd image: /boot/initrd.img-4.15.0-29-generic
grub-probe: error: cannot find a GRUB drive for /dev/sdb1. Check your device.map.
Found Windows Boot Manager on /dev/sda2@/EFI/Microsoft/Boot/bootmgfw.efi
Found Ubuntu 18.10 (18.10) on /dev/sda4
Adding boot menu entry for EFI firmware configuration
done
root@kubuntu:/# ls -1 /boot
abi-4.15.0-29-generic
config-4.15.0-29-generic
efi
grub
initrd.img-4.15.0-29-generic
lost+found
memtest86+.bin
memtest86+.elf
memtest86+_multiboot.bin
retpoline-4.15.0-29-generic
System.map-4.15.0-29-generic
vmlinuz-4.15.0-29-generic
root@kubuntu:/# lsblk -lf
NAME FSTYPE LABEL UUID MOUNTPOINT
loop0 squashfs
sda
sda1
sda2 vfat BCB3-3DA0 /boot/efi
sda3 ntfs F2B6E7A8B6E76C13
sda4 ext4 2d2846e3-4382-4dec-bad3-ec27c9f3311d
sda5 ntfs SAS DI 605EEA015EE9D038
sda6 ntfs MADURI C4F8CC63F8CC54F8
sda7 ext4 4eab37c8-7d22-4580-b53e-47e8768318c8 /home/OBP
sda8 ext4 e569a993-a701-4b1f-acc1-ba0e862ba0de /
sda9 ext4 360b1c4c-b6f8-49fd-93e2-c9c086e95e4c /boot
sdb iso9660 Kubuntu 18.04.1 LTS amd64 2018-07-25-03-28-48-00
sdb1 iso9660 Kubuntu 18.04.1 LTS amd64 2018-07-25-03-28-48-00
sdb2 vfat Kubuntu 18.04.1 LTS amd64 0D5F-1DB6
sr0
root@kubuntu:/# exit
exit
kubuntu@kubuntu:~$ shutdown now
Things to know before log on to "Try Kubuntu" session.
- Root partition; in my case it is
/dev/sda8
. - EFI partition; in my case it is
/dev/sda2
. -
/boot
old partition; in my case it is/dev/sda7
. - New
/boot
partition; in my case it is/dev/sda9
. - Drive letter of the hard disk; in my case it is sda.
I am going to change my boot partition from sda7 to sda9
Log on with Kubuntu 18.04 "Try Kubuntu" session.
Open Konsole and run the command
sudo blkid
and copy the UUID of the partition that is going to be new /boot partition that is sda9sudo mount /dev/sda8 /mnt
# mounting root partitionsudo mount /dev/sda9 /mnt/boot
# mounting new /boot partitionsudo chroot /mnt
-
nano /etc/fstab
# open the fstab file
Manually scroll down to the UUID part of /boot
in the /etc/fstab
file by arrow keys.
Paste the copied UUID (from step 1) by deleting the UUID of old boot partition.
To save the file, press Ctrl+X, Y and Enter
-
exit
# exit from chroot
Before mounting the /boot/efi
partition we have to copy the data in old boot partition to new boot partition.
-
sudo mkdir /mnt/home/OBP
# folder creation for mounting old boot partition -
sudo mount /dev/sda7 /mnt/home/OBP
# Old Boot Partition Mounting -
sudo cp -r /mnt/home/OBP/* /mnt/boot/
-
sudo mount /dev/sda2 /mnt/boot/efi
-
for i in /sys /proc /dev /run; do sudo mount --bind "$i" "/mnt$i"; done
-
sudo chroot /mnt
-
update-grub
-
grub-install /dev/sda
-
update-grub
exit
shutdown now
Fresh start the system and you may now delete the old boot partition.
Solution 2:
256 MB for /boot
and 200 GB for /
You have lots of space but /boot
directory is "space challenged". I'd suggest moving /boot
from sdb5
to /
on sdb6
.
Your current plan of moving /boot
to new partition sdb7
which is only 512 MB seems limited. Sometimes my /boot
can be many GB if I'm testing out multiple kernels.
How to move /boot
to /
There is already an answer here:
Yes it is possible. Also its not easy. If you intent to move separated /boot partition and or / partition you should consider first of all changing the fstab entries.
If you are moving the files to new partition then don't forget to use cp -p
while copying to preserve permissions. adjust then your /etc/fstab
to the new UUID's of partitions that you will use. YOu can get the partition uuid by running blkid /dev/sdXn
where X is name of the drive and n number of partition.
You can also use blkid to attach labels to your partitions and then mount via labels which is much easier read man blkid
to learn more.
After you change the partitions and adjust /etc/fstab you should run the update-grub
- available on Debian/Ubuntu script or grub-mkconfig -o /boot/grub/grub.cfg
to generate a new config file and then reinstall grub into the first hdd that you bot from. grub-install --recheck /dev/sdb
Of course do not forget that when copiying mount a new / or /boot partition on /mnt and after copying all of the files mount them as / and /boot chroot and only then run update of the grub if you want things to be done correctly.
Solution 3:
So, I guess you need just move/copy all kernel files from old directory to new, and update grub. Try: sudo cp /mnt/boot/* /boot && sudo update-grub