Overclock.net › Forums › Software, Programming and Coding › Operating Systems › Linux, Unix › Summer Project: Conversion of my Asus RT-N16 router to an all-in-one pxe-boot device [Completed]
New Posts  All Forums:Forum Nav:

Summer Project: Conversion of my Asus RT-N16 router to an all-in-one pxe-boot device [Completed] - Page 2

post #11 of 15
Quote:
Originally Posted by subassy View Post

Adventures in button pushing

I think I mentioned this previously but I'll mention it again: OpenWRT does not use /etc/fstab. It's pretty much impossible to tell from the wiki what it would use in its place.

Even though I'm doing basically everything I set out to do with this router being able to mount and unmount the storage device without rebooting the router or having to SSH in and manually adjust would be a significant usability feature. So I set out to try and accomplish this.

What I soon realized, in my mount/unmounting manually adventures, is that unmounting /dev/sda1 is going to error out if the TFTPD daemon is running and pointing at it (says the device is in use). So I had to really assign the button to both stopping TFTPD and then unmounting /dev/sda1.

The TFTP daemon is this case is tftpd-hpa and I've been using /etc/intit.d/tftpd-hpa start/stop/restart/reload to control the status of the daemon.

First, I had to figure out if I could even capture the button press/release event.

I should mention is my desperation/inpatience to try and get some kind of response out of the button I was copy/pasting a lot of install package commands and putting in a lot of files. At some point I simply pushed the WPS button the the wifi disabled. So I had the task of finding where this action was being assingned. Doing a find command I found these three files:
I tried editing them and creating my own scripts with similar syntax but I couldn't get the button to do anything with my own script so I moved all the scripts to subdirectory under rc.button called backup so at least the button wouldn't be doing anything.

Next, even though I have no idea if it's really necessary or not, I followed the instructions on the OpenWRT wiki about assigned a button push only the script in the first didn't actually exist so I created it with the suggested content. The wiki doesn't say anything about having to make it executable but I did anyway.
/etc/hotplug2.rules (Click to show)
Code:
$include /etc/hotplug2-common.rules
 
SUBSYSTEM ~~ (^net$|^input$|button$|^usb$|^ieee1394$|^block$|^atm$|^zaptel$|^tty$) {
        exec /sbin/hotplug-call %SUBSYSTEM%
}
 
DEVICENAME == watchdog {
        exec /sbin/watchdog -t 5 /dev/watchdog
        next-event
}


Then, per the wiki, created this buttons file:
/etc/hotplug.d/button/buttons (Click to show)
Code:
#!/bin/sh
logger $BUTTON
logger $ACTION

I tried pushing the button after that: the wifi stayed enabled and upon running the logread | tail command got the desired output:
Code:
 OpenWrt user.notice root: RESSET 
 OpenWrt user.notice root: pressed   
 OpenWrt user.notice root: RESET    
 OpenWrt user.notice root: released

Ok so I didn't copy/paste the exact entry from the SSH window. It's close enough and point is I've got some kind of acknowledgement of the WPS button's existence. Also, the OS is referring to the button as RESET.

After much experimenting with the entries the /etc/config/system file I determined that a push of the button could almost entirely reliably stop TFTPD and unmount /dev/sda1 but could not, under any circumstances start TFTPD.

Generically, the entry in the /etc/config/system file looks something like this:
Code:
config button
        option button 'RESET'
        option action 'pressed'
        option handler 'mount /dev/sda1 /mnt'

For whatever reason using an echo in that handler statement doesn't do anything. It is possible to add an entry via logger and get output that way with the logread | tail command.

It is possible to hand off that handler entry to a separate shell script, which I did.

And wow, I so many different combinations of commands to make this button work.

I was trying to build in some logic: if sda1 is mount then stop TFTPD and run the umount command. It isn't mounted then mount it and start TFTPD command.

This command, for instance, will run on the CLI and works 100% of the time:
Code:
if [ $(ls -l /mnt/) == ""]; then mount /dev/sda1 /mnt; /etc/init.d/tftpd-hpa restart; /etc/init.d/dnsmasq restart; else /etc/init.d/tftpd-hpa stop;  cd /;  umount /mnt; fi

But if I literally paste that entry into either an external script or directly into that option handler entry it doesn't work.

I finally just tried stopping tftpd-hpa and putting in nothing but /etc/init.d/tftpd-hpa start for the handler and...it didn't work.

I actually tried this:
(mount /dev/sda1 && /etc/init.d/tftpd-hpa start) && logger -t tftpdstart "started?"

which unless I don't understand command lines and boolean logic as well as I think (which is possible) should be saying first run the mount and tftpd start commands AND ONLY IF THOSE TWO WORKED run that logger command... right? So if either the mount or daemon start things didn't work I shouldn't have that logger entry...

Well I still got the logger entry, sda1 was mounted, but tftpd was still stopped.

So I've about had enough of banging my head against the wall trying to get that logical mount/unmount button push functionality to work.

As a work around I put in the mount and tftpd commands in the local.rc file so sda1 is just mounted as the device boots. I then used the above method to try and unmount it when I push the button. Without any kind of external visual indicator I don't have a way of knowing if this actually worked.

Any suggestions/help on this are welcome. Otherwise this project is officially declared done. Until I decide to do a start-to-end article for the articles section anyway...

I may or may not post come bonus content (one or more scripts I ended up creating in my trying to get this work) below.
Quote:
Originally Posted by subassy View Post

Adventures in button pushing

I think I mentioned this previously but I'll mention it again: OpenWRT does not use /etc/fstab. It's pretty much impossible to tell from the wiki what it would use in its place.

Even though I'm doing basically everything I set out to do with this router being able to mount and unmount the storage device without rebooting the router or having to SSH in and manually adjust would be a significant usability feature. So I set out to try and accomplish this.

What I soon realized, in my mount/unmounting manually adventures, is that unmounting /dev/sda1 is going to error out if the TFTPD daemon is running and pointing at it (says the device is in use). So I had to really assign the button to both stopping TFTPD and then unmounting /dev/sda1.

The TFTP daemon is this case is tftpd-hpa and I've been using /etc/intit.d/tftpd-hpa start/stop/restart/reload to control the status of the daemon.

First, I had to figure out if I could even capture the button press/release event.

I should mention is my desperation/inpatience to try and get some kind of response out of the button I was copy/pasting a lot of install package commands and putting in a lot of files. At some point I simply pushed the WPS button the the wifi disabled. So I had the task of finding where this action was being assingned. Doing a find command I found these three files:
I tried editing them and creating my own scripts with similar syntax but I couldn't get the button to do anything with my own script so I moved all the scripts to subdirectory under rc.button called backup so at least the button wouldn't be doing anything.

Next, even though I have no idea if it's really necessary or not, I followed the instructions on the OpenWRT wiki about assigned a button push only the script in the first didn't actually exist so I created it with the suggested content. The wiki doesn't say anything about having to make it executable but I did anyway.
/etc/hotplug2.rules (Click to show)
Code:
$include /etc/hotplug2-common.rules
 
SUBSYSTEM ~~ (^net$|^input$|button$|^usb$|^ieee1394$|^block$|^atm$|^zaptel$|^tty$) {
        exec /sbin/hotplug-call %SUBSYSTEM%
}
 
DEVICENAME == watchdog {
        exec /sbin/watchdog -t 5 /dev/watchdog
        next-event
}


Then, per the wiki, created this buttons file:
/etc/hotplug.d/button/buttons (Click to show)
Code:
#!/bin/sh
logger $BUTTON
logger $ACTION

I tried pushing the button after that: the wifi stayed enabled and upon running the logread | tail command got the desired output:
Code:
 OpenWrt user.notice root: RESSET 
 OpenWrt user.notice root: pressed   
 OpenWrt user.notice root: RESET    
 OpenWrt user.notice root: released

Ok so I didn't copy/paste the exact entry from the SSH window. It's close enough and point is I've got some kind of acknowledgement of the WPS button's existence. Also, the OS is referring to the button as RESET.

After much experimenting with the entries the /etc/config/system file I determined that a push of the button could almost entirely reliably stop TFTPD and unmount /dev/sda1 but could not, under any circumstances start TFTPD.

Generically, the entry in the /etc/config/system file looks something like this:
Code:
config button
        option button 'RESET'
        option action 'pressed'
        option handler 'mount /dev/sda1 /mnt'

For whatever reason using an echo in that handler statement doesn't do anything. It is possible to add an entry via logger and get output that way with the logread | tail command.

It is possible to hand off that handler entry to a separate shell script, which I did.

