CentOS root partition resizing method

Source: Internet
Author: User
Operating environment: [root @ linuxidc ~] # Uname-aLinuxlinuxidc2.6.32-358.18.1.el6.x86_64 #1SMPWedAug2817: 19: 38UTC2013x86_64x86_64x86_64GNU/Linux status analysis: the system has two hard disks, the first hard disk 107 GB, & ldquo;/& rdquo; partition space at that time

Operating Environment:
[Root @ linuxidc ~] # Uname-
Linux linuxidc 2.6.32-358.18.1.el6.x86 _ 64 #1 SMP Wed Aug 28 17:19:38 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
Status quo analysis:
The system has two hard disks. The first hard disk is 107 GB, and the "/" partition space is limited to 7.7gb at that time. the space is occupied immediately. Now, the size of the second hard disk sdb is 16 GB. we hope to add all the space of the sdb to the "/" partition, is its space capacity from 7.7GB to 7.7 GB + 16 GB (about 2.4 GB ). (If there is only one sda hard disk, you can perform the same operation if there is a lot of space available)
The procedure is as follows:
Step 1. view the current partition of the local machine
[Root @ linuxidc ~] # Df-h
File system capacity in use available % mount point
/Dev/mapper/VolGroup-lv_root
7.7G 7.1G 155 M 98%/
Tmpfs 3.9G 296 K 3.9G 1%/dev/shm
/Dev/sda1 485 M 64 M 396 M 14%/boot
/Dev/sda3 83G 350 M 79G 1%/media
Step 2. view the local disk
[Root @ linuxidc ~] # Fdisk-l


Disk/dev/sda: 107.4 GB, 107374182400 bytes
255 heads, 63 sectors/track, 13054 cylinders
Units = cylinders of 16065*512 = 8225280 bytes
Sector size (logical/physical): 512 bytes/512 bytes
I/O size (minimum/optimal): 512 bytes/512 bytes
Disk identifier: 0x000dc0ad


Device Boot Start End Blocks Id System
/Dev/sda1*1 64 512000 83 Linux
Partition 1 does not end on cylinder boundary.
/Dev/sda2 64 2089 16264192 8e Linux LVM
/Dev/sda3 2090 13054 88076362 + 83 Linux


Disk/dev/mapper/VolGroup-lv_root: 8325 MB, 8325693440 bytes
255 heads, 63 sectors/track, 1012 cylinders
Units = cylinders of 16065*512 = 8225280 bytes
Sector size (logical/physical): 512 bytes/512 bytes
I/O size (minimum/optimal): 512 bytes/512 bytes
Disk identifier: 0x00000000

 


Disk/dev/mapper/VolGroup-lv_swap: 8325 MB, 8325693440 bytes
255 heads, 63 sectors/track, 1012 cylinders
Units = cylinders of 16065*512 = 8225280 bytes
Sector size (logical/physical): 512 bytes/512 bytes
I/O size (minimum/optimal): 512 bytes/512 bytes
Disk identifier: 0x00000000
Note: the second hard disk has not been added to EXSI5.0.
[Root @ linuxidc ~] #
Step 3: Add the second hard disk


View the system disk status at this time
Root @ linuxidc ~] # Fdisk-l


Disk/dev/sda: 107.4 GB, 107374182400 bytes
255 heads, 63 sectors/track, 13054 cylinders
Units = cylinders of 16065*512 = 8225280 bytes
Sector size (logical/physical): 512 bytes/512 bytes
I/O size (minimum/optimal): 512 bytes/512 bytes
Disk identifier: 0x000dc0ad


Device Boot Start End Blocks Id System
/Dev/sda1*1 64 512000 83 Linux
Partition 1 does not end on cylinderboundary.
/Dev/sda2 64 2089 16264192 8e Linux LVM
/Dev/sda3 2090 13054 88076362 + 83 Linux


Disk/dev/sdb: 17.2 GB, 17179869184 bytes
255 heads, 63 sectors/track, 2088 cylinders
Units = cylinders of 16065*512 = 8225280 bytes
Sector size (logical/physical): 512 bytes/512 bytes
I/O size (minimum/optimal): 512 bytes/512 bytes
Disk identifier: 0x00000000

 


Disk/dev/mapper/VolGroup-lv_root: 8325 MB, 8325693440 bytes
255 heads, 63 sectors/track, 1012 cylinders
Units = cylinders of 16065*512 = 8225280 bytes
Sector size (logical/physical): 512 bytes/512 bytes
I/O size (minimum/optimal): 512 bytes/512 bytes
Disk identifier: 0x00000000

 


Disk/dev/mapper/VolGroup-lv_swap: 8325 MB, 8325693440 bytes
255 heads, 63 sectors/track, 1012 cylinders
Units = cylinders of 16065*512 = 8225280 bytes
Sector size (logical/physical): 512 bytes/512 bytes
I/O size (minimum/optimal): 512 bytes/512 bytes
Disk identifier: 0x00000000


We can see the newly added hard disk sdb.


[Root @ linuxidc ~] #
Step 4: partition the second hard disk sdb


[Root @ linuxidc ~] # Fdisk/dev/sdb
Device contains neither a valid DOSpartition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with diskidentifier 0xfa4abbdc.
Changes will remain in memory only, untilyou decide to write them.
After that, of course, the previous contentwon't be recoverable.


Warning: invalid flag 0x0000 of partitiontable 4 will be corrected by w (rite)


WARNING: DOS-compatible mode is deprecated. It's stronugly recommended
Switch off the mode (command 'C') and change display units
Sectors (command 'u ').


Command (m for help): m
Command action
A toggle a bootable flag
B edit bsd disklabel
C toggle the dos compatibilityflag
D delete a partition
L list known partition types
M print this menu
N add a new partition
O create a new empty DOSpartition table
P print the partition table
Q quit without saving changes
S create a new empty Sundisklabel
T change a partition's system id
U change display/entry units
V verify the partition table
W write table to disk and exit
X extra functionality (expertsonly)


Command (m for help): n
Command action
E extended
P primary partition (1-4)
P
Partition number (1-4): 4
First cylinder (1-2088, default 1 ):
Using default value 1
Last cylinder, + cylinders or + size {K, M, G} (1-2088, default 2088 ):
Using default value 2088


Command (m for help): w
The partition table has been altered!


Calling ioctl () to re-read partition table.
Syncing disks.


Note: the above operations partition the sdb hard disk and set it to the sdb4 partition (of course, the primary partition created above can be any one of the 1-4 partitions, I select 4 here ).


Step 5. format the newly created sdb4 partition


[Root @ linuxidc ~] # Mkfs. ext4/dev/sdb4
Mke2fs 1.41.12 (17-May-2010)
File system Tag =
Operating system: Linux
Block size = 4096 (log = 2)
Part size = 4096 (log = 2)
Stride = 0 blocks, Stripe width = 0 blocks
1048576 inodes, 4192957 blocks
209647 blocks (5.00%) reserved for thesuper user
First Data block = 0
Maximum filesystem blocks = 4294967296
128 block groups
32768 blocks per group, 32768 fragments pergroup
8192 inodes per group
Superblock backups stored on blocks:
32768,983 04, 163840,229 376, 294912,819 200, 884736,160 5632, 2654208,
4096000


Writing to inode table: Complete
Creating journal (32768 blocks): done
Writing superblocks and filesystemaccounting information: Completed by done


This filesystem will be automaticallychecked every 20 mounts or
180 days, whichever comes first. Use tune2fs-c or-I to override.


Note: format the sdb4 partition to the ext4 format. because CentOS is installed in the system format ext4, pay attention to it here.


Step 6: add the formatted sdb4 partition as a physical volume
[Root @ linuxidc ~] # Pvcreate/dev/sdb4
Physical volume "/dev/sdb4" successfully created

 

Step 7: view the physical volume (PV) of the current system


[Root @ linuxidc ~] # Pvdisplay
--- Physical volume ---
PVName/dev/sda2
VGName VolGroup
PVSize 15.51 GiB/not usable3.00 MiB
Allocatable yes (butfull)
PESize 4.00 MiB
Total PE 3970
Free PE 0
Allocated PE 3970.
PVUUID Up77sG-sNKf-Ja0k-crBf-N0wz-a5hy-T6sVFh


"/Dev/sdb4" is a new physical volume of "15.99 GiB"
--- NEW Physical volume ---
PVName/dev/sdb4
VGName
PVSize 15.99 GiB
Allocatable NO
PESize 0
Total PE 0
Free PE 0
Allocated PE 0
PVUUID Gqnw7N-HooX-S2Nz-1NIZ-YpOe-g0jo-grG1rQ
Note: the size of the new physical volume sdb4 is consistent with the settings we added.

 


Step 8. view the current volume Group
[Root @ linuxidc ~] # Vgdisplay
--- Volume group ---
VGName VolGroup
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 3
VGAccess read/write
VGStatus resizable
MAXLV 0
CurLV 2
Open LV 2
MaxPV 0
CurPV 1
ActPV 1
VGSize 15.51 GiB
PESize 4.00 MiB
Total PE 3970
Alloc PE/Size 3970/15 .51GiB
Free PE/Size 0/0
PPrifh-glzl-nnxX-YkBm-xJ1s-rgnw-d1WsJd VGUUID


Step 9: convert the sdb4 partition to an extended partition


[Root @ linuxidc ~] # Vgextend VolGroup/dev/sdb4
Volume group "VolGroup" successfully extended


Step 10: view the current logical volume


[Root @ linuxidc ~] # Lvdisplay
--- Logical volume ---
LVPath/dev/VolGroup/lv_root
LVName lv_root
VGName VolGroup
LVUUID dCIsej-0NWX-bVFe-bT6L-c4eY-oy4G-9lNBOC
LVWrite Access read/write
LVCreation host, time,
LVStatus available
# Open 1
LVSize 7.75 GiB
Current LE 1985
Segments 1
Allocation inherit
Read ahead sectors auto
-Currently sets to 256
Block device 253: 0


--- Logical volume ---
LVPath/dev/VolGroup/lv_swap
LVName lv_swap
VGName VolGroup
LVUUID K5bxJo-2SmM-6NCU-mBJP-Qzp1-ZODH-nbLK0k
LVWrite Access read/write
LVCreation host, time,
LVStatus available
# Open 1
LVSize 7.75 GiB
Current LE 1985
Segments 1
Allocation inherit
Read ahead sectors auto
-Currently sets to 256
Blocks device 253: 1


Note: The path name of the "/" root partition is/dev/VolGroup/lv_root.


Step 2. view the expanded volume Group
[Root @ linuxidc ~] # Vgdisplay
--- Volume group ---
VGName VolGroup
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 4
VGAccess read/write
VGStatus resizable
MAXLV 0
CurLV 2
Open LV 2
MaxPV 0
CurPV 2
ActPV 2
VGSize 31.50 GiB
PESize 4.00 MiB
Total PE 8064
Alloc PE/Size 3970/15 .51GiB
Free PE/Size 4094/15 .99 GiB
PPrifh-glzl-nnxX-YkBm-xJ1s-rgnw-d1WsJd VGUUID
Note: After expansion, we can see that the size is increased by 16 GB (compared with that in step 8)


Step 2: extend all new logical volumes to the "/" partition


[Root @ linuxidc ~] # Lvextend-L + 15.99G/dev/VolGroup/lv_root
Rounding size to boundary between physical extents: 15.99 GiB
Extending logical volume lv_root to 23.75 GiB
Logical volume lv_root successfully resized


Note: sdb4 has a total of 16 GB, so add all 16BG to the root partition.


Step 3: view the "/" root partition format and refresh the size of the root partition.
[Root @ linuxidc ~] # E2fsck-f/dev/VolGroup/lv_root
E2fsck 1.41.12 (17-May-2010)
/Dev/VolGroup/lv_root is mounted.
E2fsck: unable to continue. abort.


[Root @ linuxidc ~] # Resize2fs/dev/VolGroup/lv_root
Resize2fs 1.41.12 (17-May-2010)
Filesystem at/dev/VolGroup/lv_root ismounted on/; on-line resizing required
Old desc_blocks = 1, new_desc_blocks = 2
Ming an on-line resize of/dev/VolGroup/lv_root to 6224896 (4 k) blocks.
The filesystem on/dev/VolGroup/lv_root isnow 6224896 blocks long.
Note: The resize2fs command refreshes the capacity of the root partition "/dev/VolGroup/lv_root.


Step 1. view the size of the root partition after refreshing


[Root @ linuxidc ~] # Df-h
File system capacity in use available % mount point
/Dev/mapper/VolGroup-lv_root
24 GB 7.1G 16G 32%/
Tmpfs 3.9G 144 K 3.9G 1%/dev/shm
/Dev/sda3 83G 350 M 79G 1%/media/Lucene


Note: the size of the root partition is changed from 7.7G to 24G. restart the system to check the situation. In this case, you can continue to install the software without prompting you that the space is insufficient.

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.