linux file system resizing method of linux resizes partitions

  • 2020-05-07 20:49:12
  • OfStack

In the process of using linux, there are sometimes situations where some partitions have insufficient space and others have excessive space due to improper partitioning during the installation of the system. For example: When I was in installation system to/usr local distributor for 5 G space, but use 1 section of the process and found that most/usr local only 1 G. So we can adjust/usr local size for 1 G. Take 4 G reserved for other USES. This article summarizes the under the premise of not to break the fast file system data to adjust the size of the file system. Here is the method of "forced, to". Of course, if you have not the disk partition of free space, You don't have to reduce the space of a partition.

  preparation

(1) backup

First group the files in the partition you want to change. Operating on the disk may result in data loss. It is best to save important data to another partition before starting work.

(2) to obtain relevant information

1, run $df, view the file system information, note the partition you want to adjust the corresponding hardpoints and device files.

This step is to see which device file /usr/local corresponds to /dev/. This article takes /dev/hda7 as an example.

2, run # sudo fdisk /dev/sda. Enter fdisk and press p to view the partition information.

Note that the file system size is not the same as the disk partition size: at least they are measured in different units. In the file system, 1 is usually KB, MB, GB, but in fdisk, unit is the disk's "unit" value (that is, the number of bytes contained in a cylinder). 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) calculates the termination cylinder number

e.g: the original size of /usr/local was 5000 MB, starting cylinder number 2550 and ending cylinder number 3157.

Termination cylinder number = 2550 + [(1000 * 1024 * 1024) / 8225280] = 2678

Delete the original partition using fdisk (data from previous partitions 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.

Increase partition size: terminate cylinder number is set to the last cylinder number of free space. Decrease partition size: terminate cylinder number is calculated.

Began to adjust

Before starting the adjustment, it is best to take a piece of paper and write down the following information about the partition to be adjusted:

Resize before, resize after. Which directory it is mounted in, which device in /dev/. Start and stop cylinders

e.g: before adjustment: 5G, after adjustment: 1G, hardpoint: /usr/local, corresponding to /dev/hda7

1. Unmount the partition

It is best to uninstall runlevel=1.


#umount/dev/

2. Check the 1 - tropism of the file system


#fsck-n/dev/

3, if enough is ext3 system, also remove the log


#tune2fs-O^has_journal/dev/

Note: the ext3 system cannot be mounted after the log is taken out, use

tune2fs-j/dev/ rebuild log.

4. Resize the file system


#resize_reiserfs-s1000M/dev/hda7

After resizing the file system, use the following command for a full file system review:


#reiserfsck--check--fix-fixable/dev/hda7

5. Enter fdisk and resize the partition


#fdisk/dev/hda

Since the kernel is still using the old partition table, the next step is done after restarting.

With the above steps, we have completed the hard disk partition resizing, and now we return to the problem of resizing the file system. Since disk partitions are planned as cylinders, it is difficult to adjust the file system size to exactly the same size as the disk partition in step 1 of resize_reiserfs. So 1 is generally to adjust the disk partition is a little bit larger than the file system, and then through the following command to synchronize (of course, if you do not care that there is some space in the disk partition can also ignore the following steps) :


#umount/home/
#resize_reiserfs/dev/hda6

This resizes /usr/local to 1G, leaving 4G free disk space.


Related articles: