Posts tagged grub2

linux: chroot and reinstall grub2
posted on 2015-10-02 01:53:04

First, while in the live disk (i.e. grml) you just booted, mount everthing to a folder, which will be the chroot root. I.e. ~/asdf.

mkdir asdf
mount /dev/sda1 asdf
cd asdf

After cd'ing into there you have to mount some special folders:

  • /proc
  • /sys
  • /dev
  • /dev/pts
  • /run

Like this:

mount  -t      proc   proc       ./proc
mount  -t      sysfs  sys        ./sys
mount  --bind         /dev       ./dev
mount  -t      devpts devpts     ./dev/pts
mount  --bind         /run       ./run

Possibly you need to mount /boot and /boot/efi, too, if your boot partition is separate and if you have a UEFI setup.

followed by:

chroot .

Should you use a grml live disk and it is complaining about a missing zsh shell:

chroot . /bin/bash

Then reinstall grub:

<!-- grub2-install --recheck --no-floppy /dev/sda -->
<!-- grub2-mkconfig -o /boot/grub2/grub.cfg -->
<!-- mkinitrd -->
grub-install /dev/sda

Exit the chroot and reboot.

grub2: Windows boot entry fix
posted on 2015-02-10 17:57:13

If you have linux along with windows installed on different partitions, and you somehow manage to lose your windows boot entry, try the following.


Either edit /etc/grub.d/40_custom, or if the file does not exist, create a new one. Prefix it with a number you like, it will let grub decide where the boot menu entry will appear. If put into the 40_custom, it will appear on the end of the boot menu.

There add this:

menuentry "Windows" {
set root=(hd0,3)
chainloader +1

Then issue the command update-grub in the shell (which should be aliased to update-grub2, in case you wondered), to update the /boot/grub/grub.cfg. Else your changes will not have any effect.

It is however EXTREMELY likely, that hd0,3 from above will not work in your case. More on this later on.

So reboot, and try booting the new entry.


As menuentry chose whatever you like, that is just the string which will appear in the menu.

set root=... decides which partition will be loaded.
chainloader +1 tells grub to chainload the next bootlader from there if one is present, starting on the first block of the partition, IIRC, no warranty on that. It is basically the same as chainloader 0+1, for more info on the block list syntax see here.

If it won't work reboot again, and press 'e' to edit the boot entry. Choose another harddisk or partition until you 'hit ground'. (hd0,1) is for example the first harddisk, with its first partition which will be tried. From there, the numbers are simply incremented. If this is information overflow, it is more condensed int the grub manual. If you use NTFS on the windows partion, you might also try the insmod chain and insmod ntfs commands from the last link.

troubleshooting and finding the correct harddisk and partition

boot a linux for setup inspection

Use a linux (either the installed one if it still boots or a boot stick), and have a look at your existing partitions via either fdisk -l or parted, if you want to du further troubleshooting. An idea would be to search which partition was intended to be the windows boot partition (hint: it should be around 100MB in size), remember the number, it might help you.

use grub to identify the partitions

Also you can use grub's shell to list all possible harddisk/partition combos. Just boot into grub2, hit 'c' to enter the console and do ls.

This will show you something like this:

grub> ls
(hd0,msdos6) (hd0,msdos5) (hd0,msdos4) (hd0,msdos3) (hd0,msdos2)

These are all the partitions you can try, either by editing the grub configs in /etc/grub.d, or when editing the menu entries directly when in grub and hitting 'e' when having chosen your just created entry.

FreeBSD/PFSense via Grub2
posted on 2014-05-23 17:21:18

After installing PFSense (which is based on FreeBSD) on a dedicated machine for firewalling, a debian install was decided to be set up along with it. This should enable shorter setup times in case PFSense would not suffice: Just boot debian and fix the firewall via iptables in /etc/init.d/firewall.

Long story short, after the debian install and the grub, PFSense was lacking a boot entry. (Who would have guessed.)

Output of fdisk -l from within debian gave this:

Disk /dev/sja: 4011 MB, 4011614208 bytes
16 heads, 63 sectors/track, 7773 cylinders, total 7835184 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x90909090

    Device  Boot      Start         End      Blocks     Id  System
/dev/sda1     *          63     1639999      818968+    a5  FreeBSD
/dev/sda2           1638000     7835183     3098592     83  Linux

So the first partition has the PFSense on it.

Putting the lower part of this into /etc/grub.d/40_custom in debian did the trick:

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 "PFSense" {
    # discern partition name easiest via grub shell
    set root=(hd0,1)
    chainloader +1
    # instead of `chainloader +1`, this should work, too
    #kfreebsd /boot/loader

Do update-grub afterwards, reboot, and be done.

This blog covers .csv, .htaccess, .pfx, .vmx, /etc/crypttab, /etc/network/interfaces, /etc/sudoers, /proc, 10.04, 14.04, AS, ASA, ControlPanel, DS1054Z, GPT, HWR, Hyper-V, IPSEC, KVM, LSI, LVM, LXC, MBR, MTU, MegaCli, PHP, PKI, R, RAID, S.M.A.R.T., SNMP, SSD, SSL, TLS, TRIM, VEEAM, VMware, VServer, VirtualBox, Virtuozzo, XenServer, acpi, adaptec, algorithm, ansible, apache, apachebench, apple, arcconf, arch, architecture, areca, arping, asa, asdm, awk, backup, bandit, bar, bash, benchmarking, binding, bitrate, blackarmor, blowfish, bochs, bond, bonding, booknotes, bootable, bsd, btrfs, buffer, c-states, cache, caching, ccl, centos, certificate, certtool, cgdisk, cheatsheet, chrome, chroot, cisco, clamav, cli, clp, clush, cluster, coleslaw, colorscheme, common lisp, console, container, containers, controller, cron, cryptsetup, csync2, cu, cups, cygwin, d-states, database, date, db2, dcfldd, dcim, dd, debian, debug, debugger, debugging, decimal, desktop, df, dhclient, dhcp, diff, dig, display manager, dm-crypt, dmesg, dmidecode, dns, docker, dos, drivers, dtrace, dtrace4linux, du, dynamictracing, e2fsck, eBPF, ebook, efi, egrep, emacs, encoding, env, error, ess, esx, esxcli, esxi, ethtool, evil, expect, exportfs, factory reset, factory_reset, factoryreset, fail2ban, fbsd, fedora, file, filesystem, find, fio, firewall, firmware, fish, flashrom, forensics, free, freebsd, freedos, fritzbox, fsck, fstrim, ftp, ftps, g-states, gentoo, ghostscript, git, git-filter-branch, github, gitolite, gnutls, gradle, grep, grml, grub, grub2, guacamole, hardware, haskell, hdd, hdparm, hellowor, hex, hexdump, history, howto, htop, htpasswd, http, httpd, https, i3, icmp, ifenslave, iftop, iis, imagemagick, imap, imaps, init, innoDB, inodes, intel, ioncube, ios, iostat, ip, iperf, iphone, ipmi, ipmitool, iproute2, ipsec, iptables, ipv6, irc, irssi, iw, iwconfig, iwlist, iwlwifi, jailbreak, jails, java, javascript, javaws, js, juniper, junit, kali, kde, kemp, kernel, keyremap, kill, kpartx, krypton, lacp, lamp, languages, ldap, ldapsearch, less, leviathan, liero, lightning, links, linux, linuxin3months, lisp, list, livedisk, lmctfy, loadbalancing, locale, log, logrotate, looback, loopback, losetup, lsblk, lsi, lsof, lsusb, lsyncd, luks, lvextend, lvm, lvm2, lvreduce, lxc, lxde, macbook, macro, magento, mailclient, mailing, mailq, manpages, markdown, mbr, mdadm, megacli, micro sd, microsoft, minicom, mkfs, mktemp, mod_pagespeed, mod_proxy, modbus, modprobe, mount, mouse, movement, mpstat, multitasking, myISAM, mysql, mysql 5.7, mysql workbench, mysqlcheck, mysqldump, nagios, nas, nat, nc, netfilter, networking, nfs, nginx, nmap, nocaps, nodejs, numberingsystem, numbers, od, onyx, opcode-cache, openVZ, openlierox, openssl, openvpn, openvswitch, openwrt, oracle linux, org-mode, os, oscilloscope, overview, parallel, parameter expansion, parted, partitioning, passwd, patch, pdf, performance, pfsense, php, php7, phpmyadmin, pi, pidgin, pidstat, pins, pkill, plesk, plugin, posix, postfix, postfixadmin, postgres, postgresql, poudriere, powershell, preview, profiling, prompt, proxmox, ps, puppet, pv, pvecm, pvresize, python, qemu, qemu-img, qm, qmrestore, quicklisp, r, racktables, raid, raspberry pi, raspberrypi, raspbian, rbpi, rdp, redhat, redirect, registry, requirements, resize2fs, rewrite, rewrites, rhel, rigol, roccat, routing, rs0485, rs232, rsync, s-states, s_client, samba, sar, sata, sbcl, scite, scp, screen, scripting, seafile, seagate, security, sed, serial, serial port, setup, sftp, sg300, shell, shopware, shortcuts, showmount, signals, slattach, slip, slow-query-log, smbclient, snmpget, snmpwalk, software RAID, software raid, softwareraid, sophos, spacemacs, spam, specification, speedport, spi, sqlite, squid, ssd, ssh, ssh-add, sshd, ssl, stats, storage, strace, stronswan, su, submodules, subzone, sudo, sudoers, sup, swaks, swap, switch, switching, synaptics, synergy, sysfs, systemd, systemtap, tar, tcpdump, tcsh, tee, telnet, terminal, terminator, testdisk, testing, throughput, tmux, todo, tomcat, top, tput, trafficshaping, ttl, tuning, tunnel, tunneling, typo3, uboot, ubuntu, ubuntu 16.04, udev, uefi, ulimit, uname, unetbootin, unit testing, upstart, uptime, usb, usbstick, utf8, utm, utm 220, ux305, vcs, vgchange, vim, vimdiff, virtualbox, virtualization, visual studio code, vlan, vmstat, vmware, vnc, vncviewer, voltage, vpn, vsphere, vzdump, w, w701, wakeonlan, wargames, web, webdav, weechat, wget, whois, wicd, wifi, windowmanager, windows, wine, wireshark, wpa, wpa_passphrase, wpa_supplicant, x2x, xfce, xfreerdp, xmodem, xterm, xxd, yum, zones, zsh

View posts from 2017-02, 2017-01, 2016-12, 2016-11, 2016-10, 2016-09, 2016-08, 2016-07, 2016-06, 2016-05, 2016-04, 2016-03, 2016-02, 2016-01, 2015-12, 2015-11, 2015-10, 2015-09, 2015-08, 2015-07, 2015-06, 2015-05, 2015-04, 2015-03, 2015-02, 2015-01, 2014-12, 2014-11, 2014-10, 2014-09, 2014-08, 2014-07, 2014-06, 2014-05, 2014-04, 2014-03, 2014-01, 2013-12, 2013-11, 2013-10

Unless otherwise credited all material Creative Commons License by sjas