Adjust the Linux disk partition size-general Linux technology-Linux technology and application information. For more information, see. In the process of using linux, sometimes there may be insufficient partition space due to improper partition space during system installation, and some cases of excessive partition space. 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.
Preparations
(1) backup
First, set the files in the partitions to be changed for the backup. operations on the disk may cause data loss. It is best to save important data to another partition before you start working.
(2) obtain relevant information.
1. run $ df to view the file system information. Write down the mount point and device file corresponding to the partition you want to adjust.
This step is 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 bytes
255 heads, 63 sectors/track, 19929 cylinders
Units = cylinders of 16065*512 = 8225280 bytes
(3) Calculate the ending Cylinder 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. The end cylindrical number ([3.2] = 4) should be calculated as follows ):
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.
Start Adjustment
Before starting the adjustment, you 'd better take a piece of paper to note the following information about the partition to be adjusted:
Adjust the pre-size and post-size. The directory in which it is mounted and the device corresponding to/dev/. start and end the cylinder.
E. g: Before adjustment: 5G, after adjustment: 1G, mount point:/usr/local, corresponding to/dev/hda7. start and end cylinder are 2550,315 7.
1. Detach a partition
It is best to uninstall it when runlevel = 1.
# Umount/dev/
2. Check file system consistency
# Fsck-n/dev/
3. If it is an ext3 system, you need to remove logs.
# Tune2fs-O ^ has_journal/dev/
Note: The ext3 system after the log is retrieved cannot be mounted.
# Tune2fs-j/dev/ Rebuild 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 before proceeding to 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 free disk space.
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