create growroot element
We can resize the rootfs without the initrd based approach. Create a growroot element which performs rootfs resizing as part of system init. Change-Id: Ibeb846b0170d141fb72323a441d14b65b93ae0a1
This commit is contained in:
parent
7f6dbe534f
commit
16fc1f9012
7
elements/growroot/README.rst
Normal file
7
elements/growroot/README.rst
Normal file
@ -0,0 +1,7 @@
|
||||
========
|
||||
growroot
|
||||
========
|
||||
|
||||
Grow the root partition on first boot.
|
||||
|
||||
This only supported on ubuntu trusty or later.
|
2
elements/growroot/element-deps
Normal file
2
elements/growroot/element-deps
Normal file
@ -0,0 +1,2 @@
|
||||
dib-init-system
|
||||
install-static
|
9
elements/growroot/init-scripts/upstart/growroot.conf
Normal file
9
elements/growroot/init-scripts/upstart/growroot.conf
Normal file
@ -0,0 +1,9 @@
|
||||
description "Growing root partition"
|
||||
|
||||
console output
|
||||
|
||||
start on mounted MOUNTPOINT=/
|
||||
|
||||
post-start script
|
||||
/usr/local/sbin/growroot
|
||||
end script
|
26
elements/growroot/static/usr/local/sbin/growroot
Executable file
26
elements/growroot/static/usr/local/sbin/growroot
Executable file
@ -0,0 +1,26 @@
|
||||
#!/bin/bash
|
||||
# dib-lint: disable=dibdebugtrace
|
||||
|
||||
set -exu
|
||||
set -o pipefail
|
||||
|
||||
root_dev=$(df -P / | tail -n 1 | awk '/.*/ { print $1 }')
|
||||
minor_dev_no=$(stat --printf="%T" $root_dev)
|
||||
major_dev_no=$(stat --printf="%t" $root_dev)
|
||||
|
||||
# The last digit of our minor number should, on a partitioned block device,
|
||||
# be the partition number of the device (starting at 1). We need to convert
|
||||
# this value to decimal from hex for use in growpart.
|
||||
part_no=$(echo $minor_dev_no | tail -c 2)
|
||||
part_no=$((16#$part_no))
|
||||
|
||||
disk=$(find /sys/dev/block -name "$((16#$major_dev_no)):${minor_dev_no::-1}0")
|
||||
disk="/dev/$(source ${disk}/uevent; echo $DEVNAME)"
|
||||
|
||||
set +e
|
||||
growpart $disk $part_no
|
||||
# Error code 1 means no change
|
||||
if [ "$?" -le 1 ]; then
|
||||
# always return true because this might not work if were are non ext4
|
||||
resize2fs $root_dev || true
|
||||
fi
|
Loading…
Reference in New Issue
Block a user