DaemonForums  

Go Back   DaemonForums > OpenBSD > OpenBSD General

OpenBSD General Other questions regarding OpenBSD which do not fit in any of the categories below.

Reply
 
Thread Tools Display Modes
  #1   (View Single Post)  
Old 7th December 2017
gustaf gustaf is offline
Fdisk Soldier
 
Join Date: Dec 2016
Posts: 65
Default Verify integrity of disk image file written to disk ?

I have copied the file https://<local-mirror-domain-name>/pub/OpenBSD/6.2/amd64/install62.fs
to a flash drive using dd(1), according to the instrucions in /pub/OpenBSD/6.2/amd64/INSTALL.amd64.

These instructions also suggest that
Quote:
...copying the image back to a file and doing a compare or checksum is a good way to verify that the USB key is readable and free of read/write errors.
This would be relatively easy to accomplish with a reverse dd(1) if the file and the drive were the same size: $ doas dd if=/dev/rsd1c of=/path/to/install62.fs.copy bs=1m.

The problem is that /dev/rsd1c (the drive that contains the copied image) is larger than install62.fs (the original file). Any attempt to copy and compare will inevitably fail.

One possible solution is to extract the 'install62.fs' data from the drive before copying it to a file, but I can't find a command to do this.

Once I have a duplicate file, it's a simple matter of running cmp(1), sha256(1), or sha512(1) to see if the two files match.

Does anyone have any suggestions for how to copy the image on the drive back to a file so I can verify that the drive was written correctly?

I can mount the file systems and see the files, so I think it's OK, but I'd like to have some extra assurance since this is part of my emergency recovery plan.

Thanks.
Reply With Quote
  #2   (View Single Post)  
Old 7th December 2017
jggimi's Avatar
jggimi jggimi is offline
More noise than signal
 
Join Date: May 2008
Location: USA
Posts: 7,975
Default

dd(1) has a count=n option.

Example: The cd62.iso file for the amd64 -release is 9953280 bytes. This is not divisible by megabytes, but it is divisible by 8K (8192 bytes). There are 1215 8K blocks in the file. I used a 2GB vnd(4) test device, creating the 2GB sparse file that backed the device with vmctl(8) as it was convenient, as I don't have a spare USB stick at the moment.

Writing to the drive with 1MB blocks, dd() completed 9 full 1MB blocks, plus 1 partial block:
Code:
$ sha256 cd62.iso 
SHA256 (cd62.iso) = e66b406cf5775c934b04eb2c3af1f8f6f4704f67445b2dd22916a7b962a74667
$ vmctl create test.file -s 2g
vmctl: imagefile created
$ doas vnconfig vnd0 test.file 
$ doas dd if=cd62.iso of=/dev/rvnd0c bs=1m
9+1 records in
9+1 records out
9953280 bytes transferred in 0.149 secs (66761325 bytes/sec)
Testing the resulting data written to the drive, I used a 1215 count with an 8K block size. The sha256(1) hash was identical.
Code:
                 
$ doas dd if=/dev/rvnd0c bs=8192 count=1215 | sha256
1215+0 records in
1215+0 records out
9953280 bytes transferred in 0.340 secs (29257170 bytes/sec)
e66b406cf5775c934b04eb2c3af1f8f6f4704f67445b2dd22916a7b962a74667

Last edited by jggimi; 7th December 2017 at 11:57 AM. Reason: typos
Reply With Quote
  #3   (View Single Post)  
Old 14th December 2017
gustaf gustaf is offline
Fdisk Soldier
 
Join Date: Dec 2016
Posts: 65
Default

Hi jggimi,

Thanks for the example. I missed the count=n option when I read dd(1).

It turns out that this drive wasn't actually written correctly, in spite of the fact that it appeared OK on visual inspection.

The initial sha256(1) checksum comparison failed. Running cmp(1) revealed 40 errors.

I re-wrote the drive and now the checksums match.

Lesson: Appearances are deceiving. If byte-for-byte accuracy is important, run a checksum.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to get % written in file copy operation? Prevet OpenBSD General 6 26th November 2017 10:33 AM
disk mgt and zfs ananix FreeBSD General 1 26th December 2011 10:37 PM
Disk > 100% Weaseal FreeBSD General 3 11th February 2009 05:50 PM
Disk geometry for Seagate disk phreud FreeBSD Installation and Upgrading 5 8th November 2008 10:51 PM
backup drive to image file milo974 OpenBSD General 8 14th August 2008 02:01 PM


All times are GMT. The time now is 06:07 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Content copyright © 2007-2010, the authors
Daemon image copyright ©1988, Marshall Kirk McKusick