centos linux lvm partition standard partition disk expansion

1. Disk partitioning during Centos installation

  1. Select disk partition
    Insert image description here

  2. Select the partitioning method:
    automatic partitioning is the least labor-intensive. After selecting, click done to complete the partition configuration;
    manual partitioning requires configuration, and generally reserves "/boot" (boot startup), "/swap" (memory expansion), and "/" Root directory
    Insert image description here

  3. Looking at manual partitioning, you can use LVM partitioning or standard partitioning "Standard Partition".
    Taking LVM as an example, select I will configure partitioning, click Done in the upper left corner, and enter the following picture configuration page.
    Insert image description here

  4. Click the plus sign, add swap with a size of 2 GB, then add /boot with a size of 2 GB, and then add / to allocate the remaining disk space. If the space is not that big, /boot can be configured with 200M, and swap can also be configured smaller.
    Insert image description here

  5. Click the plus sign three times, add "/boot", "/swap", and "/", click Done in the upper left corner, wait for the SUMMARY OF CHANGES interface to pop up, and click Accept Changes
    Insert image description here

Now that the disk partitioning is complete, all that is left is to install it yourself.
Log in to the system and execute df -h to see that the boot and root directories are mounted.
Insert image description here

2. Re-allocate disk partitions after selecting automatic partitioning

I selected automatic partitioning during installation. After installation, I feel that it does not meet my needs. Can I redistribute it?
Of course you can, provided you haven't written data into it yet, otherwise your data will be gone after repartitioning.
During automatic partitioning, if the disk exceeds 50G, the extra part will be mounted to "/home". If you want to mount it to "/", you need to manually expand it yourself.

Standard partition disk expansion

Use df -h to see that there is 400G space. The root directory is 50G and the home directory is 350G. Now allocate all the space to the root directory.
Insert image description here

Partition steps:

  1. Unmount the home partition
    umount /home
    Insert image description here

  2. fdisk /dev/sda Enter the disk configuration interface
    p View the corresponding partition
    d Delete the partition corresponding to /home (second partition, enter 2)
    d Delete the partition corresponding to / (third partition, enter 3)
    n Create a new partition and allocate all remaining space, please note that the starting position must be consistent with the starting position of the original root partition.
    w write save and exit
    Insert image description here

  3. Edit the vi /etc/fstab file and comment out the /home configuration
    Insert image description here

  4. Restart the virtual machine

  5. Use xfs_growfs to resize the file system: xfs_growfs/

LVM partition disk expansion

For example, as shown in the figure below, I have 400G space. df -h shows that the root directory is 50G, and the rest are in the home directory. Now I want to delete home and allocate all the space in home to the root directory.
Insert image description here

How to determine whether your partition is a standard partition or an lvm partition?
I figured it out at a glance. The file system is /dev/mapper/xxxxx, which is the lvm partition format.
Insert image description here

lvm partition steps:

Uninstall "/home"

umount /home

Delete home partition space

lvremove /dev/mapper/centos-home

Add space to the root directory

lvextend -L +344G /dev/mapper/centos-root 

I only added 344 to the remaining 345. For a big family, the extra is not enough for 1G, so I don’t want it.
Insert image description here

  1. df -hT checks that the format of / is xfs. At this time, the root directory is still only 50G.
    Insert image description here

  2. It cannot take effect immediately after adding it. You need to initialize the partition xfs_growfs /dev/mapper/centos-root.
    Insert image description here

  3. After taking effect, check df -h again and you will see that the root directory has become 394G.
    Insert image description here

    Compare and see
    Insert image description here

  4. After we have uninstalled the home partition, we need to shield the home partition in the /etc/fstab file. Otherwise, home will be loaded when the system restarts. If you delete home, the system cannot find it and you will not be able to boot.
    vi /etc/fstab, after commenting: wq, just save and exit.
    Insert image description here

Guess you like

Origin blog.csdn.net/forlorn_mere/article/details/131640330