11

I am running Oracle Linux 7 (CentOS / RedHat based distro) in a VirtualBox VM on a Mac with OS X 10.10. I have a Synology Diskstation serving as an iscsi target.

I have successfully connected to the Synology, partitioned the disk and created a filesystem. It is refernced as /dev/sdb and the partition is /dev/sdb1. Now, what I would like to do is create a mount point so I can easily access it:

    mount /dev/sdb1 /mnt/www

That command works. But obviously, it isn't persistent across a reboot. No worries...into /etc/fstab we go.

First, I got the UUID of the partition to ensure I am always using the correct device:

    blkid /dev/sdb1

Result:
    /dev/sdb1: UUID="723eb295-8fe0-409f-a75f-a26eede8904f" TYPE="ext3"

Now, I inserted the following line into my /etc/fstab

    UUID=723eb295-8fe0-409f-a75f-a26eede8904f /mnt/www    ext3   defaults   0 0

Upon reboot, the system crashes and goes into maintenance mode. If I remove the line I inserted, all works again. However, I am following the instructions verbatim from Oracle-Base

I know I am missing something..can anyone point me in the right direction?

Allan
  • 1,010
  • 3
  • 15
  • 31
  • "the system crashes and goes into maintenance mode" ... surely it gives some error before dumping you into a shell? Please include the error messages in your question. If necessary, take a picture of the screen with a cell phone camera and include that. – derobert Apr 08 '15 at 21:16

2 Answers2

26

Just change the parameter "defaults" by "_netdev", like this:

UUID=723eb295-8fe0-409f-a75f-a26eede8904f /mnt/www ext3 _netdev 0 0

This way the mount point will be mounted only after the network start correctly.

  • 1
    That worked perfectly. I was wondering if the problem was that network wasn't "ready" when the mount was attempted, but I couldn't make heads nor tails in the logs. Most everything that was related to it said "failed" which was kinda obvious ;-) – Allan Apr 08 '15 at 21:51
0

Intro:

This is a SystemD alternative to mount an iSCSI drive at boot.

Mounting an iSCSI disk at boot is a (2) step process:

  1. The LUN must be connected by the host

  2. And then mounted to a point on the local filesystem.

The scripts- developed using Ubuntu 20.04 LTS- pasted in below answer I've made available to save others the donkey work of configuring an iSCI mount; it is indeed fiddly, tedious business. They are known to work correctly and produce consistent, correct results as of the date of this posting.

To download the scripts directly to your host mounting your iSCSI drive:

git clone https://github.com/f1linux/iscsi-automount.git

Please note that there are some Debian-specific commands in the full scripts in the Github repo- ie: dpkg. The abridged scripts below are distribution in-specific and should work on any distro using SystemD.

Pre-Requisites:

  1. open-iscsi installed and its' configuration files /etc/iscsi/iscsid.conf & initiatorname.iscsi configured.

  2. Manually test the connections using the iscsiadm command before running the scripts.

The (2) Scripts:

config-iscsi-storage.sh: Automatically connects the LUN at boot by creating a SystemD service called connect-luns.service. This script must be executed FIRST. After the LUN is connected you must next partition and laydown a filesystem on it before running the next script.

config-iscsi-storage-mounts.sh: Automatically mounts the connected, partitioned iSCSI disk with a filesystem to a mount point on the local filesystem as a SystemD mount at boot.

The Scripts:

NOTE: I've removed the echo'ed feedback, instructions and other debris from the scripts to aid ease of reading for you to assess their operation.

config-iscsi-storage.sh

#######   SET VARIABLES   #######

# Host exposing the LUNs:
STORAGEIP=''

# Get this value from the storage host exposing the LUN:
IQNTARGET=''


if [ ! -d /root/scripts ]; then
    mkdir /root/scripts
fi


if [ ! -f /root/scripts/connect-luns.sh ]; then 

cat <<EOF> /root/scripts/connect-luns.sh
#!/bin/bash

# Use of "sendtargets" necessary to wake up the Synology Storage Host:
iscsiadm -m discovery -t sendtargets -p $STORAGEIP

# The iscsiadm command to CONNECT the LUN lives in this file
iscsiadm -m node -T $IQNTARGET -p $STORAGEIP:3260 --login
EOF

chmod 700 /root/scripts/connect-luns.sh
chown root:root /root/scripts/connect-luns.sh

else
    echo "iscsiadm -m node -T $IQNTARGET -p $STORAGEIP:3260 --login" >> /root/scripts/connect-luns.sh
fi

if [ ! -f /root/scripts/disconnect-luns.sh ]; then

cat <<EOF> /root/scripts/disconnect-luns.sh
#!/bin/bash

# The iscsiadm command to DISCONNECT the LUN lives in this file
iscsiadm -m node -T $IQNTARGET -p $STORAGEIP:3260, 1 -u
EOF

chmod 700 /root/scripts/disconnect-luns.sh
chown root:root /root/scripts/disconnect-luns.sh

else
    echo "iscsiadm -m node -T $IQNTARGET -p $STORAGEIP:3260, 1 -u" >> /root/scripts/disconnect-luns.sh
fi

if [ ! -f /etc/systemd/system/connect-luns.service ]; then

cat <<EOF> /etc/systemd/system/connect-luns.service
[Unit]
Description=Connect iSCSI LUN
Documentation=https://github.com/f1linux/iscsi-automount
Requires=network-online.target
DefaultDependencies=no

[Service]
User=root
Group=root
Type=oneshot
RemainAfterExit=true
ExecStart=/root/scripts/connect-luns.sh "Connecting LUN"
StandardOutput=journal

[Install]
WantedBy=multi-user.target

EOF

chmod 644 /etc/systemd/system/connect-luns.service

systemctl daemon-reload
systemctl enable connect-luns.service
systemctl start connect-luns.service

fi

iscsiadm -m discovery -t sendtargets -p $STORAGEIP
fdisk -l

echo
echo "$(tput setaf 5)#######   NEXT STEPS:   #######$(tput sgr 0)"
echo
echo 'STEP 1: Find the iSCSCI disk in the output above and then partition it,'
echo '       ie: fdisk /dev/sdX where "X" is the letter of the iSCSI disk'
echo
echo 'STEP 2: Format the iSCSI disk with a filesystem'
echo '       ie: mkfs.ext4 /dev/sdX1 where the iSCSI disk is /dev/sdX'
echo
echo 'STEP 3: Execute script config-iscsi-storage-mounts.sh to configure auto-mounting the iSCSI disk'
echo '        to configure mounting the newly formatted iSCSI disks on boot'
echo

config-iscsi-storage-mounts.sh

#######   SET VARIABLES   #######

# Use 'fdisk -l' to identify the iSCSI disk
ISCSIDEVICE='sda1'

# The script will create the folder with the name supplied in "ISCSIDISKMOUNTFOLDER" variable
# in the path /mnt. Therefore do NOT manually create the folder the LUN is mounted to.
#
# NAMING REQUIREMENTS: Do NOT specify a folder name with a hypen in folder name that the LUN will be mounted on.
#         This will cause the SystemD mount to fail.
#         ie: "logsproxy" is a valid name and WILL work but "logs-proxy" will NOT and cause the mount to fail.
#
ISCSIDISKMOUNTFOLDER='logs'

# Filesystem type the LUN was formatted for which is supplied in the 'Type' field below
FILESYSTEM='ext4'

# SystemD mount file comment:
# Below variable sets "Description" field in the file that starts the mount.
MOUNTDESCRIPTION='Persistent Data living on iSCSI LUN'

## NOTE: Most settings below show work out of the box

if [ ! -d /mnt/$ISCSIDISKMOUNTFOLDER ]; then
    mkdir /mnt/$ISCSIDISKMOUNTFOLDER
    chmod 770 /mnt/$ISCSIDISKMOUNTFOLDER
fi

if [ ! -f /etc/systemd/system/mnt-$ISCSIDISKMOUNTFOLDER.mount ]; then

cat <<EOF> /etc/systemd/system/mnt-$ISCSIDISKMOUNTFOLDER.mount
[Unit]
Description=$MOUNTDESCRIPTION
After=connect-luns.service
DefaultDependencies=no

[Mount]
What=/dev/disk/by-uuid/$(ls -al /dev/disk/by-uuid | grep $ISCSIDEVICE | awk '{print $9}')
Where=/mnt/$ISCSIDISKMOUNTFOLDER
Type=$FILESYSTEM
StandardOutput=journal

[Install]
WantedBy=multi-user.target

EOF

chown root:root /etc/systemd/system/mnt-$ISCSIDISKMOUNTFOLDER.mount
chmod 644 /etc/systemd/system/mnt-$ISCSIDISKMOUNTFOLDER.mount

systemctl daemon-reload
systemctl enable mnt-$ISCSIDISKMOUNTFOLDER.mount
sudo systemctl start mnt-$ISCSIDISKMOUNTFOLDER.mount

else
    echo "'/etc/systemd/system/mnt-$ISCSIDISKMOUNTFOLDER.mount' already exists"
fi

echo
echo "$(tput setaf 5)#######   NEXT STEPS:   #######$(tput sgr 0)"
echo
echo 'Reboot and verify that the iscsi disk automatically mounted on boot using the "mount" command'
echo

Conclusion:

As you can see, connecting an iSCSI disk is fiddily work. Hope this saved you some grunt work-

F1Linux
  • 2,286
  • 1
  • 16
  • 28