5

I recently got a new SSD and I cloned my old HDD to my new SSD.

I was able to boot into Ubuntu 16.04 LTS after the cloning process,but when I put the old HDD back into the computer, the computer boots using the old HDD, and not the new SSD as it should.

I used boot repair and selected my SSD as my "OS to boot by default" and it fixed grub. Now, when I select the SSD in the updated grub menu, it boots from the HDD instead.

How do I fix this?

Notes:

  • I think it may have something to do with the UUID.
  • My old HDD is found at /dev/sda2.
  • I currently have Windows 7 installed, and booting properly from the new SSD using the grub menu and experience no issues with Windows.
mo mo
  • 51
  • You cannot have duplicate UUIDs. That is why it often is easier just to reinstall Ubuntu to a new drive and copy your /home over to new drive. Post these: cat /etc/fstab & lsblk -f – oldfred May 12 '18 at 22:36
  • While you can change UUID, update fstab & reinstall grub. If not familar with UUIDs and where they are in system, it often is just easier to do a new clean install. My install to a SSD from my HDD takes 10 min. That is just for install, copying data & reconfiguring and in about an hour I have a working system. – oldfred May 19 '18 at 03:32

2 Answers2

3

You're probably correct... duplicate UUIDs.

You'll need to change the UUID on either the HDD or SSD, and edit your /etc/fstab.

  • disconnect the HDD
  • boot to the SSD

In terminal...

  • sudo blkid # to determine /dev/sdaN and old UUID for the Ubuntu partition
  • sudo cp /etc/fstab /etc/fstab.bck # backup this file
  • sudo pico /etc/fstab # edit the fstab file
  • change UUID=the_old_UUID to read /dev/sdaN, where N is the number of the Ubuntu partition, for the boot drive mount
    • control+o # to save the edit
    • return # to confirm the filename
    • control+x # to exit the editor
  • reboot # to make sure it still boots properly

Boot to a Ubuntu Live DVD...

In terminal...

  • sudo blkid # to determine /dev/sdaN and old UUID for the Ubuntu partition
  • sudo uuidgen -t # generate a new time-based UUID (write down this new UUID)
  • sudo tune2fs -U new_UUID /dev/sdaN # using your own new UUID and /dev/sdaN numbers
  • reboot # to reboot to the SSD and confirm operation

Update #1: There's a slight possibility that the Ubuntu won't boot here, due to the UUID change, so you may have to edit the GRUB boot command once.

If so, at the GRUB menu...

  • highlight the appropriate Ubuntu boot selection
  • hit the e key to edit the GRUB command line
  • use the arrow keys and move to the line that contains "splash quiet"
  • manually change the old UUID to the new UUID you wrote down earlier
  • control+x to continue booting

Boot back into the SSD...

In terminal...

  • sudo blkid # to obtain the new UUID
  • sudo pico /etc/fstab # edit the file
  • change the /dev/sdaN, where N is the number of the Ubuntu partition, back to UUID=the_new_UUID, for the boot drive mount
    • control+o # to save the edit
    • return # to confirm the filename
    • control+x # to exit the editor
  • sudo update-grub # update grub
  • reboot # to make sure it still boots properly

Reinstall HDD if desired.

heynnema
  • 70,711
  • Thank you for your reply, I'll try your above answer as soon as I have a chance to access my device. I'll notify you with the result. – mo mo May 14 '18 at 06:08
  • I'm currently trying your solution, but when I try sudo tune2fs -U new_UUID /dev/sdaN (I changed new_UUID and sdaN to the numbers generated and my sdaN) it gave me "The UUID may only be changed when the filesystem is unmounted." and when i tried to unmount it refused because i was running the ubuntu that i wanted to unmount so, I tried booting from an external usb stick that had boot repair and I tried the same thing in a terminal after unmounting the sdaN that had ubuntu on my SSD but it didn't work either it said i must run a command and when i did it refused because i don't have permission – mo mo May 18 '18 at 21:15
  • @momo see my updated procedure – heynnema May 18 '18 at 23:37
  • I just tried your updated solution, I'm currently facing an error when I run the sudo tune2fs -U new_UUID /dev/sdaN it brings up **This operation requires a freshly checked filesystem.

    Please run e2fsck -f on the filesystem.** I did generate a new UUID and I replaced new_UUID and also N I replaced it with the sdaN number

    – mo mo May 25 '18 at 11:25
  • I even tried to generate a new UUID from Gparted after I boot from a ubuntu live on a usb stick and it gave me the same error as above. I had to unmount my SSD ubuntu to be able to click on new UUID from Gparted – mo mo May 25 '18 at 11:27
  • I've managed to change the UUID to a new one, now I'm at the point to change the old UUID to the new generated UUID in the /etc/fstab directory I was able to edit the old one with the new generated UUID but when I try to save ctrl+o abd hit return afterwords it says Error writing /etc/fstab: Read-only file system how do I save the /etc/fstab I have been following it commands u mentioned above now in stock at the read only error. – mo mo May 25 '18 at 12:14
  • @momo If you've successfully changed the UUID and booted back into the SSD, your file system should be r/w and you shouldn't see that error. – heynnema May 25 '18 at 13:39
