Linux disk and file system Management (i)

Source: Internet
Author: User
Tags disk usage

Disk and file System Management (i)

Requirements:

One, add a 20GB SCSI disk after shutdown, reboot into Rhel 5 system

Two, partitioning and formatting

1, use the FDISK command to partition the new hard disk, create a 10GB primary partition ("/DEV/SBD1")

Steps::

Execute the "fdisk-l" command to view and confirm the device name and settings for the new drive. The purpose of the FDISK-L command is to list information about all hard disk devices and their partitions in the current system.

650) this.width=650; "Style=" background-image:none; border-bottom:0px; border-left:0px; margin:0px; padding-left:0px; padding-right:0px; border-top:0px; border-right:0px; padding-top:0px "title=" clip_image003 "border=" 0 "alt=" clip_image003 "src=" http://s3.51cto.com/wyfs02/M00/77/5B/ Wkiol1zmth6bswruaaaqqrnx0-q372.png "" 244 "height="/>

Operations such as creating, deleting, changing partitions on a hard disk device are also done through the Fdisk command, as long as the device files of the hard disk are used as parameters.

Execute the "fdisk/dev/sdb" command to enter into the interactive partition management interface. : 650) this.width=650; "Style=" background-image:none; border-bottom:0px; border-left:0px; margin:0px; padding-left:0px; padding-right:0px; border-top:0px; border-right:0px; padding-top:0px "title=" clip_image005 "border=" 0 "alt=" clip_image005 "src=" http://s3.51cto.com/wyfs02/M02/77/5D/ Wkiom1zmta-qic24aaazpjdb1yk686.png "" 244 "height="/>

You can complete each partition management task by entering a specific partition action directive after the command (M for help): Prompt in the operator interface. After entering the "m" instruction, you can view help information for various operation instructions. :

650) this.width=650; "Style=" background-image:none; border-bottom:0px; border-left:0px; margin:0px; padding-left:0px; padding-right:0px; border-top:0px; border-right:0px; padding-top:0px "title=" clip_image007 "border=" 0 "alt=" clip_image007 "src=" http://s3.51cto.com/wyfs02/M01/77/5B/ Wkiol1zmticc8x8haaaphbq5sn0429.png "" 244 "height=" 103 "/>

? "P" instructions-lists the partitions on the hard disk. :

650) this.width=650; "Style=" background-image:none; border-bottom:0px; border-left:0px; margin:0px; padding-left:0px; padding-right:0px; border-top:0px; border-right:0px; padding-top:0px "title=" clip_image009 "border=" 0 "alt=" clip_image009 "src=" http://s3.51cto.com/wyfs02/M00/77/5B/ Wkiol1zmtigiekt8aaasnmtbuj4582.png "" 244 "height="/>

? "n" instruction-New partition

Use the "n" directive to create partitions, including primary and extended partitions. Follow the prompts continue to enter "P" select Create Primary partition, enter "E" select Create extended partition, after creating the extended partition, you can enter "L" select Create Logical partition. You can then select the partition ordinal, start position, end position, or partition size to complete the creation of the new partition.

When you select a partition number, the number of primary and extended partitions can only be 1~4. The starting position of the partition is generally recognized by Fdisk by default, and the end position or size can be in the form of "+sizem" or "+sizek" or "+sizeg".

To create the primary partition /DEV/SDB1:

650) this.width=650; "Style=" background-image:none; border-bottom:0px; border-left:0px; margin:0px; padding-left:0px; padding-right:0px; border-top:0px; border-right:0px; padding-top:0px "title=" clip_image011 "border=" 0 "alt=" clip_image011 "src=" http://s3.51cto.com/wyfs02/M00/77/5D/ Wkiom1zmtbhajkmuaaavztceuao311.png "244" height= "/>"

To create an extended partition /DEV/SDB4:

650) this.width=650; "Style=" background-image:none; border-bottom:0px; border-left:0px; margin:0px; padding-left:0px; padding-right:0px; border-top:0px; border-right:0px; padding-top:0px "title=" clip_image013 "border=" 0 "alt=" clip_image013 "src=" http://s3.51cto.com/wyfs02/M01/77/5D/ Wkiom1zmtbktd4y-aaayzldyiuk082.png "" 244 "height="/>

To create a logical partition /DEV/SDB5:

650) this.width=650; "Style=" background-image:none; border-bottom:0px; border-left:0px; margin:0px; padding-left:0px; padding-right:0px; border-top:0px; border-right:0px; padding-top:0px "title=" clip_image015 "border=" 0 "alt=" clip_image015 "src=" http://s3.51cto.com/wyfs02/M02/77/5D/ Wkiom1zmtboypcswaaavxwquk0m029.png "244" height= "Wuyi"/>

Execute the "P" command to view the partition. :

650) this.width=650; "Style=" background-image:none; border-bottom:0px; border-left:0px; margin:0px; padding-left:0px; padding-right:0px; border-top:0px; border-right:0px; padding-top:0px "title=" clip_image017 "border=" 0 "alt=" clip_image017 "src=" http://s3.51cto.com/wyfs02/M01/77/5B/ Wkiol1zmtiosgqu2aaab2eodc68530.png "" 244 "height="/>

? "D" directives-delete partitions

Use the "D" directive to delete the specified partition and continue to enter the number of partitions to be deleted as prompted. Be careful when performing a delete partition, you should first use the P command to view the serial number of the partition, and then delete it after the error is confirmed. It is important to note that if the extended partition is deleted, the logical partition under the extended partition will also be deleted. It is therefore recommended that the deletion be initiated from the last partition so that the partition sequence identified by Fdisk is not disturbed.

650) this.width=650; "Style=" background-image:none; border-bottom:0px; border-left:0px; margin:0px; padding-left:0px; padding-right:0px; border-top:0px; border-right:0px; padding-top:0px "title=" clip_image019 "border=" 0 "alt=" clip_image019 "src=" http://s3.51cto.com/wyfs02/M02/77/5D/ Wkiom1zmtbssgx_kaaahcn4ms8s810.png "" 244 "height="/>

? "t" instruction-Change the type of partition

In the Fdisk partitioning tool, the newly created partition uses the file system type EXT3 by default and does not normally need to be changed. However, if the new partition needs to be used as a swap partition or other type of file system, the partition type needs to be changed to maintain consistency, thus avoiding confusion when managing partitions.

You can change the ID number of a partition by using the "T" directive. You need to specify the target partition ordinal, and the new system ID number, in turn. Different types of file systems correspond to different ID numbers, represented by 16 decimal numbers, which can be entered as "L" instructions in the Fdisk interactive environment. The most commonly used EXT3, swap file systems have an ID number of 83, 82, and the ID number for the FAT32 file system in Windows is typically B.

650) this.width=650; "Style=" background-image:none; border-bottom:0px; border-left:0px; margin:0px; padding-left:0px; padding-right:0px; border-top:0px; border-right:0px; padding-top:0px "title=" clip_image021 "border=" 0 "alt=" clip_image021 "src=" http://s3.51cto.com/wyfs02/M01/77/5D/ Wkiom1zmtbtrddgraaaoeeuhcm0722.png "" 244 "height="/>

? "W" and "Q" directives-exit the Fdisk partitioning tool

After you complete the partition operation on the hard disk, you can exit the Fdisk partitioning tool by executing a "w" or "q" instruction. Where the "w" instruction will save the partition operation, and the "q" instruction will not save the partition operation on the hard disk.

Execute "w" instruction, save and exit. :

650) this.width=650; "Style=" background-image:none; border-bottom:0px; border-left:0px; margin:0px; padding-left:0px; padding-right:0px; border-top:0px; border-right:0px; padding-top:0px "title=" clip_image023 "border=" 0 "alt=" clip_image023 "src=" http://s3.51cto.com/wyfs02/M00/77/5B/ Wkiol1zmtixqofx2aaakgkiigme735.png "" 244 "height="/>

2, perform "Partprobe" to update the partition table information, use the MKFS command to format the newly created partition in the previous step to the EXT3 file system

