linux系统扩展根分区容量大小

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了linux系统扩展根分区容量大小相关的知识,希望对你有一定的参考价值。

#查看新增加的磁盘

[[email protected] ~]# 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

技术分享

#新建分区

[[email protected] ~]# 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.

技术分享

#格式化分区

[[email protected] ~]# 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格式

[[email protected] ~]# 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.

技术分享

#查看更改后的分区格式

[[email protected] ~]# 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

[[email protected] ~]# 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与查看

[[email protected] ~]# pvcreate /dev/sdb1

  Physical volume "/dev/sdb1" successfully created

[[email protected] ~]# 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

[[email protected] ~]# 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扩容

[[email protected] ~]# vgextend vg_centos002 /dev/sdb1

  Volume group "vg_centos002" successfully extended

[[email protected] ~]# 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

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

[[email protected] ~]# 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分区大小

[[email protected] ~]# lvextend -L 28G /dev/vg_centos002/lv_root

  Insufficient free space: 2670 extents needed, but only 2558 available

  #报错说明扩容的空间不足,需要调整值

[[email protected] ~]# 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.

[[email protected] ~]# 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

   技术分享

#再次查看磁盘大小还是没有增加

[[email protected] ~]# 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


#重设根分区大小

[[email protected] ~]# 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.

技术分享

#重新查看根分区大小

[[email protected] ~]# 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系统扩展根分区容量大小的主要内容,如果未能解决你的问题,请参考以下文章

linux系统如何在原来的分区上扩大分区??

Linux下使用fdisk扩展分区容量

虚拟机LInux系统磁盘扩容

调整home分区和根分区的大小

Linux的根分区的文件系统类型是啥?

linux如何增加文件系统大小