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? Thanks!
Jonathan Billings
2020-Oct-08 21:10 UTC
[CentOS] SEcontext setting failure on an external harddisk
On Oct 8, 2020, at 15:22, H <agents at meddatainc.com> wrote:> > ?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.I don?t believe that the volume will be mounted on boot in /run/media, that is for storage mounted by a user logged at the console. It would make more sense to set up a systemd .mount and .automount unit for the device and mount point (someplace outside of /run, such as /srv/mountpointname). Then set up the labels correctly. You need to use a file system that supports extended attribute if you want it to work with selinux, so XFS or ext4. -- Jonathan Billings
On 10/08/2020 11:10 PM, Jonathan Billings wrote:> On Oct 8, 2020, at 15:22, H <agents at meddatainc.com> wrote: >> ?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. > I don?t believe that the volume will be mounted on boot in /run/media, that is for storage mounted by a user logged at the console. > > It would make more sense to set up a systemd .mount and .automount unit for the device and mount point (someplace outside of /run, such as /srv/mountpointname). Then set up the labels correctly. > > You need to use a file system that supports extended attribute if you want it to work with selinux, so XFS or ext4. > > -- > Jonathan Billings > _______________________________________________ > CentOS mailing list > CentOS at centos.org > https://lists.centos.org/mailman/listinfo/centosYou are correct, I mounted the external harddisk as a user. The harddisk is formatted xfs so it supports labels. However, I was not planning to automount this disk every time which of course would mean postgresql would fail without the harddisk. It might be better to use the smaller existing space on the existing harddisk until I buy a larger internal harddisk which would automount and then move postgresql to that. Thank you for your reply.