måndag 29 april 2013

Enabling a bridge interface when you're on nfs root

When you enable a bridge interface with brctl from bridge-utils you loose network connectivity for a short while. This means trouble if you use nfs root or something that needs to have network to load the next command,  or acces other files or directories.

Here's what to do.  Warning!  Understand what you do. If you are working logged in remotely and it screws up, you'll have to reboot the machine, because it has lost its access to the nfs root file system!

Anyway, here we go:

We must create a small rootfs on a directory that is not nfsrooted such as a tmpfs (a ram-based file system), there is often one mounted already. Look for one with mount.

I have a tmpfs mounted at /run.  I notice that it is mounted as 'noexec' which means that I can't run commands from it.  To solve that, remount it with the exec option set.
Then make a root dir called /run/root  for instance.
Then copy over /lib and /bin  (we don't need all of it, but we're lazy, remember!).
Put the stuff we need to do in a script file in the temp root, and then execute it from a chroot with busybox (or sh if you have put everything you need into the chroot).  Make sure that you actually have busybox.

Here is what I have in my script (https://gist.github.com/anonymous/5480567):