This repository was archived by the owner on Sep 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathkali-chroot.sh
More file actions
executable file
·62 lines (48 loc) · 1.5 KB
/
kali-chroot.sh
File metadata and controls
executable file
·62 lines (48 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/bin/bash
# Remember to use: https://www.shellcheck.net
set -euo pipefail
IFS=$'\n\t'
# Uncomment for Debugging
#set -x
# Kali Linux chroot script by Doomguy [github.com/doomguy]
# make sure only root can run our script
if [ "$(id -u)" != "0" ]; then
echo -e "This script must be run as root!\nTry \"sudo $0 {start|stop}\"" 1>&2
exit 1
fi
# usage
if [ $# -eq 0 ]; then
echo "Usage: $0 {start|stop}"
exit;
fi
# check for vmware-mount
if [ ! -x /bin/vmware-mount ]; then
echo "vmware-mount not found. Install e.g. VMware Player! Exiting.."
exit 1
fi
# variables
kali_vmdk="/home/doomguy/VMs/Kali-Linux-2.0.0-vm-amd64/Kali-Linux-2.0.0-vm-amd64.vmdk"
mnt_path="/mnt/kali"
if [ ! -x $mnt_path ]; then
echo "$mnt_path does not exist. Creating now.."
mkdir -p $mnt_path || (echo "Error creating mnt_path! Exiting.." && exit 1)
fi
# mount stuff
if [ "$1" = "start" ]; then
echo "Starting Kali chroot.."
[ -z "$(mount | grep $mnt_path | grep ^/dev/loop)" ] && /bin/vmware-mount $kali_vmdk 1 $mnt_path
[ -z "$(mount | grep $mnt_path/proc)" ] && /bin/mount -t proc proc $mnt_path/proc/
[ -z "$(mount | grep $mnt_path/sys)" ] && /bin/mount -t sysfs sys $mnt_path/sys/
[ -z "$(mount | grep $mnt_path/dev)" ] && /bin/mount -o bind /dev $mnt_path/dev/
# change to new root
chroot $mnt_path
fi
# umount stuff
if [ "$1" = "stop" ]; then
echo "Stopping Kali chroot.."
/bin/umount $mnt_path/proc/
/bin/umount $mnt_path/sys/
/bin/umount $mnt_path/dev/
/bin/vmware-mount -x
echo "all done!"
fi