[HOW TO] Get Your *nix Bootloader Back


Recommended Posts

I saw where Aaron had written the HOWTO Guide for getting the Windows bootloader back, but what if you're someone who needs their GRUB or LILO back? What then? Well, I found the answer for anyone who might need it :D

GRUB

  1. Boot into the first CD
  2. Type linux rescue when asked what to boot.
  3. After you have chosen Language and Keyboard layout, you are asked if you want to mount your harddisk system. Say yes to this.
  4. Now you system is mounted as /mnt/sysimage. Say 'OK'. Now type: chroot /mnt/sysimage. This will make you run on your already installed system, instead of the CD-ROM
  5. Type /sbin/grub-install /dev/hda (change hda to sda if you're using an SATA hard drive)

LILO

  1. Boot into the first CD
  2. Type linux rescue when asked what to boot.
  3. After you have chosen Language and Keyboard layout, you are asked if you want to mount your harddisk system. Say yes to this.
  4. Now you system is mounted as /mnt/sysimage. Say 'OK'. Now type: chroot /mnt/sysimage. This will make you run on your already installed system, instead of the CD-ROM. Now you can edit /etc/lilo.conf if something was wrong (vi /etc/lilo.conf and run lilo), or if you need to reinstall LILO just type lilo. The LILO installation process should now run.

This may be different for different distros and how you may have your system setup. I do not issue any guarantees with this HOWTO. Neowin, nor myself, is responsible if you bork your system. If you have any problems post them here ;)

Edited by Hurmoth
Link to comment
https://www.neowin.net/forum/topic/324741-how-to-get-your-nix-bootloader-back/
Share on other sites

Just an addendeum. You can install GRUB from within GRUB (this is how I like to do it).

1. Boot from a floppy or CD which uses GRUB as it's bootloader.

2. When you see GRUB's boot-menu, hit 'c'. You should see a "grub>" prompt

3. Type the following commands:

grub> root (hd0, 0)
grub> setup (hd0)

Commands explained:

"root (hd0, 0)" - This tells grub where it can find grub's files which are normally located in "/boot/grub/". The sample command tells grub that the files are located on the first hard drive, on partition 0 (first partition). If you don't know which drive/partition hold grub's files, you can do a:

grub> find /boot/grub/stage1

"setup (hd0)" - Tells grub to install itself on the Master Boot Record (MBR) of the first hard drive. You can also tell grub to install onto a partition by doing a "setup (hd0, 1)". This will tell grub to install to the second partition of the first hard drive.

Tips:

- Grub has a "help" command. Use it.

- Grub supports "bash-like" auto-completing. Say you don't quite know the partition number of your linux partition, but you know it's on the first hard drive and you know it's an ext2 partition. You can type:

