running a script on boot.

I had created a zfs array, and I am using it as a /music partition (/ is on another disk, using the UFS file system).
I have created a little script, zfstart.sh:
Code:
#!/bin/sh
/sbin/zfs set mountpoint=/music tank/music
runinig
Code:
./zfstart.sh
mounts the /music partition and it is ready to be used.
I would like to run it automatically on boot. For that purpose, I have tried to use the following script:

Code:
#!/bin/sh

zfs-mount_enable=${slpd_enable-"NO"}
zfs-mount_flags=${zfs-mount_flags-"-p /var/run/zfs-mount.pid"}

Code:
. /etc/rc.subr

name="zfs-mount"
rcvar=$(set_rcvar)

#command='/sbin/zfs set mountpoint=/music tank/music'
command="./root/zfstart.sh"
load_rc_config "${name}"

run_rc_command "$1"

I have put the script in /usr/local/etc/rc.d with the name zfs-mount, fixed the right permissions for it, and added the line zfs-
Code:
mount_enable="YES"
to /etc/rc.conf.
However, it does not work, and all I get is the following message:
Code:
zfs-mount_enable=YES: not found
What am I doing wrong? How can I fix it?
Code:
uname -a
FreeBSD nisooi.workgroup 8.0-RELEASE FreeBSD 8.0-RELEASE #0: Sat Nov 21 15:48:17 UTC 2009     [email]root@almeida.cse.buffalo.edu[/email]:/usr/obj/usr/src/sys/GENERIC  i386
Code:
nisooi# df
Filesystem  1K-blocks      Used     Avail Capacity  Mounted on
/dev/ad0s2a  30462636   5617412  22408214    20%    /
devfs               1         1         0   100%    /dev
tank/music  383941248 116169728 267771520    30%    /music
 
if you set the mountpoint for a dataset once, there is no need to set it every time.
Unless you change it at somepoint.
 
Add zfs_enable="YES" into /etc/rc.conf then set the mountpoint property for the dataset: # zfs set mountpoint=/music tank/music.

Finally, add the following to /boot/loader.conf:
Code:
zfs_load="YES"

After that, /music will be automatically mounted at every boot.
 
Thanks for your reply.
I have added the following line to /etc/fstab:
Code:
zfs set mountpoint=/music tank/music
(your other suggestions were already implemented, off course).
On next boot I got the following message:
Code:
fstab /etc/fstab:5: Inappropriate file type or format.
/music had not been mounted.
 
Follow phoenix' advice, forget about fstab.

If you do add something to fstab make sure it's correct, see fstab(5).
 
vrachil said:
if you set the mountpoint for a dataset once, there is no need to set it every time.
Unless you change it at somepoint.
This is clearly not working in my case. I need to re-run
zfs set mountpoint=/music tank/music each time after I boot.
 
luli said:
This is clearly not working in my case. I need to re-run
zfs set mountpoint=/music tank/music each time after I boot.

That's because zfs isn't loaded at boot. Follow phoenix' advice and zfs will be loaded at boot.
 
luli:
Well, as to your primary post, firstly the variable names may not contain '-', so the variable name "zfs-mount_enable" is simply invalid. Replacing the minus with underscore would do.
Secondly, the line
Code:
command="./root/zfstart.sh"
is apparently pointing to a nonexistent directory/file ./root/zfstart.sh, rather than to (probably intended) /root/zfstart.sh.
After correcting these small mistakes, I think, the script from /usr/local/etc/rc.d/ should work.
Just a small notice: if you put a script in /usr/local/etc/rc.d/, don't forget that it will also be executed on shutdown, so it's best to check the parameter for the script and execute your command only in the case when it is equal to "start", or set up "start_cmd"/"stop_cmd" functions .
 
Thank you all.
first, to clear things up, Here is my /etc/rc.conf:

Code:
hostname="nisooi.workgroup"
ifconfig_re0="DHCP"
keymap="us.iso"
sshd_enable="YES"
dbus_enable="YES"
hald_enable="YES"
snddetect_enable="YES"
mixer_enable="YES"
linux_enable="YES"
avahi_daemon_enable="YES"
samba_enable="YES"
winbindd_enable="YES"
cups_enable="YES"
avahi_daemon_enable="YES"
zfs_mount_enable="YES"
moused_port="/dev/mse0"
moused_type="auto"
moused_enable="YES"
moused_ums0_flags="-F 200 -A 1.5,2.0 -a 0.7 -r high -V"

and this is /boot/loader.conf
Code:
ahci_load="YES"
sdhci_load="YES"
sound_load="YES"
snd_hda_load="YES"
snd_uaudio_load="YES"
libiconv_load="YES"
libmchain_load="YES"
cd9660_iconv_load="YES"
msdosfs_iconv_load="YES"
ntfs_load="YES"
ntfs_iconv_load="YES"
udf_load="YES"
udf_iconv_load="YES"
zfs_load="YES"
tmpfs_load="YES"
sem_load="YES"
nvidia_load="YES"

therefor the problem is not there.

Secondly, I have found this in /var/log/mount.today:

Code:
/dev/ad0s2a		/			ufs	rw		1 1
devfs			/dev			devfs	multilabel 	0 0
tank/music		/music			zfs	noatime		0 0

So I have tried to enter the third line into /etc/fstab - but again I have got the "fstab Inappropriate line" error.

Finally, I have changed the boot script name to zfs_mount, and it looks now like this:
Code:
#!/bin/sh

zfs_mount_enable=${slpd_enable-"NO"}
zfs_mount_flags=${zfs-mount_flags-"-p /var/run/zfs-mount.pid"}

. /etc/rc.subr

name="zfs-mount"
rcvar=$(set_rcvar)

#command='/sbin/zfs set mountpoint=/music tank/music'
command="/root/zfstart.sh"
load_rc_config "${name}"

run_rc_command "$1"

The error message has indeed disappeared, but the partition is stile not mounted on boot.
 
luli said:
Code:
zfs_mount_enable=${slpd_enable-"NO"}
This is wrong. It checks if slpd_enable (ldap service) has been set, if not it sets zfs_mount_enable to NO.
 
SirDice said:
This is wrong. It checks if slpd_enable (ldap service) has been set, if not it sets zfs_mount_enable to NO.
Thanks. I have corrected it, and zfs_mount looks now like that:


Code:
#!/bin/sh

zfs_mount_enable=${zfs_mount_enable-"NO"}
zfs_mount_flags=${zfs_mount_flags-"-p /var/run/zfs_mount.pid"}

. /etc/rc.subr

name="zfs_mount"
rcvar=$(set_rcvar)

#command='/sbin/zfs set mountpoint=/music tank/music'
command="/root/zfstart.sh"
load_rc_config "${name}"

run_rc_command "$1"
but yet, /music is not mounted on boot.
 
Have you read what Phoenix suggested?
You don't have zfs_enable="YES" in rc.conf and that is your problem.
Add that line, and set zfs_mount_enable="NO". I'd bet it will work without any more tuning.
 
Back
Top