A Linux system generally has four main parts:

Kernel, shell, file system, and application. The kernel, shell, and file system together form the basic operating system structure that allows users to run programs, manage files, and use the system. Figure 1-1 shows some hierarchies.

The Linux kernel

The kernel is the core of the operating system, with many of the most basic functions, it is responsible for the management of system processes, memory, device drivers, files and network systems, determines the performance and stability of the system.

The Linux kernel consists of the following parts: memory management, process management, device driver, file system, and network management. As shown in figure:



Figure 1

System call interface: The SCI layer provides some mechanism to perform function calls from user space to the kernel. This interface is architecturally dependent, even within the same processor family. SCI is actually a very useful function call multiplexing and demultiplexing service. You can find implementations of SCI in./ Linux /kernel, and architecture-dependent sections in./ Linux /arch.

Memory Management For any computer, its memory and other resources are limited. To allow limited physical memory to meet the high memory requirements of applications, Linux adopts a memory management approach called “virtual memory”. Linux divides memory into manageable “memory pages” (4KB for most architectures). Linux includes ways to manage available memory, as well as hardware mechanisms for physical and virtual mapping.

But memory management requires more than 4KB buffers. Linux provides an abstraction of 4KB buffers, such as the SLAB allocator. This memory management pattern uses a 4KB buffer base, allocates structure from it, and tracks memory page usage, such as which pages are full, which pages are not fully used, and which pages are empty. This allows the pattern to dynamically adjust memory usage based on system needs.

In order to support multiple users using memory, sometimes the available memory is consumed. For this reason, pages can be moved out of memory and into disk. This process is called swapping because pages are swapped from memory to hard disk. The source code for memory management can be found in./ Linux /mm.

Process management A process is actually a running entity for a particular application. In Linux, it is possible to run multiple processes at the same time, and Linux implements “multitasking” by taking turns running these processes at short intervals. This short interval is called a “time slice”, the method of rotating processes is called a “process schedule”, and the program that completes the schedule is called a scheduler.

Process scheduling controls CPU access by processes. When it is time to select the next process to run, the scheduler selects the most worthwhile process to run. Runnable processes are actually processes that are only waiting for CPU resources. If a process is waiting for other resources, it is a non-runnable process. Linux uses a simpler priority-based process scheduling algorithm to select new processes.

Through multi-tasking, each process can think of itself as exclusive to the computer, thus simplifying program writing. Each process has its own separate address space and can only be accessed by that process, so the operating system avoids interference between processes and the harm that “bad” programs can cause to the system. In order to accomplish a particular task, it is sometimes necessary to combine the functions of two programs, such as one program that outputs text and the other program that sorts text. To this end, the operating system also provides an interprocess communication mechanism to help accomplish this task. Common interprocess communication mechanisms in Linux include signals, pipes, shared memory, semaphores, and sockets.

The kernel provides an application programming Interface (API) through SCI to create a new process (fork, exec or Portable Operating System Interface [POS ⅸ] function), stop the process (kill, exit), And communicate and synchronize between them (signal or POS ⅸ mechanism).

3. Unlike operating systems such as DOS, individual file systems in Linux are not identified by drive letters or drive names such as A: or C:. Instead, like UNIX operating systems, Linux combines individual file systems into a hierarchical tree structure, which is represented by a single entity. Linux combines different file systems into a single entity by mounting new file systems to a directory in an operation called mount or mount. An important feature of the Linux operating system is that it supports many different types of file systems. The most commonly used file system in Linux is Ext2, which is also Linux’s native file system. However, Linux can also support FAT, VFAT, FAT32, MINIX and other file systems, making it easy to exchange data with other operating systems. Linux supports many different file systems and organizes them into a unified virtual file system.

VirtualFile systems (VFS) : Hides the details of various hardware, separates file system operations from the implementation details of different file systems, and provides a unified interface for all devices. The VFS provides dozens of different file systems. Virtual file systems can be divided into logical file systems and device drivers. Logical file system refers to the file system supported by Linux, such as ext2 and FAT. Device driver refers to the device driver module written for each hardware controller.

The virtual file system (VFS) is a very useful aspect of the Linux kernel because it provides a common interface abstraction for the file system. The VFS provides a switching layer between the SCI and the file systems supported by the kernel. The VFS provides a switching layer between the user and the file system.

The VFS provides a switching layer between the user and the file system:

On top of VFS is a generic API abstraction for functions such as open, close, Read, and write. Beneath the VFS is the file system abstraction, which defines how the upper-level functions are implemented. They are plug-ins for a given file system (more than 50). The source code for the file system can be found in./ Linux /fs.

Below the file system layer is the buffer cache, which provides a generic set of functions (file system-independent) for the file system layer. This caching layer optimizes access to physical devices by keeping the data for a period of time (or then prereading the data so that it is available when needed). Below the buffer cache is the device driver, which implements the interface to the specific physical device.

As a result, users and processes do not need to know the type of file system on which the files reside, but simply use them as if they were files in an Ext2 file system.

Device drivers device drivers are an essential part of the Linux kernel. Like the rest of the operating system, device drivers run in a highly privileged processor environment and can operate directly on the hardware, but because of this, errors in any one device driver can cause the operating system to crash. Device drivers actually control the interaction between the operating system and hardware devices. Device drivers provide a set of abstract interfaces understood by the operating system to complete the interaction with the operating system, while hardware specific operational details are performed by device drivers. In general, device drivers are related to the control chip of the device; for example, if your computer’s hard disk is a SCSI hard disk, you need to use a SCSI driver instead of an IDE driver.

Network Interface (NET) provides access to various network standards and support for various network hardware. Network interface can be divided into network protocol and network driver. The Network Protocol section is responsible for implementing every possible network transport protocol. As we all know, TCP/IP protocol is the standard protocol of the Internet, but also the de facto industry standard.

The Linux network implementation supports BSD sockets and supports all TCP/IP protocols. The networking part of the Linux kernel consists of BSD sockets, a network protocol layer, and a network device driver. The network device driver is responsible for communicating with the hardware device, and there are device drivers for every possible hardware device.

Second, the Linux shell

Shell is the user interface of the system, which provides an interface for users to interact with the kernel. It receives user-typed commands and sends them into the kernel to execute. It is a command interpreter. In addition, shell programming languages have many of the characteristics of ordinary programming languages, and shell programs written in this programming language have the same effect as other applications.

The following shell versions are available. Bourne Shell: Developed by Bell LABS. BASH: is the GNU Bourne Again Shell, which is the default Shell on the GNU operating system and is used by most Linux distributions. 3. Korn Shell: It is a development of Bourne Shell and is compatible with Bourne Shell in most aspects. 4. C Shell: BSD version of SUN Shell.

Linux file system

A file system is a method of organizing files on storage devices such as disks. Linux supports many popular file systems, such as EXT2, EXT3, FAT, FAT32, VFAT, and ISO9660.

3.1 File Types The following file types are used in Linux:

  1. Common files: C language meta-code, SHELL scripts, binary executable files, etc. Divided into plain text and binary.
  2. Directory file: directory, the only place to store files.
  3. Link file: a file that points to the same file or directory.
  4. Device file: Pertaining to system peripherals, usually under /dev. It is divided into block devices and character devices.

5) Pipe (FIFO) file: a way to provide process communication 6) socket file: this file type and network communication can be through ls — L, file, stat several commands to view the file type and other related information.

3.2 Linux Directory file structure is a way to organize files on storage devices such as disks. This is mainly reflected in the organization of files and directories. Directories provide a convenient and efficient way to manage files.

Linux uses a standard directory structure. At installation time, the installer has created a file system and a complete, fixed directory composition for the user, specifying the role of each directory and the types of files in it.

The entire directory tree can be divided into smaller parts that can be stored separately on their own disks or partitions. In this way, the relatively stable parts and the frequently changing parts can be stored in separate partitions for easy backup or system administration. The main parts of the directory tree are root, /usr, /var, /home, and so on (Figure 2). This layout makes it easy to share portions of the file system between Linux computers.



Figure 2

Linux uses a tree structure. The top layer is the root directory, from which all other directories are generated. Microsoft DOS and Windows also use the tree structure, but in DOS and Windows, the root of the tree structure is the drive letter of the disk partition, there are several partitions have several tree structure, the relationship between them is parallel. At the top are the different disks (partitions), such as C, D, E, F, etc.

But in Linux, no matter how many disk partitions the operating system manages, there is only one such directory tree. Structurally, tree directories on individual disk partitions are not necessarily parallel.

