From bc6c23fef300e4ea8640d94ed3beb9b49b07c0b7 Mon Sep 17 00:00:00 2001 From: Paul Whalen Date: Jun 01 2018 16:05:21 +0000 Subject: Added proper lvm support. --- diff --git a/arm-image-installer b/arm-image-installer index 6071021..93fea98 100755 --- a/arm-image-installer +++ b/arm-image-installer @@ -245,6 +245,10 @@ if [ "$NOASK" != 1 ]; then fi # umount before starting umount $MEDIA* &> /dev/null +if [ "$(fdisk -l $MEDIA | grep LVM)" != "" ] ; then + #LVM_NAME=$(pvs | grep $MEDIA | awk '{print $2}') + vgchange -a n $(pvs | grep $MEDIA | awk '{print $2}') +fi # Write the disk image to media if [ "$IMAGE" != "" ]; then @@ -253,13 +257,7 @@ if [ "$IMAGE" != "" ]; then echo "= To: $MEDIA ...." xzcat $IMAGE | dd of=$MEDIA bs=4M; sync; sleep 3 echo "= Writing image complete!" - if [ "$(echo $IMAGE | awk '/aarch64/ && /Server/')" != "" ]; then - echo "= The AArch64 Server image uses LVM and will require manual U-Boot install and resize." - exit 0 - else - # read the new partition table partprobe "$MEDIA" - fi fi # check to see how many partitions on the image partprobe "$MEDIA" @@ -271,11 +269,16 @@ case $MEDIA in BOOTPART="${MEDIA}p2" ROOTPART="${MEDIA}p5" PARTNUM=5 - else + elif [ -e "$MEDIA"p4 ]; then export FIRMPART="${MEDIA}p1" BOOTPART="${MEDIA}p2" ROOTPART="${MEDIA}p4" PARTNUM=4 + else + export FIRMPART="${MEDIA}p1" + BOOTPART="${MEDIA}p2" + ROOTPART="${MEDIA}p3" + PARTNUM=3 fi ;; *) @@ -284,11 +287,16 @@ case $MEDIA in BOOTPART="${MEDIA}2" ROOTPART="${MEDIA}5" PARTNUM=5 - else + elif [ -e "$MEDIA"4 ]; then export FIRMPART="${MEDIA}1" BOOTPART="${MEDIA}2" ROOTPART="${MEDIA}4" PARTNUM=4 + else + export FIRMPART="${MEDIA}1" + BOOTPART="${MEDIA}2" + ROOTPART="${MEDIA}3" + PARTNUM=3 fi ;; esac @@ -309,22 +317,47 @@ if [ "$RESIZEFS" != "" ]; then continue fi done + partprobe "$MEDIA" + fi - partprobe "$MEDIA" - - FS_TYPE=$(file -s "$ROOTPART" | awk '{print $3}') - if [ "$FS_TYPE" = "XFS" ]; then - mkdir /tmp/root &> /dev/null - mount "$ROOTPART" /tmp/root &> /dev/null - xfs_growfs /tmp/root - umount "$ROOTPART" - else - fsck.ext4 -fy "$ROOTPART" - resize2fs "$ROOTPART" - fi + if [ "$PARTNUM" = "3" ] && [ "$(fdisk -l $MEDIA | grep LVM)" != "" ] ; then + LVM_NAME=$(pvs | grep $MEDIA | awk '{print $2}') + vgchange -a n $LVM_NAME + echo ", +" | sfdisk -N "$PARTNUM" "$MEDIA" + while [ $? != '0' ]; do + sleep 5 + echo ", +" | sfdisk -N "$PARTNUM" "$MEDIA" + ((count++)) + if [ $count -gt 5 ]; then + echo "= Partition Resize Failed." + continue + fi + done + sleep 5 + partprobe "$MEDIA" + vgchange -a y $LVM_NAME + pvresize "$ROOTPART" + lvextend -l +100%FREE /dev/$LVM_NAME/root + ROOTPART="/dev/$LVM_NAME/root" + fi + + if [ "$LVM_NAME" != "" ]; then + FS_TYPE=$(file -s --dereference "$ROOTPART" | awk '{print $3}') else - echo "= NOTE: Manual partition resizing is required." - fi + FS_TYPE=$(file -s --dereference "$ROOTPART" | awk '{print $5}') + fi + + if [ "$FS_TYPE" = "XFS" ] && [ $LVM_NAME != "" ]; then + mkdir /tmp/root &> /dev/null + mount "$ROOTPART" /tmp/root &> /dev/null + xfs_growfs /tmp/root + umount "$ROOTPART" + elif [ "$FS_TYPE" = "ext4" ]; then + fsck.ext4 -fy "$ROOTPART" + resize2fs "$ROOTPART" + fi +else + echo "= NOTE: Manual partition resizing is required." fi # make temp mount points @@ -335,10 +368,14 @@ if [ $? -ne 0 ]; then exit 1 fi -mount "$ROOTPART" /tmp/root &> /dev/null -if [ $? -ne 0 ]; then - echo "Error: mount $ROOTPART /tmp/root failed" - exit 1 +if [ "$LVM_NAME" != "" ]; then + mount "/dev/$LVM_NAME/root" /tmp/root +else + mount "$ROOTPART" /tmp/root + if [ $? -ne 0 ]; then + echo "Error: mount $ROOTPART /tmp/root failed" + exit 1 + fi fi # turn off selinux @@ -377,6 +414,7 @@ if [ "$TARGET" = "" ]; then else PREFIX=/tmp/root . "${BOARDDIR}/${TARGET}" + # Add console if [ "$CONSOLE" = "1" ] && [ -f /tmp/boot/extlinux/extlinux.conf ]; then if [ "$SYSCON" = "" ]; then @@ -415,6 +453,9 @@ fi sync umount $ROOTPART $BOOTPART $FIRMPART &> /dev/null +if [ "$LVM_NAME" != "" ]; then + vgchange -a n $LVM_NAME +fi rmdir /tmp/root /tmp/boot /tmp/fw &> /dev/null if [ "$URL" != "" ]; then