How do I change the boot partition from one drives partition to a different drives partition?

I have two hard drives each with one primary partition, each with their own Ubuntu 18.04 install

sda1 40gb

sdb1 512gb

The only purpose of sdb1 is to hold compressed backups of sda1 Normally the computer boots and operates from sda1.

What I am trying to accomplish (via SSH konsole) is to change the boot device from sda1 to sdb1, then issue a reboot so that when it reboots sdb1 loads its copy of ubuntu, next I can create a backup image of sda1 and store it as a compressed image file on sdb1, after creating the backup image I would then want to change the boot drive back to sda1.

The purpose of this exercise is to be able to create a backup image of sda1 while it is unmounted to sdb1 using nothing but SSH.

I am familiar with changing boot devices in bios, or booting from thumb drives to create backups, I am trying to accomplish my goal without any physical interaction with the computer. (I do have physical access in-case things go wrong)

I have attempted changing the UUID entry in /etc/fstab to point to the UUID of sdb1 but grub/fstab still loads sda1 on boot/reboot.

5

2 Answers

If you are using EFI boot, you can temporarily set your next boot target using sudo efibootmgr -n <boot number>

First check the boot list using

$ sudo efibootmgr
BootCurrent: 0000
Timeout: 10 seconds
BootOrder: 0000,0004,2001,2002,2003
Boot0000* ubuntu
Boot0003* Windows Boot Manager
Boot0004* Windows Boot Manager
Boot2001* EFI USB Device
Boot2002* EFI DVD/CDROM
Boot2003* EFI Network
$ sudo efibootmgr -n 4
BootNext: 0004
BootCurrent: 0000
Timeout: 10 seconds
BootOrder: 0000,0004,2001,2002,2003
Boot0000* ubuntu
Boot0003* Windows Boot Manager
Boot0004* Windows Boot Manager
Boot2001* EFI USB Device
Boot2002* EFI DVD/CDROM
Boot2003* EFI Network

The change only affect the next boot, so after rebooting again it will revert to the original boot order.

(BIOS setup from Xekon's post)

For BIOS systems, the best solution is grub-reboot which allows a one time boot of a different grub entry.

First we must set some settings for grub so that it cooperates with grub-reboot:

sudo nano /etc/default/grub
GRUB_DEFAULT=saved
GRUB_TIMEOUT=2

ctrl+x to save and exit

sudo grub-set-default 0
sudo update-grub

now upon boot, look at the grub entries, it is 0 based, for me I have:

0 Ubuntu
1 Advanced options for Ubuntu
2 Ubuntu 18.04.1 LTS (18.04) (on /dev/sdb1)
3 Advanced options for Ubuntu 18.04.1 LTS (18.04) (on /dev/sdb1)

so my default is 0 (Ubuntu on /dev/sda1) and 2 (Ubuntu on /dev/sdb1) is my other install of ubuntu on the second hard drive.

So doing the following while booted into /dev/sda1, will allow me to boot a single time into /dev/sdb1:

sudo grub-reboot 2
sudo reboot

Then I can perform my backup or restore on /dev/sda1, and then simply issue a sudo reboot, and be booted back into /dev/sda1

5

For UEFI systems, see Bernard Wei post

For BIOS systems, the best solution is grub-reboot which allows a one time boot of a different grub entry.

First we must set some settings for grub so that it cooperates with grub-reboot:

sudo nano /etc/default/grub
GRUB_DEFAULT=saved
GRUB_TIMEOUT=2

ctrl+x to save and exit

sudo grub-set-default 0
sudo update-grub

now upon boot, look at the grub entries, it is 0 based, for me I have:

0 Ubuntu
1 Advanced options for Ubuntu
2 Ubuntu 18.04.1 LTS (18.04) (on /dev/sdb1)
3 Advanced options for Ubuntu 18.04.1 LTS (18.04) (on /dev/sdb1)

so my default is 0 (Ubuntu on /dev/sda1) and 2 (Ubuntu on /dev/sdb1) is my other install of ubuntu on the second hard drive.

So doing the following while booted into /dev/sda1, will allow me to boot a single time into /dev/sdb1:

sudo grub-reboot 2
sudo reboot

Then I can perform my backup or restore on /dev/sda1, and then simply issue a sudo reboot, and be booted back into /dev/sda1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like