1 rhel7 挂载windows虚机镜像
在rhel 7.0 内挂载windows虚拟镜像,需要ntfs-3g的软件包。当你安装该软件包后,挂载windows虚拟机镜像时,仍然出现下面问题:
[root@selinuxplus.com]# mount /opt/windowsxp_32.img /mnt
mount: /dev/loop0 is write-protected, mounting read-only
mount: unknown filesystem type '(null)'
1
2
3
[root@selinuxplus.com]# mount /opt/windowsxp_32.img /mnt
mount:/dev/loop0iswrite-protected,mountingread-only
mount:unknownfilesystemtype'(null)'
或者使用mount.ntfs-3g进行挂载。
[root@selinuxplus.com]# mount.ntfs-3g /opt/windowsxp_32.img /mnt -o loop
NTFS signature is missing.
Failed to mount '/opt/windowsxp_32.img': Invalid argument
The device '/opt/windowsxp_32.img' doesn't seem to have a valid NTFS.
Maybe the wrong device is used? Or the whole disk instead of a
partition (e.g. /dev/sda, not /dev/sda1)? Or the other way around?
1
2
3
4
5
6
[root@selinuxplus.com]# mount.ntfs-3g /opt/windowsxp_32.img /mnt -o loop
NTFSsignatureismissing.
Failedtomount'/opt/windowsxp_32.img':Invalidargument
Thedevice'/opt/windowsxp_32.img'doesn'tseemtohaveavalidNTFS.
Maybethewrongdeviceisused?Orthewholediskinsteadofa
partition(e.g./dev/sda,not/dev/sda1)?Ortheotherwayaround?
问题是无法挂载分区,详细信息见上面的报错信息。
主要是因为windowsxp_32.img镜像的起始分区是1,因为磁盘的第一个字节包含主引导记录和一些磁盘结构,如MS-DOS结构。如果你使用0作为第一个分区的起始,我们使用parted查看该分区结构,libparted会跳过开始的几个字节的信息允许查看分区结构。
[root@localhost ~]# parted /opt/windowsxp_32.img unit b print
Model: (file)
Disk /opt/windowsxp_32.img: 10737418240B
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:
Number Start End Size Type File system Flags
1 32256B 10725765119B 10725732864B primary ntfs boot
1
2
3
4
5
6
7
8
9
[root@localhost~]# parted /opt/windowsxp_32.img unit b print
Model:(file)
Disk/opt/windowsxp_32.img:10737418240B
Sectorsize(logical/physical):512B/512B
PartitionTable:msdos
DiskFlags:
NumberStartEndSizeTypeFilesystemFlags
132256B10725765119B10725732864Bprimaryntfsboot
我们可以看到起始的位置为32kB的地方,我们利用offset设置32kB的分区偏移量。32kB的起始,因为使用的工具太旧了。如果你使用的是512字节的扇区,实际的分区偏移可能是32256对应的63Sector(磁区)。
我们尝试使用offset进行分区挂载:
[root@selinuxplus.com opt]# mount -o loop,ro,offset=32256 windowsxp_32.img /mnt
[root@selinuxplus.com opt]# cd /mnt
[root@selinuxplus.com mnt]# ls
bootfont.bin ntldr
boot.ini pagefile.sys
CONFIG.SYS Program Files
Documents and Settings RECYCLER
hiberfil.sys System Volume Information
IO.SYS temp
Java virtio-win-0.1-74
MSDOS.SYS WINDOWS
1
2
3
4
5
6
7
8
9
10
11
[root@selinuxplus.comopt]# mount -o loop,ro,offset=32256 windowsxp_32.img /mnt
[root@selinuxplus.comopt]# cd /mnt
[root@selinuxplus.commnt]# ls
bootfont.binntldr
boot.inipagefile.sys
CONFIG.SYSProgramFiles
DocumentsandSettingsRECYCLER
hiberfil.sysSystemVolumeInformation
IO.SYStemp
Javavirtio-win-0.1-74
MSDOS.SYSWINDOWS
2 libguestfs 挂载windows虚机镜像
当使用libguestfs挂载windows虚机镜像时,也出现了这个问题.
[root@selinuxplus.com opt]# guestfish -a windowsxp_32.img
Welcome to guestfish, the guest filesystem shell for
editing virtual machine filesystems and disk images.
Type: 'help' for help on commands
'man' to read the manual
'quit' to quit the shell
> run
100%
> list-filesystems
/dev/sda1: ntfs
> mount /dev/sda1 /
libguestfs: error: mount: /dev/sda1 on / (options: ''): mount: unknown filesystem type 'ntfs'
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[root@selinuxplus.comopt]# guestfish -a windowsxp_32.img
Welcometoguestfish,theguestfilesystemshellfor
editingvirtualmachinefilesystemsanddiskimages.
Type:'help'forhelponcommands
'man'toreadthemanual
'quit'toquittheshell
>run
100%
>list-filesystems
/dev/sda1:ntfs
>mount/dev/sda1/
libguestfs:error:mount:/dev/sda1on/(options:''):mount:unknownfilesystemtype'ntfs'
需要安装libguestfs-winsupport
> mount /dev/sda1 /
> ll /
total 2097129
drwxrwxrwx 1 root root 4096 Dec 22 21:46 .
drwxr-xr-x 23 root root 4096 Dec 22 21:54 ..
-rwxrwxrwx 1 root root 0 Jan 8 2014 AUTOEXEC.BAT
-rwxrwxrwx 1 root root 0 Jan 8 2014 CONFIG.SYS
drwxrwxrwx 1 root root 4096 Mar 10 2014 Documents and Settings
-rwxrwxrwx 1 root root 0 Jan 8 2014 IO.SYS
1
2
3
4
5
6
7
8
9
>mount/dev/sda1/
>ll/
total2097129
drwxrwxrwx1rootroot4096Dec2221:46.
drwxr-xr-x23rootroot4096Dec2221:54..
-rwxrwxrwx1rootroot0Jan82014AUTOEXEC.BAT
-rwxrwxrwx1rootroot0Jan82014CONFIG.SYS
drwxrwxrwx1rootroot4096Mar102014DocumentsandSettings
-rwxrwxrwx1rootroot0Jan82014IO.SYS