No Account Yet?

You are not logged in.

Add to: JBookmarks Add to: Facebook Add to: Windows Live Add to: Digg Add to: Del.icoi.us Add to: Reddit Add to: StumbleUpon Add to: Slashdot Add to: Netscape Add to: Furl Add to: Yahoo Add to: Blogmarks Add to: Technorati Add to: Newsvine Add to: Google Information
Mounting and Partitioning HowTo E-mail
Linux HowTo's - Beginner Linux HowTo's
Written by Allen Sanabria   
Friday, 30 May 2008 06:39

I see this question in forums all the time.... How do I mount a file system? How do I create a new partition and a file system? How do I set it to mount automatically? how do I set the permissions on the mount? Well I'm going to do my best here and answer all the questions above.

I'm doing this how to with the screen shots on Linux Mint (based off of Ubuntu), which means I'm using sudo in front of all of my commands instead of being logged in as root, though you can be logged in as root as well

Delete/Create a Partition and Create a File System

I'm going to demonstrate how to delete and create a partition and create a file system using my trusty 4gig USB drive...
If you have a USB drive, testing this will be a cinch :). Make sure there is nothing on there that you want unless it is GONE!!!

You might have to delete the current file system first, if so please follow the directions below.

Delete The Partition
  • Insert your USB drive
  • Run "fdisk -l" as the root user or "sudo fdisk -l" This command will print out your disks and its partitions
  • Now run "fdisk /dev/sdb" (This might be different for you, refer back to the output of "fdisk -l") 
  • Type"p" (This means print)
  • Now delete the partition by typing "d" (this means delete). If you only have 1 partition in there it will choose that one by default
  • Type "p" We are doing this is to verify that the partition is gone
  • Now finally type "w" This means to write the changes you just did
    Here is the screen shot of the steps above..



Create The Partition
  • Now run "fdisk /dev/sdb" (This might be different for you, refer back to the output of "fdisk -l")
  • Type"p" (This means print)
  • Now create the partition by typing "n" (This means create a new partition)
  • Type "P" (P for primary partition)
  • Type "1" for the first partition (You can only choose 1-4 for primary partitions after that it would have to be extended)
  • Now choose the default which is "1". (You are choosing which cylinder to place the beginning of this partition at.)
  • Time to choose the size of your partition or use the default which is the entire size of the disk
    I chose to only use "+1024M" (which is 1G)
  • If you want you can type "p" To print your partition table and see if the partition was created.
  • Finally type "w" (This will commit your changes)
  • Below is the screen shot of the whole process..

 

Create The File System

Now it is time to choose the type of file system you want to create. I chose to use "ext3" file system. (Which is the default on most distributions of late)

  • To create the ext3 file system you will have to run this command...
    Example "mkfs -t ext3 /dev/sdb1"
    Syntax "mkfs -t <File System Type> <Target Partition>"
    Here is the screen shot below..

 

Mounting a File System

Here I will show you how to mount an NTFS File System.

  • Run "fdisk -l" as the root user or "sudo fdisk -l"
    Here is a screen shot of the output
  • From that screen shot you can tell that my NTFS file system is /dev/sda2. Now I want to mount it. First thing you need to do is create a directory where you want to mount your NTFS file system at.
    Example "mkdir /mnt/share"
    Syntax "mkdir <Target Directory>"
  • Now it is time to mount the file system.
    Example "mount -t ntfs /dev/sda2 /mnt/share"
    Syntax
    "mount -t <File System Type> <File System> <Target Directory>"
    This command will mount /dev/sda2 to /mnt/share as Read and Write by default.
    just for sanity purposes, verify that you can write to that directory...
    Example "touch /mnt/share/test"
    Syntax "touch <create empty file at current or target directory>"
  • Now when you run a "df -h"  or "mount" and now you should see your mount at the bottom of the output of either command.
    here is a screen shot of the output of both commands.
  • Now what if you want to mount that NTFS Volume as Read Only??
    First thing you need to do is unmount the volume. You can do this by running this command.
    Example "umount /mnt/share"
    Syntax "umount <Directory where file system is mounted>
    As you can see the "umount" command is to unmount a file system.
    There are quite a few good options to use with umount that we will discuss later. 
  • Now mount the file system using this command..
    Example "mount -t ntfs -o ro /dev/sda2 /mnt/share"
    Syntax "mount -t <File System Type> -o <Permissions> <file system> <Target Directory>

 

Add Mount to Automatically Mount After Every Reboot

In the steps above I showed you how to delete/create a partition, how to create a filesystem, and how to mount/unmount the file system. Now I will show you how to make your system automaticall mount your file system every time. We can do this 2 ways, either using an editor (vi) or by appending the output to /etc/fstab. I will show you how to append ( I do not feel like teaching VI right now ;).

  • Lets show you how to append the output to "/etc/fstab".
    I tried using sudo in front of echo but it did not work so I had to use the root account for the following..
    The Example below will automatically mount /dev/sda2 to /mnt/share using the ntfs file system and mounting as "ro" Read Only.
    You could also use the "rw" which is Read Write
    Example echo "/dev/sda2       /mnt/share    ntfs    ro      0       2" >> /etc/fstab
    Syntax echo "<file system> <mount point>   <type>  <options>       <dump>  <pass>" >> <File To Append To>
    Here is the screen shot below..

Comments
Search RSS
Only registered users can write comments!

3.22 Copyright (C) 2007 Alain Georgette / Copyright (C) 2006 Frantisek Hliva. All rights reserved."

Last Updated ( Friday, 30 May 2008 13:16 )