PDA

View Full Version : [ubuntu] advanced grub2 question for home nas



wally.nl
June 14th, 2010, 08:38 PM
I have my DIY-nas running for a while but I'm seeing errors on sda2 which is on my bootdrive. Today I tried a disk-replacement scenario with a VM but grub2 is giving me a hard time. I'm hoping somebody has some tips for me (& other home nas enthousiast) how to make life easier.

Setup: 4x hitachi 2TB drives, this means GPT which by itself renders part of standard recovery tools useless to begin with. I installed originally with ubuntu 9.10 alternate x86 and upgraded to 10.04. Basically there's a 300MB partition on every disk (/boot on sda1, sdb1/sdc1/sdd1 are copies of that and also have bootable flag). The remainder is raid partition (md raid 5) on which lvm2 is used, so for / to be working raid and lvm must be running (you can see this in the current grub.cfg).


wally@carmen:~$ sudo parted

(parted) print list
Model: ATA Hitachi HDS72202 (scsi)
Disk /dev/sda: 2000GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt

Number Start End Size File system Name Flags
1 17.4kB 300MB 300MB ext3 boot
2 300MB 2000GB 2000GB raid

Model: ATA Hitachi HDS72202 (scsi)
Disk /dev/sdb: 2000GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt

Number Start End Size File system Name Flags
1 17.4kB 300MB 300MB ext3 boot
2 300MB 2000GB 2000GB raid

Model: ATA Hitachi HDS72202 (scsi)
Disk /dev/sdc: 2000GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt

Number Start End Size File system Name Flags
1 17.4kB 300MB 300MB ext3 boot
2 300MB 2000GB 2000GB raid

Model: ATA Hitachi HDS72202 (scsi)
Disk /dev/sdd: 2000GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt

Number Start End Size File system Name Flags
1 17.4kB 300MB 300MB ext3 primary boot
2 300MB 2000GB 2000GB primary raid

Model: Linux device-mapper (linear) (dm)
Disk /dev/mapper/vg0-lv_data: 5821GB
Sector size (logical/physical): 512B/512B
Partition Table: loop

Number Start End Size File system Flags
1 0.00B 5821GB 5821GB ext4

Error: /dev/mapper/vg0-lv_spare: unrecognised disk label

Model: Linux device-mapper (linear) (dm)
Disk /dev/mapper/vg0-lv_var: 9999MB
Sector size (logical/physical): 512B/512B
Partition Table: loop

Number Start End Size File system Flags
1 0.00B 9999MB 9999MB ext4

Model: Linux device-mapper (linear) (dm)
Disk /dev/mapper/vg0-lv_root: 50.0GB
Sector size (logical/physical): 512B/512B
Partition Table: loop

Number Start End Size File system Flags
1 0.00B 50.0GB 50.0GB ext4

Model: Linux device-mapper (linear) (dm)
Disk /dev/mapper/vg0-lv_swap: 1996MB
Sector size (logical/physical): 512B/512B
Partition Table: loop

Number Start End Size File system Flags
1 0.00B 1996MB 1996MB linux-swap(v1)

Error: /dev/md0: unrecognised disk label
--------------------------------------
wally@carmen:~$ sudo blkid
/dev/sdb1: UUID="8835ac6a-0b45-45d3-b196-7b3b41bd78f2" SEC_TYPE="ext2" TYPE="ext3"
/dev/sdc1: UUID="ce7ffa98-70fb-4f57-9a90-6a07cb622b11" SEC_TYPE="ext2" TYPE="ext3"
/dev/sdd1: UUID="953927c8-96a4-4c68-8293-c01a7d1e3b00" SEC_TYPE="ext2" TYPE="ext3"
/dev/mapper/vg0-lv_swap: TYPE="swap"
/dev/sdd2: UUID="8f964c33-cf5a-57f8-a93f-88615adc9b1f" TYPE="linux_raid_member"
/dev/sda2: UUID="8f964c33-cf5a-57f8-a93f-88615adc9b1f" TYPE="linux_raid_member"
/dev/sdb2: UUID="8f964c33-cf5a-57f8-a93f-88615adc9b1f" TYPE="linux_raid_member"
/dev/sdc2: UUID="8f964c33-cf5a-57f8-a93f-88615adc9b1f" TYPE="linux_raid_member"
/dev/sda1: UUID="20b2ac6b-9383-4b17-8e6d-bb2a442d8797" TYPE="ext3"
/dev/md0: UUID="CFApgx-oZyc-ehuc-4xSS-AirZ-6VB0-u3BnW2" TYPE="LVM2_member"
/dev/mapper/vg0-lv_root: UUID="fa5c32ea-f817-433a-aea9-693fac15b95c" TYPE="ext4"
/dev/mapper/vg0-lv_var: UUID="dd49f59c-925c-4270-b3df-0038767f7a84" TYPE="ext4"
/dev/mapper/vg0-lv_data: UUID="31f6fef8-8d01-44f4-aef5-5f97fd7847a6" TYPE="ext4"
-----------------------------------------------------------
wally@carmen:~$ cat /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
}

function recordfail {
set recordfail=1
if [ -n ${have_grubenv} ]; then if [ -z ${boot_once} ]; then save_env recordfail; fi; fi
}
insmod raid
insmod raid5rec
insmod mdraid
insmod lvm
insmod ext2
set root='(vg0-lv_root)'
search --no-floppy --fs-uuid --set fa5c32ea-f817-433a-aea9-693fac15b95c
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,1)'
search --no-floppy --fs-uuid --set 20b2ac6b-9383-4b17-8e6d-bb2a442d8797
set locale_dir=($root)/grub/locale
set lang=en
insmod gettext
if [ ${recordfail} = 1 ]; then
set timeout=-1
else
set timeout=10
fi
### END /etc/grub.d/00_header ###

