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

Monday, November 9, 2009

/etc/fstab file

Imagine a situation that you have mounted something (e.g. some nfs share) anywhere on your system using the mount command. Everything works fine but if you restart your computer, your folder is not mounted anymore. 

If you would like your system to mount everything on boot, updating /etc/fstab file is the way to go. The file fstab is a plain text configuration file for setting mount points. Fstab is an abbreviation of File System Table. For altering this file you'll need to become root. It should be located in /etc/fstab on all distributions.

If you open your fstab file it should look like this one:

# /etc/fstab: static file system information.
#
# Use 'vol_id --uuid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
#
proc /proc proc defaults 0 0  
/dev/sda1 / ext3 defaults 0 1
/dev/scd0 /media/cdrom0 udf,iso9660 user,noauto,exec,utf8 0 0
/dev/sda5 /win ntfs 0 0

You can see, that the syntax is very simple. Every one line in this file stands for one mounted device. There should always be 6 parameters on every line, divided by one or more spaces.

The first parameter is the device you would like to mount and the second one specifies the mount point (a folder, where the device will be mounted). The third parameter stands for the file system. You may also specify auto, if you wish to let the system guess.

The fourth parameter is for writing parameters. The most important are:

  • noauto - don't connect automatically on startup
  • users - users can access this device
  • codepage - codepage of filenames
  • iocharset - codepage to which the filenames will be converted
  • noexec - don't execute files on this device
  • umask - setting file access rights mask
  • ro - read only
  • rw - read and write.

All values are separated by comma(,). If you don't have any parameters to set write defaults.

The fifth parameter may only be 1 or 0. If you'd like this drive to be backuped by the dump, then set 1, otherwise set 0.

And finally, the sixth parameter marks the order for drive check by the fsck. The root folder / should always be checked first, so set 1. If you don't want your drive to be checked, then write 0. This will disable the check.

You can of course use fstab to mount nfs or samba shares. This is an example of setting nfs share:

10.0.0.1:/sharing /mnt/server nfs rw 0 0

If you have this line in your fstab file, then /sharing folder on 10.0.0.1 will be always mounted to /mnt/server on your local system. If you are using samba, then it is very similar, but you will usually have to set your username and a password.

//10.0.0.1/sharing /mnt/server smbfs username=user,password=pass,rw 0 0

If you are looking for more detailed description, then you may have a look at fstab man page.

Sunday, November 8, 2009

How to use mount

In Windows operating system you have one root folder for device you connect (eg. C:,D:..), but in Linux, or any POSIX system in general, there is always only one root folder /. This root folder is a place, where your main hdd is usually mounted, but if you wish to work with another disk, or any other device, you will have to create a new folder and then mount the device to this folder.

Let's imagine, that you have just connected a flash disk and you would like to have a look at the data in your flash. First you will have to find the device descriptor for your flash. All descriptors are located in /dev folder. Every connected device should have its own descriptor in this directory. All hard drives descriptors are called /dev/hdx, where x is a letter. Your first hdd should be /dev/hda. But you will need to mount the partition, not the drive itself. Partitions are called /dev/hdxy, where x is still the same letter, and y is a number marking the partition. So if you have one partition on disk /dev/hda it should be called /dev/hda1.

There's one small complication with non-IDE drives. These are not called /dev/hdx, but /dev/sdx. The sd stands for "special device". But now, to make things easier, in kernel 2.6.31 and newer, there are no /dev/hdx devices anymore. Every storage device is now called /dev/sdx, no matter, whether it's an IDE device, or not.

If you have connected your flash, you should be shown some message showing the descriptor for your new device. Now imagine your new flash is called /dev/sdc and has one partition called /dev/sdc1, which you would like to mount to /mnt/flash. First thing you will have to do is to make sure, that you have folder /mnt/flash on your system and then mount the flash.

mkdir /mnt/flash
mount /dev/sdc1 /mnt/flash

Now you should be able to view the /mnt/flash directory, where you should see the contents of your flash disk. We have used the mount command for the first time. Its basic syntax is 

mount -t type device dir

 If you don't specify the -t option, as we did, mount will try to decide the type (e.g. filesystem) itself. Now you know how to mount a storage device but mount can do even more interesting things.  You can for example mount a nfs share to your computer.

mount -t nfs 10.0.0.1:/share /mnt/server

 This would mount a share folder located on 10.0.0.1 to our local /mnt/server folder. If your server is running Windows and has a samba share, you can mount it as well.

mount -t smbfs //10.0.0.1/share /mnt/server -o username=user,password=pass

You can see, that there is some difference. You will have to specify your username and your password to make it work.

So now we have something mounted, but you may also want to unmount something. We will use the umount command. Its syntax is really simple. It may look like this

umount /dev/sdc1

If you have troubles, like getting "device is bussy" you may also try this.

umount -l /dev/sdc1

This should work as a workaround. Please note, that if you mount with the mount command it will be mounted only until you restart the system. If you wish your mount to stay mounted even after reboot, you would have to use /etc/fstab file. We will have a look at this next time.

Saturday, November 7, 2009

How to set up Samba server

Imagine, that you have a computer running linux (e.g. home server) and you would like to share some files with your windows computer. Now you have two possibilities. You can either install nfs client on your windows computer, or a samba server on linux. Today we will have a look on how to set up a samba server on your linux system.

First you will need to install the samba itself. This differs a lot according to your distribution, but on debian I would do simply

apt-get install samba

Now, that you have the samba installed on your computer, it's time for the funny part, the configuration. The main configuration file of samba should be /etc/samba/smb.conf. It will be filled with some default data, but I recommend you to delete this file and start writing a new one with your favourite editor.

rm /etc/samba/smb.conf
nano /etc/samba/smb.conf

Now fill your new file with this:


[global]
workgroup = MASLIK.CZ
server string = maslik.cz samba server
browseable = yes
hosts allow = 10.0.0.
security = user
hide dot files = yes

[sharing]
path = /export
browseable = yes
writable = yes

 This is the very basic configuration. You should of course fill your own values to workgroup and hosts allow in the global part. After that part we define all of our shares. I have one folder defined. For windows clients it will be shown as a sharing folder (the [sharing] string manages this), but the real folder shared is /export. You may of course also set writable = no, if you wish to have a read-only folder.

After changing the configuration file you should restart the samba daemons, if you are not planning to restart your computer.

/etc/init.d/samba restart

Now the last step, you have to take is to make a new samba password for any user, that will have access to your samba server. You will do that by this command:

smbpasswd -a user

After entering this command you will be prompted to enter the new password. This would create a password for user user, so fill your own username. Finally you may also like to use chmod to update the access rights to your shared folder.

So I wish you good luck with setting up your server. Samba of course gives us many more possibilities of settings. One of the most important is a printer sharing. We will have a look at that next time.