2

If you are using GRUB 2 as your bootloader, you can use GRUB's command line to choose which partition to boot from and which partition to mount as root.

I'm assuming your ultimate goal is to reformat your old drive, preferably without having to use live media. If you are trying to set up a multi-boot system between the cloned disks, this will allow you to boot to one or the other, but I wouldn't recommend it as a permanent solution.

1. Show the GRUB menu while booting

If your system wasn't set up to do this, you can do it by:

  • Holding Shift while booting via BIOS, or
  • Pressing Esc while booting via UEFI

2. Open the GRUB Command Prompt

Once the GRUB menu is up, press c. This should take you to the GRUB command line. I also found that in the course of continuously pressing Esc, you may end up in the GRUB command line anyway. You should see something like:

Minimal BASH-like line editing is supported. For the first word, 
TAB lists possible command completions. Anywhere else TAB lists 
possible device or file completions. ESC at any time exits.

grub> _

3. Find your root directory on your new SSD

Use ls to list the drives and partitions:

grub> ls

(proc) (hd0) (hd0,gpt2) (hd0,gpt1) (hd1) (hd1,gpt2) (hd1,gpt2)

This roughly equates to the output of an lsblk BASH command, where (hd0) would be /dev/sda, (hd0,gpt1) would be /dev/sda1, etc.

You can then use the ls command to find your root directory on the new SSD. Be sure to include the trailing / or the command will just display some info about the partition and not the files contained therein.

grub> ls (hd0,gpt2)/
lost+found/ boot/ dev/ proc/ run/ sys/ bin lib lib32 lib64 libx32 sbin etc/
home/ media/ mnt/ opt/ root/ snap/ srv/ tmp/ usr/ var/

4. Set the root directory

Once you've found root, you can set it:

grub> set root=(hd0,gpt2)

where (hd0,gpt2) is the absolute path to your root directory.

5. Get kernel and initrd image

These files are typically found in your boot directory. You'll need the file names, including kernel version, for the next step.

grub> ls /boot/
efi/ initrd.img initrd.img.old vmlinuz vmlinuz.old grub/
config-5.13.0-27-generic vmlinuz-5.13.0-27-generic memtest86+.bin
memtest86+.elf memtest86+_multiboot.bin System.map-5.13.0-27-generic
initrd.img-5.13.0-27-generic

In this case, the files I used were vmlinuz-5.13.0-27-generic and initrd.img-5.13.0-27-generic. You may also be able to use vmlinuz and initrd.img, but I have not tested that.

6. Boot

Boot your system using the new SSD with the following commands:

grub> linux /boot/vmlinuz-X.XX.X-XX-generic root=/dev/sd##
grub> initrd /boot/initrd.img-X.XX.X-XX-generic
grub> boot

where vmlinuz-X.XX.X-XX-generic and initrd.img-X.XX.X-XX-generic is the kernel version you found in the previous step and ## is the letter and number combination of the partition where your root directory is located on the new SSD. I determined this based on (hd0,gpt2) roughly equating to /dev/sda2 for me.

At this point, you should be booted onto your new SSD. In my case, I wanted to erase my old drive to use it as storage, so I was able to reformat it from the new SSD.

Sources

claypooj
  • 161
  • 3