It is currently Sat Sep 20, 2014 10:11 pm

All times are UTC - 8 hours




Post new topic Reply to topic  [ 32 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: HOW-TO: Boot Linux into RAM for silence and speed
PostPosted: Fri Jun 06, 2008 6:35 am 
Offline

Joined: Fri Jan 23, 2004 7:50 am
Posts: 1705
Location: Baton Rouge, Louisiana
[edit: I've created a new and improved how-to. The original version is included below the new version, but there's no reason to prefer the old one.]
-----------------------------
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.


=====================
=====================
=====================
=====================
=====================
(Original How-to is below)
=====================
=====================
=====================
=====================
=====================

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 twice on the hard drive

2. Create a modified /etc/fstab which has tmpfs for the root partition

3. Create a script which makes a stripped down OS image

4. Create a custom initrd.img which loads the OS image into a tmpfs ramdisk

5. Modify /boot/grub/menu.lst with an entry for the custom initrd.img

-------------------------------------------------
After completing these steps, you will have a triple boot system with the following boot options:

A) "auxiliary" OS, where you run the OS snapshot/stripping script
B) "main" OS, where you install new software or change settings
C) "ramboot" OS, for high speed silent computing

-------------------------------------------------
Step 1. Installing Debian 4.0 twice

Create three partitions:

hda1 ext3 4 gigs
hda5 ext3 2 gigs (unless you have lots of RAM and plan on making a BIG image)
hda6 swap

First, install onto hda5 do NOT select either Desktop Workstation or Base software suites.

Upgrade the kernel, and install the following:

apt-get install hdparm localepurge debconf-english (will remove debconf-i18n)

Do some stripping down by removing the following:

apt-get remove --purge aptitude tasksel nano
apt-get clean

Second, install onto hda1. This is the auxiliary OS, and you do not need to do anything special to strip it down if you don't want to. Upgrade the kernel to the same version as the other install.

In the auxiliary OS, set it to mount /dev/hda5 to /mnt/hda5.
-------------------------------------------------
Step 2. Create a modified /etc/fstab

Go to create and edit a new fstab using these commands:

cd /mnt/hda5/etc/
cp -vax fstab fstab.ramboot
vi fstab.ramboot

Comment out the swap entry and the /dev/hda5 entry. Create a new / line like this:

none / tmpfs defaults 0 0

-------------------------------------------------
Step 3. Create a script which makes a stripped down OS image

Boot up into the auxiliary hda1 OS, and login as root. Then create a basic script like this:

Code:
#!/bin/sh
#
# Takes an OS snapshot from /mnt/hda5, strips it down, and wraps it up into /snapstrip.tar

# Clean up anything previous
touch /snapstrip
touch /snapstrip.tar
rm -fvr /snapstrip
rm -fvr /snapstrip.tar

