using switch_root from initfamfs ( switch_root: error moving root)

E Robertson e.robertson.svg at gmail.com
Tue Apr 21 14:05:01 UTC 2009


On Mon, Apr 20, 2009 at 7:30 PM, Denys Vlasenko
<vda.linux at googlemail.com> wrote:
> On Monday 20 April 2009 22:45, E Robertson wrote:
>> Hi all,
>> During an initramfs filesystem boot I created a /tmp/root and mount it
>> as tmpfs to which I copy some new files to.
>> I then did:
>>
>>     umount -l /proc
>>     umount -l /sys
>>     exec switch_root -c /dev/console /tmp/root /sbin/init
>>
>> but then I got:
>> switch_root: error moving root
>> Kernel panic - not syncing: Attempted to kill init!
>>
>> In looking through the switch_root.c I see that the contents of "/" is
>> deleted and I'm wondering to what extent.
>
> static void delete_contents(const char *directory, dev_t rootdev)
> ...
>        // Don't descend into other filesystems
>        if (lstat(directory, &st) || st.st_dev != rootdev)
>                return;
>
>
>> Do that mean that all directories under "/" is deleted? If so, that
>> means that all of the /dev devices ahould be deleted.
>
> And why is this a problem?
>
>> Since mounting to a /dev/mtd device has worked for me in the past I
>> doubt "everything" is "everything". is this correct?
>>
>>       // Zap everything out of rootdev
>>
>>       delete_contents("/");
>>
>>       // Overmount / with newdir and chroot into it.  The chdir is needed to
>>       // recalculate "." and ".." links.
>>
>>       if (mount(".", "/", NULL, MS_MOVE, NULL) || chroot("."))
>>               bb_error_msg_and_die("error moving root");
>>       xchdir("/");
>
> Replace  bb_error_msg_and_die  with  bb_perror_msg_and_die  -
> it will print error code.
>>
>> Is the problem because I'm switching to another tmpfs root system? (in
>> that all of /tmp is deleted?)
>
> It should not be, because /tmp/root is on a different filesystem.
>
> But even if it will be, mount should succeed
>
>> /tmp/root is mounted with -t tmps tmpfs /tmp/root
>> and /tmp is also mounted as tmpfs. Should this be a problem?
>
>

Apparently  it doesn't like the /sbin/init at the end I get
switch_root: error moving root: Invalid argument

However, with just exec switch_root -c /dev/console /tmp/root
 or
exec switch_root  /tmp/root
I'm having problems mounting the root:
Kernel panic - not syncing: Attempted to kill init!

The same filesystem I use for my Initramfs is the same file system I
used to change into so I don't think that's it.
Anyone has any ideas what I might be missing here? I've done this with
no problems before but only with mtd devices but not sure what I might
be doing wrong.
Thanks.


More information about the busybox mailing list