Mounton - Chroot Script for Chromebooks
-
- Offline
- 3 years 2 months ago
- 2015-01-09
Hey everybody! I've been impressed with how lightweight this linux distro is and I thought it would be perfect to use as developer environment under ChromeOS. Creating a chroot wasn't to terribly difficult to do, however, I've made a script intended to facilitate the process for other users. The script can be found on my github account at https://github.com/jrcowart/Mounton. It is incredibly bare bones at the moment, having no fail safes of any kind, but it is still a work in progress. I hope to eventually add some fail safes (checking directory existence, handling of download failure, etc.) and some of the nice features that crouton has (such as backups and install from a backup, multiple chroots, etc.).
Disclaimer: This script is still in testing, so I do not expect it to run flawlessly for everybody. However, feedback would be very helpful for getting this script polished into a safe and user friendly tool. Please look over the script before running and if you find any issues or have suggestions for the code, let me know!
The script:
#!/bin/bash CHROOT_DIR=/usr/local/chroots/alpine MIRROR=http://nl.alpinelinux.org/alpine TEMP=/usr/local/chroots/tmp #making a temporary directory to keep files which can be safely deleted after completion mkdir $TEMP #setting up chroot directory mkdir $CHROOT_DIR #change to $TEMP directory cd $TEMP #get list of packages from $MIRROR curl "$MIRROR/edge/main/x86_64/" -o packages.tmp #get name of current apk-tools-static and download CURRENT_APK=$(grep -o "apk-tools-static-[[:alnum:]/._-]*" packages.tmp | head -1) wget $MIRROR/edge/main/x86_64/$CURRENT_APK #extract apk tar -xzf $CURRENT_APK #install base system ./sbin/apk.static -X $MIRROR/edge/main/ -U --allow-untrusted --root $CHROOT_DIR --initdb add alpine-base #mounting system proc,sys,dev in chroot mount -t proc none $CHROOT_DIR/proc mount -o bind /sys $CHROOT_DIR/sys mount -o bind /dev $CHROOT_DIR/dev #update apk repository list echo "$MIRROR/edge/main" > $CHROOT_DIR/etc/apk/repositories #copying system resolv.conf to alpine chroot for internet access cp /etc/resolv.conf $CHROOT_DIR/etc/resolv.conf #remove $TEMP cd / rm -rf $TEMP #creates easy way to enter chroot: type 'climb' at command line cd /usr/local/bin/ echo "chroot /usr/local/chroots/alpine /bin/sh -l" > climb chmod ugo+x climb #creates easy way to 'nuke' the chroot: type 'avalanche' at command line echo "#!/bin/bash echo -n \"Running avalanche will delete your Alpine chroot. Are you sure you want to continue (type 'YES' in all capital letters to do so)\": read CONTINUE if [ \$CONTINUE == \"YES\" ] then umount /usr/local/chroots/alpine/proc umount /usr/local/chroots/alpine/sys umount -l /usr/local/chroots/alpine/dev rm -rf /usr/local/chroots/alpine rm /usr/local/bin/climb rm /usr/local/bin/avalanche exit 1 else echo \"Canceling operation.\" exit 1 fi" > avalanche chmod ugo+x avalanche echo "\n\nYour Alpine Linux chroot is ready to use! Type 'climb' at the command line to start using or type 'avalanche' to delete the chroot and any related file."
Usage is pretty straight forward, do the following after downloading the script:
cd ~/Downloads sudo sh -e mounton.sh
This will install an Alpine Linux (running on Edge) chroot under /usr/local/chroots/alpine, and two helper scripts (climb and avalanche) to /usr/local/bin.
The following will run the helper scripts:
sudo climb #easy way to enter the chroot sudo avalanche #will delete chroot and helper scripts
Again, I'm more the open to any questions, comments, suggestions, and criticisms related to this script! I think that we can make this distribution an incredibly viable choice for Chromebook users, as many use their Chromebooks for development work on the go.
I hope you like it!
P.S.
A big thanks to the dev team of Alpine Linux for making such an awesome distribution!