img 파일의 유형을 찾아 마운트하는 방법은 무엇입니까?


36

.img 파일을 마운트해야하지만 .img 유형이 무엇인지 모르겠습니다. 어떤 형식의 .img 파일인지 어떻게 알 수 있습니까?

# mount -t auto -o ro,loop gmapsupp.img /mnt/iso/
mount: you must specify the filesystem type
# file -k gmapsupp.img 
gmapsupp.img: x86 boot sector, code offset 0x0
#

답변:


34

명령을 실행 해보십시오 fdisk -l <img file>. 일반적으로 .img파일이 KVM VM의 전체 디스크 인 경우 기술적으로 가상 디스크입니다.

다음 file명령 으로 CentOS KVM VM이 표시됩니다 .

$ file centostest.img 
centostest.img: x86 boot sector; partition 1: ID=0x83, active, starthead 1, startsector 63, 208782 sectors; partition 2: ID=0x8e, starthead 0, startsector 208845, 20755980 sectors, code offset 0x48

fdisk그것으로 실행 :

$ sudo /sbin/fdisk -lu /kvm/centostest.img
last_lba(): I don't know how to handle files with mode 81ed
You must set cylinders.
You can do this from the extra functions menu.

Disk /kvm/centostest.img: 0 MB, 0 bytes
255 heads, 63 sectors/track, 0 cylinders, total 0 sectors
Units = sectors of 1 * 512 = 512 bytes

              Device Boot      Start         End      Blocks   Id  System
/kvm/centostest.img1   *          63      208844      104391   83  Linux
/kvm/centostest.img2          208845    20964824    10377990   8e  Linux LVM
Partition 2 has different physical/logical endings:
     phys=(1023, 254, 63) logical=(1304, 254, 63)

이 파티션 중 하나를 마운트하려면 다음과 같이하십시오.

fdisk (실린더 출력)
  • 블록 크기는 512 바이트이고 시작 블록은 63입니다.
  • 오프셋은 512 * 63 = 32256입니다.
fdisk (섹터 출력)
  • 512 바이트의 블록 크기이고 시작 블록은 1입니다.
  • 오프셋은 512 * 1 = 512입니다.

따라서 mount 명령은 다음과 같습니다.

실린더에서
$ mount -o loop,offset=32256 centostest.img /mnt/tmp

다른 파티션을 마운트하려면 (512 * 208845 = 106928640) :

$ mount -o loop,offset=106928640 centostest.img /mnt/tmp
부문에서
$ mount -o loop,offset=512 centostest.img /mnt/tmp

다른 파티션을 마운트하려면 (512 * 14 = 7168) :

$ mount -o loop,offset=7168 centostest.img /mnt/tmp

노트

mount가 마운트하려는 "파티션"내의 파일 시스템 유형을 결정할 수있는 경우에만 작동합니다. 예를 들어 를 포함 -t auto시키거나 구체적으로 말해야 mount할 수도 있습니다 -t ext4.

참고 문헌


# mount -t auto -o ro,loop,offset=512 gmapsupp.img /mnt/iso/\mount: you must specify the filesystem type
루이지

# fdisk -l gmapsupp.img Disk gmapsupp.img: 0 MB, 0 bytes 255 heads, 63 sectors/track, 0 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00000000 Device Boot Start End Blocks Id System gmapsupp.img1 1 9 65536 0 Empty Partition 1 has different physical/logical endings: phys=(1023, 15, 8) logical=(8, 40, 32) Partition 1 does not end on cylinder boundary.
Luigi

@Luigi-이 의견을 질문에 대한 업데이트로 게시 할 수 있습니까? 무슨 일인지 알 수 없습니다.
slm

@Luigi- -t auto파티션 유형을 식별 할 수 있다는 보장은 없습니다 . 당신은 다른 것을 시도해야 작동하는 것을 볼 수 있습니다.
slm

두 번째 파티션의 오프셋을 결정하는 방법은 무엇입니까? 왜 512x14입니까? 내 첫 번째 파티션이 첫 번째 파티션 W95 FAT16 (LBA) -t vfat을 마운트하지 못했습니다.
Necktwi

21

parted오프셋 값을 식별하는 데 사용 합니다.

root@mysystem:~/# parted myimage.img
GNU Parted 2.3
Using /root/myimage.img
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) u
Unit?  [compact]? B
(parted) print
Model:  (file)
Disk /root/myimage.img: 8589934592B
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number  Start        End          Size         Type     File system     Flags
 1      32256B       254983679B   254951424B   primary  ext3            boot
 2      254983680B   1274918399B  1019934720B  primary  linux-swap(v1)
 3      1274918400B  3323013119B  2048094720B  primary  ext3
 4      3323013120B  8587192319B  5264179200B  primary  ext3

(parted) 

이제 오프셋 값이 있으며이를 사용하여 파일 시스템을 마운트 할 수 있습니다.

# mount -o loop,offset=32256 myimage.img /mnt/disk1 
# mount -o loop,offset=1274918400 myimage.img /mnt/disk2
# mount -o loop,offset=3323013120 myimage.img /mnt/disk3

1
한 줄 또는 두 줄 답변은 종종 도움이되지 않는 것으로 간주됩니다. 권장 사항에 대한 설명을 확장하거나 관련 문서 또는 유용한 리소스에 연결하십시오.
HalosGhost

Fayiz / HalosGhost 덕분에 약간의 설명, 여기에 가장 효율적인 대답으로 확실히 더 좋습니다!
tisc0

parted : 인식 할 수없는 디스크 레이블
user180574

1

@slm에 약간의 수학이 있거나 적어도 fdisk -l출력 과 일치하지 않는 것 같습니다 . 개정판 u에서 fdisk에 매개 변수를 추가하여 실린더에서 섹터로 변경된 것처럼 보 입니까? Dunno, 그러나 기본값은 섹터이어야하기 때문에 광산에서 아무것도하지 않습니다.

내 이미지에서 :

$ fdisk -l bone-debian-7.5-2015-01-14-beaglebone.img
Disk bone-debian-7.5-2015-01-14-beaglebone.img: 3.7 GiB, 3965190144 bytes, 7744512 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
Disklabel type: dos
Disk identifier: 0x00000000

Device                                     Boot     Start       End  Blocks  Id System
bone-debian-7.5-2015-01-14-beaglebone.img1 *         2048    198655   98304   e W95 FAT16 (LBA)
bone-debian-7.5-2015-01-14-beaglebone.img2         198656   3481599 1641472  83 Linux

$ sudo mount -t vfat -o loop,offset=1048576,ro bone-debian-7.5-2015-01-14-beaglebone.img /mnt

어디

offset = Block size from 'Units' x Fdisk 'Start' column

내 예에서 fdisk는 2048 * 512 블록 크기 = 1048576에서 시작한다고 말합니다.


1

최신 버전의 file명령은 fdisk 또는 parted보다 훨씬 편리한 방식으로 시작 섹터를보고합니다.

file $img Armbian_jw.img: DOS/MBR boot sector; partition 1 : ID=0x83, start-CHS (0x40,0,1), end-CHS (0x3ff,3,32), startsector 8192, 2883584 sectors

이 한 줄짜리 출력은 다음과 같이 스크립팅 할 수 있습니다.

startsector=$(file $img | sed -n -e 's/.* startsector *\([0-9]*\),.*/\1/p')
offset=$(expr $startsector '*' 512)
echo $offset
 4194304
sudo mount -o loop,offset=$offset $img /mnt

1

losetup -P 오토메이션

다음 스크립트는 이미지의 모든 파티션을 자동으로 마운트합니다.

용법:

$ 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

출처:

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"
)

우분투 16.04에서 테스트되었습니다.

당사 사이트를 사용함과 동시에 당사의 쿠키 정책개인정보 보호정책을 읽고 이해하였음을 인정하는 것으로 간주합니다.
Licensed under cc by-sa 3.0 with attribution required.