Can I override the SELinux file context of a file whose filesystem is mounted with the `context` mount option?

Solution Unverified - Updated -

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 to var_log_t. But when I change the context with semanage fcontext and then run restorecon, 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.

Current Customers and Partners

Log in for full access

Log In

New to Red Hat?

Learn more about Red Hat subscriptions

Using a Red Hat product through a public cloud?

How to access this content