jdbennet
Posts: 96
Joined: Sun Jul 22, 2012 2:25 pm

Script to make custom Debian images

Wed Aug 01, 2012 5:48 pm

Ive found a modified a script to make and install a minimal Debian Unstable (sid/armel) system onto a specified SD card. I've used it myself as I wanted a minimal starting point, with lots of the latest and greatest.

May be use to someone, just change it in 2 or 3 places and you could use it to roll a raspbian armhf image, for example. You need to do: "sudo apt-get install binfmt-support qemu qemu-user-static debootstrap kpartx lvm2 dosfstools". I used squeeze as my host. Run with "sudo bootstrap.sh /dev/sd[x], were X is the device letter of the SD card.

Login is root:raspberry. USB-Serial enabled.

Wont let me upload scripts, so here is a link
http://james-bennet.com/bootstrap.sh

Code: Select all

#!/bin/bash

# Based on work by Klaus M Pfeiffer at http://blog.kmp.or.at/2012/05/build-your-own-raspberry-pi-image/
# you need to do: "sudo apt-get install binfmt-support qemu qemu-user-static debootstrap kpartx lvm2 dosfstools"
# run with "sudo bootstrap.sh /dev/sd[x]"

echo "Use like: sudo bootstrap.sh /dev/sd[x]"
sudo apt-get install binfmt-support qemu qemu-user-static debootstrap kpartx lvm2 dosfstools

deb_mirror="http://ftp.debian.org/debian"
deb_local_mirror="http://ftp.debian.org/debian"

bootsize="64M"
deb_release="sid"

device=$1
buildenv="/root/rpi"
rootfs="${buildenv}/rootfs"
bootfs="${rootfs}/boot"

mydate=`date +%Y%m%d`

if [ "$deb_local_mirror" == "" ]; then
  deb_local_mirror=$deb_mirror  
fi

image=""


if [ $EUID -ne 0 ]; then
  echo "ERROR: This tool must be run as Root"
  exit 1
fi

if ! [ -b $device ]; then
  echo "ERROR: Device: $device Is not a block device"
  exit 1
fi

if [ "$device" == "" ]; then
  echo "WARNING: No block device given, creating image instead."
  mkdir -p $buildenv
  image="${buildenv}/rpi_basic_${deb_release}_${mydate}.img"
  dd if=/dev/zero of=$image bs=1MB count=1000
  device=`losetup -f --show $image`
  echo "Image $image Created and mounted as $device"
else
  dd if=/dev/zero of=$device bs=512 count=1
fi

fdisk $device << EOF
n
p
1

+$bootsize
t
c
n
p
2


w
EOF


if [ "$image" != "" ]; then
  losetup -d $device
  device=`kpartx -va $image | sed -E 's/.*(loop[0-9])p.*/\1/g' | head -1`
  device="/dev/mapper/${device}"
  bootp=${device}p1
  rootp=${device}p2
else
  if ! [ -b ${device}1 ]; then
    bootp=${device}p1
    rootp=${device}p2
    if ! [ -b ${bootp} ]; then
      echo "ERROR: Can't find boot partition, neither as ${device}1, nor as ${device}p1. Exiting."
      exit 1
    fi
  else
    bootp=${device}1
    rootp=${device}2
  fi  
fi

mkfs.vfat $bootp
mkfs.ext4 $rootp

mkdir -p $rootfs

mount $rootp $rootfs

cd $rootfs

debootstrap --foreign --arch armel $deb_release $rootfs $deb_local_mirror
cp /usr/bin/qemu-arm-static usr/bin/
LANG=C chroot $rootfs /debootstrap/debootstrap --second-stage

mount $bootp $bootfs

echo "deb $deb_local_mirror $deb_release main contrib non-free
" > etc/apt/sources.list

echo "dwc_otg.lpm_enable=0 console=ttyUSB0,115200 kgdboc=ttyUSB0,115200 root=/dev/mmcblk0p2 rootfstype=ext4 rootwait" > boot/cmdline.txt

echo "proc            /proc           proc    defaults        0       0
/dev/mmcblk0p1  /boot           vfat    defaults        0       0
" > etc/fstab

echo "raspberrypi" > etc/hostname

echo "auto lo
iface lo inet loopback

auto eth0
iface eth0 inet dhcp
" > etc/network/interfaces

echo "vchiq
snd_bcm2835
" >> etc/modules

echo "console-common	console-data/keymap/policy	select	Select keymap from full list
console-common	console-data/keymap/full	select	de-latin1-nodeadkeys
" > debconf.set

echo "#!/bin/bash
debconf-set-selections /debconf.set
rm -f /debconf.set
apt-get update 
apt-get -y install git-core binutils ca-certificates
wget http://goo.gl/1BOfJ -O /usr/bin/rpi-update
chmod +x /usr/bin/rpi-update
mkdir -p /lib/modules/3.1.9+
touch /boot/start.elf
rpi-update
apt-get -y install locales console-common ntp openssh-server less vim
echo \"root:raspberry\" | chpasswd
sed -i -e 's/KERNEL\!=\"eth\*|/KERNEL\!=\"/' /lib/udev/rules.d/75-persistent-net-generator.rules
rm -f /etc/udev/rules.d/70-persistent-net.rules
rm -f third-stage
" > third-stage
chmod +x third-stage
LANG=C chroot $rootfs /third-stage

echo "deb $deb_mirror $deb_release main contrib non-free
" > etc/apt/sources.list

echo "#!/bin/bash
aptitude update
aptitude clean
apt-get clean
rm -f cleanup
" > cleanup
chmod +x cleanup
LANG=C chroot $rootfs /cleanup

cd

umount $bootp
umount $rootp

if [ "$image" != "" ]; then
  kpartx -d $image
  echo "Created Image: $image"
fi


echo "Done."



jdbennet
Posts: 96
Joined: Sun Jul 22, 2012 2:25 pm

Re: Script to make custom Debian images

Wed Aug 01, 2012 8:24 pm

Update: does not 100% work with raspbian wheezy/armhf. Host may give some fatal qemu error if its version is too old.

abulte
Posts: 1
Joined: Fri Oct 19, 2012 10:18 am

Re: Script to make custom Debian images

Fri Oct 19, 2012 10:28 am

Guess I found the needed modifications ;-)
http://elinux.org/Raspbian

linux34
Posts: 46
Joined: Sat Jul 21, 2012 9:00 am

Re: Script to make custom Debian images

Wed Feb 25, 2015 11:07 pm

This debian image work in raspPİ2?

And is booting with Pi logo?

Im search a core or minimal debian image with Tux logo. Working with RaspPi2

Thanks.

Return to “Debian”