Topic: Windows to Linux Tour: Part 6. Use partitions and file systems

xiaoxiao2021-03-06  73

Using disks and devices in Linux

Level: primary

Chris Walden (cmwalden-at-us.ibm.com) e-commerce architect, IBM Developer Relations 2004 January

IBM e-commerce architect Chris Walden will pass him

The nine series of articles published on DeveloperWorks guides you how to use your Windows operation skills in your Linux environment. In this section, we studied the layered directory structure of Linux, as well as loading and equipment.

The use of files and storage devices in Linux is different from Windows. Although there are also files and hierarchical directory structures, you also need to create a different way of thinking.

Listing 1. Directory structure

/

| - bin

| - Boot

| - DEV

| - ETC

| - MNT

| - OPT

| | | - IBM

| | | | - WebSpherestudio

| | `- DB2

| | - IBMHTTPSERVER

| - ROOT

| - Sbin

| - TMP

| - USR

| | | - x11r6

| | | | - BIN

| | | | - Include

| | | | - LIB

| | | | - Man

| | `- Share

| | | - BIN

| | | - DICT

| | | - DOC

| | | - ETC

| | - Include

| | | - LIB

| | | - LIBEXEC

| | | - Local

| | | | - OpenOffice

| | | | | - Sbin

No drive letters! There is no drive letter in Linux, which is really useful. If you have used the Windows system in a complex network environment, and you can find a number of devices that run this system, you may find that the letters in the alphabet are not enough. In Linux, there is only one file structure. It starts with root (/), all local file systems, all local devices, and all remote file systems are represented as subdirectory in this structure.

When Linux first boots, it builds this file structure according to the information in the / etc / fstab file. Windows assigns drive letters for hard drive partitions and other storage devices, and Linux assigns them for them in the root file structure. This layered structure is fully configurable and can be dynamically modified.

Loading! Add a device to the file system, the term is called loading. Linux will automatically load a / (root) file system. There may also have a separate / boot file system, where the core kernel boot file is stored. Linux will also load some special file systems. The switching partition does not represent part of the file system, but the core will handle it. However, other special file systems, such as Proc, is considered as a regular part of the file system, which can be processed like a normal file.

What is / proc? / Proc file system is an excellent example of Windows Thought and Linux Thoughts. / PROC stores virtual descriptions on all aspects of the system running. There are many information such as IRQ settings, memory usage, loaded device drivers, and network status. There is even a file called / proc / kcore, which is a virtual description of all used system memory. Each file here can be parsed as a normal file or binary file. Some files can be written to change the behavior of the running kernel without rebooting. For example, to open the IP forwarding of the first Ethernet device enabled in the system, you can use a file command: echo 1> / proc / sys / net / ipv4 / conf / eth0 / forwarding this main benefit of this system is, You only need to use a simple script technology to perform in-depth and efficient operations for your running system. Other file systems, such as movable media or remote file systems, require manual loading. When loading a file system, you need to know the correct way to reference it in Linux, there is also an empty directory as a loading point. For removable media, Linux may create a loading point for you during installation. In Red Hat Linux, the CDROM device is configured to / mnt / cdrom directory. That is to say, after you put a CD into the CDROM device, enter the command:

Mount / MNT / CDROM

The CD will be added to the file system, and the CDROM device is locked to make it unforeseen. You can access the contents of the CD only need to go to the / mnt / cdrom directory. When you no longer use the CD, you can remove it from the file system with the following command:

Umount / MNT / CDROM

The / MNT / CDROM directory will void, and the lock of the CDROM device is released. You can now safely pop up the CD. This is also true for other movable media, such as a floppy disk drive (/ mnt / floppy.

The mount command that runs without a parameter will display the currently loaded file system.

Why do you need to lock? Don't forget, Linux is not only multi-user, but also more sessions. That is to say, several users can log in to the system at the same time, run the program, and use resources. This is different from the use of shared files with the login in Windows. Each user can use the system as you sit in front of the console. In order to maintain stability, Linux does not allow any release of the currently used file system, by locking the CD, until no one is not popped up before use.

The association between the / etc / fstab file device and its loading point is configured in / etc / fstab. This file can be modified directly or can be maintained by management tools. Below is an example of / etc / fstab:

Understanding / etc / fstab

/ Dev / hda5ext3defaults1 1 / dev / hda2 / bootext3exec, dev, duid, rw1 2 / dev / hda6swapswapdefaults0 0 / dev / scd0 / mnt / cdromautoro, noauto, exec0 0none / dev / ptsdevptsid = 5, mode = 6200 0none / procprocdefaults0 0none / dev / shmtmpfsdefaults0 0

Each row represents a file system to be loaded. The first column indicates that the device to be loaded is. The second column is a load point, that is, the location of the device in the file system. The third column indicates the type of file system. The fourth column is an option to handle the file system. The last column is the logo of the file system. The first number is 1 or 0, specifying whether the system should be replicated with DUMP (one option of the system backup). The second number is 0, 1 or 2, specifying the order of checking the file system when booting. 0 indicates that it is completely inspected. 1 means to check the first check, the root (/) file system needs to be specified as 1. Other file systems should be 2. In the FSTAB file listed above, the root file system is located in the fifth partition of the first IDE hard drive, which is the first logical drive of the extended partition. The / Boot file system is located in the second primary partition of the first IDE hard drive, where the kernel startup file is stored. The exchange partition is located sixth partition of the first IDE hard drive, that is, the second logical drive of the extended partition. Other file systems in the list correspond to "None". We will immediately explain this problem. Now let's pay attention to physical disks.

Everything is that the file is in Linux, the file system is represented by the name similar to the file. All files in / dev directory are special files called Nodes, which are connected to physical devices through the device driver. This makes you do some interesting things. For example, in order to make a CD's ISO image, you can use the CP (COPY) command: CP / dev / cdRecorder mycd.iso is replicated with a binary image instead of the CD file structure. With document-centric approach also allows you to specify meaningful alias for your device name. For example, there is usually an alias called / dev / cdrom, pointing to a physical CDROM device, and this device is usually / dev / hdc. Once you have created an alias, you can access that device via / dev / cdrom, so better. Alias ​​technology also allows you to standardize the script so that these scripts can be used on systems that are different in different systems.

The options in the fourth column will vary with the file system type. In the above example, / and / boot load options are "default". That is, they use asynchronous I / O to be automatically loaded with readable and writable. Only root can be loaded or loaded, but the user can perform binary files and use "Sticky Bit" (later introduction). The file system will be processed as a block character device. However, for / mnt / cdrom, the option is different. It will not be loaded automatically and will be loaded as a read-only file system. The user will execute scripts and programs in the file system.

Adding a file system Add a new row in the / etc / fstab file, you can add the file system to / etc / fstab. As an actual example, I have a RAID device that stores the file resources used by the department. There is only a data file in this device, and it is maintained from the operating system so that it can be transferred to another system when a hardware failure occurs. RAID has been configured, identified in Linux as / dev / sdc, the third SCSI device. The EXT3 file system with logs is created on the first partition so that we can access it through / dev / sdc1. I want to automatically load this RAID to the file system when you boot.

I added the following line in / etc / fstab:

/ DEV / SDC1 / DATA EXT3 DEFAULTS 0 0

This will be loaded like / and / boot systems when booting. Now I will create a directory as the specified load point:

MKDIR / DATA

Once this empty directory is created, we can load the file system to it:

Mount / Data

RAID is now associated with / DATA. If the system is rebooted, / DATA will be automatically loaded. Partition is the same in the Linux middle partitions in nature in WINDOWS. The console command fdisk can create and manage partitions. When you use fdisk, you must indicate which device it wants to do. You can use the command fdisk -l to view the available devices.

Listing 2. Using fdisk

[root @ cmw-t30 root] # fdisk -l

Disk / dev / hda: 240 Heads, 63 Sectors, 7752 Cylinders

Units = cylinders of 15120 * 512 BYTES

Device Boot Start End Blocks ID SYSTEM

/ DEV / HDA1 1 8 60448 8E Linux LVM

/ DEV / HDA2 9 15 52920 83 Linux

/ DEV / HDA3 * 16 1403 10493280 C Win95 FAT32 (LBA)

/ DEV / HDA4 1404 7751 47990880 F Win95 ext'd (lba)

/ DEV / HDA5 1404 5565 31464688 83 linux

/ DEV / HDA6 5566 5635 529168 82 Linux SWAP

/ DEV / HDA7 5636 7751 15996928 b Win95 FAT32

The above list comes from a laptop, so it displays a bit different from the server. It shows a IDE hard drive with several partitions. If there are other devices, it will also be listed. For example, the second IDE hard drive may appear as / dev / hdb.

Specify a device runs FDISK again and you will get a short tip.

Listing 3. Run FDISK for a device

[root @ cmw-t30 root] # fdisk / dev / hda

The Number of Cylinders for this disk is set to 7752.

There Is Nothing Wrong with That, But this is larger Than 1024,

And CALD IN CERTAIN SETUPS CAUSE Problems with:

1) Software That Runs At Boot Time (E.G., Old Versions Of Lilo)

