You are not logged in.

#1 2014-03-23 18:13:17

KairiTech
Member
From: Toronto, Canada
Registered: 2011-06-04
Posts: 275

[Solved] On the fly RAM root Arch for USB, RAID, LVM, ISO, whatever...

Synopsys: De-compress the initramfs, add a few lines of code to init to copy the root filesystem to RAM then unmount it, re-compress the initramfs with the updated init.
 
After lots of searching around here and elsewhere I've put together the script below to create an ISO image that loads the root filesystem into RAM and does not depend on a storage device. I'm using an Arch base install from a directory (instead of a device) as the starting point.

Obviously I'm patching things together so some of what I've done may depend to tools from other distros that I haven't added.

When I boot the ISO I get:

Kernel panic - not syncing : VFS : Unable to mount root fs on unknown-block(0,0)

So my question is can this even be done and what am I missing from the directory install and/or isolinux config?

I'd like this to be as generic a method as possible and necessarily specific to Arch.

echo "  ||  ISO files location"
mkdir --verbose                              /tmp/CD_root/

echo "  ||  copy kernel"
mkdir --verbose                              /tmp/CD_root/kernel/
cp --verbose /tmp/RAMArch/boot/vmlinuz-linux /tmp/CD_root/kernel/bzImage

echo "  ||  make root image"
mkdir --verbose                              /tmp/CD_root/images/
cd /tmp/RAMArch/
find . -print | cpio -o -H newc | gzip -9 >  /tmp/CD_root/images/rootfs.gz
cd ~

echo "  ||  configure isolinux"
mkdir --verbose                              /tmp/CD_root/isolinux/
cp --verbose -r /usr/lib/syslinux/bios/*     /tmp/CD_root/isolinux/
#_____________________
cat > /tmp/CD_root/isolinux/isolinux.cfg<<EOF-isolinux
DISPLAY boot.txt
PROMPT 1
TIMEOUT 50
DEFAULT RAMArch
 
LABEL RAMArch
    kernel /kernel/bzImage
    append initrd=/images/rootfs.gz rw root=/dev/null init=/usr/lib/systemd/systemd
        
LABEL RAMArch-fallback
    kernel /kernel/bzImage
    append initrd=/images/rootfs.gz rw root=/dev/null init=/usr/lib/systemd/systemd
EOF-isolinux
#_____________________
 
#_____________________
cat > /tmp/CD_root/isolinux/boot.txt<<EOF-boot

                          RAMArch 



EOF-boot
#_____________________

echo "  ||  make ISO image"
mkisofs -o /tmp/RAMArch.iso -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table /tmp/CD_root

Last edited by KairiTech (2014-03-28 19:02:47)

Offline

#2 2014-03-23 18:19:29

teateawhy
Member
From: GER
Registered: 2012-03-05
Posts: 1,138
Website

Offline

#3 2014-03-26 14:08:30

KairiTech
Member
From: Toronto, Canada
Registered: 2011-06-04
Posts: 275

Re: [Solved] On the fly RAM root Arch for USB, RAID, LVM, ISO, whatever...

I’ve been to those links before but reading through them again must have triggered the correct keywords in my brain for my DuckDuckGo search because I found this.

So I decompressed the initramfs:

mkdir /tmp/initramfs/

cd /tmp/initramfs/

gzip -d < /mnt/boot/initramfs-linux.img | cpio –i

Added this code to /tmp/initramfs/init after the detection of the successful mount of the storage-based root filesystem:

echo "  ||  "
echo "  ||  Press a key or I will load root filesystem to RAM..."
echo "  ||  "
if read -t 3 -n 1 k
   then
      echo -en "  ||  Okay! If you say so...No RAM root for you."
   else
      echo -en "  ||  " ; mkdir                                      /tmp/real_root/
      echo -en "  ||  " ; mount --move                     /new_root/ /tmp/real_root/
      echo -en "  ||  " ; mount -t tmpfs -o size=60% none  /new_root/
      if [[ -f /tmp/real_root/rootfs.tar.gz ]]
         then
            echo "  ||  Copying root archive to RAM..."         
            tar -xf /tmp/real_root/rootfs.tar.gz        -C /new_root/
         else        
            echo "  ||  Copying root filesystem to RAM..."
            acp -a -g -R  /tmp/real_root/*                 /new_root/
      fi # [[ -f rootfs.tar.gz ]]
      echo -en "  ||  " ; umount --verbose /tmp/real_root/
      touch                                                /new_root/RAMroot
      read -p "  ||  Done! Press [Enter] to continue..." RESP
fi # ! read -t 3 -n 1 k

Re-compressed the initramfs:

find . | cpio -o -H newc | gzip -9 > /mnt/boot/initramfs-linux.img

cd ~

…and it worked. And just to convince myself I un-plugged my SSD RAID array and it kept going.

Advantages:

This will work with any distro just remember that updates are only persistent when you boot into the real root but the good thing is they will follow through to the RAM root the next time you boot into it.

TO DO:

Takes forever to copy the root filesystem with a fully functional desktop to RAM but it works so:

Pare down my desktop to the bare essentials – already have a system in place to install and configure apps on demand from a local repo which would actually be faster than copying it during boot.

Find a replacement for cp like maybe a binary block copy.

Try compressing the roof filesystem and de-compress it to RAM instead or copying it from storage – but this will negate the auto update advantage mentioned above.

Decompressing the root filesystem archive decreases the load to RAM time by a factor of 50 or more. Especially noticeable from a USB. I just need to remember to recreate the archive after a system update but only when I booted to the real root. Small price to pay for a significantly faster load to RAM.

Compressed root like this:

time tar -vzcf /rootfs.tar.gz / --exclude={/rootfs.tar.gz,/boot,dev/\*,/proc/\*,/sys/\*,/tmp/\*,/run/\*,/mnt/\*,/media/\*,/lost+found}

Last edited by KairiTech (2014-04-09 01:51:19)

Offline

#4 2014-03-26 14:14:51

progandy
Member
Registered: 2012-05-17
Posts: 5,259

Re: [Solved] On the fly RAM root Arch for USB, RAID, LVM, ISO, whatever...

Why don't you put your root filesystem directly into your initramfs. and skip the copying during the boot phase?
Skip everything the ramfs-init does and put everything necessary into systemd service files, then link systemd to init.

Last edited by progandy (2014-03-26 14:16:10)


| alias CUTF='LANG=en_XX.UTF-8@POSIX ' |

Offline

#5 2014-03-26 14:52:56

KairiTech
Member
From: Toronto, Canada
Registered: 2011-06-04
Posts: 275

Re: [Solved] On the fly RAM root Arch for USB, RAID, LVM, ISO, whatever...

progandy wrote:

Why don't you put your root filesystem directly into your initramfs. and skip the copying during the boot phase?
Skip everything the ramfs-init does and put everything necessary into systemd service files, then link systemd to init.

I did consider that but I would have to rebuild the initramfs after every software update or addition to my bare-bones desktop.

If putting the root filesystem into the initramfs would speed up the load into RAM sufficiently I would certainly consider it though.

Offline

Board footer

Powered by FluxBB