FreeBSD Mini MemStick Image with SSH Access

by Ramses Soto-Navarro ramses@sotosystems.com 10/10/2020


Overview
Download
Disk Image
Boot Ministick
Manual Startup
Auto Startup
Remount Set Root
Configure SSHD
Remote Login
SSHD Problem


Overview

The FreeBSD 10 ministick does not have sshd enabled by default. It must be manually configured. The same goes for the FreeBSD 12.1 ministick (mini memory stick image). mfsBSD already offers it by default. Here is how to enable it on the FreeBSD ministick. There are no permanent settings yet, so it will have to be entered every time - good for disaster recovery practice. More on remastering later.

Download

$ DIR="https://download.freebsd.org/ftp/releases/amd64/amd64/ISO-IMAGES/12.1"
$ wget $DIR/FreeBSD-12.1-RELEASE-amd64-mini-memstick.img.xz
$ xz -d FreeBSD-12.1-RELEASE-amd64-mini-memstick.img.xz
$ ln -s FreeBSD-12.1-RELEASE-amd64-mini-memstick.img mini.img

Disk Image

Create a standard 504MB disk image; great for restoring legacy BSD installs; use the BIOS standard 1024 cylinder, 16 heads and 63 sectors per track.

$ echo "1024*16*63" | bc
1032192
$ dd if=/dev/zero of=hd.img bs=512 count=1032192
1032192+0 records in
1032192+0 records out
528482304 bytes (528 MB, 504 MiB) copied, 1.79958 s, 294 MB/s
$ chmod 0666 hd.img

Boot Ministick

Create the qemu boot script. First verify that you have a network tap tunnel already running.

$ vi boot.sh

#!/bin/bash 
BOOT=c
HD="mini.img"
HD2="hd.img"
#CD="cd.iso"
MEM="256m"
qemu-system-i386 -M pc -cpu 486 -m $MEM -name "FreeBSD Memstick" -smp 1,sockets=1,maxcpus=1 -hda $HD -hdb $HD2 -net nic,model=ne2k_pci -net tap,ifname=tap0,script=no,downscript=no -boot $BOOT -no-fd-bootchk -k en-us -rtc base=localtime 2>&1 &
# -drive file=$CD,if=ide,index=1,media=cdrom 
#Convert floppy from 1.2MB to 1.44MB
# (cat dist.fs;dd if=/dev/zero bs=1 count=245760)>dist2.fs
$ ./boot.sh

When asked which session, press escape <ESC> and drop into the command prompt.

Remount and Set Root

Remount the ram disk in rear/write mode and set the root password:

# mount -o rw /
# passwd
# sync

Manual Startup

With a custom startup script you can fashion your session, start static networking, start SSH:

# vi ~/run.sh

ifconfig ed0 192.168.1.200 netmask 255.255.255.0
route add default 192.168.1.1
echo "nameserver 192.168.1.1" >> /etc/resolv.conf
/us/sbin/sshd
# dhcpclient ed0

# sync

Auto Startup

Add the auto settings to /etc/rc.conf.

# vi /etc/rc.conf
ifconfig_ed0="inet 192.169.1.200/24"
defaultrouter="192.168.1.1"
sshd_enable="YES"

# sync

Configure SSHD

Configure SSHD with new system keys. Confirm that it is running:

# cat >> /etc/ssh/sshd_config << EOF
PermitRootLogin yes
EOF

# service sshd start
# sync
# ssh-keygen -f /etc/ssh/ssh_host_rsa_key -N '' -t rsa
# /usr/sbin/sshd 
# ps aux | grep ssh
# sockstat | grep 22

This would be a good time to add configure key authentication.

# ssh-copy 192.168.1.200

Remote Login

Reboot the memstick. When prompted, select , then and login remotely.

# ssh 192.168.1.200

SSHD Problem

NOTE: I could not get SSHD to start automatically; had to start it manually. I tried looking for fixes online but did
not find any. Finally discovered how to auto start by adding the process to beginning of /etc/rc.local:

# vi /etc/rc.local
...
MACHINE=`uname -a`

service sshd start
...

The End.