h0sch1
Well-Known Member
Hi
Da ich sehr häufig ein FreeBSD installieren muss (Neuer Server hier, Test-System da)
habe ich mir jetzt ein Script gebaut, das die Installation automatisiert.
Was tut es:
1. Festplatte partitionieren 1GB Root, 2GB SWAP, 1 GB tmp, 2GB var, REST usr
2. Alle erstellten Partitionen UFS formatieren
3. FreeBSD 9.0 auf die Festplatte kopieren, entweder download oder er findet die Daten lokal ($sourcedir)
4. FreeBSD installieren
5. rc.conf fstab und loader.conf erstellen
Viel Spaß damit.
freebsd_installer.sh
Da ich sehr häufig ein FreeBSD installieren muss (Neuer Server hier, Test-System da)
habe ich mir jetzt ein Script gebaut, das die Installation automatisiert.
Was tut es:
1. Festplatte partitionieren 1GB Root, 2GB SWAP, 1 GB tmp, 2GB var, REST usr
2. Alle erstellten Partitionen UFS formatieren
3. FreeBSD 9.0 auf die Festplatte kopieren, entweder download oder er findet die Daten lokal ($sourcedir)
4. FreeBSD installieren
5. rc.conf fstab und loader.conf erstellen
Viel Spaß damit.
freebsd_installer.sh
Code:
#!/bin/sh
####
### Autor: hoschi@anukis.de
####
### Config
scriptversion="1.0"
freebsdversion="9.0"
sourcedir="/usb/FreeBSD_install"
destinationdir="/mnt/install"
installdir="/mnt"
prg_gpart="/sbin/gpart"
### Program (DONT TOUCH)
DONE="\033[80C\033[11D\033[1;34m -= OK =-\033[m"
i386pkg="base.txz doc.txz games.txz kernel.txz ports.txz src.txz"
amd64pkg="base.txz doc.txz games.txz kernel.txz lib32.txz ports.txz src.txz"
freebsdurl="http://ftp2.de.freebsd.org/pub/FreeBSD/releases"
usage="usage: $0 ad|da|ada[0123456789] i386|amd64
i386 or amd64 is optional
Example:
$0 ada0
or
$0 da2 amd64
"
clear
echo "starting installer version ${scriptversion} for FreeBSD ${freebsdversion}"
case "${1}" in
ad[0-9]|da[0-9]|ada[0-9])
echo " --> installing FreeBSD on ${1}"
echo -n " --> destroy all partitions on ${1}"
${prg_gpart} destroy -F ${1} >/dev/null 2>&1
echo -e "${DONE}"
echo -n " --> create GPT on ${1}"
${prg_gpart} create -s gpt ${1} >/dev/null 2>&1
echo -e "${DONE}"
echo -n " --> create boot partition on ${1}"
${prg_gpart} add -s 128k -t freebsd-boot -l boot -i 1 ${1} >/dev/null 2>&1
echo -e "${DONE}"
echo -n " --> insert bootcode on ${1}"
${prg_gpart} bootcode -b /boot/pmbr -p /boot/gptboot -i 1 ${1} >/dev/null 2>&1
echo -e "${DONE}"
echo -n " --> create 2GB swap partition on ${1}"
${prg_gpart} add -s 2G -t freebsd-swap -i 2 ${1} >/dev/null 2>&1
echo -e "${DONE}"
echo -n " --> create 1GB root partition on ${1}"
${prg_gpart} add -s 1G -t freebsd-ufs -l root -i 3 ${1} >/dev/null 2>&1
echo -e "${DONE}"
echo -n " --> create 1GB tmp partition on ${1}"
${prg_gpart} add -s 1G -t freebsd-ufs -l tmp -i 4 ${1} >/dev/null 2>&1
echo -e "${DONE}"
echo -n " --> create 2GB var partition on ${1}"
${prg_gpart} add -s 2G -t freebsd-ufs -l var -i 5 ${1} >/dev/null 2>&1
echo -e "${DONE}"
echo -n " --> create usr partition on ${1}"
${prg_gpart} add -t freebsd-ufs -l usr -i 6 ${1} >/dev/null 2>&1
echo -e "${DONE}"
echo -n " --> UFS format all partitions "
for i in ${1}p3 ${1}p4 ${1}p5 ${1}p6; do
if [ "${i}" = "${1}p3" ]; then
newfs -O1 "/dev/${1}p3" >/dev/null 2>&1
else
newfs -O2 -U "/dev/${i}" >/dev/null 2>&1
fi
done
echo -e "${DONE}"
echo -n " --> mount all partitions "
if [ ! -d "${installdir}" ]; then
mkdir "${installdir}"
fi
mount "/dev/${1}p3" "${installdir}"
mkdir "${destinationdir}"
mkdir "${installdir}/tmp" "${installdir}/var" "${installdir}/usr"
mount "/dev/${1}p4" "${installdir}/tmp"
mount "/dev/${1}p5" "${installdir}/var"
mount "/dev/${1}p6" "${installdir}/usr"
echo -e "${DONE}"
####
### Part2 Download and install Software
####
if [ -z "${2}"]; then
v="`uname -m`"
else
v="${2}"
fi
echo " --> install FreeBSD ${freebsdversion} ${v}"
case "${v}" in
i386)
if [ -d "${sourcedir}/${freebsdversion}/${v}" ]; then
echo " --> found local install files"
for i in ${i386pkg}; do
echo -n " --> copy file ${i} to ${destinationdir}"
cp "${sourcedir}/${freebsdversion}/${v}/${i}" "${destinationdir}"
echo -e "${DONE}"
done
else
echo " --> download install files"
for i in ${i386pkg}; do
echo -n " --> download file ${i} to ${destinationdir}"
cd ${destinationdir}
fetch "${freebsdurl}/${v}/${v}/${freebsdversion}-RELEASE/${i}" >/dev/null 2>&1
echo -e "${DONE}"
done
fi
;;
amd64)
if [ -d "${sourcedir}/${freebsdversion}/${v}" ]; then
echo " --> found local install files"
for i in ${amd64pkg}; do
echo -n " --> copy file ${i} to ${destinationdir}"
cp "${sourcedir}/${freebsdversion}/${v}/${i}" "${destinationdir}"
echo -e "${DONE}"
done
else
echo " --> download install files"
for i in ${i386pkg}; do
echo -n " --> download file ${i} to ${destinationdir}"
cd ${destinationdir}
fetch "${freebsdurl}/${v}/${v}/${freebsdversion}-RELEASE/${i}" >/dev/null 2>&1
echo -e "${DONE}"
done
fi
;;
*)
echo "${usage}"
exit 0
;;
esac
cd "${installdir}"
for i in `ls -1 ${destinationdir}/*.txz`; do
echo -n " --> install file ${i} to ${installdir}"
tar -xzpf "${i}"
echo -e "${DONE}"
done
echo -n " --> create ${installdir}/etc/fstab"
echo "/dev/${1}p2 none swap sw 0 0
/dev/${1}p3 / ufs rw 1 1
/dev/${1}p4 /tmp ufs rw 2 2
/dev/${1}p5 /var ufs rw 2 2
/dev/${1}p6 /usr ufs rw 2 2
" > "${installdir}/etc/fstab"
echo -e "${DONE}"
echo -n " --> create ${installdir}/etc/rc.conf"
all_interfaces="`ifconfig | egrep "^[a-z][a-z]?[a-z]?[a-z][0-9]" | cut -f1 -d':'`"
echo 'hostname="beastie.freebsd.local"' > "${installdir}/etc/rc.conf"
for i in ${all_interfaces}; do
if [ "${i}" != "lo0" ] ; then
echo "ifconfig_${i}=\"DHCP\"" >> "${installdir}/etc/rc.conf"
fi
done
echo '
keymap="german.iso"
keyrate="fast"
font8x8="NO"
font8x14="NO"
font8x16="NO"
scrnmap="NO"
' >> "${installdir}/etc/rc.conf"
echo -e "${DONE}"
echo -n " --> create ${installdir}/boot/loader.conf"
echo 'loader_color="YES"
loader_logo="beastie"
' > "${installdir}/boot/loader.conf"
echo -e "${DONE}"
;;
*)
echo "${usage}"
exit 0
;;
esac
exit 0