Raspberry Pi 3 Model B+ – Reusable Raspbian Custom Image

Build a Custom Raspbian Image using only Raspbian Stretch running on a Raspberry Pi 3 Model B+. Create a non expanding image, customized with the applications & tools to meet your specification. Learn the basic commands for this six (6) part process to produce a Reusable Raspbian Image.

The Six (6) Part Process - Reusable Raspbian Custom Image

  • Part OO — Introduction
  • Part OA — Install Raspbian OS
  • Part OB — Resize Partition & File System
  • Part OC — Update Disk ID
  • Part OD — Disable Auto Resize
  • Part OE — Configure & Update
  • Part OF — Create Backup Image



Disclaimer and word of caution, these methods & disk imaging processes will destroy all data stored on the SD card. Please ensure you have a full backup of any important data saved on the SD card before you start.

Usually it takes about 30-45 mins, on a fast connection, to complete all six (6) parts of the above process. Be patient, ensure you have stable power and do not unplug the power adapter.

If you enjoy our videos, then please Like & Share. Our channel is updated every week so hit the Subscribe button to get the newest videos.




Part OA – Install Raspbian OS

#
# Step A.01 - Install Applications - If Required
#
sudo apt-get install gparted -y
sudo apt-get install eject -y


#
# Step A.02 - Find Device - microSD - '/dev/sde'
#
Menu --> Preferences --> GParted


#
# Step A.03 - Verify MD5 - Raspbian Image
#
sudo md5sum -c 2018-04-18-raspbian-stretch.img.md5


#
# Step A.04 - Install OS - Raspbian Image
#
sudo dd if=2018-04-18-raspbian-stretch.img of=/dev/sde bs=5M status=progress conv=sync




Part OB – Resize Partition & File System

#
# Step B.05 - ReSize 'root' Partition - Number 2
#
sudo parted -m /dev/sde u s resizepart 2 6144MB


#
# Step B.06 - Check 'root' FileSystem
#
sudo e2fsck -f /dev/sde2


#
# Step B.07 - ReSize 'root' FileSystem
#
sudo resize2fs /dev/sde2


#
# Step B.08 - Verify Changes Visually - /dev/sde
#
Menu --> Preferences --> GParted




Part OC – Update Disk ID

#
# Step C.09 - Get Disk UUID - '/dev/sde' - 8 Hex Digits - 'xxxxxxxx'
#
sudo blkid -o export /dev/sde | grep PTUUID


#
# Step C.10 - Mount 'boot' & 'root' FileSystem
#
sudo mkdir /media/pi/boot
sudo mkdir /media/pi/rootfs
#
sudo mount /dev/sde1 /media/pi/boot
sudo mount /dev/sde2 /media/pi/rootfs


#
# Step C.11 - Modify Auto Mount - '/etc/fstab'
#
# a. Update 'PARTUUID=xxxxxxxx-01 /boot '
# b. Update 'PARTUUID=xxxxxxxx-02 /'
#
sudo nano /media/pi/rootfs/etc/fstab


#
# Step C.12 - Modify '/boot/cmdline.txt'
#
# a. Update 'root=PARTUUID=xxxxxxxx-02'
# b. Delete 'init=/usr/lib/raspi-config/init_resize.sh'
#
sudo nano /media/pi/boot/cmdline.txt




Part OD – Disable Auto Resize

#
# Step D.13 - Delete '/etc/init.d/resize2fs_once'
#
sudo rm /media/pi/rootfs/etc/init.d/resize2fs_once


#
# Step D.14 - Delete '/etc/rc3.d/S01resize2fs_once'
#
sudo rm /media/pi/rootfs/etc/rc3.d/S01resize2fs_once


#
# Step D.15 - Clean Up & UnMount 'boot' & 'root' FileSystem
#
sudo umount /dev/sde1
sudo umount /dev/sde2
#
sudo rmdir /media/pi/boot
sudo rmdir /media/pi/rootfs


#
# Step D.16 - Eject Device - /dev/sde
#
sudo eject /dev/sde




Part OE – Configure & Update

#
# Step E.17 - Install Applications
#
sudo apt-get install xscreensaver -y
sudo apt-get install numlockx -y
sudo apt-get install eject -y
sudo apt-get install hdparm -y
sudo apt-get install sysbench -y
sudo apt-get install gparted -y


#
# Step E.18 - Install Updates & Configure
#
sudo apt-get update
sudo apt-get upgrade -y
sudo update-nodejs-and-nodered




Part OF – Create Backup Image

#
# Step F.19 - Create Backup - Raspbian Image
#
sudo dd if=/dev/sde of=base.img bs=1M count=6400 status=progress conv=sync


#
# Step F.20 - Create MD5 - Raspbian Image
#
sudo md5sum base.img > base.img.md5


Comments