centos 增加分区容量

增加完新硬盘后,执行以下命令
/sys/class/scsi_host/
[root@centos4 scsi_host]# ls
host0  host1  host2
有几个host就刷几次
[root@centos4 scsi_host]# echo "- - -" > /sys/class/scsi_host/host0/scan
[root@centos4 scsi_host]# echo "- - -" > /sys/class/scsi_host/host1/scan
[root@centos4 scsi_host]# echo "- - -" > /sys/class/scsi_host/host2/scan
刷新后悔出现/dev/sdb1之类的新设备
 
 
1. 登录到系统中,查看硬盘情况。 /dev/sdb就是新增加的硬盘。(如果sda的空间没有用完,可以对sda进行以下操作)
lsblk                  #也可以用fdisk -l 查看
分区后重启或用
partprobe刷新
 
[root@controller ~]# fdisk -l     

Disk /dev/sda: 23.6 GB, 23593779200 bytes, 46081600 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000ac27e

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     1026047      512000   83  Linux
/dev/sda2         1026048    46079999    22526976   8e  Linux LVM

Disk /dev/sdb: 85.9 GB, 85899345920 bytes, 167772160 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
 
 

Disk /dev/mapper/centos-root: 20.7 GB, 20661141504 bytes, 40353792 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
 

Disk /dev/mapper/centos-swap: 2361 MB, 2361393152 bytes, 4612096 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
2. 操作/dev/sdb,进行分区,格式化。
[root@controller ~]#
[root@controller ~]#
[root@controller ~]# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0xd7252d64.
 
Command (m for help): m
Command action
   a   toggle a bootable flag
   b   edit bsd disklabel
   c   toggle the dos compatibility flag
   d   delete a partition
   g   create a new empty GPT partition table
   G   create an IRIX (SGI) partition table
   l   list known partition types
   m   print this menu
   n   add a new partition
   o   create a new empty DOS partition table
   p   print the partition table
   q   quit without saving changes
   s   create a new empty Sun disklabel
   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 (experts only)

Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
Partition number (1-4, default 1):
First sector (2048-167772159, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-167772159, default 167772159):
Using default value 167772159
Partition 1 of type Linux and of size 80 GiB is set

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

Calling ioctl() to re-read partition table.
Syncing disks.
[root@controller ~]#
[root@controller ~]# fdisk -l

Disk /dev/sda: 23.6 GB, 23593779200 bytes, 46081600 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000ac27e

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     1026047      512000   83  Linux
/dev/sda2         1026048    46079999    22526976   8e  Linux LVM

Disk /dev/sdb: 85.9 GB, 85899345920 bytes, 167772160 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0xd7252d64

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048   167772159    83885056   83  Linux

Disk /dev/mapper/centos-root: 20.7 GB, 20661141504 bytes, 40353792 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
 

Disk /dev/mapper/centos-swap: 2361 MB, 2361393152 bytes, 4612096 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
3. 修改硬盘类型,修改为linux LVM,代码8e。此步骤也可以在分区步骤中直接完成。
[root@controller ~]#
[root@controller ~]# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
 

Command (m for help): t
Selected partition 1
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'

Command (m for help): p

Disk /dev/sdb: 85.9 GB, 85899345920 bytes, 167772160 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0xd7252d64

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048   167772159    83885056   8e  Linux LVM

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

Calling ioctl() to re-read partition table.
Syncing disks.
[root@controller ~]#
[root@controller ~]# fdisk -l

Disk /dev/sda: 23.6 GB, 23593779200 bytes, 46081600 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000ac27e

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     1026047      512000   83  Linux
/dev/sda2         1026048    46079999    22526976   8e  Linux LVM

Disk /dev/sdb: 85.9 GB, 85899345920 bytes, 167772160 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0xd7252d64

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048   167772159    83885056   8e  Linux LVM

Disk /dev/mapper/centos-root: 20.7 GB, 20661141504 bytes, 40353792 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
 

Disk /dev/mapper/centos-swap: 2361 MB, 2361393152 bytes, 4612096 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
 
partprobe     同步新分区信息,不用重启了
mkfs.ext4 /dev/sdb   格式化新分区

4. 创建 PV。
[root@controller ~]# pvcreate /dev/sdb1
  Physical volume "/dev/sdb1" successfully created.
[root@controller ~]#
5. 查看VG.  注意VG的名称
[root@controller ~]# vgs
  VG     #PV #LV #SN Attr   VSize  VFree
  centos   1   2   0 wz--n- 21.48g 40.00m
[root@controller ~]#
6. 扩展 VG。
[root@controller ~]# vgextend centos /dev/sdb1
  Volume group "centos" successfully extended
[root@controller ~]#
[root@controller ~]# df -hl
Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/centos-root   20G  5.7G   14G  30% /
devtmpfs                 1.9G     0  1.9G   0% /dev
tmpfs                    1.9G     0  1.9G   0% /dev/shm
tmpfs                    1.9G  8.4M  1.9G   1% /run
tmpfs                    1.9G     0  1.9G   0% /sys/fs/cgroup
/dev/sda1                497M  215M  283M  44% /boot
tmpfs                    380M     0  380M   0% /run/user/0
[root@controller ~]#

7. 扩展 LV./dev/mapper/centos-root 为根目录。
[root@controller ~]#
[root@controller ~]# lvextend -L +70G /dev/mapper/centos-root /dev/sdb1
  Size of logical volume centos/root changed from 19.24 GiB (4926 extents) to 89.24 GiB (22846 extents).
  Logical volume centos/root successfully resized.
[root@controller ~]#
[root@controller ~]#
[root@controller ~]# df -hl
Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/centos-root   20G  5.7G   14G  30% /
devtmpfs                 1.9G     0  1.9G   0% /dev
tmpfs                    1.9G     0  1.9G   0% /dev/shm
tmpfs                    1.9G  8.5M  1.9G   1% /run
tmpfs                    1.9G     0  1.9G   0% /sys/fs/cgroup
/dev/sda1                497M  215M  283M  44% /boot
tmpfs                    380M     0  380M   0% /run/user/0
[root@controller ~]#
8. 扩展生效。
[root@controller ~]# xfs_growfs  /dev/mapper/centos-root
meta-data=/dev/mapper/centos-root isize=256    agcount=4, agsize=1261056 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=0        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=5044224, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=0
log      =internal               bsize=4096   blocks=2560, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 5044224 to 23394304
[root@controller ~]#
[root@controller ~]# df -h
Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/centos-root   90G  5.7G   84G   7% /
devtmpfs                 1.9G     0  1.9G   0% /dev
tmpfs                    1.9G     0  1.9G   0% /dev/shm
tmpfs                    1.9G  8.5M  1.9G   1% /run
tmpfs                    1.9G     0  1.9G   0% /sys/fs/cgroup
/dev/sda1                497M  215M  283M  44% /boot
tmpfs                    380M     0  380M   0% /run/user/0
[root@controller ~]#
[root@controller ~]# 
---------------------
作者:李家乐
来源:CSDN
原文:https://blog.csdn.net/weixin_39992639/article/details/79082944
版权声明:本文为博主原创文章,转载请附上博文链接!
posted @ 2019-02-15 09:05  liulj0713  阅读(1733)  评论(0编辑  收藏  举报