轉:Linux - Load your root partition to RAM and boot it

來源:互聯網
上載者:User

標籤:

This tutorial will guide you through the steps to modify your initramfs to load all files from / to a tmpfs. This will only work with Debian or Ubuntu ? or any unix thats supports booting from a initramfs. Since this is a virtual filesystem in RAM, not a virtual harddisk, this has many advantages.

What you need:
* lots of RAM
* Debian based distribution or any that supports booting from initramfs
* mkinitramfs or a tool to build a new initramfs
* some linux knowledge
* no need to create an image
* no need for Grub4Dos
* no need for a "special driver"

Step 1:
Choose a distribution thats supports booting from initramfs. (like ubuntu)

Step 2:
Install to harddisk. Make sure you split it into multiple partitions (/, /boot, /home, swap, ...).

Step 3:
Boot your new system, install updates, drivers if neccessary (this will improve performance), strip it down to the minimum. Every file will be loaded to RAM ! A fresh install uses about 2 GB auf harddisk-space.

Step 4:
modify /etc/fstab :
* make a backup

cp /etc/fstab /etc/fstab.bak

* find the line specifing the root partition and change it in:

none / tmpfs defaults 0 0

* save

Step 5:
edit the local script in your initramfs:

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

* make a backup of /usr/share/initramfs-tools/scripts/local

cp local local.bak

* modify local, find this line:

# FIXME This has no error checking# Mount rootmount ${roflag} -t ${FSTYPE} ${ROOTFLAGS} ${ROOT} ${rootmnt}

* change it to:

# FIXME This has no error checking# Mount root#mount ${roflag} -t ${FSTYPE} ${ROOTFLAGS} ${ROOT} ${rootmnt}mkdir /ramboottmpmount ${roflag} -t ${FSTYPE} ${ROOTFLAGS} ${ROOT} /ramboottmpmount -t tmpfs -o size=100% none ${rootmnt}cd ${rootmnt}cp -rfa /ramboottmp/* ${rootmnt}umount /ramboottmp

* save
* execute, or rebuild initramfs

mkinitramfs -o /boot/initrd.img-ramboot

* replace modified local with original file

cp -f local.bak local

Step 6:
* modify this file (needs a better solution)

/boot/grub/grub.cfg

* copy the first boot entry and replace the /initrd line with this:

/initrd /initrd.img-ramdisk

* label the new entrie as RAMBOOT
This will boot our generated initramfs instead the original one.


Step 7:
* reboot
* choose standart boot (no ramdisk)
* choose RAMBOOT and all your files on the root partition will be loaded to a tmpfs

Results:
Test setup:
*Kernel : Linux 2.6.38-8-generic (i686)
*Compiled : #42-Ubuntu SMP Mon Apr 11 03:31:50 UTC 2011
*Distribution : Ubuntu 11.04
*no graphics driver
*Desktop HP 8100E
*Core i7 860
*4GB Memory 2 Modules (DDR3)
*WDVeliciraptor 10k rpm 160GB 

轉:Linux - Load your root partition to RAM and boot it

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.