Show Table of Contents
5.9.5. Archiving Files with star
The
star utility does not retain extended attributes by default. Since SELinux contexts are stored in extended attributes, contexts can be lost when archiving files. Use the star -xattr -H=exustar command to create archives that retain contexts. The star package is not installed by default. To install star, run the yum install star command as the Linux root user.
The following example demonstrates creating a Star archive that retains SELinux contexts:
- As the Linux root user, run the
touch /var/www/html/file{1,2,3}command to create three files (file1,file2, andfile3). These files inherit thehttpd_sys_content_ttype from the/var/www/html/directory:~]#
touch /var/www/html/file{1,2,3}~]#ls -Z /var/www/html/-rw-r--r-- root root unconfined_u:object_r:httpd_sys_content_t:s0 file1 -rw-r--r-- root root unconfined_u:object_r:httpd_sys_content_t:s0 file2 -rw-r--r-- root root unconfined_u:object_r:httpd_sys_content_t:s0 file3 - Run the
cd /var/www/html/command to change into the/var/www/html/directory. Once in this directory, as the Linux root user, run thestar -xattr -H=exustar -c -f=test.star file{1,2,3}command to create a Star archive namedtest.star:~]#
star -xattr -H=exustar -c -f=test.star file{1,2,3}star: 1 blocks + 0 bytes (total of 10240 bytes = 10.00k). - As the Linux root user, run the
mkdir /testcommand to create a new directory, and then, run thechmod 777 /test/command to allow all users full-access to the/test/directory. - Run the
cp /var/www/html/test.star /test/command to copy thetest.starfile in to the/test/directory. - Run the
cd /test/command to change into the/test/directory. Once in this directory, run thestar -x -f=test.starcommand to extract the Star archive:~]$
star -x -f=test.starstar: 1 blocks + 0 bytes (total of 10240 bytes = 10.00k). - Run the
ls -lZ /test/command to view the SELinux contexts. Thehttpd_sys_content_ttype has been retained, rather than being changed todefault_t, which would have happened had the-xattr -H=exustaroption not been used:~]$
ls -lZ /test/-rw-r--r-- user1 group1 unconfined_u:object_r:httpd_sys_content_t:s0 file1 -rw-r--r-- user1 group1 unconfined_u:object_r:httpd_sys_content_t:s0 file2 -rw-r--r-- user1 group1 unconfined_u:object_r:httpd_sys_content_t:s0 file3 -rw-r--r-- user1 group1 unconfined_u:object_r:default_t:s0 test.star - If the
/test/directory is no longer required, as the Linux root user, run therm -ri /test/command to remove it, as well as all files in it. - If
staris no longer required, as the Linux root user, run theyum remove starcommand to remove the package.
Refer to the star(1) manual page for further information about
star.

Where did the comment section go?
Red Hat's documentation publication system recently went through an upgrade to enable speedier, more mobile-friendly content. We decided to re-evaluate our commenting platform to ensure that it meets your expectations and serves as an optimal feedback mechanism. During this redesign, we invite your input on providing feedback on Red Hat documentation via the discussion platform.