Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I want to create an image (for example ext3 image) from a given directory hierarchy. This directory hierarchy is owned by a given user. But on the final image, I want the files to be owned by superuser. Is there a solution for tranlating the user uid / gid to 0 ?

Here is a pseudo workflow :

  1. Create file hierarchy, as user in /home/user/rootfs

  2. Create an ext3 img on a file

  3. loop mount the empty img (as user or root) in /somewhere/loopmount

  4. cp -R --magic_uid_options 500=0 /home/user/rootfs /somewhere/loopmount

Or step 4 could be a normal copy and step 5 a clever find that would chown and chgrp recursively. Is there well known solution to this kind of problem ?

share|improve this question
add comment

2 Answers 2

I don't know any "--magic_uid_options" for the cp command and you don't need to be clever for doing recursive chown or chgrp.

In fact I would:

  • keep as much files/directory properties as possible when doing the copy (timestamp, ...)

    cp -pR /home/users/rootfs /somewhere/loopmount/
    
  • chown all to root:root:

    chown -R root:root /somewhere/loopmount
    
share|improve this answer
    
Your absolutely right. Just after asking the question I googled for recursive chown... -R is not that clever indeed ;) –  shodanex Feb 14 '12 at 20:33
    
man is also a good thing to start with ;) –  Ouki Feb 14 '12 at 22:32
add comment

You could make step 4, as root:

cd /home/user/rootfs
pax -rw -pp . /somewhere/loopmount

-pp preserves modes and times but creates files owned by the user and group running pax.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.