{"id":356,"date":"2012-02-25T01:39:50","date_gmt":"2012-02-25T01:39:50","guid":{"rendered":"http:\/\/joelinoff.com\/blog\/?p=356"},"modified":"2012-03-15T00:31:38","modified_gmt":"2012-03-15T00:31:38","slug":"how-to-fix-stale-nfs-mounts-on-linux-without-rebooting","status":"publish","type":"post","link":"https:\/\/joelinoff.com\/blog\/?p=356","title":{"rendered":"How to fix stale NFS mounts on linux without rebooting"},"content":{"rendered":"<p>I have often noticed that some folks reboot systems to fix stale NFS mount problems which can be disruptive. <\/p>\n<p>Fortunately, that often isn&#8217;t necessary. All you have to do is restart nfs and autofs services.  However that sometimes fails because user processes have files open on the stale partition or users are cd&#8217;ed to the stale partition. <\/p>\n<p>Both conditions are easy to fix. The steps to fix stale mounts by addressing the previously described conditions are described below.<br \/>\n<!--more--><\/p>\n<h1>Step 1. Kill process with open files on the partition<\/h1>\n<p>Use <code>lsof <\/code> to find the processes that have files open on the partition and then kill those processes using <code>kill<\/code> or <code>pkill<\/code>.<\/p>\n<p>[crayon lang=&#8221;bash&#8221; toolbar=&#8221;always&#8221; title=&#8221;Step 1. Kill Processes&#8221;]<br \/>\n% sudo su &#8211;<\/p>\n<p>% # Find the jobs that are accessing the state partition and kill them.<br \/>\n% kill -9 $(lsof |\\<br \/>\n    egrep &#8216;\/stale\/fs|\/export\/backup&#8217; |\\<br \/>\n    awk &#8216;{print $2;}&#8217; |\\<br \/>\n    sort -fu )<\/p>\n<p>% # Restart the NFS and AUTOFS services<br \/>\n% service nfs stop<br \/>\n% service autofs stop<br \/>\n% service nfs start<br \/>\n% service autofs start<\/p>\n<p>% # Check it<br \/>\n% ls \/stale\/fs<br \/>\n[\/crayon]<br \/>\nTypically this is sufficient but if it fails, you need to go to step 2.<\/p>\n<h1>Step 2. Kill process that have cd&#8217;ed to the partition<\/h1>\n<p>Look at the current working directory of all of the users. If any of them are on the partition, that process has to be killed. <\/p>\n<p>[crayon lang=&#8221;bash&#8221; toolbar=&#8221;always&#8221; title=&#8221;Step 2. Kill Specific Users&#8221;]<br \/>\n% sudo su &#8211;<\/p>\n<p>% # List the users that are cd&#8217;ed to the stale partition and kill their jobs.<br \/>\n% # NOTE: change \/stale\/fs to the path to your stale partition.<br \/>\n% kill -9 $( for u in $( who | awk &#8216;{print $1;}&#8217; | sort -fu ) ; do \\<br \/>\n    pwdx $(pgrep -u $u) |\\<br \/>\n    grep &#8216;\/stale\/fs&#8217; |\\<br \/>\n    awk -F: &#8216;{print $1;}&#8217; ; \\<br \/>\ndone)<\/p>\n<p>% # umount the stale partition<br \/>\n% umount -f \/state\/fs<\/p>\n<p>% # Restart the NFS and AUTOFS services<br \/>\n% service nfs stop<br \/>\n% service autofs stop<br \/>\n% service nfs start<br \/>\n% service autofs start<\/p>\n<p>% # Check it<br \/>\n% ls \/stale\/fs<br \/>\n[\/crayon]<\/p>\n<p>If that fails you have to kill all of the users.<\/p>\n<h1>Step 3. Kill all of the users<\/h3>\n<p>If step 2 doesn&#8217;t work then there is something strange going on but killing all of the user processes will usually fix it. That is done as follows.<\/p>\n<p>[crayon lang=&#8221;bash&#8221; toolbar=&#8221;always&#8221; title=&#8221;Step 3. Kill All Users&#8221;]<br \/>\n% sudo su &#8211;<\/p>\n<p>% # Kill all user processes.<br \/>\n% for u in $( who | awk &#8216;{print $1;}&#8217; | sort -fu ) ; do \\<br \/>\n    kill -9 $(pgrep -u $u) |\\<br \/>\n    awk -F: &#8216;{print $1;}&#8217; ; \\<br \/>\ndone<\/p>\n<p>% # umount the stale partition<br \/>\n% umount -f \/state\/fs<\/p>\n<p>% # Restart the NFS and AUTOFS services<br \/>\n% service nfs stop<br \/>\n% service autofs stop<br \/>\n% service nfs start<br \/>\n% service autofs start<\/p>\n<p>% # Check it<br \/>\n% ls \/stale\/fs<br \/>\n[\/crayon]<\/p>\n<p>As you can see, it is basically the same as step 2 except that all user processes are killed.<\/p>\n<p>If that doesn&#8217;t work you need to resort the nuclear option: rebooting.<\/p>\n<h1>Step 4. Reboot<\/h1>\n<p>This is the option of last resort but it should always work.<\/p>\n<p>If you know of any other tips for fix stale NFS mounts I would really like to hear about them.<\/p>\n<p>Enjoy!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I have often noticed that some folks reboot systems to fix stale NFS mount problems which can be disruptive. Fortunately, that often isn&#8217;t necessary. All you have to do is restart nfs and autofs services. However that sometimes fails because user processes have files open on the stale partition or users are cd&#8217;ed to the &hellip; <a href=\"https:\/\/joelinoff.com\/blog\/?p=356\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">How to fix stale NFS mounts on linux without rebooting<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0},"categories":[15],"tags":[],"_links":{"self":[{"href":"https:\/\/joelinoff.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/356"}],"collection":[{"href":"https:\/\/joelinoff.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/joelinoff.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/joelinoff.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/joelinoff.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=356"}],"version-history":[{"count":12,"href":"https:\/\/joelinoff.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/356\/revisions"}],"predecessor-version":[{"id":1001,"href":"https:\/\/joelinoff.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/356\/revisions\/1001"}],"wp:attachment":[{"href":"https:\/\/joelinoff.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=356"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/joelinoff.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=356"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/joelinoff.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=356"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}