# Scripted bsdinstall



## tommiie (Nov 17, 2019)

I want to write a script to create a jail with *bsdinstall*. However I can't get it to work. Running *bsdinstall script ./jail-installscript.sh* (where that file contains the below code) gives me the error *No root partition was found. The root FreeBSD partition must have a mountpoint of '/'.*


```
# Part I: preamble
BSDINSTALL_CHROOT="/var/jails/_base"
BSDINSTALL_DISTSITE="ftp://ftp.nl.freebsd.org/pub/FreeBSD/releases/amd64/amd64/12.0-RELEASE"
DISTRIBUTIONS="base.txz"
# Part II: setup script
#!/bin/sh
echo Test
```

Can someone provide a small working example to get me started? Or help me find the issue with my current script?


----------



## Phishfry (Nov 17, 2019)

I have never used a bsdinstall script, but I have used a bsdinstall shell to install FreeBSD on a gmirror created outside of the installer.
The one thing i discovered is the file path to the new install resides under /tmp/bsdinstall_*
So try this as your `BSDINSTALL_CHROOT=/tmp/bsdinstall_var/jails/_base`
I really don't think /var is the spot I would personally use. The /var folder is meant for "multi-purpose log, temporary, transient, and spool files"
See hier(7) for that quote.

Here is some of my FreeBSD bsdinstaller shell exploration:








						Install UEFI FreeBSD on gmirror
					

I wanted to post instruction for installing FreeBSD on a GEOM_MIRROR  -aka- gmirror(8). This is an advanced topic so I assume you are capable of determining that your two chosen disks are empty. UFS RAID1 on FreeBSD is enabled with the geom_mirror module. I am using ada0 and ada1 as examples...




					forums.freebsd.org
				



I later made this into a shell script and copied it onto my USB memstick installer.
The only thing I had to change was the `exit` statement. This was causing the whole bsdinstall to shut down instead of ending the script.

For your particular project you will need the Networking phase to complete to have internet working.
So you should use the "post-Install shell" provided at the very end of FreeBSD install to run your script.
I needed my gmirror script to run before the Disk Setup phase began.


----------



## tommiie (Nov 17, 2019)

Getting a bit off topic here, but on the /var directory as the "home" for my jails. As per the same quote, the /var directory is meant for transient and spool files, e.g. user mailbox files and I believe many Linux distributions also put their website data in /var/www, or at least used to. To me it makes sense to put mail, web, jail... data in /var as they are transient in nature. So also /var/gamesfor game status and score files, i.e. game data that changes in contents and size. Could you recommend a better location for jail and web data? hier(7) does not explicitly state where you should put that data (other than, as I read it, in /var).

Back on topic, changing the variable BSDINSTALL_CHROOT to your recommended setting does not change anything. I will check the link you posted.


----------



## Phishfry (Nov 17, 2019)

I would try and do this manually from a `bsdinstall` shell and then scriptify it.


tommiie said:


> you recommend a better location for jail


/usr/jail is what I use.
That was just my personal opinion. Jails can go anywhere you want.

The handbook suggests  /usr/jail





						FreeBSD Handbook
					

FreeBSD is an operating system used to power modern servers, desktops, and embedded platforms.




					www.freebsd.org
				



Bullet point 1.)  "A good choice can be /usr/jail/jailname, where jailname is the hostname identifying the jail."


----------



## tommiie (Nov 18, 2019)

Phishfry said:


> I would try and do this manually from a `bsdinstall` shell and then scriptify it.


I have installed a bunch of jails manually and now want to script it. Doing the bsdinstall manually does not help me in finding the correct values for these parameters.


Phishfry said:


> /usr/jail is what I use.
> That was just my personal opinion. Jails can go anywhere you want.
> 
> The handbook suggests  /usr/jail
> ...


I know it is just your personal opinion   and that you can put anything anywhere. To me, /var sounds like a more logical place as /usr is for "user utilities and applications" (as per hier(7)) and for me jails are just data for the host OS, not applications.

I believe Linux created /srv for hosting services, which could include jails (virtualization), websites, and the like.


----------

