0

I have downloaded the boot partition from a server I needed a local copy of using dd and SSH. I can boot up the partition using a virtual machine, however, I have noticed some file names are corrupted. It seems like the files were in use during the process. The filenames now look like ;68;48:70;10 (random example of the format) instead of letters. I have determined the numbers correspond to the ASCII codes of the file name. How can I fix the filenames so I can use the server copy for local development?

1 Answers1

0

You should never do a block device copy when any partition in it is mounted with write capability for the exact reason you discovered on your own: Files may be written as the copy is happening.

This is why there is the handy-dandy rsync command, which copies individual files from a mounted file system. There is no risk of corrupting the file system because it maintains in control of the writes. My answer in Copy (almost) entire filesystem with minimal effort can help you craft an appropriate rsync command to copy your file system.

If you don't know how to mount a partition without putting it into a virtual machine, you can create the disk image with truncate -s 1G disk.img (where 1G is the size of the desired disk and disk.img is a file name of your choice) and then turn it into a block device by loopback with losetup. You can then partition the loopback device like a real disk, mount the partition you want, and then use rsync to copy the files from the server.


If you really want to do a block device copy, you can remount the source file system as read only (mount -o remount,ro) before starting the copy. Obviously, there will be side effects if something on the source tries to modify a file it can no longer modify, and you cannot do this if the mount is busy.

If you cannot remount as read-only, you would have to reboot the source into a rescue environment where the source data would not be mounted, but this means downtime and a lot of hassle.

Deltik
  • 19,971