[CentOS] SEcontext setting failure on an external harddisk

Thu Oct 8 19:21:39 UTC 2020
H <agents at meddatainc.com>

I tried moving a PosgreSQL database to an external harddisk due to lack of space on the main harddisks. Not the ideal solution of course but it should work. However, on CentOS 7 the external harddisk is mounted under /run/media and the user. I copied the postgresql database directory and made sure it is owned recursively by postgres, changed the necessary settings in both the systemd unit and the conf file.

After that, updating the selinux contexts is required but that fails on the external disk due to a conflict which I understand is due it is under /run/media and the user. semanage fcontext kicked back an error message suggesting I try setting it for /var/run/media etc instead which works but restorecon -Rv for that directory fails to set the context which I can check with ls -lZ.

Does anyone know how I can get around this? Is there an inherent conflict because it is mounted under a specific user despite the postgresql directory is owned by postgres? If so, should I mount it under eg /opt/ instead? Would that make a difference?

Or, can I "force" a new context on the postgres directory tree some other way?