How to Install Debian Stretch - Arm

This version is for Arm router RT-AC86U with kernel v4.1.27, not working on other arm routers with older kernel v2.6.36
Can't be installed on mipsel devices because kernel is too old, use debian wheezy instead from here

I setup a chrooted Debian Stretch v9.2 where you can compile and install any package you want, of course if routers memory permit it, ex. transmission, plexmediaserver, 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 folder, in this case is /mnt/usb_disk/optware

ipkg install findutils coreutils

or

1b - Install NEW GENERATION ENTWARE from here, to simplify things, debian will be installed in entware folder, in this case is /mnt/usb_disk/entware

opkg install coreutils-chroot

2 - Download and extract prepared archive

cd /opt
wget -c -O debian_stretch-9.2-armhf_clean.tgz goo.gl/f5WGGt
tar -xvzf ./debian_stretch-9.2-armhf_clean.tgz

3 - Create startup script for installed services (thanks @ryzhov_al), this is usefull for minidlna, transmission or any other package...

cat >> /opt/etc/init.d/S99debian << 'EOF'
#!/bin/sh
PATH=/opt/bin:/opt/sbin:/sbin:/bin:/usr/sbin:/usr/bin
# Folder with Debian Stretch
CHROOT_DIR=/tmp/mnt/sda1/entware/debian
# Some folder outside of sandbox,
# will be mounted to /mnt folder in Debian
# Uncommented "EXT_DIR=" line if you need to
# mount a folder inside debian (remove #)
# 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
umount /opt/debian/dev/pts
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
EOF

Press ENTER
Make script executable

chmod 755 /opt/etc/init.d/S99debian

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, inside Debian, EXT_DIR /mnt/sda1/Media/ will become /mnt (Ex. you need to set Transmission download path to /mnt/transmission or a new library in Plex Media Server path to /mnt

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:

nano /opt/etc/init.d/S99debian

After editing EXT_DIR and CHROOT_DIR, save settings with CTRL-O, press ENTER and exit nano with CTRL-X

4 - Create symlink to start-stop services or enter debian easier
touch /opt/etc/chroot-services.list
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 start
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

5 - Copy hosts file to debian (usefull for some debian packages)
cp /etc/hosts /opt/debian/etc/

6 - Enter chrooted debian, you will see in terminal username will change to root@RT-AC... from admin@RT-AC... or other name if changed previously in router menu (all terminals commands with purple border are inside debian)

debian enter

7 - Run update to see if some recent packages are available

apt update && apt upgrade -y

8 - Set your country time zone

dpkg-reconfigure tzdata

9 - Install some packages, ex. wget

apt install wget

Now you have a full Debian distro and may install any package from here
10 - To exit chrooted debian just type exit

exit
Enjoy...

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...

1 - Stop debian and unmount external folder
debian stop
/opt/etc/init.d/S99debian stop
2 - Remove entire debian directory
rm -r /opt/debian
3 - Remove startup script
rm /opt/etc/init.d/S99debian
rm /opt/bin/debian
4 - Reboot router
reboot

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...

Stop debian and unmount external folder
debian stop
BackUp debian
cd /opt
tar -cvzf ./chosen_debian_name.tgz ./debian/
Restore debian when needed
cd /opt
tar -xvzf ./chosen_debian_name.tgz

 

  • Lorenzo Copparoni

    Hi, I have some problems at step 3:

    "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, inside Debian, EXT_DIR /mnt/sda1/Media/ will become /mnt (Ex. you need to set Transmission download path to /mnt/transmission or a new library in Plex Media Server path to /mnt

    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:"

    I can't understand too much what EXT_DIR is and also CHROOT_DIR. For example, I would install Debian on my USB stick as said, its mounted partition is USB8GB. Then I have my USB HDD which has a single partition named Touro. Now, what should I modify in the script at the step 3? My actual transmission download path is /mnt/Touro/Pubblica/Torrent/Completed. Is it ok if I create another folder and the path would be: /mnt/Touro/Pubblica/Media ? CHROOT_DIR instead? What does it mean? I also didn't understand what you mean by "don't forget to uncomment if it is used".

    Thanks a lot!

    • Chroot dir is where you installed entware CHROOT_DIR=/tmp/mnt/sda1/entware/debian
      In your case is CHROOT_DIR=/tmp/mnt/USB8G/entware/debian
      As for Media directory
      EXT_DIR=/mnt/Touro/Pubblica/Torrent/Completed

  • Luke H

    Can I install this on my AC56U? If not, how can I install something with kernel >=3.2 on that one cause that's required for libgc which is required for some stuff I want to install.
    Thanks

    • For RT-AC56U use Debian Jessie https://www.hqt.ro/how-to-install-debian-jessie-arm/
      You can't install packages that requires a newer kernel than 2.6.36.
      As alternative, you can flash another custom firmware from Tomato, DD-WRT... if they have a newer kernel.

      • Luke H

        Thanks, I already use Jessie and Merlin firmware and since I wrote this I also searched and understood how where the kernel actually stands. Hope Merlin will upgrade that too at some point since DD-WRT did it after-all. Not eager to switch to DD-WRT at this point but if packages that I already use would require newer kernel I may be doing that.
        PS: what's the cheapest router from emag.ro on which I can install this Stretch + Merlin?
        PPS: your newer tutorial like this one won't properly appear on the homepage.

      • Luke H

        Maybe a stupid question but, since Merlin doesn't touch the kernel, would there be a way to flash DD-WRT, backup the kernel or something, flash Merlin again and somehow get the newer kernel from DD-WRT along with Merlin?

        • No, it's not possible because almost all packages are compiled for a specific kernel.

SUBSCRIBE

To be notified by email when a new tutorial is posted :)

Thanks for Subscribing! I'll keeping you up-to-date with latest tutorials!

Something went wrong, try again...