Extend boot partition of rasperry

Extend boot partition of rasperry

  1. Download the Raspbian Lite image, and extract/unzip

  2. Code:

    1
    kpartx -u -v /Downloads/2018-06-27-raspbian-stretch-lite.img

    (Change as appropriate image for image name, and assume that it created loop0, loop0p1 & loop0p2 )

  3. Code:

    1
    fdisk -l /dev/loop0

    Disk /dev/loop0: 1.8 GiB, 1862270976 bytes, 3637248 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: 0x4d3ee428

    Device Boot Start End Sectors Size Id Type
    /dev/loop0p1 8192 96663 $88472$ 43.2M c W95 FAT32 (LBA)
    /dev/loop0p2 98304 3637247 $3538944$ 1.7G 83 Linux

    The important part here is the number of sectors for the linux/ext4 partition number 2 ($3538944$ above), will be used in creating partition 2 below.

  4. Code:

    1
    blkid /dev/loop0

    Look for the PTUID value, like the below, to be used in fdisk below.

    /dev/loop0: PTUUID=”4d3ee428” PTTYPE=”dos”

  5. insert SD card and locate the sd? device name/number, in my case it was /dev/sdd

  6. Code:

    1
    fdisk /dev/sdd
  7. delete any/all partitions and start with a MBR partition table

  8. create the boot partition (primary 1) with the needed size. with the start $8192$ (I’m not sure if it makes a diffference, but rather keep that !

  9. 't' (type) and set it as 'c' (Win Fat32 lba)

  10. print the table using the 'p' command

  11. create the 2nd primary partition

  12. use the last sector number of the first partition as start, 'fdisk' will barf on it, but then it’ll give a more “appropriate” start than $2048$.

  13. use the size of the loop0p2 partition’s number af sectors to define the end, by prepending a + to the number, like:

    Code:

    1
    +3538944

    using my values from fdisk -l /dev/loop0 above.

  14. go to expert mode using: 'x'

  15. set the disk identifier using the 'i' command

  16. using the above example/information: 0x4d3ee428 (remember the 0x infront !)

  17. exit to normal mode: 'r'

  18. write the partition table to disk 'w'

  19. Code:

    1
    mkfs.fat -n "boot       " -F 32 /dev/sdd1

    the extra spaces is what is/was in the original (find that with file -Ls /dev/loop0)

  20. Code:

    1
    2
    3
    mkdir /tmp/sd1 /tmp/lp1
    mount /dev/mapper/loop0p1 /tmp/lp1
    mount /dev/sdd1 /tmp/sd1

    Now we’ve mounted the partitions to copy data from

  21. Code:

    1
    rsync -vaP /tmp/lp1/ /tmp/sd1/

    and this copies the boot partition’s data

  22. Code:

    1
    2
    dd if=/dev/mapper/loop0p2 of=/dev/sdd2 status=progress bs=4M

    This copies the Raspbian linux FS to the SD card

  23. Code:

    1
    2
    vi /tmp/sd1/cmdline.txt

    remove the quiet portion to see atleast if the kernel is booting, and double check the root=PARTUUID=4d3ee428-2 part, and you’ll read it as the device ID appended with a dash (-) and the partition number of the root FS. If the device ID/partuuid changes, you’ll also need to fix some other stuff inside the root FS (like the /usr/lib/raspi_config/init_resize.sh and /etc/fstab) that depends on that specific PARTUUID value(s), so I’d rather fix it before we hit that

  24. Code:

    1
    2
    3
    4
    umount /tmp/lp1
    umount /tmp/sd1
    sync

  25. remove SD card, and try to boot…. should be working as it does for me with a bigger boot FS for extra kernels