Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh /etc/rc.common
- # Unlock MTD partitions at startup
- START=10
- # 20250213版
- # スクリプト名を取得
- SCRIPT_NAME=$(basename "$0")
- # モデル名を取得
- MODEL=$(ubus call system board | jsonfilter -e '@.model')
- # モデルに応じた MTD_NUM と UBI_VOLUME の設定
- case "$MODEL" in
- "Buffalo WSR-3200AX4S")
- MTD_NUM=11
- UBI_VOLUME="dpi"
- ;;
- "ELECOM WRC-X3200GST3")
- MTD_NUM=10
- UBI_VOLUME="dpi"
- ;;
- *)
- echo "$SCRIPT_NAME: Unsupported model: $MODEL" > /dev/kmsg
- exit 1
- ;;
- esac
- # 成功した場合のログ出力
- echo "$SCRIPT_NAME: Model detected: $MODEL, MTD_NUM=$MTD_NUM, UBI_VOLUME=$UBI_VOLUME" > /dev/kmsg
- # 変数定義
- MTD_DEV="/dev/mtd$MTD_NUM"
- MOUNT_POINT="/mnt/vacant_space"
- boot() {
- echo "$SCRIPT_NAME: Unlocking MTD partitions..." > /dev/kmsg
- # 1. insmod mtd-rw
- if insmod mtd-rw i_want_a_brick=1; then
- echo "$SCRIPT_NAME: insmod mtd-rw successful" > /dev/kmsg
- else
- echo "$SCRIPT_NAME: insmod mtd-rw failed" > /dev/kmsg
- fi
- # 2. mtd unlock
- if mtd unlock "$MTD_DEV"; then
- echo "$SCRIPT_NAME: mtd unlock $MTD_DEV successful" > /dev/kmsg
- else
- echo "$SCRIPT_NAME: mtd unlock $MTD_DEV failed" > /dev/kmsg
- fi
- # 3. ubiattach
- if ubiattach -m "$MTD_NUM"; then
- echo "$SCRIPT_NAME: ubiattach -m $MTD_NUM successful" > /dev/kmsg
- else
- echo "$SCRIPT_NAME: ubiattach -m $MTD_NUM failed" > /dev/kmsg
- fi
- # 'UBI_VOLUME' ボリュームを含む UBI デバイスの特定
- ubi_dev=""
- for dev in /dev/ubi[0-9]*; do
- if ubinfo "$dev" -a | grep -q "Name: *$UBI_VOLUME"; then
- ubi_dev="${dev#/dev/}"
- break
- fi
- done
- if [ -z "$ubi_dev" ]; then
- echo "$SCRIPT_NAME: Failed to detect UBI device containing '$UBI_VOLUME' volume" > /dev/kmsg
- ubi_dev="ubi1" # デフォルトで ubi1 を使用
- else
- echo "$SCRIPT_NAME: Detected UBI device: $ubi_dev" > /dev/kmsg
- fi
- # マウント処理
- mkdir -p "$MOUNT_POINT"
- if mount -t ubifs "$ubi_dev:$UBI_VOLUME" "$MOUNT_POINT"; then
- echo "$SCRIPT_NAME: Mount succeeded: '$UBI_VOLUME' volume mounted on $MOUNT_POINT" > /dev/kmsg
- # 容量を多く消費する /usr/sbin を空き地へ置き換える。bind でマウント
- if [ ! -d "$MOUNT_POINT/usr_sbin" ]; then
- mkdir -p "$MOUNT_POINT/usr_sbin"
- cp -a /usr/sbin/* "$MOUNT_POINT/usr_sbin"
- fi
- mount --bind "$MOUNT_POINT/usr_sbin" /usr/sbin
- else
- echo "$SCRIPT_NAME: Mount failed: Unable to mount '$UBI_VOLUME' volume on $MOUNT_POINT" > /dev/kmsg
- exit
- fi
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement