Last active
July 3, 2019 18:45
-
-
Save JamesOBenson/6be2133467cb3586c6b1fa9bc2514e92 to your computer and use it in GitHub Desktop.
Download all VM disk images and run in VirtualBox VM.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/shell | |
# This will download all files in your ceph cluster under the 'vms' pool, | |
# Convert them from raw to qcow2, Create a virtualbox and mount that | |
# disk to the new VM for local access. | |
array=() | |
while IFS='' read -r line; do array+=("$line"); done < <(rbd ls -p vms | grep disk) | |
for ID in "${array[@]}"; do | |
rbd export vms/"$ID" ~/"$ID".raw | |
qemu-img convert -f raw -O qcow2 "$ID".raw "$ID".qcow2 | |
chmod +666 "$ID".qcow2 | |
echo "Creating new VM $ID" | |
VBoxManage createvm --name "$ID" --ostype "Ubuntu_64" --register | |
echo "Updating RAM to 1GB and Video Memory to 9MB and disconnected serial port" | |
# Serial port is necessary per https://bugs.launchpad.net/cloud-images/+bug/1573095/comments/37 | |
VBoxManage modifyvm "$ID" --memory 1024 --vram 9 --uart1 0x3f8 4 --uartmode1 disconnected | |
echo "Creating Storage controller" | |
VBoxManage storagectl "$ID" --name "SATA Controller" --add sata --controller IntelAhci | |
echo "Attaching HD to Storage" | |
VBoxManage storageattach "$ID" --storagectl "SATA Controller" --port 0 --device 0 --type hdd --medium "$ID".qcow2 | |
done | |
mount_locally(){ | |
VDI_IMAGE=$1 | |
MOUNTING_LOCATION=$2 | |
mkdir -p "$MOUNTING_LOCATION" | |
# sudo apt-get install qemu | |
sudo rmmod nbd | |
echo "Creating 16 Network Block Devices (NBD)" | |
sudo modprobe nbd max_part=16 | |
echo "Attaching VDI Image to NBD" | |
sudo qemu-nbd -c /dev/nbd0 "$VDI_IMAGE" | |
echo "Mounting..." | |
sudo mount /dev/nbd0p1 "$MOUNTING_LOCATION" | |
# sudo qemu-nbd -d /dev/nbd0 # TO disconnect. | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment