Skip to contentSkip to conversation

UUID support in installer (poky-contrib: ed/oe-core/uuid-init-install)

PATCH Superseded Ed Bartosh 1 participant 11 messages Jun 15, 2015

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Ed Bartosh

author
#0 lore raw

cover UUID support in installer (poky-contrib: ed/oe-core/uuid-init-install)

Hi,

This patchet adds support of GPT partition table and UUID support to initramfs installer scripts.

Using UUID in favor of device names is more reliable as UUID names are persistent.

Device names can change as the order of adding device nodes is arbitrary. This sometimes results in device names switching on each boot, which can cause system fail to boot. Persistent naming solves these issues.

Implementation details:
Used partition UUID in kernel command line to specify root partition. Used partition UUID in /etc/fstab to specify swap partition. Used filesystem UUID in /etc/fstab to specify boot partition.

Code cleanup and usability fixes were done along the way. They're also included into this patchset.

Patchest was tested on NUC device in both EFI and non-EFI modes.

See more details in [YOCTO #6101]

NOTE: Please drop the following pending patches as they're included into the patchset:
[OE-core] [PATCH] image-live: Set syslinux timeout to 5s
[OE-core] [PATCH] initramfs-live-install: Add gptdisk to initramfs [OE-core] [PATCH] init-install-efi: Implement UUID support

Please review

Ed Bartosh (10):
image-live: Set syslinux timeout to 5s
initramfs-live-install: Add blkid to initramfs
busybox: Enable UUID-related options
init-install-efi: Implement UUID support
init-install: Use GPT table with GRUB 2
init-install: Implement UUID support
init-install: Specify filesystem type in parted command line
init-install: Specify partition name in parted command line
init-install: code cleanup: Replace tabs with spaces
init-install: code cleanup: replace /dev/$device -> $device

 meta/classes/image-live.bbclass                    |   2 +-
 meta/recipes-core/busybox/busybox/defconfig        |   8 +-
 .../initrdscripts/files/init-install-efi.sh        |  90 ++++++-------
 .../initrdscripts/files/init-install.sh            | 146 +++++++++++++--------
 .../initramfs-live-install-efi_1.0.bb              |   2 +-
 .../initrdscripts/initramfs-live-install_1.0.bb    |   2 +-
 6 files changed, 143 insertions(+), 107 deletions(-)

--
Ed

author
#1 lore raw

PATCH 1/10 image-live: Set syslinux timeout to 5s

Increased syslinux timeout to 5s as default 1s timeout is not enough to notice syslinux prompt on some devices.

meta/classes/image-live.bbclass +1 -1
index 7b770fb..52b6de7 100644
@@ -3,7 +3,7 @@ AUTO_SYSLINUXCFG = "1"
 INITRD_IMAGE ?= "core-image-minimal-initramfs"
 INITRD ?= "${DEPLOY_DIR_IMAGE}/${INITRD_IMAGE}-${MACHINE}.cpio.gz"
 SYSLINUX_ROOT = "root=/dev/ram0"
-SYSLINUX_TIMEOUT ?= "10"
+SYSLINUX_TIMEOUT ?= "50"
 SYSLINUX_LABELS ?= "boot install"
 LABELS_append = " ${SYSLINUX_LABELS} "
 
Signature · 1 line
2.1.4
author
#2 lore raw

PATCH 2/10 initramfs-live-install: Add blkid to initramfs

In reply to Ed Bartosh

Added util-linux-blkid to the list of dependencies of initramfs-live-install and initramfs-live-install-efi.

This is a part of the work to support partiion UUID in installer. blkid is going to be used to get partition and filesystem UUIDs.

meta/recipes-core/initrdscripts/initramfs-live-install-efi_1.0.bb +1 -1
index b0994d7..32c1fce 100644
@@ -5,7 +5,7 @@ SRC_URI = "file://init-install-efi.sh"
 
 PR = "r1"
 
-RDEPENDS_${PN} = "parted e2fsprogs-mke2fs dosfstools"
+RDEPENDS_${PN} = "parted e2fsprogs-mke2fs dosfstools util-linux-blkid"
 
 S = "${WORKDIR}"
 
meta/recipes-core/initrdscripts/initramfs-live-install_1.0.bb +1 -1
index 6241a90..88b3b30 100644
@@ -7,7 +7,7 @@ PR = "r9"
 
 S = "${WORKDIR}"
 
-RDEPENDS_${PN} = "grub parted e2fsprogs-mke2fs"
+RDEPENDS_${PN} = "grub parted e2fsprogs-mke2fs util-linux-blkid"
 
 do_install() {
         install -m 0755 ${WORKDIR}/init-install.sh ${D}/install.sh
Signature · 1 line
2.1.4
author
#3 lore raw

PATCH 3/10 busybox: Enable UUID-related options

In reply to Ed Bartosh

Enabled MOUNT_LABEL and VOLUMEID* features for busybox mount to understand 'UUID=' syntax in fstab.

meta/recipes-core/busybox/busybox/defconfig +4 -4
index c200ee0..468c40e 100644
@@ -582,7 +582,7 @@ CONFIG_MOUNT=y
 # CONFIG_FEATURE_MOUNT_FAKE is not set
 # CONFIG_FEATURE_MOUNT_VERBOSE is not set
 # CONFIG_FEATURE_MOUNT_HELPERS is not set
-# CONFIG_FEATURE_MOUNT_LABEL is not set
+CONFIG_FEATURE_MOUNT_LABEL=y
 CONFIG_FEATURE_MOUNT_NFS=y
 # CONFIG_FEATURE_MOUNT_CIFS is not set
 CONFIG_FEATURE_MOUNT_FLAGS=y
@@ -607,11 +607,11 @@ CONFIG_FEATURE_UMOUNT_ALL=y
 CONFIG_FEATURE_MOUNT_LOOP=y
 CONFIG_FEATURE_MOUNT_LOOP_CREATE=y
 # CONFIG_FEATURE_MTAB_SUPPORT is not set
-# CONFIG_VOLUMEID is not set
-# CONFIG_FEATURE_VOLUMEID_EXT is not set
+CONFIG_VOLUMEID=y
+CONFIG_FEATURE_VOLUMEID_EXT=y
 # CONFIG_FEATURE_VOLUMEID_BTRFS is not set
 # CONFIG_FEATURE_VOLUMEID_REISERFS is not set
-# CONFIG_FEATURE_VOLUMEID_FAT is not set
+CONFIG_FEATURE_VOLUMEID_FAT=y
 # CONFIG_FEATURE_VOLUMEID_HFS is not set
 # CONFIG_FEATURE_VOLUMEID_JFS is not set
 # CONFIG_FEATURE_VOLUMEID_XFS is not set
Signature · 1 line
2.1.4
author
#4 lore raw

PATCH 4/10 init-install-efi: Implement UUID support

In reply to Ed Bartosh

Using UUID in favor of device names is more reliable as UUID names are persistent.

Device names can change as the order of adding device nodes is arbitrary. This sometimes results in device names switching on each boot, which can cause system fail to boot. Persistent naming solves these issues.

Used partition UUID in kernel command line to specify root partition. Used partition UUID in /etc/fstab to specify swap partition. Used filesystem UUID in /etc/fstab to specify boot partition.

[YOCTO #6101]

meta/recipes-core/initrdscripts/files/init-install-efi.sh +7 -4
index 8dd2749..5fb4d4d 100644
@@ -164,8 +164,10 @@ mount -o rw,loop,noatime,nodiratime /run/media/$1/$2 /src_root
 echo "Copying rootfs files..."
 cp -a /src_root/* /tgt_root
 if [ -d /tgt_root/etc/ ] ; then
-    echo "$swap                swap             swap       defaults              0  0" >> /tgt_root/etc/fstab
-    echo "$bootfs              /boot            vfat       defaults              1  2" >> /tgt_root/etc/fstab
+    boot_uuid=$(blkid -o value -s UUID /dev/${device}1)
+    swap_part_uuid=$(blkid -o value -s PARTUUID /dev/${device}3)
+    echo "/dev/disk/by-partuuid/$swap_part_uuid                swap             swap       defaults              0  0" >> /tgt_root/etc/fstab
+    echo "UUID=$boot_uuid              /boot            vfat       defaults              1  2" >> /tgt_root/etc/fstab
     # We dont want udev to mount our root device while we're booting...
     if [ -d /tgt_root/etc/udev/ ] ; then
 	echo "/dev/${device}" >> /tgt_root/etc/udev/mount.blacklist
@@ -184,6 +186,7 @@ mkdir -p $EFIDIR
 cp /run/media/$1/EFI/BOOT/*.efi $EFIDIR
 
 if [ -f /run/media/$1/EFI/BOOT/grub.cfg ]; then
+    root_part_uuid=$(blkid -o value -s PARTUUID /dev/${device}2)
     GRUBCFG="$EFIDIR/grub.cfg"
     cp /run/media/$1/EFI/BOOT/grub.cfg $GRUBCFG
     # Update grub config for the installed image
@@ -196,7 +199,7 @@ if [ -f /run/media/$1/EFI/BOOT/grub.cfg ]; then
     # Delete any root= strings
     sed -i "s/ root=[^ ]*/ /" $GRUBCFG
     # Add the root= and other standard boot options
-    sed -i "s@linux /vmlinuz *@linux /vmlinuz root=$rootfs rw $rootwait quiet @" $GRUBCFG
+    sed -i "s@linux /vmlinuz *@linux /vmlinuz root=PARTUUID=$root_part_uuid rw $rootwait quiet @" $GRUBCFG
 fi
 
 if [ -d /run/media/$1/loader ]; then
@@ -212,7 +215,7 @@ if [ -d /run/media/$1/loader ]; then
     # delete any root= strings
     sed -i "s/ root=[^ ]*/ /" $GUMMIBOOT_CFGS
     # add the root= and other standard boot options
-    sed -i "s@options *@options root=$rootfs rw $rootwait quiet @" $GUMMIBOOT_CFGS
+    sed -i "s@options *@options root=PARTUUID=$rootuuid rw $rootwait quiet @" $GUMMIBOOT_CFGS
 fi
 
 umount /tgt_root
Signature · 1 line
2.1.4
author
#5 lore raw

PATCH 5/10 init-install: Use GPT table with GRUB 2

In reply to Ed Bartosh

Changed partition type from 'msdos' to 'gpt'. Added special partition for grub stage2 bootloader.

NOTE: This is done only for GRUB 2 as legacy GRUB is rarely used and doesn't support GPT partitions.

meta/recipes-core/initrdscripts/files/init-install.sh +40 -12
index cb26163..298ea8d 100644
@@ -106,10 +106,21 @@ fi
 
 disk_size=$(parted /dev/${device} unit mb print | grep Disk | cut -d" " -f 3 | sed -e "s/MB//")
 
+grub_version=$(grub-install -v|sed 's/.* \([0-9]\).*/\1/')
+
+if [ $grub_version -eq 0 ] ; then
+    bios_boot_size=0
+else
+    # For GRUB 2 we need separate parition to store stage2 grub image
+    # 2Mb value is chosen to align partition for best performance.
+    bios_boot_size=2
+fi
+
 swap_size=$((disk_size*swap_ratio/100))
-rootfs_size=$((disk_size-boot_size-swap_size))
+rootfs_size=$((disk_size-bios_boot_size-boot_size-swap_size))
 
-rootfs_start=$((boot_size))
+boot_start=$((bios_boot_size))
+rootfs_start=$((bios_boot_size+boot_size))
 rootfs_end=$((rootfs_start+rootfs_size))
 swap_start=$((rootfs_end))
 
@@ -122,11 +133,21 @@ if [ ! "${device#mmcblk}" = "${device}" ]; then
 	part_prefix="p"
 	rootwait="rootwait"
 fi
-bootfs=/dev/${device}${part_prefix}1
-rootfs=/dev/${device}${part_prefix}2
-swap=/dev/${device}${part_prefix}3
+
+if [ $grub_version -eq 0 ] ; then
+    bios_boot=''
+    bootfs=/dev/${device}${part_prefix}1
+    rootfs=/dev/${device}${part_prefix}2
+    swap=/dev/${device}${part_prefix}3
+else
+    bios_boot=/dev/${device}${part_prefix}1
+    bootfs=/dev/${device}${part_prefix}2
+    rootfs=/dev/${device}${part_prefix}3
+    swap=/dev/${device}${part_prefix}4
+fi
 
 echo "*****************"
+[ $grub_version -ne 0 ] && echo "BIOS boot partition size: $bios_boot_size MB ($bios_boot)"
 echo "Boot partition size:   $boot_size MB ($bootfs)"
 echo "Rootfs partition size: $rootfs_size MB ($rootfs)"
 echo "Swap partition size:   $swap_size MB ($swap)"
@@ -135,10 +156,18 @@ echo "Deleting partition table on /dev/${device} ..."
 dd if=/dev/zero of=/dev/${device} bs=512 count=2
 
 echo "Creating new partition table on /dev/${device} ..."
-parted /dev/${device} mklabel msdos
-
-echo "Creating boot partition on $bootfs"
-parted /dev/${device} mkpart primary 0% $boot_size
+if [ $grub_version -eq 0 ] ; then
+    parted /dev/${device} mktable msdos
+    echo "Creating boot partition on $bootfs"
+    parted /dev/${device} mkpart primary 0% $boot_size
+else
+    parted /dev/${device} mktable gpt
+    echo "Creating BIOS boot partition on $bios_boot"
+    parted /dev/${device} mkpart primary 0% $bios_boot_size
+    parted /dev/${device} set 1 bios_grub on
+    echo "Creating boot partition on $bootfs"
+    parted /dev/${device} mkpart primary $boot_start $boot_size
+fi
 
 echo "Creating rootfs partition on $rootfs"
 parted /dev/${device} mkpart primary $rootfs_start $rootfs_end
@@ -186,7 +215,7 @@ if [ -f /etc/grub.d/00_header ] ; then
     mkdir -p $(dirname $GRUBCFG)
     cat >$GRUBCFG <<_EOF
 menuentry "Linux" {
-    set root=(hd0,1)
+    set root=(hd0,2)
     linux /vmlinuz root=$rootfs $rootwait rw $5 $3 $4 quiet
 }
 _EOF
@@ -195,8 +224,7 @@ fi
 grub-install /dev/${device}
 echo "(hd0) /dev/${device}" > /boot/grub/device.map
 
-# If grub.cfg doesn't exist, assume GRUB 0.97 and create a menu.lst
-if [ ! -f /boot/grub/grub.cfg ] ; then
+if [ $grub_version -eq 0 ] ; then
     echo "Preparing custom grub menu..."
     echo "default 0" > /boot/grub/menu.lst
     echo "timeout 30" >> /boot/grub/menu.lst
Signature · 1 line
2.1.4
author
#6 lore raw

PATCH 6/10 init-install: Implement UUID support

In reply to Ed Bartosh

Used partition UUID in kernel command line to specify root partition. Searched root device by file system uuid in GRUB configuration. Used partition UUID in /etc/fstab to specify swap partition. Used filesystem UUID in /etc/fstab to specify boot partition.

[YOCTO #6101]

meta/recipes-core/initrdscripts/files/init-install.sh +11 -7
index 298ea8d..74ca0be 100644
@@ -195,9 +195,11 @@ mount $rootfs /tgt_root
 mount -o rw,loop,noatime,nodiratime /run/media/$1/$2 /src_root
 echo "Copying rootfs files..."
 cp -a /src_root/* /tgt_root
-if [ -d /tgt_root/etc/ ] ; then
-    echo "$swap                swap             swap       defaults              0  0" >> /tgt_root/etc/fstab
-    echo "$bootfs              /boot            ext3       defaults              1  2" >> /tgt_root/etc/fstab
+if [ -d /tgt_root/etc/ -a $grub_version -ne 0 ] ; then
+    boot_uuid=$(blkid -o value -s UUID /dev/${device}2)
+    swap_part_uuid=$(blkid -o value -s PARTUUID /dev/${device}4)
+    echo "/dev/disk/by-partuuid/$swap_part_uuid                swap             swap       defaults              0  0" >> /tgt_root/etc/fstab
+    echo "UUID=$boot_uuid              /boot            ext3       defaults              1  2" >> /tgt_root/etc/fstab
     # We dont want udev to mount our root device while we're booting...
     if [ -d /tgt_root/etc/udev/ ] ; then
 	echo "/dev/${device}" >> /tgt_root/etc/udev/mount.blacklist
@@ -209,22 +211,24 @@ umount /src_root
 # Handling of the target boot partition
 mount $bootfs /boot
 echo "Preparing boot partition..."
-if [ -f /etc/grub.d/00_header ] ; then
+if [ -f /etc/grub.d/00_header -a $grub_version -ne 0 ] ; then
     echo "Preparing custom grub2 menu..."
+    root_part_uuid=$(blkid -o value -s PARTUUID /dev/${device}3)
+    boot_uuid=$(blkid -o value -s UUID /dev/${device}2)
     GRUBCFG="/boot/grub/grub.cfg"
     mkdir -p $(dirname $GRUBCFG)
     cat >$GRUBCFG <<_EOF
 menuentry "Linux" {
-    set root=(hd0,2)
-    linux /vmlinuz root=$rootfs $rootwait rw $5 $3 $4 quiet
+    search --no-floppy --fs-uuid $boot_uuid --set root
+    linux /vmlinuz root=PARTUUID=$root_part_uuid rootwait rw $5 $3 $4 quiet
 }
 _EOF
     chmod 0444 $GRUBCFG
 fi
 grub-install /dev/${device}
-echo "(hd0) /dev/${device}" > /boot/grub/device.map
 
 if [ $grub_version -eq 0 ] ; then
+    echo "(hd0) /dev/${device}" > /boot/grub/device.map
     echo "Preparing custom grub menu..."
     echo "default 0" > /boot/grub/menu.lst
     echo "timeout 30" >> /boot/grub/menu.lst
Signature · 1 line
2.1.4
author
#7 lore raw

PATCH 7/10 init-install: Specify filesystem type in parted command line

In reply to Ed Bartosh

Explicitly specified filesystem type for parted mkpart command. This makes partition table to look more informative.

meta/recipes-core/initrdscripts/files/init-install-efi.sh +3 -3
index 5fb4d4d..7f3e889 100644
@@ -134,14 +134,14 @@ echo "Creating new partition table on /dev/${device} ..."
 parted /dev/${device} mklabel gpt
 
 echo "Creating boot partition on $bootfs"
-parted /dev/${device} mkpart primary 0% $boot_size
+parted /dev/${device} mkpart primary fat32 0% $boot_size
 parted /dev/${device} set 1 boot on
 
 echo "Creating rootfs partition on $rootfs"
-parted /dev/${device} mkpart primary $rootfs_start $rootfs_end
+parted /dev/${device} mkpart primary ext3 $rootfs_start $rootfs_end
 
 echo "Creating swap partition on $swap"
-parted /dev/${device} mkpart primary $swap_start 100%
+parted /dev/${device} mkpart primary linux-swap $swap_start 100%
 
 parted /dev/${device} print
 
meta/recipes-core/initrdscripts/files/init-install.sh +4 -4
index 74ca0be..ee191a4 100644
@@ -159,21 +159,21 @@ echo "Creating new partition table on /dev/${device} ..."
 if [ $grub_version -eq 0 ] ; then
     parted /dev/${device} mktable msdos
     echo "Creating boot partition on $bootfs"
-    parted /dev/${device} mkpart primary 0% $boot_size
+    parted /dev/${device} mkpart primary ext3 0% $boot_size
 else
     parted /dev/${device} mktable gpt
     echo "Creating BIOS boot partition on $bios_boot"
     parted /dev/${device} mkpart primary 0% $bios_boot_size
     parted /dev/${device} set 1 bios_grub on
     echo "Creating boot partition on $bootfs"
-    parted /dev/${device} mkpart primary $boot_start $boot_size
+    parted /dev/${device} mkpart primary ext3 $boot_start $boot_size
 fi
 
 echo "Creating rootfs partition on $rootfs"
-parted /dev/${device} mkpart primary $rootfs_start $rootfs_end
+parted /dev/${device} mkpart primary ext3 $rootfs_start $rootfs_end
 
 echo "Creating swap partition on $swap"
-parted /dev/${device} mkpart primary $swap_start 100%
+parted /dev/${device} mkpart primary linux-swap $swap_start 100%
 
 parted /dev/${device} print
 
Signature · 1 line
2.1.4
author
#8 lore raw

PATCH 8/10 init-install: Specify partition name in parted command line

In reply to Ed Bartosh

parted allows to use names for partitions if GPT partition table is used on the device. msdos partitioning can have only partition
types: 'primary', 'logical' or 'extended'.

Used meaningful partition names in parted command line for GPT partitioning.

meta/recipes-core/initrdscripts/files/init-install-efi.sh +3 -3
index 7f3e889..a6a8679 100644
@@ -134,14 +134,14 @@ echo "Creating new partition table on /dev/${device} ..."
 parted /dev/${device} mklabel gpt
 
 echo "Creating boot partition on $bootfs"
-parted /dev/${device} mkpart primary fat32 0% $boot_size
+parted /dev/${device} mkpart boot fat32 0% $boot_size
 parted /dev/${device} set 1 boot on
 
 echo "Creating rootfs partition on $rootfs"
-parted /dev/${device} mkpart primary ext3 $rootfs_start $rootfs_end
+parted /dev/${device} mkpart root ext3 $rootfs_start $rootfs_end
 
 echo "Creating swap partition on $swap"
-parted /dev/${device} mkpart primary linux-swap $swap_start 100%
+parted /dev/${device} mkpart swap linux-swap $swap_start 100%
 
 parted /dev/${device} print
 
meta/recipes-core/initrdscripts/files/init-install.sh +6 -4
index ee191a4..2c5d530 100644
@@ -163,17 +163,19 @@ if [ $grub_version -eq 0 ] ; then
 else
     parted /dev/${device} mktable gpt
     echo "Creating BIOS boot partition on $bios_boot"
-    parted /dev/${device} mkpart primary 0% $bios_boot_size
+    parted /dev/${device} mkpart bios_boot 0% $bios_boot_size
     parted /dev/${device} set 1 bios_grub on
     echo "Creating boot partition on $bootfs"
-    parted /dev/${device} mkpart primary ext3 $boot_start $boot_size
+    parted /dev/${device} mkpart boot ext3 $boot_start $boot_size
 fi
 
 echo "Creating rootfs partition on $rootfs"
-parted /dev/${device} mkpart primary ext3 $rootfs_start $rootfs_end
+[ $grub_version -eq 0 ] && pname='primary' || pname='root'
+parted /dev/${device} mkpart $pname ext3 $rootfs_start $rootfs_end
 
 echo "Creating swap partition on $swap"
-parted /dev/${device} mkpart primary linux-swap $swap_start 100%
+[ $grub_version -eq 0 ] && pname='primary' || pname='swap'
+parted /dev/${device} mkpart $pname linux-swap $swap_start 100%
 
 parted /dev/${device} print
 
Signature · 1 line
2.1.4
author
#9 lore raw

PATCH 9/10 init-install: code cleanup: Replace tabs with spaces

In reply to Ed Bartosh

Cleaned up spaces from init-install* shell scripts.

meta/recipes-core/initrdscripts/files/init-install-efi.sh +24 -25
index a6a8679..dca1432 100644
@@ -24,22 +24,22 @@ echo "Searching for hard drives ..."
 
 for device in `ls /sys/block/`; do
     case $device in
-	loop*)
+        loop*)
             # skip loop device
-	    ;;
-	sr*)
+            ;;
+        sr*)
             # skip CDROM device
-	    ;;
-	ram*)
+            ;;
+        ram*)
             # skip ram device
-	    ;;
-	*)
-	    # skip the device LiveOS is on
-	    # Add valid hard drive name to the list
-	    if [ $device != $live_dev_name -a -e /dev/$device ]; then
-		hdnamelist="$hdnamelist $device"
-	    fi
-	    ;;
+            ;;
+        *)
+            # skip the device LiveOS is on
+            # Add valid hard drive name to the list
+            if [ $device != $live_dev_name -a -e /dev/$device ]; then
+                hdnamelist="$hdnamelist $device"
+            fi
+            ;;
     esac
 done
 
@@ -49,8 +49,8 @@ for hdname in $hdnamelist; do
     echo "-------------------------------"
     echo /dev/$hdname
     if [ -r /sys/block/$hdname/device/vendor ]; then
-	echo -n "VENDOR="
-	cat /sys/block/$hdname/device/vendor
+        echo -n "VENDOR="
+        cat /sys/block/$hdname/device/vendor
     fi
     if [ -r /sys/block/$hdname/device/model ]; then
         echo -n "MODEL="
@@ -63,18 +63,17 @@ for hdname in $hdnamelist; do
     echo
     # Get user choice
     while true; do
-	echo -n "Do you want to install this image there? [y/n] "
-	read answer
-	if [ "$answer" = "y" -o "$answer" = "n" ]; then
-	    break
-	fi
-	echo "Please answer y or n"
+        echo -n "Do you want to install this image there? [y/n] "
+        read answer
+        if [ "$answer" = "y" -o "$answer" = "n" ]; then
+            break
+        fi
+        echo "Please answer y or n"
     done
     if [ "$answer" = "y" ]; then
-	TARGET_DEVICE_NAME=$hdname
-	break
+        TARGET_DEVICE_NAME=$hdname
+        break
     fi
-
 done
 
 if [ -n "$TARGET_DEVICE_NAME" ]; then
@@ -170,7 +169,7 @@ if [ -d /tgt_root/etc/ ] ; then
     echo "UUID=$boot_uuid              /boot            vfat       defaults              1  2" >> /tgt_root/etc/fstab
     # We dont want udev to mount our root device while we're booting...
     if [ -d /tgt_root/etc/udev/ ] ; then
-	echo "/dev/${device}" >> /tgt_root/etc/udev/mount.blacklist
+        echo "/dev/${device}" >> /tgt_root/etc/udev/mount.blacklist
     fi
 fi
 
meta/recipes-core/initrdscripts/files/init-install.sh +27 -27

95 lines not on this page · raw message

Signature · 1 line
2.1.4
author
#10 lore raw

PATCH 10/10 init-install: code cleanup: replace /dev/$device -> $device

In reply to Ed Bartosh

Shortened code by including /dev/ prefix into variable.

meta/recipes-core/initrdscripts/files/init-install-efi.sh +19 -19
index dca1432..74372b0 100644
@@ -83,7 +83,7 @@ else
     exit 1
 fi
 
-device=$TARGET_DEVICE_NAME
+device=/dev/$TARGET_DEVICE_NAME
 
 #
 # The udev automounter can cause pain here, kill it
@@ -94,12 +94,12 @@ rm -f /etc/udev/scripts/mount*
 #
 # Unmount anything the automounter had mounted
 #
-umount /dev/${device}* 2> /dev/null || /bin/true
+umount ${device}* 2> /dev/null || /bin/true
 
 mkdir -p /tmp
 cat /proc/mounts > /etc/mtab
 
-disk_size=$(parted /dev/${device} unit mb print | grep Disk | cut -d" " -f 3 | sed -e "s/MB//")
+disk_size=$(parted ${device} unit mb print | grep Disk | cut -d" " -f 3 | sed -e "s/MB//")
 
 swap_size=$((disk_size*swap_ratio/100))
 rootfs_size=$((disk_size-boot_size-swap_size))
@@ -117,32 +117,32 @@ if [ ! "${device#mmcblk}" = "${device}" ]; then
     part_prefix="p"
     rootwait="rootwait"
 fi
-bootfs=/dev/${device}${part_prefix}1
-rootfs=/dev/${device}${part_prefix}2
-swap=/dev/${device}${part_prefix}3
+bootfs=${device}${part_prefix}1
+rootfs=${device}${part_prefix}2
+swap=${device}${part_prefix}3
 
 echo "*****************"
 echo "Boot partition size:   $boot_size MB ($bootfs)"
 echo "Rootfs partition size: $rootfs_size MB ($rootfs)"
 echo "Swap partition size:   $swap_size MB ($swap)"
 echo "*****************"
-echo "Deleting partition table on /dev/${device} ..."
-dd if=/dev/zero of=/dev/${device} bs=512 count=2
+echo "Deleting partition table on ${device} ..."
+dd if=/dev/zero of=${device} bs=512 count=2
 
-echo "Creating new partition table on /dev/${device} ..."
-parted /dev/${device} mklabel gpt
+echo "Creating new partition table on ${device} ..."
+parted ${device} mklabel gpt
 
 echo "Creating boot partition on $bootfs"
-parted /dev/${device} mkpart boot fat32 0% $boot_size
-parted /dev/${device} set 1 boot on
+parted ${device} mkpart boot fat32 0% $boot_size
+parted ${device} set 1 boot on
 
 echo "Creating rootfs partition on $rootfs"
-parted /dev/${device} mkpart root ext3 $rootfs_start $rootfs_end
+parted ${device} mkpart root ext3 $rootfs_start $rootfs_end
 
 echo "Creating swap partition on $swap"
-parted /dev/${device} mkpart swap linux-swap $swap_start 100%
+parted ${device} mkpart swap linux-swap $swap_start 100%
 
-parted /dev/${device} print
+parted ${device} print
 
 echo "Formatting $bootfs to vfat..."
 mkfs.vfat $bootfs
@@ -163,13 +163,13 @@ mount -o rw,loop,noatime,nodiratime /run/media/$1/$2 /src_root
 echo "Copying rootfs files..."
 cp -a /src_root/* /tgt_root
 if [ -d /tgt_root/etc/ ] ; then
-    boot_uuid=$(blkid -o value -s UUID /dev/${device}1)
-    swap_part_uuid=$(blkid -o value -s PARTUUID /dev/${device}3)
+    boot_uuid=$(blkid -o value -s UUID ${device}1)
+    swap_part_uuid=$(blkid -o value -s PARTUUID ${device}3)
     echo "/dev/disk/by-partuuid/$swap_part_uuid                swap             swap       defaults              0  0" >> /tgt_root/etc/fstab
     echo "UUID=$boot_uuid              /boot            vfat       defaults              1  2" >> /tgt_root/etc/fstab
     # We dont want udev to mount our root device while we're booting...
     if [ -d /tgt_root/etc/udev/ ] ; then
-        echo "/dev/${device}" >> /tgt_root/etc/udev/mount.blacklist
+        echo "${device}" >> /tgt_root/etc/udev/mount.blacklist
     fi
 fi
 
@@ -185,7 +185,7 @@ mkdir -p $EFIDIR
 cp /run/media/$1/EFI/BOOT/*.efi $EFIDIR
 
 if [ -f /run/media/$1/EFI/BOOT/grub.cfg ]; then
-    root_part_uuid=$(blkid -o value -s PARTUUID /dev/${device}2)
+    root_part_uuid=$(blkid -o value -s PARTUUID ${device}2)
     GRUBCFG="$EFIDIR/grub.cfg"
     cp /run/media/$1/EFI/BOOT/grub.cfg $GRUBCFG
     # Update grub config for the installed image
meta/recipes-core/initrdscripts/files/init-install.sh +29 -29

127 lines not on this page · raw message

Signature · 1 line
2.1.4