And wow, I so many different combinations of commands to make this button work.

I was trying to build in some logic: if sda1 is mount then stop TFTPD and run the umount command. It isn't mounted then mount it and start TFTPD command.

This command, for instance, will run on the CLI and works 100% of the time:
Code:
if [ $(ls -l /mnt/) == ""]; then mount /dev/sda1 /mnt; /etc/init.d/tftpd-hpa restart; /etc/init.d/dnsmasq restart; else /etc/init.d/tftpd-hpa stop;  cd /;  umount /mnt; fi

But if I literally paste that entry into either an external script or directly into that option handler entry it doesn't work.

I finally just tried stopping tftpd-hpa and putting in nothing but /etc/init.d/tftpd-hpa start for the handler and...it didn't work.

I actually tried this:
(mount /dev/sda1 && /etc/init.d/tftpd-hpa start) && logger -t tftpdstart "started?"

which unless I don't understand command lines and boolean logic as well as I think (which is possible) should be saying first run the mount and tftpd start commands AND ONLY IF THOSE TWO WORKED run that logger command... right? So if either the mount or daemon start things didn't work I shouldn't have that logger entry...

Well I still got the logger entry, sda1 was mounted, but tftpd was still stopped.
Chelsy
So I've about had enough of banging my head against the wall trying to get that logical mount/unmount button push functionality to work.

As a work around I put in the mount and tftpd commands in the local.rc file so sda1 is just mounted as the device boots. I then used the above method to try and unmount it when I push the button. Without any kind of external visual indicator I don't have a way of knowing if this actually worked.

Any suggestions/help on this are welcome. Otherwise this project is officially declared done. Until I decide to do a start-to-end article for the articles section anyway...

I may or may not post come bonus content (one or more scripts I ended up creating in my trying to get this work) below.


Can't you just check to see if tftp is. Running then if it is have the button stop it. And if its not running have the nutton start it?
post #12 of 15
http://wiki.openwrt.org/doc/howto/hardware.button

Here first you need to tell open wrt the button exists and is has 2 states.
post #13 of 15
Thread Starter 
Quote:
Originally Posted by lameandboard View Post


Can't you just check to see if tftp is. Running then if it is have the button stop it. And if its not running have the nutton start it?

Quote:
Originally Posted by lameandboard View Post

http://wiki.openwrt.org/doc/howto/hardware.button

Here first you need to tell open wrt the button exists and is has 2 states.

Uh yeah. As mentioned in the hpost you quoted I figured out the multi-state thing:
Quote:
OpenWrt user.notice root: RESET
OpenWrt user.notice root: pressed
OpenWrt user.notice root: RESET
OpenWrt user.notice root: released

See? One state is pressed one state is released? By the way I think I have the wiki page about memorized I went over it so many times.

That wasn't the issue. The issue was tftp-hpa's daemon would not work with the button no matter what.

This line at the BASH prompt:
(mount /dev/sda1 && /etc/init.d/tftpd-hpa start) && logger -t tftpdstart "started?"
should not put anything into logger if the tftp daemon didn't start. The line works at the CLI, it works in a text file flagged as an exe but it wouldn't work when invoked by the button press. (in this case the button press ran the script, the logger entry was made but the daemon was not started).

To get around this I could a) use DNSMasq's TFTP deamon b) do what I did as a work around or c) spend the next 6 months learning C/C++ so you can read and modify source code to make it work.

I went with (b).
Quote:
Originally Posted by lameandboard 
Hey, I know this is from a little while ago, but I just randomly happened to come across it. Just wanted to let you know if you usedd dd-wrt pretty much everything you wanted to do is already built in and could be achieved with just changing a few configs. But it seems like you probably enjoy doing it this way and the learning... well good luck and thanks I took some notes from your posts.

I was starting to look into DD-WRT but all the articles I read seemed most enthusiastic about OpenWRT because of the customization and open-ness. I've since realized I don't really care if what I'm using is closed/proprietary/not custom compile-able to work on whatever device...dealing with outdated/inaccurate wikis pages and a seemingly dead community has to be better if it has those things. So my next router will most likely have DD-WRT (or i'll go back to tomato).

And yes, I wanted to learn how to set up linux as a router. More plot device for learning Linux CLI.
 
