I noticed when I use the ( cd / ; sudo cpio -pud /tmp/package < /mnt/sda1/myfilelist.lst) command, directorys in the package directory have not maintained their original ownership. For instance:
tc@box:/tmp/package$ ls -l
drwxr-xr-x 2 tc staff 80 Jan 26 19:14 etc/
drwxr-xr-x 3 tc staff 60 Jan 26 18:25 home/
tc@box:/tmp/package$ cd /
tc@box:/$ ls -l
drwxr-xr-x 2 root root 1400 Jan 26 18:07 bin/
drwxr-xr-x 10 root root 9260 Jan 26 18:13 dev/
drwxr-xr-x 9 root root 780 Jan 26 18:38 etc/
Is this really the non-sudo case? If you are executing as user tc, you cannot create files owned by root, so you would get these ownerships.
If I execute the command as root things get even worse, /home and tc become owned by root.
root@box:/tmp# ( cd / ; cpio -pud /tmp/package < /mnt/sda1/myfilelist.lst)
3 blocks
root@box:/tmp# cd package/
root@box:/tmp/package# ls -l
drwxr-xr-x 2 root root 80 Jan 26 19:36 etc
drwxr-xr-x 3 root root 60 Jan 26 19:36 home
In the first example the files in etc have the correct ownership. In the second example the files in /home/tc seem to be correct as well..
Any ideas as to how to fix this?
I am not sure to which examples you are referring. Is it the non-sudo and sudo cases or the /etc and /home cases of the second example output.
If cpio executes as a non-root user, the ownership rights are set for that user.
If cpio executes as root, the ownership rights are copied from the original files.
Create two files owned by tc and root:
echo date >test.tc
sudo sh -c "echo date >test.root"
Execute cpio as tc:
( cd .
{ echo test.tc ; echo test.root ; } | cpio -pud /tmp/test_tc
ls -l /tmp/test_tc
)
-rw-r--r-- 1 tc staff 5 Jan 27 02:28 test.root
-rw-r--r-- 1 tc staff 5 Jan 27 02:28 test.tc
File test.root is owned by user tc since that user cannot create files owned by root.
Execute cpio as root:
( cd .
{ echo test.tc ; echo test.root ; } | sudo cpio -pud /tmp/test_root
ls -l /tmp/test_root
)
-rw-r--r-- 1 root staff 5 Jan 27 02:28 test.root
-rw-r--r-- 1 tc staff 5 Jan 27 02:28 test.tc
In this case test.root is owned by root and test.tc is owned by tc since root has the power to ownerships arbitrarily.
Please try your question again if this has not helped.