#!/bin/bash # Copyright (C) 2017-2018 Daniel Tartavel-jeannot # Copyright (C) 2019-2020 Jean-Baptiste Biernacki # # This program 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 2 of the License, or # (at your option) any later version. # # This program 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 program. If not, see . p1_Start_sector="${DEFAULT}" p1_Size="128M" p1_Type="uefi" #p1_Bootable="*" p1_Bootable="${DEFAULT}" p2_Start_sector="${DEFAULT}" p2_Size="${DEFAULT}" p2_Type="linux" p2_Bootable="${DEFAULT}" SFDISK_SCRIPT="label: gpt ${p1_Start_sector}, ${p1_Size}, ${p1_Type}, ${p1_Bootable} ${p2_Start_sector}, ${p2_Size}, ${p2_Type}, ${p2_Bootable} write " function createImageWrap() { title "Wrap image creation" preImgCreation if [ ${?} -ne 0 ]; then error "line ${LINENO} error in the process ${CONFIG_PATH}/specialFunctions.sh ." cleanExit ${ERR_1} fi createimage partitionningimage loopingImage BOOTFS=${BOOTFS:="ext4"} formatpartitions ${BOOTFS} ext4 unloopingImage loopingImage return 0 } function loopingImage() { title "Looping image ..." # Mettre en place et contrôler des périphériques boucle. # -f, --find trouver le premier périphérique inutilisé # --show afficher le nom du périphérique après configuration (avec -f) # DEVICE=$(/usr/sbin/losetup -f --show "${INSTALL_PATH}/${IMAGE}") DEVICE=$(/usr/bin/udisksctl loop-setup -f ${INSTALL_PATH}/${IMAGE} | sed -e 's|^.*\/dev\/|\/dev\/|' -e 's|\.$||') if [ -z "${DEVICE}" ]; then error "Error, device missing from udisksctl loop-setup output." cleanExit ${ERR_1} fi print_info "Image looped on ${DEVICE}" #Previous function give us a list of partition. It is easy to get it and define prior this list the partition. #But... How to distinguish between the boot p1 and the root p2 if both are empty and ext4 ? ... if [ 1 -eq ${SEPARATE_BOOT_PARTITION} ]; then BOOTP="${DEVICE}p1" ROOTP="${DEVICE}p2" # BOOT_UUID=$(/usr/sbin/blkid -s UUID -o value UUID "${BOOTP}") BOOT_UUID=$(/usr/bin/lsblk -n -o UUID "${BOOTP}") print_info "Boot UUID: ${BOOT_UUID}" else ROOTP="${DEVICE}p1" fi # ROOT_UUID=$(/usr/sbin/blkid -s UUID -o value UUID "${ROOTP}") ROOT_UUID=$(/usr/bin/lsblk -n -o UUID "${ROOTP}") print_info "Root UUID: ${ROOT_UUID}" return 0 } function formatpartitions() { print_info "Formatting partitions" if [ 1 -eq ${SEPARATE_BOOT_PARTITION} ]; then print_info "Boot : ${BOOTP} as ${1}" if [ "vfat" = ${1} ]; then FSINFO=$(/usr/sbin/mkfs.vfat ${BOOTP} ) BOOT_UUID=$(echo "${FSINFO}" | grep 'Volume ID is' | sed 's/Volume ID is \([[:alnum:]]*\),.*$/\1/') print_info "Boot UUID = ${BOOT_UUID}" rm -f ${temporary} else FSINFO=$(yes | /usr/sbin/mkfs.ext4 -E offset=${BOOT_OFFSET_B} ${INSTALL_PATH}/${IMAGE} $((${BOOT_SIZE_KB}))k) BOOT_UUID=$(echo "${FSINFO}" | grep 'Filesystem UUID' | sed 's/Filesystem UUID: //') fi # "/sbin/mkfs.${1}" "${BOOTP}" if [ ${?} -ne 0 ]; then error "line ${LINENO} error formating ${BOOTP} : exiting" # /usr/sbin/losetup -d "${DEVICE}" udisksctl unmount -b ${BOOTP} cleanExit ${ERR_1} fi # BOOT_UUID=$(/usr/sbin/blkid -s UUID -o value UUID "${BOOTP}") # print_info "Boot UUID: ${BOOT_UUID}" fi print_info "Root : ${ROOTP} as ${2}" FSINFO=$(yes | /sbin/mkfs.${2} "${ROOTP}" ) if [ ${?} -ne 0 ]; then error "line ${LINENO} error formating ${ROOTP} : exiting" cleanExit ${ERR_1} fi ROOT_UUID=$(echo "${FSINFO}" | grep 'Filesystem UUID' | sed 's/Filesystem UUID: //') # ROOT_UUID=$(/usr/sbin/blkid -s UUID -o value UUID "${ROOTP}") print_info "Root UUID: ${ROOT_UUID}" /usr/bin/sync return 0 } function imageConversion() { title "Converting image into a qcow2 file" qemu-img convert -O qcow2 ${INSTALL_PATH}/${IMAGE} ${INSTALL_PATH}/${IMAGE}.qcow2 return 0 } function preImgCreation() { # title "Creating Banana Pro image" #Nothing to download. return 0 } function postPrepareChroot() { #Nothing to do. return 0 } function burningBootloader() { # DEVICE is set just before this function and looped. return 0 } function copyingCustomSystem() { # installpkg ${CONFIG_PATH}/package.mga7.aarch64.rpm # installpkg package return 0 }