From 5af1c085bff377220047e80d8e4a64a5d8819d83 Mon Sep 17 00:00:00 2001 From: Joren Van Onder Date: Tue, 15 Mar 2016 14:28:12 +0100 Subject: [PATCH] [IMP] point_of_sale: migrate POSBox to Raspbian Jessie The main reason for doing this is supporting the new Raspberry Pi 3. No functional changes where made. For Raspbian Wheezy we used to download the full image and strip it as best we could to obtain a reasonable image size for people to download. Since Raspbian Jessie the Raspberry Pi Foundation has started releasing an official minimal image (Raspbian Jessie Lite) which we will use from now on to build our image. One downside of this is that the minimal image is a 1.3 GiB image which is too small for our purposes so it has to be resized. Because Raspbian Jessie migrated to systemd we cannot rely on /etc/init.d/rcS to set up the ramdisks anymore. Jessie provides a compatibility layer so old SysVinit scripts still work but rcS does not block like it does in a SysVinit system, it is run in parallel with other startup services. In our case this is a bad thing as setting up the ramdisks has to be done before any other services are started. To accomplish this the rcS hack has been migrated to a systemd service running before basic.target and with DefaultDependencies=no. This has a similar effect as the rcS hack because normal systemd services (with DefaultDependencies=yes) all require basic.target by default. --- .../posbox/configuration/setup_ramdisks.sh | 9 +++--- .../overwrite_after_init/etc/init.d/rcS | 10 ------- .../overwrite_after_init/etc/ld.so.preload | 1 + .../posbox/overwrite_before_init/etc/fstab | 5 ++++ .../etc/init_posbox_image.sh | 28 ++++--------------- .../overwrite_before_init/etc/ld.so.preload | 2 +- .../etc/systemd/system/ramdisks.service | 12 ++++++++ .../tools/posbox/posbox_create_image.sh | 23 ++++++++++++++- .../tools/posbox/posbox_download_images.sh | 4 +-- 9 files changed, 53 insertions(+), 41 deletions(-) delete mode 100755 addons/point_of_sale/tools/posbox/overwrite_after_init/etc/init.d/rcS create mode 100644 addons/point_of_sale/tools/posbox/overwrite_after_init/etc/ld.so.preload create mode 100644 addons/point_of_sale/tools/posbox/overwrite_before_init/etc/fstab create mode 100644 addons/point_of_sale/tools/posbox/overwrite_before_init/etc/systemd/system/ramdisks.service diff --git a/addons/point_of_sale/tools/posbox/configuration/setup_ramdisks.sh b/addons/point_of_sale/tools/posbox/configuration/setup_ramdisks.sh index 47e11d1bdd3..ce2f2e633e6 100755 --- a/addons/point_of_sale/tools/posbox/configuration/setup_ramdisks.sh +++ b/addons/point_of_sale/tools/posbox/configuration/setup_ramdisks.sh @@ -15,11 +15,10 @@ create_ramdisk () { mount --bind "${RAMDISK}" "${ORIGINAL}" } -# check /proc/cmdline - -# bind mount / so that we can get to the real /var and /etc -mount --bind / /root_bypass_ramdisks - echo "Creating ramdisks..." create_ramdisk "/var" "128M" create_ramdisk "/etc" "16M" +create_ramdisk "/tmp" "16M" + +# bind mount / so that we can get to the real /var and /etc +mount --bind / /root_bypass_ramdisks diff --git a/addons/point_of_sale/tools/posbox/overwrite_after_init/etc/init.d/rcS b/addons/point_of_sale/tools/posbox/overwrite_after_init/etc/init.d/rcS deleted file mode 100755 index 4d32107fac8..00000000000 --- a/addons/point_of_sale/tools/posbox/overwrite_after_init/etc/init.d/rcS +++ /dev/null @@ -1,10 +0,0 @@ -#! /bin/sh -# -# rcS -# -# Call all S??* scripts in /etc/rcS.d/ in numerical/alphabetical order -# - -/home/pi/odoo/addons/point_of_sale/tools/posbox/configuration/setup_ramdisks.sh - -exec /etc/init.d/rc S diff --git a/addons/point_of_sale/tools/posbox/overwrite_after_init/etc/ld.so.preload b/addons/point_of_sale/tools/posbox/overwrite_after_init/etc/ld.so.preload new file mode 100644 index 00000000000..37a96726c29 --- /dev/null +++ b/addons/point_of_sale/tools/posbox/overwrite_after_init/etc/ld.so.preload @@ -0,0 +1 @@ +/usr/lib/arm-linux-gnueabihf/libarmmem.so diff --git a/addons/point_of_sale/tools/posbox/overwrite_before_init/etc/fstab b/addons/point_of_sale/tools/posbox/overwrite_before_init/etc/fstab new file mode 100644 index 00000000000..d8e448c02d0 --- /dev/null +++ b/addons/point_of_sale/tools/posbox/overwrite_before_init/etc/fstab @@ -0,0 +1,5 @@ +proc /proc proc defaults 0 0 +#/dev/mmcblk0p1 /boot vfat defaults 0 2 +#/dev/mmcblk0p2 / ext4 defaults,noatime 0 1 +# a swapfile is not a swap partition, no line here +# use dphys-swapfile swap[on|off] for that diff --git a/addons/point_of_sale/tools/posbox/overwrite_before_init/etc/init_posbox_image.sh b/addons/point_of_sale/tools/posbox/overwrite_before_init/etc/init_posbox_image.sh index c6d019cd945..86d2e7ffe3b 100755 --- a/addons/point_of_sale/tools/posbox/overwrite_before_init/etc/init_posbox_image.sh +++ b/addons/point_of_sale/tools/posbox/overwrite_before_init/etc/init_posbox_image.sh @@ -11,37 +11,16 @@ __base="$(basename ${__file} .sh)" # Recommends: antiword, graphviz, ghostscript, postgresql, python-gevent, poppler-utils export DEBIAN_FRONTEND=noninteractive -# GUI-related packages -PKGS_TO_DELETE="xserver-xorg-video-fbdev xserver-xorg xinit gstreamer1.0-x gstreamer1.0-omx gstreamer1.0-plugins-base gstreamer1.0-plugins-good gstreamer1.0-plugins-bad gstreamer1.0-alsa gstreamer1.0-libav epiphany-browser lxde lxtask menu-xdg gksu xserver-xorg-video-fbturbo xpdf gtk2-engines alsa-utils netsurf-gtk zenity desktop-base lxpolkit weston omxplayer raspberrypi-artwork lightdm gnome-themes-standard-data gnome-icon-theme qt50-snapshot qt50-quick-particle-examples idle python-pygame python-tk idle3 python-serial python-picamera debian-reference-en dillo x2x scratch nuscratch raspberrypi-ui-mods timidity smartsim penguinspuzzle pistore sonic-pi python-pifacecommon python-pifacedigitalio oracle-java8-jdk minecraft-pi python-minecraftpi wolfram-engine raspi-config libgl1-mesa-dri libicu48 pypy-upstream lxde-icon-theme python3 avahi-daemon" -INSTALLED_PKGS_TO_DELETE="" -set +o errexit -for CURRENT_PKG in $(echo $PKGS_TO_DELETE); do - $(dpkg --status $CURRENT_PKG &> /dev/null) - if [[ $? -eq 0 ]]; then - INSTALLED_PKGS_TO_DELETE="$INSTALLED_PKGS_TO_DELETE $CURRENT_PKG" - fi -done -set -o errexit - -apt-get -y remove --purge ${INSTALLED_PKGS_TO_DELETE} - -# Remove automatically installed dependency packages -apt-get -y autoremove - apt-get update apt-get -y dist-upgrade -PKGS_TO_INSTALL="adduser postgresql-client python python-dateutil python-decorator python-docutils python-feedparser python-imaging python-jinja2 python-ldap python-libxslt1 python-lxml python-mako python-mock python-openid python-passlib python-psutil python-psycopg2 python-pybabel python-pychart python-pydot python-pyparsing python-pypdf python-reportlab python-requests python-simplejson python-tz python-unittest2 python-vatnumber python-vobject python-werkzeug python-xlwt python-yaml postgresql python-gevent python-serial python-pip python-dev localepurge vim mc mg screen iw hostapd isc-dhcp-server" +PKGS_TO_INSTALL="adduser postgresql-client python python-dateutil python-decorator python-docutils python-feedparser python-imaging python-jinja2 python-ldap python-libxslt1 python-lxml python-mako python-mock python-openid python-passlib python-psutil python-psycopg2 python-pybabel python-pychart python-pydot python-pyparsing python-pypdf python-reportlab python-requests python-simplejson python-tz python-unittest2 python-vatnumber python-vobject python-werkzeug python-xlwt python-yaml postgresql python-gevent python-serial python-pip python-dev localepurge vim mc mg screen iw hostapd isc-dhcp-server git rsync console-data" apt-get -y install ${PKGS_TO_INSTALL} apt-get clean localepurge rm -rf /usr/share/doc -rm -rf /home/pi/python_games - -# remove raspi-config notice, it's not necessary and it's not installed anyway -rm -f /etc/profile.d/raspi-config.sh # python-usb in wheezy is too old # the latest pyusb from pip does not work either, usb.core.find() never returns @@ -70,6 +49,10 @@ echo "* * * * * rm /var/run/odoo/sessions/*" | crontab - update-rc.d -f hostapd remove update-rc.d -f isc-dhcp-server remove +systemctl daemon-reload +systemctl enable ramdisks.service +systemctl disable dphys-swapfile.service + # https://www.raspberrypi.org/forums/viewtopic.php?p=79249 # to not have "setting up console font and keymap" during boot take ages setupcon @@ -81,6 +64,7 @@ create_ramdisk_dir () { create_ramdisk_dir "/var" create_ramdisk_dir "/etc" +create_ramdisk_dir "/tmp" mkdir /root_bypass_ramdisks reboot diff --git a/addons/point_of_sale/tools/posbox/overwrite_before_init/etc/ld.so.preload b/addons/point_of_sale/tools/posbox/overwrite_before_init/etc/ld.so.preload index cfa850b8356..f1341ff1a3e 100644 --- a/addons/point_of_sale/tools/posbox/overwrite_before_init/etc/ld.so.preload +++ b/addons/point_of_sale/tools/posbox/overwrite_before_init/etc/ld.so.preload @@ -1 +1 @@ -#/usr/lib/arm-linux-gnueabihf/libcofi_rpi.so +#/usr/lib/arm-linux-gnueabihf/libarmmem.so diff --git a/addons/point_of_sale/tools/posbox/overwrite_before_init/etc/systemd/system/ramdisks.service b/addons/point_of_sale/tools/posbox/overwrite_before_init/etc/systemd/system/ramdisks.service new file mode 100644 index 00000000000..48c75daabb8 --- /dev/null +++ b/addons/point_of_sale/tools/posbox/overwrite_before_init/etc/systemd/system/ramdisks.service @@ -0,0 +1,12 @@ +[Unit] +Description=ramdisks +DefaultDependencies=no +After=sysinit.target local-fs.target +Before=basic.target + +[Service] +Type=oneshot +ExecStart=/home/pi/odoo/addons/point_of_sale/tools/posbox/configuration/setup_ramdisks.sh + +[Install] +WantedBy=basic.target diff --git a/addons/point_of_sale/tools/posbox/posbox_create_image.sh b/addons/point_of_sale/tools/posbox/posbox_create_image.sh index 5e3d464ef2b..ba01ef09da5 100755 --- a/addons/point_of_sale/tools/posbox/posbox_create_image.sh +++ b/addons/point_of_sale/tools/posbox/posbox_create_image.sh @@ -50,8 +50,29 @@ rm ngrok.zip cd "${__dir}" mv /tmp/ngrok "${USR_BIN}" +# zero pad the image to be around 3.5 GiB, by default the image is only ~1.3 GiB +dd if=/dev/zero bs=1M count=2048 >> posbox.img + +# resize partition table +START_OF_ROOT_PARTITION=$(fdisk -l posbox.img | tail -n 1 | awk '{print $2}') +(echo 'p'; # print + echo 'd'; # delete + echo '2'; # second partition + echo 'n'; # create new partition + echo 'p'; # primary + echo '2'; # number 2 + echo "${START_OF_ROOT_PARTITION}"; # starting at previous offset + echo ''; # ending at default (fdisk should propose max) + echo 'p'; # print + echo 'w') | fdisk posbox.img # write and quit + LOOP_MAPPER_PATH=$(kpartx -av posbox.img | tail -n 1 | cut -d ' ' -f 3) LOOP_MAPPER_PATH="/dev/mapper/${LOOP_MAPPER_PATH}" + +# resize filesystem +e2fsck -f "${LOOP_MAPPER_PATH}" # resize2fs requires clean fs +resize2fs "${LOOP_MAPPER_PATH}" + mkdir "${MOUNT_POINT}" mount "${LOOP_MAPPER_PATH}" "${MOUNT_POINT}" @@ -70,7 +91,7 @@ umount "${MOUNT_POINT}" # from http://paulscott.co.za/blog/full-raspberry-pi-raspbian-emulation-with-qemu/ # ssh pi@localhost -p10022 -QEMU_OPTS=(-kernel kernel-qemu -cpu arm1176 -m 256 -M versatilepb -no-reboot -serial stdio -append 'root=/dev/sda2 panic=1 rootfstype=ext4 rw' -hda posbox.img -net user,hostfwd=tcp::10022-:22,hostfwd=tcp::18069-:8069 -net nic) +QEMU_OPTS=(-kernel kernel-qemu -cpu arm1176 -m 256 -M versatilepb -no-reboot -serial stdio -append 'root=/dev/sda2 rootfstype=ext4 rw' -hda posbox.img -net user,hostfwd=tcp::10022-:22,hostfwd=tcp::18069-:8069 -net nic) if [ -z ${DISPLAY:-} ] ; then QEMU_OPTS+=(-nographic) fi diff --git a/addons/point_of_sale/tools/posbox/posbox_download_images.sh b/addons/point_of_sale/tools/posbox/posbox_download_images.sh index a138e44bfab..b500094058d 100755 --- a/addons/point_of_sale/tools/posbox/posbox_download_images.sh +++ b/addons/point_of_sale/tools/posbox/posbox_download_images.sh @@ -1,5 +1,5 @@ #!/bin/sh -wget 'http://downloads.raspberrypi.org/raspbian_latest' -O raspbian.img.zip +wget 'https://downloads.raspberrypi.org/raspbian_lite_latest' -O raspbian.img.zip unzip raspbian.img.zip -wget 'https://github.com/dhruvvyas90/qemu-rpi-kernel/raw/master/kernel-qemu' +wget 'https://github.com/dhruvvyas90/qemu-rpi-kernel/raw/master/kernel-qemu-4.1.13-jessie' -O kernel-qemu