Process
- Mount recovery partition into temporary location
mkdir -p /mnt/recovery
mount /dev/mmcblk0p6 /mnt/recovery
- Prepare
old_root
directory
mkdir -p /mnt/recovery/mnt/old_root
- 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)
- 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
- Start a shell inside of new root
exec /bin/sh
Mount root filesystem from NFS
- Setup nfs-service on host machine (refer [3-Resource/Linux/NFS|this]({< ref “/posts/3-resource/linux/nfs|this/” >}}))
- Mount NFS filesystem into the board
mount -t nfs -o nolock 192.168.1.27:/home/rishav/Public /mnt/nfsroot
- 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
andchroot