Assisting 13869411 developers since 2005.

Web Developer, Open Source, Loyal, Dad.  

Read More »

How to Create And Mount A Disk Partition in Linux

Posted by David  •  Oct 5th, 2014 9:29:59 pm - Subscribe | Mood: introspective | Music: Reggie and the Full Effect - Sundae Booty Sundae

This short entry explains how to create a mount a disk partition in linux. I will show you how to mount a peripheral such as a USB stick, External Drive, or anything else that can be easily remove from your Linux machine. Let’s get started.

What you will need:

  • Linux operating system
  • USB stick or external drive
  • Approximately 5 to 10 mins of time

    Basics
  • Begin by logging into your linux system as su
  • Su - (this will give you uninterrupted access to run commands)
  • Navigate to /home/{yourusername} by typing in cd /home/{yourusername}
  • Create a directory called mount: mkdir mount

    Peripherals
  • Navigate to the dev directory on your linux system: cd /dev
  • Now we need to list the files in the /dev directory by executing the command: ls
  • Plug in your usb stick / external drive to your linux system (depending on size this may take a few seconds for the machine to fully recognize your device)
  • Now type the list command: ls
  • Do you notice a new device listed? For example mine is called xvdj your’s will be called something different.
  • Once you have located the name of the device {xvdj} we need to mount it to our /home/{yourusername} directory

    Specify a File System
    In linux there are many types of file systems, but we will talk about. ext2, ext3, ext4. ext2 is the native file system on your linux machine, if you do not specify ext2 your linux system will default to this. ext3 is much like ext2, but that it allows journaling. Journaling does exactly that, it will log the commands and actions that you do. This will allow you recover a file / directory should it be accidently deleted. (this is in no way to be used as a backup utility) ext4 will allow you to create a file system that is up to: 32TB large and will support a file up to: 2TB big. So now that you no some of the differences, lets specify.

  • Begin by enter the command, be sure to change {xvdj} to your device name that your system has given it: mkfs -t ext3 /dev/{xvdj} Keep in mind that running this command can either go fast or slow so be patient. Once it completes, your disk volume will now be formatted with the file system: ext3
  • Optional: You have the ability in the command above to pass the -m {#} flag to change the reserve disk space (this prevents a system crash when the director is full), and the -c flag will add a bad block check, which means every sector on the partition of the device will be checked to see if it can be trusted to reliability hold data. (good for old drives)

    Mounting
  • Navigate back to our /home/{username} by typing cd /home/{yourusername}
  • You will notice if you run the ls command that our mount directory is here. So what we are going to do is mount our /dev/{xvdj} to /home/{username}/mount this will give us the ability to see our devices content in our users mount directory.
  • To mount the device we will enter: mount /dev/{xvdj} /home/{yourusername}/mount now hit enter.
  • If you received an error stating: mount: you must specify the file system type. Then go back to Specify a File Systems in the list above.
  • You're done! You have now mounted a device to your linux file system.

    Unmounting
    If you wish to unmount the device/peripheral from your linux system enter the following command.

  • umount /home/{yourusername}/mount (be sure that you are not in the directory when running this, or the device is not running a process when executing the command) If it is you will get an error that says: umount: /home/{yourusername}/mount: device is busy

    Notice
    Just a heads up that mounting a device in this manner will disconnect upon reboot...see my next post on how to prevent that from happening.

    Comments 0  •  Oct 5th, 2014 9:29:59 pm - Subscribe  •  Tweet this entry | Post a comment



  • Responses

    Leave a Reply


    ReCaptcha:

    Posting as anonymous Anonymous guest, why not register, or login now.

    Image Gallery

    Badges

    Amazon Wishlist Stumble Upon Toolbar
    Internet Blogs - Blog Top Sites Internet Blogs - Blog Top Sites Technology

    About Me

    avatar

    @davidpolanco
    iPhone: 29.513522,-98.565523 Web Designer, Open Source, Loyal, Dad. Learn more...