Monday, 3 October 2011

Mount a partition during startup

JUMP TO THE EXAMPLE if you are not interested in the details.
    • Enter superuser mode:
      1. Open a Terminal window.
      2. Type "sudo su" - This will give you administrative privileges for all commands entered here after.
    •  Determine which partition you want to mount:
      1. Type "fdisk -l" - This will show the available partitions.
      2. Make a note of the partition name (Something like /dev/sdxx)
               Eg: /dev/sda
    • Create a mount directory and test if you can mount the partition: 
      1. Type "mkdir dir-name" to create a new directory.]
      2. Type the command:
                    mount -t fs-type device-name dir-name
        Where,
                fs-type: File system type (ext2, ext3, ext4, ntfs, vfat, etc.)
                device-name: Device name (/dev/sdxx), displayed by "fdisk -l"
                dir-name: The new directory created above
      3. Check if the partition is mounted using the "df"  command. If it is mounted you will see the partition and the directory name in the list.
                   Eg: mkdir /home/myname/d-drive
                          mount -t ntfs /dev/sda6 /home/myname/d-drive
                          df
      • Unmount the partiton:
        •  Type the command:
                      umount dir-name
          Where,
                  dir-name: Mount directory
                   Eg: umount /home/myname/d-drive
      • Modify "/etc/fstab"
        1. Type "gedit /etc/fstab &" to open /etc/fstab in an editor (On Xubuntu: "mousepad /etc/fstab &"). The "&" runs this as a new process in the background.
        2. Add an entry in this format:
                device-name dir-name fs-type rw 0 0
          Where,
                  device-name: Device name (/dev/sdxx), displayed by "fdisk -l"
                  dir-name: Mount directory
                  fs-type: File system type (ext2, ext3, ext4, ntfs, etc.)        
        3. Save the file, but don't close it.
        4. Go back to the terminal and type "mount -a". This will mount the partition. 
        5. Check if the partition is mounted using the "df"  command. If it is mounted you will see the partition and the directory name in the list. If you don't see it, then something is wrong, undo the changes in the file and try again)
        6. Close the file     
                   Eg: gedit /etc/fstab &
                          Add
                                     /dev/sda6 /home/myname/d-drive ntfs rw 0 0
                          Save the file
                          Go back to the terminal and type:
                                     mount -a
                                     df
      • Grant read/write access to all users:
        •  Type the command:
                      chmod 777 dir-name
          Where,
                  dir-name: Mount directory
                   Eg: chmod 777 /home/myname/d-drive
                         
      • Exit from superuser mode:
        1. Enter "exit" or press <CTRL>D.
        2. Close the terminal window.
      • Reboot

    EXAMPLE:
    To mount /dev/sda6 on a directory "d-drive" under "/home/myname/":
    1. Open a Terminal window.
    2. sudo su - Enter supervisor mode.
    3. fdisk -l - Make sure the partition /dev/sda6 exists
    4. mkdir /home/myname/d-drive - Create the mount directory
    5. mount -t <fstype> /dev/sda6 /home/myname/d-drive - Mount the partition (the -t <fstype> is optional and depends on the file system type)
      Eg:
          To mount ext4: mount -t ext4 /dev/sda6 /home/myname/d-drive
          To mount ntfs: mount -t ntfs /dev/sda6 /home/myname/d-drive
    6. df - Check if the partition is successfully mounted
    7. umount /home/myname/d-drive - Unmount the partition
    8. df - Check if the partition is successfully unmounted
    9. gedit /etc/fstab & - Edit /etc/fstab (On Xubuntu: mousepad /etc/fstab &)
    10. /dev/sda6 /home/myname/d-drive <fstype> rw 0 0 - Add this entry (<fstype> is the file system type)
      Eg:
          In case of ext4: /dev/sda6 /home/myname/d-drive ext4 rw 0 0
          In case of ntfs: /dev/sda6 /home/myname/d-drive ntfs rw 0 0

    11. mount -a - Mount all partitions listed in /etc/fstab
    12. df - Check if the partition is successfully mounted
    13. Close /etc/fstab
    14. chmod 777  /home/myname/d-drive - Give read/write/execute permissions for all users
    15. exit or <CTRL>D - Get out of supervisor mode
    16. Close the terminal
    17. Reboot/ restart
      The partition will be mounted on the directory /home/myname/d-drive. You can access the partition by using this path.

    3 comments:

    Anonymous said...

    Great! ;-)

    Anonymous said...

    Thanx! Nice detailed article.

    Anonymous said...

    Worked great, very detailed guide.

    Post a Comment