Use commands to partition Linux (CentOS)

Source: Internet
Author: User
After the Linux (CentOS) partition server supplier gave the linux server a command, it was found that the partition with root and data is too small, only about 300 GB, but the home is as high as GB, space Utilization is very problematic. Therefore, try to partition again. However, it is difficult to repartition Linux. However, you can use commands to partition Linux (CentOS ).
After the server supplier gave the linux server, it was found that the partition with root and data is too small, only about 300 GB, while/home is as high as GB, which is very problematic in space utilization. Therefore, try to partition again. However, it is very troublesome to repartition Linux. However, as long as you follow the steps below, there is generally no problem. However, please note that if your system is running and there is already a lot of data, we recommend that you back up the data first, just in case. Furthermore, the partition you want to adjust must not be larger than the space occupied by the original file. otherwise, data will be lost !!! In the following example, we can see that the default partition is unreasonable./root only has around 300 GB, while/home has about GB: first, you can run the following command to view the status of your partition: [root @ localhost ~] # Df-h (view partition status) file system capacity used available % mount point/dev/mapper/VolGroup-lv_root 154G 7.9G 139G 6%/tmpfs 1.9G 100 K 1.9G 1%/dev/shm/dev/sda1 485 M 69 M 391 M 15%/boot/dev/mapper/VolGroup-lv_home 299G 984 M 283G 1%/home because we want to narrow down/home, uninstall/home first: [root @ localhost ~] # Umount/home (uninstall/home) [root @ localhost ~] # E2fsck-f/dev/mapper/VolGroup-lv_home (check for errors in VolGroup-lv_home files,-f forcibly checks correctness even if the file system shows no signs of errors .) E2fsck 1.41.12 (17-May-2010) Step 1: Check inode, block, and size Step 2: Check directory structure Step 2: check Directory connectivity Pass 4: Checking reference counts Step 2: check the cluster profile information/dev/mapper/VolGroup-lv_home: 21/19857408 files (0.0% non-contiguous), 1498180/79429632 blocks because/home only installs the system, so there is no need for too much space, we decided to adjust it to a small value: [root @ localhost ~] # Resize2fs-p/dev/mapper/VolGroup-lv_home 20G (adjust mapper/VolGroup-lv_home file size to 20G) resize2fs 1.41.12 (17-May-2010) resizing the filesystem on/dev/mapper/VolGroup-lv_home to 5242880 (4 k) blocks. begin pass 2 (max = 32778) is re-positioning the block; pass 3 (max = 2424) is scanning the inode table; pass 4 (max = 10) is updating inode reference XXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXThe filesystem on/dev/mapper/VolGroup-lv_home is now 5242880 blocks long. [root @ localhost ~] # Mount/home (mounted on/home) [root @ localhost ~] # Df-h (view partition status) file system capacity used available % mount point/dev/mapper/VolGroup-lv_root 154G 7.9G 139G 6%/tmpfs 1.9G 100 K 1.9G 1%/dev/shm/dev/sda1 485 M 69 M 391 M 15%/boot/dev/mapper/VolGroup-lv_home 20G 962 M 18G 6%/home [root @ localhost ~] # Lvreduce-L 20G/dev/mapper/VolGroup-lv_home (lvreduce command is used to reduce the space occupied by LVM Logical Volumes. The existing data on the logical volume may be deleted, so you must confirm before performing the operation .) WARNING: switching active and open logical volume to 20.00 GiB this may destroy your data (filesystem etc.) Do you really want to reduce lv_home? [Y/n]: y Cing logical volume lv_home to 20.00 GiB Logical volume lv_home successfully resized [root @ localhost ~] # Df-h (view partition status) file system capacity used available % mount point/dev/mapper/VolGroup-lv_root 154G 7.9G 139G 6%/tmpfs 1.9G 100 K 1.9G 1%/dev/shm/dev/sda1 485 M 69 M 391 M 15%/boot/dev/mapper/VolGroup-lv_home 20G 962 M 18G 6%/home [root @ localhost ~] # Vgdisplay --- Volume group --- VG Name VolGroup System ID Format lvm2 Metadata Areas 1 Metadata Sequence No 7 VG Access read/write VG Status resizable max lv 0 Cur LV 3 Open LV 3 Max PV 0 cur PV 1 Act PV 1 VG Size 465.27 GiB PE Size 4.00 MiB Total PE 119109 Alloc PE/Size 46660/182 .27 GiB Free PE/Size 72449/283 .00 GiB vg uuid gPA8XS-ZncK-mGQj-2Vn9-TFTQ-6yOU-6atjE9 [root @ localhost ~] # Lvextend-L + 283G/dev/mapper/VolGroup-lv_root (lvextend command: extended logical volume space) Extending Logical volume lv_root to 439.39 GiB logical volume lv_root successfully resized [root @ localhost ~] # Resize2fs-p/dev/mapper/VolGroup-lv_rootresize2fs 1.41.12 (17-May-2010) Filesystem at/dev/mapper/VolGroup-lv_root is mounted on/; on-line resizing requiredold desc_blocks = 10, new_desc_blocks = 28 faster Ming an on-line resize of/dev/mapper/VolGroup-lv_root to 115183616 (4 k) blocks. the filesystem on/dev/mapper/VolGroup-lv_root is now 115183616 blocks long. now check the adjustment result: [root @ localhost ~] # Df-H file system capacity available in use % mount point/dev/mapper/VolGroup-lv_root 433G 7.9G 403G 2%/tmpfs 1.9G 100 K 1.9G 1%/dev/shm /dev/sda1 485 M 69 M 391 M 15%/boot/dev/mapper/VolGroup-lv_home 20G 962 M 18G 6%/home [root @ localhost ~] # This operation is smooth, saving time for reinstallation.
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.