Centos disk management (advanced tutorial)

Source: Internet
Author: User

Command for creating a partition:

Command Format: fdisk + device type can create up to 15 partitions

12 # fdisk-l ------ // list the partition information of all disks # fdisk-l/dev/sda ---- // view the partition information of the sda Disk

Figure 1

123456 Linux: Sda [1-4] S (interface type) da1: first primary partition Sda2: Second Primary partition Sda3: Third Primary partition Sda4: fourth primary Partition

Sda5: the first logical partition, the extended partition must start from 5, and the 5 is the marker of the logical partition.

Command Format: fdisk-l/dev/[sh] d [0-9]

Figure 2

12345d delete a partition ------ // delete a partition n add a new partition ----- // create a partition p print the partition table ---- // display the information of the current partition w write table to disk and exit ---- // save and quit q quit without saving changes ---- // do not save and quit

System ID ---- indicates the partition type related to the operating System.

To Format a partition into a file system, make sure that its partition ID matches the file system type.

L list known partition types-system ID corresponding to multiple partition types-that is, the file system type.

83 ---- Linux

82 ---- Linux swap/So

8e ---- Linux LVM logical volume

85 ---- Linux extended

Fd ---- Linux raid auto soft RAID Software Raid

12 t change a partition's system id // modify the system ID a toggle a bootable flag of a specified partition // set the enable flag (set this partition to enable the OS

Area) ------ it is rarely used. Just understand it.

Figure 3

Save and exit

Figure 4

Create two 6 GB partitions:

Figure 5

: There is only one primary Partition Number. To create any two more partitions, you must create an extended partition and create a new logical partition in the extended partition.

Therefore, create an extended partition first.

5 must be 5 under 4, and all logical partitions must be created under extended partitions. This is very important! The start and end columns here can use the default one. You must add the remaining space to the extended partition, because if you do not give the extended partition, it will never be used. This is especially important for beginners!

Figure 6

Figure 7

If an error is written in the middle, press ctrl and press tab to delete the error command!

Extended partitions cannot be used directly. Therefore, new partitions must be added.

A hard disk can only have one extended partition! Remember this!

Figure 8

Add 6 GB logical partitions

Figure 9

The above two partitions are all created in the extended partition! Are you clear?

Therefore, logical partitions must be created within the extended partitions!

If you do not want to delete a partition, you can use dl to delete it. In this case, can partition 4 be deleted directly?

Figure 10

It seems that partitions 5 and 6 also disappear with the deletion of extended partitions!

Therefore, be cautious with this operation!

At this time, the only solution is q ------- quit without saving it ~

Because our kernel has not been formatted into partitions, that is to say, all operations before you are ready are considered invalid !!!

So sometimes it's like this !!!!!

Figure 11

After the partition is created, you can use fdisk-l to view all the partition information in the system.

Figure 12

Can fdisk identify so many partitions that the inner nuclear energy can recognize? The kernel is used to deal with hardware !!!!

If the kernel cannot identify it, it means there is no such hardware device!

View the partition information identified by the kernel:

1 # cat/proc/partitons

Figure 13

Can the software recognize and the kernel cannot recognize it? What should I do?

Any program must modify the hardware through the kernel. It must be synchronized to the running kernel for Kernel recognition! The problem is how to synchronize data?

Note: commands for RHEL5.0 and RHEL6.0 synchronization are also different.

View test machine version information:

1234 # cat/etc/issue # lsb_release-a # cat/proc/version # uname-

Figure 13-1

RHEL5 re-reads the hard disk partition table from the kernel:

Partprobe [Device] -- Re-test

You can specify a device to test. If this parameter is not specified, all devices are detected by default.

Figure 14

Reading failed. It is invalid before restart.

Not Read

RHEl6 use another command

RHEL6 re-reads the hard disk partition table from the kernel:

123456 partx-a [partition] device # man partx-a add specified partitions or read disk and add all partitions. read all-l list partitions. note that the all numbers arein 512-byte sectors.

1 # cat/proc/partitions

--- The kernel will format partitions only when the command displays information about each partition. Otherwise, all partitions are invalid! Remember !!!

Figure 18

Manually adding one by one seems to be able to be added, but an error will still be reported! I don't know if it is a kernel issue.

OK. The kernel has been recognized!

Figure 19

OK. All partitions have been created. How can we implement this and store files in the partitions? How can we use this partition? What operations do we need next?

Format the partition to create a file system.

There is no way to create a file in the file system! Why? Because it is a bare device! Haha 1

Linux partition creation command:

Two-step implementation: Specify the partition type and partition object

Note: Extended partitions cannot be formatted. Remember!

Format/dev/sda3 partition type to ext4

Figure 20

Display/dev/sda3 partition attributes

Figure 21

UUID --- indicates a globally unique ID. It is a column of random strings that can be used to manage Hard Disk Partitions when the number of hard disks is large in the future. Therefore, each partition creates a globally unique identifier.

Blkid: displays the UUID and file system type of the device.

Note: Extended partitions cannot be formatted.

123456 # mkfs-t ext4/dev/sda3 = mke2fa-t ext4/dev/sda3 # mkfs-t ext3 = mkfs. ext3 = mk2efs-j = mke2fs-t ext3 # mkfs-t ext4 = mkfs. ext4 # mkfs-t ext2 = mkfs. ext2 = mke2fs # mke2fs-t {ext2 | ext3 | ext4} # blid/dev/sda3 blkid device displays the UUID and file system type of the device.

Uuid is used to identify the Globally Unique ID number. It is a series of random numbers. A supercomputer has thousands of Mount partitions. How can we identify these tens of thousands of partitions? Sda and sdb may conflict with each other.

Therefore, a globally unique random ID is created for each partition. The possibility of repetition is very small, like Halle's star hitting the Earth. No matter which host the hard disk is placed on, the possibility of duplication is almost nonexistent.

# Man mkfs

-T fstype

# Mke2fs-t ext4/dev/sda3

Mke2fs-create an ext2/ext3/ext4 filesystem

Mke2fs-B {1024 bytes, 2048 bytes, 4096 bytes default}

Figure 22

Configuration File: vim/etc/mke2fs. conf is used to set the default features and the unique default features of each file system.

1 # mke2fs-t ext4-b2048/dev/sda3

------ B specifies the block size. The default value is 1kb, 2kb. 3kb.

What does block size mean?

The block size depends on the CPU's support for the memory leaf size. Generally, the X86 Memory Page is 4 kb. The default value is 4096.

View disk partition attributes

123 # tune2fs-l devcie | grep "Block size" # tune2fs-l/dev/sda3 Block size: 4096 # tune2fs-l/dev/sda3 | grep "Block size"

Figure 23

Note: a) a block can only belong to one file.

B) if the block size is too large, the disk space will be wasted.

C) The Block Size is determined by the files to be stored in the future.

D. Only disk partitions can be formatted to change the block size.

-L --> new-volume-label: Set the volume label

Set the volume label for the filesystem to new-vol-

Ume-label. The maximum length of the volume label

Is 16 bytes.

12 # mke2fs-t ext3-b1024-L mytest1/dev/sda3 note: the smaller the block, the longer the formatting time

To display the block size

1 # Tune2fs-l device | grep "Block size"

Figure 24

-L specify the volume label and set the volume label

Using the volume label or UUID is one of the best ways to avoid cross-reference!

The volume tag may be repeated. Use UUID!

# Mke2fs-b1024-L mytest1/dev/sda3

Note: the smaller the block, the longer the formatting time!

Figure 25

1 # blkid/dev/sda3 can also display LABEL information

Figure 26

What will happen if a hard disk is filled up?

# Tune2fs-l/dev/sda3 | grep "Reserved" view default Reserved disk space

Figure 27

1 # echo $ [2, 577085/11541700]

[Root @ localhost ~] # Bc

577085/11541700

0

Scale = 2 set precision

577085/11541700 */

. 05 = 5% retain 5% of the total disk space. 5% GB reserved is 10 GB

[-M reserved-blocks-percentage] ratio of the block reserved for management to the total block.

12 # mke2fs-t ext4-b2048-m3-L mytest1/dev/sda3 # tune2fs-l/dev/sda3 | grep "Reserverd"

Figure 28

Figure 29

Figure 30

As the block size changes, the reserved space changes significantly.

The difference between mke2fs and tune2fs is equivalent to useradd and usermod. Do you know this?

Modify partition attributes

Reset the volume label:-L

123 # blkid/dev/sda3 # tune2fs-L test2/dev/sda3 # blkid/dev/sda3

Figure 31

Adjust the block size:-m

12 # tune2fs-m5/dev/sda3 # tune2fs-l/dev/sda3 | grep "Reserved"

Figure 32

12 # tune2fs-m1/dev/sda3 # tune2fs-l/dev/sda3 | grep "Reserved"

Figure 33

12345-o: Set the default Mount Option-O: set the default features of the file system-r adjust the number of blocks reserved for management-E set the extended attributes of the file system-l display the file system super block information

E2label display set volume label

123 # e2label/dev/sda3 # e2label/dev/sda3 test3 # e2label/devsda3

Next

Mount

Concept: attaching is actually a process of association.

FileSystem: a software that is implemented in the kernel

Format: mount-t filesystem options device mount-point

Mount Option:

