You are not logged in.

#1 2010-04-14 22:50:06

brahan
Member
From: South Carolina
Registered: 2009-11-08
Posts: 15

Qemu, mounting a raw img to temp file, mount needs a filesystem type.

Hello,

I need to transfer files from my host machine to a qemu target img.  I am trying to mount the hd image as shown in the qemu arch wiki, however mount is asking for the filesystem type.

I don't understand how the method suggested in the wiki would work because I don't understand how you could specify a type for a file that only qemu knows how to read?

How do I specify a type when the image has multiple partitions?

Is there even a way to specify a type that mount recognizes when the host machine does not represent the hd image as a filesystem?

I suppose I will open a github account and wget my code while running the vm.  Just wanted to hear your thoughts on this.  Should there be a wiki revision?

[wiki]http://wiki.archlinux.org/index.php/QEMU[/wiki]


Bradley Hanna (brahan)
brahandevel@gmail.com

Offline

#2 2010-04-14 23:12:12

Profjim
Member
From: NYC
Registered: 2008-03-24
Posts: 658

Re: Qemu, mounting a raw img to temp file, mount needs a filesystem type.

I didn't manage to get this working either. But I was under the impression that the raw image was just a byte-for-byte model of a disk.

On the guest side it'd just look like there's a new device: a fake /dev/sdb or something. On *either* the host side or the guest side, you're *first* going to need to install a filesystem onto this emulated disk.

To do it on the guest side, just continue on as though /dev/sdb were a real drive. Then on the host side you should be able to do "mount -o loop diskimagefile /mntpoint". If you're asked for a filesystem type, supply the one you installed.

(You should never have the disk image file in use by both host and guest at the same time.)

To do the formatting on the host side instead, I'd guess you'd first do a losetup associating the disk image with /dev/loop0 or something (see man losetup), then install the filesystem onto /dev/loop0, then do a "losetup -d /dev/loop0". That's my understanding of how it's supposed to work.

As I said, though, I wasn't able to get everything going myself.

Last edited by Profjim (2010-04-14 23:14:48)

Offline

#3 2010-04-14 23:51:56

Vain
Member
Registered: 2008-10-19
Posts: 179
Website

Re: Qemu, mounting a raw img to temp file, mount needs a filesystem type.

If you're asked to supply a file system type, you probably got the offset wrong.

Remember: What you're trying to mount is not an image of a partition but of a whole drive. That is, there's a master boot record at the beginning of the image and probably some padding after the MBR.

Hence you need to read/parse the MBR of your image first. This can be done with fdisk.

$ fdisk -ul disk.img
...
Units = sectors of 1 * 512 = 512 bytes
...
   Device Boot      Start         End      Blocks   Id  System
disk.img1              63       16064        8001    1  FAT12
disk.img2           16065       48194       16065    5  Extended
disk.img5           16128       32129        8001   83  Linux
disk.img6           32193       48194        8001    1  FAT12

Ok, so that's the partitions in my disk image. Suppose you want to mount the first logical partition ("disk.img5" -- those names don't really exist, of course, it's just fdisk internals -- would be /dev/sda5 in a linux guest).

# mount -o loop,offset=$((16128 * 512)) /tmp/disk.img /mnt
# mount
...
/dev/loop0 on /mnt type ext3 (rw,offset=8257536)
# l /mnt
total 19k
drwxr-xr-x  3 root root 1.1k Apr 15 01:36 ./
drwxr-xr-x 20 root root 4.1k Apr  5 23:47 ../
drwx------  2 root root  13k Apr 15 01:36 lost+found/
-rw-rw-rw-  1 root root    3 Apr 15 01:37 testfile

The first number, 16128, is the offset counted in sectors as shown by fdisk. However, mount expects the offset in bytes, so you have to multiply it first. fdisk also tells you the size of one sector.

That's it. smile

Last edited by Vain (2010-04-15 00:04:39)

Offline

#4 2010-04-15 01:17:47

brahan
Member
From: South Carolina
Registered: 2009-11-08
Posts: 15

Re: Qemu, mounting a raw img to temp file, mount needs a filesystem type.

Vain wrote:

If you're asked to supply a file system type, you probably got the offset wrong.

Bah!

Naively, I have assumed that the offset given in the wiki example would work for me.

Thank You Vain, I should have known better.

The wiki should be revised to explain this.


Bradley Hanna (brahan)
brahandevel@gmail.com

Offline

#5 2013-11-26 16:02:09

bhussein
Member
Registered: 2013-11-26
Posts: 1

Re: Qemu, mounting a raw img to temp file, mount needs a filesystem type.

I keep getting this error message when i follow your instructions here

mount -o loop,offset=$((4194305 * 512)) bb.img /mnt/bb/
NTFS signature is missing.
Failed to mount '/dev/loop0': Invalid argument
The device '/dev/loop0' 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?

Any help would be much appreciated big_smile

Offline

#6 2013-11-26 16:19:11

Inxsible
Forum Fellow
From: Chicago
Registered: 2008-06-09
Posts: 9,183

Re: Qemu, mounting a raw img to temp file, mount needs a filesystem type.

bhussein, welcome to the forums. Do not necrobump threads. Start a new thread and link to this if you feel its relevant. Also please read our forum rules.

Closing..


Forum Rules

There's no such thing as a stupid question, but there sure are a lot of inquisitive idiots !

Offline

Board footer

Powered by FluxBB