2) Booting and partitioning Software from other od

(E.G., DOS FDISK, OS / 2 fdisk)

Command (M for Help):

Enter "M" to view the command menu. You can use "P" to display the current partition table. You can create, delete, and modify the type of existing partition. "L" will list a full list of available partition types. Use "W" to write your modification to the partition table and exit the program, or use "Q" to exit using "Q" does not save the modification. Some modifications will take effect immediately. Some modifications require system reboot to take effect.

The partition rules under Linux are the same as in Windows. You can use 4 primary partitions, each of which can be an extension partition.

File System Type Linux can handle any file system types identified by the kernel. Quite a number of types are compiled into the kernel by default, and new file systems can be added. Here are some important file system types:

EXT2: Standard Linux File System Ext3: Standard Linux File System VFAT: Microsoft FAT32 File System JFS: IBM Log File System Reiserfs: Another popular log file system log save time, preservation data log file system helps Protect the data when it is abnormal. If a volume is not loaded, it is closed, and the unfinished work may be left, and the file in the in-BetWeen state. In a typical file system, this volume is required to perform a comprehensive check, which requires a longer time for larger volumes. The log file system keeps a transaction record for each write operation of the disk (such as 5 seconds). When this volume is not fully loaded, the file system only needs to roll back to the last known normal state. It takes only 20 minutes to restore a volume, now just a few seconds!

After formatting the subregional creation, format it with the appropriate version of the MKFS command. The file system will have its own version of MKFS, such as mkfs.ext2 or mkfs.ext3. These assistant scripts allow you to create a file system only if you need to specify a partition. Here are some examples:

Listing 4. Using MKFS

# Create an ext2 file system on the think

# Parition of the first ide har drive

MKFS.EXT2 / DEV / HDA3

# Create An Ext3 File System on The First3 File System on The First3 File System

# partition of the 2nd scsi hard drivemkfs.ext2

MKFS.EXT3 / DEV / SDB1

# Create a JFS file system in an extended

# Partition on the first ide hard drive.

MKFS.JFS / DEV / HDA5

Some advanced parameters will affect how the partition is formatted, but for the usual use, you can use the default parameters. Once the partition is formatted, it can be loaded into the / file system. A file system must be reformatted after being loaded.

Other file system tools let us take a look at other useful tools.

There are several tools to view the status of disk and file system.

DFDF represents "Disk Free". It reports the size of the disk space that has been used and available on the loaded file system. Useful switch:

