Posts tagged ‘ZFS’

How to install FreeBSD 8.0 using only ZFS partitions? (Newbie proof, I hope)

Ok, so I want to install the newly released FreeBSD 8.0 and only have ZFS partitions.

Questions I had that I am answering here for you:

  1. Does Sysinstall support ZFS?

    No. You have to install manually using Fixit.

  2. Can I boot off a ZFS partition?

    Yes, you can. Takes some effort to set it up though.

  3. Is it easy?

    No, it isn’t easy it is hard. Unless you have used FreeBSD for some time, then it is just tedious and not really easy or hard.

  4. Is there a guide?

    Yes, it is here:
    But hopefully by the time I am done, the best guide will be this post.

Ok, so here it goes, I am following this guide:
I am going to improve upon it and try to make it newbie proof and not skip steps in my guide when this guide skips steps. Why am I making it newbie proof? I don’t know, you would think if you are doing ZFS you aren’t a newbie, but who knows. Better safe than sorry.

Steps for How to install FreeBSD 8.0 using only ZFS partitions?
Step 1. Creating a bootable ZFS Filesystem

  1. Download the FreeBSD 8 DVD ISO from here:
    Ok, so this isn’t exactly a download link, but it takes you to where you choose your architecture. Click on the [ISO] link next to your Architecture type.
    If you are a newbie and don’t know your architecture, you probably want i386. If you just bought a new 64 bit machine then you want amd64.
    Ok, so the actually link you want is the one that looks as follows:
    For amd64 – 8.0-RELEASE-amd64-dvd1.iso.gz
    For i386 – 8.0-RELEASE-i386-dvd1.iso.gz

  2. Extract it as it is zipped.
  3. Burn the ISO to DVD disk (or if you are using VMWare just point your VM’s CD-ROM at the ISO).
  4. Boot off the FreeBSD 8 DVD and let it boot all the way up.
  5. Choose your country/region.
    You should now be at the Sysinstall Main Menu. Remember, we cannot use Sysinstall because it doesn’t yet support ZFS. (I am hoping for a new installer over fixing this old one.)

  6. Choose Fixit. You will be promted to Please choose a fixit option.
  7. Choose CDROM/DVD.
    You are now at a Fixit command prompt. And if you are following the wiki guide, you are only at that guide’s step 3. Create MBR disk

  8. Create an MBR disk by running the following command:
    gpart create -s mbr ad0

    However, what the guide assumes you already know is that ad0 is the name of your hard drive and can be different for each installation. I am installing on VMWare using SCSI and the name of my hard drive is da0. So I would run:

    gpart create -s mbr da0

    You can find out your by looking at a directory listing of /dev if you are familiar with common names, otherwise, you can start a Standard install and see what name is used when you get to the Disk label editor section of the install.

    I am going to use da0 or ad0 in the rest of my document interchangeably, so you need to remember to always use the correct disk name for your drive.

  9. Run the following command to show the information for your disk
    gpart show ad0

    There are two columns of numbers. The first column number is a start block for the slice and the second is the size in blocks for the slice. 63 is the start of every first slice. However, the end of a slice is variable depending on the size of your hard drive.

    A slice is not exactly a partition. On FreeBSD you first create a Slice and then you create your partitions on your slice. The next steps will show you have to do both.

  10. Create a new Slice using the entire disk.

    Obviously the guy who wrote the wiki I am following already had two slices for windows, so he must have been dual booting. I am assuming that you are not dual booting and that you are installing a new server and you plan to use the entire disk.

    To create a slice using the entire disk, run this command replacing the value after the -s with the value you saw when you ran the previous command.

    gpart add -b 63 -s 104857515 -t freebsd da0

    It will output something like “da0s1 added”. If you look at the da0s1 string, it makes sense. da0 (your disk name) s1 (slice 1 – the slice you just created).

  11. Now lets create our slice. No, I am not sure why you have to both add the slice and create the slice, but I am sure there is a good reason.
    gpart create -s BSD da0s1
  12. Lets make our slice the active slice. Sounds like this is only sometimes needed. Better to do it and not need it than to not do it an find out you need it.
    gpart set -a active -i 1 da0

    You can run the gpart show da0 command again to make sure it is set as active.

  13. Look at the slice.
    gpart show da0s1

    Again, you will have two rows of numbers. This time the first number is 0 and the second number is the size of the slice.

    We want at least two partitions, one for / and one as a swap partition. So we need to determine how much space we want for the swap partition. I want 3 GB.

    Now we have to convert the desired size from GB to sectors.

    1 kilobyte = 1024 bytes or 2 sectors (Sectors are normally 512 Bytes)
    1 megabyte = 1024 kilobytes
    1 gigabyte = 1024 megabytes

    So to get the number of sectors in 1 GB, we need to use the following equation:

    Gigabytes in Sectors = NumberOfGB * numberOfMBInAGB * NumberOfKBInAMB * NumberOfSectorsInAKB

    1 GB in sectors = 1 * 1024 * 1024 * 2 = 2097152
    3 GB in sectors = 3 * 1024 * 1024 * 2 = 6291456

    So take the total size of your slice in sectors and subtract 6291456 and you will have the size of your / partition. And our swap partition will be 6291456.

  14. Create your / partition.
    gpart add -i 1 -b 0 -s 98566059 -t freebsd-zfs da0s1
  15. Create the swap partition.
    gpart add -i 2 -b 98566059 -s 6291456 -t freebsd-swap da0s1
  16. Load the ZFS kernel module.
    kldload /mnt2/boot/kernel/opensolaris.ko
    kldload /mnt2/boot/kernel/zfs.ko
  17. Create your zpools.
    mkdir /boot/zfs
    zpool create zroot /dev/da0s1a
    zpool set bootfs=zroot zroot
  18. Install the boot manager.
    gpart bootcode -b /mnt2/boot/boot0 da0
  19. Install ZFS boot.
    zpool export zroot
    dd if=/mnt2/boot/zfsboot of=/dev/da0s1 count=1
    dd if=/mnt2/boot/zfsboot of=/dev/da0s1a skip=1 seek=1024
    zpool import zroot

Yeah we are done with step 1. Stay tuned for step 2 and step 3 coming.

… I am back for round 2…er uh…step 2 that is.

Step 2. Installing FreeBSD to the ZFS filesystem

Ok for those of you who skipped the details above, I am reading this wiki:

My intention is to make a more thorough and newbie proof version of this wiki. So here we go, diving into step 2.

  1. Create the ZFS hierarchy.

    Wow, this is going to be a lot of tedious typing. You know, while FreeBSD didn’t make an installer for all this, how hard would it have been to create a couple of scripts and include them on the CD so this would be easier.

    zfs set checksum=fletcher4 zroot

    zfs create -o compression=on -o exec=on -o setuid=off zroot/tmp
    chmod 1777 /zroot/tmp

    zfs create zroot/usr
    zfs create zroot/usr/home
    cd zroot ; ln -s /usr/home home

    zfs create -o compression=lzjb -o setuid=off zroot/usr/ports
    zfs create -o compression=off -o exec=off -o setuid=off zroot/usr/ports/distfiles
    zfs create -o compression=off -o exec=off -o setuid=off zroot/usr/ports/packages

    zfs create -o compression=lzjb -o exec=off -o setuid=off zroot/usr/src

    zfs create zroot/var
    zfs create -o compression=lzjb -o exec=off -o setuid=off zroot/var/crash
    zfs create -o exec=off -o setuid=off zroot/var/db
    zfs create -o compression=lzjb -o exec=on -o setuid=off zroot/var/db/pkg
    zfs create -o exec=off -o setuid=off zroot/var/empty
    zfs create -o compression=lzjb -o exec=off -o setuid=off zroot/var/log
    zfs create -o compression=gzip -o exec=off -o setuid=off zroot/var/mail
    zfs create -o exec=off -o setuid=off zroot/var/run
    zfs create -o compression=lzjb -o exec=on -o setuid=off zroot/var/tmp
    chmod 1777 /zroot/var/tmp

    cd /dist/8.0-RELEASE
    export DESTDIR=/zroot
    for dir in base catpages dict doc games info lib32 manpages ports; \
    do (cd $dir ; ./ ; done
    cd src ; ./ all
    cd ../kernels ; ./ generic
    cd /zroot/boot ; cp -Rlp GENERIC/* /zroot/boot/kernel/
    zfs set readonly=on zroot/var/empty

    chroot /zroot

    echo ‘zfs_enable=”YES”‘ > /etc/rc.conf
    echo ‘hostname=”zfs.mydomain.local”‘ >> /etc/rc.conf
    echo ‘ifconfig_em0=”DHCP”‘ >> /etc/rc.conf

    echo ‘zfs_load=”YES”‘ > /boot/loader.conf
    echo ‘vfs.root.mountfrom=”zfs:zroot”‘ >> /boot/loader.conf

    echo ‘LOADER_ZFS_SUPPORT=YES’ > /etc/src.conf

    mount -t devfs devfs /dev
    export DESTDIR=””

    cd /usr/src/sys/boot/
    make obj
    make depend
    cd i386/loader
    make install



    cd /etc/mail
    make aliases
    umount /dev
    cp /boot/zfs/zpool.cache /zroot/boot/zfs/zpool.cache

Warning! There is only one line that might catch a newbie off-guard. Every other line you can type in as is but this one.

echo ‘ifconfig_em0=”DHCP”‘ >> /etc/rc.conf

On FreeBSD this is how you setup your network card to use FreeBSD. However, while my card is em0, not all cards are em0. Run the ifconfig command on FreeBSD to see your card type and replace em0 with the type for you card.

Step 3 – Finish

I followed the guide almost exactly except I had to do a cd / before unmounting. So I added that command where it needs to be, so this should be very newbie proof.

  1. Run these commands.
    cat < /zroot/etc/fstab # Device Mountpoint FStype Options Dump Pass# /dev/ad0s3b none swap sw 0 0 EOF export LD_LIBRARY_PATH=/mnt2/lib cd / zfs unmount -a zfs set mountpoint=legacy zroot zfs set mountpoint=/tmp zroot/tmp zfs set mountpoint=/usr zroot/usr zfs set mountpoint=/var zroot/var

I made some mistakes but finally got it to work.