imgclone icon indicating copy to clipboard operation
imgclone copied to clipboard

Can't clone if boooting from USB

Open thalesmaoa opened this issue 1 year ago • 10 comments

Hi @tom-2015, the program can't find the sd card to clone. That is true, since I'm not using it.

$ sudo ../imgclone -d mybackup.img
----    Raspberry Pi clone to image V1.8    ---
-----------------------------------------------
---- DO NOT CHANGE FILES ON YOUR SD CARD    ---
---- WHILE THE BACKUP PROGRAM IS RUNNING    ---
---- THE DESTINATION .IMG FILE MUST BE      ---
---- ON AN EXTERNAL STORAGE / NETWORK SHARE ---
-----------------------------------------------
Cloning /dev/mmcblk0 to mybackup.img
uuid | cut -f1 -d-
Error: Could not stat device /dev/mmcblk0 - No such file or directory.
$ lsblk
NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINTS
sda      8:0    0 119.2G  0 disk 
├─sda1   8:1    0   512M  0 part /boot/firmware
└─sda2   8:2    0 118.7G  0 part /

Is it possible to make it generic somehow, or specify the root partition?

thalesmaoa avatar Apr 23 '24 23:04 thalesmaoa

Yes I think if you change this line 676: sprintf(src_dev, "/dev/mmcblk0");

Change the /dev/mmcblk0 to the location of the USB drive, probably /dev/sda

tom-2015 avatar Apr 24 '24 16:04 tom-2015

I've made that and others, but now I'm getting the following error:

$ sudo ~/script/imgclone/imgclone/imgclone -d ./backup.img
----    Raspberry Pi clone to image V1.8    ---
-----------------------------------------------
---- DO NOT CHANGE FILES ON YOUR SD CARD    ---
---- WHILE THE BACKUP PROGRAM IS RUNNING    ---
---- THE DESTINATION .IMG FILE MUST BE      ---
---- ON AN EXTERNAL STORAGE / NETWORK SHARE ---
-----------------------------------------------
Cloning /dev/sda to ./backup.img
uuid | cut -f1 -d-
mktemp -d
mktemp -d
-----------------------------------------------
----    READING PARTITIONS               ------
-----------------------------------------------
Partition 1 start: 8192 end: 1056767 ptype:primary ftype:fat32 flags: lba
.Partition 2 start: 1056768 end: 250069679 ptype:primary ftype:ext4 flags: 
.partprobe
Last partition starts at 541065216 bytes.
mount /dev/sda2 /tmp/tmp.hIvCOWWMCW
df /tmp/tmp.hIvCOWWMCW | tail -n 1 | tr -s " " " " | cut -d ' ' -f 2
df /tmp/tmp.hIvCOWWMCW | tail -n 1 | tr -s " " " " | cut -d ' ' -f 4
Used size of last partition /tmp/tmp.hIvCOWWMCW is 7719178240 bytes.
umount /tmp/tmp.hIvCOWWMCW
Required size for destination image: 8435934208 bytes
-----------------------------------------------
----    ALLOCATING SPACE FOR .IMG FILE   ------
-----------------------------------------------
touch "./backup.img"
df "./backup.img" | tail -n 1 | tr -s " " " " | cut -d ' ' -f 1
192.168.200.254:/shared/NFS
df --output=avail -B 1 "./backup.img" | tail -n 1
852269727744
truncate --size 8435934208 "./backup.img"
-----------------------------------------------
----  CREATING DISK DEVICE FOR .IMG FILE ------
-----------------------------------------------
losetup --show -f "./backup.img"
dd if=/dev/zero of=/dev/loop0 bs=512 count=1
1+0 records in
1+0 records out
512 bytes copied, 0.00298593 s, 171 kB/s
Creating FAT on /dev/loop0.
parted -s /dev/loop0 mklabel msdos
-----------------------------------------------
----    CREATING PARTITIONS PLEASE WAIT  ------
-----------------------------------------------
parted -s /dev/loop0 mkpart primary fat32 8192s 1056767s
partprobe
lsblk -o name,uuid /dev/sda | grep sda1 | tr -s " " | cut -d " " -f 2
lsblk -o name,label /dev/sda | grep sda1 | tr -s " " | cut -d " " -f 2
blkid /dev/sda | rev | cut -f 2 -d ' ' | rev | cut -f 2 -d \"
mkfs.fat -F 32 -i 44FC6CF2 /dev/loop01
mkfs.fat: unable to open /dev/loop01: No such file or directory
mkfs.fat 4.2 (2021-01-31)
mkfs.fat -F 32 /dev/loop01
mkfs.fat: unable to open /dev/loop01: No such file or directory
mkfs.fat 4.2 (2021-01-31)
Could not create file system on uid 44FC6CF2: mkfs.fat -F 32 /dev/loop01

