Language Selection

English French German Italian Portuguese Spanish

How-to Edit Grub

Filed under
HowTos
-s

So you've just installed your second, or third, or ninth Linux distribution and it either didn't recognize all your installs or you chose to skip that phase of the install. Of course you'd like to be able to boot all of these installs. Editing the grub.conf (or menu.lst) is an easy peasy procedure once you have an elementary understanding of the basic components.

If you are editing your Grub menu then we'll assume you already have it installed. This howto is to merely add an additional system to the existing file. This howto was inspired by this poor chap who resorted to reinstalling a whole system in order to update his Grub menu. No one should have to do that. Hopefully this will help.

Now I'm far from an expert, but having had to recently learn how to do this myself, I think I'll share what I do. The main advantage of using Grub is that editing the menu file is all that's necessary - as opposed to Lilo which requires one to rerun the Lilo program to reinstall it into the mbr.

The first thing I do is copy and paste an existing entry. No sense in retyping all of that and chances are you will probably want to use the same kernel parameters for the new install that you've used for previous. So:

  1. Copy and paste your favorite existing entry either where you think you'd like it or at the end of the list.

  2. Start the edit. The first thing one might need to consider is the title. This is easy, just change it to a meaningful name for your new install. In "Tryst's" case, he needed a new entry for PCLinuxOS 2007. So, he could have used PCLOS2007. Unlike Lilo, with Grub you can use names with spaces, so he could have used PCLOS 2007 if he chose.

  3. Now the bit more tricky part, the root. This is the component that specifies where the boot kernel is. Is it in a shared /boot partition or is it in the /boot directory of the new install?

    • First case scenario: Let's say you told the installer about your seperate /boot partition and it installed the boot kernel into it. The root component must then point to your shared /boot partition.

      The format might look scary at first, but it isn't. In the true Unix fashion, it begins its numbering with 0 (zero). The first number indicates the harddrive number. So, hda is 0, hdb is 1, hdc is 2, and so on. So, more than likely your boot partition is located on hda and in which case 0 is the number you want there. Just remember it's N - 1.

      The second number is the partition number. Again, hda1 is 0, hda2 is 1, and so on. So, say your /boot partition is located at sda5 you'd want to put a 4 there. So, your root entry might look like so:

      root (hd0,4)

    • Second scenario: You told the installer to install Grub onto the / (root) partition of the new install or you chose to skip installing Grub altogether. In this case the root component needs to point to the install partition. So, for example, say your new system is installed on hdb8, your root parameter should read:

      root (hd1,7)

  4. The next component is the kernel. This entry can contain lots of boot parameters but the most important is the correct name of the boot kernel. So, ls the /boot partition or directory to get that name.

    • If it's in a shared /boot partition you will need to just specify the name of the kernel as if in the working directory, like so:

      /vmlinuz-2.6.18.8.tex5

    • If it's on the install partition, then it will need to list the directory on that partition in which the boot kernel is found, like so:

      /boot/vmlinuz-2.6.18.8.tex5

      • Another necessary component of the kernel line is the root partition. This is in the more tradition partitioning scheme and points to the install partition. So, in our example, it should point to hdb8 like so:

        root=/dev/hdb8 (or root=/dev/sdb8)

      • Next is the resume. If you wish to use some advanced powersaving features such as suspend to disk, then you'll want a resume parameter listed. This is your swap partition where the disk image is stored. Again, the format is the more commonly used /dev/hdxX pattern. In my case, my swap is /dev/sda6, so it should look like:

        resume=/dev/sda6

      • You may also have other kernel parameters set here, such as splash=silent, vga=788, or noapic, whatever. These are system specific and usually already in place if you just copied an original working entry as in step 1.

  5. The final necessary component is the initrd. Not all boot kernels use or require an initrd, but most larger modern systems like openSUSE, Mandriva, and PCLOS do. This usually contains filesystem modules you might need to mount the system partition or the purdy boot splashes we like so much. You can tell if you need one by issuing ls -t in /boot directory of the new system or in the shared /boot partition. -t tells it to list by time, so you can see your newest files first. If one doesn't exist in the /boot directory, or you can't find one that matches the boot kernel, then you can assume you don't need one.

    If there is one listed, then you'll need to tell Grub about it. In "Tryst's" case, he does. So:

    • First case scenario: initrd /initrd-2.6.18.8.tex5.img

    • Second case: initrd /boot/initrd-2.6.18.8.tex5.img

That's it, that should get you in. If you need to, you can temporarily edit any grub entry at boot time, usually by hitting the "e" key. You will probably have to hit "e" again when the edit the entry screen appears to edit the particular component. Then you can hit "b" to boot it. You'll need to edit the grub.conf (or menu.lst) to make it permanent.

