#!/bin/sh

rescue_shell() {
  echo "Something went wrong. Dropping you to a shell."
  busybox --install -s
  exec /bin/sh
}


/bin/mount -t proc proc /proc || rescue_shell
/bin/mount -t sysfs sysfs /sys || rescue_shell
/bin/mount -t devtmpfs devtmpfs /dev || rescue_shell

/sbin/vgscan --mknodes
/sbin/vgchange -ay

wait || rescue_shell

# Replace device with the resume (swap) partition
local device=$(ls -lL "/dev/mapper/vg_andromeda_sda4-swap" | sed 's/\  */ /g' | cut -d \  -f 5-6 | sed 's/,\ */:/')
[ -f /sys/power/resume ] && echo "${device}" > /sys/power/resume

/bin/mount -t ext4 -onoatime,discard /dev/mapper/vg_andromeda_sda4-root /newroot || rescue_shell

/bin/mount -t devtmpfs none /newroot/dev || rescue_shell
/bin/mount -t proc none /newroot/proc || rescue_shell
/bin/mount -t sysfs none /newroot/sys || rescue_shell

/bin/umount /proc
/bin/umount /sys
/bin/umount /dev

exec switch_root /newroot /sbin/init || rescue_shell

