This is a follow up post to the ones immediately above re: converting an SD card from a seven partition NOOBS to a two partition plain Raspbian with unallocated free space at the end. This is a way around the problem of Apple Pi-Baker and DD complaining that the source image is larger than the destination SD card.
Read the outline in the post above before going farther. That gives you an overview of the process without a lot of confusing detail. This post will fill in the details.
Warning: I'm a Raspberry Pi and Linux newby. There may be better or less risky ways to accomplish these tasks. Consider this a proof of concept and not a polished methodology.
COPY BOOT & ROOT PARTITION IMAGES INDIVIDUALLY TO HARDDRIVE FROM SD CARD (ON MAC)
diskutil list
sudo diskutil unmount /dev/disk6s6 ## change to your SD card disk & partition numbers
cd /volumes/"Internal Raid" ## Change to your destination directory.
sudo dd if=/dev/rdisk6s6 of=boot.dmg bs=4096; sync
sudo dd if=/dev/rdisk6s7 of=root.dmg bs=8192; sync
CALCULATE BYTES NEEDED FOR THE NEW PARTIONS (ON Rpi)
<span style="font-size: 16px;">Put the card you just made images from back in your Rpi and use fdisk or gparted to look at the partition sizes.</span>
sudo fdisk -l /dev/sda
Sectors used 56609800 * 512 bytes = 28984217600 bytes (This is my root)
If you have to calculate sectors used from the starting and ending sector numbers, don't forget to add 1 after subtracting.
boot 2488319 - 2359296 = 129023+ 1= 129024 * 512 = 66060288 bytes
FORMAT AND PARTITION SD CARD (ON MAC)
<span style="font-size: 16px;">Format SD card with 3 partions: two FAT and 1 Free Space.</span>
Disk utility is confusing when specifying the size of a partition. It uses a strange definition of GB. Set a partition to 29GB but it ends up as: 29,000,003,584 bytes when it should be 3113851289.
It's easiest to use the command line using bytes from your sector calculations and your SD card drive number from Disk Utility
diskutil partitionDisk /dev/disk6 MBRFormat MS-DOS BOOT 66060288B MS-DOS ROOT 29000003584B free FREE 0B
COPY INDIVIDUAL PARTION IMAGES FROM HARD DRIVE TO SD CARD on MAC
BOOT
cd /volumes/"Internal Raid" (Change to where you stored your images.)
diskutil list
sudo diskutil unmount /dev/disk6s1 (Change to your destination SD card as reported by diskutil.)
sudo dd if=boot.dmg of=/dev/disk6s1 bs=4096; sync (Change disk number)
ROOT
sudo diskutil unmount /dev/disk6s2 (Change disk number)
sudo dd if=root.dmg of=/dev/disk6s2 bs=4096; sync (Change disk number)
<span style="font-size: 16px;">This can take awhile. A 29GB root partition took me anywhere from 3 to 8 hours depending on the speed of the destination card.</span>
CHECK THE FILE SYTEM ON THE NEW CARD (ON Rpi)
Mount the new card in a USB slot on the Rpi.
umount /dev/sda1 (Check disk number matches your system)
sudo fsck -n /dev/sda1 (Check disk number)
No errors should be reported
umount /dev/sda2 (Check disk number)
sudo fsck -n /dev/sda2 (Check disk number)
No errors should be reported
Use gparted to look at the partitions on the new SD card.
sudo gparted
It should show unallocated space at the end of two partitions.
A boot partition of 63Mib (At least for my NOOBS distribution.)
A root partition whose size will vary. Mine shows 27.01GiB, 21.67 unused with 4.7GiB used. Mine has a warning that there is 656.56Mib of unallocated space within the partition. I don't know why that's there or the possibility it might cause a problem later. (Maybe if I filled up the 21.67 unused space.)
EDIT cmdline.text and fstab ON THE NEW CARD (ON Rpi).
With the new card mounted in a USB slot on the Rpi.
Edit /boot/cmdline.txt on the “New” card changing: partition p6 to p1 & partition p7 to p2
Edit /root/etc/fstab “New” card changing: partition p7 to p2
SHUTDOWN THE Rpi AND BOOT FROM YOUR NEW CARD (ON Rpi)
If it doesn't boot, look at the troubleshooting steps below.
If they're no help, make a post here with the last text showing on the display where it hangs up.
MAKE COPIES OF THE NEW SD CARD USING APPLE PI-BAKER (ON MAC)
Now you're ready to make a backup copy of the entire new card onto your harddrive using Apple Pi-Baker. After that, you can easily make (restore) as many clones as you want.
Apple Pi-Baker will report during the restore that the image is too large for the card. That's OK, the bytes at the end of the copy that don't fit and are lost are part of the 1GB or more of unallocated space of the third partition.
TROUBLESHOOTING
If format fails with "Unable to write to the last block of the device." or "File System Formatter Failed", format TWICE in a camera. If that doesn't work try HP USB Disk Storage Format Tool - v2.1.8
< http://files.extremeoverclocking.com/file.php?f=197> The errors came up in The Disk Utility application. Formatting from the command line might have different error messages.
<span style="font-size: 16px;">----</span>
If dd finishes with "end of device". This seems to mean the copy stopped because it ran into the end of the partition. You probably made the partition to small--recheck your calculations.
---------
If you get "FAIlED Unknown block(179,1)" on Rpi bootup with the new card, it most likely means that Rpi can't find the root file system.
- check cmdline.txt and fstab to make sure you changed them correctly
- use gparted and make sure the root partition isn't pure white but shows an appropriate amount of beige content. I've see the pure white when I apparently didn't make the root partition large enough and the DD copy to the SD card ended with: "end of device":
Summary
There are two reasons to go through all this.
1. To convert a NOOBS SD card to plain Raspbian for whatever good reason you have.
2. To reduce the size of your NOOBS SD card so you can copy it to a slightly smaller SD card. NOOBS has extra partitions. Only two are needed. The rest use roughly 1GB of space--most of it by the Recovery partition.
This is proof of concept that almost all the work can be done on the Mac and probably automated. Editing two text files are the critical parts that are easier on the Rpi.
Have fun,
Irv Kanode