1. 程式人生 > >linux系統擴展根分區容量大小

linux系統擴展根分區容量大小

linux 擴容 實戰

#查看新增加的磁盤

[root@centos002 ~]# fdisk -l

Disk /dev/sda: 21.5 GB, 21474836480 bytes

255 heads, 63 sectors/track, 2610 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: 0x000c8b4b


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 2611 20458496 8e Linux LVM


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

Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel

Building a new DOS disklabel with disk identifier 0x3ec1c9a6.

Changes will remain in memory only, until you decide to write them.

After that, of course, the previous content won‘t be recoverable.


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

WARNING: DOS-compatible mode is deprecated. It‘s strongly recommended to

switch off the mode (command ‘c‘) and change display units to

sectors (command ‘u‘).


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.

技術分享

#將新建分區更改為支持LVM格式

[root@centos002 ~]# fdisk /dev/sdb

WARNING: DOS-compatible mode is deprecated. It‘s strongly recommended to

switch off the mode (command ‘c‘) and change display units to

sectors (command ‘u‘).


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 ~]# fdisk -l

Disk /dev/sda: 21.5 GB, 21474836480 bytes

255 heads, 63 sectors/track, 2610 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: 0x000c8b4b


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 2611 20458496 8e Linux LVM


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 8e Linux LVM


##查看VG

[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

技術分享

#創建PV與查看

[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 10.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

技術分享

#查看LV

[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

技術分享

#LVM擴容

[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 477M 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 ~]# 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 27.00 GiB

Current LE 6912

Segments 2

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 ~]# 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 477M 28M 425M 7% /boot


#重設根分區大小

[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.

技術分享

#重新查看根分區大小

[root@centos002 ~]# df -h

Filesystem Size Used Avail Use% Mounted on

/dev/mapper/vg_centos002-lv_root

27G 803M 25G 4% /

tmpfs 238M 0 238M 0% /dev/shm

/dev/sda1 477M 28M 425M 7% /boot


本文出自 “民工哥博客” 博客,請務必保留此出處http://mingongge.blog.51cto.com/2429897/1981144

linux系統擴展根分區容量大小