FreeBSD LiveCD - installing a small set of tools from packages on read-only file system

If you ever happen to use a LiveCD to restore or diagnose some computer and you have only the Bootable DVD you can use this method to install additional software that you need in the ram drive. In the following example i will show you how to boot and install sysutils/testdisk midnight-commander misc/mc and sysutils/smartmontools

Depending of the tools that you need to temporary install you can adjust the size of the tmpfs. In following example i'm using 1GB of total memory in VM


1. Boot from FreeBSD-12.1-RELEASE-amd64-bootonly.iso and on the first screen select Live CD and login using root
2. Create in-memory file system where we can install the packages
mount -o size=600M -t tmpfs tmpfs /usr/local/
3. As you need internet access to download them you also need working DNS (resolve.conf) which for the liveCD is stored under /tmp/bsdinstall_etc and for packages to be extracted pkg also use /tmp which by default is only 20M and it's not enough for extraction of PACKAGESITE.txz That's why we first copy the content of the /tmp directory and then increase it's size and restore it's content. This is done only because we need resolve.conf file there and it's easy that way instead of creating directories manually.

cp -R /tmp/ /usr/local/tmp/
mount -o size=200M -t tmpfs tmpfs /tmp/
cp -R /usr/local/tmp/ /tmp/

4. Configure your network interface in my case using DHCP for interface name "hn0"

dhclient hn0

5. Install pkg

pkg bootstrap

6. Edit /usr/local/etc/pkg.conf and change PKG_DBDIR and PKG_CACHEDIR

ee /usr/local/etc/pkg.conf

Code:
PKG_DBDIR = "/usr/local/db/pkg";
PKG_CACHEDIR = "/usr/local/cache/pkg";

ESC -> leave editor -> save changes

7. Install Midnight Commander

pkg install mc

Because /root/ is on read-only fs and mc need to save the configuration under the home directory we need to change the env first or create another tmpfs for the /root/ as we did for /tmp/

setenv MC_PROFILE_ROOT /tmp/

Then we can start mc

rehash
mc

8. You can install other tools like sysutils/testdisk and sysutils/smartmontools or sysutils/scan_ffs

pkg install testdisk
pkg install smartmontools


Case:
you have unbootable FreeBSD and you need to copy some files to remote location or external usb disk.

After you boot from the LiveCD you can mount the partition that hold your /usr and then using scp(1) to copy the files but you will need to copy them one by one. Instead you can start the MC press F9 for drop down menu and make a SFTP link sftp://user@host:22/ and then navigate and copy the files to remote location become much easier.
 
Last edited:
It's working just fine under 13.2-RELEASE. Maybe you miss some step.
Did you edit /usr/local/etc/pkg.conf and uncomment the PKG_DBDIR and PKG_CACHEDIR?
 
Back
Top