Fortigate50EにOpenWrtいれてみる

ライセンス切れのFortigate 50Eを入手したので、OpenWrtをいれてみる。

手順は大破さんのブログにあるのでそれを参考にやる。

自分なりのつまづきポイントなども書いていく。

手順

FG-50Eのブートメニューに入る

まずコンソールにケーブルをさして、screenコマンドなどで通信を待機する。

その後、電源をさして起動する。起動中にPlease wait for OS to boot, or press any key to display configuration menuと表示されたときに、なにか適当なキーを押してブートメニューに入る。

TFTPサーバを用意する

設定を確認

ブートメニュー上でrを押してtftpサーバーの設定を確認する。

[C]: Configure TFTP parameters.
[R]: Review TFTP parameters.
[T]: Initiate TFTP firmware transfer.
[F]: Format boot device.
[I]: System information.
[B]: Boot with backup firmware and set as default.
[Q]: Quit menu and continue to boot.
[H]: Display this list of options.

Enter C,R,T,F,I,B,Q,or H:

Image download port:    WAN1
DHCP status:            Disabled
Local VLAN ID:          <NULL>
Local IP address:       192.168.1.188
Local subnet mask:      255.255.255.0
Local gateway:          192.168.1.254
TFTP server IP address: 192.168.1.168
Firmware file name:     image.out

WAN1に接続したPCで192.168.1.168でTFTPサーバーを立てて、image.outとしてinitramfsイメージを読ませるといいことがわかる(一応、cでパラメータを自分で設定できる)。

サーバーの準備

https://qiita.com/YusukeIwaki/items/ed81bb813153e9e40b58

上記を参考に準備する。

brew install dnsmasq

ここで、

sudo dnsmasq --log-debug --log-facility=/tmp/tftp.log  --keep-in-foreground -i en10 -p 0 -z --enable-tftp --tftp-root /tmp

を実行しようとするがen10がUPじゃないと立ち上がらないぽい。なので、50E側で待機モードにしてからtftpサーバーを立ち上げたり、IPの変更をする。

TFTPから読み込ませる

ブートメニュー上でtを押して転送待機状態にする。 ここでUSB-LANでmacと50Eのwan1を接続しておく。

Please connect TFTP server to Ethernet port 'WAN1'.

と表示されたらインターフェースがUP状態になるので

sudo dnsmasq --log-debug --log-facility=/tmp/tftp.log  --keep-in-foreground -i en10 -p 0 -z --enable-tftp --tftp-root /tmp

を実行する。

別ターミナルでログを見れる

sudo less +F /tmp/tftp.log

TFTPサーバからファイルを読み込みブートする

TFTPサーバーからinitramfsイメージを50Eにダウンロードさせて起動する。 待っても進まないときは、IPの設定を確認したり、dnsmasqコマンドを再度実行するとうまくいった。

Please connect TFTP server to Ethernet port 'WAN1'.

MAC: 70:4c:a5:ac:47:be

Connect to tftp server 192.168.1.168 ...

Retry count exceeded; starting again
MAC: 70:4c:a5:ac:47:be

Connect to tftp server 192.168.1.168 ...

############
Image Received.
Checking image... OK

Save as Default firmware/Backup firmware/Run image without saving:[D/B/R]?r

Save as Default firmware/Backup firmware/Run image without saving:[D/B/R]?というプロンプトが表示されるので、rをおして起動する。

メーカーファームウェアをバックアップ

root@OpenWrt:/# mkdir /tmp/mtd
root@OpenWrt:/# cd /tmp/mtd/
root@OpenWrt:/tmp/mtd# cat /proc/mtd
dev:    size   erasesize  name
mtd0: 001c0000 00010000 "u-boot"
mtd1: 00010000 00010000 "firmware-info"
mtd2: 00010000 00010000 "dtb"
mtd3: 00010000 00010000 "u-boot-env"
mtd4: 00010000 00010000 "board-info"
mtd5: 00600000 00010000 "kernel"
mtd6: 01800000 00010000 "rootfs"
mtd7: 00600000 00010000 "kn2"
mtd8: 01800000 00010000 "rfs2"
mtd9: 01200000 00010000 "part1"
mtd10: 01200000 00010000 "part2"
mtd11: 01e00000 00010000 "config"
root@OpenWrt:/tmp/mtd# dd if=/dev/mtdblock1 of=mtd1_firmware-info.bin
128+0 records in
128+0 records out
root@OpenWrt:/tmp/mtd# dd if=/dev/mtdblock5 of=mtd5_kernel.bin
12288+0 records in
12288+0 records out
root@OpenWrt:/tmp/mtd# dd if=/dev/mtdblock6 of=mtd6_rootfs.bin
49152+0 records in
49152+0 records out

