FreeBSD Mini MemStick Image with SSH Access

by Ramses Soto-Navarro 10/10/2020

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


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.


$ DIR=""
$ 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
$ 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

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
$ ./

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 ~/

ifconfig ed0 netmask
route add default
echo "nameserver" >> /etc/resolv.conf
# dhcpclient ed0

# sync

Auto Startup

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

# vi /etc/rc.conf

# sync

Configure SSHD

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

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

# 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

Remote Login

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

# ssh

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.