My ongoing experiences with Ubuntu, and later Mythbuntu, as a media center with MythTV. I'm also using the system for a virtual machine server, a mediawiki server and a general all around home infrastructure base.

Showing posts with label samba. Show all posts
Showing posts with label samba. Show all posts

Sunday, September 28, 2008

Installing Samba on Ubuntu Server

Previously I had installed Samba via the Ubuntu desktop, but now I wanted to do it on Ubuntu server.

First, I installed samba:

apt-get install samba


At the end of the install on my VMWare host system, I got the warning below:

--------- IMPORTANT INFORMATION FOR XINETD USERS ----------
The following line will be added to your /etc/inetd.conf file:

## netbios-ssn stream tcp nowait root /usr/sbin/tcpd /usr/sbin/smbd

If you are indeed using xinetd, you will have to convert the
above into /etc/xinetd.conf format, and add it manually. See
/usr/share/doc/xinetd/README.Debian for more information.
-----------------------------------------------------------


I didn't end up having to do anything special, but wanted to mention it anyways.

Next, I edited /etc/samba/smb.conf to look like the one below. (You'll want to replace "username" with an actual username or list of usernames.)

 
[global]
workgroup = WORKGROUP
server string = %h server (Samba, Ubuntu)
# This will prevent nmbd to search for NetBIOS names through DNS.
dns proxy = no

# This tells Samba to use a separate log file for each machine
# that connects
log file = /var/log/samba/log.%m

# Cap the size of the individual log files (in KiB).
max log size = 1000

# Do something sensible when Samba crashes: mail the admin a backtrace
panic action = /usr/share/samba/panic-action %d

# "security = user" is always a good idea. This will require a Unix account
# in this server for every user accessing the server.
security = user
encrypt passwords = true
passdb backend = tdbsam
obey pam restrictions = yes
invalid users = root
# This option controls how nsuccessful authentication attempts are mapped
# to anonymous connections
map to guest = bad user
socket options = TCP_NODELAY SO_RCVBUF=8192 SO_SNDBUF=8192

[tmp]
comment = tmp
path = /tmp
valid users = username
writable = yes
create mask = 0644
directory mask = 0755


You can validate your smb.conf file by running 'testparm', e.g:
# testparm -s
Load smb config files from /etc/samba/smb.conf
Processing section "[music]"
Loaded services file OK.
...


Restart Samba:
# /etc/init.d/samba reload
* Reloading /etc/samba/smb.conf smbd only
...done.



Add samba users via smbpassword:
smbpasswd -a username


That's it.

BTW, one tidbit, if you get "Error code -6602" on the client, this is caused by a non-existent path in /etc/samba/smb.conf.

Monday, May 14, 2007

Adding a second hard drive

I needed some room for backups, so I bought a Western Digital SAA 300 250GB drive. Physically installing it was fairly easy, just took me a minute to find the open SATA plugs on the motherboard (about 2 inches below the two used ones for the primary drive and the DVD drive).

What follows are the steps to then get the drive operational.

First, looks like the drive was found on boot:

root@casey:/dev# dmesg | grep sdb
[17179574.992000] SCSI device sdb: 488397168 512-byte hdwr sectors (250059 MB)
[17179574.992000] sdb: Write Protect is off
[17179574.992000] sdb: Mode Sense: 00 3a 00 00
[17179574.992000] SCSI device sdb: drive cache: write back
[17179575.000000] SCSI device sdb: 488397168 512-byte hdwr sectors (250059 MB)
[17179575.000000] sdb: Write Protect is off
[17179575.000000] sdb: Mode Sense: 00 3a 00 00
[17179575.000000] SCSI device sdb: drive cache: write back
[17179575.000000] sdb: unknown partition table
[17179575.008000] sd 2:0:0:0: Attached scsi disk sdb
root@casey:/dev# ls -l /dev/sdb
brw-rw---- 1 root disk 8, 16 2007-05-14 20:22 /dev/sdb

Following directions at http://wiki.linuxquestions.org/wiki/Add_a_new_hard_drive, I first ran fdisk to partition the drive (one big partition in this case):

root@casey:/dev# fdisk /dev/sdb

The number of cylinders for this disk is set to 30401.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)

Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-30401, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-30401, default 30401):
Using default value 30401

Command (m for help): p

Disk /dev/sdb: 250.0 GB, 250059350016 bytes
255 heads, 63 sectors/track, 30401 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sdb1 1 30401 244196001 83 Linux

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
Looks like that worked, I now have a partition:
root@casey:/dev# ls -l /dev/sdb*
brw-rw---- 1 root disk 8, 16 2007-05-14 20:29 /dev/sdb
brw-rw---- 1 root disk 8, 17 2007-05-14 20:30 /dev/sdb1
Now to format the drive:
root@casey:/dev# mkfs /dev/sdb1
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
30539776 inodes, 61049000 blocks
3052450 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=62914560
1864 block groups
32768 blocks per group, 32768 fragments per group
16384 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624, 11239424, 20480000, 23887872

Writing inode tables: done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 28 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
Now I made a mount point and mounted the drive:

root@casey:/# mkdir /mnt/backup
root@casey:/# mount /dev/sdb1 /mnt/backup
root@casey:/# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda1 237517496 215500056 9952264 96% /
varrun 484776 160 484616 1% /var/run
varlock 484776 0 484776 0% /var/lock
procbususb 10240 116 10124 2% /proc/bus/usb
udev 10240 116 10124 2% /dev
devshm 484776 0 484776 0% /dev/shm
lrm 484776 17580 467196 4% /lib/modules/2.6.17-11-generic/volatile
/dev/sdb1 240362656 61464 228091392 1% /mnt/backup
Then added it to /etc/fstab so it gets mounted at boot:
root@casey:/# vi /etc/fstab
grep sdb1 /etc/fstab
/dev/sdb1 /mnt/backup ext2 defaults 0 0
Now I added the names of all the local users I wanted to be able to write to the volume to the backup group (in this case, I'll use the names user1 and user2):
root@casey:/# vi /etc/group
root@casey:/# grep backup /etc/group
backup:x:34:user1,user2
And made the backup directory writable by that group:
root@casey:/# chgrp backup /mnt/backup
root@casey:/# chmod 775 /mnt/backup
Now I added the new volume to the Samba-exported filesystems and restarted the samba deamon:
root@casey:/# cp /etc/samba/smb.conf /tmp/smb.conf
root@casey:/# vi /etc/samba/smb.conf
root@casey:/# diff -c /tmp/smb.conf /etc/samba/smb.conf
*** /tmp/smb.conf 2007-05-14 20:45:49.000000000 -0500
--- /etc/samba/smb.conf 2007-05-14 20:46:44.000000000 -0500
***************
*** 305,307 ****
--- 305,314 ----
browsable = yes
public = yes
writable = yes
+
+ [backup]
+ path = /mnt/backup
+ available = yes
+ browsable = yes
+ public = yes
+ writable = yes
+ valid users = user1 user2
+ guest ok = yes
root@casey:/# /etc/init.d/samba restart
* Stopping Samba daemons...
...done.
* Starting Samba daemons...
...done.
That did it. I could now mount the backup partition on my windows system and write to it.

Thursday, March 15, 2007

Adding a New Disc to Itunes via Rythmbox/Samba

Itunes is getting music via Samba from Ubuntu. If you import a new CD on the Umbuntu server, you have to import the new folder on the Samba Share under Itunes for it to appear in the library on the Samba client.

To do this select File/Add Folder to Library. Then find the network share and then the specific new folder that the CD was imported into. Yes, if you have a lot of CDs, this will be slow. It should import quickly once you find it and be immediately available under Itunes.

Saturday, February 3, 2007

Samba Sharing from Ubuntu to Itunes

Ok, so I've gotten my music library onto Ubuntu and am sharing it via Samba. Now I want to remove the MP3 files from my Windows laptop and instead get at them via Samba.

My goal here is to be able to continue using Itunes on my Windows laptop to download podcasts and Itunes store purchases (i.e. the dynamic stuff) while keeping the bulk of the static MP3s on the server. And then sync my iPod from the laptop using a combination of the local and remote content. New CD's will be added by ripping them on the Ubuntu server and then being imported on the laptop (I think they will have to be manually added to the iTunes library on each laptop unfortunately).

First, I mount the Samba voume on my windows box. Then I fire up Itunes and delete all the music I copied over to Ubuntu, moving it to the recycle bin in the process. Yes, this takes a little while. (BTW, for reference I have about 8000 MP3s consuming about 40 GB and am using fairly modern machines.)

Now, I make sure that I don't copy the files from Samba to the local disk. I select Edit/Preferences and then select the Advanced tab and make sure "Copy files to iTunes folder when adding to library" is NOT selected. Then click OK.

Now I select File/Add Folder to Library. Then I find the mounted SAMBA folder and select the Music folder and hit OK.

Now go get lunch while it runs. It took roughly 30 minutes to import (after which you can start playing back music) and then another few hours to Process Album Artwork and Determine Gapless Playback Information (during which time iTunes is very sluggish but functional).

Following this I plugged in my iPod and synched. It took a while for the sync to start, I'm assuming iTunes took a while to confirm everything on the iPod matched the "new" MP3s in the iTunes library.

The one weird things I saw during synch, was that my single purchased song off of iTunes became duplicated in my library with the duplicate pointing to a missing file. I deleted this broken duplicate and all seemed well. *Shrug*

Saturday, January 27, 2007

Ubuntu 6.10 Samba File Sharing

I'm setting up Ubuntu 6.10 (Edgy) on a new PC for use as a general file and MP3 server for a couple Windows XP and MacOS laptops we have. I'm doing this on a Dell n series Optiplex 740, which I mention beause you can order one without windows pre-installed.

As I do this process, I thought I'd share my experiences (and record them so I can remember them) since although Ubuntu is nice, I'm still having to work through a number of non-trivial steps. Hence I created this blog as an experiment to do so. We'll see how it goes...

I'm fairly well versed in Unix and Windows. I'm assuming the reader has some experise, so I'm not going into every little detail, just the stuff I though was non obvious. I strongly recommend the Ubuntu Guide for more information if you're just getting going with Ubuntu.

The first thing I wanted to get going was Samba file sharing so that the various laptops could access server's disk. Starting up Samba turned out to be easy, I selected System/Preferences/Shared Folders and the system informed me I didn't have Samba installed and asked me if I wanted it installed. I replied affirmatively and the install went smooth as silk. I clicked on my home directory (eventually I plan on exporting a number of things, but this works to start with) and Properties. I selected "Windows networks (SMB)" and gave it a share name of my choosing. I unchecked Read only, because I wanted to be able to both read and write from the various laptops.

Back in Shared Folders/General Properties I have MSHOME for a Domain/Workgroup (this seems to be some Windows default name). WINS server was unchecked and the WINS server text field was blank.

Click Close and all seemed well. I was able to see the share from my various laptops, but not able to authenticate to actually mount it. Turns out the way Samba is configured by default, you have to add users to the Samba user database, e.g. launch Applications/Terminal and type:

sudo smbpasswd -L -a username
sudo smbpasswd -L -e username

Replace username with a username of your choosing. It needs to be the same for both commands. In my case the chosen username matched my Unix/Ubuntu username - I think it's ok for the default Samba configure if it doesn't but I haven't tested it yet (see my subsequent notes about smb.conf).

After being asked for the system password, you'll be asked to create a password for the Samba username (this is in response to the first command, the second command just activates the account and doesn't prompt for anything). BTW, I usually don't type sudo for each command, I launch a root shell with "sudo -s", I suspect as I go along I may forget this and leave off sudo.

Then using that username and password I was able to mount the filesystem on my various laptops.

BTW, looking at the /etc/samba/smb.conf file it looks like there are various options to try and keep the Samba and Unix/Ubuntu passwords in sync, including options to force Sambe usernames to have a corresponding Unix username (which seems to be off by default). I haven't played with any at this time and am using the default smb.conf file.