Why bind to LiveCD /proc before building initramfs ?

Imagine I have an unbootable system where I need to update the kernel image using

update-initramfs

.

I have seen numerous examples online which show the following

$ mount -t proc none /mnt/ubuntu/proc
$ mount -o bind /dev /mnt/ubuntu/dev
$ mount -o bind /sys /mnt/ubuntu/sys

After that we chroot into the broken OS and then execute the command to update the initramfs.

My questions are as follows-:

  1. Are we binding the /proc and /dev of the Live CD to the broken system ? Or are we binding the /proc and /dev of the broken system to the live cd ?
  2. If building the initramfs is dependent on the information of the OS for which the initramfs is built then won't it contain erroneous information if we build for the Live CD ? That is use the /proc and /dev of the LiveCD ?

Neither. The Live CD booted from has no writable media so is useless for doing any real work. So a 'proc' filesystem is created in memory, and system directories on the booted Live CD are mapped (bind) into memory.

Any idea what the answer will be for my second question ? I am really stumped with that one.

Technically, the 'initramfs' on the 'Live CD' should contain ALL common drivers and load modules needed for commonly found hardware and therefore should run on your box (unless you loaded third-party driver(s) at install time). Therefore, once up and running, the O/S recovery function can probe your hardware and check that the required drivers are installed and uncorrupted. The recovery function should/probably/hopefully only check for the really required drivers for your platform.

So let me get this straight. What you are saying is that 90% percent of the using the /proc and /dev of the LiveCd will not cause any problems because they are very similar to the original system that I will boot into.

Am I correct in my assumption ?

I think that I understand your question. The 'Live CD' contains all commonly required drivers but those drivers are only loaded if the hardware is actually present. The 'Live CD' is designed so that it can boot on almost all hardware without extra drivers.

Neither. /dev and especially /proc are virtual filesystems, which don't show files but rather imaginary kernel things.

So they're neither livecd, nor your broken system, but something belonging to whatever kernel you're running.

These kernel / device interfaces are pretty hard for a system to do without.

It doesn't so much archive them as use them.

2 Likes

So what you mean is that it does not store any information after the command has been executed, right ? It is just used when the command is executed ?

If I am correct in my above assumption, then could you please give me an example on what that information may be like. Normally, if you need some information to perform an operation, it is required again during another execution of the same operation.

Like if update-initramfs generates using the information from a 3.0x kernel and the actual operating system that will use that is a 2.4x kernel, will that initrd still work ?

It is certainly not archiving the contents of /proc. It's important that the dir exists and has the right permissions.

It might archive a tiny, minimal portion of /dev - just basic device files like /dev/console necessary for a system to boot.

Mostly, I think, what's happening is tricking it into building it from the given kernel instead of the running one.