LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   *BSD (http://www.linuxquestions.org/questions/%2Absd-17/)
-   -   HOWTO: Modern FreeBSD Install (vermaden way) (http://www.linuxquestions.org/questions/%2Absd-17/howto-modern-freebsd-install-vermaden-way-783841/)

vermaden 01-21-2010 03:05 PM

HOWTO: Modern FreeBSD Install (vermaden way)
 
All these years sysinstall(8) was helping us to install FreeBSD with most options we needed, today with new filesystems/features like GJournal/ZFS/Geli/GMirror/GStripe its no longer up to the task, because it only supports creating installation on UFS filesystem with SoftUpdates turned ON or OFF.

In this guide you will learn how to setup FreeBSD installation in simple yet flexible setup based on read-only UFS (without SoftUpdates) for 'base system' [1], some SWAP space, /tmp mounted on SWAP and all the other filesystems (/var /usr ...) mounted on ZFS. It will not require rebuilding anything, just simple setup on plain MBR partitions. I should also mention that we would be using AHCI mode for disks. I also provided two versions, for system with one harddisk and with three of them for redundant setup.

Here is the layout of the system with 1 harddisk:
Code:

MBR SLICE 1 |    / | 512 MB | UFS/read-only
            | SWAP |  2 GB |
            | /tmp | 512 MB | mounted on SWAP with mdmfs(8)
------------+------+---------------------------------------
MBR SLICE 2 | /usr |  REST | ZFS dataset
            | /var |  REST | ZFS dataset

... and here layout for single disk for system with 3 disks:
Code:

MBR SLICE 1 |    / | 512 MB | UFS/read-only
------------+------+--------+------------------------------
MBR SLICE 2 | SWAP |  1 GB |
            | /tmp | 512 MB | mounted on SWAP with mdmfs(8)
------------+------+--------+------------------------------
MBR SLICE 3 | /usr |  REST | ZFS dataset
            | /var |  REST | ZFS dataset

Redundancy planning for system with 3 disks:
Code:

[ DISK0 ]          [ DISK1 ]          [ DISK2 ]
 [  /  ] < RAID1 > [  /  ] < RAID1 > [  /  ]
 [ SWAP0 ]          [ SWAP1 ]          [ SWAP2 ]
 [  Z  ] < RAID5 > [  F  ] < RAID5 > [  S  ]

FreeBSD core, the 'base system' [1] should remain almost unchanged/untouched on daily basis while you can mess all other filesystems, this ensures that when things go wrong, you will be able to fix anything still having working 'base system' [1].

You will need *-dvd-* disk or *-memstick-* image for this installation, *-disk1-* will not do since it does not contain livefs system.

Here is the procedude, described as simple as possible.

1.0. I assume that our disk for the installation would be /dev/ad0 (/dev/ad0 /dev/ad1 /dev/ad2 for system with 3 disks)

1.1. Boot *-dvd-* from DVD disk or *-memstick-* image from pendrive
Code:

Country Selection --> United States
Fixit --> CDROM/DVD (*-dvd-*) or USB (*-memstick-*)

1.2. Create your temporary working environment
Code:

fixit# /mnt2/bin/csh
# setenv PATH /mnt2/rescue:/mnt2/usr/bin:/mnt2/sbin
# set filec
# set autolist
# set nobeep

1.3. Load needed modules
Code:

fixit# kldload /mnt2/boot/kernel/geom_mbr.ko
fixit# kldload /mnt2/boot/kernel/opensolaris.ko
fixit# kldload /mnt2/boot/kernel/zfs.ko

1.4. Create/mount needed filesystems
Code:

DISKS: 3                                              | DISKS: 1
# cat > part << __EOF__                                | # cat > part << __EOF__
p 1 165 63  512M                                      | p 1 165 63  2560M
p 2 165  * 1024M                                      | p 2 159  *    *
p 3 159  *    *                                      | p 3  0  0    0
p 4  0  0    0                                      | p 4  0  0    0
a 1                                                    | a 1
__EOF__                                                | __EOF__
                                                      |
# fdisk -f part ad0                                    | # fdisk -f part ad0
# fdisk -f part ad1                                    |
# fdisk -f part ad2                                    |
                                                      |
# kldload /mnt2/boot/kernel/geom_mirror.ko            |
# gmirror label  rootfs ad0s1                          |
# gmirror insert rootfs ad1s1                          |
# gmirror insert rootfs ad2s1                          |
                                                      |
# bsdlabel -B -w /dev/mirror/rootfs                    | # cat > label << __EOF__
                                                      | # /dev/ad0s1:
                                                      | 8 partitions:
                                                      |   a: 512m  0 4.2BSD
                                                      |   b: *    * swap
                                                      | __EOF__
                                                      |
                                                      | # bsdlabel -B -w ad0s1
                                                      | # bsdlabel      ad0s1 | tail -1 >> label
                                                      | # bsdlabel -R    ad0s1 label
                                                      |
# glabel label swap0 ad0s2                            | # glabel label rootfs ad0s1a
# glabel label swap1 ad1s2                            | # glabel label swap  ad0s1b
# glabel label swap2 ad2s2                            |
                                                      |
# newfs /dev/mirror/rootfsa                            | # newfs /dev/label/rootfs
# zpool create basefs raidz ad0s3 ad1s3 ad2s3          | # zpool create basefs ad0s2
# zfs create basefs/usr                                | # zfs create basefs/usr
# zfs create basefs/var                                | # zfs create basefs/var
# mkdir /NEWROOT                                      | # mkdir /NEWROOT
# mount /dev/mirror/rootfsa /NEWROOT                  | # mount /dev/label/rootfs /NEWROOT
# zfs set mountpoint=/NEWROOT/usr basefs/usr          | # zfs set mountpoint=/NEWROOT/usr basefs/usr
# zfs set mountpoint=/NEWROOT/var basefs/var          | # zfs set mountpoint=/NEWROOT/var basefs/var

1.5. Actually install needed FreeBSD sets
Code:

# setenv DESTDIR /NEWROOT
# cd /dist/8.0-RELEASE

# cd base
# ./install.sh (answer 'y' here)
# cd ..

# cd manpages
# ./install.sh
# cd ..

# cd kernels
# ./install.sh generic
# cd ..

# cd /NEWROOT/boot
# rm -r kernel
# mv GENERIC kernel

1.6. Provide basic configuration needed to boot new system
1.6.1.
Code:

DISKS: 3                                          | DISKS: 1
# cat > /NEWROOT/etc/fstab << __EOF__            | # cat > /NEWROOT/etc/fstab << __EOF__
#dev                #mount #fs  #opts #dump #pass | #dev              #mount #fs  #opts #dump #pass
/dev/mirror/rootfsa /      ufs  rw    1    1    | /dev/label/rootfs /      ufs  rw    1    1
/dev/label/swap0    none  swap sw    0    0    | /dev/label/swap  none  swap sw    0    0
/dev/label/swap1    none  swap sw    0    0    | __EOF__
/dev/label/swap2    none  swap sw    0    0    |
__EOF__                                          |
                                                  |
# cat > /NEWROOT/boot/loader.conf << __EOF__      | # cat > /NEWROOT/boot/loader.conf << __EOF__
zfs_load="YES"                                    | zfs_load="YES"
ahci_load="YES"                                  | ahci_load="YES"
geom_mirror_load="YES"                            | __EOF__
__EOF__                                          |

1.6.1.
Code:

# cat > /NEWROOT/etc/rc.conf << __EOF__
zfs_enable="YES"
__EOF__

1.7. Unmount filesystems and reboot
Code:

# cd /
# zfs umount -a
# umount /NEWROOT
# zfs set mountpoint=/usr basefs/usr
# zfs set mountpoint=/var basefs/var
# zpool export basefs
# reboot

Now lets talk things you will need to do after reboot.

2.0. At boot loader select boot into single user mode
4. Boot FreeBSD in single user mode

Code:

Enter full pathname of shell or RETURN for /bin/sh: /bin/csh
% /rescue/mount -w /
% /rescue/zpool import -D || /rescue/zpool import -f basefs
% exit

2.1. Login as root without password
Code:

login: root
password: (just hit ENTER)

2.2. Set root password
Code:

# passwd
2.3. Set hostname
Code:

# echo hostname=\"HOSTNAME\" >> /etc/rc.conf
2.4. Set timezone and date/time
Code:

# tzsetup
# date 201001142240

2.5. Tune the ZFS filesystem (only for i386)
Code:

# cat > /boot/loader.conf << __EOF__
vfs.zfs.prefetch_disable=0      # enable prefetch
vfs.zfs.arc_max=134217728      # 128 MB
vm.kmem_size=536870912          # 512 MB
vm.kmem_size_max=536870912      # 512 MB
vfs.zfs.vdev.cache.size=8388608 #  8 MB
__EOF__

2.6. Mount /tmp on SWAP
Code:

# cat >> /etc/rc.conf << __EOF__
tmpmfs="YES"
tmpsize="512m"
tmpmfs_flags="-m 0 -o async,noatime -S -p 1777"
__EOF__

2.7. Move termcap into /etc (instead of useless link on crash)
Code:

# rm /etc/termcap
# mv /usr/share/misc/termcap /etc
# ln -s /etc/termcap /usr/share/misc/termcap

2.8. Add latest security patches
Code:

# freebsd-update fetch
# freebsd-update install

2.9. Make all changes to configuration in /etc, then set / to be mounted read-only in /etc/fstab
Code:

DISKS: 3                                          | DISKS: 1
 #dev                #mount #fs  #opts #dump #pass |  #dev              #mount #fs  #opts #dump #pass
+/dev/mirror/rootfsa /      ufs  rw    1    1    | +/dev/label/rootfs /      ufs  rw    1    1
-/dev/mirror/rootfsa /      ufs  rw    1    1    | -/dev/label/rootfs /      ufs  rw    1    1
 /dev/label/swap0    none  swap sw    0    0    |  /dev/label/swap  none  swap sw    0    0
 /dev/label/swap1    none  swap sw    0    0    |
 /dev/label/swap2    none  swap sw    0    0    |

2.10. Reboot and enjoy modern install of FreeBSD system
Code:

# shutdown -r now
To summarise, this setup provides us these things:
-- bulletproof 'base system' [1] on UFS (w/o SU) mounted read-only
-- /tmp filesystem mounted on SWAP
-- usage of new AHCI mode in FreeBSD
-- flexibility for all other filesystems on ZFS
-- fully working environment on crash (/etc/termcap)
-- disks/filesystems mounted by label, possible device name changes are harmless
-- RAID1 for / and RAID5 for all other systems on setup with 3 disks

[1] base system is / and /usr while this setup, in context of this setup I name 'base system'
the most important core of FreeBSD, the / filesystem and its binaries/libraries/configuration
(thanks to phoenix for reminding me what REAL base system is/means) ;)


CHANGELOG

1.0 / 2010-01-14 / initial version
1.1 / 2010-01-15 / simplified PATH
+fixit# setenv PATH /mnt2/rescue:/mnt2/usr/bin
-fixit# setenv PATH /mnt2/bin:/mnt2/sbin:/mnt2/usr/bin:/mnt2/usr/sbin
1.2 / 2010-01-15 / added link for termcap (instead of duplicate on /etc and /usr) [2.6.]
.# rm /etc/termcap
+# mv /usr/share/misc/termcap /etc
+# ln -s /etc/termcap /usr/share/misc/termcap

-# cp /usr/share/misc/termcap /etc
1.3 / 2010-01-21 / removed unneeded mount commands [2.0.]
-# zfs mount basefs/var
-# zfs mount basefs/usr
1.4 / 2010-03-08 / added setup for 3 disks + cleanup
too much to fit here, we can as well call this new version RELOADED ;)
MIRROR THREAD: http://daemonforums.org/showthread.php?t=4200
MIRROR THREAD: http://forums.freebsd.org/showthread.php?t=10334
POLISH VERSION: http://bsdguru.org/dyskusja/viewtopic.php?t=19392

