gpart restore is different to gpart backup

Chris Whitehouse cwhiteh at onetel.com
Wed Feb 5 16:42:01 UTC 2014


On 04/02/2014 18:59, Warren Block wrote:
> 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.
>

Hi Warren, thanks for the suggestions.

After dd'ing the MBR from the original disk to the new one gpart shows 
no info, fdisk sees the partitions. fdisk -u to change the size of the 
last partition and rewrite the partition table, then gpart sees them. 
Also clonezilla now sees them as the correct size. So looks like gpart 
doesn't deal properly with mbr partitions?

I'll update the PR and put a link to this mail.

Last question - is there an invocation of dd which will read the last 
block of a disk without my calculating disk size and block size, then 
write that block to another disk? I thought I'd seen something like 
count=-1 but I can't find it in the man page.

Script of proceedings below.

Chris

Script started on Tue Feb  4 21:55:15 2014
root@:~ # fdisk ada0
******* Working on device /dev/ada0 *******
parameters extracted from in-core disklabel are:
cylinders=248086 heads=15 sectors/track=63 (945 blks/cyl)

Figures below won't work with BIOS for partitions not in cyl 1
parameters to be used for BIOS calculations are:
cylinders=248086 heads=15 sectors/track=63 (945 blks/cyl)

fdisk: invalid fdisk partition table found
Media sector size is 512
Warning: BIOS sector numbering starts with sector 1
Information from DOS bootblock is:
The data for partition 1 is:
sysid 165 (0xa5),(FreeBSD/NetBSD/386BSD)
     start 63, size 234441207 (114473 Meg), flag 80 (active)
         beg: cyl 0/ head 1/ sector 1;
         end: cyl 277/ head 14/ sector 63
The data for partition 2 is:
<UNUSED>
The data for partition 3 is:
<UNUSED>
The data for partition 4 is:
<UNUSED>
root@:~ # gpart show ada0
gpart: No such geom: ada0.
root@:~ # dd if=/mnt/win7mbr.bin of=/dev/ada0
1+0 records in
1+0 records out
512 bytes transferred in 0.406384 secs (1260 bytes/sec)
root@:~ # gpart show ada0
gpart: No such geom: ada0.
root@:~ # fdisk ada0
******* Working on device /dev/ada0 *******
parameters extracted from in-core disklabel are:
cylinders=248086 heads=15 sectors/track=63 (945 blks/cyl)

Figures below won't work with BIOS for partitions not in cyl 1
parameters to be used for BIOS calculations are:
cylinders=248086 heads=15 sectors/track=63 (945 blks/cyl)

Media sector size is 512
Warning: BIOS sector numbering starts with sector 1
Information from DOS bootblock is:
The data for partition 1 is:
sysid 39 (0x27),(unknown)
     start 2048, size 25165824 (12288 Meg), flag 0
         beg: cyl 0/ head 32/ sector 33;
         end: cyl 1023/ head 239/ sector 63
The data for partition 2 is:
sysid 7 (0x07),(NTFS, OS/2 HPFS, QNX-2 (16 bit) or Advanced UNIX)
     start 25167872, size 204800 (100 Meg), flag 80 (active)
         beg: cyl 1023/ head 239/ sector 63;
         end: cyl 1023/ head 239/ sector 63
The data for partition 3 is:
sysid 7 (0x07),(NTFS, OS/2 HPFS, QNX-2 (16 bit) or Advanced UNIX)
     start 25372672, size 287205376 (140237 Meg), flag 0
         beg: cyl 1023/ head 254/ sector 63;
         end: cyl 1023/ head 254/ sector 63
The data for partition 4 is:
<UNUSED>
root@:~ # fdisk -u ada0
******* Working on device /dev/ada0 *******
parameters extracted from in-core disklabel are:
cylinders=248086 heads=15 sectors/track=63 (945 blks/cyl)

Figures below won't work with BIOS for partitions not in cyl 1
parameters to be used for BIOS calculations are:
cylinders=248086 heads=15 sectors/track=63 (945 blks/cyl)

Do you want to change our idea of what BIOS thinks ? [n]
Media sector size is 512
Warning: BIOS sector numbering starts with sector 1
Information from DOS bootblock is:
The data for partition 1 is:
sysid 39 (0x27),(unknown)
     start 2048, size 25165824 (12288 Meg), flag 0
         beg: cyl 0/ head 32/ sector 33;
         end: cyl 1023/ head 239/ sector 63
Do you want to change it? [n]
The data for partition 2 is:
sysid 7 (0x07),(NTFS, OS/2 HPFS, QNX-2 (16 bit) or Advanced UNIX)
     start 25167872, size 204800 (100 Meg), flag 80 (active)
         beg: cyl 1023/ head 239/ sector 63;
         end: cyl 1023/ head 239/ sector 63
