RAID1 and grub - again

Darshaka Pathirana dpat at syn-net.org
Sun Jan 31 23:48:36 CET 2010


On 01/28/2010 09:06 PM, Cristian Ionescu-Idbohrn wrote:
> On Thu, 28 Jan 2010, Darshaka Pathirana wrote:
> 
>> diff -r 282adc0454ed class/50-host-classes
>> --- a/class/50-host-classes     Mon Jan 25 12:38:32 2010 +0100
>> +++ b/class/50-host-classes     Thu Jan 28 18:27:11 2010 +0100
>> @@ -29,5 +29,5 @@
>>         echo "FAIBASE DHCPC" ;;
>>  esac
>>
>> -(ifclass I386 || ifclass AMD64) && echo GRUB
>> +(ifclass I386 || ifclass AMD64) && [ ! ifclass GRUB_PC ] && echo GRUB
> 
> To avoid forking a subshell and getting a syntax error, I think you want
> to use this instead:
> 
> { ifclass I386 || ifclass AMD64; } && ! ifclass GRUB_PC && echo GRUB
> 
>> diff -r 282adc0454ed scripts/GRUB_PC/10-setup
>> --- a/scripts/GRUB_PC/10-setup  Mon Jan 25 12:38:32 2010 +0100
>> +++ b/scripts/GRUB_PC/10-setup  Thu Jan 28 18:27:11 2010 +0100
>> @@ -3,7 +3,11 @@
>>  error=0 ; trap "error=$((error|1))" ERR
>>
>>  $ROOTCMD grub-mkdevicemap -n -m /boot/grub/device.map
>> -$ROOTCMD grub-mkconfig -o /boot/grub/grub.cfg
>> -$ROOTCMD grub-install --no-floppy "(hd0)"
>> +$ROOTCMD update-grub
>> +
>> +for device in $(echo $BOOT_DEVICE); do
> 
> To avoid forking a subshell, I think you want to use this instead:
> 
> for device in $BOOT_DEVICE; do

Thanks for pointing out. Here my update then. Hope it's better:


diff -r 282adc0454ed class/50-host-classes
--- a/class/50-host-classes     Mon Jan 25 12:38:32 2010 +0100
+++ b/class/50-host-classes     Sun Jan 31 23:42:02 2010 +0100
@@ -29,5 +29,4 @@
        echo "FAIBASE DHCPC" ;;
 esac
 
-(ifclass I386 || ifclass AMD64) && echo GRUB 
 exit 0
diff -r 282adc0454ed class/51-grub
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/class/51-grub     Sun Jan 31 23:42:02 2010 +0100
@@ -0,0 +1,4 @@
+#! /bin/bash
+
+{ ifclass I386 || ifclass AMD64; } && ! ifclass GRUB_PC && echo GRUB 
+exit 0
diff -r 282adc0454ed scripts/GRUB_PC/10-setup
--- a/scripts/GRUB_PC/10-setup  Mon Jan 25 12:38:32 2010 +0100
+++ b/scripts/GRUB_PC/10-setup  Sun Jan 31 23:42:02 2010 +0100
@@ -3,7 +3,12 @@
 error=0 ; trap "error=$((error|1))" ERR
 
 $ROOTCMD grub-mkdevicemap -n -m /boot/grub/device.map
-$ROOTCMD grub-mkconfig -o /boot/grub/grub.cfg
-$ROOTCMD grub-install --no-floppy "(hd0)"
+$ROOTCMD update-grub 
+
+for device in $BOOT_DEVICE; do
+       GROOT=$(device2grub $device)
+       [ -z $GROOT ] && exit 1
+       $ROOTCMD grub-install --no-floppy "$GROOT"
+done
 
 exit $error

Please note that I had to add "51-grub" to check for GRUB / GRUB_PC
because testing for GRUB_PC in "50-host-classes" does not work (if you
add GRUB_PC to any of your machines in there) as the classes are only
added and detected by ifclass after the script has terminated.

> There's no error check here:
> 
>> +       GROOT=$(device2grub $device)
> 
> so you may end up executing:
> 
>> +       $ROOTCMD grub-install --no-floppy "$GROOT"
> 
> with an empty 3rd argument (1st grub-install argument), which will produce
> an error (which is not handled).

I checked the sample-scripts but could not find an example on how to
handle such an error. So I did a "exit 1" if no grub-device can be
made up. Is that ok?

Greetings,
 - Darsha



More information about the linux-fai mailing list