Linux copy to ram

Linux Mint Forums

Hi everyone!
Recently I made use of PCLinuxOS’s «copy to RAM» feature on their liveCD — a rather useful feature, to be sure (e.g. I used it so I could wipe my hard disk, download the Ubuntu Maverick RC to RAM, and burn the iso to CD — something that can’t be done while using a liveCD, of course). On the flip-side, it could be a potential problem for any new users that load a CD and use the option, even though they have less than 2GB RAM (as the feature takes about 1.5GB). In any case, I was just wondering if such a feature might nonetheless be considered for future releases of Mint. the idea’s out there now! So, what do others think?

Re: «Copy To RAM» Booting Option On LiveCD

Post by eiver » Thu Sep 30, 2010 10:40 am

An extremely useful feature. I’d love to see it available in Mint. The system would work much faster without costant reading from the CD too.

Re: «Copy To RAM» Booting Option On LiveCD

Post by piratesmack » Tue Oct 05, 2010 5:41 pm

I took a look at the init script to see if I could add this feature, and found that it was already there. (add ‘toram’ to the boot parameters)

Or maybe you already knew that and were only suggesting that Clem adds a ‘Copy2ram’ entry to the boot menu? Good idea I think.

Re: «Copy To RAM» Booting Option On LiveCD

Post by daquirm » Sun Nov 28, 2010 6:13 pm

Does this work with fluxbox edition? I’m unable to do it. I added this to grub.cfg file, but with little success. I ran a multiboot live USB created by this tool http://liveusb.info/dotclear/index.php?

Re: «Copy To RAM» Booting Option On LiveCD

Post by itsme4401 » Mon Nov 29, 2010 6:44 am

If you use this option («toram») however, you will not be able to repair grub/grub2 and do other useful trics on the MBR of your HD. So it’s a mixed blessing at best.

Re: «Copy To RAM» Booting Option On LiveCD

Post by piratesmack » Mon Nov 29, 2010 7:05 pm

daquirm wrote: Does this work with fluxbox edition? I’m unable to do it. I added this to grub.cfg file, but with little success. I ran a multiboot live USB created by this tool http://liveusb.info/dotclear/index.php?

That live usb tool appears to boot directly from the ISO using the Grub2 ‘loopback’ command.
I’m not sure if ‘toram’ will work that way. Try creating a live usb the normal way using unetbootin or the Ubuntu startup disk creater (or whatever it’s called)

itsme4401 wrote: If you use this option («toram») however, you will not be able to repair grub/grub2 and do other useful trics on the MBR of your HD. So it’s a mixed blessing at best.

Источник

Placing Files in RAM in Linux

announcement - icon

The Kubernetes ecosystem is huge and quite complex, so it’s easy to forget about costs when trying out all of the exciting tools.

Читайте также:  Kali linux поиск человека

To avoid overspending on your Kubernetes cluster, definitely have a look at the free K8s cost monitoring tool from the automation platform CAST AI. You can view your costs in real time, allocate them, calculate burn rates for projects, spot anomalies or spikes, and get insightful reports you can share with your team.

Connect your cluster and start monitoring your K8s costs right away:

1. Overview

In this tutorial, we’ll learn how to place our files into RAM in Linux. Specifically, we’ll learn how to mount the RAM filesystem onto a directory to speed up I/O performance.

2. RAM Filesystem in Linux

In computing, random access memory (RAM) is a volatile memory and offers a much faster read-write speed than nonvolatile memory such as a hard disk drive (HDD) or solid-state drive (SSD). One downside of RAM is that the RAM will not persist the data across reboots.

Despite not being able to persist data permanently, the faster read-write speed offered by RAM is helpful for significantly improving the runtime of applications that do a lot of I/O. Therefore, it’s common to see cases where files are being placed onto a RAM disk to improve the performance of the application. For example, putting source code onto a RAM disk during the build phase will usually speed up the build time, given that there are a lot of I/O activities going on.

In Linux, there are two different types of RAM filesystems available: ramfs and tmpfs.

3. ramfs and tmpfs

Both ramfs and tmpfs are RAM-based file systems. In other words, data stored on both file systems will be on volatile memory and, therefore, will not persist across reboot.

On the other hand, there are several differences between ramfs and tmpfs. On a high level, ramfs are based on the kernel caching system’s mechanism, whereas tmpfs is a newer implementation that builds on top of ramfs to include more features. As a result, people tend to use tmpfs more than ramfs nowadays.

Additionally, the ramfs cannot be limited in size and will happily use up all the available memory. In contrast, the tmpfs offer a size limit configuration to impose a size limit on the directory. This feature of tmpfs is considered an enhancement over ramfs as it provides better system stability by ensuring no one process can take up the entire RAM.

Besides that, ramfs is not eligible for swap, whereas tmpfs may use swap space when the size grows. Depending on use cases, the fact that tmpfs can be swapped might not be desirable since swapping involves nonvolatile disk I/O. As a result, it regresses the overall I/O performance back to the disk-based memory.

Finally, the ramfs does not accept permissions bits parameters such as uid and gid. On the other hand, tmpfs accepts permissions parameters such as uid and gid to configure the permissions bits on the mounted directory.

3. Mounting ramfs to Directory Using mount Command

In most cases, we should prefer the tmpfs as it is the newer implementation and offers more configuration options. However, if we wanted a pure RAM filesystem that does not involve swap space at all, we should still use the ramfs.

Before we proceed, we must keep in mind that because no limit can be imposed on the ramfs, we must exercise caution to prevent the size of the mount from growing uncontrollably. If we fail to do that, we might risk starving critical processes from RAM resources and crashing the system.

3.1. Creating a ramfs Mount

To create a ramfs mount, we can run the command mount ramfs with the -t ramfs option followed by the target directory.

Читайте также:  Сменить язык линукс терминал

Let’s mount the ramfs onto the /ram-dir directory:

$ sudo mount ramfs -t ramfs /ram-dir

Note that the ramfs filesystem does not accept any other parameters, such as permission bits and size limits. Passing the options to the mount command will not result in any error, but the ramfs will simply ignore them.

Subsequently, any content we put into the /ram-dir will live in the physical RAM. One obvious effect we can observe right away is that the read-write speed on the /ram-dir will significantly increase. To perform the comparison, let’s move 1GB of data into a normal directory and time it:

$ dd bs=1M count=1024 if=/dev/zero of=/control/test conv=fdatasync 1024+0 records in 1024+0 records out 1073741824 bytes (1.1 GB, 1.0 GiB) copied, 3.4594 s, 310 MB/s

The script above uses the dd command to create a 1GB file from /dev/zero. Then, it moves the file into the /control directory. We see that the write speed is 310 MB per second, which is what we can expect from an SSD.

Now let’s run the same command, but this time, we write the 1GB file into our ramfs mounted /ram-dir directory:

$ dd bs=1M count=1024 if=/dev/zero of=/ram-dir/test conv=fdatasync 1024+0 records in 1024+0 records out 1073741824 bytes (1.1 GB, 1.0 GiB) copied, 0.244371 s, 4.4 GB/s

From the result, we can observe that the writing speed of the ramfs mount is a staggering 4.4GB per second, ten times the write speed of SSD!

4. Mounting tmpfs to Directory Using mount Command

To create a tmpfs mount, we use the command mount tmpfs followed by the option -t tmpfs. For instance, we can mount the tmpfs onto the /ram-dir directory as such:

$ sudo mount tmpfs -t tmpfs /ram-dir

Contrary to the ramfs, tmpfs offers several configurations we can tweak to impose size limits and set permission bits on the mount. Let’s see how we can configure the mount using the -o flag in the subsequent sections.

4.1. Limiting tmpfs Size

The tmpfs mount takes the -o size option to limit the size of the mount. For instance, we can limit our tmpfs to 100 Kb by specifying the option as -o size=100k:

$ sudo mount tmpfs -t tmpfs -o size=100k /ram-dir

The size parameters accept the suffixes k, m, and G, which stand for kilobytes, megabytes, and gigabytes, respectively.

To see the limit in action, we can try to move a file that’s larger than 100kb into the /ram-dir using the mv command:

$ ls -lh total 704K -rw-r--r-- 1 bob bob 703K Jan 21 07:07 700kbfile.txt $ mv 700kbfile.txt /ram-dir/700kbfile.txt mv: error writing 'ram-dir/700kbfile.txt': No space left on device

As expected, the mv command fails with “no space left on device” because the file we are trying to move has exceeded the size we’ve allocated for the mount.

4.2. Setting the UID and GID of Mount

The tmpfs mount also supports setting the permission bits on the mount through the -o uid and -o gid parameters. For instance, we can mount the ramfs onto the ram-disk directory and set its uid and gid to bob:

$ sudo mount tmpfs -t tmpfs -o uid=bob -o gid=bob /ram-disk ls -hl total 0 drwxrwxrwt 2 bob bob 40 Jan 21 08:00 ram-disk

Without the options, the default uid and gid will be set to the root user instead.

5. Conclusion

In this tutorial, we’ve briefly introduced the RAM filesystem in Linux. Particularly, we’ve highlighted the non-persistence nature of the RAM filesystem as well as the I/O speed boost it offers. Then, we’ve looked at the comparison between the ramfs and the tmpfs RAM filesystem.

Читайте также:  Автозапуск приложений linux ubuntu

Furthermore, we saw how we could mount the ramfs onto the directory using the mount command in Linux. Finally, we’ve repeated the same demonstration with the tmpfs.

Источник

Slax author’s Blog (RSS)

I’ve implemented copy2ram feature into Linux Live kit, making it effectively available in Slax as well. What it does?

When Slax starts, during the LiveKit phase, it searches for its filesystem data on all available devices, such as CD/DVD drives, hard drives and USB devices. As soon as Slax data is found, it stops searching and runs Slax from the device.

Due to that, user can’t ‘unplug’ the device from which Slax runs, it also makes the CD/DVD locked if Slax runs from it. But there may be situations when this is unwanted.

If you need to unplug your USB key drive or eject Slax CD as soon as possible, you may benefit from the «Copy to RAM» feature. Simply check «Copy to RAM» option in the boot menu, and boot Slax. The boot time will be a bit longer, since it will copy the entire ‘/slax’ directory from CD or USB to your computer’s memory, but then it will start Slax from there, freeing your boot device. You need, of course, lots of RAM to hold all Slax data while still having enough free RAM for the operating system.

I’ll push out new Slax-core version soon with the mentioned copy2ram feature, for you to test.

User comments

Yea! I absolutely use copy2ram all the time, since the 5.x days at least. Why? Well, I have lots of ram and I always use «always fresh». I mean, if I didn’t want to do that, I could use Ubuntu, right? I want a live OS that I don’t have to virus manage, and that I can reboot to the same state after I initially set it up. And I don’t want a USB drive sticking out of it. Anyway, I’m glad that development is proceeding again. 🙂 (BTW, just back from watching our local football team lose so take this message with a grain of salt.)

I totally agree with Pat. Booting SLAX on RAM is the best way to kill, at shutdown, any possible virus that was able to penetrate from external connections such as the Internet browsing 🙁 and so on. Moreover, with nowdays desktops with 4, 8 or 16 GB RAM, SLAX in RAM is VERY FASTTTTTTTTT. Many thanks for keeping this great feature in the new release. Could you please integrate also an internal Firewall as the one you developed in the Salx 6.2 version?

If I remember correctly the firewall just was there but wasn’t used automatically, you had to start it by hand. You can use the very same script, I will add it to Slax 7 too if you like, it doesn’t have any negative impact on size 🙂

Many thanks for 7 version! Yesterday I first tried it and now I’m using its Konqueror for your blog.
My advice refers to the start up menu:
1) I’d like to increase default start time from 3 to 5 sec; and
2) Unmark (*)persistent changes (since I have to unzip Slax.tar file for the second time, as changes were promt to write down on my USB before I managed to uncheck it).

Alexandre Magno 2017-12-07 00:39

How to turn on «Copy to RAM» by default? Is it possible through a module or via savechanges?

Ich liebe das Slax Image ! Alles machbar damit ! Danke ! Wenn ich Copy To RAM mache kann ich dann trotzdem die Daten alle auf HDD speichern ! Mfg

Источник

Оцените статью
Adblock
detector