VM Server
(17 items)
 
 
CPUGraphicsRAMHard Drive
Intel Ivy Bridge Core i7-3630QM nVidia GeForce GTX 680M 16GB DDR3 1600MHz Dual Channel Memory (2 SODIMMS) Hard Drive: Serial-ATA II 3GB/s 
Hard DriveOSMonitorPower
Hard Drive: Serial-ATA II 3GB/s Windows 10 Pro x64 17.3" FHD 16:9 (1920x1080) Battery: Smart Li-ion Battery (8-Cell) 
Audio
Sound Blaster Compatible 3D Audio 
CPUMotherboardGraphicsRAM
Intel Core i7 860 Biostar T5 XE Radeon HD 5870 Corsair 16GB  
Hard DriveHard DriveOptical DriveOS
Western Digital hard drive wd1001fals-00e8b0 Maxtor 300GB I don't need no stinking optical drive Microsoft Windows 7 Ultimate x64 
MonitorMonitorKeyboardPower
HP ZR24w 24'' Samsung SyncMaster 24" logitech wireless k360 Seventeam ST-850ZAF 850W ATX 
CaseMouseAudioAudio
Thermaltake V9 Black Edition Logitech G500 Programmable Gaming Mouse FiiO E7 USB DAC and Portable Headphone Amplifier Sennheiser HD555 Professional Headphones 
  hide details  
Reply
 
VM Server
(17 items)
 
 
CPUGraphicsRAMHard Drive
Intel Ivy Bridge Core i7-3630QM nVidia GeForce GTX 680M 16GB DDR3 1600MHz Dual Channel Memory (2 SODIMMS) Hard Drive: Serial-ATA II 3GB/s 
Hard DriveOSMonitorPower
Hard Drive: Serial-ATA II 3GB/s Windows 10 Pro x64 17.3" FHD 16:9 (1920x1080) Battery: Smart Li-ion Battery (8-Cell) 
Audio
Sound Blaster Compatible 3D Audio 
CPUMotherboardGraphicsRAM
Intel Core i7 860 Biostar T5 XE Radeon HD 5870 Corsair 16GB  
Hard DriveHard DriveOptical DriveOS
Western Digital hard drive wd1001fals-00e8b0 Maxtor 300GB I don't need no stinking optical drive Microsoft Windows 7 Ultimate x64 
MonitorMonitorKeyboardPower
HP ZR24w 24'' Samsung SyncMaster 24" logitech wireless k360 Seventeam ST-850ZAF 850W ATX 
CaseMouseAudioAudio
Thermaltake V9 Black Edition Logitech G500 Programmable Gaming Mouse FiiO E7 USB DAC and Portable Headphone Amplifier Sennheiser HD555 Professional Headphones 
  hide details  
Reply
post #14 of 15
Thats really cool. I really need to try this.l
ESXi Home Box
(6 items)
 
The Workstation.
(16 items)
 
 
CPURAMHard DriveOS
Dual L5630 72GB DDR3 RECC 120GB VERTEX 4 + 6TB RAID5 ESXi 6.0 U2 
Other
Dell PowedgeR710  
CPUGraphicsRAMHard Drive
Intel Core i5 2.4GHZ Intel Iris Pro 16GB DDR3 256GB PCI-e x2 
OSKeyboardMouse
OSX 10.11 + Win 10 Apple Wireless Keyboard Apple Magic Trackpad 
  hide details  
Reply
ESXi Home Box
(6 items)
 
The Workstation.
(16 items)
 
 
CPURAMHard DriveOS
Dual L5630 72GB DDR3 RECC 120GB VERTEX 4 + 6TB RAID5 ESXi 6.0 U2 
Other
Dell PowedgeR710  
CPUGraphicsRAMHard Drive
Intel Core i5 2.4GHZ Intel Iris Pro 16GB DDR3 256GB PCI-e x2 
OSKeyboardMouse
OSX 10.11 + Win 10 Apple Wireless Keyboard Apple Magic Trackpad 
  hide details  
Reply
post #15 of 15
I've been playing with PXE booting Linux on my home LAN recently. Not got too far yet, I've only set up dnsmasq as my DHCP server and created some basic pxelinux.0 rules.
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Linux, Unix
Overclock.net › Forums › Software, Programming and Coding › Operating Systems › Linux, Unix › Summer Project: Conversion of my Asus RT-N16 router to an all-in-one pxe-boot device [Completed]