Linux

無法掛載磁碟映像

  • September 24, 2021

我有一個磁碟映像文件,我正在嘗試使用循環設備在本地掛載。使用 parted 我可以看到圖像有兩個分區,但是,我無法掛載第一個分區並losetup認為第二個分區不存在。有人知道我如何掛載第二個分區嗎?

/m/sf_VMShare ❯❯❯ sudo losetup /dev/loop0 ./imm_image-2017-05-28.img
/m/sf_VMShare ❯❯❯ sudo losetup -a
/dev/loop0: [0023]:99 (/media/sf_VMShare/imm_image-2017-05-28.img)
/m/sf_VMShare ❯❯❯ sudo parted /dev/loop0 print
Model: Loopback device (loop)
Disk /dev/loop0: 1206MB
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number  Start   End     Size   Type     File system  Flags
1      10.5MB  360MB   349MB  primary  ext4
2      361MB   1205MB  844MB  primary  ext4

/m/sf_VMShare ❯❯❯ sudo mount -t ext4 /dev/loop0p2 /tmp/vdisk
mount: special device /dev/loop0p2 does not exist
/m/sf_VMShare ❯❯❯ sudo mount -t ext4 /dev/loop0p1 /tmp/vdisk 
mount: wrong fs type, bad option, bad superblock on /dev/loop0p1,
      missing codepage or helper program, or other error
      In some cases useful info is found in syslog - try
      dmesg | tail  or so

/m/sf_VMShare ❯❯❯ mount | grep /tmp/vdisk
/m/sf_VMShare ❯❯❯
/m/sf_VMShare ❯❯❯ ls /dev/loop*
/dev/loop0    /dev/loop1  /dev/loop3  /dev/loop5  /dev/loop7
/dev/loop0p1  /dev/loop2  /dev/loop4  /dev/loop6  /dev/loop-control
/m/sf_VMShare ❯❯❯ lsblk -f
NAME      FSTYPE LABEL MOUNTPOINT
sda                    
├─sda1                 /
├─sda2                 
└─sda5                 [SWAP]
sdb                    
└─sdb1                 /home/foo/workspace
sr0                    
loop0                  
└─loop0p1              

如何在包含 msdos 分區表的完整磁碟映像中掛載分區。

工具:

  • fdisk
  • mount
  • 計算器

獲取鏡像的分區佈局。

sudo fdisk -l -u=sectors /work/loop_test/disk_image.img

範例輸出:

Disk /work/loop_test/disk_image.img: 29 MB, 29629952 bytes
255 heads, 63 sectors/track, 3 cylinders, total 57871 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0009d7e5

                    Device Boot      Start         End      Blocks   Id  System
/work/loop_test/disk_image.img1       2048       18431        8192   83  Linux
/work/loop_test/disk_image.img2       18432      57343       19456    7  HPFS/NTFS/exFAT

計算從圖像開始到分區開始的偏移量。在這種情況下,ntfs 分區。

公式:

Sector size * Start = Offset
512 * 18432 = 9437184

掛載映像,傳遞所需分區的偏移量。

在本例中為 ntfs 分區。

sudo mount -o loop,offset=9437184 /work/loop_test/disk_image.img /mnt/ntfs_partition

引用自:https://unix.stackexchange.com/questions/372024