Moving system partition and booting from it

2

I'm running a Linux Mint system on a former windows (Vista) hard drive. After a year or so of never booting the Windows, and getting space issues on the linux system partition, I decide to wipe the Windows partition (now primary partition /dev/sda1 below) and move the Linux system to it. I follow this guide, and all seems to work fine until I reboot after having moved and reconfigured grub2, the Master Boot Record and all, when the system keeps booting with the old partition. No way to make it boot from sda1.

My partition table:

image

I managed to edit the grub.cfg, /etc/fstab on the new location, update the MBR, but the system won't boot on the partition I want. No matter what I do, I always end up booting from the old one.

I must admit that not all looked perfectly like in the guide. The grub.cfg had unexpected things in it. Here's an excerpt of grub.cfg where I had to improvise. This is the original version:

if [ "$linux_gfx_mode" != "text" ]; then load_video; fi
menuentry 'Linux Mint 17.1 Cinnamon 64-bit, 3.13.0-37-generic (/dev/sda5)' --class ubuntu --class gnu-linux --class gnu --class os {
    recordfail
    gfxmode $linux_gfx_mode
    insmod gzio
    insmod part_msdos
    insmod ext2
    set root='hd0,msdos5'
    if [ x$feature_platform_search_hint = xy ]; then
      search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos5 --hint-efi=hd0,msdos5 --hint-baremetal=ahci0,msdos5  6b3cf8c6-8c6e-4c24-8f01-90276ef061c1
    else
      search --no-floppy --fs-uuid --set=root 6b3cf8c6-8c6e-4c24-8f01-90276ef061c1
    fi
    linux   /boot/vmlinuz-3.13.0-37-generic root=UUID=6b3cf8c6-8c6e-4c24-8f01-90276ef061c1 ro   quiet splash $vt_handoff
    initrd  /boot/initrd.img-3.13.0-37-generic
}

Here I replaced the UUID to the new partition as needed, but didn't quite understand how to change the root=hd0,msdos5. So didn't change it. The guide says to:

Using gedit, find and replace every "(hdX,Y)" appropriately

X and Y should be replaced based on your new partition's /dev/sdZY or /dev/hdZY, if Z is 'a' then X should be '0', if Z is 'b' then X should be '1' and so on.

I can imagine that this is because the grub was set to enable booting in Windows. There was a menu entry like this, that I removed completely in the new grub.cfg:

menuentry 'Windows 7 (loader) (on /dev/sda1)' --class windows --class os $menuentry_id_option 'osprober-chain-BE8602CA860282DF' {
    insmod part_msdos
    insmod ntfs
    set root='hd0,msdos1'
    if [ x$feature_platform_search_hint = xy ]; then
      search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1  BE8602CA860282DF
    else
      search --no-floppy --fs-uuid --set=root BE8602CA860282DF
    fi
    parttool ${root} hidden-
    chainloader +1
}

I have feeling that these hd0,msdos entries should be different, but I can't figure out what to enter.

Anyway, the system keeps booting from the old partition, I'm still out of space on the system disk and would really appreciate to find a solution! Thanks!

Max

Posted 2016-03-22T17:23:03.443

Reputation: 123

Are tou using UEFI or legacy mode for booting ? – davidgo – 2016-03-23T08:08:01.610

How can I tell? – Max – 2016-03-23T15:32:58.810

This is obviously BIOS/MBR, because no FAT partition (so no EFI System Partition, so BIOS/CSM, unless you're booting this disk from another disk...), and the extended partition indicated that it's MBR partition table. – Tom Yan – 2016-03-24T06:38:58.933

Answers

0

Truth is you can trim:

set root='hd0,msdos5'
if [ x$feature_platform_search_hint = xy ]; then
  search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos5 --hint-efi=hd0,msdos5 --hint-baremetal=ahci0,msdos5  6b3cf8c6-8c6e-4c24-8f01-90276ef061c1
else
  search --no-floppy --fs-uuid --set=root 6b3cf8c6-8c6e-4c24-8f01-90276ef061c1
fi

down to:

search --fs-uuid --set=root 6b3cf8c6-8c6e-4c24-8f01-90276ef061c1

or even alternatively:

search -u -s 6b3cf8c6-8c6e-4c24-8f01-90276ef061c1

Of course you can just change all the hd0,msdos5 to hd0,msdos1. sda5 to sda1; msdos5 to msdos1, isn't it straight-forward? FWIW, msdos here means "MSDOS partition table", which is often considered a more proper name of "MBR partition table". hd0 and ahci0 doesn't always end up to be sda in the booted system though.

But the thing you need to do before tinkering the grub.cfg is to make sure the grub boot code on the MBR (and post-MBR gap) is going to look for the grub.cfg on your desired partition. (You claimed that you updated the MBR, but I wonder what exactly you did.)

mount /dev/sda1 /mnt
grub-install --boot-directory /mnt/boot /dev/sda

And edit the grub.cfg and the fstab on it:

$EDITOR /mnt/boot/grub/grub.cfg
$EDITOR /mnt/etc/fstab

Btw, if you edit the grub.cfg, it means you should not use utility like update-grub or grub-mkconfig anymore, unless you further update your /etc/default/grub accordingly later.

However, I am not sure if you can manage to mount /dev/sda1 /mnt, since according to your gparted screenshot, both sda1 and sda5 has been mounted to / somehow. So I don't even know which /boot/grub/grub.cfg were actually being modified when you edited it. And I don't know whether it can be as simple as umount / to fix this mess. I will say you better fix everything with a live medium.

Tom Yan

Posted 2016-03-22T17:23:03.443

Reputation: 4 744

0

Of course, once you want to boot from sda1, you must change all your msdos5 instances to msdos1 at the 5'th step in the manual you reffered to. Now you have to follow the rest steps to finish.

Oleg Bolden

Posted 2016-03-22T17:23:03.443

Reputation: 1 507