Having trouble with device mapping at reboot (iscsi device mapping can change at every reboot) ?
Use UUID (Universal Unique Identifier)!
Say you have two iSCSI targets on your Linux. They show, for example, as disks /dev/sdc and /dev/sdd the first time you discover them (with iscsiadm) :
# sfdisk -s /dev/sda: 20971520 /dev/sdb: 104857600 /dev/sdc: 2122317824 /dev/sdd: 2122317824
Using fdisk or parted you will create the devices /dev/sdc1 and /dev/sdd1 :
# sfdisk -l /dev/sdc Disk /dev/sdc: 264216 cylinders, 255 heads, 63 sectors/track Units = cylinders of 8225280 bytes, blocks of 1024 bytes, counting from 0 Device Boot Start End #cyls #blocks Id System /dev/sdc1 0+ 264215 264216- 2122314988+ 83 Linux /dev/sdc2 0 - 0 0 0 Empty /dev/sdc3 0 - 0 0 0 Empty /dev/sdc4 0 - 0 0 0 Empty Disk /dev/sdd: 264216 cylinders, 255 heads, 63 sectors/track Units = cylinders of 8225280 bytes, blocks of 1024 bytes, counting from 0 Device Boot Start End #cyls #blocks Id System /dev/sdd1 0+ 264215 264216- 2122314988+ 83 Linux /dev/sdd2 0 - 0 0 0 Empty /dev/sdd3 0 - 0 0 0 Empty /dev/sdd4 0 - 0 0 0 Empty
Then you can create the two file systems and mount them:
# mkfs -t ext3 /dev/sdc1 # mount -t ext3 /dev/sdc1 /VLS1 # mkfs -t ext3 /dev/sdd1 # mount -t ext3 /dev/sdd1 /VLS2
You need to add the file system in /etc/fstab in order to automatically mount them at startup.
However let’s first reboot the system to check if everything is alright.
At you surprise after reboot you can’t mount /dev/sdc1 and /dev/sdd1.
If you check with sfdisk –l you can see that /dev/sdc1 and /dev/sdd1 still exist but /dev/sde1 and /dev/sdf1 appeared out of nowhere …
Actually, your two iSCSI disks are now /dev/sde1 et sdf1 (but sdc1 can also be sdd1 at the new reboot and so on …) thanks to the magic of Linux’s dynamic mapping of devices (udev).
That’s where UUID is your best friend !
UUID (Universal Unique Identifier) enable to uniquely identify you device. UUID is not changing at every reboot the way device files (/dev/sdX ou /dev/hdX …) are.
For instance you may know MAC addresses are unique identifier for network cards, well MAC addresses are UUID (version 1).
So if you can get the UUID for your two file systems your problem is solved.
On linux you can get a file system UUIDs with command “blkid” (“vol_id” command can sometimes be used for old Linux versions).
blkid can be found into util-linux package.
# blkid /dev/sdc1 /dev/sdc1: UUID="01066206-c67c-47d1-83a9-d61791fff943" SEC_TYPE="ext2" TYPE="ext3" # blkid /dev/sdd1 /dev/sdd1 UUID="cea28516-ca98-4ac4-954f-6710b6ac36c7" SEC_TYPE="ext2" TYPE="ext3"
Then add the following lines to /etc/fstab :
UUID=4a496f92-6840-4736-a0d5-5b9916113835 /VLS1 ext3 _netdev 0 0 UUID=cab5e3ec-4797-4227-98e8-e9bca3c3f766 /VLS2 ext3 _netdev 0 0
“_netdev” substitute to the usual “default” because network needs to be up before iSCSI filesystems mount.
Now your iSCSI file systems will be automatically mounted after every reboot (well, as long as your iSCSI server is up ?).