From f36626142d0b637c6a7c5e0e51e8173221e83d58 Mon Sep 17 00:00:00 2001 From: Michael Pereira Neves Date: Wed, 3 Sep 2014 16:17:04 -0300 Subject: [setup_partitions] reworked setup partitions script, testing needed --- .../opt/openslx/scripts/systemd-setup_partitions | 191 +++++++++++---------- 1 file changed, 104 insertions(+), 87 deletions(-) diff --git a/remote/rootfs/rootfs-stage32/data/opt/openslx/scripts/systemd-setup_partitions b/remote/rootfs/rootfs-stage32/data/opt/openslx/scripts/systemd-setup_partitions index cd42ee91..b282a486 100755 --- a/remote/rootfs/rootfs-stage32/data/opt/openslx/scripts/systemd-setup_partitions +++ b/remote/rootfs/rootfs-stage32/data/opt/openslx/scripts/systemd-setup_partitions @@ -13,8 +13,9 @@ # detecting swap and special partitions ############################################################################# -CONFIGPATH="./config" -. $CONFIGPATH + +# read global OpenSLX config +. /opt/openslx/config || { echo "Could not source config!"; exit 23; } # General formatter for the /tmp partition on a local harddisk diskfm () { @@ -88,109 +89,125 @@ mount_temp_fallback () { return 0 } -mount_part() { # $1=mountpoint, $2=partition(/dev/*) - mkdir -p "$1" - if ! mount -t auto -o noexec "${2}" "$1" 2> /dev/null ; then - diskfm "$2" "jfs xfs ext3" || continue - mount -t auto -o noexec "${2}" "$1" || continue +mount_partition() { + local mountpoint="$1" + local partition="$2" + local options="$3" + [[ $options == *persistent* ]] && local persistent="1" + + mkdir -p "$mountpoint" + if ! mount -t auto -o noexec "$partition" "$mountpoint" ; then + if [[ $persistent == 1 ]]; then + fsck "$partition" || return $? + mount -t auto -o noexec "$partition" "$mountpoint" || return $? + else + diskfm "$partition" "jfs xfs ext3" || return $? + mount -t auto -o noexec "$partition" "$mountpoint" || return $? + fi fi - echo -e "${2}\t${1}\tauto\t\tnoauto,noexec\t\t 0 0" >> "/etc/fstab" + echo -e "${partition}\t${mountpoint}\tauto\t\tnoauto,noexec\t\t 0 0" >> "/etc/fstab" } -# default case -if [ -z "$SLX_PARTITION_TABLE" ]; then - SLX_PARTITION_TABLE=' - 44,10G,/tmp - 45,10G,/var/scratch' +read_partitions() { + # create the /etc/disk.partition file with all the partitions and respective id's (MSDOS and GPT) + echo "PARTITION - ID" > "/etc/disk.partition" + for hd in $(cat /proc/partitions | tr -s ' ' | cut -d ' ' -f5 | grep -o -e "[a-z]*$"); do + echo -n "$hd (" >> "/etc/disk.partition" + sfdisk -d /dev/$hd 2>&1 | grep 'GPT' > /dev/null + if [ $? -eq 1 ]; then + echo "MSDOS)" >> "/etc/disk.partition" + fdisk /dev/$hd -l | sed -n "/^\/dev\//p" | tr -d '*' | tr -s ' ' | cut -d ' ' -f1,5 >> "/etc/disk.partition" + else + echo "GPT)" >> "/etc/disk.partition" + for part in $(cat /proc/partitions | tr -s ' ' | cut -d ' ' -f5 | grep -o -e "$hd[0-9][0-9]*$"); do + LINE="/dev/$part " + LINE=${LINE}$(sgdisk /dev/$hd -i ${part:3} | grep 'GUID code' | cut -d ' ' -f4) + echo -e $LINE >> "/etc/disk.partition" + done + fi + done + + echo "Partitions:" + cat "/etc/disk.partition" +} + +# default partitions, if not specifies in config (note: size is irrelevant for setup_partitions) +if [ -z "${SLX_PARTITION_TABLE}" ]; then + SLX_PARTITION_TABLE=' + 44,10G,/tmp + 45,10G,/var/scratch,persistent' fi -declare -A PARTTBL -COUNTER=1 for PARTITION in $SLX_PARTITION_TABLE; do IFS=, set $PARTITION - PARTTBL["$COUNTER/id"]=$1 - PARTTBL["$COUNTER/size"]=$(echo $2 | egrep -o "[0-9]*") - PARTTBL["$COUNTER/mountpoint"]=$3 - if [ -e $4 ]; then - PARTTBL["$COUNTER/bootable"]=0 - else - PARTTBL["$COUNTER/bootable"]=1 - fi - PARTTBL["$COUNTER/persistent"]="no" - COUNTER=$(($COUNTER+1)) -done -unset IFS - - -# create the /etc/disk.partition file with all the partitions and respective id's (MSDOS and GPT) -echo "PARTITION - ID" > "/etc/disk.partition" -for hd in $(cat /proc/partitions | tr -s ' ' | cut -d ' ' -f5 | grep -o -e "[a-z]*$"); do - echo -n "$hd (" >> "/etc/disk.partition" - sfdisk -d /dev/$hd 2>&1 | grep 'GPT' > /dev/null - if [[ $? -eq 1 ]]; then - echo "MSDOS)" >> "/etc/disk.partition" - fdisk /dev/$hd -l | sed -n "/^\/dev\//p" | tr -d '*' | tr -s ' ' | cut -d ' ' -f1,5 >> "/etc/disk.partition" - else - echo "GPT)" >> "/etc/disk.partition" - for part in $(cat /proc/partitions | tr -s ' ' | cut -d ' ' -f5 | grep -o -e "$hd[0-9][0-9]*$"); do - LINE="/dev/$part " - LINE=$LINE$(sgdisk /dev/$hd -i ${part:3} | grep 'GUID code' | cut -d ' ' -f4) - echo -e $LINE >> "/etc/disk.partition" - done - fi -done + id=$1; shift + size=$1; shift + [ -e $1 ] && mountpoint="$1"; shift + [ $# -gt 0 ] && options="$*" -echo "Partitions:" -cat "/etc/disk.partition" -# Check for standard swap partitions and make them available to the system -HAVE_SWAP=no -for swppart in $(grep -e "82$\|0657FD6D-A4AB-43C4-84E5-0933C84B4F4F$" /etc/disk.partition | cut -d ' ' -f1); do - echo -e "$swppart\tswap\t\tswap\t\tdefaults\t 0 0" >> "/etc/fstab" - swapon "$swppart" -p 10 && HAVE_SWAP=yes # low priority, in case we have zram swap, prefer that) -done -# Put detected linux partitions (83) into /etc/fstab with "noauto" -for linuxpart in $(grep -e "83$\|0FC63DAF-8483-4772-8E79-3D69D8477DE4$" /etc/disk.partition | cut -d ' ' -f1); do - mkdir -p "/media/${linuxpart#/dev/*}" - echo -e "${linuxpart}\t/media/${linuxpart#/dev/*}\tauto\t\tnoauto,noexec\t 0 0" >> "/etc/fstab" -done + case $id in + 44) + HAVE_TEMP="no" + TMP_SIZE=$size + for tmppart in $(grep -e "44$\|44000000-0000-0000-0000-000000000000$" /etc/disk.partition | cut -d ' ' -f1); do + if diskfm "$tmppart"; then + # echo "$tmppart is mounted to /mnt/tmp at $(sysup)" >/tmp/tmpready + mount_temp "$mopt" "$tmppart" || continue + echo -e "${tmppart}\t/tmp\t\tauto\t\tnoexec\t 0 0" >> "/etc/fstab" + HAVE_TEMP="yes" + else + echo "formatting failed for some reason" + fi # Made this non-forking, systemd should handle it - 2013-05-28 + done + ;; + 46) + for openslxpart in $(grep -e "46$\|46000000-0000-0000-0000-000000000000$" /etc/disk.partition | cut -d ' ' -f1); do + mkdir -p "/media/${openslxpart#/dev/*}" + #mount -t auto ${openslxpart} /mnt/media/${openslxpart#/dev/*} \n\ + #test -d /mnt/media/${openslxpart#/dev/*}/home && \ + #ln -sf /media/${openslxpart#/dev/*} /var/home + echo -e "${openslxpart}\t/media/${openslxpart#/dev/*}\tauto\t\tnoauto\t\t 0 0" >> "/etc/fstab" + done + ;; + 82) + # Check for standard swap partitions and make them available to the system + HAVE_SWAP=no + for swppart in $(grep -e "82$\|0657FD6D-A4AB-43C4-84E5-0933C84B4F4F$" /etc/disk.partition | cut -d ' ' -f1); do + echo -e "$swppart\tswap\t\tswap\t\tdefaults\t 0 0" >> "/etc/fstab" + swapon "$swppart" -p 10 && HAVE_SWAP=yes # low priority, in case we have zram swap, prefer that) + done + ;; + *) + for hdpartnr in $(grep -e "${id}$\|${id}000000-0000-0000-0000-000000000000$" /etc/disk.partition | cut -d ' ' -f1); do + mount_part "${mountpoint}" $hdpartnr $options + if [ $? -ne 0 ]; then + echo "Mount of partition $hdpartnr on ${mountpoint} failed with exit code: $?" + [ -d "${mountpoint}" ] && rm -r "${mountpoint}" + fi + done + ;; + esac -for openslxpart in $(grep -e "46$\|46000000-0000-0000-0000-000000000000$" /etc/disk.partition | cut -d ' ' -f1); do - mkdir -p "/media/${openslxpart#/dev/*}" - #mount -t auto ${openslxpart} /mnt/media/${openslxpart#/dev/*} \n\ - #test -d /mnt/media/${openslxpart#/dev/*}/home && \ - # ln -sf /media/${openslxpart#/dev/*} /var/home - echo -e "${openslxpart}\t/media/${openslxpart#/dev/*}\tauto\t\tnoauto\t\t 0 0" >> "/etc/fstab" done -HAVE_TEMP="no" -for (( i = 1; i < $COUNTER; i++ )); do - for hdpartnr in $(grep -e ${PARTTBL["$i/id"]}"$\|"${PARTTBL["$i/id"]}"000000-0000-0000-0000-000000000000$" /etc/disk.partition | cut -d ' ' -f1); do - if [ "${PARTTBL["$i/mountpoint"]}" = "/tmp" ]; then - if diskfm "$hdpartnr"; then - # echo "$hdpartnr is mounted to /mnt/tmp at $(sysup)" >/tmp/tmpready - mount_temp "$mopt" "$hdpartnr" || continue - echo -e "${hdpartnr}\t/tmp\t\tauto\t\tnoexec\t 0 0" >> "/etc/fstab" - HAVE_TEMP="yes" - PARTTBL["$i/persistent"]="yes" - else - echo "formatting failed for some reason" - fi # Made this non-forking, systemd should handle it - 2013-05-28 - elif [ "${PARTTBL["$i/id"]}" != "82" ] && [ "${PARTTBL["$i/id"]}" != "83" ] && [ "${PARTTBL["$i/id"]}" != "46" ]; then - mount_part "${PARTTBL["$i/mountpoint"]}" $hdpartnr - PARTTBL["$i/persistent"]="yes" - fi - done - [ "${PARTTBL["$i/persistent"]}" = "no" -a -d "${PARTTBL["$i/mountpoint"]}" ] && rm -f "${PARTTBL["$i/mountpoint"]}" +#Put detected linux partitions (83) into /etc/fstab with "noauto" +for linuxpart in $(grep -e "83$\|0FC63DAF-8483-4772-8E79-3D69D8477DE4$" /etc/disk.partition | cut -d ' ' -f1); do + mountpoint="/media" + mkdir -p "${mountpoint}/${linuxpart#/dev/*}" + echo -e "${linuxpart}\t${mountpoint}/${linuxpart#/dev/*}\tauto\t\tnoauto,noexec\t 0 0" >> "/etc/fstab" done mount -a + # Make huge tmpfs if nothing could be mounted for /tmp if [ "$HAVE_TEMP" = "no" ]; then - mount_temp -t tmpfs -o size=20G none - slxlog "partition-temp" "Running /tmp on tmpfs only!" "/etc/disk.partition" + mount_temp -t tmpfs -o size=${TMP_SIZE} none + slxlog "partition-temp" "Running /tmp on tmpfs only!" "/etc/disk.partition" fi + if [ "$HAVE_SWAP" = "no" ]; then slxlog "partition-swap" "Have no (formatted) swap partition, using zram swap only!" "/etc/disk.partition" fi -exit 0 \ No newline at end of file + +exit 0 -- cgit v1.2.3-55-g7522