# Examples of using rc.initdiskless



## balanga (Jan 25, 2020)

Can anyone provide any examples of how /etc/rc.initdiskless is used?


----------



## sol289 (Jan 25, 2020)

Have you read https://www.freebsd.org/doc/handbook/network-diskless.html already? It is a step-by-step guide to build a diskless system on FreeBSD, you should start there.


----------



## balanga (Jan 25, 2020)

Thanks for referring me to the above page... I have read those instructions many times and am able to pxeboot FreeBSD but unable to make /etc and /var writable and was never really sure how /etc/rc.initdiskless came into play.... but here its is plain as day:-



> When booting from an NFS root volume, /etc/rc detects the NFS boot and runs /etc/rc.initdiskless. In this case, /etc and /var need to be memory backed file systems so that these directories are writable but the NFS root directory is read-only:



Seems as though I need to figure this bit out before revisiting diskless booting...

```
# chroot ${NFSROOTDIR}
# mkdir -p conf/base
# tar -c -v -f conf/base/etc.cpio.gz --format cpio --gzip etc
# tar -c -v -f conf/base/var.cpio.gz --format cpio --gzip var
```


----------



## sol289 (Jan 26, 2020)

I see that you have asked this before, and I'm already answered to you thoroughly in Thread diskless-help.71975.
/etc in diskless setup shouldn't be writeable, and /var is temporary memory-backed FS. You can make /etc writeble, if you mount writeble NFS share above it, but I don't see why you would want to do this. 

Maybe you should post your diskless /etc/fstab here, so that we can start from somewhere. Also read again my message in old thread.


----------



## balanga (Jan 31, 2020)

After much trial and error (mostly error) I have my system remote booting with writable directories... but can't yet figure out how to install pkgs. I tried to copy a FreeBSD installation which included installed pkgs to ${NFSROOTDIR}
but that didn't work. Also tried `chroot ${NFSROOTDIR}` and `pkg add -y mc` but that didn't work either...

Accodring to http://www.nber.org/sys-admin/FreeBSD-diskless.html



> *Upates with pkg-add*
> pkg-add keeps a database of installed packages at /var/db/pkg. We do updates from a client machine with rw access to /pxeroot and the original freebsdboot:/pxeroot/var mounted as its /var.



.... unfortunately I don't follow how to do this....


----------



## sol289 (Jan 31, 2020)

balanga said:


> Also tried `chroot ${NFSROOTDIR}` and `pkg add -y mc` but that didn't work either...



This is the right way, but use `pkg install -y mc` instead.


----------



## balanga (Jan 31, 2020)

> root@freenas:/ # chroot /mnt/nas/tftproot/FreeBSD
> root@freenas:/ # pkg install -y mc
> pkg: /var/db/pkg/local.sqlite permissions (0775) too lax



I managed to change this to (0644) but then got:-


> root@freenas:/ # pkg install -y mc
> pkg: /var/db/pkg/local.sqlite wrong user or group ownership (expected 0/0 versus actual 65534/65534)



After setting `chmod` and `chown` correctly and trying again I get:-


> oot@freenas:/ # pkg install -y mc
> Updating FreeBSD repository catalogue...
> FreeBSD repository is up to date.
> All repositories are up to date.
> ...



This clearly isn't correct since when I try running mc various libs are missing.....

Maybe I should delete it and try again...


----------



## sol289 (Feb 1, 2020)

Try `pkg install -f mc`.


----------



## T-Daemon (Feb 1, 2020)

Run first `pkg -f update` or `pkg upgrade`


----------



## sol289 (Feb 1, 2020)

Also it will be good to know your system versions in both of your system's root and your `$NFSROOT`. And which way did you take to you make your `$NFSROOT` - `make buildworld installworld`, `bsdinstall` or other.


----------



## balanga (Feb 1, 2020)

Thanks for the suggestions on how to install mc, but something is missing.... mc is installed but I get:-


> ld-elf.so.1: Shared object "libslang.so.2" not found, required by "mc"


----------



## balanga (Feb 1, 2020)

sol289 said:


> Also it will be good to know your system versions in both of your system's root and your `$NFSROOT`. And which way did you take to you make your `$NFSROOT` - `make buildworld installworld`, `bsdinstall` or other.



I will try and create a script to detail exactly what I did, but in brief terms I just extracted kernel.txz and base.txz from https://download.freebsd.org/ftp/releases/amd64/12.0-RELEASE/ into `$NFSROOT`.

I did try 12.1 but that wouldn't even boot.


----------



## T-Daemon (Feb 1, 2020)

balanga said:


> ld-elf.so.1: Shared object "libslang.so.2" not found, required by "mc"



libslang.so.2 is provided by devel/libslang2, check if is installed.


----------



## sol289 (Feb 1, 2020)

balanga said:


> I will try and create a script to detail exactly what I did, but in brief terms I just extracted kernel.txz and base.txz from https://download.freebsd.org/ftp/releases/amd64/12.0-RELEASE/ into `$NFSROOT`.



You forgot to extract lib32.txz, `amd64` arch requires it.  You can try the script that I wrote for simple and fast installing of FreeBSD - on the new system or as a jail template or as the diskless root - you can take it in this thread: 
	

	







						bsdinstall fails
					

After playing around with scripting bsdinstall I now tried to manually create a jail with bsdintall.  % sudo zfs create zroot/var/jails/_base % sudo bsdinstall jail /var/jails/_base/   I then can select a mirror and I've tried several of them, but they all return the error message: Error while...




					forums.FreeBSD.org
				



 .


----------



## balanga (Feb 1, 2020)

I've just installed FreeBSD 12.0 amd64 from scratch and only need kernel.txz and base.txz and as soon as the system booted I ran `pkg install -y mc` and misc/mc got installed without a problem...

I guess I'll try copying this partition to ${NFSROOTDIR} and see if it works....


----------



## balanga (Feb 1, 2020)

It works!

Now to try hone things.... I notice a number errors such as 'Write to restore size failed' but they scroll past too quickly and nothing seems to get shown when running `dmesg`.


----------



## sol289 (Feb 1, 2020)

Look into /var/run/dmesg.boot


----------



## balanga (Feb 1, 2020)

Those particular msgs don't seem to get recorded.


----------

