Auto Mounting an Unpartitioned iSCSI LUN at System Startup
by Muhammad Sharfuddin
Audience
Administrators who know how to manually edit the /etc/fstab file, and create a file system(reiserfs, ext3) manually from the command line utility(mkfs.reiserfs / mkfs.ext3 etc), and also know how to configure the iSCSI initiator and target properly.
Pre-reqs
- an iSCSI target configured (in my example I have configured a SLES 10 SP2 x864).
- an iSCSI client(initiator) configured (in my example I have configured a SLES 10 SP2 i586 ).
- on iSCSI client the filesystem has been created on the iSCSI LUN (entire disk), without creating a partition on iSCSI LUN, i.e creating the file system onto the whole LUN (entire disk), instead of first creating a partition on the LUN, then creating a file system on the partition.
- on iSCSI client, in /etc/fstab proper information (line) has been written to automatically mount the iSCSI LUN on system startup/boot.
Problem
Unpartitioned iSCSI LUN(s) are not mounted automatically at system startup/boot.
Exception
I sometimes (very rare) found that unpartitioned iSCSI LUNs mounted automatically at system startup, but this is very rare.
Reason
Nothing obvious (it might be a bug in SLES 10 SP2), but one thing I can say for sure is that since using YaST, we can not make a file system on an unpartitioned disk(LUN), so it automatically means that such a setup is at least not supported.
Workaround/Solution
Either use partitioned LUNs, or, if you think that you should use the unpartitioned LUN (entire disk), then create a file ‘after.local’ under the “/etc/init.d/” directory, and append “mount -a” in the /etc/init.d/after.local.
Here is the example.
/etc/fstab of iSCSI-initiator(client)
cat /etc/fstab |grep iscsi
/dev/disk/by-path/ip-192.168.0.1:3260-iscsi-iqn.2009-04.nds.gw:2c59a403-7e5c-4ae0-84d6-103a8be06200-lun-0 /tdata reiserfs auto,hotplug 1 2
Here you can see, I am mounting the unpartitioned LUN(…:2c59a403-7e5c-4ae0-84d6-103a8be06200-lun-0), and not the partitioned LUN(:2c59a403-7e5c-4ae0-84d6-103a8be06200-lun-0-part1)
Now, as I said earlier, that this iSCSI LUN won’t mount automatically at system startup, that’s why we will use /etc/init.d/after.local. Here is the output of the ‘/etc/init.d/after.local’ that mounts it automatically at system startup
cat /etc/init.d/after.local
#!/bin/sh mount -a
Now, reboot your iSCSI client machine, and you will find that the iSCSI LUN(s) are automatically mounted successfully at system startup.
But, I still don’t recommend the above approach/method to mount the iSCSI LUNs (either partitioned or unpartitioned)… because when you shutdown your machine (or whenever you stop the iSCSI-initiator service(/etc/init.d/open-iscsi stop)) you will notice/find the following message on your console:
done
The above FATAL message is obvious, because during the system shutdown process, the iSCSI-initiator(client) service stops very early, while all of the mounted file systems (including the iSCSI LUNs) are unmounted in the very last stage of shutdown process. We always see the above FATAL error whenever the system is going to shutdown while iSCSI LUNs (partitioned or unpartitioned(entire disk)) are mounted.
Preferred solution for mounting partitioned and unpartitioned (entire disk) iSCSI LUN(s)
To avoid the “FATAL: Module iscsi_tcp is in use” message, and to mount the unpartitioned iSCSI LUNs (entire disk) automatically, I preferred to use a script.
Here is the step by step method we use to mount the iSCSI LUNs.
To my iSCSI-client, two LUNs are available.
# lsscsi |grep IET [3:0:0:0] disk IET VIRTUAL-DISK 0 /dev/sdc [4:0:0:0] disk IET VIRTUAL-DISK 0 /dev/sdd # ls -l /dev/disk/by-path/ |grep ip lrwxrwxrwx 1 root root 9 Apr 22 13:56 ip-192.168.0.1:3260-iscsi-iqn.2009-04.nds.gw:2c59a403-7e5c-4ae0-84d6-103a8be06200-lun-0 -> ../../sdc lrwxrwxrwx 1 root root 9 Apr 22 13:56 ip-192.168.0.1:3260-iscsi-iqn.2009-04.nds.gw:4b4e8cf3-baaa-44e5-975a-af9376b79e7e-lun-0 -> ../../sdd
In this example we will use the entire /dev/sdc(entire disk), and create a partition on /dev/sdd, i.e we will create file system on /dev/sdd1.
First we create a file system on /dev/sdc.
# mkreiserfs -f /dev/sdc
Then create a partition /dev/sdd1 and make a file system on it.
Append the following lines in /etc/fstab:
cat /etc/fstab |grep ip /dev/disk/by-path/ip-192.168.0.1:3260-iscsi-iqn.2009-04.nds.gw:2c59a403-7e5c-4ae0-84d6-103a8be06200-lun-0 /edata reiserfs hotplug 1 2 /dev/disk/by-path/ip-192.168.0.1:3260-iscsi-iqn.2009-04.nds.gw:4b4e8cf3-baaa-44e5-975a-af9376b79e7e-lun-0-part1 /pdata reiserfs hotplug,noauto 1 2
where
/dev/disk/by-path/ip-192.168.0.1:3260-iscsi-iqn.2009-04.nds.gw:2c59a403-7e5c-4ae0-84d6-103a8be06200-lun-0 is an entire disk(unpartitioned LUN)
/dev/disk/by-path/ip-192.168.0.1:3260-iscsi-iqn.2009-04.nds.gw:4b4e8cf3-baaa-44e5-975a-af9376b79e7e-lun-0-part1 is the partition.
since
/dev/sdd1(/dev/disk/by-path/ip-192.168.0.1:3260-iscsi-iqn.2009-04.nds.gw:4b4e8cf3-baaa-44e5-975a-af9376b79e7e-lun-0-part1) is the partition, it will be automatically mounted at the system startup, and since I want to avoid the “FATAL: Module iscsi_tcp is in use” message and also want to mount all of the iSCSI LUNs(either partitioned or unpartitioned) via a script, I used the noauto option, so that this LUN won’t mount automatically.
Now after making the file system and making proper editing in /etc/fstab, here is the runlevel script that mounts all of the iSCSI LUNs, and also unmount the iSCSI LUNs before the iSCSI-initiator service stop (i. no more “FATAL: Module iscsi_tcp is in use” message).
cat /etc/init.d/mount_iscsi_luns
#!/bin/bash # # /etc/init.d/mount_iscsi_luns # # ### BEGIN INIT INFO # Provides: mount_iscsi_luns # Required-Start: iscsi # Should-Start: # Required-Stop: # Should-Stop: # Default-Start: 3 5 # Default-Stop: 0 1 2 6 # Short-Description: mounts the iSCSI LUNs ### END INIT INFO . /etc/rc.status # Reset status of this service rc_reset case "$1" in start) sleep 4 echo -e "\nStart mounting the iSCSI LUN(s) \n" for i in `cat /etc/fstab | grep ^"/dev/disk/by-path/ip-" | awk {'print $2'}` do cat /proc/mounts | grep "$i" > /dev/null if [ "$?" == "0" ] then echo -e "\n $i already mounted ... skipping, and moving to next task" continue else echo -e "\n Trying to mount $i \n" /bin/mount "$i" if [ "$?" == "0" ] then cat /proc/mounts | grep "$i" ; echo -e " ... $i mounted Successfully \n" else echo -e "Unable to mount $i \n" fi fi done # Remember status and be verbose rc_status -v ;; stop) echo -n " Unmounting the iSCSI LUN(s) " for i in `cat /proc/mounts | grep "/dev/disk/by-path/ip-" | awk {'print $2'}` do /bin/umount $i if [ "$?" == "0" ] then echo -e "\n iSCSI LUN($i) unmounted successfully" fi done # Remember status and be verbose rc_status -v ;; restart) ## Stop the service and regardless of whether it was ## running or not, start it again. $0 stop $0 start # Remember status and be quiet rc_status ;; status) echo -n "Checking mount status of iSCSI LUN(s) " cat /proc/mounts | grep "/dev/disk/by-path/ip-" # "status" option and adapts its messages accordingly. rc_status -v ;; *) echo "Usage: $0 {start|stop|status|restart}" exit 1 ;; esac rc_exit
Make this script executeable, via:
chmod +x /etc/init.d/mount_iscsi_luns
Make this script automatically run on system startup:
insserv mount_iscsi_luns
Now reboot your machine to check that both of the iSCSI LUNs are mounted, and you will also note that now you wont get “FATAL: Module iscsi_tcp is in use” message on system shutdown.
Done 😉
No comments yet