Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Dec 22nd, 2011  |  syntax: None  |  size: 7.95 KB  |  hits: 129  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. # Install r29570 on TP-Link MR3220 v1
  2.  
  3. # Login with telnet, change root password, login with SSH
  4.  
  5. # Install packages to support extroot
  6. opkg update
  7. opkg install kmod-usb-storage kmod-fs-ext4 block-mount fdisk e2fsprogs swap-utils
  8.  
  9. # Wipe existing partition table from USB memory stick
  10. dd if=/dev/zero of=/dev/sda bs=64k count=1
  11.  
  12. # Partition USB memory stick with 64M swap, 256M root and rest as third partition
  13. cat | fdisk /dev/sda <<__EOF__
  14. n
  15. p
  16. 1
  17. 1
  18. +64M
  19. t
  20. 82
  21. n
  22. p
  23. 2
  24.  
  25. +256M
  26. n
  27. p
  28. 3
  29.  
  30.  
  31. w
  32. q
  33. __EOF__
  34.  
  35. # Should look like this
  36. root@OpenWrt:~# fdisk -l /dev/sda
  37.  
  38. Disk /dev/sda: 4206 MB, 4206886912 bytes
  39. 130 heads, 62 sectors/track, 1019 cylinders
  40. Units = cylinders of 8060 * 512 = 4126720 bytes
  41. Disk identifier: 0xcb85d70e
  42.  
  43.    Device Boot      Start         End      Blocks   Id  System
  44. /dev/sda1               1          17       68479   82  Linux swap / Solaris
  45. /dev/sda2              18          80      253890   83  Linux
  46. /dev/sda3              81        1019     3784170   83  Linux
  47.  
  48. # Create swap and filesystems, also set unique label in addition to automatically generated uuid
  49. mkswap    /dev/sda1 -L ow_swap_`dd if=/dev/urandom bs=1k count=1|tr -dc "a-f0-9"|cut -c1-6`
  50. mkfs.ext3 /dev/sda2 -L ow_root_`dd if=/dev/urandom bs=1k count=1|tr -dc "a-f0-9"|cut -c1-6`
  51. mkfs.ext3 /dev/sda3 -L ow_data_`dd if=/dev/urandom bs=1k count=1|tr -dc "a-f0-9"|cut -c1-6`
  52.  
  53. # Check label and uuid with blkid command
  54. root@OpenWrt:~# blkid
  55. /dev/mtdblock2: TYPE="squashfs"
  56. /dev/sda1: TYPE="swap" LABEL="ow_swap_53bdb3" UUID="3ebd4c59-fffd-47b5-b598-136ff740a20f"
  57. /dev/sda2: LABEL="ow_root_f479b3" UUID="0b4dfe19-3f7d-4579-983c-452ed9e4bc83" SEC_TYPE="ext2" TYPE="ext3"
  58. /dev/sda3: LABEL="ow_data_8505fb" UUID="a6ca6666-7639-4825-9eee-727718affd19" SEC_TYPE="ext2" TYPE="ext3"
  59.  
  60. # Configure swap to be enabled on next boot
  61. /etc/init.d/fstab stop
  62. uci delete fstab.@swap[0]
  63. uci commit fstab
  64. uci add fstab swap
  65. # Works with /dev/sda1 as device
  66. #uci set fstab.@swap[-1].device=/dev/sda1
  67. # Fails with label
  68. #uci set fstab.@swap[-1].label=`blkid -s LABEL /dev/sda1 | cut -d\" -f2`
  69. # Fails with uuid
  70. uci set fstab.@swap[-1].uuid=`blkid -s UUID /dev/sda1 | cut -d\" -f2`
  71. uci set fstab.@swap[-1].enabled=1
  72. uci commit fstab
  73.  
  74. # Configure extroot to be mounted on next boot
  75. uci delete fstab.@mount[0]
  76. uci commit fstab
  77. uci add fstab mount
  78. # Works with /dev/sda2 as device
  79. #uci set fstab.@mount[-1].device=/dev/sda2
  80. # Fails with label
  81. #uci set fstab.@mount[-1].label=`blkid -s LABEL /dev/sda2 | cut -d\" -f2`
  82. # Fails with uuid
  83. uci set fstab.@mount[-1].uuid=`blkid -s UUID /dev/sda2 | cut -d\" -f2`
  84. uci set fstab.@mount[-1].options=rw,sync,noatime
  85. uci set fstab.@mount[-1].fstype=ext3
  86. uci set fstab.@mount[-1].enabled_fsck=1
  87. uci set fstab.@mount[-1].enabled=1
  88. uci set fstab.@mount[-1].target=/
  89. # or with target=/overlay if using overlay mode
  90. uci commit fstab
  91.  
  92. # Configure data partition to be mounted on next boot
  93. mkdir -p /mnt/data
  94. uci add fstab mount
  95. # Works with /dev/sda3 as device
  96. #uci set fstab.@mount[-1].device=/dev/sda3
  97. # Fails with label
  98. #uci set fstab.@mount[-1].label=`blkid -s LABEL /dev/sda3 | cut -d\" -f2`
  99. # Fails with uuid
  100. uci set fstab.@mount[-1].uuid=`blkid -s UUID /dev/sda3 | cut -d\" -f2`
  101. uci set fstab.@mount[-1].options=rw,sync,noatime
  102. uci set fstab.@mount[-1].fstype=ext3
  103. uci set fstab.@mount[-1].enabled_fsck=1
  104. uci set fstab.@mount[-1].enabled=1
  105. uci set fstab.@mount[-1].target=/mnt/data
  106. uci commit fstab
  107.  
  108. # Disable anon mount feature
  109. uci set fstab.automount.anon_mount=0
  110. uci commit fstab
  111.  
  112. # Resulting /etc/config/fstab
  113. root@OpenWrt:~# cat /etc/config/fstab
  114.  
  115. config 'global' 'automount'
  116.         option 'from_fstab' '1'
  117.         option 'anon_mount' '0'
  118.  
  119. config 'global' 'autoswap'
  120.         option 'from_fstab' '1'
  121.         option 'anon_swap' '0'
  122.  
  123. config 'swap'
  124.         option 'uuid' '3ebd4c59-fffd-47b5-b598-136ff740a20f'
  125.         option 'enabled' '1'
  126.  
  127. config 'mount'
  128.         option 'uuid' '0b4dfe19-3f7d-4579-983c-452ed9e4bc83'
  129.         option 'options' 'rw,sync,noatime'
  130.         option 'fstype' 'ext3'
  131.         option 'enabled_fsck' '1'
  132.         option 'enabled' '1'
  133.         option 'target' '/'
  134.  
  135. config 'mount'
  136.         option 'uuid' 'a6ca6666-7639-4825-9eee-727718affd19'
  137.         option 'options' 'rw,sync,noatime'
  138.         option 'fstype' 'ext3'
  139.         option 'enabled_fsck' '1'
  140.         option 'enabled' '1'
  141.         option 'target' '/mnt/data'
  142.  
  143. # Populate new rootfs with content of existing rootfs
  144. mkdir -p /mnt/sda2 /tmp/cproot
  145. mount --bind / /tmp/cproot
  146. mount /dev/sda2 /mnt/sda2
  147. tar -C /tmp/cproot -cvf - . | tar -C /mnt/sda2 -xf -
  148. sync; umount /mnt/sda2 ; umount /tmp/cproot
  149.  
  150. # Activate extroot on next boot
  151. /etc/init.d/fstab enable
  152. /etc/init.d/fstab start
  153. /etc/init.d/fstab whole_root_enable
  154. # or if using overlay mode
  155. #/etc/init.d/fstab overlay_enable
  156.  
  157. # Reboot router
  158. reboot
  159.  
  160. # Login and check mounts after restart
  161. # Looks like extroot is not working but data partition was properly mounted with uuid
  162. root@OpenWrt:~# df -h
  163. Filesystem                Size      Used Available Use% Mounted on
  164. rootfs                    1.5M    848.0K    688.0K  55% /
  165. /dev/root                 1.5M      1.5M         0 100% /rom
  166. tmpfs                    14.4M     64.0K     14.3M   0% /tmp
  167. tmpfs                   512.0K         0    512.0K   0% /dev
  168. /dev/mtdblock3            1.5M    848.0K    688.0K  55% /overlay
  169. overlayfs:/overlay        1.5M    848.0K    688.0K  55% /
  170. /dev/sda2               240.1M     12.0M    215.7M   5% /tmp/whole_root-disabled
  171. /dev/sda3                 3.6G     71.3M      3.3G   2% /mnt/data
  172.  
  173. # Check that uuid's are still in place with blkid
  174. root@OpenWrt:~# blkid
  175. /dev/mtdblock2: TYPE="squashfs"
  176. /dev/sda1: TYPE="swap" LABEL="ow_swap_53bdb3" UUID="3ebd4c59-fffd-47b5-b598-136ff740a20f"
  177. /dev/sda2: LABEL="ow_root_f479b3" UUID="0b4dfe19-3f7d-4579-983c-452ed9e4bc83" SEC_TYPE="ext2" TYPE="ext3"
  178. /dev/sda3: LABEL="ow_data_8505fb" UUID="a6ca6666-7639-4825-9eee-727718affd19" SEC_TYPE="ext2" TYPE="ext3"
  179.  
  180. # Swap seems to be enabled
  181. root@OpenWrt:~# free
  182.              total         used         free       shared      buffers
  183. Mem:         29436        17936        11500            0         2244
  184. -/+ buffers:              15692        13744
  185. Swap:        68472            0        68472
  186.  
  187. # Switch from uuid's to device names
  188. uci delete fstab.@swap[-1].uuid
  189. uci set fstab.@swap[-1].device=/dev/sda1
  190. uci delete fstab.@mount[0].uuid
  191. uci set fstab.@mount[0].device=/dev/sda2
  192. uci delete fstab.@mount[1].uuid
  193. uci set fstab.@mount[1].device=/dev/sda3
  194. uci commit
  195.  
  196. # Resulting /etc/config/fstab
  197. root@OpenWrt:~# cat /etc/config/fstab
  198.  
  199. config 'global' 'automount'
  200.         option 'from_fstab' '1'
  201.         option 'anon_mount' '0'
  202.  
  203. config 'global' 'autoswap'
  204.         option 'from_fstab' '1'
  205.         option 'anon_swap' '0'
  206.  
  207. config 'swap'
  208.         option 'enabled' '1'
  209.         option 'device' '/dev/sda1'
  210.  
  211. config 'mount'
  212.         option 'options' 'rw,sync,noatime'
  213.         option 'fstype' 'ext3'
  214.         option 'enabled_fsck' '1'
  215.         option 'enabled' '1'
  216.         option 'target' '/'
  217.         option 'device' '/dev/sda2'
  218.  
  219. config 'mount'
  220.         option 'options' 'rw,sync,noatime'
  221.         option 'fstype' 'ext3'
  222.         option 'enabled_fsck' '1'
  223.         option 'enabled' '1'
  224.         option 'target' '/mnt/data'
  225.         option 'device' '/dev/sda3'
  226.  
  227. # Re-enable extroot
  228. /etc/init.d/fstab enable
  229. /etc/init.d/fstab start
  230. /etc/init.d/fstab whole_root_enable
  231.  
  232. # Reboot
  233. reboot
  234.  
  235. # Login and check if extroot is working
  236. # Yes, seems to work now.
  237. root@OpenWrt:~# df -h
  238. Filesystem                Size      Used Available Use% Mounted on
  239. rootfs                  240.1M     12.0M    215.7M   5% /
  240. /dev/root                 1.5M      1.5M         0 100% /rom
  241. tmpfs                    14.4M     60.0K     14.3M   0% /tmp
  242. tmpfs                   512.0K         0    512.0K   0% /dev
  243. /dev/sda2               240.1M     12.0M    215.7M   5% /
  244. /dev/sda3                 3.6G     71.3M      3.3G   2% /mnt/data