You are not logged in.

#1 2010-02-24 02:17:24

DeeCodeUh
Member
From: Michigan, USA
Registered: 2007-11-27
Posts: 176

If you use an SD card as your home partition... This may help.

Hello, if you by chance have very limited space on your netbook, and want to use an SD card for say.. your home partition like I do. Then you could use this script I wrote.

#!/bin/bash

. /etc/rc.conf
. /etc/rc.d/functions

#Variables you should change
MNTPNT="/home/coda"
UUID="8d35d9ce-7f16-4fdb-ba8c-aafcdebad05a"
FS="ext4"

#Something that does not change
DEVICE="/dev/disk/by-uuid/$UUID"

case "$1" in
  start)
      stat_busy "Mounting SD card..."
      echo "Waiting for SD card to exist..."
      COUNT=0
      while [ ! -e $DEVICE ]; do
    sleep 1
    ((COUNT++))
    if ((COUNT > 5)); then
        echo "Device does not exist..."
        stat_fail
        exit
    fi
      done
      echo "Card exists!"
      mount $DEVICE $MNTPNT -t $FS
      if cat /proc/mounts | grep -q $MNTPNT; then
    echo "Mounted at $MNTPNT"
    stat_done
      else
    echo "Failed to mount device!"
    stat_fail
      fi
    ;;
  stop)
      stat_busy "Unmounting SD card..."
      umount $DEVICE
      if cat /proc/mounts | grep -q $MNTPNT; then
    echo "Failed to unmount device!"
    stat_fail
      else
    echo "Device has been successfully unmounted."
    stat_done
      fi
    ;;
  restart)
      echo "ummm.... no"
      stat_fail
    ;;
  *)
    echo "usage: $0 {start|stop|restart}"
esac
exit 0

Just put that in your /etc/rc.d/ folder, and then put it in your daemons list in rc.conf right after hal.
I didn't feel that the restart function would be of any use, so I didn't code it.
If you have suggestions of better ways of doing this, please suggest.

Offline

#2 2010-02-24 02:43:09

n0dix
Member
Registered: 2009-09-22
Posts: 956

Re: If you use an SD card as your home partition... This may help.

You can solved your problem with the shell script, great wink
Thanks for the functionality.

Offline

#3 2010-02-24 10:15:37

ichbinesderelch
Member
Registered: 2008-01-17
Posts: 203

Re: If you use an SD card as your home partition... This may help.

whats that script exactly for? for us not so pro ppl wink i have an sd card mounted as my home partition on my netbook and it is working without problems without that script?
does it just check if an sd card is inserted or not, than mount it or unmount it with start/stop?

Last edited by ichbinesderelch (2010-02-24 10:26:17)

Offline

#4 2010-02-24 11:14:07

fukawi2
Ex-Administratorino
From: .vic.au
Registered: 2007-09-28
Posts: 6,224
Website

Re: If you use an SD card as your home partition... This may help.

Maybe I am missing something, but what does this achieve over an entry in /etc/fstab...?

Offline

#5 2010-02-24 12:12:16

Ultraman
Member
Registered: 2009-12-24
Posts: 242

Re: If you use an SD card as your home partition... This may help.

fukawi2 wrote:

Maybe I am missing something, but what does this achieve over an entry in /etc/fstab...?

My thoughts exactly...
I have an entry for an SD card in there. It doesn't hold my home partition, but it could if I wanted to using the same method.

Offline

#6 2010-02-24 12:28:05

DeeCodeUh
Member
From: Michigan, USA
Registered: 2007-11-27
Posts: 176

Re: If you use an SD card as your home partition... This may help.

fukawi2 wrote:

Maybe I am missing something, but what does this achieve over an entry in /etc/fstab...?

Because an entry in fstab tries to mount the SD card too early, before the device exists, and fails.

Offline

#7 2010-02-24 12:42:57

lolilolicon
Member
Registered: 2009-03-05
Posts: 1,722

Re: If you use an SD card as your home partition... This may help.

Why is this supposed to be a daemon?


This silver ladybug at line 28...

Offline

#8 2010-02-24 14:16:26

DeeCodeUh
Member
From: Michigan, USA
Registered: 2007-11-27
Posts: 176

Re: If you use an SD card as your home partition... This may help.

lolilolicon wrote:

Why is this supposed to be a daemon?

What do you think it should be?

Offline

#9 2010-02-24 16:13:23

lolilolicon
Member
Registered: 2009-03-05
Posts: 1,722

Re: If you use an SD card as your home partition... This may help.

Archwiki wrote:

A daemon is a program that runs in the background, waiting for events to occur and offering services.

You script is not this kind of thing; IMO it's "daemon abuse".


This silver ladybug at line 28...

