Setting up iSCSI vmkernel switches and portgroups via CLI

With ESXi 5.0 you can do this via the GUI but I much prefer just using the CLI to create switches and portgroups. To start with you cant rename a vSwitch (or enter a custom name) via the GUI. This is quite annoying if you need to keep your vSwitch naming policy correct and of course vMotion requires all switches to be named identically.

Note: This configuration is for a VSS switch.

In this example, I will be using a basic set up of 3 pNICS and 3 VMKKernel Portgroups in a 1:1 to manner which will be connecting to an iSCSI SAN

1) Create a vSwitch called “vSwitch2”
esxcfg-vswitch -a vSwitch2

2) Enable Jumbo Frames on the vSwitch
esxcfg-vswitch –m 9000 vSwitch2
To verify the the switch settings run
esxcfg-vswitch –l

You can also check this via the GUI (press refresh in the configuation -> networking of the host)

3) Create VMKernel Portgroups

esxcfg-vswitch -A iSCSI1 vSwitch2
esxcfg-vswitch -A iSCSI2 vSwitch2
esxcfg-vswitch -A iSCSI3 vSwitch2

4) Configure IP address, netmask and Jumbo Frames for watch porgroup
esxcfg-vmknic -a -i 192.168.70.31 -n 255.255.255.0 iSCSI1 -m 9000
esxcfg-vmknic -a -i 192.168.70.32 -n 255.255.255.0 iSCSI2 -m 9000
esxcfg-vmknic -a -i 192.168.70.33 -n 255.255.255.0 iSCSI3 -m 9000

Verify the IP addressing/Jumbo Frames
esxcfg-vmknic –l

5) Assign the network adapters (Best practice to use a pNIC from different network cards – just incase one fails)
esxcfg-vswitch -L vmnic3 vSwitch2
esxcfg-vswitch -L vmnic6 vSwitch2
esxcfg-vswitch -L vmnic10 vSwitch2

6) We now need to remove the required pNICs from the VMkernel ports so that we only have 1 vmnic in each uplink

esxcfg-vswitch –p iSCSI1 –N vmnic6 vSwitch2
esxcfg-vswitch –p iSCSI1 –N vmnic10 vSwitch2
esxcfg-vswitch –p iSCSI2 –N vmnic3 vSwitch2
esxcfg-vswitch –p iSCSI2 –N vmnic10 vSwitch2
esxcfg-vswitch –p iSCSI3 –N vmnic3 vSwitch2
esxcfg-vswitch –p iSCSI3 –N vmnic6 vSwitch2

 

This will ensure :
iSCSI1 is mapped to vmnic3
iSCSI2 is mapped to vmnic6
iSCSI3 is mapped to vmnic10
on a 1:1 basis

Now thats done, I normally just set the iCSI binding via the GUI (only in ESXI5.0 +) but here are the steps if you want to go CLI all the way!

7) Enable iSCSI initiator (you should be able to get the vmhba number from the output. You’ll need this in the next step. Or you can just grab it from the GUI)
esxcfg-scsidevs –a

 

8) Bind you VMks to iSCSI initatior
esxcli swiscsi nic add –n vmk1 –d vmhba33
esxcli swiscsi nic add –n vmk2 –d vmhba33
esxcli swiscsi nic add –n vmk3 –d vmhba33

verify all vmks are bound to the vmhba
esxcli swiscsi nic list –d vmhba33

You can then scan for datastores again via the GUI.

 

Note: I should really script this for future new hosts but I never get around to it!