Skip to content
This repository has been archived by the owner on Aug 14, 2023. It is now read-only.

Commit

Permalink
Merge pull request #8 from hypriot/prepare-odroid-partition-layout
Browse files Browse the repository at this point in the history
Prepare odroid partition layout
  • Loading branch information
StefanScherer committed Jun 7, 2016
2 parents 9cafe94 + 1a16fcd commit 8194275
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ services:
language: bash
script:
- make rpi-raw-image
- make odroid-raw-image
- ls -lah
branches:
only:
Expand All @@ -17,6 +18,8 @@ deploy:
file:
- "rpi-raw.img.zip"
- "rpi-raw.img.zip.sha256"
- "odroid-raw.img.zip"
- "odroid-raw.img.zip.sha256"
on:
tags: true
repo: hypriot/image-builder-raw
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ build:
rpi-raw-image: build
docker run --rm --privileged -v $(shell pwd):/workspace image-builder-raw /workspace/builder/rpi/build.sh

odroid-raw-image: build
docker run --rm --privileged -v $(shell pwd):/workspace image-builder-raw /workspace/builder/odroid/build.sh

shell: build
docker run --rm -ti --privileged -v $(shell pwd):/workspace image-builder-raw bash

Expand Down
69 changes: 69 additions & 0 deletions builder/odroid/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#!/bin/bash
set -ex
# this script should be run only inside of a Docker container
if [ ! -f /.dockerenv ]; then
echo "ERROR: script works only in a Docker container!"
exit 1
fi

### setting up some important variables to control the build process
BUILD_RESULT_PATH="/workspace"
IMAGE_PATH="odroid-raw.img"
SD_CARD_SIZE=800
BOOT_PARTITION_SIZE=64

# create empty BOOT/ROOTFS image file
# - SD_CARD_SIZE in MByte
# - DD uses 256 Bytes
# - sector block size is 512Bytes
# - MBR size is 512 Bytes, so we start at sector 2048 (1MByte reserved space)
BOOTFS_START=3072
BOOTFS_SIZE=$((BOOT_PARTITION_SIZE * 2048))
ROOTFS_START=$((BOOTFS_SIZE + BOOTFS_START))
SD_MINUS_DD=$((SD_CARD_SIZE * 1024 * 1024 - 256))
ROOTFS_SIZE=$((SD_MINUS_DD / 512 - ROOTFS_START))

dd if=/dev/zero of=${IMAGE_PATH} bs=1MiB count=${SD_CARD_SIZE}

DEVICE=$(losetup -f --show ${IMAGE_PATH})

echo "Image ${IMAGE_PATH} created and mounted as ${DEVICE}."

# create partions
sfdisk --force "${DEVICE}" <<PARTITION
unit: sectors
/dev/loop0p1 : start= ${BOOTFS_START}, size= ${BOOTFS_SIZE}, Id= c
/dev/loop0p2 : start= ${ROOTFS_START}, size= ${ROOTFS_SIZE}, Id=83
/dev/loop0p3 : start= 0, size= 0, Id= 0
/dev/loop0p4 : start= 0, size= 0, Id= 0
PARTITION

losetup -d "${DEVICE}"
DEVICE=$(kpartx -va ${IMAGE_PATH} | sed -E 's/.*(loop[0-9])p.*/\1/g' | head -1)
dmsetup --noudevsync mknodes
BOOTP="/dev/mapper/${DEVICE}p1"
ROOTP="/dev/mapper/${DEVICE}p2"
DEVICE="/dev/${DEVICE}"

# give some time to system to refresh
sleep 3

# create file systems
mkfs.vfat "${BOOTP}" -n HypriotOS
mkfs.ext4 "${ROOTP}" -L root -i 4096 # create 1 inode per 4kByte block (maximum ratio is 1 per 1kByte)

echo "### remove dev mapper devices for image partitions"
kpartx -vds ${IMAGE_PATH} || true

# ensure that the travis-ci user can access the sd-card image file
umask 0000

# compress image
zip "${BUILD_RESULT_PATH}/${IMAGE_PATH}.zip" "${IMAGE_PATH}"
sleep 2
cd ${BUILD_RESULT_PATH} && sha256sum "${IMAGE_PATH}.zip" > "${IMAGE_PATH}.zip.sha256" && cd -

fdisk -l /odroid-raw.img
# test raw image that we have built
rspec --format documentation --color ${BUILD_RESULT_PATH}/builder/odroid/test
36 changes: 36 additions & 0 deletions builder/odroid/test/image_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
require 'serverspec'
set :backend, :exec

describe "Raw Image" do
let(:image_path) { return '/odroid-raw.img' }

it "exists" do
image_file = file(image_path)
expect(image_file).to exist
end

context "Partition table" do
let(:stdout) { command("fdisk -l #{image_path} | grep '^/odroid-raw'").stdout }

it "has 2 partitions" do
partitions = stdout.split(/\r?\n/)
expect(partitions.size).to be 2
end

it "has a boot-partition with a sda1 W95 FAT32 filesystem" do
expect(stdout).to contain('^.*\.img1 .*W95 FAT32 \(LBA\)$')
end

it "has a root-partition with a sda2 Linux filesystem" do
expect(stdout).to contain('^.*\.img2 .*Linux$')
end

it "partition sda1 starts at sector 3072" do
expect(stdout).to contain('^.*\.img1\ *3072 .*$')
end

it "partition sda1 has a size of 64M" do
expect(stdout).to contain('^.*\.img1.* 64M c.*$')
end
end
end

0 comments on commit 8194275

Please sign in to comment.