DragonFly BSD

howto reinstall hammer

* THIS GUIDE IS INCOMPLETE *

Scenario

I have got a 250GB SATA harddisk with DragonFlyBSD 2.3.2 32-bit installed on it.

Actually I want to repartition my harddisk in order to install other OSes besides DragonFly, so for that I need to shrink the current installation size. Above all, I would like my system just like it is now.

Although several methods could be used, as this is a HAMMER installation, I'm going to use HAMMERS's mirror-{read,write} capabilities. This assumes you cannot store the PFSs in another HAMMER disk so that you have to store physical data compressed in files that can be put in any share you have.
Here I will be using a NFS share.

Pre-steps

HAMMER version

You should check that your HAMMER version is at least 2 (NORM 2.3 - New directory entry layout).

smash64# hammer version /
min=1 wip=3 max=2 current=2 description="2.3 - New directory entry layout"
available versions:
    1   NORM    2.0 - First HAMMER release
    2   NORM    2.3 - New directory entry layout

If not, you would have to use hammer version-upgrade. See hammer(8) for details.

LiveCD

You will need a DragonFlyBSD LiveCD in order to perform steps for the new installation. Release 2.4.0 or later is recommended. Download the ISOs from here.

/boot partition

Note that if your /boot is out of the ROOT HAMMER filesystem, you should copy the data also, so you can restore your current kernel in the new installation. Having kernel and world out of sync can be a problem sometimes. You have been warned.

Data backup

At this point you should have a place ready to store all the compressed files you are going to generate. In our case:

smash64# df -h /mnt/pfs
Filesystem                 Size   Used  Avail Capacity  Mounted on
dualsmash:/home/data/pfs   364G   235G   111G    68%    /mnt/pfs
smash64#

So we can start saving all our data:

smash64# cd /mnt/pfs

smash64# hammer mirror-read / | gzip -3 -c > root.gz
histogram range 0000000000000000 - 000000129a02c4b0
Mirror-read: Mirror from 0000000000000000 to 000000129a02c4b0
smash64#

smash64# hammer mirror-read /var | gzip -3 -c > var.gz
histogram range 0000000000000001 - 000000129a02c4f0
Mirror-read: Mirror from 0000000000000001 to 000000129a02c4f0
Mirror-read /var succeeded
smash64#

smash64# hammer mirror-read /tmp | gzip -3 -c > tmp.gz
histogram range 0000000000000001 - 000000129a02c790
Mirror-read: Mirror from 0000000000000001 to 000000129a02c790
Mirror-read /tmp succeeded
smash64#

[....]

Make sure the shared storage you have used is available for the LiveCD.

New installation process

Booting LiveCD

Boot the LiveCD in the machine you want to install. You can run installer in order to do some basic configurations for the LiveCD environment, under option "LiveCD utilities", and then exit again to the shell.

Backup data accesibility

Prepare the share where you have the backup data: # mkdir /root/pfs # mount 192.168.3.1:/home/data/pfs /root/pfs # df -h /root/pfs Filesystem Size Used Avail Capacity Mounted on 192.168.3.1:/home/data/pfs 364G 247G 98G 72% /root/pfs

Creating disk layout

This part is critical. With this you will lose all the data on the disk you have chosen.

*Warning: You are discouraged to use fdisk. Use another partition utility while you can *

Initalize the disk and partition it. After that, you will have to manually partition your disk, and with fdisk can be no fun.

# fdisk -BI ad4
# fdisk -i

( this is only an extract )

[....]

Do you want to change our idea of what BIOS thinks ? [n] 
Media sector size is 512
Warning: BIOS sector numbering starts with sector 1
Information from DOS bootblock is:
The data for partition 1 is:
sysid 165,(DragonFly/FreeBSD/NetBSD/386BSD)
    start 63, size 148990401 (72749 Meg), flag 0
        beg: cyl 0/ head 1/ sector 1;
        end: cyl 1023/ head 255/ sector 63
Do you want to change it? [n] y
Supply a decimal value for "sysid (165=DragonFly)" [0] 165
Supply a decimal value for "start" [0] 63
Supply a decimal value for "size" [0] 148990401
Explicitly specify beg/end address ? [n] 
Warning: ending cylinder wraps, using all 1's
sysid 165,(DragonFly/FreeBSD/NetBSD/386BSD)
    start 63, size 148990401 (72749 Meg), flag 0
        beg: cyl 0/ head 1/ sector 1;
        end: cyl 1023/ head 255/ sector 63
Are we happy with this entry? [n] y
Do you want to change the active partition? [n] y
Supply a decimal value for "active partition" [1] 1
Are you happy with this choice [n] y

[....]

Information from DOS bootblock is:
1: sysid 165,(DragonFly/FreeBSD/NetBSD/386BSD)
    start 63, size 148990401 (72749 Meg), flag 80 (active)
        beg: cyl 0/ head 1/ sector 1;
        end: cyl 1023/ head 255/ sector 63
2: <UNUSED>
3: <UNUSED>
4: <UNUSED>
Should we write new partition table? [n] y

Now that we have the partition, we can create the slices for our new installation.

As of now, the recommended configuration is /boot on UFS and / can be HAMMER.

So you do: # disklabel64 -r -w ad4s1 auto # disklabel64 -e ad4s1

(do the layout you want)

# disklabel64 ad4s1
#          size     offset    fstype   fsuuid
  a:     262144          0    4.2BSD    #     256.000MB
  b:    1048576     262144      swap    #    1024.000MB
  d:   73184440    1310720    HAMMER    #   71469.180MB

Finally, we create the filesystems:

# newfs /dev/ad4s1a
/dev/ad4s1a: media size 256.00MB
Warning: Block size restricts cylinders per group to 94.
/dev/ad4s1a:    524288 sectors in 128 cylinders of 1 tracks, 4096 sectors
        256.0MB in 2 cyl groups (94 c/g, 188.00MB/g, 16256 i/g)
super-block backups (for fsck -b #) at:
 32, 385056

# newfs_hammer -L ROOT /dev/ad4s1d
Volume 0 DEVICE /dev/ad4s1d     size  69.79GB
initialize freemap volume 0
---------------------------------------------
1 volume total size  69.79GB version 2
boot-area-size:       64.00MB
memory-log-size:     256.00MB
undo-buffer-size:    104.00MB
total-pre-allocated: 120.00MB
fsid:                738615f8-a702-11de-8ec9-011617eff231

[....]

Prepare mount points

Now we setup the mount points where the data will actually be restored.

You will need

# mkdir /root/target
# mount_hammer /dev/ad4s1d /root/target
# mkdir /root/target/boot
# mkdir /root/target/pfs
# mount /dev/ad4s1a /root/target/boot

You must create an intermediate slave PFS in order to restore / mount. PFS#0 cannot be downgraded to slave, so you have no choice here.

Restoring the data

Let's start recovering our data into the physical media:

# gunzip -c /root/pfs/usr.gz | hammer mirror-write /root/target/pfs/usr
PFS slave /root/target/pfs/usr does not exist.
Do you want to create a new slave PFS? (yes|no) y
Creating PFS #1 succeeded!
[....]

# gunzip -c /root/pfs/var.gz | hammer mirror-write /root/target/pfs/var
PFS slave /root/target/pfs/var does not exist.
Do you want to create a new slave PFS? (yes|no) yes
Creating PFS #2 succeeded!
And so on with all the PFSs we backed up.
[....]

Now we need to restore our / in the intermediate PFS, then cpdup it into our target dir:

# gunzip -c /root/pfs/root.gz | hammer mirror-write /root/target/pfs/rootcopy
PFS slave /root/target/pfs/rootcopy does not exist.
Do you want to create a new slave PFS? (yes|no) y
Creating PFS #6 succeeded!
[....]
# cpdup -vv -I /root/target/pfs/rootcopy/ /root/target/
# cd /root/target/pfs/rootcopy/boot && cpdup . /root/target/boot

Fixing the configuration

Our next step is to make all our slave PFS to master and wipe out rootcopy, which is temporary.

Also we will create /usr/obj, /var/tmp and /var/crash PFSs.

# hammer pfs-destroy /root/target/pfs/rootcopy/
You have requested that PFS#6 () be destroyed
This will irrevocably destroy all data on this PFS!!!!!
[....]
# rm /root/target/pfs/rootcopy 

# hammer pfs-upgrade /root/target/pfs/usr
pfs-upgrade of PFS#3 () succeeded
# hammer pfs-upgrade /root/target/pfs/tmp
pfs-upgrade of PFS#2 () succeeded
# hammer pfs-upgrade /root/target/pfs/home
pfs-upgrade of PFS#4 () succeeded
# hammer pfs-upgrade /root/target/pfs/var
pfs-upgrade of PFS#1 () succeeded
# hammer pfs-master /root/target/pfs/var.tmp
Creating PFS #7 succeeded!
# hammer pfs-master /root/target/pfs/var.crash
Creating PFS #8 succeeded!
# hammer pfs-master /root/target/pfs/usr.obj
Creating PFS #9 succeeded!

Finally fix your /etc/fstab to match your new slice entries!

Booting

Problems after the new installation.