- load zfs and tmpfs by default

- rewrite interfaces script
- add new mfsbsd script to handle kenv-supplied variables
- disable additional consoles by default
- mount tmp using tmpfs
- move rootpw to compile-time variable
- have rootpw encrypted
- pre-generate ssh host keys
- be less verbose
- report sizes and file names of images created
- clear only contents of working directory
This commit is contained in:
Martin Matuska 2009-10-02 13:13:26 +00:00
Родитель f103f13705
Коммит 482126b84e
11 изменённых файлов: 195 добавлений и 90 удалений

Просмотреть файл

@ -3,6 +3,17 @@
# mfsBSD changelog
# Copyright (c) 2007-2008 Martin Matuska <mm at FreeBSD.org>
#
02.10.2009
- Drop FreeBSD-6 support
- Load ZFS and tmpfs by default
- Introduce new mfsbsd script for kenv variables
- Rewrite interfaces script
- Disable consoles (leave only v0 and v1)
- Mount tmp using tmpfs
- Move rootpw to a variable, encrypt the root password
- Pre-generate ssh host keys
- Other cleanup and fixes
20.08.2009
- Switch from doFS.sh to makefs

Просмотреть файл

@ -3,7 +3,7 @@
# mfsBSD installation (deployment) instructions
# Copyright (c) 2007 Martin Matuska <mm at FreeBSD.org>
#
# Version 1.0-BETA2
# Version 1.0-BETA4
BUILD:
For customized build please see the BUILD file
@ -15,7 +15,7 @@ You have a linux server without console access and want to install
FreeBSD on this server.
a) modify your configuration files (do this properly, or no ssh access)
b) create an image file (e.g. make DIST=1 BASE=/cdrom/7.2-RELEASE)
b) create an image file (e.g. make BASE=/cdrom/7.2-RELEASE)
c) write image with dd to the bootable harddrive of the linux server
d) reboot
e) ssh to your machine and enjoy :)
@ -25,7 +25,7 @@ You want a rescue CD-ROM with a minimal FreeBSD installation that doesn't
need to remain in the tray after booting.
a) modify your configuration files
b) create an iso image file (e.g. make iso DIST=1 BASE=/cdrom/7.2-RELEASE)
b) create an iso image file (e.g. make iso BASE=/cdrom/7.2-RELEASE)
c) burn ISO image onto a writable CD
d) boot from the CD and enjoy :)
@ -34,7 +34,7 @@ You want a rescue partition on your FreeBSD system so you can re-partition
all harddrives remotely.
a) modify your configuration files
b) create an .tar.gz file (e.g. make tar DIST=1 BASE=/cdrom/7.2-RELEASE)
b) create an .tar.gz file (e.g. make tar BASE=/cdrom/7.2-RELEASE)
c) create your slice with sysinstall or fdisk (e.g. ad0s1)
d) auto-label the slice (e.g. bsdlabel -r -w ad0s1 auto)
e) create a filesystem on the slice (e.g. newfs /dev/ad0s1a)

Просмотреть файл

@ -3,7 +3,7 @@
# mfsBSD
# Copyright (c) 2007-2008 Martin Matuska <mm at FreeBSD.org>
#
# Version 1.0-BETA3
# Version 1.0-BETA4
#
#
@ -17,6 +17,7 @@ KERNCONF?= GENERIC
MFSROOT_FREE_INODES?=5%
MFSROOT_FREE_BLOCKS?=5%
MFSROOT_MAXSIZE?=45m
ROOTPW?= mfsbsd
# If you want to build your own kernel and make you own world, you need to set
# -DCUSTOM or CUSTOM=1
@ -57,8 +58,11 @@ MKUZIP=/usr/bin/mkuzip
GZIP=/usr/bin/gzip
TOUCH=/usr/bin/touch
LS=/bin/ls
PW=/usr/sbin/pw
SED=/usr/bin/sed
UNAME=/usr/bin/uname
MAKEFS=/usr/sbin/makefs
SSHKEYGEN=/usr/bin/ssh-keygen
MKISOFS=/usr/local/bin/mkisofs
#
CURDIR!=${PWD}
@ -69,11 +73,10 @@ BSDLABEL=bsdlabel
STEPS=7
#
DOFS=${TOOLSDIR}/doFS.sh
SCRIPTS=mdinit rootpw interfaces packages
BOOTMODULES=acpi snp geom_uzip zlib
SCRIPTS=mdinit mfsbsd interfaces packages
BOOTMODULES=acpi snp geom_uzip zlib tmpfs opensolaris zfs
MFSMODULES=geom_label geom_mirror
#
IMGSIZE=48000
all: image
@ -194,17 +197,29 @@ ${WRKDIR}/.config_done:
${CP} ${SCRIPTSDIR}/$${SCRIPT} ${WRKDIR}/mfs/etc/rc.d/; \
${CHMOD} 555 ${WRKDIR}/mfs/etc/rc.d/$${SCRIPT}; \
done
@${SED} -I -E 's/\(ttyv[2-7].*\)on /\1off/g' ${WRKDIR}/mfs/etc/ttys
@echo "/dev/md0 / ufs rw 0 0" > ${WRKDIR}/mfs/etc/fstab
@echo "tmpfs /tmp tmpfs rw 0 0" >> ${WRKDIR}/mfs/etc/fstab
@echo ${ROOTPW} | ${PW} -V ${WRKDIR}/mfs/etc usermod root -h 0
@echo PermitRootLogin yes >> ${WRKDIR}/mfs/etc/ssh/sshd_config
@echo 127.0.0.1 localhost > ${WRKDIR}/mfs/etc/hosts
@${TOUCH} ${WRKDIR}/.config_done
@echo " done"
genkeys: config ${WRKDIR}/.genkeys_done
${WRKDIR}/.genkeys_done:
@echo -n "Generating SSH host keys ..."
@${SSHKEYGEN} -t rsa1 -b 1024 -f ${WRKDIR}/mfs/etc/ssh/ssh_host_key -N '' > /dev/null
@${SSHKEYGEN} -t dsa -f ${WRKDIR}/mfs/etc/ssh/ssh_host_dsa_key -N '' > /dev/null
@${SSHKEYGEN} -t rsa -f ${WRKDIR}/mfs/etc/ssh/ssh_host_rsa_key -N '' > /dev/null
@${TOUCH} ${WRKDIR}/.genkeys_done
@echo " done"
usr.uzip: install prune ${WRKDIR}/.usr.uzip_done
${WRKDIR}/.usr.uzip_done:
@echo -n "Creating usr.uzip ..."
@${MKDIR} ${WRKDIR}/mnt
@${MAKEFS} -t ffs ${WRKDIR}/usr.img ${WRKDIR}/mnt
@${MAKEFS} -t ffs ${WRKDIR}/usr.img ${WRKDIR}/mfs/usr > /dev/null
@${MKUZIP} -o ${WRKDIR}/mfs/usr.uzip ${WRKDIR}/usr.img > /dev/null
@${RM} -rf ${WRKDIR}/mfs/usr ${WRKDIR}/usr.img && ${MKDIR} ${WRKDIR}/mfs/usr
@${TOUCH} ${WRKDIR}/.usr.uzip_done
@ -228,11 +243,11 @@ ${WRKDIR}/.boot_done:
@${TOUCH} ${WRKDIR}/.boot_done
@echo " done"
mfsroot: install prune config boot usr.uzip packages ${WRKDIR}/.mfsroot_done
mfsroot: install prune config genkeys boot usr.uzip packages ${WRKDIR}/.mfsroot_done
${WRKDIR}/.mfsroot_done:
@echo -n "Creating and compressing mfsroot ..."
@${MKDIR} ${WRKDIR}/mnt
@${MAKEFS} -t ffs -m ${MFSROOT_MAXSIZE} -f ${MFSROOT_FREE_INODES} -b ${MFSROOT_FREE_BLOCKS} ${WRKDIR}/disk/mfsroot ${WRKDIR}/mfs
@${MAKEFS} -t ffs -m ${MFSROOT_MAXSIZE} -f ${MFSROOT_FREE_INODES} -b ${MFSROOT_FREE_BLOCKS} ${WRKDIR}/disk/mfsroot ${WRKDIR}/mfs > /dev/null
@${RM} -rf ${WRKDIR}/mnt ${WRKDIR}/mfs
@${GZIP} -9 -f ${WRKDIR}/disk/mfsroot
@${GZIP} -9 -f ${WRKDIR}/disk/boot/kernel/kernel
@ -244,7 +259,7 @@ ${WRKDIR}/.mfsroot_done:
@${TOUCH} ${WRKDIR}/.mfsroot_done
@echo " done"
image: install prune config boot usr.uzip mfsroot ${IMAGE}
image: install prune config genkeys boot usr.uzip mfsroot ${IMAGE}
${IMAGE}:
@echo -n "Creating image file ..."
@${MKDIR} ${WRKDIR}/mnt ${WRKDIR}/trees/base/boot
@ -254,20 +269,23 @@ ${IMAGE}:
@${RM} -rf ${WRKDIR}/mnt ${WRKDIR}/trees
@${MV} ${WRKDIR}/disk.img ${IMAGE}
@echo " done"
@${LS} -l ${IMAGE}
iso: install prune config boot usr.uzip mfsroot ${ISOIMAGE}
iso: install prune config genkeys boot usr.uzip mfsroot ${ISOIMAGE}
${ISOIMAGE}:
@if [ ! -x "${MKISOFS}" ]; then exit 1; fi
@echo -n "Creating ISO image ..."
@${MKISOFS} -b boot/cdboot -no-emul-boot -r -J -V mfsBSD -o ${ISOIMAGE} ${WRKDIR}/disk
@${MKISOFS} -b boot/cdboot -no-emul-boot -r -J -V mfsBSD -o ${ISOIMAGE} ${WRKDIR}/disk > /dev/null 2> /dev/null
@echo " done"
@${LS} -l ${ISOIMAGE}
tar: install prune config boot usr.uzip mfsroot ${TARFILE}
${TARFILE}:
@echo -n "Creating tar.gz file ..."
@${TAR} -c -z -f ${TARFILE} -C ${WRKDIR}/disk boot mfsroot.gz
@echo " done"
@${LS} -l ${TARFILE}
clean:
@if [ -d ${WRKDIR} ]; then ${CHFLAGS} -R noschg ${WRKDIR}; fi
@${RM} -rf ${WRKDIR}
@cd ${WRKDIR} && ${RM} -rf mfs mnt disk trees .*_done

6
README
Просмотреть файл

@ -3,7 +3,7 @@
# mfsBSD README
# Copyright (c) 2007 Martin Matuska <mm at FreeBSD.org>
#
# Version 1.0-BETA3
# Version 1.0-BETA4
DESCRIPTION:
This is a set of scripts that generates a bootable image, ISO file or boot
@ -15,8 +15,8 @@ e.g. a hard disk or a USB stick e.g. /dev/da0, or a bootable slice only,
e.g. /dev/ad0s1
REQUIREMENTS (build):
- FreeBSD 6 or higher installed, tested on i386 or amd64
- Base and kernel from a FreeBSD 6 or 7 distribution
- FreeBSD 7 or higher installed, tested on i386 or amd64
- Base and kernel from a FreeBSD 7 or 8 distribution
(release or snapshots, e.g mounted CDROM disc1 or ISO file)
- mkisofs from sysutils/cdrtools (optional) to create ISO images

Просмотреть файл

@ -1,28 +1,16 @@
# $Id$
#
# If you don't know the exact interface names and/or order in which they appear,
# you can configure interfaces depending on their MAC addresses here.
#
# ! If you know exact interface names and have already configured interfaces !
# ! in rc.conf, leave the initconf_interfaces list empty. !
#
# !!! DON'T FORGET TO SET defaultrouter IN rc.conf !!!
# If you don't know the exact interface names and/or order in which they
# appear, you can configure interfaces depending on their MAC addresses here.
# inifconf_interfaces should be a list of
# names of interfaces.
#initconf_interfaces="ext1 ext2"
# mac_interfaces should be a user-defined list of virtual interface names.
#mac_interfaces="ext1 ext2"
# initconf_mac_FOO should be the MAC address
# of interface FOO
initconf_mac_ext1="00:00:00:00:00:00"
initconf_mac_ext2="ff:ff:ff:ff:ff:ff"
# ifconfig_FOO_mac should be the MAC address of interface FOO
#ifconfig_ext1_mac="00:00:00:00:00:00"
#ifconfig_ext2_mac="ff:ff:ff:ff:ff:ff"
# initconf_ip_FOO should be the IP address
# of interface FOO
initconf_ip_ext1="192.168.0.1"
initconf_ip_ext2="192.168.1.1"
# initconf_netmask_FOO should be the
# netmask of interface FOO
initconf_netmask_ext1="255.255.255.0"
initconf_netmask_ext2="255.255.255.0"
# ifconfig_FOO should be configured like the real interface behind FOO
# for more information, see ifconfig(8)
#ifconfig_ext1="inet 192.168.0.1/24"
#ifconfig_ext2="inet 192.168.1.1/24"

Просмотреть файл

@ -1,10 +1,51 @@
# $Id$
#
# This is the /boot/loader.conf of your image
#
# Custom mfsbsd variables
#
# Set all auto-detected interfaces to DHCP
#mfsbsd.autodhcp="YES"
#
# Define a new root password
#mfsbsd.rootpw="foobar"
#
# Add additional nameservers here
#mfsbsd.nameservers="192.168.1.1 192.168.1.2"
#
# Change system hostname
#mfsbsd.hostname="mfsbsd"
#
# List of interfaces to be set
#mfsbsd.interfaces="em0 em1"
#
# Individual configuration of each interface
#mfsbsd.ifconfig_em0="DHCP"
#mfsbsd.ifconfig_em1="DHCP"
#
# List of special interfaces to be created
#mfsbsd.cloned_interfaces=""
#
# List of mac_interfaces (see interfaces.conf.sample)
#mfsbsd.mac_interfaces="eth0"
#mfsbsd.ifconfig_eth0_mac="xx:xx:xx:xx:xx:xx"
#mfsbsd.ifconfig_eth0="inet 192.168.1.10/24"
#
# Default router
#mfsbsd.defaultrouter="192.168.1.1"
#
# List of static routes and their definitions
#mfsbsd.static_routes="r1 r2"
#mfsbsd.route_r1="-net 192.168.2 192.168.1.1"
#mfsbsd.route_r2="-net 192.168.3 192.168.1.1"
#
# Do not change anything here until you know what you are doing
#
geom_uzip_load="YES"
mfs_load="YES"
mfs_type="mfs_root"
mfs_name="/mfsroot"
tmpfs_load="YES"
zfs_load="YES"
vfs.root.mountfrom="ufs:/dev/md0"

Просмотреть файл

@ -9,11 +9,6 @@
# Set this to any desired hostname
hostname="mfsbsd"
#
# Set this to your desired root password of the installation
# As an alternative, you can add keys to the authorized_keys file.
# If rootpw is unset or empty, you can authorize with keys only.
rootpw="mfsbsd"
#
# You need a gateway defined for a working network setup
#defaultrouter="192.168.0.254"
#
@ -22,14 +17,12 @@ rootpw="mfsbsd"
#ifconfig_rl0="DHCP"
#
# Set the size of your memory var and tmp filesystems
#
varmfs="YES"
varsize="64m"
tmpmfs="YES"
tmpsize="128m"
#
# Change the values below only if you know what you are doing!
#
mfsbsd_enable="YES"
sshd_enable="YES"
sendmail_enable="NONE"
cron_enable="NO"

Просмотреть файл

@ -2,5 +2,5 @@
#
# The file will be the /etc/resolv.conf file in your image
#
domain com
nameserver 192.168.0.254
#domain com
#nameserver 192.168.0.254

Просмотреть файл

@ -2,7 +2,8 @@
# $Id$
# PROVIDE: interfaces
# REQUIRE: LOGIN
# BEFORE: NETWORKING netif
# REQUIRE: mdinit mfsbsd
# KEYWORD: FreeBSD
. /etc/rc.subr
@ -13,25 +14,24 @@ stop_cmd=":"
interfaces_start()
{
if [ -z "${initconf_interfaces}" ]; then
if [ -z "${mac_interfaces}" ]; then
exit 0
fi
for interface in ${initconf_interfaces}; do
macaddr=`eval echo "\\$initconf_mac_${interface}"`
ipaddr=`eval echo "\\$initconf_ip_${interface}"`
netmask=`eval echo "\\$initconf_netmask_${interface}"`
echo ${ipaddr} ${initconf_hostname} ${initconf_hostname}.>> /etc/hosts
for real_if in `ifconfig -l`; do
if ifconfig ${real_if} | grep -qi ${macaddr}; then
echo ifconfig_${real_if}=\"inet ${ipaddr} netmask ${netmask}\" >> /etc/rc.conf
fi
done
for if in ${mac_interfaces}; do
_cmac=`eval echo "\\$ifconfig_${if}_mac"`
if [ -n "$_cmac" ]; then
_dif=`/sbin/ifconfig -l | /usr/bin/sed -E 's/lo[0-9]+//g'`
for i in $_dif; do
_mac=`/sbin/ifconfig $i | /usr/bin/grep ether | /usr/bin/awk '{ print $2 }'`
if [ "$_mac" = "$_cmac" ]; then
_cif=`eval echo "\\$ifconfig_${if}"`
if [ -n "$_cif" ]; then
echo "ifconfig_$i=\"${_cif}\"" >> /etc/rc.conf.d/network
fi
fi
done
fi
done
/etc/rc.d/netif restart
/etc/rc.d/routing restart
/etc/rc.d/sshd restart
}
load_rc_config $name

76
scripts/mfsbsd Normal file
Просмотреть файл

@ -0,0 +1,76 @@
#!/bin/sh
# $Id$
# PROVIDE: mfsbsd
# BEFORE: NETWORKING netif routing hostname
# REQUIRE: mountcritlocal mdinit
# KEYWORD: FreeBSD
. /etc/rc.subr
name="mfsbsd"
start_cmd="mfsbsd_start"
stop_cmd=":"
mfsbsd_start()
{
_hn=`/bin/kenv -q mfsbsd.hostname`
_clif=`/bin/kenv -q mfsbsd.cloned_interfaces`
_mif=`/bin/kenv -q mfsbsd.mac_interfaces`
_dhcp=`/bin/kenv -q mfsbsd.autodhcp`
_if=`/bin/kenv -q mfsbsd.interfaces`
_dr=`/bin/kenv -q mfsbsd.defaultrouter`
_sr=`/bin/kenv -q mfsbsd.static_routes`
_ns=`/bin/kenv -q mfsbsd.nameservers`
_rootpw=`/bin/kenv -q mfsbsd.rootpw`
if [ -n "$_hn" ]; then
echo "hostname=\"$_hn\"" >> /etc/rc.conf.d/hostname
fi
if [ -n "$_clif" ]; then
echo "cloned_interfaces=\"$_clif\"" >> /etc/rc.conf.d/network
fi
if [ -n "$_mif" ]; then
echo "mac_interfaces=\"$_clif\"" >> /etc/rc.conf.d/interfaces
for i in $_mif; do
_mac=`/bin/kenv mfsbsd.ifconfig_$i_mac`
if [ -n $_mac ]; then
echo "ifconfig_$i_mac=\"$_mac\"" >> /etc/rc.conf.d/interfaces
fi
done
fi
if `checkyesno _dhcp`; then
_dif=`/sbin/ifconfig -l | /usr/bin/sed -E 's/lo[0-9]+//g'`
for i in $_dif; do
echo "ifconfig_$i=\"DHCP\"" >> /etc/rc.conf.d/network
done
fi
for i in $_if $_mif $_clif; do
_config=`/bin/kenv mfsbsd.ifconfig_$i`
if [ -n $_config ]; then
echo "ifconfig_$i=\"$_config\"" >> /etc/rc.conf.d/network
fi
done
if [ -n "$_dr" ]; then
echo "defaultrouter=\"$_dr\"" >> /etc/rc.conf.d/routing
fi
if [ -n "$_sr" ]; then
echo "static_routes=\"$_sr\"" >> /etc/rc.conf.d/routing
for i in $_sr; do
_config=`/bin/kenv mfsbsd.route_$i`
if [ -n $_config ]; then
echo "route_$i=\"$_config\"" >> /etc/rc.conf.d/routing
fi
done
fi
if [ -n "$_rootpw" ]; then
echo $_rootpw | /usr/sbin/pw usermod root -h 0
fi
if [ -n "$_ns" ]; then
for n in $_ns; do
echo "nameserver $_n" >> /etc/resolv.conf
done
fi
}
load_rc_config $name
run_rc_command "$1"

Просмотреть файл

@ -1,22 +0,0 @@
#!/bin/sh
# $Id$
# PROVIDE: rootpw
# REQUIRE: LOGIN
# KEYWORD: FreeBSD
. /etc/rc.subr
name="rootpw"
start_cmd="rootpw_start"
stop_cmd=":"
rootpw_start()
{
if [ -n "${rootpw}" ]; then
echo ${rootpw} | pw usermod root -h 0
fi
}
load_rc_config $name
run_rc_command "$1"