Why does file ownership matter within an RPM or DEB package

aliendebpackage-managementpermissionsrpm

Context:

I'm trying to convert a .deb package to .rpm using alien, I use this command:

$ alien -r foo.deb

but it complains thusly:

> Warning: alien is not running as root!
> Warning: Ownerships of files in the generated packages will probably be wrong.

I think all alien needs root for is to guarantee that it has permission to create foo.deb's root-owned files for the foo.rpm output, but I'm not sure.

Questions:

  1. Do packages always need some root-owned files?
  2. Why do they need root-owned files at all?
  3. If I'm wrong, why does alien need root?

Best Answer

Rpm and deb packages contain archives of the files to install (cpio archives in the case of rpm, tar in the case of deb). These archives contain metadata about each file, including its name, modification date, owning user and group, and permissions. When a package is installed, each file ends up having the ownership described in the archive (unless a post-installation script modifies it).

Most files installed by packages are owned by root, because no user is authorized to modify them.

Alien converts packages by unpacking the archive and repacking it (as well as other things like converting pre/post-installation scripts). For example, to convert an rpm into a deb, alien calls cpio to extract the archive to a temporary location, then tar to build a new archive. If the unpacking is not done with root permissions, then all the temporary files will be owned by the user who is doing the unpacking, so when the files are packed into the new archive, they will end up being owned by that user.

Alien doesn't actually need to run as root since it doesn't need to modify anything in the system. Fakeroot runs alien (or any other command) in an environment where that command receives fake information about filesystem operations, pretending that operations that normally require root (such as changing file ownership) have succeeded. This way, the unpacking is done as root and sets correct file owernship (as far as alien and its subprocesses are concerned) and thus the repacking creates the intended archive.

Related Question