Root shell helper script

AmigaOne X1000 platform specific issues related to Linux only.
Post Reply
User avatar
Hypex
Beta Tester
Beta Tester
Posts: 909
Joined: Mon Dec 20, 2010 2:23 pm
Location: Vic. Australia.

Root shell helper script

Post by Hypex »

Hi guys. A common method to fix a broken system is to mount it and chroot a shell into it. This can work well but to do anything more than basic file editing like accessing network and installing software requires more work for it to be functional. Namely some common system mounts need to be active. So I wrote this script to chroot into a mounted volume. It mounts proc,sys, dev and pts then does a chroot into it. When shell is exited it unmounts and returns back to base. It relies on sudo so is Ubuntu centric. I called it rootsh and copied it to my /usr/sbin. :-)

Code: Select all

#/bin/sh

if [ -z "$1" ]; then
	echo "$0 <mount>"
	echo
	echo "Root shell:"
	echo "The rootsh command will bind local proc,sys and dev mounts onto a"
	echo "mounted system and chroot to give root shell."
	
	exit 0
elif ! mountpoint -q "$1" ; then
	echo "Mount point at $1 does not exist"
	
	exit 5
fi

sudo mount -t proc proc "$1/proc"
sudo mount -t sysfs sysfs "$1/sys"
sudo mount -o bind /dev "$1/dev"
sudo mount -t devpts pts "$1/dev/pts"

sudo chroot "$1"

sudo umount "$1/dev/pts"
sudo umount "$1/dev"
sudo umount "$1/sys"
sudo umount "$1/proc"

exit 0
User avatar
sailorMH
Posts: 272
Joined: Wed Aug 28, 2013 7:01 pm
Location: Czech republic

Re: Root shell helper script

Post by sailorMH »

@Hypex
nice!
A1200, Micro A1-C (G3/1.2 GHz), AmigaOne XE (G4/1.4 GHz), Pegasos II (G4/1.33 GHz), Sam440ep, Sam440ep-flex, Sam460LE, AmigaOne X1000
Efika 5200b, Pegasos I, Powerbook, Mac Mini (1.83 GHz), iMac, Powermac Quad

AmigaOS, MorphOS, linux, MacOS X
User avatar
Hypex
Beta Tester
Beta Tester
Posts: 909
Joined: Mon Dec 20, 2010 2:23 pm
Location: Vic. Australia.

Re: Root shell helper script

Post by Hypex »

Thanks! It's based on research for what needs to be mounted and how. But can have its quirks as binding mount points can affect the host system like not unmounting cleanly.
Post Reply