Coder Social home page Coder Social logo

ramroot's Introduction

ramroot

Run Linux entirely from RAM! This is a customizable mkinitcpio hook that completely loads the root file system to a zram partition during the initramfs boot stage.

Usage

During early system boot, the ramroot initcpio hook determines the host machine's total ram and prompts the user y/n to load the root file system to zram if enough space is available.

A ramroot helper script easily enables/disables and/or generates additional ramroot config files.

Installation

This package is available in the AUR for easy installation. A basic config file is created during initial installation.

Requirements

Arch Linux
ramroot is designed specifically to work with the Arch Linux boot process. These scripts work with slight modifications on other distributions from time to time, however this not officially supported
mkinitcpio
Create custom initial ramdisk image.

Configuration

/etc/ramroot.conf

This file is an ash shell script. Many common bash builtins are not available here and the syntax tends to be a bit stricter. The fallback config file can be viewed at /usr/lib/ramroot/ramroot.conf.

After any changes are made to /etc/ramroot.conf, a user must execute ramroot -E or mkinitcpio -P in order for those changes to be built into a new initramfs image.

All UUID (or PARTUUID) values must include the proper UUID= prefix. A mountpath is an absolute mount path (as given in /etc/fstab). Every size is a whole number of mebibytes with no-suffix.

mounts_zram
Additional mounts loaded to zram when ramroot is active. A mount consists of the UUID separated from the mountpath by a colon. Multiple mounts are separated by spaces or newlines.
mounts_null
Mounts excluded when ramroot is active. The UUID is optional for these mounts. These will not be loaded to zram or mounted normally. If / is specified in mounts_null, ramroot will skip loading altogether.
ps_default
Default zram boot y/n prompt value. Valid values are yes or no.
ps_timeout
zram boot prompt timeout, positive integer between 1 and 32. After this many seconds, the prompt will select the ps_default value.
ram_min
Minimum amount of free ram required.
zram_min
Minimum amount of free zram required. If both this and ram_min cannot be satisfied, the zram boot prompt will automatically select no.
ram_pref
Preferred amount of free ram. Additional memory is allocated to ram up to this preferred value.
zram_max
Maximum amount of free zram. If ram_pref is satisfied, free zram is increased to zram_max.

All remaining memory is allocated towards ram.

/etc/ramroot.z/

The structure of this directory mirrors the hierarchy of the root file system. Upon a successful sync to zram, any files and directories contained in /etc/ramroot/ are non-persistently overwritten to the root directory.

This can be used to load any number of custom scripts, binaries, configs, etc when boot from zram. A few use case examples for this include: a custom zram hostname at /etc/ramroot.z/etc/hostname, enable autologin when boot from zram via a /etc/ramroot.z/etc/systemd/system/[email protected]/override.conf file, or even add more sudo access with drop in files in /etc/ramroot.z/etc/sudoers.d/.

Any files copied from /etc/ramroot.z/ to / in this manner preserve all ownerships. Be wary that any symbolic links (rather than their target files) will be overwritten by this action as they aren't resolved yet during early initramfs.

~/.ramroot.z/

Any files contained within a ~/.ramroot.z directory in a user's home folder are non-persistently overwritten to their home folders upon a sync to zram as described in /etc/ramroot.z/ above.

Ramroot Script

ramroot <options>

Options

-C, --config-gen
Attempt to detect the root file system partitions and generate a new config file.
-D, --disable
Remove ramroot hook from /etc/mkinitcpio.conf and rebuild initramfs image.
-E, --enable
Add ramroot hook to /etc/mkinitcpio.conf and rebuild initramfs image.
-o, --output <FILE>
Save new config to FILE instead of /etc/mkinitcpio.conf.
-Y, --yes
Overwrite output files without asking.
-H, --help
Display help text and exit.

Notes

The file system transfer to zram takes several minutes. As soon as the boot process is complete, the boot media can be safely removed.

Remember that all changes to files in zram are completely lost when the host machine is power cycled. To persistently update the system and edit files, boot the device without transferring the filesystem to zram.

Keep a clean and trimmed down system to maintain faster zram sync times. Arch Linux stores downloaded packages in /var/cache/pacman/pkg/. Consider removing old packages after system updates.

Higher quality (more expensive) USB flash drives exhibit a dramatic improvement in zram sync times.

Credits

This project was motivated greatly in part by the liveroot package and by several inquisitive forum posts.

Author:Chris Magyar
Version:2.0.2
License:GPL 3.0
Donate(xmr):41dUPANhvCvLUuRVJpUc9cRFnsLHzWiTPUhyuamrVwa61xoP uxZaD6R28cLqxEhTaC6LuwcHtkbUi2uELDD88MoQHJKePvP

ramroot's People

Contributors

arcmags avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ramroot's Issues

Doesn't work with full disk encryption

Expected behavior:

On boot, the device encrypted with LUKS should prompt for the decryption key before asking me if I want to load the root filesystem into RAM.

What happens

