tar: .: Cannot utime: Operation not permitted
tar: .: Cannot change mode to rwxr-xr-x: Operation not permitted
tar: Exiting with failure status due to previous errorsI have my files in Downloads folder and I am running the installation file from Downloads folder to the /opt/pkg folder and here are the commands I used
chmod -R 777 Downloads/*
sudo chmod -R 777 /opt/*
chmod +x petalinux-v2017.1-final-installer.run
./petalinux-v2017.1-final-installer.run /opt/pkgat the end the installer is failing giving the above error messages. And I am providing all permissions needed to Downloads folder and also for /opt/pkg folder.
3 Answers
Question: Permissions cannot be restored for a tar
Answer: only root can.
Reference: read this informative Q&A on askubuntu:
even if you use
tar's--same-ownerflag, you will still need to extract the files as root to preserve ownership.
Update: Here's some more details about tar's behaviour. Let's say we are user1 and have created an archive with tar cvpzf test.tar.gz . that includes files owned by user2. If we extract the archive in a directory owned by user2 with permissions 777, here's the outcome:
$ tar xpvzf test.tar.gz
./
./file1
./file2
tar: .: Cannot utime: Operation not permitted
tar: .: Cannot change mode to rwxrwxr-x: Operation not permitted
tar: Exiting with failure status due to previous errors
$ ls -al
drwxrwxrwx 2 user2 user2 .
-rw-rw-r-- 1 user1 user1 file1
-rw-rw-r-- 1 user1 user1 file2tar throws an error because it cannot change ownership and permissions for files owned by user2. The files are however extracted, although owned by user1.
Here's what happens if the extraction is performed in a directory owned by user1 instead:
$ tar xpvzf test.tar.gz
./
./file1
./file2
$ ls -al
drwxrwxr-x 2 user1 user1 .
-rw-rw-r-- 1 user1 user1 file1
-rw-rw-r-- 1 user1 user1 file2Permissions are restored for both the folder and the files, and no error is thrown even though user2 ownership could not be restored.
Judging from the OP's own answer, it seems then that the installer checks tar's exit code and stops if an error was encountered. chowning the folder to the current user makes tar fail silently so the installer can continue.
chmod -R 777 Downloads/*
sudo chmod -R 777 /opt/*
mkdir /opt/pkg
cd /home/my_ubuntu/Downloads
chmod +x petalinux-v2017.1-final-installer.run
./petalinux-v2017.1-final-installer.run /opt/pkg
now it will install and tar file permissions are restored when u create the directory pkg as normal user and not the root user.
0In addition to restoring files from an archive, tar also attempts to restore timestamp and permissions. Some filesystems (perhaps non-Linux, perhaps network drives) do not support a client modifying/setting a UNIX timestamp or modifying/setting UNIX permissions. These can result in the following errors from tar:
- Cannot utime: Operation not permitted
- Cannot change mode to rwxrwxr-x: Operation not permitted
If you want to proceed to extract the files anyway but do not care about the original timestamps or permissions, then, you can use these additional options in tar:
-m, --touch Don't extract file modified time.
--no-overwrite-dir Preserve metadata of existing directories.Consult man tar for more info.