As stated this is how I do it and there is a lot more to Grub than discussed here. But hopefully this will help one edit their grub.conf or menu.lst file to boot their new Linux partitions.

PS. Windows and Unix (bsd) use entries like so:

title windows
root (hd0,0)
makeactive
chainloader +1

StumbleUpon



I use chain loader

It's good to see the subject nailed down in plain English. I found out about the chain loader method you mention from the PCLinuxOS documents for the previous version.

First, when I install a distro, I tell the installer to write the grub menu to the first sector of the root partition (i.e. the partition to which I'm installing) instead of the master boot record. The 'buntus just will not co-operate with that, so they get short shrift. I also become hypercritical of any distro which does not give me the option of using grub.

Secondly, before even beginning the installation, I add a verse like the following to menu.lst in the distro which has grub installed on the master boot record:

title KateOS_3.2
root (hd0,2)
chainloader +1

When you select that distro from the main grub menu, you then get the separate grub menu provided by the distro itself, with different options for logging in to that distro.

Advantages to using that method:
1. You can boot into the new system from the grub menu as soon as you have finished the initial installation;
2. The installer works out all the difficult technical stuff and you reduce the scope for typing errors;
3. You enable the new distro to have several options for booting, usually simple, non-fb and fail-safe.

Disadvantages:
1. There is a double choice to make and a double time lag. You can reduce the time lag on the second menu and make the distro the default choice if you wish.

This is how I eventually fixed it! (From "the poor chap")

Hey thanks for your effort, but what you wrote, for a person like me, was tooo scary. Really, I'm one of these people who find it difficult to read too much technical stuff... and so I found it difficult (and scary) to read your help. But you did inspire me to fix my GRUB immediately, and so, I did. And this is how I did it.

Firstly, taking on from your pointer, I realised that GRUB is just code. Thanks for that pointer.

Secondly, I realised that I actually needed to "cut and paste" only. Thanks for this pointer too.

However what I did, was I went to my openSUSE GRUB menu.lst and opened the file (using su) and then I copied openSUSE's boot code, which in my case was

title openSUSE 10.2
root (hd0,3)
kernel /boot/vmlinuz root=/dev/hdc4 vga=0x317 resume=/dev/hdc3 splash=silent
initrd /boot/initrd

I pasted this to the end (replacing my previous openSUSE detailed attempt). And then tested.

Viola, it worked!

Now I know that people like me are the bane of linux. Meaning, if I knew the code, I'd understand it... but instead, more and more, a generation of windows-based users are infiltrating linux and filling the space with a desire for 'easy' solutions. I try not to be one of them, but sometimes I am. However, I guess I have to go with my strengths. I don't think I will ever be friendly about understanding code (cut and paste solutions are just about all that I can do), and so I guess I want to thank you again for taking the time to address this issue... and hopefully there will be more people who will read your entry and actually UNDERSTAND what they're doing.

Cheers!

(ps. I'm going to paste this comment onto my blog along with a link to your post, because your solution actually looks and sounds really cool!)

It used to be worse

These days, BIOSes on modern motherboards work great with GRUB (and, presumably, LILO -- but, as you noted, GRUB has the advantage of not having to be reinstalled to the MBR each time its configuration file is changed). I had one computer in the mid 90s that flat would not boot using LILO, and another computer in the late 90s that would use LILO, but flat would not boot using GRUB.

There's nothing quite like a hang at boot time to induce panic, especially when you dual-boot. (Backup? What's a backup?) So afterwards, even through a succession of new computers and new motherboards, I first used loadlin, until MS-DOS went away, and then GRUB for Windows, which uses Windows' NTLDR. Finally, one day an install of openSUSE put GRUB on the MBR (even though I told it not to) and it worked just fine, so I gave in and started using "real" GRUB.

It's also really easy these days to pop in a Knoppix CD and make a backup of the MBR (with or without the partition table) and save it on a floppy.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

More in Tux Machines

Purism's Linux Phone to Use Convergence for a Unified Experience Across Devices

For Purism, the company that sells quality computers using a Linux-based operating system and are intended to protect user's privacy and freedom, designing a convergent Linux phone is a long-term goal to unify the mobile experience across various devices. Purism's François Téchené shares some initial details on how the company plans to use convergence for their short and long-term design goals of Librem 5, the Linux smartphone that raised more than $2 million on Kickstarter last year, saying they're looking to unify the human experience across different device you might own. Read more

Leftovers: ExeeLinux Show/Unleaded Hangouts, Linux Foundation's CNCF/Akraino and More

  • What’s Holding Linux Back – Unleaded Hangouts
    What’s Holding Linux Back? Obviously we’ve seen some growth, but it does feel like there may be some things that hold Linux back a bit. We discuss.
  • ExeeLinux Show 18.9 | Mr. Desktop & Mr. Server Ep. 9 – PDisks
    ExeeLinux Show 18.9 | Mr. Desktop & Mr. Server Ep. 9 – PDisks
  • How Kubernetes became the solution for migrating legacy applications
    In 2015, Google released Kubernetes as an open source project. It was an implementation of Google's internal system called Borg. Google and the Linux Foundation created the Cloud-Native Computing Foundation (CNCF) to host Kubernetes (and other cloud-native projects) as an independent project governed by a community around it. Kubernetes quickly became one of the fastest growing open source projects in history, growing to thousands of contributors across dozens of companies and organizations. What makes Kubernetes so incredible is its implementation of Google's own experience with Borg. Nothing beats the scale of Google. Borg launches more than 2-billion containers per week, an average of 3,300 per second. At its peak, it's many, many more. Kubernetes was born in a cauldron of fire, battle-tested and ready for massive workloads.
  • Akraino, a New Linux Foundation Project, Aims to Drive Alignment Around High-Availability Cloud Services for Network Edge
    Akraino will offer users new levels of flexibility to scale edge cloud services quickly, to maximize the applications or subscribers supported on each server, and to help ensure the reliability of systems that must be up at all times. While several open source projects exist to help solve pieces of the puzzle, nothing currently meets the need for an edge infrastructure solution. Integration of existing efforts in this new project will help deliver ease of use, hardened reliability, unique features, and performance for carrier, provider, and IoT networks.
  • Absolute 15.0 Beta 4 released
    Based on Slackware64-current Another beta... with all the kernel updates, glib and such -- trying to make things easier on beta testers :-)
  • State of Wisconsin Investment Board Has $33.92 Million Stake in Red Hat Inc (RHT)

