- How to mount usb drive in a linux system
- Step 1: Plug-in USB drive to your PC
- Step 2 – Detecting USB Drive
- Step 3 – Creating Mount Point
- Step 4 – Delete a Directory in USB
- Step 5 – Formatting the USB
- Format vs Fat FileSystem
- Format NTFS FileSystem
- Format EXT4 FileSystem
- How to Mount USB/External Disks/CD Drive in Linux
- Syntax
- Mount and change permissions on external drives
- Mounting CD Drive
- Mounting a USB Device
- Mounting an ISO Image
- Mounting Hard Disk partitions
- How to Unmount Devices in Linux
- To un-mount a floppy drive
- To un-mount a CD ROM drive
- To un-mount a USB drive
- Manually Mounting a USB Flash Drive in Linux
- procedure to manually mount drive once
- procedure to manually mount drive for repeated use
How to mount usb drive in a linux system
Do you know “how to use USB memory sticks with Linux”, If you are not sure then this article describes “how to mount USB drive on a Linux system with command line interface”
Universal serial bus, or USB (also known as Flash drive), is an electronic communications protocol that is commonly used in computer accessories and other small devices. If you have an up-to-date Linux system and a modern Desktop environment, your device should show up on your desktop, with no need to open a console. There are few important factors which are involved in learning how to mount USB drive with Linux machine.
Following are the step by step instructions to understand further –
Step 1: Plug-in USB drive to your PC
Step 2 – Detecting USB Drive
After you plug in your USB device to your Linux system USB port, It will add new block device into /dev/ directory. To verify it, use the following command –
The sample output should be like this –
We can observe from the above result that, device boot, blocks, id and system format are displayed.
Step 3 – Creating Mount Point
To mount the USB, use the following command –
To create a directory in the mounted device, use the following commands –
The above command creates a directory called john in USB device.
Step 4 – Delete a Directory in USB
To delete a directory in USB, use the following command –
Step 5 – Formatting the USB
You should unmount the device first to format the USB device, then use the following command to unmount the device –
Now use either of the commands as per file system based on your requirement. To format a USB drive, users generally prefer VFAT or NTFS file systems because they can be easily mounted on Windows operating systems and Linux systems.
Format vs Fat FileSystem
To format USB with vFat File System, use the following command –
Format NTFS FileSystem
To format a USB Flash Drive with NTFS file system, use the following command –
Format EXT4 FileSystem
To format a USB with EXT4 file system, use the following command –
Congratulations! Now, you know “How to Mount USB Drive in a Linux System?”. We’ll learn more about these types of commands in our next Linux post. Keep reading!
Источник
How to Mount USB/External Disks/CD Drive in Linux
In Linux mounting of devices (external disks,usb,cd drive) is done with a command known as mount . While mounting any device you should pass the argument to the command that what is the name of the partition and where do you want to mount the same. The mount point should be any directory present on your system.
Syntax
For Instance, if you want to mount a Floppy drive then,
So, here the /dev/fd0 is the alias for floppy drive in Linux system and /mnt/floppy is the mount point. It is the folder where we are mounting the floppy drive. So, if you want to view the files under floppy disk then you should directly access /mnt/floppy folder.
Note: In some Linux distribution, alias for the floppy drive may be different so, you should check the same before executing the command.
Mount and change permissions on external drives
By default, it’s only the user of the pen drive that has read and write permissions as shown below. The group and other users are restricted from having both read and write permissions as shown below. The pen drive, in this case, is labeled KIARIE found in /run/media/tarantula/ file path.
Output
This can also be seen in the file manager properties of the flash drive below
To grant other people access to the drive including all files and folders in the drive, run the following commands:
First, create a mount point in the /media/ directory. Let’s call it /data
Run fdisk -l to find out the partition information of the flash drive. If it’s the only removable drive, you’ll find that it’s indicated as /dev/sdb1 Implying that it’s the first partition of the second hard drive with a filesystem of FAT32.
The second step is to mount it to /mnt/data with read and write options.
This procedure will only work for an external drive formatted in ext4 format. If you are using a drive in Vfat or FAT 32 filesystem, you’ll need to convert it to ext4 using Gparted utility tool. Ensure to back up any data before conversion as this leads to formatting of the drive from one filesystem to another.
Another way you can mount and change permissions on external drives is by using pysdm package. However, this package has been obsoleted and is no longer in use for Ubuntu versions 12.10 and later.
When changing files permissions on the last step, you can also use the octal system i.e chmod +R 766 /mnt/data to give the group and other users read and write permissions. Thank you.
Mounting CD Drive
Here, the alias for the CD ROM is /dev/cdrom and the mount point is /mnt/CD.
Mounting a USB Device
Once we plug the USB device in the port, Linux will detect it as a new device and create its alias in /dev directory. To check that alias you can execute the following command.
Once you identify your USB device from the above output then you can mount the same with the following command:
Here, the mount point that should be creating in the system is /mnt/test.
Mounting an ISO Image
ISO Image is actually an image of any optical disk having extension .iso.
Here, -o loop option is used to support a file system that is in ISO format. It helps us to access such file system.
Mounting Hard Disk partitions
Once you have created a partition of your Hard Disk in Linux box then you should also mount those partitions to access them. Here, you can use the same command to find out the total partitions of the hard disk.
Once you identify the partition which you want to mount then use the following command to mount the same.
Here, the mount point that should be created in the system is /mnt/part1.
How to Unmount Devices in Linux
Un-mount means detaching any device from the Linux system and it is generally done with umount command. So, while un-mounting any device you should tell Linux what device to un-mount. For example,
To un-mount a floppy drive
To un-mount a CD ROM drive
To un-mount a USB drive
Assuming /dev/sda1 is the usb mount partition
This will detach the device from your Linux box. You can then remove that device from the system.
Источник
Manually Mounting a USB Flash Drive in Linux
February 16, 2005 | By: coolguys-suse
By Jason Jones
Posted: 16 Feb 2005
*note* Before you begin trying to do this manually, make sure Linux has not all ready mounted your drive to your Desktop automatically.
There are two ways to manually mount your flash drive in Linux.
The first way we’ll describe should be used if you are going to rarely mount your drive, or only mount it once.
The second way we’ll explain should be used if you plan on using your flash drive on a more regular basis.
procedure to manually mount drive once
Plug in the flash drive into one of the USB ports on your computer.
These usually are found on the back-side of your computer. Some newer models also have some ports on the front panel.
After you’ve plugged it in, you’ll want to open a terminal window and become the “root” user. This user is the only one which can access the commands to manually mount your drive. To become the root user, type in the following commands.
When it asks for your password, enter the root password. (You won’t see any typing on the screen when you enter your password. This is normal, and makes your computer more secure.)
After you’ve become root, enter the following command into the same terminal window to see if your computer has recognized the flash drive you plugged in.
This information tells me that the system recognized one USB device named “M-Systems Flash Disk Pioneers DiskOnKey” That is good. Yours will most likely have a different name, so look for the name of your flash disk’s manufacturer in the output.
*note* My system only has one USB device plugged in. If you have multiple devices plugged in, it will recognize them as well as your flash device, so your output will most likely look very differently than mine.
If your output doesn’t list anything that looks like your flash drive, I’d recommend trying different USB ports on your computer to see if it can get listed. You must get your computer to recognize your flash drive in order to continue with this tutorial.
After successful recognition of your USB drive, you’ll want to create a directory where your USB drive will be mounted. I entered the following commands into the same terminal window to do this.
- The “cd Desktop” command tells the computer to go into the Desktop directory (this is where I want to make the directory, so I can access the flash drive directly from my Desktop)
- The “mkdir flash” command makes a directory named “flash” which we’re going to use to mount the flash drive.
With that done, we need to get the appropriate device which is attached to your flash drive.
To do this, simply issue the following command in the same terminal window.
dmesg | grep -i “SCSI device”
As you can see, there are three lines of output, but they are all the same. The information we’re interested in is the output immediately after “SCSI device”. On my machine it’s sda.
This is the device we’re looking for. On most machines this will be the case. If you’ve got a newer machine with an SATA drive or a SCSI drive in it, the output will most likely be quite different. The words you’ll be looking for will probably be sdb or sdc. To make sure you select the correct device, simply look for some information that describes your flash drive. For example, my flash drive has 16 megabytes of storage on it. On the output, the words (16 MB) would be a good indicator of that being my flash drive.
When you’ve found the correct device (sda, sdb, sdc, etc…) enter the following command into the same terminal window:
There’s quite a bit there, so let’s break it down.
- “pwd” is used to see where the path is to your Desktop, so we can accurately mount the flash drive. You’ll use the line after it later.
- The next command is the command to mount your flash drive to the flash directory. Let’s break that down so we can understand it.
- “mount” is the command used.
- “-t vfat” tells the command to mount the “vfat” filesystem (which most flash drives are).
- “-o uid=jason,gid=users” makes the mount accessible by the “jason” user. You’ll want to change this to the user with which you use to log in. Example: if you use the username “jhamilton” to log in, you’d use “-o uid=jhamilton,gid=users” instead.
- “/dev/sda” points to the correct device. Make sure you use the same device you found earlier. Example: If you found your correct device to be “sdc” earlier, you’d use “/dev/sdc” instead.
- “/home/jason/Desktop/flash” is the directory to which you want the device to be mounted. You’ll want to use the results of the “pwd” command here. Example: If the line after the “pwd” command was “/home/jhamilton/Desktop” you’d use “/home/jhamilton/Desktop/flash” instead.
Your flash drive is now mounted and ready to use. If you followed the instructions exactly, there is a new folder on your desktop named “flash” which can be used to put files, images, music, or anything else you want!
When you’re done copying, simply pop out the drive and you’re on your way.
procedure to manually mount drive for repeated use
This is the way you should mount your drive if you plan on using it often.
Plug in the flash drive into one of the USB ports on your computer.
These usually are found on the back-side of your computer. Some newer models also have some ports on the front panel.
After you’ve plugged it in, you’ll want to open a terminal window and become the “root” user. This user is the only one which can access the commands to manually mount your drive. To become the root user, type in the following commands.
When it asks for your password, enter the root password. (You won’t see any typing on the screen when you enter your password. This is normal, and makes your computer more secure.)
After you’ve become root, enter the following command into the same terminal window to see if your computer has recognized the flash drive you plugged in.
This information tells me that the system recognized one USB device named “M-Systems Flash Disk Pioneers DiskOnKey” That is good. Yours will most likely have a different name, so look for the name of your flash disk’s manufacturer or name in the output.
*note* My system only has one USB device plugged in. If you have multiple devices plugged in, it will recognize them as well as your flash device, so your output will most likely look very differently than mine.
If your output doesn’t list anything that looks like your flash drive, I’d recommend trying different USB ports on your computer to see if it can get listed. You must get your computer to recognize your flash drive in order to continue with this tutorial.
After successful recognition of your USB drive, you’ll want to create a directory where your USB drive will be mounted. I entered the following commands into the same terminal window to do this.
- The “cd Desktop” command tells the computer to go into the Desktop directory (this is where I want to make the directory, so I can access the flash drive directly from my Desktop)
- The “mkdir flash” command makes a directory named “flash” which we’re going to use to mount the flash drive.
With that done, we need to get the appropriate device which is attached to your flash drive.
To do this, simply issue the following command in the same terminal window.
dmesg | grep -i “SCSI device”
As you can see, there are three lines of output, but they are all the same. The information we’re interested in is the output immediately after “SCSI device”. On my machine it’s sda.
This is the device we’re looking for. On most machines this will be the case. If you’ve got a newer machine with an SATA drive or a SCSI drive in it, the output will most likely be quite different. The words you’ll be looking for will probably be sdb or sdc. To make sure you select the correct device, simply look for some information that describes your flash drive. For example, my flash drive has 16 megabytes of storage on it. On the output, the words (16 MB) would be a good indicator of that being my flash drive.
Now, enter the simple command as follows:
This command is simply to tell us what the path is to your Desktop. We’ll be using this later.
After that is done, the first thing to do is make a backup of a *very* important file named “/etc/fstab” by issuing the following command:
Now, we’re going to need to tell your computer to set itself up to mount your flash drive every time your computer is turned on. To do this you’ll need to add something like the following line to the “/etc/fstab” file. (yours might vary a little bit depending on the information you’ve received previously)
/dev/sda /home/jason/Desktop/flash vfat users,noauto,uid=jason,gid=users 0 0
Some of the information might be different for you. If you didn’t find sda for your device before, you’ll have to enter the appropriate device. Example: If you found “sdc” for your device, you would change the “/dev/sda” line to “/dev/sdc“.
You will also change the /home/jason/Desktop/flash line to the appropriate directory. Example: If the line after the “pwd” command was “/home/jhamilton/Desktop” you’d use “/home/jhamilton/Desktop/flash” instead of “/home/jason/Desktop/flash”.
Also, you’ll need to change the “uid=jason” line to reflect the username you enter when you start Linux. Example: If you type in “JHamilton” when you log into NLD, you’ll want to change “uid=jason” to “uid=JHamilton“.
With that, you should be good to go.
Now we’re gonna enter the command to alter the /etc/fstab file. To do this issue the following command in your terminal window:
*note* Be sure to use your own info from above!
Now your /etc/fstab file has been altered, and you’re ready to mount your flash drive.
to do so, simply enter the following commands:
And your flash drive should be mounted! You can now drag ‘n’ drop things into your “flash” folder on your Desktop!
When you turn your computer off, in order to mount it again, simply go to your Desktop directory in a new terminal by typing “cd Desktop” and then type in “mount flash” and it’ll be mounted again.
Источник