Posted by Steve on Thu 24 Aug 2006 at 11:39
mount is a command which most people take for granted, once they've mounted their local filesystems it doesn't get used very often. Recently I've come to appreciate one of the more unusual mount facilities; the ability to mount something in multiple locations.
As we recently saw it is possible to install Debian via debootstrap, and this works nicely for most things.
However if you were to boot a system using Knoppix, or similar, and attempt to install a new machine with debootstrap you'll soon realise that guide isn't complete - your new system has no kernel installed and is also missing a bootloader.
How do we fix this? Well the solution is very simple, we use chroot to change our root into the new installation, then we can use apt-get to install a kernel.
The process would look something like this:
# chroot /target # apt-get update # apt-get install kernel-image-2.6.8-3-686 # apt-get install grub
(Note: The kernel you install will depend upon which distribution of Debian you're working with, and upon your architecture.)
Now we're almost at a point where we have a real installation, the only thing remaining is that we've still to configure the bootloader.
There are a couple of steps to this if you're installing grub like this:
It is that last step which reintroduced me to using mount. For the first to steps you should be able to just run this:
# mkdir -p /boot/grub # cp /lib/grub/i386-pc/* /boot/grub # $EDITOR /boot/grub/menu.lst
The contents of the menu.lst file will vary depending on what you're using, for me I used:
title Debian GNU/Linux, kernel 2.6.16-2-k7 root (hd0,1) kernel /boot/vmlinuz-2.6.16-3-686 root=/dev/sda2 ro initrd /boot/initrd.img-2.6.16-3-686
Now we need to use the grub interactive installer, and you'll discover that it won't run properly because the system does not have a fully-populated /dev directory - so grub cannot discover the device(s) to use.
(In my case I was relying upon the /dev directory being setup dynamically when the new system booted, so having it be missing on the newly installed debootstrap system wasn't a problem.)
The solution? Exit the chroot and make the /dev directory of the host available to the chroot using the bind option:
# mount --bind /dev /target/dev # mount --bind /proc /target/proc
Now if you return to the system, via "chroot /target", you can see /dev as you'd expect. The same directory is available in two locations without any symlinks or other complications!
Completing the setup with grub now becomes a simple job:
# grub grub> grub> device (hd0) /dev/sda grub> root (hd0,1) grub> setup (hd0) grub> quit
(Note: Any setup of your own will use different devices/hd-strings. This is just a simple example.)
"mount --bind" is really just a shortcut for "mount .... -o bind", but it is a useful one.
There are probably a lot of uses for the --bind option which I've not yet discovered, but this one was good enough.
This article can be found online at the Debian Administration website at the following bookmarkable URL:
This article is copyright 2006 Steve - please ask for permission to republish or translate.