3.3 Linux Disk Partitions

Primary, extended, and Logical partitions: Linux partitions differ from Windows in that both hard disks and hard disk partitions are represented as devices. There are three types of hard disk partitions: primary, extended, and logical. A hard disk can be partitioned into two types: Primary Partion and Extension Partion. The total number of Primary partitions and Extension partitions cannot exceed four.

  • Primary Partion: can be used immediately but cannot be partitioned again.
  • Extension Partion: It must be partitioned again before it can be used, that is, it must be partitioned again.
  • Logical Partion: A partition created by an extended partition. There is no limit to the number of logical partitions.
  • An extended partition is nothing more than a “container” for logical partitions. In fact, only the primary partition and logical partition are used for data storage.

In Linux, the disk partition identifier is /dev/hd[a-z]X or /dev/sd[a-z]X, where [a-z] indicates the disk ID, and X indicates the disk partition ID.

Block id of a disk partition: In Linux, hDA, HDB, Sda, and SDB are used to identify different disks.

IDE interface disk: /dev/hda1, /dev/hdb… ; A SCSI or SATA disk can be /dev/sda, /dev/sdb… … ; Disk partitions: If the value of X is 1 to 4, it indicates the primary partition (including the extended partition) of the disk. /dev/hda5 is a logical partition.

For example, use hDA1, hDA2, hDA5, and hDA6 to identify different partitions. The letter A represents the first hard disk, the letter B represents the second hard disk, and so on. The number 1 represents the first partition of a hard drive, the number 2 represents the second partition, and so on. 1 to 4 correspond to Primary partitions or Extension partitions. Starting from 5, Logical partitions of hard disks are mapped. Note that even if a hard disk has only one primary partition, the logical partitions are numbered from 5.

Summary: a hard disk partition should first confirm which hard disk, and then confirm which hard disk partition it is located in.

/dev/hda is not a bad example; Fdisk -l = /dev/hda /dev/ HDB;

[root@localhost ~]# fdisk -l Disk /dev/hda: 80.0 GB, 80026361856 bytes 255 Heads, 63 sectors/track, Cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System /dev/hda1 * 1 970 7791493+ 7 HPFS/NTFS /dev/hda2 971 9729 70356667+ 5 Extended /dev/hda5 971 2915 15623181 b W95 FAT32 /dev/hda6 2916 4131 9767488+ 83 Linux /dev/hda7 4132 5590 11719386 83 Linux /dev/hda8 5591 6806 9767488+ 83 Linux /dev/hda9 6807 9657 22900626 83 Linux /dev/hda10 9658 9729 578308+ 82 Linux swap/SolarisCopy the code

Disk /dev/hda: 80.0GB, 80026361856 bytes The following is the partition of the hard disk, each partition has detailed information, here is not detailed; In Linux, the relationship between disk partitions and directories is as follows:

  • – Each partition must be mounted to a directory.
  • – Directories are logical distinctions. A partition is a physical partition.
  • – The Linux partition of a disk can be read or written only after being mounted to a specific directory in the directory tree.
  • – The root directory is where all Linux files and directories reside. You need to mount a disk partition to the root directory.

3.4 Functions of the Linux Main Directory.

/bin Binary executable commands /dev device special files /etc system management and configuration files /etc/rc.d Configuration files and scripts for startup /home The base point of the home directory of the user. For example, the home directory of the user is /home/user. You can use ~user to represent the /lib standard programming library, also known as dynamic link shared library, which is similar to the Windows. DLL file /sbin system management command. / TMP common temporary file storage point /root System administrator's home directory/MNT System provides this directory for users to temporarily mount other file systems. The /proc virtual directory is a map of the system's memory. You can access this directory directly to obtain system information. /var The overflow area of some large files, such as the log files of various services, /usr, the largest directory, where almost all applications and files are used. These include: /usr/x11r6 X Window directory /usr/bin A number of applications /usr/sbin some administrators /usr/doc Linux documents /usr/include Header file for developing and compiling applications in Linux /usr/lib Configuration file for the common dynamic link library and software package /usr/man help document /usr/src source code The source code for the Linux kernel is stored in /usr/src/linux. /usr/local/binCopy the code

