pavement

ZFS, booting from

From FreeBSDwiki
(Difference between revisions)
Jump to: navigation, search
(Created page with "Note: if you're using FreeBSD 7.x or 8.x, please see ZFS, booting from (pre 9.0-RELEASE) =Installing FreeBSD Root on ZFS (Mirror) using GPT= ==Creating a bootable ZFS Fi...")
 
 
(12 intermediate revisions by 2 users not shown)
Line 1: Line 1:
Note: if you're using FreeBSD 7.x or 8.x, please see [[ZFS, booting from (pre 9.0-RELEASE)]]
+
Note: '''THIS ARTICLE IS FOR 9.0-RELEASE AND UP!'''  If you're using FreeBSD 7.x or 8.x, please see [[ZFS, booting from (pre 9.0-RELEASE)]].
  
 
=Installing FreeBSD Root on ZFS (Mirror) using GPT=
 
=Installing FreeBSD Root on ZFS (Mirror) using GPT=
Line 5: Line 5:
 
==Creating a bootable ZFS Filesystem==
 
==Creating a bootable ZFS Filesystem==
  
Boot FreeBSD install DVD or USB Memstick, and choose the Fixit option in sysinstall.
+
Boot FreeBSD install DVD or USB Memstick, and choose Install.  Choose your keyboard mapping, hostname, and distribution components (doc, games, lib32, ports, and src - I'd highly advise you to leave ports selected!) as normal.  At the Partitioning stage, select <'''S'''hell>.
  
 
===Create GPT Disks===
 
===Create GPT Disks===
  
  Fixit# gpart create -s gpt ad0
+
In this stage we'll assume you have two drives, ada0 and ada1 - check your device names ('''ls /dev/ada*''') and adjust as appropriate, and of course if you have more drives, copy these commands for those drives as well. 
  Fixit# gpart create -s gpt ad1
+
 
 +
  # gpart create -s gpt ada0
 +
  # gpart create -s gpt ada1
  
 
===Create the boot, swap and zfs partitions===
 
===Create the boot, swap and zfs partitions===
  
Create 3 partitions on both drives ad0 and ad1. The first partition contains the gptzfsboot loader which is able to recognize and load the loader from a ZFS partition. The second partition is a 4 GB swap partition. The third partition is the partition containing the zpool (20GB).
+
Create 3 partitions on both drives ada0 and ada1. The first partition contains the gptzfsboot loader which is able to recognize and load the loader from a ZFS partition. The second partition is a 4 GB swap partition. The third partition is the partition containing the zpool (20GB). NOTE: you'll greatly decrease your chance of fat-finger mistakes if for each new command, you use the up-arrow key to duplicate the previous line, then just edit the parameters as appropriate!
  
  Fixit# gpart add -b 34 -s 128 -t freebsd-boot -l boot0 ad0
+
  # gpart add -b 34 -s 128 -t freebsd-boot -l boot0 ada0
  Fixit# gpart add -b 162 -s 8388608 -t freebsd-swap -l swap0 ad0
+
  # gpart add -b 34 -s 128 -t freebsd-boot -l boot1 ada1
  Fixit# gpart add -b 8388770 -s 41943040 -t freebsd-zfs -l root0 ad0
+
  # gpart add -b 162 -s 8388608 -t freebsd-swap -l swap0 ada0
+
  # gpart add -b 162 -s 8388608 -t freebsd-swap -l swap1 ada1
  Fixit# gpart add -b 34 -s 128 -t freebsd-boot -l boot1 ad1
+
  # gpart add -b 8388770 -s 41943040 -t freebsd-zfs -l root0 ada0
  Fixit# gpart add -b 162 -s 8388608 -t freebsd-swap -l swap1 ad1
+
  # gpart add -b 8388770 -s 41943040 -t freebsd-zfs -l root1 ada1
  Fixit# gpart add -b 8388770 -s 41943040 -t freebsd-zfs -l root1 ad1
+
  
 
Notes:
 
Notes:
Line 31: Line 32:
 
===Install the Protected MBR (pmbr) and gptzfsboot loader to both drives===
 
===Install the Protected MBR (pmbr) and gptzfsboot loader to both drives===
  
  Fixit# gpart bootcode -b /mnt2/boot/pmbr -p /mnt2/boot/gptzfsboot -i 1 ad0
+
  # gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 1 ada0
  Fixit# gpart bootcode -b /mnt2/boot/pmbr -p /mnt2/boot/gptzfsboot -i 1 ad1
+
  # gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 1 ada1
  
 
This may fail with an "operation not permitted" error message, since the kernel likes to protect critical parts of the disk. If this happens for you, run:
 
This may fail with an "operation not permitted" error message, since the kernel likes to protect critical parts of the disk. If this happens for you, run:
  
  Fixit# sysctl kern.geom.debugflags=0x10
+
  # sysctl kern.geom.debugflags=0x10
  
 
===Create the root ZFS Pool===
 
===Create the root ZFS Pool===
  
  Fixit# kldload /mnt2/boot/kernel/opensolaris.ko
+
  # zpool create -o altroot=/mnt zroot mirror gpt/root0 gpt/root1
Fixit# kldload /mnt2/boot/kernel/zfs.ko
+
  # zpool set bootfs=zroot zroot
Fixit# mkdir /boot/zfs
+
Fixit# zpool create zroot mirror /dev/gpt/root0 /dev/gpt/root1
+
  Fixit# zpool set bootfs=zroot zroot
+
  
 
=Install FreeBSD to zroot=
 
=Install FreeBSD to zroot=
Line 60: Line 58:
 
The fletcher4 algorithm should be more robust than the fletcher2 algorithm.
 
The fletcher4 algorithm should be more robust than the fletcher2 algorithm.
  
  Fixit# zfs set checksum=fletcher4 zroot
+
  # zfs set checksum=fletcher4 zroot
  
 
==Installing the system==
 
==Installing the system==
  
  Fixit# cd /zroot
+
  # exit
Fixit# cd /dist/8.0-*
+
Fixit# export DESTDIR=/zroot
+
Fixit# for dir in base catpages dict doc games info lib32 manpages ports; \
+
do (cd $dir ; ./install.sh) ; done
+
Fixit# cd src ; ./install.sh all
+
Fixit# cd ../kernels ; ./install.sh generic
+
Fixit# cd /zroot/boot ; cp -Rlp GENERIC/* /zroot/boot/kernel/
+
  
==Initial configuration of the new system==
+
Now you'll be back in the normal installer, and it will start decompressing and copying files as usual.  This shouldn't take too long.  Enter a root password as prompted.  Configure your network interface(s) and system time as usual.  Choose your system boot services (usually sshd and ntpd).  Enable crash dumps (recommended).  Add a user account if you want to.  Now, back at the "Final Configuration" menu, '''E'''xit.  Now at "Manual Configuration", when asked if you would like to open a shell to make any final manual modifications, '''select No.'''  This is a lie, but it's a lie you have to tell!  '''NOW''', at the "Complete" menu, when asked "Would you like to reboot into the installed system now?" select <'''L'''ive CD>.
  
=== chroot into the new system ===
+
Log in as root - you will not be prompted for a password - and make some necessary final configuration changes. '''Your system will not boot if you forget these steps!'''
  Fixit# chroot /zroot
+
  
=== create a /home directory ===
+
==Initial configuration of the new system==
 
+
If you didn't create a dataset for home in the [[ZFS, creating datasets for the FreeBSD system|optional steps above]], you'll need to create a directory for it now.
+
 
+
Fixit# mkdir /usr/home
+
Fixit# ln -s /usr/home home
+
  
 
=== configure /etc/rc.conf ===
 
=== configure /etc/rc.conf ===
  Fixit# echo 'zfs_enable="YES"' > /etc/rc.conf
+
  hostname# echo 'zfs_enable="YES"' >> /mnt/etc/rc.conf
Fixit# echo 'hostname="beastie.mydomain.local"' >> /etc/rc.conf
+
Fixit# echo 'ifconfig_re0="DHCP"' >> /etc/rc.conf
+
 
+
Note:
+
Replace re0 with the name of the Network interface for the new system
+
  
 
=== configure /boot/loader.conf ===
 
=== configure /boot/loader.conf ===
  Fixit# echo 'zfs_load="YES"' > /boot/loader.conf
+
  hostname# echo 'zfs_load="YES"' >> /mnt/boot/loader.conf
  Fixit# echo 'vfs.root.mountfrom="zfs:zroot"' >> /boot/loader.conf
+
  hostname# echo 'vfs.root.mountfrom="zfs:zroot"' >> /mnt/boot/loader.conf
  
 
Check your loader.conf, and make CERTAIN you the quotes in "zfs:zroot" showed up - your system '''will not boot''' if they're not there!
 
Check your loader.conf, and make CERTAIN you the quotes in "zfs:zroot" showed up - your system '''will not boot''' if they're not there!
 
=== Change root's password ===
 
 
Fixit# passwd
 
 
=== Set the local time zone ===
 
 
Fixit# tzsetup
 
 
=== Create /etc/mail/aliases.db ===
 
 
Fixit# cd /etc/mail
 
Fixit# make aliases
 
 
 
==Installing ZFS aware /boot/loader (Required for 8.0-RELEASE and 7.{0-2}-RELEASE)==
 
 
'''Note''': This step is obsoleted in FreeBSD 8.0-STABLE, FreeBSD 9.0-CURRENT, FreeBSD 7.2-STABLE, and newer.
 
 
Fixit# echo 'LOADER_ZFS_SUPPORT=YES' > /etc/src.conf
 
Fixit# mount -t devfs devfs /dev
 
Fixit# export DESTDIR=""
 
Fixit# cd /usr/src/sys/boot/
 
Fixit# make obj
 
Fixit# make depend
 
Fixit# make
 
Fixit# cd i386/loader
 
Fixit# make install
 
Fixit# umount /dev
 
 
== Exit from the /zroot ==
 
 
Fixit# exit
 
  
 
== Install zpool.cache to the ZFS filesystem ==
 
== Install zpool.cache to the ZFS filesystem ==
  
  Fixit# cp /boot/zfs/zpool.cache /zroot/boot/zfs/zpool.cache
+
  hostname# zpool export zroot
 +
hostname# zpool import -o altroot=/mnt -o cachefile=/tmp/zpool.cache zroot
 +
hostname# cp /tmp/zpool.cache /mnt/boot/zfs/
  
 
= Finishing the installation =
 
= Finishing the installation =
  
 
==Using swap==
 
==Using swap==
 
There are 2 ways to use the gpt/swap0 and gpt/swap1 partitions.  '''Only choose one!'''
 
  
 
===Create /etc/fstab to use both swap partitions===
 
===Create /etc/fstab to use both swap partitions===
  
  Fixit# cat << EOF > /zroot/etc/fstab
+
  hostname# cat << EOF > /mnt/etc/fstab
 
  # Device                      Mountpoint              FStype  Options        Dump    Pass#
 
  # Device                      Mountpoint              FStype  Options        Dump    Pass#
 
  /dev/gpt/swap0                none                    swap    sw              0      0
 
  /dev/gpt/swap0                none                    swap    sw              0      0
Line 150: Line 97:
 
  EOF
 
  EOF
  
===Use gmirror to mirror the swap partitions===
+
==Reboot into your new system==
 
+
Fixit# kldload /mnt2/boot/kernel/geom_mirror.ko
+
Fixit# gmirror label -b prefer swap gpt/swap0 gpt/swap1
+
 
+
Note: The 'prefer' balance algorithm can be replaced by 'round-robin'. See the gmirror(8) man page about problem using the 'round-robin' balance algorithm and kernel dumps
+
 
+
Fixit# cat << EOF > /zroot/etc/fstab
+
# Device                      Mountpoint              FStype  Options        Dump    Pass#
+
/dev/mirror/swap                      none                    swap    sw              0      0
+
EOF
+
 
+
  Fixit# echo 'geom_mirror_load="YES"' >> /zroot/boot/loader.conf
+
 
+
 
+
== Setting mountpoints before first boot ==
+
 
+
Fixit# export LD_LIBRARY_PATH=/mnt2/lib
+
Fixit# cd /
+
Fixit# zfs unmount -a
+
Fixit# zfs set mountpoint=legacy zroot
+
 
+
If you set up the full hierarchy of ZFS datasets for the system in the optional steps above, you need to set their mountpoints as well:
+
  
  Fixit# zfs set mountpoint=/tmp zroot/tmp
+
  hostname# reboot
Fixit# zfs set mountpoint=/usr zroot/usr
+
Fixit# zfs set mountpoint=/var zroot/var
+
  
Exit Fixit mode and sysinstall. Remove the FreeBSD install DVD/Memstick and the system will boot using the ZFS root.  
+
The system will now reboot into your new installation. Enjoy!
  
 
[[Category:ZFS]]  [[Category:FreeBSD for Servers]]  [[Category:RAID]]
 
[[Category:ZFS]]  [[Category:FreeBSD for Servers]]  [[Category:RAID]]

Latest revision as of 16:58, 25 August 2012

Note: THIS ARTICLE IS FOR 9.0-RELEASE AND UP! If you're using FreeBSD 7.x or 8.x, please see ZFS, booting from (pre 9.0-RELEASE).

Contents

[edit] Installing FreeBSD Root on ZFS (Mirror) using GPT

[edit] Creating a bootable ZFS Filesystem

Boot FreeBSD install DVD or USB Memstick, and choose Install. Choose your keyboard mapping, hostname, and distribution components (doc, games, lib32, ports, and src - I'd highly advise you to leave ports selected!) as normal. At the Partitioning stage, select <Shell>.

[edit] Create GPT Disks

In this stage we'll assume you have two drives, ada0 and ada1 - check your device names (ls /dev/ada*) and adjust as appropriate, and of course if you have more drives, copy these commands for those drives as well.

# gpart create -s gpt ada0
# gpart create -s gpt ada1

[edit] Create the boot, swap and zfs partitions

Create 3 partitions on both drives ada0 and ada1. The first partition contains the gptzfsboot loader which is able to recognize and load the loader from a ZFS partition. The second partition is a 4 GB swap partition. The third partition is the partition containing the zpool (20GB). NOTE: you'll greatly decrease your chance of fat-finger mistakes if for each new command, you use the up-arrow key to duplicate the previous line, then just edit the parameters as appropriate!

# gpart add -b 34 -s 128 -t freebsd-boot -l boot0 ada0
# gpart add -b 34 -s 128 -t freebsd-boot -l boot1 ada1
# gpart add -b 162 -s 8388608 -t freebsd-swap -l swap0 ada0
# gpart add -b 162 -s 8388608 -t freebsd-swap -l swap1 ada1
# gpart add -b 8388770 -s 41943040 -t freebsd-zfs -l root0 ada0
# gpart add -b 8388770 -s 41943040 -t freebsd-zfs -l root1 ada1

Notes: 1. While a ZFS Swap Volume can be used instead of the freebsd-swap partition, crash dumps can't be created on the ZFS Swap Volume. 2. Sizes and offsets are specified in sectors (1 sector is typically 512 bytes). 3. You may issue a gpart show command to see the correct location and size for further partitions you might need.

[edit] Install the Protected MBR (pmbr) and gptzfsboot loader to both drives

# gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 1 ada0
# gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 1 ada1

This may fail with an "operation not permitted" error message, since the kernel likes to protect critical parts of the disk. If this happens for you, run:

# sysctl kern.geom.debugflags=0x10

[edit] Create the root ZFS Pool

# zpool create -o altroot=/mnt zroot mirror gpt/root0 gpt/root1
# zpool set bootfs=zroot zroot

[edit] Install FreeBSD to zroot

[edit] Optional: Create ZFS datasets specifically for a FreeBSD system

If you wish, you may set up ZFS datasets within the zroot pool specifically optimized for the FreeBSD system.

I wish to stress that this is optional, and many admins may prefer to simply install to the single 20GB zroot pool already set up - among other things, following the guide linked to will cause sixteen new filesystems to show up in the output of df!

If this sounds like more trouble than it's worth, skip this step completely and move on.

[edit] Optional: Change the checksum algorithm

The fletcher4 algorithm should be more robust than the fletcher2 algorithm.

# zfs set checksum=fletcher4 zroot

[edit] Installing the system

# exit

Now you'll be back in the normal installer, and it will start decompressing and copying files as usual. This shouldn't take too long. Enter a root password as prompted. Configure your network interface(s) and system time as usual. Choose your system boot services (usually sshd and ntpd). Enable crash dumps (recommended). Add a user account if you want to. Now, back at the "Final Configuration" menu, Exit. Now at "Manual Configuration", when asked if you would like to open a shell to make any final manual modifications, select No. This is a lie, but it's a lie you have to tell! NOW, at the "Complete" menu, when asked "Would you like to reboot into the installed system now?" select <Live CD>.

Log in as root - you will not be prompted for a password - and make some necessary final configuration changes. Your system will not boot if you forget these steps!

[edit] Initial configuration of the new system

[edit] configure /etc/rc.conf

hostname# echo 'zfs_enable="YES"' >> /mnt/etc/rc.conf

[edit] configure /boot/loader.conf

hostname# echo 'zfs_load="YES"' >> /mnt/boot/loader.conf
hostname# echo 'vfs.root.mountfrom="zfs:zroot"' >> /mnt/boot/loader.conf

Check your loader.conf, and make CERTAIN you the quotes in "zfs:zroot" showed up - your system will not boot if they're not there!

[edit] Install zpool.cache to the ZFS filesystem

hostname# zpool export zroot
hostname# zpool import -o altroot=/mnt -o cachefile=/tmp/zpool.cache zroot
hostname# cp /tmp/zpool.cache /mnt/boot/zfs/

[edit] Finishing the installation

[edit] Using swap

[edit] Create /etc/fstab to use both swap partitions

hostname# cat << EOF > /mnt/etc/fstab
# Device                       Mountpoint              FStype  Options         Dump    Pass#
/dev/gpt/swap0                 none                    swap    sw              0       0
/dev/gpt/swap1                 none                    swap    sw              0       0
EOF

[edit] Reboot into your new system

hostname# reboot

The system will now reboot into your new installation. Enjoy!

Personal tools