Linux boot in memory

How do I have Linux boot with a rootfs in RAM?

The rootfs is a squashfs image and my bootloader is loading it into some address in SDRAM. What parameters do I need to pass to the kernel so It can mount the rootfs from there? Squashfs support is built-in and it already works with

root=/dev/mtdblock2 rootfstype=squashfs 

for booting from the flash. EDIT: This is a MIPS based embedded device, using a custom bootloader. Normally, the bootloader extracts the compressed kernel from the flash into the SDRAM, and then kernel mounts /dev/mtdblock2 as the rootfs. I am trying to improve the bootloader so it can download an image to its RAM and boot without writing to the flash. I cannot figure out how to make Linux mount a filesystem image in the RAM as the rootfs.

Please describe better, what are you trying to achieve, if you already know squashfs works. How do you you know that it works? What happens? And most importantly, what doesn’t work the way you want?

I think if you use memdisk (from SYSLINUX) as kernel, it loads the whole image in memory and then boots from it

3 Answers 3

Many Linux distributions use an initramfs (not to be confused with an initrd, they are different) during the boot process, mostly to be able to start userspace programs very early in the boot process. However, you can use it for whatever you want.

The benefit of an initramfs over an initrd is that an initramfs uses a tmpfs filesystem while an initrd uses a ram block device. The key difference here is that for an initrd, you must preallocate all the space for the filesystem, even if you’re not going to use all that space. So if you don’t use the filesystem space, you waste ram, which on an embedded device, is often a scarce resource. Tmpfs is a filesystem which runs out of ram, but only uses as much ram as is currently in use on the filesystem. So if you delete a file from a tmpfs, that ram is immediately freed up.

Читайте также:  Linux ssd trim all

Now normally an initramfs is temporary, only used to run some programs extremely early in the boot process. After those programs run, control is turned over to the real filesystem running on a physical disk. However, you do not have to do that. There is nothing stopping you from running out of the initramfs indefinitely.

Источник

karlbunch / boot-from-ram-debian.md

Step 2: Install to harddisk. Make sure you split it into multiple partitions (/, /boot, /home, swap, . ).

Step 3: Boot your new system, install updates, drivers if neccessary (this will improve performance), strip it down to the minimum. Every file will be loaded to RAM ! A fresh install uses about 2 GB auf harddisk-space.

cp /etc/fstab /etc/fstab.bak find the line specifing the root partition and change it in: none / tmpfs defaults 0 0* save

Step 5: edit the local script in your initramfs: cd /usr/share/initramfs-tools/scripts/* make a backup of /usr/share/initramfs-tools/scripts/local cp local local.bak* modify local, find this line:

# FIXME This has no error checking # Mount root mount $ -t $ $ $ $
# FIXME This has no error checking # Mount root #mount $ -t $ $ $ $ mkdir /ramboottmp mount $ -t $ $ $ /ramboottmp mount -t tmpfs -o size=100% none $ cd $ cp -rfa /ramboottmp/* $ umount /ramboottmp 
  • save
  • execute, or rebuild initramfs mkinitramfs -o /boot/initrd.img-ramboot* replace modified local with original file cp -f local.bak localStep 6:
  • modify this file (needs a better solution) /boot/grub/grub.cfg* copy the first boot entry and replace the /initrd line with this: /initrd /initrd.img-ramdisk* label the new entrie as RAMBOOT This will boot our generated initramfs instead the original one. Step 7:
  • reboot
  • choose standart boot (no ramdisk)
  • choose RAMBOOT and all your files on the root partition will be loaded to a tmpfs

Источник

How to get Ubuntu system to boot and run entirely in RAM?

I want to dual boot Ubuntu and have it run in RAM. I have used Puppy Linux from live USB stick which ran completely in RAM, but a lot of things didn’t work and so I decided to just go with a full system. With Puppy Linux, literally EVERYTHING was in RAM, but now that I want a full Ubuntu install, I only want the Ubuntu system (system files) and not all documents and files (like documents I create, save or download) in RAM. I’d like to get as much speed as possible from Ubuntu, and don’t need folders such as documents, downloads, etc. loaded into RAM. I am not technical enough to create a custom Ubuntu image as some have suggested. Is there a way to achieve this?

Читайте также:  Linux php ini reload

What problem are you trying to solve by having the system run entirely in RAM? Also, can you perhaps edit your question to clarify the distinction between «the Ubuntu system» and «all documents and files«? Thanks.

You want a full Ubuntu install but at the same time you want it to run from the RAM. This is technically not possible since RAM data is erased everytime you power off.. If you run a live Ubuntu disk, that is a different matter but there is actually no way to do this if you want to perform a full install. Also, as @Michael Kjörling said, it would be useful if you clarified what you mean by «All documents and files». The best thing you can do is run Ubuntu on an SSD, which is pretty fast.

I have no idea how to answer this question, but I’m struggling to believe that only the initial kernel can boot out of a ramdisk. While the ramdisk wold need to be stored on a drive somewhere, it seems like ti should be possible to boot a fully functional (albeit immutable) system that runs from a ramdisk.

Your request of «to boot and run in RAM» is not clear. The kernel (once loaded during boot) is always in RAM (except for loadable modules). Do you mean that the root filesystem should also be in RAM? The modern version of ramdisk is ramfs and tmpfs, which can be used for a RAM-resident rootfs aka initramfs. Distros publish such versions as LiveCDs.

2 Answers 2

You could run a Live Ubuntu, which can be made to boot from a USB stick or a hard disk partition, and use a persistent storage partition for your documents. Ubuntu comes with a «Startup Disk Creator» that makes this fairly easy.

Читайте также:  Операционной системой является tcp ip linux 1c

This will make the documents you safe to the persistent storage partition survive a reboot, but it will reset the whole rest of your system every time you reboot. So, you can’t install updates or new programs and have them survive a reboot.

This strikes me as extremely cumbersome.

However, if that’s the way you want to go, you can also customize such a live system, but you’ll have to know quite a lot about how Ubuntu works, how it boots, how initial ram drives work etc. Ubuntu has a help page about customizing it’s Live environment (see https://help.ubuntu.com/community/LiveCDCustomization). I did this a few years ago for a group of students and even though it worked nicely, I decided it was too much work to repeat the experiment.

It would be interesting to know why you need such a strange setup.

If you’re worried about the speed of running a linux system from a hard drive, don’t be. Nowadays you can even run Linux over a local network link and never notice your not working on your own machine. You can even run GUI applications over an internet connection (though there the lag is noticeable).

There are a few alternatives you might consider if you’re asking out of privacy needs:

A standard Ubuntu Installation comes with a «Guest User» functionality that keeps a guest’s home folder in memory, so whenever you log in as a guest user, once you reboot, all the changes he made are lost.

You can encrypt either your home directory or your whole system partition. In fact, you could set it up so your system boots from an USB drive you keep on your keychain and keeps its root file system encrypted on your hard drive.

Источник

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