FreeBSD fdisk how to?

Roland Smith rsmith at
Sat Jun 21 10:07:35 UTC 2008

On Sat, Jun 21, 2008 at 11:26:01AM +0200, Nejc Škoberne wrote:
> Hi,
> > Well, fdisk(8) is somewhat cumbersome to use.  Personally I tend to invoke
> > sysinstall(8) to create new slices (can be done after install too.)  Much
> > easier to use.
> OT, but: does sysinstall's "fdisk" also support gmirror and gstripe devices?


> Or do I need to use fdisk to make slices there?

Yes. But it is not hard.

First of all: _make backups_ !

To create this mirror configuration, the machine is booted from a CD
which contains a live filesystem. I used the
7.0-RELEASE-amd64-livefs.iso image to create this CD. After the machine
boots, the sysinstall(8) application is started automatically. In the
first two menus you have to set your location and keyboard type. The
location doesn't really matter since we won't be installing anything. It
is probably best to choose the default keyboard layout, unless you know
otherwise. Next the ``Fixit'' option is chosen, followed by the
``CDROM/DVD'' option in the next menu. We are now in the shell of the
livefs. The first order of business is to check if the disks have been
recognized. The command

# ls /dev/ad*

should return two disks. 
Now it is time to create a mirrored device using
the gmirror(8) tool. Next the mirror is activated by loading the
geom_mirror kernel module. After the kernel module has been
loaded, the mirrored device \texttt/dev/mirror/gm0 should appear.

# gmirror label gm0 ad4 ad6
# kldload /mnt2/boot/kernel/geom_mirror.ko

Now it is time to devide the disks into slices (which are called partitions
in PC parlance). The -I option creates one FreeBSD slice covering
the entire disk. The -B option writes a boot block.

# fdisk -vBI /dev/ad4
# fdisk -vBI /dev/ad6

Now that the disk has been given a single slice, a new device
/dev/mirror/gm0s1 will appear. We will now subdivide that into
FreeBSD partitions using bsdlabel(8). First we will write a standard
label and boot blocks. 

# bsdlabel -wB /dev/mirror/gm0s1
# export EDITOR=/mnt2/usr/bin/ee
# bsdlabel -e /dev/mirror/gm0s1

The command in the middle sets the editor to something more user friendly
then vi! The last command will open a text editor with the
partition table that the first command made. It should be edited to look
like the following (for example);

# /dev/mirror/gm0s1:
8 partitions:
#  size  offset  fstype  [fsize bsize]
a: 500M  16      4.2BSD  2048 16384  # /
b: 8G    *       swap                # Reserved for swap.
c: *     *       unused  0    0      # "raw" part.
d: 2G    *       4.2BSD   2048 16384 # /var
e: 50G   *       4.2BSD   2048 16384 # /tmp
f: 20G   *       4.2BSD   2048 16384 # /usr
g: *     *       4.2BSD   2048 16384 # /home

The disk partitions are now ready to put the filesystems on them. To
minimize the chance of problems with the root partition, softupdates are
not enabled for root.

# newfs /dev/mirror/gm0s1a
# newfs -U /dev/mirror/gm0s1d
# newfs -U /dev/mirror/gm0s1e
# newfs -U /dev/mirror/gm0s1f
# newfs -U /dev/mirror/gm0s1g

Now you can restore your backups.

Before you reboot, edit /etc/fstab to mount the right partitions.

And edit /boot/loader.conf to load the geom_mirror module.

# echo 'geom_mirror_load="YES"' >>/boot/loader.conf

[plain text _non-HTML_ PGP/GnuPG encrypted/signed email much appreciated]
pgp: 1A2B 477F 9970 BA3C 2914  B7CE 1277 EFB0 C321 A725 (KeyID: C321A725)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 195 bytes
Desc: not available
Url :

More information about the freebsd-questions mailing list