Linux Learning Mounts

Source: Internet
Author: User
Tags uuid

the system organization of Linux is--the whole system starts from the root, according to the tree-shaped directory downward gradually expand, classify and store different uses of the file,/read as a "slash", English slash; when it writes a path, the first/represents the root, that is, root, the other/representing the path delimiter, but all read as "Slash" or "slash".
when the system starts, a partition is mounted to the/, which can be understood as the partition is assigned/This strange "drive letter" (Note that in Windows, this symbol is used as the command parameter guide symbol, and the backslash \, English backslash as the path separator, the habit is different only, Just like the British driving on the left, there is nothing strange about it.
this mounted partition, called the root partition (whether it is a primary partition or a logical partition), has a special place in the Stacks Linux system since all the hard drives on the entire computer, including all the other partitions on it, are in this "root partition", regardless of the primary partition or logical partition. As the backbone, start constructing the Linux tree and eventually become a branch or leaf on the tree. The entire Linux system structure, there is only one root (root partition), there is no possibility of a second (in fact, any one partition, can be mounted as/,windows partition can also.) The purpose of mounting the root partition is to start the system, and if/below it does not have the Linux kernel and the required system files, it will not boot the system. So this root partition is not mysterious).
your other partitions can only be mounted to a directory under the/(root partition), such as "/mnt" or "/media" or "/what" directories, and then when you read and write data to this directory, is to read and write data to another partition that is attached to the directory (it can be understood that inserting a hard disk at that location can read and write data to the hard drive). Multiple partitions can only be mounted to a number of different directories at the same time, such as "/mnt/a", "/media/123" or "/home/anywhere", and any directory under/under may be used as a "platform" to mount other partitions. Of course, the system needs to use the directory, ah, you create your own use it.
after mounting, the data in your hard drive can be found in a way similar to/path/to/anywhere, and if it is not mounted, you cannot find it.
in a vulgar analogy,"/" is equivalent to C: \, while the "/etc,/bin,/sbin,/lib" directories are probably equivalent to C:\Windows and C. \program Files, and "/home" equals c:\Documents and Settings, and when you mount the second partition to "/mnt/partition2", this directory is the equivalent of D:\

Code:
1 cd/mnt                  (switch to/mnt directory)2sudo mkdir partition2      (Create a new empty directory named Partition2, You may feel free to use another name)3 sudo mount/dev/sda5 partition2   (if you have only one hard disk and the second partition is a logical partition, this command will mount the partition to Partition2)  4 cd partition2            (Switch to/mnt/partition2 directory)5 ls                     (file listing this directory)

This should allow you to see the files under your D-disk.
Now that you can mount it, you will be able to counter-mount it:

Code:
1 sudo umount/dev/sda5   (or/mnt/partition2)

This command will "unload" the partition, and now you will see that Partition2 is empty directory again.
here, someone might say, "Linux is too much trouble, I have more than 10 partitions, do I have to knock dozens of lines at a time?" Why don't you just hook me up when you start up like Windows? "
1. I said to knock orders, but I didn't say "every time"! The fstab file that will be introduced below will let you solve the problem once and for all in this matter; in fact, there is even a "0" peace method, you even a command do not have to knock, a few mouse click on it;
2. Automatically hangs like Windows? No problem, install one or two software, but I want to remind you:
is this really good? Not necessarily. I am sure that you will only use a few specific partitions most of the time, and then take a step back, even if you are the exception, but you should also think for others? For example, I have a partition with "sensitive" data, and not commonly used, usually not mounted, to be used to hang up
"Like windows," Why are you thinking like that all the time in your head? Is it because Windows has the most "good" method? Not necessarily, at best, you are accustomed to "that" only. Imagine if you've ever used Linux for "this" and then one day when I suddenly gave you a Windows computer, you'd be wondering, "Where's My home directory?" "Why can't you do it like Linux?" ”。
An example ______________________________________________________________

