Copy MBR and boot partition to a smaller disk

ddfdiskmbrraspberry pi

I'm using a 32GB SD card for my raspberry pi. I have successfully transferred the operating system (Archlinux ARM) to a usb harddrive. Which means that I only need the boot partition on the SD card.

A 32GB card that only uses about 100MB is an awful waste of space and I do have a smaller SD card with 4GB around.

How do I copy the MBR and the first partition of the 32GB card to the 4GB card?

I've tried saving the MBR and the first partition of the bigger card with dd:

dd if=/dev/sdb of=mbr_image bs=446 count=1
dd if=/dev/sdb1 of=boot_image

I then created a new partition table on the smaller card
that looks exactly like the table on the original 32GB card:

Device    Boot Start       End Blocks  Id System
/dev/sdc1 *     2048    194559  96256  c  W95 FAT32 (LBA)

Finally I copied the previously stored images onto my smaller card:

dd if=mbr_image of=/dev/sdc bs=446 count=1
dd if=boot_image of=/dev/sdc1

Everything looks fine in fdisk but it does not work.
My raspberry doesn't do anything when I try to boot from the smaller card.

Where is the error?

Best Answer

In my case I've been having trouble just copying MBR. For me the next steps worked:

  1. fdisk the new card with the partitions you want.

  2. Mount the new card and cp the partition files you want (I guess it is just boot partition) from the old one to the new one. Modify (in case you're using grub2) /boot/grub/grub.cfg in the new card so that the UUID of the boot partition is now the one of your 4GB card (use blkid to identify the UUID).

  3. Start the system with the 32GB card and mount the 4GB card.
  4. mount --bind /dev, /proc and /sys from the old card to the new one.
  5. chroot to the mounted 4GB card.
  6. grub-install to your 4GB card.

EDIT: Steps 4-6 can be replaced by grub-install --boot-directory=YourPathToMounted4GBBoot /dev/your4GBcard

Related Question