├── README.md ├── install.sh ├── opt └── etc │ └── init.d │ └── S99debian └── prepare-env.txt /README.md: -------------------------------------------------------------------------------- 1 | # Debian chroot environment 2 | 3 | This scripts helps to install Debian 8 services on MIPS routers with [Padavan firmware](https://bitbucket.org/padavan/rt-n56u). 4 | 5 | 6 | ## Prerequisites 7 | 8 | Prepare Ext2/Ext3/Ext4 partition on USB drive by following [this manual](https://bitbucket.org/padavan/rt-n56u/wiki/EN/HowToConfigureEntware). 9 | Clean Debian environment takes ~300MB. SWAP usage is also recommended (especially on 64MB RAM devices). 10 | 11 | ## Installation 12 | 13 | It takes few minutes to download and unpack ~50MB archive. Log into router's SSH/telnet/serial console and type: 14 | ``` 15 | wget --no-check-certificate https://raw.githubusercontent.com/DontBeAPadavan/chroot-debian/master/install.sh 16 | sh install.sh 17 | ``` 18 | If all goes as expected, you'll get: 19 | ``` 20 | Downloading /opt/etc/init.d/rc.func... success! 21 | Downloading /opt/etc/init.d/rc.unslung... success! 22 | Downloading /opt/etc/init.d/S99debian... success! 23 | Downloading /opt/debian_clean.tgz... success! 24 | Unpacking Debian environment... success! 25 | The Debian services from /opt/debian/chroot-services.list will be started automatically at boot time. You may log into Debian environment via SSH root:debian@192.168.0.1:65022. Do you wish to start it now? [y/n]: y 26 | Starting Debian services... 27 | [ ok ] Starting OpenBSD Secure Shell server: sshd. 28 | Done. 29 | ``` 30 | 31 | 32 | ## Usage 33 | 34 | Log into chroot'ed Debian environment by `root:debian@192.168.0.1:65022` where `192.168.0.1` is the IP address of router. You've got full blown Debian on board with all it's 40+ thousands packages! Let's install transmission as an example: 35 | ``` 36 | apt-get update 37 | apt-get install transmission-daemon 38 | echo 'transmission-daemon' >> /chroot-services.list 39 | ``` 40 | The last command adds transmssion to the list of Debian services, which is started at boot time. `transmission-daemon` is the script name from `/etc/init.d/`. 41 | 42 | This is just a sandbox, which is isolated from host system. If you'll break it, you can always start from scratch. Log into router console and run: 43 | ``` 44 | cd /opt 45 | /opt/etc/init.d/S99debian stop 46 | rm -fr debian 47 | rm /opt/etc/init.d/S99debian 48 | sh install.sh 49 | ``` 50 | Voilà! You've got fresh Debian installation again. 51 | 52 | 53 | ## Details 54 | 55 | The installation script unpacks prepared Debian environment. You can prepare it manually, [see how](https://github.com/ryzhovau/padavan-debian/blob/master/prepare-env.txt). 56 | 57 | Also, take a look at `/opt/etc/init.d/S99debian`. You can mount any host folder as `/media` in Debian env. by setting `$EXT_DIR` varialble. It's a "bridge" between host and chroot'ed systems. 58 | 59 | Good luck! 60 | -------------------------------------------------------------------------------- /install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | if [ -z $(nvram get help_enable) ] ; then 4 | echo 'It works on Padavan firmware only, sorry. Exiting...' 5 | exit 1 6 | fi 7 | 8 | dl () { 9 | # $1 - URL to download 10 | # $2 - place to store 11 | # $3 - 'x' if should be executable 12 | echo -n "Downloading $2... " 13 | wget -q --no-check-certificate $1 -O $2 14 | if [ $? -eq 0 ] ; then 15 | echo 'success!' 16 | else 17 | echo 'failed!' 18 | exit 1 19 | fi 20 | [ -z "$3" ] || chmod +x $2 21 | } 22 | 23 | cd /opt 24 | 25 | if [ ! -e '/opt/bin/opkg' ] ; then 26 | # Entware is not installed, install start scripts 27 | mkdir -p /opt/etc/init.d 28 | dl http://pkg.entware.net/binaries/mipsel/installer/rc.func /opt/etc/init.d/rc.func 29 | dl http://pkg.entware.net/binaries/mipsel/installer/rc.unslung /opt/etc/init.d/rc.unslung x 30 | sed -i 's|/opt/bin/find|find|g' /opt/etc/init.d/rc.unslung 31 | # This prevents f\w to install Entware 32 | mkdir -p /opt/bin 33 | touch /opt/bin/opkg 34 | fi 35 | 36 | dl https://raw.githubusercontent.com/DontBeAPadavan/chroot-debian/master/opt/etc/init.d/S99debian /opt/etc/init.d/S99debian x 37 | dl http://files.ryzhov-al.ru/Routers/chroot-debian/debian_clean.tgz /opt/debian_clean.tgz 38 | 39 | echo -n 'Unpacking Debian environment... ' 40 | tar -xzf debian_clean.tgz 41 | if [ $? -eq 0 ] ; then 42 | echo 'success!' 43 | else 44 | echo 'failed!' 45 | exit 1 46 | fi 47 | rm debian_clean.tgz 48 | echo 'ssh' > /opt/debian/chroot-services.list 49 | 50 | echo -n 'The Debian services from /opt/debian/chroot-services.list will be started automatically at boot time. You may log into Debian environment via SSH root:debian@192.168.0.1:65022. Do you wish to start it now? [y/n]: ' 51 | read yn 52 | [ "$yn" = "y" ] && /opt/etc/init.d/S99debian start 53 | -------------------------------------------------------------------------------- /opt/etc/init.d/S99debian: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | PATH=/opt/bin:/opt/sbin:/sbin:/bin:/usr/sbin:/usr/bin 3 | 4 | # Debian folder 5 | CHROOT_DIR=/opt/debian 6 | 7 | # Some folder outside of sandbox, will be mounted to /mnt folder in Debian 8 | # Leave commented if not needed 9 | EXT_DIR=/media 10 | 11 | CHROOT_SERVICES_LIST=$CHROOT_DIR/chroot-services.list 12 | if [ ! -e "$CHROOT_SERVICES_LIST" ]; then 13 | echo "Please, define Debian services to start in $CHROOT_SERVICES_LIST first!" 14 | echo 'One service per line. Hint: this is a script names from Debian /etc/init.d/' 15 | exit 1 16 | fi 17 | 18 | MountedDirCount="$(mount | grep $CHROOT_DIR | wc -l)" 19 | 20 | start() { 21 | if [ $MountedDirCount -gt 0 ]; then 22 | echo 'Debian services seems to be already started, exiting...' 23 | exit 1 24 | fi 25 | echo 'Starting Debian services...' 26 | for dir in dev dev/pts proc sys; do 27 | mount -o bind /$dir $CHROOT_DIR/$dir 28 | done 29 | [ -z "$EXT_DIR" ] || mount -o bind $EXT_DIR $CHROOT_DIR/media 30 | for item in $(cat $CHROOT_SERVICES_LIST); do 31 | PATH=/usr/local/bin:/usr/bin:/bin:/sbin:/usr/local/games:/usr/games:/usr/sbin \ 32 | LC_ALL=C \ 33 | LANGUAGE=C \ 34 | LANG=C \ 35 | chroot $CHROOT_DIR /etc/init.d/$item start 36 | done 37 | } 38 | 39 | stop() { 40 | if [ $MountedDirCount -eq 0 ]; then 41 | echo 'Debian services seems to be already stopped, exiting...' 42 | exit 1 43 | fi 44 | echo 'Stopping Debian services...' 45 | for item in $(cat $CHROOT_SERVICES_LIST); do 46 | PATH=/usr/local/bin:/usr/bin:/bin:/sbin:/usr/local/games:/usr/games:/usr/sbin \ 47 | LC_ALL=C \ 48 | LANGUAGE=C \ 49 | LANG=C \ 50 | chroot $CHROOT_DIR /etc/init.d/$item stop 51 | done 52 | umount $CHROOT_DIR/dev/pts 53 | mount | grep $CHROOT_DIR | awk "{print \$3}" | xargs umount 54 | } 55 | 56 | status() { 57 | if [ $MountedDirCount -gt 0 ]; then 58 | echo 'Debian services is running' 59 | else 60 | echo 'Debian services is stopped' 61 | fi 62 | } 63 | 64 | case "$1" in 65 | start) 66 | start 67 | ;; 68 | stop) 69 | stop 70 | ;; 71 | restart) 72 | stop 73 | sleep 5 74 | start 75 | ;; 76 | status) status 77 | ;; 78 | *) 79 | echo "Usage: $0 (start|stop|restart|status)" 80 | exit 1 81 | ;; 82 | esac 83 | 84 | echo 'Done.' 85 | exit 0 86 | -------------------------------------------------------------------------------- /prepare-env.txt: -------------------------------------------------------------------------------- 1 | # How to prepare minimal Debian environment from scratch. 2 | 3 | # 1st stage from linux PC 4 | sudo debootstrap --arch mipsel --foreign --variant=minbase --include=openssh-server stable debian ftp://ftp.debian.org/debian 5 | sudo tar -cvzf ./debian-stable-mipsel.tgz debian 6 | # now transfer debian-stable-mipsel.tgz to router. 7 | 8 | # 2nd stage from router 9 | cd /opt 10 | tar -xvzf debian-stable-mipsel.tgz 11 | mount /dev/ debian/dev 12 | mount /proc/ debian/proc 13 | mount /sys/ debian/sys 14 | LC_ALL=C LANGUAGE=C LANG=C chroot debian /debootstrap/debootstrap --second-stage 15 | sed -i 's|Port 22|Port 65022|g' debian/etc/ssh/sshd_config 16 | sed -i 's|PermitRootLogin without-password|PermitRootLogin yes|g' debian/etc/ssh/sshd_config 17 | cat > debian/usr/sbin/policy-rc.d <