The problem is that you're using the -X option incorrectly. The -X (or --exclude-from) option expects a file that contains a list of patterns, not the patterns themselves. In your command, the shell expands /proc/*, /dev/*, etc., and passes those as file names for tar to read exclusion patterns from. Since those files (or directories) aren’t written in the expected exclusion pattern format, tar behaves unexpectedly—or even appears to hang.
In addition, when you archive from / and write the tarball to a subdirectory (here /tmp), you risk including the archive file into the archive unless you explicitly exclude it. This can cause tar to try to read from an output file that's still growing, leading to errors or hanging behavior.
Here’s how to fix it:
1. Use --exclude Instead of -X
Replace the -X options with --exclude and give the patterns directly to tar. For example, if you want to exclude everything under /proc, /dev, /sys, and /tmp, you can write:
tar --exclude=/proc \
--exclude=/dev \
--exclude=/sys \
--exclude=/tmp \
-czf /tmp/malix.tgz /
Note:
-
Excluding /tmp means that the entire /tmp directory won’t be archived. If you’re writing the archive into /tmp, then you need to either write it somewhere else (like /root) or exclude only the specific file from /tmp.
-
If you want to archive most of / but not include the tarball in /tmp, you can do:
tar --exclude=/tmp/malix.tgz \
--exclude=/proc \
--exclude=/dev \
--exclude=/sys \
-czf /tmp/malix.tgz /
2. Avoid Archiving the Archive File
If you create the archive in a directory that you’re archiving (like /tmp), you might accidentally include it unless you exclude it explicitly (as shown above). A safer approach is to write the tarball outside of the directories being archived. For example:
tar --exclude=/proc \
--exclude=/dev \
--exclude=/sys \
--exclude=/tmp \
-czf /root/malix.tgz /
Then, if needed, move the archive where you want it.
3. General Advice When Working in Containers
If your goal is to capture the entire container filesystem, consider using Docker’s export capability from the host rather than running tar inside the container. For instance:
docker export <container-id> | gzip > /path/on/host/malix.tgz
This command avoids dealing with pseudo-filesystems like /proc and /sys altogether, as Docker’s export omits them by design.
Summary
Your original command:
tar -X /proc/* -X /dev/* -X /sys/* -X /tmp/* -czf /tmp/malix/tgz /
has two issues:
- Wrong Exclusion Option: Replace each
-X /pattern/* with --exclude=/pattern.
- Archiving the Archive File: Ensure the output tar file isn’t being included in the archived tree.
A corrected command might be:
tar --exclude=/tmp/malix.tgz \
--exclude=/proc \
--exclude=/dev \
--exclude=/sys \
-czf /tmp/malix.tgz /
or, safer, create the archive outside of directories you want to archive:
tar --exclude=/proc \
--exclude=/dev \
--exclude=/sys \
--exclude=/tmp \
-czf /root/malix.tgz /
This should work without hanging and produce a proper tarball.