You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ublinux-init/ublinux/rc.preinit.d/11-partitions

116 lines
4.5 KiB

#!/bin/bash
#
# Initial script for UBLinux
# This script are launching before starting init from initrd script
# Current dir allways must be set to root (/)
# All system path must be relative, except initrd dirs
ENABLED=no
[[ ${ENABLED} == "yes" ]] || exit 0
PATH=.:/:/usr/bin:/usr/local/bin:/usr/local/sbin
DEBUGMODE=no
#. usr/lib/ublinux/scripts/liblinuxlive
. usr/lib/ublinux/functions
. usr/lib/ublinux/default
debug_mode "$0" "$@"
echo $SYSCONF | grep -q ^/ && SYSCONF=.$SYSCONF
SOURCE=${SYSCONF}/config; [ -f "${SOURCE}" ] && . ${SOURCE} 2>/dev/null
SOURCE=${SYSCONF}/mount; [ -f "${SOURCE}" ] && . ${SOURCE} 2>/dev/null
get_name()
{
for b in "" $(seq 2 64) ;do
grep -q " /media/$1$b " etc/fstab || break
done
echo $1$b
}
[ -z "$PARTITIONSMOUNTUID" ] && PARTITIONSMOUNTUID=500
FSCKFLAG=0
[ $(cmdline_parameter fsck) ] && FSCKFLAG=2
#Find and use swap partition. If not, use window$ swapfile.
if [ "$(cmdline_parameter findswap)" ] ;then
sed -i /FINDSWAP/d etc/fstab
debug_log "Find linux native patitions"
FSWAP=$(blkid -t TYPE="swap" -l | awk -F: '{print $1}')
if [ "$FSWAP" ] ;then
echo "$FSWAP none swap defaults 0 0 #FINDSWAP" >> etc/fstab
else
debug_log "Capturing windows swapfile"
FSWAP=$(find_in_computer /pagefile.sys /$UNION/mnt/windows)
if [ "$FSWAP" ] ;then
if [ -f "$FSWAP" ] ;then
mkswap "$FSWAP"
DSWAP=$(dirname $FSWAP)
DEV=$(grep /$UNION/mnt/windows /proc/mounts | awk '{ print $1 }')
DEVTYPE=$(blkid $DEV -s TYPE | awk -F\" '{print $2}' )
if [ "$DSWAP" = "/$UNION/mnt/windows" -a -b "$DEV" ] ;then
DEVOPTS=$(fs_options $DEV fstab),uid=$PARTITIONSMOUNTUID
echo "$DEV /mnt/windows $DEVTYPE $DEVOPTS 0 $FSCKFLAG # FINDSWAP" >>etc/fstab
umount /$UNION/mnt/windows 2>/dev/null
fi
echo "$FSWAP none swap defaults 0 0 # FINDSWAP" | sed s-/$UNION-- >> etc/fstab
fi
fi
fi
fi
#Creating partitions in /etc/fstab
if [ "$TMPFS" == "no" ] ;then
ln -sf /dev/null etc/systemd/system/tmp.mount
fi
if [ "$VARTMPFS" = "no" -a -h var/tmp ] ;then
rm -f var/tmp 2>/dev/null
mkdir -m 1777 var/tmp
elif [ "$VARTMPFS" != "no" -a ! -h var/tmp ] ;then
rm -fr var/tmp 2>/dev/null
ln -s ../tmp var/tmp
fi
grep -q "tmpfs /media tmpfs" etc/fstab || echo "tmpfs /media tmpfs size=1M 0 0 # AutoUpdate" >>etc/fstab
if [ "$PARTITIONSAUTOMOUNT" = "yes" ] ;then
sed -i /PARTITIONSAUTOMOUNT/d etc/fstab
blkid | grep -Ev "loop|/dev/ram" | grep /dev/ | awk -F: '{ print $1 }' | while read a ; do
grep -q "^$a " etc/fstab && continue
if grep -q "^$a " /proc/mounts ;then
grep -m1 "^$a " /proc/mounts | grep /memory | sed s/$/" #PARTITIONSAUTOMOUNT=yes"/ >> etc/fstab
else
DEVTYPE=$(blkid $a | awk -FTYPE=\" '{print $2}'| sed s/\".*// )
if [ "$DEVTYPE" != "" -a "$DEVTYPE" != "swap" -a "$DEVTYPE" != "udf" -a "$DEVTYPE" != "iso9660" ] ;then
DEVLABEL=$( blkid $a | awk -FLABEL=\" '{print $2}'| sed s/\".*// | tr -d [:cntrl:][:space:])
[ -z "$DEVLABEL" ] && DEVLABEL=$(get_name disk)
[ -d media/"$DEVLABEL" ] && DEVLABEL=$(get_name $DEVLABEL)
echo " $PARTITIONSNOMOUNT " | tr ',;' ' ' | grep -q " $DEVLABEL " && continue
DEVOPTS=$(fs_options $a fstab)
[ "$DEVTYPE" = "vfat" -o "$DEVTYPE" = "ntfs" ] && DEVOPTS="$DEVOPTS,uid=$PARTITIONSMOUNTUID"
echo "$a /media/$DEVLABEL $DEVTYPE $DEVOPTS 0 $FSCKFLAG #PARTITIONSAUTOMOUNT=yes" >>etc/fstab
[ -d media/$DEVLABEL ] || mkdir -p media/$DEVLABEL
elif [ "$DEVTYPE" = "swap" ] ;then
grep -q "^$a none swap" etc/fstab || echo "$a none swap defaults 0 0 #PARTITIONSAUTOMOUNT=yes" >>etc/fstab
fi
fi
done
fi
#Enable compcache if it is needed
#[ "$(grep " swap " etc/fstab)$(echo $SERVICESNOSTART | grep compcache)" = "" ] && chroot . chkconfig --add compcache >/dev/null 2<&1
#Exporting partitions
if [ "$PARTITIONSSHARE" = "yes" ];then
for a in $(grep " /media/" etc/fstab | awk '{print $2}' | sed s-/media/--) ;do
grep -q "^/media/$a " etc/exports && continue
echo " $PARTITIONSNOSHARE " | tr ',;' ' ' | grep -q " $a " && continue
echo "/media/$a 192.168.1.0/24(all_squash,anonuid=500,anongid=100,async,secure,no_subtree_check,rw)" >>etc/exports
done
fi
if [ -d /mnt/livemedia/ublinux-data -a ! -d /mnt/livedata ] ;then
ln -sf livemedia mnt/livedata
fi
[ "$MNT_BLOCK" = "yes" ] && chmod 600 /mnt