This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
usb_formatting_with_swap_partition [2021/02/22 23:24] – [Final setup]-added Overview link hogwild | usb_formatting_with_swap_partition [2024/03/27 15:32] – [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, |
- | Assuming | + | This example assumes |
- | + | ||
- | 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 | + | This assumes your drive' |
- | The **echo 1000M** statement below defines the size of the swap partition (in MB). You may want to adjust that, according 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: | ||
- | < | + | \\ |
+ | |||
+ | < | ||
device=/ | device=/ | ||
partition=$device' | partition=$device' | ||
+ | swappartition=$device' | ||
nvram set usb_automount=" | nvram set usb_automount=" | ||
- | (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 | + | # mkfs.ext2 -L usb $partion |
- | swapon | + | # mkfs.vfat -n usb $partion |
- | mkdir /mnt/sda1 && mount /dev/sda1 /mnt/sda1 | + | mkswap |
+ | swapon | ||
+ | mkdir /mnt/usb && mount /dev/sda1 /mnt/usb | ||
nvram set usb_automount=" | nvram set usb_automount=" | ||
- | |||
</ | </ | ||
+ | \\ | ||
- | ===== 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:// | [[https:// | ||
- | Via SSH: delete any existing partitions: | + | \\ \\ Then, logon via SSH or Telnet and delete any existing partitions: |
- | <font inherit/ | + | <code -> |
+ | fdisk /dev/sda | ||
- | <font inherit/ | + | o |
- | <font inherit/ | + | At this point your USB flash drive is unpartitioned. Now let's create the necessary partition table: |
- | <font inherit/ | + | n |
- | <font inherit/ | + | p |
- | <font inherit/ | + | 2 |
- | <font inherit/ | + | ENTER |
- | <font inherit/ | + | +1000M (Essentially 1 GB will used for swap) |
- | <font inherit/ | + | t |
- | <font inherit/ | + | 82 |
- | <font inherit/ | + | n |
- | <font inherit/ | + | p ENTER |
- | \\ | + | |
- | ENTER (default)</ | + | |
- | <font inherit/ | + | ENTER |
- | <font inherit/ | + | l (to verify) |
- | <font inherit/ | + | w (write to save changes |
+ | </code> | ||
- | At this point you should have two unformatted partitions on your USB flash drive: | + | |
- | sda1 ~14GB (fs-type ext2/3/4)\\ | + | * sda1 |
- | sda2 ~1GB (fs-type swap) | + | |
[[https:// | [[https:// | ||
- | Now, let's format the partitions. **NOTE:** it is suggested you use **<font inherit/ | + | \\ |
- | < | + | |
+ | | ||
+ | |||
+ | <code -> | ||
mkfs.ext2 -L USB /dev/sda1 | mkfs.ext2 -L USB /dev/sda1 | ||
mkswap /dev/sda2 | mkswap /dev/sda2 | ||
- | |||
</ | </ | ||
- | Now, mount the partitions | + | |
- | < | + | < |
swapon /dev/sda2 | swapon /dev/sda2 | ||
mkdir /mnt/sda1 && mount /dev/sda1 /mnt/sda1 | mkdir /mnt/sda1 && mount /dev/sda1 /mnt/sda1 | ||
+ | </ | ||
+ | | ||
+ | |||
+ | 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, | ||
+ | |||
+ | |||
+ | \\ | ||
+ | |||
+ | ==== Activating Swap Partition (Post Mount Command) ==== | ||
+ | |||
+ | To activate the swap partition you created on the drive, enter the following into the "**Run after mounting**" | ||
+ | |||
+ | \\ | ||
+ | |||
+ | <code -> | ||
+ | swapon /dev/sda2 | ||
</ | </ | ||
- | You can now re-enable USB Automount on the USB and NAS menu. | + | \\ |
+ | |||
+ | The field should look like this: | ||
+ | |||
+ | {{: | ||
+ | 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, **/// | ||
+ | |||
+ | \\ | ||
+ | |||
+ | <code -> | ||
+ | swapoff /dev/sda2 | ||
+ | </ | ||
+ | |||
+ | \\ | ||
+ | |||
+ | The field should appear like this: | ||
+ | |||
+ | {{: | ||
+ | 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: | + | |
+ | |||
+ | \\ [[https:// | ||
+ | |||
+ | | ||
- | [[https:// | + | \\ [[https:// |
- | Under Attached Devices, you should see something similar | + | |
- | [[https:// | + | |
- | To verify the swap partition is working well, check the [[: | + | \\ |
- | [[https:// | + | \\ |