1

I'm trying repeatedly to copy one folder between two partitions in the same disk. Both partitions uses the same filesystem ext4. I use cp command but some files are not exactly copied. I want to know how to make an exact copy.

rodrigorodriguez@Geminis005:~$ uname -a
Linux Geminis005 5.4.0-52-generic #57-Ubuntu SMP Thu Oct 15 10:57:00 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux

rodrigorodriguez@Geminis005:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 20.04.1 LTS
Release:    20.04
Codename:   focal

rodrigorodriguez@Geminis005:~$ cp -i -r /mnt/e04ba234-8b05-4f4b-b879-e1161e4d205e/VirtualBox/VBoxVMs/WXP_SP3_Activ20200808_COA_PH247 /home/rodrigorodriguez/Documentos

rodrigorodriguez@Geminis005:~$ diff -r -q /mnt/e04ba234-8b05-4f4b-b879-e1161e4d205e/VirtualBox/VBoxVMs/WXP_SP3_Activ20200808_COA_PH247 /home/rodrigorodriguez/Documentos/WXP_SP3_Activ20200808_COA_PH247
Los archivos /mnt/e04ba234-8b05-4f4b-b879-e1161e4d205e/VirtualBox/VBoxVMs/WXP_SP3_Activ20200808_COA_PH247/Snapshots/{3d70c7f3-06bc-451d-8611-a12e13e2ad13}.vdi y /home/rodrigorodriguez/Documentos/WXP_SP3_Activ20200808_COA_PH247/Snapshots/{3d70c7f3-06bc-451d-8611-a12e13e2ad13}.vdi son distintos
Los archivos /mnt/e04ba234-8b05-4f4b-b879-e1161e4d205e/VirtualBox/VBoxVMs/WXP_SP3_Activ20200808_COA_PH247/WXP_SP3_Activ20200808_COA_PH247.vdi y /home/rodrigorodriguez/Documentos/WXP_SP3_Activ20200808_COA_PH247/WXP_SP3_Activ20200808_COA_PH247.vdi son distintos

The other files were copied successfully. I tried to copy, one by one, the two files that failed but the problem remains. These are large files:

odrigorodriguez@Geminis005:~$ ls -l /mnt/e04ba234-8b05-4f4b-b879-e1161e4d205e/VirtualBox/VBoxVMs/WXP_SP3_Activ20200808_COA_PH247/Snapshots/{3d70c7f3-06bc-451d-8611-a12e13e2ad13}.vdi
-rw------- 1 rodrigorodriguez rodrigorodriguez 406847488 oct 23 14:27 /mnt/e04ba234-8b05-4f4b-b879-e1161e4d205e/VirtualBox/VBoxVMs/WXP_SP3_Activ20200808_COA_PH247/Snapshots/{3d70c7f3-06bc-451d-8611-a12e13e2ad13}.vdi
rodrigorodriguez@Geminis005:~$ ls -l /mnt/e04ba234-8b05-4f4b-b879-e1161e4d205e/VirtualBox/VBoxVMs/WXP_SP3_Activ20200808_COA_PH247/WXP_SP3_Activ20200808_COA_PH247.vdi
-rw------- 1 rodrigorodriguez rodrigorodriguez 4349493248 sep 16 05:21 /mnt/e04ba234-8b05-4f4b-b879-e1161e4d205e/VirtualBox/VBoxVMs/WXP_SP3_Activ20200808_COA_PH247/WXP_SP3_Activ20200808_COA_PH247.vdi

I've also tried rsync with the same result:

rodrigorodriguez@Geminis005:/mnt/e04ba234-8b05-4f4b-b879-e1161e4d205e/VirtualBox/VBoxVMs$ rsync -a -v --delete WXP_SP3_Activ20200808_COA_PH247 /home/rodrigorodriguez/Imágenes/
sending incremental file list
WXP_SP3_Activ20200808_COA_PH247/
WXP_SP3_Activ20200808_COA_PH247/WXP_SP3_Activ20200808_COA_PH247.vbox
WXP_SP3_Activ20200808_COA_PH247/WXP_SP3_Activ20200808_COA_PH247.vbox-prev
WXP_SP3_Activ20200808_COA_PH247/WXP_SP3_Activ20200808_COA_PH247.vdi
WXP_SP3_Activ20200808_COA_PH247/Logs/
WXP_SP3_Activ20200808_COA_PH247/Logs/VBox.log
WXP_SP3_Activ20200808_COA_PH247/Logs/VBox.log.1
WXP_SP3_Activ20200808_COA_PH247/Logs/VBox.log.2
WXP_SP3_Activ20200808_COA_PH247/Logs/VBox.log.3
WXP_SP3_Activ20200808_COA_PH247/Snapshots/
WXP_SP3_Activ20200808_COA_PH247/Snapshots/{3d70c7f3-06bc-451d-8611-a12e13e2ad13}.vdi

sent 4,758,018,024 bytes  received 192 bytes  62,196,316.55 bytes/sec
total size is 4,756,855,903  speedup is 1.00

