Linux Mount detailed

Source: Internet
Author: User
Tags uuid

First, the Linux file structure

A file structure is a method of organizing files on storage devices such as disks. Mainly embodied in the organization of files and directories. The directory provides a convenient and effective way to manage files.
Linux uses a standard directory structure that, when installed, has created a file system for the user and a complete and fixed directory composition, specifying the role of each directory and the file types in it.

Linux uses a tree-based structure. The top level is the root directory, and all other directories are generated from the root directory. Microsoft DOS and Windows also adopt a tree structure, but in DOS and windows such a tree structure root is the disk partition of the letter, there are several partitions there are several tree structure, the relationship between them is tied. However, in Linux, there is only one directory tree that manages several disk partitions, regardless of the operating system. Structurally, the tree catalogs on each disk partition are not necessarily tied.

If this is not easy to understand, let me cite an example:

There is a hard disk that is divided into 4 partitions, the FAT for/and/boot or/and/usr in/;/boot;/usr and windows, which are subordinate relationships, and for/boot and/usr.
If I attach a FAT partition under Windows to/mnt/winc, then for/mnt/winc and/usr or/mnt/winc and/boot, they are two branches that do not have any relationship to the directory tree.
Because Linux is a multi-user system, developing a fixed directory plan can help unify the management of system files and different user files. But that's what makes many beginners who go from Windows to Linux feel headache. The following lists the functions of some of the main directories under Linux.

/(This is the famous root)
├──bin (most programs you run at the terminal, such as CP, MV ...)
├──boot (the kernel is placed here, this directory is also often used as a mount point for a separate partition)
│└──grub (The Grub bootloader and boot menu are placed here)
├──cdrom
├──dev (storage device file, here is equivalent to a Device Manager, automatically generated by the system.) Vary greatly depending on the hardware environment)
│├──block
│├──bsg
│├──bus
│├──char
│├──disk (disk information, to mount the hard disk partition will pay attention to the information here)
││├──by-id (permanent symbolic link for hard disk partitions)
││├──by-label (identifies other hard disk partitions by volume, often used for mounting)
││├──by-path (node link for hard disk partitioning)
││└──by-uuid (hard drive partition identified by UUID, often used for mounting)
│├──dri
│├──fd
│├──input
│├──net
│├──pts
│├──shm
│└──snd
├──ETC (Storage of all program and system configuration files and global variables, effective for all users, well worth backup)
├──home (This is the famous home directory, note is not "home directory", it is highly recommended to put a separate partition to mount here!) )
│├──adagio (This is my real home!) In general, the directory name is the account name, of course, it can not, casually. Wavy lines in command line ~ represent here)
│├──mnt (This is where I mount other hard drive partitions, you can see directory names that are differentiated by the hard drive brand, capacity, or purpose)
││├──max40nt1 (Maxtor 40G)
││├──st160nt1 (Seagate 160G First Partition, below two similar)
││├──st160nt2
││├──st160sys
││├──st320g (Seagate 320G)
│││├──movie
│││├──music
│││└──P2P (electric donkey, BT buffer zone)
││├──st80g (Seagate 80G)
│││├──program
│││├──st80pe
│││└──year
││└──wd1000 (West number 1T)
││├──wd2
││├──wd3
││├──wd5
││├──wd6. Lib
││└──wd7
│└──test (the home directory of another account I created, dedicated to testing, once you get to the point where you can't clean up, simply
│ Delete all the files inside, you can restore the default. You can actually have an unlimited number of accounts)
├──lib (library files shared by all programs)
├──lost+found (missing data from disk scan)
├──media (the partition that you automatically mount when you click in the File Manager is here, named after the volume, no volume is named by size)
├──mnt (also used to mount the disk, which is the most traditional location, like hanging where casually)
├──opt (some special programs like to put data here, like Java)
├──proc (all the details of the current system, the "file" here does not exist in the hard disk, but in memory or cache, each boot is not the same)
├──root (This is the home of the system's highest authority root user!) He is the boss, so he does not live in/home, where the Grass people live)
├──sbin (similar to/bin, store common programs, but the program here is very deadly Ah, such as formatting, so only the root user or sudo program is authorized to use)
├──srv (Files to be accessed by some services)
├──sys (System core file, similar to/proc, do not care about it)
├──tmp (store temporary files, all users can use, but you have to be careful, all of the files here once restarted is completely gone, automatically emptied)
├──USR (all the program data you used under X are here, including icons, manual, etc.). Available to all users. Also the largest catalogue)
└──var (Variation, as the name implies, is a variable, which stores the frequently changing data in the system. Different from/tmp, very useful place)
├──backups
├──cache
│└──apt
│└──archives (the Deb pack that holds all the programs you install!) Re-install the system is too useful, be sure to back up well, then put back.
│ I recommend stacks/var to be mounted separately to a separate partition, like/home. After you re-install the system, only
│ need to simply mount the stacks partition to/var on the line, eliminating the backup-restore time. You know, these Deb packs
│ is not dozens of M, but it is possible hundreds of M, a few g, one can be very tough. You can also mount it separately
│ one partition to/var/cache/apt/archives, the others do not.
│ Of course, this adds a little more complexity to the system structure, like how to please yourself. )
├──crash
├──games
├──lib
├──local
├──lock
├──log (hehe, the file here is the complete record of the system operation, out of the problem must come here to see)
├──mail (this is where all user email is stored)
├──opt
├──run
├──spool
└──tmp
40616 directories (there are 40,616 subdirectories in the root directory, you do not want to browse it again?) ) Second, Linux file system

The file system refers to the physical space in which a file exists, and each partition in a Linux system is a file system with its own directory hierarchy. Linux will form the overall directory hierarchy of a system in a way that is divided into separate file systems that belong to different partitions. An operating system can not operate without the operation of the file, so it is necessary to own and maintain their own file system.
The Linux file system uses an index node to log file information that acts like a Windows file allocation table. An index node is a structure that contains information such as the length of a file, creation and modification times, permissions, affiliation, location on disk, and so on. A file system maintains an array of index nodes, each of which corresponds to the only element in an array of index nodes. The system assigns a number to each index node, which is the index number of the node in the array, called the index node number.

The Linux file system saves both the file index node number and the filename in the directory. So, the directory is just a table that combines the name of the file with its index node number, and each pair of file names and index nodes in the directory is called a connection.
For a file, there is a unique index node number corresponding to it, for an index node number, but can have more than one file name corresponding. Therefore, the same file on the disk can be accessed through a different path. You can use the LN command to create a new connection to an already existing file without copying the contents of the file.

The connection has the soft connection and the hard connection cent, the soft connection is also called the symbolic connection. Each of them is characterized by:
Hard connect: Both the original file name and the connection file name point to the same physical address. Directories cannot have hard connections;
Hard connections cannot span file systems (cannot span different partitions) files have only one copy on disk, saving hard disk space;
Because deleting a file succeeds when the same index node belongs to a unique connection, you can prevent unnecessary accidental deletions.
Symbolic connection: Establishing a symbolic connection for a file with the Ln-s command is a special file of Linux, and as a file, its data is the pathname of the file it is connected to. Like a shortcut under Windows. Can delete the original file and save the connection file, there is no prevention of accidental deletion function.

This paragraph of the content is too abstract, but also the node is an array, I have tried to popular again, and not good examples for demonstration. If you are still foggy, I have no way, only first remember, in the future in the practical application of slowly experience, understanding. This is also my study of a method.

Third, Mount file system

As we know from the previous section, each partition in a Linux system is a file system with its own directory hierarchy. Linux will form the overall directory hierarchy of a system in a way that is divided into separate file systems that belong to different partitions. The word "in a certain way" means the mount.

Hang the top-level directory of one file system on a subdirectory of another file system, making them a whole, called mounts. Refer to this subdirectory as a mount point.
Note: 1, mount point must be a directory.
2, a partition is mounted on an existing directory, this directory can not be empty, but the contents of the previous directory will not be available after mounting. This is true for the mounting of file systems created by other operating systems. However, it is necessary to understand that the format of the file system used by the CD, floppy disk, and other operating systems is not the same as the file system format used by Linux. The disc is ISO9660, the floppy disk is FAT16 or Ext2;windows NT is FAT16, NTFS;WINDOWS98 is FAT16, fat32;windows2000 and WindowsXP are FAT16, FAT32, NTFS.
Before mounting, see if Linux supports the file system format that you want to mount.
Mount with mount command:

Format: Mount [-parameter] [device name] [Mount Point]