Everything sort of messes up and then I'm tossed into emergency mode, since the root filesystem hasn't been decrypted yet

How to fix

I solved this by moving the ramroot hook after the encrypt hook in /etc/mkinitcpio.conf and rebuilding the initramfs. Maybe add some logic for detecting if encrypt is loaded, and insert ramroot after that.

MODULES(lzo) had to be added

Hello,

No idea if it's related to my setup only, but I had to add lzo to the MODULES() in /etc/mkinitcpio.conf yesterday and re-run mkinitcpio -P again to get it to work

Feel free to dismiss this if it's a false alarm, otherwise I suggest modprobe lzo along with zram in the hook, I spent quite a few hours to track this down, no idea why I didn't simply modify your hook too, perhaps I will later.

BR,
Tamás

[critical] ramroot --enable bricked my system :-(

Arch Linux, current.
Linux v5.4.68-1-lts, 26 Sep 2020 [latest version]

Before:

My /etc/mkinitcpio.conf

HOOKS="base udev autodetect keyboard keymap consolefont modconf block lvm2 filesystems fsck"

During

image

==> ramroot added to /etc/mkinitcpio.conf HOOKS
==> Building image from preset: /etc/mkinitcpio.d/linux-lts.preset: 'default'
  -> -k /boot/vmlinuz-linux-lts -c /etc/mkinitcpio.conf -g /boot/initramfs-linux-lts.img
==> ERROR: Invalid config: No hooks found

After

Several days go by. I had completely forgotten about this failure.

I rebooted Linux and, well, let's just say my initramfs was pretty screwed. I had no idea what was wrong, but I was able to run SystemRescueCD and restore my btrfs snapshots one after another until I got to one a week prior before I ran ramroot --enable.

Actually, this may have hosed my system during the yay -S ramroot.

I had NO idea what /etc/mkinitcpio.conf was prior to all this. It's still kinda fuzzy. I'm guessing it's how Arch keeps track of what custom modules to build for new kernels?

The Problem

Here's what ramroot did to my /etc/mkinitcpio.conf:

##   This setup loads an lvm2 volume group on a usb device.
#    HOOKS="base udev autodetect keyboard keymap consolefont modconf block lvm2 filesystems fsck"
#
##   NOTE: If you have /usr on a separate partition, you MUST include the
#    usr, fsck and shutdown hooks.
HOOKS=()

The Workaround

I edited it so that it became

HOOKS=(base udev autodetect keyboard keymap consolefont modconf block lvm2 filesystems)

However, I am totally not sure if this is going to screw over other Arch upgrades in the future :-/

ramroot not working on 5.10+

Why does it not work? Where exactly is the problem? Are you working on it or are you waiting for some other part to fall in place?
Can anybody help with that? Maybe I can help if you point me in the right direction and it is in my power to understand the problem.

Feature Request: --preset switch

You're assuming every system uses the default linux-kernel. I'm using the linux-lts kernel, so the mkinitcpio command fails since it cannot find the linux.preset. The easiest fix would likely be to add the --preset/-p switch to ramroot which is then passed through to the identical switch in mkinitcpio.

The most elegant solution would be to do the same that pacman does post-install and trigger mkinitcpio for all .preset-files in order to rebuild for all installed kernels.

Bug in output when generating config

Generating config results in output:

==> ramroot config written to %s\n

The line:

msg 'ramroot config written to %s\n' "$opt_output"

should be either:

printf 'ramroot config written to %s\n' "$opt_output"

or

msg "ramroot config written to $opt_output"

zramctl: failed to set disksize

Procedure:
ramroot -E
ramroot -C

On reboot i get asked to load root into ram, Needed: 6GB, available: 16GB
Output:
zramctl: /dev/zram0: failed to set disksize : Cannot allocate memory
=> Failed: error initializing zram device

OS Version: 5.9.14-arch1-1

Typo in README.rst

Hi ! I think you've made a typo in README.rst :

"This is was designed..."

"is" or "was" ?

Regards.

Ramroot on pi4 4GB

I have installed Ramroot on Raspberry pi4 with 4GB RAM
Installation went fine, I have enabled it without errors, but it will not go to ram mode.
I am receiving these type of errors:

Nov 21 00:29:47 raspberry kernel: zram: Added device: zram0
Nov 21 00:29:47 raspberry kernel: zram: Cannot initialise lzo compressing backend

Really zlo is installed.

Got it working on Manjaro with kernel 5.10

This took me quite a while to figure out and go to all the old issues and potential fixes but I got it.

  • First problem is that the version in AUG is not the latest and also messes up your mkinitcpio.conf.
    I think this happens when your formatting looks like HOOKS="" instead of HOOKS=().
    On my system I changed the "" to () and it worked, also added the LZ4 module:
    MODULES=(lz4)
    On my system it now looks like:
    HOOKS=(base udev autodetect modconf block keyboard keymap consolefont lvm2 ventoy encrypt ramroot filesystems fsck)
    This may look different depending on your configuration.
    Best way is to implement this is to install it from AUG and then manually update the files with the latests from Git and then edit them until these changes are implemented. Or simply use my attached files :).

  • Second problem I had is that ramroot does not detect the needed size for the drive in my case, probably due to it being encrypted by luks? So I changed zram_max=1000 to zram_max=12288 in ramroot.conf:
    zram_max=12288
    In my case that is enough and it should work woth at least 16GB of ram. However, at boot ramroot stills says only 1000MB is needed but it work nontheless

  • Lastly it seems the latest version does not use any compression so I changed it to lz4 in the usr/lib/initcpio/hooks/ramroot script based on the open pull request:
    line 170: zram_device="$(zramctl -f -s ${zram}M -a lz4)"

Now it is working flawless :) and a pretty amazing product so I hope it will be updated because this deserves more attention.

In my case I use a Ventoy USB drive to load a .vhd.vtoy file with an Manjaro installation. That is a real installation and not a livecd with persistance so I can treat it as a genuine portable OS. It has a VPN, a passwordmanager a privacy aware browser etc installed so I can carry it everywhere and simply put it in a pc and do my thing. For instance my work monitors pc activity and since I am not sure if they also log my keys when I want to check my email or do some banking stuff I simply boot from Ventoy.
But, because I also use it on a not so trusted pc or simply want to make sure I dont break my system or make any permanent changes to my .vhd installation my default is to run it from ram using ramroot.
So default I boot from ramroot and once in a while I do a regular boot and run all the updates/changes I want to. Best of both worlds in my case.

ramroot-master-working-linux510.zip

Y/N problem at boot

In the hot fix release did you fix the problem with Y/N at boot prompt?
Now is accepting only "yes" or "no" but not accepting "y" or "n"

Error in /etc/mkinitcpio.conf FIXED MANUALLY

First of all: I am writing this from a totally RAM loaded Arch, thanks to you 👍 I will provide some feedback elsewhere (positive), but here I will only describe the problem I encountered.

Setup

I have an up-to-date Arch and used git clone <AUR link> to clone ramroot package into ~/builds/
then I obviously ran makepkg and after the script finished I realized it did not put ramroot binary and the lib content in the right directories. I therefore copied cp ~/build/ramroot/usr/bin/* /usr/bin/ and did the same for the lib directory (was too lazy to copy the man pages).

Problem

I ran ramroot enable and encountered an error. While I don't have the error log, and don't feel like messing up again once it works, it essentially said "unexpected EOF" line 67 in /etc/mkinitpio.conf when creating the initramfs. So I checked the file and I found the error (hence, a log file is unneccessary): It turns out, your script added the hooks correctly but did not add the modules correctly. Instead of having: MODULES=(zram ext4) which works for me, your script wrote: MODULES=() zram ext4" (IMPORTANT: notice the qoute sign on the right). I'm not sure why this happened, but I edited it to be the correct version as above (inside the braces). I think there are two alternative syntax' avaible and your script messed them together or something.

Solution

After I edited /etc/mkinitcpio.conf file: MODULES=(zram ext4) I ran sudo mkinitcpio -c /etc/mkinitcpio.conf -g /boot/initramfs-linux.img
This has finally worked and not threw any errors. I have rebooted and everything was as it should be. I am not sure whether the problem is in your script or in my setup. However, I want to signal it, so if somebody else encounters it it will be fixed/or he can fix it himself.

P.S. I'd like to provide some feedback (not technical problem, but report of what I like in ramroot and how I use it), but not sure where to post it. Issue? Email? Pull Request?

How exclude some directories?

How can I exclude some directories from loading to ram? For example, in a multimedia installation, I would like to exclude something like /media/music or /media/video where I would store my files.

debian/ubuntu release

Great work putting this together. I wouldn't mind if this project would be expanded to include a debian/ubuntu -specific version.

System not loaded to RAM even if default is Y

It seems that in some updated archlinux systems recently, even if in the configuration file
ps_default=yes
at boot there is the message:

Load root file system to zram [Y/n]
zramctl: /dev/zram0: failed to reset: Device or resource busy
===> FAILED: error initializing the device

After few seconds the system will boot to normal mode.
Available RAM is not the case here.

Typing Y and ENTER will boot correctly to RAM but this is not automatic.

determining space requirement not working for longer block device names

I have LVM on LUKS so my root partition looks like /dev/mapper/lvmLALA which makes df -m /local_root/ produce 3 lines instead of 2. I'm unfamiliar with awk, you could probably improve this hotfix, I also appended "line" to the local variables:

line=$(df -m /local_root/ | awk 'NR>1 {print}')
zram=$((zram+$(echo $line | awk '{print int($3)}')))
umount /local_root 

Deleting files from zram does not free up space from the drive = RAM

Please add the "-o discard" tag to your mounting function.

I recently experimented with zram on my daily driver and noticed that deleting ~1.2GB data from /tmp (/dev/zram1) does not affect the "DATA" size reported by zramctl. Added the discard to /etc/fstab solved my problem.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.