FreeBSD remote install - hpaluch/hpaluch.github.io GitHub Wiki
I want to perform main FreeBSD installation remotely via SSH, because I need to copy & paste lot of commands from https://wiki.freebsd.org/RootOnZFS/GPTZFSBoot (I want to use ZFS on root, but I want to use only portion of disk - which Auto install option does NOT support).
NOTE: You still need local console access to boot "Live system" from it - and issue several commands listed below to enable SSHd.
So I wrote to USB stick (decompressed !) media:
After boot select "Live CD".
But there is problem - whole / filesystem is readonly - including /etc/ssh. Thanks to USB stick
we can make it read-write :-) with:
mount -u -o rw /WARNING! This will make persistent change to your USB stick image! - If you want back your original image you should write .img to it again...
Now normally use vi /etc/ssh/sshd_config and set PermitRootLogin yes
To configure IP address via DHCP do this:
ifconfig # find your network interface
dhclient nfe0 # nfe0 is for MCP55 NVidia ethernetFinally set root password and start sshd:
passwd root
/etc/rc.d/sshd onestartAnd now you can simply run ssh root@FREEBSD_IP on your Client
machine to get SSH access to your FreeBSD installation.
Note: to log everything I do on client machine:
script ~/bsd-install.log
ssh root@FREEBSD_IP
....When you are ready to continue FreeBSD installation - run bsdinstall
In my case of ZFS on Root install I will now follow:
Here is example log
- I did manual ZFS install because I want to use only around 100GB of 500GB HDD (SATA3 WD Blue HDD) while "AutoZFS" option always use whole disk (which is shame).
 - scheme GPT+BIOS (I plan to install later OpenSUSE linux on ZFS to compare performance)
 
Here is brief command log:
- you should run these command under -> Paritioning -> Shell
 
camcontrol devlist
<HL-DT-ST DVDRAM GSA-H12N UL01>    at scbus0 target 0 lun 0 (pass0,cd0)
<WDC WD5000AAKX-001CA0 15.01H15>   at scbus9 target 0 lun 0 (pass1,ada0)
<USB SanDisk 3.2Gen1 1.00>         at scbus28 target 0 lun 0 (pass2,da0)
#>>> ada0 is our target
gpart show ada0
=>       34  976773101  ada0  GPT  (466G)
         34  976773101        - free -  (466G)
#>>> ada0 has empty GPT partition scheme
# Legacy boot (GPT+BIOS)
# Do NOT use more than '-s 512K' - it will fail to boot with error "Loaded only 545K" !
# Align is 4KB
gpart add -a 4k -s 512K -t freebsd-boot ada0
gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 1 ada0
#>>> Add 16GB swap - unlike linux FreeBSD use much more swap, because
#    FreeBSD stores on swap complete binary (not just data).
gpart add -a 1m -s 16G -t freebsd-swap -l swap0 ada0
# In my case I will create only 100GB ZFS partition (-s 100G)
gpart add -a 1m -s 100G -t freebsd-zfs -l disk0 ada0
# Here is final GPT+BIOS partition layout
gpart show ada0
=>       34  976773101  ada0  GPT  (466G)
         34          6        - free -  (3.0K)
         40       1024     1  freebsd-boot  (512K)
       1064        984        - free -  (492K)
       2048   33554432     2  freebsd-swap  (16G)
   33556480  209715200     3  freebsd-zfs  (100G)
  243271680  733501455        - free -  (350G)
mount -t tmpfs tmpfs /mntNote:
- will use 
zbsdfor Root pool name instead ofzrootbecause I plan to install other systems (several Linux distribution on ZFS). 
# you may need to add -f if you used ZFS on same offset in the past...
zpool create -o altroot=/mnt zbsd ada0p3
zfs set compress=on                                           zbsd
zfs create -o mountpoint=none                                  zbsd/ROOT
zfs create -o mountpoint=none                                  zbsd/ROOT/default
mount -t zfs zbsd/ROOT/default /mnt
zfs create -o mountpoint=/tmp  -o exec=on      -o setuid=off   zbsd/tmp
zfs create -o canmount=off -o mountpoint=/usr                  zbsd/usr
zfs create                                                     zbsd/usr/home
zfs create                     -o exec=off     -o setuid=off   zbsd/usr/src
zfs create                                                     zbsd/usr/obj
zfs create -o mountpoint=/usr/ports            -o setuid=off   zbsd/usr/ports
zfs create                     -o exec=off     -o setuid=off   zbsd/usr/ports/distfiles
zfs create                     -o exec=off     -o setuid=off   zbsd/usr/ports/packages
zfs create -o canmount=off -o mountpoint=/var                  zbsd/var
zfs create                     -o exec=off     -o setuid=off   zbsd/var/audit
zfs create                     -o exec=off     -o setuid=off   zbsd/var/crash
zfs create                     -o exec=off     -o setuid=off   zbsd/var/log
zfs create -o atime=on         -o exec=off     -o setuid=off   zbsd/var/mail
zfs create                     -o exec=on      -o setuid=off   zbsd/var/tmp
ln -s /usr/home /mnt/home
chmod 1777 /mnt/var/tmp
chmod 1777 /mnt/tmp
zpool set bootfs=zbsd/ROOT/default zbsd
cat << EOF > /tmp/bsdinstall_etc/fstab
# Device                       Mountpoint              FStype  Options         Dump    Pass#
/dev/gpt/swap0                 none                    swap    sw              0       0
EOF
#>>> Exit partitioning shell
exitIn Postinstall Shell do this (honestly I forgot that):
sysrc zfs_enable="YES"
cat /boot/loader.conf
# do not run line below, if there is already zfs_load=...
echo 'zfs_load="YES"' >> /boot/loader.confRescue ZFS:
- If you something forgot (like me):
 - boot again from USB stick and go to Shell
 - import and mount root ZFS on alternate place:
zpool import -N -R /mnt zbsd mount -t zfs zbsd/ROOT/default /mnt
 - fix things
 - unmount and export everything:
umount zbsd/ROOT/default zpool export zbsd - and reboot with 
reboot 
--hp
This work is licensed under a