Site Tools


usb_formatting_with_swap_partition

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
usb_formatting_with_swap_partition [2021/02/22 23:24] – [Final setup]-added Overview link hogwildusb_formatting_with_swap_partition [2024/03/27 15:32] (current) – [Deactivating the Swap Partition (Pre-unmount command)] -condense hogwild
Line 1: Line 1:
 ====== USB formatting with swap partition ====== ====== USB formatting with swap partition ======
  
-It is highly advisable to make some form of permanent storage available to Tomato. A swap partition can prevent several types of insufficient RAM symptoms, such as system instability, failing processes, and in very severe cases, even spontaneous reboots. All this will depend largely on the network load and on Tomato's configuration. Some functions require much more RAM than others, and higher network traffic will put more load on the router and require more RAM than lower traffic. USB is an excellent candidate for providing swap space.+A swap partition can prevent several types of insufficient RAM symptoms, such as system instability, failing processes, and in severe cases, even reboots. All this depends largely on the network load and on FreshTomato's configuration. Some functions require much more RAM than others, and higher network traffic puts more load on the router and requires more RAM. USB storage is an excellent way to provide swap space.
  
-Assuming you are using either an ARM build or MIPS build with USB support, it is assumed you have already have USB support enabled. If you're not sure how to enable USB support, check the USB and NAS/[[:usb_support|USB Support]] menu. +This example assumes you are using an ARM or MIPS build with USB support, and USB support is already enabled. If you're not sure how to enable USB support, check the [[nas-usb|USB Support]] page.
- +
-For this example I'm using a 16GB USB 3.0 USB flash drive which is seen in the system as device **sda**.+
  
 +For this example, we use a 16GB USB flash drive seen in the system as device **sda**.
  
 ===== Automatic method ===== ===== Automatic method =====
  
-This assumes your drive device device name is sda ! If it's not, make sure to change the following commands consistent with your drive's device name.+This assumes your drive'device name is "sda! If it's not, remember to change these commands consistent with your drive's device name.
  
-The **echo 1000M** statement below defines the size of the swap partition (in MB). You may want to adjust thataccording to your needs.+The **echo 1000M** statement below defines the size of the swap partition (in MB). You may adjust that according to your needs. 
 + 
 + \\
  
 Then enter: Then enter:
  
-<code>+ \\ 
 + 
 +<code ->
 device=/dev/sda device=/dev/sda
 partition=$device'1' partition=$device'1'
 +swappartition=$device'2'
 nvram set usb_automount="0" nvram set usb_automount="0"
-(echo o; echo n; echo p; echo 2; echo ; echo 1000M; echo t; echo 82; echo n; echo p; echo 1; echo ; echo ; echo w) | fdisk $device +(echo o; echo n; echo p; echo 2; echo ; echo +1000M; echo t; echo 82; echo n; echo p; echo 1; echo ; echo ; echo w) | fdisk $device 
-mkfs.ext2 -L USB $partion +# Uncomment the preferred option here below: 
-mkswap /dev/sda2 +mkfs.ext2 -L usb $partion 
-swapon /dev/sda2 +# mkfs.vfat -n usb $partion 
-mkdir /mnt/sda1 && mount /dev/sda1 /mnt/sda1+mkswap -L swap $swappartion 
 +swapon swap 
 +mkdir /mnt/usb && mount /dev/sda1 /mnt/usb
 nvram set usb_automount="1" nvram set usb_automount="1"
- 
 </code> </code>
  
 + \\
  
-===== Manual method=====+===== Manual method =====
  
