Here is an example of mounting the second partition of image data containing two partitions and checking the contents.
#!/bin/sh -e
#File name of the image file
FILENAME=$1
#Mount point
MOUNT_POINT=$2
#Associates the image specified by the argument with the loopback device. The loopback device name is the variable LOOPBACK_Assign to DEVICE.
LOOPBACK_DEVICE=$(sudo losetup -P --show -f ${FILENAME})
#Display the loopback device list
sudo losetup -l
#The liver when mounting image data containing multiple partitions
#When you mount image data containing multiple partitions on a loopback device
#Partition 1/dev/loopXXXp1
#Partition 2/dev/loopXXXp2
#A device with the suffix p number is created.
LOOPBACK_DEVICE_P2=${LOOPBACK_DEVICE}p2
#Display a list of loopback device names corresponding to each partition of the assigned image file.
sudo ls -l ${LOOPBACK_DEVICE}*
#Mount the assigned loopback device
sudo mount ${LOOPBACK_DEVICE_P2} ${MOUNT_POINT}
#Check the contents of the mounted file system
#Can be rewritten as needed
sudo ls -l ${MOUNT_POINT}
#Unmount.
sudo umount ${MOUNT_POINT}
#Release the loopback device.
sudo losetup -d ${LOOPBACK_DEVICE}
https://gist.github.com/m-tmatma/d6ef575fcf1a2c5aed5a10e439bc7f12
losetup -f Associates the image file specified by the command with the loopback device.
-P
.--show
.Run the following command to associate an image in the image file path with a loopback device and display its device name.
sudo losetup -P --show -f image file path
For example, if you associate it with / dev / loop10
, partition 1 of this image will be associated with / dev / loop10p1
and partition 2 will be associated with / dev / loop10p2
.
The first script refers to partition 2 with / dev / loop10p2
by doing $ {LOOPBACK_DEVICE} p2
.
Execute the following command to enumerate and display information on all loopback devices.
sudo losetup -l
sudo mount ${LOOPBACK_DEVICE_P2} ${MOUNT_POINT}
$ {MOUNT_POINT} specifies the mount point given as an argument. Here, it is / mnt / test
.
The above command is as follows.
sudo mount /dev/loop10p2 /mnt/test
This allows partition 2 of the image specified as the image file to be referenced in / mnt / test
.