tadd basic imaging - libdevuansdk - common library for devuan's simple distro kits (HTM) git clone https://git.parazyd.org/libdevuansdk (DIR) Log (DIR) Files (DIR) Refs (DIR) Submodules (DIR) README (DIR) LICENSE --- (DIR) commit 47464d636879875f9cd2cb865912756fff815559 (DIR) parent 91b1f24e1cfa25ada9fa7a6bb8758a08a4ca2ecd (HTM) Author: parazyd <parazyd@dyne.org> Date: Thu, 29 Sep 2016 22:36:12 +0200 add basic imaging Diffstat: M config | 2 ++ M libdevuansdk | 1 + M zlibs/bootstrap | 7 +++++-- M zlibs/helpers | 13 +++++++++++++ A zlibs/imaging | 92 +++++++++++++++++++++++++++++++ 5 files changed, 113 insertions(+), 2 deletions(-) --- (DIR) diff --git a/config b/config t@@ -28,6 +28,8 @@ version="1.0.0-beta" mirror="http://packages.devuan.org/merged" section="main" +image_name=${image_name:-$os_$release_$version_$arch.img} + core_packages=( devuan_keyring debian_keyring (DIR) diff --git a/libdevuansdk b/libdevuansdk t@@ -23,6 +23,7 @@ LIBPATH=${LIBPATH:-`dirname $0`} source $LIBPATH/config source $LIBPATH/zlibs/bootstrap source $LIBPATH/zlibs/helpers +source $LIBPATH/zlibs/imaging source $LIBPATH/zlibs/sysconf vars+=(libdevuansdk_version) (DIR) diff --git a/zlibs/bootstrap b/zlibs/bootstrap t@@ -19,8 +19,8 @@ vars+=(bootstrap_tgz) -bootstrap() { - fn bootstrap "$@" +bootstrap_complete_base() { + fn bootstrap_complete_base "$@" req=(arch) ckreq || return 1 t@@ -55,6 +55,9 @@ bootstrap() { conf_print_networkifaces | sudo tee $strapdir/etc/network/interfaces conf_print_resolvconf | sudo tee $strapdir/etc/resolv.conf conf_print_sourceslist | sudo tee $strapdir/etc/apt/sources.list + ## below typically used in arm-sdk + [[ -n $inittap ]] && { print $inittab | sudo tee -a $strapdir/etc/inittab } + for i in $custmodules; do print $i | sudo tee -a $strapdir/etc/modules; done ## write third-stage for chroot bootstrap_config_thirdstage | sudo tee $strapdir/thirdstage (DIR) diff --git a/zlibs/helpers b/zlibs/helpers t@@ -39,6 +39,19 @@ devprocsys() { fi } +findloopmapp() { + fn findloopmapp + req=(workdir image_name) + ckreq || return 1 + + notice "finding a free loopdevice" + + loopdevice=$(sudo losetup -f --show $workdir/${image_name}.img) + mappdevice=$(sudo kpartx -va $loopdevice | sed -E 's/.*(loop[0-9])p.*/\1/g' | sed 1q) + func "loopdevice: $loopdevice" + func "mappdevice: $mappdevice" +} + silly() { fn silly "$@" local arg1="$1" (DIR) diff --git a/zlibs/imaging b/zlibs/imaging t@@ -0,0 +1,92 @@ +#!/usr/bin/env zsh +# Copyright (c) 2016 Dyne.org Foundation +# libdevuansdk is maintained by Ivan J. <parazyd@dyne.org> +# +# This file is part of libdevuansdk +# +# This source code is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This software is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this source code. If not, see <http://www.gnu.org/licenses/>. + +## imagine images + +vars+=(image_name bootpart rootpart) + +image_prepare_raw() { + fn image_prepare_raw + req=(workdir size image_name) + ckreq || return 1 + + notice "creating raw image file from zeroes..." + + dd if=/dev/zero \ + of=$workdir/${image_name}.img \ + bs=1M \ + count=$size +} + +image_partition_raw_dos() { + fn image_partition_raw_dos + req=(workdir image_name parted_boot parted_root) + ckreq || return 1 + + notice "partitioning raw dos image..." + + parted $workdir/${image_name}.img --script -- mklabel msdos + parted $workdir/${image_name}.img --script -- mkpart primary ${parted_boot} + parted $workdir/${image_name}.img --script -- mkpart primary ${parted_root} + + ## get loopdevice and mapper device (see ./helpers) + findloopmapp + + mappdevice="/dev/mapper/$mappdevice" + bootpart=${mappdevice}p1 + rootpart=${mappdevice}p2 + + notice "formatting partitions..." + sudo mkfs.vfat $bootpart + sudo mkfs.ext4 $rootpart +} + +image_partition_raw_gpt() { + fn image_partition_raw_gpt + req=(workdir image_name) + ckreq || return 1 + + notice "partitioning raw gpt image..." + + parted $workdir/${image_name}.img --script -- mklabel gpt + cgpt create -z ${image_name}.img + cgpt create ${image_name}.img + cgpt add -i 1 -t kernel -b 8192 -s 32768 -l kernel -S 1 -T 5 -P 10 ${image_name}.img + cgpt add -i 2 -t data -b 40960 -s $(expr $(cgpt show ${image_name}.img \ + | awk '/Sec GPT table/ {print \$1}') - 40960) -l Root ${image_name}.img + + findloopmapp + + mappdevice="/dev/mapper/${mappdevice}" + bootpart=${mappdevice}p1 + rootpart=${mappdevice}p2 + + notice "formatting partitions..." + sudo mkfs.ext4 -L rootfs $rootpart +} + +image_raw_mount() { + fn image_raw_mount + req=(workdir bootpart rootpart) + ckreq || return 1 + + mkdir -p $workdir/boot $workdir/root + sudo mount $bootpart $workdir/boot && act "mounted boot partition" || zerr + sudo mount $rootpart $workdir/root && act "mounted root partition" || zerr +}