How to adjust the size of Linux Disk Partitions

Source: Internet
Author: User

Adjust the size of Linux Disk Partitions when using linux, sometimes some partitions are insufficient due to improper partition space during system installation, and some partition space is too large. for example, I installed the/usr/local distributor with 5 GB space. However, after a while, I found that/usr/local only used 1 GB space at most. in this way, the/usr/local size can be adjusted to 1 GB. 4G blank for use. this article summarizes how to adjust the file system size without breaking the file system data. here, we use the "Remove east wall and add west wall" method. of course, if your disk has unpartitioned free space, you do not need to reduce the space of a partition. preparation for www.2cto.com (I) backup first, set up the files in the partition to be changed for backup. disk operations may cause data loss. before getting started, it is best to save important data to another partition. (2) obtain relevant information. 1. run $ df to view the file system information. write down the mount points and Device Files corresponding to the partition you want to adjust. Www.2cto.com is used to check which device file in/usr/local corresponds to/dev. this document uses/dev/hda7 as an example. 2. Run # sudo fdisk/dev/sda. enter fdisk and press p to view disk partition information. write down the start and end Cylinder Number of/dev/sda8. set them to start and end respectively. and how many bytes does the Unit contain. note: The file system size and disk partition size cannot be the same: At least their measurement units are different. in a file system, the Unit is KB, MB, and GB. however, in fdisk, it is calculated based on the disk's "unit" value (that is, the number of bytes contained in a cylindrical disk. after we run # fdisk/dev/sda, fdisk displays the following information: Disk/dev/sda: 163.9 GB, 163928604672 bytes255 heads, 63 sectors/track, 1 9929 cylindersUnits = cylinders of 16065*512 = 8225280 bytes (3) Calculate the end cylindrical number e. g: the size of the original/usr/local is 5000 MB, the start cylinder number is 2550, and the end cylinder number is 3157. now I want to change its size to 1000 MB, so we should calculate the end cylindrical number ([3.2] = 4): End cylindrical number = 2550 + [(1000*1024*1024) /8225280] = 2678 use fdisk to delete the original partition (data in the previous partition will not be lost !). Then create a new partition. The only difference between the new partition and the old partition is that the partition size is different, which is manifested in the fact that they terminate different cylindrical numbers. increase partition size: the ending cylinder number is set to the last Cylinder Number of the free space. reduce partition size: the ending cylinder number is calculated. before starting the adjustment, it is best to take a piece of paper to note the following information about the partition to be adjusted: adjust the size before and after the adjustment. the directory to which it is mounted and the device in/dev. start and end the cylinder. e. g: Before adjustment: 5G, after adjustment: 1G, mount point:/usr/local, corresponding to/dev/hda7. start, end cylinder is 2550,315 7. 1. It is best to detach a partition when runlevel is 1. # umount/dev/2, check file system consistency # fsck-n/dev/3, for example, ext3 system, also remove logs # tune2fs-O ^ has_journal/dev/Note: The ext3 system after the log is retrieved is Unable to mount. Use # tune2fs-j/dev/to re-create the log. 4. Adjust the file system size # resize_reiserfs-s 1000 M/dev/hda7 after adjusting the file system size, run the following command to perform a comprehensive check on the file system: # reiserfsck -- check -- fix-fixable/dev/hda7 5, enter fdisk, and adjust the partition size. # fdisk/dev/hda because the kernel still uses the old Partition Table, restart the table and perform the subsequent steps. through the above steps, we have completed the hard disk partition size adjustment operation, and then back to the problem of re-adjusting the file system size. Since hard disk partitions are planned according to the cylinder, it is difficult to adjust the file system size in one step in the resize_reiserfs step to be exactly the same as the hard disk partition size. Therefore, hard disk partitioning is generally a little bigger than the file system, and then you can use the following command to synchronize (of course, if you do not care about the space in the hard disk partition, you can ignore the following steps ): # umount/home/# resize_reiserfs/dev/hda6. In this way, the size of/usr/local is adjusted to 1 GB, leaving 4 GB of free disk space.
 

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.