From owner-freebsd-bugs@FreeBSD.ORG Tue Jan 2 21:50:34 2007 Return-Path: X-Original-To: freebsd-bugs@hub.freebsd.org Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id EBB3116A522 for ; Tue, 2 Jan 2007 21:50:33 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [69.147.83.40]) by mx1.freebsd.org (Postfix) with ESMTP id CCF1B13C46A for ; Tue, 2 Jan 2007 21:50:33 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.13.4/8.13.4) with ESMTP id l02LoXOQ070835 for ; Tue, 2 Jan 2007 21:50:33 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.13.4/8.13.4/Submit) id l02LoXi5070834; Tue, 2 Jan 2007 21:50:33 GMT (envelope-from gnats) Resent-Date: Tue, 2 Jan 2007 21:50:33 GMT Resent-Message-Id: <200701022150.l02LoXi5070834@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, James Risner Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 1036716A40F for ; Tue, 2 Jan 2007 21:48:40 +0000 (UTC) (envelope-from nobody@FreeBSD.org) Received: from www.freebsd.org (www.freebsd.org [69.147.83.33]) by mx1.freebsd.org (Postfix) with ESMTP id E9DFB13C43E for ; Tue, 2 Jan 2007 21:48:39 +0000 (UTC) (envelope-from nobody@FreeBSD.org) Received: from www.freebsd.org (localhost [127.0.0.1]) by www.freebsd.org (8.13.1/8.13.1) with ESMTP id l02LmdvM092891 for ; Tue, 2 Jan 2007 21:48:39 GMT (envelope-from nobody@www.freebsd.org) Received: (from nobody@localhost) by www.freebsd.org (8.13.1/8.13.1/Submit) id l02Lmdad092890; Tue, 2 Jan 2007 21:48:39 GMT (envelope-from nobody) Message-Id: <200701022148.l02Lmdad092890@www.freebsd.org> Date: Tue, 2 Jan 2007 21:48:39 GMT From: James Risner To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-3.0 Cc: Subject: misc/107443: dd fails to copy from disk to disk when bad sectors are involved X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 02 Jan 2007 21:50:34 -0000 >Number: 107443 >Category: misc >Synopsis: dd fails to copy from disk to disk when bad sectors are involved >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Tue Jan 02 21:50:33 GMT 2007 >Closed-Date: >Last-Modified: >Originator: James Risner >Release: 5.5 and 6.2 >Organization: OpenWorld, Inc >Environment: FreeBSD akira.stdio.com 6.2-PRERELEASE FreeBSD 6.2-PRERELEASE #2: Mon Sep 11 10:55:57 EDT 2006 risner@akira.stdio.com:/usr/obj/usr/src/sys/AKIRA i386 >Description: I have had this problem multiple times over the years. I am unwise because I run drives with no redundancy until they have bad sectors, then copy the data from one drive to another (usually with dd.) I first ran into the "you can not correctly copy disk to disk" problem with this ticket: bin/22347: dd copies incorrect data after 2^32 bytes and I/O error In that case, I solved the problem with a simple patch to dd source. When that ticket was closed, I assumed the problem was fixed. I recently had another disk fail and copied the disk with dd: Fdisk and partitioned the destination disk correctly. dd if=/dev/ad0s1a bs=512 of=/dev/ad1s1a conv=noerror,sync That partition was 8 gigabytes. The approximately 2000 bad sectors cause the end result to be shifted down 4096 bytes. By this I mean if I examined (with hexdump) a region of the partiton (/dev/ad1s1a) around 7 gb into the partition, it was not aligned to the source (/dev/ad0s1a). This alignment problem means that fsck can not find the superblocks and all superblocks don't match (due to the alignment shift.) I solved this problem by writing my own tiny dd program: #include #include char *src = "/dev/ad0s1a"; int fsrc; char *dst = "/dev/ad1s1a"; int fdst; char buf[256]; main() { int flen = 16777216; // size of partition size_t i, ret; fsrc = open(src, O_RDONLY); if (fsrc < 0) { perror("open src"); exit(1); } fcntl(fsrc, F_SETFL, O_NONBLOCK); fdst = open(dst, O_WRONLY); if (fdst < 0) { perror("open dst"); exit(1); } fcntl(fdst, F_SETFL, O_NONBLOCK); printf("fsrc = %d, fdst = %d\n", fsrc, fdst); for (i=0; iHow-To-Repeat: Find a failed drive with many bad sectors larger than 2 gb. Copy from the failed drive to a new drive using dd on FreeBSD. >Fix: I have no idea. My current fix was to use my tiny rdd program that I hand write on the spot when I identified the reason the new disk could not fsck was that the data was not aligned properly in the destination. It seems when there are disk errors in the src, dd gets confused about the dst pointer and does not advance properly even with "sync" conversion? >Release-Note: >Audit-Trail: >Unformatted: