写在最前:本教程只是在openwrt系统安装一个debian子系统,不会对openwrt系统造成任何影响
1.自己编译openwrt的:请进行make kernel_menuconfig,将FPU emulator选上。如果使用别人编译好的固件,请确认固件是支持FPU emulator的,否则运行debian的时候会报错。目前大多数固件都是支持的。
2.下载debian系统,有两种方法,一种是使用openwrt下载,一种是使用电脑ubuntu或者debian下载。
方法差不多的,路由器或电脑安装,提前安装debootstrap。如果使用openwrt下载的话,方法是opkg update然后opkg install debootstrap;使用ubuntu或者debian,方法是apt-get update 然后 apt-get install debootstrap
安装完debootstrap后就可以下载路由器下运行的debian系统了:
下载命令debootstrap --arch mips --foreign stretch ./debian http://mirrors.ustc.edu.cn/debian/
1)--arch mips其中的mips必须符合你路由器的架构,自己修改,如何查看路由器架构这里有有个简单方法,到路由器Luci界面,查看软件源,类似于这样的src/gz openwrt_base https://mirrors4.tuna.tsinghua.edu.cn/lede/releases/18.06.2/packages/mipsel_24kc/base,从这里可以看出,我的路由器是mipsel
2)--foreign stretch其中stretch是下载的debian的版本
Debian 10("buster") — 当前的稳定版(stable)
Debian 9("stretch") — 旧的稳定版(oldstable)
Debian 8("jessie") — 更旧的稳定版(oldoldstable)
Debian 7("wheezy") — 被淘汰的稳定版
Debian 6.0("squeeze") — 被淘汰的稳定版
3)./debian是下载的目录,自己随便指定,必须放到ext格式的分区里,不能放在fat或者ntfs
4)http://mirrors.ustc.edu.cn/debian/是软件源,可以用这个,也可以自己换成别的
5)实测我用路由器直接下载没成功过,用电脑10分钟就下载成功了,如果用电脑下载的话,下载完成后直接打包,然后到路由器上解包就行了,打包命令tar -czvpf debian.tar.gz ./debian
6)使用SSH登录到你的路由器,将debian.tar.gz拷贝到路由器的/mnt/sda1,解包命令 tar -xzvpf debian.tar.gz -C /mnt/sda1。路由器最好挂载的大一点的移动硬盘。使用U盘的话,要用速度好一点的,最好是USB3.0的,文件系统必须是ext3或者ext4,容量8G以上。
3.解包到路由器上以后就可以执行第二步了,依次执行以下命令,我以debian的路径是/mnt/sda1/debian为例,大家根据自己实际情况修改
mount -o bind /proc /mnt/sda1/debian/proc
chroot /mnt/sda1/debian /bin/bash
/debootstrap/debootstrap --second-stage
等十几分钟,debian就安装好了
4.下一次想进入debian系统,只要用ssh链接到路由器后,执行
mount -o bind /proc /mnt/sda1/debian/proc 注:这个命令可以写到路由器的自动启动脚本里
chroot /mnt/sda1/debian /bin/bash
就是debian系统了,可以尽情的apt-get你想要的软件了
5.这时候你的debian可能上不了网,执行一次以下命令
echo "nameserver 192.168.1.1" > /etc/resolv.conf 注:192.168.1.1是你的DNS服务器
6.配置优化,在debian子系统里安装ssh服务器
1)执行mount -t devpts devpts /dev/pts
2)修改debian系统root用户的密码,执行passwd修改
3)根据https://www.cnblogs.com/yinheyi/p/6266748.html里的教程安装
4)配置ssh服务器的时候,注意监听端口不能设置成22,这个与路由器的ssh服务器冲突: Port 2222 #设置ssh监听的端口号,默认2222端口
5)将如下代码写入到路由器的自启动脚本
mount -o bind /proc /mnt/sda1/debian/proc
chroot /mnt/sda1/debian /bin/mount -t devpts devpts /dev/pts
chroot /mnt/sda1/debian /etc/init.d/ssh start
以后就可以直接用putty登陆到debian子系统中了。