LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How to fix grub after moving root partition? (http://www.linuxquestions.org/questions/linux-newbie-8/how-to-fix-grub-after-moving-root-partition-808063/)

gandrusz 05-15-2010 06:03 PM

How to fix grub after moving root partition?
 
Hi,

Because I am using one of the new WD disks I am trying to aling my root partition with the real sectors, as described here:

http://community.wdc.com/t5/Desktop/...m-p/10920#M631

So I copied all files to a temp location, deleted my partition (/dev/sda3), recreated it a few cylinders later (same name) and copied the files to the newly created partition. But now when I try to boot, I get my old grub menu but after selecting my kernel version it hangs... Any idea how I can fix it?

brucehinrichs 05-15-2010 06:16 PM

Use a LiveCD to boot, open a terminal and type: sudo grub-install. Select where you want grub installed (probably to the MBR, but if you are dual-booting maybe to /), and reboot. If that doesn't work, post back, as there are alternative solutions. :)

zuzoa 05-15-2010 06:22 PM

Are you sure the partition was recreated as /dev/sda3? If it changed, you'll have to edit your /boot/grub/grub.conf or /boot/grub/menu.lst with the new info. Please post the contents of this file and the output of 'fdisk -l'.

gandrusz 05-15-2010 06:22 PM

Hi,

Yes, I have grub installed in MBR (because of dual boot as you suggested). I did actually run grub-install from Knoppix (sorry, should have mentioned in the initial post) and grub itself IS running fine, its just hanging after I select my configuration from the list (I haven't tried booting to Windows yet).

brucehinrichs 05-15-2010 06:26 PM

The command blkid (as root) will give you the current UUID number for that (actually all) partition. Check that number against the UUID in your /boot/grub/menu.lst file. If the numbers don't match, change the value in /boot/grub/menu.lst to the value blkid returned, then try booting again.

EDIT: If you're certain it is /dev/sda3, you can use blkid /dev/sda3 to get the UUID for that partition only.

gandrusz 05-15-2010 06:27 PM

Quote:

Originally Posted by zuzoa (Post 3970048)
Are you sure the partition was recreated as /dev/sda3? If it changed, you'll have to edit your /boot/grub/grub.conf or /boot/grub/menu.lst with the new info. Please post the contents of this file and the output of 'fdisk -l'.


knoppix@Microknoppix:~$ fdisk -l

Disk /dev/sda: 1500.3 GB, 1500301910016 bytes
255 heads, 63 sectors/track, 182401 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x24b4d5f6

Device Boot Start End Blocks Id System
/dev/sda1 1 13 102400 7 HPFS/NTFS
Partition 1 does not end on cylinder boundary.
/dev/sda2 13 25497 204696576 7 HPFS/NTFS
/dev/sda3 * 25498 37654 97642496 83 Linux
/dev/sda4 37655 182401 1162680277+ 5 Extended
/dev/sda5 37655 38870 9767488+ 82 Linux swap / Solaris
/dev/sda6 38871 182401 1152912726 83 Linux

zuzoa 05-15-2010 06:36 PM

Well it looks like your linux partition is still /dev/sda3. Can you post the contents of your /boot/grub/menu.lst (or grub.conf) file?

gandrusz 05-15-2010 06:46 PM

Quote:

Originally Posted by brucehinrichs (Post 3970056)
The command blkid (as root) will give you the current UUID number for that (actually all) partition. Check that number against the UUID in your /boot/grub/menu.lst file. If the numbers don't match, change the value in /boot/grub/menu.lst to the value blkid returned, then try booting again.

EDIT: If you're certain it is /dev/sda3, you can use blkid /dev/sda3 to get the UUID for that partition only.

The UUIDs were different indeed (I didn't find menu.lst, updated grub.cfg instead). Currently I get the following error messages:

Code:

mount: mounting /dev on /root/dev failed: No such file or directory
mount: mounting /sys on /root/sys failed: No such file or directory
mount: mounting /proc on /root/proc failed: No such file or directory
/init: line 253: can't open /root/dev/console: no such file
... Kernel Panic....


My current grub.cfg:
Code:

knoppix@Microknoppix:~$ cat /media/sda3/boot/grub/grub.cfg
#
# DO NOT EDIT THIS FILE
#
# It is automatically generated by /usr/sbin/grub-mkconfig using templates
# from /etc/grub.d and settings from /etc/default/grub
#

### BEGIN /etc/grub.d/00_header ###
if [ -s $prefix/grubenv ]; then
  load_env
fi
set default="0"
if [ ${prev_saved_entry} ]; then
  set saved_entry=${prev_saved_entry}
  save_env saved_entry
  set prev_saved_entry=
  save_env prev_saved_entry
  set boot_once=true
fi

function savedefault {
  if [ -z ${boot_once} ]; then
    saved_entry=${chosen}
    save_env saved_entry
  fi
}
insmod ext2
set root='(hd0,3)'
search --no-floppy --fs-uuid --set c2612767-032d-43a2-b414-aac0a0f7d5f5
if loadfont /usr/share/grub/unicode.pf2 ; then
  set gfxmode=640x480
  insmod gfxterm
  insmod vbe
  if terminal_output gfxterm ; then true ; else
    # For backward compatibility with versions of terminal.mod that don't
    # understand terminal_output
    terminal gfxterm
  fi
fi
insmod ext2
set root='(hd0,3)'
search --no-floppy --fs-uuid --set c2612767-032d-43a2-b414-aac0a0f7d5f5
set locale_dir=($root)/boot/grub/locale
set lang=en
insmod gettext
set timeout=5
### END /etc/grub.d/00_header ###

### BEGIN /etc/grub.d/05_debian_theme ###
insmod ext2
set root='(hd0,3)'
search --no-floppy --fs-uuid --set c2612767-032d-43a2-b414-aac0a0f7d5f5
insmod png
if background_image /boot/grub/moreblue-orbit-grub.png ; then
  set color_normal=black/black
  set color_highlight=magenta/black
else
  set menu_color_normal=cyan/blue
  set menu_color_highlight=white/blue
fi
### END /etc/grub.d/05_debian_theme ###

### BEGIN /etc/grub.d/10_linux ###
menuentry "Debian GNU/Linux, with Linux 2.6.32-trunk-686" --class debian --class gnu-linux --class gnu --class os {
        insmod ext2
        set root='(hd0,3)'
        search --no-floppy --fs-uuid --set c2612767-032d-43a2-b414-aac0a0f7d5f5
        echo        Loading Linux 2.6.32-trunk-686 ...
        linux        /boot/vmlinuz-2.6.32-trunk-686 root=UUID=c2612767-032d-43a2-b414-aac0a0f7d5f5 ro  quiet
        echo        Loading initial ramdisk ...
        initrd        /boot/initrd.img-2.6.32-trunk-686
}
menuentry "Debian GNU/Linux, with Linux 2.6.32-trunk-686 (recovery mode)" --class debian --class gnu-linux --class gnu --class os {
        insmod ext2
        set root='(hd0,3)'
        search --no-floppy --fs-uuid --set c2612767-032d-43a2-b414-aac0a0f7d5f5
        echo        Loading Linux 2.6.32-trunk-686 ...
        linux        /boot/vmlinuz-2.6.32-trunk-686 root=UUID=c2612767-032d-43a2-b414-aac0a0f7d5f5 ro single
        echo        Loading initial ramdisk ...
        initrd        /boot/initrd.img-2.6.32-trunk-686
}
menuentry "Debian GNU/Linux, with Linux 2.6.32-3-686" --class debian --class gnu-linux --class gnu --class os {
        insmod ext2
        set root='(hd0,3)'
        search --no-floppy --fs-uuid --set c2612767-032d-43a2-b414-aac0a0f7d5f5
        echo        Loading Linux 2.6.32-3-686 ...
        linux        /boot/vmlinuz-2.6.32-3-686 root=UUID=c2612767-032d-43a2-b414-aac0a0f7d5f5 ro  quiet
        echo        Loading initial ramdisk ...
        initrd        /boot/initrd.img-2.6.32-3-686
}
menuentry "Debian GNU/Linux, with Linux 2.6.32-3-686 (recovery mode)" --class debian --class gnu-linux --class gnu --class os {
        insmod ext2
        set root='(hd0,3)'
        search --no-floppy --fs-uuid --set c2612767-032d-43a2-b414-aac0a0f7d5f5
        echo        Loading Linux 2.6.32-3-686 ...
        linux        /boot/vmlinuz-2.6.32-3-686 root=UUID=c2612767-032d-43a2-b414-aac0a0f7d5f5 ro single
        echo        Loading initial ramdisk ...
        initrd        /boot/initrd.img-2.6.32-3-686
}
### END /etc/grub.d/10_linux ###

### BEGIN /etc/grub.d/11_Windows ###
menuentry ���Windows 7��� {
    insmod ntfs
    set root=(hd0,2)
    search --no-floppy --fs-uuid --set 5e5001485001287b
    chainloader +1
}
### END /etc/grub.d/11_Windows ###

### BEGIN /etc/grub.d/30_os-prober ###
menuentry "Windows 7 (loader) (on /dev/sda1)" {
        insmod ntfs
        set root='(hd0,1)'
        search --no-floppy --fs-uuid --set 5e5001485001287b
        chainloader +1
}
### END /etc/grub.d/30_os-prober ###

### BEGIN /etc/grub.d/40_custom ###
# This file provides an easy way to add custom menu entries.  Simply type the
# menu entries you want to add after this comment.  Be careful not to change
# the 'exec tail' line above.
### END /etc/grub.d/40_custom ###


zuzoa 05-15-2010 06:54 PM

Sometimes it helps to add the partition, (hd0,2), before the paths like /boot/vmlinuz and /boot/initrd, so they become "(hd0,2)/boot/vmlinuz-2.6.32-trunk-686 root=UUID=c2612767-032d-43a2-b414-aac0a0f7d5f5 ro quiet"

brucehinrichs 05-15-2010 06:57 PM

I hope this isn't it :eek:, but the filesystem may have been corrupted. From the liveCD terminal try:
Code:

e2fsck -fyv /dev/sda3
to check the filesystem.

brucehinrichs 05-15-2010 07:02 PM

@zuzoa: Does grub2 use the same naming scheme as grub legacy (/dev/sda3 = (hd0,2)) or did they change it to correspond to the /dev scheme (/dev/sda3 = (hd0,3))? I honestly don't remember, as I still use legacy.

EDIT: The reason I ask is OPs grub.cfg file says "set root='(hd0,3)'"

zuzoa 05-15-2010 07:07 PM

Quote:

Originally Posted by brucehinrichs (Post 3970084)
@zuzoa: Does grub2 use the same naming scheme as grub legacy (/dev/sda3 = (hd0,2)) or did they change it to correspond to the /dev scheme (/dev/sda3 = (hd0,3))? I honestly don't remember, as I still use legacy.

EDIT: The reason I ask is OPs grub.cfg file says "set root='(hd0,3)'"

Honestly, I'm not sure. I still use legacy as well. If one doesn't work, try the other :P I would guess it's probably the same convention to avoid confusion, but I don't know.

Edit: I just realised that this might be the cause of the problems. OP, Please change the line to "set root='(hd0,2)'" and try booting.

brucehinrichs 05-15-2010 07:14 PM

From this link:
Quote:

In other words, devices are still numbered from 0, but partitions start with 1. For example, this means that sda1 is now (hd0,1) and NOT (hd0,0) as before!
So, /dev/sda3 = (hd0,3), and zuzoa's (good) suggestion amended:
Quote:

Sometimes it helps to add the partition, (hd0,3), before the paths like /boot/vmlinuz and /boot/initrd, so they become "(hd0,3)/boot/vmlinuz-2.6.32-trunk-686 root=UUID=c2612767-032d-43a2-b414-aac0a0f7d5f5 ro quiet"

gandrusz 05-16-2010 02:20 AM

Quote:

Originally Posted by zuzoa (Post 3970085)
Honestly, I'm not sure. I still use legacy as well. If one doesn't work, try the other :P I would guess it's probably the same convention to avoid confusion, but I don't know.

Edit: I just realised that this might be the cause of the problems. OP, Please change the line to "set root='(hd0,2)'" and try booting.

Tried that and it completely doesn't work now (so I think they must have changed the convention)

gandrusz 05-16-2010 02:22 AM

Quote:

Originally Posted by brucehinrichs (Post 3970078)
I hope this isn't it :eek:, but the filesystem may have been corrupted. From the liveCD terminal try:
Code:

e2fsck -fyv /dev/sda3
to check the filesystem.

The filesystem looks alright:
Code:

root@Microknoppix:/home/knoppix# e2fsck -fyv /dev/sda3
e2fsck 1.41.9 (22-Aug-2009)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information

  307025 inodes used (5.03%)
      56 non-contiguous files (0.0%)
    240 non-contiguous directories (0.1%)
        # of inodes with ind/dind/tind blocks: 16891/186/0
 2494089 blocks used (10.22%)
      0 bad blocks
      1 large file

  239379 regular files
  25314 directories
      0 character device files
      0 block device files
      0 fifos
    411 links
  42323 symbolic links (36640 fast symbolic links)
      0 sockets
--------
  307427 files



All times are GMT -5. The time now is 11:28 PM.