Skip to content

Instantly share code, notes, and snippets.

@vane
Forked from jeremyckahn/init_rootfs.sh
Last active January 2, 2018 01:30
Show Gist options
  • Save vane/6b27d03951ac96798ebde7c689b81a86 to your computer and use it in GitHub Desktop.
Save vane/6b27d03951ac96798ebde7c689b81a86 to your computer and use it in GitHub Desktop.
Setting up Raspbian rootfs on Ubuntu
#!/bin/bash
# For Ubuntu. Probably works elsewhere too.
# This script downloads the Raspbian file system into ~/rpi/chroot-raspbian-armhf
# It also chroots you into the directory, so you can act as a Raspbian user.
# This was all taken from here: http://superpiadventures.com/2012/07/development-environment/
mkdir -p ~/rpi
cd ~/rpi
# Get some packages.
sudo apt-get install qemu-user-static debootstrap
# This step takes a little while. Don't do it on a low battery.
sudo qemu-debootstrap --arch armhf stretch chroot-raspbian-armhf http://archive.raspbian.org/raspbian
# Mount some filesystems. These calls to "mount" need to be done
# again after rebooting, so consider making a BASH alias.
#sudo mount -t proc proc ~/rpi/chroot-raspbian-armhf/proc
#sudo mount -t sysfs sysfs ~/rpi/chroot-raspbian-armhf/sys
#sudo mount -o bind /dev ~/rpi/chroot-raspbian-armhf/dev
# chroot into the Raspbian filesystem
# Do this each time you need to work with the Raspbian files.
# Again, consider making a BASH alias.
#sudo LC_ALL=C chroot ~/rpi/chroot-raspbian-armhf
# Add the Raspbian repo and set up a GPG key.
echo "deb http://archive.raspbian.org/raspbian stretch main" >> /etc/apt/sources.list
wget http://archive.raspbian.org/raspbian.public.key -O - | apt-key add -
apt-get update
[stretch-armhf]
description=Raspbian 64-bit chroot based on Stretch
type=directory
directory=/home/pi/rpi/chroot-raspbian-armhf
users=pi
groups=pi
root-users=pi
setup.copyfiles=default/copyfiles
setup.fstab=default/stretch-armhf.fstab
#/etc/schroot/chroot.d/
# fstab: static file system information for chroots.
# Note that the mount point will be prefixed by the chroot path
# (CHROOT_PATH)
#
# <file system> <mount point> <type> <options> <dump> <pass>
/home/pi/rpi/chroot-raspbian-armhf/bin /bin none rw,bind 0 0
/proc /proc none rw,bind 0 0
/sys /sys none rw,bind 0 0
/dev /dev none rw,bind 0 0
/dev/pts /dev/pts none rw,bind 0 0
/home /home none rw,bind 0 0
/tmp /tmp none rw,bind 0 0
# It may be desirable to have access to /run, especially if you wish
# to run additional services in the chroot. However, note that this
# may potentially cause undesirable behaviour on upgrades, such as
# killing services on the host.
/run /run none rw,bind 0 0
/run/lock /run/lock none rw,bind 0 0
/dev/shm /dev/shm none rw,bind 0 0
/run/shm /run/shm none rw,bind 0 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment