Linux扩容分区操作过程
在服务器上新加一块10G大小的磁盘
[root@centos002 ~]# fdisk -l
....................................................
Disk /dev/sdb: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 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
#新建分区
[root@centos002 ~]# fdisk /dev/sdb
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-1305, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-1305, default 1305):
Using default value 1305
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
#格式化分区
[root@centos002 ~]# mkfs.ext4 /dev/sdb1
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
655360 inodes, 2620595 blocks
131029 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2684354560
80 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 26 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@centos002 ~]# fdisk /dev/sdb
Command (m for help): p
Disk /dev/sdb: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 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: 0x3ec1c9a6
Device Boot Start End Blocks Id System
/dev/sdb1 1 1305 10482381 83 Linux
Command (m for help): t
Selected partition 1
Hex code (type L to list codes): 8e
Changed system type of partition 1 to 8e (Linux LVM)
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
#查看更改后的分区格式
[root@centos002 ~]# vgdisplay
--- Volume group ---
VG Name vg_centos002
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 3
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 1
Act PV 1
VG Size 19.51 GiB
PE Size 4.00 MiB
Total PE 4994
Alloc PE / Size 4994 / 19.51 GiB
Free PE / Size 0 / 0
VG UUID ugeSA9-XCNj-M5XK-Gz4d-DxoR-7TSv-X9Pq6O
[root@centos002 ~]# pvcreate /dev/sdb1
Physical volume "/dev/sdb1" successfully created
[root@centos002 ~]# pvdisplay
--- Physical volume ---
PV Name /dev/sda2
VG Name vg_centos002
PV Size 19.51 GiB / not usable 3.00 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 4994
Free PE 0
Allocated PE 4994
PV UUID Z7AOVb-LEzI-su15-J5lC-alj8-a94k-1NmRRv
"/dev/sdb1" is a new physical volume of "10.00 GiB"
--- NEW Physical volume ---
PV Name /dev/sdb1
VG Name
PV Size 0.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID 4N37pw-Q59f-FRZE-glEx-lRWh-BY5O-Zk9JrF
[root@centos002 ~]# lvdisplay
--- Logical volume ---
LV Path /dev/vg_centos002/lv_root
LV Name lv_root
VG Name vg_centos002
LV UUID 2G4f2m-gkIR-xXG0-MCfO-jFO2-jYNC-IBKYqL
LV Write Access read/write
LV Creation host, time centos002, 2017-08-21 13:15:29 +0800
LV Status available
# open 1
LV Size 17.57 GiB
Current LE 4498
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0
--- Logical volume ---
LV Path /dev/vg_centos002/lv_swap
LV Name lv_swap
VG Name vg_centos002
LV UUID ITJYHF-bGpM-z314-lW1B-q8gj-8tgl-8NZ4bM
LV Write Access read/write
LV Creation host, time centos002, 2017-08-21 13:15:34 +0800
LV Status available
# open 1
LV Size 1.94 GiB
Current LE 496
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:1
[root@centos002 ~]# vgextend vg_centos002 /dev/sdb1
Volume group "vg_centos002" successfully extended
[root@centos002 ~]# vgdisplay
--- Volume group ---
VG Name vg_centos002
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 4
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 2
Act PV 2
VG Size 29.50 GiB
PE Size 4.00 MiB
Total PE 7552
Alloc PE / Size 4994 / 19.51 GiB
Free PE / Size 2558 / 9.99 GiB
VG UUID ugeSA9-XCNj-M5XK-Gz4d-DxoR-7TSv-X9Pq6O
#此时查看磁盘大小并没有增加
[root@centos002 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_centos002-lv_root
18G 803M 16G 5% /
tmpfs 238M 0 238M 0% /dev/shm
/dev/sda1 77M 28M 425M 7% /boot
#扩展LVM分区大小
[root@centos002 ~]# lvextend -L 28G /dev/vg_centos002/lv_root
Insufficient free space: 2670 extents needed, but only 2558 available
#报错说明扩容的空间不足,需要调整值
[root@centos002 ~]# lvextend -L 27G /dev/vg_centos002/lv_root
Size of logical volume vg_centos002/lv_root changed from 17.57 GiB (4498 extents) to 27.00 GiB (6912 extents).
Logical volume lv_root successfully resized.
#重设根分区大小
[root@centos002 ~]# resize2fs /dev/vg_centos002/lv_root
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/vg_centos002/lv_root is mounted on /; on-line resizing required
old desc_blocks = 2, new_desc_blocks = 2
Performing an on-line resize of /dev/vg_centos002/lv_root to 7077888 (4k) blocks.
The filesystem on /dev/vg_centos002/lv_root is now 7077888 blocks long.
写文不易如有帮助,扫码即刻打赏民工哥!!