On Friday, August 2, 2019, 阿保 純一 <abo_junghi...@yahoo.co.jp> wrote: >> Speaking of, since we are now overmounting the root before zapping the >> initramfs, I wonder if we can remove one check about whether the new root >> is a mount point (this saves code size; mount() would fail with EINVAL in >> that case). > At least, I must check other mount points. > For example, below is the init-script I'm using in initramfs. > > #!/bin/sh > mount -t vfat /dev/sda2 /disk > mount -o loop,ro -t squashfs /disk/squash.img /base > mount -o loop -t xfs /disk/xfs.img /vary > mount -o lowerdir=/base,upperdir=/vary/rootfs,workdir=/vary/work \ > -t overlay overlay /root > mount --move /disk /root/initfs/disk > mount --move /base /root/initfs/base > mount --move /vary /root/initfs/vary > my_standalone_switch_root -c /dev/tty1 /root /sbin/init > > I think switch_root in busybox is written already so dense, so every it's check-codes treats not only the new-root but also other storages. >
What I suggested is to remove these lines: if (st.st_dev == rootdev) { // Show usage, it says new root must be a mountpoint bb_show_usage(); } Because mount(..., MS_MOVE) will do the same check before moving the mount point, and the check would be done before deleting anything if your patch is applied. (And there is no point to show the program usage when it's already PID 1. You would rather see error message of what specifically goes wrong. The kernel will panic when PID 1 dies, leaving you no option but reboot.) The delete_contents() function in switch_root.c already prevents itself from deleting files of other filesystems.
_______________________________________________ busybox mailing list busybox@busybox.net http://lists.busybox.net/mailman/listinfo/busybox