Back to the main page

lockfs - locking Solaris UFS file system

I am sure you'll find yourself in situation when it's needed to perform some work with data on a file system when no one is accessing. 

And nowadays, especially in IT business with offices worldwide, you cannot say for sure that at midnight someone else isn't doing anything on the FS. 

Okay, so you can unmount the FS but then data is not accessible. Yes, you can mount FS as read-only. But why not just lock the FS!?  

Check man page for many options, since here I'll just mention some of them, I guess used the most. 

Say, I want to copy data to other system and want to make sure no one is writing/adding new stuff 
(yes, I am sending notification to users, but you cannot always trust they read your emails and will be patient for you to finish work). 

First I want to flush all data from RAM to the disk (don't take chance to miss anything). 

Using lockfs is more reliable than sync, since it doesn't return until all data is saved to disk. 
# lockfs -f
Note: using hard lock here is not good, since you cannot read the FS. Hard lock cannot be unlocked, so I need to unmount and mount it. See example:
# lockfs -h /.0

Filesystem           Locktype   Comment
/.0                  hard

# ls /.0
/.0: I/O error

# lockfs -u /.0  -> cannot unlock it
/.0: I/O error

# umount /.0 ; mount /.0

# ls /.0  (now I can see what's on FS)
total 66
drwxr-xr-x   6 root     root         512 Nov  5 15:40 .
drwxr-xr-x  26 root     root        1024 Nov  4 18:57 ..
-rw-------   1 root     root           6 Nov  5 14:41 1
-rw-------   1 root     root           2 Nov  5 14:55 2
Okay, so let's use write lock, since this will allow us to access data (while write is not allowed).
# lockfs -w /.0

# lockfs
Filesystem           Locktype   Comment
/.0                  write
Once I am done with coping data to other system, I can unlock the FS.
# lockfs -u /.0
And no FS is locked any more.
# lockfs   (no output)
Back to the main page