[SOLVED] How to swap physical hard disks (sda <-> sdb) with several Linux OSs installed

Questions about Grub, UEFI,the liveCD and the installer
Forum rules
Before you post please read how to get help
Post Reply
111MilesToGo
Level 2
Level 2
Posts: 90
Joined: Fri Oct 14, 2016 5:43 am

[SOLVED] How to swap physical hard disks (sda <-> sdb) with several Linux OSs installed

Post by 111MilesToGo »

In short: I have two physical hard disks (both SSDs) for my laptop. Both have several Linux distros installed. Both were installed when the respective disk was sitting on the laptop's main SATA port, i.e. both were /dev/sda at the time of installation. I now want to put one of the disks into an external enclosure and have both running at the same time, making the second disk /dev/sdb (or any other). What steps would it take to get everything (the Linux OSs themselves, the GRUB2 bootings) work fine under all circumstances?

Long write-up:

Motivation behind having two physical hard disks:

One is for "real production", i.e. it is updated thoroughly, has all SSD life-saving measures in place, and it holds all my precious data. The other hard disk is for "testing" purposes, i.e. try a new Kernel or Plasma version, try a program first here, evaluate other Linux distros etc. Yes, this does sound like it's calling for VirtualBox with several Virtual Machines. However, I decided to try the separate-hard-disk approach since (1) a virtual machine is never the same as a physical one (graphics, audio, some packages maybe working differently), (2) the virtual machines would have to reside on the second hard disk and not on the "real" one for HD space reasons, and (3) laptop performance would be compromised a lot because of reason 2 and because of getting only half of the laptop resources (CPUs, RAM).

What I did up to now: Let's call my two physical hard disks PH1 (the "real" thing) and PH2 (the "testing ground"):
  • PH1 is UEFI-booted and GPT-partitioned. It has Tumbleweed / Leap 42.2 / Linux Mint 18.1 on it across a total of seven partitions (root and home x3, joint swap). Its eighths partition holds my data. Of course, there is also an EFI partition holding all EFI boot stuff from GRUB2. When PH1 was installed, it was sitting on the laptop's internal SATA port (6GB/s) as /dev/sda.
  • PH2 is BIOS-booted and also GPT-partitioned. It has a total of six Linux distros (each with separate root and home) on it, plus a joint swap. It has a BIOS boot partition, but the GRUB2 bootloader stub is installed in the disk's MBR. When installing PH2, it was sitting on the same internal SATA port, making it /dev/sda.
Both disks boot fine, and all Linux systems run fine.

What I want to do now:
  • I want to put PH2 into an external enclosure with eSATA 3GB/s connection type (takes half of the disk speed away, but seems faster and more reliable than USB 3.0).
  • And PH1 shall go back into the laptop's internal SATA port.
  • I want to operate PH1 in the same manner as before, including OS and GRUB2 updates.
    • This would work right away, and it would not require any changes if PH2 is removed during such updates.
    • In case PH2 were connected during updates, I think I would have to insert the line

      Code: Select all

      GRUB_OS_PROBER_SKIP_LIST="FSUUID1@/dev/sdb2 FSUUID2@/dev/sdb3 etc"
      in each of the /etc/default/grub files of each operating system on PH1 in order to make the GRUB2 OS Prober ignore all operating systems on PH2 during any GRUB update from PH1 OSs, since I want the GRUB2 boot menu to show me only PH1 OSs when booting from PH1.
    • One final step would be required: Update GRUB2 from within the "master" operating system on PH1, which happens to be Tumbleweed.
  • The harder task is to prepare and run PH2 from the external enclosure, i.e. as /dev/sdb if there are no USB sticks or other media listed in front of it. I am seeking community advice on what and how to do this in the best way possible.
    • Of course, an appropriate

      Code: Select all

      GRUB_OS_PROBER_SKIP_LIST="FSUUID1@/dev/sda2 etc"
      would have to be put into all /etc/default/grub files of each OS on PH2.
    • What else needs to be done? Maybe modify device.map, fstab ?
    • Would a grub update that is run from an OS on PH2 know that it should touch only PH2 which would be /dev/sdb now instead of /dev/sda at the time of installing PH2 ???
    • Would any Linux OS on PH2 know under all circumstances that the /dev/sda (which was PH2 at the time of installation) no longer is /dev/sda now, but /dev/sdb ? Any known hard-wired dependencies on /dev/sdX settings ???
  • I suppose my laptop would be able to first boot from the eSATA external disk when the laptop BIOS boot order calls it first, even when the eSATA is BIOS-booted and the internal SATA is UEFI-booted. Remark: This laptop doesn't have an eSATA UEFI boot option, just eSATA BIOS; but it has both BIOS and UEFI boot modes for the internal hard disk.
Please, I am seeking all expert advice on what to do for qmaking my PH2 run properly from the external eSATA port as /dev/sdb or sdc. "Run properly" meaning (1) run the Linux OSs properly, (2) do all updates (in particular, Kernels and GRUB2 configs) properly, and (3) don't touch anything on PH1 except when told explicitly to do so. This is what I mean by swapping physical hard disks (sda <-> sdb). I didn't find much convincing advice in the various fora yet; most people look into transferring a system from one disk to another.

If you were to advise seriously to forget this idea of having two separate hard disks, I would ruefully turn to Virtual Machines (cf. above). Or I would keep my "real" PH1 only. But having a testing and play ground would be really nice...

Thanks a lot in advance.
Last edited by 111MilesToGo on Sat Jun 24, 2017 6:17 pm, edited 1 time in total.
acerimusdux
Level 4
Level 4
Posts: 343
Joined: Sat Dec 26, 2009 3:36 pm