grub> root (hd0,

and hit [tab]

This gives me:

Possible partitions are:
   Partition num: 0,  Filesystem type is reiserfs, partition type 0x83
   Partition num: 1,  Filesystem type is ext2fs, partition type 0x83
   Partition num: 2,  Filesystem type is reiserfs, partition type 0x83

Voila! It's partition number 1. Auto-completeing also works for other grub commands.

  markjensen said:
Anyone have an addition for doing this for LILO users?

585974127[/snapback]

If anyone adds it, I'll change the title and add it to my first post (giving the person credit of course) ;)

  markjensen said:
Good idea to have this posted (Y)  I have never had to do this, but many others have had to and have posted questions on it.

My boss' GRUB got messed up and wouldn't boot so I had to research how to fix it. The first place I looked was here and all I saw was Armeck's guide to getting the Windows bootloader back.

Yes this is a good post. My grub was messed too (error 18) and I couldn't fix it because Linspire Live couldn't detect my damn hard drive for some reason so I couldn't fix it. Also, when I attempted to go into linuxrecovery of the Debian cd, it wouldn't let me reinstall grub from there.

I added a way to reinstall LILO using the first installation disc, this can also be done with a Rescue Disc or Floppy Disk. I have never used LILO, so early this morning I installed a fresh copy of FC3 and used LILO instead of GRUB and messed it up on purpose to try and find out how to reinstall LILO... and that is what I came up with. Let me know if I have any typos :D

  • 7 months later...
  invalidbuffalo said:

I get the error:

/dev/hda: Not found or not a block device.

when I try to reinstall GRUB.

If you do an fdisk -l (that is a lowercase letter "L", not the number one), what do you get for drives listed? Do you have SATA drives?

  • 4 months later...
  wildworld_ammsa said:

i think this topic needs to be a Sticky. if some admin agrees, can he/she plz add it?

[Pinned]

This may not stay, but we'll see. There is a limit as to how many topics we can "pin". This is a good topic to have handy. :woot:

Barney

  • 4 weeks later...
  • 2 months later...
  • 1 month later...

Why lose it in the first place?

Its easy to avoid the entire unpleasantness when installing Linux onto a PC thats already hosts Windows, you just have to think about not upsetting precious windows, after all, its more finicky about its bootsector than Linux is.

Here's what i do:

Install linux.....wait until bootloader setup

Then

* Modify setting if needed to put bootloader on root partition (the partition that hosts \)

Then AFTER bootloader is written and anytime BEFORE you complete installation reboot:

* Switch to a terminal window form the setup GUI, on SuSE 10.1 for example i use CRTL ALT + F5.

* Put a floppy disk in your floppy drive

* Make a folder under /mnt, e.g. md /mnt/floppy (on some linuces, you may need to make an entirely different folder than floppy, as one may already exist and not be able to be written to - dont ask why, ive seen it, in this case try md /mnt/fdtemp etc.)

* Mount your floppy disk, e.g. mount -t vfat /dev/fd0 /mnt/floppy

* Type: dd if=/dev/hdaX of=/mnt/floppy/bootsec.lnx bs=512 count=1

Where X = the root partition number (e.g. /dev/hda11 as it is on mine)

* Browse to the floppy and make sure the bootsec.lnx file is there.

* Complete linux install and reboot into Windows

* Copy bootsec.lnx to c:\

* Keep floppy in a safe place, or copy the bootsec.lnx to a safe place.

* Open boot.ini in notepad

* Add "XXXX Linux" = c:\bootsec.lnx in the OS list under windows.

Where XXXX is the name of the linux or something witty and anti MS

* Save the file.

* Enjoy.

A few seconds work and thinking intelligently means you can avoid the whole bootsector drama completely and not upset either. I havent met a linux yet this isnt possible to use on.

As i said ive been using this since my first forays into Red Hat and Windows 2000, hasnt failed me yet.

Why lose it in the first place?

Its easy to avoid the entire unpleasantness when installing Linux onto a PC thats already hosts Windows, you just have to think about not upsetting precious windows, after all, its more finicky about its bootsector than Linux is.

Here's what i do:

Install linux.....wait until bootloader setup

Then

* Modify setting if needed to put bootloader on root partition (the partition that hosts \)

Then AFTER bootloader is written and anytime BEFORE you complete installation reboot:

* Switch to a terminal window form the setup GUI, on SuSE 10.1 for example i use CRTL ALT + F5.

* Put a floppy disk in your floppy drive

* Make a folder under /mnt, e.g. md /mnt/floppy (on some linuces, you may need to make an entirely different folder than floppy, as one may already exist and not be able to be written to - dont ask why, ive seen it, in this case try md /mnt/fdtemp etc.)

* Mount your floppy disk, e.g. mount -t vfat /dev/fd0 /mnt/floppy

* Type: dd if=/dev/hdaX of=/mnt/floppy/bootsec.lnx bs=512 count=1

Where X = the root partition number (e.g. /dev/hda11 as it is on mine)

* Browse to the floppy and make sure the bootsec.lnx file is there.

* Reboot into Windows

* Copy bootsec.lnx to c:\

* Keep floppy in a safe place, or copy the bootsec.lnx to a safe place.

* Open boot.ini in notepad

* Add "XXXX Linux" = c:\bootsec.lnx in the OS list under windows.

Where XXXX is the name of the linux or something witty and anti MS

* Save the file.

* Enjoy.

A few seconds work and thinking intelligently means you can avoid the whole bootsector drama completely and not upset either. I havent met a linux yet this isnt possible to use on.

As i said ive been using this since my first forays into Red Hat and Windows 2000, hasnt failed me yet.

  • 3 months later...

i really didn't understand the first post (i'm new to linux).

i had to reinstall winxp because dual booting Ubuntu corrupted winxp files.

I got it back by:

Boot the livecd.

Start a terminal.

sudo -i

grub

find /boot/grub/stage1 // Will print something like (hd0,1)

root (hd0,1)

setup (hd0)

quit

was easy for me :)

  • 1 month later...

Hi,

  Quote
Boot the livecd.

Start a terminal.

sudo -i

grub

find /boot/grub/stage1 // Will print something like (hd0,1)

root (hd0,1)

setup (hd0)

quit

I already had winxp installed on my PC and have just installed the latest Ubuntu 7.04, immediately upon reboot I received a grub error 22 and nothing booted! Thanks to my PDA net access and this forum I got my windows bootloader back and then have just followed the above info to try and get a boot screen back to be able to choose either winxp or ubuntu but with no joy.

I just tried the above and it all seemed to go ok (no errors within the terminal window), but when I rebooted my PC it just started up straight into windows xp again....!

Help!

  • 2 years later...

