Datenschutz
Home/IT/OpenBSD/Replacing Hard Disks  

OpenBSD on VMware  

 

Fragmentation

One problem of all unsupported VMware guest operating systems is the fragmentation of the virtual hard disks. These disk images are large regular files from the host's point of view. In my case I have two hard disks made of four files each (8 GB capacity each disk). The size of these files is starting at almost zero and is growing once the virtual hard disks are going to be formated and filled with data. Unfortunately, deleting data in the guest won't shrink the hard disk files. To free space, the disk images must decrease using the so called VMware tools which are not available for OpenBSD.

There are several strategies to limit the size of the hard disk images. One of them is the renewal of the virtual hard disks and will be explained here. On a real PC this would mean to replace the hard disks by new ones.

Creating New Hard Disks

With the following procedure the physical size of the virtual hard disks can be reduced and the hard disk layout or the total disk size may be changed if that ever should become necessary. First of all the data on the disks should be reduced to the minimum. Delete all needless files such as the web browser's cache, the ports directory /usr/ports/ or the operating system's source code in /usr/src/, basically all data that might be reinstalled easily. Power down the machine.

The first step is to create two new virtual hard disks using the Virtual Machine Control Panel. The new disks may get exactly the same size as the old ones, which makes it easier to transfer the disklabel, but they may differ to make changes in the layout as well. However, in this example the new disks will be identically to the old ones. The new hard disks are created in a new directory and are called new/openbsd-system.vmdk and new/openbsd-home.vmdk.

Preparing The Hard Disks

The next step is the transfer of the disk's content: IDE 0:0 (in OpenBSD language: wd0) will copied to IDE 1:0 (wd2), IDE 0:1 (wd1) to IDE 1:1 (wd3). Power on the virtual machine and boot into Single User Mode. Start typing the command within five seconds and mention the US keyboard layout.

boot> boot bsd -s
...
Enter pathname of shell or RETURN for sh:
# kbd de
# mount -a
# /usr/local/bin/bash -l
Terminal type? [dumb] vt220
#

The new hard disks must get a partition table which the PC's BIOS can understand. Four primary partitions will be created, one of them (the fourth) will declared as OpenBSD type. The other three are left empty. This is done using the program /sbin/fdisk.

# fdisk -i wd2
        -----------------------------------------------------
        ------ ATTENTION - UPDATING MASTER BOOT RECORD ------
        -----------------------------------------------------

Do you wish to write new MBR and partition table? [n] y
wd2: no disk label

# fdisk -i wd3
        -----------------------------------------------------
        ------ ATTENTION - UPDATING MASTER BOOT RECORD ------
        -----------------------------------------------------

Do you wish to write new MBR and partition table? [n] y
wd3: no disk label

Now the new OpenBSD partitions will get a disklabel, which specifies the borders of the slices within the partition. First I store the old disklabels in text files.

# disklabel wd0 > /etc/disklabels/wd0
# using MBR partition 3: type A6 off 63 (0x3f) size 8176833 (0x7cc4c1)
# disklabel wd1 > /etc/disklabels/wd1
# using MBR partition 3: type A6 off 63 (0x3f) size 8176833 (0x7cc4c1)

And then the disklabel may be transfered to the new disks. That means that the slices will have exactly the same sizes as before.

# disklabel -R wd2 /etc/disklabels/wd0
# using MBR partition 3: type A6 off 63 (0x3f) size 8176833 (0x7cc4c1)
# disklabel -R wd3 /etc/disklabels/wd1
# using MBR partition 3: type A6 off 63 (0x3f) size 8176833 (0x7cc4c1)

Okay, now the new slices must be formated. Please make no typo, as it could ruin all work already done...

# newfs wd2a
# newfs wd2d
# newfs wd2e
# newfs wd2f
# newfs wd2g
# newfs wd3a

In order to make the new system disk bootable, a Master Boot Record must be installed on it.

# mount /dev/wd2a /mnt/
# cp /boot /mnt/boot
# /usr/mdec/installboot -v /mnt/boot /usr/mdec/biosboot wd2
boot: /mnt/boot
proto: /usr/mdec/biosboot
device: /dev/rwd2c
/usr/mdec/biosboot: entry point 0
proto bootblock size 512
/mnt/boot is 3 blocks x 16384 bytes
fs block shift 2; part offset 63; inode block 24; offset 936
using MBR partition 3: type 166 (0xa6) offset 63 (0x3f)
# umount /mnt

Transferring Data

Now the data can be copied from the old disks to the new ones, one partition after each other. Every slice is mounted to /mnt and filled with the appropriate data.

# mount /dev/wd2a /mnt
# cd /
# tar cfX - . | (cd /mnt ; tar xpf - )
# umount /mnt

# mount /dev/wd2d /mnt
# cd /var
# tar cfX - . | (cd /mnt ; tar xpf - )
tar: Ustar cannot archive a socket ./cron/tabs/.sock
# umount /mnt

# mount /dev/wd2f /mnt
# cd /usr
# tar cfX - . | (cd /mnt ; tar xpf - )
# umount /mnt

# mount /dev/wd2g /mnt
# cd /usr/local
# tar cfX - . | (cd /mnt ; tar xpf - )
# umount /mnt

# mount /dev/wd3a /mnt
# cd /home
# tar cfX - . | (cd /mnt ; tar xpf - )
# umount /mnt

The data of the /tmp partition don't need to be copied:

# mount /dev/wd2e /mnt
# chmod 1777 /mnt
# umount /mnt
# halt -p

Switching The Hard Disks

Now the old disks may be removed from the computer. The new disks will be moved onto the final place and their original entries are removed from the machine's configuration file (using the Virtual Machine Control Panel). The CD-ROM drive can be reinstalled.

$ mkdir old/
$ mv openbsd-system* old/
$ mv openbsd-home* old/
$ mv new/openbsd-system* .
$ mv new/openbsd-home* .

At the end of the procedure everything should be in the same state as it was before, except that the disks need much less space on the host. If everything went well, the old disks may be removed.

$ rm -r old/