Staring the Pandora with "added" defaults


milinks

Member
Joined
Mar 22, 2011
Messages
170
Hi, I've a CC Pandora, and a lot of the apps/games I use require a swap file to use, I've got the swapfile.pnd installed and I know its not much effort to activate my swap file, but is there a way to change startup options, or to make swapfile start up when the Pandora starts up? I am no use with programming etc, but just wondered if it could be something that could be automated when I start the Pandora, sounds lazy I know, but if I don't ask...
 
Sure, it's just a simple swapon command.  If you can find where it's set up your swap file it's just a matter of:

swapon <swapfile>

I don't know where swapfile.pnd creates its as I've never used it (I've only ever used ZRAM swap on my GHz).  It may well be in it's appdata - look in /media/<SD>/profile/appdata/swapfile

Now, there are ten dozen ways of getting something to start at startup in Linux depending on exactly when and in what context it should happen, and to be honest I always get a bit mixed up with them all, and just trying to research them now I can't find a user file that automatically gets run when you log in graphically and don't necessarily use bash, but if there is some bash script buried in there, putting it in /home/<user>/.bashrc should do the job.

Perhaps you should also have a corresponding swapoff command at shutdown, and the corresponding file for that would probably be .bash_logout in your home directory.

Sorry I can't be more concrete, but it seems I've found a hole in my Linux knowledge, and my google-fu is weak today.
 
putting swapon in your .bashrc is likely a bad entry point.  Especially considering that it will almost certainly run on every pnd load and possibly multiple times.  Anything that instantiates a new shell will run the command.

It is possible that running swapon multiple times is 'safe', but it is quite likely to have many side effects that are difficult to triage, such as exiting with errors because it is already running causing odd error states, increasing load times due to failure timeouts when the card isn't inserted and such.

Generally you put the swap loading in your /etc/fstab, but due to boot priority and that the SD cards are unlikely to be mounted when you initially boot.

Anyway... without looking myself, I'd expect the proper place would be to create a script under /etc/rc.d/rc.<something>

Honestly setting it up in any manner shouldn't be difficult, but hardening everything is the problem.  In a typical system you'll never be allowed to remove a running disk that has your swap.  However on the pandora we can quite easily eject the SD card physically without issuing a swapoff and unmounting the partition.  Removing it improperly is the equivalent of just removing system memory forcibly and will definitely result in a crash scenario of some kind at some point.
 
Ah, I thought my .profile was the one that got run for every instance of bash, while .bashrc got run once, but I guess I'm showing my ignorance again.

Yes, the /etc/rc*.d folders is probably a good place to put it, but I was ideally looking for something that got triggered after logon - afaik it's already in runlevel 5 before the login screen pops up, but not for so long that it'll risk spending the whole boot swapping (not that it should anyway unless it tries to use more RAM than it's got).  Yeah, probably the best place to put it on consideration.

FWIW, according to the docs (and my experience of swaponning ZRAM) a duplicated swapon won't do anything, but either way it's not best practice to run it unnecessarily.  And also writing your own swapoff code is unnecessary, as /etc/rc.6/S40umountfs already does a swapoff -a.  Oddly on my Debian box all my rc.6 steps seem to have been disabled (they're all K* links) including umountfs, so I don't know how Debian does it.
 
Levi, 

From: http://stackoverflow.com/questions/415403/whats-the-difference-between-bashrc-bash-profile-and-environment

The main difference with shell config files is that some are only read by "login" shells (eg. when you login from another host, or login at the text console of a local unix machine). these are the ones called, say, .login or .profile or .zlogin (depending on which shell you're using).

Then you have config files that are read by "interactive" shells (as in, ones connected to a terminal (or pseudo-terminal in the case of, say, a terminal emulator running under a windowing system). these are the ones with names like .bashrc, .tcshrc, .zshrc, etc.

bash complicates this in that .bashrc is only read by a shell that's both interactive and non-login, so you'll find most people end up telling their .bash_profile to also read .bashrc with something like

[[ -r ~/.bashrc ]] && . ~/.bashrc
You are right with your definition, but I have found cases where systems don't actually behave as documented.  This can be caused by an admin modifying /etc/bash_profile among other things to load bashrc/.bashrc... 

I'd still avoid using .bashrc where possible though for loading services since you can also throw in other problems if you ssh'd in, logged in as another user...

At any rate, sounds like you have a plan! :)
 
Thanks for the replies guys, if theres a chance that it could cause crashes, however small the chance, I think i'll have more of a look at your suggestions before i take it further.
 
I don't think any crashes that you will find would be above and beyond what you're doing to just use the swap now.

Worst case... create a script to start/stop the swap, and just run that.... you should be able to check if it is already running/stopped based on what is mounted at the time... if my memory is serving me correctly.
 
Back
Top