Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
USB FlashDrive Mounting under sdx1
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
hongkongblue2
n00b
n00b


Joined: 06 Apr 2005
Posts: 64
Location: Hong Kong, China

PostPosted: Tue May 24, 2005 7:53 am    Post subject: USB FlashDrive Mounting under sdx1 Reply with quote

Searching the forums recently I found this excellent advice from 2003 at "forums.gentoo.org/viewtopic-t-118474-highlight-retain+dev.html". There are many many many ways to accomplish this goal - this is just one noob way of doing it. Refer to the original post if you find this confusing!

You'll need: A Functioning coldplugged usb enabled system (/sys, UDEV with hotplug + Coldplug installed. Coldplug daemon run from boot runlevel)


#### HOWTO MAKE SURE YOUR FLASHDRIVE MOUNTS PROPERLY WITH THE CORRECT SDx(n) ADDRESS ####


[A] Get Information about your usb device: (user=root)


Code1: #tail -f /var/log/messages ## Plug the usb device in and retrieve the correct sdx (i.e., sde)

Code2: #cfdisk /dev/sdx ## Check what partitions are present on the sdx device (i.e., sde1)

Code3: #cat /sys/block/sdx/device/model ## Write down the model name exactly as displayed.
or
Code3: #lsusb ## Use the model name exactly as displayed next to the header 'model'.


[B] Create symlinks from the usb device to the desired sdxn dev entry (user=root)


Code4: #mkdir /etc/hotplug.d/block

Code5: #cat /etc/hotplug/block/make-symlinks.hotplug (sdx = your device)

Quote:
#!/bin/bash

CONFIG="/etc/hotplug.d/block/symlinks.rc"

touch /dev/sdx

get_symlink () {
local target_model=$(echo $1)
local link=""

link=$(cat "${CONFIG}" | grep -i "${target_model}" | awk '{ print $1 }')

if test -n "${link}" ; then
echo "${link}"
return 0
else
return 1
fi
}

wait_for_file () {
local count=0
while test $count -lt 10 && ! test -r "$1" ; do
sleep 1
count=$((count + 1))
done
test $count -eq 10 && return 1
return 0
}

test "${1}" = "block" || exit 1 # (Not called for block hotplug)

partition=$(echo "${DEVPATH}" | awk -F\/ '{ print $4 }')
test -n "${partition}" || exit 2 # (Invalid $DEVPATH; should be /block/sd?/sd??)

device=$(echo "${DEVPATH}" | awk -F\/ '{ print $3 }')
test -n "${device}" || exit 2

model_file="/sys/block/${device}/device/model"

wait_for_file "${model_file}"
test -r "${model_file}" || exit 3 # (Could not read model)

model=$(< ${model_file})
test -n "${model}" || exit 3

link=$(get_symlink "${model}")
test -n "${link}" || exit 4 # (Could not find link for model)

case "${ACTION}" in
add)
ln -sf "/dev/${partition}" "${link}"
;;
remove)
test -L "${link}" && rm -f "${link}"
;;
esac



C: Create the following rc script to direct hotplug to the newly symlinked device


!! remember: Symlink name = your choice (i.e., flashdrive) ; USB Device name = your device name (i.e., USB2.0FlashDrive) !!

Code:6: #cat /etc/hotplug/block/symlinks.rc

Quote:
dev/flashdrive USB2.0FlashDrive




D: Edit /etc/fstab to use the new symlink


Code7: #cat /etc/fstab

Quote:
/dev/flashdrive /mnt/usb auto noauto,user,exec 0 0



Thus, /dev/flashdrive stays static at /dev/sdxn even if other devices are hotswapped in and out.

Thanks to the original posteriser!
_________________
Gentoo [~x86] GCC-4.1.0 (Beta) : NPTL ONLY (nitro-sources [2.6.12-n5]) : Mobo:915G-intel, HDA Audio-Alsa, 1GB Ram, 4xSATA:SW-RAID@Reiser4, HT-P4 3GHz, 19" LCD.
Back to top
View user's profile Send private message
Maedhros
Bodhisattva
Bodhisattva


Joined: 14 Apr 2004
Posts: 5511
Location: Durham, UK

PostPosted: Wed May 25, 2005 2:53 pm    Post subject: Reply with quote

Thanks for writing this up: I've moved it from Portage & Programming to Documentation, Tips & Tricks.

BTW, you can also do this sort of thing with udev: http://www.gentoo.org/doc/en/udev-guide.xml
_________________
No-one's more important than the earthworm.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum