10 August 2021

Rasberry Pi 4 Print Server: Part 2

These are the steps that I went thru to update the firmware and get Ubuntu Server 20.04 LTS installed on my Raspberry Pi 4 2GB from my Chromebook

Prerequisites:

Firmware Update Steps:
  1. Download the latest firmware from: https://github.com/raspberrypi/rpi-eeprom/releases
  2. Insert your SD Card into your Chromebook
  3. Copy the Contents of the Zip file onto the SD Card
  4. Uses Files to eject your SD Card and then remove from Chromebook
  5. Boot your Raspberry Pi using the SD Card
Ubuntu Steps:

  1. Download 64-bit Ubuntu Server for Rasberry Pi from here: https://ubuntu.com/download/raspberry-pi
  2. In Files: Move it from Downloads to your Linux Files
  3. On the Linux Command Prompt run:
    • xz -d ubuntu-20.04.1-preinstalled-server-arm64+raspi.img.xz
  4. In Files: Right click the IMG file and click Zip selection
  5. Insert your SD Card or USB Drive you want to use
  6. Write the image to your removable media:
    1. Open Chromebook Recovery Utility
    2. Click the Setting Wheel next to the close window button
    3. Click "Use local image"
    4. Use files to select the zip file you just created
    5. Wait for the progress bar to complete TWICE (once for unpacking, once for writing)
    6. Exit Chromebook Recovery Utility
  7. Ubuntu 20.04 preinstalled servers uses cloud-init on first boot, you can find out more here:
  8. Setup your WiFi
    1. Open /system-boot/network-config in a text editor
    2. Uncomment (remove the # from the front of the line) the wifis section and update it with your wireless network and password
    3. wifis:
        wlan0:
          dhcp4: true
          optional: true
          access-points:
            "YourWifiNameHere":
              password: "YourPasswordHere"

    4. Or for a fixed IP
    5. wifis:
        wlan0:
          addresses: [192.168.1.XX/24]
          gateway4: 192.168.1.1
          nameservers:
            addresses: [192.168.1.1]
          dhcp4: false
          optional: true
          access-points:
            "YourWifiNameHere":
              password: "YourPasswordHere"

    6. Save the File
  9. If you are using a SD Card, you are finished and can:
    1. Eject the removable media using the Files app
    2. Remove it from the laptop
If you are using a USB Flash Drive, follow these additional steps:
  1. Decompress vmlinux
    1. Share the system-boot partition with Linux
      • In the files app, right click it and click "Share with Linux"
    2. Open the terminal
      1. cd /mnt/chromeos/removable/system-boot
      2. zcat vmlinuz > vmlinux
  2. Update /system-boot/config.txt to have the pi4 section look like:
    • [pi4]
      max_framebuffers=2
      dtoverlay=vc4-fkms-v3d
      boot_delay
      kernel=vmlinux
      initramfs initrd.img followkernel
  3. Install a script that will do this after installing updates (currently this cannot be done on a Chromebook because the writable partition is mounted read-only --oh the irony--)
    1. Create a file on /system-boot (/system-boot/firmware if logged into the pi) called auto_decompress_kernel and paste the code that is at the end of the blog
    2. Create a file in /writable/etc/apt/apt.conf.d called 999_decompress_rpi_kernel and paste the following single line into it:
      • DPkg::Post-Invoke {"/bin/bash /boot/auto_decompress_kernel"; };
    3. Share the writable partition with Linux
      • In the files app, right click it and click "Share with Linux"
    4. Open the terminal
      1. cd /mnt/chromeos/removable/writable/etc/apt/apt.conf.d
      2. chmod +x 999_decompress_rpi_kernel
You can now install the SD card or USB drive into the Raspberry Pi and start it up. You will need to login and change the password and then reboot (sudo reboot now) before it will connect to WiFi


auto_decompress_kernel
#!/bin/bash -e

#Set Variables
BTPATH=/boot/firmware
CKPATH=$BTPATH/vmlinuz
DKPATH=$BTPATH/vmlinux

#Check if compression needs to be done.
if [ -e $BTPATH/check.md5 ]; then
    if md5sum --status --ignore-missing -c $BTPATH/check.md5; then
    echo -e "e[32mFiles have not changed, Decompression not needede[0m"
    exit 0
    else echo -e "e[31mHash failed, kernel will be compressede[0m"
    fi
fi

#Backup the old decompressed kernel
mv $DKPATH $DKPATH.bak

if [ ! $? == 0 ]; then
    echo -e "e[31mDECOMPRESSED KERNEL BACKUP FAILED!e[0m"
    exit 1
else    echo -e "e[32mDecompressed kernel backup was successfule[0m"
fi

#Decompress the new kernel
echo "Decompressing kernel: "$CKPATH".............."

zcat $CKPATH > $DKPATH

if [ ! $? == 0 ]; then
    echo -e "e[31mKERNEL FAILED TO DECOMPRESS!e[0m"
    exit 1
else
    echo -e "e[32mKernel Decompressed Succesfullye[0m"
fi

#Hash the new kernel for checking
md5sum $CKPATH $DKPATH > $BTPATH/check.md5

if [ ! $? == 0 ]; then
    echo -e "e[31mMD5 GENERATION FAILED!e[0m"
    else echo -e "e[32mMD5 generated Succesfullye[0m"
fi

#Exit
exit 0

Sources and Thanks to:


No comments:

Post a Comment