Created
October 18, 2020 10:27
-
-
Save nicolalamacchia/04e09acaca3a58c5f5960c546e972278 to your computer and use it in GitHub Desktop.
Creates loop devices from a disk image file. Those loop devices have to be mounted manually.
This file contains 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 | |
# Usage: img2loop /path/to/disk.img | |
# Outputs created loop devices. | |
set -eu | |
if [[ $(id -u) -ne 0 ]]; then | |
echo "Error, run this program as root" >&2 | |
exit 1 | |
fi | |
image=$1 | |
loopdev=$(losetup -f --show "${image}") | |
parts=$(partprobe -s ${loopdev}) | |
readonly image loopdev parts | |
echo -e "${parts}\n" | |
ls -1 ${loopdev}* |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment