Note: This bug is displayed in read-only format because the product is no longer active in Red Hat Bugzilla.
RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.

Bug 1049924

Summary: Problem with moving mysql to another partition
Product: Red Hat Enterprise Linux 6 Reporter: Mikhail <mikhail.v.gavrilov>
Component: selinux-policyAssignee: Miroslav Grepl <mgrepl>
Status: CLOSED NOTABUG QA Contact: BaseOS QE Security Team <qe-baseos-security>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 6.5CC: dwalsh, lvrabec, mmalik
Target Milestone: rcKeywords: Reopened
Target Release: ---   
Hardware: Unspecified   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2014-06-24 10:18:42 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Attachments:
Description Flags
audit.log none

Description Mikhail 2014-01-08 13:48:27 UTC
Created attachment 847153 [details]
audit.log

Description of problem:
I am use Amazon EC2 VDS root partition have size 5Gb, so I add another disk for my data. This is disk mounted in /mnt
# mount 
/dev/xvda1 on / type ext4 (rw)
none on /proc type proc (rw)
none on /sys type sysfs (rw)
none on /dev/pts type devpts (rw,gid=5,mode=620)
none on /dev/shm type tmpfs (rw,rootcontext="system_u:object_r:tmpfs_t:s0")
/dev/xvdb on /mnt type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)

I am stop MariaDB and move /var/lib/mysql to /mnt/mysql and create symbolic link
# ln -s /mnt/mysql /var/lib/mysql
after it I run restorecon -vR /

But after moving mysql data folder SELinux interrupt running MariaDB

[root@ip-172-31-5-20 ~]# ls -Zla /mnt/
total 40
drwxr-xr-x.  7 system_u:object_r:mnt_t:s0       root   root    4096 Янв  8 11:09 .
dr-xr-xr-x. 25 system_u:object_r:root_t:s0      root   root    4096 Янв  8 12:36 ..
drwxr-xr-x.  2 system_u:object_r:mnt_t:s0       crmdev crmdev  4096 Янв  7 22:17 logs
drwx------.  2 system_u:object_r:mnt_t:s0       root   root   16384 Янв  7 21:57 lost+found
drwxr-xr-x.  6 system_u:object_r:mnt_t:s0       mysql  mysql   4096 Янв  8 12:35 mysql
drwxr-xr-x.  8 system_u:object_r:mnt_t:s0       crmdev crmdev  4096 Янв  7 19:56 rpmbuild
drwxr-xr-x.  3 system_u:object_r:mnt_t:s0       crmdev crmdev  4096 Янв  7 22:22 www
[root@ip-172-31-5-20 ~]# ls -Zlad /var/lib/mysql/
drwxr-xr-x. 6 system_u:object_r:mnt_t:s0       mysql mysql 4096 Янв  8 12:35 /var/lib/mysql/
[root@ip-172-31-5-20 ~]# setenforce 1
[root@ip-172-31-5-20 ~]# service mysql restart
MySQL server PID file could not be found!                  [FAILED]
Starting MySQL.The server quit without updating PID file (/[FAILED]mysql/ip-172-31-5-20.eu-west-1.compute.internal.pid).
[root@ip-172-31-5-20 ~]# setenforce 0
[root@ip-172-31-5-20 ~]# service mysql restart
MySQL server PID file could not be found!                  [FAILED]
Starting MySQL...                                          [  OK  ]
[root@ip-172-31-5-20 ~]# semodule -DB
[root@ip-172-31-5-20 ~]# service mysql restart
Shutting down MySQL.                                       [  OK  ]
Starting MySQL..                                           [  OK  ]
[root@ip-172-31-5-20 ~]# ausearch -m avc,user_avc -ts recent > /tmp/audit.log
[root@ip-172-31-5-20 ~]# semodule -B

I am attach audit.log here

Comment 2 Mikhail 2014-01-08 15:26:10 UTC
# ls -lZ /mnt/mysql
-rw-rw----. mysql mysql system_u:object_r:file_t:s0      aria_log.00000001
-rw-rw----. mysql mysql system_u:object_r:file_t:s0      aria_log_control
drwx------. mysql mysql system_u:object_r:file_t:s0      bankdev
-rw-rw----. mysql mysql system_u:object_r:file_t:s0      ibdata1
-rw-rw----. mysql mysql system_u:object_r:file_t:s0      ib_logfile0
-rw-rw----. mysql mysql system_u:object_r:file_t:s0      ib_logfile1
-rw-r-----. mysql root  system_u:object_r:file_t:s0      ip-172-31-5-20.eu-west-1.compute.internal.err
-rw-rw----. mysql mysql unconfined_u:object_r:mnt_t:s0   ip-172-31-5-20.eu-west-1.compute.internal.pid
drwx--x--x. mysql mysql system_u:object_r:file_t:s0      mysql
srwxrwxrwx. mysql mysql unconfined_u:object_r:mnt_t:s0   mysql.sock
drwx------. mysql mysql system_u:object_r:file_t:s0      performance_schema
drwxr-xr-x. mysql mysql system_u:object_r:file_t:s0      test

Comment 3 Daniel Walsh 2014-01-08 16:36:52 UTC
Why not mount the new disk right at  /var/lib/mysql/

ANd then run restorecon on it.

Comment 4 Mikhail 2014-01-08 16:40:31 UTC
(In reply to Daniel Walsh from comment #3)
> Why not mount the new disk right at  /var/lib/mysql/
> 
> ANd then run restorecon on it.

Because I needed move to another partition not only mysql data. 
Also I move application and attachments which stored in file system and logs.

Comment 5 Daniel Walsh 2014-01-08 16:46:55 UTC
Then you could bind mount rather then symlink and run the restorecon.

mount -o bind /mnt/mysql /var/lib/mysql
restorecon -R -v /var/lib/mysql

Make sure you add a link in your fstab.

If you really want the current setup, you could setup alternate labeling.

# semanage fcontext -a -e -t /var/lib/mysql /mnt/mysql
# restorecon -R -v /var/lib/mysql

Comment 6 Mikhail 2014-01-08 18:11:08 UTC
# semanage fcontext -a -e -t /var/lib/mysql /mnt/mysql
/usr/sbin/semanage: bad option

Comment 7 Daniel Walsh 2014-01-09 21:25:34 UTC
Sorry take out the -t

# semanage fcontext -a -e /var/lib/mysql /mnt/mysql

Comment 8 Mikhail 2014-01-09 21:40:04 UTC
Thanks, now MariaDB works with enabled SELinux.