In the process of using Linux, it is sometimes due to improper partition caused by the installation of the system due to the lack of partition space, and some areas of excess space. For example: I installed the system to the/usr/local distributor 5G space, but after using a process found that/usr/ Local only uses up to 1G. This can adjust the/usr/local size to 1G. Leave 4G for his use. This paper summarizes the method of adjusting file system size without breaking fast file system data. Here is the "Rob Peter, robbing" approach. Of course, if you have unpartitioned free space on your disk, you don't have to reduce the space of a partition.
Preparatory work
(i) Backup
First, group the files in the partition that you want to change. Operations on the disk may result in loss of data. It is a good idea to save important data to a different partition before you start working.
(ii) access to relevant information
1, run $ DF to view file system information. Note The mount point and device file for the partition you want to adjust.
This step is to see which device file in the/usr/local corresponds to the/dev/. This paper takes/dev/hda7 as an example.
2, running # sudo fdisk/dev/sda. Go to Fdisk, press p to view the disk partition information. Note the starting cylinder number of the/dev/sda8 and terminate the cylinder number. Set them to start, end. And note how many bytes a "unit" contains.
Note that the file system size and disk partition size are not equal: at least they have different units of measurement. In the file system, it is typically in kilobytes, MB, and GB. In Fdisk, however, the disk's "unit" value (that is, the number of bytes contained in a cylinder) is computed. After we run # FDISK/DEV/SDA, Fdisk displays the following information:
Copy Code code as follows:
disk/dev/sda:163.9 GB, 163928604672 bytes
255 heads, Sectors/track, 19929 cylinders
Units = Cylinders of 16065 * 8225280 bytes
(iii) Calculation of termination cylinder number
e.g: the original/usr/local size is 5000 MB, the starting cylinder number is 2550, and the Terminator cylinder number is 3157. So I'm going to change the size of it to 1000MB now, so calculate the end cylinder number ([3.2] = 4):
End Cylinder Number = 2550 + [(1000 * 1024 * 1024)/8225280] = 2678
Use Fdisk to delete the original partition (previously partitioned data will not be lost!). Then a new partition is created, and the only difference is that the partitions are different in size, as they terminate the column number.
Increase the partition size: The end cylinder number is set to the last cylinder number of the free space. Reduce partition size: Terminating cylinder numbers are calculated.
Start adjusting
Before you start tuning, it's a good idea to take a piece of paper and note the following information about the partition you want to adjust:
Resize before adjustment, resize. Which directory it mounts, corresponds to which device in the/dev/. Start, terminate cylinder
e.g: 5G, after adjustment: 1G, mount point:/usr/local, corresponding to/DEV/HDA7. Starting, terminating the cylindrical surface is 2550,3157 respectively
1, uninstall the partition
It is best to uninstall in case of Runlevel=1.
Copy Code code as follows:
2, check the consistency of the file system
Copy Code code as follows:
3, if enough is the ext3 system, but also to remove the log
Copy Code code as follows:
#tune2fs-o^has_journal/dev/
Note: The EXT3 system is unable to mount after the log is removed, using
#tune2fs-j/dev/rebuild the log.
4, adjust file system size
Copy Code code as follows:
#resize_reiserfs-S1000M/DEV/HDA7
After resizing the file system, use the following command to perform a comprehensive check of the file system:
Copy Code code as follows:
#reiserfsck--CHECK--FIX-FIXABLE/DEV/HDA7
5, go to fdisk, resize the partition
Copy Code code as follows:
Because the kernel still uses the old partition table, reboot and then follow the steps.
With the above steps, we have completed the hard disk partition sizing operation, and then go back to the problem of resizing the file system. Since the hard disk partitions are scheduled according to the cylinder, it is difficult to one-step the file system size to the hard disk partition on the Resize_reiserfs step. So it is generally a bit larger than the file system, and then the following command to sync (of course, if you do not care about the hard disk partition there are some space, you can also ignore the following steps):
Copy Code code as follows:
#umount/home/
#resize_reiserfs/dev/hda6
In this way, the size of the/usr/local is adjusted to 1G, leaving 4G of free disk space.