?
Solved

How do I copy a partition table to a new drive ?

Posted on 2004-08-04
4
Medium Priority
?
1,959 Views
Last Modified: 2008-01-09
Hi all,

I'm trying to work out how to do something on Linux that I can currently do on FreeBSD.

I want to copy the partition table from one device (say /dev/sda) to another device of the same size (say /dev/sdb).

On FreeBSD I can do this by using disklabel -w to write a disklabel that I got from disklabel /dev/driveid.

I can get the base output I want in Linux by doing fdisk -l /dev/sda. I then have to edit this and change all occurances of sda to sdb, a step I don't need to do in FreeBSD because partition tables are separate to labels. Now I have a file with all of my partition information, how do I put this onto a drive (e.g. sdb) ?

Thanks,
0
Comment
Question by:Anonymouslemming
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 8

Expert Comment

by:da99rmd
ID: 11714020
Hi Anonymouslemming,
are the disks the same size ?
if they are use this command and you will copy the data and the partitiontable and MBR.
dd if=/dev/sda of=/dev/sdb

If you just want the partition table just create it using fdisk or sfdisk.

/Rob
0
 
LVL 3

Expert Comment

by:pYrania
ID: 11714068
dd if=/dev/sda of=/dev/sdb bs=512 count=1

That command will copy the MBR (512 Bytes) from sda to sdb.

Though, only the 447th through 510th bytes are the actual partition table - each partition has 16 records/bytes.
The first 446 bytes represent the bootloader and the last 2 bytes are unused.
0
 
LVL 20

Expert Comment

by:Gns
ID: 11715703
Only do this if the disk geometry actually match. Otherwise, let's instead script something around fdisk.... Or better yet (and as suggested by Rob) sfdisk.

-- Glenn

0
 
LVL 20

Accepted Solution

by:
Gns earned 2000 total points
ID: 11715806
Hm, yes... the -O/-I options of sfdisk would be unuseable (pretty much as the dd case) with "logical partitions", so one would need rely on
sfdisk -d /dev/sda > sda.out
sed -i -e 's#/dev/sda#/dev/sdb#' sda.out
sfdisk /dev/sdb < sda.out
... should do the trick in a rather more "safe" way.

-- Glenn
0

Featured Post

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction We as admins face situation where we need to redirect websites to another. This may be required as a part of an upgrade keeping the old URL but website should be served from new URL. This document would brief you on different ways ca…
The purpose of this article is to demonstrate how we can use conditional statements using Python.
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses
Course of the Month12 days, 1 hour left to enroll

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question