Solved gpart backup and restore not work?

Hi,
I'm trying to duplicate a installer on a USB stick...

---------------------------------------------------------------------------------
Prior to FreeBSD 14.1

I have used this procedure in the past on older versions of FreeBSD without problems, for example to duplicate a MacOS installation media...


# gpart show da0

Code:
=>      63  60604353  da0  MBR  (29G)
        63    109761       - free -  (54M)
    109824  60494592    1  apple-hfs  [active]  (29G)


# gpart show da1

Code:
gpart: No such geom: da1.


# gpart backup da0 | gpart restore -F da1



# gpart show da1

Code:
=>      63  60604353  da1  MBR  (29G)
        63    109761       - free -  (54M)
    109824  60494592    1  apple-hfs  [active]  (29G)


# dd if=/dev/da0 of=/dev/da1 bs=64K conv=noerror,sync status=progress

Code:
  226492416 bytes (226 MB, 216 MiB) transferred 17.254s, 13 MB/s
[...]
148607+0 records in
148607+0 records out
9739108352 bytes transferred in 917.596735 secs (10613713 bytes/sec)
dd: /dev/da0: Device not configured
[...]
308554+0 records in
308554+0 records out
20221394944 bytes transferred in 1833.343824 secs (11029789 bytes/sec)

The da1 disk could be used to install the Operating System without problems...

---------------------------------------------------------------------------------
Now on FreeBSD 14.1


# freebsd-version

Code:
14.1-RELEASE-p3

I try to do the same procedure to duplicate a installer on a USB stick with and it doesn't work


# gpart show da0

Code:
=>       1  30297215  da0  MBR  (14G)
         1     66584    1  efi  (33M)
     66585   2668176    2  freebsd  [active]  (1.3G)
   2734761  27562455       - free -  (13G)


# gpart show da1

Code:
gpart: No such geom: da1.


# gpart backup da0 | gpart restore -F da1

Code:
gpart: start '1': Invalid argument

Does anyone know why the procedure no longer works?

Note:
In this case I'm testing by a FreeBSD installer, but the procedure should work the way it did with the MacOS installer.

Thanks for any advice or ideas!
 
If the new usb stick doesn't have a partitioning scheme on it already (because it is blank, or partitioned a different way) you get that.
Make sure that the new stick is the correct one and try gpart create - S GPT da1. Double check that da1 (hint: messages) is the one you want first.
 
tingo


# camcontrol devlist | grep Kingston

Code:
<Kingston DataTraveler 2.0 1.00>   at scbus5 target 0 lun 0 (da0,pass3)
<Kingston DataTraveler 2.0 1.00>   at scbus6 target 0 lun 0 (da1,pass4)


# gpart show da0

Code:
=>       1  30297215  da0  MBR  (14G)
         1     66584    1  efi  (33M)
     66585   2668176    2  freebsd  [active]  (1.3G)
   2734761  27562455       - free -  (13G)


# gpart show da1

Code:
gpart: No such geom: da1.

---------------------------------------------------------------------------------
Try one (MBR)


# gpart create -s MBR da1

Code:
da1 created


# gpart show da1

Code:
=>      63  30297153  da1  MBR  (14G)
        63  30297153       - free -  (14G)


# gpart backup da0 | gpart restore -F da1

Code:
gpart: start '1': Invalid argument


# gpart destroy -F da1

Code:
da1 destroyed

---------------------------------------------------------------------------------
Try two (GPT)


# gpart create -s GPT da1

Code:
da1 created


# gpart show da1

Code:
=>      40  30297136  da1  GPT  (14G)
        40  30297136       - free -  (14G)


# gpart backup da0 | gpart restore -F da1

Code:
gpart: start '1': Invalid argument


# gpart destroy -F da1

Code:
da1 destroyed

It doesn't work with either the MBR partition or the GPT partition.

I think that the idea of creating the partitions using the da0 scheme to replicate it in da1 is precisely if there are no partitions in da1
 
I want to ask if you realize that gpart backup is only for the Boot Sector.

If you are 'duplicating' some media why would you need to back anything up?

dd does a 1 to 1 copy of everything. Including the boot sector.

Am I missing something here? Why are you backing up bootsector to duplicate medium?
 
# gpart backup da0 | gpart restore -F da1

Code:
gpart: start '1': Invalid argument
Does anyone know why the procedure no longer works?
I am not doubting that it does not work but why the pipe?
Separate the problem into two commands.
Backup the bootsector (into a proper file) and then restore it.

I am not sure a pipe is appropiate here. You write to file and restore. That is the gist.

See example in manual:
Code:
Backup and Restore
       Create a    backup of the partition    table from da0:

         /sbin/gpart backup    da0 > da0.backup

       Restore the partition table from    the backup to da0:

         /sbin/gpart restore -l da0    < /mnt/da0.backup
 
Phishfry

In the past I needed to replace a bad HDD with a good one and I recreated the partitions like this:

Working HDD, part of the array, view the partition scheme

# gpart show ada1

Code:
=>        40  5860533088  ada1  GPT  (2.7T)
          40        1024     1  freebsd-boot  (512K)
        1064         984        - free -  (492K)
        2048    16777216     2  freebsd-swap  (8.0G)
    16779264  5843752960     3  freebsd-zfs  (2.7T)
  5860532224         904        - free -  (452K)

The new HDD, destroy the partition scheme (if exist)

# gpart destroy -F ada3


Copy partition scheme from an existing disk (ada1) to new disk (ada3)

# gpart backup ada1 | gpart restore -F ada3 # <- HERE WORK OK!


To view the new partition scheme on ada3

# gpart show ada3

Code:
=>        40  5860533088  ada3  GPT  (2.7T)
          40        1024     1  freebsd-boot  (512K)
        1064         984        - free -  (492K)
        2048    16777216     2  freebsd-swap  (8.0G)
    16779264  5843752960     3  freebsd-zfs  (2.7T)
  5860532224         904        - free -  (452K)

gpart backup and restore worked fine, the above recreated the partition table on the new disk ada3 from ada1


Now I'm in a similar case, but instead of HDD, it's on a USB stick with a partition scheme

Suppose I have da0 with an recovery of any Operating System and I want to duplicate that installer on da1

By example USB (HP Recovery Manager) have this:


# gpart show da0

Code:
=>      63  30310337  da0  MBR  (14G)
        63      1985       - free -  (993K)
      2048  30298112    1  fat32lba  [active]  (14G)
  30300160     10240       - free -  (5.0M)

I want to clone that installer on da1


# gpart show da1

Code:
gpart: No such geom: da1.


# gpart backup da0 | gpart restore -F da1 # <- NOT WORK!

Code:
gpart: start '1': Invalid argument


# gpart show da1

Code:
# gpart show da1
gpart: No such geom: da1.


# dd if=/dev/da0 of=/dev/da1 bs=64K conv=noerror,sync status=progress

Code:
dd: /dev/da1: end of device 14 GiB) transferred 3297.006s, 4705 kB/s  

236698+0 records in
236697+0 records out
15512174592 bytes transferred in 3297.094143 secs (4704802 bytes/sec)


# gpart show da1

Code:
# gpart show da1
gpart: No such geom: da1.
 
# gpart backup da0 | gpart restore -F da1 # <- NOT WORK!
Break it apart. Pipe could be shell dependant problem. Very small file just save it out first. Then try restore.
Right now you cannot tell which part of the pipe is failing correct?
Do it separate just like manual. Then if error maybe a bug. Pipe can introduce problems.
 
Phishfry


# camcontrol devlist | grep Kingston

Code:
<Kingston DataTraveler 2.0 1.00>   at scbus5 target 0 lun 0 (da0,pass3)
<Kingston DataTraveler 2.0 1.00>   at scbus6 target 0 lun 0 (da1,pass4)


# gpart destroy -F da0
# gpart destroy -F da1



# dd if=/tmp/FreeBSD-14.1-RELEASE-amd64-memstick.img of=/dev/da0 bs=1m conv=sync status=progress

Code:
  1397751808 bytes (1398 MB, 1333 MiB) transferred 265.023s, 5274 kB/s
1336+0 records in
1336+0 records out
1400897536 bytes transferred in 265.414381 secs (5278152 bytes/sec)


# gpart show da0

Code:
=>       1  30297215  da0  MBR  (14G)
         1     66584    1  efi  (33M)
     66585   2668176    2  freebsd  [active]  (1.3G)
   2734761  27562455       - free -  (13G)

gpart without the pipe


# gpart backup da0 > /tmp/config.txt



# cat /tmp/config.txt

Code:
MBR 4
1     efi        1    66584  
2 freebsd    66585  2668176   [active]


# gpart restore da1 < /tmp/config.txt

Code:
gpart: start '1': Invalid argument
 
That file output suprises me. I would not expect such plain text.

This post uses fdisk to capture partition table and gpart restore . Give this a method a whirl:


So it seems gpart backup is not working with MBR correctly but is working with GPT for you?

I see additional flags in manual and above post.

gpart restore -l -F
 
Phishfry

I try this:


# fdisk -i -f /tmp/fdisk_da0.txt /dev/da0

Code:
******* Working on device /dev/da0 *******


# gpart restore -lF da1 < /tmp/fdisk_da0.txt

Code:
-su: cannot open /tmp/fdisk_da0.txt: No such file or directory


# ls /tmp/fdisk_da0.txt

Code:
ls: /tmp/fdisk_da0.txt: No such file or directory

(Homer Simpson tearing his hair out)
 
VladiBG

Testing on the same USB stick!


# camcontrol devlist | grep Kingston

Code:
<Kingston DataTraveler 2.0 1.00>   at scbus5 target 0 lun 0 (da0,pass3)


# gpart show da0

Code:
=>       1  30297215  da0  MBR  (14G)
         1     66584    1  efi  (33M)
     66585   2668176    2  freebsd  [active]  (1.3G)
   2734761  27562455       - free -  (13G)


# gpart backup da0 > /tmp/config.txt



# cat /tmp/config.txt

Code:
MBR 4
1     efi        1    66584 
2 freebsd    66585  2668176   [active]


# gpart destroy -F da0

Code:
da0 destroyed


# gpart show da0

Code:
gpart: No such geom: da0.


# gpart restore da0 < /tmp/config.txt

Code:
gpart: start '1': Invalid argument
 
use gpart create -s mbr da0 then check the output of gpart show da0 and see which is the first sector which the firmware report. If it start from 63 then when you are trying to restore it will use gpart add -t freebsd -b 1 -s 34091520B which will return error for the invalid start location. This is because the drive wasn't created with this version of gpart but with another utility or system where it actually report itself with different initial sector.

Edit:
maybe it was created with fdisk / bsdlabel?
 
VladiBG


# geom disk list da0

Code:
Geom name: da0
Providers:
1. Name: da0
   Mediasize: 15512174592 (14G)
   Sectorsize: 512
   Mode: r0w0e0
   descr: Kingston DataTraveler 2.0
   ident: C86000BDB740CE803A276D5F
   rotationrate: unknown
   fwsectors: 63
   fwheads: 255


# gpart destroy -F da0

Code:
gpart: arg0 'da0': Invalid argument


# gpart create -s mbr da0

Code:
da0 created


# gpart show da0

Code:
=>      63  30297153  da0  MBR  (14G)
        63  30297153       - free -  (14G)


# gpart add -t freebsd -b 1 -s 34091520B da0

Code:
gpart: start '1': Invalid argument
 
yes this is because the start location with "-b 1" is invalid it should be 63
for example
gpart -add -t freebsd da0
(this will align the partition at 4k with maximum size to the entire disk)
or
gpart -add -t freebsd -b 63 -s 1G
(this will create partition starting from 63 with size of 1GB) but it will give you a warning that the partition is not aligned)
As you see after you create MBR the starting point for the first partition is 63 and before it was reporting itself as 1

1 30297215 da0 MBR (14G)

63 30297153 da0 MBR (14G)

That's why you can't restore it when you backup it first as you can't create again the same partition starting from 1

I don't know where are you going to use this disk but i recommend instead of MBR with freebsd slices to start using GPT with EFI and freebsd-ufs or ZFS
 
VladiBG


# camcontrol devlist | grep Kingston

Code:
<Kingston DataTraveler 2.0 1.00>   at scbus5 target 0 lun 0 (da0,pass3)
<Kingston DataTraveler 2.0 1.00>   at scbus6 target 0 lun 0 (da1,pass4)


# gpart destroy -F da0

Code:
da0 destroyed


# gpart create -s GPT da0

Code:
da0 created


# gpart show da0

Code:
=>      40  30297136  da0  GPT  (14G)
        40  30297136       - free -  (14G)


# gpart add -t freebsd da0

Code:
da0s1 added


# gpart show da0

Code:
=>      40  30297136  da0  GPT  (14G)
        40  30297136    1  freebsd  (14G)


# gpart backup da0 > /tmp/config.txt



# cat /tmp/config.txt

Code:
GPT 128
1   freebsd       40 30297136


# gpart destroy -F da0

Code:
da0 destroyed


# gpart show da0

Code:
gpart: No such geom: da0.


# gpart restore da0 < /tmp/config.txt



# gpart show da0

Code:
=>      34  30297149  da0  GPT  (14G)
        34         6       - free -  (3.0K)
        40  30297136    1  freebsd  (14G)
  30297176         7       - free -  (3.5K)


# gpart show da1

Code:
gpart: No such geom: da1.


# gpart backup da0 | gpart restore -F da1



# gpart show da1

Code:
=>      34  30297149  da1  GPT  (14G)
        34         6       - free -  (3.0K)
        40  30297136    1  freebsd  (14G)
  30297176         7       - free -  (3.5K)


# gpart destroy -F da1

Code:
da1 destroyed


# gpart show da1

Code:
gpart: No such geom: da1.


# gpart restore da1 < /tmp/config.txt



# gpart show da1

Code:
=>      34  30297149  da1  GPT  (14G)
        34         6       - free -  (3.0K)
        40  30297136    1  freebsd  (14G)
  30297176         7       - free -  (3.5K)

Apparently gpart backup and restore works fine if the disk is in GPT, but if it is in MBR it doesn't work?
 
it works with MBR too but see how one of the disk start from 40 and other from 34 so if you try other way around to restore the partition which start from 34 to the disk with report itself to start 40 it will give you error of invalid start 34

Also don't use freebsd as partition type in GPT it's for bsdlabel slices in MBR. Instead use freebsd-ufs or if this is portable USB then use FAT32
 
VladiBG

On the same disk gpart backup and restore does not work if it is in MBR according to my tests

from the man gpart:

Clone the partition table from ada0 to ada1 and ada2:

/sbin/gpart backup ada0 | /sbin/gpart restore -F ada1 ada2

Or it requires adding other parameters that I don't know about.

The reason is to recreate a USB flash drive to restore HP Windows computers. The restore creates the flash drive with MBR and those partitions.
 
gpart backup / restore is not the tool to create clone of the USB flash drive. Instead you should use the original HP tool which created the USB bootable flash like HP Cloud Recovery Tool or HP USB Recovery Flash Disk Utility depending what was the original one.
 
VladiBG

HP Recovery Manager only allow to create the recovery one time, if you usb memory fail you no have the option of create another.

1729688029754.png


For this reason I am looking for a way to save the content of that USB memory in a .img and then save it in a safe place (sometimes it happened to me that during the restoration process with the USB memory, the memory gets damaged).

That's why my approach was with gpart and dd, but it didn't work, I'll look at other tools!
 
VladiBG

Thank you very much for all your help, I have looked at similar tutorials, but if you change the HDD to an SSD the recovery tool does not exist on the new SSD.

This is why it is still necessary to find a way to save an image for the USB stick.

I'm telling you this from my own experience...

At my work we have several HPs, in the first one we created the recovery memory and with it we reinstalled the System in the following computers replacing the old HDDs with new SSDs, but almost at the end of the process the recovery USB memory died and in the last computer we were able to recreate the USB memory again, but if that recovery USB memory also dies I'm screwed.

I think we can close this topic, for now I'm trying to recreate the recovery USB stick by creating the partitions manually and synchronizing its content with rsync to see what happens, if that doesn't work, I'm thinking of looking for example with CloneZilla and trying to create an image of the USB stick.

Thanks again to everyone for their interest and help!
 
Final solution!

gpart and tar

-------------------------------------------------------------------------------
Creating the backup

Connect the memory created from the HP utility


# camcontrol devlist | grep Kingston

Code:
<Kingston DataTraveler 2.0 1.00>   at scbus5 target 0 lun 0 (da0,pass3)


# gpart show da0

Code:
=>      63  30310337  da0  MBR  (14G)
        63      1985       - free -  (993K)
      2048  30298112    1  fat32lba  [active]  (14G)
  30300160     10240       - free -  (5.0M)


# mount -o -l -t msdos /dev/da0s1 /mnt



# ls /mnt

Code:
$MfeDeepRem                hp                    install21.swm                install34.swm
EFI                    install.swm                install22.swm                install35.swm
[...]


# tar -cvzf /tmp/HP-Recovery-Manager.tar.gz /mnt

Code:
tar: Removing leading '/' from member names
a mnt
a mnt/System Volume Information
[...]


# umount /mnt



# du -h /tmp/HP-Recovery-Manager.tar.gz

Code:
 12G    /tmp/HP-Recovery-Manager.tar.gz

Save the file in a safe place

-------------------------------------------------------------------------------
Restoring the backup

Connect the empty memory where the backup will be restored


# gpart destroy -F da0

Code:
da0 destroyed


# gpart show da0

Code:
gpart: No such geom: da1.


# gpart create -s MBR da0

Code:
da0 created


# gpart show da0

Code:
=>      63  30297153  da0  MBR  (14G)
        63  30297153       - free -  (14G)


# gpart add -t fat32lba -b 1M -s 14G da0

Code:
da0s1 added


# gpart show da0

Code:
=>      63  30297153  da0  MBR  (14G)
        63      1985       - free -  (993K)
      2048  29360128    1  fat32lba  (14G)
  29362176    935040       - free -  (457M)


# gpart set -a active -i 1 /dev/da0

Code:
active set on da0s1


# gpart show da0

Code:
=>      63  30297153  da0  MBR  (14G)
        63      1985       - free -  (993K)
      2048  29360128    1  fat32lba  [active]  (14G)
  29362176    935040       - free -  (457M)


# newfs_msdos -F32 /dev/da0s1

Code:
/dev/da0s1: 29352896 sectors in 458639 FAT32 clusters (32768 bytes/cluster)
BytesPerSec=512 SecPerClust=64 ResSectors=32 FATs=2 Media=0xf0 SecPerTrack=63 Heads=255 HiddenSecs=0 HugeSectors=29360128 FATsecs=3584 RootCluster=2 FSInfo=1 Backup=2


# mount -o -l -t msdos /dev/da0s1 /mnt



# tar -xvzf /tmp/HP-Recovery-Manager.tar.gz -C /mnt --strip-components 1

Code:
x mnt/System Volume Information
x mnt/install35.swm
[...]


# ls /mnt

Code:
$MfeDeepRem                hp                    install21.swm                install34.swm
EFI                    install.swm                install22.swm                install35.swm
[...]


# umount /mnt


Done, the new memory is ready to restore an HP computer!
 
Back
Top