Process

  1. Mount recovery partition into temporary location
mkdir -p /mnt/recovery
mount /dev/mmcblk0p6 /mnt/recovery
  1. Prepare old_root directory
mkdir -p /mnt/recovery/mnt/old_root
  1. Switch root using pivot_root
cd /mnt/recovery
pivot_root . mnt/old_root

Now:

  • New root is /mnt/recovery (i.e., /)
  • The previous root (e.g., initramfs or mainfs) is now mounted at /mnt/old_root

Note: The chroot must be available under the old root and under the new root(recovery)

  1. Remount /proc, /sys, /dev, etc
mount -t proc proc /proc
mount -t sysfs sysfs /sys
mount -o bind /mnt/old_root/dev /dev
mount -o bind /mnt/old_root/tmp /tmp
mount -o bind /mnt/old_root/run /run
  1. Start a shell inside of new root
exec /bin/sh

Mount root filesystem from NFS

  1. Setup nfs-service on host machine (refer [3-Resource/Linux/NFS|this]({< ref “/posts/3-resource/linux/nfs|this/” >}}))
  2. Mount NFS filesystem into the board
mount -t nfs -o nolock 192.168.1.27:/home/rishav/Public /mnt/nfsroot
  1. Mount ext image as a loopback device
mkdir -p /mnt/local
cp /mnt/nfs/rootfs.ext4 /tmp/rootfs.ext4
mount -o loop /tmp/rootfs.ext4 /mnt/local

References

  • Manual page of pivot_root
  • Also see difference between pivot_root and chroot