Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 4 Oct 2017 13:14:17 +0200
From:      Polytropon <freebsd@edvax.de>
To:        Johan Hendriks <joh.hendriks@gmail.com>
Cc:        freebsd-questions@freebsd.org
Subject:   Re: Edit the qcow2 FreeBSD image file
Message-ID:  <20171004131417.4bfbaacb.freebsd@edvax.de>
In-Reply-To: <f739337b-e212-24f0-c66e-210461fd553c@gmail.com>
References:  <dc133ebc-d931-6b9e-b989-bf8e69b2be81@gmail.com> <20171004112931.bb6524b9.freebsd@edvax.de> <bc0b02fb-e121-be41-e5ce-1b2d84958d1c@gmail.com> <20171004120949.24b4cd25.freebsd@edvax.de> <f739337b-e212-24f0-c66e-210461fd553c@gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Wed, 4 Oct 2017 12:41:46 +0200, Johan Hendriks wrote:
>=20
>=20
> Op 04/10/2017 om 12:09 schreef Polytropon:
> > On Wed, 4 Oct 2017 12:02:56 +0200, Johan Hendriks wrote:
> >>
> >> Op 04/10/2017 om 11:29 schreef Polytropon:
> >>> On Wed, 4 Oct 2017 09:47:47 +0200, Johan Hendriks wrote:
> >>>> I want to add a script to the default qcow2 file of the FreeBSD qcow=
2 image.
> >>>> But how do i mount the qcow2 file on FreeBSD?
> >>>> There are a lot of howto's how to do it on Linux but i do not always
> >>>> have a Linux box ready.
> >>> Without having verified, I'd say something like this will work:
> >>>
> >>> 	# mdconfig -a -t vnode -f <flename> -u 0
> >>> 	# mount -t ufs -o rw /dev/md0s1a /mnt
> >>>
> >>> The key is to connect the file to a md device ("memory disk"),
> >>> and then use it as if it was a real disk. But always check the
> >>> correct device file name - md0 will reflect the "disk layout"
> >>> of the image file, so maybe you need to use /dev/md0p1 or
> >>> /dev/md0a or simply /dev/md0, so check "ls /dev/md0*" to see
> >>> how the layout is being translated to device files - this
> >>> depends on the layout that has been constructed within the
> >>> image file.
> >>>
> >>> When you're done, use:
> >>>
> >>> 	# umount /mnt
> >>> 	# mdconfig -d -u 0
> >>>
> >>> This will finally sync any changes and disconnect the device.
> >>> The image file can be used now.
> >>>
> >> Thanks, I tried that, but it does not work.
> >> root@desk:~ # mdconfig -a -t vnode -f FreeBSD-11.1-RELEASE-amd64.qcow2=
 -u 0
> >>
> >> Then a ls of /dev/md0 only shows md0 and i can not mount that one.
> >> root@desk:~ # ls -al /dev/md*
> >> crw-r-----=A0 1 root=A0 operator=A0 0x8c Oct=A0 4 11:48 /dev/md0
> >> crw-------=A0 1 root=A0 wheel=A0=A0=A0=A0=A0 0xb Sep 21 14:16 /dev/mdc=
tl
> >>
> >> And a mount of /dev/md0 gives an error.
> >>
> >> root@desk:~ # mount -t ufs -o rw /dev/md0 /mnt
> >> mount: /dev/md0: Invalid argument
> > Check the file format of md0 if it is recognized as a filesystem
> > image:
> >
> > 	# file FreeBSD-11.1-RELEASE-amd64.qcow2
> > 	# file -s /dev/md0
> >
> > it should be recognized as a UFS file system (typically called
> > "Unix Fast File system [v2]"). Note that you can only mount a
> > file system which is being recognized correctly.
> >
> Indeed it is not recognized as a regular filesystem.
> root@desk:~ # file FreeBSD-11.1-RELEASE-amd64.qcow2
> FreeBSD-11.1-RELEASE-amd64.qcow2: QEMU QCOW Image (v2), 22548643840 bytes
> root@desk:~ # file -s /dev/md0
> /dev/md0: QEMU QCOW Image (v2), 22548643840 bytes

This shows that the file is _not_ a file system image (that
FreeBSD can understand natively).



> Well I installed the qemu-tools port and created a .raw file.
> This way i can mount the file with mdconfig like you discribed.
>=20
> root@desk:~ #=A0 qemu-img convert FreeBSD-11.1-RELEASE-amd64.qcow2
> FreeBSD-11.1-RELEASE-amd64.raw
> root@desk:~ # mdconfig -d -u 0
> root@desk:~ # mdconfig -a -t vnode -f FreeBSD-11.1-RELEASE-amd64.raw -u 0
> root@desk:~ # ls /dev/md0*
> /dev/md0=A0=A0=A0 /dev/md0p1=A0=A0=A0 /dev/md0p2=A0=A0=A0 /dev/md0p3

So there are three GPT partitions inside that image, and with
the raw file connected to the memory disk device, they are
represented as individual files, just as intended.



> root@desk:~ # mount /dev/md0p3 /mnt
> root@desk:~ # cd /mnt
> root@desk:/mnt # ls -al
> total 121
> drwxr-xr-x=A0 19 root=A0 wheel=A0=A0=A0=A0=A0 512 Jul 21 04:33 .
> drwxr-xr-x=A0 31 root=A0 wheel=A0=A0=A0=A0=A0=A0 39 Sep 21 14:16 ..
> -rw-r--r--=A0=A0 2 root=A0 wheel=A0=A0=A0=A0=A0 957 Jul 21 04:33 .cshrc
> -rw-r--r--=A0=A0 2 root=A0 wheel=A0=A0=A0=A0=A0 249 Jul 21 04:33 .profile
> drwxrwxr-x=A0=A0 2 root=A0 operator=A0=A0 512 Jul 21 04:30 .snap
> -r--r--r--=A0=A0 1 root=A0 wheel=A0=A0=A0=A0 6199 Jul 21 04:33 COPYRIGHT
> drwxr-xr-x=A0=A0 2 root=A0 wheel=A0=A0=A0=A0 1024 Jul 21 04:31 bin
> drwxr-xr-x=A0=A0 8 root=A0 wheel=A0=A0=A0=A0 1024 Jul 21 04:33 boot
> dr-xr-xr-x=A0=A0 2 root=A0 wheel=A0=A0=A0=A0=A0 512 Jul 21 04:30 dev
> drwxr-xr-x=A0 27 root=A0 wheel=A0=A0=A0=A0 2048 Jul 21 04:33 etc
> drwxr-xr-x=A0=A0 4 root=A0 wheel=A0=A0=A0=A0 1536 Jul 21 04:31 lib
> drwxr-xr-x=A0=A0 3 root=A0 wheel=A0=A0=A0=A0=A0 512 Jul 21 04:33 libexec
> drwxr-xr-x=A0=A0 2 root=A0 wheel=A0=A0=A0=A0=A0 512 Jul 21 04:30 media
> drwxr-xr-x=A0=A0 2 root=A0 wheel=A0=A0=A0=A0=A0 512 Jul 21 04:30 mnt
> drwxr-xr-x=A0=A0 2 root=A0 wheel=A0=A0=A0=A0=A0 512 Jul 21 04:30 net
> dr-xr-xr-x=A0=A0 2 root=A0 wheel=A0=A0=A0=A0=A0 512 Jul 21 04:30 proc
> drwxr-xr-x=A0=A0 2 root=A0 wheel=A0=A0=A0=A0 2560 Jul 21 04:31 rescue
> drwxr-xr-x=A0=A0 2 root=A0 wheel=A0=A0=A0=A0=A0 512 Jul 21 04:33 root
> drwxr-xr-x=A0=A0 2 root=A0 wheel=A0=A0=A0=A0 2560 Jul 21 04:32 sbin
> lrwxr-xr-x=A0=A0 1 root=A0 wheel=A0=A0=A0=A0=A0=A0 11 Jul 21 04:30 sys ->=
 usr/src/sys
> drwxrwxrwt=A0=A0 2 root=A0 wheel=A0=A0=A0=A0=A0 512 Jul 21 04:30 tmp
> drwxr-xr-x=A0 14 root=A0 wheel=A0=A0=A0=A0=A0 512 Jul 21 04:30 usr
> drwxr-xr-x=A0 24 root=A0 wheel=A0=A0=A0=A0=A0 512 Jul 21 04:30 var

Excellent!


--=20
Polytropon
Magdeburg, Germany
Happy FreeBSD user since 4.0
Andra moi ennepe, Mousa, ...



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20171004131417.4bfbaacb.freebsd>