Security: Updates, Nintendo 'Hackers', Microsoft Windows Back Doors, and FlightSimLabs Malware

  • Security updates for Tuesday
  • Hackers Release Video Of Nintendo Switch Running A Linux Distro
    When it comes to porting software to potentially unsupported devices, hackers are quite comfortable to push themselves beyond the boundaries set by the manufactures.
  • Epidemic of cryptojacking can be traced to escaped NSA superweapon [Ed: It's a Microsoft Windows issue. All versions of Windows (ME onwards) have NSA back doors]
    It all started when the Shadow Brokers dumped a collection of NSA cyberweapons that the NSA had fashioned from unreported bugs in commonly used software, including versions of Windows. The NSA discovered these bugs and then hoarded them, rather than warning the public and/or the manufacturers about them, in order to develop weapons that turned these bugs into attacks that could be used against the NSA's enemies.
  • Flight Sim Company Embeds Malware to Steal Pirates’ Passwords

    Flight sim company FlightSimLabs has found itself in trouble after installing malware onto users' machines as an anti-piracy measure. Code embedded in its A320-X module contained a mechanism for detecting 'pirate' serial numbers distributed on The Pirate Bay, which then triggered a process through which the company stole usernames and passwords from users' web browsers.

Software and Games Leftovers

  • LXD Weekly Status #35
    This past week we’ve been focusing on a number of open pull requests, getting closer to merging improvements to our storage volume handling, unix char/block devices handling and the massive clustering branch that’s been cooking for a while. We’re hoping to see most of those land at some point this coming week. On the LXC side of things, the focus was on bugfixes and cleanups as well as preparing for the removal of the python3 and lua bindings from the main repository. We’re also making good progress on distrobuilder and hope to start moving some of our images to using it as the build tool very soon.
  • Performance Co-Pilot 4.0.0 released
    It gives me great pleasure to announce the first major-numbered PCP release in nine and a half years - PCP v4 - is here!
  • Performance Co-Pilot Sees First Major Version Bump In Nearly A Decade
    The Performance Co-Pilot open-source cross-platform monitoring/visualizing stack has reached version 4.0 as its first major version hike in almost ten years.
  •  
  • Sci-fi mystery 'The Station' has released, it’s a short but memorable experience
    What would happen if we discovered the existence of alien life? A question I've often asked and a question many games, films and books have covered in great detail. The Station [Steam] is a sci-fi mystery that sees you investigate The Espial, a space station sent to research a sentient alien civilization.
  • Halcyon 6: The Precursor Legacy DLC released, some good content for a small price
    Halcyon 6: The Precursor Legacy DLC [GOG, Steam] was released earlier this month, adding some really nice content at a small price to an already great game.
  • Parry and dodge your way to victory in 'Way of the Passive Fist', launching March 6th
    Way of the Passive Fist [Steam, Official Site] is a rather unique and very colourful arcade brawler and it's releasing with Linux support on March 6th.