From ArchWiki
Revision as of 20:37, 10 November 2011 by Karol (Talk | contribs) (Useful links: fox formatting)

Jump to: navigation, search

This template has only maintenance purposes. For linking to local translations please use interlanguage links, see Help:i18n#Interlanguage links.

Local languages: Català – Dansk – English – Español – Esperanto – Hrvatski – Indonesia – Italiano – Lietuviškai – Magyar – Nederlands – Norsk Bokmål – Polski – Português – Slovenský – Česky – Ελληνικά – Български – Русский – Српски – Українська – עברית – العربية – ไทย – 日本語 – 正體中文 – 简体中文 – 한국어

External languages (all articles in these languages should be moved to the external wiki): Deutsch – Français – Română – Suomi – Svenska – Tiếng Việt – Türkçe – فارسی

A ramdisk is a portion of RAM utilised as a disk. Many distributions use /dev/ram for this, however Arch does not have a /dev/ram so we must use /etc/fstab to create ramdisks. The most important thing to remember about a ramdisk is that it is stored in RAM and thus volatile. Anything stored on a ramdisk will be lost if the computer completely seizes up, or loses power. Therefore, it is necessary to save the contents of your ramdisk to the harddrive if you want to save them.

Why use one?

As a ramdisk is stored in RAM, it is much faster than a conventional filesystem. So, if you need to manipulate files at high speed, a ramdisk could be the best solution. Popular choices include /tmp, /var/cache/pacman, or /var/lib/pacman, although I'm sure you could think of many others.

How to create a ramdisk

To create a ramdisk, you must treat it as any other mounted filesystem. You must first pick and create a location for it to reside on, and then add it to your /etc/fstab file as follows:

none     /path/to/location     ramfs  defaults   0     0

If you do not have a lot of spare ram, it is recommended to use 'tmpfs' instead of 'ramfs', as tmpfs uses Swap when the available RAM starts to run out, whereas ramfs does not. Of course, dipping into swap loses the performance benefits of RAM, so it's a little pointless unless you have a lot of spare RAM.

Example usage

The files that have been edited are /etc/fstab, /etc/rc.local, and /etc/rc.local.shutdown to store /tmp, /var/cache/pacman, and /var/lib/pacman in RAM, and sync them to disk before shutting down. Portions of the files not relevant to the topic at hand have been removed to save space


none        /tmp         ramfs   defaults              0 0
none        /mnt/ramdisk ramfs   defaults              0 0


chmod 777 /tmp
touch /etc/ramdisk.sh

/bin/cat - >> /etc/ramdisk.sh << EOT

cd /var/ && /bin/tar cf abs.tar abs/
cd /var/cache/ && /bin/tar cf pacman.tar pacman/
cd /var/lib/ && /bin/tar cf pacman.tar pacman/

/bin/mkdir /mnt/ramdisk/var/
/bin/mkdir /mnt/ramdisk/var/cache/
/bin/mkdir /mnt/ramdisk/var/lib/

/bin/mv /var/abs /mnt/ramdisk/var && /bin/ln -s /mnt/ramdisk/var/abs /var/abs
/bin/mv /var/cache/pacman /mnt/ramdisk/var/cache &&  /bin/ln -s /mnt/ramdisk/var/lib/pacman /var/lib/pacman
/bin/mv /var/lib/pacman /mnt/ramdisk/var/lib && /bin/ln -s /mnt/ramdisk/var/cache/pacman /var/cache/pacman

/bin/ln -s /tmp /mnt/ramdisk/tmp
/bin/chmod 777 /mnt/ramdisk/tmp

/etc/ramdisk.sh &


echo "Saving contents of ramdisk to harddrive"
rm /var/abs
rm /var/cache/pacman
rm /var/lib/pacman
mv /mnt/ramdisk/var/abs /var
mv /mnt/ramdisk/var/cache/pacman /var/cache
mv /mnt/ramdisk/var/lib/pacman /var/lib

Useful links