Increase partition size in Linux

Source: Internet
Author: User

Here, we use Red hat AS4 as an example. When the disk partition is not found enough, the first way you can think of is to increase the partition size. However, if Linux does not use logical volume management, it is very difficult to dynamically increase the partition size. One way to think about it is to back up the partition file system data, delete the partition, and then re-create the partition, restore the backup file system. This method is more mysterious. The system may fail to start after the partition is deleted.
 
The second approach is to create a new logical partition (of course, there must be unused disk space available for allocation), copy the file system from the old partition to the new partition, and then modify fstab, replace the old partition/File System with the new partition/File System
 
The third approach is to create a new logical partition, format the new logical partition into an ext3 (or another type) file system, and mount it to a file system with insufficient disk space, just like the original partition/file system.
 
The third method is used here:
 
Sdb is the second SCSI hard disk.
[Root @ hdp0 hadoop] #/sbin/fdisk/dev/sdb
 
The number of cylinders for this disk is set to 8942.
There is nothing wrong with that, but this is larger than 1024,
And coshould in certain setups cause problems:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(E.g., dos fdisk, OS/2 FDISK)
 
Command (m for help): p
 
Disk/dev/sdb: 73.5 GB, 73557090304 bytes
255 heads, 63 sectors/track, 8942 cylinders
Units = cylinders of 16065*512 = 8225280 bytes
 
Device Boot Start End Blocks Id System
/Dev/sdb1*1 130 1044193 + 83 Linux
/Dev/sdb2 131 391 2096482 + 82 Linux swap
/Dev/sdb3 392 521 1044225 83 Linux
/Dev/sdb4 522 8942 67641682 + 5 Extended
/Dev/sdb5 522 586 522081 83 Linux
/Dev/sdb6 587 651 522081 83 Linux
/Dev/sdb7 652 1173 4192933 + 83 Linux
We can see that sdb1, 2, and 3 are the primary partitions, and sdb4 is the extended partition. Sdb5, 6, and 7 are logical partitions. The Start (End) is continuous. sdb7 only uses 1173 channels, and the maximum value is 8942 from the extended partition. That is to say, there are 7769 idle cylinders, the size of a cylinder is 8225280, which is about 8 Mb. 7769*8225280 bytes left, about GB unused.
 
Add a new logical partition (Note: if it involves the primary partition and the extended partition, the actual situation may be more complex than this. Here, the four primary partitions (including the extended partition) have all been divided, so it can only be divided into logical partitions)
Command (m for help): n
First cylinder (1174-8942, default 1174 ):
Using default value 1174
 
Increase the size to 10 Gb.
Last cylinder or + size or + sizeM or + sizeK (1174-8942, default 8942): + 10240 M
After adding the partition, check that a logical partition/dev/sdb8 is added.
 
Command (m for help): p
 
Disk/dev/sdb: 73.5 GB, 73557090304 bytes
255 heads, 63 sectors/track, 8942 cylinders
Units = cylinders of 16065*512 = 8225280 bytes
 
Device Boot Start End Blocks Id System
/Dev/sdb1*1 130 1044193 + 83 Linux
/Dev/sdb2 131 391 2096482 + 82 Linux swap
/Dev/sdb3 392 521 1044225 83 Linux
/Dev/sdb4 522 8942 67641682 + 5 Extended
/Dev/sdb5 522 586 522081 83 Linux
/Dev/sdb6 587 651 522081 83 Linux
/Dev/sdb7 652 1173 4192933 + 83 Linux
/Dev/sdb8 1174 2419 10008463 + 83 Linux
 
 
We can see that an sdb8 partition is added, and the number of the cylinder ranges from 1174 to 2419.
Write to the partition table and perform partition operations
Command (m for help): w
The partition table has been altered!
 
Calling ioctl () to re-read partition table.
 
WARNING: Re-reading the partition table failed with error 16: the device or resource is busy.
The kernel still uses the old table.
The new table will be used at the next reboot.
Syncing disks.
 
After partitioning, the file system is invisible.
[Root @ hdp0 hadoop] # df-m
Filesystem 1 M-block used available % mount point
/Dev/sdb1 1004 582 372 62%/
None 1014 0 1014 0%/dev/shm
/Dev/sdb3 1004 807 147 85%/home
/Dev/sdb5 494 11 458 3%/opt
/Dev/sdb7 4031 3272 554 86%/usr
/Dev/sdb6 494 87 382 19%/var
 
Restart the machine
 
Reboot
 
Format a File System
 
[Root @ hdp0 hadoop] #/sbin/mkfs. ext3/dev/sdb8
 
Mount the file system./home/develop is the directory under/home.
[Root @ hdp0 hadoop] # mount/dev/sdb8/home/develop
 
View the file system. You can see that the new partition/File System has been mounted and can be used.
 
[Root @ hdp0 hadoop] # df-m
Filesystem 1 M-block used available % mount point
/Dev/sdb1 1004 582 372 62%/
None 1014 0 1014 0%/dev/shm
/Dev/sdb3 1004 807 147 85%/home
/Dev/sdb5 494 11 458 3%/opt
/Dev/sdb7 4031 3272 554 86%/usr
/Dev/sdb6 494 87 382 19%/var
/Dev/sdb8 9621 54 9079 1%/home/develop

From the column hongweigg

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.