Steps:

After changing the partition settings of the hard disk (especially the hard disk you are using), it is recommended that you restart the system once or execute the "partprobe" command to enable the operating system to detect new partition tables. In some Linux operating systems, failure to do so may result in corruption of the data already on the hard disk when the partition is formatted, even if the system crashes. :

650) this.width=650; "Style=" background-image:none; border-bottom:0px; border-left:0px; margin:0px; padding-left:0px; padding-right:0px; border-top:0px; border-right:0px; padding-top:0px "title=" clip_image025 "border=" 0 "alt=" clip_image025 "src=" http://s3.51cto.com/wyfs02/M02/77/5D/ Wkiom1zmtbajog7oaaag1afpzq8743.png "" 244 "height="/>

1. use of the MKFS command:

In fact, the MKFS command is a front-end tool that automatically loads different programs to create various types of partitions, and the latter includes several tools related to the MKFS command, which are located in the/sbin/directory. :

650) this.width=650; "Style=" background-image:none; border-bottom:0px; border-left:0px; margin:0px; padding-left:0px; padding-right:0px; border-top:0px; border-right:0px; padding-top:0px "title=" clip_image027 "border=" 0 "alt=" clip_image027 "src=" http://s3.51cto.com/wyfs02/M00/77/5D/ Wkiom1zmtbazpy7saaaoqajppp4194.png "" 244 "height="/>

When using the MKFS command program, the basic command format is as follows:

mkfs-t File System Type partition device

? Create EXT3 file System . :

650) this.width=650; "Style=" background-image:none; border-bottom:0px; border-left:0px; margin:0px; padding-left:0px; padding-right:0px; border-top:0px; border-right:0px; padding-top:0px "title=" clip_image029 "border=" 0 "alt=" clip_image029 "src=" http://s3.51cto.com/wyfs02/M00/77/5B/ Wkiol1zmtierogviaaa5l1nk5pm857.png "" 244 "height="/>

Or

650) this.width=650; "Style=" background-image:none; border-bottom:0px; border-left:0px; margin:0px; padding-left:0px; padding-right:0px; border-top:0px; border-right:0px; padding-top:0px "title=" clip_image031 "border=" 0 "alt=" clip_image031 "src=" http://s3.51cto.com/wyfs02/M01/77/5B/ Wkiol1zmtieyf8hlaaafjhpqiro849.png "" 244 "height="/>

? Create FAT32 file System. :

650) this.width=650; "Style=" background-image:none; border-bottom:0px; border-left:0px; margin:0px; padding-left:0px; padding-right:0px; border-top:0px; border-right:0px; padding-top:0px "title=" clip_image033 "border=" 0 "alt=" clip_image033 "src=" http://s3.51cto.com/wyfs02/M02/77/5D/ Wkiom1zmtbisppqxaaakk8sfoou547.png "" 244 "height="/>

Or

650) this.width=650; "Style=" background-image:none; border-bottom:0px; border-left:0px; margin:0px; padding-left:0px; padding-right:0px; border-top:0px; border-right:0px; padding-top:0px "title=" clip_image035 "border=" 0 "alt=" clip_image035 "src=" http://s3.51cto.com/wyfs02/M00/77/5B/ Wkiol1zmtiibff56aaaj0nkuvuq520.png "" 244 "height="/>

2. use of the Mkswap command:

In a Linux system, a swap partition acts like "virtual memory" in a Windows system to mitigate physical memory shortages to some extent. If the current Linux host runs more services and needs more swap space to support the application, you can add a new swap partition for it.

Using the mkswap Command tool, you can create a swap file system on the specified partition, and the target partition should first set the ID to 82 through the Fdisk tool. :

650) this.width=650; "Style=" background-image:none; border-bottom:0px; border-left:0px; margin:0px; padding-left:0px; padding-right:0px; border-top:0px; border-right:0px; padding-top:0px "title=" clip_image037 "border=" 0 "alt=" clip_image037 "src=" http://s3.51cto.com/wyfs02/M02/77/5D/ Wkiom1zmtbmtnekgaaakvtmylty855.png "" 244 "height="/>

