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
 
重啟已生效分區
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
版權聲明:本文為博主原創文章,轉載請附上博文鏈接!


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM