# Diskless help



## balanga (Aug 19, 2019)

I have managed to set up an environment which me to run FreeBSD diskless(), but one thing I can't figure out is how to make certain directories writable, eg /var.  According to http://www.nber.org/sys-admin/FreeBSD-diskless.html what I need to do is add all per system customisation to a  conf/ directory but am unable to make this work.

If anyone has any working examples, I'd like to have a look.


----------



## sol289 (Aug 19, 2019)

First of all, read official handbook chapter Diskless Operation with PXE.

In short, your server(s) must be:
1. NFS server serving root FS for you diskless clients.
2. TFTP server which will serve pxeboot file.
3. DHCP server which will provide clients with IP address, boot file name and location.

If i understand you correctly, all three parts is working, and when booted you have read-only root. I have used bsdinstall to fetch and extract clean system root to /mnt/diskless dir. Server's IP is 10.101.0.1, client gets fixed IP from DHCP server using per-MAC config in dhcpd.conf. Here's files from my diskless server with which diskless clients boots and mounts read-only root and make memory FS /var and /tmp.

I'm using 11.3-RELEASE for server and clients.

/etc/rc.conf:

```
hostname="virt"
ifconfig_em1="inet 10.101.0.1/24"
sshd_enable="YES"
ntpd_enable="YES"
inetd_enable="YES"

nfs_server_enable="YES"
nfs_server_flags="-u -t -n 4 -h 10.101.0.1"
rpcbind_enable="YES"
mountd_enable="YES"
mountd_flags="-l -r"
rpc_lockd_enable="YES"
rpc_statd_enable="YES"
nfsuserd_enable="YES"
nfsuserd_flags="-verbose -domain local"
nfsv4_server_enable="YES"

dhcpd_enable="YES"
dhcpd_ifaces="em1"
```

/etc/exports:

```
/mnt/diskless -maproot=root -network 10.101.0 -mask 255.255.255.0
```

/mnt/diskless/etc/fstab:

```
10.101.0.1:/mnt/diskless    /   nfs ro  0   0
```

conf dir in diskless root

```
# ls /mnt/diskless/conf
total 8
drwxr-xr-x  3 root  wheel  512 14 авг.  15:33 10.101.0.20
drwxr-xr-x  2 root  wheel  512 14 авг.  15:40 base
```

default /etc and /var for all clients (done as said in Handbook chapter, see link)

```
# ls /mnt/diskless/conf/base
total 960
-rw-r--r--  1 root  wheel  356664 14 авг.  15:40 etc.cpio.gz
-rw-r--r--  1 root  wheel  582993 14 авг.  14:43 var.cpio.gz
```

particular diskless client's /etc dir

```
# ls /mnt/diskless/conf/10.101.0.20/etc/
total 112
-rw-r--r--  1 root  wheel    360 14 авг.  15:39 fstab
-rw-r--r--  1 root  wheel    476  5 июля  08:47 group
-rw-r--r--  1 root  wheel   1162 15 авг.  00:18 hosts
-rw-------  1 root  wheel   1720  5 июля  08:47 master.passwd
-rw-r--r--  1 root  wheel      6 14 авг.  15:31 md_size
-rw-r--r--  1 root  wheel     47 15 авг.  00:21 motd
-rw-r--r--  1 root  wheel   1596  5 июля  08:47 passwd
-rw-r--r--  1 root  wheel  40960  5 июля  08:47 pwd.db
-rw-r--r--  1 root  wheel    250 15 авг.  03:35 rc.conf
-rw-------  1 root  wheel  40960  5 июля  08:47 spwd.db
```

I need different fstab for this client to mount some other share, md_size contains string "20000" to make size of /etc dir 10Mb instead of default 5Mb.
TFTP server:

```
# cat /etc/inetd.conf | grep tftpboot
tftp    dgram   udp wait    root    /usr/libexec/tftpd  tftpd -l -s /mnt/tftpboot
```


```
# ls -l /mnt/tftpboot
total 252
-r--r--r--  1 root  wheel  256000 14 авг.  10:38 pxeboot
```

DHCP server (i'm using pkg isc-dhcp44-server)

```
# cat /usr/local/etc/dhcpd.conf
subnet 10.101.0.0 netmask 255.255.255.0 {
    range 10.101.0.50 10.101.0.99;
    filename "pxeboot";
    option root-path "10.101.0.1:/mnt/diskless";
    next-server 10.101.0.1;
}

host fixed_netboot {
    hardware ethernet 00:50:56:30:fe:f6;
    fixed-address 10.101.0.20;
}
```

And here's what i have on diskless client when booted:


```
# mount
10.101.0.1:/mnt/diskless on / (nfs, read-only)
devfs on /dev (devfs, local, multilabel)
tmpfs on /etc (tmpfs, local)
tmpfs on /var (tmpfs, local)
procfs on /proc (procfs, local)
tmpfs on /var (tmpfs, local)
tmpfs on /tmp (tmpfs, local)

# df -h
Filesystem                    Size    Used   Avail Capacity  Mounted on
10.101.0.1:/mnt/diskless      9.7G    952M    8.0G    10%    /
devfs                         1.0K    1.0K      0B   100%    /dev
tmpfs                         9.8M    3.0M    6.7M    31%    /etc
tmpfs                         5.0M    5.0M      0B   100%    /var
procfs                        4.0K    4.0K      0B   100%    /proc
tmpfs                          32M    124K     32M     0%    /var
tmpfs                          20M    8.0K     20M     0%    /tmp
```

/etc, /var and /tmp are writeble, and for some reason mounted twice.


----------



## T-Daemon (Aug 20, 2019)

balanga said:


> ... one thing I can't figure out is how to make certain directories writable, eg /var.


You should also read besides the chapter in the handbook and diskless(8) the documentation at the beginning of the /etc/rc.initdiskless script.

It gives a detailed overview over the creation and population of memory filesystems mounted on top of a read-only root filesystem to implement writeable and host-specific parts of root.

The handbook might be out of date, there is a note regarding /var, the document does not  recommand to create it by specifying it in /conf, but by creating it in fstab.


----------

