Created
April 4, 2018 11:07
-
-
Save MircoT/1668164668e6156fbc698b370a32a667 to your computer and use it in GitHub Desktop.
Script to connect and mount a qcow2 image in a temporary directory. Plus, you can close the connection and check the status with fdisk or install the dependencies.
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/bash | |
| # $2: have to be a qcow2 image | |
| if [ $EUID != 0 ]; then | |
| echo "You need sudo to exec commands..." ; | |
| echo "- Remember also to install dependencies with install-deps command !" | |
| else | |
| case "$1" in | |
| "connect-status" ) | |
| fdisk /dev/nbd0 -l ;; | |
| "install-deps" ) | |
| apt install -y qemu-kvm ; modprobe nbd max_part=8 ;; | |
| "open" ) | |
| mkdir -p /mnt/tmp ; qemu-nbd --connect=/dev/nbd0 "$2" ; mount /dev/nbd0p1 /mnt/tmp ;; | |
| "close" ) | |
| umount /mnt/tmp ; qemu-nbd --disconnect /dev/nbd0 ;; | |
| esac | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment