From owner-freebsd-questions@freebsd.org Wed Oct 4 10:40:29 2017 Return-Path: Delivered-To: freebsd-questions@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 0C127E35695 for ; Wed, 4 Oct 2017 10:40:29 +0000 (UTC) (envelope-from joh.hendriks@gmail.com) Received: from mail-wm0-x22a.google.com (mail-wm0-x22a.google.com [IPv6:2a00:1450:400c:c09::22a]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 900797FC05 for ; Wed, 4 Oct 2017 10:40:28 +0000 (UTC) (envelope-from joh.hendriks@gmail.com) Received: by mail-wm0-x22a.google.com with SMTP id u138so22227385wmu.4 for ; Wed, 04 Oct 2017 03:40:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding:content-language; bh=v5yGOfJrS0JsEH7VAxT3E1xFUP8Eszxw+tciUME9PjE=; b=hZicrzSaYjGbK6P6PA3jdLrd11uBPTxb63KTMcKqXparowVnymZD3b5fH5pD4hbCuW o62E+iLTFK2LnXq7x6ntKLbjhPJd6teSrdI4kNM2gC3i9waRfIvacK/BgsXyMiB928Qv L4h/mQhj7y6tUzndnVNB7lO7S/CzyloP+CGDuEytuFlvDBFLiI1FFcLHqHkTcs/ejM2I y74X4pYNk5gV9jddtVbV3w1dMtlTu75qYBkA8UmBMrpZvGXiIKk/kWTEReJUd3sJlVID oY0x3HltUATMFZQ8SUtYLEXnW6TJ4LRFIqCwtG+IOAW5CRdmzYR3d0L4AHSUNKGOhmKl o30g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=v5yGOfJrS0JsEH7VAxT3E1xFUP8Eszxw+tciUME9PjE=; b=rTqPaDcM0u12D4j3b0ZG6sQf2CkjgIf8k3pBrbzjTqA4SAOWCRJT2H7nfqejWrArFF 80XcgLMG7p0LjpULsuD2SMEw/leLoogEDPuXyllP077UE9R9Kz4LkCMKldBSCpAP2nID U4j3YrWcngzDPBvSpUVU8AZCDADax/Hny80M4aBFfDQO4CKCs6yVUJP1+Y+bh/yzmEih 6t+fDbhSoLqDsAHDNIm4NMnygKQMHUqoJb5v/QRpckd5sBb7LZMtc+vL11gj+C5GMeRw G4S2+RwQY3puewv7pmhUNaec1i3GNY/wzXhwkHsFg0V4TsGVSmmMJhUol9ebGAmmwmME z2tQ== X-Gm-Message-State: AHPjjUjnYGXn/5sU2zzVay2PQ0JukkpP9u/ZXHLM8qdKFxVS/derIM5M elYXoBXHxV75Sf7WmHcGiUFALg== X-Google-Smtp-Source: AOwi7QBl+vFvXnP0yXwtWZQtKr+V8GS5Vcr2WNsS9PN8q6MWguguQonSh1ozOK3mHikYelndRjKUFg== X-Received: by 10.80.135.170 with SMTP id a39mr28657553eda.207.1507113626100; Wed, 04 Oct 2017 03:40:26 -0700 (PDT) Received: from Johans-MacBook-Air-2.local (92-111-79-242.static.chello.nl. [92.111.79.242]) by smtp.googlemail.com with ESMTPSA id 3sm2458326edv.50.2017.10.04.03.40.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 04 Oct 2017 03:40:25 -0700 (PDT) Subject: Re: Edit the qcow2 FreeBSD image file To: Polytropon , freebsd-questions@freebsd.org References: <20171004112931.bb6524b9.freebsd@edvax.de> <20171004120949.24b4cd25.freebsd@edvax.de> From: Johan Hendriks Message-ID: Date: Wed, 4 Oct 2017 12:41:46 +0200 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 MIME-Version: 1.0 In-Reply-To: <20171004120949.24b4cd25.freebsd@edvax.de> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Content-Language: nl X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 04 Oct 2017 10:40:29 -0000 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 qcow2 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 -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-----  1 root  operator  0x8c Oct  4 11:48 /dev/md0 >> crw-------  1 root  wheel      0xb Sep 21 14:16 /dev/mdctl >> >> 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 Well I installed the qemu-tools port and created a .raw file. This way i can mount the file with mdconfig like you discribed. root@desk:~ #  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    /dev/md0p1    /dev/md0p2    /dev/md0p3 root@desk:~ # mount /dev/md0p3 /mnt root@desk:~ # cd /mnt root@desk:/mnt # ls -al total 121 drwxr-xr-x  19 root  wheel      512 Jul 21 04:33 . drwxr-xr-x  31 root  wheel       39 Sep 21 14:16 .. -rw-r--r--   2 root  wheel      957 Jul 21 04:33 .cshrc -rw-r--r--   2 root  wheel      249 Jul 21 04:33 .profile drwxrwxr-x   2 root  operator   512 Jul 21 04:30 .snap -r--r--r--   1 root  wheel     6199 Jul 21 04:33 COPYRIGHT drwxr-xr-x   2 root  wheel     1024 Jul 21 04:31 bin drwxr-xr-x   8 root  wheel     1024 Jul 21 04:33 boot dr-xr-xr-x   2 root  wheel      512 Jul 21 04:30 dev drwxr-xr-x  27 root  wheel     2048 Jul 21 04:33 etc drwxr-xr-x   4 root  wheel     1536 Jul 21 04:31 lib drwxr-xr-x   3 root  wheel      512 Jul 21 04:33 libexec drwxr-xr-x   2 root  wheel      512 Jul 21 04:30 media drwxr-xr-x   2 root  wheel      512 Jul 21 04:30 mnt drwxr-xr-x   2 root  wheel      512 Jul 21 04:30 net dr-xr-xr-x   2 root  wheel      512 Jul 21 04:30 proc drwxr-xr-x   2 root  wheel     2560 Jul 21 04:31 rescue drwxr-xr-x   2 root  wheel      512 Jul 21 04:33 root drwxr-xr-x   2 root  wheel     2560 Jul 21 04:32 sbin lrwxr-xr-x   1 root  wheel       11 Jul 21 04:30 sys -> usr/src/sys drwxrwxrwt   2 root  wheel      512 Jul 21 04:30 tmp drwxr-xr-x  14 root  wheel      512 Jul 21 04:30 usr drwxr-xr-x  24 root  wheel      512 Jul 21 04:30 var Thank you both for your time. I can now do what i want. regards, Johan