Advertisement
sa-kt

mount_vacant_space

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