Linux – What are these commands for

grub2linuxmount

Yesterday I had to install a Windows with its Grub override.

Well, it's not the first time I had to fix Grub, so I used LiveCD, mounted the root partition (I don't have boot, just / and home) and ran grub-install --root-directory=/mnt/ /dev/sda. However, it didn't work.

After Googling a while I found a tutorial in which instead of just mounting the Linux partition, he also did mount --bind /mnt/dev /dev and mount --bind /mnt/proc /proc/. After that chroot to /mnt and then installed Grub, and using this method, it worked.

What are the mount --bind commands for? I'm familiar with the usage of --bind used (man page) but I do not know why it was used on this example.

Best Answer

proc and sys filesystems are provided by the running kernel -- when the kernel is not running, they cease to exist. This means that when you chroot into another operating system, these filesystems are not present. Many programs expect them to exist so that they can function, for example, they may require information about the running system, or want to modify the way the kernel handles something. It is often enough simply to provide /proc and /sys from the current kernel for these programs to work as expected.

A symlink would not suffice, as the act of chrooting would invalidate the file paths used. In Linux, you also cannot hard link directories (other than . and .., as provided by mkdir). This means that a third option has to be used to mirror these filesystems to the chrooted environment -- bind mounting. A bind mount is provided by the kernel directly, and works as expected within a chroot.

Related Question