From owner-freebsd-questions@FreeBSD.ORG Tue Feb 4 18:59:33 2014 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id BAF3F288 for ; Tue, 4 Feb 2014 18:59:33 +0000 (UTC) Received: from wonkity.com (wonkity.com [67.158.26.137]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 639AC1D2B for ; Tue, 4 Feb 2014 18:59:33 +0000 (UTC) Received: from wonkity.com (localhost [127.0.0.1]) by wonkity.com (8.14.7/8.14.7) with ESMTP id s14IxVQd039161; Tue, 4 Feb 2014 11:59:31 -0700 (MST) (envelope-from wblock@wonkity.com) Received: from localhost (wblock@localhost) by wonkity.com (8.14.7/8.14.7/Submit) with ESMTP id s14IxU7p039158; Tue, 4 Feb 2014 11:59:31 -0700 (MST) (envelope-from wblock@wonkity.com) Date: Tue, 4 Feb 2014 11:59:30 -0700 (MST) From: Warren Block To: Chris Whitehouse Subject: Re: gpart restore is different to gpart backup In-Reply-To: <52F127C2.4050201@onetel.com> Message-ID: References: <52F127C2.4050201@onetel.com> User-Agent: Alpine 2.00 (BSF 1167 2008-08-23) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.4.3 (wonkity.com [127.0.0.1]); Tue, 04 Feb 2014 11:59:31 -0700 (MST) Cc: User Questions X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 04 Feb 2014 18:59:33 -0000 On Tue, 4 Feb 2014, Chris Whitehouse wrote: > Hi, > > I have two disks, one with a Windows 7 installation which includes a recovery > partition. I saved the recovery partition with Clonezilla and then attempted > to duplicate the partition scheme with gpart backup and restore. > > The original Win7 disk is 160gb, the replacement is 120gb. > > Booting from FreeBSD 10 usb flash drive I did > > # gpart backup ada0 > /mnt/gpart_backup_ada0.txt > > Next I created gpart_restore_ada0.txt from gpart_backup_ada0.txt with the > size of the last partition reduced to allow for the size difference between > the disks. > > I swapped disks and did the following > > Script started on Tue Feb 4 17:03:38 2014 > root@:~ # gpart show ada0 > gpart: No such geom: ada0. > root@:~ # cat /mnt/gpart_show_ada0.txt ## this is the Win7 setup. > => 63 312581745 ada0 MBR (149G) > 63 1985 - free - (993K) > 2048 25165824 1 !39 (12G) > 25167872 204800 2 ntfs [active] (100M) > 25372672 287205376 3 ntfs (137G) > 312578048 3760 - free - (1.8M) This is a standard Windows setup. The !39 partition starts at block 2048, or 1M. This is a good spot to start the first data partition for a number of reasons: 4K disks, SSDs, RAID controller metadata. > root@:~ # cat /mnt/gpart_restore_ada0.txt > MBR 4 > 1 !39 2048 25165824 > 2 ntfs 25167872 204800 [active] > 3 ntfs 25372672 209068913 > root@:~ # gpart restore ada0 < /mnt/gpart_restore_ada0.txt > root@:~ # gpart show ada0 ## this is the restored setup. > => 63 234441585 ada0 MBR (112G) > 63 2016 - free - (1.0M) > 2079 25165791 1 !39 (12G) > 25167870 63 - free - (32K) > 25167933 204687 2 ntfs [active] (100M) > 25372620 63 - free - (32K) > 25372683 209068902 3 ntfs (100G) > 234441585 63 - free - (32K) The MBR standard says that partitions should start on even multiples of CHS values. 2079 is an even multiple of the standard 63 blocks per track (S) value. At present, gpart uses kernel routines that enforce the CHS standards when writing an MBR, and there is no way to override that (and no warning message). There is a PR for this: http://www.freebsd.org/cgi/query-pr.cgi?pr=bin/169542 You might want to add to that. For a workaround, two ways come to mind. 1: use dd(1) to copy the MBR to the second disk, then edit it with gpart. gpart may refuse to edit it, because the last partition goes past the end of the disk. In that case, fdisk(8) might be able to edit it. 2: use fdisk(8) to create the new MBR from scratch. Bootcode might be difficult. > There's a further issue that on trying to restore Clonezilla thinks the 12G > partition is 2885MB. No idea on that.