5

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

chtenb
  • 1,935
  • 2
  • 16
  • 17

2 Answers2

2

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

the blizz
  • 171
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.

harrymc
  • 498,455