0

I compiled a Linux rootfs in a folder on a remote server. I need to download it and put it into an SD card on a local compter, and use it to boot an embedded computer. How can I preserve every attribute of the files when downloading them? Thanks.

1
  • Would Tar or Zip work? On opening the archive, most attributes would stay the same, but ownership might become that of the user. Jul 18 '19 at 21:23
0

tar should be able to do it. It stores information about ownership and permissions and is recursive by default. I understand at the end the ownership of the files on the SD card should rely neither on users or groups defined on the server, nor on users or groups defined on the local computer; so --numeric-owner is a good idea.

While extracting you need to use --same-owner and --same-permissions flags (which are default if you do it as root).


If you have the authority on the remote server to mount a file as a block device (losetup), you can create a filesystem within the file, mount, then deploy your files to it so they "preserve every attribute" (sudo cp -a). Then (after umount, sync and losetup -d) you download the said file only and push it raw to a partition of a local SD card (with dd, cp, cat or whatever) or mount it locally and retrieve the files.

Note many mkfs tools can operate on a regular file. Also modern implementations of mount can mount a regular file semi-directly (doing all losetup-related things for you). You probably wont have to explicitly use losetup at all. It may be like:

# on the server
truncate -s <desired_image_size> image
mkfs.<type> <options> image
sudo mount image <mountpoint>
sudo cp -a <directory>/* <mountpoint>/    # warning: * doesn't match dotfiles
sudo umount <mountpoint>

Even if you need additional steps that cannot be done on the server, downloading files in a form of a whole filesystem guarantees that all features supported by the filesystem will remain during transfer. Your concern is to preserve them while copying from/to another filesystem, but the transfer itself cannot alter them. In some cases this may be better than tar, especially if you need "exotic" features (which doesn't seem to be the case here though). Therefore this method is the most generic.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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