using switch_root from initfamfs ( switch_root: error moving root)

Denys Vlasenko vda.linux at googlemail.com
Tue Apr 21 20:01:55 UTC 2009


On Tuesday 21 April 2009 16:05, E Robertson wrote:
> >>       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

        if (mount(".", "/", NULL, MS_MOVE, NULL))
                bb_perror_msg_and_die("error moving root");

This means that "." is not a mountpoint, but merely a subdirectory.

> 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!

No, it's just the result of process 1 exiting. Kernel does not like that.
The real error is reported in the previous line.

> 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.

Bingo. switch_root assumes that new root is a different filesystem.
It even checks for that here:

        xchdir(newroot);
        if (lstat(".", &st1) || lstat("/", &st2) || st1.st_dev == st2.st_dev) {
                bb_error_msg_and_die("bad newroot %s", newroot);
        }
bb_error_msg("1:%llx 2:%llx", (long long) st1.st_dev, (long long) st2.st_dev);
        rootdev = st2.st_dev;

I am surprised it did not trigger for you. Please add bb_error_msg("1:%llx...
line as shown above and let me know what do you see?


--
vda


More information about the busybox mailing list