Skip to content

Instantly share code, notes, and snippets.

@Wyvernslay3r
Forked from maravedi/ResizeKaliDisk.txt
Created February 21, 2024 13:35
Show Gist options
  • Select an option

  • Save Wyvernslay3r/ea1f7c8805032e24588386dbf7e4c391 to your computer and use it in GitHub Desktop.

Select an option

Save Wyvernslay3r/ea1f7c8805032e24588386dbf7e4c391 to your computer and use it in GitHub Desktop.
Resize Kali Disk
I needed to increase my Kali VM's drive space from 7GB to 30GB because I ran out of space. I use VirtualBox, so here's how I increased the size of the virtual disk.
The virtual disk was in the vmdk format, so I had to clone that and change it to vdi so that I could expand it. Here's how I did that:
VBoxManage.exe clonehd "C:\Users\maravedi\VirtualBox VMs\Kali\Kali-disk1.vmdk" "C:\Users\maravedi\VirtualBox VMs\Kali-disk1.vdi"
VBoxManage.exe modifyhd "C:\Users\maravedi\VirtualBox VMs\Kali\Kali-disk1.vdi" --resize 30720
Next, I had to expand the root partition within the OS. I found two resposnes on AskUbuntu that, when combined, helped me solve this problem:
https://askubuntu.com/a/116367
https://askubuntu.com/a/109224
1. Run swapoff /dev/sda5
2. Run sudo fdisk /dev/sda
3. Use p to list the partitions. Make note of the start cylinder of /dev/sda1
4. Use d to delete first the swap partition (2) and then the /dev/sda1 partition. This is very scary but is actually harmless as the data is not written to the disk until you write the changes to the disk.
5. Use n to create a new primary partition. Make sure its start cylinder is exactly the same as the old /dev/sda1 used to have. For the end cylinder agree with the default choice, which is to make the partition to span the whole disk.
6. Use a to toggle the bootable flag on the new /dev/sda1
7. Review your changes, make a deep breath and use w to write the new partition table to disk. You'll get a message telling that the kernel couldn't re-read the partition table because the device is busy, but that's ok.
Reboot with sudo reboot. When the system boots, you'll have a smaller filesystem living inside a larger partition.
8. Run sudo resize2fs /dev/sda1 - this will default to making the filesystem to take all available space on the partition.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment