about using dd command to copy hard drives

Jerry McAllister jerrymc at clunix.cl.msu.edu
Fri Aug 22 08:42:00 PDT 2003


> 
> I'm using freebsd 5.0 Jan 2003 series
> 
> I know that dd is good at copying block devices when they
> are at identical sizes. But if they're different sizes will it
> copy correctly?

If you are copying to a bigger disk you can make it work.  But, for
what you seem to want to do, it is not the best way.

> I want to copy my entire freebsd hard disk  which is 6 GB
> to a new hard disk at 20 GB.
> 
> I read the man pages but still can't understand it.  I'm only a user
> not a programmer nor sys admin. If you have any comments or
> suggestions, I would surely appreciate it.

First of all, you are right.  The man page entries are not helpful,
especially the one for fdisk.  It doesn't even document all of its
switches and parameters!!   You have to get some of that by reading
the examples in the disklabel man page and guessing.   But, it is
eventually possible to do it.   

Two things you didn't mention are if the old 6 GB disk is you system/boot 
disk or not and how the old disk is divided in to partitions or if it
is just one big filesystem.   Also, does the new disk need to become
the boot disk?

NOTE:  You can do the fdisk/disklabel/newfs stuff via /stand/sysinstall
       and it works pretty well and painlessly, especially if you intend 
       to use the whole disk for FreeBSD.  But then you wouldn't have
       the thrill of learning to use fdisk/disklabel/newfs and really
       they work very well.  The documentation is just garbled.

What you want to do is fdisk to create one slice on the whole disk,
partition with disklabel, newfs in each partition (except swap) and
then use dump/restore to copy the filesystems from the old to the
new disk.   At this point you could change

Lets say for example you are doing this to a
  - SCSI disk and that 
  - it is the second disk (da1) and you intend to 
  - move it in to the first position after you are done and boot from it.  
  - Finally, assume that you intend to have partitions 
      for root, swap, /tmp and /home.   
You may have filesystems divided up differently, but the process is exactly
the same - just with different numbers and names. 


    fdisk -BI -v -b /boot/mbr da1        /makes one large FreeBSD slice/

    disklabel -r -e -B -b /boot/boot1 -s /boot/boot2 da1s1

      Edit the disklabel so it looks something like:
        Adjust sizes to suit you.  Leave all the header stuff as is. 
        Don't worry about fsize bsize, etc

  8 partitions:
  #        size   offset    fstype  [fsize bsize bps/cpg]
    a:  1048576        0    4.2BSD   1024  8192  22  # (Cyl.    0 - 65*)
    b:  2097152        *    swap
    c:        *        0    unused      0     0      # (Cyl.    0 - 2212*)
    e:  1048576        *    4.2BSD   
    f:        *        *    4.2BSD   

This gives a 512 MG root, 1GB swap, 512 /tmp and all the rest to /home

    newfs -b 8192 -f 1024 /dev/da1s1a            ( /  (root) partition )

    newfs -b 8192 -f 1024 /dev/da1s1e            ( /tmp partition )

    newfs -b 16384 -f 2048 -i 2048 /dev/da1s1f   ( /home partition )

  Fix up your /etc/fstab to add the following
  # Disk da1
  /dev/da1s1a         /newroot      ufs     rw              2       2
  /dev/da1s1f         /newhome      ufs     rw              2       2

fsck the new filesystems (just to be thorough)

  fsck -f /newroot
  fsck -f /newhome

Mount the new files systems

  mount /newroot
  mount /newhome

Now do the dump and restore to copy the file systems.
Again, this presumes you have this current disk structure - eg essentially
a root and home directory.   (/tmp and swap) don't have to be moved)
If you have more partitions/filesystems you will have to adjust the
disklabel edit, add appropriate newfs-s, add more fstab entries and
do the additional dump/restores.

  cd /newroot
  dump -0f - / | restore -xf -
                              This will take a while
  cd /newhome
  dump -0f - /home | restore -xf -
                              This may take even longer

Make sure the /etc/fstab on the new disk is right, do:
  vi /newroot/etc/fstab
It needs to have mounts for:

  # Disk da0
  /dev/da0s1a         /              ufs     rw              1       1
  /dev/da0s1b         none           swap    sw              0       0
  /dev/da0s1e         /tmp           ufs     rw              2       2
  /dev/da0s1f         /home          ufs     rw,userquota    2       2

  # Disk da1
  # /dev/da1s1a         /newroot      ufs     rw              2       2
  # /dev/da1s1f         /newhome      ufs     rw              2       2

Comment out or delete the lines added for /newhome and /newroot

When it is all done, shut down, switch the drives and reboot.

////jerry
   
> 
> Thanks
> 
> David
> 
> _______________________________________________
> freebsd-questions at freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-questions
> To unsubscribe, send any mail to "freebsd-questions-unsubscribe at freebsd.org"
> 



More information about the freebsd-questions mailing list