Skip to content

Commit

Permalink
add helper functions ctam, ctau, ctai for interactive chrooting into …
Browse files Browse the repository at this point in the history
…/target

ctam (Chroot TArget Mount pseudo filesystems)
ctau (Chroot TArget Umount)
ctai (Chroot TArget Into)

these helpers (u)mount pseudo filesystems to /target
  • Loading branch information
Mrfai committed Oct 15, 2022
1 parent bad46b4 commit 3e593f7
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions lib/subroutines
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,57 @@ rwmount() {
mount -o rw,remount $1
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ctam() {

# mount pseudo filesystems into /target
if [ -z "$target" -o "$target" = "/" ]; then
echo "ERROR: \$target is not set (correctly)."
return
fi
if [ -f $target/proc/cpuinfo ] ; then
echo "Filesystems already mounted to $target."
return
fi

for f in /sys /proc /dev /dev/pts; do
mount --bind $f ${target}$f
done
if [ -d /sys/firmware/efi ]; then
mount --bind /sys/firmware/efi/efivars $target/sys/firmware/efi/efivars
fi
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ctau() {

# umount pseudo filesystems from /target
if [ -z "$target" -o "$target" = "/" ]; then
echo "ERROR: \$target is not set (correctly)."
return
fi
if [ ! -f $target/proc/cpuinfo ] ; then
echo "Filesystems already umounted from $target."
return
fi

for f in /dev/pts /dev /proc /sys/firmware/efi/efivars /sys; do
umount ${target}$f
done
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ctai() {

# chroot into target
if [ -z "$target" -o "$target" = "/" ]; then
echo "ERROR: \$target is not set (correctly)."
return
fi
if [ ! -f $target/bin/bash ]; then
echo "ERROR: Cannot chroot into $target."
return
fi
chroot $target bash
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
save_dmesg() {

[ $do_init_tasks -eq 0 ] && return
Expand Down

0 comments on commit 3e593f7

Please sign in to comment.