On Fri, Oct 24, 2008 at 01:29:18PM -0300, Joey Mingrone wrote:

> Hi,
> My laptop "died" recently and to get back to work as quickly as
> possible I simply took the laptop ide drive and put it into an old
> desktop using a 2.5" -> 3.5" ide adapter.  After loading a few new
> drivers into the kernel everything is working quite well.
> The next thing I've tried to do, without success, is mirror the
> contents of the 2.5" drive to a 3.5" drive in the desktop.
> The 2.5" drive is sliced/partitioned like this:
> Filesystem      Size    Mounted on
> /dev/ad0s2a     989M   /
> /dev/ad0s2d     989M   /tmp
> /dev/ad0s2f      59G     /usr
> /dev/ad0s2e     989M   /var
> ad0s1 is a 20GB slice that I have window installed on.
> The drive's total capacity is 80G.
> The 3.5" drive is only 70G so I'll have to skip the ad0s1 slice.
> Ideally what I'd like to do is copy everything from the ad0s2 slice to
> the 3.5" and run the OS off that drive.  Then, each dump the contents
> of the 3.5" drive to the 2.5" drive.  That way if either drive dies
> I'll, hopefully at worst, just have to switch which drive I boot from.
> Can anyone with experience doing something this make suggestions?

Are you saying that you have 70GB available on the 3.5" drive?
So the 64 GB of the 2.5" drive (not counting the MS part) will fit?

It is going to be really tight, but it should be doable.  Maybe
you can actually trim that /usr partition down a little if it
isn't full.

To do all of what you want (according to what you say here) you
will either have to use a fixit CD boot or multiple passes with
the current disks.   Presuming you will just nuke that MS part,
you can do the following.   (you might actually be able to use a
utility such as gpart or Partition Magic to squeeze that MS slice
down enough to keep it if you want if /usr is not very full, or you
can just leave it alone where it is)

It sounds like you are currently booting from the 2.5" drive from
the laptop.  If that is true, you only need two major steps.

First, you will need to be able to put both drives in to the desktop
machine and mount their filesystems (except the ms part).

Lets say, when you finally get that accomplished, that they
device name out as: 
  2.5" MS slice      = ad0s1
  2.5" FreeBSD slice = ad0s2
  3.5" Old drive     = ad1
If the names come out differently, then you will have to adjust.

Boot the system up on the 2.5" drive.

Wipe and initialize the 3.5" disk with fdisk.
Doing a dd to it first might make it go more smoothly.
It may not be needed.

  dd if=/dev/zero of=/dev/ad1 bs=512 count=1000

  fdisk fdisk -BI ad1

That fdisk initializes it and puts on an MBR - the standard FreeBSD one.
This form makes it all in one large slice - so it creates ad1s1

Now, use bsdlabel to create the partition table and write the
boot block on it.

  bsdlabel -w -B ad1s1

The boot block is where the system jumps from the MBR when you 
select to boot that slice (if there is only one slice, there is
no selection, it just goes there after doing MBR stuff).

Now, edit the partition table in slice one to have the partitions
you want.

  bsdlabel -e ad1s1

This will bring up an edit screen - probably in vi unless you have
set your main editor to something else.   In that screen, it will
show only the  c: partition as containing the whole space and marked
unused and a note to  'don't edit'.  

It will look something like this:
8 partitions:
#        size   offset  fstype   [fsize bsize bps/cpg]
  c: 78316875      0    unused      0     0       # "raw" part, don't edit

Do not change the c partition line.
But, the easiest way to make new lines is to copy it.  
In vi do that by putting the cursor on it and hitting  dd  then
hitting p enough times for the number of copies you want (6 times in this 

One thing you didn't mention was swap.  It is normal to make the 'b'
partition be swap space.   Maybe you left that out because it doesn't
show up in a df.   But, your system needs it.

So, then change the first line to be an a partition.  Make it a BSD4.2
type.    Make the second line a b partition and change its type to swap
Make your d, e and f partition lines.   

The offset for both the c and the a partions  should be 0
After that you don't have to worry, because newer versions of bsdlabel
(and the previous disklabel) will calculate the offsets for you.
It will also calculate the size of the last partition if you want
it to be a catch all for the amount of space that remains.  (Usually
one makes that the largest one then)  To get it to do the calculations,
just put an asterisk in the field.   

Note: the sizes are given in 512 byte blocks.  You can use others
such as 1G or 1024M for 1GB, but I find this easier to keep track of.

It should look something like the following.  This example 
makes r00t, swap, tmp, var all be 1GB and usr (part f) get all the rest.

8 partitions:
#        size   offset  fstype   [fsize bsize bps/cpg]
  a:  2097152        0   4.2BSD    2048 16384 32776
  b:  2097152        *     swap
  c: 78316875        0   unused       0     0        # "raw" part, don't edit
  d:  2097152        *   4.2BSD    2048 16384     8
  e:  2097152        *   4.2BSD    2048 16384 28552
  f:        *        *   4.2BSD    2048 16384 28552

When you are finally done fixing up the partition table, do a write/quite
in the editor  ESC:wq  in vi and it will write the partition table for you.

Following that, you need to newfs all the new partitions except
the swap (and of course c).

  newfs /dev/ad1s1a

probably the defaults on newfs are just fine.
Although more recent fdisk and bsdlabel let you skip
the /dev/ prefix to the device name, the latest version I
currently have of newfs still requires the full device name.

It would be a good idea to do an fsck on each of the mountable
partitions at this point.   

Then you need to copy over the filesystems.
Don't bother with /tmp, and of course, swap.

Create mount points and mount the filesystems.

  mkdir newroot
  mkdir newvar
  mkdir newusr

  mount /dev/ad1s1a /newroot
  mount /dev/ad1s1e /newvar
  mount /dev/ad1s1f /newusr

Use dump piped to restore to copy the file systems.
It is a good idea to do this part in single user mode so
you can reboot to single.  You can do it without, but it a
file should change during that time, it will not get copied
properly.   Mostly that is a fairly small risk.

If you reboot to single user, you have to make sure things
are clean and mounted.   So, at the prompt, do:

  fsck -p
  mount -u /
  mount -a
  swapon -a
  mount /dev/ad1s1a /newroot
  mount /dev/ad1s1e /newvar
  mount /dev/ad1s1f /newusr
In either case, then do:

cd /newroot
dump 0af - / | restore -rf -
cd /newvar
dump 0af - /var | restore -rf -
cd /newusr
dump 0af - /usr | restore -rf -

At this point you should have a bootable copy of your 2.5" drive
on your 3.5" drive.

Try switching them around so the 3.5" drive is in the mount position
and boot it up and see what happens.   It has worked for me and I
don't think I left anything out.    I do different partitions
and sizes, but otherwise it is the same.

You can just make the new mount points on the 3.5" drive while
it is booted and rm -rf * each of the file systems on the 2.5"
drive to clean them out and then do the dump/restore back to
the 2.5" drive.    You will have to contend with some files
that are chflags-ed that you will have to clear before being able
to nuke them.  

Of course, all of this will have to be done as root.

But, I would suggest that you might rather go to a store and buy
up a decently large USB hard drive and use it for your backups,
rather than going back and forth with these drives.  If you can
manage to get both working in the machine, then just use both
of them and use the USB for backups.

Have fun,


> Thanks,
> Joey
> _______________________________________________
> freebsd-questions@freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-questions
> To unsubscribe, send any mail to "[EMAIL PROTECTED]"
freebsd-questions@freebsd.org mailing list
To unsubscribe, send any mail to "[EMAIL PROTECTED]"

Reply via email to