From ff3bbf7bb85739fe4b27e82d90a810f905478c6e Mon Sep 17 00:00:00 2001 From: "Carl D. Roth" Date: Fri, 22 Jul 2016 13:27:58 -0700 Subject: [PATCH 1/2] Remount onie-boot if necessary --- builds/any/installer/installer.sh.in | 24 ++++++++-- .../vendor-config-onl/src/lib/install/lib.sh | 47 +++++++++++++++++++ 2 files changed, 67 insertions(+), 4 deletions(-) diff --git a/builds/any/installer/installer.sh.in b/builds/any/installer/installer.sh.in index e2dbd86e..fc2a95fa 100644 --- a/builds/any/installer/installer.sh.in +++ b/builds/any/installer/installer.sh.in @@ -399,10 +399,26 @@ installer_mkchroot "${rootdir}" mkdir -p "${rootdir}/mnt/installer" mount -o ro,bind "${installer_dir}" "${rootdir}/mnt/installer" -# make the onie boot files available to the chroot -mkdir -p "${rootdir}/mnt/onie-boot" -if test -d "/mnt/onie-boot"; then - mount -o ro,bind "/mnt/onie-boot" "${rootdir}/mnt/onie-boot" +# make sure onie-boot is mounted +if test -d /mnt/onie-boot; then + if grep -q " /mnt/onie-boot " /proc/mounts; then + : + else + ONIE_BOOT_DEVICE= + visit_blkid blkid_find_onie + if test -b "$ONIE_BOOT_DEVICE"; then + installer_say "Mounting ONIE-BOOT ($ONIE_BOOT_DEVICE) as /mnt/onie-boot" + mount -o defaults,rw $ONIE_BOOT_DEVICE /mnt/onie-boot + else + installer_say "*** missing ONIE-BOOT device" + fi + fi + + if grep -q " /mnt/onie-boot " /proc/mounts; then + # make the onie boot files available to the chroot + mkdir -p "${rootdir}/mnt/onie-boot" + mount -o ro,bind "/mnt/onie-boot" "${rootdir}/mnt/onie-boot" + fi fi # generate config for installer environment diff --git a/packages/base/all/vendor-config-onl/src/lib/install/lib.sh b/packages/base/all/vendor-config-onl/src/lib/install/lib.sh index 78a5033b..cce68557 100644 --- a/packages/base/all/vendor-config-onl/src/lib/install/lib.sh +++ b/packages/base/all/vendor-config-onl/src/lib/install/lib.sh @@ -123,6 +123,53 @@ installer_mkchroot() { fi } +visit_blkid() +{ + local fn rest + fn=$1; shift + rest="$@" + + local ifs + ifs=IFS; IFS=$CR + for line in $(blkid); do + IFS=$ifs + + local dev + dev=${line%%:*} + line=${line#*:} + + local TYPE LABEL PARTLABEL UUID PARTUUID + while test "$line"; do + local key + key=${line%%=*} + line=${line#*=} + case "$line" in + '"'*) + line=${line#\"} + val=${line%%\"*} + line=${line#*\"} + line=${line## } + ;; + *) + val=${line%% *} + line=${line#* } + ;; + esac + eval "$key=\"$val\"" + done + + local sts + eval $fn \"$dev\" \"$LABEL\" \"$UUID\" \"$PARTLABEL\" \"$PARTUUID\" $rest + sts=$? + if test $sts -eq 2; then break; fi + if test $sts -ne 0; then return $sts; fi + + done + IFS=$ifs + + return 0 +} + # Local variables # mode: sh # sh-basic-offset: 2 From a2a255ae06eee7d262193dee3ea39d78d51ab6c1 Mon Sep 17 00:00:00 2001 From: "Carl D. Roth" Date: Fri, 22 Jul 2016 13:33:00 -0700 Subject: [PATCH 2/2] Updates for large disks - report logical and physical sector sizes - be less strict about sector sizes - align partitions on physical sector size --- .../src/python/onl/install/BaseInstall.py | 45 ++++++++++++++----- 1 file changed, 34 insertions(+), 11 deletions(-) diff --git a/packages/base/all/vendor-config-onl/src/python/onl/install/BaseInstall.py b/packages/base/all/vendor-config-onl/src/python/onl/install/BaseInstall.py index f18cd649..44fc575a 100644 --- a/packages/base/all/vendor-config-onl/src/python/onl/install/BaseInstall.py +++ b/packages/base/all/vendor-config-onl/src/python/onl/install/BaseInstall.py @@ -225,9 +225,28 @@ class Base: devices = {} def _u2s(sz, u): + """Convert to units of logical sectors.""" bsz = sz * u - bsz = bsz + self.partedDevice.physicalSectorSize - 1 - return bsz / self.partedDevice.physicalSectorSize + bsz = bsz + self.partedDevice.sectorSize - 1 + return bsz / self.partedDevice.sectorSize + + def _align(spos): + """Align this sector number.""" + sz = self.partedDevice.sectorSize + psz = self.partedDevice.physicalSectorSize + + if type(psz) != int: return spos + if psz <= sz: return spos + if (psz % sz) != 0: return spos + if psz > 1048576: return spos + + stride = psz / sz + off = spos % stride + off = stride - off + off = off % stride + + spos += off + return spos UNITS = { 'GiB' : 1024 * 1024 * 1024, @@ -260,7 +279,7 @@ class Base: part, sz) return 1 - start = nextBlock + start = _align(nextBlock) end = start + cnt - 1 if end <= self.partedDevice.getLength(): self.log.info("Allocating %d sectors for %s", @@ -526,15 +545,17 @@ class GrubInstaller(SubprocessMixin, Base): self.log.info("disk is %s", self.partedDevice.path) + self.log.info("found %s partitions (bsz %s, lbsz %s)", + self.partedDisk.type, + self.partedDevice.sectorSize, + self.partedDevice.physicalSectorSize) if self.partedDisk.type != 'gpt': self.log.error("not a GPT partition table") return 1 if self.partedDevice.sectorSize != 512: - self.log.error("invalid logical block size") - return 1 + self.log.warn("invalid logical block size, expected 512") if self.partedDevice.physicalSectorSize != 512: - self.log.error("invalid physical block size") - return 1 + self.log.warn("invalid physical block size, expected 512") self.log.info("found a disk with %d blocks", self.partedDevice.getLength()) @@ -745,15 +766,17 @@ class UbootInstaller(SubprocessMixin, Base): self.log.info("Installing to %s", self.device) + self.log.info("found %s partitions (bsz %s, lbsz %s)", + self.partedDisk.type, + self.partedDevice.sectorSize, + self.partedDevice.physicalSectorSize) if self.partedDisk.type != 'msdos': self.log.error("not an MSDOS partition table") return 1 if self.partedDevice.sectorSize != 512: - self.log.error("invalid logical block size") - return 1 + self.log.warn("invalid logical block size, expected 512") if self.partedDevice.physicalSectorSize != 512: - self.log.error("invalid physical block size") - return 1 + self.log.warn("invalid physical block size, expected 512") self.log.info("found a disk with %d blocks", self.partedDevice.getLength())