mfsBSD tweaks to help automation

I PXE boot mfsBSD to boostrap FreeBSD and Puppet installation, because it is small, and it works. In the past I have used the i386 version because it’s smaller, but as of 10.1 I the difference is negligible. Some of its defaults get in the way of automation, so I change them:

  • Mount the ISO, clone its contents, mount the root filesystem
mkdir dist
fetch -o dist
mkdir mfsiso.mnt
mfs_iso_dev=`sudo mdconfig -a -t vnode -f $iso_image`
sudo mount_cd9660 /dev/$mfs_iso_dev mfsiso.mnt
mkdir isocontents
cp -Rp mfsiso.mnt/* isocontents/
gunzip isocontents/mfsroot.gz
mkdir mfsroot.mnt
mfs_root_dev=`sudo mdconfig -a -t vnode -f isocontents/mfsroot`
sudo mount /dev/$mfs_root_dev mfsroot.mnt
  • Make desired modifications
### autologin ###
sudo sed -i '' -e 's/:ht:np:/:al=root:ht:np:/' mfsroot.mnt/etc/gettytab
### .login automatic operations ###
sudo chmod g+w mfsroot.mnt/root/{,.login}
cat > mfsroot.mnt/root/ <<__eof_prepare__
while [ "0" != "\$ping_response" ]; do
  echo Waiting to let network connections settle ...
  sleep 1
  ping -qc 1 \$puppet_server > /dev/null
mkdir -p \$mount_point
mount \$puppet_server:/usr/exports/deploy \$mount_point
ln -sf \$mount_point/ ./
chmod ug+x mfsroot.mnt/root/
sudo chown root mfsroot.mnt/root/
cat > mfsroot.mnt/root/.login <<__eof_login__
/root/ \$tty && /root/
sudo chmod g-w mfsroot.mnt/root/{,.login}
echo 'autoboot_delay="2"' >> isocontents/boot/loader.conf
  • Unmount and repackage the image to a new ISO[1]
sudo umount mfsroot.mnt
sudo mdconfig -d -u `echo $mfs_root_dev | sed 's/md//'`
gzip isocontents/mfsroot
boot_sector=`isoinfo -d -i $iso_image | grep Bootoff | awk '{print $3}'`
dd if=$iso_image bs=2048 count=1 skip=$boot_sector of=isocontents/boot.img
mkisofs -J -R -no-emul-boot -boot-load-size 4 -b boot.img -o new_image.iso isocontents/
sudo mv -i new_image.iso /tftpboot/images/mfsbsd10/mfsbsd-10.1-RELEASE-amd64.iso
  • Clean up
sudo umount mfsiso.mnt
sudo mdconfig -d -u `echo $mfs_iso_dev | sed 's/md//'`
rmdir mfsiso.mnt
rmdir mfsroot.mnt

[1] Thanks to this old blog post for tips on getting ISOs created.