findgrub 3.8.2 - fixes /tmp bug in function lzmacore.
findgrub had a syntax error, as a user tried to run it in a chroot enviroment, where - I guess - /tmp was missing. Grub2 core - since version 1.99 - is lzma compressed, and findgrub needs to uncompress the core (in /tmp) in order to determine the partition (when the boot loader is installed in a VBR).
See the error here: http://forums.opensuse.org/frana-ais...ml#post2477271
Now, if /tmp doesn't exist (unlikely but not impossible), findgrub will output that:
Code:
# findgrub -v
Find Grub Version 3.8.2 - Written for openSUSE Forums
- reading MBR on disk /dev/sda ... --> Grub2 (1.99) found in sda MBR => sd?? 0x?? using core (Ubuntu)
- searching partition /dev/sda1 (FAT16) ... --> Windows NT/2K/XP Loader found in /dev/sda1
- skipping partition /dev/sda2 (FreeBSD)
- skipping partition /dev/sda3 (FreeBSD)
- reading bootsector /dev/sda4 * (Extended) ... --> Legacy GRUB found in /dev/sda4 => sda9 0x83 at offset 582502656 (openSUSE)
- skipping partition /dev/sda5 (swap)
- reading bootsector /dev/sda6 (LINUX) ...
- reading bootsector /dev/sda7 (LINUX) ...
- reading bootsector /dev/sda8 (LINUX) ...
- reading bootsector /dev/sda9 (LINUX) ... --> Legacy GRUB found in /dev/sda9 => sda9 0x83 at offset 582502656 (openSUSE)
- reading bootsector /dev/sda10 (LINUX) ... --> Grub2 (1.99) found in /dev/sda10 => sd?? 0x?? at offset 616960472 (openSUSE)
- reading bootsector /dev/sda11 (LINUX) ... --> Grub2 (1.99) found in /dev/sda11 => sd?? 0x?? at offset 655821248 (Ubuntu)
- reading bootsector /dev/sda12 (LINUX) ...
- reading bootsector /dev/sda13 (LINUX) ... --> Legacy GRUB found in /dev/sda13 => sda13 0x83 at offset 705130602 (Mandriva/ArchLinux/Debian)
- reading bootsector /dev/sda14 (LINUX) ...
- reading bootsector /dev/sda15 (LINUX) ...
- reading bootsector /dev/sda16 (LINUX) ... --> Legacy GRUB found in /dev/sda16 => sda16 0x83 at offset 784242820 (Mandriva/ArchLinux/Debian)
- reading bootsector /dev/sda17 (LINUX) ...
- reading MBR on disk /dev/sdb ... --> Legacy GRUB found in sdb MBR => sda11 0x83 using stage1.5 (openSUSE)
- searching partition /dev/sdb1 * (FAT16) ... --> Windows NT/2K/XP Loader found in /dev/sdb1
- skipping partition /dev/sdb2 (FreeBSD)
- skipping partition /dev/sdb3 (FreeBSD)
- reading bootsector /dev/sdb4 (Extended) ... --> Legacy GRUB found in /dev/sdb4 => sda9 0x83 at offset 582155312 (openSUSE)
- skipping partition /dev/sdb5 (swap)
- reading bootsector /dev/sdb6 (LINUX) ... --> Legacy GRUB found in /dev/sdb6 => sdb6 0x83 at offset 640035343 (Mandriva/ArchLinux/Debian)
- reading bootsector /dev/sdb7 (LINUX) ...
- reading bootsector /dev/sdb8 (LINUX) ...
- reading bootsector /dev/sdb9 (LINUX) ...
- reading bootsector /dev/sdb10 (LINUX) ...
- reading bootsector /dev/sdb11 (LINUX) ...
- reading bootsector /dev/sdb12 (LINUX) ...
- reading bootsector /dev/sdb13 (LINUX) ...
Press <enter> to Exit findgrub...
If /tmp exists, but for some reason, the partition number could not be determined from the core, it will output this:
Code:
# findgrub -v
Find Grub Version 3.8.2 - Written for openSUSE Forums
- reading MBR on disk /dev/sda ... --> Grub2 (1.99) found in sda MBR => sda? 0x?? using core (Ubuntu)
- searching partition /dev/sda1 (FAT16) ... --> Windows NT/2K/XP Loader found in /dev/sda1
- skipping partition /dev/sda2 (FreeBSD)
- skipping partition /dev/sda3 (FreeBSD)
- reading bootsector /dev/sda4 * (Extended) ... --> Legacy GRUB found in /dev/sda4 => sda9 0x83 at offset 582502656 (openSUSE)
- skipping partition /dev/sda5 (swap)
- reading bootsector /dev/sda6 (LINUX) ...
- reading bootsector /dev/sda7 (LINUX) ...
- reading bootsector /dev/sda8 (LINUX) ...
- reading bootsector /dev/sda9 (LINUX) ... --> Legacy GRUB found in /dev/sda9 => sda9 0x83 at offset 582502656 (openSUSE)
- reading bootsector /dev/sda10 (LINUX) ... --> Grub2 (1.99) found in /dev/sda10 => sda? 0x?? at offset 616960472 (openSUSE)
- reading bootsector /dev/sda11 (LINUX) ... --> Grub2 (1.99) found in /dev/sda11 => sda? 0x?? at offset 655821248 (Ubuntu)
- reading bootsector /dev/sda12 (LINUX) ...
- reading bootsector /dev/sda13 (LINUX) ... --> Legacy GRUB found in /dev/sda13 => sda13 0x83 at offset 705130602 (Mandriva/ArchLinux/Debian)
- reading bootsector /dev/sda14 (LINUX) ...
- reading bootsector /dev/sda15 (LINUX) ...
- reading bootsector /dev/sda16 (LINUX) ... --> Legacy GRUB found in /dev/sda16 => sda16 0x83 at offset 784242820 (Mandriva/ArchLinux/Debian)
- reading bootsector /dev/sda17 (LINUX) ...
- reading MBR on disk /dev/sdb ... --> Legacy GRUB found in sdb MBR => sda11 0x83 using stage1.5 (openSUSE)
- searching partition /dev/sdb1 * (FAT16) ... --> Windows NT/2K/XP Loader found in /dev/sdb1
- skipping partition /dev/sdb2 (FreeBSD)
- skipping partition /dev/sdb3 (FreeBSD)
- reading bootsector /dev/sdb4 (Extended) ... --> Legacy GRUB found in /dev/sdb4 => sda9 0x83 at offset 582155312 (openSUSE)
- skipping partition /dev/sdb5 (swap)
- reading bootsector /dev/sdb6 (LINUX) ... --> Legacy GRUB found in /dev/sdb6 => sdb6 0x83 at offset 640035343 (Mandriva/ArchLinux/Debian)
- reading bootsector /dev/sdb7 (LINUX) ...
- reading bootsector /dev/sdb8 (LINUX) ...
- reading bootsector /dev/sdb9 (LINUX) ...
- reading bootsector /dev/sdb10 (LINUX) ...
- reading bootsector /dev/sdb11 (LINUX) ...
- reading bootsector /dev/sdb12 (LINUX) ...
- reading bootsector /dev/sdb13 (LINUX) ...
Press <enter> to Exit findgrub...
Here's the diff of 3.8.1 vs 3.8.2:
Code:
--- findgrub-3.8.1 2012-07-31 07:59:26.283391290 -0700
+++ findgrub 2012-07-31 09:08:49.740582460 -0700
@@ -2,9 +2,9 @@
#: Title : findgrub
#: Date Created : Wed Sep 29 20:02:40 CDT 2010
-#: Last Edit : Thu Jun 21 00:05:52 PDT 2012
+#: Last Edit : Tue Jul 31 08:17:01 PDT 2012
#: Author : please_try_again & edited by j McDaniel
-#: Version : 3.8.1
+#: Version : 3.8.2
#: Description : Locates the Grub Boot Loader & Windows BootLoader, Creates Grub Menu.Lst Entries
#: Options : -h | --help, -w | -- writemenu, -k | --kernel, -a | --activate, -s | --coresize, -d | --debug, -m | --map
@@ -21,7 +21,7 @@
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# current version
-version="3.8.1"
+version="3.8.2"
# default mountpoint
mnt=/mnt
@@ -347,21 +347,29 @@
function lzmacore {
# part of this code was borrowed from Boot Info Script: http://bootinfoscript.sourceforge.net
- core=/tmp/core.img ; ucore=/tmp/ucore.img ; clog=/tmp/ulog
- dd if=$1 of=$core skip=$2 count=1024 2>/dev/null
- eval $(hexdump -v -s 520 -n 7 -e '1/4 "m=%u; " 1/4 "k=%u;"' $core)
- lzpos=$(($(hexdump -v -n $k -e '1/1 "%02x"' /tmp/core.img | grep -bo 'd1e9dffeffff0000' | sed 's/:.*//')/2+8))
- if [ $lzpos -gt 0 ] ; then
- [ $(hexdump -v -s ${lzpos} -n 8 -e '1/1 "%02x"' $core) = '0000000000000000' ] && lzpos=$(( $lzpos + 8 ))
- lzusize=$(( $m + $k - $lzpos + 512 ))
- printf '\x5d\x00\x00\x01\x00'$(printf '%08x' $((512 - $lzpos)) | awk '{printf "\\x%s\\x%s\\x%s\\x%s", substr($0,7,2), substr($0,5,2), substr($0,3,2), substr($0,1,2)}')'\x00\x00\x00\x00' > $clog
- dd if=$core bs=$lzpos skip=1 count=$(($lzusize/$lzpos + 1)) 2> /dev/null | cat $clog - | $unlzma > $ucore 2>/dev/null
- p=$(hexdump -v -s 7 -n 8 -e '"%_c"' $ucore | sed 's|)/boot.*||')
- echo ${!h}$p $lzusize
+ tmpdir=${TMPDIR:-/tmp}
+ if [ -d $tmpdir ] ; then
+ core=$tmpdir/core.img ; ucore=$tmpdir/ucore.img ; clog=$tmpdir/ulog
+ dd if=$1 of=$core skip=$2 count=1024 2>/dev/null
+ eval $(hexdump -v -s 520 -n 7 -e '1/4 "m=%u; " 1/4 "k=%u;"' $core)
+ l=$(hexdump -v -n $k -e '1/1 "%02x"' $core | grep -bo 'd1e9dffeffff0000' | sed 's/:.*//')
+ [ "$l" ] && l=$(($l*1)) || l=0; l=0
+ lzpos=$(($l/2+8))
+ if [ $lzpos -gt 0 ] ; then
+ [ $(hexdump -v -s ${lzpos} -n 8 -e '1/1 "%02x"' $core) = '0000000000000000' ] && lzpos=$(( $lzpos + 8 ))
+ lzusize=$(( $m + $k - $lzpos + 512 ))
+ printf '\x5d\x00\x00\x01\x00'$(printf '%08x' $((512 - $lzpos)) | awk '{printf "\\x%s\\x%s\\x%s\\x%s", substr($0,7,2), substr($0,5,2), substr($0,3,2), substr($0,1,2)}')'\x00\x00\x00\x00' > $clog
+ dd if=$core bs=$lzpos skip=1 count=$(($lzusize/$lzpos + 1)) 2> /dev/null | cat $clog - | $unlzma > $ucore 2>/dev/null
+ p=$(hexdump -v -s 7 -n 8 -e '"%_c"' $ucore | sed 's|)/boot.*||')
+ [ "$p" ] || p="?"
+ echo ${!h}$p $lzusize
+ else
+ echo "sd??"
+ fi
+ rm -f $core $ucore $clog
else
echo "sd??"
fi
- rm -f $core $ucore $clog
}
function coreimg {
findgrub 3.8.2 is available here: http://www.unixversal.com/linux/openSUSE/findgrub-3.8.2.tgz
I haven't include it in updagrub yet. Maybe I won't, since I'm planning to add a new feature in the next version pretty soon.
Bookmarks