{"id":288183,"date":"2018-08-17T19:30:17","date_gmt":"2018-08-17T15:30:17","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=288183"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=288183","title":{"rendered":"Linux in RAM: debirf way 2018"},"content":{"rendered":"\n<div data-io-article-url=\"https:\/\/habr.com\/post\/420501\/\" class=\"post__text post__text-html js-mediator-article\">\n<h1 id=\"linux-in-ram-debirf-way\">Linux in RAM: debirf way<\/h1>\n<p>  <\/p>\n<p>You want to have absolute disk speed? Let&#8217;s see how it can be done in 2018 with versioning and automation.<\/p>\n<p><a name=\"habracut\"><\/a>  <\/p>\n<h2 id=\"before-run-this-tutorial\">before run this tutorial<\/h2>\n<p>  <\/p>\n<h3 id=\"you-must-know\">you must know<\/h3>\n<p>  <\/p>\n<ul>\n<li>linux essential<\/li>\n<li>difference between <code>bash<\/code> and <code>sh<\/code> (debirf writen on <code>sh<\/code>)<\/li>\n<li>how to format usb key (any way)<\/li>\n<li>what drivers you need for your hardware (or you can debug it via <code>dmesg|lspci<\/code>)<\/li>\n<li>how to automate you desires via scripting<\/li>\n<\/ul>\n<p>  <\/p>\n<h3 id=\"you-can-replace\">you can replace:<\/h3>\n<p>  <\/p>\n<ul>\n<li>usb letter from <code>\/dev\/sdb<\/code> to any else (<code>\/dev\/sdd<\/code>)<\/li>\n<li>working directory from <code>\/root\/Projects\/debirf\/<\/code> to your choice (<code>\/home\/username\/Documents\/debirf<\/code>)<\/li>\n<li>mountpoint from <code>\/media\/root\/8B46-1189<\/code> to <code>\/media\/username\/myflashdrive<\/code><\/li>\n<\/ul>\n<p>  <\/p>\n<h2 id=\"steps-to-prepare\">Steps to prepare<\/h2>\n<p>  <\/p>\n<h3 id=\"optional-enable-non-free-components-for-basic-installation\">(optional) enable non-free components for basic installation<\/h3>\n<p>  <\/p>\n<p>I think, you will need the non-free repository.<\/p>\n<p>  <\/p>\n<ul>\n<li>open line number 107 of file <code>\/usr\/bin\/debirf<\/code> like <code>nano +107 $(which debirf)<\/code><\/li>\n<li>find function <code>create_debootstrap<\/code><\/li>\n<li>find line like <code>local OPTS=&quot;<\/code><\/li>\n<li>add <code>--components main,contrib,non-free<\/code> in brackets<\/li>\n<\/ul>\n<p>  <\/p>\n<h3 id=\"for-start\">for start:<\/h3>\n<p>  <\/p>\n<p>Let&#8217;s think, our flash drive:<\/p>\n<p>  <\/p>\n<ul>\n<li>must be fast. recommend to use 8+ class, or booting will take many of your time<\/li>\n<li>\/dev\/sdb<\/li>\n<li>formated<\/li>\n<li>mounted at <code>\/media\/root\/8B46-1189<\/code>.<\/li>\n<li>our working directory <code>\/root\/Projects\/debirf\/<\/code><\/li>\n<\/ul>\n<p>  <\/p>\n<h3 id=\"install-debirf\">Install debirf<\/h3>\n<p>  <\/p>\n<pre><code class=\"bash\">apt-get install -yq debirf mtools genisoimage<\/code><\/pre>\n<p>  <\/p>\n<ul>\n<li>mtools needed for create iso via debirf (not working, but needed)<\/li>\n<li>genisoimage needed for create real working iso (optional)<\/li>\n<\/ul>\n<p>  <\/p>\n<h3 id=\"prepare-debirf-working-directory\">Prepare debirf working directory<\/h3>\n<p>  <\/p>\n<pre><code class=\"bash\">mkdir -p \/root\/Projects\/debirf tar xzf \/usr\/share\/doc\/debirf\/example-profiles\/rescue.tgz -C \/root\/Projects\/debirf cd \/root\/Projects\/debirf\/rescue<\/code><\/pre>\n<p>  <\/p>\n<h3 id=\"and-configure-rootprojectsdebirfrescuedebirfconf\">And configure \/root\/Projects\/debirf\/rescue\/debirf.conf<\/h3>\n<p>  <\/p>\n<pre><code class=\"bash\">DEBIRF_LABEL=&quot;debirf-rescue&quot; DEBIRF_SUITE=stretch DEBIRF_DISTRO=debian DEBIRF_MIRROR=http:\/\/ftp.ru.debian.org\/debian\/<\/code><\/pre>\n<p>  <\/p>\n<h2 id=\"create-lir\">Create LiR<\/h2>\n<p>  <\/p>\n<ul>\n<li>Run <code>debirf make .<\/code> and go away. It need many time, at minimal 15 minutes on top hardware.<\/li>\n<li>Run <code>debirf makeiso .<\/code> for create not working iso (needed for grub.cfg file)<\/li>\n<\/ul>\n<p>  <\/p>\n<h3 id=\"install-grub-to-flash-drive-and-copy-lir-on-it\">Install grub to flash drive and copy LiR on it<\/h3>\n<p>  <\/p>\n<p>I recommend you use bios legacy boot and package grub-pc. Not tested with UEFI, but must work. Next lines will be do:<\/p>\n<p>  <\/p>\n<ul>\n<li>create mount point (on GUI-powered systems enabled auto-mount, not needed)<\/li>\n<li>mount usb key to mount point (on GUI-powered systems enabled auto-mount, not needed)<\/li>\n<li>install grub<\/li>\n<li>copy grub file<\/li>\n<li>copy initramfs (system)<\/li>\n<li>copy vmlinuz (kernel)<\/li>\n<li>unmount usb key<\/li>\n<li>remove mount point<\/li>\n<\/ul>\n<p>  <\/p>\n<pre><code class=\"bash\">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<\/code><\/pre>\n<p>  <\/p>\n<h3 id=\"create-bootable-iso-optional\">Create bootable iso (optional)<\/h3>\n<p>  <\/p>\n<ul>\n<li>download isolinux.bin<\/li>\n<li>create isolinux config file<\/li>\n<li>create iso<\/li>\n<\/ul>\n<p>  <\/p>\n<pre><code class=\"bash\">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 &lt;&lt; EOF &gt; 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 &quot;Linux in RAM&quot; -o rescue\/rescue.iso rescue\/iso\/<\/code><\/pre>\n<p>  <\/p>\n<h2 id=\"check-result\">Check result<\/h2>\n<p>  <\/p>\n<ul>\n<li>Install QEMU hypervisor <code>apt-get install -yq qemu<\/code><\/li>\n<li>run <code>qemu-system-x86_64 -enable-kvm -m 512 -hda \/dev\/sdb<\/code><\/li>\n<li>if previous command fails, remove <code>-enable-kvm<\/code><\/li>\n<li>VM will be started, booted from usb key<\/li>\n<li>you must see two menu items, difference in end: console and serial. Select first entry.<\/li>\n<li>in ~minute you will see many lines. after it ends \u2014 press enter to see welcome message<\/li>\n<li>login: root, no password<\/li>\n<\/ul>\n<p>  <\/p>\n<h2 id=\"customize-it-create-custom-debirf-module\">Customize it: Create custom debirf module<\/h2>\n<p>  <\/p>\n<p>Module \u2014 executable sh script for running during LiR creating<\/p>\n<p>  <\/p>\n<ul>\n<li>create module file<\/li>\n<li>The order of file names is important. In file <code>network<\/code> the resolving file will be changed to the system-resolved, and you can not work with the network.<\/li>\n<li>lines from 1 to 3 must be present, line 3 must present file name<\/li>\n<li>if you want install package \u2014 use construction <code>#DEBIRF_PACKAGE&gt;+<\/code><\/li>\n<li>if you want work with rootfs \u2014 use <code>$DEBIRF_ROOT<\/code><\/li>\n<li>if you want to run command in fakeroot \u2014 use <code>debirf_exec<\/code><\/li>\n<\/ul>\n<p>  <\/p>\n<h3 id=\"sample\">Sample:<\/h3>\n<p>  <\/p>\n<pre><code class=\"bash\">cat &lt;&lt;&lt; EOF &gt; rescue\/modules\/mi #!\/bin\/sh -e  # debirf module: mi # prepare to run on mi notebook # # This script were written by # Eduard Generalov &lt;eduard@generalov.net&gt; # # They are Copyright 2018, and published under the MIT,  #DEBIRF_PACKAGE&gt;+firmware-iwlwifi #DEBIRF_PACKAGE&gt;+firmware-misc-nonfree #DEBIRF_PACKAGE&gt;+wpasupplicant  echo 'iwlwifi' &gt;&gt; $DEBIRF_ROOT\/etc\/modules  cat &lt;&lt; EOF &gt; $DEBIRF_ROOT\/etc\/wpa_supplicant\/wpa_supplicant-wlp1s0.conf ctrl_interface=\/run\/wpa_supplicant update_config=1 network={         ssid=&quot;WiFi_SSID&quot;         psk=&quot;WIFIPASSWORD&quot; } EOF  cat &lt;&lt; EOF &gt; $DEBIRF_ROOT\/etc\/systemd\/network\/wireless.network [Match] Name=wlp1s0 [Network] DHCP=ipv4 [DHCP] RouteMetric=20 EOF <\/code><\/pre>\n<p>  <\/p>\n<p>and replace line with <code>resolved<\/code> in file rescue\/modules\/network with <code>debirf_exec systemctl enable wpa_supplicant@wlp1s0.service systemd-networkd.service systemd-resolved.service<\/code><\/p>\n<p>  <\/p>\n<h3 id=\"bonus-lxc-on-lir\">Bonus: lxc on LiR<\/h3>\n<p>  <\/p>\n<p>module rescue\/modules\/lxc<\/p>\n<p>  <\/p>\n<pre><code class=\"bash\">#!\/bin\/sh -e  # debirf module: lxc # prepare lxc # # This script were written by # Eduard Generalov &lt;eduard@generalov.net&gt; # # They are Copyright 2018, and published under the MIT,  #DEBIRF_PACKAGE&gt;+lxc  mkdir -p $DEBIRF_ROOT\/root\/.ssh\/ ssh-keygen -b 2048 -t rsa -f $DEBIRF_ROOT\/root\/.ssh\/id_rsa -q -N &quot;&quot; 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 &lt;&lt; EOF &gt; $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 &lt;&lt; EOF &gt; $DEBIRF_ROOT\/etc\/default\/lxc-net  USE_LXC_BRIDGE=&quot;true&quot; LXC_BRIDGE=&quot;lxc&quot; LXC_ADDR=&quot;10.0.3.1&quot; LXC_NETMASK=&quot;255.255.255.0&quot; LXC_NETWORK=&quot;10.0.3.0\/24&quot; LXC_DHCP_RANGE=&quot;10.0.3.2,10.0.3.254&quot; LXC_DHCP_MAX=&quot;253&quot; LXC_DHCP_CONFILE=&quot;&quot; LXC_DOMAIN=&quot;lxc&quot; EOF<\/code><\/pre>\n<p>  <\/p>\n<blockquote><p>\u041e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u0435 \u043c\u043e\u0434\u0435\u0440\u0430\u0442\u043e\u0440\u0430: \u043d\u0430\u043c \u0442\u0443\u0442 \u0432 \u041f\u0435\u0441\u043e\u0447\u043d\u0438\u0446\u0443 \u043f\u0440\u0438\u0448\u043b\u0430 \u0441\u0442\u0430\u0442\u044c\u044f \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u043d\u0430 \u0430\u043d\u0433\u043b\u0438\u0439\u0441\u043a\u043e\u043c \u044f\u0437\u044b\u043a\u0435. \u041c\u044b \u0435\u0451 \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u043b\u0438 \u0438 \u0440\u0435\u0448\u0438\u043b\u0438 \u0432\u044b\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0440\u0430\u0434\u0438 \u043e\u0447\u0435\u0440\u0435\u0434\u043d\u043e\u0433\u043e \u043f\u044f\u0442\u043d\u0438\u0447\u043d\u043e\u0433\u043e \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u0430. \u041d\u0435 \u0441\u0443\u0434\u0438\u0442\u0435 \u0441\u0442\u0440\u043e\u0433\u043e, \u0432\u0441\u0435\u043c peace and happy Friday! Let&#8217;s come together! \u041a\u043e\u0440\u043e\u0447\u0435, \u0444\u0440\u043e\u043c \u0437\u0435 \u0431\u043e\u0442\u0442\u043e\u043c \u043e\u0444 \u0430\u0443\u0430 \u0445\u0430\u0440\u0442\u0441.<\/p><\/blockquote>\n<\/div>\n<p>        <script class=\"js-mediator-script\">!function(e){function t(t,n){if(!(n in e)){for(var r,a=e.document,i=a.scripts,o=i.length;o--;)if(-1!==i[o].src.indexOf(t)){r=i[o];break}if(!r){r=a.createElement(\"script\"),r.type=\"text\/javascript\",r.async=!0,r.defer=!0,r.src=t,r.charset=\"UTF-8\";var d=function(){var e=a.getElementsByTagName(\"script\")[0];e.parentNode.insertBefore(r,e)};\"[object Opera]\"==e.opera?a.addEventListener?a.addEventListener(\"DOMContentLoaded\",d,!1):e.attachEvent(\"onload\",d):d()}}}t(\"\/\/mediator.mail.ru\/script\/2820404\/\",\"_mediator\")}(window);<\/script>     <br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/post\/420501\/\"> https:\/\/habr.com\/post\/420501\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div data-io-article-url=\"https:\/\/habr.com\/post\/420501\/\" class=\"post__text post__text-html js-mediator-article\">\n<h1 id=\"linux-in-ram-debirf-way\">Linux in RAM: debirf way<\/h1>\n<p>  <\/p>\n<p>You want to have absolute disk speed? Let&#8217;s see how it can be done in 2018 with versioning and automation.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-288183","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/288183","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=288183"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/288183\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=288183"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=288183"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=288183"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}