Disk and file system management

Source: Internet
Author: User
Tags disk usage

Check and confirm the New Hard Disk

 

After a new disk device is connected and the host is started, the Linux system will automatically detect and load the hard disk, without the need to install additional drivers. Run the "fdisk-L" command to view and confirm the device name and location of the new hard disk device.

650) This. width = 650; "Title =" image001.png "alt =" wKioL1POV-3AH7O-AAHU86FWixE001.jpg "src =" http://s3.51cto.com/wyfs02/M01/40/48/wKioL1POV-3AH7O-AAHU86FWixE001.jpg "/>

The above information includes the overall and partition information of various hard disks. "/dev/SDA" is the original hard disk device, and "/dev/SDB" is the new hard disk, the new hard disk device has not been initialized and does not contain valid partition information. For existing partitions, the following information is output through the list.

Device: Name of the partition device file.

Boot: Whether it is a boot partition. If yes, It is identified.

Start: The starting position (number of cylinders) of the partition in the hard disk ).

End: End position of the partition in the hard disk (number of cylinders ).

Blocks: Partition size, in blocks (Block). The default block size is 1024 bytes.

ID: ID mark of the partition type. For ext3 partitions, the value is 83, and the value of LVM partitions is 8e.

System: Partition type

 

After identifying a new hard disk device, you can create a new partition on the hard disk. In Linux, the partitioning and formatting processes are relatively independent.

 

Plan partitions in the hard disk

 

To create, delete, or change a partition on a hard disk device, run the fdisk command as long as the device file on the hard disk is used as the parameter. For example, run the "fdisk/dev/SDB" command to enter the interactive partition management interface.

650) This. width = 650; "Title =" image002.png "alt =" wkiom1povu_jfiojaaiqp1saogs459.jpg "src =" http://s3.51cto.com/wyfs02/M02/40/48/wKiom1POVu_jfIojAAIqP1SAOgs459.jpg "/>

P -- list partitions in a hard disk

The "p" command can be used to list detailed partition information. The display format is the same as that of fdisk-L. Partition has not been created in the hard disk, so the output information is empty.

650) This. width = 650; "Title =" image003.png "alt =" wKiom1POVv_Ra-5VAADPle_iME8886.jpg "src =" http://s3.51cto.com/wyfs02/M02/40/48/wKiom1POVv_Ra-5VAADPle_iME8886.jpg "/>

N -- create a partition

You can use the "N" command to create partitions, including primary partitions and extended partitions. "P" creates a primary partition, "E" creates an extended partition, and "L" creates an extended partition, and then selects the partition sequence number, starting position, and ending position, or partition size to create a new partition.

To create a logical partition, you must have an extended partition.

When you select a partition number, the sequence numbers of the primary and extended partitions can only be 1 ~ 4. the start position of a partition is identified by default. The ending position or size can be in the form of "+ size" or "+ sizek.

Create a 20 GB partition as follows:

650) This. width = 650; "Title =" image004.png "alt =" wkiol1powcszs39saadsgvpmeb0070.jpg "src =" http://s3.51cto.com/wyfs02/M00/40/48/wKioL1POWCSzs39SAADsGVPMeB0070.jpg "/>

D -- delete Partition

You can use the "D" command to delete a specified partition. Follow the prompts to enter the sequence number of the partition to be deleted. Note that if an extended partition is deleted, the logical partitions under the extended partition are also deleted. Therefore, we recommend that you delete the last partition.

650) This. width = 650; "Title =" image005.png "alt =" wkiol1powdddb5awaabpvwasdtk107.jpg "src =" http://s3.51cto.com/wyfs02/M02/40/48/wKioL1POWDDDb5AWAABPvwAsDtk107.jpg "/>

T -- change partition type

The default file system used for the new partition is ext3, which does not need to be changed. However, if the new partition needs to be used as a swap partition or another type of file system, you need to change the partition type to maintain consistency.

Change the ext3 partition to swap.

650) This. width = 650; "Title =" image006.png "alt =" wkiom1povx7airsuaaf_pwf3s7y778.jpg "src =" http://s3.51cto.com/wyfs02/M02/40/48/wKiom1POVx7AirSUAAF_PwF3s7Y778.jpg "/>

W and Q -- exit the partition

W command to save the partition operation

The Q command does not save partitions.

 

After changing the partition settings of the hard disk (especially the hard disk in use), we recommend that you restart the system once or execute the "partprobe" command to check the operating system for new partition tables. In some Linux operating systems, if you do not perform these operations, the existing data in the hard disk may be damaged during partition formatting, which may cause serious or even system crashes.

 

Create a File System

After creating a partition in Linux, you also need to format the partition and mount it to the specified directory in the system before it can be used to store files, directories, and other data.

 

The process of creating a file system is the process of formatting partitions. in Linux, you can use the mkfs command tool to format partitions of different types, such as ext3 and FAT32, and use the mkswap command to create swap partitions.

 

When using the mkfs command program, the basic command format is as follows.

Mkfs-T file system type partition Device

 

The command for creating an ext3 file system is as follows:

 

Mkswap can be used to create an swap file system on a specified partition. the ID of the destination partition is 82.

Command Format:

650) This. width = 650; "Title =" image007.png "alt =" wkiol1powhkqzwv0aaiklll4eba653.jpg "src =" http://s3.51cto.com/wyfs02/M00/40/48/wKioL1POWHKQZWv0AAIKLll4ebA653.jpg "/>

For the newly added swap partition, use the Swapon command to enable it. Otherwise, use the swapoff command to disable the specific swap partition.

650) This. width = 650; "Title =" image008.png "alt =" wkiol1powiwsym4jaabvm4htpcm980.jpg "src =" http://s3.51cto.com/wyfs02/M01/40/48/wKioL1POWIWSYm4jAABvm4hTpcM980.jpg "/>

Mount a File System

During the installation of the Linux operating system, partitions automatically created or identified are usually automatically mounted by the session system. For example, "/" partition and "Boot" partition. However, for the new hard disk partition, USB, CD and other devices, the Administrator sometimes needs to manually mount them. In fact, the user accesses the file system created after formatting. When mounting a partition, you must specify a directory as the mount point for it. You can use this directory to access files and directory data in the device.

 

Mount [-T file system type] storage device mount point

The mount command is as follows:

650) This. width = 650; "Title =" image009.png "alt =" wKiom1POV33hLsOiAAB-RqVM2Dg473.jpg "src =" http://s3.51cto.com/wyfs02/M00/40/48/wKiom1POV33hLsOiAAB-RqVM2Dg473.jpg "/>

 

Detach a File System

When you need to uninstall the file system, the command used is umount, And the mount point directory or the file name of the corresponding device is used as the unload parameter.

The command is as follows:

 

650) This. width = 650; "Title =" image010.png "alt =" wkiom1pov4fwm6kaaabxplk6cze937.jpg "src =" http://s3.51cto.com/wyfs02/M01/40/48/wKiom1POV4fwm6kAAABXpLK6czE937.jpg "/>

Set automatic file system mounting

In the/etc/fstab file in the system, each row records the mounting configuration information of a partition or device. The number from left to right contains six fields. The meanings of each part are described as follows.

650) This. width = 650; "Title =" image011.png "alt =" wkiol1powkucu42vaaeletbuy1_657.jpg "src =" http://s3.51cto.com/wyfs02/M02/40/48/wKioL1POWKuCu42VAAELEtBUyjw657.jpg "/>

Field 1: device name or device volume name

Field 2: Location of the mount point directory of the file system

Field 3: file system type, such as ext3 and swap

Field 4: Mount parameters, which can be used after the "-o" option of the mount command, such as ults and RW.

Field 5: indicates whether the file system needs dump backup (dump is a backup tool). Generally, if it is set to 1, it indicates yes. If it is set to 0, it will be ignored by dump.

Field 6: This number is used to determine the sequence of disk checks when the system starts. 0 is not checked, 1 is preferred, and 2 is secondary. Set the root partition to 1 and other partitions to 2.

 

By adding the corresponding mounting configuration to the/etc/fstab file, you can automatically mount the specified partition after the boot.

As shown in the following figure, it is the configuration record for adding/dev/sdb1 automatic mounting. (Use VI to modify)

650) This. width = 650; "Title =" image012.png "alt =" wkiom1pov56zdd24aae452xkuwg814.jpg "src =" http://s3.51cto.com/wyfs02/M02/40/49/wKiom1POV56zDD24AAE452XkUWg814.jpg "/>

View disk usage.

To learn about the disk usage of the mounted file system in the system, run the DF command.

-H: displayed in more readable capacity units

-T: displays the type of the corresponding file system.

650) This. width = 650; "Title =" image013.png "alt =" wkiol1powmphb1sxaad2gc8chzy782.jpg "src =" http://s3.51cto.com/wyfs02/M00/40/49/wKioL1POWMPhB1sXAAD2gC8ChZY782.jpg "/>

 

This article from the "plum blossom from bitter cold" blog, please be sure to keep this http://wangjunkang.blog.51cto.com/8809812/1441519

Disk and file system management

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.