路由器為TP-Link Archer C7 v5,OpenWrt版本19.07.1
C:\Users\User>ssh [email protected]
[email protected]'s password:
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.1, r10911-c155900f66
-----------------------------------------------------
root@OpenWrt:~#
ssh 進去你的路由器
$ ssh [email protected]
安裝所需驅動
#refresh software packages
$ opkg update
#install usb drives
$ opkg install kmod-usb-storage
$ opkg install kmod-usb-storage-uas
$ opkg install usbutils
檢查usb是否被成功檢測
$ lsusb -t
output
root@OpenWrt:~# lsusb -t
/: Bus 01.Port 1: Dev 1, Class=root_hub, Driver=ehci-platform/1p, 480M
|__ Port 1: Dev 2, If 0, Class=Mass Storage, Driver=usb-storage, 480M
看見Driver=usb-storage
就代表已檢測到你的usb裝置
輸入
$ ls -l /dev/sd*
output
root@OpenWrt:~# ls -l /dev/sd*
brw------- 1 root root 8, 0 Jan 1 1970 /dev/sda
brw------- 1 root root 8, 1 Jan 1 1970 /dev/sda1
brw------- 1 root root 8, 5 Jan 1 1970 /dev/sda5
brw------- 1 root root 8, 6 Jan 1 1970 /dev/sda6
brw------- 1 root root 8, 7 Jan 1 1970 /dev/sda7
註:sda5
, sda6
, sda7
為我的usb裝置
安裝block
工具查看詳細資料
$ opkg install block-mount
使用block
工具
$ block info | grep "/dev/sd"
output
root@OpenWrt:~# block info | grep "/dev/sd"
/dev/sda5: VERSION="1" TYPE="swap"
/dev/sda6: UUID="c79e3fb7-e7ea-4855-87fa-30e1b769678f" VERSION="1.0" MOUNT="/overlay" TYPE="ext4"
/dev/sda7: UUID="e7bd5e85-552a-4d0c-af38-720291d6d2c4" VERSION="1.0" MOUNT="/data" TYPE="ext4"
如你的usb裝置已格式化分區,那則會顯示出來,如上面的/dev/sda5
, /dev/sda6
, /dev/sda7
因我的usb裝置建立好分區已經是一年前的事了,忘了怎樣做,故現貼上官方教學,有機會再攝寫實戰教學
Create a partition on the USB disk
if the previous chapter did not list any existing partitions (like “/dev/sda1”, “/dev/sda2”, “/dev/sdb1”…), you have to create a partition first for further storage usage.
To do so, install gdisk:
$ opkg install gdisk
Start gdisk with the disk name identified in the previous chapter:
$ gdisk /dev/sda
In the interactive gdisk menu, create a partition with gdisk command
$ n
This triggers an interactive dialogue: Use the suggested defaults for the partition creation (number, starting sector, size, Hex code)
When done, confirm the changes with gdisk interactive command
$ w
and then confirm your choice with
$ Y
Refer to the gdisk help text (write “?”) in case you need additional help. Stick to a single partition, to stay aligned to the following HowTo.
usb hard disk -> ext4
$ opkg install e2fsprogs
$ opkg install kmod-fs-ext4
#please edit /dev/sda* to desire partitions, eg. /dev/sda5
$ mkfs.ext4 /dev/sda*
SSD drives and thumb drives -> F2FS
$ opkg install f2fs-tools
$ opkg install kmod-fs-f2fs
#please edit /dev/sda* to desire partitions, eg. /dev/sda5
$ mkfs.f2fs /dev/sda*
data 和 swap分區校易設置
安裝nano (雖然內置vi但很難用)
#refresh package list and install nano
$ opkg update && opkg install nano
更改fstab設置 (我不想用uci逐一設置,太麻煩了)
按照你的usb裝置進行修改,然後使用nano編輯/etc/config/fstab
#/etc/config/fstab
config global
option anon_swap '0'
option anon_mount '0'
option auto_swap '1'
option auto_mount '1'
option delay_root '5'
option check_fs '0'
config mount
option enabled '1'
option target '/data'
option uuid 'e7bd5e85-552a-4d0c-af38-720291d6d2c4'
config swap
option enabled '1'
option device '/dev/sda5'
將fstab
服務設為開機自啟動
$ /etc/init.d/fstab boot
# or
# in this case , I use the following
$ /etc/init.d/fstab enable
# or
$ service fstab boot
# or
$ service fstab enable
儲存後重啟
$ reboot
設置/overlay
分區
增加/etc/config/fstab
設置
config mount 'overlay'
option uuid 'f112c97c-1b84-a949-989f-3cd15c226e2e'
option target '/overlay'
option enabled '1'
轉移原/overlay
數據至外置usb
#/dev/sd* is your usb device/partition
$ mount /dev/sda* /mnt
$ cp -a -f /overlay/. /mnt
$ umount /mnt
重啟路由器
$ reboot
檢查效果
$ df
output
root@OpenWrt:/etc/config# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/root 2816 2816 0 100% /rom
tmpfs 62260 4084 58176 7% /tmp
/dev/sda6 1011384 14220 928572 2% /overlay
overlayfs:/overlay 1011384 14220 928572 2% /
tmpfs 512 0 512 0% /dev
/dev/sda7 304547896 77212 288930820 0% /data
註意未掛載並use% 是42%,掛載後為2%
ps: 這裡其可不重新啟動路由器,手動掛載mount /dev/sd* /overlay
,但為確保設置正常運作,reboot
一次確認自動掛載機能正常運作。
hdparm: 使用commandl line 管理
$ opkg update && opkg install hdparm
#setting harddisk idle
#/dev/sda* is your harddisk/partition, eg. /dev/sda5
hdparm -S 240 /dev/sda*
hd-idle (With LuCi integration): 使Luci圖形介面設置
$ opkg update && opkg install luci-app-hd-idle
進入luci, service -> hd-idle