在N1的OpenWRT上使用debootstrap安装debian环境

  1. 创建磁盘镜像
cd /mnt/data
dd if=/dev/zero of=debian.img bs=1M count=1024
mkfs.ext4 debian.img
mkdir /debian
mount debian.img /debian
  1. 安装debian
opkg install debootstrap
/bin/debootstrap --arch arm64 stable /debian http://ftp.debian.org/debian
  1. 进入debian环境
mount -o bind /dev /debian/dev
mount -o bind /dev/pts /debian/dev/pts
mount -o bind /proc /debian/proc
mount -o bind /sys /debian/sys
chroot /debian /bin/bash
  1. debian环境下
apt update
apt install vim
apt install locales
dpkg-reconfigure locales
dpkg-reconfigure tzdata
export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8
export LANGUAGE=en_US.UTF-8
  1. 安装桌面环境及VNCServer
tasksel
mate
apt install default-jdk
apt install tightvncserver
vncserver
  1. xstartup配置
#!/bin/sh

unset DBUS_SESSION_BUS_ADDRESS
[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
xsetroot -solid grey
vncconfig -iconic &
#x-terminal-emulator -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
x-window-manager &
mate-session &

  1. start-debian.sh脚本
#!/bin/sh

PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/sbin:/opt/bin \
HOME=/root \
SHELL=/bin/bash \
TERMINFO=/usr/share/terminfo \
TEMP=/tmp \
TMP=/tmp \
LANG=en.US_UTF-8 \
LANGUAGE=en.US_UTF-8 \
LC_ALL=en.US_UTF-8 \
`which chroot` /debian /bin/bash --login
  1. /etc/init.d/debian脚本
#!/bin/sh /etc/rc.common

START=99
STOP=10

NAME=debian

PATH=/bin:/sbin:/usr/sbin:/usr/bin
CHROOT_DIR=`readlink -f /debian`
CHROOT_SERVICES_LIST=$CHROOT_DIR/chroot-services.list
CHROOT_BIN=`which chroot`
MountedDirCount="$(/bin/mount | grep $CHROOT_DIR | wc -l)"


start() {
    if [ -f /etc/hosts ]; then
        cp /etc/hosts $CHROOT_DIR/etc/hosts
    fi
    if [ -f /etc/resolve.conf ]; then
        cp /etc/resolve.conf $CHROOT_DIR/etc/resolve.conf
    fi

    if [ $MountedDirCount -gt 1 ]; then
        echo 'Debian services have already started, exiting...'
        exit 1
    fi
    echo 'Starting Debian services...'
    for dir in dev dev/pts proc sys; do
        /bin/mount -o bind /$dir $CHROOT_DIR/$dir
        sleep 2
    done
    if [ ! -e "$CHROOT_SERVICES_LIST" ]; then
        echo 'WARNING: No Debian services defined.'
        echo "Please, define Debian services to start in $CHROOT_SERVICES_LIST file!"
        echo 'One service per line. Hint: these are script names from Debian /etc/init.d/'
    else
        for item in $(cat $CHROOT_SERVICES_LIST); do
            PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin \
            LC_ALL=C \
            LANGUAGE=C \
            LANG=C \
            $CHROOT_BIN $CHROOT_DIR /etc/init.d/$item start
        done
    fi

# You can add mounting of your device strorages here, if you need.
# For QNAP it may look something like
# mkdir -p $CHROOT_DIR/media/disk1
# mount -o bind /share/HDA_DATA $CHROOT_DIR/media/disk1
# or
# mount -o bind /share/CACHEDEV1_DATA $CHROOT_DIR/media/disk1
}

stop() {
    if [ $MountedDirCount -eq 0 ]; then
        echo 'Debian services have been already stopped, exiting...'
        exit 1
    fi
    if [ -e "$CHROOT_SERVICES_LIST" ]; then
        echo 'Stopping Debian services...'
        for item in $(cat $CHROOT_SERVICES_LIST); do
            PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin \
            LC_ALL=C \
            LANGUAGE=C \
            LANG=C \
            $CHROOT_BIN $CHROOT_DIR /etc/init.d/$item stop
        done
    fi
    # device can be unstable in case we do not unmount properly
    #so we try to umount 3 times
    sleep 1
    for dir in dev/pts dev proc sys opt; do
        /bin/umount $CHROOT_DIR/$dir 2>/dev/null
        sleep 2
    done
    for dir in dev/pts dev proc sys opt; do
        /bin/umount -lf $CHROOT_DIR/$dir 2>/dev/null
        sleep 2
    done
    for dir in dev/pts dev proc sys opt; do
        /bin/umount -l $CHROOT_DIR/$dir 2>/dev/null
        sleep 2
    done
}

  1. apache2 php mysql
apt install apache2
apt install php php-fpm php-cgi
apt install curl
apt install libapache2-mod-php
apt install git python python-pip python3 python3-pip
apt install mysql-client mysql-server
apt install php-mysql php-mbstring
  1. mysql
$sudo mysql -u root
[mysql] use mysql;
[mysql] update user set plugin='' where User='root';
[mysql] flush privileges;
[mysql] \q

推荐阅读更多精彩内容