losetup 2.21 -P opsi
losetup -P -f --show my.img
Membuat satu /dev/loopXpY
per partisi.
Keuntungan: executable pra-instal di banyak distro (paket util-linux).
Kerugian: opsi yang sangat baru, tidak ada di Ubuntu 14.04, sebelum itu hanya menggunakan kpartx: https://unix.stackexchange.com/a/405639/32558
losetup -P
otomatisasi
Pemakaian:
$ los my.img
/dev/loop0
/mnt/loop0p1
/mnt/loop0p2
$ ls /mnt/loop0p1
/whatever
/files
/youhave
/there
$ sudo losetup -l
NAME SIZELIMIT OFFSET AUTOCLEAR RO BACK-FILE DIO
/dev/loop1 0 0 0 0 /full/path/to/my.img
$ # Cleanup.
$ losd 0
$ ls /mnt/loop0p1
$ ls /dev | grep loop0
loop0
Sumber:
los() (
img="$1"
dev="$(sudo losetup --show -f -P "$img")"
echo "$dev"
for part in "$dev"?*; do
if [ "$part" = "${dev}p*" ]; then
part="${dev}"
fi
dst="/mnt/$(basename "$part")"
echo "$dst"
sudo mkdir -p "$dst"
sudo mount "$part" "$dst"
done
)
losd() (
dev="/dev/loop$1"
for part in "$dev"?*; do
if [ "$part" = "${dev}p*" ]; then
part="${dev}"
fi
dst="/mnt/$(basename "$part")"
sudo umount "$dst"
done
sudo losetup -d "$dev"
)