WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: A best way to mount all mountable device automatically?  (Read 4032 times)

Offline littlebat

  • Newbie
  • *
  • Posts: 25
A best way to mount all mountable device automatically?
« on: December 17, 2011, 03:32:26 AM »
I try to customize file "/usr/sbin/rebuildfstab" and add "mount -a" into "/opt/bootlocal.sh" to mount all mountable device  automatically. So, I changed 'OPTIONS="noauto,users,exec"' to 'OPTIONS="users,exec"'. But, when test the customized tinycore on an ASUS P5QL PRO motherboard machine, it stop booting because no floppy device or no media in a MARVELL PATA COMBO R/W DVD.

I found a way to only mount those device can be determined its file system by "blkid"(/usr/sbin/fstype). I added some code into /usr/sbin/rebuildfstab as below:
Quote
  DEVNAME=`echo "$i" | awk 'BEGIN{FS="/"}{print $(NF-1)}'`
  DEVMAJOR="$(cat $i|cut -f1 -d:)"
 
# Check file system for auto mounting 
  FSTYPE="$(fstype "/dev/$DEVNAME")"
  if [ -z "$FSTYPE" ]; then 
    OPTIONS="noauto,users,exec"
  else
    OPTIONS="users,exec"
  fi 

Is there a better way to do this job? Is there any problem in my code?

Thanks.

Offline bmarkus

  • Administrator
  • Hero Member
  • *****
  • Posts: 7183
    • My Community Forum
Re: A best way to mount all mountable device automatically?
« Reply #1 on: December 17, 2011, 04:49:28 AM »
You can use udev. Search Forum, it was discussed.
Béla
Ham Radio callsign: HA5DI

"Amateur Radio: The First Technology-Based Social Network."

Offline coreplayer2

  • Hero Member
  • *****
  • Posts: 3020
Re: A best way to mount all mountable device automatically?
« Reply #2 on: December 17, 2011, 10:23:03 AM »
I just searched for "udev"  and was surprised to find only one hit, this thread.


 :-\

Not believing the search results I tried a second time, Voila!!  so many hits this time round, now to find the one where ths topic has been discussed before..
« Last Edit: December 17, 2011, 10:25:41 AM by coreplayer2 »

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11560
Re: A best way to mount all mountable device automatically?
« Reply #3 on: December 17, 2011, 10:34:45 AM »
Hi coreplayer2
Try changing the  By user  field on the search page from * to gutmensch when searching for udev.
I seem to remember he provided an in depth discussion on the subject somewhere.

Offline coreplayer2

  • Hero Member
  • *****
  • Posts: 3020
Re: A best way to mount all mountable device automatically?
« Reply #4 on: December 17, 2011, 11:11:26 AM »
Not sure if this thread was the one referred too http://forum.tinycorelinux.net/index.php/topic,9037.msg49256.html#msg49256


Thanks Rich,  wait USER field?  that must be an advanced feature or something maybe from the menu...?

However Just realized the issue here, searches from the quick search field above (top right) are not global, ie the quick search only searches the current thread, to search the whole forum db one has to search from the home page or possibly use the search menu

;)
« Last Edit: December 17, 2011, 11:21:47 AM by coreplayer2 »

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11560
Re: A best way to mount all mountable device automatically?
« Reply #5 on: December 17, 2011, 11:25:15 AM »
Hi coreplayer2
Yes, that was the main one, there might  have been others.
Quote
Thanks Rich,  wait USER field?  that must be an advanced feature or something maybe from the menu...?
Look at the top of the page where it says  Home  Help  Search  Moderate .....     and click on search.

Offline coreplayer2

  • Hero Member
  • *****
  • Posts: 3020
Re: A best way to mount all mountable device automatically?
« Reply #6 on: December 17, 2011, 11:48:40 AM »
I've always assumed that the quick search (top right) searches the entire db, only today realized it's searches are relative to the current thread only..

Got it now thanks

Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 11037
Re: A best way to mount all mountable device automatically?
« Reply #7 on: December 18, 2011, 05:21:26 AM »
Your code is fine.
The only barriers that can stop you are the ones you create yourself.

Offline littlebat

  • Newbie
  • *
  • Posts: 25
Re: A best way to mount all mountable device automatically?
« Reply #8 on: December 23, 2011, 08:36:18 AM »
Your code is fine.

I test the code again, when the floppy device doesn't exist, "fstype /dev/fd0" will still cause system stop booting. So, I changed the code as below:
Quote
[ -s "$CDROMSF" ] &&  read CDROMS < "$CDROMSF"

# Delete invalid fstab entries and mount point, force to umount invalid mounting
# Borrowed idea for CDlinux (http://www.cdlinux.info/)
for fstabitems in `grep "$ADDEDBY" /etc/fstab | awk '{print $1"$"$2}'`; do
  FSTABDEV=`echo $fstabitems | cut -d '$' -f1`
  FSTABDIR=`echo $fstabitems | cut -d '$' -f2`
  [ -e $FSTABDEV ] || {
    sed -i "\@^$FSTABDEV @d" /etc/fstab
    /bin/umount -f $FSTABDIR >/dev/null 2>&1
    rmdir $FSTABDIR
  }
done

grep -v "$ADDEDBY" /etc/fstab > "$TMP"


Quote
  DEVNAME=`echo "$i" | awk 'BEGIN{FS="/"}{print $(NF-1)}'`
  DEVMAJOR="$(cat $i|cut -f1 -d:)"

# Check file system for auto mounting 
  FSTYPE=""
  [ "$DEVMAJOR" != 2 ] && FSTYPE="$(fstype "/dev/$DEVNAME")"
  if [ -z "$FSTYPE" ]; then 
    OPTIONS="noauto,users,exec"
  else
    OPTIONS="users,exec"
  fi


Quote
# If another copy tried to run while we were running, rescan.
if [ -e /var/run/rebuildfstab.rescan ]; then
  rm -f /var/run/rebuildfstab.rescan
  exec $0 "$@"
fi

# Mount all mountable devices
/bin/mount -a >/dev/null 2>&1

This can work well on usb disk. But it can't mount a cdrom disc automatically when insert it into cdrom driver, it seems udev rules can't deal with the events about cdrom disc inserting or ejecting.

Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 11037
Re: A best way to mount all mountable device automatically?
« Reply #9 on: December 23, 2011, 09:23:16 AM »
Why would fstype /dev/fd0 be called if the device doesn't exist? Do you have a funny bios?
The only barriers that can stop you are the ones you create yourself.

Offline littlebat

  • Newbie
  • *
  • Posts: 25
Re: A best way to mount all mountable device automatically?
« Reply #10 on: December 23, 2011, 10:28:23 AM »
Why would fstype /dev/fd0 be called if the device doesn't exist? Do you have a funny bios?

Maybe, an ASUS P5QL PRO motherboard machine, has a floppy slot but has no a floppy driver connected. Maybe its BIOS don't disable floppy. I will confirm it next week.

Offline littlebat

  • Newbie
  • *
  • Posts: 25
Re: A best way to mount all mountable device automatically?
« Reply #11 on: December 26, 2011, 10:16:47 AM »
Yes, the floppy option doesn't be disabled in BIOS while the floppy driver doesn't exist.