Among the parameters commonly used are
-t< file System type > specified device file system type, common are:
Minix Linux The earliest file system used
EXT2 Linux currently used file system
Msdos MS-DOS FAT, is FAT16
VFAT Windows98 commonly used FAT32
NFS Network File System
ISO9660 CD-ROM standard file system
NTFS file system for Windows NT 2000
HPFS OS/2 File System
Auto automatically detects the file system
-o< Options > Specify options when mounting the file system. Some are also available in/etc/fstab. Commonly used to have
CODEPAGE=XXX code page
Iocharset=xxx Character Set
RO mount in read-only mode
RW mount in read-write mode
Nouser makes it impossible for ordinary users to mount
User can mount a device to a normal user

As a reminder, the Mount command does not have a mount point feature, so you should ensure that the mount point already exists when you execute the Mount command. (Don't understand?) The point is that you want to mount the file system, first of all to build a directory. Is that OK? )

Example: Windows98 is installed in the HDA1 partition, and there are floppy disks and discs on the computer that need to be mounted.

# Mk/mnt/winc
# Mk/mnt/floppy
# Mk/mnt/cdrom
# mount-t Vfat/dev/hda1/mnt/winc
# mount-t Msdos/dev/fd0/mnt/floppy
# mount-t Iso9660/dev/cdrom/mnt/cdrom

It is now possible to read and write these file systems into directories such as/mnt/winc.
To ensure that the last two lines of the command are not wrong, make sure that there is a disk in the floppy drive and optical drive. (If the disk disc of the hard disk can be replaced frequently at any time, I think I will not make such a mistake:->)

If you have a Chinese file name in your Windows98 directory, a bunch of garbled characters are displayed when you mount it using the command above. This will use the CodePage iocharset option in the-o parameter. CODEPAGE specifies the code page of the file system, the Chinese code is 936;iocharset specified character set, Simplified Chinese is generally used cp936 or gb2312.
Mount must have an error when mounting file system Linux is not supported, such as Windows2000 's NTFS file system. You can recompile the Linux kernel to gain support for the file system. About recompiling the Linux kernel, that's not the point.

Iv. Automatic Mounting

It's obviously too cumbersome to run the Mount command every time you access the Windows partition, why not use the Mount command to access other Linux partitions?
In fact, Linux automatically mounts the Linux partitions that need to be mounted on each boot. So can we set Linux to mount the partitions we want to mount, such as Windows partitions, when booting up, to automatically mount the file system? This is perfectly possible. There is a fstab file in the/etc directory, which lists the list of file systems that are automatically mounted when Linux is powered on.
My/etc/fstab file is as follows:

/DEV/HDA2/EXT3 Defaults 1 1
/dev/hda1/boot ext3 Defaults 1 2
None/dev/pts devpts gid=5,mode=620 0 0
NONE/PROC proc Defaults 0 0
NONE/DEV/SHM TMPFS Defaults 0 0
/dev/hda3 swap swap defaults 0 0
/dev/cdrom/mnt/cdrom iso9660 noauto,codepage=936,iocharset=gb2312 0 0
/dev/fd0/mnt/floppy Auto Noauto,owner,kudzu 0 0
/dev/hdb1/mnt/winc vfat defaults,codepage=936,iocharset=cp936 0 0
/dev/hda5/mnt/wind vfat defaults,codepage=936,iocharset=cp936 0 0

In the/etc/fstab file, the first column is the device name of the mounted file system, the second column is the mount point, the third column is the mounted file system type, the fourth column is the Mount option, and the options are separated by commas. The 56th column does not know what to mean, but also looks at the expert pointing.
The last two lines are the c;d disks that I added manually under Windows, plus the codepage=936 and iocharset=cp936 parameters to support Chinese filenames. The parameter defaults actually contains a set of default parameters:

RW is mounted in read/write mode
SUID Open User ID and group ID setting bit
Dev interprets character or block devices on a file system
EXEC executable binary file
Auto Mount automatically
Nouser makes it impossible for ordinary users to mount
Async performs a file system's input-output operation in an unsynchronized manner

As you can see in this list, the optical drive and floppy drive are not mounted automatically and the parameters are set to Noauto. (If you want to set it to auto-mount, make sure you have a disk in your CD-ROM and floppy drive every time you turn it on.) )

Linux Mount detailed

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.