mirror of
https://github.com/rancher/os.git
synced 2025-07-20 09:59:03 +00:00
Refactor image builder, add support for Pi 3
This commit is contained in:
parent
58c769cab5
commit
d30e307e2f
@ -1,15 +1,19 @@
|
||||
FROM debian:jessie
|
||||
ENV DAPPER_RUN_ARGS --device /dev/kvm
|
||||
ENV DAPPER_RUN_ARGS --privileged
|
||||
ENV DAPPER_OUTPUT dist
|
||||
RUN apt-get update -y
|
||||
RUN DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
|
||||
libguestfs-tools curl zip linux-image-amd64 unzip
|
||||
ca-certificates curl dosfstools tree zip
|
||||
RUN mkdir -p /source/assets
|
||||
|
||||
RUN curl -fL http://downloads.hypriot.com/hypriot-rpi-20151115-132854.img.zip > /source/assets/hypriot.img.zip
|
||||
RUN cd /source/assets && \
|
||||
unzip hypriot.img.zip
|
||||
# RancherOS for ARM
|
||||
RUN curl -fL https://releases.rancher.com/os/latest/rootfs_arm.tar.gz > /source/assets/rootfs_arm.tar.gz
|
||||
|
||||
# Hypriot Kernel 4.1.17+ and bootfiles for RPi2
|
||||
RUN curl -fL http://downloads.hypriot.com/raspberrypi-bootloader_20160212-075712_armhf.deb > /source/assets/raspberrypi-bootloader_20160212-075712_armhf.deb
|
||||
|
||||
# Bootfiles to support Raspberry Pi 3 B
|
||||
RUN curl -fL http://downloads.hypriot.com/rpi3-bootfiles.tar.gz > /source/assets/rpi3-bootfiles.tar.gz
|
||||
|
||||
WORKDIR /source
|
||||
CMD ["./scripts/build.sh"]
|
||||
|
@ -3,7 +3,9 @@ RaspberryPi 2 Image
|
||||
|
||||
Build by running `dapper` in this folder and the build will produce `./dist/rancheros-rpi2.zip`.
|
||||
|
||||
KVM
|
||||
===
|
||||
This image is compatible with the Raspberry Pi 3 too, but only ARMv7 is supported now.
|
||||
|
||||
This build requires a host capable of KVM. If you don't have KVM then remove `ENV DAPPER_RUN_ARGS --device /dev/kvm` from `Dockerfile.dapper`, but it will run very slow.
|
||||
Build Requirements
|
||||
==================
|
||||
|
||||
This build uses local loopback devices and thus requires to run as a privileged container. So please keep the setting `ENV DAPPER_RUN_ARGS --privileged` from `Dockerfile.dapper` for now. The build is running quite fast and has been tested on OS X with boot2docker.
|
||||
|
@ -1,36 +1,79 @@
|
||||
#!/bin/bash
|
||||
set -e -x
|
||||
|
||||
BOOT_DEVICE=/dev/sda1
|
||||
DEVICE=/dev/sda2
|
||||
|
||||
cd $(dirname $0)/..
|
||||
|
||||
mkdir -p dist build
|
||||
# create build directory for assembling our image filesystem
|
||||
mkdir -p build/{boot,root,basefs} dist
|
||||
|
||||
cp assets/hypriot*.img build/run.img
|
||||
guestfish --progress-bars --verbose -a build/run.img run \
|
||||
: mount $DEVICE / \
|
||||
: tar-out /lib/modules modules.tar \
|
||||
: tar-out /lib/firmware firmware.tar \
|
||||
: umount / \
|
||||
: zero-device $DEVICE \
|
||||
: mkfs ext4 $DEVICE \
|
||||
: mount $DEVICE / \
|
||||
: mkdir-p /lib/modules \
|
||||
: mkdir-p /lib/firmware \
|
||||
: set-verbose false \
|
||||
: echo tar-in modules.tar /lib/modules \
|
||||
: tar-in modules.tar /lib/modules \
|
||||
: echo tar-in firmware.tar /lib/firmware \
|
||||
: tar-in firmware.tar /lib/firmware \
|
||||
: echo tgz-in assets/rootfs_arm.tar.gz / \
|
||||
: tgz-in assets/rootfs_arm.tar.gz / \
|
||||
: set-verbose true \
|
||||
: umount / \
|
||||
: mount $BOOT_DEVICE / \
|
||||
: write /cmdline.txt "+dwc_otg.lpm_enable=0 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 cgroup-enable=memory swapaccount=1 elevator=deadline rootwait console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty0 rancher.password=rancher rw init=/init
|
||||
" \
|
||||
: umount /
|
||||
cp assets/raspberrypi-bootloader_*_armhf.deb build/bootloader.deb
|
||||
cp assets/rpi3-bootfiles.tar.gz build/rpi3-bootfiles.tar.gz
|
||||
|
||||
zip dist/rancheros-rpi2.zip build/run.img
|
||||
#---build SD card image---
|
||||
|
||||
# size of root and boot partion (in MByte)
|
||||
IMAGE_TOTAL_SIZE=500
|
||||
BOOT_PARTITION_START=2048
|
||||
BOOT_PARTITION_SIZE=25
|
||||
#---don't change here---
|
||||
BOOT_PARTITION_OFFSET="$((BOOT_PARTITION_START*512))"
|
||||
BOOT_PARTITION_BYTES="$((BOOT_PARTITION_SIZE*1024*1024))"
|
||||
BOOT_PARTITION_SECTORS="$((BOOT_PARTITION_SIZE*1024*2))"
|
||||
ROOT_PARTITION_START="$((BOOT_PARTITION_START+BOOT_PARTITION_SECTORS))"
|
||||
ROOT_PARTITION_OFFSET="$((ROOT_PARTITION_START*512))"
|
||||
#---don't change here---
|
||||
|
||||
# create image file with two partitions (FAT32, EXT4)
|
||||
dd if=/dev/zero of=build/run.img bs=1MiB count=$IMAGE_TOTAL_SIZE
|
||||
echo -e "o\nn\np\n1\n${BOOT_PARTITION_START}\n+${BOOT_PARTITION_SECTORS}\nt\nc\nn\np\n2\n${ROOT_PARTITION_START}\n\nw\n" | fdisk build/run.img
|
||||
fdisk -l build/run.img
|
||||
ls -al build/run.img
|
||||
|
||||
# partition #1 - Type= c W95 FAT32 (LBA)
|
||||
losetup -d /dev/loop0 || /bin/true
|
||||
losetup --offset $BOOT_PARTITION_OFFSET --sizelimit $BOOT_PARTITION_BYTES /dev/loop0 build/run.img
|
||||
mkfs.vfat -n RancherOS /dev/loop0
|
||||
losetup -d /dev/loop0
|
||||
|
||||
# partition #2 - Type=83 Linux
|
||||
losetup -d /dev/loop1 || /bin/true
|
||||
losetup --offset $ROOT_PARTITION_OFFSET /dev/loop1 build/run.img
|
||||
mkfs.ext4 -O ^has_journal -b 4096 -L rootfs /dev/loop1
|
||||
losetup -d /dev/loop1
|
||||
|
||||
# mount partitions as loopback devices
|
||||
mount -t ext4 -o loop=/dev/loop1,offset=$ROOT_PARTITION_OFFSET build/run.img build/root
|
||||
mkdir -p build/root/boot
|
||||
mount -t vfat -o loop=/dev/loop0,offset=$BOOT_PARTITION_OFFSET build/run.img build/root/boot
|
||||
echo "RancherOS: boot partition" > build/root/boot/boot.txt
|
||||
echo "RancherOS: root partition" > build/root/root.txt
|
||||
|
||||
# unpack and cleanup the basefs
|
||||
#- doing this on a local folder keeps our resulting image clean (no dirty blocks from a delete)
|
||||
dpkg-deb -x build/bootloader.deb build/basefs
|
||||
# upgrade Raspberry Pi bootfile for RPi3 support
|
||||
tar xvzf build/rpi3-bootfiles.tar.gz -C build/basefs/boot
|
||||
# remove RPi1 kernel, we only support RPi2 and RPi3 in ARMv7 mode
|
||||
rm -fr build/basefs/boot/kernel.img
|
||||
rm -fr build/basefs/lib/modules/{4.1.17+,4.1.17-hypriotos+}
|
||||
|
||||
# populate kernel, bootloader and RancherOS rootfs
|
||||
cp -R build/basefs/* build/root
|
||||
tar -xf assets/rootfs_arm.tar.gz -C build/root
|
||||
echo "+dwc_otg.lpm_enable=0 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 cgroup-enable=memory swapaccount=1 elevator=deadline rootwait console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty0 rancher.password=rancher rw init=/init" > build/root/boot/cmdline.txt
|
||||
|
||||
# show details
|
||||
tree -a -L 3 build/root
|
||||
df -h
|
||||
|
||||
# unmount partitions (loopback devices will be removed automatically)
|
||||
umount build/root/boot
|
||||
umount build/root
|
||||
|
||||
# package, compress and export image file
|
||||
mv build/run.img build/rancheros-rpi2.img
|
||||
zip dist/rancheros-rpi2.zip build/rancheros-rpi2.img
|
||||
ls -alh dist
|
||||
|
||||
# cleanup build environment
|
||||
rm -fr build
|
||||
|
Loading…
Reference in New Issue
Block a user