centos7.x 根目录扩容

centos7.x 根目录扩容

在平时,经常会遇到装完的系统硬盘太小无法很好使用的情况,现在介绍下,根目录扩容的方法。本文有些基本的知识,PV,VG,LV等概念,自己事情调查理解。

另外,virtualbox 增加硬盘步骤不在赘述。如下图,界面点点即可。


下面就阐述,如何进行扩充根目录。

1. 登录到系统中,查看硬盘情况。 /dev/sdb就是在virtualbox界面增加的硬盘。

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

[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 ~]# 
  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值