DebianThis forum is for the discussion of Debian Linux.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I've got a Thinkpad laptop that is loaded with WinXP/Debian8. in the process of adding FreeBSD to the mix, the grub bootloader was replaced by FreeBSD's boot loader 'boot0cfg', and it doesn't detect Linux partition and I can no longer boot into Debian.
i tried to reinstall grub by using both 'netinstall' and full image of Debian8 installation.
with 'netinstall', I can get to 'rescue mode'(under 'Advanced option' on the main menu), but it returns error about not detecting a valid kernel image.
on full image (live cd version), it doesn't list rescue under 'Advanced Option' at main menu.
which image file contains 'rescue mode' so I can recover the debian bootloader?
NOTE: The advice below presumes that Debian is not installed in EFI-mode.
Load up a live ISO and use these commands to chroot into your system from the live environment:
Code:
# mkdir /target
# mount /dev/sdXY /target
# for i in /sys /proc /dev; do mount --bind $i /target$i; done
# chroot /target /bin/bash
# source /etc/profile
# grub-install /dev/sdX
# update-grub
Replace "X" with the drive letter assigned to your Debian HDD and replace "Y" with the partition number of your root partition.
If you have a separate /boot partition, you will have to mount that as well before running the `chroot` command (and after you mount the root partition).
Code:
# mount /dev/sdXZ /target/boot
Where "Z" is the partition number of your /boot partition.
You will have to write a custom menu entry for FreeBSD -- add this to the end of the file at /etc/grub.d/40_custom
Code:
menuentry 'FreeBSD {
set root='(hdX,A)'
chainloader +1
}
Replace "A" with the partition containing your FreeBSD system and use `update-grub` to add the custom entry to your GRUB menu.
If you have a separate /boot partition, you will have to mount that as well before running the `chroot` command (and after you mount the root partition).
Code:
# mount /dev/sdXZ /target/boot
Where "Z" is the partition number of your /boot partition.
here's the partition info by 'fdisk' and output of os-prober(before I installed 'boot0cfg' and can still boot into Debian). Master boot record is on windows partition. Does this mean /boot partition is 'sda1' and I need to mount it before 'chroot'?
Code:
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x9f114bc6
Device Boot Start End Sectors Size Id Type
/dev/sda1 63 62929439 62929377 30G 7 HPFS/NTFS/exFAT
/dev/sda2 * 106027047 143775701 37748655 18G a5 FreeBSD
/dev/sda3 143806320 156295439 12489120 6G c W95 FAT32 (LBA)
/dev/sda4 62930942 106027007 43096066 20.6G f W95 Ext'd (LBA)
/dev/sda5 62930944 82460671 19529728 9.3G 83 Linux
/dev/sda6 82462720 85053439 2590720 1.2G 82 Linux swap / Solaris
/dev/sda7 85055488 106027007 20971520 10G 83 Linux
Partition table entries are not in disk order.
erdos@debian:~$ os-prober
unshare failed: Operation not permitted
rm: cannot remove ‘/var/lib/os-prober/labels’: Permission denied
erdos@debian:~$ sudo os-prober
/dev/sda1:Microsoft Windows XP Professional:Windows:chain
/dev/sda3:Windows NT/2000/XP:Windows1:chain
erdos@debian:~$
erdos@debian:~$
success! first part works flawlessly, I got 'grub' back and now I'm in Debian typing this message.
Code:
# mkdir /target
# mount /dev/sda5 /target
# for i in /sys /proc /dev; do mount --bind $i /target$i; done
# chroot /target /bin/bash
# source /etc/profile
# grub-install /dev/sda
# update-grub
second part generates error, here's my /etc/grub.d/40_custom:
Code:
menuentry 'FreeBSD {
set root='(hda,2)'
chainloader +1
}
error while run 'update-grub'
Code:
erdos@debian:~$ sudo update-grub
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-3.16.0-4-amd64
Found initrd image: /boot/initrd.img-3.16.0-4-amd64
Found Microsoft Windows XP Professional on /dev/sda1
Found unknown Linux distribution on /dev/sda2
Found Windows NT/2000/XP on /dev/sda3
error: out of memory.
error: syntax error.
error: Incorrect command.
error: syntax error.
Syntax error at line 216
Syntax errors are detected in generated GRUB config file.
Ensure that there are no errors in /etc/default/grub
and /etc/grub.d/* files or please file a bug report with
/boot/grub/grub.cfg.new file attached.
done
erdos@debian:~$
second part generates error, here's my /etc/grub.d/40_custom:
Code:
menuentry 'FreeBSD {
set root='(hda,2)'
chainloader +1
}
I did say to add that to the end of40_custom -- you need these lines at the top of the file:
Code:
#!/bin/sh
exec tail -n +3 $0
# This file provides an easy way to add custom menu entries. Simply type the
# menu entries you want to add after this comment. Be careful not to change
# the 'exec tail' line above.
If it still doesn't work, you should probably mark this thread [SOLVED] and start a new thread about adding a FreeBSD entry to GRUB2.
I used to have a FreeBSD system booting from GRUB but it's gone now and I can't remember exactly what I used to create the entry.
EDIT: Also, it should be "set root='(hd0,2)'" rather than '(hda,2)'
Last edited by Head_on_a_Stick; 06-12-2015 at 04:28 PM.
that's correct, i appended the menuentry to the end of /etc/grub.d/40_custom.
Code:
#!/bin/sh
exec tail -n +3 $0
# This file provides an easy way to add custom menu entries. Simply type the
# menu entries you want to add after this comment. Be careful not to change
# the 'exec tail' line above.
menuentry 'FreeBSD {
set root='(hd0,2)'
chainloader +1
}
the update-grub returned the same error when i use 'set root='(hd0,2)'
I've marked the thread solved, thanks a lot for the help!
after i put freebsd in between double quotation " ", 'update-grub' runs without error. upon reboot, freebsd appears in grub and I can boot into it as well.
Code:
menuentry "FreeBSD" {
set root='(hd0,2)'
chainloader +1
}
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.