? How to enable the newly added swap partition:

Steps:

1. First look at the size of the total swap space in the system. :

650) this.width=650; "Style=" background-image:none; border-bottom:0px; border-left:0px; margin:0px; padding-left:0px; padding-right:0px; border-top:0px; border-right:0px; padding-top:0px "title=" clip_image039 "border=" 0 "alt=" clip_image039 "src=" http://s3.51cto.com/wyfs02/M01/77/5B/ Wkiol1zmtimy-us2aaakp_y1qlo130.png "" 244 "height="/>

2. Then use the "swapon" command to enable it. :

650) this.width=650; "Style=" background-image:none; border-bottom:0px; border-left:0px; margin:0px; padding-left:0px; padding-right:0px; border-top:0px; border-right:0px; padding-top:0px "title=" clip_image041 "border=" 0 "alt=" clip_image041 "src=" http://s3.51cto.com/wyfs02/M02/77/5B/ Wkiol1zmtinzkni5aaagsslfwq0119.png "" 244 "height="/>

3. Then check the size of the total swap space in the system. :

650) this.width=650; "Style=" background-image:none; border-bottom:0px; border-left:0px; margin:0px; padding-left:0px; padding-right:0px; border-top:0px; border-right:0px; padding-top:0px "title=" clip_image043 "border=" 0 "alt=" clip_image043 "src=" http://s3.51cto.com/wyfs02/M00/77/5B/ Wkiol1zmtiqgjnbkaaakm_ademo598.png "" 244 "height="/>

4. If you do not use the newly added swap partition, you can use the "swapoff" command to deactivate it. :

650) this.width=650; "Style=" background-image:none; border-bottom:0px; border-left:0px; margin:0px; padding-left:0px; padding-right:0px; border-top:0px; border-right:0px; padding-top:0px "title=" clip_image045 "border=" 0 "alt=" clip_image045 "src=" http://s3.51cto.com/wyfs02/M01/77/5B/ Wkiol1zmtirr1urwaaagqd3_y94735.png "" 244 "height="/>

Third, migrate the "/home" Partition

1. Transfer the contents of the original "/home" directory and do a backup

Steps:

650) this.width=650; "Style=" background-image:none; border-bottom:0px; border-left:0px; margin:0px; padding-left:0px; padding-right:0px; border-top:0px; border-right:0px; padding-top:0px "title=" clip_image047 "border=" 0 "alt=" clip_image047 "src=" http://s3.51cto.com/wyfs02/M01/77/5D/ Wkiom1zmtbus4jzuaaajabms3e8244.png "" 244 "height="/>

2. Modify the partition mount settings in the "/etc/fstab" file

Steps:

1. Edit the/etc/fstab file using the "Vim" command. :

650) this.width=650; "Style=" background-image:none; border-bottom:0px; border-left:0px; margin:0px; padding-left:0px; padding-right:0px; border-top:0px; border-right:0px; padding-top:0px "title=" clip_image049 "border=" 0 "alt=" clip_image049 "src=" http://s3.51cto.com/wyfs02/M02/77/5D/ Wkiom1zmtburkibraaafi762q58044.png "" 244 "height="/>

2. In the following screen, enter a line "/dev/sdb1/home ext3 defaults 0 0" and then save and exit. :

650) this.width=650; "Style=" background-image:none; border-bottom:0px; border-left:0px; margin:0px; padding-left:0px; padding-right:0px; border-top:0px; border-right:0px; padding-top:0px "title=" clip_image051 "border=" 0 "alt=" clip_image051 "src=" http://s3.51cto.com/wyfs02/M02/77/5B/ Wkiol1zmtiytszr6aaahctlqyrs586.png "" 244 "height=" 137 "/>

The above operation, is the file system automatic Mount settings.

3, press the settings in the "/etc/fstab" file to mount the newly created partition to the "/home" directory

Steps:

Mount File System:

The basic use format of the Mount command is as follows:

