Other 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)
 
Back
Top