BootToRAM

Revision 6 as of 2007-05-04 16:58:09

Clear message

Booting Ubuntu To RAM

Preface

This article aims to document the process of creating a customized Ubuntu that loads an image from the hard disk to RAM, then boots an entire Ubuntu session out of RAM. It is intended for intermediate to advanced Ubuntu users who are familiar with the shell, and may have limited experience customizing the livecd (LiveCDCustomization) and shell scripting. We will customize a LiveCD and copy it to the hard drive, and make a few modifications to bootup scripts so that it copies to RAM via our good friend tmpfs.

WARNING: The author asserts that this procedure works for him, but cannot guarantee that this procedure works for anyone else. Although this procedure is meant to be 100% safe, it is feasible that there may be mistakes, or a chance of misunderstanding the instructions in a manner that causes loss of data. Please make a backup and do not attempt on mission critical systems. Read through this article thoroughly, and do not attempt if you do not comprehend or feel comfortable about any of the instructions!

Use Cases

There are many cases where one would like to boot Ubuntu to RAM:

  • Performance: The desktop performance is dramatically improved. A 400MB squashed filesystem in RAM, that holds 1200MB of data, is read back on a 1.6GHz Core Duo in about 3 seconds, including decompression time.
  • Power, Noise, Durability: Although modern hard disks don't use much power compared to other system components, this may still be important for some. In laptops, hard disks are often the noisiest components, so this setup can reduce system noise. With the hard disk spun down, a laptop can potentially withstand greater shocks without damage.
  • Abrupt poweroff: Since the hard disk is only momentarily used in read-only mode during boot, then never touched again, there are few or no negative consequences of an abrupt poweroff. If a system is used where power is inconsistent, or the system is regularly used in a context where fast shutoffs are required, this is very handy.

Requirements

The most obvious increased requirement is RAM. For best performance, I recommend having 256MB RAM + enough RAM to hold a customized image. Stripping Openoffice and some fonts and documentation from a stock Ubuntu LiveCD results in a 400MB compressed image, which fits in RAM comfortably on a system with 1GB RAM.

Tmpfs can fall back on swap (Ubuntu LiveCD scripts will mount any swap it finds), which is excellent for a bit of overflow, but if you regularly need to fall back on swap, performance will naturally suffer.

I have not investigated CPU requirements, but squashfs is compressed and decompressing takes some CPU power, so this is probably not a great idea on systems older than the Pentium III era.

As far as setting this system up, the requirements would be:

  1. Having a Feisty LiveCD ISO or CD handy.
  2. About 2-4GB of free space
  3. A combined 1GB or so of RAM and swap available.

The Process

Unpack LiveCD

First, we need to unpack the LiveCD for customization. For this article, I am going to make the following assumptions about paths. You can of course reject my choices and substitute your own.

  • The compressed root image is at /casper/filesystem.squashfs
  • The kernel is at /casper/vmlinuz
  • The initramfs is at /casper/initrd.gz
  • /dev/hda1 contains the /casper directory
  • We will make a temporary directory /casper/chroot where we edit this root filesystem.

For the first 3 files are located in /casper on the LiveCD. Please copy these files from the LiveCD to /casper on your hard disk. You may use the GNOME archive manager (file-roller) as root, bind-mounting, or a physical CD. I will assume you know how to do this.

Customize LiveCD

Please see [LiveCDCustomization/6.06] for detailed instructions on customizing the LiveCD. I will only be providing a basic rundown on the process.