diff --git a/xCAT-server/lib/xcat/plugins/anaconda.pm b/xCAT-server/lib/xcat/plugins/anaconda.pm index a7aa1fd58..2496a7d90 100644 --- a/xCAT-server/lib/xcat/plugins/anaconda.pm +++ b/xCAT-server/lib/xcat/plugins/anaconda.pm @@ -1260,6 +1260,16 @@ sub setupNFSTree { xCAT::Utils->runcmd($cmd, 0); # exportfs can export this directory immediately $callback->({data=>["now $nfsdirectory is exported!"]}); + $cmd = "cat /etc/exports"; + @entries = xCAT::Utils->runcmd($cmd, 0); + if(my $entry = grep /\Q$nfsdirectory\E/, @entries) { + # nothing to do + }else { + # if no entry in /etc/exports, one entry with default options will be added + $cmd = qq{echo "$nfsdirectory *(rw,no_root_squash,sync,no_subtree_check)" >> /etc/exports}; + xCAT::Utils->runcmd($cmd, 0); + $callback->({data=>["$nfsdirectory is added to /etc/exports with default option"]}); + } } } } @@ -1293,6 +1303,19 @@ sub setupStatemnt { $cmd = "/usr/sbin/exportfs :$nfsdirectory -o rw,no_root_squash,sync,no_subtree_check"; xCAT::Utils->runcmd($cmd, 0); $callback->({data=>["now $nfsdirectory is exported!"]}); + # add the directory into /etc/exports if not exist + $cmd = "cat /etc/exports"; + @entries = xCAT::Utils->runcmd($cmd, 0); + if(my $entry = grep /\Q$nfsdirectory\E/, @entries) { + if ($entry =~ m/rw/) { + # nothing to do + } else { + $callback->({data => ["The $nfsdirectory should be with rw option in /etc/exports"]}); + } + } else { + xCAT::Utils->runcmd(qq{echo "$nfsdirectory *(rw,no_root_squash,sync,no_subtree_check)" >> /etc/exports}, 0); + $callback->({data => ["$nfsdirectory is added into /etc/exports with default options"]}); + } } } } diff --git a/xCAT-server/lib/xcat/plugins/sles.pm b/xCAT-server/lib/xcat/plugins/sles.pm index bd5d1c5b3..15e53778b 100644 --- a/xCAT-server/lib/xcat/plugins/sles.pm +++ b/xCAT-server/lib/xcat/plugins/sles.pm @@ -1184,6 +1184,16 @@ sub setupNFSTree { xCAT::Utils->runcmd($cmd, 0); # exportfs can export this directory immediately $callback->({data=>["now $nfsdirectory is exported!"]}); + $cmd = "cat /etc/exports"; + @entries = xCAT::Utils->runcmd($cmd, 0); + if(my $entry = grep /\Q$nfsdirectory\E/, @entries) { + # nothing to do + } else { + #if there's no entry in /etc/exports, one with default option is added + $cmd = qq{echo "$nfsdirectory *(rw,no_root_squash,sync,no_subtree_check)" >> /etc/exports}; + xCAT::Utils->runcmd($cmd, 0); + $callback->({data=>["$nfsdirectory is added into /etc/exports with default option"]}); + } } } } @@ -1216,6 +1226,17 @@ sub setupStatemnt { $cmd = "/usr/sbin/exportfs :$nfsdirectory -o rw,no_root_squash,sync,no_subtree_check"; xCAT::Utils->runcmd($cmd, 0); $callback->({data=>["now $nfsdirectory is exported!"]}); + # add the directory into /etc/exports if not exist + $cmd = "cat /etc/exports"; + @entries = xCAT::Utils->runcmd($cmd, 0); + if(my $entry = grep /\Q$nfsdirectory\E/, @entries) { + if ($entry =~ m/rw/) { + }esle { + $callback->({data=>["The $nfsdirectory should be with rw option in /etc/exports"]}); + } + }else { + xCAT::Utils->runcmd(qq{echo "$nfsdirectory *(rw,no_root_squash,sync,no_subtree_check)" >>/etc/exports}, 0); + } } }