Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't clone if boooting from USB #19

Open
thalesmaoa opened this issue Apr 23, 2024 · 8 comments
Open

Can't clone if boooting from USB #19

thalesmaoa opened this issue Apr 23, 2024 · 8 comments

Comments

@thalesmaoa
Copy link

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?

@tom-2015
Copy link
Owner

tom-2015 commented Apr 24, 2024

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

@thalesmaoa
Copy link
Author

thalesmaoa commented Apr 24, 2024

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

@tom-2015
Copy link
Owner

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.

@thalesmaoa
Copy link
Author

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

@tom-2015
Copy link
Owner

not that should not be a problem

@thalesmaoa
Copy link
Author

thalesmaoa commented Apr 28, 2024 via email

@kdurlu
Copy link

kdurlu commented May 2, 2024

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

@thalesmaoanz
Copy link

thalesmaoanz commented May 3, 2024

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");

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants