centos应用服务配置我用 Linux

[centos+VMware] 硬盘容量扩展

2019-01-02  本文已影响1人  Hellooooooworld

part.0 环境

centos: 7.5.1804
VMware: 14.1.1
扩容大小:20G


part.1 增加VMware硬盘空间

1.1 关闭虚拟机
1.2 虚拟机-> 设置-> 硬盘 ->选中需要的硬盘扩展

part.2 新增硬盘分区

$ 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): p #查看以分区数量(存在两个sda1和sda2)

Disk /dev/sda: 42.9 GB, 42949672960 bytes, 83886080 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: 0x000bc5e0

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200    41943039    19921920   8e  Linux LVM

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): 3 #因为已经存在两个分区,所以分区号为3
First sector (41943040-83886079, default 41943040): 
Using default value 41943040
Last sector, +sectors or +size{K,M,G} (41943040-83886079, default 83886079): 
Using default value 83886079
Partition 3 of type Linux and of size 20 GiB is set
Command (m for help): t #修改分区类型
Partition number (1-3, default 3): 3 #分区号
Hex code (type L to list all codes): 8e #分区类型为8e
Changed type of partition 'XENIX usr' to '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.
$ shutdown -r now # 分区后需要重启

part.3 硬盘格式化

$ mkfs.ext3 /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
1310720 inodes, 5242880 blocks
262144 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
160 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

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done 

part.4 添加新LVM到已存在的LVM,进行扩容

$ lvm
lvm> pvcreate /dev/sda3
WARNING: ext3 signature detected on /dev/sda3 at offset 1080. Wipe it? [y/n]: y
  Wiping ext3 signature on /dev/sda3.
  Physical volume "/dev/sda3" successfully created.
lvm> vgextend centos /dev/sdb3
  Device /dev/sdb3 not found.
lvm> vgextend centos /dev/sda3
  Volume group "centos" successfully extended
lvm> lvextend -L +20G /dev/mapper/centos-root
  Insufficient free space: 5120 extents needed, but only 5119 available
lvm> lvextend -L +19.9G /dev/mapper/centos-root  
  Rounding size to boundary between physical extents: 19.90 GiB.
  Size of logical volume centos/root changed from <17.00 GiB (4351 extents) to <36.90 GiB (9446 extents).
  Logical volume centos/root successfully resized.
lvm> pvdisplay 
  --- Physical volume ---
  PV Name               /dev/sda2
  VG Name               centos
  PV Size               <19.00 GiB / not usable 3.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              4863
  Free PE               0
  Allocated PE          4863
  PV UUID               NhWECB-7yJu-3h3e-eJjI-Soqb-J3hM-JtBuRq
   
  --- Physical volume ---
  PV Name               /dev/sda3
  VG Name               centos
  PV Size               20.00 GiB / not usable 4.00 MiB
  Allocatable           yes 
  PE Size               4.00 MiB
  Total PE              5119
  Free PE               24
  Allocated PE          5095
  PV UUID               pCXJQ8-1FN7-cG8d-tMBR-2QgF-VvHC-uJvUnM
   
lvm> quit
  Exiting.

part.5 文件系统扩容

$ resize2fs /dev/mapper/centos-
centos-root  centos-swap  
[root@hadoop1 ~]# resize2fs /dev/mapper/centos-root 
resize2fs 1.42.9 (28-Dec-2013)
resize2fs: Bad magic number in super-block while trying to open /dev/mapper/centos-root
Couldn't find valid filesystem superblock.

error: Bad magic number in super-block while trying to open /dev/mapper/centos-root,Couldn't find valid filesystem superblock.

出现上述错误时,尝试xfs_growfs

$ xfs_growfs /dev/mapper/centos-root 
meta-data=/dev/mapper/centos-root isize=512    agcount=4, agsize=1113856 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=4455424, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
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 4455424 to 9672704

查看硬盘信息

$ df -Th
Filesystem              Type      Size  Used Avail Use% Mounted on
/dev/mapper/centos-root xfs        37G   17G   21G  46% /
devtmpfs                devtmpfs  1.4G     0  1.4G   0% /dev
tmpfs                   tmpfs     1.4G     0  1.4G   0% /dev/shm
tmpfs                   tmpfs     1.4G  9.5M  1.4G   1% /run
tmpfs                   tmpfs     1.4G     0  1.4G   0% /sys/fs/cgroup
/dev/sdb1               ext4      9.8G  896M  8.4G  10% /usr/local/work
/dev/sda1               xfs      1014M  142M  873M  14% /boot
tmpfs                   tmpfs     283M     0  283M   0% /run/user/0
上一篇下一篇

猜你喜欢

热点阅读