• 添加新硬盘,扩展Centos7根分区


    ##背景介绍,系统安装时,分配的硬盘容量太小,根分区空间不够用,现添加一个新硬盘,通过以下步骤来扩展centos7根分区

      1 [root@t201 ~]# df -h
      2 文件系统                 容量  已用  可用 已用% 挂载点
      3 devtmpfs                 3.9G     0  3.9G    0% /dev
      4 tmpfs                    3.9G     0  3.9G    0% /dev/shm
      5 tmpfs                    3.9G  8.6M  3.9G    1% /run
      6 tmpfs                    3.9G     0  3.9G    0% /sys/fs/cgroup
      7 /dev/mapper/centos-root   14G  2.2G   12G   16% /
      8 /dev/sda1               1014M  134M  881M   14% /boot
      9 tmpfs                    797M     0  797M    0% /run/user/0
     10 [root@t201 ~]# fdisk -l
     11 
     12 磁盘 /dev/sda:17.2 GB, 17179869184 字节,33554432 个扇区
     13 Units = 扇区 of 1 * 512 = 512 bytes
     14 扇区大小(逻辑/物理):512 字节 / 512 字节
     15 I/O 大小(最小/最佳):512 字节 / 512 字节
     16 磁盘标签类型:dos
     17 磁盘标识符:0x000db98a
     18 
     19    设备 Boot      Start         End      Blocks   Id  System
     20 /dev/sda1   *        2048     2099199     1048576   83  Linux
     21 /dev/sda2         2099200    33554431    15727616   8e  Linux LVM
     22 
     23 磁盘 /dev/sdb:21.5 GB, 21474836480 字节,41943040 个扇区
     24 Units = 扇区 of 1 * 512 = 512 bytes
     25 扇区大小(逻辑/物理):512 字节 / 512 字节
     26 I/O 大小(最小/最佳):512 字节 / 512 字节
     27 
     28 
     29 磁盘 /dev/mapper/centos-root:14.4 GB, 14382268416 字节,28090368 个扇区
     30 Units = 扇区 of 1 * 512 = 512 bytes
     31 扇区大小(逻辑/物理):512 字节 / 512 字节
     32 I/O 大小(最小/最佳):512 字节 / 512 字节
     33 
     34 
     35 磁盘 /dev/mapper/centos-swap:1719 MB, 1719664640 字节,3358720 个扇区
     36 Units = 扇区 of 1 * 512 = 512 bytes
     37 扇区大小(逻辑/物理):512 字节 / 512 字节
     38 I/O 大小(最小/最佳):512 字节 / 512 字节
     39 
     40 [root@t201 ~]# fdisk /dev/sdb
     41 欢迎使用 fdisk (util-linux 2.23.2)。
     42 
     43 更改将停留在内存中,直到您决定将更改写入磁盘。
     44 使用写入命令前请三思。
     45 
     46 Device does not contain a recognized partition table
     47 使用磁盘标识符 0xb1065d94 创建新的 DOS 磁盘标签。
     48 
     49 命令(输入 m 获取帮助):m
     50 命令操作
     51    a   toggle a bootable flag
     52    b   edit bsd disklabel
     53    c   toggle the dos compatibility flag
     54    d   delete a partition
     55    g   create a new empty GPT partition table
     56    G   create an IRIX (SGI) partition table
     57    l   list known partition types
     58    m   print this menu
     59    n   add a new partition
     60    o   create a new empty DOS partition table
     61    p   print the partition table
     62    q   quit without saving changes
     63    s   create a new empty Sun disklabel
     64    t   change a partition's system id
     65    u   change display/entry units
     66    v   verify the partition table
     67    w   write table to disk and exit
     68    x   extra functionality (experts only)
     69 
     70 命令(输入 m 获取帮助):n
     71 Partition type:
     72    p   primary (0 primary, 0 extended, 4 free)
     73    e   extended
     74 Select (default p): p
     75 分区号 (1-4,默认 1):
     76 起始 扇区 (2048-41943039,默认为 2048):
     77 将使用默认值 2048
     78 Last 扇区, +扇区 or +size{K,M,G} (2048-41943039,默认为 41943039):
     79 将使用默认值 41943039
     80 分区 1 已设置为 Linux 类型,大小设为 20 GiB
     81 
     82 命令(输入 m 获取帮助):w
     83 The partition table has been altered!
     84 
     85 Calling ioctl() to re-read partition table.
     86 正在同步磁盘。
     87 [root@t201 ~]# df -h
     88 文件系统                 容量  已用  可用 已用% 挂载点
     89 devtmpfs                 3.9G     0  3.9G    0% /dev
     90 tmpfs                    3.9G     0  3.9G    0% /dev/shm
     91 tmpfs                    3.9G  8.6M  3.9G    1% /run
     92 tmpfs                    3.9G     0  3.9G    0% /sys/fs/cgroup
     93 /dev/mapper/centos-root   14G  2.2G   12G   16% /
     94 /dev/sda1               1014M  134M  881M   14% /boot
     95 tmpfs                    797M     0  797M    0% /run/user/0
     96 [root@t201 ~]# fdisk -l
     97 
     98 磁盘 /dev/sda:17.2 GB, 17179869184 字节,33554432 个扇区
     99 Units = 扇区 of 1 * 512 = 512 bytes
    100 扇区大小(逻辑/物理):512 字节 / 512 字节
    101 I/O 大小(最小/最佳):512 字节 / 512 字节
    102 磁盘标签类型:dos
    103 磁盘标识符:0x000db98a
    104 
    105    设备 Boot      Start         End      Blocks   Id  System
    106 /dev/sda1   *        2048     2099199     1048576   83  Linux
    107 /dev/sda2         2099200    33554431    15727616   8e  Linux LVM
    108 
    109 磁盘 /dev/sdb:21.5 GB, 21474836480 字节,41943040 个扇区
    110 Units = 扇区 of 1 * 512 = 512 bytes
    111 扇区大小(逻辑/物理):512 字节 / 512 字节
    112 I/O 大小(最小/最佳):512 字节 / 512 字节
    113 磁盘标签类型:dos
    114 磁盘标识符:0xb1065d94
    115 
    116    设备 Boot      Start         End      Blocks   Id  System
    117 /dev/sdb1            2048    41943039    20970496   83  Linux
    118 
    119 磁盘 /dev/mapper/centos-root:14.4 GB, 14382268416 字节,28090368 个扇区
    120 Units = 扇区 of 1 * 512 = 512 bytes
    121 扇区大小(逻辑/物理):512 字节 / 512 字节
    122 I/O 大小(最小/最佳):512 字节 / 512 字节
    123 
    124 
    125 磁盘 /dev/mapper/centos-swap:1719 MB, 1719664640 字节,3358720 个扇区
    126 Units = 扇区 of 1 * 512 = 512 bytes
    127 扇区大小(逻辑/物理):512 字节 / 512 字节
    128 I/O 大小(最小/最佳):512 字节 / 512 字节
    129 
    130 [root@t201 ~]# vgdisplay -v
    131   --- Volume group ---
    132   VG Name               centos
    133   System ID             
    134   Format                lvm2
    135   Metadata Areas        1
    136   Metadata Sequence No  3
    137   VG Access             read/write
    138   VG Status             resizable
    139   MAX LV                0
    140   Cur LV                2
    141   Open LV               2
    142   Max PV                0
    143   Cur PV                1
    144   Act PV                1
    145   VG Size               <15.00 GiB
    146   PE Size               4.00 MiB
    147   Total PE              3839
    148   Alloc PE / Size       3839 / <15.00 GiB
    149   Free  PE / Size       0 / 0   
    150   VG UUID               Fj5EY6-duHB-Vtmx-RaKo-JpuY-UwCy-f3xemr
    151    
    152   --- Logical volume ---
    153   LV Path                /dev/centos/swap
    154   LV Name                swap
    155   VG Name                centos
    156   LV UUID                YKyysg-qNJY-x3sa-HjHm-5JHX-mBRf-mTpVXl
    157   LV Write Access        read/write
    158   LV Creation host, time localhost, 2019-11-14 08:57:14 +0800
    159   LV Status              available
    160   # open                 2
    161   LV Size                1.60 GiB
    162   Current LE             410
    163   Segments               1
    164   Allocation             inherit
    165   Read ahead sectors     auto
    166   - currently set to     8192
    167   Block device           253:1
    168    
    169   --- Logical volume ---
    170   LV Path                /dev/centos/root
    171   LV Name                root
    172   VG Name                centos
    173   LV UUID                dLgGwO-UXqd-41WI-C97j-suC8-siWt-3QWQQv
    174   LV Write Access        read/write
    175   LV Creation host, time localhost, 2019-11-14 08:57:14 +0800
    176   LV Status              available
    177   # open                 1
    178   LV Size                13.39 GiB
    179   Current LE             3429
    180   Segments               1
    181   Allocation             inherit
    182   Read ahead sectors     auto
    183   - currently set to     8192
    184   Block device           253:0
    185    
    186   --- Physical volumes ---
    187   PV Name               /dev/sda2     
    188   PV UUID               dzMQgG-eMzE-6Vi4-WHOt-BdDH-KuTt-Ofk0gH
    189   PV Status             allocatable
    190   Total PE / Free PE    3839 / 0
    191    
    192 [root@t201 ~]# pvcreate /dev/sdb
    193 sdb   sdb1  
    194 [root@t201 ~]# pvcreate /dev/sdb
    195 sdb   sdb1  
    196 [root@t201 ~]# pvcreate /dev/sdb1
    197   Physical volume "/dev/sdb1" successfully created.
    198 [root@t201 ~]# pvdisplay 
    199   --- Physical volume ---
    200   PV Name               /dev/sda2
    201   VG Name               centos
    202   PV Size               <15.00 GiB / not usable 3.00 MiB
    203   Allocatable           yes (but full)
    204   PE Size               4.00 MiB
    205   Total PE              3839
    206   Free PE               0
    207   Allocated PE          3839
    208   PV UUID               dzMQgG-eMzE-6Vi4-WHOt-BdDH-KuTt-Ofk0gH
    209    
    210   "/dev/sdb1" is a new physical volume of "<20.00 GiB"
    211   --- NEW Physical volume ---
    212   PV Name               /dev/sdb1
    213   VG Name               
    214   PV Size               <20.00 GiB
    215   Allocatable           NO
    216   PE Size               0   
    217   Total PE              0
    218   Free PE               0
    219   Allocated PE          0
    220   PV UUID               G9jtn0-Gg0H-U55j-Hwzs-pafT-Mhtx-doyA9f
    221    
    222 [root@t201 ~]# vgextend centos /dev/sdb1
    223   Volume group "centos" successfully extended
    224 [root@t201 ~]# lvdisplay 
    225   --- Logical volume ---
    226   LV Path                /dev/centos/swap
    227   LV Name                swap
    228   VG Name                centos
    229   LV UUID                YKyysg-qNJY-x3sa-HjHm-5JHX-mBRf-mTpVXl
    230   LV Write Access        read/write
    231   LV Creation host, time localhost, 2019-11-14 08:57:14 +0800
    232   LV Status              available
    233   # open                 2
    234   LV Size                1.60 GiB
    235   Current LE             410
    236   Segments               1
    237   Allocation             inherit
    238   Read ahead sectors     auto
    239   - currently set to     8192
    240   Block device           253:1
    241    
    242   --- Logical volume ---
    243   LV Path                /dev/centos/root
    244   LV Name                root
    245   VG Name                centos
    246   LV UUID                dLgGwO-UXqd-41WI-C97j-suC8-siWt-3QWQQv
    247   LV Write Access        read/write
    248   LV Creation host, time localhost, 2019-11-14 08:57:14 +0800
    249   LV Status              available
    250   # open                 1
    251   LV Size                13.39 GiB
    252   Current LE             3429
    253   Segments               1
    254   Allocation             inherit
    255   Read ahead sectors     auto
    256   - currently set to     8192
    257   Block device           253:0
    258    
    259 [root@t201 ~]# lvextend -l +100%Free /dev/centos/root
    260   Size of logical volume centos/root changed from 13.39 GiB (3429 extents) to 33.39 GiB (8548 extents).
    261   Logical volume centos/root successfully resized.
    262 [root@t201 ~]# xfs_growfs /dev/centos/root
    263 meta-data=/dev/mapper/centos-root isize=512    agcount=4, agsize=877824 blks
    264          =                       sectsz=512   attr=2, projid32bit=1
    265          =                       crc=1        finobt=0 spinodes=0
    266 data     =                       bsize=4096   blocks=3511296, imaxpct=25
    267          =                       sunit=0      swidth=0 blks
    268 naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
    269 log      =internal               bsize=4096   blocks=2560, version=2
    270          =                       sectsz=512   sunit=0 blks, lazy-count=1
    271 realtime =none                   extsz=4096   blocks=0, rtextents=0
    272 data blocks changed from 3511296 to 8753152
    273 [root@t201 ~]# df -Th
    274 文件系统                类型      容量  已用  可用 已用% 挂载点
    275 devtmpfs                devtmpfs  3.9G     0  3.9G    0% /dev
    276 tmpfs                   tmpfs     3.9G     0  3.9G    0% /dev/shm
    277 tmpfs                   tmpfs     3.9G  8.6M  3.9G    1% /run
    278 tmpfs                   tmpfs     3.9G     0  3.9G    0% /sys/fs/cgroup
    279 /dev/mapper/centos-root xfs        34G  2.2G   32G    7% /
    280 /dev/sda1               xfs      1014M  134M  881M   14% /boot
    281 tmpfs                   tmpfs     797M     0  797M    0% /run/user/0
    282 [root@t201 ~]# 
    有趣的事,有趣的人,有趣的灵魂!
  • 相关阅读:
    git生成SSH秘钥
    ifconfig
    接口自动化测试平台:简介
    Gitd的使用
    jenkins自动化部署和Tomcat中间件容器
    Struts2——用来开发 MVC 应用程序的框架,可用于创建企业级Java web应用程序
    Hibernate——Java 领域的持久化ORM框架
    jQuery——JavaScript库
    JavaScript HTML DOM——文档对象模型
    JVM 完整深入解析
  • 原文地址:https://www.cnblogs.com/alusss/p/12113015.html
Copyright © 2020-2023  润新知