Skip to content

Instantly share code, notes, and snippets.

@jlongman
Created May 11, 2015 19:37
Show Gist options
  • Save jlongman/ccfb88d5f87e907cfa96 to your computer and use it in GitHub Desktop.
Save jlongman/ccfb88d5f87e907cfa96 to your computer and use it in GitHub Desktop.
VirtualBox drive cleaner, removes inaccessible references from hard drive management and boxes
#!/bin/bash
################################################################################
# closes all inaccessible drives that are not snapshots, and which dont exist
################################################################################
vboxmanage=VBoxManage
while read rawuuid; do
uuid=`echo $rawuuid| grep -Eo ' [a-f0-9-]+' | grep -Eo '[a-f0-9-]+'`
read rawlocation
location=`echo $rawlocation | grep -o "/.*"`
echo "$uuid" " to " "$location"
if [ ! -e "$location" ]; then
$vboxmanage closemedium disk "$uuid"
else
echo -e $uuid file found!
ls -la "$location"
fi
done < <($vboxmanage list hdds | grep -C 2 --null inaccessible | grep -E '(UUID|Location)' | grep -v Parent)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment