DaemonForums  

Go Back   DaemonForums > Miscellaneous > Guides

Guides All Guides and HOWTO's.

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1   (View Single Post)  
Old 15th February 2010
J65nko J65nko is offline
Administrator
 
Join Date: May 2008
Location: Budel - the Netherlands
Posts: 4,128
Default Adding 'noatime' and 'softdep' mount options to '/etc/fstab'

On my current desktop I have the following /etc/fstab:
Code:
/dev/wd0a / ffs rw 1 1
/dev/wd0m /home ffs rw,nodev,nosuid 1 2
/dev/wd0e /home/xx ffs rw,nodev,nosuid 1 2
/dev/wd0d /tmp ffs rw,nodev,nosuid 1 2
/dev/wd0k /usr ffs rw,nodev 1 2
/dev/wd0l /usr/local ffs rw,nodev 1 2
/dev/wd0f /var ffs rw,nodev,nosuid 1 2
/dev/wd0h /var/log ffs rw,nodev,nosuid 1 2
/dev/wd0g /var/tmp ffs rw,nodev,nosuid 1 2
For adding the mount options 'noatime' and 'softdep' I use the following script, which is easily adapted to another disk layout.

Code:
# ---------------------------------------------------------
FILE=/etc/fstab
FILE=$( basename ${FILE} )
ORIG=${FILE}.orig

LABELS=adefghiml
OPTIONS='noatime,softdep'       # no trailing "," after last option !
DISK=wd
NR=0

cat <<END
Enabling mount option(s) "${OPTIONS}" on disk ${DISK}${NR} for label(s): "${LABELS}"
END

cp -p ${FILE} ${ORIG} 
sed -e "/${DISK}[${NR}][${LABELS}]/  s/rw/rw,${OPTIONS}/" ${ORIG} >${FILE}
As you can see, there are no hardcoded values for the disk name and nr, no mention of "wd0" or "wd1".
The same applies to the mount options to be added and the labels. Even the file name and the name of the backup of the original, have been factored out.

As a test we first copy the /etc/fstab to the current directory. Then we run the script with the sh -vx options to check if the variables are being expanded correctly.

Code:
$ cp /etc/fstab . 
$ sh -vx   softdep-noatime-adefghiml
# ---------------------------------------------------------
FILE=/etc/fstab
+ FILE=/etc/fstab
FILE=$( basename ${FILE} )
+ basename /etc/fstab
+ FILE=fstab
ORIG=${FILE}.orig
+ ORIG=fstab.orig

LABELS=adefghiml
+ LABELS=adefghiml
OPTIONS='noatime,softdep'       # no trailing "," after last option !
+ OPTIONS=noatime,softdep
DISK=wd
+ DISK=wd
NR=0
+ NR=0

cat <<END
Enabling mount option(s) "${OPTIONS}" on disk ${DISK}${NR} for label(s): "${LABELS}"
END
+ cat
+ << END 
Enabling mount option(s) "noatime,softdep" on disk wd0 for label(s): "adefghiml"

cp -p ${FILE} ${ORIG} 
+ cp -p fstab fstab.orig
sed -e "/${DISK}[${NR}][${LABELS}]/  s/rw/rw,${OPTIONS}/" ${ORIG} >${FILE}
+ sed -e /wd[0][adefghiml]/  s/rw/rw,noatime,softdep/ fstab.orig
+ > fstab
The result is
Code:
/dev/wd0a / ffs rw,noatime,softdep 1 1
/dev/wd0m /home ffs rw,noatime,softdep,nodev,nosuid 1 2
/dev/wd0e /home/xx ffs rw,noatime,softdep,nodev,nosuid 1 2
/dev/wd0d /tmp ffs rw,noatime,softdep,nodev,nosuid 1 2
/dev/wd0k /usr ffs rw,nodev 1 2
/dev/wd0l /usr/local ffs rw,noatime,softdep,nodev 1 2
/dev/wd0f /var ffs rw,noatime,softdep,nodev,nosuid 1 2
/dev/wd0h /var/log ffs rw,noatime,softdep,nodev,nosuid 1 2
/dev/wd0g /var/tmp ffs rw,noatime,softdep,nodev,nosuid 1 2
A break down of the sed(1) command which accomplishes this result:
Code:
sed -e /wd[0][adefghiml]/  s/rw/rw,noatime,softdep/ fstab.orig >fstab

-e              : the sed command(s) follow in-line

On all lines matching the pattern:

        /wd[0][adefghiml]/

substitute the 'rw' with 'rw,noatime,softdep' 

The  pattern selecting on which lines to do this substitution or replacement:

/               : start of search pattern
w               : a "w" character followed by a
d               : "d" character followed by a
[0]             : the "0' character. In this case the two brackets could
                  have been left out. A 'wd[01]' would match both a 'wd0' 
                  and a 'wd1' string 
                  So a '0' followed by one of the followin charaters between
                  the '[' and ']'
[               : start of the character class
adefghiml       : the  members of this class
]               : end of character class
                  This means that 'wd0a', 'wd0d' and 'wd0e' up to 'wd0l[/b]
                  will match.
/               ; end of search pattern

The 'subsitute' or 'search and replace' operation.     

s               : we do a substitution
/               : delimiter for start of the pattern
rw              : a 'r" followed by a 'w'
/               : end delimiter of search pattern, start delimiter of
                  replacement pattern
rw,             : the string sequence 'rw' followed by a comma, followed 
noatime,        : by the strings 'noatime,' and 
softdep         : the string 'softdep'
/               : delimiter signalling end of replacement pattern
__________________
You don't need to be a genius to debug a pf.conf firewall ruleset, you just need the guts to run tcpdump
Reply With Quote
 

Tags
/etc/fstab, freebsd, mount options, noatime, openbsd, softdep

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with some more sensible fstab defaults maxrussell FreeBSD General 4 18th July 2009 02:44 PM
C F Card and fstab terryd FreeBSD General 1 3rd December 2008 05:26 PM
Mounting ext2 in fstab latorion FreeBSD General 3 6th August 2008 04:56 PM
mount fusefs (sshfs) from fstab elon FreeBSD General 4 29th July 2008 06:41 PM
fstab and CD/DVD device corneliu FreeBSD General 7 24th May 2008 02:11 AM


All times are GMT. The time now is 11:03 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Content copyright © 2007-2010, the authors
Daemon image copyright ©1988, Marshall Kirk McKusick