Grub2 mapping drives


Results 1 to 8 of 8

Thread: Grub2 mapping drives

  1. #1
    Join Date
    Jun 2002
    Location
    Michigan
    Posts
    875

    Grub2 mapping drives

    Howdy all

    Well what I am doing is trying to map a windows drive in Grub2, but Grub2 is telling me that "map is unrecognized command"
    Here is my

    fdisk -l
    Code:
    Disk /dev/sda: 320.1 GB, 320072933376 bytes
    255 heads, 63 sectors/track, 38913 cylinders
    Units = cylinders of 16065 * 512 = 8225280 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disk identifier: 0x84bf84bf
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/sda1   *           1       77825   625129281    7  HPFS/NTFS
    
    Disk /dev/sdb: 320.1 GB, 320072933376 bytes
    255 heads, 63 sectors/track, 38913 cylinders
    Units = cylinders of 16065 * 512 = 8225280 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disk identifier: 0x00000201
    
    Disk /dev/sdb doesn't contain a valid partition table
    
    Disk /dev/sdc: 80.0 GB, 80000000000 bytes
    255 heads, 63 sectors/track, 9726 cylinders
    Units = cylinders of 16065 * 512 = 8225280 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disk identifier: 0x0000bec9
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/sdc1   *           1        9325    74895360   83  Linux
    /dev/sdc2            9325        9726     3226625    5  Extended
    /dev/sdc5            9325        9726     3226624   82  Linux swap / Solaris
    Here is my windows script located in /etc/grub.d/09_Windows
    Code:
    #!/bin/sh -e
    echo "Adding Windows XP to GRUB 2 menu"
    cat << EOF
    menuentry "Windows xp" {
    set root=(hd1,0)
    map (hd1) (hd0)
    map (hd0) (hd1)
    chainloader +1
    }
    EOF
    So I'm wondering if anyone knows how Grub2 has changed the way it maps drives?
    I did search google.com/linux but could not find any relevant articles.

    Thanks for any help
    Dan

  2. #2
    Join Date
    Jun 2002
    Location
    Michigan
    Posts
    875
    Well after a lot more searching I finely found the answer.

    If the windows bootloader is on a entirely different harddrive than grub, it may be neccessary to trick windows into believing that it is in fact the first harddrive. This was passible in the old grub with map, and is now done with drivemap. Assume grub is on hd0 and windows on hd2, you need to add the following after set root
    Code:
    drivemap -s hd0 hd2
    So after editing my /etc/grub.d/09_Windows script it looks like this

    Code:
    #!/bin/sh -e
    echo "Adding Windows XP to GRUB 2 menu"
    cat << EOF
    menuentry "Windows xp" {
    set root=(hd1,1)
    drivemap -s hd0 hd1
    chainloader +1
    }
    EOF
    make sure after editing the script you run update-grub this will write the changes to grub.cfg located in /boot/grub/

    I should also note for anyone reading this later, Grub2 numbers partitions starting with 1 and NOT 0 as Legacy Grub used to. So instead of root (hd0,0) Grub2 would look like so
    Code:
    set root=(hd0,1)
    So I'm not sure who does it but this thread can be marked <SOLVED>
    thanks
    Last edited by saikee; 09-07-2010 at 03:47 AM.

  3. #3
    Join Date
    Jun 2004
    Location
    Newcastle upon Tyne
    Posts
    2,978
    We can't alter the thread title so we highlighted solved in red.

    Yep the relevant bit is Grub2 counts partition number from 1 but the disk number still starts from 0. This is now same as MS Windows.

    In its place "map" used in Grub1 the Grub2 equivalent is now "drivemap".

    As far as I am aware apart from not having a Grub shell (the "grub" command in a Linux terminal) most Grub1 commands have the equivalents in Grub2.
    Linux user started Jun 2004 - No. 361921
    Using a Linux live CD to clone XP
    To install Linux and keep Windows MBR untouched
    Adding extra Linux & Doing it in a lazy way
    A Grub menu booting 100+ systems & A "Howto" to install and boot 145 systems
    Just cloning tips Just booting tips A collection of booting tips

    Judge asked Linux "You are being charged murdering Windoze by stabbing its heart with a weapon, what was it?" Replied Linux "A Live CD"

  4. #4
    Join Date
    Jul 2002
    Location
    New Orleans, LA USA
    Posts
    986
    Quote Originally Posted by saikee View Post
    As far as I am aware apart from not having a Grub shell (the "grub" command in a Linux terminal) most Grub1 commands have the equivalents in Grub2.
    It is odd to read that... Case and point, I updated a friends computer over the weekend. Since I don't get by there all that often, he had a wall of upgrades and I missed that it updated grub to grub2. The first time he rebooted grub2 was unable to boot Linux so I went back over. The grub2 rescue shell has to be the worst experience I've had with Linux in the last 10 years. Not in relation to the time required to solve, but that it has been so long since I've been that frustrated with a program's utter lack of functionality and documentation.

    Many basic (but REQUIRED) commands from grub are missing or changed - map, root, linux, etc., you lose the functionality of tab to auto complete commands and show * matches, and there is no help file or directive accessible from grub2 prompt.

    I was able to google on my phone to determine root was replaced with set root (and 0 = 1 now), map replaced with drivemap, but it claimed linux was replaced with kernel which both were unrecognized commands so it was physically impossible to load his kernel. Luckily I had a debian thumb drive in my pack so was able to boot to that and remove grub2 then restore legacy grub (chroot).

    I definitely will not be switching to grub2, ever (unless something hardware wise in the future forces me too). I'll keep a copy to compile if need be, and could care less that my /boot is stuck in ext3 for life.
    Last edited by trilarian; 09-07-2010 at 04:57 PM.
    "Whenever you find yourself on the side of the majority, it's time to pause and reflect."

    -Mark Twain

  5. #5
    Join Date
    Jun 2004
    Location
    Newcastle upon Tyne
    Posts
    2,978
    trilarian,

    Sorry to hear your disappointment with Grub2.

    Grub2 has Grub rescue which in my opinion is rather useless. The true Grub2 prompt however is very similar to the Grub1 prompt and it is the one that you press the "c" key before booting up a system.

    The "help" command is there same as Grub1. Grub2 does have "ls" in place of "geometry" and it works like Linux kernel's "ls". The new ls command can list any directory including those from a NTFS partition. Thus Grub2 can be installed inside a MS Windows. The tab to auto complete is there too so use Grub2 prompt and disregard Grub rescue which is triggered if the second stage is broken.

    There are only small changes between the two Grub which I got in my Ubuntu. The Grub1 booting instructions from menu.lst is listed here
    Code:
    title	Ubuntu 9.04, kernel 2.6.28-11-generic
    uuid	e64d0e8b-63f1-4e79-917d-06a809eba07e
    kernel /boot/vmlinuz-2.6.28-11-generic root=UUID=e64d0e8b-63f1-4e79-917d-06a809eba07e ro quiet splash 
    initrd	/boot/initrd.img-2.6.28-11-generic
    and the Grub2 translation in grub.cfg, after using Ubuntu package manager installing Grub2 gave
    Code:
    menuentry "Ubuntu, linux 2.6.28-11-generic" {
    set root=(hd0,6)
    search --fs-uuid --set e64d0e8b-63f1-4e79-917d-06a809eba07e
    linux  /boot/vmlinuz-2.6.28-11-generic root=UUID=e64d0e8b-63f1-4e79-917d-06a809eba07e ro  quiet splash
    initrd /boot/initrd.img-2.6.28-11-generic
    }
    I highlighted the difference in red.

    Thus the differences are very small. Also I don't normally bother with uuid reference and have booted the system "manually" in Grub1 with commands
    Code:
    root (hd0,5)
    kernel /boot/vmlinuz-2.6.28-11-generic root=/dev/sda6 ro  
    initrd	/boot/initrd.img-2.6.28-11-generic
    boot
    and if I use Grub2 it is just
    Code:
    set root=(hd0,6)
    linux /boot/vmlinuz-2.6.28-11-generic root=/dev/sda6 ro  
    initrd	/boot/initrd.img-2.6.28-11-generic
    boot
    The green bits are by tab auto complete.

    The three useful features in Grub2 (not found in Grub1) are

    (1) Grub2 can read ntfs partition and so it can be installed as a stand alone system inside a MS Windows. I have tried this with Xp and Win7.

    (2) Grub2 is factory-ready for gpt partitions so it can work seamlessly with hard disks in excess of 2TB size.

    (3) Grub1 will complain if the partition to be booted is beyond the 1.3TB position in a hard disk with a error complaining "the number of cylinders exceed the maximum supported by the Bios". Grub2 has overcome this limitation.

    The important point to note is both Grub can boot each other by "chainloader +1" command if the Grub has been installed/replicated inside the partition containing the /boot directory.
    Last edited by saikee; 09-07-2010 at 07:05 PM.
    Linux user started Jun 2004 - No. 361921
    Using a Linux live CD to clone XP
    To install Linux and keep Windows MBR untouched
    Adding extra Linux & Doing it in a lazy way
    A Grub menu booting 100+ systems & A "Howto" to install and boot 145 systems
    Just cloning tips Just booting tips A collection of booting tips

    Judge asked Linux "You are being charged murdering Windoze by stabbing its heart with a weapon, what was it?" Replied Linux "A Live CD"

  6. #6
    Join Date
    Jul 2002
    Location
    New Orleans, LA USA
    Posts
    986
    First, thanks for responding. Don't take any of my griping as personal, it is all directed at grub2 and I appreciate your time in explaining it to me.

    Quote Originally Posted by saikee View Post
    Grub2 has Grub rescue which in my opinion is rather useless. The true Grub2 prompt however is very similar to the Grub1 prompt and it is the one that you press the "c" key before booting up a system.
    Something else must be wrong then when it is installed as an upgrade. It's been awhile, but I remember not being able to boot my own computer either when trying to play with grub2. The only time I ever got grub2 to successfully boot anything is when they included it in the Debian net-install as an option. However, after the first apt-get upgrade (which updated the kernel) it became unbootable again. On the flip side, I haven't ever come across something grub can't boot.

    In this recent case, grub_rescue> pops up immediately after the RAM test, so there is no time to input any key sequence and there is no information sent to the screen. Furthermore, grub rescue doesn't even have enough commands available to actually boot the system (both linux and kernel are 'not found' when invoked) - so shouldn't even be available as it currently is imho.

    Quote Originally Posted by saikee View Post
    The "help" command is there same as Grub1. Grub2 does have "ls" in place of "geometry" and it works like Linux kernel's "ls". The new ls command can list any directory including those from a NTFS partition. Thus Grub2 can be installed inside a MS Windows. The tab to auto complete is there too so use Grub2 prompt and disregard Grub rescue which is triggered if the second stage is broken.
    If they have the code for ls and help, why isn't it in rescue? Why is rescue the default error catcher instead of grub2 shell? Honestly I could care less about installing grub unto a NTFS partition... what scenario would this be good for outside of just saying I did it? If it is windows only, let the regular windows boot loader take care of things - it is faster and easily fixable. If it is a dual boot, install grub to the linux partition or in the MBR. If it's pure Linux, why have NTFS anyway? Am I missing something neat?

    Quote Originally Posted by saikee View Post
    There are only small changes between the two Grub which I got in my Ubuntu. The Grub1 booting instructions from menu.lst is listed here
    Code:
    title	Ubuntu 9.04, kernel 2.6.28-11-generic
    uuid	e64d0e8b-63f1-4e79-917d-06a809eba07e
    kernel /boot/vmlinuz-2.6.28-11-generic root=UUID=e64d0e8b-63f1-4e79-917d-06a809eba07e ro quiet splash 
    initrd	/boot/initrd.img-2.6.28-11-generic
    and the Grub2 translation in grub.cfg, after using Ubuntu package manager installing Grub2 gave
    Code:
    menuentry "Ubuntu, linux 2.6.28-11-generic" {
    set root=(hd0,6)
    search --fs-uuid --set e64d0e8b-63f1-4e79-917d-06a809eba07e
    linux  /boot/vmlinuz-2.6.28-11-generic root=UUID=e64d0e8b-63f1-4e79-917d-06a809eba07e ro  quiet splash
    initrd /boot/initrd.img-2.6.28-11-generic
    }
    I highlighted the difference in red.
    So if I'm reading this right... if the below works for grub if I manually type it in, why can't what is below that work for grub2? And how do you manually boot a system with grub2 when there isn't a linux or kernel command available?

    Grub Example:
    Code:
    root (hd0,0)
    kernel /boot/vmlinuz-2.6.32-trunk-amd64 root=/dev/hda1 ro
    initrd /boot/initrd-2.6.32-trunk-amd64
    boot
    Grub2 (doesn't work, but should):
    Code:
    set root (hd1,1)
    linux /boot/vmlinuz-2.6.32-trunk-amd64 root=/dev/hda1 ro
    initrd /boot/initrd-2.6.32-trunk-amd64
    boot
    Quote Originally Posted by saikee View Post
    Thus the differences are very small. Also I don't normally bother with uuid reference and have booted the system "manually" in Grub1 with commands
    Code:
    root (hd0,5)
    kernel /boot/vmlinuz-2.6.28-11-generic root=/dev/sda6 ro  
    initrd	/boot/initrd.img-2.6.28-11-generic
    boot
    and if I use Grub2 it is just
    Code:
    set root=(hd0,6)
    linux /boot/vmlinuz-2.6.28-11-generic root=/dev/sda6 ro  
    initrd	/boot/initrd.img-2.6.28-11-generic
    boot
    The green bits are by tab auto complete.
    This just baffles me. Unless grub2_rescue is a retarded subset of code not meant to ever, ever, ever be used, this simply is not true on my system. Hitting tab never fills in the remainder of a command or file name, and does not give partial matches. Furthermore, typing in "linux /boot/..." line kept returning "command linux not found". I'm sure I didn't misspell it.... I tried typing it a few times, tried casing, tried l tab, etc. but nothing.


    Quote Originally Posted by saikee View Post
    The three useful features in Grub2 (not found in Grub1) are

    (1) Grub2 can read ntfs partition and so it can be installed as a stand alone system inside a MS Windows. I have tried this with Xp and Win7.
    I guess I still don't see the significance of this... maybe you can enlighten me to a use I'm overlooking?

    Quote Originally Posted by saikee View Post
    (2) Grub2 is factory-ready for gpt partitions so it can work seamlessly with hard disks in excess of 2TB size.
    This may eventually be an issue, but the more I think about, probably never. Right now I have 2x 1TB drives in software RAID-0 - effectively 2TBs - on my server. I'm assuming since the way you load up the raid modules (and encryption modules) is by making the small /boot partition a raid mirror unencrypted (so in grub's chain of events, a single partition on a single drive) it will never see that upper limit. I can't think of any reason in my life time to need a /boot over 2TB.

    For the rare case of having another OS installed in a partition over 2TB I guess this is useful, but it is an awful waste of space. Put the OS on a smaller partition, and fill the rest as a shared storage partition readable by all installed OS.

    Quote Originally Posted by saikee View Post
    (3) Grub1 will complain if the partition to be booted is beyond the 1.3TB position in a hard disk with a error complaining "the number of cylinders exceed the maximum supported by the Bios". Grub2 has overcome this limitation.
    I haven't seen this error. My setup was listed above, but outside of /boot (which is 150MB x2) the rest is one large partition on top of the software raid which is one encrypted partition, that once unlocked is subdivided with LVM. Since I haven't received the error you mention, I can only assume the 1.3TB limit is again only assigned to /boot or the root partition of say a Windows install. That again brings up my rebuttal to #2, put the OS in less than 2TB (or 1.3TB in this case) and make the largest partition be your storage partition that is readable by all.

    I don't see any advantage to throwing everything in one partition, and if it is the only partition on the drive - like in the case of a windows only install (even though as of Vista? windows makes a smaller boot partition) - then use the windows boot loader.

    Here is a simple solution for grub2 to be instantly usable... Grub2 should have a working shell that will let you manually boot if the auto script errors out. Delete all code relating to grub_rescue as fast as humanely possible. Add an alias to any commands that simply have a new name (like linux vs kernel, map vs drivemap, etc.) so that users of grub feel at home and the current grub2 syntax still works. I don't see a need for new command names when the function is the same - grub2 uses a different config file if they were worried about that.
    "Whenever you find yourself on the side of the majority, it's time to pause and reflect."

    -Mark Twain

  7. #7
    Join Date
    Jun 2004
    Location
    Newcastle upon Tyne
    Posts
    2,978
    trilarian,

    Let us be sure about one thing. Grub_rescue is not the full Grub2.

    Grub1 has stage1 and stage2 while the equivalent in Grub2 are boot.img and core.img. The first part of either stage1 or boot.img is exactly 512 bytes large but for the second part stage2 is 120k large while the Grub2's core.img is a mere 24k in size.

    When the core.img is removed or deleted from the hard disk Grub2 will boot to Grub_rescue. I have installed Grub2, deleted its partition and generate the Grub_rescue condition before. Therefore Grub_rescue could be only 512 bytes large and is incapable of booting any operating system. Thus it is pointless to complain the deficiency of Grub2 based on the performance of Grub_rescue.

    One can put Grub2 (or Grub1) on a floppy, a CD or a Pen Drive to boot any operating system manually. Therefore having a Grub_rescue from a broken Grub2 isn't an issue if one can use another Grub2 from a floppy or CD to manually boot up the same system. I have put Grub2 in all media to boot OSes just like I did with Grub1. So to me anyone can boot any Linux or any installed PC system using either Grub1 or Grub2 as a stand alone system. The only difference is be aware of the small differences in the syntax between the two versions of Grub.

    Lastly there may be a case of term definition causing confusion here. I define a shell as a subsystem within a larger system. Therefore a Grub environment issued "inside" a Linux by typing the command "grub" at the console is a shell to me because the large system is the kernel (BASH terminal)l.

    When Grub2 is booted and before a Linux is selected I call the Grub environment a Grub prompt because Grub is the "only" system in the PC at that time. In a Grub prompt both Grub1 and Grub2 are very similar as I have mentioned before. In this respect Grub_rescue is just a tiny part of the Grub2 prompt.

    I am neutral on the pros and cons of Grub_rescue as the equivalent in Grub1 is just an error message and the system hangs immediately. With Grub_rescue one can at least do a little bit of investigation. May be I am being realistic by not expecting much can happen with a code apparently only 512 bytes long.
    Last edited by saikee; 09-08-2010 at 08:55 PM.
    Linux user started Jun 2004 - No. 361921
    Using a Linux live CD to clone XP
    To install Linux and keep Windows MBR untouched
    Adding extra Linux & Doing it in a lazy way
    A Grub menu booting 100+ systems & A "Howto" to install and boot 145 systems
    Just cloning tips Just booting tips A collection of booting tips

    Judge asked Linux "You are being charged murdering Windoze by stabbing its heart with a weapon, what was it?" Replied Linux "A Live CD"

  8. #8
    Join Date
    Jul 2002
    Location
    New Orleans, LA USA
    Posts
    986
    Quote Originally Posted by saikee View Post
    Let us be sure about one thing. Grub_rescue is not the full Grub2.
    Yea, I'm guilty as charged on that.

    Quote Originally Posted by saikee View Post
    Grub1 has stage1 and stage2 while the equivalent in Grub2 are boot.img and core.img. The first part of either stage1 or boot.img is exactly 512 bytes large but for the second part stage2 is 120k large while the Grub2's core.img is a mere 24k in size.

    When the core.img is removed or deleted from the hard disk Grub2 will boot to Grub_rescue. I have installed Grub2, deleted its partition and generate the Grub_rescue condition before. Therefore Grub_rescue could be only 512 bytes large and is incapable of booting any operating system. Thus it is pointless to complain the deficiency of Grub2 based on the performance of Grub_rescue.
    Thanks. I never really read up on the difference in stage1/stage2. In the 12 years or so I've been using Linux I have yet to experience a stage1 failure... until grub2 it seems. The odd thing is I know I haven't deleted any files and there is more than enough free space in /boot, so apparently upgrading from grub to grub2 does not create the core.img file you say it needs.

    I agree I can't really compare 512 bytes to a vastly larger user space program. They probably should dump some text to the screen instead of just bringing you to a prompt with grub_rescue which implies it is a rescue service (which rescue disc usually allow 'rescue' functions like reinstall of boot loader, write to MBR, etc.).

    Quote Originally Posted by saikee View Post
    One can put Grub2 (or Grub1) on a floppy, a CD or a Pen Drive to boot any operating system manually. Therefore having a Grub_rescue from a broken Grub2 isn't an issue if one can use another Grub2 from a floppy or CD to manually boot up the same system. I have put Grub2 in all media to boot OSes just like I did with Grub1. So to me anyone can boot any Linux or any installed PC system using either Grub1 or Grub2 as a stand alone system. The only difference is be aware of the small differences in the syntax between the two versions of Grub.
    I guess I don't see much functionality in this. If I need an external source, why not have a live install? I haven't even had the ability to attach a floppy drive in many years, and a cd or flash drive has more than enough space. Linux is all about choice though, so if it works for someone great.

    Quote Originally Posted by saikee View Post
    Lastly there may be a case of term definition causing confusion here. I define a shell as a subsystem within a larger system. Therefore a Grub environment issued "inside" a Linux by typing the command "grub" at the console is a shell to me because the large system is the kernel (BASH terminal).
    I consider a shell any form of a functioning OS that can be either stand alone or embedded as a subset of a larger system (be that correct or not). Shells can be very small with only a few commands or more robust like BASH. Generally if a shell is very limited it at least allows basic recovery features like touching a file system (not raid, encrypt, etc.). Grub_Rescue is not a shell IMHO. Without knowing the stage1/stage2 process, I looked at grub which has either worked or dropped to a shell I could recover the system with, and figured grub_rescue was the same. When it was unable to do anything, not even point to the kernel, I became frustrated.

    Quote Originally Posted by saikee View Post
    I am neutral on the pros and cons of Grub_rescue as the equivalent in Grub1 is just an error message and the system hangs immediately. With Grub_rescue one can at least do a little bit of investigation. May be I am being realistic by not expecting much can happen with a code apparently only 512 bytes long.
    I'm against as it stands, but can see where some would find it useful I guess. I would rather an error with a text dump of "Core.img was not found on (hd1,1). Boot to a rescue disc and run program x to fix." At any rate, I'm over it... thanks for explaining the details. I think I'll stick with legacy grub for now as, for me at least, it is vastly superior.
    "Whenever you find yourself on the side of the majority, it's time to pause and reflect."

    -Mark Twain

Posting Permissions

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