Wiki

Cài debian

  1. Cài debian trong entware
opkg install coreutils-chroot
  1. Tải xuống và giải nén kho lưu trữ đã chuẩn bị
cd /opt
wget -c -O debian_stretch-9.2-armhf_clean.tgz https://bit.ly/2LFoL0G
tar -xvzf ./debian_stretch-9.2-armhf_clean.tgz
  1. Tạo file khởi động cho các dịch vụ đã cài đặt
cat >> /opt/etc/init.d/S99debian << 'EOF'
#!/bin/sh
PATH=/opt/bin:/opt/sbin:/sbin:/bin:/usr/sbin:/usr/bin
# Folder with Debian Jessie
CHROOT_DIR=/@volume1/@Entware/opt/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

Nhấn ENTER để tạo file

  1. Làm cho tập lệnh có thể thực thi được
chmod 755 /opt/etc/init.d/S99debian
  1. Tạo liên kết tượng trưng đến các dịch vụ start-stop hoặc vào debian dễ dàng hơn
touch /opt/etc/chroot-services.list
ln -s /opt/etc/init.d/S99debian /opt/bin/debian

Chúng ta dễ dàng chạy, vào, thoát, dừng debian thông qua các lệnh

debian start
debian stop
debian restart
debian enter
debian status
  1. Copy file host
cp /etc/hosts /opt/debian/etc/
dpkg-reconfigure tzdata
aptitude install locales
dpkg-reconfigure locales

Sao lưu và phục hồi

Tạo bản sao lưu

tar -cvzf debian-bullseye-11_clean.tgz debian/

Khôi phục lại

tar -xvzf debian-buster-11_clean.tgz

Xóa debian

debian stop
/opt/etc/init.d/S99debian stop
rm -r /opt/debian
rm /opt/etc/init.d/S99debian
rm /opt/bin/debian
reboot