What's new
  • SNBForums Code of Conduct

    SNBForums is a community for everyone, no matter what their level of experience.

    Please be tolerant and patient of others, especially newcomers. We are all here to share and learn!

    The rules are simple: Be patient, be nice, be helpful or be gone!

Tutorial [Scripts][2025-12-07] SSD TRIM, IPSet-based Firewall & Tunnel Director, IPv6 Enhancements, WG Port Forwarder, and more

Hello. I copied the repo to my jffs folder and then made the files executable. But when I run sls
I get:

Code:
: not foundscripts/sdn/sdn_v6_shared.sh: line 2:
: not foundscripts/sdn/sdn_v6_shared.sh: line 10:
-sh: /jffs/scripts/sdn/sdn_v6_shared.sh: line 48: syntax error: unexpected word (expecting "do")

May I know where I am going wrong? Thanks.

I am only interested in IPv6 SLAAC and RA support for SDN networks currently. Thanks

Trying on Asus GT-AX6000 on 3006.102.6
 
Hello. I copied the repo to my jffs folder and then made the files executable. But when I run sls
I get:

Code:
: not foundscripts/sdn/sdn_v6_shared.sh: line 2:
: not foundscripts/sdn/sdn_v6_shared.sh: line 10:
-sh: /jffs/scripts/sdn/sdn_v6_shared.sh: line 48: syntax error: unexpected word (expecting "do")

May I know where I am going wrong? Thanks.

I am only interested in IPv6 SLAAC and RA support for SDN networks currently. Thanks

Trying on Asus GT-AX6000 on 3006.102.6
It looks like a similar issue to the one @Milan encountered in this thread. Are you using a Windows tool like WinSCP to upload the files? It can mess up line endings. If so, could you change the transfer mode to binary (or a similar option) and reupload the files?

Generally, you only need the files explicitly listed in the SDN section: everything in /jffs/scripts/sdn, dhcpc-event + dnsmasq-sdn.postconf + firewall-start in /jffs/scripts, and profile.add in /jffs/configs. Everything else is not needed.
 
It looks like a similar issue to the one @Milan encountered in this thread. Are you using a Windows tool like WinSCP to upload the files? It can mess up line endings. If so, could you change the transfer mode to binary (or a similar option) and reupload the files?

Generally, you only need the files explicitly listed in the SDN section: everything in /jffs/scripts/sdn, dhcpc-event + dnsmasq-sdn.postconf + firewall-start in /jffs/scripts, and profile.add in /jffs/configs. Everything else is not needed.
I used the scp which comes with windows now, I think its a part of OpenSSH. I will try to upload from a wsl distro and see if that is any better. Thanks.
 
Maybe when I’m brave enough to tinker with a non-critical router not affected by WAF…
So, I plucked up the courage to try this and wrote down my simplified steps for other folks wanting just SSD Trim but daunted by the process. Assumes you have SSH access to your Router (I use Putty) and can make Dirs and Transfer files (I use WinSCP).

Simplified how to (assuming using WinSCP for file transfers) setup SSD Trim ONLY:
  • Create new directory “ssd” on router under /jffs/scripts/ i.e. /jffs/scripts/ssd.
  • Create new directory “utils” on router under /jffs/scripts/ i.e. /jffs/scripts/utils.
  • If asked by WinSCP, give these dirs 0644 permissions, which I believe is the default anyway.
  • Download the (currently) two files config.sh and ssd_trim.sh from the link on kuchovsky GitHub (see links below) to your desktop. Note: to download them without each being turned into html, do NOT right click save as, but rather click the file, then select download "raw" file.
  • Absolutely not necessary, but if you want to be neat, put them both in a local dir /jffs/scripts/ssd.
  • Similarly, download the common.sh file to your desktop. Again. not necessary, but if you want to be neat, put it in a local dir /jffs/scripts/utils.
  • WinSCP these three "raw" files from your desktop to the respective newly created dirs on the router i.e. config.sh and ssd_trim.sh -> /jffs/scripts/ssd and common.sh -> /jffs/scripts/utils.
  • That's it for the manual "install".
Running:
  • To run once manually, ssh into your router, go to jffs/scripts/ssd (cd jffs/scripts/ssd) and run sh ssd_trim.sh. All going well (which it did on my two network systems) it should find your SSD and do the trim. It did not take long.
  • Separately, to set up a cron (scheduled) job for this, append these lines to your existing services-start file in /jffs/scripts/.
# --------------------- Trim SSD Cron Job - ref Kuchovsky ------------------
# trim_ssd - run every Sunday 04:00, sends fstrim to USB SSDs
cru a trim_ssd "0 4 * * 0 /jffs/scripts/ssd/ssd_trim.sh"

Refs: Links to files on GitHub

https://github.com/kuchkovsky/asuswrt-merlin-scripts/tree/main/jffs/scripts/ssd
https://github.com/kuchkovsky/asuswrt-merlin-scripts/blob/main/jffs/scripts/ssd/config.sh

https://github.com/kuchkovsky/asuswrt-merlin-scripts/blob/main/jffs/scripts/utils/common.sh

Many thanks to @kuchkovsky, this is simply fantastic!
RawFile.jpg
Dirs_Permissions.jpg
TrimDaTrim.jpg
 
Last edited:
It looks like a similar issue to the one @Milan encountered in this thread. Are you using a Windows tool like WinSCP to upload the files? It can mess up line endings. If so, could you change the transfer mode to binary (or a similar option) and reupload the files?

Generally, you only need the files explicitly listed in the SDN section: everything in /jffs/scripts/sdn, dhcpc-event + dnsmasq-sdn.postconf + firewall-start in /jffs/scripts, and profile.add in /jffs/configs. Everything else is not needed.
So the utils folder was also required. But I genuinely want to thank you for this script. I had enabled IPv6 via GUI and did not realise that was the reason IPv6 was broken on my android phone which I needed to bypass CG-NAT for Tailscale. You have genuinely made my life better and I want to thank you for it. And I hope the SLAAC part becomes a part of the firmware because I don't know who thought breaking SLAAC was a good way of distributing IPv6 subnets.
 
The deeper I look into this kind of setup and functionality, it seems to me that SDN is the line one crosses from SOHO networking into larger, more involved, potentially more “professional” config, and maybe asus hardware isn’t the best choice anymore. I’m certain other manufacturers have the same functionality out of the box (I’m thinking mikrotik’s RouterOS off the top of my head), but don’t let this musing deter anybody from continuing down this road.

Post in thread 'MerVLAN v0.50 Simple and Powerful VLAN Management **BETA**'
https://www.snbforums.com/threads/m...werful-vlan-management-beta.95936/post-977834
My opinion is there is a collab or partnership that might benefit everyone if it comes to pass.
 
I had tried running ssd_trim.sh against my Samsung T5 500GB USB SSD. It had not worked because changing provisioning_mode from full to unmap would fail. However, I kept my updater script and ran it today.
Well, something did change yesterday and the trim from the new version of ssd_trim.sh ran successfully. Thank you @kuchkovsky.
Code:
/jffs/scripts/ssd# ./ssd_trim.sh
ssd_trim: Scanning /proc/mounts for USB-backed filesystems under /tmp/mnt
ssd_trim: Detected SSD candidate: label=ent mount=/tmp/mnt/ent part=/dev/sda1 fs=ext4 vendor_id=04e8 vendor_name='Samsung'
ssd_trim: Set 'unmap' (was 'full') -> /sys/block/sda/device/scsi_disk/0:0:0:0/provisioning_mode
ssd_trim: Running fstrim on /tmp/mnt/ent...
ssd_trim: fstrim succeeded: /tmp/mnt/ent: 4914870272 bytes trimmed
ssd_trim: Detected SSD candidate: label=smb mount=/tmp/mnt/smb part=/dev/sda2 fs=ext4 vendor_id=04e8 vendor_name='Samsung'
ssd_trim: Running fstrim on /tmp/mnt/smb...
ssd_trim: fstrim succeeded: /tmp/mnt/smb: 7671943168 bytes trimmed
ssd_trim: Successfully trimmed all selected SSD mountpoints
ssd_trim.PNG
 
Last edited:

2025-12-07​

This minor update introduces several improvements to the SSD TRIM script (thanks to @guynich on GitHub for reporting the issue and supplying detailed information):
  • Added -n to all echo writes to sysfs device files to ensure compatibility with 3004.388.x firmware.
  • Added a hardcoded fallback discard_max_bytes=33553920 (~32 MiB) when write_same_max_bytes is missing, invalid, or zero.
  • Added explicit handling for fstrim: FITRIM: Input/output error - if this error occurs and no working fallback value is found, the disk is permanently disabled via nvram for future runs.
  • Shortened the nvram key format used for storing discard_max_bytes.
  • Applied several cosmetic code-style cleanups.
 
So the utils folder was also required.
Yes. Sorry, I forgot to mention that here. It's a default dependency for all scripts in the repo (it's noted in the README, though).

Well, something did change yesterday and the trim from the new version of ssd_trim.sh ran successfully.
I recently merged the updated version mentioned in the post above, but waited to announce it until I received user confirmation that the fix worked. This update includes a fix for the 3004.388.x firmware, which is likely why it worked for you.
 
Last edited:

Latest threads

Support SNBForums w/ Amazon

If you'd like to support SNBForums, just use this link and buy anything on Amazon. Thanks!

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!

Members online

Back
Top