I have a Xbox running Gentoo (cooool) to do some p2p downloading, and I set up a Samba server on it to share the files.
The following is to mount the Samba share:check
this post for detailed instructions.
1) Install Samba file system
sudo apt-get install smbfs
2) Make mount point
mkdir /media/xbox
3) Create a password file for the samba share
nano /root/.smbcredentials
And enter the following:
username=sambasuername
password=sambapassword
This file is needed because my Samba server has password.
4) Edit /etc/fstab, add the following (one line)
//xbox/public /media/xbox cifs credentials=/root/.smbcredentials,
iocharset=utf8,
file_mode=0777,dir_mode=0777,
uid=1000,gid=46,noperm,setuids,rw 0 0
Now try
mount /media/xbox
will mount Samba share on my xbox to /media/xbox.
Because I have some utf8 file names on samba share, I have to use cifs. The uid and gid option will actually be ignored by cifs. The uid of mounted files will be the actual uid of that file on the samba server, i.e. my xbox. For example, all my sharing files on the server belong to user 1002, so all files under /media/xbox in my Ubuntu will belong to user 1002.
But 1002 does not exist on my Ubuntu box, and I want only user 1000 have the ownership of the samba share. I am too lazy to find the real solution. I just changed all the sharing files on samba server to a new owner 1000. Like this (executed on xbox):
xbox$chown 1000 /sambaShare/* -R
And of course I have to add user 1000 into my Samba server.
The following is to automatically mount Samba shareMy xbox is not up running all the time, and I want it to be mounted whenever it is running. So I wrote following script. Basically it is a daemon pings xbox every couple seconds, if it finds the xbox is alive, then mount it.
Create a new file /usr/local/sbin/mountxbox.sh as following
(or download it from here
http://www.box.net/public/7m9e432ypt)
#!/bin/bash
#this is a daemon to detect xbox and mount its samba if the
#xbox is running, it assumes /media/xbox is already defined
#in fstab
CHECK_INTERVAL=40 #check interval, in seconds
MOUNT_DIR="/media/xbox"
XBOX_IP="192.168.1.10"
SHUTDOWN_SIGNAL="/tmp/killmountxbox.sh"
while [ 1 ]
do
#quit if was signled to quit
if [ -f $SHUTDOWN_SIGNAL ]
then
#echo remove $SHUTDOWN_SIGNAL from .sh
rm $SHUTDOWN_SIGNAL #remove the file first
break
fi
#check if the dir is already mounted
#grep -c will output number of lines contain MOUNT_DIR
ALREADY_MOUNTED=$(mount|grep -c $MOUNT_DIR)
#check if xbox is alive
if ping -c 1 -q $XBOX_IP &> /dev/null
then
XBOX_ALIVE=1
else
XBOX_ALIVE=0
fi
#do nothing if already mounted
if [ $ALREADY_MOUNTED -gt 0 ]
then
#unmount the share if xbox is not alive
if [ $XBOX_ALIVE -eq 0 ]
then
umount -f $MOUNT_DIR
fi
#echo "already mounted"
sleep $CHECK_INTERVAL
continue
fi
#check if the xbox is open
if [ $XBOX_ALIVE -eq 1 ]
then
#echo "xbox is alive, try to mount"
mount $MOUNT_DIR
fi
sleep $CHECK_INTERVAL
done
And then
chmod +x /usr/local/sbin/mountxbox.sh
To make it executable
Create a start up script /etc/init.d/mountxbox
(or download it from here
http://www.box.net/public/q7jlp0huxk)
### BEGIN INIT INFO
# Provides: mountxbox
# Default-Start: S
# Default-Stop:
# Short-Description: Start or stop auto mount script for /media/xbox
# Description: Starts or stops auto mount script for /media/xbox
### END INIT INFO
#!/bin/bash
#call /usr/local/sbin/mountxbox.sh to start
#a daemon to auto mount /media/xbox
CMMD_PATH="/usr/local/sbin/mountxbox.sh"
SHUTDOWN_SIGNAL="/tmp/killmountxbox.sh"
ACTION="$1"
case "$ACTION" in
start)
if [ -f $SHUTDOWN_SIGNAL ]
then
echo remove $SHUTDOWN_SIGNAL
rm $SHUTDOWN_SIGNAL
sleep 1
fi
$CMMD_PATH 2>&1 &
;;
stop)
touch $SHUTDOWN_SIGNAL
;;
*)
esac
exit 0
And
chmod +x /etc/init.d/mountxbox
to make it executable.
And make a link
ln -s /etc/init.d/mountxbox /etc/rcS.d/mountxbox
This should start it up when boot. (I actually used Boot-up Manager, so never tested the link command, but it should work)
Labels: Install/Setup