Created
April 11, 2017 08:37
-
-
Save manio/436d48526c335b9478a3ea7e65ce3656 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# root2ram.sh | |
# more info: https://skyboo.net/2017/04/rpi-creating-a-ram-disk-running-linux-environment-from-nfs-booted-raspbian/ | |
set -x | |
#uncomment following 2 lines to have a network in qemu: | |
#ip route del default | |
#ip route add default via 10.0.2.2 dev eth0 | |
#setting time from NTP as the first step, otherwise all created files/dirs will have a bad dates | |
/usr/src/ntpclient/ntpclient -n -d -c1 -s ntp.task.gda.pl | |
mount -t tmpfs tmpfs /mnt | |
cd /mnt | |
mkdir dev bin proc sys run var | |
cp /bin/busybox ./bin | |
/mnt/bin/busybox --install /mnt/bin | |
mount --move /dev /mnt/dev | |
# Pivot root using instructions from pivot_root(8) man page | |
cd /mnt | |
mkdir old_root | |
pivot_root . old_root | |
# The current directory now seems invalid, so fix it | |
cd / | |
mkdir -p /etc/init.d | |
cp /old_root/rcS /etc/init.d/rcS | |
mount -t proc proc /proc | |
mount -t sysfs -o nosuid,nodev,noexec sysfs /sys | |
mount -t tmpfs -o mode=0755,nosuid,nodev tmpfs /run | |
mkdir -p /dev/pts | |
mount -t devpts -o nosuid,noexec,gid=5,mode=620 devpts /dev/pts | |
mkdir -p /dev/shm | |
mount -t tmpfs -o nosuid,nodev tmpfs /dev/shm | |
ln -s /run /var/run | |
exec chroot . /bin/init | |
# Old root can only be unmounted once sh running from old root finishes. | |
# If enough was copied, you could continue startup normally using init. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment