Sample Header Ad - 728x90

Failed to umount oldroot after `pivot_root` and `chroot` in Linux

0 votes
1 answer
69 views
I am working on an embedded Linux system (kernel-5.10.24), and busybox as init. I created 2 rootfs partitions in system, I want to use pivot_root and chroot to change rootfs between them. When the system firstly bootup, the mount showed.
# mount
ubi0:rootfs on / type ubifs (rw,relatime,assert=read-only,ubi=0,vol=0)
devtmpfs on /dev type devtmpfs (rw,relatime,size=42008k,nr_inodes=10502,mode=755)
proc on /proc type proc (rw,relatime)
tmpfs on /tmp type tmpfs (rw,relatime)
tmpfs on /run type tmpfs (rw,nosuid,nodev,relatime,mode=755)
sysfs on /sys type sysfs (rw,relatime)
devpts on /dev/pts type devpts (rw,relatime,mode=600,ptmxmode=000)
tmpfs on /dev/shm type tmpfs (rw,relatime)
Now, I mounted 2nd rootfs into /mnt, then I run pivot_root and chroot.
# mount -t ubifs /dev/ubi1_0 /mnt/
# cd /mnt
# pivot_root . oldroot
# chroot . sh
# umount /oldroot
umount: can't unmount /oldroot: Device or resource busy
I mount proc after pivot_root and chroot, and mount showed.
# mount -t proc proc /proc
# mount
ubi0:rootfs on /oldroot type ubifs (rw,relatime,assert=read-only,ubi=0,vol=0)
devtmpfs on /oldroot/dev type devtmpfs (rw,relatime,size=42008k,nr_inodes=10502,mode=755)
proc on /oldroot/proc type proc (rw,relatime)
tmpfs on /oldroot/tmp type tmpfs (rw,relatime)
tmpfs on /oldroot/run type tmpfs (rw,nosuid,nodev,relatime,mode=755)
sysfs on /oldroot/sys type sysfs (rw,relatime)
devpts on /oldroot/dev/pts type devpts (rw,relatime,mode=600,ptmxmode=000)
tmpfs on /oldroot/dev/shm type tmpfs (rw,relatime)
/dev/ubi1_0 on / type ubifs (rw,relatime,assert=read-only,ubi=1,vol=0)
proc on /proc type proc (rw,relatime)
I checked the comments and answer of https://unix.stackexchange.com/questions/306406/unable-to-umount-after-pivot-root and tried the script, but I still failed with the same error. What should I do to umount /oldroot after pivot_root and chroot? ## Updated. I found umount -l /oldroot can umount the oldroot. But how can I relaunch the init in the new_root and go through the /etc/inittab??
Asked by wangt13 (631 rep)
Dec 21, 2024, 09:02 AM
Last activity: Dec 21, 2024, 01:57 PM