debchroot.sh-e 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #!/usr/bin/env bash
  2. if [ -z $1 ] || [ $1 == '--help' ]; then
  3. echo 'chroot helper script for Debian'
  4. echo 'No mount directory specified. Mount partitions to /mnt and then run:'
  5. echo " $0 /mnt"
  6. exit 0
  7. fi
  8. if [ ! -x "$(command -v apt)" ]; then
  9. echo 'You are not running from Debian. This script was designed to be run from Debian.'
  10. echo 'This may not work as expected.'
  11. echo 'Do you want to continue? [y/N]'
  12. read ans
  13. if [[ ! "$ans" == [Yy] ]]; then
  14. exit 0
  15. fi
  16. fi
  17. CHROOT_DIR=$1
  18. if [ ! -d "$CHROOT_DIR" ]; then
  19. echo "The directory $CHROOT_DIR does not exist."
  20. echo 'Please create the directory, mount devices to it and try again.'
  21. exit 0
  22. fi
  23. if [ ! -d "$CHROOT_DIR/dev" ]; then
  24. echo "Debian is not probably installed yet on $CHROOT_DIR."
  25. echo 'Please install Debian and try again.'
  26. exit 0
  27. fi
  28. echo "Mounting and copying things to $CHROOT_DIR..."
  29. mount -o rbind /dev "$CHROOT_DIR/dev"
  30. mount -t proc proc "$CHROOT_DIR/proc"
  31. mount -t sysfs sys "$CHROOT_DIR/sys"
  32. mount -o rbind /run/lvm "$CHROOT_DIR/run/lvm"
  33. mount -o rbind /run/lock/lvm "$CHROOT_DIR/run/lock/lvm"
  34. cp /etc/resolv.conf "$CHROOT_DIR/etc/resolv.conf"
  35. cp /etc/mtab "$CHROOT_DIR/etc/mtab"
  36. echo "Running chroot on $CHROOT_DIR..."
  37. chroot "$CHROOT_DIR" /bin/bash