-   Linux - Newbie (
-   -   Copying from /dev/sda to /dev/sdb (

fof3 07-02-2006 01:45 PM

Copying from /dev/sda to /dev/sdb
I have two scsi disks; exact in size and make. On sda there's a dual boot system - Windows XP, and Linux (debian).

Windows is expanding; with 4G free space. I want to transfer Linux to sdb; and let Windows do its thing.

I partitioned sdb, using Partition Magic; and I made the partition sizes a little greater than their corresponding ones on sda.

I created the file system on sdb with KNOPPIX 4.0.
I first tried "cp -pr /dev/sda2 /dev/sdb1" [sda1 is NTFS] and got "'/dev/sda2 ->' /dev/sdb1".

If the copy command won't do it what will? I had tried dd in the past, and got the error that there was no more space left on the device.

Tinkster 07-02-2006 02:01 PM

Can you please elaborate on the result of the cp? It really should
have worked (you could try -a instead).


tnandy 07-02-2006 02:24 PM

You don't say what brand of SCSI disk it is, but most new IDE disks come with a software CD from the factory or utilities available for download from the manufacturer's website. This software allows such things such as partitioning and copying a partition from the old disk to the new disk. It does not care what the contents of the partition are. If your new SCSI drive came with a similar CD or you can find the utilities on the web, I would use those tools instead.

pokemaster 07-02-2006 02:29 PM

haha, hey guys -- no big deal, you just copied one device and overwrote another....

you need to mount the filesystems and copy all the files.


mkdir -p /mnt/sda1 && mkdir -p /mnt/sdb1
mount /dev/sda1 /mnt/sda1 && mount /dev/sdb1 /mnt/sdb1
cp -pr /mnt/sda1/* /mnt/sdb1/*

this will take a few minutes...

umount /mnt/sda1 && umount /mnt/sdb1
and there you have it.

good luck!

HappyTux 07-02-2006 02:30 PM

Here is what I usually would do when duplicating my install to my spare drive. First boot with knoppix 2 to get to a console root prompt then,


mount /dev/sda2 /mnt/sda2
mount /dev/sdb1 /mnt/sdb1
cp -Rp /mnt/sda2/* /mnt/sdb1/
vi /mnt/sdb1/etc/fstab        <----- Changing all sda2 to sdb1
vi /mnt/sdb1/etc/lilo.conf or /mnt/sdb1/boot/menu/grub.lst  <------ Making changes for new drive again
chroot /mnt/sdb1 /sbin/lilo -v    <----- or for grub
setup (hd?)

Now for installing the lilo/grub it can get a little complicated unless you want to keep it on the drive you already have it on in which case when editing their config files only change the parts that refer where the kernel is located and just let it install itself into the MBR of the sda drive like it is now (it it?). If you still have problems the output of fdisk -l and seeing which of the config files you are using would be nice.

pokemaster 07-02-2006 02:33 PM

ps. problem with the dd command is that using it will create identical partitions


dd if=/dev/sda1 of=/dev/sdb1
will make sdb1 exactly like sda1 - right down to the size.

you can use dd, then resize the partition on sdb1, but this can get tricky.

marozsas 07-02-2006 02:39 PM

Since the partitions sizes aren't the same, copying a partition would not work. To use a partition as source/target, they must have the exactly same size.

You need to use a mount point as source and target. Mount /dev/sda2 as /mnt/source and /dev/sdb1 as /mnt/target and "cp -pr /mnt/source /mnt/target" will work just fine.

Of course, you need to create a filesystem on /dev/sdb1 first. This filesystem can be different than the one on /dev/sda2.

fof3 07-03-2006 06:45 PM

I created partitions on /sdb that are equal in size to those on /sda.

I created a filesystem on each partition of /sdb.

After having cd'd into each /sda mount point, I copied data using 'cp ./* mnt/sdb_'.

As I see it, what I need to do next is:

1.Edit /etc/fstab

2.Modify /etc/lilo.conf to reflect where root is on /sdb

3. Reboot, and expect the best.


marozsas 07-04-2006 07:19 AM


Originally Posted by fof3

There is the boot manager (lilo/grub) issue to deal with.
1) The boot loader on /dev/sda must be not changed or overwriten by windows.
2) If the boot manager is lilo them the MBR must be updated to reflect the new boot dir. (lilo -v)

A working live CD would be valuable if anything goes wrong.
And don't delete the linux on /dev/sda before you are sure your system is working right on the new location.
Keep copies of the original /etc/lilo.conf and /etc/fstab just in case.

good luck !

All times are GMT -5. The time now is 11:52 AM.