📜 ⬆️ ⬇️

Linux in RAM: debirf way 2018

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.


From the moderator: we received an article in English in the Sandbox. We read it and decided to publish it as a Friday experiment. Do not judge strictly, all peace and happy Friday! Let's come together! In short, from the bottom of the office of aua hearth.

Changelog:



You must know before running this tutorial:



you can replace:



Steps to preparing


They are (optional) enable non-free components for basic installation. In addition, I think you will need a non-free repository.



Up to start:


Let's imagine our flash drive:



Install debirf


 apt-get install -yq debirf mtools genisoimage 


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



Test it



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


asciicast


Install grub flash drive and copy 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:



 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 << EOF > 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



Customize it: Create custom debirf module


Module - executable sh script for running during LiR creating



Sample:


 cat <<< EOF > rescue/modules/mi #!/bin/sh -e # debirf module: mi # prepare to run on mi notebook # # This script were written by # Eduard Generalov <eduard@generalov.net> # # 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 << EOF > $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 << EOF > $DEBIRF_ROOT/etc/systemd/network/wireless.network [Match] Name=wlp1s0 [Network] DHCP=ipv4 [DHCP] RouteMetric=20 EOF 

and replace line with resolved rescue / modules / network with debirf_exec systemctl enable wpa_supplicant@wlp1s0.service systemd-networkd.service systemd-resolved.service


Bonus: lxc on LiR


module rescue / modules / lxc


 #!/bin/sh -e # debirf module: lxc # prepare lxc # # This script were written by # Eduard Generalov <eduard@generalov.net> # # 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 << EOF > $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 << EOF > $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 

')

Source: https://habr.com/ru/post/420501/


All Articles