0

Everybody knows - by raspi-config we can expand the image to the borders of the ext4 partition of the SD-card, but shrinking is impossible.

This will generate copy problems, using a second SD-card to copy to, with labeled same size, but in reality the usable space is a bit smaller (e.g. 8Gb SD-Card 1, 7,2 GB space usable; 8GB SD-Card 2, 7,1 GB space usable)

This means, even when the used space of the larger SD Card is (much) smaller than the available space of the fresh second SD-Card, win32DiskManager will not work as it can only copy physical blocks 1:1 ...

To overcome this situation shrinking the ext4 content of SD-card 1 is a Must to succeed

How to manage this situation technically?

My idea (e.g. with the below constraints):

SD-Card 1, labeled 8 GB, real space is 7.2 GB, Raspian Image is expanded to its boarders

fresh SD-Card 2, (labeled 8GB, real space is 7.1 GB, FAT32 - empty)

Additional Linux PC (e.g. Virtual Box VM running your Linux Guest on your Host windows 10 system)

Steps:

  1. Prepare the second (smaller) SD-card with a fresh Raspian image, boot and expand it by raspi-config to the SD-card borders.

  2. Mount the two SD-cards into your running virtual Linux system

  3. By File Archiving (not Partition Archiving!) "fsarchiver savedir ..." prepare a file archive from all files of the ext4 partition of the 1. (larger) SD-Card

  4. Delete all files in the ext4 partition of the second SD-Card (e.g. by "rm -r *")

  5. Use "fsarchiver restdir" to restore the archived ext4 files from the 1. SD-Card ext4 partition into the corresponding ext4 partition on the 2nd SD-card. As you are not copying the partition - but files, the slightly smaller ext4 partition of SD-Card 2 will now contain all ext4 files of the 1. SD-Card. The nautilus explorer confirms this!!!

  6. Unmount your 2nd SD-Card put into your Raspberry and boot ...!

I have tried this- no chance the boot fails! This method will only work when the second SD-card provides exactly the same ext4 space as the 1 SD-Card.

I am confused now, because I had assumed that copying files (and not partitions) could resolve the win32DiskManager Block Copy issue.

What is my error, please?

Your expert explanation is pretty much appreciated.

Thanks in advance

Karl
  • 3
  • 3

1 Answers1

0

I also make copies the way you describe and stumbled also about the problem you have: a copied SD Card does not boot. I found that the problem was the master boot record (MBR), the very first sector with 512 bytes on the storage. If it does not fit exactly to what Raspbian expects then it will not boot. Here is what you need to do to create the MBR with a Linux machine provided the unmounted SD Card is attached as /dev/sdb. You can look at the MBR with:

pc ~$ sudo hd -n 512 /dev/sdb

To create the MBR do:

pc ~$ sudo -Es
pc ~# dd if=/dev/zero of=/dev/sdb bs=512 count=1
pc ~# /bin/echo -ne '\x28\xe4\x3e\x4d' | dd of=/dev/sdb bs=1 seek=440
pc ~# /bin/echo -ne '\x55\xaa' | dd of=/dev/sdb bs=1 seek=510
pc ~# exit
pc ~$

Be aware that this will overwrite your existing partition table without warning and you
loose ALL data on the SD Card!

Based on this I have made a tested Howto prepare a SD card from a tar archive on a Linux machine but only using Linux commands.

Ingo
  • 42,961
  • 20
  • 87
  • 207