Setting up an iSCSI Target on a Synology NAS
This project was to enable me to migrate my test Virtual machines from their default location of /var/lib/libvirt/images to storage that was not local to the server. My server has limited physical storage capabilities compared with the 10 TBs of storage on the NAS. There are probably a few different ways I could have mounted a volume, however, I went with iSCSI because I was learning it as one of my RHCE objectives. Next is how the process of setting up an iSCSI Target on a Synology NAS.
Setting up the iSCSI Target with Synology
The first step is to get our Target configured. With the GUI interface, this process is quick and easy.
- Login to your Synology NAS
- Open Storage Manager
- Choose iSCSI Target
- Choose Create
- You then will give your target a name. I left mine as Target-1.
- Next is the
IQN: The default comes up with iqn.2000.01.com.synology: ….
- I changed mine to match the naming standards, which is the current year and month, plus your domain (in reverse).
- Mine ended up being iqn.2018.03.com.therootuser.den:SynologyNAS…
We then will continue by selecting Next, if you wish to use CHAP, fill in the appropriate information.
You have the option to create a new iSCSCI LUN or Map existing iSCSI LUNs. You can see the one I already created, but chances are you’ll not have one already, so pick create a new iSCSI LUN and then click Next to continue.
Our next option is to choose the LUN type. I went with iSCSI LUN (File-Level)
It shows that this type of iSCSI LUN provides the flexibility of dynamic capacity management with Thin Provisioning.
When you are happy with your choice, you can click on Next to continue.
Finally, we set up how we want the LUN to be configured, such as the LUN name, if it will be Thin Provisioned, which volume we are going to store it on within the NAS, and how large the LUN will be. I went with 500 GB for the example.
Once you are happy with everything you can hit next and you’ll see a summary of your choices, if all looks as it should you can press Apply and your iSCSI target will be configured and you can then move on to the next phase, of setting up the iSCSI connection on the RHEL server.
Setting up the iSCSI connection on a RHEL Server
We need to first ensure we have all the required packages. Do so with a yum command:
# yum install iscsi-initiator-utils lsscsi
We need to discover our target, so we need to run the command:
# iscsiadm -m discovery -t sendtargets -p 192.168.1.68 --discover
The portal IP is the IP of your Synology NAS (or any server you are running your iSCSI Target on).
Next, we can issue the command:
# iscsiadm -m node --targetname iqn.2018-03.com.therootuser.den:SynologyNAS.Target-1.96a0fad3b1 --portal 192.168.1.68 --login
The iSCSI device should now be available. You can verify by typing lsscsi and then to see all disks:
# iscsiadm -m session -P3
We will need to put a file system on our device now, so run lsblk from the command line to see your devices. For my system the new device was on /dev/sdb. I went with XFS for my file system as I wasn’t going to have multiple systems trying to write to it at the same time.
# mkfs -t xfs /dev/sdb
# blkid /dev/sdb
The above command will give you the UUID number of the device which you can then use in fstab.
# vim /etc/fstab
Add the UUID number with the options of :
/SynologyNAS xfs _netdev 0 2
The /SynologyNAS can be whatever you wish, just create it in a location on your file system as it will be the mount point of the iSCSI device. For instance, as I wanted my mount point to be called SynlogyNAS, I did a mkdir /SynlogyNAS to create the mount point folder.
When done, save fstab and then run:
# mount -a
Assuming no errors came up you are ready, you can verify with mount to show all mounted devices. If you see an error, go back and check your fstab file and correct the error.
So if all you wanted out of this is how to get iSCSI going, you are done. Throw some files on your new mount and have fun. I, however, had a purpose for this, which was to relocate my VMs. So the next step, moving and reconfiguring the KVM VMs on RHEL 7.4.
Migrating the VMs to iSCSI
I currently had 5 VMs that were local to the RHEL server that needed to be moved. So the first step is to power all the VMs down.
I then made a directory on the iSCSI mount, mkdir /images (this was within /SynologyNAS)
Then move your VMs over with:
# mv /var/lib/libvirt/images/* /SynologyNAS/images
Depending on the size of your VMs this is going to take a minute or so to complete.
Now that they are moved over you’ll need to edit those configuration files of each of the servers, otherwise, they won’t start as they are pointing to the old location.
# virsh edit server1
Run this command and it will open the editor and you can change the VM location from the old to the new. You’ll want to do this for each server. Once you are done you can issue the command:
# systemctl restart libvirtd
From there close out KVM if it’s still running and then start it again from the command line
You can then start each of your VMs back up and they should load without issue. Our final step though is to change the storage default location for VMs with KVM so they will go to your new iSCSI device.
Changing default VM locations in KVM
First, just open Connection Details within KVM, then go to Storage.
I selected default, hit the X to stop the pool, then selected to delete the pool completely.
Then hit the plus to create a new pool, call it default, choose dir: filesystem Directory and choose forward.
The next option will be the path of the pool, which for me was /SynologyNAS/images, then click on Finish.
From there I did a restarted the service one more time for good measure and attempted to create a new VM. The location of the VM showed it was going to the iSCSI device so I was pleased.
So nothing really too difficult here, just takes some time to get it all set up and working correctly.
If you have any questions or comments, please feel free to reach out to me.
Ivan Windon – RHCSA