Skip to contentSkip to conversation

Mounting qemu virtual disk images from host linux os

Qemu-devel Tom Sandholm 6 participants 13 messages Jan 16, 2005 – Jan 18, 2005 1 message not in the archive

lore
Share & tools
lore
#0 lore raw

I found the lomount program that is supposed to mount your qemu virtual-disk-images; but it isn't working for me.

I've installed debian "sarge" onto the virtual image, using ext3 filesystems as default, with /dev/hda1 as the primary bootable linux partition (root).

When I execute the lomount program, here's what I get.
============================================================

nixsys:/qemu# ./lomount -t ext3 -diskimage debian02_sarge_hda.img /mnt
mount: wrong fs type, bad option, bad superblock on /dev/loop0,
      or too many mounted file systems
nixsys:/qemu#
===========================================================

What am I doing wrong?
Thanks!

Tom Sandholm

begin:vcard
fn:Tom Sandholm
n:Sandholm;Tom
email;internet:[email protected]
version:2.1
end:vcard

#1 lore raw
Quoted 9 lines · Tom Sandholm

I found the lomount program that is supposed to mount your qemu virtual-disk-images; but it isn't working for me.

I've installed debian "sarge" onto the virtual image, using ext3 filesystems as default, with /dev/hda1 as the primary bootable linux partition (root).

When I execute the lomount program, here's what I get.
============================================================

Quoted 7 lines
nixsys:/qemu# ./lomount -t ext3 -diskimage debian02_sarge_hda.img /mnt
mount: wrong fs type, bad option, bad superblock on /dev/loop0,
       or too many mounted file systems
nixsys:/qemu#
===========================================================

What am I doing wrong?

I don't know about lomount, but are you sure your .img-file is a partition? Maybe the file represents a virtual disk with partition table and partitions?

/ magnus

#2 lore raw

Oh yes, it is multi-partitioned. Any suggestions on how I can select a specific partition?

Thanks
Tom

Quoted 25 lines · Magnus Damm
Quoted 9 lines · Tom Sandholm

I found the lomount program that is supposed to mount your qemu virtual-disk-images; but it isn't working for me.

I've installed debian "sarge" onto the virtual image, using ext3 filesystems as default, with /dev/hda1 as the primary bootable linux partition (root).

When I execute the lomount program, here's what I get.
============================================================

Quoted 9 lines
nixsys:/qemu# ./lomount -t ext3 -diskimage debian02_sarge_hda.img /mnt
mount: wrong fs type, bad option, bad superblock on /dev/loop0,
      or too many mounted file systems
nixsys:/qemu#
===========================================================

What am I doing wrong?

I don't know about lomount, but are you sure your .img-file is a partition? Maybe the file represents a virtual disk with partition table and partitions?

Quoted 11 lines

/ magnus

_______________________________________________
Qemu-devel mailing list
[email protected]
http://lists.nongnu.org/mailman/listinfo/qemu-devel

begin:vcard
fn:Tom Sandholm
n:Sandholm;Tom
email;internet:[email protected]
version:2.1
end:vcard

#3 lore raw

I've not used lomount before so maybe you can pass flags to lomount directly. I can tell you how to do it using losetup / mount separately:

You can use losetup to bind a partition of the disk file to a /dev/loop device and then mount that. Use the -o option to specify the offset into the file where the partition is to be found. Use the -s option to specify the size of the partition.

You can probably fdisk the file (or, if that doesn't work, a loop device bound to the whole file) to figure out where the partition boundaries are.

HTH,
Mark

Quoted 8 lines · Tom Sandholm

Oh yes, it is multi-partitioned. Any suggestions on how I can select a specific partition?

Thanks
Tom

Quoted 1 line · Magnus Damm

On Sun, 16 Jan 2005 18:33:54 -0500, Tom Sandholm <[email protected]>

Quoted 28 lines · wrote:
Quoted 28 lines
Quoted 9 lines

I found the lomount program that is supposed to mount your qemu virtual-disk-images; but it isn't working for me.

I've installed debian "sarge" onto the virtual image, using ext3 filesystems as default, with /dev/hda1 as the primary bootable linux partition (root).

When I execute the lomount program, here's what I get.
============================================================

Quoted 7 lines
nixsys:/qemu# ./lomount -t ext3 -diskimage debian02_sarge_hda.img /mnt
mount: wrong fs type, bad option, bad superblock on /dev/loop0,
      or too many mounted file systems
nixsys:/qemu#
===========================================================

What am I doing wrong?

I don't know about lomount, but are you sure your .img-file is a partition? Maybe the file represents a virtual disk with partition table and partitions?

/ magnus

_______________________________________________
Qemu-devel mailing list
[email protected]
http://lists.nongnu.org/mailman/listinfo/qemu-devel

#4 lore raw
Quoted 8 lines · Mark Williamson

I've not used lomount before so maybe you can pass flags to lomount directly. I can tell you how to do it using losetup / mount separately:

You can use losetup to bind a partition of the disk file to a /dev/loop device and then mount that. Use the -o option to specify the offset into the file where the partition is to be found. Use the -s option to specify the size of the partition.

Quoted 5 lines

You can probably fdisk the file (or, if that doesn't work, a loop device bound to the whole file) to figure out where the partition boundaries are.

HTH,
Mark

lomount does all of this internally. You can't pass it an offset into the file, only which partition you wish to mount. It calculates the offset by looking it up in the partition table.

I'm wondering if he is trying to mount a COW image or some fancy-but-qemu-supported disk image. lomount has only been tested with raw images and sparse images, and is unlikely to work w/ anything else.

Signature · 2 lines
Infinite complexity begets infinite beauty.
Infinite precision begets infinite perfection.
#5 lore raw

Hi,
Thanks for all the replies.
The image was created with qemu-img, with a size of 4GB. I am able to fdisk image-name and see the partitions. (as follows) Just can't mount partition 1.
====================================

nixsys:/qemu# fdisk debian01_sarge_hda.img

The number of cylinders for this disk is set to 8322. There is nothing wrong with that, but this is larger than 1024, and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs (e.g., DOS FDISK, OS/2 FDISK)

Command (m for help): p

Disk debian01_sarge_hda.img: 4294 MB, 4294967296 bytes 16 heads, 63 sectors/track, 8322 cylinders Units = cylinders of 1008 * 512 = 516096 bytes

                Device Boot      Start         End      Blocks   Id  System
debian01_sarge_hda.img1   *           1        7904     3983584+  83  Linux
debian01_sarge_hda.img2            7905        8322      210672    f  W95 Ext'd (LBA)
debian01_sarge_hda.img5            7905        8322      210640+  82  Linux swap

Command (m for help):
========================================

Thanks!
Tom Sandholm.

Quoted 19 lines · Jim C. Brown
Quoted 8 lines · Mark Williamson

I've not used lomount before so maybe you can pass flags to lomount directly. I can tell you how to do it using losetup / mount separately:

You can use losetup to bind a partition of the disk file to a /dev/loop device and then mount that. Use the -o option to specify the offset into the file where the partition is to be found. Use the -s option to specify the size of the partition.

Quoted 7 lines

You can probably fdisk the file (or, if that doesn't work, a loop device bound to the whole file) to figure out where the partition boundaries are.

HTH,
Mark

Quoted 10 lines

lomount does all of this internally. You can't pass it an offset into the file, only which partition you wish to mount. It calculates the offset by looking it up in the partition table.

I'm wondering if he is trying to mount a COW image or some fancy-but-qemu-supported disk image. lomount has only been tested with raw images and sparse images, and is unlikely to work w/ anything else.

begin:vcard
fn:Tom Sandholm
n:Sandholm;Tom
email;internet:[email protected]
version:2.1
end:vcard

#6 lore raw
In reply to Tom Sandholm
Quoted 1 line

Oh yes, it is multi-partitioned. Any suggestions on how I can select a specific partition?

According to the source, lomount has a "-partition" option. So you might want to try:

./lomount -t ext3 -diskimage debian02_sarge_hda.img -partition 1 /mnt

- Bartosz

#7 lore raw
Quoted 10 lines · Bartosz Fabianowski
Quoted 2 lines

Oh yes, it is multi-partitioned. Any suggestions on how I can select a specific partition?

According to the source, lomount has a "-partition" option. So you might want to try:

./lomount -t ext3 -diskimage debian02_sarge_hda.img -partition 1 /mnt

- Bartosz

Well, lomount defaults to partition 1 if not given that option. He might want a different partition tho. (Brute force method: try adding "-partition 2", "-partition 3", and so on until it mounts the one you want it to.)

Signature · 2 lines
Infinite complexity begets infinite beauty.
Infinite precision begets infinite perfection.
#8 lore raw
In reply to Magnus Damm
Quoted 5 lines · Magnus Damm

I don't know about lomount, but are you sure your .img-file is a partition? Maybe the file represents a virtual disk with partition table and partitions?

/ magnus

Shouldn't matter. lomount defaults to partition 1. You can specify a different one via the -partition option.

Signature · 2 lines
Infinite complexity begets infinite beauty.
Infinite precision begets infinite perfection.
#9 lore raw
In reply to Tom Sandholm
Quoted 15 lines · Tom Sandholm

I found the lomount program that is supposed to mount your qemu virtual-disk-images; but it isn't working for me.

I've installed debian "sarge" onto the virtual image, using ext3 filesystems as default, with /dev/hda1 as the primary bootable linux partition (root).

When I execute the lomount program, here's what I get.
============================================================

nixsys:/qemu# ./lomount -t ext3 -diskimage debian02_sarge_hda.img /mnt
mount: wrong fs type, bad option, bad superblock on /dev/loop0,
      or too many mounted file systems
nixsys:/qemu#
===========================================================
Quoted 5 lines

What am I doing wrong?
Thanks!

Tom Sandholm

What partition do you want to mount? Are you sure it is the very first parition? What is the output of "sdisk -l debian02_sarge_hda.img" ?

Quoted 4 lines

_______________________________________________
Qemu-devel mailing list
[email protected]
http://lists.nongnu.org/mailman/listinfo/qemu-devel

Signature · 2 lines
Infinite complexity begets infinite beauty.
Infinite precision begets infinite perfection.
#10 lore raw

Output of "sfdisk -l debian02_sarge_hda.img".

====================================================

:nixsys:/qemu# sfdisk -l debian02_sarge_hda.img
Disk debian02_sarge_hda.img: cannot get geometry

Disk debian02_sarge_hda.img: 0 cylinders, 0 heads, 0 sectors/track
Warning: The partition table looks like it was made
for C/H/S=*/16/63 (instead of 0/0/0).
For this listing I'll assume that geometry.
Units = cylinders of 516096 bytes, blocks of 1024 bytes, counting from 0

Device Boot Start End #cyls #blocks Id System

debian02_sarge_hda.img1   *      0+   7903    7904-   3983584+  83  Linux
debian02_sarge_hda.img2       7904    8321     418     210672    f  W95 Ext'd (LBA)
debian02_sarge_hda.img3          0       -       0          0    0  Empty
debian02_sarge_hda.img4          0       -       0          0    0  Empty
debian02_sarge_hda.img5       7904+   8321     418-    210640+  82  Linux swap
Quoted 18 lines · Tom Sandholm
Quoted 17 lines

I found the lomount program that is supposed to mount your qemu virtual-disk-images; but it isn't working for me.

I've installed debian "sarge" onto the virtual image, using ext3 filesystems as default, with /dev/hda1 as the primary bootable linux partition (root).

When I execute the lomount program, here's what I get.
============================================================

nixsys:/qemu# ./lomount -t ext3 -diskimage debian02_sarge_hda.img /mnt
mount: wrong fs type, bad option, bad superblock on /dev/loop0,
     or too many mounted file systems
nixsys:/qemu#
===========================================================

What am I doing wrong?
Thanks!

Quoted 20 lines
Quoted 4 lines

Tom Sandholm

What partition do you want to mount? Are you sure it is the very first parition? What is the output of "sdisk -l debian02_sarge_hda.img" ?

Quoted 6 lines

_______________________________________________
Qemu-devel mailing list
[email protected]
http://lists.nongnu.org/mailman/listinfo/qemu-devel

begin:vcard
fn:Tom Sandholm
n:Sandholm;Tom
email;internet:[email protected]
version:2.1
end:vcard

#11 lore raw

Tom Sandholm <[email protected]> writes:

[ mounting disk partitions ]

You might want to try the following script I'm using for mounting entire disk images. I wouldn't say it's really finished, but it works for me so far so I hope it might be of some use.

==========================================================================
~/bin/mount-hd-image
==========================================================================
#!/bin/sh
#
# Time-stamp: <2005-01-10 10:50:16 hcz>

pname=${0##*/}
usage() {
iconv -f utf-8 <<EOF
Syntax: $pname [-t type] raw_image mountpoint
Function: mount all partitions of a complete hd image
optionally create a new one
opts:

        -c        create image if it doesn't exist
        -f        run fdisk on the image
        -m        make a filesystem on it
        -v        debug level (may be given multiple times)
        -x        Script debug (det -x)

EOF
}

if [ -z "$nopt" ]; then

    black=$(tput oc)$(tput sgr0) # Reset color + attribs
    bold=$(tput bold)
    red=$(tput setaf 1)
    green=$(tput setaf 2)
    blue=$(tput setaf 4)
    cyan=$(tput setaf 6)

fi 2>/dev/null

d_echo(){
    # $1: minimum debug level req'd for display
    # $2 ..: message
    if [ "$vopt" -ge "$1" ]; then
	shift
	echo "$@"
    fi
}
muss(){
    res=0
    d_echo 1 -e "$cyan$*$black"
    "$@" || abort "$*"
}
kann(){
    d_echo 1 -e "$cyan$*$black"
    "$@"
}
kann0(){
    d_echo 1 -e "$cyan$*$black"
    "$@" >/dev/null 2>&1
}
abort(){
    [ $# -gt 0 ] && echo -n "$pname: "
    for i in "$@"; do echo >&2 "$i"; done
    echo "$pname: aborted."
    exit 2
}

###################################################

vopt=0
dopt=/home/hcz/qemu
while getopts xvh-:fmc: argv; do

    case $argv in
        c) eval ${argv}opt="\$OPTARG";;
        f|m) eval ${argv}opt=\$argv;;
        v) eval ': $(('$argv'opt++))';;
        x) set -x;;
        *) usage; exit 0;;
    esac

done
shift $((OPTIND-1))

if [ $# -lt 2 ]; then
abort "Not enough arguments"
exit 1
fi

src="$1"
dest="$2"
shift; shift
mkdir -p "${dest##*/}" || abort "Can't create $dest" uid=$(id -u)
gid=$(id -g)
losetup=/sbin/losetup
#types="vfat captive-ntfs ntfs"

if [ -n "$copt" ]; then
if [ -f "$src" ]; then
read -p "$src already exists. Overwrite (Y/N*): " echo $REPLY | egrep -i '^ *y' || abort
fi
muss qemu-img create -f raw "$src" $copt
fi

if [ -n "$copt$fopt" ]; then

    muss /sbin/fdisk -C $(( $(stat "$src" -c "%s") / 255 / 63 /512)) "$src"

fi

x=$(/sbin/fdisk -ul "$src" 2>/dev/null)
[ -z "$x" ] && abort "Can't 'fdisk -ul $src'"
echo $x | grep -q "This doesn't look like a partition table" &&
abort "You selected a partition, but there is no valid partition table"
echo "Mounting harddisk image '$src' ..."

# win-b1              63    20964824    10482381    7  HPFS/NTFS
#      ()1            ()2   (                       ){3}  ()3
echo "$x" | grep -v 'Extended$' |
 sed -ne "s#^${src}p\?\([0-9]\+\)[ *]*\([0-9]*\) \+\([0-9]\++\? \+\)\{3\}\(.\+\)#\1 \2 \3 \4#p" |
 while read partno start id system; do
    d_echo 2 "p:$partno start:$start id:$id sys:$system"
    case $system in
        Extended) continue;;
        FAT*) types="msdos vfat"; mkfs=(/sbin/mkfs.msdos -F32);;
        HPFS/NTFS) types="captive-ntfs ntfs";;
        *) types=auto;;
    esac
    echo -n "Patition $partno: trying "
    mkdir -p "$dest/$partno"
    for type in $types; do
        echo -n "$type "
        res=99
        loop_dev=$($losetup -f) 
        [ -z "$loop_dev" ] && abort "Can't find a loop device"
        muss $losetup -o $((start * 512)) $loop_dev "$src"
        if [ -n "$mopt" ]; then
            [ -n "$mkfs" ] ||
               echo "Don't know how to make a $system file system"
            muss "${mkfs[@]}" $loop_dev
            # muss $losetup -d $loop_dev
        fi
        if kann0 sudo mount -o uid=$uid,gid=$gid,users \
                  -t  $type "$loop_dev" "$dest/$partno"; then
            kann0 sudo chmod a+xrw "$2"
            echo "... $type: ok."
            res=0
            break
        fi
    done
    [ "$res" -eq 0 ] || abort "Error mounting partition $partno"
done

A message that is not in the archive (sent off-list or not yet received): [email protected]

#13 lore raw
Quoted 9 lines · Heike C. Zimmerer

Tom Sandholm <[email protected]> writes:

[ mounting disk partitions ]

You might want to try the following script I'm using for mounting entire disk images. I wouldn't say it's really finished, but it works for me so far so I hope it might be of some use.

[ ~/bin/mount-hd-image ]

Let me add that only the disk image mounting part of the script has seen some testing. The options to create entire partitioned disk images are pretty much untested.

- Heike