HOW-TO: Boot OS into RAM for speed and silence
How to RAMboot
This details a method of loading your entire OS into an uncompressed ramdisk. The result is lightning fast performance, and elimination of hard drive noise and power consumption (if swap is not used and the hard drive is spun down). The basic steps are: 1. Install Debian 4.0 on the hard drive 2. Create a modified /etc/fstab which has tmpfs for the root partition 3. Optionally create a startup script to park hard drives 4. Create a script which makes a stripped down OS image 5. Create a custom initrd.img which loads the OS image into a tmpfs ramdisk 6. Modify /boot/grub/menu.lst with an entry for the custom initrd.img After completing these steps, you will have a dual boot system with the following boot options: A) Boot normally, where you install new software or change settings B) Boot into the "ramboot" OS image, for high speed silent computing ------------------------------------------------- Step 1. Installing Debian 4.0 a) Install Debian 4.0 onto a partition of least 500megs. For purposes of the rest of these instructions, I'll assume you're have installing into the hda1 partition. b) In the software selection step, deselect the so-called Base software suite. You will manually install only what you need later on. c) After doing the install, log in as root and edit /etc/apt/sources.list to comment out the CD-ROM entry (use the command "nano /etc/apt/sources.list"). Then run the following commands: Code:
apt-get update ------------------------------------------------- Step 2. Create a modified /etc/fstab Create and edit a new fstab using these commands: Code:
cd /etc/ Code:
none / tmpfs defaults 0 0 Step 3. Optionally create a startup script to park hard drives If you want, create a startup script with these commands: Code:
nano /etc/init.d/ijkijkijk Code:
#! /bin/sh Step 4. Create a script which makes a stripped down OS image Login as root. Then create a basic script like this: Code:
#!/bin/sh ------------------------------------------------- Step 5. Create a custom initrd.img which loads the OS image into a tmpfs ramdisk This is step is a hack. It works with Debian 4.0. There's probably a less "hackish" way of doing this. Use the following commands: Code:
cd /usr/share/initramfs-tools/scripts/ Code:
[...] Code:
mkinitramfs -o /boot/initrd.img.ramboot Code:
cp -vax local.bak local ------------------------------------------------- Step 6. Modify /boot/grub/menu.lst with an entry for the custom initrd.img Modify /boot/grub/menu.lst with a new entry. Copy existing OS's entry. Then modify the initrd to use your new initrd.img. It will look something like this: Code:
title RAMdisk Debian GNU/Linux After following these steps, you'll have a very basic working system. Now you can boot into the "main" OS and install things like X (only install the xserver you need) and other programs like icewm and iceweasel. For example: apt-get install xserver-xorg-video-vesa xserver-xorg-video-ati xfonts-base alsa-base alsa-utils icewm menu iceweasel xfe aterm The default icewm theme is rather ugly, so you can copy over a nice theme like /usr/share/icewm/themes/IceCrack2 from another install. Obviously, you don't want to install all of the themes in icewm-themes since they'll be consuming RAM just sitting there. |
Hi, why not further compress your disk image ? squashfs + aufs would do the job just fine. That would save, not only space, but also time when you copy everything into tmpfs. And overall better performance, if possible.
Also, you should not modify the /usr/share/initramfs-tools/* files but you should make your own things in /etc/initramfs-tools/ to keep things tidy. And instead of moving files back and forth, I would use a kernel option, i.e., you boot with ramboot and it puts everything into tmpfs, you boot without and it does a normal boot. Lastly, you can have anything in the initramfs. Anything includes your whole hardrive if you want to. That would simplify everything in your case, the computer would do all the work of putting your initamfs into RAM. |
My experience with LiveCD's which do that is that performance is sluggish compared to an uncompressed OS.
I'm not familiar enough with initramfs-tools to know how to properly do this in /etc/initramfs-tools/ rather than /usr/share/initramfs-tools/, or how to script kernel options. I'd appreciate some pointers. My first idea was to use the initramfs, but it seemed more complicated to figure out. I wanted to do an essentially small modification to the OS's normal operations. I really like the idea of bulking up the initramfs into a truly minimal OS, though. Thanks for the comments and ideas! |
Are you comparing a squashfs partition on a CD to an uncompressed partition on a hard-disk drive? If so, the difference in performance is not due to the compression but to the media used. In principle, squashfs reduces head movement at the expense of increased CPU usage, the tradeoff should be worthy. You can find benchmarks here http://forums.gentoo.org/viewtopic-t...-squashfs.html and my own experience fits in: compressing /usr indeed increases performances (you can start here, I mean only squash /usr and see for yourself, it is not a very dangerous operation.)
By a kernel option, I meant an option on the kernel line in grub. You set it in /boot/grub/menu.lst or "on the fly" while booting by entering in the interactive grub menu. I do not know if you have read man (8) initramfs-tools but you probably should, Debian makes it easy to tinker with the boot process. (http://man.he.net/man8/initramfs-tools). Options on the kernel line are read from /proc/cmdline, you can see how by reading files in /usr/share/initramfs-tools, you should definitely have a look at init. On my Debian laptop, I have a small script in /etc/initramfs-tools/scripts/local-bottom that moves /root to /ro (it is the squashed fs) then, if a root_rw=<device> option is provided, the scripts mounts the device on /rw and uses aufs to union /ro and /rw on /root; if no root_rw is provided, then tmpfs is mounted on /rw, etc. I do not copy anything to RAM, but it is a good idea and I may actually try that since I do not touch RAM that much on that computer. I do not have the computer here, otherwise I would post my script. /usr is for programs and you should not make local changes in this place: it is package manager land; configurations are set in /etc. For update-initramfs and initramfs-tools, files in /usr/share/initramfs-tools or /etc/initramfs-tools are treated equally. The difference is for you: next time you update initramfs-tools, you lose all your changes in /usr/* while files in /etc/* are left alone. Now, an initramfs is just a compressed filesystem containing an executable called init. A long time ago, I started a wiki entry on the Gentoo wiki on how to make an initramfs from scratch (second part in http://gentoo-wiki.com/HOWTO_Initramfs ) and you may have a look over there. Also for reference, the kernel doc: Documentation/early-userspace/README and another how to from scratch http://jootamam.net/howto-initramfs-image.htm. It requires some work to do it this way, but it is not that difficult. Enjoy! |
hi there,
IsaacKuo .......... dude ........... you are great. |
Nice tutorial, I've bookmarked it, going to try this sometime.
|
Hi again, I do things a bit different from you: I use LVM; I also prefer a squashed filesystem, but here are the scripts I use (this is not a very original idea, but my scripts are better written than most of what I have seen so far on the subject)
You'll get the idea of what I told you (kernel options; scripts in /etc/initramfs-tools/ ...) 1. Mount the squashfs filesystem, if the option root_rw=<DEVICE> is provided, <DEVICE> is used as a read-write fs; if not, tmpfs is used Code:
#!/bin/sh -e Code:
#!/bin/sh -e 3. squashfs is read-only, if you use it with tmpfs, you cannot make persistant changes to rootfs. However, you can make persistant changes from the initram! like this Code:
#!/bin/sh -e |
Hi,
Sorry for bringing up this thread, i've just used it successfully with debian lenny. (Thanks) However as we know the RAMBOOT is non-persistant. Is it a good idea to "restore" the ram back to the harddisk by copying the data back? My main idea is to use this ramboot on my network firewall (router) without keeping the hdd spinning. I want to keep the changes made to /etc (dhcp editing, adding/removing firewallrules, ...) and especially the logs. - Boot into ramboot - Mount the harddisk to a folder (see this as backupfolder) - Create a snapshot dir from the ramboot to the backupfolder - Create the tar snapshot and place it in the correct folder on the harddisk for the next boot ------------------------- - Reboot (the new tar file should be used automatically) - Remount the harddisk - Rsync the ramboot with the "backupfolder" (with crontab or on halt/reboot) - Recreate the tar snapshot from the "backupfolder" for the next reboot Any other (better) ideas? |
Quote:
Quote:
So, for me personally, I like to keep servers and routers as boring and "stock" as possible. Yeah, I'm a wuss... Quote:
I mean--why in the world do the tar thing at all? Well, it's because the thing I THOUGHT would work (a simple recursive cp) didn't work (the limited cp available at the start just isn't powerful enough for the job). So I just messed around until I figured out a hack that would work. |
Quote:
|
All times are GMT -5. The time now is 11:07 PM. |