In Linux, if you want to use a storage device (Mo, hard disk, CD-ROM, etc.), you have to mount it first, and when the storage device is mounted, you can access it as a directory. Mount a device and use the mount command.
When using the mount command, you must first know the following three kinds of information:
1. What file system type is the object to be mounted? (File system type)
2. The name of the device to be mounted? (/dev/????)
3. Which directory should the device be mounted to?
First, get the system supports file system types
on the first point, the user can execute
cat / proc / filesystems
to obtain the file system types are supported on the machine. If the system does not support the file system type of the device you want to mount, you may need to recompile the kernel to add support for this file type. For how to compile the kernel, please refer to the relevant articles in the LinuxAid online training column.
Commonly used file systems are:
Win95/98 commonly used FAT 32 file system: vfat
Win NT file system: ntfs
OS2 file system: hpfs
Linux file system: ext2
CD-ROM file system: iso9660
which although vfat Refers to the FAT 32 system, but in fact it is also compatible with the FAT 16 file system type.
Second, determine the device name
in Linux, device name usually in / dev years. The naming of these device names has rules, and we can find out the device names by "inference".
For example, the IDE device /dev/hda1. HD means Hard Disk, sd means SCSI Device, and fd means Floppy Device (or Floppy Disk?). a represents the first device, usually four IDE devices (such as four hard disks) can be connected to the IDE interface. So to are methods of identifying IDE hard it
is: hda, hdb, hdc, hdd . In addition, the "1" in hda1 represents the first
partition of hda, hda2 represents the second partition of hda, and so on.
In addition, you can directly check the file /var/log/messages. In this file, you can find the device code recognized by the system after the computer is turned on.
Third, find a mount point
and finally we will have to decide where to mount the device, first look at your computer is not there a empty directory / mnt of? This directory is specifically used as a directory for Mount Point. It is recommended that you create more directories in /mnt: /mnt/cdrom, /mnt/floppy, /mnt/mo, etc., as dedicated mount points for the directories.
For example, if you want to mount the following five devices, the execution instructions may be (assuming that they are all Linux
ext2 systems, if it is Win XX, please change ext2 to vfat):
1. Floppy disk ===>mount -t ext2 /dev/fd0 /mnt/floppy
2. MO ===>mount -t ext2 /dev/sda /mnt/mo
3. cdrom ===>mount -t ext2 /dev/hdc /mnt/cdrom
4 . SCSI cdrom ===>mount -t iso9660 /dev/sdb /mnt/scdrom
5. SCSI cdr ===>mount -t iso9660 /dev/sdc /mnt/scdr
This is an assumption, if the name of your device is different from this, please modify it yourself.
The last thing to note is:
1. When executing the mount action, first hit pwd to see if the current directory is at the mount point. If the current directory is at the mount point, the mount (or umount) will not succeed (device busy will be displayed) ).
2. The syntax for unmounting a device is the umount directory name, such as umount /mnt/cdrom, etc.
1. How to mount a file in ISO format
To mount: # mount -t iso9660 /<file.iso> /<mountpoint> -o loop
To unmount: # umount /<mountpoint>
On Solaris:
To mount:
# lofiadm -a /<file.iso> (will create device file /dev/lofi/1)
# mount -F hsfs -o ro /dev/lofi/1 /<mountpoint>
To unmount:
# umount /<mountpoint>
# lofiadm -d /dev/lofi/1
On HP-UX:
To mount:
# nohup pfs_mountd &
# nohup pfsd &
# pfs_mount -o xlat=UNIX <file.iso> /<mountpoint>
To unmount:
# pfs_umount /<mountpoint>
Subsequently, kill the following processes:
1. pfs_mountd
2. pfsd
3. pfs_mountd.rpc
4. pfsd.rpc
On IBM AIX:
To mount:
1. Build a logical volume (the size of an ISO image, better if a little bigger)
2. Create an entry in /etc/filesystem using that logical volume (LV), but setting its Virtual File System (V'S) to be cdrfs
3. Create the mount point for this LV/ISO
4. Copy the ISO image to the LV using dd
5. Mount and work on it like a mounted CD-ROM
The entry in /etc/filesystem should look like:
/IsoCD:
dev = /dev/lv09
vfs = cdrfs
mount = false
options = ro
account = false
To unmount:
1. Unmount the file system
2. Destroy the logical volume
Mounting ISO images on AIX
There is a known problem with mounting ISO images on the AIX platform. To workaround the problem, complete the following instructions:
- Obtain the size of the image.
For example:
# ls -al
total 731594
drwxr-xr-x 2 root system 512 Aug 18 11:33 .
drwxr-xr-x 6 root system 512 Aug 18 11:32 ..
-rw-r--r-- 1 root system 374575104 Apr 29 02:59
fim_console_rios_aix_5.iso - Identify the nearest multiple of 128 MB that will provide enough space for the image. In the above example, the image is approximately 374 MB, so use 384 MB as an image size.
Make a logical volume of this size. Ensure that there is enough space on the physical volume. For example, hdisk0.
# mklv -y cdlv -s n -L /dev/cdlv rootvg 384M hdisk0
If the command fails, increase the volume size by a multiple of 128.
- Use thedd command to create a pseudo-device. Ensure that the partition has enough space for the pseudo-device. In the following example command, the pseudo-device is /dev/cdlv.
# dd if=/opt/software/iso/fim_console_rios_aix_5.iso of=/dev/cdlv
Note that this command may take a long time and will create two dd processes.
- Mount the device like a CD-ROM in AIX. Ensure that the mount point exists.
# mount -v cdrfs -o ro /dev/cdlv /mnt/iso
- Change directory into /mnt/iso.
2. How to mount USB files
Check the manual to mount, with the average user key to a script .usbmount to mount, as follows
-----------
sudo mount -t vfat -o codepage = 936, iocharset = cp936, uid = $ UID,gid=$GID /dev/sda /media/usb
ln -s /media/usb /home/$USER/usb
-----------------
Just run this script OK, the codepage=936 corresponds to simplified Chinese. For the detailed information of the codepage, please refer to the content: http://www.linuxforum.net/chinese/topic/lcr-3.html Then I wrote a umount script , Get it done!
Resolving process, errors in the middle, and solutions
1. Cannot display Chinese, command: mount -t vfat /dev/sda /media/usb
needs to add -o iocharset=utf8
2. Cannot load files in usb, command: mount -t vfat -o iocharset=utf8 /dev/sda /media/usb
add uid gid, the specific id value can be obtained through id command.
3. Can not display Chinese correctly in gnome-terminal, command: mount -t vfat -o iocharset=utf8,uid=XXX,gid=XXX /dev/sda /media/usb
join codepage, modify ischarset. Get the final script.
3. Other ways to summarize
1. Mount floppy drive: mount -t msdos /dev/fd0 /mnt
2. Mount u disk: fdisk -l view, then mount -t vfat /dev/sda1 /mnt
3. Mount CD-ROM: mount /dev/cdrom /mnt
Attachment: mount other types (reposted)
When learning operating systems, we all learned that the file system is an important part of the operating system. There are many types of file systems, such as fat and fat32 in windows; ext, ext2 or ext3 in Linux; ufs in FreeBSD and so on. In the process of using Linux, the Linux operating system often uses the virtual file system VFS. Through VFS, other file systems that have been supported by the kernel can be directly accessed. It is used like an ordinary Linux ext series file system. Early Linux built-in file system support is not much, since kernel 2.0.x and support to VFAT, gradually increase in the future, so far it can be said that most of the file systems have support. Only some such as NTFS need to recompile the kernel to support.
During the boot process of Linux, the file system on each partition will be mounted to the corresponding mount point according to the settings in /etc/fstab. Linux requires at least two partitions to boot: one is the root partition/, and the other is the swap partition. If the root partition fails to load during boot, Linux cannot complete the boot. If the swap partition fails to load, Linux will not be able to boot, and the speed will be greatly affected if the memory is insufficient. The file system type of the root partition is usually ext, ext2, or ext3, but it can also be other file systems.
In addition to loading the file system necessary for Linux, Linux users often need to use various other file systems, especially when multiple operating systems are installed on a machine at the same time. For example, both Linux and Windows 2000 are installed on the author's machine. The C drive of Windows uses the NTFS file system and the D drive uses the FAT32 file system. And when I work on Linux, I often need to access the contents of the C drive and D drive of Windows, even the shared directory on the network, and mount a file system under Linux using the mount command, which can be obtained with the man mount command Detailed explanation of the command parameters. Here's how to add a file system via command line in several situations:
1. Add FAT32 file system
The simplest usage
mount /dev/hda6 /mnt/d
/dev/hda6 is the D drive of the author's Windows, and /mnt/d is the directory plus the hanging point. Linux will recognize the file system type of the /dev/hda6 partition and add it. Of course, you can also specify the file system type of the partition, the command is as follows:
mount -t vfat /dev/hda6 /mnt/d
In actual operation, directly add a windows partition, the Chinese file name and directory name will appear garbled, in order to avoid this situation, you can specify the character set, the command is as follows:
mount /dev/hda6 /mnt/d -o codepage="936",iocharset=cp936
mount -t vfat /dev/hda6 /mnt/d -o codepage="936",iocharset=cp936
Note: cp936 refers to simplified Chinese and cp950 refers to traditional Chinese.
2. Add NTFS file system
On most current Linux versions, it is necessary to recompile the Linux kernel to add NTFS partitions (please refer to other articles for the compilation method). After the core supports NTFS, you can add it with the following command:
mount -t ntfs /dev/hda2 /mnt/c
Similarly, for the problem of garbled characters in Chinese file names and directory names, you can specify the character set, but unlike adding vfat partitions, the following commands are actually feasible:
mount -t ntfs -o iocharset="cp936" /dev/hda2 /mnt/c -r
mount -t ntfs -o iocharset="cp936",rw /dev/hda2 /mnt/c
3. Add the file system on the U disk
Nowadays, there are more and more people using USB flash drives. In fact, it is very easy to use USB flash drives under Linux. Linux has very good support for USB devices. After you insert the USB flash drive, the USB flash drive is recognized as a SCSI disk, usually You can
mount the file system on the U disk with the following command mount /dev/sda1 /usb
Similarly, for the problem of garbled characters in Chinese file names and directory names, you can specify the character set. The command is similar to the FAT32 introduced above:
mount /dev/sda1 /usb -o pagecode="936",iocharset=cp936
4. Add a directory shared by the Linux system through samba
In fact, it is difficult to tell which file system it was originally shared by using samba, but this is not important, as long as it is transparent to users. When adding, we specify the type as smbfs. When adding a samba shared partition, the Chinese file name and directory name will be garbled. You can use the following command to add:
mount -t smbfs -o
username=terry,password=terry,codepage=936,iocharset=cp936
//terry-linux/terry /mp3/
mount -t smbfs -o
username=terry,password=terry,codepage=936,iocharset=cp936
//192.168.100.228/terry /mp3/
Note: You don’t need to write the parameter password=terry directly. The system will ask you to enter your password, so that you can prevent someone from seeing your password directly. Depending on the specific situation, the parameters after -o can be increased or decreased accordingly.
5. Add a directory shared by the Window system
In the local area network, it is often necessary to access the directories shared by other Windows systems. Under Linux, after installing samba, you can use the commands in samba to access the shared resources of the Windows machine.
Use smbclient to list the shared resources of the Windows machine
smbclient -L 192.168.100.111
According to the Windows shared resources listed above, you can select the Windows shared resources that need to be added to the local Linux, and then use smbmount or mount to add, please refer to the following commands:
smbmount //192.168.100.111/public /public/
mount //192.168.100.111/d /mnt/cdrom -o username="terry" (the password must be entered on the command line)
mount //192.168.100.111/d /mnt /cdrom -o username="terry"$1234 (so you don’t have to enter the password on the command line)
Note: In addition to the command line methods described above, the best way at this time is to use other clients, such as LinNeighborhood, networkneighbours, ksmbshare, etc., please refer to other articles.
The above is the command line method, and you have to enter it every time you use it. If you often want to add some file systems, what should you do if you want to automatically add them at startup? Two methods are described below:
Method 1.
Put the added commands in /etc/rc.d/rc.local.
Method 2.
Modify the partition configuration file /etc/fstab, add a file system when booting, the following is my /etc/fstab file:
LABEL=/ / ext3 defaults
1 1
none /dev/pts devpts gid=5,mode= 620
0 0
LABEL=/home /home ext3 defaults
1 2
none /proc proc defaults
0 0
none /dev/shm tmpfs defaults
0 0
/dev/hda4 swap swap defaults
0 0
/dev/cdrom /mnt/cdrom iso9660
noauto,owner ,kudzu,ro 0 0
/dev/hda2 /ntfs ntfs defaults,iocharset=cp936 0 0
/dev/hda6 /win vfat defaults,codepage=936,iocharset= cp936 0 0
//192.168.100.228/terry /mp3 smbfs username=terry,password=terry,codepage=cp936,iocharset=cp936 0 0
Note the last three lines:
The fourth to last line, add my C drive, NTFS format the
third to last line, add my D drive, the
second to last line in FAT32 format , add another Linux on my LAN with samba installed A directory on the file server
Mount use detailed explanation
Syntax: mount [-afFhnrvVw] [-L<label>] [-o<option>] [-t<file system type>] [device name] [load point]
Instructions: mount can set the specified file in the specified device The system is loaded into the Linux directory (that is, the mount point). The frequently used equipment can be written into the file /etc/fastab so that the system is automatically loaded every time it starts. The information of the mount device is recorded in the /etc/mtab file. When the umount command is used to unmount the device, the record will be cleared.
Common parameters and options:
-a Load all devices set in the file /etc/fstab.
-f Do not actually load the device. Can be used together with -v and other parameters to view the execution process of mount.
-F needs to be used with the -a parameter. All devices set in /etc/fstab will be loaded at the same time, which can speed up the execution.
-h Display online help information.
-L<label> Load the device whose file system label is <label>.
-n Do not record loading information in the /etc/mtab file.
-o<options> Specify options when loading the file system. Some options can also be used in /etc/fstab.
These options include: async Performs input and output actions of the file system in an asynchronous manner.
atime Update the access time of the inode every time it is accessed, the default setting, the cancel option is noatime.
auto must be specified in the /etc/fstab file. When the -a parameter is executed, the device set to auto will be loaded, and noauto will be deselected.
defaults Use the default options. The default options are rw, suid, dev, exec, anto nouser, and async.
dev Character or block device on the readable file system, the cancellation option is nodev.
exec executable binary file, the cancellation option is noexec.
noatime Does not update the access time of the inode each time it is accessed.
noauto cannot be loaded with the -a parameter.
nodev does not read character or block devices on the file system.
noexec cannot execute the binary file.
nosuid Turn off the set-user-identifier (set user ID) and set-group-identifer (set group ID) setting bits.
nouser makes it impossible for a user to perform the load operation, the default setting.
remount Reload the device. Usually used to change the setting status of the device.
ro is loaded in read-only mode.
rw is loaded in read-write mode.
suid enables the set-user-identifier (set user ID) and set-group-identifer (set group ID) setting bits, and the cancel option is nosuid.
sync executes the input and output actions of the file system in a synchronous manner.
user can allow general users to load the device.
-r Load the device in read-only mode.
-t<file system type> Specifies the file system type of the device. Commonly used option descriptions are: The
earliest file system used by minix Linux.
The current commonly used file system for ext2 Linux.
msdos FAT for MS-DOS.
vfat Win85/98 VFAT.
nfs network file system.
The standard file system of iso9660 CD-ROM.
ntfs Windows NT file system.
hpfs OS/2 file system. File system of versions prior to Windows NT 3.51.
auto automatically detects the file system.
-v displays detailed information during execution.
-V Display version information.
-w Load the device in read-write mode, the default setting.
eg::
Query : smbclient -L 192.168.1.104
挂接:smbmount //192.168.1.104/varconfig /tang/varconfig/ -o username="panzuji"$111111
Delete: unmount /tang/varconfig/
|