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

Clone to smaller disk not working. #7

Open
mkomarsr opened this issue Jul 27, 2019 · 9 comments
Open

Clone to smaller disk not working. #7

mkomarsr opened this issue Jul 27, 2019 · 9 comments

Comments

@mkomarsr
Copy link

I'm running the latest clonepi (1.7.4) on the latest debian (10.0).

I narrowed part of the problem down to 'sed' not matching on the sfdisk output.

I made this change to move past that:
MBR=sfdisk -d $DEST_DISK
to
MBR=sfdisk -d $DEST_DISK|tr -s \

I don't have an old machine handy, but I suspect that the sfdisk output changed recently adding some spaces. Unsure if my approach was the best, but for testing purposes, it improved things.

What I'm running into now, is:
/dev/sda6: Start sector 204800 out of range.
Failed to add #6 partition: Numerical result out of range

Manually creating the same partition sizes results in a different starting sector.

My knowledge of file system partitioning leaves me short of a best solution here.

Any input is welcome. I'm happy to submit a PR but would like some input on what direction to go toward a resolution.

Thanks!

For reference:

root@tvpi:~# sfdisk -l /dev/mmcblk0
Disk /dev/mmcblk0: 59.5 GiB, 63864569856 bytes, 124735488 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xa8a452f2

Device Boot Start End Sectors Size Id Type
/dev/mmcblk0p1 8192 137215 129024 63M e W95 FAT16 (LBA)
/dev/mmcblk0p2 137216 124735487 124598272 59.4G 5 Extended
/dev/mmcblk0p5 139264 204797 65534 32M 83 Linux
/dev/mmcblk0p6 204800 729085 524286 256M c W95 FAT32 (LBA)
/dev/mmcblk0p7 729088 124735487 124006400 59.1G 83 Linux

and

root@tvpi:~# sfdisk -l /dev/sda
Disk /dev/sda: 29.7 GiB, 31914983424 bytes, 62333952 sectors
Disk model: Storage Device
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xa8a452f2

Device Boot Start End Sectors Size Id Type
/dev/sda1 8192 137215 129024 63M e W95 FAT16 (LBA)
/dev/sda2 137216 62333951 62196736 29.7G 5 Extended
/dev/sda5 139264 204799 65536 32M 83 Linux
/dev/sda6 206848 731135 524288 256M c W95 FAT32 (LBA)
/dev/sda7 733184 62333951 61600768 29.4G 83 Linux

@SpoddyCoder
Copy link
Owner

Thanks for the report and detail - currently travelling, so it'll be a few days before I can take a proper look - are you able to paste the ClonePi output?

If you do manage to find the fix before me - PR's are very welcome :)

@mkomarsr
Copy link
Author

mkomarsr commented Jul 28, 2019 via email

@mkomarsr
Copy link
Author

I've looked a little more at this and can see where the bad partitioning attempt is happening, but I'm not as well versed in partitioning as I'd like to be and as such am not sure what the correct values should be. I'll look again when I get some more time.

@mkomarsr
Copy link
Author

I've boiled it down to this:

The first thing the clone does is to use DD to replicate the partition table. Then it goes through and adjusts the partition sizes but doesn't do anything about the start block of the partitions.

I'm thinking a better approach in the event that the disks are being initialized is to instead of duplicating and then resizing the partitions, is to instead just create them from scratch with the sizes appropriate for the destination disk.

I may make that change in my fork and see where that gets me.

@SpoddyCoder
Copy link
Owner

Hey @mkomarsr - thanks for keeping the issue updated. You're correct - the approach is to do partial dd to copy the MBR (& a few byes to beyond) - and then let rsync copy the actual filesystem contents. A more refined approach would be what you're suggesting to build it from scratch - tho my feeling is there may be more devil in the detail than there than it initially seems.

If you find a full solution to your issue, please do submit a PR and I will try to review it along with your first PR.

Apologies for the slow responses - work has kept me busy the last few weeks.

@mkomarsr
Copy link
Author

I certainly did discover the devil in those details. :) ... I think I have something getting it done though. I was hesitant on my current approach initially. I liked the idea of pulling as much data from the source filesystem as possible ... but... after some consideration I decided that the idea here (I think) is to clone NOOBS created SD cards. So in theory the partitions should always be the same (other than different sizes based on the card capacity) ... So I'm pretty happy with the direction I'm going. If you agree and it can get pulled back into your branch, that'd be awesome. If not, maybe it'll just be a fork.

@mkomarsr
Copy link
Author

Any more thoughts on this?

@SpoddyCoder
Copy link
Owner

Thanks for chasing up @mkomarsr - the issue is now understood and a fix will be released in the next week or so.

@crankynet
Copy link

Looks like I ran into this issue. Because I want to move my system from a Pi 3 to a 4, I cloned an SD card but the card won't boot either on my Pi 4 or Pi 3. Found out the copied card is slightly smaller than my source card even though they both are from Sandisk and both are sold as 32GB SD card.

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

3 participants