Reboot FreeBSD into md

Sometimes it is handy to tweak something about the root filesystem, and rebooting onto installation media requires walking, not to mention physical access. Alternatively, one can make a memory disk and reroot into that, allowing ssh and network access, which is far more convenient if all goes well.

To begin, ssh in as root, then run the following commands.

sh md=$(mdconfig -s 2G) newfs /dev/$md mount /dev/$md /mnt tar --one-file-system -C / -cpf - bin etc lib libexec rescue root/.ssh sbin usr/bin usr/lib usr/libdata usr/libexec usr/sbin usr/share var/empty var/run | tar -C /mnt -xpf - mkdir /mnt/dev /mnt/mnt /mnt/tmp chmod 777 /mnt/tmp ln -s ../tmp /mnt/var/tmp echo sshd_enable=YES >/mnt/etc/rc.conf echo /dev/$md / ufs rw 0 0 >/mnt/etc/fstab cat >/mnt/etc/ssh/sshd_config <<EOF PasswordAuthentication no PermitRootLogin without-password UseDNS no UsePAM no EOF umount /mnt kenv vfs.root.mountfrom=ufs:/dev/$md reboot -r

Then connect by ssh again. Easy peazy.