How to resize Linux Disk Partitions

Source: Internet
Author: User
Article Title: how to adjust the size of Linux disk partitions. Linux is a technology channel of the IT lab in China. Including desktop applications, Linux system management, kernel research, embedded systems, open source, and other basic categories in the process of using linux, sometimes there may be insufficient partition space due to improper partition space during system installation, while there may be excess 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 up the files in the partitions 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.
 
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 the disk partition information. Write down the start and end number of the/dev/sda8 cylinder. Set them to start and end respectively, and remember the number of bytes contained in the next "Unit.
 
Note: The file system size and disk partition size cannot be the same: At least they have different measurement units. 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 means that they terminate different cylinder 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 size before and after adjustment. The directory in 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 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/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. Go to fdisk and adjust the partition size.
 
# Fdisk/dev/hda
 
Because the kernel still uses the old Partition Table, restart the system 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 free disk space.
 
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.