From: David Marec Date: Sun, 7 Oct 2018 20:09:12 +0000 (+0200) Subject: first issue X-Git-Url: http://popeye.lapinbilly.eu/git/?p=zfsinstaller.git;a=commitdiff_plain;h=b6b4582750fc7597d17521a55e70ceeb9fe35cbf first issue --- b6b4582750fc7597d17521a55e70ceeb9fe35cbf diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..51f1f5d --- /dev/null +++ b/LICENSE @@ -0,0 +1,25 @@ +BSD 2-Clause License + +Copyright (c) 2017, David Marec +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/rc.conf.d/hostname b/rc.conf.d/hostname new file mode 100644 index 0000000..46dabcb --- /dev/null +++ b/rc.conf.d/hostname @@ -0,0 +1,2 @@ +hostname="matarje" + diff --git a/rc.conf.d/network b/rc.conf.d/network new file mode 100644 index 0000000..a935a34 --- /dev/null +++ b/rc.conf.d/network @@ -0,0 +1,3 @@ +#ifconfig_re0="inet netmask " +#defaultrouter="" +#ifconfig_re0_ipv6="inet6 accept_rtadv" diff --git a/rc.conf.local b/rc.conf.local new file mode 100644 index 0000000..ea2b15a --- /dev/null +++ b/rc.conf.local @@ -0,0 +1,2 @@ +local_enable="YES" +keymap="fr.iso.acc.kbd" diff --git a/resolv.conf b/resolv.conf new file mode 100644 index 0000000..94aa5ad --- /dev/null +++ b/resolv.conf @@ -0,0 +1,6 @@ +# Generated by resolvconf +search your-server.de +nameserver 213.133.98.98 +nameserver 213.133.99.99 +nameserver 213.133.100.100 + diff --git a/settings.sh b/settings.sh new file mode 100644 index 0000000..babe354 --- /dev/null +++ b/settings.sh @@ -0,0 +1,4 @@ +export DESTDISK="ada1" +export DESTDIR="/mnt/zfs" +export ZPOOL="zroot" + diff --git a/zfsinstall.sh b/zfsinstall.sh new file mode 100644 index 0000000..f78c88f --- /dev/null +++ b/zfsinstall.sh @@ -0,0 +1,163 @@ +#!/bin/sh + +DESTDISK="ada0" +DESTDIR="/mnt/zfs" +ZPOOL="zroot" + +SCRIPTBASE=${PWD} + +# check if the zpool already exists + +ZPOOL_EXISTS=` zpool list -H | cut -f 1 | grep "${ZPOOL}"` +if [ "${?}" -ne 1 ]; then + echo "One zpool called ${ZPOOL} already exists, you have to destroy it first:" + echo " # zpool destroy ${ZPOOL}" + exit 1 +fi + +# check if the disk is ok for writing + +echo checking sanity ${DESTDISK} +echo ============= +gpart show ${DESTDISK} 1>/dev/null +if [ "${?}" -eq 0 ]; then + + gpart destroy -F ${DESTDISK} + if [ "${?}" -ne 0 ]; then + echo unable to reset ${DESTDISK} + exit 1 + fi +fi + +echo partitioning ${DESTDISK} +echo ============= + +gpart create -s gpt ${DESTDISK} +gpart add -a 1m -t freebsd-boot -s 128k -l boot ${DESTDISK} +gpart add -a 1m -s 32G -t freebsd-swap -l swap ${DESTDISK} +gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 1 ${DESTDISK} +gpart add -a 1m -t freebsd-zfs -l syszfs ${DESTDISK} + +gpart show ${DESTDISK} 1>/dev/null + +sysctl vfs.zfs.min_auto_ashift=12 + +echo set up zfs pool: ${ZPOOL} alt mount: ${DESTDIR} +echo ================= + +zpool create -m none -f -R ${DESTDIR} ${ZPOOL} ${DESTDISK}p3 +if [ "${?}" -ne 0 ]; then + echo "unable to create zpool" + exit 1 +fi + + +for I in ROOT VAR HOME; do + zfs create -o mountpoint=none -o canmount=off ${ZPOOL}/${I} +done + +zfs create -o atime=off -o mountpoint=/ ${ZPOOL}/ROOT/master +zfs create -o mountpoint=/usr/obj ${ZPOOL}/ROOT/obj +zfs create -o compression=off -o mountpoint=/usr/src ${ZPOOL}/ROOT/src +# useless ? as far /tmp mountpoint will be mounted by tmpfs +zfs create -o mountpoint=/tmp ${ZPOOL}/ROOT/tmp + +zfs create -o mountpoint=/usr/local ${ZPOOL}/LOCAL +zfs create -o mountpoint=/usr/local/etc ${ZPOOL}/LOCAL/config +zfs create -o copies=1 -o mountpoint=/usr/src -o compression=off ${ZPOOL}/src +zfs create -o copies=1 -o mountpoint=/usr/doc -o compression=on ${ZPOOL}/doc +zfs create -o copies=1 -o mountpoint=/usr/obj -o compression=on ${ZPOOL}/obj + + +zfs create -o mountpoint=/var ${ZPOOL}/VAR/master +zfs create -o mountpoint=/var/crash ${ZPOOL}/VAR/crash +zfs create -o exec=off -o setuid=off -o mountpoint=/var/db ${ZPOOL}/VAR/db +zfs create -o compression=lz4 -o exec=on -o setuid=off -o mountpoint=/var/db/pkg ${ZPOOL}/VAR/db/pkg +zfs create -o compression=on -o exec=off -o setuid=off -o mountpoint=/var/mail ${ZPOOL}/VAR/mail +zfs create -o compression=on -o exec=off -o setuid=off -o mountpoint=/var/log ${ZPOOL}/VAR/log +zfs create -o exec=off -o setuid=off -o mountpoint=/var/run ${ZPOOL}/VAR/run +zfs create -o exec=off -o setuid=off -o mountpoint=/var/tmp ${ZPOOL}/VAR/tmp + +zfs create -o mountpoint=/usr/home ${ZPOOL}/HOME/master + + +chmod 1777 ${DESTDIR}/tmp ${DESTDIR}/var/tmp + +zfs list -r ${ZPOOL} + +cd ${DESTDIR}/tmp +if [ "${?}" -ne 0 ]; then + echo zfs mountpoints arent ready + exit 1 +fi + +echo Fetching and Extracting base files into ${DESTDIR} +echo ======================================= + + +for I in base.txz kernel.txz lib32.txz; do + fetch http://ftp.freebsd.org/pub/FreeBSD/snapshots/amd64/12.0-ALPHA8/${I} + tar --unlink -pJxf ${I} -C ${DESTDIR} +done + +echo writing configuration files +echo ========================== + +cat << EOF >> ${DESTDIR}/etc/fstab +/dev/${DESTDISK}p2 none swap sw 0 0 +tmpfs /tmp tmpfs rw,mode=1777 0 0 +EOF + +cat << EOF >> ${DESTDIR}/boot/loader.conf +zfs_load=YES +tmpfs_load=YES +EOF + +cat << EOF >> ${DESTDIR}/boot/loader.conf.local +vfs.root.mountfrom="zfs:${ZPOOL}/ROOT/master" +EOF + +cat << EOF >> ${DESTDIR}/etc/rc.conf +sshd_enable="YES" +sendmail_enable="NONE" +kld_list="vmm cuse4bsd cpuctl filemon" +ntpd_enable="YES" +# Set dumpdev to "AUTO" to enable crash dumps, "NO" to disable +dumpdev="AUTO" +zfs_enable="YES" +EOF + +cd ${SCRIPTBASE} +for I in resolv.conf rc.conf.local; do + if [ -r "${I}" ]; then + echo installing ${I} + install -o root -g wheel -m 0644 ${I} ${DESTDIR}/etc/ + fi +done + +for I in loader.conf.local; do + if [ -r "${I}" ]; then + echo installing ${I} + install -o root -g wheel -m 0644 ${I} ${DESTDIR}/boot/ + fi +done + +echo installing rc.conf.d +install -o root -g wheel -d -m 0755 ${DESTDIR}/etc/rc.conf.d +if [ -d "./rc.conf.d" ]; then + echo installing files into rc.conf.d + install -o root -g wheel -m 0644 ./rc.conf.d/* ${DESTDIR}/etc/rc.conf.d/ +fi + +chroot ${DESTDIR} passwd +chroot ${DESTDIR} adduser + +read -p "Do you wish to open a shell ?" yn +case $yn in + [Nn]* ) exit 0;; + [Yy]* ) ;; + * ) echo "Please answer yes or no.";; +esac +chroot ${DESTDIR} tcsh +exit 0 +