当前位置: 首页>>技术教程>>正文


如何制作RAM磁盘?

, ,

问题描述

我想制作一个由ram制成的分区……

在Windows 7中,您可以创建一个由ram组成的分区

partitioning,ram,ubuntu

我在ram中创建了1 GB的分区。使用Primo RamDisk

在Ubuntu中有什么好的选择吗?

最佳解决办法

This will show you how to make a RAMDISK super fast and easily. With a RAMDISK you can use your memory for temporary space and it’s also a lot quicker than your hard drive.

Now lets start by using the next 2 commands to make your RAMDISK.

Put whatever you want your RAMDISK to be called where I wrote “nameme”.

mkdir -p /media/nameme  mount -t tmpfs -o size=2048M tmpfs /media/nameme/ 

The above commands would use 2GB of my RAM for the RAMDISK. If you don’t have as much ram as I do I would use 512MB or 1GB. So next were going to create a command for Terminal that will automatically create the RAMDISK for you.

资料来源:How To Create A RAMDISK In Linux

次佳解决办法

tmpfs文件系统是RAMDISK。以下将创建一个始终可用的2G RAMDISK。

sudo mkdir -p /media/ramdisk
sudo mount -t tmpfs -o size=2048M tmpfs /media/ramdisk

ramdisk文件夹由root拥有,因为它在重新启动时可用。 ramdisk权限应该是每个人都可写的。 tmpfs默认权限(chmod 1777)是正确的。

sudo chmod 1777 /media/ramdisk
drwxrwxrwt 2 root root 180 Apr 23 07:34 /media/ramdisk 

要使ramdisk永久可用,请将其添加到/etc /fstab。

grep /media/ramdisk /etc/mtab | sudo tee -a /etc/fstab

您将看到该行从mtab移动到fstab。它看起来像这样。

tmpfs /media/ramdisk tmpfs rw,size=2048M 0 0 

RAMDISK在使用之前不会消耗内存。在最大系统负载期间仔细检查您的内存要求。如果RAMDISK太大,您的系统将使用交换存储来弥补差异。

要调整RAMDISK的大小,请编辑/etc /fstab并通过重新安装ramdisk进行验证(您将在重新启动时丢失当前的RAMDISK内容)。以下内容将把ramdisk的大小更改为512M

# Check the existing ramdisk size.
df /media/ramdisk
# change size=512M for a 512 megabyte ram drive.
sudo vi /etc/fstab
# Remount the ramdisk, you will lose any existing content.
sudo mount -a /media/ramdisk
# Verify the new ramdisk size.
df /media/ramdisk

第三种解决办法

在没有root-privileges的情况下添加我的2美分:

从unix.stackexchange引用this answer

Linux provides a tmpfs device which any user can use, /dev/shm. It is not mounted to a specific directory by default, but you can still use it as one.

Simply create a directory in /dev/shm and then symlink it to wherever you want. You can give the created directory any permissions you choose, so that other users can’t access it.

This is a RAM backed device, so what’s there is in memory by default. You can create any directories you need inside /dev/shm

Naturally, files placed here will not survive a reboot, and if your machine starts swapping, /dev/shm won’t help you.

参考资料

本文由Ubuntu问答整理, 博文地址: https://ubuntuqa.com/article/2165.html,未经允许,请勿转载。