Offline

#10 2010-02-24 17:16:01

ichbinesderelch
Member
Registered: 2008-01-17
Posts: 203

Re: If you use an SD card as your home partition... This may help.

DeeCodeUh wrote:

Because an entry in fstab tries to mount the SD card too early, before the device exists, and fails.

it does? my sd card gets mounted proberly on every boot with an fstab entry!

Offline

#11 2010-02-24 17:31:24

DeeCodeUh
Member
From: Michigan, USA
Registered: 2007-11-27
Posts: 176

Re: If you use an SD card as your home partition... This may help.

Ok, fine.. I will keep things like this to myself. This script is something I need, and I thought other people would like it.

Offline

#12 2010-02-24 17:37:03

Runiq
Member
From: Germany
Registered: 2008-10-29
Posts: 1,053

Re: If you use an SD card as your home partition... This may help.

Maybe you could put it in an rc.* script instead of making it a daemon.

DeeCodeUh wrote:

Ok, fine.. I will keep things like this to myself. This script is something I need, and I thought other people would like it.

Naa, don't sweat it, he didn't mean it like that wink This would be a good candidate for the "Post your handy self-made command line utilities" thread.

Offline

#13 2010-02-24 17:50:29

ichbinesderelch
Member
Registered: 2008-01-17
Posts: 203

Re: If you use an SD card as your home partition... This may help.

DeeCodeUh wrote:

Ok, fine.. I will keep things like this to myself. This script is something I need, and I thought other people would like it.

i guess we all didnt mean to offend you, just asking for the need of it.

Offline

#14 2010-02-24 17:55:24

DeeCodeUh
Member
From: Michigan, USA
Registered: 2007-11-27
Posts: 176

Re: If you use an SD card as your home partition... This may help.

ichbinesderelch wrote:
DeeCodeUh wrote:

Ok, fine.. I will keep things like this to myself. This script is something I need, and I thought other people would like it.

i guess we all didnt mean to offend you, just asking for the need of it.

Not everyone will need it, but some computers like mine have sd card readers that wont be available until very late in the startup process, and a simple entry in fstab wont work. This takes care of it, by waiting up to 5 seconds (usually only takes 1 or 2) for the device to become available, then mounts it. This was a problem I was trying to solve for a while, until I figured that this was the best way in my opinion. Both my friend and I enjoy using this script, as it solves the problem on both of our netbooks.

Offline

#15 2010-02-24 18:06:29

DeeCodeUh
Member
From: Michigan, USA
Registered: 2007-11-27
Posts: 176

Re: If you use an SD card as your home partition... This may help.

Runiq wrote:

Maybe you could put it in an rc.* script instead of making it a daemon.

DeeCodeUh wrote:

Ok, fine.. I will keep things like this to myself. This script is something I need, and I thought other people would like it.

Naa, don't sweat it, he didn't mean it like that wink This would be a good candidate for the "Post your handy self-made command line utilities" thread.

What do you mean rc.* script? How do I do that?

Offline

#16 2010-02-24 22:02:27

fukawi2
Ex-Administratorino
From: .vic.au
Registered: 2007-09-28
Posts: 6,224
Website

Re: If you use an SD card as your home partition... This may help.

DeeCodeUh wrote:

Ok, fine.. I will keep things like this to myself. This script is something I need, and I thought other people would like it.

We didn't mean it like that, just trying to understand the problem you were trying to solve... We didn't know that you have issues with the block device being created too late for fstab smile

Offline

#17 2010-02-24 22:10:00

DeeCodeUh
Member
From: Michigan, USA
Registered: 2007-11-27
Posts: 176

Re: If you use an SD card as your home partition... This may help.

fukawi2 wrote:
DeeCodeUh wrote:

Ok, fine.. I will keep things like this to myself. This script is something I need, and I thought other people would like it.

We didn't mean it like that, just trying to understand the problem you were trying to solve... We didn't know that you have issues with the block device being created too late for fstab smile

It's alright, thanks for clarifying.

Offline

#18 2010-02-25 01:21:51

anonymous_user
Member
Registered: 2009-08-28
Posts: 3,059

Re: If you use an SD card as your home partition... This may help.

DeeCodeUh wrote:
Runiq wrote:

Maybe you could put it in an rc.* script instead of making it a daemon.

DeeCodeUh wrote:

Ok, fine.. I will keep things like this to myself. This script is something I need, and I thought other people would like it.

Naa, don't sweat it, he didn't mean it like that wink This would be a good candidate for the "Post your handy self-made command line utilities" thread.

What do you mean rc.* script? How do I do that?

You could edit the /etc/rc.local and add a line to launch your script.

Offline

Board footer

Powered by FluxBB