Page 17 of 27 FirstFirst ... 71516171819 ... LastLast
Results 161 to 170 of 263

Thread: Looking for Grub and Windows bootloader in all partitions.

  1. #161
    jdmcdaniel3's Avatar
    jdmcdaniel3 is online now Global Moderator
    Join Date
    Mar 2010
    Location
    Austin - Texas
    Posts
    9,348
    Blog Entries
    46

    Thumbs up Re: Looking for Grub and Windows bootloader in all partitions.

    Yes, findgrub 3.7.2 is working great here. Here is a listing on my backup PC:

    Code:
    Find Grub Version 3.7.2 - Written for openSUSE Forums
    
     - reading MBR on disk /dev/sda                       ... --> SUSE Generic MBR (Sig: 0xff40c)
     - reading bootsector  /dev/sda1   *  (LINUX)         ... --> Legacy GRUB  found in /dev/sda1   => sda1   0x83 (openSUSE)
    
     - reading MBR on disk /dev/sdb                       ... --> Windows Generic MBR (Sig: 0xdbb32d12)
     - searching partition /dev/sdb1   *  (NTFS)          ... --> Windows7/Vista Loader found in /dev/sdb1
    
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    You can add the following entry to /boot/grub/menu.lst :
    
    ###Don't change this comment - YaST2 identifier: Original name: WindowsBootLoader###
    title Windows on /dev/sdb1
        rootnoverify (hd1,0)
        map (hd1) (hd0)
        map (hd0) (hd1)
        chainloader +1
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
     - skipping partition  /dev/sdb2      (swap)         
     - reading bootsector  /dev/sdb3      (LINUX)         ...
    
     - reading MBR on disk /dev/sdc                       ... --> SUSE Generic MBR (Sig: 0xb4540b)
     - searching partition /dev/sdc1   *  (NTFS)          ...
    
     - reading MBR on disk /dev/sde                       ... --> Windows Generic MBR (Sig: 0x68c84a40)
     - searching partition /dev/sde1      (NTFS)          ...
    Great work please_try_again!!!!

    Thank You,
    My Blog: https://forums.opensuse.org/blogs/jdmcdaniel3/

    Software efficiency halves every 18 months, thus compensating for Moore's Law

    Its James again from Austin, Texas

  2. #162
    please_try_again is offline Flux Capacitor Penguin
    Join Date
    Sep 2008
    Posts
    9,385

    Default Re: Looking for Grub and Windows bootloader in all partitions.

    findgrub 3.8

    This new findgrub version optionally displays the sector number (offset) where Grub is looking for the next stage - when it is not using stage1.5 (Legacy) or embedded core (Grub2). Since the output will become wider - and is only interesting in certain cases - I made this feature optional. It is invoked with the option -v (or --verbose).

    In the following example, the machine has both Legacy Grub and Grub2 under openSUSE 12.1 in sda9 and sda10 VBRs, looking for the next stage in sda9, where /boot is located (not on a separate partition. sda9 is just 12.1 root partition).

    Code:
    # findgrub -v
    
    Find Grub Version 3.8 - Written for openSUSE Forums
    
     - reading MBR on disk /dev/sda                       ... --> Grub2 (1.99) found in sda MBR     => sda6   0x83 using core (Ubuntu/Mint)
     - 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  => sda9   0x83 at offset 616960472 (openSUSE)
     - reading bootsector  /dev/sda11     (LINUX)         ... --> Grub2 (1.99) found in /dev/sda11  => sda11  0x83 at offset 655821248 (Ubuntu/Mint)
     - 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...
    What are 582502656 and 616960472 in this example, where both Legacy and Grub2 boot loaders are looking for openSUSE on sda9?

    582502656 is the offset (the LBA sector on disk) of /boot/grub/stage2 and 616960472 the offset of /boot/grub2/core.img. This value is written in the boot loader when you install Grub in a partition boot sector (VBR).

    Reading sector 582502656 or the first 512 bytes of /boot/grub/stage2 show the same thing. I'll use the strings command here to filter the output, since the rest is not human readable.

    Code:
    # dd if=/dev/sda skip=582502656 bs=512 count=1 2>/dev/null | strings
    pPf1
    Loading stage2
    Geom
    Read
     Error
    
    # dd if=/boot/grub/stage2 bs=512 count=1 2>/dev/null | strings
    pPf1
    Loading stage2
    Geom
    Read
     Error
    Looks familiar, eh?
    Similarly sector 616960472 contains the first 512 bytes of /boot/grub2/core.img:

    Code:
    # dd if=/dev/sda skip=616960472 bs=512 count=1 2>/dev/null |strings
    loading
    Geom
    Read
     Error
    
    # dd if=/boot/grub2/core.img  bs=512 count=1 2>/dev/null | strings
    loading
    Geom
    Read
     Error

    Looks a little bit less familiar (there is no mention of stage2, and it is called "core" under Grub2) ... but when you see the words "loading" and "Error" not far from each other within the same sector, you can assume that you have to deal with a boot loader.

    This example should also demonstrate (at least I hope so) that booting from MBR is more reliable - as far as Linux is concerned.

    When Grub (either Legacy or Grub2) is installed in MBR, it doesn't use blocklists to look for the next stage. In fact, the boot loader has the value "1" instead of stage2's offset (or "core" in Grub2's terminology) - which findgrub will translate into "using stage 1.5" or "using core" - and it uses stage1.5 (Legacy Grub) or its embedded core (Grub2) to find the boot menu on the filesystem, among other things.

    When Grub (either Legacy or Grub2) is installed in a partition and stage2 (Legacy) or core.img (Grub2) "physical" position has changed - because you move it and copied it back, you cloned a partition but not the entire disk, you experienced a brutal fsck or after an adventurous repartitioning, it won't boot anymore. You might not even get an error message (Grub's error messages have to be read from somewhere) but probably just a blinking hyphen.

    findgrub 3.8 is include in updategrub-1.8.2 in my repo and available here: http://www.unixversal.com/linux/openSUSE/findgrub-3.8.tgz


  3. #163
    please_try_again is offline Flux Capacitor Penguin
    Join Date
    Sep 2008
    Posts
    9,385

    Default Re: Looking for Grub and Windows bootloader in all partitions.

    There have been changes (including some regressions which I was told won't be fixed) in latest udev and util-linux. On the 3 ArchLinux systems I have, the /dev/disk/by-path symlinks are missing now. I take it that udev doesn't generate them anymore. In any case, it breaks findgrub when it tries to figure out BIOS devices on systems without a device.map. Thus I had to find another way. In this new version, I use the value of DEVPATH given by udev, which is not the same as the by-path symlink. by-path symlinks will still be displayed if they exist in the output of findgrub -M (and findgrub -m), but they're not relevant anymore and won't cause an error if they are missing. See the differences between findgrub 3.8 and 3.8.1 below:

    Code:
    # findgrub -M
    Find Grub Version 3.8 - Written for openSUSE Forums
    
    --- DEVICE.MAP: sda is ata drive hd0
    --- DEVICE.MAP: looking for /dev/sda in /boot/grub/device.map:
    --- DEVICE.MAP: - /dev/sda
    --- DEVICE.MAP: - /dev/disk/by-id/ata-WDC_WD5000AAKS-00A7B2_WD-WCASY8019640 -> hd0
    --- DEVICE.MAP: - /dev/disk/by-id/scsi-SATA_WDC_WD5000AAKS-_WD-WCASY8019640
    --- DEVICE.MAP: - /dev/disk/by-id/wwn-0x50014ee258d6c850
    --- DEVICE.MAP: - /dev/disk/by-path/pci-0000:00:1f.2-scsi-0:0:0:0
    --- DEVICE.MAP: => sda - found in device.map - is now hd0
    --- DEVICE.MAP:
    --- DEVICE.MAP: sdb is ata drive hd1
    --- DEVICE.MAP: looking for /dev/sdb in /boot/grub/device.map:
    --- DEVICE.MAP: - /dev/sdb
    --- DEVICE.MAP: - /dev/disk/by-id/ata-WDC_WD5000AAKS-00A7B0_WD-WMASY6644220 -> hd1
    --- DEVICE.MAP: - /dev/disk/by-id/scsi-SATA_WDC_WD5000AAKS-_WD-WMASY6644220
    --- DEVICE.MAP: - /dev/disk/by-id/wwn-0x50014ee0abc70c92
    --- DEVICE.MAP: - /dev/disk/by-path/pci-0000:00:1f.2-scsi-1:0:0:0
    --- DEVICE.MAP: => sdb - found in device.map - is now hd1
    --- DEVICE.MAP:
    ********************************************************************************
    
    
    # findgrub -M
    Find Grub Version 3.8.1 - Written for openSUSE Forums
    
    --- DEVICE.MAP: sda is ata drive hd0
    --- DEVICE.MAP: looking for /dev/sda in /boot/grub/device.map:
    --- DEVICE.MAP: - /dev/sda
    --- DEVICE.MAP: - /devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda
    --- DEVICE.MAP: - /dev/disk/by-id/ata-WDC_WD5000AAKS-00A7B2_WD-WCASY8019640 -> hd0
    --- DEVICE.MAP: - /dev/disk/by-id/scsi-SATA_WDC_WD5000AAKS-_WD-WCASY8019640
    --- DEVICE.MAP: - /dev/disk/by-path/pci-0000:00:1f.2-scsi-0:0:0:0
    --- DEVICE.MAP: - /dev/disk/by-id/wwn-0x50014ee258d6c850
    --- DEVICE.MAP: => sda - found in device.map - is now hd0
    --- DEVICE.MAP:
    --- DEVICE.MAP: sdb is ata drive hd1
    --- DEVICE.MAP: looking for /dev/sdb in /boot/grub/device.map:
    --- DEVICE.MAP: - /dev/sdb
    --- DEVICE.MAP: - /devices/pci0000:00/0000:00:1f.2/host1/target1:0:0/1:0:0:0/block/sdb
    --- DEVICE.MAP: - /dev/disk/by-id/ata-WDC_WD5000AAKS-00A7B0_WD-WMASY6644220 -> hd1
    --- DEVICE.MAP: - /dev/disk/by-id/scsi-SATA_WDC_WD5000AAKS-_WD-WMASY6644220
    --- DEVICE.MAP: - /dev/disk/by-path/pci-0000:00:1f.2-scsi-1:0:0:0
    --- DEVICE.MAP: - /dev/disk/by-id/wwn-0x50014ee0abc70c92
    --- DEVICE.MAP: => sdb - found in device.map - is now hd1
    --- DEVICE.MAP:
    ********************************************************************************
    Targets are not necessarely 0 and 1. I've seen for example 2,4,6, etc. too. findgrub just sorts the entries and number them starting at 0. I don't know how reliable this new method is. But It doesn't seem less reliable than the other one, which used by-path symlinks. It is only needed if you don't have device.map, which is rarely the case under openSUSE, since a device.map is always created when you install the system.

    findgrub 3.8.1 is included in updategrub-1.8.2-114.1 in my repo and available here: http://www.unixversal.com/linux/openSUSE/findgrub-3.8.1.tgz

  4. #164
    please_try_again is offline Flux Capacitor Penguin
    Join Date
    Sep 2008
    Posts
    9,385

    Default Re: Looking for Grub and Windows bootloader in all partitions.

    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.

  5. #165
    please_try_again is offline Flux Capacitor Penguin
    Join Date
    Sep 2008
    Posts
    9,385

    Default Re: Looking for Grub and Windows bootloader in all partitions.

    findgrub/cfindgrub 4.0 brings a new option -c (or --core). In addition to the offset (absolute sector) of stage2/core which option -v reads from the boot loader, option -c determines the inode on the files sytem which contains this sector and the path of the file which starts at this inode. It will obviously always be stage2 for legacy Grub and core.img fro Grub2 ... but you might also have suprises (see sdb4 entry on the picture below).



    This option might take a few seconds, as it uses tune2fs and debugfs. It will only work for ext2/3/4 fs. You don't want to use it on a daily basis to check the health of your ssd drive.

    findgrub 4.0 is included in updategrub in my repo and available here: http://www.unixversal.com/linux/openSUSE/findgrub-4.0.tgz

  6. #166
    jdmcdaniel3's Avatar
    jdmcdaniel3 is online now Global Moderator
    Join Date
    Mar 2010
    Location
    Austin - Texas
    Posts
    9,348
    Blog Entries
    46

    Smile Re: Looking for Grub and Windows bootloader in all partitions.

    This is great stuff please_try_again. For anyone that might like to have an application icon that would run FindGrub in the default display mode, here is an icon file you could create. First, After extraction of findgrub, I placed the bash script into the folder /usr/local/bin (as root), which is in your default application path. Next, copy the text from the code block below and save it in the folder /usr/share/applications with the file name FindGrub.desktop as root.

    Code:
    In KDE do Alt-F2: kdesu kwrite /usr/share/applications/FindGrub.desktop
    Code:
    [Desktop Entry]
    Comment[en_US]=
    Comment=
    Exec=/usr/local/bin/findgrub
    GenericName[en_US]=Drive Partition and Booting Detection Utility
    GenericName=Drive Partition and Booting Detection Utility
    Icon=yast-disk
    MimeType=
    Name[en_US]=FindGrub
    Name=FindGrub
    Path=
    StartupNotify=true
    Terminal=true
    TerminalOptions=
    Type=Application
    X-DBUS-ServiceName=
    X-DBUS-StartupType=none
    X-KDE-SubstituteUID=false
    X-KDE-Username=
    X-SuSE-translate=true
    You need to mark the icon file executable and from terminal use the command:

    Code:
    sudo chmod +x /usr/share/applications/FindGrub.desktop
    Now, if you open up the KDE menu, you will see /menu/Applications/FindGrub as a program option. You could also copy the icon to your $HOME/Desktop to have the icon usable there as well. I might also suggest you could modify the root detection section to clear the screen on startup. It makes for a cleaner display though in your example you would not see the command used to start FindGrub. For those of us not running FindGrub as a root user, the password request will be left at the top of the screen. Here is this simple addition:

    Code:
    #
    # Check to see if we are root
    #
    if [[ $UID -ne 0 ]]; then
      id -Gn | grep -q wheel || echo "Root User Permissions are required, Please Enter the ..."
      echo
      sudo $0 $1
      exit 0
    else
      clear
    fi
    As another question, have you ever thought of having just one version of FindGrub and having a color Enable/Disable at the top? A while ago, I decided to switch to using the very same escape color sequence as you. But I wrote a function block that emulates the tput color commands. Here is that function block I have been using.

    Code:
    # *****************************************************************************
    #                 Do you want to see XXXXX in color?  
    #             The default is true, but can be set to false 
    #           New Escape Sequences work without a Desktop loaded 
    # *****************************************************************************
    
    use_color=true
    
    # *****************************************************************************
    # Color Display Request - color foreground background [b/n] 
    #
    # 0:Black  1:Blue  2:Green  3:Cyan  4:Red  5:Magenta  6:Yellow  7:White
    #
    # Example: color 7 0 B 
    #
    # where foreground is white (7), background is black (0) and text is in bold (B)
    #                           $1                       $2                      $3
    # *****************************************************************************
    
    function color {
      if $use_color ; then
        if [[ $3 == [Bb] ]] ; then
          case "$1" in
            "0") echo -ne '\E[1;30m' ;;
            "1") echo -ne '\E[1;34m' ;;
            "2") echo -ne '\E[1;32m' ;;
            "3") echo -ne '\E[1;36m' ;;
            "4") echo -ne '\E[1;31m' ;;
            "5") echo -ne '\E[1;35m' ;;
            "6") echo -ne '\E[1;33m' ;;
            "7") echo -ne '\E[1;37m' ;;
            *) echo -ne '\E[1;37m' ;;
          esac
        else
          case "$1" in
            "0") echo -ne '\E[30m' ;;
            "1") echo -ne '\E[34m' ;;
            "2") echo -ne '\E[32m' ;;
            "3") echo -ne '\E[36m' ;;
            "4") echo -ne '\E[31m' ;;
            "5") echo -ne '\E[35m' ;;
            "6") echo -ne '\E[33m' ;;
            "7") echo -ne '\E[37m' ;;
            *) echo -ne '\E[37m' ;;
          esac
        fi
        case "$2" in
          "0") echo -ne '\E[40m' ;;
          "1") echo -ne '\E[44m' ;;
          "2") echo -ne '\E[42m' ;;
          "3") echo -ne '\E[46m' ;;
          "4") echo -ne '\E[41m' ;;
          "5") echo -ne '\E[45m' ;;
          "6") echo -ne '\E[43m' ;;
          "7") echo -ne '\E[47m' ;;
          *) echo -ne '\E[40m' ;;
        esac
      else
        echo -ne '\E[37;40m' 
      fi
      if [[ $3 == [Nn] ]] ; then
        tput sgr0
      fi
      return 0
    }
    It might be a pain to use at first, but after that, you only have one version of FindGrub to use. Its funny to make suggestions to you since you know so much about bash scripting. Anyone that programs has their own idea of what is important and what is not which causes us to go down a different path. But, do consider I find your work important and useful and only wish to help.

    Keep up the GREAT work with FindGrub!!!!

    Thank You,
    Last edited by jdmcdaniel3; 25-Aug-2012 at 07:48.
    My Blog: https://forums.opensuse.org/blogs/jdmcdaniel3/

    Software efficiency halves every 18 months, thus compensating for Moore's Law

    Its James again from Austin, Texas

  7. #167
    please_try_again is offline Flux Capacitor Penguin
    Join Date
    Sep 2008
    Posts
    9,385

    Default Re: Looking for Grub and Windows bootloader in all partitions.

    Quote Originally Posted by jdmcdaniel3 View Post
    As another question, have you ever thought of having just one version of FindGrub and having a color Enable/Disable at the top?
    Early versions of findgrub had a COLOR flag. At some point the code became so complicated that I had to focus on other things. Now that you remind me that it would be better to have only one script - which I agree with - I merged findgrub and cfindgrub and restore this feature ... but the script is now more unreadable than ever. Who's going to do the code review?

    All right, let's say that cfindgrub has reached EOL. findgrub will now use color output by default. Use the option -n ( --nocolor) to disable it. Users should be advised to use this option before posting here.

    findgrub 4.1 is available here: http://www.unixversal.com/linux/openSUSE/findgrub-4.1.tgz

    Quote Originally Posted by jdmcdaniel3 View Post
    A while ago, I decided to switch to using the very same escape color sequence as you. But I wrote a function block that emulates the tput color commands. Here is that function block I have been using.

    Code:
    # *****************************************************************************
    #                 Do you want to see XXXXX in color?  
    #             The default is true, but can be set to false 
    #           New Escape Sequences work without a Desktop loaded 
    # *****************************************************************************
    
    use_color=true
    
    # *****************************************************************************
    # Color Display Request - color foreground background [b/n] 
    #
    # 0:Black  1:Blue  2:Green  3:Cyan  4:Red  5:Magenta  6:Yellow  7:White
    #
    # Example: color 7 0 B 
    #
    # where foreground is white (7), background is black (0) and text is in bold (B)
    #                           $1                       $2                      $3
    # *****************************************************************************
    
    function color {
      if $use_color ; then
        if [[ $3 == [Bb] ]] ; then
          case "$1" in
            "0") echo -ne '\E[1;30m' ;;
            "1") echo -ne '\E[1;34m' ;;
            "2") echo -ne '\E[1;32m' ;;
            "3") echo -ne '\E[1;36m' ;;
            "4") echo -ne '\E[1;31m' ;;
            "5") echo -ne '\E[1;35m' ;;
            "6") echo -ne '\E[1;33m' ;;
            "7") echo -ne '\E[1;37m' ;;
            *) echo -ne '\E[1;37m' ;;
          esac
        else
          case "$1" in
            "0") echo -ne '\E[30m' ;;
            "1") echo -ne '\E[34m' ;;
            "2") echo -ne '\E[32m' ;;
            "3") echo -ne '\E[36m' ;;
            "4") echo -ne '\E[31m' ;;
            "5") echo -ne '\E[35m' ;;
            "6") echo -ne '\E[33m' ;;
            "7") echo -ne '\E[37m' ;;
            *) echo -ne '\E[37m' ;;
          esac
        fi
        case "$2" in
          "0") echo -ne '\E[40m' ;;
          "1") echo -ne '\E[44m' ;;
          "2") echo -ne '\E[42m' ;;
          "3") echo -ne '\E[46m' ;;
          "4") echo -ne '\E[41m' ;;
          "5") echo -ne '\E[45m' ;;
          "6") echo -ne '\E[43m' ;;
          "7") echo -ne '\E[47m' ;;
          *) echo -ne '\E[40m' ;;
        esac
      else
        echo -ne '\E[37;40m' 
      fi
      if [[ $3 == [Nn] ]] ; then
        tput sgr0
      fi
      return 0
    }
    If you use colors in printf strings (but not in printf variables) you can use the octal value \033 instead od the escape character. It is more portable and more "transportable". There is not much you can do with echo. How about using printf to format output? Leave "echo" to those old DOS batch files!

    Actually the trick is to put color stuff in printf variables* and unset all variables based on the value of a NOCOLOR flag for example. That's how I did. findgrub 4.1 is only 66 characters longer than cfindgrub 4.0.

    * But you have to use either escape character or $(tput ...).

  8. #168
    jdmcdaniel3's Avatar
    jdmcdaniel3 is online now Global Moderator
    Join Date
    Mar 2010
    Location
    Austin - Texas
    Posts
    9,348
    Blog Entries
    46

    Default Re: Looking for Grub and Windows bootloader in all partitions.

    I feel it is the right choice please_try_again to maintain only one script version, to default using color and have an option for no color. I have thought of switching to printf myself, but my scripts work fine in openSUSE and it could be a task I might save for the future as another "improvement" I could unleash on the openSUSE community.

    Thank You,
    My Blog: https://forums.opensuse.org/blogs/jdmcdaniel3/

    Software efficiency halves every 18 months, thus compensating for Moore's Law

    Its James again from Austin, Texas

  9. #169
    please_try_again is offline Flux Capacitor Penguin
    Join Date
    Sep 2008
    Posts
    9,385

    Default Re: Looking for Grub and Windows bootloader in all partitions.

    findgrub 4.2 is able to identify Grub2 v 2.00. However it still can not find core.img (Remember that findgrub does NOT and should not use os-prober nor mount Linux partitions). Little progress though.

    http://www.unixversal.com/linux/openSUSE/findgrub-4.2.tgz

    findgrub 4.1 vs findgrub 4.2

    Code:
    # findgrub 
    Find Grub Version 4.1 - Written for openSUSE Forums
    
     - reading MBR on disk /dev/sda                       ... --> Grub2 (1.99) found in sda MBR     => sda6   0x83 (Ubuntu)
     - searching partition /dev/sda1      (FAT16)         ... --> Windows NT/2K/XP Loader found in /dev/sda1
    
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    You can add the following entry to /boot/grub/menu.lst :
    
    ###Don't change this comment - YaST2 identifier: Original name: WindowsBootLoader###
    title Windows on /dev/sda1
        rootnoverify (hd0,0)
        chainloader +1
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
     - skipping partition  /dev/sda2      (FreeBSD)      
     - skipping partition  /dev/sda3      (FreeBSD)      
     - reading bootsector  /dev/sda4   *  (Extended)      ... --> Legacy GRUB  found in /dev/sda4   => sda9   0x83 (INVALID)
     - 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)         ... --> Grub2 (1.99) found in /dev/sda9   => sda?   0x?? (openSUSE)
     - reading bootsector  /dev/sda10     (LINUX)         ...
     - reading bootsector  /dev/sda11     (LINUX)         ...
     - reading bootsector  /dev/sda12     (LINUX)         ...
     - reading bootsector  /dev/sda13     (LINUX)         ... --> Grub2 (1.99) found in /dev/sda13  => sda13  0x83 (Fedora)
     - reading bootsector  /dev/sda14     (LINUX)         ...
     - reading bootsector  /dev/sda15     (LINUX)         ... --> Legacy GRUB  found in /dev/sda15  => sda15  0x83 (Mandriva/ArchLinux/Debian)
     - reading bootsector  /dev/sda16     (LINUX)         ...
    
     - reading MBR on disk /dev/sdb                       ... --> Legacy GRUB  found in sdb MBR     => sda15  0x83 (Fedora)
     - searching partition /dev/sdb1      (FAT16)         ... --> Windows NT/2K/XP Loader found in /dev/sdb1
    
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    You can add the following entry to /boot/grub/menu.lst :
    
    ###Don't change this comment - YaST2 identifier: Original name: WindowsBootLoader###
    title Windows on /dev/sdb1
        rootnoverify (hd1,0)
        map (hd1) (hd0)
        map (hd0) (hd1)
        chainloader +1
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
     - skipping partition  /dev/sdb2      (FreeBSD)      
     - skipping partition  /dev/sdb3      (FreeBSD)      
     - reading bootsector  /dev/sdb4      (Extended)      ...
     - skipping partition  /dev/sdb5      (swap)         
     - reading bootsector  /dev/sdb6      (LINUX)         ... --> Legacy GRUB  found in /dev/sdb6   => sdb6   0x83 (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)         ...
    
    
    Press <enter> to Exit findgrub...


    Code:
    # findgrub
    Find Grub Version 4.2 - Written for openSUSE Forums
    
     - reading MBR on disk /dev/sda                       ... --> Grub2 (1.99) found in sda MBR     => sda6   0x83 (Ubuntu)
     - searching partition /dev/sda1      (FAT16)         ... --> Windows NT/2K/XP Loader found in /dev/sda1
    
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    You can add the following entry to /boot/grub/menu.lst :
    
    ###Don't change this comment - YaST2 identifier: Original name: WindowsBootLoader###
    title Windows on /dev/sda1
        rootnoverify (hd0,0)
        chainloader +1
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
     - skipping partition  /dev/sda2      (FreeBSD)      
     - skipping partition  /dev/sda3      (FreeBSD)      
     - reading bootsector  /dev/sda4   *  (Extended)      ... --> Legacy GRUB  found in /dev/sda4   => sda9   0x83 (INVALID)
     - 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)         ... --> Grub2 (2.00) found in /dev/sda9   => sda?   0x?? (openSUSE)
     - reading bootsector  /dev/sda10     (LINUX)         ...
     - reading bootsector  /dev/sda11     (LINUX)         ...
     - reading bootsector  /dev/sda12     (LINUX)         ...
     - reading bootsector  /dev/sda13     (LINUX)         ... --> Grub2 (1.99) found in /dev/sda13  => sda13  0x83 (Fedora)
     - reading bootsector  /dev/sda14     (LINUX)         ...
     - reading bootsector  /dev/sda15     (LINUX)         ... --> Legacy GRUB  found in /dev/sda15  => sda15  0x83 (Mandriva/ArchLinux/Debian)
     - reading bootsector  /dev/sda16     (LINUX)         ...
    
     - reading MBR on disk /dev/sdb                       ... --> Legacy GRUB  found in sdb MBR     => sda15  0x83 (Fedora)
     - searching partition /dev/sdb1      (FAT16)         ... --> Windows NT/2K/XP Loader found in /dev/sdb1
    
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    You can add the following entry to /boot/grub/menu.lst :
    
    ###Don't change this comment - YaST2 identifier: Original name: WindowsBootLoader###
    title Windows on /dev/sdb1
        rootnoverify (hd1,0)
        map (hd1) (hd0)
        map (hd0) (hd1)
        chainloader +1
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
     - skipping partition  /dev/sdb2      (FreeBSD)      
     - skipping partition  /dev/sdb3      (FreeBSD)      
     - reading bootsector  /dev/sdb4      (Extended)      ...
     - skipping partition  /dev/sdb5      (swap)         
     - reading bootsector  /dev/sdb6      (LINUX)         ... --> Legacy GRUB  found in /dev/sdb6   => sdb6   0x83 (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)         ...
    
    
    Press <enter> to Exit findgrub...

  10. #170
    arvidjaar is online now Wise Penguin
    Join Date
    Sep 2012
    Posts
    1,282

    Default Re: Looking for Grub and Windows bootloader in all partitions.

    It leaves terminal in some strange state where I get visually empty lines after outputting some color (e.g. colorized ls) until I press RETURN. This is Gnome terminal in standard 24x80 mode.

Page 17 of 27 FirstFirst ... 71516171819 ... LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Search Engine Friendly URLs by vBSEO 3.5.2 PL2