Creating detached dm-integrity hashes for existing disk
Ciprian Craciun <[email protected]>
| Newsgroups | dev.linux.lists.cryptsetup |
|---|---|
| Message-ID | <CA+Tk8fwf2tH=ZWrpH=hn0NoKM8U-sWDnm6MUZUYV-JLLHozP_Q@mail.gmail.com> |
Hello all! (Please keep me in CC, as I'm not subscribed to the mailing list.)
I already have a large disk containing important data (backup data)
and I would like to use `dm-integrity` (with meta-data on a separate
device) to make sure that when reading from that disk I actually get
the original, non-corrupted, data. (It seems that just the SATA
provided CRC isn't enough sometime with a problematic USB-to-SATA
adapter, and I get successful reads with corrupted data.)
Thus, I've tried using `integritysetup format` with `--no-wipe`,
`--data-device` and `--integrity-bitmap-mode`, and then
`integritysetup open` with `--integrity-recalculate`. However upon
subsequent `integritysetup open` without the recalculate flag, the
`dump` command still shows the recalculating flag. Searching on the
internet about this I've found only a few issues about this, but no
actual solution or more insight.
As such my question: is there a way to actually force `dm-integrity`
to compute the hashes without wiping my original data?
Here are the snippets I've tried (on blank files via loop devices):
# create empty files
truncate --size 4GiB -- /tmp/dm-integrity-tests-data
truncate --size 512MiB -- /tmp/dm-integrity-tests-meta
# fill the data with something to make sure dm-integrity doesn't touch
the original data
dd if=/dev/urandom of=/tmp/dm-integrity-tests-data bs=1M count=128
iflag=fullblock status=progress
# compute a hash of the original data
md5sum -b -- /tmp/dm-integrity-tests-data /tmp/dm-integrity-tests-meta
# the data is loop0, and the meta-data is loop1
losetup --show --sector-size 4096 --find /tmp/dm-integrity-tests-data
losetup --show --sector-size 4096 --find /tmp/dm-integrity-tests-meta
# format, but DO NOT TOUCH the original data
# both the bitmap and hash should use 4096 bytes
integritysetup format \
--batch-mode \
--verbose \
--no-wipe \
--sector-size 4096 \
--integrity sha256 \
--integrity-bitmap-mode \
--bitmap-sectors-per-bit 8 \
--data-device /dev/loop0 \
-- \
/dev/loop1 \
#
# open, requesting a recalculation of the hashes
integritysetup open \
--verbose \
--integrity sha256 \
--data-device /dev/loop0 \
--integrity-recalculate \
-- \
/dev/loop1 \
dm-integrity-tests \
#
# read the target, checking if we get our original data
dd if=/dev/mapper/dm-integrity-tests bs=1M iflag=fullblock status=progress \
| md5sum -b
integritysetup close dm-integrity-tests
# open, without the recalculation flag
integritysetup open \
--verbose \
--integrity sha256 \
--data-device /dev/loop0 \
-- \
/dev/loop1 \
dm-integrity-tests \
#
integritysetup close dm-integrity-tests
# recalculation still shows up
integritysetup dump -- /tmp/dm-integrity-tests-meta
Am I missing something? Shouldn't the recalculation flag disappear?
Thanks,
Ciprian.