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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
01-04-2006, 05:14 PM
|
#1
|
Member
Registered: Sep 2003
Posts: 76
Rep:
|
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
|
|
|
01-04-2006, 05:36 PM
|
#2
|
Senior Member
Registered: Oct 2003
Posts: 3,057
Rep:
|
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
|
|
|
01-04-2006, 06:42 PM
|
#3
|
LQ Veteran
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809
|
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.
|
|
|
01-04-2006, 08:13 PM
|
#4
|
Senior Member
Registered: Jun 2004
Location: Australia
Distribution: Mandriva/Slack - KDE
Posts: 1,672
Rep:
|
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...
|
|
|
01-05-2006, 12:52 AM
|
#5
|
Senior Member
Registered: Oct 2003
Location: /earth/usa/nj (UTC-5)
Distribution: RHEL, AltimaLinux, Rocky
Posts: 1,151
Rep:
|
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.
|
|
|
01-05-2006, 10:41 AM
|
#6
|
Member
Registered: Sep 2003
Posts: 76
Original Poster
Rep:
|
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?
|
|
|
01-05-2006, 11:17 AM
|
#7
|
Senior Member
Registered: Oct 2003
Location: /earth/usa/nj (UTC-5)
Distribution: RHEL, AltimaLinux, Rocky
Posts: 1,151
Rep:
|
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.
|
|
|
01-05-2006, 11:41 AM
|
#8
|
Member
Registered: Sep 2003
Posts: 76
Original Poster
Rep:
|
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.
|
|
|
01-05-2006, 12:02 PM
|
#9
|
Senior Member
Registered: Oct 2003
Location: /earth/usa/nj (UTC-5)
Distribution: RHEL, AltimaLinux, Rocky
Posts: 1,151
Rep:
|
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.
|
|
|
01-05-2006, 12:08 PM
|
#10
|
Senior Member
Registered: Oct 2003
Posts: 3,057
Rep:
|
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.
|
|
|
01-05-2006, 03:20 PM
|
#11
|
Member
Registered: Sep 2003
Posts: 76
Original Poster
Rep:
|
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
|
|
|
All times are GMT -5. The time now is 06:44 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|