[Centos-1] centos7 mounts the hard disk and allocates space to the home directory

When I was using centos recently, I found that the hard disk was installed but not mounted. Finally, the /home space was not enough to save files. So with this article.

aims:

  • Two situations of hard disk mounting

  • Format a new hard drive

  • Mount the new space to the specified node

Two situations of hard disk mounting

  • The first is to directly add a new hard disk and then mount it.

  • The second type is to expand the hard disk, partition the expanded space and then mount it.

Case 1: New hard disk mounting process

After inserting the new hard disk, enter fdisk -l command to see the current disk information

img

You can see that under /dev/sdb, it is a newly added hard disk device, enter fdisk /dev/sdb to partition sdb

Enter the fdisk command, enter h to see the help of the command, press n to partition (that is NEW)

img

Enter e here to divide it into logical partitions, and press p to divide it into primary partitions. We want to divide this disk into primary partitions and enter p.

(Logical partition:; Primary partition: also called boot partition, up to 4 may be created. When four primary partitions are created, extended partitions can no longer be created, and of course there is no logical partition; extended partitions: except for primary partitions , The remaining disk space is the extended partition. The extended partition is a concept and is actually invisible.)

img

Here, enter the primary partition as the first partition. Since it is a new disk, we enter 1 to divide the first primary partition

img

img

The next step is to define the size of the partition. If you press the default (press Enter) to use all available storage, it can also be a number ending in M ​​or m (uppercase M means big B, if you enter 1M actually It is X8, which is 8m space), here we first divide a 1G space, so after entering +1024m, enter w to write into the partition, and wait for the end

img

Then enter fdisk -l to see the partition we just divided, and then format it with: mkfs -t ext3 -c /dev/sdb1, if there are multiple partitions, change sdb1 to sdb2 sdb3..., use fdisk -l see the name of each partition

img

After formatting, you can write the volume label of the hard disk. If you don’t want it, just press Enter to partition. Use mount to mount the partition and you can use it. Here I mount it in the mnt directory, or you can create a directory by yourself. Mount, such as /home. After mounting, it is performed by the ROOT user, and other users need to adjust the directory permissions when storing!

img

To see if the partition size is the same as the scheduled one, use the df -TH command to see the currently mounted partition and size (the picture is not fully displayed)

img

If you want to automatically mount the partition every time the system restarts, you can modify the /etc/fstab file and add at the end:

/dev/sdb1 /mnt ext3 defaults 1 2

PS: The role of this piece is doubtful, there is no specific verification function

(Format description: /dev/sdb1 represents which partition, /mnt is the mount directory, ext3 is the format of the partition, defaults is the parameter to be set when mounting (read-only, read-write, enable quota, etc.), enter defaults Included parameters are (rw, dev, exec, auto, nouser, async), 1 is whether to use dump to record, 0 is not. 2 is the order of checking when booting, it is 1 for boot system files, other file systems are all Is 2, if not checked, it is 0)

Case 2: The expanded hard disk is mounted to the designated node

It is recommended that if you want to expand the data that already exists in the node, then this method will cause the loss of node data, and this method is only suitable for a newly configured environment.

1. View basic information

fdisk -l check the current space situation, and found that there is 120G space under /dev/sda that is not used, as shown in the figure below, sda1-》sda7 is the hard disk partition that has been mounted now.

uploading.4e448015.gifUploading... re-upload canceled

2. Partition the expansion space

Similar to the first case, run fdisk /dev/sda

According to the help prompt, type: n to add a new partition

At this point, fdisk will let you choose to add as a logical partition (numbering starts from 5) or a primary partition (numbering 1 to 4). Generally, there is no requirement, just default.

At this point, fdisk will ask you to select the number of the primary partition, because it has been said that there are primary partitions sda1 and sda2, then the number is 3, that is, the partition to be created is sda3. Type: 3

Then select the start value of the partition: it is the Start value (start cylinder) of the partition; press Enter here directly, if you enter a non-default number, it will cause a waste of space; type: w

Save all and exit, partition is completed

3. Specify the file system type

Note: It must be restarted. Here, fdisk -l can see that the related operations have been completed, but in fact it cannot be recognized, which will cause errors:

Run the command mkfs -t ext3 /dev/sda3 where ext3 is the partition format, other formats can also be selected. If there is no mkfs function, you can add it and install it, as well as related format types.

4. Mount the file system

Hanging directly under /home will cause data loss on the /home node. Therefore, creating a new directory under /home can expand the capacity.

Create a directory to be mounted: mkdir /home/work

Mount the partition to the directory: mount /dev/sda3 /home/work

5. Auto mount at boot

Step 4 is to manually mount the file system, and now I want to automatically mount the file system when I boot up in the future

Edit: vi /etc/fstab

Add a sentence at the end of the file: /dev/sda3 /home/work ext3 defaults 0 1

 

Save and exit. OK, you can store things in the /home/work folder in the future, that is, they will be stored on the newly added hard drive.

Note: In fact, the partition mounting of the expanded hard disk is similar to the newly mounted hard disk, that is, continue to partition the expanded space, and everything else is the same.

Note: The mounting is carried out by the ROOT user, other users need to adjust the permissions to store files in the mounting directory

 

If you have tried it, or if you have any questions, you can leave me a message!

Guess you like

Origin blog.csdn.net/u010472858/article/details/104809919