/dev/mtdblock1, /dev/mtdblock5, /dev/mtdblock6の内容を最低限バックアップすればいいらしい。

PCからこのファイルをpullする。 USB-LANの設定はそのままでも良くて、LAN側に差し直す。 ここで192.168.1.1にpingできるか試す。 できたらscpコマンドでpullする。

❯ scp -O ./mtd1_firmware-info.bin [email protected]:/tmp/mtd/mtd1_firmware-info.bin
mtd1_firmware-info.bin                                                                 100%   64KB  15.8MB/s   00:00

❯ scp -O ./mtd6_rootfs.bin [email protected]:/tmp/mtd/mtd6_rootfs.bin
mtd6_rootfs.bin                                                                        100%   24MB  29.3MB/s   00:00

❯ scp -O ./mtd5_kernel.bin [email protected]:/tmp/mtd/mtd5_kernel.bin
mtd5_kernel.bin                                                                        100% 6144KB  28.9MB/s   00:00

起動するイメージとしてOpenWrtを書き込む(sysupgrade)

sysupgradeイメージをダウンロードする

50EのWAN1ポートにネットに繋がるLANケーブルをさしてsysupgradeイメージをダウンロードする。 バックアップ時と同様にscpでPCから転送しても良い。

https://openwrt.org/toh/hwdata/fortinet/fortinet_fortigate_50e

root@OpenWrt:/tmp# wget https://downloads.openwrt.org/snapshots/targets/mvebu/cortexa9/openwrt-mvebu-cortexa9-fortinet_fg-50e-squashfs-sysupgrade.bin

sysupgradeを実行する

root@OpenWrt:/tmp# sysupgrade openwrt-mvebu-cortexa9-fortinet_fg-50e-squashfs-sysupgrade.bin

(すぐ終わった)

sysupgradeから起動までのログ

root@OpenWrt:/tmp# sysupgrade openwrt-mvebu-cortexa9-fortinet_fg-50e-squashfs-sy
supgrade.bin
Cannot save config while running from ramdisk.
Sat Mar  2 13:25:57 UTC 2024 upgrade: Commencing upgrade. Closing all shell sessions.
Watchdog handover: fd=3
- watchdog -
Watchdog does not have CARDRESET support
Sat Mar  2 13:25:57 UTC 2024 upgrade: Sending TERM to remaining processes ...
Sat Mar  2 13:26:01 UTC 2024 upgrade: Sending KILL to remaining processes ...
[  826.407622] stage2 (3773)op_caches: Sat Mar  2 13:26:07 UTC 2024 upgrade: Switching to ramdisk...
Sat Mar  2 13:26:08 UTC 2024 upgrade: Performing system upgrade...
fwinfo: offset-> 0x184, blocks-> 0x1da4 (len: 0x003b46da)
1+0 records in
1+0 records out
fwinfo: offset-> 0x18c, blocks-> 0x1201 (len: 0x00240004)
1+0 records in
1+0 records out
Unlocking kernel ...

Writing from <stdin> to kernel ...
Unlocking rootfs ...

Writing from <stdin> to rootfs ...
Appending jffs2 data from /tmp/sysupgrade.tgz to rootfs..
.File /tmp/sysupgrade.tgz does not exist
Sat Mar  2 13:26:39 UTC 2024 upgrade: Upgrade completed
Sat Mar  2 13:26[  859.457829] reboot: Restg sys

FortiGate-50E (17:37-01.31.2017)
Ver:05000016
Serial number: FGT50E5618007179
CPU(00): 1600MHz
Total RAM: 2GB
Initializing boot device...
Initializing MAC... egiga1
Please wait for OS to boot, or press any key to display configuration menu..........

Booting OS...

Reading boot image... 3885056 bytes.
Initializing firewall...
[    0.000000] Booting Linux on physical CPU 0x0
[    0.000000] Linux version 6.1.79 (builder@buildhost) (arm-openwrt-linux-muslgnueabi-gcc (OpenWrt GCC 12.3.0 r25366-7f13b9f8be) 12.3.0, GNU ld (GNU Binutils) 2.40.0) #0 SMP Fri Mar  1 18:51:24 2024
...

できた!

できました。

WiFiルーターにOEM GUI経由でならインストール経験はありますが、シリアルとTFTP使ってのインストールは初めてやりました。 意外とつまづいた。

おまけ

簡単にOpenWrtの設定をしてみる。目標はLuCiの日本語化まで。

opkg update
opkg install luci
opkg install luci-i18n-base-ja

これだけだった。http://192.168.1.1にアクセスするとLuCiが見れた。

Built with Hugo
Theme Stack designed by Jimmy