Bug 1629426 - copy_out "tar: This does not look like a tar archive"
Summary: copy_out "tar: This does not look like a tar archive"
Keywords:
Status: CLOSED DEFERRED
Alias: None
Product: Virtualization Tools
Classification: Community
Component: libguestfs
Version: unspecified
Hardware: Unspecified
OS: Linux
unspecified
unspecified
Target Milestone: ---
Assignee: Richard W.M. Jones
QA Contact:
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2018-09-16 07:59 UTC by Radostin Stoyanov
Modified: 2018-09-18 11:35 UTC (History)
2 users (show)

Fixed In Version:
Clone Of:
Environment:
Last Closed: 2018-09-18 11:25:01 UTC
Embargoed:


Attachments (Terms of Use)
Output generated with LIBGUESTFS_DEBUG=1 and LIBGUESTFS_TRACE=1 (189.44 KB, text/plain)
2018-09-16 07:59 UTC, Radostin Stoyanov
no flags Details

Description Radostin Stoyanov 2018-09-16 07:59:48 UTC
Created attachment 1483659 [details]
Output generated with LIBGUESTFS_DEBUG=1 and LIBGUESTFS_TRACE=1

Description of problem:
On Ubuntu 18.04 copy_out fails with "tar: This does not look like a tar archive"

Version-Release number of selected component (if applicable):
Tested with:
- libguestfs 1.36.13 and 1.39.9
- tar v1.29 and v1.30

How reproducible: 100%

Steps to Reproduce:
1. # virt-builder centos-7.5 -o /tmp/test.img --no-network
2. # mkdir ~/test
3. # virt-copy-out -a /tmp/test.img / ~/test

Actual results:

libguestfs: error: file receive cancelled by daemon
libguestfs: error: tar subprocess failed: tar: This does not look like a tar archive
tar: Exiting with failure status due to previous errors

Comment 1 Richard W.M. Jones 2018-09-16 22:23:56 UTC
FWIW I cannot reproduce this with libguestfs-1.38.3-1.fc28.x86_64

I believe the error

tar -C /sysroot/ -cf - .
pclose: /: Success

comes from:

https://github.com/libguestfs/libguestfs/blob/51a9c874d3f0a9c4780f2cd3ee7072180446e685/daemon/tar.c#L387

It seems as if the tar command is exiting abruptly (without any
error message).

I wonder if the Ubuntu tar command has some sort of problem with
the CentOS filesystem.  SELinux labels?

You might try running:

$ virt-rescue --scratch

and checking if the tar command in the appliance is functioning properly.

Comment 2 Barry S 2018-09-17 12:57:28 UTC
Hi Richard. 

On Ubuntu 18.04, I receive the original error as well. Also, it gives same error when running against non-Centos images. For instance, the following also gives same error: 

$ virt-builder debian-8 -o debian8.img --no-network
$ mkdir debfs
$ virt-copy-out -a debian8.img / ~/debfs/


Follwing your suggestion, I've run 

$ virt-rescue --scratch 

And can confirm that tar is there and appears to be functional I only tested by tar-ing and untar-ing the included bin/ directory. (Not sure how I can access the debian8.img file as referenced above?)

However, one thing I notice from the debug log on my machine, are these lines:

guestfsd: main_loop: new request, len 0x34^M
libguestfs: trace: is_dir = 1
libguestfs: command: run: tar
libguestfs: command: run: \ -xf
libguestfs: command: run: \ -

It strikes me as odd that "tar -xf -" is being reported on 3 separate lines broken up like that...is it possible that its trying to run each as its own sub-command instead of running it as a single command?

Comment 3 Richard W.M. Jones 2018-09-17 13:48:21 UTC
(In reply to Barry S from comment #2)
> Hi Richard. 
> 
> On Ubuntu 18.04, I receive the original error as well. Also, it gives same
> error when running against non-Centos images. For instance, the following
> also gives same error: 
> 
> $ virt-builder debian-8 -o debian8.img --no-network
> $ mkdir debfs
> $ virt-copy-out -a debian8.img / ~/debfs/
> 
> 
> Follwing your suggestion, I've run 
> 
> $ virt-rescue --scratch 
> 
> And can confirm that tar is there and appears to be functional I only tested
> by tar-ing and untar-ing the included bin/ directory. (Not sure how I can
> access the debian8.img file as referenced above?)

Can you try:

$ virt-rescue --ro -a debian8.img

The image should be available as /dev/sda and can be mounted inside
virt-rescue, eg:

  ><rescue> mount /dev/sdaX /sysroot/

> However, one thing I notice from the debug log on my machine, are these
> lines:
> 
> guestfsd: main_loop: new request, len 0x34^M
> libguestfs: trace: is_dir = 1
> libguestfs: command: run: tar
> libguestfs: command: run: \ -xf
> libguestfs: command: run: \ -
> 
> It strikes me as odd that "tar -xf -" is being reported on 3 separate lines
> broken up like that...is it possible that its trying to run each as its own
> sub-command instead of running it as a single command?

No.

virt-copy-out works by running a copy of ‘tar -cf ...’ inside the appliance
and connecting it to a copy of ‘tar -xf ...’ running on the host.  The debug
messages above show the copy running on the host:

https://github.com/libguestfs/libguestfs/blob/51a9c874d3f0a9c4780f2cd3ee7072180446e685/lib/copy-in-out.c#L201
https://github.com/libguestfs/libguestfs/blob/51a9c874d3f0a9c4780f2cd3ee7072180446e685/lib/command.c#L426

Comment 4 Barry S 2018-09-17 16:02:25 UTC
>Can you try:
>
>$ virt-rescue --ro -a debian8.img
>
>The image should be available as /dev/sda and can be mounted inside
>virt-rescue, eg:
>
> <rescue> mount /dev/sdaX /sysroot/

I can mount without problem and see the files inside /sysroot

Any other test I can run? 

>No.

>virt-copy-out works by running a copy of ‘tar -cf ...’ inside the appliance
>and connecting it to a copy of ‘tar -xf ...’ running on the host.  The debug
>messages above show the copy running on the host

Thanks, understood.

Comment 5 Richard W.M. Jones 2018-09-17 16:28:31 UTC
I would try this test:

(1) Mount the root and maybe boot filesystems as they would
be in the real appliance, eg:

  ><rescue> mount /dev/sda3 /sysroot
  ><rescue> mount /dev/sda1 /sysroot/boot

(actual device names might be different)

(2) Run a tar command as the appliance does:

  ><rescue> tar -C /sysroot/ -cf - . >/dev/null

Does the tar command exit successfully?  Is any error printed?

Is the output (sent to /dev/null above) an actual tar file?

It's difficult to get coredumps inside virt-rescue but you may
be able to get a stack trace if tar is crashing by doing:

LD_PRELOAD=/lib/libSegFault.so tar [etc]

Comment 6 Barry S 2018-09-17 16:44:14 UTC
Thanks for the hand holding.

>(1) Mount the root and maybe boot filesystems as they would
>be in the real appliance, eg:
>
> <rescue> mount /dev/sda3 /sysroot
> <rescue> mount /dev/sda1 /sysroot/boot

Just a note. Appears this debian8.img file only has a single partition /dev/sda1 - therefore /boot is already there inside. 


>(2) Run a tar command as the appliance does:
>
>  <rescue> tar -C /sysroot/ -cf - . >/dev/null

Works fine with no errors. 

In addition, I ran:

<rescue> tar -C /sysroot/ -cf - . > myfile.tar
<rescue> file myfile.tar
myfile.tar: POSIX tar archive (GNU)


Additionally, I can run "tar tf myfile.tar" and successfully see all files contained inside.

Comment 7 Radostin Stoyanov 2018-09-17 23:27:14 UTC
Hi Richard and Barry,

I noticed that the following commands do not report any error (like Barry already mentioned)

# virt-rescue --ro -a debian8.img
><rescue> mount /dev/sda1 /sysroot
><rescue> tar -C /sysroot/ -cf - . > /dev/null

but guestfish fails

# guestfish
><fs> add-drive debian8.img
><fs> run
><fs> tar-out / - | tar tf -
libguestfs: error: file receive cancelled by daemon
tar: This does not look like a tar archive
tar: Exiting with failure status due to previous errors

What is the difference tar running with virt-rescue and when called from tar-out command of guestfish?

Is it possible to get a stack trace of tar when is executed by guestfish?

Comment 8 Radostin Stoyanov 2018-09-17 23:36:01 UTC
I managed to get strace log with this hack:

$ sudo mv /bin/tar /bin/tar-back
$ sudo cat > /bin/tar <<-EOF
#!/bin/bash
strace -o /tmp/strace.log /bin/tar-back $@
EOF
$ sudo chmod +x /bin/tar


This is the content of strace.log
https://paste.fedoraproject.org/paste/L5pqLmbtmYwNguWltZAARw/raw

Comment 9 Radostin Stoyanov 2018-09-17 23:48:53 UTC
I found the following description of the error message from tar

https://git.savannah.gnu.org/cgit/tar.git/tree/NEWS#n755

* Recognition of broken archives.

When supplied an archive smaller than 512 bytes in reading mode (-x,
-t), the previous version of tar silently ignored it, exiting with
code 0.  It is fixed.  Tar now issues the following diagnostic message:
'This does not look like a tar archive', and exits with code 2.

Comment 10 Barry S 2018-09-18 03:45:28 UTC
(In reply to rstoyanov1 from comment #7)
><rescue> tar -C /sysroot/ -cf - . > /dev/null
> 
> but guestfish fails
> 
> # guestfish
> ><fs> add-drive debian8.img
> ><fs> run
> ><fs> tar-out / - | tar tf -
> libguestfs: error: file receive cancelled by daemon
> tar: This does not look like a tar archive
> tar: Exiting with failure status due to previous errors
> 

Thank you for this. 

I've downloaded libguestfs 1.39.9 from github and have built in a local directory on my Ubuntu 18.04 box. 

I can confirm that this version works with virt-builder / virt-copy-out without problems. So its definitely appears to be related to the version of guestfish that Ubuntu is shipping with (1.36.13). 

I'm hesitant to actually install this source version for production as there are so many dependencies related to libguestfs that it will cause a maintenance issues in trying to support. However, as a temporary workaround, I can just build my images in the 1.39.9 build directory and then move the resulting img-dir into the production area.

Comment 11 Richard W.M. Jones 2018-09-18 08:15:26 UTC
(In reply to Radostin Stoyanov from comment #8)
> I managed to get strace log with this hack:
> 
> $ sudo mv /bin/tar /bin/tar-back
> $ sudo cat > /bin/tar <<-EOF
> #!/bin/bash
> strace -o /tmp/strace.log /bin/tar-back $@
> EOF
> $ sudo chmod +x /bin/tar
> 
> 
> This is the content of strace.log
> https://paste.fedoraproject.org/paste/L5pqLmbtmYwNguWltZAARw/raw

This shows it is reading no data from stdin:

read(0, "", 10240)                      = 0

Comment 12 Richard W.M. Jones 2018-09-18 11:25:01 UTC
Since this bug seems to be specific to Ubuntu, it seems best to
continue this discussion on the downstream Launchpad bug:

https://bugs.launchpad.net/ubuntu/+source/libguestfs/+bug/1793056?comments=all

Comment 13 Barry S 2018-09-18 11:35:33 UTC
Agreed. Thanks for your help Richard.


Note You need to log in before you can comment on or make changes to this bug.