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
apt-get install hdparm localepurge debconf-english
apt-get remove --purge aptitude tasksel tasksel-data laptop-detect
apt-get clean
Note that installing debconf-english will remove debconf-i18n. This is normal.
-------------------------------------------------
Step 2. Create a modified /etc/fstab
Create and edit a new fstab using these commands:
Code:
cd /etc/
cp fstab fstab.ramboot
nano fstab.ramboot
Comment out the / entry. Create a new / line like this:
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
chmod 755 /etc/init.d/ijkijkijk
update-rc.d ijkijkijk defaults 20
The contents of ijkijkijk should be something like this:
Code:
#! /bin/sh
# /etc/init.d/ijkijkijk
# Some things that run always
touch /var/lock/ijkijkijk
# Carry out specific functions when asked to by the system
case "$1" in
start)
echo "Starting script ijkijkijk"
echo "Isaac Kuo script parking drives"
hdparm -S 6 /dev/hda
hdparm -y /dev/hda
#hdparm -S 6 /dev/hdb
#hdparm -y /dev/hdb
#hdparm -S 6 /dev/hdc
#hdparm -y /dev/hdc
#hdparm -S 6 /dev/hdd
#hdparm -y /dev/hdd
;;
stop)
echo "Stopping script ijkijkijk"
;;
*)
echo "Usage: /etc/init.d/blah {start|stop}"
exit 1
;;
esac
exit 0
-------------------------------------------------
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
#
# Takes an OS snapshot, strips it down, and wraps it up into /snapstrip.tar
# Clean up anything previous
touch /snapstrip.tar
touch /snapstrip
rm -fvr /snapstrip.tar
rm -fvr /snapstrip
# Create temporary ramdisk and copy files over
mkdir /snapstrip
mount -t tmpfs -o size=100% none /snapstrip
cp -vax /. /snapstrip/.
cp -vax /dev/. /snapstrip/dev/.
# Move over the modified fstab
cd /snapstrip/etc/
cp -vax fstab.ramboot fstab
# Strip down unnecessary stuff
cd /snapstrip/
rm -fvr /snapstrip/boot/*
rm -fvr /snapstrip/var/lib/apt/lists/*
rm -fvr /snapstrip/usr/share/doc-base/*
rm -fvr /snapstrip/usr/share/doc/*
rm -fvr /snapstrip/usr/share/man/*
rm -fvr /snapstrip/lib/modules/*/kernel/drivers/bluetooth
rm -fvr /snapstrip/lib/modules/*/kernel/drivers/ieee1394
rm -fvr /snapstrip/lib/modules/*/kernel/drivers/parport
rm -fvr /snapstrip/lib/modules/*/kernel/drivers/pcmcia
rm -fvr /snapstrip/lib/modules/*/kernel/drivers/telephony
rm -fvr /snapstrip/lib/modules/*/kernel/drivers/isdn
rm -fvr /snapstrip/lib/modules/*/kernel/drivers/md
rm -fvr /snapstrip/lib/modules/*/kernel/fs/ntfs
rm -fvr /snapstrip/lib/modules/*/kernel/fs/reiserfs
rm -fvr /snapstrip/lib/modules/*/kernel/fs/hfs
rm -fvr /snapstrip/lib/modules/*/kernel/fs/hfsplus
rm -fvr /snapstrip/lib/modules/*/kernel/fs/xfs
rm -fvr /snapstrip/lib/modules/*/kernel/net/appletalk
rm -fvr /snapstrip/lib/modules/*/kernel/net/bluetooth
rm -fvr /snapstrip/lib/modules/*/kernel/net/irda
### ADD IN MORE STUFF TO STRIP HERE ###
# Create the tar archive
cd /snapstrip/
tar cf /snapstrip.tar *
Run the script to create the tar archive. You'll run this script after making changes to the main OS to create a new snapshot file.
-------------------------------------------------
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/
cp -vax local local.bak
nano local
cp -vax local local.ramboot
In nano, you'll want to modify the portion where the actual "mount" command is done. Comment it out and insert something like this:
Code:
[...]
########### ramboot
# FIXME This has no error checking
# Mount root
### mount ${roflag} -t ${FSTYPE} ${ROOTFLAGS} ${ROOT} ${rootmnt}
########### mount the filesystem
mkdir /ijkijk
mount ${roflag} -t ${FSTYPE} ${ROOTFLAGS} ${ROOT} /ijkijk
########### create root ramdisk
mount -t tmpfs -o size=100% none ${rootmnt}
########### copy the files over to the ramdisk
cd ${rootmnt}
tar xf /ijkijk/snapstrip.tar
########### umount the filesystem and set to spin down
umount /ijkijk
hdparm -S 1 /dev/hda
[...]
After making these modifications, create the initrd.img with this command:
Code:
mkinitramfs -o /boot/initrd.img.ramboot
After creating this ramdisk make sure to copy back the backup file with:
Code:
cp -vax local.bak local
This is important! If you forget to do this, then your system will be screwed up if your kernel is upgraded!
-------------------------------------------------
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
root (hd0,0)
kernel /boot/vmlinuz-2.6.18-6-486 root=/dev/hda1 ro
initrd /boot/initrd.img.ramboot
-------------------------------------------------
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.