diff options
Diffstat (limited to 'elements/systems/devel-system-image.bst')
-rw-r--r-- | elements/systems/devel-system-image.bst | 141 |
1 files changed, 141 insertions, 0 deletions
diff --git a/elements/systems/devel-system-image.bst b/elements/systems/devel-system-image.bst new file mode 100644 index 00000000..7a91a2b4 --- /dev/null +++ b/elements/systems/devel-system-image.bst @@ -0,0 +1,141 @@ +kind: script +description: Create a deployment of the devel system +depends: +- filename: systems/devel-system.bst + type: build +- filename: deploy-tools.bst + type: build + +variables: + # Size of the disk to create + # + # Should be able to calculate this based on the space + # used, however it must be a multiple of (63 * 512) bytes + # as mtools wants a size that is devisable by sectors (512 bytes) + # per track (63). + boot-size: 252000K + + rootfs-size: 4G + swap-size: 1G + sector-size: 512 + +config: + base: deploy-tools.bst + input: systems/devel-system.bst + + collect: "%{install-root}" + + commands: + + - | + # Split up the boot directory and the other + cd /buildstream + mkdir -p /buildstream/sda1 + mkdir -p /buildstream/sda2 + + mv %{build-root}/boot/* /buildstream/sda1 + mv %{build-root}/* /buildstream/sda2 + + - | + # Generate an fstab + cat > /buildstream/sda2/etc/fstab << EOF + /dev/sda2 / ext4 defaults,rw,noatime 0 1 + /dev/sda1 /boot vfat defaults 0 2 + /dev/sda3 none swap defaults 0 0 + EOF + + - | + # Create the syslinux config + mkdir -p /buildstream/sda1/syslinux + cat > /buildstream/sda1/syslinux/syslinux.cfg << EOF + PROMPT 0 + TIMEOUT 5 + + ALLOWOPTIONS 1 + SERIAL 0 115200 + + DEFAULT boot + LABEL boot + + KERNEL /vmlinuz + INITRD /initramfs.gz + + APPEND root=/dev/sda2 rootfstype=ext4 rootdelay=20 init=/usr/lib/systemd/systemd + EOF + + - | + # Create the vfat image + truncate -s %{boot-size} /buildstream/sda1.img + mkdosfs /buildstream/sda1.img + + - | + # Copy all that stuff into the image + mcopy -D s -i /buildstream/sda1.img -s /buildstream/sda1/* ::/ + + - | + # Install the bootloader on the image, it should get the config file + # from inside the vfat image, I think + syslinux --directory /syslinux/ /buildstream/sda1.img + + - | + # Now create the root filesys on sda2 + truncate -s %{rootfs-size} /buildstream/sda2.img + mkfs.ext4 -F -i 8192 /buildstream/sda2.img -L root -d /buildstream/sda2 + + - | + # Create swap + truncate -s %{swap-size} /buildstream/sda3.img + mkswap -L swap /buildstream/sda3.img + + - | + + ######################################## + # Partition the disk # + ######################################## + + # First get the size in bytes + sda1size=$(stat --printf="%s" /buildstream/sda1.img) + sda2size=$(stat --printf="%s" /buildstream/sda2.img) + sda3size=$(stat --printf="%s" /buildstream/sda3.img) + + # Now convert to sectors + sda1sec=$(( ${sda1size} / %{sector-size} )) + sda2sec=$(( ${sda2size} / %{sector-size} )) + sda3sec=$(( ${sda3size} / %{sector-size} )) + + # Now get the offsets in sectors, first sector is MBR + sda1offset=1 + sda2offset=$(( ${sda1offset} + ${sda1sec} )) + sda3offset=$(( ${sda2offset} + ${sda2sec} )) + + # Get total disk size in sectors and bytes + sdasectors=$(( ${sda3offset} + ${sda3sec} )) + sdabytes=$(( ${sdasectors} * %{sector-size} )) + + # Create the main disk and do the partitioning + truncate -s ${sdabytes} /buildstream/sda.img + parted -s /buildstream/sda.img mklabel msdos + parted -s /buildstream/sda.img unit s mkpart primary fat32 ${sda1offset} $(( ${sda1offset} + ${sda1sec} - 1 )) + parted -s /buildstream/sda.img unit s mkpart primary ext2 ${sda2offset} $(( ${sda2offset} + ${sda2sec} - 1 )) + parted -s /buildstream/sda.img unit s mkpart primary linux-swap ${sda3offset} $(( ${sda3offset} + ${sda3sec} - 1 )) + + # Make partition 1 the boot partition + parted -s /buildstream/sda.img set 1 boot on + + # Now splice the existing filesystems directly into the image + dd if=/buildstream/sda1.img of=/buildstream/sda.img \ + ibs=%{sector-size} obs=%{sector-size} conv=notrunc \ + count=${sda1sec} seek=${sda1offset} + + dd if=/buildstream/sda2.img of=/buildstream/sda.img \ + ibs=%{sector-size} obs=%{sector-size} conv=notrunc \ + count=${sda2sec} seek=${sda2offset} + + dd if=/buildstream/sda3.img of=/buildstream/sda.img \ + ibs=%{sector-size} obs=%{sector-size} conv=notrunc \ + count=${sda3sec} seek=${sda3offset} + + - | + # Move the image where it will be collected + mv /buildstream/sda.img %{install-root} + chmod 0644 %{install-root}/sda.img |