5

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.

  • while installing Ubuntu on sdb1 have you selected boot loader for installation as sda? have you chosen something else option? can you open GParted and attach screenshots when you select sda, sdb and sdc devices. – PRATAP Sep 19 '18 at 2:54
  • Could you please add the output of sudo lsblk -f, sudo os-prober and the content of /broot/grub/grub.cfg to your question? Thanks. – David Foerster Sep 20 '18 at 21:13
6

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.

enter image description here

enter image description here

enter image description here

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.

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

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.

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

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

enter image description here

Now delete the EFI partition (sda2) on sda or you can format entire device sda.

enter image description here

Now we need to install grub on /dev/sdb.

Procedure:

  1. sudo mount /dev/sdb2 /mnt # mounting root partition. (sdb2 is the ext4 /)
  2. for i in /sys /proc /run /dev; do sudo mount --bind "$i" "/mnt$i"; done
    (binding the required folders).
  3. sudo mount /dev/sdb1 /mnt/boot/efi # sdb1 is the EFI partition on sdb.
  4. sudo chroot /mnt
  5. update-grub
  6. grub-install /dev/sdb
  7. update-grub
  8. 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.

enter image description here

enter image description here

enter image description here

Now reboot.

enter image description here

  • 2
    After 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 with sudo 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. – mook765 Sep 19 '18 at 11:37
  • 1
    @mook765 ..thank you for the superb point. I have edited the answer and added your point. Thank you once again. – PRATAP Sep 19 '18 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 B Sep 20 '18 at 19:16
  • 2
    PRATAP I do really appreciate all the work you did though that was very thorough thank you – Bruce B Sep 20 '18 at 19:25
  • 1
    Thanks a lot for your great answer and work! Still working in 2019! – Pengxer yesterday
3

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

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

  2. 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 B Sep 20 '18 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. – David Foerster Sep 20 '18 at 21:14

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.