Resizing a VirtualBox Disk

I needed to resize a virtual disk for a windows vm. I found that the vm needed to be stopped for the resize to work but also that Windows would not see the additional space until after it was restarted. Also, I discovered that you need to resize the snapshot disk too. So, to resize to 40GB:

$ cd ~/virtualbox/machine
$ VBoxManage modifyhd disk.vdi --resize 40960
$ for x in Snapshots/*.vdi ; do VBoxManage modifyhd $x --resize  40960 ; done

Then restart windows (I had colsed the vm, saving its state; I needed to resume it, shut down and reboot) and use *Control Panel -> Administrative Tools -> Computer Management -> Disk Management" to resize the disk.