[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

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

Posted on 2004-08-04
4
Medium Priority
?
1,964 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

If you have a server on collocation with the super-fast CPU, that doesn't mean that you get it running at full power. Here is a preamble. When doing inventory of Linux servers, that I'm administering, I've found that some of them are running on l…
The purpose of this article is to demonstrate how we can use conditional statements using Python.
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…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
Suggested Courses

650 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