Well, I felt unprepared to do it and had hope that somebody will fix it for me
The shell script syntax is a
nightmare for me.
But this did not happen, so today I ..
tried. The boot process is somwhat unclear to me.
I decided to keep the mount points under /mnt, just modifying their names. To do so, I need to find where the partitions get mounted by init.
I found this line in linuxrc:
Code: Select all
...
# Create /etc/fstab and mount devices:
fstab
.........................
So i went to line 44 "# Device Functions" and modified the
fstab() function, assuming that this will do what's needed. But it didn't - I ended with probably "properly" created
fstab,
mtab but the folders under /mnt were not present and instead the old device-named folders appeared. The partitions were mounted, but not at /mnt. They left mounted at
/mnt/live/mnt/
So probably i need to rewrite more functions, but I don't know which. The modified
fstab() (w lots ot echo" DBG:...) so far looks like this:
Code: Select all
fstab() { rm -f /tmp/devices
param nocd || for x in /dev/sr*; do blkid $x >>/tmp/devices; done
param nohd || blkid | egrep -v '/dev/sr|/dev/loop|/dev/mapper' >>/tmp/devices
dev=`egrep -v 'TYPE="sw|TYPE="LVM|TYPE=".*_raid_member"' /tmp/devices 2>/dev/null | cut -d: -f1 | cut -d/ -f3 | sort | uniq`
cat > /etc/fstab << EOF
# Do not edit this file as fstab is recreated automatically during every boot.
# Please use /etc/rc.d/rc.local or sysvinit scripts if you want to mount/unmount
# drive, filesystem or network share.
# System mounts:
aufs / aufs defaults 0 0
proc /proc proc defaults 0 0
sysfs /sys sysfs defaults 0 0
devtmpfs /dev devtmpfs defaults 0 0
devpts /dev/pts devpts rw,mode=0620,gid=5 0 0
# Device partitions:
EOF
# set mountpoint names:
mpts="" #initial
for d in $dev; do
bi=`blkid /dev/$d` # cache blkid output
r=`echo $bi | cut -f2 -d":" | cut -f1 -d"=" | sed 's/[[:space:]]//g'` # has label ?
is_cd=`echo $d | egrep -o 'sr|scd|cdrom'`
echo "DBG: r=$r bi=$bi"
if [ "$r" = "LABEL" ] && [ "$is_cd" = "" ]; then
#m=`echo $bi | egrep -o ' LABEL=[^ ]+' | cut -d'"' -f2` # take the label
m=`echo $bi |sed 's/^.*LABEL="//' | cut -d'"' -f1 |sed 's/[[:space:]]/_/g' ` #take the label, replace spaces w underline
echo "The device $d is not a cdrom, has label $m"
else
echo "The device $d left $d "
m=$d
fi
# test if the new mountpoint is unique, fix if not
r=`echo $mpts | egrep -o "$m" | sed 's/[[:space:]]//g'`; # sed here used to trim any spaces
#r="sda1"; # to test
i=0
nm=$m; # we preserve the orig. value in m
while [ "$r" != "" ]
do
i=$(($i+1)) #i++
nm=$m"$i"
#echo "new m=$nm"
r=`echo $mpts | egrep -o "$nm" | sed 's/[[:space:]]//g'`; #test again
done
echo "DBG_l: I want to mount dev=$d at /mnt/$nm "
if [ "$mpts" = "" ]; then mpts=$nm; else mpts=$mpts" $nm"; fi # add the generated mount point
echo 'DBG_l: mpts='$mpts
done
echo "DBG: dev=$d, mpts=$mpts"
for d in $dev; do
fs=`grep -w /dev/$d /tmp/devices | egrep -o ' TYPE=[^ ]+' | cut -d'"' -f2`
mp=`echo $mpts | cut -d' ' -f1` # get the first word (mountpoint)
echo "DBG: Trying to mount /dev/$d at /mnt/$mp fstype=$fs"
[ $fs = "vfat" ] && echo "/dev/$d /mnt/$mp vfat $MOPT,umask=0,check=s,utf8 0 0" >>/etc/fstab || echo "/dev/$d /mnt/$mp $fs $MOPT 0 0" >>/etc/fstab
if [ ! -d /mnt/$mp ]; then
mkdir /mnt/$mp
if [ $fs = "ntfs" ]; then
ntfs-3g /dev/$d /mnt/$mp -o $MOPT 2>/dev/null || { sed -i "/$mp /d" /etc/fstab; rmdir /mnt/$mp; } # on failure removes the mountpoint from fstab and /mnt/
else
mount -n /mnt/$mp 2>/dev/null || { modprobe $fs 2>/dev/null && mount -n /mnt/$mp 2>/dev/null || { sed -i "/$mp /d" /etc/fstab; rmdir /mnt/$mp; }; }
fi
fi
if [ ! -d /mnt/$mp ]; then
echo "DBG: mount /dev/$d at /mnt/$mp failed, cmd='mount -n /mnt/$mp'"
else
echo "DBG: mount /dev/$d at /mnt/$mp succeeded"
fi
mpts=`echo $mpts | sed 's/[^ ]* //'` # remove the first mountpoint ( word ) (everything before the first space)
done
if [ -z "`egrep -o " noswap( |\$)" /proc/cmdline`" -a -e /tmp/devices ]; then
echo -e "\n# Swap partitions:" >>/etc/fstab
for x in `grep 'TYPE="swap"' /tmp/devices | cut -d: -f1`; do echo "$x none swap sw,pri=1 0 0" >>/etc/fstab; done
fi }
What it does ? It tries to get the partition labels, then calculates the new mountpoint names where labels are present. Where the labels absent, it
retains the device name as mountpoint. It avoids duplicate mountpoint names (when 2 names match it appends a number to the name). The
spaces within the label names are converted to underlines. This may improve later.