I'm running tar on a complete remote filesystem using

ssh -n <hostname> 'sudo tar -cpvzf - --one-file-system /' | cat > Bak.tar.gz

This gave me a tarball. I tried importing this tarball into another service I'm using and ran into an issue because it appears it did not include the /dev directories. I'm wondering if I can do something like --include="/dev" or /dev after the initial tar. Need some guidance here.


Just add /dev onto the list of files to archive:

ssh -n <hostname> sudo tar -cpvzf - --one-file-system / /dev > Bak.tar.gz

--one-file-system only prevents recursing into directories on different filesystems. You can still list files/directories on different filesystems directly as arguments to tar.


You could probably simply add it to the pathnames to be included.

tar -cf - --one-file-system / /dev/

However this is usually not what you really want at all, as the dynamic /dev would include way too many completely wrong or irrelevant device nodes.

A better way (better in the sense of actually getting a complete copy of the original root filesystem, including files hidden by other mounts) to do it is to make another mount of the filesystem, which is not obstructed by submounts, and tar that.

That way you get the /dev/ (and everything else) that is actually stored on the root filesystem. That should usually include only a standard set of /dev nodes that was originally created at install time, and only needed at boot time until the system sets up the dynamic /dev/ on top of it.

mkdir /mnt/root
mount --bind / /mnt/root
cd /mnt/root
tar -cpvzf - .
cd /
umount /mnt/root

As the mount manpage states, the bind mount call attaches only (part of) a single filesystem, not possible submounts. That's why the --one-file-system is no longer needed: there are no other filesystems under this structure.

  • How do I do all that over ssh and port the pipe the tar over ssh – kevzettler Dec 4 '13 at 20:43
  • ssh host 'mkdir /mnt/root;mount --bind / /mnt/root;cd /mnt/root;tar ......' > piped.tar but usually you'd just put this in a script you store and execute on the server. Esp. as you should be doing some extra checks (does the mount point already exist, is it already mounted, any errors executing tar etc. etc.). The pipe works despite the other commands as long as tar is the only command actually outputting anything to stdout. – frostschutz Dec 4 '13 at 21:22

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.