3.5 Linux File System A file system refers to the physical space for files. In Linux, each partition is a file system and has its own directory hierarchy. Linux organizes these separate, partitioned file systems into a system’s overall directory hierarchy. An operating system cannot operate without files, so it is necessary to own and maintain its own file system. 1. File system type:

  • Ext2: A file system commonly used in early Linux
  • Ext3: an upgraded version of ext2 with the logging function
  • RAMFS: Memory file system, very fast
  • NFS: Network file system invented by SUN for remote file sharing
  • Ms-dos: MS-DOS file system
  • VFAT: indicates the file system used by Windows 95/98
  • FAT: indicates the file system used in Windows XP
  • NTFS: a file system used by Windows NT/XP
  • HPFS: file system used by OS/2
  • PROC: Virtual process file system
  • ISO9660: the file system used by most optical disks
  • UfsSun: file system used by the OS
  • NCPFS: The file system used by Novell servers
  • SMBFS: Samba’s shared file system
  • XFS: Advanced journaling file system developed by SGI that supports very large files
  • JFS: Logging file system used by IBM’S AIX
  • ReiserFS: a file system based on a balanced tree structure
  • Udf: Erasable data DISK file system

2. File system features: After the disk partition is completed, it needs to be formatted so that the operating system can use the partition. The purpose of formatting is to enable the operating system to use the file system format (that is, we mentioned the file system type above). Each operating system can use different file systems. For example, Microsoft operating systems prior to Windows 98 mainly used FAT (or FAT16) file systems, while versions of Windows 2000 and later had the so-called NTFS file system, For Linux, the orthodox file system is Ext2 (Linux Second Extended File System, ext2FS) this one. Furthermore, Linux Ext2 is not recognized by Windows operating systems by default.

In traditional disk and filesystem applications, a partition can only be formatted as a filesystem, so a filesystem can be said to be a partition. But thanks to new technologies, such as LVM and Software RAID, which we often hear about, these technologies can format a partition into multiple file systems (such as LVM), and can combine multiple partitions into a single file system (LVM, RAID)! If you want to format a partition, you can call it a filesystem instead of a partition.

So how does the file system work? This has to do with the operating system’s file data. File data in newer operating systems usually contains many attributes in addition to the actual contents of the file, such as file permissions (RWX) and file attributes (owner, group, time parameters, etc.) in Linux. File systems typically store these two pieces of data in separate blocks, with permissions and attributes in inodes and the actual data in data blocks. In addition, there is a superblock that records the overall information of the entire file system, including the total number of inodes and blocks, usage, and remaining amount.

For a disk partition, after being designated as the corresponding file system, the entire partition is divided into blocks of 1024,2048, and 4096 bytes. According to different blocks, it can be divided into:

Superblock: This is the first space in the entire file system. The file system includes basic information about the entire file system, such as the block size, total inodes/blocks, usage, and remaining amount, and Pointers to spatial inodes and data blocks.

Inode block (file index node) : file system index, record file attributes. It is the most basic unit of the file system and the bridge between any subdirectory and any file of the file system. Each subdirectory and file has a unique inode block. It contains information about the basic attributes of files in the file system, such as the length, creation and modification time, permission, and ownership relationship of files, and the location where data is stored. In Linux, you can run the ls-li command to view the inode information of a file. The hard link and the source file have the same inode.

3. Data blocks: Records the content of the file. If the file is too large, multiple blocks will be occupied. To improve directory access efficiency, Linux also provides a dentry structure that expresses the relationship between path and inode. It describes path information and connects to node inodes, contains various directory information, and also points to inodes and superblocks.

It’s like a book with a cover, a table of contents and a body. In the file system, the superblock is the cover, from which you can learn the basic information about the book. Inode blocks are equivalent to directories, from which the location of each chapter can be known. The data block is the body of the book, recording the specific content.

Traditional Linux file systems (such as Ext2 and 3) partition disks into super blocks, inode Table blocks, and data blocks. A file consists of a superblock, inode, and data area block. Inodes contain file properties (such as read and write properties, owner, and Pointers to data blocks). Data area blocks are file contents. When viewing a file, the inode table obtains file attributes and data storage points, and then reads data from data blocks.



Diagram of the ext2 file system

The file system formats the inode and block blocks, assuming that the attributes and permissions of a file are placed in inode number 4 (the smaller box below). The inode records the actual placement of the file data at the four block numbers 2, 7, 13, and 15. The operating system can then read the disk in order of the four blocks in one go. The data is then read as specified by the arrow in the figure below.



Figure inode/block data access diagram

This approach to data access is called Indexed Allocation. Are there any other common file systems to compare? B: Yes, that’s the flash drive we use. The file system used for flash drives is usually in FAT format. FAT file systems do not have inodes, so FAT cannot read all blocks from the file at first. Each block number is recorded in the previous block, which reads something like this:



FAT file system data access diagram

In the figure above, we assume that the file is written to the four block numbers 1->7->4->15, but the file system does not know the four block numbers in one sitting. It has to read the blocks one by one before it knows where the next block is. If blocks are spread too far apart, the disk read head will not be able to read all the data in one turn of the disk, so the disk will have to turn several times to read the entire file!

How often do you hear about “defragmentation”? The reason for defragmentation is that the blocks written to the file are too discrete, and the file read performance becomes poor. This can be done by fragmenting the same file blocks together, so that the data will be easier to read ah! Of course, FAT file systems need frequent defragmentation, so does Ext2 require disk refactoring?

Because Ext2 is an indexed file system, there is little need for frequent defragmentation. However, if the file system is used for too long and files are frequently deleted/edited/added, then the file data may be too discrete and may need to be reorganized.

You can use the ln command to create a new connection to an existing file without copying the contents of the file. There are soft connection and hard connection, soft connection is also called symbolic connection. Their respective characteristics are:

Hard connection: Both the original file name and the connection file name point to the same physical address. Directories cannot be hardwired; Hard connection can not be across the file system (can not be across different partitions) file in the disk only one copy, save disk space;

Because deleting a file can only succeed if the same index node belongs to a unique connection, it can prevent unnecessary deletions by mistake. A symbolic link is a type of Linux special file whose data, as a file, is the pathname of the file to which it is connected. Similar to Windows shortcuts. Can delete the original file and save the connection file, there is no protection against accidental deletion function.

The content of this paragraph is too abstract, and the node and the array, I have tried to be as simple as possible, and can not add examples to demonstrate. If you are still in the clouds, I do not have any way, only remember, in the future in the practical application slowly experience, understand. That’s one of the ways I learn.

3.6 Representation of file systems in the kernel

Kernel data structure

The VFS subsystem of the Linux kernel can be illustrated as follows:

File with the IO: The file descriptor is the index of this table. Each entry has a pointer to an open file. Now let’s clarify: Open files are represented by the file structure in the kernel, and Pointers in the file descriptor table point to the File structure.

Maintains the File Status Flag (f_FLAGS of the file structure) and the current read/write position (f_pos of the file structure) in the file structure. In the figure above, process 1 and process 2 both open the same file but have different file structures, so they can have different file Status flags and read/write positions. Some important members of the file structure are f_count, which means Reference Count. As we will see later, system calls such as DUP and fork can cause multiple file descriptors to refer to the same file structure. For example, fd1 and Fd2 both refer to the same file structure. So it has a reference count of 2, and when you close(fd1) it doesn’t free the file structure, it just reduces the reference count to 1, and if you close(fd2) it will reduce the reference count to 0 and free the file structure, and that really closes the file.

Each file structure points to a file_operations structure, whose members are function Pointers to kernel functions that implement various file operations. For example, if you read a file descriptor in a user program, read goes into the kernel via a system call, finds the file structure that the file descriptor points to, finds the file_operations structure that the file structure points to, and calls the kernel function that its read member points to to complete the user request. Lseek, read, write, ioctl, open and other functions are called in the user program, and ultimately the kernel function pointed to by each member of the kernel call file_operations completes the user request.

The release member in the file_operations structure is used to complete close requests from user programs. It is called release instead of close because it does not necessarily close the file, but rather reduces the reference count until the file is closed when the reference count is reduced to zero. For regular open files on the same file system, the steps and methods of read and write operations should be the same, and the functions called should be the same, so the file structure of the three open files in the figure points to the same file_operations structure. If you open a character device file, its read and write operations will be different from regular files. Instead of reading and writing disk blocks, it will read and write hardware devices. Therefore, the file structure should point to different file_operations structures, where the various file operations are implemented by the device driver.

