Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[SOLVED]Copying files with cpio change file permissions
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo
View previous topic :: View next topic  
Author Message
/root
n00b
n00b


Joined: 19 Sep 2003
Posts: 49
Location: Saarbrücken / Germany

PostPosted: Sat Feb 03, 2007 1:27 am    Post subject: [SOLVED]Copying files with cpio change file permissions Reply with quote

I encountered some weird behaviour of the cpio command.

A binary file (e.g. /bin/bb, with 755 rights) is copied over to another dir on the same partition with
Code:
echo /bin/bb | cpio -dpmLv /otherdir

After that, the file has only read/write rights (600 rights).

This problem occurs while working with Raffi's lvm2create_initrd script discussed in this thread.

I'm running Gentoo 2006.1 with ~x86 keyword, stage1 and currently 2.6.19-ck2-r4 kernel.

Initially I've started with stage3, 2.6.19-ck2-r3 kernel and everything had worked fine.

This month I bootstrapped my system an do an emerge -e system && emerge -e world. I noticed nothing strange so far, but cpio. Normal copy with cp works as expected.

Does anyone have an idea why cpio change the file permissions?


Version of cpio,e2fsprogs and current kernel:
Code:
morpheus ~ # cpio --version
cpio (GNU cpio) 2.7
morpheus ~ # equery b mke2fs
[ Searching for file(s) mke2fs in *... ]
sys-fs/e2fsprogs-1.39-r1 (/sbin/mke2fs)
morpheus ~ # uname -r
2.6.19-ck2-r4


"Proof of concept":
Code:
morpheus initrd-image # echo /bin/bb | cpio -pdmLv /mnt/initrd-image
/mnt/initrd-image/bin/bb
3432 blocks
morpheus initrd-image # mkdir sbin
morpheus initrd-image # echo /sbin/lvm | cpio -pdmLv /mnt/initrd-image
/mnt/initrd-image/sbin/lvm
2642 blocks
morpheus initrd-image # ls * -la
bin:
total 1726
drwx------ 2 root root    1024 Feb  2 23:28 .
drwxr-xr-x 5 root root    1024 Feb  2 23:29 ..
-rw------- 1 root root 1757020 Feb  2 23:28 bb

sbin:
total 1330
drwxr-xr-x 2 root root    1024 Feb  2 23:29 .
drwxr-xr-x 5 root root    1024 Feb  2 23:29 ..
-rw------- 1 root root 1352628 Feb  2 23:29 lvm
morpheus initrd-image # cp /sbin/insmod.static sbin/
morpheus initrd-image # ls sbin/ins* -la
-rwxr-xr-x 1 root root 476176 Feb  2 23:36 sbin/insmod.static


Bye.


Last edited by /root on Mon Feb 05, 2007 3:45 pm; edited 1 time in total
Back to top
View user's profile Send private message
wynn
Advocate
Advocate


Joined: 01 Apr 2005
Posts: 2421
Location: UK

PostPosted: Sat Feb 03, 2007 11:22 am    Post subject: Reply with quote

Strange. In Re: tar, cpio, or cp? says
Quote:
I prefer cpio as it (IMHO) does the best job of preserving permissions, and it doesn't throw up on device files and the like.
Also
Code:
$ ls -l /bin/bb
1676 -rwxr-xr-x 1 root root 1709256 Jan 20 16:42 /bin/bb*
$ echo /bin/bb | cpio -dpmLv ./otherdir
./otherdir/bin/bb
3339 blocks
$ ls -l ./otherdir/bin/bb
1676 -rwxr-xr-x 1 wynn users 1709256 Jan 20 16:42 ./otherdir/bin/bb*
and as root
Code:
# echo /bin/bb | cpio -dpmLv ./otherdir
./otherdir/bin/bb
3339 blocks
# l ./otherdir/bin/bb
1676 -rwxr-xr-x 1 root root 1709256 Jan 20 16:42 ./otherdir/bin/bb*
Versions
Code:
# cpio --version
cpio (GNU cpio) 2.6
# uname -r
2.6.19-gentoo-r5

_________________
The avatar is jorma, a "duck" from "Elephants Dream": the film and all the production materials have been made available under a Creative Commons Attribution 2.5 License, see orange.blender.org for details.
Back to top
View user's profile Send private message
Raffi
l33t
l33t


Joined: 17 Mar 2003
Posts: 731
Location: Moscow, Id.

PostPosted: Sat Feb 03, 2007 8:32 pm    Post subject: Reply with quote

Here's what I just tried on my system running vanilla 2.6.19.2.

Code:

# mke2fs /dev/ram0
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
1024 inodes, 4096 blocks
204 blocks (4.98%) reserved for the super user
First data block=1
Maximum filesystem blocks=4194304
1 block group
8192 blocks per group, 8192 fragments per group
1024 inodes per group