123456789101)-o: used to specify the mounting option 2) ro: Read-Only mounting 3)-n does not update the/etc/mtab file when mounting the file system 4) rw: read/write, the default value is read/write. 5) noatime: Disable the access time update function. 6) auto: whether the access time can be mounted by "mout-a". 7) -r is equivalent to "-o ro" Read-Only mounting 8) defaults: equivalent to rw, suid, dev, exec, nouser, auto, async, and realatime9) sync synchronous write, poor performance, CPU to memory 10NS, CPU to hard disk 100NS10) async asynchronous write, most of which are asynchronous, good performance

Sync is saved in memory, files are edited and read into memory first, and files are edited in memory.

The mount [-t filetype] system will call blkid to automatically identify the file type. This option can omit the mount point of the mounting device.

1) create a blank directory

123456 # mkdir/test_m1 # cp/etc/inittab/test_m1 # cp/etc/fstab/test_m1 # cp/etc/rc. d/rc. sysinit/test_m1 # cp/etc/rc. d/init. d/functions/test_m1 # ls/test_m1

2) Mount and establish Association

12 # mount-t ext4/dev/sda3/test_m1/# ls/test_m1/

The original file is missing. Why?

3) unmount, that is, detach

You only need to specify a project when uninstalling, either a mount point or a partition name.

4) use the volume label for mounting

12 # e2label/dev/sda3 # mount LABEL = "test2"/test_m1/



6. unmount umount/test_m1/using the volume label/

LABEL = "volume LABEL"

7) mount with UUID

UUID = "UUID"

12 # blkid/dev/sda3 # mount UUID = "a54233f0-51c0-4f30-9a0f-eea4c0999f49"/test_m1/

1 # mount ------> display all devices mounted by the current system

/Etc/fstab ------> file system automatically mounted at the system startup

Note: The logical volume is not displayed on fdisk-l RHEL5.

Fdisk-l RHEL 6 displays all Disk Partitions

Fdisk-l/dev/[hs] d [a-z]

12 mount: // associate a file system with the root file system. mount: // display all mounted devices.

12 # cat/etc/mtab tracks all files mounted to the file system on the current system and updates them at any time. # Umount/dev/sda3

1 # cat/etc/mtab12 # // fuser is used to display the process that is accessing a file # fuser/media/-km forces the process that is accessing this mount point to be used with caution!

Defines the disk write policy in the kernel, which is maintained by the kernel itself.

12345678910 # remount: remount # mount-o remount, ro/dev/sda3 as long as it has been mounted before, you do not need to re-specify the mount point loop: local loopback device, actually not a device, is a file mount-o remount, other_options devicemount-o loop, other_options device mount point is used to mount the loopback device-n: Do not update the cat/etc/mtab file-r when mounting the file system: it is equivalent to "-o, ro" mounting fuser [mount_point] Read-Only. // view the process of accessing the mount point fuser-km [mount_point] // forcibly killing the process that is accessing the mount point

1 #/etc/fstab // six fields separated by blank characters

12345678910111) mounted devices: Device Files, Volume labels, UUID (many storage devices can be used on the server) 2) mount point (must be an empty directory) 3) file system type: ext2, ext3, ext4 ..... 4) Mount Option: defaults indicates that the default option is used. Multiple options are separated by commas. Dumping frequency: the backup frequency (that is, the time when a backup is performed). 0: Never backup, by default, this option can be set to 1: daily backup 2. Backup every other day 5) self-check order-perform file system detection (if the file system is inconsistent) 6) define the self-check order:

Ext3 Log File System

0: No Detection

1. First check: Generally, only the root file system is detected first. Generally, only the root file system is 1.

12342-9 one by one check # vim ++ // open the file directly and locate the last line # vim +/etc/fstab # press the lowercase letter o, create a new row in the row where the current cursor is located and convert it to the input mode

12a) the above operations can only be automatically mounted at the next boot! B) the following operations are immediately mounted to the associated Directory, which can be used at any time!

1 # mount-a // mount/etc/fstab all file systems supporting auto mount Selection

SWAP partition in Linux: SWAP

1) create a swap Partition

123 mkfs-t [fstype] partition1. The file system must be supported by the kernel before it can be used. That is, the kernel has a corresponding kernel module or has been compiled into the kernel; 2. You must have a file system creation tool, mkfs. fstype, one-to-one correspondence with Kernel Modules


Enable swap Partition

123 # mkswap device // enable swap partition # swapon device // enable specified swap partition # swapoff-a // enable all swap partitions

Disable swap Partition

123 # swapoff device # swapopp-a # enable swap partition at startup, which can be written to/etc/fstab

Pay attention to the following two points during mounting:

121) Fill in swap2 for the mount point) Fill in swap for the file system type

Write partition information to the kernel

Create swap Partition

Set automatic mounting upon startup

Complete!

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.