Check disk space

DF -H Human readable format; in terms of easy-to-read K, M, G instead of bytes, only list local file systems; by default, remote file systems will also be List

DUDU means "Disk USAGE". It reports the disk space size used by specific files and each subdirectory (directory specified in parameters). Useful switch:

Check disk usage

Du -a lists the space occupied by all files, not only the directory du -h human readable format; to read the size of the K, M, G instead of bytes, show the size of the file Du -c All parameter processing is output, output a total; can be used to get a given set of files or directory The total disk space DU -S that only shows the sum of the file size specified by each parameter.

FSCK This program is used to check and repair file systems, equivalent to Chkdsk in Windows. Like MKFS, there are different versions of different file system types. FSCK must run on the already loaded volume, although it will be rarely used in unless it is completely complete in the file system. Detailed information is provided in MAN FSCK and INFO FSCK, and in the final reference information of this article.

Webminwebmin has some tools to manage file systems and partitions.

Figure 1. Webmin partition tool

Hardware, partitions on local disks, each disk and partition, and their usage of them are displayed. Click on a file system to view the details. For unloaded partitions, you can edit it, and format its file system. The system, disk, and network file system loaded and unloaded file systems are listed in / etc / fstab. The normal file system type has a wizard for creating an entry. The file system type that is not identified can be loaded and loaded here, but only manually edits / etc / fstab. Most server file systems can be treated well here.

A complete system is the sum of the partitions. Although there are many similar to the management of partition and file systems in Linux, there are many similarities in Windows, but from the driver alphabet to a complete hierarchical tree may also need to make some adjustments. Therefore, some robust console tools can use the configuration files in these features and / etc. Webmin, etc. provide some useful tools based on browser.

Reference

Read the other parts of Windows to Linux Tour Series (DeveloperWorks, November 2003). Linux Partition HowTo discusses in depth the partition mechanism and detail the available tools. Although Linux Administration Made Easy is a relatively old reference, it is still useful because Linux usually procedures and technologies are still consistent. Multi Disk System Tuning Howto describes how to best use multiple disks and partitions in Linux. "Installing and configuring SUSE Linux Enterprise Server (SLES 8" describes how to install and configure SUSE Linux Enterprise Server (SLES) 8, including steps to use YaST for graphical configuration. Linux System Administrator's Guide is a Linux system management prepared for novice. DeveloperWorks Tutorial "LPI CERTIFICATION 101 Exam PREP, Part 4: Advanced Administration" page describes file system, quotas, etc. IBM DeveloperWorks Series Articles Advanced File System Implementors Guide is a high-level topic, but you also introduce you to different file systems available under Linux. Learn how to use virtual file systems in your code through the IBM DeveloperWorks article. Format a new system? Please first read two articles from IBM DeveloperWorks: "Partition Planning Tips" and "Adjust the partition when working in system." IBM DeveloperWorks' "Double Boot Linux" article introduces you how to easily install Windows and Linux on a machine. IBM DeveloperWorks Article "Maximum Swappage" can help you improve the performance of the Linux server's exchange partition. Linux Loader, or LILO, has been replaced! Read the developerWorks tutorial "GRUB Getting Started" to learn all the situation. When you learn "Burnt CD on Linux" on IBM DeveloperWorks, you can easily burn the disc on Linux. Chapter 3, Introduction To Linux, the Linux Documentation Project, tells the file permissions and security. Linux User Technology FAQ can also help you transition from Windows to Linux smoothly. To start using IBM software products on Linux, develop refueling for your Linux application will provide you with the best reference. You can find installation prompts and reference information about DB2, Lotus Domino, WebSphere Application Server, WebSphere Studio, etc. You can also log in to get the free Linux Software Evaluation Kit, with trial software and training materials. More reference materials for Linux developers can be found in the developerWorks Linux zone.

转载请注明原文地址:https://www.9cbs.com/read-121424.html

New Post(0)