Re: Copying a FreeBSD install to a smaller disk

2008-09-12 Thread Jerry McAllister
On Thu, Sep 11, 2008 at 05:19:55PM -0700, Chris Weiss wrote:

> How would I go about copying an existing FreeBSD installation to a smaller 
> disk?
> 
> I've got a 3rd FreeBSD install I can boot from and store temporary
> files on, all the disks are in the same hardware, so there's no
> reconfiguration other than the boot device name and interface (IE
> -SATA ad4 will become IDE ad0). The disk is partitioned using the
> "default" sysinstall values and the contents of the larger disk will
> fit on the smaller disk, although I need to increase the size of the /
> and /var slices on the target to hold everything (/usr is fairly
> empty, so it'll easily fit on the smaller disk).
> 
> For now, we'll say ad0 = new smaller disk, ad4 = boot BSD disk, and
> ad6 = the BSD install I want to clone.
> 
> The path I've been going down is to manually partition and slice ad0
> create ad4/mnt/source and ad4/mnt/target and mount /var, /tmp, etc
> from ad0 and ad6 and manually copy the files. But I'm stuck on how to
> handle /, since it'll have dev and proc and such.
> 
> Any thoughts on how to do this, or on a completely different approach?
> I'm not aware of any 3rd party tools that'll deal with shrinking
> FreeBSD partitions.
> 
> Thanks in advance for any help you folks can give!

Seems like you are generally on the right track, though some of your 
mounting seems backwards to me.

First, as you have indicated, manually slice, partition and newfs
the new disk (ad0) to match what you want to have on it.  If you
are making an identical, just smaller, disk to ad4, then do a df 
and see what slices and partitions are being used on ad4.   Probably
it is one slice, divided into several partitions.   

While you are at it, look at each of the filesystem sizes and make 
sure you will have room on the new, smaller disk.   You want at least
the current used size + 10%.   Really you want more to actually
operate.   

Presuming you want a single bootable slice (ad0s1) which is then 
divided in to partitions for:
 a: /
 b: swap
 d: /tmp
 e: /usr
 f: /var
 g: /home

Do:
  fdisk -BI ad0
Creates a single bootable slice with default MBR (good enough).
  bsdlabel -w -B da0s1
Writes an initial label and boot block on the slice
  bsdlabel -e da0s1
Puts you in edit (vi by default) with the current condition of
the partition label showing.  If it is new, it will only show
a 'c' partition covering the whole available size of the slice.
  Edit this page by duplicating that 'c' line for each real partition
  you want to have and changing fstype from 'unused' to '4.2BSD' on
  the a, d, e, f, g partitions and 'swap' on the b partition.

In the end you will have something that looks about like:

# /dev/ad0s3:
8 partitions:
#   size   offset   fstype  [fsize bsize bps/cpg]
 a:   5242880   4.2BSD2048 16384 32776
 b:  2572288* swap
 c: 783168750   unused   0 0# "raw" part, don't edit
 d:  1048576*   4.2BSD2048 16384 8
 e:  4194304*   4.2BSD2048 16384 28552
 f:  6291456*   4.2BSD2048 16384 28552
 g:**   4.2BSD2048 16384 28552

You need only specify the sizes.  You can put '*' for the offset
and the bsdlabel utility figures it out correctly.
Also, you can put '*' for both size and offset on the last
partition and it will use all the remaining available space.
Don't do anything with the actual 'c' partition.

Remember that sizes here are in 512 Byte blocks/sectors.
The sizes I have here are for a disk I happen to have handy at
the moment to look at.
  a: 256 MBMount as;  /
  b:   1,256 MB   swap
  d: 512 MB  "   "/tmp
  e:   2,048 MB  "   "/usr
  f:   3,072 MB  "   "/var
  g:  31,096 MB  "   "/home

Then do a regular newfs on each real file system a, d, e, f, g
  newfs /dev/ad0s1a
  newfs /dev/ad0s1d
etc  for e, f, g

Once you have the new disk created, I would do the rest all in
single user mode.

Boot to single useri, then

  fsck -p
  mount -u /
  mount -a
  swapon -a

Create temporary mount points for the new filesystems (ignore /tmp
unless you actually have something there to maintain - unlikely)
  mkdir /newroot
  mkdir /newusr
  mkdir /newvar
  mkdir /newhome

Use dump/restore to copy the file systems

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

These can take a while, especially the /home dump/restore if
it is large.  

Once you are finished with this you need to fix up 
the /etc/fstab file on /newroot.
After this, when you reboot, as long as ad0 is in front of ad4 in
the BIOS boot sequence, the system will attempt to boot from ad0.
Since there are more than one bootable disks now on the machine,
it should give you a menu of bootable slices from which you can select.

Have fun,

jerry

> 
> -- 
> -Chris
> __

Re: Copying a FreeBSD install to a smaller disk

2008-09-11 Thread Giorgos Keramidas
On Fri, 12 Sep 2008 04:55:36 +0300, Giorgos Keramidas <[EMAIL PROTECTED]> wrote:
> [8] The final step was to chroot [...]
> [9] Finally, I checked the new `/etc/fstab' [...]

Heh!  Adding `one last "final" step' didn't really work very well in
this case.  I should have read the long message another time before
hitting `send'.

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


Re: Copying a FreeBSD install to a smaller disk

2008-09-11 Thread Giorgos Keramidas
On Thu, 11 Sep 2008 17:19:55 -0700, "Chris Weiss" <[EMAIL PROTECTED]> wrote:
> How would I go about copying an existing FreeBSD installation to a smaller 
> disk?
>
> I've got a 3rd FreeBSD install I can boot from and store temporary
> files on, all the disks are in the same hardware, so there's no
> reconfiguration other than the boot device name and interface (IE
> -SATA ad4 will become IDE ad0). The disk is partitioned using the
> "default" sysinstall values and the contents of the larger disk will
> fit on the smaller disk, although I need to increase the size of the /
> and /var slices on the target to hold everything (/usr is fairly
> empty, so it'll easily fit on the smaller disk).
>
> For now, we'll say ad0 = new smaller disk, ad4 = boot BSD disk, and
> ad6 = the BSD install I want to clone.
>
> The path I've been going down is to manually partition and slice ad0
> create ad4/mnt/source and ad4/mnt/target and mount /var, /tmp, etc
> from ad0 and ad6 and manually copy the files. But I'm stuck on how to
> handle /, since it'll have dev and proc and such.

Hi Chris,

If all you want is to make ad0 bootable, you don't need the *contents*
of the /dev and /proc file systems.  They are dynamically generated by
the kernel when you mount these file systems and access them.

If the used disk space in ad6 (the clone source drive) is less than the
size of the clone target, it should be possible to copy the source files
using any of:

* tar
* dump & restore
* cpio

Some care must be taken to avoid copying special file systems, like /dev
and /proc that you mentioned.  If you use something like a Live CD-ROM
to boot, instead of booting from the 'source' disk, this should be easy,
because the special /dev and /proc file systems will be mounted only for
the *boot* device (the CD-ROM in this case), so the hard disk partitions
will merely include empty directories as `potential mount-points' for
the /dev, /proc and other special places.

FWIW, the steps I followed when I cloned my old laptop installation to a
new hard disk are the ones shown below.  I didn't want to open the
laptop, because that would violate its guarantee terms.  So I kept the
'target' disk as ad0 and used a USB-attached enclosure for 2.5" hard
disks to attach the original 'source' disk (taken out of my old, dead
laptop).

[1] Boot from CD-ROM using a FreeSBIE installation(*).

(*) Many thanks to the FreeSBIE folks, for making such an easy to
use Live CD-ROM.  I have found it very useful far too many times to
mention all of them in an email post!

[2] Create an /mnt/source and /mnt/target directory.

# mkdir -p /mnt/source
# mkdir -p /mnt/target

[3] Mount the source root partition, and then use the existing mount
points under that source tree to mount the target partitions:

# mount -o ro /dev/da0s1a /mnt/source
# mount -o ro /dev/da0s1e /mnt/source/home

Note that, for extra safety, I mounted the source partitions as
read-only.  This way I would at least get a warning if I botched the
copying process, and avoid messing my original 'source' data.

[4] Partition and mount the target disk (the internal ad0 disk of the
laptop).  This is where booting from a Live CD-ROM helped a lot,
because I didn't have to do anything special to 'resize' or 'keep'
parts of the disk unpartitioned.  I could use the *full* disk for
the new installation.

# fdisk -BI /dev/ad0
# bsdlabel -w -B /dev/ad0s1
# bsdlabel -e /dev/ad0s1

When I had configured the new ad0s1a and ad0s1e partitions, I saved
the label and exited bsdlabel's editor.

[5] Format the target partitions:

# newfs -L MYROOT /dev/ad0s1a
# newfs -L MYHOME -U /dev/ad0s1e

The -L labels are entirely optional, and, as you can see, I only
enabled softupdates on the new /home partition.

[6] Mount the target partitions under `/mnt/target'.  The mounts were
read-write this time:

# mount /dev/ad0s1a /mnt/target
# mkdir /mnt/target/home
# mount /dev/ad0s1e /mnt/target/home

Note that the second command is not optional.  The new root file
system was brand new, so it appears completely empty after being
mounted.

[7] Copy everything using BSD tar(1):

# tar -C /mnt/source -cf - . | tar -C /mnt/target xvf -

[8] The final step was to chroot into the new 'target' system, and
fix-up any special directory permissions, by using the mtree(8)
specifications from `/etc/mtree'.  This restores any special flags
like `noschg' or the permissions required for proper daemon
operation in `/var/run' and so on.

To avoid side-effects from the runtime environment of the shell I
was using `outside' of the chroot, I cleared all environment
variables, and manually set only the bare minimum of stuff I needed
`inside' the chroot:

# env -i USER='root' SHELL='/bin/csh' HOME='/root' \
  PATH='/bin:/sbin

Copying a FreeBSD install to a smaller disk

2008-09-11 Thread Chris Weiss
How would I go about copying an existing FreeBSD installation to a smaller disk?

I've got a 3rd FreeBSD install I can boot from and store temporary
files on, all the disks are in the same hardware, so there's no
reconfiguration other than the boot device name and interface (IE
-SATA ad4 will become IDE ad0). The disk is partitioned using the
"default" sysinstall values and the contents of the larger disk will
fit on the smaller disk, although I need to increase the size of the /
and /var slices on the target to hold everything (/usr is fairly
empty, so it'll easily fit on the smaller disk).

For now, we'll say ad0 = new smaller disk, ad4 = boot BSD disk, and
ad6 = the BSD install I want to clone.

The path I've been going down is to manually partition and slice ad0
create ad4/mnt/source and ad4/mnt/target and mount /var, /tmp, etc
from ad0 and ad6 and manually copy the files. But I'm stuck on how to
handle /, since it'll have dev and proc and such.

Any thoughts on how to do this, or on a completely different approach?
I'm not aware of any 3rd party tools that'll deal with shrinking
FreeBSD partitions.

Thanks in advance for any help you folks can give!

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