You are not logged in.

#1 2023-10-13 11:48:52

bedtime
Member
Registered: 2019-02-12
Posts: 70

Mounted successfully but cannot find sbin/init... [Solved]

*** edit ***

Got it working. Solution below!

...

I'm trying to get my btrfs system to copy and boot completely into ram (at which point the disk could be removed). The script below was found in a necro post and updated a little by myself. The issue is that I believe this script was intended to be used with ext4 and not btrfs.

Upon booting, the script successfully copies all the contents of the btrfs filesystem into ram (i.e., /new_root/) but then displays the error that it mounted successfully but cannot find sbin/init (or something to that effect).

My guess is that it's something to do with btrfs being located at '\@' and not just '\', like a regular ext4 system, but I'm not sure how to incorporate that.

As to why I'm doing this, I think it would be a great recovery/install disk for testing things out. Would even make for a decent emergency option for a messed up disk when using the working pre-compressed image.


/usr/lib/initcpio/install/liveroot:

#!/bin/ash

build() {
  add_runscript
}

help() {
  cat <<HELPEOF
Run Arch from RAM
HELPEOF
}

/usr/lib/initcpio/hooks/liveroot:

#!/usr/bin/ash

run_hook() {

   echo "Press any key now to load filesystem into RAM..."

   if read -t 5 -n 1 k ; then

      poll_device ${root} 10
      echo "Root device is: ${root}"
      mkdir /real_root/
      mount ${root} /real_root/
      mount -t tmpfs -o size=70% none /new_root/

      if [[ -f /real_root/@rootfs.tar.gz ]] ; then

         echo "Copying root filesystem ARCHIVE to RAM..."
         bsdtar -pxf /real_root/@rootfs.tar.gz -C /new_root/  > /new_root/LIVE 2>&1

      else

         echo "Copying root filesystem to RAM. Please be patient..."
         cp -p -a -R /real_root/* /new_root/

      fi

      touch /new_root/LIVE
      umount -R -l /real_root/

      LIVE_mount() {

         # since init doesn't have to mount anything anymore give it something to do instead
         echo "Live system."

         # bash is ultimately not found, and at this point we're dumped in a semi-functional shell
         /bin/bash

      }

      mount_handler=LIVE_mount

   fi # read -t 3 -n 1 k
}

# To make the compressed image:
# bsdtar --exclude={/rootfs.tar.gz,/var/cache/pacman/pkg/*,/boot/*,/dev/*,/proc/*,/sys/*,/tmp/*,/run/*,/mnt/*,/media/*,/lost+found,/usr/share/man/*,/usr/share/doc/*,/usr/share/gtk-doc/*,/.snapshots/*,/var/tmp/*,/var/log/*,/etc/pacman.d/gnupg/*} -zcf /rootfs.tar.gz /

...

Working solution:

#!/usr/bin/ash
run_hook() {
...

if [[ -f /real_root/@/rootfs.tar.gz ]] ; then

         echo "Copying root filesystem ARCHIVE to RAM..."
         tar -xzf /real_root/@/rootfs.tar.gz -C /new_root/
         echo "Done copying file."

      else

         echo "Copying root filesystem to RAM. Please be patient..."
         cp -p -a -R /real_root/@/* /new_root/
         echo "Done copying file."

fi

...}

I switched 'bsdtar' for 'tar' as bsdtar isn't accessible at this time in the boot. All working now.

Last edited by bedtime (2023-10-13 16:41:07)

Offline

Board footer

Powered by FluxBB