attempting to tranfer Ubuntu 22.04 OS to another drive

Bob Proulx bob at proulx.com
Fri Dec 9 03:48:35 UTC 2022


Phil Marsh wrote:
> I have a Xubuntu installation on a hard drive. Originally, I did the
> installation on a SATA SSD but somehow the installer directed the
> installation on the new drive to mount the efi partition on the
> original install on the SSD.

The BIOS has a concept of the boot disk priority.  And so does GRUB.
And so does Linux.  These are often different!

I think from this and from other discussion you had multiple drives
attached, you installed to one of the lower priority drives according
to GRUB, when grub installed it installed to the BIOS boot drive,
creating the situation that you are in.

My advice is to unplug all drives except for the one you want to
install upon.  This can simply be by unplugging the SATA cable.  Then
the various installers have no choices.  Things tend to go better that
way.  And then later attach other drives back onto the system, plug
the SATA cable back in.

I have re-ordered the SATA ports on devices in order to get everything
to match up.  So that the BIOS boot drive and the GRUB boot drive are
both the same drives.  This can be confusing though.

> I'm trying to correct this and tried to copy all the OS files to an
> external drive and tried to make that drive bootable with no
> success, using an old method that used to work for Ubuntu 18.04 on
> my old server.

What was that old method that you used?

> When booting from the external drive grub comes up with an error
> because it's trying to look for the OS on the wrong drive, in spite
> of being installed to the external drive.

What was the error?

Though this does not surprise me.  It might be required to boot the
installer in rescue-mode and then use it to mount and chroot into the
system and then use that to install grub again.

In the old days I would say "grub-install /dev/sdX" but on Debian
based systems I find that the grub packaging is abusing the debconf
database as a registry in spite of debconf specifically saying it is
not to be used as a registry.  It uses it to register the boot devices
so that upon later package upgrades it will use that in the postinst
script to install and update the grub-install.

Meaning that one must "dpkg-reconfigure grub-pc" for legacy BIOS
booting so that it can register the boot device and upgrade it upon
later package upgrades.  AFAIK this does not apply to grub-efi-amd64
the grub EFI boot package.

> I also changed the external drive's fstab file to reflect the
> external drive,

The /etc/fstab is not involved in the grub boot process.  Therefore it
just does not matter.

> but grub still looks on the wrong drive - which is
> removed during the boot of the external USB drive.  Basically, would
> one of you be able to kindly tell me how to transfer the OS files to
> a new drive and make that drive bootable?

It's possible.  But honestly it is easier to install again.

> I'd set my machine's bios to boot in legacy but it seems that the
> efi partition keeps getting mounted.

That indicates that the system is actually booting in UEFI mode.

> I'll need to know how to do this in the future because I use this
> method to be able to always come up with a bootable drive and
> recover without a total reinstallation of the OS.

The hardest part is getting the partitioning correct.  Different
partitions are needed for UEFI than for Legacy BIOS.  It is possible
to include both sets and then the system can be adapted to boot from
either one or the other later by installing the matching grub
package.  Either grub-pc for Legacy BIOS or grub-efi-amd64 for UEFI.

I will sometimes use the installer to do the partitioning.  Then exit
out of the installer after the partitions are finalized.  Then create
the file systems and copy all of the files onto them from another
system.  Then chroot into the newly copied files and install grub (and
dpkg-reconfigure grub-pc if needed).  At that point the system should
boot.

Bob


More information about the NCLUG mailing list