-
Notifications
You must be signed in to change notification settings - Fork 0
/
automount-iscsi-nfs-nas.sh
executable file
·79 lines (64 loc) · 2.43 KB
/
automount-iscsi-nfs-nas.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/bin/bash
# Set variables for the iSCSI target and mount point
target="/dev/disk/by-id/scsi-36589cfc0000005c4396bf256e82d0db3-part1"
mount_point="/media/dankk/truenas-iscsi"
# Create the mount point directory if it doesn't exist
if [ ! -d "$mount_point" ]; then
sudo mkdir "$mount_point"
fi
# Login to iSCSI target with timeout
if timeout 20 sudo iscsiadm --mode node --targetname iqn.2005-10.org.freenas.ctl:truenas-iscsi --portal 192.168.160.50 --login; then
echo "iSCSI target login successful"
else
echo "iSCSI target login failed"
exit 1
fi
# Mount the iSCSI target to the mount point
sudo mount -t ext4 "$target" "$mount_point"
# Verify that the mount was successful
if [ $? -eq 0 ]; then
echo "iSCSI target mounted successfully to $mount_point"
else
echo "Failed to mount iSCSI target"
fi
# NFS Share 1 (from Truenas IP 192.168.160.50)
nfs_truenas_ip="192.168.160.50"
nfs_share="/mnt/zpool/deddspace-nas"
nfs_mount_point="/media/dankk/truenas-nfs"
nfs_options="rw,noatime,rsize=131072,wsize=131072,hard,intr,timeo=150,retrans=3"
# NFS Share 2 (from additional server IP 192.168.160.45)
nfs_additional_ip="192.168.160.45"
nfs_additional_share="/mnt/deddcloud"
nfs_additional_mount_point="/media/dankk/deddcloud"
nfs_additional_options="rw,noatime,rsize=131072,wsize=131072,hard,intr,timeo=150,retrans=3"
# SMB Share
smb_share="//192.168.160.50/deddspace-nas"
smb_mount_point="/media/dankk/truenas-smb"
smb_options="vers=3.0,credentials=/home/dankk/.smbcreds,iocharset=utf8,uid=1000,gid=1000,noperm"
# Function to mount a share
mount_share() {
share_type=$1
share=$2
mount_point=$3
options=$4
# Check if the mount point already exists
if [ ! -d "$mount_point" ]; then
echo "Creating mount point directory for $share_type..."
sudo mkdir -p "$mount_point"
fi
# Mount the share
echo "Mounting $share_type share..."
sudo mount -t $share_type -o "$options" "$share" "$mount_point"
# Check if the mount was successful
if [ $? -eq 0 ]; then
echo "$share_type share mounted successfully!"
else
echo "Failed to mount $share_type share."
fi
}
# Mount NFS share 1
mount_share "nfs" "$nfs_truenas_ip:$nfs_share" "$nfs_mount_point" "$nfs_options"
# Mount NFS share 2
mount_share "nfs" "$nfs_additional_ip:$nfs_additional_share" "$nfs_additional_mount_point" "$nfs_additional_options"
# Mount SMB share
mount_share "cifs" "$smb_share" "$smb_mount_point" "$smb_options"