AutoFsck - Technical Review

Krzysztof Lichota krzysiek at lichota.net
Fri Aug 22 10:34:02 BST 2008


2008/8/21 Phillip Susi <psusi at cfl.rr.com>:
> You chroot() to a subdirectory of the cwd, then you can chdir("..") to
> escape.  Once you chdir to the real root you chroot(".").

OK, but how to get to rootfs? In my /proc/mounts it is overmounted on
"/", so it is not visible. I have tried to mount it in some other
directory using "mount -t rootfs none /rootfs" but it fails.

>> Unlink in the sense of "rm"?
>
> Yes.  The real root filesystem is a tmpfs populated by unpacking the
> initramfs, so the last thing the init scripts do is unlink all of the
> files, chroot, and exec the real init on the real filesystem, which then
> frees up all of the memory used to hold the files from the initramfs
> once the last reference is dropped.

OK. Smart :)

> Once you get back to the real real rootfs ( in ram ), place your
> executables there, and exec them,

Yes, this is obvious, the hard part is switching back to rootfs :)

> there are no more references to files
> in the on disk root so you just umount /root ( where the init scripts
> mounted it initially ).

Do you mean I should modify init scripts to do stuff after chroot to
disk root? I.e. in init on rootfs:
...
mount /dev/sda /root
chroot /root /sbin/init
umount /root
...do my stuff...

Or in real system:
mount_somehow_rootfs
copy my files to rootfs
chroot /rootfs /sbin/fsck_on_shutdown
And in /sbin/fsck_on_shutdown
umount /root
...do my stuff...

BTW. Thanks for explanations :)

-- 

	Krzysztof Lichota



More information about the ubuntu-devel mailing list