mount an image file and change contents

wblock said:
The technique depends on the type of image file.
Code:
# file bin.img
bin.img: x86 boot sector; partition 1: ID=0x83, active, starthead 0, startsector 1, 593919 sectors
 
0x83 is a Linux partition type, so use mdconfig(8). Hopefully it's ext2 or 3 so you can use mount_ext2fs... Which is not being built on my 8-STABLE system for some reason.

Edit: because mount -t ext2fs does not just call mount_ext2fs internally, as I thought. So use
mount -t ext2fs /dev/md0s1
to mount that image.
 
  • Thanks
Reactions: ccc
I've done, but cannot mount it:
Code:
# mdconfig -a -t vnode -f bin.img -u 0
# mdconfig -l
md0
# mount -t ext3 /dev/md0 /mnt/cc
mount: /dev/md0 : Operation not supported by device
# mount -t ext2 /dev/md0 /mnt/cc
mount: /dev/md0 : Operation not supported by device
# /usr/src/sbin/mount_ext2fs /dev/md0 /mnt/cc
/usr/src/sbin/mount_ext2fs: Permission denied.
# /usr/src/sbin/mount_ext2fs bin.img /mnt/cc
/usr/src/sbin/mount_ext2fs: Permission denied.
 
ccc said:
I've done, but cannot mount it:
Code:
# mdconfig -a -t vnode -f bin.img -u 0
# mdconfig -l
md0
# mount -t ext3 /dev/md0 /mnt/cc
mount: /dev/md0 : Operation not supported by device
# mount -t ext2 /dev/md0 /mnt/cc
mount: /dev/md0 : Operation not supported by device

md0 is the device. But you need to mount the first slice on that device, which is s1. See the example in post #5 again. Also, I don't think there is an ext3 module; ext2 should mount ext3 filesystems.

Code:
# /usr/src/sbin/mount_ext2fs /dev/md0 /mnt/cc

That's a source directory, not an executable program.
 
It still doesn't work and my FreeBSD 7.3 cannot find the mount_ext2fs command:
Code:
# mount -t ext2fs /dev/md0s1 /mnt/cc
mount: /dev/md0s1 : Invalid argument

# mount_ext2fs
mount_ext2fs: Command not found.

# uname -a
FreeBSD bsd.net 7.3-RELEASE-p2 FreeBSD 7.3-RELEASE-p2 #0: Mon Jul 12 19:04:04 UTC 2010     
root@i386-builder.daemonology.net:/usr/obj/usr/src/sys/GENERIC  i386
 
"Invalid argument" usually means it's not what you think it is.

Do not use mount_ext2fs, it's gone.

Ask file(1) about that first slice:
# file -s /dev/md0s1
 
  • Thanks
Reactions: ccc
wblock said:
"Invalid argument" usually means it's not what you think it is.

Do not use mount_ext2fs, it's gone.

Ask file(1) about that first slice:
# file -s /dev/md0s1

Code:
# file -s /dev/md0s1
/dev/md0s1: x86 boot sector

BTW on linux I can mount this image file using:
Code:
# mount -o loop,offset=512 bin.img /mnt/cc

Howto set offset parameter for mount command on FreeBSD?
 
ccc said:
Code:
# file -s /dev/md0s1
/dev/md0s1: x86 boot sector

That's odd. Seems like something is not quite right, and you might have to refer back to where you got the image. Which, so far, has not been named or described, and that might tell us something, too.

BTW on linux I can mount this image file using:
Code:
# mount -o loop,offset=512 bin.img /mnt/cc

mdconfig doesn't have an offset parameter, and this is the second time in recent memory I've thought it would be useful.

It can be done manually, using dd(1) to skip over the first 512 bytes (the MBR) and write the rest to a new file. Or use tail(1).
 
  • Thanks
Reactions: ccc
That's bootable Live USB image file and was created under linux using live-helper.
 
I'm having the same challenge on FreeBSD 9.1, but my image file contains just the file system.

I create the md:

Code:
[root@fb91 ~]# mdconfig -f ~john/src/z/osj/sdx 
md0

But I'm stumped when trying to mount:

Code:
[root@fb91 ~]# mount -t ext2 /dev/md0 ~john/src/z/osj/fs
mount: /dev/md0: Operation not supported by device
[root@fb91 ~]# ls /dev/md*
/dev/md0        /dev/mdctl
[root@fb91 ~]# file -s /dev/md0
/dev/md0: Linux rev 1.0 ext2 filesystem data (mounted or unclean), UUID=ceed52c9-7aed-4a5f-ba81-e90abf8447b9
The fs directory exists and is empty. Running e2fsck on md0 has no effect (other than the response to "file").

What gives?
 
I don't have a solution to your problem @jphartmann but I came up with an idea to another problem presented in this thread at post #10.

How about using gnop(8) and its -o option to create a virtual disk that omits the first 512 bytes of the original image:

# gnop create -o 512 /dev/md0

Not sure if the offset is in bytes or sectors, I'm assuming it's in bytes here. Edit: seems to be in bytes.

Now /dev/md0.nop should have the proper image.
 
Last edited by a moderator:
Does this mean that mount has rejected the mount point or is just what -v gets you anyhow?

Code:
[root@fb91 ~]# ls -l /dev/md0
crw-r-----  1 root  operator    0, 125 Apr 10 14:06 /dev/md0
[root@fb91 ~]# mount -v -v -v -t ext2 /dev/md0 /var/local/fs
mount: /dev/md0: Operation not supported by device
/dev/gpt/91root on / (ufs, NFS exported, local, noatime, journaled soft-updates, writes: sync 0 async 47, reads: sync 919 async 5, fsid c6f22351fba90533)
Forgive my saying so, but it is rather frustrating that mount/ext2fs know exactly why the command is rejected.
 
You can't mount an unclean ext2 filesystem. Therefore try fsck.ext2 /dev/md0, then
mount -t ext2fs -o rw /dev/md0 /mnt/linux_ext2 as root.
 
Re:

kpa said:
How about using gnop(8) and its -o option to create a virtual disk that omits the first 512 bytes of the original image:
Nice! :beergrin For some time now I was wondering how to do it under FreeBSD other than using dd and gnop somehow didn't come into my mind. As I was always in hurry I used Linux (offset) to do it.
 
wblock@ said:
There is an example at the end of mdconfig(8).
You are right. I didn't go through the whole page when I was looking for a solution, I was only searching for "offset", which is not there. And you know how it is sometimes when you have to solve something fast - you either look and read or use something you know already.:) Today I really wanted to know how to do it under FreeBSD.
 
Back
Top