Each file structure has a pointer to the dentry structure, which is short for Directory Entry. The argument we pass to the open, stat, and other functions is a path, such as /home/akaedu/a, to find the inode of the file. To reduce the number of disk reads, the kernel caches a tree of directories called the Dentry cache, where each node is a dentry structure. Search along the dentry of each part of the path, from the root/to the home directory, then to the akaedu directory, and then to the file A. The dentry cache stores only the recently accessed directory entry. If the desired directory entry is not in the cache, it is read from disk to memory.

Each dentry structure has a pointer to the inode structure. The inode structure holds information read from the disk inode. In the example above, there are two dentries representing /home/akaedu/a and /home/akaedu/b, which point to the same inode, indicating that the two files are hard linked to each other. The inode structure holds information such as owner, file size, file type, and permission bits read from the inode of the disk partition. Each inode structure has a pointer to the inode_operations structure, which is also a set of function Pointers to kernel functions that perform file directory operations. Unlike file_operations, inode_operations refers not to functions that operate on a file, but to functions that affect the layout of files and directories, such as adding and removing files and directories, tracking symbolic links, and so on. Inode structures belonging to the same file system can point to the same inode_operations structure.

The inode structure has a pointer to the super_block structure. The super_block structure holds information read from the superblock of a disk partition, such as file system type, block size, and so on. The s_root member of the super_block structure is a pointer to dentry, indicating where the root directory of the file system is mounted, in the example above the partition is mounted to /home.

File, dentry, inode, and super_block constitute the core concepts of VFS. For ext2 file systems, there are also concepts of inodes and superblocks in the disk storage layout, so it’s easy to match the concepts in VFS. Other file system formats come from non-UNIX systems (FAT32, NTFS for Windows, for example) and may not have inodes or superblocks, but may have to be scraped together in the driver to mount to Linux. If you look at FAT32 and NTFS partitions under Linux, you’ll see that the permission bits are wrong, and all files are RWXRWXRWX, because they don’t have the concept of inodes and permission bits, it’s just crudged.

3.6 Mounting a File System In Linux, each partition is a file system and has its own directory hierarchy. Linux organizes these separate, partitioned file systems into a system’s overall directory hierarchy. By “in a certain way” I mean mount.

Mounting the top level directory of one file system to the subdirectories of another file system to make them a whole is called mounting. Call this subdirectory a mount point.

For example, to read a formatted partition, CD-ROM, or software device on a hard disk, you must map the device to a directory, which is called a mount point, so that the device can be read. After mounting, the details of physical partitions are shielded so that users only have a unified logical concept. Everything is a file.

Note: 1. Mount point must be a directory. 2. A partition is mounted to an existing directory. The directory may not be empty, but the previous contents in the directory are unavailable after the partition is mounted. The same is true for mounting file systems built by other operating systems. However, it is important to understand that the file system formats used by CD-RoMs, floppy disks, and other operating systems are different from those used by Linux. CD is ISO9660; Floppy disks are FAT16 or ext2; Windows NT is FAT16, NTFS; Windows98 is fat16, fat32; Windows2000 and windowsXP are fat16, fat32, NTFS. Before mounting, know whether Linux supports the file system format you want to mount. Mount the mount command in the format of mount [- Parameter] [device name] [mount point]

-t specifies the file system type of the device (what file types are mentioned) -o specifies the options for mounting the file system. Some can also be used in /etc/fstab. Commonly used with

Codepage =XXX codepage iocharset=XXX character set ro mount in read-only mode rw mount in read-write mode nouser enable common users to mount user enable common users to mount devicesCopy the code

For example, mount a Windows file system:

/dev/hda5 2) mkdir create a directory where you want to mount disk E to: /dev/hda5 Mk/MNT /winc 3) Windows and Linux do not use the same file system. In general, Linux does not mount Windows file system, so you need to manually mount:

# mount -t vfat /dev/hda5 / MNT /winc (-t vfat indicates fat32)Copy the code

Mount CD: # mk/MNT /cdrom

# mount iso9660 /dev/cdrom/MNT /cdrom # mount iso9660 /dev/cdrom/MNT /cdromCopy the code

3. Vm shared folder: For example, in VirtualBox, the host is Windows, and Ubuntu is Guest. There are three steps:

