A while back I installed Linux on my SSD, sdb1. I also have a 1 terabyte drive for my home directory, sdc1. I have Windows on another hard drive, sda1, which I haven’t booted into in over 2 years. It is a terabyte in size. I would like to get rid of Windows and utilize that extra space without reinstalling Linux, but Grub is on the Windows hard drive, sda1. What I would like to do is put Grub onto my SSD, sdb1, if possible in order to format the Windows drive, sda1, and have extra space. It is Legacy BIOS on the computer.
2 Answers
I have done a trail with my dummy practical computer with one hdd and one ssd.
I assume, you have installed windows in UEFI boot mode with gpt partitioning type on your hdd. sda.
Since mine is a dummy practical computer, I don't need to worry about backup. I do recommend you to take backup.
I have not considered sdc for separate home partition as I don't have other drive free.
Procedure:
Log on with live session of Ubuntu.
Here are my sda-1tb hdd and sdb-120gb ssd.
I have windows10 on sda and Ubuntu18.04.1 on sdb. Grub is on sda.
You can see windows10 is installed in device sda with EFI partition on sda2. This is what controlling the grub now.
Important: this partition sda2 has UUID matched with the text in the file /etc/fstab on device sdb.
As we are going to format sda. We need to create EFI System Partition on sdb. sdb has only one partition sdb1. We have to create a EFI partition at start of the disk.
Now we got unallocated space of 100mb at start of disk sdb. In order to install grub on this we need it in FAT32 format with boot and esp flags.
Here if you observe, we have created 100mb EFI partition at the start of the disk. which should be named as sdb1. but gparted still shows it as sdb2. to sort out this
run sudo sgdisk -s /dev/sdb
Now delete the EFI partition (sda2) on sda or you can format entire device sda.
Now we need to install grub on /dev/sdb.
Procedure:
sudo mount /dev/sdb2 /mnt
# mounting root partition. (sdb2 is the ext4 /)for i in /sys /proc /run /dev; do sudo mount --bind "$i" "/mnt$i"; done
(binding the required folders).sudo mount /dev/sdb1 /mnt/boot/efi
# sdb1 is the EFI partition on sdb.sudo chroot /mnt
update-grub
grub-install /dev/sdb
update-grub
exit
Now we need to know the UUID of freshly created EFI Partition (sdb1) on device sdb.
Open "Disks" app.
Copy the UUID of sdb1.
Open the fstab file.
sudo nano /mnt/etc/fstab
. (note: i have used gedit, attached pics are gedit in the below).
paste the UUID at the rite place.
Save and Close.
Now reboot.
-
2After chrooting and reinstalling Grub to the new ESP you don't unmount nor reboot so the partition
sdb2
is still mounted at/mnt
and you can not mount it somehwere else unless you unmount it first. Probably easier to edit fstab withsudo nano /mnt/etc/fstab
to change the entry to the new UUID. Alternatively we could change the UUID of the new ESP to match the UUID of the old ESP, then there wouldn't be a need to edit fstab.– mook765Commented Sep 19, 2018 at 11:37 -
1@mook765 ..thank you for the superb point. I have edited the answer and added your point. Thank you once again.– PRATAPCommented Sep 19, 2018 at 13:39
-
I probably should have mentioned Legacy BIOS is all that necessary if I have regular bios and not UEFI. I really appreciate the work you did to explain it.– Bruce BCommented Sep 20, 2018 at 19:16
-
2PRATAP I do really appreciate all the work you did though that was very thorough thank you– Bruce BCommented Sep 20, 2018 at 19:25
-
1Thanks a lot for your great answer and work! Still working in 2019! Commented Mar 19, 2019 at 22:27
If you boot Grub in legacy BIOS mode you can (re-)install it to any drive with grub-install
using your current Ubuntu installation. (No need to boot a live system like when you need to reinstall/repair Grub on an unbootable system.)
Run:
sudo grub-install /dev/sdX
Replace
sdX
with the name that is currently assigned to the drive that you intend to use as boot device in the future.Configure your BIOS to boot from the drive with the new Grub installation.
There’s no real need to remove the old Grub installation.
-
When I run the command sudo grub-install /dev/sd? and my computer goes to update like new kernels is it going to automatically know to go to the new grub installation?– Bruce BCommented Sep 20, 2018 at 19:30
-
1@BruceB: Your follow-up question made me think of a few corner cases where this would fail. Could you please add the requested info to your question? I’ll explain based on the results. Commented Sep 20, 2018 at 21:14
sudo lsblk -f
,sudo os-prober
and the content of/broot/grub/grub.cfg
to your question? Thanks.