Thread: Running Linux from a ramdisk (root)

  1. #1
    Registered User
    Join Date
    Dec 2006

    Running Linux from a ramdisk (root)

    I have been pondering about this for a while now...

    Is it possible to run Linux entirely from RAM (ramdisk)?

    Actually, I am pretty sure it's possible (everything is possible in Linux ), since we already have initrd. So let's change the question to... is it sensible?

    A script can be written to copy the content of the ramdisk to harddrive on shutdown, and from harddrive on boot, essentially making shutdown into hibernate.

    I am thinking about doing this on a laptop

    advantages -
    SPEED! (~2GB/s read/write)
    low power consumption if we can turn off the harddrive (RAM is powered all the time anyways)
    weight (if we can take out the harddrive, but I don't think we can, read on)

    disadvantages -
    small capacity - most laptops only have 2 SODIMM slots, and 4GB DDR2 modules are insanely expensive/not available right now, which means we can get a maximum of 2x2GB. Potentially 2x4GB in a year or 2.
    volatile - data loss on power loss, and makes complete shutdowns longer (copying ramdisk to HD)

    The small capacity problem can be elevated by using tmpfs (like ramdisk, except it only uses as much memory as it needs to store the files, and CAN be swapped), and a large swap partition. This is why I said it's probably not possible to remove the harddrive entirely.

    Volatility is not so much of a problem on laptops, since they have batteries, and can be configured to hibernate automatically when battery is critically low. Most of the time it can be put to suspend/standby (powering down everything except RAM) when not in use. On my laptop, for example, suspend takes about 1%/hr, which I think is acceptable, as long as it's charged everyday.

    Obviously important files shouldn't be saved on the ramdisk. They can be saved to either harddrive or over network.

    So... what do you think? Anything I overlooked?

    Looks like someone thought about this already =D.
    Last edited by cyberfish; 05-08-2009 at 06:42 PM.

  2. #2
    Registered User
    Join Date
    Dec 2006
    Okay, getting it down to < 2GB is hard...

    I am at 1.9GB right now. Already deleted all the docs and my virtual machines. Time to start deleting programs and libraries...

    Need to get more RAM for sure if this works out .

  3. #3
    Registered User
    Join Date
    Dec 2006
    After hours of head scratching... I did it!

    yberfish@cyberfish-tablet:/$ sudo dd if=/dev/zero of=test bs=4M count=100
    100+0 records in
    100+0 records out
    419430400 bytes (419 MB) copied, 1.35247 s, 310 MB/s
    cyberfish@cyberfish-tablet:/$ df -h
    Filesystem            Size  Used Avail Use% Mounted on
    tmpfs                 975M     0  975M   0% /lib/init/rw
    varrun                975M  108K  975M   1% /var/run
    varlock               975M     0  975M   0% /var/lock
    udev                  975M  164K  975M   1% /dev
    tmpfs                 975M   88K  975M   1% /dev/shm
    rootfs                 10G  2.2G  7.9G  22% /
    lrm                   975M  2.4M  973M   1% /lib/modules/2.6.28-11-generic/volatile
    tmpfs                 975M   12K  975M   1% /tmp
    cyberfish@cyberfish-tablet:/$ free -m
                 total       used       free     shared    buffers     cached
    Mem:          1949       1357        592          0          0        838
    -/+ buffers/cache:        518       1431
    Swap:         4094       1421       2673
    Had to modify the patch on that page a bit, added tar to initrd (doesn't come with the ubuntu one for some reason, and changed fstab to remove the root.

    For the dd test I cheated by creating and deleting a huge file before the dd command to swap other files and make room for the test file. That would be the performance if I had enough RAM, though.

    The system felt noticeably faster... firefox takes about 3 seconds to start (CPU-bound!), which is about how fast it is usually when it's already in disk cache. That's reasonable since tmpfs uses the kernel disk caching system (without backing store, so pages are always marked dirty).

    There's still disk activity (swapping) once in a while since I don't have enough RAM.

    Reading the "root" archive on boot is not too bad at all. My 2GB root partition can be gzipped to about 500MB. Uncompressing and copying it to the new tmpfs takes about 20 seconds (essentially the time to read 500MB from harddrive, since gzip is so fast that it's bottlenecked by the drive. Wouldn't be the case for bzip2. And writing to RAM is of course also very fast).
    Last edited by cyberfish; 05-09-2009 at 02:48 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Running C program in Linux or Windows
    By kepler in forum C Programming
    Replies: 4
    Last Post: 09-30-2003, 08:31 AM
  2. linux and windows lookup host processes
    By Lynux-Penguin in forum Tech Board
    Replies: 0
    Last Post: 08-31-2003, 11:54 PM
  3. never compile as root!
    By Lynux-Penguin in forum Linux Programming
    Replies: 6
    Last Post: 08-21-2003, 05:46 PM
  4. Linux/Xp
    By Unregistered in forum A Brief History of
    Replies: 32
    Last Post: 06-17-2002, 11:34 AM