Rikily
Posts: 1
Joined: Mon Aug 10, 2015 5:39 pm

Moving /boot to smaller SD card

Mon Aug 10, 2015 6:02 pm

Hello all you Debian Gurus...

I installed Raspbian on a 32GB SD card, then moved the whole OS to a USB stick. Now the Pi uses only the /boot from the SD card to boot up. Is there a way to move the /boot to a smaller (250MB) SD card, I mean how can I make a bootable SD with only /boot?

Thanks a lot,
Riki

User avatar
DougieLawson
Posts: 37111
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Moving /boot to smaller SD card

Mon Aug 10, 2015 7:21 pm

You should be able to use dd to copy the /boot partition on /dev/mmcblk0p1 to another SDCard (or an *.img file). Or you can mount the new SDCard and use rsync. Or you can mount the new SDCard and use cp -R. [Pick your poison.]

If you're not using a direct dd copy of the first 122880 sectors then you'll need to create a new partition on a new SDCard in a USB SDCard reader with

fdisk /dev/sda
Command (m for help): n
Partition type
p primary (1 primary, 0 extended, 3 free)
e extended (container for logical partitions)
Select (default p): p
Partition number (1,3,4, default 1): 1
First sector (2048-15407103, default 2048): 8192
Last sector, +sectors or +size{K,M,G,T,P} (8192-122879, default nnnnnnnn): 122879

Created a new partition 1 of type 'Linux' and of size 56 MiB.

Command (m for help): w

mkfs.fat /dev/sda1
Once the filesystem is made you're ready to copy.

dd if=/dev/mmcblk0p1 of=/dev/sda1

mount /dev/sda1 /mnt
rsync -a /boot/ /mnt
umount /mnt

mount /dev/sda1 /mnt
cp -R /boot/* /mnt
umount /mnt



You could copy that on Windows if you can mount two SDCards simultaneously.


THIS WILL NOT WORK WITH NOOBS without lots of extra messing about, but if you've moved the rootfs you're probably not using NOOBS anyway.
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

User avatar
rpdom
Posts: 16121
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Moving /boot to smaller SD card

Mon Aug 10, 2015 7:28 pm

You could even dd the first part of the card (up to the end of the first partition) to a temporary file (maybe even in /run/shm - which is in RAM), then unmount /boot, swap the cards over (yes, while the Pi is running!) and dd the file back out to the new card. Then mount /boot again.

User avatar
DougieLawson
Posts: 37111
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Moving /boot to smaller SD card

Mon Aug 10, 2015 8:17 pm

rpdom wrote:You could even dd the first part of the card (up to the end of the first partition) to a temporary file (maybe even in /run/shm - which is in RAM), then unmount /boot, swap the cards over (yes, while the Pi is running!) and dd the file back out to the new card. Then mount /boot again.
Clever. 122880 * 512 sectors (56MB) isn't going to over load RAM. Once the RPi is booted you don't need /boot mounted unless you're running rpi-update.

Here's another option:
Boot from the SDCard
umount /boot
pop the card out, pop a new card in
create a /dev/mmcblk0p1 partition (as above - starts at 8192, ends at 122879)
mkfs.fat /dev/mmcblk0p1
mount it as /boot
run rpi-update to populate it with 4.1.4 #807

All that's left to copy are cmdline.txt and config.txt (and initramfs if you've got one) back from the original SCard. You could stash copies of those in /tmp before working on the new SDCard.
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

Return to “Raspbian”