Can I override the SELinux file context of a file whose filesystem is mounted with the `context` mount option?
Issue
- A filesystem is mounted with the
context=system_u:object_r:public_content_rw_t:s0
mount option. I want to change the context of certain files on the filesytsem tovar_log_t
. But when I change the context withsemanage fcontext
and then runrestorecon
, the context doesn't change.
# mount -o context=system_u:object_r:public_content_rw_t:s0 /dev/test_vg2/test_lv1 /mnt2
# touch /mnt2/testdir/testfile
# ls -Z /mnt2/testdir/
-rw-r--r--. root root system_u:object_r:public_content_rw_t:s0 testfile
# semanage fcontext -at var_log_t /mnt2/testdir/testfile
# restorecon -Rv /mnt2/testdir/
# ls -Z /mnt2/testdir/
-rw-r--r--. root root system_u:object_r:public_content_rw_t:s0 testfile
Environment
- Red Hat Enterprise Linux 7
Subscriber exclusive content
A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.