Home

Installing FreeBSD on GPT

GPT vs MBR

FreeBSD

The MBR (master boot record) is getting old. As soon as first 2 Terabyte hard drives begin to appear, it won't be able to hold such a big partition and won't even be able to use the whole drive anymore.

GPT is a new scheme for partition tables on many platforms by now. Usually you would need an EFI BIOS to start up a system partitioned with the GPT layout. But FreeBSD has a way to use an MBR to forward the loading to the GPT boot loader. This is actually a nice way to keep everything compatible, as long as mainboards with EFI are scarce.

What you need

FreeBSD

I have written this tutorial for people who don't have any system installed and want to install FreeBSD on a blank hard disk. I want to give you this warning first, because all that you will achieve here is to destroy any data on your hard drive. So be aware that this is dangerous and don't forget to backup your data properly.

So what you need here is:

Booting from FreeBSD live CD

After FreeBSD live CD booted, you have to select your country and keyboard layout. Then select Fixit and CDROM/DVD. You get a nice prompt saying Fixit #.

I'm using tcsh for my configuration, so I'm starting it first by typing:

tcsh

Partitioning the hard drive

FreeBSD

I start by initialising an empty GPT. Note that the tools often are hidden in the /dist directory and it is not a part of the PATH environment.

I want to emphasize once again. You will destroy everything on your hard disk with the following commands!

/dist/sbin/gpart create -s GPT ad0

The command

/dist/sbin/gpart show

gives you the current partitioning status. You can use it any time you want and you will need it again and again to find the next sector you can use for the next partition.

I get the following output. I will explain it, so you know how to partition your own hard drive.

=> 34 39999935 ad0 GPT (20.5GB) 34 39999935 - free - (20.5GB)

The first line tells you about your hard drive. You can start partitioning from sector 34 and the last available sector is 39999935. The second line gives information that there is free space beginning at sector 34 and spreading to sector 39999935. Ok, it means that the drive is empty.

First I need a partition for the boot sector. You can add it with the following command. You will need at least 16 sectors (8kB), but you can use more. You should perhaps keep in mind that the boot process has to load the entire boot partition to the memory to start it, so don't make it too large. If you don't know what you are doing, use 16 sectors.

/dist/sbin/gpart add -b 34 -s 16 -t freebsd-boot ad0

I added a freebsd-boot partition at sector 34 with 16 sectors on drive ad0. The partition name is ad0p1. Note the suffix p1 and don't forget that there are no slices here that you know from MBR. In case you plan to install FreeBSD on ZFS and boot it directly on a ZFS root file system, you might want to use 64 sectors (parameter -s, because you will need to transfer the file gptzfsboot which is a bit larger.

I will add more partitions here for my FreeBSD needs. You can calculate the sectors by looking at the output of /dist/sbin/gpart show.

/dist/sbin/gpart add -b 50 -s 1048576 -t freebsd-ufs ad0 /dist/sbin/gpart add -b 1048626 -s 1048576 -t freebsd-swap ad0 /dist/sbin/gpart add -b 2097202 -s 1048576 -t freebsd-ufs ad0 /dist/sbin/gpart add -b 3145778 -s 6144000 -t freebsd-ufs ad0 /dist/sbin/gpart add -b 9289778 -s 24576000 -t freebsd-ufs ad0 /dist/sbin/gpart add -b 33865778 -s 6134191 -t freebsd-ufs ad0

I have the following partition layout now:

PartitionTypeSizeFile system
ad0p1freebsd-boot8kB-
ad0p2freebsd-ufs512MB/
ad0p3freebsd-swap512MBswap
ad0p4freebsd-ufs512MB/tmp
ad0p5freebsd-ufs3GB/var
ad0p6freebsd-ufs12GB/usr
ad0p7freebsd-ufs3GB/usr/home

Optionally, you can use filesystems of type freebsd-zfs, but I would not recommend it for anything except /usr/home. If you use ZFS boot, you might want to use ZFS only in your partitions

Making your drive bootable

The step that you should not forget is to make the drive bootable. We have a partition layout now, but your system won't start up at this moment. First I want to write the main boot bootcode. This is easy.

/dist/sbin/gpart bootcode -b /dist/boot/pmbr -p /dist/boot/gptboot -i 1 ad0

I tell gpart to write the bootcode to partition ad0p1 hence the -i 1.

Initializing file systems

Now I will make the new file systems ready to copy files on it.

newfs -O2 /dev/ad0p2 newfs -O2 -U /dev/ad0p4 newfs -O2 -U /dev/ad0p5 newfs -O2 -U /dev/ad0p6 newfs -O2 -U /dev/ad0p7

It is up to you, if you want to use encryption (geli) and/or journaling at this point. You have to use the proper tools for this. The live CD has everything needed in /dist/sbin. Just don't forget to add the modules to the kernel in your /boot/loader.conf later.

Installation process

FreeBSD

The easiest thing is to fetch the install image, mount it and execute the installation scripts on the mounted destination file systems. There are, of course many ways how to install the base system. It depends where you install it and how your system and network looks like. You can also mount /usr/src and /usr/obj from some other FreeBSD system and install world and kernel. The process is a little bit more complex, though, and needs more manual intervention.

First I need my network interface up. I will use DHCP and I need to create a directory for dhclient to run it.

mkdir /var/db dhclient ed0

In next step, I need more space than my live CD offers, so I am going to mount my file systems in the /mnt subdirectory.

/dist/sbin/mount /dev/ad0p2 /mnt mkdir /mnt/tmp /mnt/var /mnt/usr /dist/sbin/mount /dev/ad0p4 /mnt/tmp /dist/sbin/mount /dev/ad0p5 /mnt/var /dist/sbin/mount /dev/ad0p6 /mnt/usr mkdir /mnt/usr/home

Now it is time to download the installation CD from my favorite FTP mirror. This can take a few minutes, depending on your download speed.

cd /mnt/usr /dist/usr/bin/fetch ftp://ftp.de.freebsd.org/pub/FreeBSD/releases/amd64/ISO-IMAGES/7.1/7.1-BETA2-amd64-disc1.iso

After finished downloading, I will mount the ISO image.

/dist/sbin/mdconfig -a -t vnode -f 7.1-BETA2-amd64-disc1.iso mkdir /mnt/cdrom /dist/sbin/mount_cd9660 /dev/md1 /mnt/cdrom

Now, I want to install all needed FreeBSD distribution files.

setenv DESTDIR /mnt setenv PATH ${PATH}:/mnt2/usr/bin cd /mnt/cdrom/7.1-BETA2/base sh install.sh cd ../kernels sh install.sh GENERIC rmdir /mnt/boot/kernel mv /mnt/boot/GENERIC /mnt/boot/kernel

Final setup

Now a totally empty FreeBSD distribution has been installed, but you still need some important settings to boot the system properly. I will therefore chroot into /mnt and setup the rest of the system.

/dist/usr/sbin/chroot /mnt /bin/tcsh passwd root

I need a /etc/fstab file. I will create it with vi.

/dev/ad0p2 / ufs rw 1 1 /dev/ad0p3 none swap sw 0 0 /dev/ad0p4 /tmp ufs rw 2 2 /dev/ad0p5 /var ufs rw 2 2 /dev/ad0p6 /usr ufs rw 2 2 /dev/ad0p7 /usr/home ufs rw 2 2

And also a /etc/rc.conf file. It will look like this for a start. I need a German keyboard layout and I like my key rate fast.

hostname="myhost" ifconfig_ed0="DHCP" keymap="german.iso" keyrate="fast"

Tidying up and rebooting the system

Ok, now the system should be ready to boot. I need to unmount my file systems cleanly and tidy up the rest.

exit /dist/sbin/umount /mnt/cdrom /dist/sbin/mdconfig -d -u 1 /dist/sbin/umount /mnt/usr /dist/sbin/umount /mnt/var /dist/sbin/umount /mnt/tmp /dist/sbin/umount /mnt exit exit

At this point we are back on the live CD GUI. Select Exit and then Exit Install. I am going to reboot the PC with my first hard drive now, where the fresh FreeBSD installation on the GPT is.

Done!

At this point everything should be set up. You should see your login prompt.

FreeBSD/amd64 (myhost) (ttyv0) login:

You can log in using your root password, update your system, install software and set up the rest of your system and software.

What should I say more? Have fun!


m8d.de, 2008