# Copy the files over
mkdir /snapstrip
cp -vax /mnt/hda5/* /snapstrip/

# 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/2.6.18-6-486/kernel/drivers/bluetooth
rm -fvr /snapstrip/lib/modules/2.6.18-6-486/kernel/drivers/ieee1394
rm -fvr /snapstrip/lib/modules/2.6.18-6-486/kernel/drivers/parport
rm -fvr /snapstrip/lib/modules/2.6.18-6-486/kernel/drivers/pcmcia
rm -fvr /snapstrip/lib/modules/2.6.18-6-486/kernel/drivers/telephony
rm -fvr /snapstrip/lib/modules/2.6.18-6-486/kernel/drivers/isdn
rm -fvr /snapstrip/lib/modules/2.6.18-6-486/kernel/drivers/md

rm -fvr /snapstrip/lib/modules/2.6.18-6-486/kernel/fs/ntfs
rm -fvr /snapstrip/lib/modules/2.6.18-6-486/kernel/fs/reiserfs
rm -fvr /snapstrip/lib/modules/2.6.18-6-486/kernel/fs/hfs
rm -fvr /snapstrip/lib/modules/2.6.18-6-486/kernel/fs/hfsplus
rm -fvr /snapstrip/lib/modules/2.6.18-6-486/kernel/fs/xfs

rm -fvr /snapstrip/lib/modules/2.6.18-6-486/kernel/net/appletalk
rm -fvr /snapstrip/lib/modules/2.6.18-6-486/kernel/net/bluetooth
rm -fvr /snapstrip/lib/modules/2.6.18-6-486/kernel/net/irda

#############ADD IN MORE STUFF TO DELETE 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 4. 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, for now at least. There's probably a less "hackish" way of doing this.

On the auxiliary OS, go to /usr/share/initramfs-tools/scripts/

cd /usr/share/initramfs-tools/scripts/

Create a backup of "local" and edit a modified version with:

cp -vax local local.bak
vi local.ramboot
cp -vax local local.ramboot

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 ramdisk (note hardcoded size)
        mount -t tmpfs -o size=400M 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 6 /dev/hda

########################################ijk
[...]

After making these modifications, create the initrd.img with this command:

mkinitramfs -o /boot/initrd.img-2.6.18-6-486.ramboot

After creating this ramdisk make sure to copy back the backup file with:

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!

Note that at first, I tried using "cp" to copy over the filesystem, but that failed since the version of cp included in busybox is apparently not up to the job. Tar worked fine.
-------------------------------------------------
Step 5. Modify /boot/grub/menu.lst with an entry for the custom initrd.img

Modify /boot/grub/menu.lst with a new entry. Copy the auxiliary OS's entry where root=/dev/hda1. Then modify the initrd to use your new initrd.img. It will look something like this:

title RAMdisk Debian GNU/Linux, kernel 2.6.18-6-486
root (hd0,0)
kernel /boot/vmlinuz-2.6.18-6-486 root=/dev/hda1 ro
initrd /boot/initrd.img-2.6.18-6-486.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.

_________________
Isaac Kuo


Last edited by IsaacKuo on Mon Aug 11, 2008 6:01 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 06, 2008 6:44 am 
Offline

Joined: Fri Jan 23, 2004 7:50 am
Posts: 1705
Location: Baton Rouge, Louisiana
On my main workstation, I've gone from diskless netbooting to this RAMboot method. It boots off a hard drive, loads the entire OS into RAM, and spins down the hard drive.

Now I can finally enjoy true silent computing!

Previously, I had used either an enclosed 2.5" drive or I use diskless booting over the network. Unfortunately, my motherboards have this "chirping" noise during any sort of disk or network access. Thus, even though the enclosed 2.5" drive or network may theoretically be silent, in practice the motherboard still make noises during I/O access.

But RAM access is dead silent.

Also, the speed is just incredible. Programs start up instantly. The web browser never pauses loading/unloading cache files. It's just plain FAST.

_________________
Isaac Kuo


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 06, 2008 2:42 pm 
Offline

Joined: Tue Feb 19, 2008 2:08 pm
Posts: 398
Location: Los Angeles
One thing... be sure to be using a processor that supports PAE(most new ones). under most flavors of *IX, you can get 42 bit memory addressing, and can utilize up to 64GB of ram.(of course, slots become the limiting factor as 8 and 16 GB modules aren't out at a reasonable price)

http://en.wikipedia.org/wiki/Physical_Address_Extension

Even 8 GB split into 4 and 4 is an enormous advantage.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 06, 2008 2:58 pm 
Offline
Friend of SPCR

Joined: Mon Mar 17, 2008 2:30 pm
Posts: 89
Location: Bucuresti, Romania
what system specs ?

_________________
i5-4570 | Ninja+B on 115x | AsRock B85 Pro 4 | 8Gb Kingston | GTX460 1Gb + Setsugen2 | ASUS XonarDX | Kingston 3K 120Gb | Samsung HD103SJ | Corsair VX450W w/ 120 Nexus | Antec Solo | 2x92 in+120 out Nexus | Grado SR325i | Acer AL2723W | Debian Sid


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 06, 2008 3:46 pm 
Offline

Joined: Fri Jan 23, 2004 7:50 am
Posts: 1705
Location: Baton Rouge, Louisiana
The machine I'm currently typing on is a Socket 754 Sempron 3100+ with 384megs of RAM. It's...a tight fit. I'm going to continue to do more trimming and will be using this on my main workstation--which has 1meg of RAM.

Even if I had tons of RAM, I'd still do the trimming because the size of the image affects how long it takes to boot up. The entire image gets loaded into RAM, of course.

_________________
Isaac Kuo


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jun 07, 2008 8:34 am 
Offline

Joined: Sat Apr 12, 2008 5:05 pm
Posts: 160
Location: Orangevale, CA
Could this technique be adapted for the Linux machine to ram-boot from an image found on a network server?

In my office, I have my personal workstation, plus several servers that support my business. I was thinking about running the DNS machine from a flash disk, but your ram-boot process might also do what I need.

Some of my machines must have disks running all the time. These could be the source for ram-boot machines.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jun 07, 2008 10:15 am 
Offline

Joined: Fri Jan 23, 2004 7:50 am
Posts: 1705
Location: Baton Rouge, Louisiana
Yes, I think so. However, netbooting is significantly more complex.

With Debian 4.0, I notice that the first time it attempts to mount the nfs root, it fails. So it will be necessary to a little more complex hacking of the nfs root mounting script to do the ramdisk creation/copy.

The little hack I suggest to the local mountroot script is simple and straightforward because it simply assumes the mount will work the first time (the original script has no error checking on this step, and simply assumes the mount works).

_________________
Isaac Kuo


Top
 Profile  
 
 Post subject: Great idea. Share it via tuxmachines.org?
PostPosted: Sat Jun 07, 2008 1:41 pm 
Offline

Joined: Thu Nov 24, 2005 3:03 pm
Posts: 317
Nice set of posts, Isaac. I'll try it as soon as I upgrade my antique machine.

You might consider sharing it via tuxmachines.org (or any of the howto or lxer-type link sites) so that more people can benefit.

E.g., http://www.tuxmachines.org/node/414 (Great site, lots of useful articles linked every day.)


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jun 07, 2008 7:42 pm 
Offline

Joined: Sat Apr 12, 2008 5:05 pm
Posts: 160
Location: Orangevale, CA
My original idea for this is simply installing to a flash drive. I can GHOST this drive, or otherwise copy it for safe keeping. My DNS tables are static, so this would be a frugal and silent way to run this machine.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jun 07, 2008 9:15 pm 
Offline

Joined: Fri Jan 23, 2004 7:50 am
Posts: 1705
Location: Baton Rouge, Louisiana
For your purposes I'd go with your original idea of installing to a flash drive. The main problem with netbooting is that the computer is essentially dependent on another particular computer being functional. I think this is acceptable for a workstation or media player "appliance", but I don't like the idea of a server being dependent on another server.

I like to have a simple "two tier" graph of dependency. The upper tier is the "servers", which don't depend on any other computer. The lower tier is the "clients", which depend on zero or more servers (no client depends on another client). This keeps me sane. If nothing else, it makes powering up easy--first power up the servers, in any order, and then power up the clients, in any order.

_________________
Isaac Kuo


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 05, 2008 4:04 am 
Offline

Joined: Tue Aug 05, 2008 4:00 am
Posts: 2
Location: Germany
Thanks for all the hints here. This works great.
But somehow my harddisk is still wakening up after about 5 seconds sleep mode. Does anybody know how to make this complete silent? Why is linux still trying to access the harddrive? Maybe I should mount /var also as a tmpfs filesystem?

Thank you


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 05, 2008 4:16 am 
Offline

Joined: Fri Jan 23, 2004 7:50 am
Posts: 1705
Location: Baton Rouge, Louisiana
Post the contents of your /etc/fstab here. My first guess is that there's some partition of your hard drive mounted--maybe swap.

_________________
Isaac Kuo


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 05, 2008 6:18 am 
Offline

Joined: Sat Jul 14, 2007 10:11 am
Posts: 292
Location: Perth, Western Australia
This is a great tip mate! Going to give this a crack with a flash disk for sure.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 05, 2008 6:50 am 
Offline

Joined: Fri Jan 23, 2004 7:50 am
Posts: 1705
Location: Baton Rouge, Louisiana
By the way, I've been refining this technique, and have figured out an elegant simplification that only involves one OS install on one partition. I'm not sure when I'll have the time to hammer down all the details and redo my how-to.

The basic idea is to just have one OS install, and for the script steps to be:

1) Delete the old image file
2) Create a ramdisk
3) Copy the OS partition to the ramdisk
4) Strip out excess files and modify fstab and such
5) Create the new image file

Compared to the original method, this greatly reduces the overall complexity and hard drive space usage (which may be very helpful for compact flash or USB thumbdrive install). It also greatly improves the performance of the script--copying files between a hard drive and a ramdrive rather than from a hard drive to itself.

The only downside is that it requires more RAM at minimum. There needs to be sufficient RAM for the OS partition even before stripping out unnecessary files. But if you're hurting for RAM, it's probably not a good idea to use this method in the first place.

_________________
Isaac Kuo


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 05, 2008 6:50 am 
Offline
Friend of SPCR

Joined: Wed Dec 17, 2003 6:14 am
Posts: 1235
Location: Finland
DerHund:

paste the full output of the command "mount" here, and we'll know.

_________________
my general purpose desktop system: HP LP3065 30" LCD 2560x1600 pixels, Q9450, 8GB DDR2 ECC 800MHz, EVGA 460GTX 1GB SC (OC@800MHz/2000MHz), WD Velociraptor 300GB, Samsung 2TB, Gigabyte EX38-DS4, Antec P182b, Corsair VX450, Thermalright Ultra 120 Extreme, Scythe S-Flex fan, <90W AC idle, 200W AC gaming


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 05, 2008 11:34 pm 
Offline

Joined: Tue Aug 05, 2008 4:00 am
Posts: 2
Location: Germany
Hello,
thank you. I checked my fstab and there was swap and /home still mounted on my harddisk. I removed them and everything was suddenly silent ;).
Thanx for the great help!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 11, 2008 6:08 pm 
Offline

Joined: Fri Jan 23, 2004 7:50 am
Posts: 1705
Location: Baton Rouge, Louisiana
I've created a new and improved version of this how-to. The new method is far more elegant and has much better performance.

The original version was too complex, using two installs and requiring three reboots whenever making changes to the OS. The new version has only one install and only requires two reboots whenever making changes (one to reboot into the hard drive install, and then one to reboot back into the RAMboot entry).

Performance is better than before when running the snapstrip script. In the old version, the temporary snapshot was put on the hard drive. This meant the old snapshot had to be deleted, which takes a while, before creating a new snapshot. The new version puts the snapshot into a ramdisk. Not only is it no longer necessary to delete the old snapshot, but speed is doubled compared to copying to/from the hard drive.

_________________
Isaac Kuo


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 14, 2008 12:08 am 
Offline

Joined: Sat Jul 14, 2007 10:11 am
Posts: 292
Location: Perth, Western Australia
Thanks for this Isaac! I can't wait to try it out when I get back from holidays.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 14, 2008 6:50 am 
Offline

Joined: Fri Jan 23, 2004 7:50 am
Posts: 1705
Location: Baton Rouge, Louisiana
You're welcome! The speed is really addicting...I can't go back to waiting around for a program to open.

I'm already thinking of another improvement on the scheme. Currently, excess stuff is simply deleted from the image, but there's still a LOT of not entirely essential stuff left in the image.

I'm thinking that instead of outright deleting the excess stuff, it could instead be offloaded to a network share. The excess "junk" files would be moved to the nfs share and softlinked in the root partition.

When booted up in normal hard drive mode, this network share is mounted read/write. When booted up in RAMboot mode, this network share is mounted read-only, joined by UnionFS to a ramdisk.

Compared to the current method of deleting the excess stuff:

1) This leaves apt-get and man fully functional.

2) The excess files no longer take up space in the root partition, so it takes less time to copy over the root partition in the snapstrip script. This also reduces the amount of RAM required by the snapstrip script.

3) It's possible to offload many files which are used infrequently or for which slower loading time is acceptable.

The disadvantages are that you need a file server, and setting everything up is slightly more complicated.

_________________
Isaac Kuo


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 14, 2008 8:44 am 
Offline

Joined: Sat Jul 14, 2007 10:11 am
Posts: 292
Location: Perth, Western Australia
If you go ahead with that Isaac, I'd love to see a howto for it. I'm planning on rearranging things when I get back from holidays. Will involve cat 6 cabling and a NAS.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 14, 2008 8:57 am 
Offline

Joined: Fri Jan 23, 2004 7:50 am
Posts: 1705
Location: Baton Rouge, Louisiana
I'm still contemplating the different possible approaches. Using nfs is pretty straightforward for me since I already have an nfs file server, but nbd may offer some compelling advantages.

Network Block Device, unlike nfs, is a block device (like an NAS). As such, file caching works like a local drive. That means that as long as there's plenty of RAM, files only need to be read once and after that read-only access is as fast as from a ramdrive.

_________________
Isaac Kuo


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 26, 2009 7:33 am 
Offline

Joined: Sun Apr 26, 2009 6:45 am
Posts: 2
Location: USA
Boot linux to ram with rsync

There is a different approach possible by using the ramdisk and rsync.
After performing steps 1 to 3 of the original How-To start with getting rsync:
Code:
aptitude install rsync


Unwrap the current initrd
Code:
mkdir /tmp/init
cp /boot/initrd.img-[KERNEL VERSION] /tmp/init
cd /tmp/init
gzip -dc initrd.img-* | cpio -id


Copy rsync to initrd (rsync needs some additional libraries)
Code:
cp /usr/bin/rsync /tmp/init/bin
cp /lib/libacl.so.1 //tmp/init/lib
cp /lib/libpopt.so.0 //tmp/init/lib
cp /lib/libattr.so.1 //tmp/init/lib


Now hange the scripts/local file to:
Code:
 [...]
# create filesystems
mkdir /tmproot
mount ${roflag} -t ${FSTYPE} -r ${ROOT} /tmproot
mount -t tmpfs /dev/ram0 ${rootmnt}

# get dir
dir=`pwd`

# copy files and then unmount disk
cd ${rootmnt}
rsync -aH /tmproot/* ./
umount /tmproot

# replace fstab
cp ${rootmnt}/etc/fstab.ramboot ${rootmnt}/etc/fstab

# set dir back gives error msg otherwise
cd $dir
[...]


Make an initrd.img and copy it to boot
Code:
cd /tmp/init
find . | cpio -o -H newc > .initramfs.img
gzip initramfs.img
cp initramfs.img.gz /boot/initrd.img-ramboot


Change grub/menu.lst.

Finished.

The advantage of this approach is, that you don't have to boot from harddrive at all. If you want your changes to be permanent just rsync the root dir to the harddrive, and volia, everything is updated.

In the scripts/local rsync can also be used with the --exclude option, to get rid of unnecessary files and dirs to make the boot faster. It should also be possible to rsync from a remote host (haven't tested it yet).

If someone knows, how i limit the size of the ramdisk (by default it uses half of the available memory) please let me know.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 26, 2009 8:30 am 
Offline
Friend of SPCR

Joined: Wed Dec 17, 2003 6:14 am
Posts: 1235
Location: Finland
I used to be interested in tinkering with things like that, even ran a totally diskless machine myself (no hdd, no flash, no optical, no floppy, just netboot).

However, now. Why don't you just get a SSD instead...

Silence? Check

Low Power? Check

Speed? Check (assuming Intel SSD)

Costs a fortune, but then again you could be working extra hours to get more pay instead of using a lot of time to configure and maintain a RAM boot system.

_________________
my general purpose desktop system: HP LP3065 30" LCD 2560x1600 pixels, Q9450, 8GB DDR2 ECC 800MHz, EVGA 460GTX 1GB SC (OC@800MHz/2000MHz), WD Velociraptor 300GB, Samsung 2TB, Gigabyte EX38-DS4, Antec P182b, Corsair VX450, Thermalright Ultra 120 Extreme, Scythe S-Flex fan, <90W AC idle, 200W AC gaming


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 26, 2009 9:03 am 
Offline

Joined: Fri Jan 23, 2004 7:50 am
Posts: 1705
Location: Baton Rouge, Louisiana
Strangely enough, in my case it would NOT be silent. For whatever reasons, all of my later motherboards make audible electronic chirps whenever accessing most I/O hardware (like ethernet, or USB thumbdrive, or hard drive). Even with a completely silent hard drive, the motherboard hardware makes chirping noises during access.

This means that an SSD isn't silent; bootable USB thumbdrive isn't silent; even netboot isn't silent.

So for me, the best silent solution is RAMboot.

_________________
Isaac Kuo


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 26, 2009 9:08 am 
Offline

Joined: Fri Jan 23, 2004 7:50 am
Posts: 1705
Location: Baton Rouge, Louisiana
goddamn wrote:
If someone knows, how i limit the size of the ramdisk (by default it uses half of the available memory) please let me know.


A tmpfs ramdisk only consumes about as much RAM as the total sum of the current contents. It dynamically resizes itself bigger/smaller, up to the nominal size limit.

By default the max size is 50%, which in my case is often too small. To mount with a different max size, use the size option. For example:

mount -t tmpfs -o size=90% none /snapstrip

This will specify a maximum size of 90% of RAM. If you're using a swap partition, you can specify a size greater than 100%.

_________________
Isaac Kuo


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 07, 2009 12:10 pm 
Offline

Joined: Sat Oct 04, 2008 3:29 am
Posts: 96
Location: Edinburgh
lm wrote:
Costs a fortune, but then again you could be working extra hours to get more pay instead of using a lot of time to configure and maintain a RAM boot system.


It would be nice if I could get work whenever I wanted it.


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 21, 2009 9:11 pm 
Offline

Joined: Thu May 21, 2009 9:04 pm
Posts: 2
Location: Earth
I want to use something like this, because I have 10 GB of RAM, and no hard disk. I want to boot from USB flash, and then remove the USB stick after booting.

I like your HOWTO, however why do we need to boot to a different boot entry to be able to change the image? I would like to make changes while running the RAMbooted image, and then save the image to a new permanent image on flash (in case power goes down or something) but without any need to reboot. Will that work?

And I don't need, nor want to delete anything from my installed standard Debian system, as I have 10 GB of RAM, more than the flash stick on which I installed Debian (2 GB).


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 21, 2009 9:33 pm 
Offline

Joined: Tue Mar 17, 2009 10:26 am
Posts: 177
Location: Germany
Puppy Linux does just what you describe "out of the box", so if you are not particularily attached to Debian, it might be worth a try.
You might have to modify some scripts to make it save to flash only on shutdown instead of every 10 minutes or so (you wany to remove the USB, right?), but that should not be too difficult.


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 21, 2009 9:43 pm 
Offline

Joined: Thu May 21, 2009 9:04 pm
Posts: 2
Location: Earth
Well, I am attached to Debian, but I might look how they do it.
Debian has now a package called live-initramfs, could it be of some use here?


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 22, 2009 1:16 am 
Offline

Joined: Mon Apr 16, 2007 7:33 pm
Posts: 37
Location: Sydney
This is pretty interesting, however I wonder if there are any more wholistic solutions.

For example, Linux has preloading and whatnot, but wouldn't it be nice to be able to specify say a diskcache priority, and have certain apps and libraries loaded at boot based on priority, and release the cache based on that priority. For example, you could specify specify KDE and the KDE apps you want plus say firefox to always remain in cache. If you have a lot of RAM, the speed would be the same as having a ramdisk.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 32 posts ]  Go to page 1, 2  Next

All times are UTC - 8 hours


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group