Stop Firefox spinning up the hdd all the time in laptop-mode

Discussion in 'Linux' started by rachel, Nov 9, 2008.

  1. rachel

    rachel

    Joined:
    Aug 10, 2008
    Messages:
    80
    Likes Received:
    0
    OK, this should work in any Ubuntu laptop system, but I was motivated to find it on my hdd-equipped Aspire One running Intrepid, so I thought I'd post it up.

    This only applies to hdd-equipped Aspire Ones. Ignore if you have an ssd model.

    The problem is that you want (well, I want) it to spin down the hard drive when I'm not doing something that ought to need it. The first step is to enable laptop mode. To do this, edit /etc/default/acpi-support:

    Code:
    gksu gedit /etc/default/acpi-support
    Find the line with "ENABLE_LAPTOP_MODE=false" and change the "false" to "true". Uncomment the line if it's commented. (I can't remember if it is by default.)

    Start laptop-mode to get the benefit straight away. It'll start automatically on your next reboot anyway.

    Code:
    /etc/init.d/laptop-mode restart
    Now, when you're on battery, the hard drive will spin down quite rapidly after any hard drive access. Great.

    Now try to use Firefox. You'll find that it spins up the hard drive every time you hit a page. Once all the other excuses are dealt with (eg: all fonts are cached, all caching is turned off or redirected to a ramdisk, it's still doing it. In fact, the only apparent way to stop it is to turn off history. But history is useful, so that's a bad move.

    The problem is that every time you hit a page it writes what you've done to the history file. That would be fine except in Firefox 3.0 that history file is an sqlite file, and after every write it forces a filesystem sync.

    My solution is to stick the whole of your mozilla settings folder into a ramdisk and run it from there. It has the additional benefit of speeding things up but that's really secondary from my point of view: I just wanted it to stop spinning up the drive all the time.

    Like this:

    First, set up /tmp to run in a ramdisk just like you would if running on an ssd-equipped AA1. So append these lines to your /etc/fstab:

    Code:
    tmpfs      /var/log        tmpfs        defaults           0    0
    tmpfs      /tmp            tmpfs        defaults           0    0
    tmpfs      /var/tmp        tmpfs        defaults           0    0
    
    Add any other steps required for this to work as detailed in the Ubuntu AspireOne howto. Reboot. (Don't just 'mount -a' and expect things to carry on working right.)

    (You can make any new location for this instead of using /tmp, but I'm using these just like I would in an ssd-equipped Aspire One basically to also cut down on hdd usage and thus have it spin up less often.)

    Quit firefox if it's running. You're about to take its world away, it won't be happy if you don't quit it.

    Code:
    mv ~/.mozilla/firefox ~/.mozilla/firefox.real
    ln -s /tmp/$LOGNAME/firefox.real firefox
    Yes, that symlink will be broken when you create it. What we're now going to do is make sure the target is there each time you log in:

    Create a file /etc/gdm/PostLogin/Default:

    Code:
    gksu gedit /etc/gdm/PostLogin/Default
    And put this in it:

    Code:
    mkdir -p /tmp/$LOGNAME
    
    if [ ! -d /tmp/$LOGNAME/firefox.real ] ; then
    	rsync -a $HOME/.mozilla/firefox.real /tmp/$LOGNAME/
    fi
    
    Make sure the file is executable:

    Code:
    chmod a+x /etc/gdm/PostLogin/Default
    Log out. Next time you log in, it will copy your ~/.mozilla/firefox.real folder into the ramdisk, unless it's there already.

    Now you can start firefox, and it will run with all its settings in ram.

    Finally, you want the changes to your firefox state to be saved back to your hard drive, so you actually get to keep the new history/bookmarks/passwords et-al you make.

    I don't have a perfect solution here; the one I have is sufficient for my purposes. It is possible that you will lose data - up to the last fifteen minutes of changed firefox state - if the machine crashes or loses power. I just decided this is less important than solving the hard drive spin-up problem.

    Put the following into a script. It doesn't matter where, as we'll be using the complete path to that script later, but I have it in my user's bin folder:

    Code:
    mkdir -p ~/Library/bin
    gedit ~/Library/bin/firefox-fromram
    
    firefox-fromram:
    Code:
    #!/bin/bash
    
    if [ -d /tmp/$LOGNAME/firefox.real ] ; then
    	rsync -a /tmp/$LOGNAME/firefox.real $HOME/.mozilla/
    fi
    
    Now we want to run this every fifteen minutes. (You can alter the interval but you'll need to read up on how crontab works some more.)

    Code:
    crontab -e
    
    Add the line:
    Code:
    0-59/15 *       *       *       *       $HOME/Library/bin/firefox-fromram
    
    Save and exit, and you're done. (No restart or logout/login needed to get that working). Now, every fifteen minutes, it will sync the firefox folder in ramdisk back to your hard drive.

    It could be made more foolproof, and more automatically-set-up for the first use, but I got it working for me and, with a nasty cold, felt I'd done enough. :)
     
    rachel, Nov 9, 2008
    #1
    1. Advertisements

  2. rachel

    RockDoctor

    Joined:
    Aug 21, 2008
    Messages:
    963
    Likes Received:
    0
    Location:
    Minnesota, USA
    Interesting. I suppose you could set up a script that you would use to poweroff that would sync up with .mozilla in ram before actually bringing down the system
     
    RockDoctor, Nov 10, 2008
    #2
    1. Advertisements

  3. rachel

    rachel

    Joined:
    Aug 10, 2008
    Messages:
    80
    Likes Received:
    0
    Sure. It's "good enough" for me now though, so I'm too lazy to do it. :)
     
    rachel, Nov 10, 2008
    #3
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.