There are some quirks with adding a third partition to the Raspbian image. First it will expand its root partition on first boot to the whole SD card so you cannot simply add a partition afterwards. Second is that using a disk partitioner like fdisk
(I prefer parted
) it will silently modify the PARTUUID
to a unique id. Because Raspbian uses the PARTUUID
in cmdline.txt
and in /etc/fstab
to address partitions, it will fail booting then. For further information look at [1]. So we have to expand the root partition to 3 GB, add the third partition and modify /boot/cmdline.txt
and etc/fstab
before the first boot. For addressing the partitions we use /dev/mmcblk0pX
.
Let's do it. First flash an image, assuming the SD card is at /dev/sdb
. For reference I use Raspbian Stretch Lite 2018-04-18.
pc ~$ sudo -Es
pc ~# unzip -p 2018-04-18-raspbian-stretch-lite.zip | dd of=/dev/sdd bs=4M conv=fsync
pc ~# parted /dev/sdb print
Model: Mass Storage Device (scsi)
Disk /dev/sdb: 8069MB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:
Number Start End Size Type File system Flags
1 4194kB 49,4MB 45,2MB primary fat32 lba
2 50,3MB 1862MB 1812MB primary ext4
pc ~# parted /dev/sdb resizepart 2 3050,3MB # expand root partition
pc ~# e2fsck -f /dev/sdb2
pc ~# resize2fs /dev/sdb2
pc ~# parted /dev/sdb mkpart primary 3050,3MB 100% # create third partition
pc ~# mkdir /mnt/sdb{1,2}
pc ~# mount /dev/sdb1 /mnt/sdb1
pc ~# mount /dev/sdb2 /mnt/sdb2
Correct to root=/dev/mmcblk0p2
in /mnt/sdb1/cmdline.txt
:
dwc_otg.lpm_enable=0 console=serial0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait quiet init=/usr/lib/raspi-config/init_resize.sh
Correct /mnt/sdb2/etc/fstab
to:
proc /proc proc defaults 0 0
/dev/mmcblk0p1 /boot vfat defaults 0 2
/dev/mmcblk0p2 / ext4 defaults,noatime 0 1
Clean up:
pc ~# umount /mnt/sdb{1,2}
pc ~# exit
pc ~$
Put the SD card into your raspi and boot. I had to power down it after first attempt, don't no why.
**references:**
[1] [Is it possible to use partition UUID for root-parameter in cmdline.txt?](https://raspberrypi.stackexchange.com/questions/78291/is-it-possible-to-use-partition-uuid-for-root-parameter-in-cmdline-txt/78308#78308)