- Linux in RAM: debirf way
- Changelog:
- You must know before running this tutorial:
- you can replace:
- Steps to preparing
- Install debirf
- Prepare debirf working directory
- And configure /root/Projects/debirf/rescue/debirf.conf
- Create LiR
- Test it
- Test sample
- Install grub to flash drive and copy LiR on it
- Create bootable iso (optional)
- Check result
- Customize it: Create custom debirf module
- Sample:
- Bonus: lxc on LiR
- Is there a linux OS that can be loaded entirely into RAM?
- 9 Answers 9
Linux in RAM: debirf way
Do you want to have absolute disk speed nowadays, don’t you? Let’s revise how it could be done with versioning and automation in 2018.
От модератора: нам в Песочницу пришла статья на английском языке. Мы её прочитали и и в качестве пятничного эксперимента решили опубликовать. Не судите строго, всем peace and happy Friday! Let’s come together! Короче, фром зе боттом оф ауа хартс.
Changelog:
- The language of the article is corrected in English
- sample repository introduced at github
- Added test params
- added asciicast
You must know before running this tutorial:
- linux essential
- the main difference between bash and sh (debirf written on sh, so I recommend to follow the style)
- how to format usb key (in any way)
- what drivers are needed for your hardware (or you can debug it via dmesg|lspci)
- how to gain your task purposes via the scripting
you can replace:
- usb letter from /dev/sdb to any else ( /dev/sdd )
- working directory from /root/Projects/debirf/ to your choice ( /home/username/Documents/debirf )
- mountpoint from /media/root/8B46-1189 to /media/username/myflashdrive
Steps to preparing
They are (optional) enable non-free components for basic installation. In addition, I think, you will need the non-free repository.
- open line number 107 of file /usr/bin/debirf like nano +107 $(which debirf)
- find function create_debootstrap
- find line like local OPTS up-to-start»>Up to start:
- must to be fast, so it is recommended to use 8+ class, or booting will take enough time
- /dev/sdb
- formated
- mounted at /media/root/8B46-1189 .
- our working directory /root/Projects/debirf/
Install debirf
apt-get install -yq debirf mtools genisoimage
- mtools needed for create iso via debirf (not working, but needed)
- genisoimage needed for create real working iso (optional)
Prepare debirf working directory
mkdir -p /root/Projects/debirf tar xzf /usr/share/doc/debirf/example-profiles/rescue.tgz -C /root/Projects/debirf cd /root/Projects/debirf/rescue
And configure /root/Projects/debirf/rescue/debirf.conf
DEBIRF_LABEL="debirf-rescue" DEBIRF_SUITE=stretch DEBIRF_DISTRO=debian DEBIRF_MIRROR=http://ftp.ru.debian.org/debian/
Create LiR
- Run debirf make . and go away. It need many time, at minimal 15 minutes on top hardware.
- Run debirf makeiso . for create not working iso (needed for grub.cfg file)
Test it
- Install qemu
- for linux: apt-get install -yq qemu
- for macos: brew install qemu
- -smp 1 1 real kernel
- -m 1G 1G memory
- -nographic will launch VM in current terminal window
- —enable-kvm enables hardware accelation
- -kernel vmlinuz-* permit directly pass kernel
- -initrd *.cgz direct access to .cgz file with initramfs
- -append allows bypass kernel params, here are the parameters for running without a graphical shell
The command to start the virtual machine:
qemu-system-x86_64 --enable-kvm -kernel vmlinuz-* -initrd *.cgz -append "console=tty0 console=ttyS0,115200n8" -m 1G -smp 1 -net nic,vlan=0 -net user -nographic
Test sample
Install grub to flash drive and copy LiR on it
I recommend you use bios legacy boot and package grub-pc. Not tested with UEFI, but must work. Next lines will be do:
- create mount point (on GUI-powered systems enabled auto-mount it isn’t needed)
- mount usb key to mount point (on GUI-powered systems enabled auto-mount it isn’t needed)
- install grub
- copy grub file
- copy initramfs (system)
- copy vmlinuz (kernel)
- unmount usb key
- remove mount point
mkdir -p /media/root/8B46-1189 mount /dev/sdb1 /media/root/8B46-1189 grub-install --boot-directory=/media/root/8B46-1189/boot /dev/sdb cp /root/Projects/debirf/rescue/iso/boot/grub/grub.cfg /media/root/8B46-1189/boot/grub/ cp /root/Projects/debirf/rescue/*.cgz /media/root/8B46-1189 cp /root/Projects/debirf/rescue/vmlinuz-* /media/root/8B46-1189 umount /media/root/8B46-1189 rm -rf /media/root/8B46-1189
Create bootable iso (optional)
mkdir -p rescue/iso/isolinux/ wget -O rescue/iso/isolinux/isolinux.bin 'http://mirror.yandex.ru/centos/7/os/x86_64/isolinux/isolinux.bin' cat rescue/iso/isolinux/isolinux.cfg TIMEOUT 5 DEFAULT lir LABEL lir LINUX /vmlinuz-4.9.0-7-amd64 INITRD /debirf-rescue_stretch_4.9.0-7-amd64.cgz EOF genisoimage -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -l -input-charset default -V LiR -A "Linux in RAM" -o rescue/rescue.iso rescue/iso/
Check result
- Install QEMU hypervisor apt-get install -yq qemu
- run qemu-system-x86_64 -enable-kvm -m 512 -hda /dev/sdb
- if previous command fails, remove -enable-kvm
- VM will be started, booted from usb key
- you must see two menu items, difference in end: console and serial. Select first entry.
- in ~minute you will see many lines. after it ends — press enter to see welcome message
- login: root, no password
Customize it: Create custom debirf module
Module — executable sh script for running during LiR creating
- create module file
- the order of file’s names is important. In file network the resolving file will be changed to the system-resolved, and you can’t work with the network;
- lines from 1 to 3 must be present, line 3 must present file name
- if you want install package — use construction #DEBIRF_PACKAGE>+
- if you want work with rootfs — use $DEBIRF_ROOT
- if you want to run command in fakeroot — use debirf_exec
Sample:
cat rescue/modules/mi #!/bin/sh -e # debirf module: mi # prepare to run on mi notebook # # This script were written by # Eduard Generalov # # They are Copyright 2018, and published under the MIT, #DEBIRF_PACKAGE>+firmware-iwlwifi #DEBIRF_PACKAGE>+firmware-misc-nonfree #DEBIRF_PACKAGE>+wpasupplicant echo 'iwlwifi' >> $DEBIRF_ROOT/etc/modules cat $DEBIRF_ROOT/etc/wpa_supplicant/wpa_supplicant-wlp1s0.conf ctrl_interface=/run/wpa_supplicant update_config=1 network= < ssid="WiFi_SSID" psk="WIFIPASSWORD" >EOF cat $DEBIRF_ROOT/etc/systemd/network/wireless.network [Match] Name=wlp1s0 [Network] DHCP=ipv4 [DHCP] RouteMetric=20 EOF
and replace line with resolved in file rescue/modules/network with debirf_exec systemctl enable wpa_supplicant@wlp1s0.service systemd-networkd.service systemd-resolved.service
Bonus: lxc on LiR
#!/bin/sh -e # debirf module: lxc # prepare lxc # # This script were written by # Eduard Generalov # # They are Copyright 2018, and published under the MIT, #DEBIRF_PACKAGE>+lxc mkdir -p $DEBIRF_ROOT/root/.ssh/ ssh-keygen -b 2048 -t rsa -f $DEBIRF_ROOT/root/.ssh/id_rsa -q -N "" cp $DEBIRF_ROOT/root/.ssh/id_rsa $DEBIRF_ROOT/root/.ssh/authorized_keys chmod 400 $DEBIRF_ROOT/root/.ssh/authorized_keys debirf_exec systemctl enable lxc-net cat $DEBIRF_ROOT/etc/lxc/default.conf lxc.network.type = veth lxc.network.link = lxc lxc.network.name = eth0 lxc.network.flags = up lxc.network.hwaddr = 00:FF:AA:FF:xx:xx lxc.mount.entry=/var/cache/apt var/cache/apt none bind,rw 0 0 lxc.mount.entry = /root/.ssh/ root/.ssh none bind,create=dir 0 0 EOF cat $DEBIRF_ROOT/etc/default/lxc-net USE_LXC_BRIDGE="true" LXC_BRIDGE="lxc" LXC_ADDR="10.0.3.1" LXC_NETMASK="255.255.255.0" LXC_NETWORK="10.0.3.0/24" LXC_DHCP_RANGE="10.0.3.2,10.0.3.254" LXC_DHCP_MAX="253" LXC_DHCP_CONFILE="" LXC_DOMAIN="lxc" EOF
Is there a linux OS that can be loaded entirely into RAM?
I have 32 GB of memory in my PC. This is more than enough for a linux OS. Is there an easy to use version of Linux (Ubuntu preferably) that can be booted via optical or USB disk and be run completely within RAM? I know a live disc can be booted with a hard disk, but stuff still runs off the disc and this takes a while to load. I’d like everything loaded into RAM and then run from there, completely volatile. Any files I need to create would be saved to a USB disk. I’m aware of http://en.wikipedia.org/wiki/List_of_Linux_distributions_that_run_from_RAM but these all depend on a little bit of RAM. I’d prefer something like Ubuntu instead of these light versions.
The SysRescueCd has a load to memory option, docache causes the CD-ROM to be fully loaded into memory. A slower start but once complete, programs start faster and the CD drive will be released allowing normal access to other CDs. This requires 400MB of memory to cache everything (including the bootdisks and isolinux directories).
I don’t know if Ubuntu supports it but IIRC Linux Mint does support toram parameter e.g. at the boot menu edit the entry and append toram to the kernel command line.
Ha, I was looking for a flavor «IIRC Linux Mint». Just occurred to me that was shorthand. Mint is good, I like that. It’s been a while since i’ve used puppy. I’ll have a look there too.
Not an answer, just a comment: almost any distro can be modified to run directly from ram. Only a minor difference is needed in the boot sequence to mount tmpfs (or a compressed version) and load a disk image into it. I’ve seen an (almost) standard debian system that boots from a network image and runs from RAM, and using a LAN package repository (mirror) to quickly install larger applications on demand (to save space). I didn’t set it up personally so I can’t post precise instructions, but it is something that can be done for any distro.
9 Answers 9
I think all distros can be run from RAM, you only need to do some changes. Read this link
You need to have in mind that any changes (updates, and the like) that you do to the filesystem that is in memmory are lost when you turn of your machine, so you need to stablish a mechanism to update your HD with those changes BEFORE the system goes down, that will delay the shutting down of the system.
not that much RAM is needed. if i can install and run a FULL Slackware in QEMU in tmpfs in 12GB of RAM then that much should be enough to run it direct.
i used to run just /etc in /tmps ages ago without an auto-save. one day it saved me from stupid blunder
@YoMismo, That link you posted is gold! The great thing about it is that you can customize your system anyway you want and then run it from RAM without fear of having your disks being thrashed by anything without your consent. Perhaps it would be a good idea to copy the steps here, just to be safe.
Any distro is capable, since the fundamental principles of the linux file system is not specific to any distribution. Recognize what INITRAMFS stands for, emphasis on the RAM part. Not to mention diskless nodes in a cluster setup which is nothing new.
Ubuntu can run on RAM, but it requires some manual changes:
This helps, thank you. I was hoping for something more out of the box though. If this is my only recourse, I’ll give it a go and mark this as the answer.
this appears to assume one is booting a LIVE CD where running in RAM would be very useful. i have run Slackware in QEMU with all disks in RAM and it was much faster. a FULL install finished in 3 minutes. the hardware had just 12GB of RAM. my newest laptop has 64GB and i am exploring how to boot from its SSD and run from RAM.
It’s outdated because it’s not needed anymore. Just add toram to the kernel parameters and you are done. Take note that this is not a linux kernel parameter though, but it’s specific to the ubuntu/debian live initramfs (see casper and live-boot).
Parrot Security OS. You have the option to load the OS directly into RAM, I believe MXLinux also allows that, no config files, straight from the boot loader you select load OS into RAM.
The Parrot & MX boot menu actually have a ton of options for different ways to run the OS. There are two versions ‘home’ and ‘security’, either one is suitable for a daily driver, unlike similar distros like Kali. Its basically a Debian MATE desktop and in the menu one of the tabs says parrot OS, in that tab you will find all of your hacker/cracker utils. Otherwise its just Debian MATE, a very nice looking Desktop.
Also it simplifies networking and starting/stopping processes in the applications menu. I loaded it into 10gb of ddr3 ram on a computer from 2012 and it runs fast. Also DietPi makes an X86 version that is crazy fast and runs in RAM.
If you do not care about package managers tiny core also runs in RAM its just and ‘odd’ distro.