linux扩容特定的分区,Linux扩容分区操作过程

查看新增磁盘

在服务器上新加一块10G大小的磁盘

77a6b2dd9bc605afdf94839a66e755de.png

[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

a97eb6adbd6689a617ff83767dc1ec4c.png创建分区与格式化

#新建分区

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

779baf36c14cd7758bcdef5aae406424.png

#格式化分区

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

91f5c3888899dc68d759afdf0f3feef4.png将新分区更改成支持LVM格式

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

aeae5c835785ec8bb5bd29f38d8d1d31.png

#查看更改后的分区格式

d335e3a39e2d204506781f4faadd5ff1.png查看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

159c1b63dd7e2b63269da837cf11a18d.png创建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       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

70fd8e22583f394a48c94407baea0ed3.png查看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

dd669f0b0df6655889b37a4109db3307.png扩展卷组VG

[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

3b1e41fdac938be496013423cb5e0a05.png

#此时查看磁盘大小并没有增加

[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

350e22536b8e7ec38faf31e876f38965.png扩展逻辑卷LVM

#扩展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.

a8e90bfdceb0babea844b334e85a0d27.png重设分区大小

#重设根分区大小

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

b05b337202a8c3641b37bc89d9853ff6.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值