Skip to content

Commit

Permalink
pi/common: add buildimage command to create .img
Browse files Browse the repository at this point in the history
Signed-off-by: Luis Banuelos <[email protected]>
Reviewed-by: Christian Stewart <[email protected]>
  • Loading branch information
luisbc92 authored and paralin committed May 1, 2021
1 parent c37a8d1 commit 1b26850
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
5 changes: 5 additions & 0 deletions configs/pi/common/extensions/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,8 @@ format:
install:
@$(SKIFF_CURRENT_CONF_DIR)/scripts/install_sd.sh

buildimage:
@$(SKIFF_CURRENT_CONF_DIR)/scripts/build_image.sh

# alias to buildimage
create-image: buildimage
1 change: 1 addition & 0 deletions configs/pi/common/metadata/commands
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
format Format a SD card and install bootloader.
install Installs to a formatted SD card.
buildimage Builds an image using a loopback device.
31 changes: 31 additions & 0 deletions configs/pi/common/scripts/build_image.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash

if [ $EUID != 0 ]; then
echo "This script requires sudo, so it might not work."
fi

set -e

if [ -z "$PI_IMAGE" ]; then
echo "Please set PI_IMAGE and try agian."
exit 1
fi

if [[ "$PI_IMAGE" != /* ]]; then
PI_IMAGE=$WORKSPACE_DIR/$PI_IMAGE
fi

echo "Allocating image..."
dd if=/dev/zero of=$PI_IMAGE bs=1GB count=1

echo "Setting up loopback device..."
PI_SD=$(sudo losetup --show -fP $PI_IMAGE)

# Setup no interactive since we know its a brand new file.
export SKIFF_NO_INTERACTIVE=1

$SKIFF_CURRENT_CONF_DIR/scripts/format_sd.sh
$SKIFF_CURRENT_CONF_DIR/scripts/install_sd.sh

echo "Removing loopback device..."
sudo losetup -d $PI_SD

0 comments on commit 1b26850

Please sign in to comment.