6 replaced http://unix.stackexchange.com/ with https://unix.stackexchange.com/
source | link

It depends if your source disk uses an MBR (aka "dos" or "msdos") or a GPT (aka "GUID") partition table.

Disks over 2 TB cannot use MBR, so they are GPT.

Disks under 2 TB can use both, so you will have to first find out which it is.

Assuming you are on Linux, use either of these commands to find out which partition table your source disk uses:

disk=/dev/sda

# Always available, but old versions may not recognize gpt
fdisk -l $disk | grep type

# `apt-get install gdisk` or equivalent on non-Debian systems
gdisk -l $disk | grep -A4 'scan'

# `apt-get install parted`
parted $disk print | grep Table

Given

source=/dev/sda
dest=/dev/sdb

For MBR disks

use sfdisk as suggested by Petr Uzel's answer, or this variant:

# Save MBR disks
sfdisk -d $source > /partitions-backup-$(basename $source).sfdisk
sfdisk -d $dest   > /partitions-backup-$(basename $dest).sfdisk

# Copy $source layout to $dest
sfdisk -d $source | sfdisk $dest

For GPT disks

The correct answer was given here and herehere by Kris HarperKris Harper.

You need GPT fdisk. Look at the download page or run sudo apt-get install gdisk.

Then use the sgdisk command:

# Save MBR disks
sgdisk --backup=/partitions-backup-$(basename $source).sgdisk $source
sgdisk --backup=/partitions-backup-$(basename $dest).sgdisk $dest

# Copy $source layout to $dest and regenerate GUIDs
sgdisk --replicate=$dest $source
sgdisk -G $dest

The last command randomizes the GUID on the disk and all the partitions. This is only necessary if the disks are to be used in the same machine, otherwise it's unnecessary.

It depends if your source disk uses an MBR (aka "dos" or "msdos") or a GPT (aka "GUID") partition table.

Disks over 2 TB cannot use MBR, so they are GPT.

Disks under 2 TB can use both, so you will have to first find out which it is.

Assuming you are on Linux, use either of these commands to find out which partition table your source disk uses:

disk=/dev/sda

# Always available, but old versions may not recognize gpt
fdisk -l $disk | grep type

# `apt-get install gdisk` or equivalent on non-Debian systems
gdisk -l $disk | grep -A4 'scan'

# `apt-get install parted`
parted $disk print | grep Table

Given

source=/dev/sda
dest=/dev/sdb

For MBR disks

use sfdisk as suggested by Petr Uzel's answer, or this variant:

# Save MBR disks
sfdisk -d $source > /partitions-backup-$(basename $source).sfdisk
sfdisk -d $dest   > /partitions-backup-$(basename $dest).sfdisk

# Copy $source layout to $dest
sfdisk -d $source | sfdisk $dest

For GPT disks

The correct answer was given here and here by Kris Harper.

You need GPT fdisk. Look at the download page or run sudo apt-get install gdisk.

Then use the sgdisk command:

# Save MBR disks
sgdisk --backup=/partitions-backup-$(basename $source).sgdisk $source
sgdisk --backup=/partitions-backup-$(basename $dest).sgdisk $dest

# Copy $source layout to $dest and regenerate GUIDs
sgdisk --replicate=$dest $source
sgdisk -G $dest

The last command randomizes the GUID on the disk and all the partitions. This is only necessary if the disks are to be used in the same machine, otherwise it's unnecessary.

It depends if your source disk uses an MBR (aka "dos" or "msdos") or a GPT (aka "GUID") partition table.

Disks over 2 TB cannot use MBR, so they are GPT.

Disks under 2 TB can use both, so you will have to first find out which it is.

Assuming you are on Linux, use either of these commands to find out which partition table your source disk uses:

disk=/dev/sda

# Always available, but old versions may not recognize gpt
fdisk -l $disk | grep type

# `apt-get install gdisk` or equivalent on non-Debian systems
gdisk -l $disk | grep -A4 'scan'

# `apt-get install parted`
parted $disk print | grep Table

Given

source=/dev/sda
dest=/dev/sdb

For MBR disks

use sfdisk as suggested by Petr Uzel's answer, or this variant:

# Save MBR disks
sfdisk -d $source > /partitions-backup-$(basename $source).sfdisk
sfdisk -d $dest   > /partitions-backup-$(basename $dest).sfdisk

# Copy $source layout to $dest
sfdisk -d $source | sfdisk $dest

For GPT disks

The correct answer was given here and here by Kris Harper.

You need GPT fdisk. Look at the download page or run sudo apt-get install gdisk.

Then use the sgdisk command:

# Save MBR disks
sgdisk --backup=/partitions-backup-$(basename $source).sgdisk $source
sgdisk --backup=/partitions-backup-$(basename $dest).sgdisk $dest

# Copy $source layout to $dest and regenerate GUIDs
sgdisk --replicate=$dest $source
sgdisk -G $dest

The last command randomizes the GUID on the disk and all the partitions. This is only necessary if the disks are to be used in the same machine, otherwise it's unnecessary.

5 replaced http://askubuntu.com/ with https://askubuntu.com/
source | link

It depends if your source disk uses an MBR (aka "dos" or "msdos") or a GPT (aka "GUID") partition table.

Disks over 2 TB cannot use MBR, so they are GPT.

Disks under 2 TB can use both, so you will have to first find out which it is.

Assuming you are on Linux, use either of these commands to find out which partition table your source disk uses:

disk=/dev/sda

# Always available, but old versions may not recognize gpt
fdisk -l $disk | grep type

# `apt-get install gdisk` or equivalent on non-Debian systems
gdisk -l $disk | grep -A4 'scan'

# `apt-get install parted`
parted $disk print | grep Table

Given

source=/dev/sda
dest=/dev/sdb

For MBR disks

use sfdisk as suggested by Petr Uzel's answer, or this variant:

# Save MBR disks
sfdisk -d $source > /partitions-backup-$(basename $source).sfdisk
sfdisk -d $dest   > /partitions-backup-$(basename $dest).sfdisk

# Copy $source layout to $dest
sfdisk -d $source | sfdisk $dest

For GPT disks

The correct answer was given herehere and here by Kris Harper.

You need GPT fdisk. Look at the download page or run sudo apt-get install gdisk.

Then use the sgdisk command:

# Save MBR disks
sgdisk --backup=/partitions-backup-$(basename $source).sgdisk $source
sgdisk --backup=/partitions-backup-$(basename $dest).sgdisk $dest

# Copy $source layout to $dest and regenerate GUIDs
sgdisk --replicate=$dest $source
sgdisk -G $dest

The last command randomizes the GUID on the disk and all the partitions. This is only necessary if the disks are to be used in the same machine, otherwise it's unnecessary.

It depends if your source disk uses an MBR (aka "dos" or "msdos") or a GPT (aka "GUID") partition table.

Disks over 2 TB cannot use MBR, so they are GPT.

Disks under 2 TB can use both, so you will have to first find out which it is.

Assuming you are on Linux, use either of these commands to find out which partition table your source disk uses:

disk=/dev/sda

# Always available, but old versions may not recognize gpt
fdisk -l $disk | grep type

# `apt-get install gdisk` or equivalent on non-Debian systems
gdisk -l $disk | grep -A4 'scan'

# `apt-get install parted`
parted $disk print | grep Table

Given

source=/dev/sda
dest=/dev/sdb

For MBR disks

use sfdisk as suggested by Petr Uzel's answer, or this variant:

# Save MBR disks
sfdisk -d $source > /partitions-backup-$(basename $source).sfdisk
sfdisk -d $dest   > /partitions-backup-$(basename $dest).sfdisk

# Copy $source layout to $dest
sfdisk -d $source | sfdisk $dest

For GPT disks

The correct answer was given here and here by Kris Harper.

You need GPT fdisk. Look at the download page or run sudo apt-get install gdisk.

Then use the sgdisk command:

# Save MBR disks
sgdisk --backup=/partitions-backup-$(basename $source).sgdisk $source
sgdisk --backup=/partitions-backup-$(basename $dest).sgdisk $dest

# Copy $source layout to $dest and regenerate GUIDs
sgdisk --replicate=$dest $source
sgdisk -G $dest

The last command randomizes the GUID on the disk and all the partitions. This is only necessary if the disks are to be used in the same machine, otherwise it's unnecessary.

It depends if your source disk uses an MBR (aka "dos" or "msdos") or a GPT (aka "GUID") partition table.

Disks over 2 TB cannot use MBR, so they are GPT.

Disks under 2 TB can use both, so you will have to first find out which it is.

Assuming you are on Linux, use either of these commands to find out which partition table your source disk uses:

disk=/dev/sda

# Always available, but old versions may not recognize gpt
fdisk -l $disk | grep type

# `apt-get install gdisk` or equivalent on non-Debian systems
gdisk -l $disk | grep -A4 'scan'

# `apt-get install parted`
parted $disk print | grep Table

Given

source=/dev/sda
dest=/dev/sdb

For MBR disks

use sfdisk as suggested by Petr Uzel's answer, or this variant:

# Save MBR disks
sfdisk -d $source > /partitions-backup-$(basename $source).sfdisk
sfdisk -d $dest   > /partitions-backup-$(basename $dest).sfdisk

# Copy $source layout to $dest
sfdisk -d $source | sfdisk $dest

For GPT disks

The correct answer was given here and here by Kris Harper.

You need GPT fdisk. Look at the download page or run sudo apt-get install gdisk.

Then use the sgdisk command:

# Save MBR disks
sgdisk --backup=/partitions-backup-$(basename $source).sgdisk $source
sgdisk --backup=/partitions-backup-$(basename $dest).sgdisk $dest

# Copy $source layout to $dest and regenerate GUIDs
sgdisk --replicate=$dest $source
sgdisk -G $dest

The last command randomizes the GUID on the disk and all the partitions. This is only necessary if the disks are to be used in the same machine, otherwise it's unnecessary.

4 shorten/simplify last section
source | link

It depends if your source disk uses an MBR (aka "dos" or "msdos") or a GPT (aka "GUID") partition table.

Disks over 2 TB cannot use MBR, so they are GPT.

Disks under 2 TB can use both, so you will have to first find out which it is.

Assuming you are on Linux, use either of these commands to find out which partition table your source disk uses:

disk=/dev/sda

# Always available, but old versions may not recognize gpt
fdisk -l $disk | grep type

# `apt-get install gdisk` or equivalent on non-Debian systems
gdisk -l $disk | grep -A4 'scan'

# `apt-get install parted`
parted $disk print | grep Table

Given

source=/dev/sda
dest=/dev/sdb

For MBR disks

use sfdisk as suggested by Petr Uzel's answer, or this variant:

# Save MBR disks
sfdisk -d $source > /partitions-backup-$(basename $source).sfdisk
sfdisk -d $dest   > /partitions-backup-$(basename $dest).sfdisk

# Copy $source layout to $dest
sfdisk -d $source | sfdisk $dest

For GPT disks

The correct answer was given here and here by Kris Harper.

You need GPT fdisk. Look at the download page or run sudo apt-get install gdisk.

Then use the sgdisk command like so

sgdisk -R=/dev/sdb /dev/sda
sgdisk -G /dev/sdb

The first command copies the partition table of sda to sdb (be careful not to mix these up). The second command randomizes the GUID on the disk and all the partitions. This is only necessary if the disks are to be used in the same machine, otherwise it's unnecessary.

Or this alternativeThen use the sgdisk command:

# Save MBR disks
sgdisk --backup=/partitions-backup-$(basename $source).sgdisk $source
sgdisk --backup=/partitions-backup-$(basename $dest).sgdisk $dest

# Copy $source layout to $dest and regenerate GUIDs
sgdisk --replicate=$dest $source
sgdisk -G $dest

The last command randomizes the GUID on the disk and all the partitions. This is only necessary if the disks are to be used in the same machine, otherwise it's unnecessary.

It depends if your source disk uses an MBR (aka "dos" or "msdos") or a GPT (aka "GUID") partition table.

Disks over 2 TB cannot use MBR, so they are GPT.

Disks under 2 TB can use both, so you will have to first find out which it is.

Assuming you are on Linux, use either of these commands to find out which partition table your source disk uses:

disk=/dev/sda

# Always available, but old versions may not recognize gpt
fdisk -l $disk | grep type

# `apt-get install gdisk` or equivalent on non-Debian systems
gdisk -l $disk | grep -A4 'scan'

# `apt-get install parted`
parted $disk print | grep Table

Given

source=/dev/sda
dest=/dev/sdb

For MBR disks

use sfdisk as suggested by Petr Uzel's answer, or this variant:

# Save MBR disks
sfdisk -d $source > /partitions-backup-$(basename $source).sfdisk
sfdisk -d $dest   > /partitions-backup-$(basename $dest).sfdisk

# Copy $source layout to $dest
sfdisk -d $source | sfdisk $dest

For GPT disks

The correct answer was given here and here by Kris Harper.

You need GPT fdisk. Look at the download page or run sudo apt-get install gdisk.

Then use the sgdisk command like so

sgdisk -R=/dev/sdb /dev/sda
sgdisk -G /dev/sdb

The first command copies the partition table of sda to sdb (be careful not to mix these up). The second command randomizes the GUID on the disk and all the partitions. This is only necessary if the disks are to be used in the same machine, otherwise it's unnecessary.

Or this alternative:

# Save MBR disks
sgdisk --backup=/partitions-backup-$(basename $source).sgdisk $source
sgdisk --backup=/partitions-backup-$(basename $dest).sgdisk $dest

# Copy $source layout to $dest and regenerate GUIDs
sgdisk --replicate=$dest $source
sgdisk -G $dest

It depends if your source disk uses an MBR (aka "dos" or "msdos") or a GPT (aka "GUID") partition table.

Disks over 2 TB cannot use MBR, so they are GPT.

Disks under 2 TB can use both, so you will have to first find out which it is.

Assuming you are on Linux, use either of these commands to find out which partition table your source disk uses:

disk=/dev/sda

# Always available, but old versions may not recognize gpt
fdisk -l $disk | grep type

# `apt-get install gdisk` or equivalent on non-Debian systems
gdisk -l $disk | grep -A4 'scan'

# `apt-get install parted`
parted $disk print | grep Table

Given

source=/dev/sda
dest=/dev/sdb

For MBR disks

use sfdisk as suggested by Petr Uzel's answer, or this variant:

# Save MBR disks
sfdisk -d $source > /partitions-backup-$(basename $source).sfdisk
sfdisk -d $dest   > /partitions-backup-$(basename $dest).sfdisk

# Copy $source layout to $dest
sfdisk -d $source | sfdisk $dest

For GPT disks

The correct answer was given here and here by Kris Harper.

You need GPT fdisk. Look at the download page or run sudo apt-get install gdisk.

Then use the sgdisk command:

# Save MBR disks
sgdisk --backup=/partitions-backup-$(basename $source).sgdisk $source
sgdisk --backup=/partitions-backup-$(basename $dest).sgdisk $dest

# Copy $source layout to $dest and regenerate GUIDs
sgdisk --replicate=$dest $source
sgdisk -G $dest

The last command randomizes the GUID on the disk and all the partitions. This is only necessary if the disks are to be used in the same machine, otherwise it's unnecessary.

3 Add MBR/GPT detect + use sfdisk for MBR, sgdisk for GPT
source | link
2 links to source
source | link
1
source | link