UFS logging in Solaris (updated)

On Solaris 7 and later, the UFS file system code was extended to provide file system logging.

When enabled, all changes to file system meta-data are written to an intent log prior to being written out to the file system itself. If the machine then crashes, the log is used to roll back any unfinished changes to the meta-data, negating the need to analyse the file system structures. This reduces the fsck for UFS based file systems to a matter of seconds.

Enabling UFS logging

To enable this facility simply specify the logging mount option in /etc/vfstab

# grep logging /etc/vfstab
/dev/dsk/c1t0d0s4   /dev/rdsk/c1t0d0s4   /data   ufs   2     yes     logging

From the above, /data has logging enabled, or we can specify the -o logging if manually mounting a file system.

# mount -o logging /dev/dsk/c1t0d0s4 /data

Disabling UFS logging

If you do not require logging of a UFS file system, then either remove the logging entry from /etc/vfstab or explicitly specify using the no_logging option.

# grep logging /etc/vfstab
/dev/dsk/c1t1d0s4   /dev/rdsk/c1t1d0s4   /data2   ufs   2     yes     no_logging

From the above /data2 has no logging explicitly set

Solaris 9 onwards...

With Solaris 9 9/04 logging is enabled by default for all UFS file systems except under the following conditions:

  • When logging is explicitly disabled.
  • If there is insufficient file system space for the log.

Troubleshooting

If you don't have enough disk space for logging data, a message similar to the following is displayed:

# mount /dev/dsk/c1t0d0s4 /data
/data: No space left on device
Could not enable logging for /mnt on /dev/dsk/c1t0d0s4.

From the mount_ufs man page...

logging | nologging
      If  logging is specified, then  logging  is
      enabled  for  the  duration  of the mounted
      file system.  Logging  is  the  process  of
      storing  transactions (changes that make up
      a complete UFS operation) in a  log  before
      the  transactions are  applied to the  file
      system.  Once a transaction is stored,  the
      transaction can be applied to the file sys-
      tem later. This prevents file systems  from
      becoming  inconsistent, therefore eliminat-
      ing the need to run  fsck.   And,   because
      fsck  can  be bypassed, logging reduces the
      time required to  reboot  a  system  if  it
      crashes,  or  after  an  unclean  halt. The
      default behavior is  nologging.

      The log is allocated from  free  blocks  on
      the file system, and is sized approximately
      1 Mbyte per 1 Gbyte of file system, up to a
      maximum   of  64  Mbytes.  Logging  can  be
      enabled on any  UFS, including  root   (/).
      The  log created by UFS logging is continu-
      ally flushed as it fills  up.  The  log  is
      totally  flushed  when  the  file system is
      unmounted or as a result of the  lockfs  -f
      command.