OUR NETWORK:TiVo Community TechLore Explore3DTV DVRplayground Dijit Community See all... About UsAdvertiseContact Us

Safe unmount script/mount script

 
Learn about scoring Download Discussion's Raw Score: 365699.0
August 17, 2010 05:59 PM
Rating (0 votes)
  • 1
  • 2
  • 3
  • 4
  • 5
Rate This!

Member Avatar

sokrin

Member

Anyone have something readily available to be used for dd-wrt? I've searched around but they're mainly for optware. I'm using jffs.

Discussion:    Add a Comment | Comments 1-21 of 21 | Latest Comment

August 20, 2010 3:06 AM

What are you up to?

There is a text field in DD-WRTs command section which allows to store commands that should be executed when a shutdown occurs, here you could add commands to kill processes and commands to umount

August 20, 2010 3:32 PM

Yeah. Basically I used umount, but it doesn't seem to work. I don't want to just pull out the external hard drive and risk corruption, so I was looking for ways to unmount it first. The only way i have been able to do it safely is to pretty much shut down the router via a sciript. Rebooting it doesn't unmount either. Any suggestions?

August 22, 2010 11:40 PM

Have you tried just SSHing into the router and unmounting that way (after enabling SSH access, that is)? This could also be combined into a single command such that, when you run it on your computer, it logs onto the router, runs umount, and then exits.

August 23, 2010 3:57 AM

@sokrin, umount can only un mount if there is not process running which has any open files on the mounted partition. That's why you need to check which proccesses access the fs and kill them prior to umounting.
I can check if I can integrate a safe umount in my dd-wrt mod

August 23, 2010 10:42 AM

that would be awesome Kong.

August 28, 2010 1:02 AM

There is a bug in busybox. By default it should already cleanly umount all drives at a reboot, shutdown.
Busybox devs are not replying to my bug report, so I'm going to fix this myself.
Next release should have this fixed.

August 28, 2010 5:04 PM

Kong said: There is a bug in busybox. By default it should already cleanly umount all drives at a reboot, shutdown. Busybox devs are not replying to my bug report, so I'm going to fix this myself. Next release should have this fixed.

I can't wait =).

September 27, 2010 5:21 PM

Hi Kong and all,

If it might help, I have written a safe unmount script that is executed when the WPS button is pressed.

It is actually part of a more complete init system that also takes care of starting and stopping al required services and uses the WPS button's light as an indicator for the USB disk (on = disk mounted - off = disk unmounted/safe to remove - blinking = unmount in progress)

At the moment I have the scripts as part of a guide (in Italian) I have written for installing Transmission on the WNR3500L, the link is here:

DD-WRT come Home Server – Parte 2 – Client BitTorrent

I will translate it to English soon but even now anyone who has a bit of experience with linux/dd-wrt can follow the steps just by looking at the pictures and terminal commands.

The part where the "init" system is installed its on page 5.

Please let me hear any comment or critic you might have, there is a lot to improve :)

September 29, 2010 5:29 AM updated: September 29, 2010 5:33 AM

awesome work from both Kong and you Lestat! This whole, short, wnr3500l with dd-wrt exprience has really been great.

@Lestat, I google-translated your whole Part 2 tutorial and only 2 questions remains.
1st: Is it safe to add a line on S00disk.startup that mounts a third partition on that very same /mnt? So the startup script would be like:
# for ext3 fs
mount -t ext3 /dev/discs/disc0/part2 /mnt
mount -t ext3 /dev/discs/disc0/part3 /mnt/Music

And the 2nd question:
I looked at the usb.startup script that allows us to press WDS button to safely unmount the USB drive but I didn't notice anything that would actually mount it back if pressed. Is that correct? If yes, how do I mount my drive again? (by switching the power off/on on my USB drive?)

Keep up the good job guys! I appriciate it!

September 29, 2010 7:10 AM

Hi micadelli,
thank you! Just a quick question: how is google's translation working for you?

I'll answer to your questions in reverse order:

2) The mounting back is handled by dd-wrt's automount. If, as you suggest, you switch the usb drive off and then back on dd-wrt will automatically re-mount the first partition to "/opt" and execute again the "usb.startup" script.
This config is set on the web-gui (I have it on page 3 of my guide).

1) This is actually a bit tricky since, at the moment, the scripts are not very flexible (and I am not proud of it :) ).
Adding a line to "S00disk.startup" is fine to mount additional partitions (I suggest adding a "sleep 3" command between mounts, expecially if you use nested directories),  however (and this is very important), there will be no automatic unmount unless you also modify the script "usb.startup".

Also, you probably know what you are doing, but myself I don't like much the idea of nested mounts, such as "part2 -> /mnt" and "part3 -> /mnt/music".

My solution would be something along the lines of: "part2 -> /mnt/data" and "part3 -> /mnt/music". It does not really add any (further) complexity to the scripts and it can avoid a lot a filesystem troubles.

"usb.startup" contains, between line 26 and 139 the code to create the script "usbunplug.sesbutton", which is executed when the WPS button is pressed.

That script is responsible for unmounting the partitions and has "/mnt" and "/opt" hard-coded (I know, it's veeery bad) in an "unmount -> check -> loop|exit" loop.

Since I like to parametrize my code as much as I can (it happens when you program mostly in C++), to add the unmount for a third partition you need to:

1 - add two variables containing the path to unmount and the unmount status for the directory. You should add something like:

check_mus='/mnt/music'
test_mus=1

(the existing variables are on line 77)

2 - Add the actual unmount code:

  echo "unmounting /mnt/music"
  umount /mnt/music

(existing code at line 89) - Please note, you should add this before the other unmounts!

3 - Add the code for checking if the partition has been unmounted.

  _check \$check_mus
  test_mus=\$?

(actual code on line 96)

4 - add the test to the success of the unmount. This is pure, old-fashioned, crappy spaghetti-code and it will be the first thing to go once I have enough time to improve everything.

 elif [ "\$test_mus" -eq "1" ]; then
    # /mnt/music is still mounted
    echo "/mnt/music still mounted"
    _blink 3
    retries=\`expr \$retries + 1\`

Existing spaghetti-blob starts at line 102. You should insert this after the first "if" test (at the moment on line 107).

By doing this everything should work, however I am writing this post from work and cannot test it directly.

I will modify the scripts pretty soon to automatically unmount all the partitions that are mounted by the "S00disk.startup" script, but for the moment this should fix it :)

Please let me know if you encounter any problem :)

October 1, 2010 4:59 AM

Lestat said: Hi micadelli, thank you! Just a quick question: how is google's translation working for you?

Well, to be honest, it isn't.. thanks to very diverse Finnish grammar and its complex noun cases etc... but Italian -> English works just fine imo.

I actually ditched the idea to make another partition to my HDD 'cause  I didn't want to mess with the code that hard.

WDS button works flawlessly now as well samba sharing.

But, how do I get miniDNLA not to run? I ran "chmod -x" to miniDLNA scripts but it didn't seem to stop it to run... alhought i'm not sure if i really reboot the router after that command. Have to check that when I get back home.

Transmission seem to have some kind of bug of connecting to trackers and reconnecting is always set to 3h 30m. Ubuntu's official tracker was the only one I managed to get a connection. The error was something to do with "scraping". I read somewhere (maybe dd-wrt wiki) that the official Transmission is buggy and they recommended enhanced cTorrent or TransmissionD. Have to give it a try.

I have noticed another weird thing. My memory usage is very high somehow. It's constantly around 59MB, so only 2-3% left. Any ideas why? All I've done is ran mini-ddwrt -> kong mod. I have set 256MB partition for linux swap but it's not working at all.

Do I have to click "JFFS2 enable"?

thanks in advance

October 1, 2010 4:09 PM

Hi again,

regarding miniDLNA, I was wrong on my guide. The startup/shutdown scripts are executed even if the execute flag is not set. That will also be fixed soon (I'll update here once I fix everything).

For the moment, just rename the scripts. The init system looks for (and executes) scripts ending in ".startup" and ".stop" in "/opt/etc/config"; if you rename "S20minidlna.startup" to, say,  "S20minidlna.startup.bak", it will not get executed.

Transmission works more than fine for me, but I am not a frequent downloader. I usually add a couple of files once in a while and leave them in the queue until the upload ratio is at least 1:2.

With my usage I do not see relevant differences from using uTorrent but that might be different if you have a more "intense" use ;)

By the way, the "Transmission" installed in my guide is, in fact, the Transmission Daemon, not the old, buggy one. And it is updated quite frequently.

Are you sure there isn't a problem with port blocking and such? Can you try to activate uPnP on the router?

Regarding the ram issue, when you run the "free" command, how much memory is used by "buffers"?

If you have a high "buffers" value (most probably) you don't have much to worry about!

Creating a "swap-type" partition on the drive will not make dd-wrt use it automagically, you will need to install the "swap-utils" package and then configure the scripts so to mount it appropriately. However I can assure you that just for Samba, miniDLNA and Transmission the 64Mb of the WNR3500L are quite enough and using a swap partition would only complicate things.

JFFS2 is (usually) only needed if you want to use flash-based memory (such as a pen drive) instead of an hard disk. If you have a normal usb hard disk connected to the router you will not need it :)

Please let me know how it goes with the RAM and if you have other issues.

October 4, 2010 8:25 AM updated: October 4, 2010 8:34 AM

hi lestat,

i still have port issues with transmission. I have tried both disabled and enabled port forwarding (settings.json) and tuned dd-wrt gui accordingly but I just can't get that port show on UPnP list and running "transmission-remote transmission:transmission --port-test" on router shows "port: closed". Running Transmiossion on my laptop with UPnP enabled, the port shows on the dd-wrt list OK.

If I have disabled port forwarding on settings.json file, I do have to put these values on dd-wrt gui, don't I:
Application Port from Protocol IP Address Port to
Trans 51413 Both 192.168.1.1 51413


And here's the my stats after running "free":
total used free shared buffers
Mem: 59940 58056 1884 0 640
Swap: 0 0 0
Total: 59940 58056 1884

Shows that i do have some memory issues?

October 4, 2010 7:09 PM

Hi micadelli,
I am afraid but I think it might not be easy to solve your problem.
In regards to the memory, let me show you what my router is reporting:

                   total          used           free    shared       buffers
Mem:        59940        58340         1600             0        20248
Swap:              0                0               0
Total:        59940        58340         1600

As you can see I have a similar situation, but there is a lot of memory occupied by the buffers. By the way, the router has been on and downloading several torrents for the last 4 days.

At the moment I have both Samba and miniDLNA off, since I don't need them now.

Can you post the output of "ps"?

Regarding the port forwarding, a rule for IPFILTER is already included in the startup script for Transmission and you have to worry about it only if you change the default port. If you want to also add them to the gui, no harm done!

Also note that I also have a "Port is open: No" message, but that doesn't mean that torrent is not working. I can assure you that I can connect to quite a good number of trackers.

If you are downloading something and run a "netstat", can you see the (should be many) connections to others?

Can you specify what you mean by "running Transmission on my laptop"? Did you install the standalone client from the official site?

The ports might not necessarily show up in the uPnP section of the router. My previous suggestion was mostly a tentative to understand if there is something different in my conf that makes it work.

In fact, I suppose dd-wrt monitors for uPnP only on the LAN segment (which makes sense).

Did you try turning the SPI Firewall off? Mine is off.

October 5, 2010 5:01 PM

Hi Lestat and Kong

I tried your script and everything works...well kind of. Here is my issue I have with my two routers, one being setup as a repeater. Each has an hard drive connected to it.

The Primary Router works perfect, I only have it setup for SAMBA and I can browse the directories and do what I need to do. However, my repeater router is being weird.

1. I cannot get the miniDLNA to work right. It starts and I guess it starts scanning the directories because I can see the music coming in, so I left it to synch. I came back about 3 hours later and it says "No Content Available" It is liked it never scanned the drive, or it reset itself

2. Samba is not working, I used the same settings as the Primary router, but just changing the names making it a different share. Every time I browse I can only see the shares from the Primary router. Do I have to do anything special on the repeater to enable Samba for the hard drive connected to it.

October 6, 2010 9:18 AM

Hi I actually finally got everything working, with a few little tweaks. Thanks Kong for your help in the forums, and thanks Lestat for a great script.

1. Instead of saving the minidlna "files.db" in /tmp/minidlna I saved it in /opt/minidlna. The database is about 50 MB so I figured I did not have enough space on the routers memory so it was giving me issues.

2. I added a line to the usb.startup script to mount my swap drive and enable it. I figured this may also help since I have about 500Gb of media

3. I also edited the minidlna startup script to change the name of the miniDLNA server to something outside of DD-WRT, this seemed to work well.

4. My Samba issues were actually my fault, my router and repeater had the exact same hostname, so when I browsed the network this caused conflicts, so after changing them to different hostnames worked like a charm.

Other than that as far as transfer speeds I get about ~6 MB/s, it is about half (~3 MB/s) if I have to transfer files between a device attached to the repeater and a device attached to the router

I actually setup my repeater bridge for roaming so everything is using the same SSID, this is working perfectly and I am getting no drop connections.

October 6, 2010 9:55 AM

Hi HeCareth,
sorry I couldn't be of help, but thanks a lot for sharing the solution. In fact it is only logical to move the db of miniDLNA to the /opt partition. I will include this solution with the next update of the scripts!

October 6, 2010 10:09 AM

Oh I should mention I am able to stream 4GB+ HD movies from my media extender connected to my repeater which is about 50 feet away from my router, in case anyone was wondering.

October 6, 2010 4:11 PM

Hi guys just noticed this myself, in case one has lots of media files the db needs to be located outside ram. I'll add a textbox in the next build that allows to specify a path for the db.

October 7, 2010 5:41 AM

I have just uploaded new builds. They links in the download section going to be updated soon. There is now a text field which allows to specify a directory where the db should be located. If nothing is specified it will default to ram.

February 10, 2011 4:37 PM

Hi all,

after a lot of time I have update my guide and also translated it to English.

If anyone needs a system to safely unplug a USB disk and to use Torrent and Optware on the WNR3500L, my guide could be of help! :)

http://www.luminaria.cc/en/dd-wrt-home-server-part-2-bittorrent-client-and-safe-unmount/

Discussion:    Add a Comment | Back to Top | Comments 1-21 of 21 | Latest Comment

Add Your Reply

(will not be displayed)

Email me when comments are added to this thread

 
 

Please log in or register to participate in this community!

Log In

Remember

Not a member? Sign up!

Did you forget your password?

You can also log in using OpenID.

close this window
close this window