Solved

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

Posted on 2004-08-04
4
1,919 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
  • 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 500 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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Suggested Solutions

Network Interface Card (NIC) bonding, also known as link aggregation, NIC teaming and trunking, is an important concept to understand and implement in any environment where high availability is of concern. Using this feature, a server administrator …
rdate is a Linux command and the network time protocol for immediate date and time setup from another machine. The clocks are synchronized by entering rdate with the -s switch (command without switch just checks the time but does not set anything). …
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

861 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

Need Help in Real-Time?

Connect with top rated Experts

30 Experts available now in Live!

Get 1:1 Help Now