Image distribution

OK, job done! The manual installation is terminated, this part is optional, and it is necessary only if you wont to make a portable image that can be installed on SD cards of different size.

Before shutting down your Raspberry Pi run the following command:

pi@d-diot:~ $ sudo systemctl enable regenerate_ssh_host_keys

Enabling this service, when you boot the new created image for the first time only, a script that deletes the old ssh host keys and regenerate new ones will be executed.
In the d-diot image this service is enabled, so every installation will have different keys, that is good for the security.

If you wont to keep he Home Assistant installation as clean as possible before image creation, go to the service page under the developer tool and run the “recorder.purge” service, with the following parameters:

{
  "keep_days":"0",
  "repack":"true"
}

This service will erase the historical data in the MariaDB database.

To clean the Home Assistant log, from the service page call the service “system_log.clear”.

Now shutdown your Raspberry Pi.

pi@d-diot:~ $ sudo poweroff

Now clone your SD card. For this purpose, if you are on a Windows machine, you can use a dedicated software like Win32DiskImager or similar.
If you are on a Linux machine you can use dd. See this guide for more details.

Once the SD card is cloned to an .img file, is time to shrink the image to save space and to make it adaptable to SD cards of any size.
The easiest way that I have found is to use PiShrink, a useful script that runs on Linux machines and automates all the process.

Download and install PiShrink:

user@host:~$ git clone https://github.com/Drewsif/PiShrink.git
user@host:~$ cd PiShrink
user@host:~/PiShrink $ chmod +x pishrink.sh
user@host:~/PiShrink $ sudo mv pishrink.sh /usr/local/bin

Do the magic and shrink the image:

user@host:~$ sudo pishrink.sh  /path/to/origin/imagefile.img /path/to/destination/imagefile.img

Done, if you wont to save some additional space, zip the shrinked image.

Follow this guide if you wont to make some small changes to some file in your image without cloning the entire SD card again.

  • system_administration/manual_installation/9_image_distribution.txt
  • Last modified: 2019/04/29 16:29
  • by franzunix