First, you have to change your udev rules. There is a rule that ejects the
drive when the button is pressed, and this rule causes problems.
Open /lib/udev/rules.d/60-cdrom_id.rules in a text editor (as root) and
comment out the line with DISK_EJECT_REQUEST by putting a hash at the
beginning of the line.
Then, to lock the drive:
$ eject -i 1
And to unlock:
$ eject -i 0