summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xscripts/contrib/mkefidisk.sh114
1 files changed, 67 insertions, 47 deletions
diff --git a/scripts/contrib/mkefidisk.sh b/scripts/contrib/mkefidisk.sh
index 85e58ef865..7ec373ef56 100755
--- a/scripts/contrib/mkefidisk.sh
+++ b/scripts/contrib/mkefidisk.sh
@@ -20,6 +20,10 @@
20 20
21LANG=C 21LANG=C
22 22
23# Set to 1 to enable additional output
24DEBUG=0
25OUT="/dev/null"
26
23# 27#
24# Defaults 28# Defaults
25# 29#
@@ -30,7 +34,7 @@ SWAP_RATIO=5
30 34
31# Cleanup after die() 35# Cleanup after die()
32cleanup() { 36cleanup() {
33 echo "Syncing and unmounting devices..." 37 debug "Syncing and unmounting devices"
34 # Unmount anything we mounted 38 # Unmount anything we mounted
35 unmount $ROOTFS_MNT || error "Failed to unmount $ROOTFS_MNT" 39 unmount $ROOTFS_MNT || error "Failed to unmount $ROOTFS_MNT"
36 unmount $BOOTFS_MNT || error "Failed to unmount $BOOTFS_MNT" 40 unmount $BOOTFS_MNT || error "Failed to unmount $BOOTFS_MNT"
@@ -38,7 +42,7 @@ cleanup() {
38 unmount $HDDIMG_MNT || error "Failed to unmount $HDDIMG_MNT" 42 unmount $HDDIMG_MNT || error "Failed to unmount $HDDIMG_MNT"
39 43
40 # Remove the TMPDIR 44 # Remove the TMPDIR
41 echo "Removing temporary files..." 45 debug "Removing temporary files"
42 if [ -d "$TMPDIR" ]; then 46 if [ -d "$TMPDIR" ]; then
43 rm -rf $TMPDIR || error "Failed to remove $TMPDIR" 47 rm -rf $TMPDIR || error "Failed to remove $TMPDIR"
44 fi 48 fi
@@ -71,9 +75,15 @@ die() {
71 cleanup 75 cleanup
72 exit 1 76 exit 1
73} 77}
78debug() {
79 if [ $DEBUG -eq 1 ]; then
80 echo "$1"
81 fi
82}
74 83
75usage() { 84usage() {
76 echo "Usage: $(basename $0) DEVICE HDDIMG TARGET_DEVICE" 85 echo "Usage: $(basename $0) [-v] DEVICE HDDIMG TARGET_DEVICE"
86 echo " -v: Verbose debug"
77 echo " DEVICE: The device to write the image to, e.g. /dev/sdh" 87 echo " DEVICE: The device to write the image to, e.g. /dev/sdh"
78 echo " HDDIMG: The hddimg file to generate the efi disk from" 88 echo " HDDIMG: The hddimg file to generate the efi disk from"
79 echo " TARGET_DEVICE: The device the target will boot from, e.g. /dev/mmcblk0" 89 echo " TARGET_DEVICE: The device the target will boot from, e.g. /dev/mmcblk0"
@@ -82,7 +92,6 @@ usage() {
82image_details() { 92image_details() {
83 IMG=$1 93 IMG=$1
84 info "Image details" 94 info "Image details"
85 echo "============="
86 echo " image: $(stat --printf '%N\n' $IMG)" 95 echo " image: $(stat --printf '%N\n' $IMG)"
87 echo " size: $(stat -L --printf '%s bytes\n' $IMG)" 96 echo " size: $(stat -L --printf '%s bytes\n' $IMG)"
88 echo " modified: $(stat -L --printf '%y\n' $IMG)" 97 echo " modified: $(stat -L --printf '%y\n' $IMG)"
@@ -95,7 +104,6 @@ device_details() {
95 BLOCK_SIZE=512 104 BLOCK_SIZE=512
96 105
97 info "Device details" 106 info "Device details"
98 echo "=============="
99 echo " device: $DEVICE" 107 echo " device: $DEVICE"
100 if [ -f "/sys/class/block/$DEV/device/vendor" ]; then 108 if [ -f "/sys/class/block/$DEV/device/vendor" ]; then
101 echo " vendor: $(cat /sys/class/block/$DEV/device/vendor)" 109 echo " vendor: $(cat /sys/class/block/$DEV/device/vendor)"
@@ -118,7 +126,7 @@ device_details() {
118unmount_device() { 126unmount_device() {
119 grep -q $DEVICE /proc/mounts 127 grep -q $DEVICE /proc/mounts
120 if [ $? -eq 0 ]; then 128 if [ $? -eq 0 ]; then
121 warn "$DEVICE listed in /proc/mounts, attempting to unmount..." 129 warn "$DEVICE listed in /proc/mounts, attempting to unmount"
122 umount $DEVICE* 2>/dev/null 130 umount $DEVICE* 2>/dev/null
123 return $? 131 return $?
124 fi 132 fi
@@ -128,7 +136,7 @@ unmount_device() {
128unmount() { 136unmount() {
129 grep -q $1 /proc/mounts 137 grep -q $1 /proc/mounts
130 if [ $? -eq 0 ]; then 138 if [ $? -eq 0 ]; then
131 echo "Unmounting $1..." 139 debug "Unmounting $1"
132 umount $1 140 umount $1
133 return $? 141 return $?
134 fi 142 fi
@@ -138,11 +146,17 @@ unmount() {
138# 146#
139# Parse and validate arguments 147# Parse and validate arguments
140# 148#
141if [ $# -ne 3 ]; then 149if [ $# -lt 3 ] || [ $# -gt 4 ]; then
142 usage 150 usage
143 exit 1 151 exit 1
144fi 152fi
145 153
154if [ "$1" = "-v" ]; then
155 DEBUG=1
156 OUT="1"
157 shift
158fi
159
146DEVICE=$1 160DEVICE=$1
147HDDIMG=$2 161HDDIMG=$2
148TARGET_DEVICE=$3 162TARGET_DEVICE=$3
@@ -230,34 +244,39 @@ fi
230TARGET_ROOTFS=$TARGET_DEVICE${TARGET_PART_PREFIX}2 244TARGET_ROOTFS=$TARGET_DEVICE${TARGET_PART_PREFIX}2
231TARGET_SWAP=$TARGET_DEVICE${TARGET_PART_PREFIX}3 245TARGET_SWAP=$TARGET_DEVICE${TARGET_PART_PREFIX}3
232 246
233echo "*****************" 247echo ""
234echo "Boot partition size: $BOOT_SIZE MB ($BOOTFS)" 248info "Boot partition size: $BOOT_SIZE MB ($BOOTFS)"
235echo "ROOTFS partition size: $ROOTFS_SIZE MB ($ROOTFS)" 249info "ROOTFS partition size: $ROOTFS_SIZE MB ($ROOTFS)"
236echo "Swap partition size: $SWAP_SIZE MB ($SWAP)" 250info "Swap partition size: $SWAP_SIZE MB ($SWAP)"
237echo "*****************" 251echo ""
238
239echo "Deleting partition table on $DEVICE ..."
240dd if=/dev/zero of=$DEVICE bs=512 count=2 > /dev/null || die "Failed to zero beginning of $DEVICE"
241 252
242# Use MSDOS by default as GPT cannot be reliably distributed in disk image form 253# Use MSDOS by default as GPT cannot be reliably distributed in disk image form
243# as it requires the backup table to be on the last block of the device, which 254# as it requires the backup table to be on the last block of the device, which
244# of course varies from device to device. 255# of course varies from device to device.
245echo "Creating new partition table (MSDOS) on $DEVICE ..."
246parted $DEVICE mklabel msdos || die "Failed to create MSDOS partition table"
247 256
248echo "Creating boot partition on $BOOTFS" 257info "Partitioning installation media ($DEVICE)"
249parted $DEVICE mkpart primary 0% $BOOT_SIZE || die "Failed to create BOOT partition"
250 258
251echo "Enabling boot flag on $BOOTFS" 259debug "Deleting partition table on $DEVICE"
252parted $DEVICE set 1 boot on || die "Failed to enable boot flag" 260dd if=/dev/zero of=$DEVICE bs=512 count=2 >$OUT 2>1 || die "Failed to zero beginning of $DEVICE"
253 261
254echo "Creating ROOTFS partition on $ROOTFS" 262debug "Creating new partition table (MSDOS) on $DEVICE"
255parted $DEVICE mkpart primary $ROOTFS_START $ROOTFS_END || die "Failed to create ROOTFS partition" 263parted $DEVICE mklabel msdos >$OUT 2>1 || die "Failed to create MSDOS partition table"
256 264
257echo "Creating swap partition on $SWAP" 265debug "Creating boot partition on $BOOTFS"
258parted $DEVICE mkpart primary $SWAP_START 100% || die "Failed to create SWAP partition" 266parted $DEVICE mkpart primary 0% $BOOT_SIZE >$OUT 2>1 || die "Failed to create BOOT partition"
259 267
260parted $DEVICE print 268debug "Enabling boot flag on $BOOTFS"
269parted $DEVICE set 1 boot on >$OUT 2>1 || die "Failed to enable boot flag"
270
271debug "Creating ROOTFS partition on $ROOTFS"
272parted $DEVICE mkpart primary $ROOTFS_START $ROOTFS_END >$OUT 2>1 || die "Failed to create ROOTFS partition"
273
274debug "Creating swap partition on $SWAP"
275parted $DEVICE mkpart primary $SWAP_START 100% >$OUT 2>1 || die "Failed to create SWAP partition"
276
277if [ $DEBUG -eq 1 ]; then
278 parted $DEVICE print
279fi
261 280
262 281
263# 282#
@@ -269,38 +288,37 @@ unmount_device || die "Failed to unmount $DEVICE partitions"
269# 288#
270# Format $DEVICE partitions 289# Format $DEVICE partitions
271# 290#
272echo "" 291info "Formating partitions"
273echo "Formatting $BOOTFS as vfat..." 292debug "Formatting $BOOTFS as vfat"
274if [ ! "${DEVICE#/dev/loop}" = "${DEVICE}" ]; then 293if [ ! "${DEVICE#/dev/loop}" = "${DEVICE}" ]; then
275 mkfs.vfat -I $BOOTFS -n "EFI" || die "Failed to format $BOOTFS" 294 mkfs.vfat -I $BOOTFS -n "EFI" >$OUT 2>1 || die "Failed to format $BOOTFS"
276else 295else
277 mkfs.vfat $BOOTFS -n "EFI" || die "Failed to format $BOOTFS" 296 mkfs.vfat $BOOTFS -n "EFI" >$OUT 2>1 || die "Failed to format $BOOTFS"
278fi 297fi
279 298
280echo "Formatting $ROOTFS as ext3..." 299debug "Formatting $ROOTFS as ext3"
281mkfs.ext3 -F $ROOTFS -L "ROOT" || die "Failed to format $ROOTFS" 300mkfs.ext3 -F $ROOTFS -L "ROOT" >$OUT 2>1 || die "Failed to format $ROOTFS"
282 301
283echo "Formatting swap partition...($SWAP)" 302debug "Formatting swap partition ($SWAP)"
284mkswap $SWAP || die "Failed to prepare swap" 303mkswap $SWAP >$OUT 2>1 || die "Failed to prepare swap"
285 304
286 305
287# 306#
288# Installing to $DEVICE 307# Installing to $DEVICE
289# 308#
290echo "" 309debug "Mounting images and device in preparation for installation"
291echo "Mounting images and device in preparation for installation..." 310mount -o loop $HDDIMG $HDDIMG_MNT >$OUT 2>1 || error "Failed to mount $HDDIMG"
292mount -o loop $HDDIMG $HDDIMG_MNT || error "Failed to mount $HDDIMG" 311mount -o loop $HDDIMG_MNT/rootfs.img $HDDIMG_ROOTFS_MNT >$OUT 2>1 || error "Failed to mount rootfs.img"
293mount -o loop $HDDIMG_MNT/rootfs.img $HDDIMG_ROOTFS_MNT || error "Failed to mount rootfs.img" 312mount $ROOTFS $ROOTFS_MNT >$OUT 2>1 || error "Failed to mount $ROOTFS on $ROOTFS_MNT"
294mount $ROOTFS $ROOTFS_MNT || error "Failed to mount $ROOTFS on $ROOTFS_MNT" 313mount $BOOTFS $BOOTFS_MNT >$OUT 2>1 || error "Failed to mount $BOOTFS on $BOOTFS_MNT"
295mount $BOOTFS $BOOTFS_MNT || error "Failed to mount $BOOTFS on $BOOTFS_MNT"
296 314
297echo "Preparing boot partition..." 315info "Preparing boot partition"
298EFIDIR="$BOOTFS_MNT/EFI/BOOT" 316EFIDIR="$BOOTFS_MNT/EFI/BOOT"
299cp $HDDIMG_MNT/vmlinuz $BOOTFS_MNT || error "Failed to copy vmlinuz" 317cp $HDDIMG_MNT/vmlinuz $BOOTFS_MNT >$OUT 2>1 || error "Failed to copy vmlinuz"
300# Copy the efi loader and configs (booti*.efi and grub.cfg if it exists) 318# Copy the efi loader and configs (booti*.efi and grub.cfg if it exists)
301cp -r $HDDIMG_MNT/EFI $BOOTFS_MNT || error "Failed to copy EFI dir" 319cp -r $HDDIMG_MNT/EFI $BOOTFS_MNT >$OUT 2>1 || error "Failed to copy EFI dir"
302# Silently ignore a missing gummiboot loader dir (we might just be a GRUB image) 320# Silently ignore a missing gummiboot loader dir (we might just be a GRUB image)
303cp -r $HDDIMG_MNT/loader $BOOTFS_MNT 2> /dev/null 321cp -r $HDDIMG_MNT/loader $BOOTFS_MNT >$OUT 2>1
304 322
305# Update the boot loaders configurations for an installed image 323# Update the boot loaders configurations for an installed image
306# Remove any existing root= kernel parameters and: 324# Remove any existing root= kernel parameters and:
@@ -331,7 +349,7 @@ GUMMI_CFG="$GUMMI_ENTRIES/boot.conf"
331if [ -d "$GUMMI_ENTRIES" ]; then 349if [ -d "$GUMMI_ENTRIES" ]; then
332 info "Configuring Gummiboot" 350 info "Configuring Gummiboot"
333 # remove the install target if it exists 351 # remove the install target if it exists
334 rm $GUMMI_ENTRIES/install.conf &> /dev/null 352 rm $GUMMI_ENTRIES/install.conf >$OUT 2>1
335 353
336 if [ ! -e "$GUMMI_CFG" ]; then 354 if [ ! -e "$GUMMI_CFG" ]; then
337 echo "ERROR: $GUMMI_CFG not found" 355 echo "ERROR: $GUMMI_CFG not found"
@@ -348,7 +366,7 @@ fi
348 366
349 367
350info "Copying ROOTFS files (this may take a while)" 368info "Copying ROOTFS files (this may take a while)"
351cp -a $HDDIMG_ROOTFS_MNT/* $ROOTFS_MNT || die "Root FS copy failed" 369cp -a $HDDIMG_ROOTFS_MNT/* $ROOTFS_MNT >$OUT 2>1 || die "Root FS copy failed"
352 370
353echo "$TARGET_SWAP swap swap defaults 0 0" >> $ROOTFS_MNT/etc/fstab 371echo "$TARGET_SWAP swap swap defaults 0 0" >> $ROOTFS_MNT/etc/fstab
354 372
@@ -361,6 +379,7 @@ fi
361# Call cleanup to unmount devices and images and remove the TMPDIR 379# Call cleanup to unmount devices and images and remove the TMPDIR
362cleanup 380cleanup
363 381
382echo ""
364if [ $WARNINGS -ne 0 ] && [ $ERRORS -eq 0 ]; then 383if [ $WARNINGS -ne 0 ] && [ $ERRORS -eq 0 ]; then
365 echo "${YELLOW}Installation completed with warnings${CLEAR}" 384 echo "${YELLOW}Installation completed with warnings${CLEAR}"
366 echo "${YELLOW}Warnings: $WARNINGS${CLEAR}" 385 echo "${YELLOW}Warnings: $WARNINGS${CLEAR}"
@@ -371,3 +390,4 @@ elif [ $ERRORS -ne 0 ]; then
371else 390else
372 success "Installation completed successfully" 391 success "Installation completed successfully"
373fi 392fi
393echo ""