Skip to content

Instantly share code, notes, and snippets.

@Mehran
Last active May 13, 2018 04:55
Show Gist options
  • Save Mehran/3b4b524acefec72090afeb5c1590d8e1 to your computer and use it in GitHub Desktop.
Save Mehran/3b4b524acefec72090afeb5c1590d8e1 to your computer and use it in GitHub Desktop.
Automation script to resize Diskspace for Kali Linux 2018.2 in RaspberryPi 3
#!/bin/sh
# Automation resize remaining diskspace for Kali Linux 2018.2 on Rapsberry Pi3
# Get the starting offset of the root partition
PART_START=$(parted /dev/mmcblk0 -ms unit s p | grep "^2" | cut -f 2 -d:)
[ "$PART_START" ] || return 1
# Return value will likely be error for fdisk as it fails to reload the
# partition table because the root fs is mounted
fdisk -uc /dev/mmcblk0 <<EOF
p
d
2
d
3
n
p
2
$PART_START
w
EOF
# Resizing filesystem
resize2fs -p /dev/mmcblk0p2
df -h
sleep 3
echo "Root partition has been resized. The filesystem will be enlarged upon the next reboot"
# Create swap partition
cd /var
dd if=/dev/zero of=swapfile bs=1M count=128
mkswap /var/swapfile && swapon /var/swapfile
echo "Swap file created ."
# Prepare fstab
rm /etc/fstab
curl -OL https://gist.githubusercontent.com/Mehran/60aa168be299bb9a5262a7e248d94d46/raw/7ad9240c7731f54586cb99ee3b004b9b1fd02a12/fstab -o /etc/
echo "fstab replaced ."
echo "Please reboot to complete ..."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment