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 5 Days Ago
gustaf gustaf is offline
Port Guard
 
Join Date: Dec 2016
Posts: 40
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 5 Days Ago
jggimi's Avatar
jggimi jggimi is offline
More noise than signal
 
Join Date: May 2008
Location: USA
Posts: 5,973
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; 5 Days Ago at 11:57 AM. Reason: typos
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 2 Weeks Ago 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 07:44 PM.


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