Jeebizz 01-25-2010 02:19 PM

This is actually really cool! Nice work and maybe this should be stickied. I also wondered how would you install FreeBSD with ZFS, when the standard installer only had the option for UFS/UFS+. Kinda disappointed that version 8 didn't even give you that option. Maybe in 8.1 this might be addressed, but if not your method can be used.

rndm_luser 01-26-2010 09:47 AM

Thank you for sharing. I am relatively new to FreeBSD and didn't know about freebsd-update. It looks like it will be useful for patching production systems that you want to keep on a release candidate rather than going through the process of updating from CVS sources.

vermaden 03-08-2010 07:54 AM

@Jeebizz | @rndm_luser

Thanks, I have added a section on how to create redundant setup with 3 disks and improved/simplified overall process.

blood_omen 06-12-2010 09:46 AM

Greetings:

I'm following the instructions, but when I get to section 2.0 and issue /rescue/zpool import -D I get an error: no pools available to import.

I have to mention that for some reason FreeBSD recognizes my ONLY drive as ad4 instead ad ad0, I follow all the steps using ad4 and I get no errors except when issuing /rescue/zpool import -D

Any help is appreciated.

vermaden 06-23-2010 01:47 PM

@blood_omen

Try /rescue/zpool import -f basefs instead of /rescue/zpool import -D then.