Writing inode tables: done                           
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 24 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
# mount /dev/ram0 /mnt/loop
# ls -l /mnt/loop
total 12
drwx------ 2 root root 12288 Feb  3 12:29 lost+found
# cp /bin/ls /mnt/loop
# ls -l /mnt/loop
total 102
drwx------ 2 root root 12288 Feb  3 12:29 lost+found
-rwxr-xr-x 1 root root 91076 Feb  3 12:29 ls


Have you tried this simple of an experiment yet? Can you cut and paste the output here?
Back to top
View user's profile Send private message
/root
n00b
n00b


Joined: 19 Sep 2003
Posts: 49
Location: Saarbrücken / Germany

PostPosted: Mon Feb 05, 2007 10:55 am    Post subject: Reply with quote

@Raffi: A simple cp preserve the permissions.
As an example I copied insmod.static.
Code:
morpheus initrd-image # cp /sbin/insmod.static sbin/
morpheus initrd-image # ls sbin/ins* -la
-rwxr-xr-x 1 root root 476176 Feb  2 23:36 sbin/insmod.static

The only question remaining is "why" is cpio showing this strange behaviour.
Back to top
View user's profile Send private message
Raffi
l33t
l33t


Joined: 17 Mar 2003
Posts: 731
Location: Moscow, Id.

PostPosted: Mon Feb 05, 2007 1:04 pm    Post subject: Reply with quote

Sorry. I misunderstood.

Have you tried downgrading cpio to an earlier version?
Back to top
View user's profile Send private message
/root
n00b
n00b


Joined: 19 Sep 2003
Posts: 49
Location: Saarbrücken / Germany

PostPosted: Mon Feb 05, 2007 3:45 pm    Post subject: Reply with quote

Downgrading to cpio 2.6-r5 does the trick.
Code:
morpheus initrd-image # echo /bin/bb | cpio -dpmL /mnt/initrd-image/
3432 blocks
morpheus initrd-image # ls bin/* -la
-rwxr-xr-x 1 root root 1757020 Jan 26 17:49 bin/bb
morpheus initrd-image # cpio --version
cpio (GNU cpio) 2.6


Thanks for all your help.

Bye.

[EDIT]Please finde below the ChangeLog from portage tree
Code:
# ChangeLog for app-arch/cpio
# Copyright 1999-2006 Gentoo Foundation; Distributed under the GPL v2
# $Header: /var/cvsroot/gentoo-x86/app-arch/cpio/ChangeLog,v 1.51 2006/11/11 06:58:30 vapier Exp $

*cpio-2.7-r1 (11 Nov 2006)

  11 Nov 2006; Mike Frysinger <vapier@gentoo.org>
  +files/cpio-2.7-link-terminate.patch, +cpio-2.7-r1.ebuild:
  Grab fix from upstream for #153782 by Brian S. Stephan.

*cpio-2.7 (21 Oct 2006)

  21 Oct 2006; Mike Frysinger <vapier@gentoo.org> +cpio-2.7.ebuild:
  Version bump.

  17 Oct 2006; Roy Marples <uberlord@gentoo.org> cpio-2.6-r5.ebuild:
  Added ~sparc-fbsd keyword.

  30 Mar 2006; Diego Pettenò <flameeyes@gentoo.org> cpio-2.6-r5.ebuild:
  Add ~x86-fbsd keyword.

  18 Feb 2006; Mike Frysinger <vapier@gentoo.org>
  +files/cpio-2.6-stpcpy-hack.patch, cpio-2.6-r5.ebuild:
  Fix by Benigno B. Junior for building on *BSD systems #123237.

  25 Dec 2005; Joshua Kinard <kumba@gentoo.org> cpio-2.6-r5.ebuild:
  Marked stable on mips.

  04 Dec 2005; Michael Hanselmann <hansmi@gentoo.org> cpio-2.6-r5.ebuild:
  Stable on ppc.

  03 Dec 2005; Simon Stelling <blubb@gentoo.org> cpio-2.6-r5.ebuild:
  stable on amd64 wrt bug 112140

  02 Dec 2005; Fernando J. Pereda <ferdy@gentoo.org> cpio-2.6-r5.ebuild:
  stable on alpha wrt bug #112140

  02 Dec 2005; Andrej Kacian <ticho@gentoo.org> cpio-2.6-r5.ebuild:
  Stable on x86, security bug #112140.

  02 Dec 2005; Fabian Groffen <grobian@gentoo.org> cpio-2.6-r5.ebuild:
  Marked ppc-macos (bug #112140)

  02 Dec 2005; Markus Rothe <corsair@gentoo.org> cpio-2.6-r5.ebuild:
  Stable on ppc64; bug #112140

  01 Dec 2005; Gustavo Zacarias <gustavoz@gentoo.org> cpio-2.6-r5.ebuild:
  Stable on sparc wrt #112140
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum