Skip to content
Permalink
Browse files

Make resize_rootfs dynamic

  • Loading branch information...
NEMS Linux
NEMS Linux committed Mar 25, 2019
1 parent f4aa295 commit 9b168ac36dacb5723277ddbfbf31799a81bd2728
@@ -1,6 +1,6 @@
#!/bin/bash
BOOT=/etc/rc.local
BOOTDEVICE=`ls -l /dev/disk/by-uuid/ | grep 96C3-9298 | awk '{print $11}' | sed "s/\.\.\/\.\.\///" | sed "s/p1//"`
rootdev=`/usr/local/bin/nems-info rootdev`
rootpart=`/usr/local/bin/nems-info rootpart`

function do_resize
{
@@ -10,24 +10,24 @@ function do_resize
echo "Saving the log to $rsflog"
sleep 4

p2_start=`/sbin/fdisk -l /dev/$BOOTDEVICE | grep ${BOOTDEVICE}p2 | awk '{print $2}'`
p2_end=$(((`/sbin/fdisk -l /dev/$BOOTDEVICE | head -n1 | grep -i bytes | awk '{print $5}'`/512)-20))
echo $p2_end
part_start=`/sbin/fdisk -l /dev/$rootdev | grep ${rootdev}p${$rootpart} | awk '{print $2}'`
part_end=$(((`/sbin/fdisk -l /dev/$rootdev | head -n1 | grep -i bytes | awk '{print $5}'`/512)-20))
echo $part_end

/sbin/fdisk /dev/$BOOTDEVICE <<EOF &>> $rsflog
/sbin/fdisk /dev/$rootdev <<EOF &>> $rsflog
p
d
2
$rootpart
n
p
2
$p2_start
$p2_end
$rootpart
$part_start
$part_end
p
w
EOF
sync && sync
sed -i "s,/root/nems/nems-admin/resize_rootfs/odroid-stage1,/root/nems/nems-admin/resize_rootfs/odroid-stage2,g" "$BOOT"
sed -i "s,/root/nems/nems-admin/resize_rootfs/odroid-stage1,/root/nems/nems-admin/resize_rootfs/odroid-stage2,g" "/etc/rc.local"
echo > /etc/udev/rules.d/70-persistent-net.rules
}

@@ -1,15 +1,15 @@
#!/bin/bash
rootdev=`/usr/local/bin/nems-info rootdev`
rootpart=`/usr/local/bin/nems-info rootpart`

# Get the log filename passed from Stage 1.
rslog=$(cat /var/log/nems/resize-logfile.tmp)
rm -f /var/log/nems/resize-logfile.tmp

BOOTDEVICE=`ls -l /dev/disk/by-uuid/ | grep 96C3-9298 | awk '{print $11}' | sed "s/\.\.\/\.\.\///" | sed "s/p1//"`
NEMSPART=${BOOTDEVICE}p2

echo "Stage 2 on $NEMSPART" >> $rslog
echo "Stage 2 on ${rootdev}p${rootpart}" >> $rslog

echo "-------- Resize --------" >> $rslog
/sbin/resize2fs /dev/$NEMSPART >> $rslog 2>&1
/sbin/resize2fs /dev/${rootdev}p${rootpart} >> $rslog 2>&1
echo "-------- /Resize -------" >> $rslog

sed -i "s,/root/nems/nems-admin/resize_rootfs/odroid-stage2,,g" /etc/rc.local
@@ -1,13 +1,6 @@
#!/bin/sh

#FROM: https://github.com/longsleep/build-pine64-image/blob/master/simpleimage/platform-scripts/resize_rootfs.sh
# The version included in the XU4 Stretch distro /root/scripts/resize is much sexier. Eventually integrate.

#The MIT License (MIT)
#Copyright (c) 2016 Simon Eisenmann <simon@longsleep.org>
#Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
#The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
rootdev=`/usr/local/bin/nems-info rootdev`
rootpart=`/usr/local/bin/nems-info rootpart`

set -e

@@ -18,29 +11,26 @@ fi

set -x

DEVICE="/dev/mmcblk0"
PART="2"

resize() {
start=$(fdisk -l ${DEVICE}|grep ${DEVICE}p${PART}|awk '{print $2}')
start=$(fdisk -l /dev/${rootdev}|grep /dev/${rootdev}p${rootpart}|awk '{print $2}')
echo $start

set +e
fdisk ${DEVICE} <<EOF
fdisk /dev/${rootdev} <<EOF
p
d
2
$rootpart
n
p
2
$rootpart
$start
w
EOF
set -e

partx -u ${DEVICE}
resize2fs ${DEVICE}p${PART}
partx -u /dev/${rootdev}
resize2fs /dev/${rootdev}p${rootpart}
}

resize
@@ -1,4 +1,9 @@
#!/bin/bash

# ******
# need to re-write this to remove the dependency on raspi-config
# ******

# Resize Raspberry Pi on first boot
platform=$(/usr/local/share/nems/nems-scripts/info.sh platform)

@@ -1,6 +1,7 @@
#!/bin/bash
BOOTDEVICE=mmcblk1
PARTITION=7
rootdev=`/usr/local/bin/nems-info rootdev`
rootpart=`/usr/local/bin/nems-info rootpart`

PLATFORM=rock64 # Must match the filename $PLATFORM-stage#

function do_resize
@@ -10,16 +11,16 @@ function do_resize
echo "Saving the log to $rsflog"
sleep 4

start=`/sbin/fdisk -l /dev/$BOOTDEVICE | grep ${BOOTDEVICE}p${PARTITION} | awk '{print $2}'`
end=$(((`/sbin/fdisk -l /dev/$BOOTDEVICE | head -n1 | grep -i bytes | awk '{print $5}'`/512)-34))
start=`/sbin/fdisk -l /dev/$rootdev | grep ${rootdev}p${rootpart} | awk '{print $2}'`
end=$(((`/sbin/fdisk -l /dev/$rootdev | head -n1 | grep -i bytes | awk '{print $5}'`/512)-34))

/sbin/fdisk /dev/$BOOTDEVICE <<EOF &>> $rsflog
/sbin/fdisk /dev/$rootdev <<EOF &>> $rsflog
p
d
$PARTITION
$rootpart
n
p
$PARTITION
$rootpart
$start
$end
p
@@ -1,9 +1,10 @@
#!/bin/bash
BOOTDEVICE=mmcblk1
PARTITION=7
rootdev=`/usr/local/bin/nems-info rootdev`
rootpart=`/usr/local/bin/nems-info rootpart`

PLATFORM=rock64 # Must match the filename $PLATFORM-stage#

/sbin/resize2fs /dev/${BOOTDEVICE}p${PARTITION}
/sbin/resize2fs /dev/${rootdev}p${rootpart}
sed -i "s,/root/nems/nems-admin/resize_rootfs/"'${PLATFORM}'"-stage2,,g" /etc/rc.local

# Log that patch (resize) has been applied to this system

0 comments on commit 9b168ac

Please sign in to comment.
You can’t perform that action at this time.