DaemonForums  

Go Back   DaemonForums > Miscellaneous > Guides

Guides All Guides and HOWTO's.

Reply
 
Thread Tools Display Modes
  #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
  #2   (View Single Post)  
Old 15th February 2010
DutchDaemon's Avatar
DutchDaemon DutchDaemon is offline
Real Name: Ben
Spam Refugee
 
Join Date: Jul 2008
Location: Rotterdam, The Netherlands
Posts: 336
Default

OpenBSD specific?
Reply With Quote
  #3   (View Single Post)  
Old 15th February 2010
J65nko J65nko is offline
Administrator
 
Join Date: May 2008
Location: Budel - the Netherlands
Posts: 4,128
Default

It has been quite a while since FreeBSD went from wd to ad for hard disks. FreeBSD also not supports the mount option 'softdep'. You have to choose to either use 'soft updates' or not when you do a newfs of the label/partition.

Considering this it is somewhat OpenBSD specific

As consolation, a FreeBSD version with adds the "noatime" mount option.

First the FreeBSD fstab:
Code:
# Device                Mountpoint      FStype  Options         Dump    Pass#
/dev/ad0s3b             none            swap    sw              0       0
/dev/ad0s3a             /               ufs     rw              1       1
/dev/ad0s3e             /tmp            ufs     rw              2       2
/dev/ad0s3f             /usr            ufs     rw              2       2
/dev/ad0s3d             /var            ufs     rw              2       2
/dev/acd0               /cdrom          cd9660  ro,noauto       0       0
The script:
Code:
# ---------------------------------------------------------
FILE=/etc/fstab
FILE=$( basename ${FILE} )
ORIG=${FILE}.orig

LABELS=adef
OPTIONS='noatime'       # no trailing "," after last option !
DISK=ad
NR=0
SLICE=s3

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

cp -p ${FILE} ${ORIG} 
sed -e "/${DISK}${NR}${SLICE}[${LABELS}]/  s/rw/rw,${OPTIONS}/" ${ORIG} >${FILE}
The sed(1) line with all the variables expanded:

Code:
 sed -e /ad0s3[adef]/  s/rw/rw,noatime/ fstab.orig >fstab
The result:
Code:
# Device                Mountpoint      FStype  Options         Dump    Pass#
/dev/ad0s3b             none            swap    sw              0       0
/dev/ad0s3a             /               ufs     rw,noatime              1       1
/dev/ad0s3e             /tmp            ufs     rw,noatime              2       2
/dev/ad0s3f             /usr            ufs     rw,noatime              2       2
/dev/ad0s3d             /var            ufs     rw,noatime              2       2
/dev/acd0               /cdrom          cd9660  ro,noauto       0       0
__________________
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
  #4   (View Single Post)  
Old 16th February 2010
Oko's Avatar
Oko Oko is offline
Rc.conf Instructor
 
Join Date: May 2008
Location: Kosovo, Serbia
Posts: 1,102
Default

J65nko,

I do not know if you are in the mood or not for more howtos but I would love to see one on
optimizing disk performance using size of the namei() cache, as well as complete HDD encryption using softraid driver (NOT svnd !)

Cheers,
OKO
Reply With Quote
Reply

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:31 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