thalesmaoa avatar Apr 24 '24 18:04 thalesmaoa

That seems like something wrong with creating the partition on the .img file which is loaded in /dev/loop0 but I don't know why. Maybe take a look at what files are in /dev when you get the error or lsblk command to see which drives and partitions are found.

I see you run the program from you home directory (~) and you write the backup to the same directory? But the home directory is this also located on your boot USB drive? This because you cannot write the backup image on the same drive as you are backing up because then it will start to copy the backup.img file into the backup.img file like an endless loop... Insert an external drive and write the backup.img to that location.

tom-2015 avatar Apr 25 '24 17:04 tom-2015

I've mounted a nfs share inside the home folder. That should be a problem?

thalesmaoa avatar Apr 25 '24 18:04 thalesmaoa

not that should not be a problem

tom-2015 avatar Apr 28 '24 17:04 tom-2015

I manage to make it work.

Loop devices followw mmcblk0 pattern. In some cases, string p is expected when using sda.

Thanks a lot.

Em dom., 28 de abr. de 2024 14:07, Tom @.***> escreveu:

not that should not be a problem

— Reply to this email directly, view it on GitHub https://github.com/tom-2015/imgclone/issues/19#issuecomment-2081557740, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADLMFTPCHWBKND426I7ROVTY7UUGFAVCNFSM6AAAAABGV2TNG6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAOBRGU2TONZUGA . You are receiving this because you authored the thread.Message ID: @.***>

thalesmaoa avatar Apr 28 '24 19:04 thalesmaoa

I manage to make it work. Loop devices followw mmcblk0 pattern. In some cases, string p is expected when using sda. Thanks a lot.

Hi, I am also having the same issue. How did you solve it? What does string p refers to. Thanks

kdurlu avatar May 02 '24 11:05 kdurlu

132,133c132,134
<     if (!strncmp (device, "/dev/mmcblk", 11) || !strncmp(device, "/dev/loop", 9))
<         sprintf (buffer, "%sp", device);
---
>     if (!strncmp (device, "/dev/sda", 11) || !strncmp(device, "/dev/loop", 9))
>         sprintf (buffer, "%s", device);
422c423
<             if (uid) sprintf (buffer, "mkfs.fat -F 32 -i %s %s%d", uuid, partition_name (dst_dev, dev), parts[p].pnum);
---
>             if (uid) sprintf (buffer, "mkfs.fat -F 32 -i %s %sp%d", uuid, partition_name (dst_dev, dev), parts[p].pnum);
444c445
<             if (lbl) sys_printf ("fatlabel %s%d %s", partition_name (dst_dev, dev), parts[p].pnum, res);
---
>             if (lbl) sys_printf ("fatlabel %sp%d %s", partition_name (dst_dev, dev), parts[p].pnum, res);
449c450
<             if (uid) sprintf (buffer, "mkfs.ext4 -F -U %s %s%d", uuid, partition_name (dst_dev, dev), parts[p].pnum);
---
>             if (uid) sprintf (buffer, "mkfs.ext4 -F -U %s %sp%d", uuid, partition_name (dst_dev, dev), parts[p].pnum);
497c498
<             if (sys_printf ("mount %s%d %s", partition_name (dst_dev, dev), parts[p].pnum, dst_mnt))
---
>             if (sys_printf ("mount %sp%d %s", partition_name (dst_dev, dev), parts[p].pnum, dst_mnt))
639c640
< 		sys_printf ("rm %s%d", partition_name (dst_dev, dev), parts[p].pnum);
---
> 		sys_printf ("rm %sp%d", partition_name (dst_dev, dev), parts[p].pnum);
676c677,678
< 	sprintf(src_dev, "/dev/mmcblk0");
---
> 	sprintf(src_dev, "/dev/sda");

thalesmaoanz avatar May 03 '24 14:05 thalesmaoanz