Mount [-t file decency type ] Storage Devices mount point

Where the file system type can usually be omitted (automatically recognized by the system), the storage device is the corresponding partition of the device file name or network resource path, mount point that the user specifies the directory for mounting. :

650) this.width=650; "Style=" background-image:none; border-bottom:0px; border-left:0px; margin:0px; padding-left:0px; padding-right:0px; border-top:0px; border-right:0px; padding-top:0px "title=" clip_image053 "border=" 0 "alt=" clip_image053 "src=" http://s3.51cto.com/wyfs02/M01/77/5D/ Wkiom1zmtbzsxzhgaaag4palooo397.png "" 244 "height="/>

4, copy the user data backed up in this step (1) to the newly mounted "/home" file system

Steps:

650) this.width=650; "Style=" background-image:none; border-bottom:0px; border-left:0px; margin:0px; padding-left:0px; padding-right:0px; border-top:0px; border-right:0px; padding-top:0px "title=" clip_image055 "border=" 0 "alt=" clip_image055 "src=" http://s3.51cto.com/wyfs02/M01/77/5D/ Wkiom1zmtb2xj4pyaaaopn2jeo4687.png "" 244 "height="/>

In the actual work, you may often download some software or application system ISO image files from the Internet, in case you cannot burn a disc, you need to unzip it before you can browse and use the file data. If you use mount Mount commands, you do not need to unpack the package to browse and use the data in the ISO image file. The ". ISO" image file is often considered a special "loopback" file system, so you need to add the "-O loop" option when you mount it. :

650) this.width=650; "Style=" background-image:none; border-bottom:0px; border-left:0px; margin:0px; padding-left:0px; padding-right:0px; border-top:0px; border-right:0px; padding-top:0px "title=" clip_image057 "border=" 0 "alt=" clip_image057 "src=" http://s3.51cto.com/wyfs02/M02/77/5D/ Wkiom1zmtb3dueubaaahu7ltjes987.png "" 244 "height="/>

? To unmount the file system:

When the file system needs to be uninstalled, the command used is "Umount", using the mount point directory or the corresponding device's file name as the Unload parameter. Linux systems, because the same device can be mounted to multiple directories, it is generally recommended to mount the point directory location to uninstall.

To unload the corresponding partition via the mount point directory:

650) this.width=650; "Style=" background-image:none; border-bottom:0px; border-left:0px; margin:0px; padding-left:0px; padding-right:0px; border-top:0px; border-right:0px; padding-top:0px "title=" clip_image059 "border=" 0 "alt=" clip_image059 "src=" http://s3.51cto.com/wyfs02/M02/77/5D/ Wkiom1zmtb3jkb3haaae5x-hhwa679.png "" 244 "height="/>

To unmount a disc from a device file:

650) this.width=650; "Style=" background-image:none; border-bottom:0px; border-left:0px; margin:0px; padding-left:0px; padding-right:0px; border-top:0px; border-right:0px; padding-top:0px "title=" clip_image061 "border=" 0 "alt=" clip_image061 "src=" http://s3.51cto.com/wyfs02/M01/77/5B/ Wkiol1zmti7y3qudaaafivjg4o4030.png "" 244 "height=" one "/>

? To View disk usage:

The Mount command without options and parameters can display the mount of a partition, and you can use the DF command to understand the disk usage of each file system mounted on the system, such as the percentage of disk space remaining.

The DF command uses a file or device as the command parameter, and the more commonly used option is "-H" and "-T". The "-H" option can display more readable capacity units, while the "-t" option displays the type of the corresponding file system. :

650) this.width=650; "Style=" background-image:none; border-bottom:0px; border-left:0px; padding-left:0px; padding-right:0px; border-top:0px; border-right:0px; padding-top:0px "title=" clip_image063 "border=" 0 "alt=" clip_image063 "src=" http://s3.51cto.com/wyfs02/M00/77/5D/ Wkiom1zmtb7zxvhzaaavnz-gnfq671.png "" 244 "height="/>

Linux disk and file system Management (i)

Related Article

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.