# Copying partitioning to new disk



## balanga (May 14, 2017)

I'd like to copy the layout of partitions on one disk to several disks and wondered if anyone knew of a simple way to do this. I don't need to copy the contents of the partitions, just the size and type. I guess what I need is just a way of parsing the output from `gpart show da0`, but not sure how to do that...


----------



## tobik@ (May 14, 2017)

See gpart(8):


> Clone the partition table from ada0 to ada1 and ada2: `/sbin/gpart backup ada0 | /sbin/gpart restore -F ada1 ada2`


----------



## balanga (May 16, 2017)

Many thanks for this. I would not have been able to work this out from the man page. An example, such as ours is very useful.

One question though... does the above also copy any bootcode installed on the source device?


----------



## SirDice (May 16, 2017)

balanga said:


> I would not have been able to work this out from the man page. An example, such as ours is very useful.


The example is copied straight from the man page. Most man pages have an examples section at the end.


```
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

     Clone the partition table from ada0 to ada1 and ada2:

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



> does the above also copy any bootcode installed on the source device?


No, only the partition table. The bootcode is not part of the partition table.


----------



## balanga (May 16, 2017)

Oops! Should have noticed, but didn't think that `gpart` would have such an option... I think I mentioned somewhere that it must have around 100 options and is not the easiest of commands to master.

I was hoping to be able to copy a device which was set up with the Grub loader installed to a new disk, but obviously missed something. I did manage to get Grub working on one device but have been unable to repeat the process, so thought copying the partition structure, formatting and copying the first two partitions and installing grub on the new partition, using instructions I had made would work, but I obviously missed something...


----------

