Skip to content

Instantly share code, notes, and snippets.

@nicolalamacchia
Created October 18, 2020 10:27
Show Gist options
  • Save nicolalamacchia/04e09acaca3a58c5f5960c546e972278 to your computer and use it in GitHub Desktop.
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.
#!/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