2

I've got a bootable usb drive with a live linux distro on it. We set it up to support persistence, so normally the changes make are kept between reboots. Booting into ram seems to make linux a lot faster than normal, which makes it a convenient way to use the live usb, especially since the live usb is a lot slower and sometimes hangs compared to a normal installation on a sata drive.

We can boot the live usb into ram by adding the boot parameters toram in the grub menu. However, obviously this breaks the persistence feature, as the filesystem is loaded onto ram, so all changes are lost upon reboot.

Once we made changes and decide we want to keep them, how can we flush the filesystem changes from the ram back to the usb drive?


For the record, I followed these instructions to make the live usb support persistence: https://docs.kali.org/downloading/kali-linux-live-usb-persistence

  • An alternative procedure in detailed here, which might give better results. – harrymc Nov 4 '17 at 16:22
  • That blog post does not deal with booting into ram, whereas my question is specifically about that. If the question is not clear enough, please tell me so I can improve the formulation! – Chiel ten Brinke Nov 4 '17 at 17:48
  • This is done afterward by adding toram as you did. Here is another article with one more method : Create a persistent Ubuntu USB which boots to RAM. – harrymc Nov 4 '17 at 18:05
  • @ChieltenBrinke I think you misunderstood what the toram option does. As far as I understand it, just the readonly filesystem is treated as ramdisk. When booting with persistence enabled, the changes you make are directly written to the usb drive, not to ram as you seem to think. – the blizz Nov 5 '17 at 11:48
  • @theblizz: I agree. In addition, USB is slower than an internal disk, so the poster is not going to get more performance, but rather less, than with a classic disk-based installation. The only advantage of a persistent boot USB is that it's a portable Linux installation that can be run on any computer, which is what I initially thought the poster was trying to achieve (but maybe I was wrong). – harrymc Nov 5 '17 at 12:50
1

Booting into RAM from USB only seems faster because only a minimal Linux version is charged into memory.

USB is slower than an internal disk, so one will not get more performance, but rather less, than with a classic disk-based installation. The only advantage of a persistent boot USB is that it's a portable Linux installation that can be run on any computer.

In addition, removable devices are physically flushed more, as the OS does not take any chance that such a device will be removed without being dismounted first. This means more writes and more often for USB than for an internal disk.

No tweaks are necessary to improve memory usage. Linux automatically maintains disk data in cache memory when read or written. Writes are delayed and done at the discretion of the OS and in optimal order. These optimizations are an extremely important part of any OS, many times judged by the efficiency of these algorithms.

Efficiency is chiefly improved by adding more RAM, which allows allocating a bigger memory cache for the disk.

OS algorithms for the memory cache and disk management are highly sophisticated, and tweaking them without a deep understanding of the effects is highly dangerous to the health of the disk and OS.

| improve this answer | |
  • "so one will not get more performance, but rather less, than with a classic disk-based installation" I never said you would get more performance with an USB installation, quoting myself "since the live usb is a lot slower and sometimes hangs compared to a normal installation on a sata drive" – Chiel ten Brinke Nov 8 '17 at 9:43
  • "No tweaks are necessary to improve memory usage." You sort of contradicted yourself with what you said earlier "removable devices are physically flushed more". In my experience, especially when the usb does not (properly) implement duplex I/O as the USB 3.0 standard prescribes, this flush of writes really slows the OS down, and the computer hangs every few seconds with applications that do frequent writes, like browsers. Preventing the OS to flush writes here would make a performance difference. – Chiel ten Brinke Nov 8 '17 at 9:48
  • 1
    Tweaking disk policies is an extremely risky way to go - you can find examples on this forum. If you are trying to get appreciably more speed out of a slow computer, you should invest in hardware. I know that this is not what you would like to hear, but unfortunately there are no magical solutions (or they would have been already incorporated in Linux). – harrymc Nov 8 '17 at 10:01
  • I agree upon it being risky – Chiel ten Brinke Nov 8 '17 at 10:39
1
+50

Here are my 50 cents.

When running a live linux distro from a CD-rom, the filesystem is readonly. This makes sense because you can't write to a CD-rom. To allow you to create files and make modifications, the live OS uses an additional overlay filesystem on a ramdisk to store your modifications. (There are several ways of implementing this, just google around on linux overlay filesystem to learn more). These changes are lost upon shutdown however, as they are not stored on the CD-rom, but on ram.

When booting a live distro from an USB drive however, you have the possibility to put this overlay filesystem on the USB drive instead of a ramdisk. This is what's usually called a live usb with persistent storage. The advantage of this is that the changes you make are persisted. The drawback is that the OS writes frequently to your usb drive, which may impact your performance on non-duplex usb drives (e.g. result in frequent freezes). Furthermore this deteriorates the durability of your usb drive, as usb drives aren't really designed to be written often.

To address these two latter issues, you might want to create a ramdisk and manually create an overlay filesystem in there. To persist your changes, save this filesystem in a file on your USB drive upon shutdown, and restore it upon startup.

Creating an overlay filesystem manually isn't hard. Read this as a start: https://wiki.archlinux.org/index.php/Overlay_filesystem

| improve this answer | |
  • Could you please share more details on how to store and restore this overlay filesystem from the USB drive? – Chiel ten Brinke Nov 10 '17 at 15:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.