WikiDevi.Wi-Cat.RU:DD-WRT/Slim samba2

Slim Samba2 for USB
Based on the work of patwood I have made a quick-and-easy and slimmed down version of Optware Samba2. I call it "Slim Samba2 for USB", and it is only made for Broadcom MIPS-based CPU routers. This includes most Asus, Linksys, and Buffalo routers supported by dd-wrt. For other CPUs you need the full Optware Samba packages.

Out-of-the-box Slim Samba2 (v.5) has been designed to run on a USB drive with one or three partitions.

Slim Samba it self is installed and run from the first partition (/mnt) on the USB drive, as this works well with the USB and NAS settings in the web-GUI.

User data is ment to be in the folder /mnt/data. You may however adjust this to your hearts content, and smb.conf has been prepared such that you can just unmark (remove #) from several of the lines in smb.conf - but for standard file server, SlimSamba should work fine out-of-the-box

With Slim Samba v.5 the use of a three partition drive will automatically be detected, and /mnt/data will automatically be mounted on (pointing to) the third partition.

Prepare for slim-samba-usb

 * Tested with Eko version V24TNG-svn11218.
 * For Mini_usb_ftp version your partition must be ext3
 * For Mega version your partition can be either ext2 or ext3

Enable USB in web-GUI and set
 * enable USB1.1, USB2 as needed for your router and usb drive
 * enable "USB Storage Support"
 * enable "ext2 / ext3 File System Support"
 * enable "Automatic Drive Mount"
 * set "Run-on-mount Script Name" to /mnt/samba2.usb
 * set "Disk Mount Point" /mnt

For good meassure you should also set shutdown commands in web-GUI
 * tab: Administration -> tab: Commands -> text field: Commands ->
 * write this line

sh /opt/usr/sbin/unplug.usb or sh /tmp/unplug.usb
 * Click "Save Shutdown"

In Services -> NAS -> ProFTPD
 * Anonymous Login can be enabled if desired
 * and "Anonymous Home Sub-directory" can be set to /data/public

Partition and format your USB drive
You need to first partition and format your drive
 * This can be done by attaching the drive to an other system like:
 * a PC running linux (maybe from a LiveCD)
 * a Windows PC using a partitioning tool
 * a windows PC with VirtualBox running a Linux guest system
 * Some have been able to use their iPod.

For use with Slim Samba the first partition on your drive needs to be ext2 or ext3. Minimum size is 5Mb.

For use with Eko Mini_usb_ftp, the first partition needs to to be ext3, for use with Mega builds, the first partition can be formatted as ext2 or ext3

You do not need more than one partition on you USB drive to use Slim Samba2, but you may also use it with a three partition drive, as is common place when used with a HD.

For large HD drives that you "permanently" attach to your router you may want to create three partitions:
 * one: for optware packages - make it 32Mb - 2Gb - use ext2/3 as the format
 * two: for swap file - make it 16-256 MB - format it as linux swap file
 * three: for data space - make it fit the rest of the disk - use ext2/3 or FAT32 as the format

Slim Samba2 does not use the swap partition, but if you partition your drive with the three mentioned partitions, you are well prepared for expansion or upgrading you systemdrive with more Optware packages, or moving up to use HDsamba2.

Slim Samba2 does not automatically recognize and mount FAT32 partitions. If you choose to format your data partition as FAT32, then after installing Slim Samba2, you need to follow the directions in section How to mount a FAT partition.

Filesystem to use that works
I initially format my usb hard drive as Fat32 because I wanted to be able to use the drive on any computer. I couldn't get Slim samba2 to run. Here is a link to the exact same issue I was having.

/opt/etc/init.d/S80samba: line 18: /opt/sbin/smbd: not found

I messed with this for a while and just decided to go with what was recommended in the Slim samba2 tutorial i.e. etx3/swap/ext3 as defined here How to - Format and Partition External Storage Device. It works great.

Ericmagaha 15:13, 31 March 2010 (CEST)

Install SlimSamba2 on a USB drive using your router and a terminal
In a (putty) terminal type in these commands cd /mnt wget http://www.3iii.dk/linux/dd-wrt/slim-samba2-usb.tar.gz tar xvzf slim-samba2-usb.tar.gz  ./samba2.usb

And you should be up and running!

If you get an error like this, it probably means that your router is not using a Broadcom CPU and you need to use the full Optware Samba packages

Starting smbd: /opt/sbin/smbd: line 15: syntax error: "(" unexpected Starting nmbd: /opt/sbin/nmbd: line 1: syntax error: "(" unexpected

USB is designed to be hot-plug, and Slim Samba2 will automatically start next time you boot the router, or next time you plug-in the USB drive.

Before you un-plug the USB drive from a live router you should however run the command: sh /tmp/unplug.usb Just to make sure all files on your USB drive are closed properly.

Install slim-samba-usb on a USB drive using a Linux PC
a) Download the file http://www.3iii.dk/linux/dd-wrt/slim-samba2-usb.tar.gz

b) Unpack the files from slim-samba2-usb.tar.gz to the USB drive

c) You should minimum see the following in the root of your USB drive

folder: data folder: opt file:     samba.usb

d) You may want to change the (Windows/SMB) workgroup name in /USBdrive/opt/etc/samba/smb.conf (see below for guide)

e) When you have set the web-GUI of you router, un-mount the USB drive from you Linux PC and plug it into your dd-wrt box. And you should be up and running.

Allowing write access for any OS i.e. Mac OSX, Windows
I used Slim_samba2 and formatted my drive as ext3/swap/ext3 i.e. Optware/Swapfile/Data as outlined How to - Format and Partition External Storage Device. Initially I had readonly access to the drive from Windows and Mac. Had to change the permissions of the Data partition i.e. /mnt/data. It defaulted to 700 i.e. rwx--. I used chmod and changed it to 777 i.e. rwxrwxrwx. I could then write to the Data partition from Windows (Windows explorer) and Mac (Finder).

Ericmagaha 15:13, 31 March 2010 (CEST)

Customise your slim-samba2-usb Windows Workgroup name
As of Slim Samba v.5 you can use the command: samba2.cwg or  samba2.changeworkgroup to change the workgroup name of your Samba2 Share.

For informational purposes there is still (below) the manual guide to change the workgroup name of a Samba2 share.

You may have to edit /opt/etc/samba/smb.conf to fit your Windows Workgroup name, or you could just use the default Windows workgroup name "workgroup" on your windows pc's.

To edit the smb.conf file in a terminal with the vi editor do the following

vi /opt/etc/samba/smb.conf

Find the line: workgroup=workgroup and change it to your windows workgroup name If you workgroup name is "valhalla" you would change the line to: workgroup=valhalla


 * Note: vi hints:
 * When you open vi it is in command mode (you see a - at the bottom left of your screen)
 * press i to enter edit mode (you see an I at the bottom left of your screen)
 * press ESC to exit edit mode and enter command mode
 * When in command mode
 * press :wq ENTER to give the commands write and quit
 * press :q! ENTER to quit without saving changes
 * press :q ENTER to quit if you have made no changes
 * When you understand that vi has the two modes of operation, command mode and edit mode, and how :easy it is to switch between the two, vi can actually become one of your best Linux friends.
 * to delete a line - be in command mode - and press dd
 * google "linux vi command" for more vi commands


 * Note: You could also use WinSCP to locate and edit script files, as an editor is included in WinSCP.

How to access Samba shared drives from windows
If your pc is in the same workgroup as Samba (default: workgroup) then you just go to Network / Neighbourhood in Windows Explorer and a new machine (default: DD-WRT) should appear.

You can also go directly to the Samba server in Windows by typing the IP number of your router in the address bar of Windows Explorer like: \\192.168.1.1

You should see data and printers folder

If your routers LAN IP does not begin with 192.168.
As of Slim Samba v.5 you no longer need to manually update the smb.conf file with your dd-wrt IP settings. Now, when you start Slim Samba2 (happens on boot or plug-in of usb drive) the samba2.ip script is automatically activated, and will automatically copy the IP settings of the dd-wrt NVRAM settings to the smb.conf file.

For informational purposes there is still (below) the manual guide to change IP settings in the smb.conf file.

If you use an IP range for your network that is not in the 192.168.x.x range, you need to edit /opt/etc/samba/smb.conf line hosts allow = to include your IP range.

If you for example use 10.0.0.x for your local network, you could change the line to be

hosts allow = 192.168. 10.0.0. 127.

or simply

hosts allow = 10.0.0. 127.

How to mount a FAT partition
If your data partition is formatted as FAT, you need to manually make the right mount command in /mnt/samba2.usb. The command is something along these lines: mount -o rw,umask=0000 /dev/discs/disc0/part3 /mnt/data
 * See example in this forum thread

Did everything go right
You can use one or more of the following commands to see if your slim-samba2-usb install went well

Check the active processes using the ps command :~# ps PID USER       VSZ STAT COMMAND ~ snip ~ 163 root     1792 S    proftpd: (accepting connections) ~ snip ~ 224 root     3588 S    /opt/sbin/smbd -D 231 root     2280 S    /opt/sbin/nmbd -D ~ snip ~

Check to see if /opt has been mounted using the ls, df or mount commands :~# ls /opt etc  lib   sbin  var

/dev/discs/disc0/part1 241116     10138    218530   4% /mnt /dev/discs/disc0/part1 241116     10138    218530   4% /opt

rootfs on / type rootfs (rw) /dev/root on / type squashfs (ro) none on /dev type devfs (rw) proc on /proc type proc (rw) ramfs on /tmp type ramfs (rw) /dev/discs/disc0/part1 on /mnt type ext3 (rw) /dev/discs/disc0/part1 on /opt type ext3 (rw)

Is /mnt/data pointing to the right place
If you use a USB drive with one partition, then /mnt/data will not show in the df or mount commands. If you have however made three partitions on your USB drive then /mnt/data should show up in the df or mount commands as follows:

Check to see if /mnt/data has been mounted correctly using the ls, df or mount commands :~# ls /mnt/data lost+found

/dev/discs/disc0/part1 241116     10138    218530   4% /mnt /dev/discs/disc0/part1 241116     10138    218530   4% /opt /dev/discs/disc0/part3 640388     16896    590964   3% /mnt/data

rootfs on / type rootfs (rw) /dev/root on / type squashfs (ro) none on /dev type devfs (rw) proc on /proc type proc (rw) ramfs on /tmp type ramfs (rw) /dev/discs/disc0/part1 on /mnt type ext3 (rw) /dev/discs/disc0/part1 on /opt type ext3 (rw) /dev/discs/disc0/part3 on /mnt/data type ext3 (rw)

A comment about PATH, LD_LIBRARY_PATH and a custom profile
So long as you use dd-wrt EKO svn11218 or newer, there should be no need to adjust anyting in the /etc/profile, as the new default profile is optimised to work better with Optware based packages.

Use command set to see how PATH and LD_LIBRARY_PATH already include /opt... paths

Why is /opt placed on /mnt/opt
With the basic dd-wrt install, the /opt folder is pointing to a read-only (ro) area. To be able to actually install Optware packages into /opt, it needs to first be pointed to a location that is read-write-able (rw).

One could choose to point /opt to the root of a partition, like mounting /opt on partition1 of a drive.

For Slim Samba2 (and for flexibility and better future expansion) it has however been decided that /mnt points to the root of the first partition, then a /mnt/opt folder is created on /mnt, and the root /opt is mounted on (pointed to) /mnt/opt. That may seem a bit confusing, but read-on.

By mounting /opt on a spot on a rw drive, /opt is made read-write-able.

After mounting /opt on /mnt/opt, and you examine the content of /opt and /mnt/opt, you will discover that they by now have the same content.

This is the Linux trick of changing /opt from being ro in the basic dd-wrt install, to now being rw and useable to install Optware packages into.

FYI, /opt could also have been mounted on (pointed to) /jffs/opt, /mmc/opt (SD card), or a folder on a CIFS drive. Because of the flexibility of the Linux tree-structure, the Optware packages will not know the difference!

Links

 * USB Storage wiki page - Links section on USB Storage wiki page
 * Optware wiki page
 * HDsamba2 wiki page