Re: How to swap physical hard disks (sda <-> sdb) with several Linux OSs installed

Post by acerimusdux »

While switching disks from /dev/sda to /dev/sdb, etc., used to cause problems, I thought most thigns were using UUIDs now. So a first suggestion is to make sure everything on both disks, from /etc/fstab, to grub installations, is identifying all the partitions by UUID, not /dev.
111MilesToGo
Level 2
Level 2
Posts: 90
Joined: Fri Oct 14, 2016 5:43 am

Re: How to swap physical hard disks (sda <-> sdb) with several Linux OSs installed

Post by 111MilesToGo »

Fully agreed. One of many things I don't know yet is: What does device.map do for GRUB2? It has s.th. like (hd0,sda) and (hd1,sdb). When is it read or used?
User avatar
gold_finger
Level 9
Level 9
Posts: 2885
Joined: Mon Mar 11, 2013 11:39 pm

Re: How to swap physical hard disks (sda <-> sdb) with several Linux OSs installed

Post by gold_finger »

While I've never done this myself (2 HHDs with distros installed in 2 diff boot modes), my guess is that you actually won't have to do anything special at all.

Keep UEFI mode (production) drive installed in computer, plug Bios mode external in and simply boot machine as you normally would to enter either drive. From your description, computer itself is set to boot normally in UEFI mode -- so, if you don't manually intervene to change boot process, it will automatically boot your production drive. Updating grub on controlling OS in production drive won't change anything on the external test drive. The worst that will happen is that the OSs on the test drive will get listed as boot choices, but because they are installed in Bios mode they will simply fail to start if selected. (I have a feeling that updating grub on production drive will not even do that, but that's just a guess.)

If you want to boot from external test drive, just use UEFI Boot Menu by hitting whatever key is assigned for that while powering up and select booting from it there. Usually computers have a key assigned to get into main UEFI Setting/Startup Menu and one for invoking a special one-time Boot Menu. Using the one-time (per-session) boot menu is easier than constantly going into main settings and changing boot mode back and forth there. You should see two choices for booting external drive -- just select the one that is non-UEFI. When booted into external drive, you can perform update-grub on controlling OS there and it won't "touch" the OSs on production drive. Again, I doubt it will even produce boot choices for those OSs because they're installed in different mode, but even if it does the only thing that will happen is those OSs won't boot when selected.

Don't worry about device designations (sda, sdb) -- grub files will be booting based on GUIDs and not the device names.

Give this a shot -- worst that will happen is you'll end up with boot listings that don't work when selecting one that is on a different drive from one that is being booted.
Please add [SOLVED] to your thread if a solution is found. Go to your first post in the thread, hit "Edit" button and add [SOLVED] to the title of the post.

How To Format Your Forum Posts.

Try Linux Beginner Search Engine for Linux questions.
acerimusdux
Level 4
Level 4
Posts: 343
Joined: Sat Dec 26, 2009 3:36 pm

Re: How to swap physical hard disks (sda <-> sdb) with several Linux OSs installed

Post by acerimusdux »

111MilesToGo wrote:Fully agreed. One of many things I don't know yet is: What does device.map do for GRUB2? It has s.th. like (hd0,sda) and (hd1,sdb). When is it read or used?
Good question. My understanding is grub currently defaults to using UUID when posible. I wonder though, when wouldn't it be possible?
111MilesToGo
Level 2
Level 2
Posts: 90
Joined: Fri Oct 14, 2016 5:43 am

Re: How to swap physical hard disks (sda <-> sdb) with several Linux OSs installed

Post by 111MilesToGo »

Thanks up to now to you. I am hoping for more tips and discussion.

I will get back to my PC on Monday and try to go on from this point.

However, I am not fully knowledgable yet about the following:
  • We have four players in the game: Computer hardware, BIOS (without or with EFI capability), GRUB2, Linux
  • We have different names for the hardware: Computer ports, hd0 etc, /dev/sda and /dev/sdan etc, UUIDs
  • We have two points in time: Boot process, updating/installing GRUB2 from an OS
Who calls whom by what name at what time? In particular, as asked above, what does device.map do and when?

I will try to read more if available, but -please- let me have more community advice. Thanks! In fact, I would like to hope nothing much needs to be done, as mentioned above.
111MilesToGo
Level 2
Level 2
Posts: 90
Joined: Fri Oct 14, 2016 5:43 am

Re: How to swap physical hard disks (sda <-> sdb) with several Linux OSs installed

Post by 111MilesToGo »

Update: Thanks, acerimusdux and gold_finger, you/we are all correct. I gave it a shot and swapped disks to what I want them to be. Both GRUB2 and Linux are using UUIDs in their key settings (/boot/grub/grub.cfg, /etc/fstab). Even though grub.cfg has entries of the type "set root='hd0,gpt2'" which are wrong when moving a disk from internal to external SATA ports, the operating systems on both disks boot fine right away.

To polish things a bit, it's nice to modify /etc/default/grub by appending the a.m. OS Prober Skip List and run update-grub or grub2-mkconfig to write a new grub.cfg. This then has the proper "hd0" and "hd1" as well as the proper grub menu hints "OS xy (on /dev/sdb6)". Works fine.

The one issue I am left with / needs to be tested is: What happens when any one of the installed OSs does a kernel update or gets a new GRUB2 version? Updating the config alone isn't bad, but what if it wants to install GRUB2 all over again?
Post Reply

Return to “Installation & Boot”