CentOS에서 부팅 시 네트워크가 느린 경우 삼바, sshfs 등의 네크워크 파일 시스템 mount가 되지 않는 경우가 발생한다.

/etc/fstab에 _netdev나 x-systemd.automount,x-systemd.requires=network-online.target,x-systemd.after=network-online.target의 경우 System의 Network가 online이 되면 mount를 시도하는 옵션이지만 mount 명령어를 따로 실행해도 mount하는데 20초 이상 걸리는 상황에서는 해당 옵션을 활성화해도 boot 후 mount가 되지 않았다.

결국 Google 검색 후 Crontab에 boot 시 script를 돌리는 것으로 해결

 

1. mount 실패 로그

● TKS_VM_BACKUP.mount - /TKS_VM_BACKUP
   Loaded: loaded (/etc/fstab; enabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Fri 2020-04-10 18:13:49 KST; 12min ago
    Where: /TKS_VM_BACKUP
     What: //192.168.x.x/TKS_VM_IMG
     Docs: man:fstab(5)
           man:systemd-fstab-generator(8)

  Process: 2270 ExecMount=/bin/mount //192.168.x.x/TKS_VM_IMG /TKS_VM_BACKUP -t cifs -o _netdev,x-systemd.after=network-online.target,noexec,nosuid,vers=3.0,credentials=/root/.smb.cred (code=exited, status=32)

Apr 10 18:13:42 winterfell systemd[1]: Mounting /TKS_VM_BACKUP...
Apr 10 18:13:42 winterfell snoopy[2270]: [uid:0 sid:1 tty:(none) cwd:/ filename:/bin/mount]: /bin/mount //192.168.x.x/TKS_VM_IMG /TKS_VM_BACKUP -t cifs -o _netdev,x-s...ot/.smb.cred
Apr 10 18:13:42 winterfell snoopy[2278]: [uid:0 sid:1 tty:(none) cwd:/ filename:/sbin/mount.cifs]: /sbin/mount.cifs //192.168.x.x/TKS_VM_IMG /TKS_VM_BACKUP -o rw,noex...cred,_netdev
Apr 10 18:13:48 winterfell mount[2270]: Unable to find suitable address.
Apr 10 18:13:49 winterfell systemd[1]: TKS_VM_BACKUP.mount mount process exited, code=exited status=32
Apr 10 18:13:49 winterfell systemd[1]: Failed to mount /TKS_VM_BACKUP.
Apr 10 18:13:49 winterfell systemd[1]: Unit TKS_VM_BACKUP.mount entered failed state.

2. Script 생성

vi /root/smb_mount_chk.sh

#!/bin/bash
# nettester.sh: test runs in loop to MAX = number of TRIES
#               or until network responds successfully

NETWORK=0
COUNTER=0

# wait till next loop
SECONDS=2

#stop testing after N times
TRIES=300
# your most faithfull url to hit success all the time
URL=192.168.x.x

until [  $COUNTER -eq "$TRIES" ]
do
      let COUNTER=$COUNTER+1
      GETURL=`curl -vs -o /dev/null --max-time 1 --connect-timeout 1 $URL 2>&1 |grep -c Connected`
      if [ $GETURL -eq 1 ]
	then
	    NETWORK=1
	    if [ $NETWORK -eq 1 ]
	      then
		COUNTER=$TRIES
	      else
		NETWORK=0
	    fi
	else
            echo 'sleep'
	    sleep $SECONDS
      fi
done

if [ $NETWORK -eq 1 ]
    then
        mount -t cifs -o credentials=/root/.smb.cred,vers=3.0 //$URL/TKS_VM_IMG /TKS_VM_BACKUP
	  # do your mount stuff here
    else
        exit 1 # -bailing, had to many tries
fi

3. Script 실행 권한 추가

chmod +x /root/smb_mount_chk.sh

4. Crontab 등록

@reboot /root/smb_mount_chk.sh > /root/cron.log 2>&1

 

+ Recent posts