For GRUB2 under Ubuntu 9.10 I had to do the following after I broke my bootloader. It kept loading up the memtest after I played around with startupmanager and GRUB2 provided NO menu to choose the kernel :\

  1. Boot via LiveCD
  2. sudo fdisk -l (list hard drives)
  3. sudo mount /dev/sda1 /mnt (mount the hard drive)
  4. sudo mount --bind /dev /mnt/dev (mount other devices)
  5. sudo chroot /mnt (great power comes great responsibility)
  6. gedit /etc/default/grub (this loads up the GRUB2 options)
  7. Change GRUB_DEFAULT=3 to GRUB_DEFAULT= (aka first kernel in grub.cfg, mine was 3 pointing at memtest)
  8. update-grub (this updates that read-only /boot/grub/grub.cfg file)
  9. shutdown -r now (reboots your baby)

That's the procedure that worked for me, I have a single hdd with no special partitioning (just default installed).

All the above is broken down from the Wiki Grub2 page.

  • 5 years later...

Speaking of bootloaders!

 

I opted out from using GRUB (or other chain loaders) and use the EFI stub in the Linux kernel and then use efibootmgr to add the kernel and the parameters as a boot entry. I don't find a reason to load a bootloader which then loads the OS when you can make UEFI load the OS directly.

If the kernel gets damaged or you screw up the parameters then you can use the EFI shell (comes with the board) to manually load the kernel.

 

What I do is:

  Quote

 

efibootmgr -b 0000 -d /dev/sda -p 1 -c -L "Arch Linux EFI stub" -l /vmlinuz-linux -u "root=UUID=3e65a7c4-0a24-44d5-aeeb-e6da72343a34 rootfstype=btrfs rootflags=ssd,discard,noatime,space_cache,compress=lzo,autodefrag,subvol=archrootfs rw quiet initrd=/initramfs-linux.img"

The 0000 is the boot entry in the UEFI boot entry list index. The boot order can be chosen with efibootmgr. I only have two entries, 0000 and 0002 (EFI shell).

The EFI system partition is partition 1 (-p 1, which is default) on HD 0 (-d /dev/sda) and is mounted at /boot in the OS. Add the custom text and then tell it which file to load (-l /vmlinuz-linux).

You can't overwrite a boot entry so you have to delete the entry first. Not specifying the list index ("bootnum") and using the -c option (create) will make it create a new entry at a unused index.

I would highly recommend this if you don't have a lot of operating systems to boot or non-UEFI compliant operating systems. Sure, having custom boot entries for failsafe or recovery modes won't be there but you can create entries for those too or even create shell commands that you can use in the EFI shell. The wiki for Arch Linux covers this subject and works on all kernels that has the EFI stub compiled into it.

 

Requirements: GPT on the drive and a UEFI system patition (a minimum 100MB or more depending on the size of the kernel(or kernels you want to load) and the standard says that it SHOULD be the first partition on the disk.

 

BTW: Don't mind the autodefrag root mount option, it only defrags metadata, it removes dead meta data, moves meta data etc, and does not do actual sector defragmentation.

  • Brandon H unpinned this topic
This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • Would you be open to allowing users to ignore/block staff/moderators here? When trying to do so now, you cannot add a mod/global mod to your ignore/block list. Curious why this is setup this way, is there any way around this?
    • If youre going to delete my comment from this thread, calling out your poor attitude, you should also remove this comment.
    • Is there any reason to think that an updated version of Linux is any less secure than Windows 11? If a govt has 30,000 PCs that won't support Win 11, then the choices are to remain on Win 10 with no security support, throw all 30,000 PCs in a landfill and buy new hardware and software, or keep the hardware and deploy open source software. Option #1 is obviously the worst. Option #2 probably costs $100s of millions and a great deal of e-waste. Option #3 is a matter of software support and personnel learning curve. This one isn't that hard to solve and it comes with a massive financial reward. Since France figured it out, so can anybody.
    • Some ewoks are Wonka's employees eyewitnessing dung
    • Windows 11 gets improved context menus, seconds for calendar clock, and more in new builds by Taras Buria Microsoft is finishing this week with two more builds for Windows Insiders in the Dev and Beta Channels. If you are in the former, you can download 26200.5651, while the latter received 26120.4441. These updates introduce some welcome improvements for context menus, calendar clock, Recall, Settings app, and more. Starting with Copilot+ PCs, users with Snapdragon-powered PCs (Intel and AMD support is coming soon) can try the new agent in Settings. You can type what you would like to change into the Settings app's search box, and the agent will do it for you. For example, you can say something like "my mouse pointer is too small," and the app will show you suggestions and offer to adjust settings on your behalf. Note: This feature is only available in the Dev build. In the European Economic Area, Recall now prompts users to save a unique code, which is required for exporting snapshots to share them with third-party apps or websites. This code is shown only once during the initial setup experience, so be sure to save it in a reliable place. Note: Today's updates will reset Recall and all your snapshots. Other Recall improvements (available in all countries where Recall is available) include the ability to reset Recall and all its data, a new default value for maximum storage duration (90 days instead of unlimited), and various tips to help you learn about Recall features. Microsoft is also introducing new features for Click to Do. You can now send text or images to Microsoft 365 Copilot. Click to Do can now let you take actions on an email address to schedule meetings or send messages in Teams. Next, we have a much-requested feature coming from Windows 10 to 11: Seconds for the calendar clock. The clock that appears in the calendar flyout can now display seconds if you want it to. Note that, unlike Windows 10, this feature is customizable: you can toggle seconds on or off in date and time settings. Here are other noteworthy changes in builds 26200.5651 and 26120.4441: Context menus now have dividers for common file actions When sharing files with OneDrive, Windows will offer additional sharing options like Nearby Sharing or third-party apps. Windows activation and expiration dialogs now feature modernized visuals. And here is what was fixed (these are rolling out gradually): [Recall (Preview)] The following fixes are rolling out for Recall on Copilot+ PCs: Fixed an issue causing Recall to crash for some Insiders in the last couple flights. [File Explorer] Fixed an issue when opening folders starting from outside of File Explorer, where File Explorer would open it in a new tab, but the tab wasn’t put in focus. Fixed a memory leak impacting some people when navigating through File Explorer folders, impacting performance and reliability over time. We’ve done some more work to improve the performance of extracting archive files – this will particularly help in the case of copy pasting large numbers of files out of large 7z or .rar archives. [Start menu] Fixed an issue for Insiders with the new Start menu, where it was displaying in the wrong direction when using an Arabic or Hebrew display language. Fixed an issue for Insiders with the updated Start menu, where the Move to front / Move right / Move left options from the context menu for pinned apps weren’t working. [Settings] Fixed an underlying issue which was causing some Insiders to see the Settings navigation pane entries in English rather than their preferred language in the last couple flights. [Other] Fixed an underlying issue which was causing fonts in certain app menu items to unexpectedly appear corrupted or overlapped for some people. This also impacted typing in Word – where when using Hebrew a period may unexpectedly show as a 3, and in Thai typing space may show a 2. Fixed an issue where running a script on a remote SMB share might take an unexpectedly long time if the share was an older Windows Server version like Windows Server 2019. And here is the list of known issues: [General] After you do a PC reset under Settings > System > Recovery, your build version may incorrectly show as Build 26100 instead of Build 26120. This will not prevent you from getting future Beta Channel updates, which will resolve this issue. The option to reset your PC under Settings > System > Recovery will not work on this build. Some Windows Insiders may experience a rollback trying to install this update with a 0x80070005 in Windows Update. We’re working on a fix. [Start menu] The following are known issues for Windows Insiders with the new Start menu: Using touch to navigate the new Start menu may not work reliably. For example, it currently does not support the swipe-up gesture. Drag and drop capabilities are limited from “All” to “Pinned.” In some cases, duplicate entries may appear in folders on the Start menu. [Xbox Controllers] Some Insiders are experiencing an issue where using their Xbox Controller via Bluetooth is causing their PC to bugcheck. Here is how to resolve the issue. Open Device Manager by searching for it via the search box on your taskbar. Once Device Manager is open, click on “View” and then “Devices by Driver”. Find the driver named “oemXXX.inf (XboxGameControllerDriver.inf)” where the “XXX” will be a specific number on your PC. Right-click on that driver and click “Uninstall”. [Click to Do (Preview)] The following known issues will be fixed in future updates to Windows Insiders: Windows Insiders on AMD or Intel™-powered Copilot+ PCs may experience long wait times on the first attempt to perform intelligent text actions in Click to Do after a new build or model update. [Improved Windows Search] [REMINDER] For improved Windows Search on Copilot+ PCs, it is recommended that you plug in your Copilot+ PC for the initial search indexing to get completed. You can check your search indexing status under Settings > Privacy & security > Searching Windows. [File Explorer] The following are known issues for AI actions in File Explorer: Narrator scan mode may not work properly in the action result canvas window for the Summarize AI action for Microsoft 365 files when reading bulleted lists. As a workaround, you can use Caps + Right key to navigate. [Widgets] Until we complete support for pinning in the new widgets board experience, pinning reverts you back to the previous experience You can find the announcement post here (Dev) and here (Beta).
  • Recent Achievements

    • First Post
      NeoToad777 earned a badge
      First Post
    • Week One Done
      JoeV earned a badge
      Week One Done
    • One Month Later
      VAT Services in UAE earned a badge
      One Month Later
    • First Post
      LsDmT earned a badge
      First Post
    • Week One Done
      evershinefacilityservice earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      573
    2. 2
      ATLien_0
      251
    3. 3
      +Edouard
      162
    4. 4
      +FloatingFatMan
      150
    5. 5
      Michael Scrip
      113
  • Tell a friend

    Love Neowin? Tell a friend!