If Your chipset does not support AHCI, then You will have ad0/ad1/ad2/... disks, they do not always start from ad0 (STATIC NUMBERING is enabled by default on the kernel config), but that is not important since You will be using LABELS instead.

Tinkster 06-24-2010 12:13 AM

Hi,

I've stickied your thread, really good work; I'd recommend a closure,
though, as it may quickly become very cluttered. What are your/others
thoughts on a closure?



Cheers,
Tink

vermaden 06-24-2010 10:26 AM

@Tinkster

Hi and thanks.

I would not close it personally, there are always some questions and problems with such big/complicated howtos, as for the 'growing problem', I have also put that howto on other forums, some grew up to 4-5 pages, and sometimes even still grow (I even got late questions about this guide if it works on FreeBSD/SPARC, and the funny thing is it even works there), but I do not see that as a problem, 1st post will remain the howto with all the rest as discussion/comments. I also got several very helpful responds just after posting the howto, which showed several errors in the process, there still may be some smaller ones, as I cannot try every possible configuration out there.

So to make my idea short, IMHO we should not close it.

Regards mate.

Tinkster 06-24-2010 02:47 PM

Your call ... my concern was (is) that it will end up as a
catch-all thread for any random questions popping up.



Cheers,
Tink

vermaden 07-25-2010 01:48 PM

