-1

My laptop originally had a 128GB M.2 ssd and 1TB hdd. The system is configured as dual-boot with windows. The /boot/efi partition is on /dev/nvme0m1p1 and the original root partition is on /dev/sda3.

I zipped the image of the original nvme0n1, swapped nvme0n1 for a 1TB M.2 ssd. and cloned the original image to the new ssd. The result was that I could boot to either windows or the /dev/sd3 version of ubuntu once the cloning was complete.

I then created a new ext4 partition, nvme0n1p6 and cloned the /dev/sda3 partition to it. I did forget to change the partition UIDD after the cloning and the first time I ran update-grub2. I subsequently changed the partition UIDD using gparted, reran update-grub2 and verified that it had found the image on the new UIDD for /dev/nvme0n1p6.

After spending 6 hours finding out I had inserted a space in a UIDD= statement in the /etc/fstab of the new image I was able to boot into that new image (my proof-reading skills can stand improvement). Once that image was loaded I ran update-grub2 again in order to move the selection for the new ubuntu to the top and default in the new grub.cfg.

Finally to the issue: After rebooting the grub menu that is displayed is still the grub.cfg of the original /dev/sda3/boot/grub folder.

copying the grub.cfg generated for /nvme0n1p6 to /sda3 allows the new grub.cfg to be displayed on subsequent boots.

renaming the grub.cfg file on /sda3 causes grub to stop at the command line on reboot. Exiting the command line causes the windows os to load. I can correct the problem with a live usb image that permits me to restore a valid grub.cfg on /sda3.

I suspect that the update-grub command is not the only command I need to run. My guess is that the images stored on /nvme0n1p1 need to be updated. Is this accomplished by running a grub install of some sort?

mrh53
  • 83

2 Answers2

0

Disclaimer: I may be totally wrong.

From your information, you seem to have one installation of Windows, and one installation of Ubuntu on your hard drive (/dev/sda3). Let us call this hard drive installation H. Now, you needed to move your installation to the SSD and thus you created a new SSD partition and cloned your hard drive installation to that SSD partition (I'd rather do a fresh installation, but that is off-topic to your question). Let us call this SSD installation S.

The issue AFAIK is that you didn't install grub at all after completing installation of S. So, the installed grub in your system still belongs to installation H [1]. Thus it would still be using the grub.cfg present in installation H.

To make grub use the grub.cfg from your installation S, you will have to install grub from S to the EFI partition.

Boot up to installation S and run:

$ sudo grub-install dummy
$ sudo update-grub

Let me know if I misunderstood your scenario, or if you face errors with the commands.


References:
How does grub EFI loader find the correct boot.cfg?

  • 1
    Mukesh, you have correctly identified my configuration. I had independently run sudo grub-install when booted in the new image prior to reading your comment. This enables the correct grub.cfg to be read. However, the old image will not boot from this new configuration. Running sudo update-grub after enables all images to be booted. I will write my full sequence for swapping my nvme0 in the answer to my question for future readers. It should be up later today. – mrh53 Dec 22 '19 at 17:08
0

Now that I have ubuntu running from the new M.2 ssd I will review the the method I used to replace a 128GB SSD containing a grub-installed dual-boot loader on nvme0n1p1 with a 1TB SSD in a laptop that has one M.2 port. For clarity most of Windows 10 resides on various partitions of nvme0 and ubuntu originally resided on the hard drive partition on sda3. When booted nvme0n1p1 is mounted at /boot/efi.

  1. Make image of nvme0n1 a. I personally did not take any steps to shrink partitions in order to reduce the image size. If this is considered necessary other individuals have provided guidance on how to do so.

    b. Write image to other drive, either internal or external. I used:

    dd if=/dev/nmve0n1 | gzip -c > pathToOtherDeviceFolder/nvme0n1.img

    The -c option causes gzip to write to standard output which is then directed to the file.

  2. Test booting from USB drive containing a live image, ubuntu live or gparted live. I had problems later because I did not test the live image with the external monitors I normally use with the laptop disconnected from the laptop. It took a couple of days of trying to go through the next steps without any external display connected that it was the absence of the external display (or ethernet) that was preventing the live USB drive from booting rather than the result of the next steps. I do not recall connecting ethernet to make the booting successful but could have along with the external displays. In either case there is a dependency of the live images I do not understand but could work around. Once booted make sure you can mount the drive containing the image you wish to move.

  3. Power down and replace the original M.2 SSD with the new one.

  4. Move image to new nvme0n1

    a. Boot from USB live disk. (You tested that already)

    b. mount the drive that contains the image you wish to move. (Again, tested)

    c. move the image to the new nvme0n1. I used:

    gunzip -c pathToOtherDeviceFolder/nvme0n1.img | dd of=/dev/nvme0n1

    Again, gunzip writes to stdout which is piped to dd to write to the new device.

  5. Move ubuntu to new partition on new nvme0n1 Here I chose to reboot to the original ubuntu image on sda3. This is no problem because the new nvme0n1 is a clone of the original. I do not know of any reason why these steps could not be taken while still operating in the USB live environment, though I have no experience doing so.

    a. create new ext4 partition on nvme0n1 using gparted or other tool. I will refer to this partition as nvme0n1p6 going forward.

    b. clone ubuntu image on /dev/sda3 (in my case) onto /dev/nvme0n1p6. I used: dd if=/dev/sda3 of=/dev/nvme0n1p6

    c. after cloning use gparted or other tool to change partition UIDD of nvme0n1p6 to a unique UIDD.

  6. Prepare new on nvme0n1p6 for operation.

    a. mount /dev/nvme0n1p6. I used /mnt as the mount point.

    b. modify /etc/fstab to mount the UIDD for nvme0n1p6 as /. Note that nvme0n1p1 is still to be mounted as /boot/efi. Make sure the modified entry is properly formatted. An extra space after UIDD= cost me another several hours of wondering what I did wrong.

    c. nvme0n1p6 can be unmounted at this time but I think I omitted this step.

  7. If still executing from USB live disk, reboot to original ubuntu image ( mine is on /dev/sda3)

  8. update the grub menu options:

sudo update-grub2

Watch that the original image, Windows image and new ubuntu image on nvme0n1p6 are found and added.

  1. reboot and while at the grub boot menu select the new ubuntu image.

  2. Once in the new image run:

    a. sudo grub-install This modifies the grub files on /boot/efi (/dev/nvme0n101) to look at /dev/nvme0n1p6/boot/grub rather than that location on sda3 for the grub menu, grub.cfg.

    b. `sudo update-grub' Will replace the cloned /boot/grub/grub.cfg with a new file that places the new image on top and as default and with the original image on sda3 as an alternate selection.

You now should be able to boot into any of the three images. Note that until grub-install is run on the new image the original image cannot be removed from the machine as grub will fail to find its menu configuration file.

Hopefully, I have not omitted any steps or mis-remembered them and that this will work for you.

mrh53
  • 83