Linux / OS X tar incompatibility – tarballs created on OS X give errors when untarred in Linux

108

30

When I tar up files on my Macbook and untar them in Linux, I repeatedly get the following warnings/errors:


 tar: Ignoring unknown extended header keyword `SCHILY.ino'
 tar: Ignoring unknown extended header keyword `SCHILY.nlink'
 tar: Ignoring unknown extended header keyword `SCHILY.dev'
 tar: Ignoring unknown extended header keyword `SCHILY.ino'
 tar: Ignoring unknown extended header keyword `SCHILY.nlink'
 tar: Ignoring unknown extended header keyword `SCHILY.dev'
 tar: Ignoring unknown extended header keyword `SCHILY.ino'
 tar: Ignoring unknown extended header keyword `SCHILY.nlink'
 tar: Ignoring unknown extended header keyword `SCHILY.dev'
 tar: Ignoring unknown extended header keyword `SCHILY.ino'
 tar: Ignoring unknown extended header keyword `SCHILY.nlink'
 tar: Ignoring unknown extended header keyword `SCHILY.dev'
 tar: Ignoring unknown extended header keyword `SCHILY.ino'
 tar: Ignoring unknown extended header keyword `SCHILY.nlink'
 tar: Ignoring unknown extended header keyword `SCHILY.dev'
 tar: Ignoring unknown extended header keyword `SCHILY.ino'
 tar: Ignoring unknown extended header keyword `SCHILY.nlink'
 tar: Error exit delayed from previous errors

Fortunately, this does NOT affect the files stored in the archive, which are restored perfectly. However, it does cause problems in a number of scenarios, especially when dealing with build processes where the non-zero failure code returned by 'tar' causes builds and installs to stop unnecessarily.

How can I get OS X to build tar files that play nicely with the rest of the Linux world?

Also, for bonus points, there exists a publicly distributed tar file with these issues. Is there any way to get Linux to handle the tar file gracefully without changing the way it was originally compressed?

Dave Dopson

Posted 2011-08-03T21:47:30.783

Reputation: 1 215

Answers

72

I Googled for the error message and it seems like a BSD tar vs. GNU tar issue.

Install GNU tar if you can on Mac OS and use that to create the tar.

holygeek

Posted 2011-08-03T21:47:30.783

Reputation: 941

sudo port install gnutar cd /usr/bin sudo rm tar sudo ln -s /opt/local/bin/gnutar tar – chaosless – 2014-10-31T00:41:59.883

1If using MacPorts, you can also just put /opt/local/libexec/gnubin/ at the top of your PATH rather than removing anything from /usr/bin or manually creating symlinks. – Lorrin – 2017-02-13T22:57:06.170

If using Homebrew: brew install gnu-tar – TrinitronX – 2019-10-07T21:19:07.710

17Mac OS X 10.6 uses a BSD tar by default but also ships with a gnutar at /usr/bin/gnutar. – None – 2011-08-03T22:03:08.477

@Ned. Thx. that's good info. – Dave Dopson – 2011-08-04T00:31:05.187

16FYI : /usr/bin/gnutar is not shipped anymore with Mac OS X (at least as of Mavericks) – foobar – 2013-11-27T13:52:41.583

62

If you are using Mavericks or newer, then gnutar is no longer included by default.

The work around, if you use homebrew, is to execute the following:

brew install gnu-tar

You can then use the command gtar for linux compatability.


If you want to replace tar with gtar, simply replace the symlink

tar --version
ll `which tar`
sudo unlink `which tar`
sudo ln -s `which gtar` /usr/bin/tar
tar --version

To restore the original tar provided with Mac Os X, run the above commands but replace which gtar with which bsdtar

Source:
https://github.com/jordansissel/fpm/issues/576

spuder

Posted 2011-08-03T21:47:30.783

Reputation: 8 755

4No need to unlink anymore, as brew instructs, you can just add this to your PATH in .bashrc (or your equivalent): PATH="/usr/local/opt/gnu-tar/libexec/gnubin:$PATH" – Bryan Petty – 2015-06-10T16:13:04.273

1Or just create a tar link in /usr/local/bin by cd /usr/local/bin ; ln -s gtar tar - possibly the simplest option – Karthik T – 2016-04-19T03:43:07.737

28

GNU tar doesn't like some of the optional information the default OSX BSD tar includes.

GNU tar will let you suppress those warnings with the option:

--warning=no-unknown-keyword

See: https://www.gnu.org/software/tar/manual/html_section/tar_27.html

Note that BSD tar doesn't support that flag so if you need to run the same unpacking code on all platforms you can use something like:

isGnuTar=$(tar --version | grep -q 'gnu')
if [ $? -eq 0 ]
then
    echo "Detected GNU tar"
    tar --warning=no-unknown-keyword -zxf my.tar.gz
else
    tar -zxf my.tar.gz
fi

Chris

Posted 2011-08-03T21:47:30.783

Reputation: 381

5this should be the right answer because it doesn't involve installing an entirely new tool for the sake of suppressing a single warning. – c z – 2017-05-22T12:53:11.123

10

To extract the tar file properly without any errors on a Linux system you could use bsdtar.

sudo apt-get install bsdtar

Then use as normal.

bsdtar -xvf file.tar where file.tar is the tar file you want to extract.

Source: https://bugs.launchpad.net/ubuntu/+source/tar/+bug/129314

Alternatively you can also use GNOME file roller.

daka

Posted 2011-08-03T21:47:30.783

Reputation: 213

6

COPYFILE_DISABLE=1 tar cf filename.tar

or

tar --disable-copyfile cf filename.tar

This is the least discoverable feature of tar on OS X that I am personally aware of.

See also Why do I get files like ._foo in my tarball on OS X?


Edit: it looks like this might only stop the creation of the unwanted ._foo-type files, it doesn't stop the header creation (at least on Yosemite/10.10); thanks commenters for pointing it out. However, (for the bonus points:) you can gracefully handle such tarballs by extracting them like this:

tar xf filename.tar --pax-option=delete=SCHILY.*,delete=LIBARCHIVE.*

This worked using gnu tar 1.15.1, which is pretty old! Alternatively, you can use pax instead, which (for me) throws the extra info into a PaxHeader directory, but at least exits without error:

pax -rf filename.tar

Zac Thompson

Posted 2011-08-03T21:47:30.783

Reputation: 887

Sadly, this does not appear to stop the extended header keyword warnings when untarring with gnutar. – JJC – 2016-09-21T14:27:09.247

Neither of these seems to work on Yosemite (tar --version indicates bsdtar 2.8.3 - libarchive 2.8.3). Also I need a dash before cf in the latter case. – tripleee – 2017-01-31T12:04:10.527

4

MacOSX comes with gnutar already. If you want a quick and dirty solution add this to ~/.bash_profile

alias tar='gnutar'

and run source ~/.bash_profile to update

Additionally, OSX ships with both GNU and BSD tar. So you can also unlink the ref of tar from bsd to gnu:

sudo unlink /usr/bin/tar;
sudo ln -s /usr/bin/gnutar /usr/bin/tar

Du3

Posted 2011-08-03T21:47:30.783

Reputation: 141

1Why in /etc/hosts? /etc/hosts is for host/IP mapping, right? – BenjiWiebe – 2013-02-21T16:47:51.563

1what @BenjiWiebe said. The even odder bit is editing /etc/hosts. I think you meant ~/.bashrc – Dave Dopson – 2013-02-21T17:57:11.713

2On OS X, .bashrc isn't loaded for Terminal sessions. You need .bash_profile, since a login shell is started with a new Terminal window. /cc @BenjiWiebe – slhck – 2013-02-21T19:32:21.663

Correct :-) I was also working in /etc/hosts at that time so it spewed onto the keyboard. Good catch – Du3 – 2013-02-25T09:52:46.987

2

Thank you. This thread was very useful. If you are using MacPorts here is a quick howto:

sudo port install gnutar

sudo ln -s /usr/local/opt/gnu-tar/libexec/gnubin/tar /usr/bin/gnutar

sudo ln -s /opt/local/libexec/gnubin/tar /usr/bin/gnutar

Add the following line to /Users/[yourname]/.profile

alias tar='/opt/local/libexec/gnubin/tar'

Quit und and restart your Terminal window.

howdytom

Posted 2011-08-03T21:47:30.783

Reputation: 121

1

Yea, Mac's built-in tar binary adds a bunch of extra stuff that CentOS doesn't like. To fix this do the following:

sudo mv /usr/bin/tar /usr/bin/darwintar
sudo ln -s /usr/bin/gnutar /usr/bin/tar
ls -l /usr/bin/tar

Hope that helps!

Shaheen Ghiassy

Posted 2011-08-03T21:47:30.783

Reputation: 117

That's probably not a good idea, for a couple of reasons. 1) Now Apple packages don't know where to find the native tar, the tar that knows how to handle Apple file attributes. 2) If you must use GNU tar, the proper place to put it is ahead in your search path, like /usr/local/bin, or something, and 3) It's probably safer still to call the foreign tar program gnutar to avoid confusing software expecting a Mac to act like a Mac. $0.02. -Erik – Erik Bennett – 2017-09-12T14:42:52.160

That's one way. I solved the GNU/BSD issue more comprehensively in https://github.com/ddopson/dotfiles. I have ~/bin/coreutils early in the path and there's small shims in there like https://github.com/ddopson/dotfiles/blob/master/bin/coreutils/tar that pick the correct executable based on linux vs Mac and if the COREUTILS environment variable is set

– Dave Dopson – 2013-02-08T02:24:17.523

You might want to modify your instructions to tell people to check for the existence of /usr/bin/gnutar before moving their working tar. Newbies can find this using google and not know how to un-break their system. – msouth – 2014-05-15T15:18:25.573

0

On MAC OSX install gnu-tar

brew install gnu-tar

then create your linux compatible tar with:

gtar -c -f your_tar_file files

Or you can create your archive with pax format

tar -c --format pax -f your_tar_file files

msadek

Posted 2011-08-03T21:47:30.783

Reputation: 31

0

Okay, I used Google search, but top three link confirmed what I suspected

  1. Bug in your tar AND/OR
  2. Incompatibility between the two tar utilities
    See this link. There someone reports that "Using "bsdtar -xvf" worked."

Edit: You are on Mac system, I thought other way round. You will need to use gnutar, it should be installed already, if not get it installed. Of course, you can look at other links by searching yourself.

Sudhi

Posted 2011-08-03T21:47:30.783

Reputation: 143