After FreeBSD 8.1-RELEASE has been released, we can now upgrade our ZPOOL(s) to newer (v13 --> v14) version, below You will find simple way to achieve that.

First check what is currently on You system:
Code:

# uname -m -r
8.1-RELEASE amd64

# zfs get version basefs
NAME    PROPERTY  VALUE    SOURCE
basefs  version  3        -

# zpool list -o version
VERSION
    13

Now lets proceed with the zpool/zfs upgrade procedure:
Code:

# zpool upgrade
This system is currently running ZFS pool version 14.

The following pools are out of date, and can be upgraded.  After being
upgraded, these pools will no longer be accessible by older software versions.

VER  POOL
---  ------------
13  basefs

Use 'zpool upgrade -v' for a list of available versions and their associated
features.

# zpool upgrade basefs
This system is currently running ZFS pool version 14.

Successfully upgraded 'basefs' from version 13 to version 14

# zfs upgrade
This system is currently running ZFS filesystem version 3.

All filesystems are formatted with the current version.

After the upgrade we can check again our ZPOOL(s) version:
Code:

# zpool list -o version
VERSION
    14

Your pool is now upgraded to newest 'release' zpool/zfs version.

c0mputerking 12-04-2010 02:03 AM

Great tutorial thanks, but......

why did u use raid 5 for the zfs partition instead of zraid? I think zraid is superior to even raid5. Just curious why you would setup zfs, and not use its best feature zraid! am i missing something. I am debating weather to use this tutorial, or the automagic mfsroot installer which broke for me after updates something about expecting version 14 got version 15

I might try just the update section of these posts maybe it will fix my mfsroot errors, however i have to agree with you about root being on raid 1, root on zfs (zraid) makes me kind of nervous what if something goes wrong? but then again software raid 1 can be a b!tch too when things go wrong

vermaden 12-04-2010 08:04 PM

Quote:

Originally Posted by c0mputerking (Post 4180209)
Great tutorial thanks, but......

why did u use raid 5 for the zfs partition instead of zraid?

Have You checked 1.4 section?
Code:

# zpool create basefs raidz ad0s3 ad1s3 ad2s3
I USE raidz, but its equivalent of RAID5, same for raidz2 as RAID6 ;)

charlie_lab 11-21-2012 12:52 PM

Hello,

Maybe a stupid question but can this also be working on a disk where freebsd is on the second partition.
On the first 200G is Win7 installed and on the last 100G FreeBSD can be installed.
If so, what are the names of the disk then ?

Roelof

vermaden 11-21-2012 02:37 PM

ada0 - disk
ada0s1 - 1st MBR partition (Windows)
ada0s2 - 2nd MBR partition (FreeBSD)
ada0s2a - 1st BSDLABEL partition of 2nd MBR partition

I haven't setup FreeBSD boot alongside Windows 7, so You will have to google that out.

Just make sure that both Windows and FreeBSD MBR partitions are PRIMARY partitions.

charlie_lab 11-21-2012 02:45 PM

Thanks

So ad0 for me is ad0s1 ??
And can I better follow this one or better the newer tutorial which can be found here : http://www.linuxquestions.org/questi...sd-4175412036/

Roelof


All times are GMT -5. The time now is 07:16 PM.