• 给VMware下的Linux扩容磁盘空间到根分区(以centos7.0为例)


    一、扩展VMWare硬盘空间

    关闭Vmware 的 Linux系统,这样,才能在VMWare菜单中设置:

      VM -> Settings... -> Hardware -> Hard Disk -> Utilities -> Expand

      输入你想要扩展到多少G。

    二、对新增加的硬盘进行分区、格式化

    查看挂载点

    # df -Th

    [root@localhost ~]# df -Th
    Filesystem              Type      Size  Used Avail Use% Mounted on
    /dev/mapper/centos-root xfs        15G  1.2G   14G   8% /
    devtmpfs                devtmpfs  1.9G     0  1.9G   0% /dev
    tmpfs                   tmpfs     1.9G     0  1.9G   0% /dev/shm
    tmpfs                   tmpfs     1.9G  8.6M  1.9G   1% /run
    tmpfs                   tmpfs     1.9G     0  1.9G   0% /sys/fs/cgroup
    /dev/sda1               xfs       197M  110M   88M  56% /boot
    tmpfs                   tmpfs     378M     0  378M   0% /run/user/0

     查看硬盘信息

    # lsblk

    [root@localhost ~]# lsblk
    NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
    sda               8:0    0  150G  0 disk 
    ├─sda1            8:1    0  200M  0 part /boot
    └─sda2            8:2    0   17G  0 part 
      ├─centos-root 253:0    0   15G  0 lvm  /
      └─centos-swap 253:1    0    2G  0 lvm  [SWAP]
    sr0              11:0    1    4G  0 rom  

     查看逻辑卷

    # lvs

    [root@localhost ~]# lvs
      LV   VG     Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
      root centos -wi-ao---- 15.00g                                                    
      swap centos -wi-ao----  2.00g   

     对扩容的硬盘进行分区

    # fdisk /dev/sda

    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): n
    Partition type:
       p   primary (2 primary, 0 extended, 2 free)
       e   extended
    Select (default p): p
    Partition number (3,4, default 3): 
    First sector (36079616-314572799, default 36079616): 
    Using default value 36079616
    Last sector, +sectors or +size{K,M,G} (36079616-314572799, default 314572799): +100G
    Partition 3 of type Linux and of size 100 GiB is set
    
    Command (m for help): p
    
    Disk /dev/sda: 161.1 GB, 161061273600 bytes, 314572800 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: 0x00007397
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/sda1   *        2048      411647      204800   83  Linux
    /dev/sda2          411648    36079615    17833984   8e  Linux LVM
    /dev/sda3        36079616   245794815   104857600   83  Linux
    
    Command (m for help): t
    Partition number (1-3, default 3): 
    Hex code (type L to list all codes): 8e
    Changed type of partition 'Linux' to 'Linux LVM'
    
    Command (m for help): p
    
    Disk /dev/sda: 161.1 GB, 161061273600 bytes, 314572800 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: 0x00007397
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/sda1   *        2048      411647      204800   83  Linux
    /dev/sda2          411648    36079615    17833984   8e  Linux LVM
    /dev/sda3        36079616   245794815   104857600   8e  Linux LVM
    
    Command (m for help): w
    The partition table has been altered!
    
    Calling ioctl() to re-read partition table.
    
    WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
    The kernel still uses the old table. The new table will be used at
    the next reboot or after you run partprobe(8) or kpartx(8)
    Syncing disks.

    需要重启才能生效

    #reboot

    重启后查看硬盘信息

    # lsblk

    [root@localhost ~]# lsblk
    NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
    sda               8:0    0  150G  0 disk 
    ├─sda1            8:1    0  200M  0 part /boot
    ├─sda2            8:2    0   17G  0 part 
    │ ├─centos-root 253:0    0   15G  0 lvm  /
    │ └─centos-swap 253:1    0    2G  0 lvm  [SWAP]
    └─sda3            8:3    0  100G  0 part 
    sr0              11:0    1    4G  0 rom  

     分区格式化

    # mkfs -t ext4 /dev/sda3

    [root@localhost ~]# mkfs -t ext4 /dev/sda3
    mke2fs 1.42.9 (28-Dec-2013)
    Filesystem label=
    OS type: Linux
    Block size=4096 (log=2)
    Fragment size=4096 (log=2)
    Stride=0 blocks, Stripe width=0 blocks
    6553600 inodes, 26214400 blocks
    1310720 blocks (5.00%) reserved for the super user
    First data block=0
    Maximum filesystem blocks=2174746624
    800 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, 2654208, 
            4096000, 7962624, 11239424, 20480000, 23887872
    
    Allocating group tables: done                            
    Writing inode tables: done                            
    Creating journal (32768 blocks): done
    Writing superblocks and filesystem accounting information: done   

    创建物理卷

    #pvcreate /dev/sda3

    [root@localhost ~]# pvcreate /dev/sda3
    WARNING: xfs signature detected on /dev/sda3 at offset 0. Wipe it? [y/n]: y
      Wiping xfs signature on /dev/sda3.
      Physical volume "/dev/sda3" successfully created

    加入根分区的逻辑卷组

    # vgextend centos /dev/sda3

    [root@localhost ~]# vgextend centos /dev/sda3
      Volume group "centos" successfully extended

    查看确认

    [root@localhost ~]# vgdisplay
      --- Volume group ---
      VG Name               centos
      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               117.00 GiB
      PE Size               4.00 MiB
      Total PE              29952
      Alloc PE / Size       4352 / 17.00 GiB
      Free  PE / Size       25600 / 100.00 GiB
      VG UUID               a27Boi-C0ue-9PCo-1rPZ-BsjW-9IRg-Woh4uX

    扩容

    # lvextend -L +100G /dev/centos/root 

    [root@localhost ~]# lvextend -L +100G /dev/centos/root 
      Size of logical volume centos/root changed from 15.00 GiB (3840 extents) to 115.00 GiB (29440 extents).
      Logical volume root successfully resized.

    操作生效

    # xfs_growfs /dev/centos/root 

    [root@localhost ~]# xfs_growfs /dev/centos/root 
    meta-data=/dev/mapper/centos-root isize=256    agcount=4, agsize=983040 blks
             =                       sectsz=512   attr=2, projid32bit=1
             =                       crc=0        finobt=0
    data     =                       bsize=4096   blocks=3932160, 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 3932160 to 30146560

    查看是否成功扩容

    # df -Th

    [root@localhost ~]# df -Th
    Filesystem              Type      Size  Used Avail Use% Mounted on
    /dev/mapper/centos-root xfs       115G  1.2G  114G   2% /
    devtmpfs                devtmpfs  1.9G     0  1.9G   0% /dev
    tmpfs                   tmpfs     1.9G     0  1.9G   0% /dev/shm
    tmpfs                   tmpfs     1.9G  8.6M  1.9G   1% /run
    tmpfs                   tmpfs     1.9G     0  1.9G   0% /sys/fs/cgroup
    /dev/sda1               xfs       197M  110M   88M  56% /boot
    tmpfs                   tmpfs     378M     0  378M   0% /run/user/0

    # vgdisplay

    [root@localhost ~]# vgdisplay
      --- Volume group ---
      VG Name               centos
      System ID             
      Format                lvm2
      Metadata Areas        2
      Metadata Sequence No  5
      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               117.00 GiB
      PE Size               4.00 MiB
      Total PE              29952
      Alloc PE / Size       29952 / 117.00 GiB
      Free  PE / Size       0 / 0   
      VG UUID               a27Boi-C0ue-9PCo-1rPZ-BsjW-9IRg-Woh4uX

    参考博客:

    Linux中VMware虚拟机增加磁盘空间的扩容操作

    https://www.cnblogs.com/matengfei123/p/7986259.html

    给VMware下的Linux扩展磁盘空间(以CentOS6.5为例)

    https://www.cnblogs.com/shijiaoyun/p/6207699.html

    end

  • 相关阅读:
    go 自定义RWMutex
    go defer的*i和i参数
    go defer 易错题
    EasyPlayer移动端播放webrtc协议时长按播放页面无法关闭“关于我们”页面
    高速公路服务区智能一体机解决方案
    【操作教程】TSINGSEE青犀视频平台如何将旧数据库导入到新数据库?
    EasyPlayer流媒体播放器播放HLS视频,起播速度慢的技术优化
    开发那些事儿:如何在CentOS7下安装部署ffmpeg?
    开发那些事儿:前端开发环境报错“[vuex]unknown action type”如何解决?
    H.264转码H.265出现崩溃并报错“missing picture”该如何解决?
  • 原文地址:https://www.cnblogs.com/djlsunshine/p/10394297.html
Copyright © 2020-2023  润新知