This version is for Mipsel routers: RT-N16, RT-N66U, RT-AC66U...
Arm version here
I setup a chrooted Debian Wheezy where you can compile and install any package you want, of course if routers memory permit it, ex. transmission, minidlna, lighttpd, rutorrent, owncloud...
Choose only one version to install from point 1a or 1b, Optware or Entware
1a - Install NEW GENERATION OPTWARE from here, to simplify things, debian will be installed in optware-ng folder, in this case is /mnt/usb_disk/optware-ng
or
1b - Install NEW GENERATION ENTWARE from here, to simplify things, debian will be installed in entware-ng folder, in this case is /mnt/usb_disk/entware-ng
2 - Download and extract prepared archive
wget -c -O debian-wheezy7.9-clean-mipsel.tgz https://bit.ly/2HCQywl
tar -xvzf ./debian-wheezy7.9-clean-mipsel.tgz
3 - Create startup script for installed services (thanks @ryzhov_al), this is useful for minidlna, transmission or any other package...
nano /opt/etc/init.d/S99debian
Paste all this lines
#!/bin/sh
PATH=/opt/bin:/opt/sbin:/sbin:/bin:/usr/sbin:/usr/bin
# Folder with Debian Wheezy
CHROOT_DIR=/tmp/mnt/sda1/entware/debian
# Some folder outside of sandbox,
# will be mounted to /mnt folder in Debian
# Uncommented next line if you need to mount a folder inside debian
# EXT_DIR=/tmp/mnt/sda1/Media
CHROOT_SERVICES_LIST=/opt/etc/chroot-services.list
if [ ! -e "$CHROOT_SERVICES_LIST" ]; then
echo "Please, define Debian services to start in
$CHROOT_SERVICES_LIST first!"
echo "One service per line. Hint: this is a script names from
Debian's /etc/init.d/"
exit 1
fi
MountedDirCount="$(mount | grep $CHROOT_DIR | wc -l)"
start() {
if [ $MountedDirCount -gt 0 ]; then
echo "Chroot'ed services seems to be already started,
exiting..."
exit 1
fi
echo "Starting chroot'ed Debian services..."
for dir in dev proc sys; do
mount -o bind /$dir $CHROOT_DIR/$dir
done
[ -z "$EXT_DIR" ] || mount -o bind $EXT_DIR $CHROOT_DIR/mnt
for item in $(cat $CHROOT_SERVICES_LIST); do
chroot $CHROOT_DIR /etc/init.d/$item start
done
}
stop() {
if [ $MountedDirCount -eq 0 ]; then
echo "Chroot'ed services seems to be already stopped,
exiting..."
exit 1
fi
echo "Stopping chroot'ed Debian services..."
for item in $(cat $CHROOT_SERVICES_LIST); do
chroot $CHROOT_DIR /etc/init.d/$item stop
sleep 2
done
mount | grep $CHROOT_DIR | awk '{print $3}' | xargs umount -l
}
restart() {
if [ $MountedDirCount -eq 0 ]; then
echo "Chroot'ed services seems to be already stopped"
start
else
echo "Stopping chroot'ed Debian services..."
for item in $(cat $CHROOT_SERVICES_LIST); do
chroot $CHROOT_DIR /etc/init.d/$item stop
sleep 2
done
mount | grep $CHROOT_DIR | awk '{print $3}' | xargs umount -l
echo "Restarting chroot'ed Debian services..."
for dir in dev proc sys; do
mount -o bind /$dir $CHROOT_DIR/$dir
done
[ -z "$EXT_DIR" ] || mount -o bind $EXT_DIR $CHROOT_DIR/mnt
for item in $(cat $CHROOT_SERVICES_LIST); do
chroot $CHROOT_DIR /etc/init.d/$item start
done
fi
}
enter() {
[ -z "$EXT_DIR" ] || mount -o bind $EXT_DIR $CHROOT_DIR/mnt
mount -o bind /dev/ /opt/debian/dev/
mount -o bind /dev/pts /opt/debian/dev/pts
mount -o bind /proc/ /opt/debian/proc/
mount -o bind /sys/ /opt/debian/sys/
chroot /opt/debian /bin/bash
}
status() {
if [ $MountedDirCount -gt 0 ]; then
echo "Chroot'ed services running..."
else
echo "Chroot'ed services not running!"
fi
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
enter)
enter
;;
status) status
;;
*)
echo "Usage: (start|stop|restart|enter|status)"
exit 1
;;
esac
echo Done.
exit 0
Save with CTRL-O, press ENTER and exit nano with CTRL-X
Make script executable
In this script is a path EXT_DIR to your external media folder which will be mounted in debian as /mnt, default is /mnt/sda1/Media (must be a single folder not the whole partition), don't forget to uncomment if is used.
If your disk has a label change sda1 from CHROOT_DIR with your disk label, modify the script to match your settings with a text editor, use this command:
After editing EXT_DIR and CHROOT_DIR, save settings with CTRL-O, press ENTER and exit nano with CTRL-X
ln -s /opt/etc/init.d/S99debian /opt/bin/debian
Every time you want to start installed services in debian without typing long command "/opt/etc/init.d/S99debian start/stop", type only
debian stop
debian restart
debian enter
debian status
But don't forget to add services name from /opt/debian/etc/init.d/ to /opt/etc/chroot-services.list
6 - Enter chrooted debian, you will see in terminal username will change to root@RT-N... from admin@RT-N... or other name if changed previously in router menu (all terminals commands with purple border are inside debian)
7 - Run update to see if some recent packages are available
8 - Set your country time zone
9 - Install some packages, ex. wget
Now you have a full Debian distro and may install any package from here but first we need a swap file
10 - To exit chrooted debian just type exit
11 - Create SWAP FILE, it's a must (In Optware-NG is created automatically)
dd if=/dev/zero of=swap bs=1024 count=524288
mkswap swap
chmod 0600 swap
swapon swap
To enable swap file when router booting, create /jffs/scripts/post-mount script with
Paste this lines in terminal
#!/bin/sh
swapon /opt/swap
Paste this lines in terminal
#!/bin/sh
swapoff /opt/swap
HOW TO UNINSTALL DEBIAN
It's very important to unmount external folder before removing debian, if not - all content from that directory will be deleted: movies, music files, photos...
rm /opt/bin/debian
HOW TO BACKUP-RESTORE DEBIAN
After installing a lot of packages, it's better to make a backup, if something goes wrong just restore it without reconfigure all off your work.
It's very important to unmount external folder before backing up debian, if not - all content from that directory will be included in archive and may become huge...
tar -cvzf ./chosen_debian_name.tgz ./debian/
tar -xvzf ./chosen_debian_name.tgz