/(This is the famous root) ├──bin (most of the 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 (storing the device file, which is equivalent to a 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 to hard disk partition) ││├──by-label (identifies other hard disk partitions by volume, often used for mounting) ││├──by-Path (node link for hard disk partition) ││└──by-uuid (hard disk 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, very well worth backing up) ├──home (this is the famous home directory, note is not "home directory", it is highly recommended to attach a separate partition here!) │├──adagio (This is my real home!) In general, the directory name is the account name, of course, it can not, casually.   command line with wavy lines ~ represent here) │├──mnt (this is where I mount other hard disk partitions, you can see directory names that are distinguished by the brand, capacity, or purpose of the drive) ││├──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││├──w D6. Lib││└──wd7│└──test (I set up a home directory of another account, dedicated to testing, once you get to the point where you can not clean up, just a simple │ put all of the files inside the delete, you will be able to 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 you automatically mount when you click in the File Manager is here, named after the volume, no volume is named) ├──mnt (also used to mount the disk, which is the most traditional location, like hanging where       ├──opt (some special programs like to put data here, such as Java) ├──proc (all the details of the current system, where the "file" does not exist in the hard disk, but in memory or cache, each boot is different) ├──root (This is the home of the system's highest authority root user!) He's the boss, so he doesn't live in/home, where the grass is lived) ├──sbin (similar/bin, store common programs, but here the program is deadly Ah, such as formatting, so only the root user or sudo program is authorized to use ├──SRV (some services to access the files) ├──sys (System core files, similar/proc, don't worry about it) ├──tmp (store temporary files, all users can use, but you have to be careful, all of the files here once restarted, automatically emptied) ├──usr (all of the program data you use under X are here, including icons, Manu Al and so on. 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.) andtmp different Ah, 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 suggest putting stacks/var is mounted separately to a separate partition, like/home. So after you re-install the system, only │ need to simply mount the stacks partition to/var on the line, eliminating the backup-the time of the restore. To know that these Deb pack │ is not dozens of M, but it is possible hundreds of M, a few g, one can be very tough. You can also mount a separate │ partition to/var/cache/apt/Archives, none of the others. │ Of course, this adds a little more complexity to the system structure, like how to please yourself. ) ├──crash├──games├──lib├──local├──Lock├──log (hehe, here the file is the system running the complete record, out of the problem must come here to see) ├──mail (here is the place to store all users email) ├──opt├──run├──s Pool└──tmp

OK, now let's be specific, use my Ubuntu startup process to do an example to see how Linux has gradually planted this tree.
First of all, you need to know what the UUID is, or at least understand what the number of HDA and SDC mean. Otherwise it must have been're same page.
grub__________________________________________________________
System boot of course is starting from grub, please open your/boot/grub/grub.cfg file, find similar to the following paragraph (the following GRUB2 menu as a sample, grub0.97 Menu.lst is actually similar).

Code:
 1  menuentry  " ubuntu 9.10, kernel 2.6.31-17-generic   "  { 2  search--no-floppy--fs-uuid--set  f1bafdd4-73c2-44b2-9a62-d50a2da4d019   3  linux/boot/vmlinuz-2.6 . 31 -d50a2da4d019 ro Splash  4  initrd/boot/initrd.img-31 -17 -generic  5 } 

It could be like this.

Code:
 1  menuentry  " ubuntu 9.10, kernel 2.6.31-17-generic   "  { 2  set  root= (Hd2,6  )  3  Linux/boot/vmlinuz-2.6 . 31 -17 -generic root=/dev/SDC5 ro Splash  4  initrd/boot/initrd.img- 2.6 . 31 - Generic  5 } 

This is a standard Ubuntu boot menu, menuentry that line only shows the name of the item (including all the statements that are enclosed in curly braces), without having to worry about it;
The second line to start, just really into the Linux system boot process, search as the name implies is to find, what? Find the kernel.
Open your/boot directory to see if there is a file named Vmlinuz-xxxxx, usually within 10M size, which is known as the Linux kernel.
with the kernel, you have half a Linux operating system, you can start booting the system.
Linux/boot/vmlinuz-2.6.31-17-generic This part of the third line, Linux is an instruction that tells the GRUB program: "Please use this kernel given later", hence the name "/boot/ Vmlinuz-2.6.31-17-generic "kernel will be loaded into memory and read" root=uuid=f1bafdd4-73c2-44b2-9a62-d50a2da4d019 (SDC5) "Some of the necessary files for this partition.
The third line means: Use a file named "/boot/initrd.img-2.6.31-17-generic" first in memory to construct a "virtual" root file system, so that the kernel after the detection of hardware information to load the necessary modules and so on, in fact, this INITRD can also be thought of as part of the kernel, just to keep the vmlinuz clean and separate, and some kernels do not even need this.
By the end of Ok,grub's work, this "half" system of the Linux kernel will take over control of the computer and begin the initialization phase.
Note that you have not started to mount the root partition so far, so you can see that the partition root=xxxxxxxx (SDC5) is read-only (RO) mounted.
If you remove the "quiet" parameter in the third row, you can see the output of the whole process in the kernel initialization on the screen, of course, the screen scrolling will be very fast, and a lot of content, mainly in the detection of hardware environment, loading the corresponding modules, start-up services and so on ....
Fortunately, you just need to worry about one thing at the moment-mount. Notice the line of characters that will appear at approximately the middle stage--mounting Locale Filesystem
If your Linux has just been installed, because there are not many mounts, it may be a flash. And if you need to mount a lot of partitions, especially if the pass parameter is 1 or 2, you can see the list of the Mount situation.
fstab_________________________________________________________
yeah! The real partition mount starts here.
At this time, Linux will read a file named Fstab, and follow the instructions in line execution, until the completion of all the content, enter the system quickly open to see it, he is located in/etc/fstab. The following is my (do not think I said "directive" afraid of fear, in fact, the content is very simple, the earth can read).

Code:
1#/etc/fstab:Staticfile system Information.2 #3# Use'blkid-o value-s UUID'To print the universally unique identifier4# fora device; ThisMay is used with uuid= asa more robust -to name5# devices that works evenifDisks is added and removed. See Fstab (5).6 #7# <file system> <mount point> <type> <options> <dump> <pass>8PROC/PROC proc Defaults0   09#/was on/dev/Sda5 during installationTenUUID=CE8493A2-73A2-46D3-AC32-FE28AC9EC860/EXT4 Errors=remount-ro0   0 One#/Home was on/dev/Sda6 during installation Auuid=5ae0aea4-f7bb-4504-bf0c-f3dbffc8fa0f/home EXT4 Defaults0   0 -# Swap was on/dev/SDA7 during installation -Uuid=db44da00-1b52-4d25-a870-57d36a6a2a85 None Swap SW0   0

Or it could have been written like this.

Code:
1#/etc/fstab:Staticfile system Information.2 #3# Use'blkid-o value-s UUID'To print the universally unique identifier4# fora device; ThisMay is used with uuid= asa more robust -to name5# devices that works evenifDisks is added and removed. See Fstab (5).6 #7# <file system> <mount point> <type> <options> <dump> <pass>8PROC/PROC proc Defaults0   09#/was on/dev/Sda5 during installationTen/DEV/SDC6/EXT4 Errors=remount-ro0   0 One#/Home was on/dev/Sda6 during installation A/dev/sdc5/home EXT4 Defaults0   0 -# Swap was on/dev/SDA7 during installation -/DEV/SDC4 None Swap SW0   0

1. Ignore all lines starting with #, which is a comment, to show to yourself that Linux will not execute it, just as a complete command of a line, it will be completely ignored.
2. Keep in mind that each line is a complete command and cannot have line breaks. or the line break (carriage return) is equivalent to the period in the article.
3. Each space or tab symbol in each line is a parameter split symbol that acts as a comma in the article. Multiple connected spaces or tabs will be treated as one.
4. Linux mount partitions will be executed from top to bottom, sequentially
The first line that works (line 8th) is proc,1 has been explained, we don't care about it;
The second working row (line 10th) is/dev/sdc6 there, which is the first root partition that Linux is mounted on;
Again down (line 12th) will continue to mount the SDC5 to/home, that is, sdc5 this original relationship equal to the partition, now feel the sdc6 of a subordinate directory;
Finally (line 14th) will "mount" the swap partition, the reason is quoted, because the swap partition is a bit special, because he is not "attached" to/, but independent use, at least you can not find it from the root directory (so the mount point is not written/swap), in short, it was "occupied" by the system , you cannot read or write any data directly in this partition.

Linux Learning Mounts

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.