-From the Web interface, disable the Automount checkbox in the **USB and NAS/USB Support** menu.+From the Web interface, disable the Automount checkbox in the [[nas-usb|USB Support]] menu. 
 + 
 + \\
  
 [[https://wiki.freshtomato.org/lib/exe/detail.php?id=usb_formatting_with_swap_partition&media=a8e2b7301ceba934bba6b9ca1b53e79d.png|{{:a8e2b7301ceba934bba6b9ca1b53e79d.png}}]] [[https://wiki.freshtomato.org/lib/exe/detail.php?id=usb_formatting_with_swap_partition&media=a8e2b7301ceba934bba6b9ca1b53e79d.png|{{:a8e2b7301ceba934bba6b9ca1b53e79d.png}}]]
  
-Via SSHdelete any existing partitions:+ \\ \\ Then, logon via SSH or Telnet and delete any existing partitions: \\   \\
  
-<font inherit/Courier New,Courier,monospace;;inherit;;inherit>fdisk /dev/sda</font>+<code -> 
 +fdisk /dev/sda
  
-<font inherit/Courier New,Courier,monospace;;inherit;;inherit>o</font>+o
  
-<font inherit/Courier New,Courier,monospace;;inherit;;inherit>At this point your USB flash drive is unpartitioned. Now let's create the necessary partition table:</font>+At this point your USB flash drive is unpartitioned. Now let's create the necessary partition table:
  
-<font inherit/Courier New,Courier,monospace;;inherit;;inherit>n</font>+n
  
-<font inherit/Courier New,Courier,monospace;;inherit;;inherit>p</font>+p
  
-<font inherit/Courier New,Courier,monospace;;inherit;;inherit>2</font>+2
  
-<font inherit/Courier New,Courier,monospace;;inherit;;inherit>ENTER (default)</font>+ENTER
  
-<font inherit/Courier New,Courier,monospace;;inherit;;inherit>1000M (Essentially 1 GB out for swap)</font>++1000M (Essentially 1 GB will used for swap)
  
-<font inherit/Courier New,Courier,monospace;;inherit;;inherit>t</font>+t
  
-<font inherit/Courier New,Courier,monospace;;inherit;;inherit>82</font>+82
  
-<font inherit/Courier New,Courier,monospace;;inherit;;inherit>n</font>+n
  
-<font inherit/Courier New,Courier,monospace;;inherit;;inherit>p\\ +p ENTER
-\\ +
-ENTER (default)</font>+
  
-<font inherit/Courier New,Courier,monospace;;inherit;;inherit>ENTER (default)</font>+ENTER
  
-<font inherit/Courier New,Courier,monospace;;inherit;;inherit>l (to verify)</font>+l (to verify)
  
-<font inherit/Courier New,Courier,monospace;;inherit;;inherit>w (to save and exit fdisk)</font>+w (write to save changes and exit fdisk) 
 +</code>
  
-At this point you should have two unformatted partitions on your USB flash drive:+ \\   \\  \\ At this pointyou should have two unformatted partitions on your flash drive:
  
-sda1 ~14GB (fs-type ext2/3/4)\\ +  * sda1   ~14GB  (fs-type ext2/3/4)  
-sda2 ~1GB (fs-type swap)+  sda2   ~1GB    (fs-type swap) \\  \\
  
 [[https://wiki.freshtomato.org/lib/exe/detail.php?id=usb_formatting_with_swap_partition&media=e92d2a33dbc6d3751c2da1c999e4922a.png|{{:e92d2a33dbc6d3751c2da1c999e4922a.png}}]] [[https://wiki.freshtomato.org/lib/exe/detail.php?id=usb_formatting_with_swap_partition&media=e92d2a33dbc6d3751c2da1c999e4922a.png|{{:e92d2a33dbc6d3751c2da1c999e4922a.png}}]]
  
-Now, let's format the partitions. **NOTE:** it is suggested you use **<font inherit/inherit;;#c0392b;;inherit>ext2</font>**  for USB flash drives and ext3 for hard disks. + \\
-<code>+
  
 + \\  \\ Now, format the partitions. The ext2 filesystem is recommended for USB flash drives and ext3 for hard disks/SSDs. \\ \\
 +
 +<code ->
 mkfs.ext2 -L USB /dev/sda1 mkfs.ext2 -L USB /dev/sda1
 mkswap /dev/sda2 mkswap /dev/sda2
- 
 </code> </code>
  
-Now, mount the partitions+ \\  Next, mount the partitions: \\ \\
  
-<code>+<code ->
 swapon /dev/sda2 swapon /dev/sda2
 mkdir /mnt/sda1 && mount /dev/sda1 /mnt/sda1 mkdir /mnt/sda1 && mount /dev/sda1 /mnt/sda1
 +</code>
  
 + \\  \\
 +
 +You can now re-enable USB Automount on the [[nas-usb|USB Support]] menu.
 +
 + \\
 +
 +
 +===== Configuring Post-mount and Pre-unmount Commands =====
 +
 +For best practice, the swap partition should be activated as swap once the USB drive/flash is mounted. Additionally, it's best to deactivate swap partitions before unmounting them. It is quite simple to configure both the post-mount and pre-unmount commands. The methods for both are as follows:
 +
 +
 + \\
 +
 +==== Activating Swap Partition (Post Mount Command) ====
 +
 +To activate the swap partition you created on the drive, enter the following into the "**Run after mounting**" form field:
 +
 + \\
 +
 +<code ->
 +swapon /dev/sda2
 </code> </code>
  
-You can now re-enable USB Automount on the USB and NAS menu.+ \\ 
 + 
 +The field should look like this: 
 + 
 +{{:pasted:20240327-054257.png?nolink&nocache}}(( 
 +You may have additional commands within the field. 
 +)) 
 + 
 + \\ 
 + 
 + 
 +==== Deactivating the Swap Partition (Pre-unmount command) ==== 
 + 
 +To configure the router to automatically deactivate the swap partition (in this case, **///dev/sda2//**) , the "**Run before unmounting**" field needs to be populated with the following: 
 + 
 + \\ 
 + 
 +<code -> 
 +swapoff /dev/sda2  
 +</code> 
 + 
 + \\ 
 + 
 +The field should appear like this: 
 + 
 +{{:pasted:20240327-060929.png?nolink}}(( 
 +Again, your form field may have additional data within it. 
 +)) 
 + 
 +In both cases, click the Save button at the bottom before continuing.
  
  
 ===== Final setup ===== ===== Final setup =====
  
-The USB flash drive is now formatted. Your USB and NAS page settings should look like this:+ \\  The USB flash drive is now formatted. Your USB and NAS page settings should look like this: 
 + 
 +\\ [[https://wiki.freshtomato.org/lib/exe/detail.php?id=usb_formatting_with_swap_partition&media=935fc69f3e8c4985542e9dbb9a4834ef.png|{{:935fc69f3e8c4985542e9dbb9a4834ef.png}}]] 
 + 
 + \\   \\  Under Attached Devices, you should see something similar to this:
  
-[[https://wiki.freshtomato.org/lib/exe/detail.php?id=usb_formatting_with_swap_partition&media=935fc69f3e8c4985542e9dbb9a4834ef.png|{{:935fc69f3e8c4985542e9dbb9a4834ef.png}}]]+\\ [[https://wiki.freshtomato.org/lib/exe/detail.php?id=usb_formatting_with_swap_partition&media=2741fc91e0778274bec4230fe9e3e686.png|{{:2741fc91e0778274bec4230fe9e3e686.png?813}}]]
  
-Under Attached Devicesyou should see something similar to this:+ \\   \\ To verify the swap partition works properlycheck the [[status-overview|Overview]] menu. You should see details related to swap space:
  
-[[https://wiki.freshtomato.org/lib/exe/detail.php?id=usb_formatting_with_swap_partition&media=2741fc91e0778274bec4230fe9e3e686.png|{{:2741fc91e0778274bec4230fe9e3e686.png}}]]+ \\ [[https://wiki.freshtomato.org/lib/exe/detail.php?id=usb_formatting_with_swap_partition&media=dbae47af7a43e0a02c8637092a2edd2b.png|{{:dbae47af7a43e0a02c8637092a2edd2b.png}}]]
  
-To verify the swap partition is working well, check the [[:overview|Overview]] menu. You should see information related to swap space:+ \\
  
-[[https://wiki.freshtomato.org/lib/exe/detail.php?id=usb_formatting_with_swap_partition&media=dbae47af7a43e0a02c8637092a2edd2b.png|{{:dbae47af7a43e0a02c8637092a2edd2b.png}}]]+ \\
  
  
usb_formatting_with_swap_partition.1614036290.txt.gz · Last modified: 2021/02/22 23:24 by hogwild