OpenWrt 라우터 펌웨어 업데이트 하는 일반적인 방법입니다. extroot 설정을 하지 않았다면 크기 신경쓸 일이 없지만 extroot 설정을 했다면 sysupgrade-with-extroot 을 참고하세요.
1. sysupgrade 옵션
root@OpenWrt:~# sysupgrade --help
Usage: /sbin/sysupgrade [<upgrade-option>...] <image file or URL>
/sbin/sysupgrade [-q] [-i] [-c] [-u] [-o] [-k] <backup-command> <file>
upgrade-option:
-f <config> restore configuration from .tar.gz (file or url)
-i interactive mode
-c attempt to preserve all changed files in /etc/
-o attempt to preserve all changed files in /, except those
from packages but including changed confs.
-u skip from backup files that are equal to those in /rom
-n do not save configuration over reflash
-p do not attempt to restore the partition table after flash.
-k include in backup a list of current installed packages at
/etc/backup/installed_packages.txt
-T | --test
Verify image and config .tar.gz but do not actually flash.
-F | --force
Flash image even if image checks fail, this is dangerous!
-q less verbose
-v more verbose
-h | --help display this help
backup-command:
-b | --create-backup <file>
create .tar.gz of files specified in sysupgrade.conf
then exit. Does not flash an image. If file is '-',
i.e. stdout, verbosity is set to 0 (i.e. quiet).
-r | --restore-backup <file>
restore a .tar.gz created with sysupgrade -b
then exit. Does not flash an image. If file is '-',
the archive is read from stdin.
-l | --list-backup
list the files that would be backed up when calling
sysupgrade -b. Does not create a backup file.
root@OpenWrt:~#
2 .기존 설정 백업
백업 목록 확인
sysupgrade 명령으로 백업할 경우 opkg list-changed-conffiles, /lib/upgrade/keep.d/, /etc/sysupgrade.conf 에 나열된 화일 목록을 백업하며 sysupgrade -l 명령으로 통해 백업화일 생성시 백업하게 될 화일의 목록을 확인합니다.
sysupgrade -l
root@OpenWrt:~# sysupgrade -l
/etc/banip/banip.blacklist
/etc/banip/banip.whitelist
/etc/config/banip
...
...
/etc/xattr.conf
/etc/uhttpd.key
/etc/uhttpd.crt
root@OpenWrt:~#
백업할 목록 추가
/etc/sysupgrade.conf 사용자가 에 백업시 추가할 할 화일이나 디렉토리를 추가할 수 있습니다. 아래는 위의 목록에 /root, /etc/wg/ 디렉토리를 별도 추가하는 설정입니다.
vi /etc/sysupgrade.conf
## This file contains files and directories that should ## be preserved during an upgrade. # /etc/example.conf # /etc/openvpn/ /root/ /etc/wg/
사용자가 별도 추가한 화일/디렉토리가 백업목록에 포함되는지 다시 확인합니다.
sysupgrade -l
3. 기존에 설치된 패키지 목록 생성
https://github.com/richb-hanover/OpenWrtScripts/blob/master/opkgscript.sh 를 활용해 설치된 패키지 목록을 작성합니다. wget 이 없는경우 wget을 설치하고 wget으로 스크립트를 다운받아 아래와 같이 목록을 생성합니다. 목록 생성 위치는 /etc/config/opkg.installed에 저장됩니다.
opkg update
opkg install wget ca-certificates ca-bundle
cd ~
wget https://github.com/richb-hanover/OpenWrtScripts/raw/master/opkgscript.sh
chomd 755 opkgscript.sh
./opkgscript.sh -v write
4. 백업
만약을 위해 usb 장치에 backup 디렉토리를 생성하고 sysupgrade -b 명령으로 백업화일을 생성하였습니다. 필요한 경우 윈도우에서 scp등을 이용해 로컬에 백업화일을 다운 받습니다.
umask 077
mkdir /mnt/sda1/backup
sysupgrade -b /mnt/sda1/backup/backup-${HOSTNAME}-$(date +%F).tar.gz
ls /mnt/sda1/backup/backup-*.tar.gz
5. sysupgrade 실행
다운로드 스크립트 생성
https://downloads.openwrt.org/releases/ 에서 업그레이드 할 라우터의 sysupgrade.bin 및 sha256sums 화일의 url을 확인해 각각 ${DOWNLOAD_LINK}와 ${SHA256SUMS}에 기입합니다.
vi ~/sysup.sh
#!/bin/sh # NETGEAR R7800 : ipq806x DOWNLOAD_LINK="https://downloads.openwrt.org/releases/19.07.6/targets/ipq806x/generic/openwrt-19.07.6-ipq806x-generic-netgear_r7800-squashfs-sysupgrade.bin" SHA256SUMS="https://downloads.openwrt.org/releases/19.07.6/targets/ipq806x/generic/sha256sums" cd /tmp; wget $DOWNLOAD_LINK; wget $SHA256SUMS; sha256sum -c sha256sums 2>/dev/null | grep OK
다운로드 스크립트 실행
스크립트 실행해 /tmp에 펌웨어 및 sha256sums를 다운받아 화일의 유효성을 검사합니다.
sh ./sysup.sh
root@OpenWrt:~# sh ./sysup.sh
--2021-01-31 16:10:14-- https://downloads.openwrt.org/releases/19.07.6/targets/ipq806x/generic/openwrt-19.07.6-ipq806x-generic-netgear_r7800-squashfs-sysupgrade.bin
Resolving downloads.openwrt.org... 168.119.138.211
Connecting to downloads.openwrt.org|168.119.138.211|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 5366032 (5.1M) [application/octet-stream]
Saving to: 'openwrt-19.07.6-ipq806x-generic-netgear_r7800-squashfs-sysupgrade.bin'
openwrt-19.07.6-ipq806x-generic-netgear_r7800-squashfs-sysu 100%[=====================================================================>] 5.12M 2.74MB/s in 1.9s
2021-01-31 16:10:17 (2.74 MB/s) - 'openwrt-19.07.6-ipq806x-generic-netgear_r7800-squashfs-sysupgrade.bin' saved [5366032/5366032]
--2021-01-31 16:10:17-- https://downloads.openwrt.org/releases/19.07.6/targets/ipq806x/generic/sha256sums
Resolving downloads.openwrt.org... 168.119.138.211
Connecting to downloads.openwrt.org|168.119.138.211|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 120135 (117K) [text/plain]
Saving to: 'sha256sums'
sha256sums 100%[=====================================================================>] 117.32K 257KB/s in 0.5s
2021-01-31 16:10:18 (257 KB/s) - 'sha256sums' saved [120135/120135]
openwrt-19.07.6-ipq806x-generic-netgear_r7800-squashfs-sysupgrade.bin: OK
root@OpenWrt:~#
sysupgrade 실행
다운받은 펌웨어를 설치합니다. 라우터의 모델을 다시한번 확인하고 화일유효성 결과가 ok 인지 확인합니다. 엔터를 눌러 펌웨어 설치 후에는 ssh 연결이 종료되니 펌웨어가 설치 완료될 때까지 잠시 기다린 후 ssh 연결을 합니다.
sysupgrade.bin 화일의 경우 sysupgrade -l 명령으로 확인한 설정화일을 자동으로 복원합니다. (이전 버전과 호환되지 않는 버전간에 업그레이드 할 때 사용자에게 경고를 표시하므로 경고 확인 필요)
sysupgrade -v /tmp/*.bin
root@OpenWrt:~# sysupgrade -v /tmp/*.bin
Saving config files...
etc/config/dhcp
etc/config/dhcp.old
etc/config/dropbear
etc/config/firewall
...
Commencing upgrade. Closing all shell sessions.
Using username "root".
Authenticating with public key "root@OpenWrt"
BusyBox v1.30.1 () built-in shell (ash)
_______ ________ __
| |.-----.-----.-----.| | | |.----.| |_
| - || _ | -__| || | | || _|| _|
|_______|| __|_____|__|__||________||__| |____|
|__| W I R E L E S S F R E E D O M
-----------------------------------------------------
OpenWrt 19.07.6, r11278-8055e38794
-----------------------------------------------------
root@OpenWrt:~#
root@OpenWrt:~#
6. 기존 설정 복원(필요시 또는 초기 펌웨어 설치시)
sysupgrade 실행시 기존 설정을 자동으로 복원해 따로 설정을 복월할 필요 없지만 초기 펌웨어 설치시, 또는 필요한 경우 위에서 백업한 기존 설정을 복원할 수 있습니다. 초기 설치시에는 usb 장치를 인식하지 못하므로 usb 에 백업한 설정화일에 접근 위해서는 usb 장치 mount 를 해야 합니다.
ls /mnt/sda1/backup/backup-*.tar.gz
cp /mnt/sda1/backup/backup-*.tar.gz /tmp
sysupgrade -r /tmp/backup-*.tar.gz
7. 기존 패키지 재설치
펌웨어 업그레이드 전 opkgscript로 작성한 기존 설치 패키지 목록 /etc/config/opkg.installed 를 바탕으로 패키지를 재설치하고 라우터 전반적인 상태를 체크합니다.
opkg update
cd ~
./opkgscript.sh -v install