lukechilds / dockerpi

A Virtualised Raspberry Pi inside a Docker image
MIT License
1.76k stars 181 forks source link

Various and different bugs inside the entrypoint.sh file and or dockerfile #37

Open Marietto2008 opened 3 years ago

Marietto2008 commented 3 years ago

My goal is to enable the persistent data storage using a bigger raspbian buster image file. This is what I did :

1) qemu-img resize 2019-09-26-raspbian-buster-lite.img 32G 2) zip 2019-09-26-raspbian-buster-lite.zip 2019-09-26-raspbian-buster-lite.img

at this point,I realized that for some unknown reason,the zipped file wasn't decompressed correctly by the zip utility,which gives a generic unzip extraction error. So,I've thought to use tar and the error is gone. So we can jump to step 3 :

3) tar -czvf 2019-09-26-raspbian-buster-lite.tar.gz 2019-09-26-raspbian-buster-lite.img

So,now I had to modify slightly Dockerfile and entrypoint.sh files like this :

4) entrypoint.sh :

#!/bin/sh

GIB_IN_BYTES="1073741824"

target="${1:-pi1}"
image_path="/sdcard/filesystem.img"
zip_path="/filesystem.tar.gz"

if [ ! -e $image_path ]; then
#  echo "No filesystem detected at ${image_path}!"
   if [ -e $zip_path ]; then
      echo "Extracting fresh filesystem..."
    # unzip $zip_path
      tar -xzvf $zip_path
      mv *.img $image_path
  else
    exit 1
  fi
fi

5) Dockerfile :

FROM dockerpi-vm as dockerpi

ARG FILESYSTEM_IMAGE_URL="http://ziomario.ns0.it/2019-09-26-raspbian-buster-lite.tar.gz"
ADD $FILESYSTEM_IMAGE_URL /filesystem.tar.gz

But as I said at the beginning,I wanted to have persistent data storage,but only for the VM model 3,the one with the parameter "machine=raspi3b". I realized that starting the container like this :

-v $HOME/.dockerpi:/sdcard lukechilds/dockerpi

it enables the persistence of the datas only for the VM model 1,the one with the paramter "machine=versatilepb" but I'm not interested to it AND if I start the VM like this :

-v $HOME/.dockerpi:/sdcard lukechilds/dockerpi pi3

it is not supported. It doesn't even enable the persistence for the VM model 3,but only for the model 1. So,let's jump to point 6)

6) I have modified again the entrypoint.sh script like this :

if [ "${target}" = "pi3" ]; then
  emulator=qemu-system-arm
  kernel="/root/qemu-rpi-kernel/kernel-qemu-4.19.50-buster"
  dtb="/root/qemu-rpi-kernel/versatile-pb.dtb"
  machine=versatilepb
  memory=256m
  root=/dev/sda2
  nic="--net nic --net user,hostfwd=tcp::5022-:22"
elif [ "${target}" = "pi2" ]; then
  emulator=qemu-system-arm
  machine=raspi2b
  memory=1024m
  kernel_pattern=kernel7.img
  dtb_pattern=bcm2709-rpi-2-b.dtb
  append="dwc_otg.fiq_fsm_enable=0"
  nic="-netdev user,id=net0,hostfwd=tcp::5022-:22 -device usb-net,netdev=net0"
elif [ "${target}" = "pi1" ]; then
  emulator=qemu-system-aarch64
  machine=raspi3b
  memory=1024m
  memory=1024m
  kernel_pattern=kernel8.img
  dtb_pattern=bcm2710-rpi-3-b-plus.dtb
  append="dwc_otg.fiq_fsm_enable=0"
  nic="-netdev user,id=net0,hostfwd=tcp::5022-:22 -device usb-net,netdev=net0"
else
  echo "Target ${target} not supported"
  echo "Supported targets: pi1 pi2 pi3"
  exit 2
fi

and finally,point 7 :

7) I can start the container with this start.sh script :

!/bin/bash
XSOCK=/tmp/.X11-unix
XAUTH=/tmp/.docker.xauth
touch $XAUTH
xauth nlist $DISPLAY | sed -e 's/^..../ffff/' | xauth -f $XAUTH nmerge -

docker run \
        -it \
        -v $XSOCK:$XSOCK:rw \
        -v $XAUTH:$XAUTH:rw \
        -e DISPLAY=$DISPLAY \
        -e XAUTHORITY=$XAUTH \
        -v $HOME/.dockerpi:/sdcard lukechilds/dockerpi

8) and now,after having did all of this,I get the following error when it decompress the tar.gz image file :

Screenshot_2021-06-06_00-19-24