Linux Filesystems – How to Copy a Filesystem Exactly As Is

cpfilesystemslinuxrsync

I have a file system for a device I am programming that I would like to make an exact copy of. Ideally I would like this copy to be identical to the folder that it was copied from. I have tried using cp -r cp -a and rsync -azvP to try to achieve this. Each one though results in a folder with different size (using du -s) and ultimately,even though my device runs off of the original folder, it won't run off of the one that I copied.

  • What is getting left out that the commands I have used aren't accounting for?
  • Is it possible to keep everything identical when copying a file system/folder? If so how would I go about doing that?

P.S. I posted a similar questions on StackOverflow but quickly realized I had asked it on the wrong exchange


Edit:
This may not be helpful but no matter which method I use the copied directory always causes the machine in question to Kernel Panic with the following output.

VFS: Unable to mount root fs via NFS, trying floppy. VFS: Cannot open
root device "nfs" or unknown-block(2,0) Please append a correct
"root=" boot option; here are the available partitions: 1f00
64 mtdblock0 (driver?) 1f02 64 mtdblock2 (driver?) 1f04
2432 mtdblock4 (driver?) 1f05 128 mtdblock5 (driver?)
1f06 4352 mtdblock6 (driver?) 1f07 204928
mtdblock7 (driver?) 1f08 50304 mtdblock8 (driver?) 0800
8388608 sda driver: sd Kernel panic – not syncing: VFS: Unable to
mount root fs on unknown-block(2,0)

Best Answer

I generally use one of the following alternatives:

  • rsync -aHAX (add v for verbosity) makes sure that you preserve any link structure and x-attrs in the target folder while copying. Don't forget a means archive and preserves time, ownership and permissions already.
  • Simple tar cvf (don't compress to save time, just tar them up) is what I use if the first one doesn't meet what I need for whatever reason and I have no time, but I always try the first one.

To check that everything went as it should, you can run diff -r <folder1> <folder2> afterwards if you want.

Related Question