2

I want to place my databases in another directory, so I can store them in an ESB (elastic block storage, just a fancy name for a virtualized harddisk) together with my web-apps and other persistent data.

I have tried to walk through a tutorial at http://crashmag.net/change-the-default-mysql-data-directory-with-selinux-enabled.

Everything seems fine until I type this command:

# semanage fcontext -a -t mysqld_db_t "/srv/mysql(/.*)?"

Then the command fails and tells me that mysqld_db_t is an invalid SELinux context even if the default MySQL data directory is labelled with this context. I am running Fedora 15 on Virtualbox (behaves like an ordinary x86-compatible box) and Amazon EC2 (based on Xen) so the tutorial should be compatible.

It is also worth to mention that turning off SELinux globally or just for the MySQL process is not an option, because such a solution will decrease the security of the system if a hacker gains access to the system via the MySQL server. I have never seen this problem before I changed to the Redhat/Fedora architecture, so it could be a distribution specific issue.

Any help is highly appreciated

1 Answer 1

2

Have you tried specifying the full context name rather than just the *_t part?

Is there some reason why you can't mount your block device under /var/lib/mysql so that you don't need to update labeling? Maybe using bind mounts or symlinks? mount -o bind /srv/mysql /var/lib/mysql for example.

I tried reproducing this behavior and was not able to, here is what I did.

$ sudo semanage fcontext -a -t mysqld_db_t "/mnt/foo(/.*)?"
$ sudo restorecon -R /mnt/foo
$ ls -Z /mnt/foo/
drwxr-xr-x. root root system_u:object_r:mysqld_db_t:s0 bar
drwxr-xr-x. root root system_u:object_r:mysqld_db_t:s0 baz
-rw-r--r--. root root system_u:object_r:mysqld_db_t:s0 quux
2
  • It is not possible to symlink the two directories because of SELinux. SELinux will only allow you to access the symlink but not its destination. I can't mount my block device under /var/lib/mysql because it is already mounted it under /srv where I have my other files. Jun 30, 2011 at 13:36
  • 1
    You can totally mount the filesystem both under /srv and /var/lib/mysql at the same time using bind mounts as I described earlier.
    – mtinberg
    Jul 5, 2011 at 20:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .