Raspberry Pi 2 Tutorial

This tutorial provides easy to follow step by step instructions of how to install Debian Wheezy with disk encryption enabled onto a USB hard drive connected to a Raspberry Pi 2 via the official netboot Debian Installer. The instructions also describe how to install the MATE desktop environment via the Debian backports package repository. This is a long process that involves installing Debian without encryption, compiling a custom Linux kernel, installing Debian with encryption, and then doing some post installation configuration.

Default selections are implied whenever a step is skipped.

If you appreciate this tutorial, please pay it forward by supporting Devuan, Debian without systemd.

1. Get a Raspberry Pi 2, a USB keyboard, a USB mouse, a 5 volt 1.2+ amp micro USB plug, an SD card, an externally powered USB hard drive, an Internet connection via an Ethernet cable, and an HDMI monitor with an HDMI cable and power cord. http://www.raspberrypi.org/help/faqs/#powerReqs

2. Install Debian without encryption. Do step 3 through 8.

3. Format SD card as MS-DOS FAT32 with the disk label RPI2LSD for Raspberry Pi Linux SD card.

4. Copy the contents of the boot partition of the Raspbian Debian Wheezy image to the SD card.
http://www.raspberrypi.org/downloads/

5. Download Debian Wheezy vexpress netboot installer named initrd.gz. Rename it initrd-debian-wheezy-armhf-vexpress-netboot.gz and then save it to the SD card.
http://http.us.debian.org/debian/dists/wheezy/main/installer-armhf/current/images/vexpress/netboot/

6. Add the following lines to the top of config.txt on the SD card.

# Boot Non-Encrypting Installer
kernel=kernel7.img
initramfs initrd-debian-wheezy-armhf-vexpress-netboot.gz

7. Edit cmdline.txt on the SD card to match the following.

# Boot Non-Encrypted USB Hard Drive
# dwc_otg.lpm_enable=0 console=ttyAMA0,115200 console=tty1 root=/dev/sda2 rootfstype=ext4 elevator=deadline rootwait

# Boot Installer
dwc_otg.lpm_enable=0 console=ttyAMA0,115200 console=tty1 elevator=deadline

8. Plug everything into the Raspberry Pi 2 and start up the installer. Decide on a temporary root password and a temporary user name and password. If necessary set your locale settings to whatever you prefer. Default settings should work fine for everything else except those specified below. Here's a tutorial for the nano text editor: http://mintaka.sdsu.edu/reu/nano.html

Continue the install without loading kernel modules? Yes
Don't worry when twice presented with a scary red screen with the following two notifications.
Software RAID not available: Continue
Logical Volume Manager not available: Continue
Select disk to partition: SCSI1 (0,0,0) (sda)...
Write the changes to disk? Yes
Continue without installing a kernel? Yes
Select software to install: Only "Standard system utilities"
No boot loader installed: Continue
Installation complete: Go Back
Execute a shell
mount /dev/mmcblk0p1 /mnt
nano /mnt/cmdline.txt
Switch boot options. Save the file by pressing Ctrl-x, y, enter.
nano /mnt/config.txt
Comment out the boot options. Save the file by pressing Ctrl-x, y, enter.
umount /mnt
exit
Finish the installation

9. Build kernel for installing from either the Wheezy or Jessie netboot Debian Installer. The Raspbian kernel fork will be used just to be on the safe side. Later it would be good to use the mainline kernel, only standard Debian tools, and optimized kernel settings specific to the Raspberry Pi 2. Do steps 10 through 15.

10. Log in as root.

11. Change your package repositories. Use nano to add the following lines to the bottom of /etc/apt/sources.list and then save your changes.

# Backports for MATE Desktop Environment
# deb http://http.debian.net/debian wheezy-backports main
# deb-src http://http.debian.net/debian wheezy-backports main

# For General Debian Packages
# deb http://mirrordirector.raspbian.org/raspbian wheezy firmware contrib non-free rpi
# deb-src http://mirrordirector.raspbian.org/raspbian wheezy firmware contrib non-free rpi
# deb http://archive.raspbian.org/raspbian wheezy firmware contrib non-free rpi
# deb-src http://archive.raspbian.org/raspbian wheezy firmware contrib non-free rpi

# For Specific Raspbian Packages
deb http://mirrordirector.raspbian.org/raspbian wheezy main firmware contrib non-free rpi
deb-src http://mirrordirector.raspbian.org/raspbian wheezy main firmware contrib non-free rpi
deb http://archive.raspbian.org/raspbian wheezy main firmware contrib non-free rpi
deb-src http://archive.raspbian.org/raspbian wheezy main firmware contrib non-free rpi

12. Install Raspbian keyring. Here's an aptitude tutorial: http://www.yourownlinux.com/2013/11/linux-aptitude-command-tutorial-with-examples.html
aptitude
Update package list
Install raspbian-archive-keyring [ Really Continue ]
Quit

13. Use nano to switch your package repositories from "Specific Raspbian Packages" to "General Debian Packages" in /etc/apt/sources.list and then save your changes.

14. Install packages.
aptitude
Update package list
Install the following packages.
fake-hwclock
ntp
Install the following packages.
build-essential
dialog
git
libncurses5-dev

15. Get kernel, build it, and install it.
git clone --depth 1 git://github.com/raspberrypi/linux.git
cd linux
make mrproper
zcat /proc/config.gz > .config
make oldconfig
Suppport for small TFT LCD display modules (FB_TFT) [N/m/y] y
https://davestechmusings.wordpress.com/tag/kernel/
...FB_*... [N/m/y] y
make menuconfig
Change the following values from <M> (module) to [*] (built-in)
- Device Drivers
- - Block devices
- - - All marked M
- - SCSI device support
- - - SCSI generic support
- - Multiple devices driver support (RAID and LVM)
- - - All marked M
- - USB Mass Storage support
- - - All marked M
- File systems
- - Btrfs filesystem support
- - FUSE (Filesystem in Userspace) support
- - - Character device in Userspace support
- - Miscellaneous filesystems
- - - eCrypt filesystem layer support
- - Native language support
- - - NLS ISO 8859-1 (Latin 1; Western European Languages)
- - - NLS ISO 8859-15 (Latin 9; Western European Languages with Euro)
- - - NLS UTF-8
- Cryptographic API
- - All marked M
- Library routines
- - All marked M
Save
Exit
make -j4
mount /dev/mmcblk0p1 /mnt
cp /root/linux/arch/arm/boot/Image /mnt/encrypting-installer-kernel.img
nano /mnt/cmdline.txt
Switch boot options. Save the file by pressing Ctrl-x, y, enter.
nano /mnt/config.txt
Add the following lines to the top of the file. Save the file by pressing Ctrl-x, y, enter.

# Boot Encrypting Installer
kernel=encrypting-installer-kernel.img
initramfs initrd-debian-wheezy-armhf-vexpress-netboot.gz

umount /mnt
shutdown -r now

16. Decide on a root password, a user name and password, and an encryption password. If necessary set your locale settings to whatever you prefer. Default settings should work fine for everything else except those specified below.

Continue the install without loading kernel modules? Yes
Partitioning method: Guided - use entire disk and set up encrypted LVM

Warning!!! This substep will irrevocably erase all contents on the USB hard drive. Make sure you only have one USB hard drive connected.

Erase the USB hard drive manually because the Debian Installer does this very slowly.  Run the following commands.

Ctrl-Alt-F2
enter
dd if=/dev/zero of=/dev/sda bs=64M
exit
Ctrl-Alt-F1

Select disk to partition: SCSI1 (0,0,0) (sda)...
Write the changes to disk and configure LVM? Yes
Erasing data on SCSI1 (0,0,0), partition #5: Cancel
Write the changes to disk? Yes
Continue without installing a kernel? Yes
Select software to install: Only "Standard system utilities"
No boot loader installed: Continue
Installation complete: Go Back
Execute a shell

mount -t proc proc /target/proc
mount -t sysfs sys /target/sys
chroot /target /bin/bash
source /etc/profile
apt-get install ntp fake-hwclock

Change your package repositories. Use nano to open /etc/apt/sources.list and then comment out all of the existing repositories and add the following lines to the bottom of the file.

# Backports for MATE Desktop Environment
# deb http://http.debian.net/debian wheezy-backports main
# deb-src http://http.debian.net/debian wheezy-backports main

# For General Debian Packages
# deb http://mirrordirector.raspbian.org/raspbian wheezy firmware contrib non-free rpi
# deb-src http://mirrordirector.raspbian.org/raspbian wheezy firmware contrib non-free rpi
# deb http://archive.raspbian.org/raspbian wheezy firmware contrib non-free rpi
# deb-src http://archive.raspbian.org/raspbian wheezy firmware contrib non-free rpi

# For Specific Raspbian Packages
deb http://mirrordirector.raspbian.org/raspbian wheezy main firmware contrib non-free rpi
deb-src http://mirrordirector.raspbian.org/raspbian wheezy main firmware contrib non-free rpi
deb http://archive.raspbian.org/raspbian wheezy main firmware contrib non-free rpi
deb-src http://archive.raspbian.org/raspbian wheezy main firmware contrib non-free rpi

aptitude
Update package list
Install raspbian-archive-keyring [ Really Continue ]
Update package list
Install linux-image-rpi2-rpfv firmware-linux libraspberrypi-bin libraspberrypi-dev libraspberrypi-doc
Ensure that busybox and raspberrypi-bootloader-nokernel are installed.
I would install linux-headers-rpi2-rpfv except that some of its dependencies conflict with currently installed generic Debian packages that I'd prefer not to change to their Raspbian equivalents unless necessary.
Quit out of aptitude

Change your package repositories. Use nano to edit and save /etc/apt/sources.list with the following changes. Comment out the "For Specific Raspbian Packages" section, uncomment the "For General Debian Packages" section, leave the "Backports for MATE Desktop Environment" section commented out, and uncomment the regular Debian repositories that aren't duplicates. Exit out of nano.

aptitude
Update package list
Quit out of aptitude
mount -t vfat /dev/mmcblk0p1 /mnt
mkdir /mnt/bootstrapper
shopt -s extglob
mv /mnt/!(bootstrapper) /mnt/bootstrapper/
mkdir /mnt/bootstrapped
cp -a /boot/* /mnt/bootstrapped/
cp -a /boot/* /mnt/
cp -a /mnt/bootstrapper/c* /mnt/
nano /mnt/cmdline.txt

Comment out the "Boot Installer" section add the following text to the top of the file, then save exit out of the file.

# Boot Encrypted USB Hard Drive
dwc_otg.lpm_enable=0 console=ttyAMA0,115200 console=tty1 root=/dev/mapper/arm-root cryptdevice=/dev/sda2:arm-root rootfstype=ext4 elevator=deadline rootwait

nano /mnt/config.txt

Comment out the "Boot Encrypting Installer" section add the following text to the top of the file, then save exit out of the file.

# Boot Encrypted USB Hard Drive
kernel=vmlinuz-3.18.0-trunk-rpi2
initramfs init.img-3.18.0-trunk-rpi2

sync
umount /mnt
exit
umount /target/proc
umount /target/sys
exit
Finish the installation

17. Configure sudo, install the MATE desktop environment, and do a bit of final configuration. Run the following commands.
Log in as root
adduser user sudo
exit
Log in as user
sudo nano /etc/apt/sources.list
Uncomment the "Backports for MATE Desktop Environment" section, save and exit out of nano.
sudo aptitude
Update package list
Install mate-desktop-environment-extras
Quit out of aptitude
sudo nano /etc/apt/sources.list
Comment out the "Backports for MATE Desktop Environment" section, save and exit out of nano.
sudo aptitude
Update package list
Install xorg lightdm gksu iceweasel-downthemall xchat geany-plugin-spellcheck
Quit out of aptitude
sudo nano /mnt/config.txt

Add the following lines and then save and quit out of nano.

disable_overscan=1
framebuffer_depth=24

sudo shutdown -r now
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License