Linux - HardwareThis forum is for Hardware issues.
Having trouble installing a piece of hardware? Want to know if that peripheral is compatible with Linux?
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.
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.
Here is the scenario: I have a SATA HD (80G /dev/sda) and an IDE HD (120G /dev/hdb). I have Debian Etch installed on the latter. I wish to clone the IDE HD so that the SATA HD contains my Linux volume. I have used approx 25G of the 120G drive at present. Here is the output of fdisk:
Code:
root@2[knoppix]# fdisk -l
Disk /dev/hdb: 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/hdb1 * 1 14219 114214086 83 Linux
/dev/hdb2 14220 14593 3004155 f W95 Ext'd (LBA)
/dev/hdb5 14220 14593 3004123+ 82 Linux swap / Solaris
Disk /dev/sda: 80.0 GB, 80000000000 bytes
255 heads, 63 sectors/track, 9726 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk /dev/sda doesn't contain a valid partition table
I am currently doing a..
Code:
dd if=/dev/zero of=/dev/sda conv=notrunc
to erase /dev/sda at the moment.
So once this is finished how would I go about doing this using dd? Because the 'if' (input file) is bigger than the output file, I cannot simply do..
Code:
dd if=/dev/hdb of=/dev/sda conv=notrunc,noerror
Can I? Will I have to resize the main Linux partition and create one the exact same size as it on the SATA hd?
Also I noticed I cannot seem to resize the linux partition from my knoppix cd, as it says it is 'active'. But I have unmounted it so I cannot see how it is active.
Thanks for taking the time to read this, any help will be greatly appreciated.
So once this is finished how would I go about doing this using dd? Because the 'if' (input file) is bigger than the output file, I cannot simply do..
Yes, you're right about that. What I'd do is format the 120G drive to have all the partitions at the beginning of the drive and have them go up to the 80G boundary (its probably less because OSes see 1 K as 1024 and hard drive amounts are 1K=1000)
2. in order to reformat your drive, I would first get something other than knoppix because it doesn't support the resizing of some linux partitions. Go find a live Cd with gparted (like sysrescuecd, www.sysresccd.org), and resize from there. You can find where you should use the 120G up (the boundary) and stop by looking at the 80 G from gparted.(I would back off at least .5 G from that amount to avoid errors or whatever)
Last edited by lambchops468; 05-19-2007 at 06:28 PM.
dd is a bad option IMHO - setup the partitions on the new disk, and simply "cp -a ..." (from a liveCD). Will handle links, everything.
rsynch is another popular option.
Will `cp -a ..` copy over filesystem information though?
You have to set up a filesystem (mkfs) after formatting sda. When you copy over using cp, you also will have to reinstall grub. You should skip /dev, /tmp, and /proc when you copy things over.
Quote:
I will give what lambchops suggested a go, and let you know how it goes. Thanks again
I wouldn't do this if I had more than one partition on the source drive. gparted won't move partitions backward on a disk, only forward (unless a recent version has remove that limitation).
OK Thanks. What I have done is used Gparted to shrink the main linux partition in the 120g hd to around 70g. I then moved the extended partition infront of the subsequent unallocated space.
in post #6 will produce a mirror image of sda1 into sdb2 because the number sectors matches each other. The cloning of the swap is unnecessary because it does not contain usable information. The Linux will not boot because of the following
(1) As far as Grub is concerned The Linux was installed in the 1st disk (hd0) so its root still points to (hd0,0) and the kernel statement will have a parameter indicating "root=/dev/hdb1"
(2) The Boot loader Grub is residing in the MBR of hdb and there is no entry to boot the newly located system in sda. To replicate the boot loader in hdb into sda the following commands are needed in Debian terminal
Code:
sudo grub
root (hd1,0)
setup (hd1)
quir
(3) The fstab has entries for the root being /dev/hdb1 and the swap being /dev/hdb5. If the Debian in sda1 is booted the kernel will go back to hdb1 to load the file and continue to use hdb5 as swap.
Thus what follows depends entirely on what the OP wants. Does he want to boot two systems side by side? In such a case he will have to correct the above 3 items.
Or does he want Debian to run on the sdb only? In such a case all he needs is to pull the hdb temporarily out and let sda be the only disk to become (hd0) to run Debian as a clone, by editing the hdbx refernces to sdax. After the boot loader has been replicated in Item (2) the cloned Debian will boot normally as the original.
In the past I have never been able to make this work as expected. Apparently something (not sure what) isn't picked up when I do it this way. Instead, to copy a partition, I use the output of sfdisk -l -sf to get the start block and the size of the partition, then I copy like this:
However, this isn't what you want to do. You want to clone the entire HD including the master boot record. So for that you'd do this:
dd if=/dev/hdb of=/dev/sda bs=whatever
This will clone every byte of the source to the destination and will give an error when it tries to run off the end of the destination drive - which will be fine since the copy will have already completed.
I take it that the most recent versions of gparted DO permit a partition to be moved forward on a drive?
I think the OP now wants to clone only the partition from hdb1 to sda1. Since both partitions have been arranged to have identically 9115 sectors the cloning by dd will work.
The latest Gparted can move a partition forward and backward as well as dragging the partition boundary to resize it.
I have in the past cloned partitions by partition name in dev and had it fail. I can't tell you why because it does seem like the entire partition should be picked up.
You can test it by cloning the partition to a file, mounting the file, and trying to read the contents. I haven't successfully done it, though it has been several years since I tried. I have never failed when specifying absolute addresses on the HD.
I then rebooted my system, changed the boot order in my BIOS to boot the SATA HD before the IDE HD, and viola! It has worked out quite nicely. I am glad I have had not problems with the dd command, it has all seemed to work fine.
Note: For anyone reading this in the future with similar problems, although I used root (hd1,0) for the above, I used (hd0,0) for the /boot/grub/menu.lst file situated in sda1
I have changed fstab corresponding to my new partition, will I have to do anything further?
Do get excited yet. The testing of the pudding is to have hdb electrically disconnected. This is because if you made a mistake the Linux can still fetch the information from hdb disk to make up for it. You need to be sure everything is coming from sda so disconnecting hdb is the final check.
Another satisfied customer - even if I was ignored ...
I gave up on dd because of the messing with partitions. Had lots of trouble resizing ext2/3; although I haven't tried in a while.
Also occasionally I like to try different filesystem types.
As for general "cloning", I see clonezilla on sf; haven't tried it, but would be worth consideration in future.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.