From cf0edd94c05a9fc0c609758016a697c24dd913a0 Mon Sep 17 00:00:00 2001 From: VG Date: Sun, 6 Nov 2016 20:04:54 +0100 Subject: add other debootstrap scripts and older instructions --- prepare-vm-by-debootstrap/README | 1 + prepare-vm-by-debootstrap/make-vm-debootstrap | 370 +++++++++++++++++++++ prepare-vm-wheezy_by_kvm_old/DONE | 8 + prepare-vm-wheezy_by_kvm_old/TODO | 4 + prepare-vm-wheezy_by_kvm_old/commands | 6 + .../ubuntu-12.10-amd64-nc/process | 39 +++ .../ubuntu-12.10-amd64-nc/startvm.sh | 10 + .../ubuntu-13.04-amd64-users/process | 42 +++ .../ubuntu-13.04-amd64-users/startvm.sh | 10 + qemu-headless/old-make-vm-debootstrap2 | 370 +++++++++++++++++++++ rpi2-debian-stdkernel/.gitignore | 1 + rpi2-debian-stdkernel/copy-to-sdcard.py | 71 ++++ .../format-sd-card-do-not-work-gpt.py | 61 ++++ rpi2-debian-stdkernel/format-sdcard.py | 33 ++ rpi2-debian-stdkernel/make-rpi-debootstrap.py | 255 ++++++++++++++ rpi2-debian-stdkernel/other_boot_files/boot.scr | 25 ++ rpi2-debian-stdkernel/other_boot_files/config.txt | 6 + rpi2-debian-stdkernel/other_boot_files/ubuntu.pref | 3 + .../other_boot_files/ubuntu.sources | 4 + .../other_boot_files/update-boot-uimage.sh | 3 + rpi2-debian-stdkernel/other_boot_files/vg-copy-rpi | 13 + 21 files changed, 1335 insertions(+) create mode 100644 prepare-vm-by-debootstrap/README create mode 100755 prepare-vm-by-debootstrap/make-vm-debootstrap create mode 100644 prepare-vm-wheezy_by_kvm_old/DONE create mode 100644 prepare-vm-wheezy_by_kvm_old/TODO create mode 100644 prepare-vm-wheezy_by_kvm_old/commands create mode 100644 qemu-before-debootstrap-instructions/ubuntu-12.10-amd64-nc/process create mode 100755 qemu-before-debootstrap-instructions/ubuntu-12.10-amd64-nc/startvm.sh create mode 100644 qemu-before-debootstrap-instructions/ubuntu-13.04-amd64-users/process create mode 100755 qemu-before-debootstrap-instructions/ubuntu-13.04-amd64-users/startvm.sh create mode 100755 qemu-headless/old-make-vm-debootstrap2 create mode 100644 rpi2-debian-stdkernel/.gitignore create mode 100755 rpi2-debian-stdkernel/copy-to-sdcard.py create mode 100755 rpi2-debian-stdkernel/format-sd-card-do-not-work-gpt.py create mode 100755 rpi2-debian-stdkernel/format-sdcard.py create mode 100755 rpi2-debian-stdkernel/make-rpi-debootstrap.py create mode 100644 rpi2-debian-stdkernel/other_boot_files/boot.scr create mode 100644 rpi2-debian-stdkernel/other_boot_files/config.txt create mode 100644 rpi2-debian-stdkernel/other_boot_files/ubuntu.pref create mode 100644 rpi2-debian-stdkernel/other_boot_files/ubuntu.sources create mode 100755 rpi2-debian-stdkernel/other_boot_files/update-boot-uimage.sh create mode 100755 rpi2-debian-stdkernel/other_boot_files/vg-copy-rpi diff --git a/prepare-vm-by-debootstrap/README b/prepare-vm-by-debootstrap/README new file mode 100644 index 0000000..b506420 --- /dev/null +++ b/prepare-vm-by-debootstrap/README @@ -0,0 +1 @@ +Here disk.img is just a temp disk to prepare a vm. I don't mind erasing it. diff --git a/prepare-vm-by-debootstrap/make-vm-debootstrap b/prepare-vm-by-debootstrap/make-vm-debootstrap new file mode 100755 index 0000000..cad9bf0 --- /dev/null +++ b/prepare-vm-by-debootstrap/make-vm-debootstrap @@ -0,0 +1,370 @@ +#!/bin/bash + +set -e +exec 3>&1 +exec >/tmp/debootstrap.log +echo "I: log=/tmp/debootstrap.log">&2 +#set -x + +if [ "$(id -ru)" != "0" ]; then + echo "Run this script as root">&2 + exit 1 +fi + +# you can abuse official mirror for debootstrap since we are going to cache +# packages anyway. + +RELEASE=raring +MIRROR=http://fr.archive.ubuntu.com/ubuntu/ +ARCH=amd64 +#DESTDIR=/tmp/debootstrap-mountpoint +PKGS="$(sed 's/^#.*$//'<&2; exit 1;; + esac + shift +done + +#[ -z "$BLOCKDEV" ] && { echo "Specify block device (-d)">&2; exit 1; } +[ -z "$DESTDIR" ] && { echo "Specify destdir (-d)">&2; exit 1; } + +ARCHIVE=$PWD/$RELEASE-$ARCH-debootstrap.tgz +KERNEL=$PWD/$RELEASE-$ARCH-vmlinuz + +#BLOCKDEV="$(df -P "$DESTDIR" | tail -n 1 | cut -d' ' -f1)" +#( +#echo "I: blockdevice associated to destination is $BLOCKDEV" +#echo "I: blockdevice will not be manipulated directly," +#echo "I: it is only used for informational purposes (such as UUID)" +#)>&2 + +echo "I: script will begin in 10seconds...">&2 +printf "I: ">&2 +for i in $(seq 10 -1 0); do sleep 1; printf "%d... " $i>&2; done +echo>&2 + +#echo "Warning: will erase $BLOCKDEV with mkfs.ext4 in 10seconds...">&2 +#for i in $(seq 10 -1 0); do sleep 1; printf "%d... " $i>&2; done +#echo>&2 +#mkfs -q -F -t ext4 -L rootfs "$BLOCKDEV" || exit 1 +#mkdir -p "$DESTDIR" +#echo "mounting block device...">&2 +#mount -v -t ext4 "$BLOCKDEV" "$DESTDIR" || \ +# mount -v -t ext4 -o loop "$BLOCKDEV" "$DESTDIR" || exit 1 +#echo "In case of error, please remember to umount $DESTDIR">&2 + +if [ ! -e "$ARCHIVE" ]; then + echo "I: debootstrap archive does not exists, making it">&2 + debootstrap --foreign --arch="$ARCH" \ + --include="$PKGS" --components=main,universe \ + --make-tarball "$ARCHIVE" \ + "$RELEASE" "$DESTDIR" "$MIRROR" || exit 1 +fi + +echo "I: debootstraping...">&2 +debootstrap --foreign --arch="$ARCH" \ + --include="$PKGS" --components=main,universe \ + --unpack-tarball "$ARCHIVE" \ + "$RELEASE" "$DESTDIR" "$MIRROR" + +if [ ! -e "$KERNEL" ];then + echo "I: wget kernel...">&2 + wget -q "$MIRROR/dists/$RELEASE/main/installer-$ARCH/current/images/netboot/ubuntu-installer/$ARCH/linux" -O "$KERNEL" +fi + +echo "I: adjust configuration...">&2 +rm -f "$DESTDIR/etc/localtime" +cat "$DESTDIR/usr/share/zoneinfo/Europe/Paris" > "$DESTDIR/etc/localtime" + +# network +cat >"$DESTDIR/etc/network/interfaces"<"$DESTDIR/etc/hosts" +echo "localhost">"$DESTDIR/etc/hostname" +echo "servername 10.1.1.254">"$DESTDIR/etc/resolv.conf" + +for f in "$DESTDIR"/etc/init/tty[1-6].conf; do + echo "manual">${f%.conf}.override +done + +chmod +w /etc/sudoers +sed 's,#* *%sudo.*,%sudo ALL=(ALL) NOPASSWD: ALL,' -i /etc/sudoers +chmod -w /etc/sudoers + +#UUID="$(blkid "$BLOCKDEV" | sed 's/^.*UUID="\([a-zA-Z0-9-]\+\)".*$/\1/')" +cat >"$DESTDIR/etc/fstab"< +/dev/vda / ext4 errors=remount-ro,noatime 0 1 +tmpfs /tmp tmpfs mode=1777,noatime,size=128m,nodev,nosuid,noexec 0 0 +tmpfs /var/log tmpfs mode=1777,noatime,size=4m,nodev,nosuid,noexec 0 0 +tmpfs /var/tmp tmpfs mode=1777,noatime,size=128m,nodev,nosuid,noexec 0 0 + +#UUID=$UUID / ext4 errors=remount-ro,noatime 0 1 +#UUID=use blkid for uuid discovery /home ext4 noatime 0 2 +#UUID=6d9ac889-3c25-4e05-90f3-d183f8b14aca none swap sw,auto 0 0 +EOF + +mkdir -p "$DESTDIR/etc/sv/ttyS0/" +mkdir -p "$DESTDIR/etc/service/" +cat >"$DESTDIR/etc/sv/ttyS0/run"<<"EOF" +#!/bin/bash +dev=/dev/ttyS0 +/bin/stty -F $dev sane clocal -crtscts -hupcl +exec <$dev >$dev 2>$dev +echo +echo "Press enter to continue..."; read +cd /root +/usr/bin/env -i HOME=/root PATH=/usr/sbin:/usr/bin:/sbin:/bin TERM=screen-256color /usr/bin/setsid /bin/bash +exec wait +#exec /bin/bash +#exec /usr/bin/env -i /bin/sh +#exec /usr/bin/setsid /bin/sh +EOF +chmod +x "$DESTDIR/etc/sv/ttyS0/run" +ln -sfv "/etc/sv/ttyS0/" "$DESTDIR/etc/service/" + +mkdir -p "$DESTDIR/etc/ssh" +cat >"$DESTDIR/etc/ssh/sshd_config"< "$DESTDIR/etc/apt/sources.list" < "$DESTDIR/etc/default/console-setup"<"$DESTDIR/etc/default/keyboard"<"$DESTDIR/etc/default/locale"<>"$DESTDIR/etc/bash.bashrc"<"$DESTDIR/etc/vim/vimrc"<,[,] +set scrolloff=1 +EOF + +rm -r "$DESTDIR/etc/skel" +mkdir -p "$DESTDIR/etc/skel" + +cat > "$DESTDIR/init-stage2.sh" << EOF +#!/bin/sh +export PATH="/usr/sbin:/usr/bin:/sbin:/bin" +mount -no remount,rw / +mount -t proc proc /proc +mount -t sysfs sysfs /sys + +/debootstrap/debootstrap --second-stage + +# second stage may unmount this... +[ -e /proc/mounts ] || mount -t proc proc /proc +[ -e /sys/kernel ] || mount -t sysfs sysfs /sys +busybox mdev -s + +echo '------ mounts:' +cat /proc/mounts +echo '------' + +mv /etc/default/extlinux /etc/default/extlinux.dist +cat >/etc/default/extlinux<~root/.bashrc +echo '. ~/.bashrc' >~root/.bash_profile +echo '. /etc/bash.bashrc' >~calendros/.bashrc +echo '. ~/.bashrc' >~calendros/.bash_profile + +locale-gen en_US.UTF-8 en_GB.UTF-8 en_DK.UTF-8 fr_FR.UTF-8 + +# dhclient may erase /etc/resolv.conf, and is not really useful here +#ip link set eth0 up +#dhclient eth0 +#apt-get update + +echo "Dropping a shell, press Ctrl-D or type exit to finish." +/bin/bash + +rm -v /etc/udev/rules.d/70-persistent-*.rules + +echo "Bootstrap ended, poweroff in 10seconds..." +rm /init-stage2.sh +#sleep 10 || exec /bin/bash # for debug +#poweroff & # does not work +sync +fuser -k / +sleep 1 +mount -o remount,ro / +exit 0 # will panic, but does not matter now (don't know how to shutdown o/w) +EOF +chmod +x "$DESTDIR/init-stage2.sh" + +cat >&2 <&1 +exec >/tmp/debootstrap.log +echo "I: log=/tmp/debootstrap.log">&2 +#set -x + +if [ "$(id -ru)" != "0" ]; then + echo "Run this script as root">&2 + exit 1 +fi + +# you can abuse official mirror for debootstrap since we are going to cache +# packages anyway. + +RELEASE=raring +MIRROR=http://fr.archive.ubuntu.com/ubuntu/ +ARCH=amd64 +#DESTDIR=/tmp/debootstrap-mountpoint +PKGS="$(sed 's/^#.*$//'<&2; exit 1;; + esac + shift +done + +#[ -z "$BLOCKDEV" ] && { echo "Specify block device (-d)">&2; exit 1; } +[ -z "$DESTDIR" ] && { echo "Specify destdir (-d)">&2; exit 1; } + +ARCHIVE=$PWD/$RELEASE-$ARCH-debootstrap.tgz +KERNEL=$PWD/$RELEASE-$ARCH-vmlinuz + +#BLOCKDEV="$(df -P "$DESTDIR" | tail -n 1 | cut -d' ' -f1)" +#( +#echo "I: blockdevice associated to destination is $BLOCKDEV" +#echo "I: blockdevice will not be manipulated directly," +#echo "I: it is only used for informational purposes (such as UUID)" +#)>&2 + +echo "I: script will begin in 10seconds...">&2 +printf "I: ">&2 +for i in $(seq 10 -1 0); do sleep 1; printf "%d... " $i>&2; done +echo>&2 + +#echo "Warning: will erase $BLOCKDEV with mkfs.ext4 in 10seconds...">&2 +#for i in $(seq 10 -1 0); do sleep 1; printf "%d... " $i>&2; done +#echo>&2 +#mkfs -q -F -t ext4 -L rootfs "$BLOCKDEV" || exit 1 +#mkdir -p "$DESTDIR" +#echo "mounting block device...">&2 +#mount -v -t ext4 "$BLOCKDEV" "$DESTDIR" || \ +# mount -v -t ext4 -o loop "$BLOCKDEV" "$DESTDIR" || exit 1 +#echo "In case of error, please remember to umount $DESTDIR">&2 + +if [ ! -e "$ARCHIVE" ]; then + echo "I: debootstrap archive does not exists, making it">&2 + debootstrap --foreign --arch="$ARCH" \ + --include="$PKGS" --components=main,universe \ + --make-tarball "$ARCHIVE" \ + "$RELEASE" "$DESTDIR" "$MIRROR" || exit 1 +fi + +echo "I: debootstraping...">&2 +debootstrap --foreign --arch="$ARCH" \ + --include="$PKGS" --components=main,universe \ + --unpack-tarball "$ARCHIVE" \ + "$RELEASE" "$DESTDIR" "$MIRROR" + +if [ ! -e "$KERNEL" ];then + echo "I: wget kernel...">&2 + wget -q "$MIRROR/dists/$RELEASE/main/installer-$ARCH/current/images/netboot/ubuntu-installer/$ARCH/linux" -O "$KERNEL" +fi + +echo "I: adjust configuration...">&2 +rm -f "$DESTDIR/etc/localtime" +cat "$DESTDIR/usr/share/zoneinfo/Europe/Paris" > "$DESTDIR/etc/localtime" + +# network +cat >"$DESTDIR/etc/network/interfaces"<"$DESTDIR/etc/hosts" +echo "localhost">"$DESTDIR/etc/hostname" +echo "servername 10.1.1.254">"$DESTDIR/etc/resolv.conf" + +for f in "$DESTDIR"/etc/init/tty[1-6].conf; do + echo "manual">${f%.conf}.override +done + +chmod +w /etc/sudoers +sed 's,#* *%sudo.*,%sudo ALL=(ALL) NOPASSWD: ALL,' -i /etc/sudoers +chmod -w /etc/sudoers + +#UUID="$(blkid "$BLOCKDEV" | sed 's/^.*UUID="\([a-zA-Z0-9-]\+\)".*$/\1/')" +cat >"$DESTDIR/etc/fstab"< +/dev/vda / ext4 errors=remount-ro,noatime 0 1 +tmpfs /tmp tmpfs mode=1777,noatime,size=128m,nodev,nosuid,noexec 0 0 +tmpfs /var/log tmpfs mode=1777,noatime,size=4m,nodev,nosuid,noexec 0 0 +tmpfs /var/tmp tmpfs mode=1777,noatime,size=128m,nodev,nosuid,noexec 0 0 + +#UUID=$UUID / ext4 errors=remount-ro,noatime 0 1 +#UUID=use blkid for uuid discovery /home ext4 noatime 0 2 +#UUID=6d9ac889-3c25-4e05-90f3-d183f8b14aca none swap sw,auto 0 0 +EOF + +mkdir -p "$DESTDIR/etc/sv/ttyS0/" +mkdir -p "$DESTDIR/etc/service/" +cat >"$DESTDIR/etc/sv/ttyS0/run"<<"EOF" +#!/bin/bash +dev=/dev/ttyS0 +/bin/stty -F $dev sane clocal -crtscts -hupcl +exec <$dev >$dev 2>$dev +echo +echo "Press enter to continue..."; read +cd /root +/usr/bin/env -i HOME=/root PATH=/usr/sbin:/usr/bin:/sbin:/bin TERM=screen-256color /usr/bin/setsid /bin/bash +exec wait +#exec /bin/bash +#exec /usr/bin/env -i /bin/sh +#exec /usr/bin/setsid /bin/sh +EOF +chmod +x "$DESTDIR/etc/sv/ttyS0/run" +ln -sfv "/etc/sv/ttyS0/" "$DESTDIR/etc/service/" + +mkdir -p "$DESTDIR/etc/ssh" +cat >"$DESTDIR/etc/ssh/sshd_config"< "$DESTDIR/etc/apt/sources.list" < "$DESTDIR/etc/default/console-setup"<"$DESTDIR/etc/default/keyboard"<"$DESTDIR/etc/default/locale"<>"$DESTDIR/etc/bash.bashrc"<"$DESTDIR/etc/vim/vimrc"<,[,] +set scrolloff=1 +EOF + +rm -r "$DESTDIR/etc/skel" +mkdir -p "$DESTDIR/etc/skel" + +cat > "$DESTDIR/init-stage2.sh" << EOF +#!/bin/sh +export PATH="/usr/sbin:/usr/bin:/sbin:/bin" +mount -no remount,rw / +mount -t proc proc /proc +mount -t sysfs sysfs /sys + +/debootstrap/debootstrap --second-stage + +# second stage may unmount this... +[ -e /proc/mounts ] || mount -t proc proc /proc +[ -e /sys/kernel ] || mount -t sysfs sysfs /sys +busybox mdev -s + +echo '------ mounts:' +cat /proc/mounts +echo '------' + +mv /etc/default/extlinux /etc/default/extlinux.dist +cat >/etc/default/extlinux<~root/.bashrc +echo '. ~/.bashrc' >~root/.bash_profile +echo '. /etc/bash.bashrc' >~calendros/.bashrc +echo '. ~/.bashrc' >~calendros/.bash_profile + +locale-gen en_US.UTF-8 en_GB.UTF-8 en_DK.UTF-8 fr_FR.UTF-8 + +# dhclient may erase /etc/resolv.conf, and is not really useful here +#ip link set eth0 up +#dhclient eth0 +#apt-get update + +echo "Dropping a shell, press Ctrl-D or type exit to finish." +/bin/bash + +rm -v /etc/udev/rules.d/70-persistent-*.rules + +echo "Bootstrap ended, poweroff in 10seconds..." +rm /init-stage2.sh +#sleep 10 || exec /bin/bash # for debug +#poweroff & # does not work +sync +fuser -k / +sleep 1 +mount -o remount,ro / +exit 0 # will panic, but does not matter now (don't know how to shutdown o/w) +EOF +chmod +x "$DESTDIR/init-stage2.sh" + +cat >&2 < timeout + + +def get_fresh_firmware(firmware_dir): + firmware_timeout = 24*3600 # 1d timeout + if (not os.path.exists(firmware_dir) + or out_of_date(firmware_dir, firmware_timeout)): + shutil.rmtree(firmware_dir, ignore_errors=True) + run(['git', 'clone', '--depth=1', + 'https://github.com/raspberrypi/firmware', + firmware_dir], check=True) + + +def copy_to_partitions(firmware_dir, boot_mountpoint, root_mountpoint): + for path in glob.glob(firmware_dir + '/boot/*'): + if os.path.isfile(path): + shutil.copy(path, boot_mountpoint) + for path in glob.glob('other_boot_files/*'): + shutil.copy(path, boot_mountpoint) + run(['rsync', '-aHX', 'debootstrapdir/.', root_mountpoint + '/.'], + check=True) + #shutil.copyfile('debootstrapdir/vmlinuz', boot_mountpoint + '/zImage', + # follow_symlinks=True) + + +def main(): + if len(sys.argv) < 2: + print('Usage: {} '.format(sys.argv[0]), file=sys.stderr) + raise SystemExit(1) + device = sys.argv[1] + reexec_root() + firmware_dir = 'rpi-firmware' + boot_mountpoint = tempfile.TemporaryDirectory() + root_mountpoint = tempfile.TemporaryDirectory() + try: + run(['mount', device + '1', boot_mountpoint.name], check=True) + run(['mount', device + '2', root_mountpoint.name], check=True) + get_fresh_firmware(firmware_dir) + copy_to_partitions(firmware_dir, + boot_mountpoint.name, + root_mountpoint.name) + finally: + run(['umount', boot_mountpoint.name]) + run(['umount', root_mountpoint.name]) + + +if __name__ == '__main__': + main() diff --git a/rpi2-debian-stdkernel/format-sd-card-do-not-work-gpt.py b/rpi2-debian-stdkernel/format-sd-card-do-not-work-gpt.py new file mode 100755 index 0000000..3d1b295 --- /dev/null +++ b/rpi2-debian-stdkernel/format-sd-card-do-not-work-gpt.py @@ -0,0 +1,61 @@ +#!/usr/bin/python3 + +import sys +import subprocess + +def run(*l, **d): + print('run:', *l, d) + return subprocess.run(*l, **d) + +def main(): + if len(sys.argv) < 2: + print('Usage: {} '.format(sys.argv[0]), file=sys.stderr) + raise SystemExit(1) + device = sys.argv[1] + # use this without check first, in some condition double invokation is + # needed... + run([ + 'sudo', + 'sgdisk', + '--zap-all', + device, + ]) + run([ + 'sudo', + 'sgdisk', + '--set-alignment=8192', + '--new=1:4M:+100M', + '--change-name=1:boot', + '--typecode=1:EF00', + '--largest-new=2', + '--change-name=2:root', + '--typecode=2:8300', + '--hybrid=1', + '--print', + '--print-mbr', + device, + ], check=True) + run([ + 'sudo', + 'mkfs.vfat', + '-F', '32', + '-n', 'boot', + device + '1', + ], check=True) + run([ + 'sudo', + 'mkfs.vfat', + '-n', 'boot', + device + '1', + ], check=True) + run([ + 'sudo', + 'mkfs.ext4', + '-q', + '-L', 'root', + device + '2' + ], check=True) + + +if __name__ == '__main__': + main() diff --git a/rpi2-debian-stdkernel/format-sdcard.py b/rpi2-debian-stdkernel/format-sdcard.py new file mode 100755 index 0000000..ea08728 --- /dev/null +++ b/rpi2-debian-stdkernel/format-sdcard.py @@ -0,0 +1,33 @@ +#!/usr/bin/python3 + +import json +import subprocess +import sys + +def run(*l, **d): + print('run:', *l, d) + return subprocess.run(*l, **d) + +def main(): + if len(sys.argv) < 2: + print('Usage: {} '.format(sys.argv[0]), file=sys.stderr) + raise SystemExit(1) + device = sys.argv[1] + # first, clean possible gpt tables + run(['sudo', 'sgdisk', '--zap-all', device]) + part_commands = ''' + mklabel msdos + mkpart primary fat32 1M 99M + mkpart primary ext4 100M -1M + set 1 boot on + print + ''' + run(['sudo', 'parted', device], + check=True, input=part_commands.encode('utf8')) + run(['sudo', 'mkfs.vfat', '-n', 'boot', device + '1', ], check=True) + run(['sudo', 'mkfs.ext4', '-q', '-F', '-L', 'root', device + '2'], + check=True) + + +if __name__ == '__main__': + main() diff --git a/rpi2-debian-stdkernel/make-rpi-debootstrap.py b/rpi2-debian-stdkernel/make-rpi-debootstrap.py new file mode 100755 index 0000000..7925118 --- /dev/null +++ b/rpi2-debian-stdkernel/make-rpi-debootstrap.py @@ -0,0 +1,255 @@ +#!/usr/bin/python3 + +import os +import sys +import glob +import subprocess +import tempfile +import shutil +import re +import functools + +# http://elinux.org/RPi_U-Boot + +parameters = dict( + release='testing', + #mirror='http://fr.archive.ubuntu.com/ubuntu/', + mirror='http://httpredir.debian.org/debian', + arch='armhf', + packages=''' + aptitude + bash + bash-completion + bind9-host + bmon + busybox + bzip2 + curl + htop + iftop + ifupdown + iotop + iperf + iproute2 + iptables + iputils-ping + less + lftp + linux-image-armmp-lpae + locales + ncdu + ncurses-base + ncurses-term + net-tools + netbase + netcat + nload + openssh-client + openssh-server + psmisc + python3 + ranger + rsync + screen + sed + socat + strace + tar + tcpdump + telnet + tmux + tree + tzdata + vim + vim-nox + vim-runtime + w3m + wget + zsh + '''.split(), +) + + +open8 = functools.partial(open, encoding='utf8') +numerical_sort = lambda y: [int(x) if x.isdigit() else x + for x in re.split('(\d+)', y)] + + +def mlstrip(s): + return re.sub(r'^\s*', '', s, flags=re.MULTILINE) + + +def run(*l, **kw): + print('run:', *l) + return subprocess.run(*l, **kw) + + +def reexec_root(): + # run as root + if os.geteuid() != 0: + os.execvp("sudo", ["sudo"] + sys.argv) + + +def system_customization(rootdir): + os.unlink(rootdir + '/etc/localtime') + open8(rootdir + '/etc/zoneinfo', 'w').write('Europe/Paris\n') + shutil.copy(rootdir + '/usr/share/zoneinfo/Europe/Paris', + rootdir + '/etc/localtime') + + open8(rootdir + '/etc/network/interfaces', 'w').write(mlstrip( + '''\ + auto lo + iface lo inet loopback + + auto eth0 + iface eth0 inet dhcp + ''')) + open8(rootdir + '/etc/hosts', 'w').write(mlstrip( + '''\ + 127.0.0.1 localhost localhost.localdomain debian + + # the following lines are desirable for IPv6 capable hosts + ::1 localhost ip6-localhost ip6-loopback + ff02::1 ip6-allnodes + ff02::2 ip6-allrouters + ''')) + open8(rootdir + '/etc/hostname', 'w').write('debian\n') + os.makedirs(rootdir + '/boot/firmware', mode=0o755) + open8(rootdir + '/etc/fstab', 'w').write(mlstrip( + '''\ + # + /dev/mmcblk0p2 / ext4 errors=remount-ro,relatime 0 1 + /dev/mmcblk0p1 /boot/firmware vfat errors=remount-ro,relatime 0 2 + ''')) + + # activate serial console + run([ + 'ln', + '-s', + '/lib/systemd/system/serial-getty@.service', + rootdir + '/etc/systemd/system/getty.target.wants/serial-getty@ttyAMA0.service', + ], check=True) + os.makedirs(rootdir + '/etc/systemd/system/serial-getty@ttyAMA0.service.d', + mode=0o755) + open8(rootdir + + '/etc/systemd/system/serial-getty@ttyAMA0.service.d/autologin.conf', + 'w').write(mlstrip( + '''\ + [Service] + ExecStart= + ExecStart=-/sbin/agetty --autologin root --login-pause --noclear %I 115200,38400,9600 vt102 + ''')) + + open8(rootdir + '/etc/default/keyboard', 'w').write(mlstrip( + '''\ + XKBMODEL="pc105" + XKBLAYOUT="fr" + XKBVARIANT="bepo" + XKBOPTIONS="" + ''')) + + open8(rootdir + '/etc/default/locale', 'w').write(mlstrip( + '''\ + LANG="en_US.UTF-8" + LC_TIME="en_DK.UTF-8" + LC_PAPER="en_GB.UTF-8" + LC_MEASUREMENT="en_GB.UTF-8" + ''')) + + for locale in ['fr_FR', 'en_US', 'en_GB', 'en_DK', 'de_DE']: + run([ + 'localedef', + '--prefix={}'.format(rootdir), + '-f', 'UTF-8', + '-i', locale, + '{}.UTF-8'.format(locale) + ], check=True) + + open8(rootdir + '/etc/bash.bashrc', 'a').write(mlstrip( + '''\ + + # enable bash completion in interactive shells + if ! shopt -oq posix; then + if [ -f /usr/share/bash-completion/bash_completion ]; then + . /usr/share/bash-completion/bash_completion + elif [ -f /etc/bash_completion ]; then + . /etc/bash_completion + fi + fi + alias ls="ls --color=aut" + alias l="ls -CF" + alias ll="l -lh" + alias la="l -a" + alias e="vim" + alias rm='rm -i' + alias cp='cp -i' + alias mv='mv -i' + export PAGER=less + export EDITOR=vim + export VISUAL=vim + ''')) + + open8(rootdir + '/etc/vim/vimrc', 'w').write(mlstrip( + '''\ + set nocompatible + + au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif + filetype plugin indent on + set autoindent + set background=dark + set backspace=2 + set hidden + set hlsearch + set ignorecase + set incsearch + set laststatus=2 + set modelines=0 + set nobackup + set nowritebackup + set ruler + set scrolloff=3 + set shiftwidth=4 + set showcmd + set showmatch + set statusline=%<%f%h%m%r%=%l,%c\ %P + set ts=4 + set whichwrap=<,>,[,] + set wildmode=list:full + syntax on + ''')) + + + #kernel_params = 'ro text console=ttyAMA0,115200n8' + #kernel_params += ' console=tty0 net.ifnames=0' + #open8(rootdir + '/boot/grub/grub.cfg', 'w').write(mlstrip( + # '''\ + # terminal_output console + # serial --unit=0 --speed=115200 --word=8 --parity=no --stop=1 + # set default=0 + # set timeout=3 + # menuentry 'default' {{ + # search --set=root --file /boot/grub/grub.cfg --hint hd0,gpt2 + # linux /vmlinuz root=PARTUUID={rid} {kp} + # initrd /initrd.img + # }} + # '''.format(rid=rootpartuuid, kp=kernel_params))) + + +def main(): + reexec_root() + rootdir = 'debootstrapdir' + os.makedirs(rootdir, mode=0o755) + run([ + 'qemu-debootstrap', + '--arch=' + parameters['arch'], + '--include=' + ','.join(parameters['packages']), + '--components=main,contrib', + parameters['release'], + rootdir, + parameters['mirror'], + ], check=True) + system_customization(rootdir) + + +if __name__ == '__main__': + main() diff --git a/rpi2-debian-stdkernel/other_boot_files/boot.scr b/rpi2-debian-stdkernel/other_boot_files/boot.scr new file mode 100644 index 0000000..f1ec9f8 --- /dev/null +++ b/rpi2-debian-stdkernel/other_boot_files/boot.scr @@ -0,0 +1,25 @@ +# u-boot commands, this file must be compiled with mk-image (or use +# update-boot-uimage.sh) + +#setenv machid 0x00000c42 + +# set the fdtfile according to your board model +#setenv fdtfile bcm2709-rpi-2-b.dtb +#setenv fdtfile bcm2835-rpi-b-rev2.dtb +setenv fdtfile bcm2836-rpi-2-b.dtb + +mmc dev 0 +#ext4load mmc 0:2 ${kernel_addr_r} vmlinuz +fatload mmc 0:1 ${kernel_addr_r} kernel.img +#ext4load mmc 0:2 ${ramdisk_addr_r} initrd.img +fatload mmc 0:1 ${fdt_addr_r} ${fdtfile} +setenv bootargs earlyprintk console=ttyAMA0,115200n8 root=/dev/mmcblk0p2 rootfstype=ext4 rootwait noinitrd +#bootz ${kernel_addr_r} ${ramdisk_addr_r} ${fdt_addr_r} +bootz ${kernel_addr_r} - ${fdt_addr_r} +#bootz ${kernel_addr_r} + +#mmc dev 0 +#ext4load mmc 0:2 0x01000000 vmlinuz +#fatload mmc 0:1 0x00000100 bcm2835-rpi-b-rev2.dtb +#setenv bootargs earlyprintk console=ttyAMA0,115200n8 +#bootz 0x01000000 - 0x00000100 diff --git a/rpi2-debian-stdkernel/other_boot_files/config.txt b/rpi2-debian-stdkernel/other_boot_files/config.txt new file mode 100644 index 0000000..62e6fd5 --- /dev/null +++ b/rpi2-debian-stdkernel/other_boot_files/config.txt @@ -0,0 +1,6 @@ +enable_uart=1 +device_tree_address=0x100 +device_tree_end=0x8000 +kernel=u-boot.bin +dtparam=i2c_arm=on +dtparam=spi=on diff --git a/rpi2-debian-stdkernel/other_boot_files/ubuntu.pref b/rpi2-debian-stdkernel/other_boot_files/ubuntu.pref new file mode 100644 index 0000000..844bf1c --- /dev/null +++ b/rpi2-debian-stdkernel/other_boot_files/ubuntu.pref @@ -0,0 +1,3 @@ +Package: * +Pin: origin "ports.ubuntu.com" +Pin-Priority: 100 diff --git a/rpi2-debian-stdkernel/other_boot_files/ubuntu.sources b/rpi2-debian-stdkernel/other_boot_files/ubuntu.sources new file mode 100644 index 0000000..a8a167d --- /dev/null +++ b/rpi2-debian-stdkernel/other_boot_files/ubuntu.sources @@ -0,0 +1,4 @@ +Types: deb +URIs: http://ports.ubuntu.com +Suites: yakkety yakkety-updates +Components: main universe diff --git a/rpi2-debian-stdkernel/other_boot_files/update-boot-uimage.sh b/rpi2-debian-stdkernel/other_boot_files/update-boot-uimage.sh new file mode 100755 index 0000000..838e411 --- /dev/null +++ b/rpi2-debian-stdkernel/other_boot_files/update-boot-uimage.sh @@ -0,0 +1,3 @@ +#!/bin/bash +# Place the relevant set of boot commands into boot.scr +mkimage -A arm -O linux -T script -C none -n boot.scr -d boot.scr boot.scr.uimg diff --git a/rpi2-debian-stdkernel/other_boot_files/vg-copy-rpi b/rpi2-debian-stdkernel/other_boot_files/vg-copy-rpi new file mode 100755 index 0000000..a8eb53e --- /dev/null +++ b/rpi2-debian-stdkernel/other_boot_files/vg-copy-rpi @@ -0,0 +1,13 @@ +#!/bin/sh +set -eux +rootsource=$(findmnt -fno source -T /) +firmwaresource=$(findmnt -fno source -T /boot/firmware/) +if ! test x"$rootsource" = x"$firmwaresource"; then + cp --dereference /vmlinuz /boot/firmware/vmlinuz \ + || cp --dereference /vmlinuz.old /boot/firmware/vmlinuz + cp --dereference /initrd.img /boot/firmware/initrd.img \ + || cp --dereference /initrd.img.old /boot/firmware/initrd.img + ls -lah /vmlinuz /initrd.img > /boot/firmware/versions.txt \ + || ls -lah /vmlinuz.old /initrd.img.old > /boot/firmware/versions.txt +fi +exit 0 -- cgit v1.2.3