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.