I was trying to debug some file access mssql-server process was trying to do with strace. It wasn’t quite working so I decided to let strace start the process:

sudo strace /opt/mssql/bin/sqlservr

Well, I was able to get the traces I needed, but as expected it ran the process as root.

When SQL Server starts, it will write some files under /var/opt/mssql, like log and other system files. Turns out that it does update some of those files on and changes the user and group file permissions to root right away.

Then when trying to start the service using systemd, I kept getting this error:

Access was denied setting up the persistent registry: \SystemRoot\licensing.hiv.

And that is because systemd starts the process as the mssql user, which now doesn’t have permissions to access the files it needs because only root can do it.

To fix it, I just had to update the permissions on that folder and subfolders:

sudo chown -R mssql:mssql /var/opt/mssql/* /var/opt/mssql/.system/	

Pay special attention to the .system folder, my first chown try was without it and took me a while to file out there was a hidden folder.

Hopefully this saves someone else some headache. No more strace for me today :)