LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 01-04-2006, 05:14 PM   #1
eyt
Member
 
Registered: Sep 2003
Posts: 76

Rep: Reputation: 15
copy partition to new disk


Hi all,

I want to set up software raid1 with 2x 120G SATA drive.
OS was now installed on /dev/sda

1. I use the following command to copy the /dev/sda partition information to the /dev/sdb: -
sfdisk -d /dev/sda | sfdisk --force /dev/sdb

It gives error.

How to use one command to copy the partition table from /dev/sda to /dev/sdb?


2. Below list partition information for /dev/sda: -
fdisk -l gives the following information:

Disk /dev/sda: 120.0 GB, 120034123776 bytes
255 heads, 63 sectors/track, 14593 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sda1 * 1 101 811251 83 Linux
/dev/sda2 102 14593 116406990 5 Extended
/dev/sda5 102 201 803218+ 82 Linux swap
/dev/sda6 202 301 803218+ 83 Linux
/dev/sda7 302 1287 7920013+ 83 Linux
/dev/sda8 1288 11999 86044108+ 83 Linux
/dev/sda9 12000 14533 20354323+ 83 Linux
/dev/sda10 14534 14593 481918+ 83 Linux

Disk /dev/sdb: 120.0 GB, 120034123776 bytes
255 heads, 63 sectors/track, 14593 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
 
Old 01-04-2006, 05:36 PM   #2
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 61
I would send the table info to a file...
sfdisk -d /dev/sda > mbr_file

then, get the information to the other drive...
sfdisk /dev/sdb < mbr_file
 
Old 01-04-2006, 06:42 PM   #3
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
Are you copying the partition or the **partition table**?

BUT---what has this got to do with setting up the two disks in RAID? To do that, you first create the RAID array, and then set up partitions. You will want to back up you data somehwere before doing any of this.
 
Old 01-04-2006, 08:13 PM   #4
amosf
Senior Member
 
Registered: Jun 2004
Location: Australia
Distribution: Mandriva/Slack - KDE
Posts: 1,672

Rep: Reputation: 46
You would normally use dd I would think... But as said, if you are going to raid then you are going to have to cp -a or something...
 
Old 01-05-2006, 12:52 AM   #5
WhatsHisName
Senior Member
 
Registered: Oct 2003
Location: /earth/usa/nj (UTC-5)
Distribution: RHEL, AltimaLinux, Rocky
Posts: 1,151

Rep: Reputation: 46
eyt: You would think that passing the sfdisk output should work, but I notice that the example in “man sfdisk” creates and then reads an output file (which is what homey suggested):

From “man sfdisk”:
-d Dump the partitions of a device in a format useful as input to sfdisk. For example,
% sfdisk -d /dev/hda > hda.out
% sfdisk /dev/hda < hda.out

Maybe they know something we don't. I've run into situations where direct passing doesn't work for whatever reasons.

Alternatively, you could manually partition the new drive with your favorite partitoning utility. Don't forget, the first logical partition points to the next, so there is no partition table that can be copied to reestablish the logical paritition structure.

At some point, the partition types for the partitions you want to mirror will need to be changed to “linux raid auto” (type fd), unless you like getting really odd warning messages during bootup.


pixellany: That's not how software raid is usually set up. You can't “subpartition” a software raid, unless you raid the entire drives and then set up an lvm on the raid.

If you duplicate the original partition structure onto the new drive, then you can use mdadm to create the software raid1 pairs for each partition you wish to mirror. After the mdadm create is finished, the new partitions will be “degraded” and will be rebuilt to match the original partitions. I think that's what eyt is up to.

This process is similar to how you would replace a failed software raid1 drive.
 
Old 01-05-2006, 10:41 AM   #6
eyt
Member
 
Registered: Sep 2003
Posts: 76

Original Poster
Rep: Reputation: 15
I want to duplicate the original partition structure for /dev/sda to the new drive /dev/sdb before using mdadm to create raid arrays.

when I try % sfdisk -d /dev/sda > mbr_file, it gives the following error message:
sfdisk: seek error: wanted 0x0000000000000000, got 0x0000000000000000

Any idea what is the problem?
 
Old 01-05-2006, 11:17 AM   #7
WhatsHisName
Senior Member
 
Registered: Oct 2003
Location: /earth/usa/nj (UTC-5)
Distribution: RHEL, AltimaLinux, Rocky
Posts: 1,151

Rep: Reputation: 46
Sorry, but I don’t use sfdisk enough to know its ins and outs, but it would only take you maybe 5 minutes to duplicate the partition structure using fdisk. Since the new drive is empty, it’s not like you’re going to do any damage if you make a mistake.

Using your printout from “fdisk -l...”, create the primary (#1) and extended (#2) partitions and then create the logical partitions (#5-10). It’s really easy to do when you know the starting and ending cylinders for the original disk partitions. You might need to change the number of logical heads using fdisk expert mode (“x”) to match the original disk before you start.

You can also change the partition types (“t”) of the soon-to-be software raid partitions after you are done setting up the disk. Be sure to write (“w”) the final setup or quit (“q”) if you want to dump what you have done. Or you can do one thing, write the results, restart fdisk and then look at your handiwork.

After you are done, you might want to format (mkfs, etc.) any non-raid partition you intend to use (e.g., swap). And as always, backups are a good idea.
 
Old 01-05-2006, 11:41 AM   #8
eyt
Member
 
Registered: Sep 2003
Posts: 76

Original Poster
Rep: Reputation: 15
Hi WhatsHisName,

Thanks for your information. You have mentioned to change the number of logical heads using fdisk expert mode. When I type fdisk /dev/sda, it gives the disk information. Is the 255 heads below listed is the logical head of /dev/sda ?

Disk /dev/sdb: 120.0 GB, 120034123776 bytes
255 heads, 63 sectors/track, 14593 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

I cannot find any expert option -x for fdisk command.
 
Old 01-05-2006, 12:02 PM   #9
WhatsHisName
Senior Member
 
Registered: Oct 2003
Location: /earth/usa/nj (UTC-5)
Distribution: RHEL, AltimaLinux, Rocky
Posts: 1,151

Rep: Reputation: 46
Expert mode isn’t an -option, it’s a fdisk shell command (and everything looks fine, 255 logical heads).

Just start fdisk (fdisk /dev/sdb) and you will get a prompt along with how to get a menu of command options. It’s really straightforward to use.
 
Old 01-05-2006, 12:08 PM   #10
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 61
I'm not sure why sfdisk is giving you that error. Maybe you will have better luck copying the partition table with dd.

For example:
Code:
# This part copies the table to file
dd if=/dev/sda of=mbr_file bs=512 count=1

# This part zeros the partition table on second drive
# Be careful to do this to second drive only!
dd if=/dev/zero of=/dev/sdb bs=512 count=1

# This part copies the mbr file onto the second drive
dd if=mbr_file of=/dev/sdb bs=512 count=1

Last edited by homey; 01-05-2006 at 12:09 PM.
 
Old 01-05-2006, 03:20 PM   #11
eyt
Member
 
Registered: Sep 2003
Posts: 76

Original Poster
Rep: Reputation: 15
Hi homey,

I use dd as stated, i.e.
dd if=/dev/sda of=mbr_file bs=512 count=1
dd if=/dev/zero of=/dev/sdb bs=512 count=1
dd if=mbr_file of=/dev/sdb bs=512 count=1

/dev/sdb was partition but the size of some partitions on /dev/sdb was different from /dev/sda : -

fdisk -u

Disk /dev/sda: 120.0 GB, 120034123776 bytes
255 heads, 63 sectors/track, 14593 cylinders, total 234441648 sectors
Units = sectors of 1 * 512 = 512 bytes

Device Boot Start End Blocks Id System
/dev/sda1 * 63 1622564 811251 83 Linux
/dev/sda2 1622565 234436544 116406990 5 Extended
/dev/sda5 1622628 3229064 803218+ 82 Linux swap
/dev/sda6 3229128 4835564 803218+ 83 Linux
/dev/sda7 4835628 20675654 7920013+ 83 Linux
/dev/sda8 20675718 192763934 86044108+ 83 Linux
/dev/sda9 192763998 233472644 20354323+ 83 Linux
/dev/sda10 233472708 234436544 481918+ 83 Linux


Disk /dev/sdb: 120.0 GB, 120034123776 bytes
255 heads, 63 sectors/track, 14593 cylinders, total 234441648 sectors
Units = sectors of 1 * 512 = 512 bytes

Device Boot Start End Blocks Id System
/dev/sdb1 * 63 1622564 811251 83 Linux
/dev/sdb2 1622565 234436544 116406990 5 Extended
/dev/sdb5 1622628 3775274 1076323+ fd Linux raid autodetect
/dev/sdb6 3775338 5895854 1060258+ 83 Linux
/dev/sdb7 5895918 23197859 8650971 fd Linux raid autodetect
/dev/sdb8 23197923 185872049 81337063+ fd Linux raid autodetect
/dev/sdb9 185872113 232749719 23438803+ fd Linux raid autodetect
/dev/sdb10 232749783 234436544 843381 fd Linux raid autodetect

Now I just use the fdisk -u /dev/sdb to create the partition one by one and it works fine. Thanks
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Hard disk partition copy elmu Linux - Hardware 1 11-10-2005 08:31 AM
Copy files from partition to partition too slow, SATA hard disk.What should I do£¿ Ryanlee SUSE / openSUSE 20 10-31-2005 07:30 AM
copy linux installation from old disk to new disk rmanocha Linux - Software 4 07-20-2004 06:21 AM
What is the code to copy a file from my windows partition to my linux partition? THEBIGFISH Linux - Newbie 3 03-15-2004 10:14 PM
Disk copy bfloeagle Linux - Hardware 4 11-16-2002 05:42 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 06:44 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration