sa-kt

mount_vacant_space

Feb 13th, 2025 (edited)
571
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.87 KB | None | 0 0
  1. #!/bin/sh /etc/rc.common
  2. # Unlock MTD partitions at startup
  3. START=10
  4.  
  5. # 20250213 初版
  6. # 20250225 I-O DATA WN-DX1200GRを追加
  7.  
  8. # スクリプト名を取得
  9. SCRIPT_NAME=$(basename "$0")
  10.  
  11. # モデル名を取得
  12. MODEL=$(ubus call system board | jsonfilter -e '@.model')
  13.  
  14. # モデルに応じた MTD_NUM と UBI_VOLUME の設定
  15. case "$MODEL" in
  16. "Buffalo WSR-3200AX4S")
  17. MTD_NUM=11
  18. UBI_VOLUME="dpi"
  19. ;;
  20. "ELECOM WRC-X3200GST3")
  21. MTD_NUM=10
  22. UBI_VOLUME="dpi"
  23. ;;
  24.  
  25. "I-O DATA WN-DX1200GR")
  26. MTD_NUM=6
  27. UBI_VOLUME="dpi"
  28. ;;
  29.  
  30. *)
  31. echo "$SCRIPT_NAME: Unsupported model: $MODEL" > /dev/kmsg
  32. exit 1
  33. ;;
  34. esac
  35.  
  36. # 成功した場合のログ出力
  37. echo "$SCRIPT_NAME: Model detected: $MODEL, MTD_NUM=$MTD_NUM, UBI_VOLUME=$UBI_VOLUME" > /dev/kmsg
  38.  
  39. # 変数定義
  40. MTD_DEV="/dev/mtd$MTD_NUM"
  41. MOUNT_POINT="/mnt/vacant_space"
  42.  
  43. boot() {
  44. echo "$SCRIPT_NAME: Unlocking MTD partitions..." > /dev/kmsg
  45.  
  46. # 1. insmod mtd-rw
  47. if insmod mtd-rw i_want_a_brick=1; then
  48. echo "$SCRIPT_NAME: insmod mtd-rw successful" > /dev/kmsg
  49. else
  50. echo "$SCRIPT_NAME: insmod mtd-rw failed" > /dev/kmsg
  51. fi
  52.  
  53. # 2. mtd unlock
  54. if mtd unlock "$MTD_DEV"; then
  55. echo "$SCRIPT_NAME: mtd unlock $MTD_DEV successful" > /dev/kmsg
  56. else
  57. echo "$SCRIPT_NAME: mtd unlock $MTD_DEV failed" > /dev/kmsg
  58. fi
  59.  
  60. # 3. ubiattach
  61. if ubiattach -m "$MTD_NUM"; then
  62. echo "$SCRIPT_NAME: ubiattach -m $MTD_NUM successful" > /dev/kmsg
  63. else
  64. echo "$SCRIPT_NAME: ubiattach -m $MTD_NUM failed" > /dev/kmsg
  65. fi
  66.  
  67. # 'UBI_VOLUME' ボリュームを含む UBI デバイスの特定
  68. ubi_dev=""
  69. for dev in /dev/ubi[0-9]*; do
  70. if ubinfo "$dev" -a | grep -q "Name: *$UBI_VOLUME"; then
  71. ubi_dev="${dev#/dev/}"
  72. break
  73. fi
  74. done
  75.  
  76. if [ -z "$ubi_dev" ]; then
  77. echo "$SCRIPT_NAME: Failed to detect UBI device containing '$UBI_VOLUME' volume" > /dev/kmsg
  78. ubi_dev="ubi1" # デフォルトで ubi1 を使用
  79. else
  80. echo "$SCRIPT_NAME: Detected UBI device: $ubi_dev" > /dev/kmsg
  81. fi
  82.  
  83. # マウント処理
  84. mkdir -p "$MOUNT_POINT"
  85. if mount -t ubifs "$ubi_dev:$UBI_VOLUME" "$MOUNT_POINT"; then
  86. echo "$SCRIPT_NAME: Mount succeeded: '$UBI_VOLUME' volume mounted on $MOUNT_POINT" > /dev/kmsg
  87. # 容量を多く消費する /usr/sbin を空き地へ置き換える。bind でマウント
  88. if [ ! -d "$MOUNT_POINT/usr_sbin" ]; then
  89. mkdir -p "$MOUNT_POINT/usr_sbin"
  90. cp -a /usr/sbin/* "$MOUNT_POINT/usr_sbin"
  91. fi
  92. mount --bind "$MOUNT_POINT/usr_sbin" /usr/sbin
  93. else
  94. echo "$SCRIPT_NAME: Mount failed: Unable to mount '$UBI_VOLUME' volume on $MOUNT_POINT" > /dev/kmsg
  95. exit
  96. fi
  97. }
  98.  
Advertisement
Add Comment
Please, Sign In to add comment