summaryrefslogtreecommitdiff
path: root/debian
diff options
context:
space:
mode:
authorScott Moser <smoser@brickies.net>2016-11-18 15:35:05 -0500
committerScott Moser <smoser@brickies.net>2016-11-18 16:50:44 -0500
commitb6d4f94134d0963af7c5384994ab35dfc05983bf (patch)
treebbe1d0f829b31bbef32fa95f99ff4a8acc35a3aa /debian
parenta6cb29c7ffb09c3916e747280f0c9d05c4955e6d (diff)
downloadvyos-cloud-init-b6d4f94134d0963af7c5384994ab35dfc05983bf.tar.gz
vyos-cloud-init-b6d4f94134d0963af7c5384994ab35dfc05983bf.zip
debian/cloud-init.postinst: update /etc/fstab on Azure instances.
The edit consists of replacing comment=cloudconfig with x-systemd.requires,comment=cloudconfig inside of the 4th (fs_mntops) field in fstab. The edits are carefully safeguarded by checks for: a.) existance of /var/lib/cloud/instance/datasource b.) running on Azure per previous datasource run. c.) existance of /etc/fstab d.) upgrading from sufficiently old version Additionally before any write is done, we check that the new and old fstab file differ. LP: #1611074
Diffstat (limited to 'debian')
-rw-r--r--debian/cloud-init.postinst67
1 files changed, 67 insertions, 0 deletions
diff --git a/debian/cloud-init.postinst b/debian/cloud-init.postinst
index a36fb248..420420b5 100644
--- a/debian/cloud-init.postinst
+++ b/debian/cloud-init.postinst
@@ -5,6 +5,11 @@
set -f # disable pathname expansion
db_capb escape # to support carriage return / multi-line values
+debug() {
+ [ "${_CI_UPGRADE_DEBUG:-0}" = "0" ] && return 0
+ echo "$@" 1>&2 || :
+}
+
update_cfg() {
# takes filename, header, new object (in yaml), optionally 'remover'
# and merges new into existing object in filename, and then updates file
@@ -212,6 +217,66 @@ disable_network_config_on_upgrade() {
fi
}
+fix_azure_upgrade_1611074() {
+ # adjust /etc/fstab on azure so boot after resize does not mount
+ # /mnt as ntfs and stop re-formatting.
+ local fixed_ver="0.7.8-49-1" dspath="/var/lib/cloud/instance/datasource"
+ local oldver="$1" tmpf="" r="" wmsg="" me="cloud-init postinst"
+
+ # if not on azure, or not booted with instance/ skip out.
+ if [ ! -e "$dspath" ]; then
+ debug "no $dspath"
+ return 0
+ fi
+ if ! grep -qi azure "$dspath"; then
+ debug "not on azure per $dspath"
+ return 0
+ fi
+
+ # if there is no /etc/fstab, then nothing to fix.
+ if [ ! -e /etc/fstab ]; then
+ debug "no /etc/fstab"
+ return 0
+ fi
+
+ if dpkg --compare-versions "$oldver" ge "$fixed_ver"; then
+ debug "previous version was fixed"
+ return 0
+ fi
+
+ wmsg="WARN: $me failed."
+ wmsg="$wmsg Subsequent resize may not update ephemeral correctly."
+ tmpf=$(mktemp "${TMPDIR:-/tmp}/cloud-init-upgrade.XXXXXX") || {
+ echo "$wmsg (mktemp failed with $?)" 1>&2
+ return 0;
+ }
+
+ awk '{
+ if ($4 !~ /x-systemd.requires/ && $4 ~ /comment=cloudconfig/) {
+ sub(/comment=cloudconfig/, "x-systemd.requires=cloud-init.service,comment=cloudconfig")
+ }
+ printf("%s\n", $0)}' /etc/fstab > "$tmpf" || {
+ echo "$wmsg (awk reading of /etc/fstab failed with $?)" 1>&2
+ rm -f "$tmpf"
+ return 0;
+ }
+ if cmp /etc/fstab "$tmpf" >/dev/null 2>&1; then
+ debug "no changes needed."
+ else
+ cat "$tmpf" > /etc/fstab || {
+ r=$?
+ echo "$wmsg (cp $tmpf /etc/fstab failed with $r)"
+ echo ==== expected to write the following to /etc/fstab =====
+ cat "$tmpf"
+ echo ========================================================
+ return $r
+ } 1>&2
+ echo "$me fixed /etc/fstab for x-systemd.requires" 1>&2
+ fi
+ rm "$tmpf" || :
+}
+
+
if [ "$1" = "configure" ]; then
# disable ureadahead (LP: #499520)
dpkg-divert --package cloud-init --rename --divert \
@@ -254,6 +319,8 @@ EOF
# make upgrades disable network changes by cloud-init
disable_network_config_on_upgrade "$2"
+
+ fix_azure_upgrade_1611074 "$2"
fi
#DEBHELPER#