Search code examples
mountmkdirbusyboxinitramfs

mkdir and mount in initramfs


I am writing an initramfs, executed in busybox, in which I mount a partition using those commands:

/bin/busybox mount -n -t proc proc /proc
mount -n -t devtmpfs devtmpfs /dev
mount -n -t sysfs sysfs /sys
mount -n -t tmpfs inittemp /mnt
mkdir /mnt/saved
mount -n -t "${rootfstype}" -o "${rootflags}" ${device} /mnt/saved

But when the system starts up, I have this error:

mount: mounting /dev/mmcblk0p2 on /mnt/saved failed: No such file or directory

I know that when the device is not found, there is a message like Device does not exist, so I think the problem is coming from the directory /mnt/saved that is not correctly created yet.

I tried adding an ls -l /mnt after the mkdir to check that the directory is correctly created, but most of the time, if I do so, the error disappears. So I though the problem might be synchronization problem (of the tmpfs, weird!) So I tried some other things like creating a dummy file in the directory to force a kind of synchronisation. This works, but is a dirty workaround and I want to find the real cause of the problem to build a clean solution.


Solution

  • By the time I was writing my question, I finally found the solution by myself… I post it anyway just in case somebody is stuck like me.

    Actually, the mount command of busybox does not show a message about device, if it cannot find it, but always show No such file or directory.

    My problem was actually coming from the root device which was not ready yet, and so not in the /dev directory yet. In order to make it work correctly, I simply added this line before the mount:

    while ${rootwait} && ! [ -b "${device}" ]; do sleep 1; done