### BEGIN /etc/grub.d/05_debian_theme ###
set menu_color_normal=white/black
set menu_color_highlight=black/light-gray
### END /etc/grub.d/05_debian_theme ###

### BEGIN /etc/grub.d/10_linux ###
menuentry 'Ubuntu, with Linux 2.6.32-22-generic' --class ubuntu --class gnu-linux --class gnu --class os {
recordfail
insmod ext2
set root='(hd0,1)'
search --no-floppy --fs-uuid --set 20b2ac6b-9383-4b17-8e6d-bb2a442d8797
linux /vmlinuz-2.6.32-22-generic root=/dev/mapper/vg0-lv_root ro
initrd /initrd.img-2.6.32-22-generic
}
menuentry 'Ubuntu, with Linux 2.6.32-22-generic (recovery mode)' --class ubuntu --class gnu-linux --class gnu --class os {
recordfail
insmod ext2
set root='(hd0,1)'
search --no-floppy --fs-uuid --set 20b2ac6b-9383-4b17-8e6d-bb2a442d8797
echo 'Loading Linux 2.6.32-22-generic ...'
linux /vmlinuz-2.6.32-22-generic root=/dev/mapper/vg0-lv_root ro single
echo 'Loading initial ramdisk ...'
initrd /initrd.img-2.6.32-22-generic
}
menuentry 'Ubuntu, with Linux 2.6.31-17-generic' --class ubuntu --class gnu-linux --class gnu --class os {
recordfail
insmod ext2
set root='(hd0,1)'
search --no-floppy --fs-uuid --set 20b2ac6b-9383-4b17-8e6d-bb2a442d8797
linux /vmlinuz-2.6.31-17-generic root=/dev/mapper/vg0-lv_root ro
initrd /initrd.img-2.6.31-17-generic
}
menuentry 'Ubuntu, with Linux 2.6.31-17-generic (recovery mode)' --class ubuntu --class gnu-linux --class gnu --class os {
recordfail
insmod ext2
set root='(hd0,1)'
search --no-floppy --fs-uuid --set 20b2ac6b-9383-4b17-8e6d-bb2a442d8797
echo 'Loading Linux 2.6.31-17-generic ...'
linux /vmlinuz-2.6.31-17-generic root=/dev/mapper/vg0-lv_root ro single
echo 'Loading initial ramdisk ...'
initrd /initrd.img-2.6.31-17-generic
}
menuentry 'Ubuntu, with Linux 2.6.31-16-generic' --class ubuntu --class gnu-linux --class gnu --class os {
recordfail
insmod ext2
set root='(hd0,1)'
search --no-floppy --fs-uuid --set 20b2ac6b-9383-4b17-8e6d-bb2a442d8797
linux /vmlinuz-2.6.31-16-generic root=/dev/mapper/vg0-lv_root ro
initrd /initrd.img-2.6.31-16-generic
}
menuentry 'Ubuntu, with Linux 2.6.31-16-generic (recovery mode)' --class ubuntu --class gnu-linux --class gnu --class os {
recordfail
insmod ext2
set root='(hd0,1)'
search --no-floppy --fs-uuid --set 20b2ac6b-9383-4b17-8e6d-bb2a442d8797
echo 'Loading Linux 2.6.31-16-generic ...'
linux /vmlinuz-2.6.31-16-generic root=/dev/mapper/vg0-lv_root ro single
echo 'Loading initial ramdisk ...'
initrd /initrd.img-2.6.31-16-generic
}
### END /etc/grub.d/10_linux ###

### BEGIN /etc/grub.d/20_memtest86+ ###
menuentry "Memory test (memtest86+)" {
insmod ext2
set root='(hd0,1)'
search --no-floppy --fs-uuid --set 20b2ac6b-9383-4b17-8e6d-bb2a442d8797
linux16 /memtest86+.bin
}
menuentry "Memory test (memtest86+, serial console 115200)" {
insmod ext2
set root='(hd0,1)'
search --no-floppy --fs-uuid --set 20b2ac6b-9383-4b17-8e6d-bb2a442d8797
linux16 /memtest86+.bin console=ttyS0,115200n8
}
### END /etc/grub.d/20_memtest86+ ###

### BEGIN /etc/grub.d/30_os-prober ###
if [ ${timeout} != -1 ]; then
if keystatus; then
if keystatus --shift; then
set timeout=-1
else
set timeout=0
fi
else
if sleep --interruptible 3 ; then
set timeout=0
fi
fi
fi
### 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 ###With the VM (4 x 5GB drives not using gpt so not completely identical) I tried

sudo mdadm /dev/md0 --fail /dev/sda2
sudo mdadm /dev/md0 --remove /dev/sda2
poweroff

I then removed the first drive and powered on the machine, boot failed, grub complained about 'no such device' and fell back to a grub rescue prompt.

It seems that when you remove the first drive the driveletters change (so the 'original' sdb becomes sda, sdc becomes sdb etc). and with all the guid's that are used in the config grub2 doesn't boot easily. Google worked overtime before I had the box booting again.

What I'm basically looking for is a 'more robust' setup so that if the original boot drive fails, I'm still able to boot from another drice (which was my plan to start with). I think this would be a nice first step to make drive replacement a bit less scary but I'm not sure if this can be done with grub2. In hindsight putting /boot on a usb drive maybe was a better idea, other suggestions are also welcome; I don't mind some criticism.