Do you want to change it? [n]
The data for partition 3 is:
sysid 7 (0x07),(NTFS, OS/2 HPFS, QNX-2 (16 bit) or Advanced UNIX)
     start 25372672, size 287205376 (140237 Meg), flag 0
         beg: cyl 1023/ head 254/ sector 63;
         end: cyl 1023/ head 254/ sector 63
Do you want to change it? [n] y
Supply a decimal value for "sysid (165=FreeBSD)" [7]
Supply a decimal value for "start" [25372672]
Supply a decimal value for "size" [287205376] 209068913
fdisk: WARNING: partition does not start on a head boundary
fdisk: WARNING: this may confuse the BIOS or some operating systems
Correct this automatically? [n] y
fdisk: WARNING: adjusting start offset of partition to 25372683
fdisk: WARNING: adjusting size of partition to 209068587
Explicitly specify beg/end address ? [n]
sysid 7 (0x07),(NTFS, OS/2 HPFS, QNX-2 (16 bit) or Advanced UNIX)
     start 25372683, size 209068587 (102084 Meg), flag 0
         beg: cyl 225/ head 6/ sector 1;
         end: cyl 277/ head 14/ sector 63
Are we happy with this entry? [n] y
The data for partition 4 is:
<UNUSED>
Do you want to change it? [n]
Partition 2 is marked active
Do you want to change the active partition? [n]

We haven't changed the partition table yet.  This is your last chance.
parameters extracted from in-core disklabel are:
cylinders=248086 heads=15 sectors/track=63 (945 blks/cyl)

Figures below won't work with BIOS for partitions not in cyl 1
parameters to be used for BIOS calculations are:
cylinders=248086 heads=15 sectors/track=63 (945 blks/cyl)

Information from DOS bootblock is:
1: sysid 39 (0x27),(unknown)
     start 2048, size 25165824 (12288 Meg), flag 0
         beg: cyl 0/ head 32/ sector 33;
         end: cyl 1023/ head 239/ sector 63
2: sysid 7 (0x07),(NTFS, OS/2 HPFS, QNX-2 (16 bit) or Advanced UNIX)
     start 25167872, size 204800 (100 Meg), flag 80 (active)
         beg: cyl 1023/ head 239/ sector 63;
         end: cyl 1023/ head 239/ sector 63
3: sysid 7 (0x07),(NTFS, OS/2 HPFS, QNX-2 (16 bit) or Advanced UNIX)
     start 25372683, size 209068587 (102084 Meg), flag 0
         beg: cyl 225/ head 6/ sector 1;
         end: cyl 277/ head 14/ sector 63
4: <UNUSED>
Should we write new partition table? [n] y
root@:~ # fdisk ada0
******* Working on device /dev/ada0 *******
parameters extracted from in-core disklabel are:
cylinders=248086 heads=15 sectors/track=63 (945 blks/cyl)

Figures below won't work with BIOS for partitions not in cyl 1
parameters to be used for BIOS calculations are:
cylinders=248086 heads=15 sectors/track=63 (945 blks/cyl)

Media sector size is 512
Warning: BIOS sector numbering starts with sector 1
Information from DOS bootblock is:
The data for partition 1 is:
sysid 39 (0x27),(unknown)
     start 2048, size 25165824 (12288 Meg), flag 0
         beg: cyl 0/ head 32/ sector 33;
         end: cyl 1023/ head 239/ sector 63
The data for partition 2 is:
sysid 7 (0x07),(NTFS, OS/2 HPFS, QNX-2 (16 bit) or Advanced UNIX)
     start 25167872, size 204800 (100 Meg), flag 80 (active)
         beg: cyl 1023/ head 239/ sector 63;
         end: cyl 1023/ head 239/ sector 63
The data for partition 3 is:
sysid 7 (0x07),(NTFS, OS/2 HPFS, QNX-2 (16 bit) or Advanced UNIX)
     start 25372683, size 209068587 (102084 Meg), flag 0
         beg: cyl 225/ head 6/ sector 1;
         end: cyl 277/ head 14/ sector 63
The data for partition 4 is:
<UNUSED>
root@:~ # gpart show ada0
=>       63  234441585  ada0  MBR  (112G)
          63       1985        - free -  (993K)
        2048   25165824     1  !39  (12G)
    25167872     204800     2  ntfs  [active]  (100M)
    25372672         11        - free -  (5.5K)
    25372683  209068587     3  ntfs  (100G)
   234441270        378        - free -  (189K)

root@:~ # exit

Script done on Tue Feb  4 22:00:17 2014



More information about the freebsd-questions mailing list