1). Install the virtual machine kit first: In the VirtualBox menu, choose “Devices” -> “Install Virtual Machine Kit”. You will find an extra CD icon on the Ubuntu desktop. This CD is automatically loaded into the folder /media/cdom0 by default, and /cdrom automatically points to this folder. By default, the file manager will automatically open the CD and you’ll see a “vboxLinuxAddition.run” file inside. Open a command line terminal and type “CD /cdrom” and “sudo sh./ vboxLinuxaddition. run” without double quotes to start the tool package installation. After the installation, you will be prompted to restart Ubuntu in English. You are advised to restart it immediately. After the reboot, the obvious change is that the mouse is in shared mode and the clipboard is shared with Windows. If there are any changes, the virtual machine kit has been installed successfully.

2). Next, set the shared folder. In the shared folder Settings window, click “Add a Shared folder” on the right, select the path of the Windows folder that you want to share, and choose any share name you like, such as “myShare”. The read-only option indicates whether only Ubuntu is allowed to read this folder. Select this option as needed.

3). Mount the shared folder to Ubuntu: sudo mount -t vboxsf myshare /media/share where “myshare” is the name of the shared folder and “/media/share” is the target file to mount to.

3.7 Automatically Mounting Windows Partitions It is too cumbersome to run the mount command to access Windows partitions every time you start up. Why not use the mount command to access other Linux partitions?

In fact, every time you boot up, Linux automatically mounts the Linux partition that needs to be mounted. So can we configure Linux to mount the partition we want at startup, such as Windows partition, to achieve automatic file system mount?

That’s perfectly ok. There is a fstab file in the /etc directory that lists the file systems that Linux automatically mounts when it starts up. 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 /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 0Copy the code

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 type of the mounted file system, and the fourth column is the mount option, separated by commas. The fifth and sixth columns do not know what the meaning is, but also hope the master to point out. In the last two lines I added C for Windows by hand; For disk D, codePage =936 and iocharset=cp936 parameters were added to support Chinese filename. The defaults argument actually contains a set of default arguments:

  • The RW is mounted in read-write mode
  • Suid Enables setting the user ID and group ID
  • Dev interprets characters or block devices on the file system
  • Exec executable binary file
  • Auto Indicates automatic mounting
  • Nouser makes mounting impossible for general users
  • Async Performs input and output operations of a file system asynchronously

As you can see in this list, the CD/DVD drive and floppy drive are not mounted automatically and the parameter is set to noauto. (If you must set auto mount, make sure your DRIVE and FLOPPY drive have a disk in them every time you boot up, hehe.)

3.8. Soft and hard links

You can use the ln command to create a new connection to an existing file without copying the contents of the file. There are soft connection and hard connection, soft connection is also called symbolic connection. Their respective characteristics are:

Hardlink: gives a copy of the file, with the original file name and the connection file name pointing to the same physical address. Directories cannot be hardwired; Hard connection can not be across the file system (can not be across different partitions) file in the disk only one copy, save disk space;

Modify one of the files to be modified at the same time. If you delete any of these files, the remaining files will not be affected.

Because deleting a file can only succeed if the same index node belongs to a unique connection, it can prevent unnecessary deletions by mistake.

A symbolic connection (soft connection) : using the ln -s command to establish a symbolic connection to a file A symbolic connection is a type of Linux special file whose data, as a file, is the pathname of the file to which it is connected. Similar to Windows shortcuts.

Of course, deleting the connection does not affect the source file, but the use of the connection file, reference is directly to the source file.

The specific relationship can be seen in the following figure:



Figure 5: Soft and hard links

The difference between hard links and soft links can be seen from the graph:

  • 1: The inode number of the hard link file is the same as that of the new file. Soft links are different.
  • 2: If the original file is deleted, the soft link is unavailable, but the hard link is not affected.
  • 3: The modification of the original file, soft and hard link file content is also modified, because they are pointing to the same file content.

3.9. File directory Management Commands Disk and file space: fdisk df du File directory and management: CD PWD mkdir rmdir ls cp rm mv View file contents cat, TAC, more, less, head, tail File directories and permissions: Chmod chown CHGRP umask File search: which, whereis, locate, find, and find

4. Linux applications

Standard Linux systems typically have a set of programs called applications, which include a text editor, programming language, X Window, office suite, Internet tools, and databases.

5. Linux kernel parameter optimization

Kernel parameters, which exist through the Linux Proc file system, are an interface between the user and the system kernel through which the user can dynamically update the kernel configuration while the system is running. Thus, you can tune the Proc file system to optimize Linux performance.