summaryrefslogtreecommitdiff
path: root/src/core/libs/lib-blockdevices-filesystems.sh
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/libs/lib-blockdevices-filesystems.sh')
-rw-r--r--src/core/libs/lib-blockdevices-filesystems.sh74
1 files changed, 64 insertions, 10 deletions
diff --git a/src/core/libs/lib-blockdevices-filesystems.sh b/src/core/libs/lib-blockdevices-filesystems.sh
index 3511557..a4bc534 100644
--- a/src/core/libs/lib-blockdevices-filesystems.sh
+++ b/src/core/libs/lib-blockdevices-filesystems.sh
@@ -4,6 +4,8 @@
# FORMAT DEFINITIONS:
# -- formats used to interface with this library --
+# these files will persist during the entire aif session (and even after stopping aif)
+# so you can use them to retrieve data from them (or use functions in this library to do that for you)
# $TMP_PARTITIONS
# one line per partition, blockdevice + partioning string for sfdisk. See docs for function partition for more info.
# $TMP_BLOCKDEVICES
@@ -76,6 +78,53 @@ target_umountall()
done
}
+# tells you which blockdevice is configured for the specific mountpoint
+# $1 mountpoint
+get_device_with_mount () {
+ ANSWER_DEVICE=`grep ";$1;" $TMP_BLOCKDEVICES 2>/dev/null | cut -d ' ' -f1`
+ [ -n "$ANSWER_DEVICE" ] # set correct exit code
+}
+
+# gives you a newline separated list of the blockdevice that hosts a certain filesystem, and below it, all underlying blockdevices supporting it, with also the blockdevice type.
+# example:
+# get_anchestors_mount ';/;' (suppose '/' is a filesystem on top of lvm on top of dm_crypt, you will get something like):
+# /dev/mapper/cryptpool-cryptroot lvm-lv
+# /dev/mapper/cryptpool lvm-vg
+# /dev/mapper/sda2crypt+ lvm-pv
+# /dev/mapper/sda2crypt dm_crypt
+# /dev/sda2 raw
+# $1 a "recognizer": a string that will match the filesystem section uniquely (using egrep), such as ';<mountpoint>;' or other specific attributes of the hosted filesystem(s)
+get_anchestors_mount () {
+ debug 'FS' "Finding anchestor for: $1"
+ local buffer=
+ read block type leftovers <<< `egrep "$1" $TMP_BLOCKDEVICES 2>/dev/null`
+ [ -z "$type" ] && return 1
+ buffer="$block $type"
+ if [ $type != 'raw' ]
+ then
+ if [ $type == lvm-lv ]
+ then
+ lv=`echo $block | sed 's/.*-//'` # /dev/mapper/cryptpool-cryptroot -> cryptroot. TODO: this may give unexpected behavior of LV has a '-' in its name
+ recognizer="lvm-lv;(yes|no);no_mountpoint;[^;]{1,};[^;]{1,};$lv;[^;]{1,}"
+ elif [ $type == lvm-vg ]
+ then
+ recognizer="lvm-vg;(yes|no);no_mountpoint;[^;]{1,};[^;]{1,};`basename $block`;[^;]{1,}"
+ elif [ $type == lvm-pv ]
+ then
+ # here we cheat a bit: we cannot match the FS section because usually we don't give a PV recognizable attributes, but since we name a PV as blockdevice + '+' we can match the blockdevice
+ recognizer="^${block/+/} .* lvm-pv;"
+ elif [ $type == dm_crypt ]
+ then
+ recognizer="dm_crypt;(yes|no);no_mountpoint;[^;]{1,};[^;]{1,};`basename $block`;[^;]{1,}"
+ fi
+ get_anchestors_mount "$recognizer" && buffer="$buffer
+$ANSWER_DEVICES"
+ fi
+ debug 'FS' "Found anchestors: $ANSWER_DEVICES"
+ ANSWER_DEVICES=$buffer
+ [ -n "$ANSWER_DEVICES" ]
+}
+
# taken from setup script, modified for separator control
# $1 set to 1 to echo a newline after device instead of a space (optional)
@@ -506,14 +555,24 @@ rollback_filesystems ()
# -> easier (implemented)
- infofy "Phase 2: destructing specified blockdevices" disks
+ infofy "Phase 2: destructing relevant blockdevices" disks
for i in `seq 1 10`
do
open_items=0
- while read part part_type part_label fs_string # $fs_string can be ignored
+ while read part part_type part_label fs_string
do
+
real_part=${part/+/}
- if [ "$part_type" = dm_crypt ] # Can be in use for: lvm-pv or raw. we don't need to care about raw (it will be unmounted so it can be destroyed)
+
+ # do not destroy a blockdevice if it hosts one or more filesystems that were set to not recreate
+ # fs_string = one or more "$fs_type;$fs_create;$fs_mountpoint;target;$fs_opts;$fs_label;$fs_params", separated by ':'
+ # there is probably a nice regex to check this but i'm bad at regexes.
+ if echo "$fs_string" | grep -q ';yes;/' || echo "$fs_string" | grep -q ';yes;no_mountpoint'
+ then
+ infofy "Skipping destruction of $part ($part_type) because one of the filesystems on it contains data you want to keep"
+ # TODO: it's possible that if we don't clear a blockdevice here because there is something on it with valuable data, that this blockdevice itself is hosted on some other blockdevice (eg lvm VG,PV or dm_crypt), \
+ # that blockdevice cannot be cleared as well because it depends on this one, so after 10 iterations the user will get a warning that not everything is cleared. so we should fix this someday.
+ elif [ "$part_type" = dm_crypt ] # Can be in use for: lvm-pv or raw. we don't need to care about raw (it will be unmounted so it can be destroyed)
then
if [ -b $real_part ] && cryptsetup status $real_part &>/dev/null # don't use 'isLuks' it only works for the "underlying" device (eg in /dev/sda1 -> luksOpen -> /dev/mapper/foo, isLuks works only on the former. status works on the latter too)
then
@@ -649,7 +708,7 @@ process_filesystem ()
fi
[ -z "$fs_label" ] && [ "$fs_type" = lvm-vg -o "$fs_type" = lvm-pv ] && fs_label=default #TODO. implement the incrementing numbers label for lvm vg's and lv's
- ret=0
+ local ret=0
#TODO: health checks on $fs_params etc
case ${fs_type} in #TODO: implement label, opts etc decently
xfs) mkfs.xfs -f $part $opts >$LOG 2>&1; ret=$? ;;
@@ -691,11 +750,6 @@ process_filesystem ()
debug 'FS' "mounting $part on $dst"
mkdir -p $dst &>/dev/null # directories may or may not already exist
mount -t $fs_type $part $dst >$LOG 2>&1 || ( show_warning 'Mount' "Error mounting $part on $dst" ; return 1 )
- if [ "$fs_mount" = target -a $fs_mountpoint = '/' ]
- then
- debug FS "setting \$PART_ROOT to $part"
- PART_ROOT=$part
- fi
fi
fi
@@ -794,7 +848,7 @@ mdraid_is-raid ()
# $1 md raid blockdevice (ex: /dev/md0)
# return the array member device which is slave 0 in the given array
# ex: /dev/md0 is an array with /dev/sda1, /dev/sdb1,
-# so we would return /dev/sda1 as slave 0
+# so we would return /dev/sda1 as slave 0
#
# This procedure is used to determine the grub value for root, ex: (hd0,0)
mdraid_slave0 ()