[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] qemu-img: add seek and -n option to dd command
From: |
Richard W.M. Jones |
Subject: |
Re: [PATCH] qemu-img: add seek and -n option to dd command |
Date: |
Fri, 5 Feb 2021 10:43:39 +0000 |
User-agent: |
Mutt/1.5.21 (2010-09-15) |
On Thu, Feb 04, 2021 at 02:44:03PM -0600, Eric Blake wrote:
> On 2/4/21 2:09 PM, Peter Lieven wrote:
> > Am 02.02.21 um 16:51 schrieb Eric Blake:
> >> On 1/28/21 8:07 AM, Peter Lieven wrote:
> >>> Signed-off-by: Peter Lieven <pl@kamp.de>
> >> Your commit message says 'what', but not 'why'. Generally, the one-line
> >> 'what' works well as the subject line, but you want the commit body to
> >> give an argument why your patch should be applied, rather than blank.
> >>
> >> Here's the last time we tried to improve qemu-img dd:
> >> https://lists.gnu.org/archive/html/qemu-devel/2018-08/msg02618.html
> >
> >
> > I was not aware of that story. My use case is that I want to be
> >
> > able to "patch" an image that Qemu is able to handle by overwriting
> >
> > certain sectors. And I especially do not want to "mount" that image
> >
> > via qemu-nbd because I might not trust it. I totally want to avoid that the
> > host
> >
> > system tries to analyse that image in terms of scanning the bootsector,
> > partprobe,
> >
> > lvm etc. pp.
>
> qemu-nbd does not have to mount an image (yes, one use of qemu-nbd is to
> use -c /dev/nbdX to get the kernel to mount it; but other uses are to
> expose the NBD image in user-space only with no kernel involvement, and
> therefore no system mount efforts).
I agree, there's nothing unsafe about qemu-nbd (provided you don't use
the -c option).
> Another thing you might try is libnbd, which now includes a utility
> nbdcopy. It should make it easier to overwrite a portion of an NBD
> image using only user-space actions. I'm not sure if Rich has got it
> doing partial file overwrites yet (.../me goes and compiles the latest
> git checkout... nope, still a TODO item to implement subsetting), but it
> may be possible to combine nbdkit's --filter=offset with the full NBD
> image in order to then easily point nbdcopy to only the subset you care
> about. Definitely some ideas worthy of implementation.
TBH I would use nbdsh. For example to overwrite the sector at 1M in a
qcow2 image with "1"s:
$ qemu-img create -f qcow2 test.qcow2 10M
$ nbdsh -c
'h.connect_systemd_socket_activation(["qemu-nbd","-t","-f","qcow2","test.qcow2"])'
\
-c 'h.pwrite(b"1"*512, 1024*1024)'
and to show it was really overwritten:
$ nbdcopy -- [ qemu-nbd -f qcow2 test.qcow2 ] - | hexdump -C
00000000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
*
00100000 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 |1111111111111111|
*
00100200 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
*
00a00000
Rich.
--
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
virt-df lists disk usage of guests without needing to install any
software inside the virtual machine. Supports Linux and Windows.
http://people.redhat.com/~rjones/virt-df/
- Re: [PATCH] qemu-img: add seek and -n option to dd command, David Edmondson, 2021/02/02
- Re: [PATCH] qemu-img: add seek and -n option to dd command, Eric Blake, 2021/02/02
- Re: [PATCH] qemu-img: add seek and -n option to dd command, Peter Lieven, 2021/02/04
- Re: [PATCH] qemu-img: add seek and -n option to dd command, Max Reitz, 2021/02/05
- Re: [PATCH] qemu-img: add seek and -n option to dd command, Peter Lieven, 2021/02/05
- Re: [PATCH] qemu-img: add seek and -n option to dd command, Max Reitz, 2021/02/05
- Re: [PATCH] qemu-img: add seek and -n option to dd command, Max Reitz, 2021/02/05