mirror of
https://git.yoctoproject.org/poky
synced 2026-06-03 13:49:49 +00:00
mkefidisk.sh: Reduce output and add verbose flag
Remove superfluous output from commands, add a -v verbose flag, and cleanup output. (From OE-Core rev: 0742bcd437362eb31b40e35f7331f191a1e070d0) Signed-off-by: Darren Hart <dvhart@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
committed by
Richard Purdie
parent
049100a9a7
commit
172c5601d4
@@ -20,6 +20,10 @@
|
|||||||
|
|
||||||
LANG=C
|
LANG=C
|
||||||
|
|
||||||
|
# Set to 1 to enable additional output
|
||||||
|
DEBUG=0
|
||||||
|
OUT="/dev/null"
|
||||||
|
|
||||||
#
|
#
|
||||||
# Defaults
|
# Defaults
|
||||||
#
|
#
|
||||||
@@ -30,7 +34,7 @@ SWAP_RATIO=5
|
|||||||
|
|
||||||
# Cleanup after die()
|
# Cleanup after die()
|
||||||
cleanup() {
|
cleanup() {
|
||||||
echo "Syncing and unmounting devices..."
|
debug "Syncing and unmounting devices"
|
||||||
# Unmount anything we mounted
|
# Unmount anything we mounted
|
||||||
unmount $ROOTFS_MNT || error "Failed to unmount $ROOTFS_MNT"
|
unmount $ROOTFS_MNT || error "Failed to unmount $ROOTFS_MNT"
|
||||||
unmount $BOOTFS_MNT || error "Failed to unmount $BOOTFS_MNT"
|
unmount $BOOTFS_MNT || error "Failed to unmount $BOOTFS_MNT"
|
||||||
@@ -38,7 +42,7 @@ cleanup() {
|
|||||||
unmount $HDDIMG_MNT || error "Failed to unmount $HDDIMG_MNT"
|
unmount $HDDIMG_MNT || error "Failed to unmount $HDDIMG_MNT"
|
||||||
|
|
||||||
# Remove the TMPDIR
|
# Remove the TMPDIR
|
||||||
echo "Removing temporary files..."
|
debug "Removing temporary files"
|
||||||
if [ -d "$TMPDIR" ]; then
|
if [ -d "$TMPDIR" ]; then
|
||||||
rm -rf $TMPDIR || error "Failed to remove $TMPDIR"
|
rm -rf $TMPDIR || error "Failed to remove $TMPDIR"
|
||||||
fi
|
fi
|
||||||
@@ -71,9 +75,15 @@ die() {
|
|||||||
cleanup
|
cleanup
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
debug() {
|
||||||
|
if [ $DEBUG -eq 1 ]; then
|
||||||
|
echo "$1"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
usage() {
|
usage() {
|
||||||
echo "Usage: $(basename $0) DEVICE HDDIMG TARGET_DEVICE"
|
echo "Usage: $(basename $0) [-v] DEVICE HDDIMG TARGET_DEVICE"
|
||||||
|
echo " -v: Verbose debug"
|
||||||
echo " DEVICE: The device to write the image to, e.g. /dev/sdh"
|
echo " DEVICE: The device to write the image to, e.g. /dev/sdh"
|
||||||
echo " HDDIMG: The hddimg file to generate the efi disk from"
|
echo " HDDIMG: The hddimg file to generate the efi disk from"
|
||||||
echo " TARGET_DEVICE: The device the target will boot from, e.g. /dev/mmcblk0"
|
echo " TARGET_DEVICE: The device the target will boot from, e.g. /dev/mmcblk0"
|
||||||
@@ -82,7 +92,6 @@ usage() {
|
|||||||
image_details() {
|
image_details() {
|
||||||
IMG=$1
|
IMG=$1
|
||||||
info "Image details"
|
info "Image details"
|
||||||
echo "============="
|
|
||||||
echo " image: $(stat --printf '%N\n' $IMG)"
|
echo " image: $(stat --printf '%N\n' $IMG)"
|
||||||
echo " size: $(stat -L --printf '%s bytes\n' $IMG)"
|
echo " size: $(stat -L --printf '%s bytes\n' $IMG)"
|
||||||
echo " modified: $(stat -L --printf '%y\n' $IMG)"
|
echo " modified: $(stat -L --printf '%y\n' $IMG)"
|
||||||
@@ -95,7 +104,6 @@ device_details() {
|
|||||||
BLOCK_SIZE=512
|
BLOCK_SIZE=512
|
||||||
|
|
||||||
info "Device details"
|
info "Device details"
|
||||||
echo "=============="
|
|
||||||
echo " device: $DEVICE"
|
echo " device: $DEVICE"
|
||||||
if [ -f "/sys/class/block/$DEV/device/vendor" ]; then
|
if [ -f "/sys/class/block/$DEV/device/vendor" ]; then
|
||||||
echo " vendor: $(cat /sys/class/block/$DEV/device/vendor)"
|
echo " vendor: $(cat /sys/class/block/$DEV/device/vendor)"
|
||||||
@@ -118,7 +126,7 @@ device_details() {
|
|||||||
unmount_device() {
|
unmount_device() {
|
||||||
grep -q $DEVICE /proc/mounts
|
grep -q $DEVICE /proc/mounts
|
||||||
if [ $? -eq 0 ]; then
|
if [ $? -eq 0 ]; then
|
||||||
warn "$DEVICE listed in /proc/mounts, attempting to unmount..."
|
warn "$DEVICE listed in /proc/mounts, attempting to unmount"
|
||||||
umount $DEVICE* 2>/dev/null
|
umount $DEVICE* 2>/dev/null
|
||||||
return $?
|
return $?
|
||||||
fi
|
fi
|
||||||
@@ -128,7 +136,7 @@ unmount_device() {
|
|||||||
unmount() {
|
unmount() {
|
||||||
grep -q $1 /proc/mounts
|
grep -q $1 /proc/mounts
|
||||||
if [ $? -eq 0 ]; then
|
if [ $? -eq 0 ]; then
|
||||||
echo "Unmounting $1..."
|
debug "Unmounting $1"
|
||||||
umount $1
|
umount $1
|
||||||
return $?
|
return $?
|
||||||
fi
|
fi
|
||||||
@@ -138,11 +146,17 @@ unmount() {
|
|||||||
#
|
#
|
||||||
# Parse and validate arguments
|
# Parse and validate arguments
|
||||||
#
|
#
|
||||||
if [ $# -ne 3 ]; then
|
if [ $# -lt 3 ] || [ $# -gt 4 ]; then
|
||||||
usage
|
usage
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [ "$1" = "-v" ]; then
|
||||||
|
DEBUG=1
|
||||||
|
OUT="1"
|
||||||
|
shift
|
||||||
|
fi
|
||||||
|
|
||||||
DEVICE=$1
|
DEVICE=$1
|
||||||
HDDIMG=$2
|
HDDIMG=$2
|
||||||
TARGET_DEVICE=$3
|
TARGET_DEVICE=$3
|
||||||
@@ -230,34 +244,39 @@ fi
|
|||||||
TARGET_ROOTFS=$TARGET_DEVICE${TARGET_PART_PREFIX}2
|
TARGET_ROOTFS=$TARGET_DEVICE${TARGET_PART_PREFIX}2
|
||||||
TARGET_SWAP=$TARGET_DEVICE${TARGET_PART_PREFIX}3
|
TARGET_SWAP=$TARGET_DEVICE${TARGET_PART_PREFIX}3
|
||||||
|
|
||||||
echo "*****************"
|
echo ""
|
||||||
echo "Boot partition size: $BOOT_SIZE MB ($BOOTFS)"
|
info "Boot partition size: $BOOT_SIZE MB ($BOOTFS)"
|
||||||
echo "ROOTFS partition size: $ROOTFS_SIZE MB ($ROOTFS)"
|
info "ROOTFS partition size: $ROOTFS_SIZE MB ($ROOTFS)"
|
||||||
echo "Swap partition size: $SWAP_SIZE MB ($SWAP)"
|
info "Swap partition size: $SWAP_SIZE MB ($SWAP)"
|
||||||
echo "*****************"
|
echo ""
|
||||||
|
|
||||||
echo "Deleting partition table on $DEVICE ..."
|
|
||||||
dd if=/dev/zero of=$DEVICE bs=512 count=2 > /dev/null || die "Failed to zero beginning of $DEVICE"
|
|
||||||
|
|
||||||
# Use MSDOS by default as GPT cannot be reliably distributed in disk image form
|
# Use MSDOS by default as GPT cannot be reliably distributed in disk image form
|
||||||
# as it requires the backup table to be on the last block of the device, which
|
# as it requires the backup table to be on the last block of the device, which
|
||||||
# of course varies from device to device.
|
# of course varies from device to device.
|
||||||
echo "Creating new partition table (MSDOS) on $DEVICE ..."
|
|
||||||
parted $DEVICE mklabel msdos || die "Failed to create MSDOS partition table"
|
|
||||||
|
|
||||||
echo "Creating boot partition on $BOOTFS"
|
info "Partitioning installation media ($DEVICE)"
|
||||||
parted $DEVICE mkpart primary 0% $BOOT_SIZE || die "Failed to create BOOT partition"
|
|
||||||
|
|
||||||
echo "Enabling boot flag on $BOOTFS"
|
debug "Deleting partition table on $DEVICE"
|
||||||
parted $DEVICE set 1 boot on || die "Failed to enable boot flag"
|
dd if=/dev/zero of=$DEVICE bs=512 count=2 >$OUT 2>1 || die "Failed to zero beginning of $DEVICE"
|
||||||
|
|
||||||
echo "Creating ROOTFS partition on $ROOTFS"
|
debug "Creating new partition table (MSDOS) on $DEVICE"
|
||||||
parted $DEVICE mkpart primary $ROOTFS_START $ROOTFS_END || die "Failed to create ROOTFS partition"
|
parted $DEVICE mklabel msdos >$OUT 2>1 || die "Failed to create MSDOS partition table"
|
||||||
|
|
||||||
echo "Creating swap partition on $SWAP"
|
debug "Creating boot partition on $BOOTFS"
|
||||||
parted $DEVICE mkpart primary $SWAP_START 100% || die "Failed to create SWAP partition"
|
parted $DEVICE mkpart primary 0% $BOOT_SIZE >$OUT 2>1 || die "Failed to create BOOT partition"
|
||||||
|
|
||||||
parted $DEVICE print
|
debug "Enabling boot flag on $BOOTFS"
|
||||||
|
parted $DEVICE set 1 boot on >$OUT 2>1 || die "Failed to enable boot flag"
|
||||||
|
|
||||||
|
debug "Creating ROOTFS partition on $ROOTFS"
|
||||||
|
parted $DEVICE mkpart primary $ROOTFS_START $ROOTFS_END >$OUT 2>1 || die "Failed to create ROOTFS partition"
|
||||||
|
|
||||||
|
debug "Creating swap partition on $SWAP"
|
||||||
|
parted $DEVICE mkpart primary $SWAP_START 100% >$OUT 2>1 || die "Failed to create SWAP partition"
|
||||||
|
|
||||||
|
if [ $DEBUG -eq 1 ]; then
|
||||||
|
parted $DEVICE print
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
@@ -269,38 +288,37 @@ unmount_device || die "Failed to unmount $DEVICE partitions"
|
|||||||
#
|
#
|
||||||
# Format $DEVICE partitions
|
# Format $DEVICE partitions
|
||||||
#
|
#
|
||||||
echo ""
|
info "Formating partitions"
|
||||||
echo "Formatting $BOOTFS as vfat..."
|
debug "Formatting $BOOTFS as vfat"
|
||||||
if [ ! "${DEVICE#/dev/loop}" = "${DEVICE}" ]; then
|
if [ ! "${DEVICE#/dev/loop}" = "${DEVICE}" ]; then
|
||||||
mkfs.vfat -I $BOOTFS -n "EFI" || die "Failed to format $BOOTFS"
|
mkfs.vfat -I $BOOTFS -n "EFI" >$OUT 2>1 || die "Failed to format $BOOTFS"
|
||||||
else
|
else
|
||||||
mkfs.vfat $BOOTFS -n "EFI" || die "Failed to format $BOOTFS"
|
mkfs.vfat $BOOTFS -n "EFI" >$OUT 2>1 || die "Failed to format $BOOTFS"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Formatting $ROOTFS as ext3..."
|
debug "Formatting $ROOTFS as ext3"
|
||||||
mkfs.ext3 -F $ROOTFS -L "ROOT" || die "Failed to format $ROOTFS"
|
mkfs.ext3 -F $ROOTFS -L "ROOT" >$OUT 2>1 || die "Failed to format $ROOTFS"
|
||||||
|
|
||||||
echo "Formatting swap partition...($SWAP)"
|
debug "Formatting swap partition ($SWAP)"
|
||||||
mkswap $SWAP || die "Failed to prepare swap"
|
mkswap $SWAP >$OUT 2>1 || die "Failed to prepare swap"
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Installing to $DEVICE
|
# Installing to $DEVICE
|
||||||
#
|
#
|
||||||
echo ""
|
debug "Mounting images and device in preparation for installation"
|
||||||
echo "Mounting images and device in preparation for installation..."
|
mount -o loop $HDDIMG $HDDIMG_MNT >$OUT 2>1 || error "Failed to mount $HDDIMG"
|
||||||
mount -o loop $HDDIMG $HDDIMG_MNT || error "Failed to mount $HDDIMG"
|
mount -o loop $HDDIMG_MNT/rootfs.img $HDDIMG_ROOTFS_MNT >$OUT 2>1 || error "Failed to mount rootfs.img"
|
||||||
mount -o loop $HDDIMG_MNT/rootfs.img $HDDIMG_ROOTFS_MNT || error "Failed to mount rootfs.img"
|
mount $ROOTFS $ROOTFS_MNT >$OUT 2>1 || error "Failed to mount $ROOTFS on $ROOTFS_MNT"
|
||||||
mount $ROOTFS $ROOTFS_MNT || error "Failed to mount $ROOTFS on $ROOTFS_MNT"
|
mount $BOOTFS $BOOTFS_MNT >$OUT 2>1 || error "Failed to mount $BOOTFS on $BOOTFS_MNT"
|
||||||
mount $BOOTFS $BOOTFS_MNT || error "Failed to mount $BOOTFS on $BOOTFS_MNT"
|
|
||||||
|
|
||||||
echo "Preparing boot partition..."
|
info "Preparing boot partition"
|
||||||
EFIDIR="$BOOTFS_MNT/EFI/BOOT"
|
EFIDIR="$BOOTFS_MNT/EFI/BOOT"
|
||||||
cp $HDDIMG_MNT/vmlinuz $BOOTFS_MNT || error "Failed to copy vmlinuz"
|
cp $HDDIMG_MNT/vmlinuz $BOOTFS_MNT >$OUT 2>1 || error "Failed to copy vmlinuz"
|
||||||
# Copy the efi loader and configs (booti*.efi and grub.cfg if it exists)
|
# Copy the efi loader and configs (booti*.efi and grub.cfg if it exists)
|
||||||
cp -r $HDDIMG_MNT/EFI $BOOTFS_MNT || error "Failed to copy EFI dir"
|
cp -r $HDDIMG_MNT/EFI $BOOTFS_MNT >$OUT 2>1 || error "Failed to copy EFI dir"
|
||||||
# Silently ignore a missing gummiboot loader dir (we might just be a GRUB image)
|
# Silently ignore a missing gummiboot loader dir (we might just be a GRUB image)
|
||||||
cp -r $HDDIMG_MNT/loader $BOOTFS_MNT 2> /dev/null
|
cp -r $HDDIMG_MNT/loader $BOOTFS_MNT >$OUT 2>1
|
||||||
|
|
||||||
# Update the boot loaders configurations for an installed image
|
# Update the boot loaders configurations for an installed image
|
||||||
# Remove any existing root= kernel parameters and:
|
# Remove any existing root= kernel parameters and:
|
||||||
@@ -331,7 +349,7 @@ GUMMI_CFG="$GUMMI_ENTRIES/boot.conf"
|
|||||||
if [ -d "$GUMMI_ENTRIES" ]; then
|
if [ -d "$GUMMI_ENTRIES" ]; then
|
||||||
info "Configuring Gummiboot"
|
info "Configuring Gummiboot"
|
||||||
# remove the install target if it exists
|
# remove the install target if it exists
|
||||||
rm $GUMMI_ENTRIES/install.conf &> /dev/null
|
rm $GUMMI_ENTRIES/install.conf >$OUT 2>1
|
||||||
|
|
||||||
if [ ! -e "$GUMMI_CFG" ]; then
|
if [ ! -e "$GUMMI_CFG" ]; then
|
||||||
echo "ERROR: $GUMMI_CFG not found"
|
echo "ERROR: $GUMMI_CFG not found"
|
||||||
@@ -348,7 +366,7 @@ fi
|
|||||||
|
|
||||||
|
|
||||||
info "Copying ROOTFS files (this may take a while)"
|
info "Copying ROOTFS files (this may take a while)"
|
||||||
cp -a $HDDIMG_ROOTFS_MNT/* $ROOTFS_MNT || die "Root FS copy failed"
|
cp -a $HDDIMG_ROOTFS_MNT/* $ROOTFS_MNT >$OUT 2>1 || die "Root FS copy failed"
|
||||||
|
|
||||||
echo "$TARGET_SWAP swap swap defaults 0 0" >> $ROOTFS_MNT/etc/fstab
|
echo "$TARGET_SWAP swap swap defaults 0 0" >> $ROOTFS_MNT/etc/fstab
|
||||||
|
|
||||||
@@ -361,6 +379,7 @@ fi
|
|||||||
# Call cleanup to unmount devices and images and remove the TMPDIR
|
# Call cleanup to unmount devices and images and remove the TMPDIR
|
||||||
cleanup
|
cleanup
|
||||||
|
|
||||||
|
echo ""
|
||||||
if [ $WARNINGS -ne 0 ] && [ $ERRORS -eq 0 ]; then
|
if [ $WARNINGS -ne 0 ] && [ $ERRORS -eq 0 ]; then
|
||||||
echo "${YELLOW}Installation completed with warnings${CLEAR}"
|
echo "${YELLOW}Installation completed with warnings${CLEAR}"
|
||||||
echo "${YELLOW}Warnings: $WARNINGS${CLEAR}"
|
echo "${YELLOW}Warnings: $WARNINGS${CLEAR}"
|
||||||
@@ -371,3 +390,4 @@ elif [ $ERRORS -ne 0 ]; then
|
|||||||
else
|
else
|
||||||
success "Installation completed successfully"
|
success "Installation completed successfully"
|
||||||
fi
|
fi
|
||||||
|
echo ""
|
||||||
|
|||||||
Reference in New Issue
Block a user