3

I have been using the following command on my system to create the .cpio archive to create an initramfs for my embedded target device

sudo find . | cpio -H newc -oc > ~/initramfs.cpio

This has always worked for me without any problem. Yesterday I was generating a new archive and I received the following error:

cpio: Archive format multiply defined: Operation not permitted
cpio: ./etc/shadow: Function open failed: Permission denied
cpio: ./usr/lib/ssh-keysign: Function open failed: Permission denied
64842 blocks

I never received these errors in the past, the files mentions with failed opens have not been touched either so I cannot understand why this has started happening. I update my host system with Ubuntu package manager so it is possible that my cpio package has been updated too. I obviously have no faith in the initramfs generated here due to all of the errors which confuse me greatly. The only option I can think of is to try and find out if my cpio version has changed and if so remove and replace with the older version I had. Is there any way I can find out this information on my system (Ubuntu 12.04)? Or is there some other way I can get around this problem?

mathematician1975
  • 1,453
  • 2
  • 24
  • 43

1 Answers1

5

The first error is because you're passing both -H newc and -c. You have to make up your mind on the format of the archive you want to generate. The "Operation not permitted" is a bug in GNU cpio, it's passing wrong arguments to the function that outputs that error message and should exit there.

The other errors are because you're not running that command as the superuser or more likely , you're not running it from the correct location. Only the superuser can read files like /etc/shadow as it contains sensitive information. You should also make sure that the archive you generate can only be read by the superuser. If it's an initramfs you're creating, chances are /etc/shadow has not business being there, unless that initramfs contains a full operating system.

Stéphane Chazelas
  • 522,931
  • 91
  • 1,010
  • 1,501
  • Thanks for your answer. The second part I would agree with but I am calling this with `sudo`. And for the first part, why is it only starting to display these errors when it has been working without them in the past? – mathematician1975 Jul 31 '13 at 09:58
  • There always was a problem with you specifying the format twice, maybe the newer cpio has been improved to check for that problem. Is the default user for `sudo` `root`? (what does `sudo id` tell you?). Are you doing `sudo find` or `sudo cpio`? What are the permissions of the `cpio` executable itself? – Stéphane Chazelas Jul 31 '13 at 10:23
  • thanks very much indeed for that comment - sudo id **is** root. If I call `sudo find . | sudo cpio ...` and omit the -c option then it works without any error. I never realised that I had to call sudo on **both** commands. I am still mystified why it worked without complaint in the past but I guess that is life. Thanks again for your help – mathematician1975 Jul 31 '13 at 10:26
  • 1
    @mathematician1975 accepting an answer on stackexchange is the highest form of flattery. – msw Jul 31 '13 at 11:50
  • @msw OK duly noted – mathematician1975 Jul 31 '13 at 14:10