This blog discusses all the work i have carried out on various subjects of my interest..

Sunday, August 3, 2008

Mounting Devices on Linux

Before accessing a hard disk or any other storage medium in Linux or UNIX they should be mounted. Note that there is no concept of mounting in windows platforms. Mount allows you to merge two file systems. Mounting of file systems are done with mount command.

The figure shows the unix file system before mounting and after mounting.

The Mount command Mount command has many options and hence little complex. But most of the time you will be able to mount file systems easily with few options. Mount command takes following general format.mount -t filesystem_type -o mount_options /dev/device_file /mnt/mount_point

Usually we don't specify t option because kernel can usually identify the file system type by looking at partition table. The o options are also optional.We can unmount a device by it's device file name or by the mount point.#umount /dev/sda#umount /mnt/flash

If you get any error follow steps given earlier.For USB drive, as root user#mount -t vfat /dev/sda1 /mnt/usb

If you get any error follow steps given above. If you still get error saying that /dev/sda is not a valid block device then check whether the disk is partitioned. You can do this with fdisk command.#fdisk -l /dev/sda

If you still find problems restart your hotplug sub system and remove and reinsert the device.#/etc/init.d/hotplug restart

When mounting DOS/Windows partitions first make sure whether it is fat formated or ntfs the following commands can be used.#mount -t vfat /dev/hda1 /mnt/windows#mount -t ntfs /dev/hda5 /mntwinxp

If you want to mount so that all users can read and write, you may want to try:#mount -t vfat -o user,rw,exec,umask=000 /dev/hda1 /mnt/c

“-o user,rw,exec,umask=000” gives every body all the permission to all the files on your partition.

Now attach this to loop back device and format.#losetup /dev/loop0 myblock.img#mkfs -t vfat /dev/loop0

Now we can mount the device by using the file as the device.#mount -o loop myblock.img /mnt/loop

How can you allow a normal user to mount a device?All you have to do is adding an entry to the /etc/fstb file It has the following format.<file> <mount> <type> <options> <dump> <pass>/dev/sda1 /mnt/usb vfat user,rw 0 0

It is stored in /etc/fstab or /etc/mtab. This is a plain text file that stores default mount settings for various file systems. When Linux is booting up, it uses the settings in this file to determine what file systems should be mounted automatically.

Very Cool answer.I'm very happy to girls are join with Linux(Great).Well Done.If you can please refer about SAMBA server and Open LDAP servers.I think it is very help full to improve you're knowledge about file system and authentication.Anyway well done,, keep going, put some more article about Linux.prabathmail@gmail.com