rodrigorodriguez@Geminis005:/mnt/e04ba234-8b05-4f4b-b879-e1161e4d205e/VirtualBox/VBoxVMs$ diff -r -q WXP_SP3_Activ20200808_COA_PH247 /home/rodrigorodriguez/Imágenes/WXP_SP3_Activ20200808_COA_PH247
Los archivos WXP_SP3_Activ20200808_COA_PH247/Snapshots/{3d70c7f3-06bc-451d-8611-a12e13e2ad13}.vdi y /home/rodrigorodriguez/Imágenes/WXP_SP3_Activ20200808_COA_PH247/Snapshots/{3d70c7f3-06bc-451d-8611-a12e13e2ad13}.vdi son distintos
Los archivos WXP_SP3_Activ20200808_COA_PH247/WXP_SP3_Activ20200808_COA_PH247.vdi y /home/rodrigorodriguez/Imágenes/WXP_SP3_Activ20200808_COA_PH247/WXP_SP3_Activ20200808_COA_PH247.vdi son distintos

Thanks to comments of @xiota and Adriaan, I learned that it's necessary to be sure that files are not in use. Thus I copied the files just after my PC started. This way those files copied successfully. But the problem arises again when I copy other files. I've started the PC and I've copied two files:

rodrigorodriguez@Geminis005:~$ ls -l /mnt/f26fa231-3c3c-4bbd-8449-1a46bb90ca7a/VBox/VBoxVMs/W7Pro_32bit_COA_34VDK/Snapshots
total 26209300
-rwxrwxr-x 1 rodrigorodriguez rodrigorodriguez  5872025600 oct 26 19:34 {05c2e7c2-1cac-421e-a0b3-5b31b6d5f68c}.vdi
-rw------- 1 rodrigorodriguez rodrigorodriguez   468713472 oct 27 06:11 {17cb8409-3c46-4f9e-916e-fbb1e4194b02}.vdi
-rwxrwxr-x 1 rodrigorodriguez rodrigorodriguez 16865296384 oct 26 19:34 {3d97d24f-7795-446a-9bd1-76342bfe9be4}.vdi
-rwxrwxr-x 1 rodrigorodriguez rodrigorodriguez  3983540224 oct 27 05:37 {6e6a3122-96c9-4bcb-b2b9-35a9571d2257}.vdi

Before to copy I verify that nothing is open in mounted partition and then I copy the file:

rodrigorodriguez@Geminis005:~$ lsof | grep "f26fa231"
rodrigorodriguez@Geminis005:~$ cp -i /mnt/f26fa231-3c3c-4bbd-8449-1a46bb90ca7a/VBox/VBoxVMs/W7Pro_32bit_COA_34VDK/Snapshots/{17cb8409-3c46-4f9e-916e-fbb1e4194b02}.vdi ~/Documentos/VMTemp/{17cb8409-3c46-4f9e-916e-fbb1e4194b02}_2.vdi
rodrigorodriguez@Geminis005:~$ cmp -l /mnt/f26fa231-3c3c-4bbd-8449-1a46bb90ca7a/VBox/VBoxVMs/W7Pro_32bit_COA_34VDK/Snapshots/{17cb8409-3c46-4f9e-916e-fbb1e4194b02}.vdi ~/Documentos/VMTemp/{17cb8409-3c46-4f9e-916e-fbb1e4194b02}_2.vdi

rodrigorodriguez@Geminis005:~$

This file (500Mb) copied OK but next file (4Gb) failed:

rodrigorodriguez@Geminis005:~$ cp -i /mnt/f26fa231-3c3c-4bbd-8449-1a46bb90ca7a/VBox/VBoxVMs/W7Pro_32bit_COA_34VDK/Snapshots/{6e6a3122-96c9-4bcb-b2b9-35a9571d2257}.vdi ~/Documentos/VMTemp
rodrigorodriguez@Geminis005:~$ cmp -l /mnt/f26fa231-3c3c-4bbd-8449-1a46bb90ca7a/VBox/VBoxVMs/W7Pro_32bit_COA_34VDK/Snapshots/{6e6a3122-96c9-4bcb-b2b9-35a9571d2257}.vdi ~/Documentos/VMTemp/{6e6a3122-96c9-4bcb-b2b9-35a9571d2257}.vdi
  73293892   0  20
  73293916 277  57
  73293932 277  57
**[...] Here is a list with 870 different bytes**

I've verified again that nothing is open and I've made a backup of the complete lsof output:

rodrigorodriguez@Geminis005:~$ lsof | grep "f26fa231"
rodrigorodriguez@Geminis005:~$ lsof > ~/Documentos/lsof.txt

It's unclear for me what others steps I need to consider or if It's better to use other commands. Anyway I've tested the copied virtual machine and works well. It seems like the differences are not relevant in this case. But for general use I think it's important for me to know better the right use of CP command.

Thanks in advance for your help.

4
  • 3
    Are the files in use while copying? Make sure all virtual machines are shut down.
    – xiota
    Oct 24, 2020 at 6:07
  • 1
    Verify the shutdown with lsof | grep "/mnt/e04ba234-8b05-4f4b-b879-e1161e4d205e".
    – Adriaan
    Oct 24, 2020 at 7:29
  • 1
    Thanks a lot to @xiota and Adriaan. That is the solution. I had closed VirtualBox but maybe some files were still open. Today I just started the PC with only Terminal open and I've made the same operations without problem. I'm not sure if commenting is the right way to notify the question is solved or if I need to post an answer.
    – ConsJMEA
    Oct 24, 2020 at 15:15
  • 1
    @ConsJMEA You don't need to do anything, but if you feel the answer would be helpful to other people, or yourself in the future, you can write an answer. A couple paragraphs should be sufficient... explaining that file mismatches could be caused by changes after or while the file is copied... then how to make sure files aren't in use.
    – xiota
    Oct 24, 2020 at 15:30

0

You must log in to answer this question.

Browse other questions tagged .