How Linux mount USB disk __linux

Source: Internet
Author: User
Tags mkdir

Look at the USB drive is the device, and then mount-t vfat/dev/to find the disk/your directory

One

Linux is not like Windows, after the new hardware can be automatically recognized, in Linux cannot automatically identify new hardware, need to manually identify. USB Mobile storage devices are usually identified as SDA1, which can be queried by fdisk-l command.

Before using a U disk, we have to create a new subdirectory for the plug-in point, the general point of the subdirectory is built in the/mnt inside, we also built there, of course, can also be built in the/directory, the name can be set, we will be named USB, terminal commands as follows:

Mkdir/mnt/usb

Then we can connect to my USB drive, and then enter the command at the terminal and hit the ENTER key:

Mount/dev/sda1/mnt/usb

Under Windows when we run out of u disk, before we remove the U disk we want to delete, also in Linux we also want to delete the starting point, the method is:

Umount/dev/sda1/mnt/usb or UMOUNT/DEV/SDA1

If you do not put the U disk to umount off, it is easy to cause the loss of data.

Two

Plug your USB drive up, open the system terminal, and see if you recognize it first.
#lsusb

If you recognize it, you'll see the USB device.

Then enter the MNT directory.
#cd/mnt

Create a new directory, such as: Usbdisk
#mkdir Usbdisk

In the Run command
#mount-T Vfat-o Iocharset=cp936/dev/sda1/mnt/usbdiak
(This is in a row, oh, T and-O is two parameters, SDA1 is your USB drive

So go into the/mnt/usbdisk directory and see if there's anything.

To uninstall.
#umount/dev/sda1
It's okay.

Three

Basic is not configured.
is used in the same way as Windows systems.
The difference is that you need to mount it under Linux.
Here we first set up a directory to mount the U disk to the directory: MKDIR/MNT/USB

Four

Red Hat linux9 GNOME desktop environment How to use the U disk

Programme I:
Linux is not like Windows, after the new hardware can be automatically recognized, in Linux cannot automatically identify new hardware, need to manually identify. USB Mobile storage devices are usually identified as SDA1, which can be queried by fdisk-l command.

Before using a U disk, we have to create a new subdirectory for the plug-in point, the general point of the subdirectory is built in the/mnt inside, we also built there, of course, can also be built in the/directory, the name can be set, we will be named USB, terminal commands as follows:

Mkdir/mnt/usb

Then we can connect to my USB drive, and then enter the command at the terminal and hit the ENTER key:

Mount/dev/sda1/mnt/usb

Under Windows when we run out of u disk, before we remove the U disk we want to delete, also in Linux we also want to delete the starting point, the method is:

Umount/dev/sda1/mnt/usb or UMOUNT/DEV/SDA1

If you do not umount off the U disk, it would easily result in loss of data.

Programme II:
USB support is the key to drive, without the drive device mount execution is certainly not. The common way I use U disk in Red Hat is as follows.

1. Do not insert U disk,/sbin/lsmod see whether there are usb-storage. If not:

Cd/lib/modules/2.4.20-8/kernel/drivers/usb

For V in *.O STORAGE/*.O; Do/sbin/insmod $v; Done

2. Here again/sbin/lsmod, should have Usbcore, USB-OHCI (or USB-UHCI, according to the motherboard chipset and different), Usb-storage, Scsi_mod and so on. Where the usb-storage state should be

(unused).

3. Insert U disk, Non-stop/sbin/lsmod, this period usb-storage state should be initializing, lasted about half a minute, in fact, the equivalent of windows in the lower right corner of the balloon balloons:)

4. After initialization,/SBIN/FDISK-L should be able to see the/DEV/SDA1 device. At this point, the execution

Mount/dev/sda1/mnt/udisk to succeed. If it is msdos format, and want to see Chinese, you can

Mount-t Vfat/dev/sda1/mnt/udisk-o iocharset=gb2312.

(For the convenience can/etc/fstab add a line, later can mount/mnt/udisk on the line).

5. It's strange that sometimes Fdisk can't see the sda1, but it can also mount

Use the above steps to hang U disk is basically "foolproof". Desktops, notebooks, VMware are the same.

Mkdir/mnt/usb

Mount/dev/sda1/mnt/usb

Install Linux usage on notebooks like desktop

Ps:

First check the Lsmod|grep usb-storage This is a USB-enabled module. If not, it is the device that cannot operate the USB interface.

If not, can hand work modprobe usb-storage, general view USB disk can use Fdisk-l can be very clear to see this hardware device name, than guess hardware name to be more accurate.
This creates a folder called USB under the MNT.
It should now be mounted: mount-t-VFAT/DEV/SDA1/MNT/USB
The above statement mounts the U disk in the USB folder. The-T-VFAT is the partition format for your U disk.

Five

Mount is the command to mount the USB, but the object that is being mounted on the back is not written right. And the Mount object does not exist
The correct procedure is as follows:

After the USB is plugged in,
First use the Disk-l command to see what your USB device name is, listed in the form has fat format is your USB device name, may be sda1, or sda2 or something
Assuming it's sda1, it's
Mount-t VFAT/DEV/SDA1 (note here is your USB in Linux device name)/mnt/

It's OK.

Then enter the MNT directory is your USB content.

Here's the script

Normally, U disk device should be/dev/sda1, but, sometimes use two different USB stick, the one behind is/dev/sdb1, so, the use of Fdisk-l | grep sd[b-z]1 | awk ' {print '} ' to obtain its device name. Code can only mount a U disk, because I basically will not be inserted at the same time two U disk, there is a need for friends can modify their own.

#! /bin/sh
#
# Mount/unmount a USB disk.
#
# Mount:
# We try to mount/dev/sda1, if failed, SEARCH/DEV/SDB1,/DEV/SDC1 ...,
# and try to mount the 1st one we found.
#

Mount_dir=/mnt/usb
Mount_dev=/dev/sda1

Mount | grep $MOUNT _dir

If ["$?" = "0"]
Then

# Kill All process locked the USB disk
Fuser-m-v-k-I $MOUNT _dir

Umount $MOUNT _dir
If ["$?" = "0"]
Then
echo USB disk at $MOUNT _dir has been unmounted
Else
echo Can not unmount $MOUNT _dir
Fi

Else
Mount-t vfat/dev/sda1 $MOUNT _dir-o codepage=936,iocharset=cp936 2>/dev/null

If ["$?" = "0"]
Then
echo USB disk $MOUNT _dev has been mounted at $MOUNT _dir
Else

#
# Search All USB disk devices, and mount the
#
For Mount_dev in $ (fdisk-l | grep sd[b-z]1 | awk ' {print $} ')
Todo
If ["$?" = "0"]
Then
Mount-t vfat $MOUNT _dev $MOUNT _dir-o codepage=936,iocharset=cp936 2>/dev/null
If ["$?" = "0"]
Then
echo USB disk $MOUNT _dev has been mounted at $MOUNT _dir
Exit 0
Fi
Fi
Done

echo Can not mount $MOUNT _dev to $MOUNT _dir

Fi

Fi

Exit 0

Note: If the U disk is formatted under Windows, then the above may not be partitioned, so the U disk device is/DEV/SDA (instead of/dev/sda1), then the above script is not suitable, need to modify.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.