擴大VMware虛擬機中CentOS7的硬盤空間

擴大VMware虛擬機中CentOS7的硬盤空間過程記錄

參考鏈接:

http://blog.csdn.net/remote_roamer/article/details/50670802

http://www.cnblogs.com/juandx/p/5618162.html

 

1.    關閉虛擬機,虛擬機設置->硬盤->磁盤實用工具->擴展

原來的linux硬盤只有30G,擴展到100G

 

2.    對新增加的硬盤進行分區、格式化

2.1對新增加的硬盤進行分區

輸入命令:fdisk /dev/sda (因爲上面選擇的是擴展,即在原有的硬盤sda進行擴展,所以增加空間的硬盤是/dev/sda)

按照提示輸入:

[root@centos7dev~]# fdisk /dev/sda

Welcome to fdisk(util-linux 2.23.2).

Changes will remainin memory only, until you decide to write them.

Be careful beforeusing the write command.

Command (m for help):p (查看已分區數量 有兩個/dev/sda1 /dev/sda2))

Disk /dev/sda: 107.4GB, 107374182400 bytes, 209715200 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:0x0003f424

Device Boot      Start         End      Blocks  Id  System

/dev/sda1   *  2048     1026047      512000 83  Linux

/dev/sda2    1026048   62914559    30944256  8e Linux LVM(原來的30G硬盤)

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 (62914560-209715199, default 62914560):Entre(回車,選擇默認起始扇區)

Using default value62914560

Last sector, +sectors or +size{K,M,G} (62914560-209715199, default209715199): Entre(回車,選擇默認結束扇區)

Using default value209715199

Partition 3 of typeLinux and of size 70 GiB is set

 

Command (m for help):t (t修改分區類型)

Partition number (1-3, default 3):3(選分區3)

Hex code (type L to list all codes):8e(修改爲LVM(8es就是上面p選項查看到的id)LVM是 LogicalVolume Manager(邏輯卷管理))

Changed type ofpartition 'Linux' to 'Linux LVM'

Command (m for help):w (保存)

The partition tablehas been altered!

Calling ioctl() tore-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 usedat

the next reboot or after you run partprobe(8) or kpartx(8)

Syncing disks.

[root@centos7dev~]# partprobe (根據上面的提示輸入)

[root@centos7dev~]# reboot (重啓linux)

 

2.2對新增加的硬盤進行格式化

重啓linux後格式化分區:mkfs.xfs /dev/sda3(sda3是剛纔分的區,另外注意:格式成什麼文件系統要使用df -Th命令先查看你當前linux系統使用的是什麼文件系統,我這邊看到的打印內容是:

Filesystem              Type      Size Used Avail Use% Mounted on

/dev/mapper/centos-root  xfs       28G   12G   17G 42% /

所以使用mkfs.xfs命令

 

2.3.添加新LVM到已有的LVM組,實現擴容

lvm 進入lvm管理:

lvm> pvcreate /dev/sda3初始化剛纔的分區

lvm> vgdisplay 查看卷組(Volumegroup)名稱

--- Volumegroup ---

VGName               centos

… … …

lvm> vgextend centos /dev/sda3  將初始化過的分區加入到虛擬卷組centos

lvm> lvdisplay 查看邏輯卷(Logical volume)情況,可以看到新建的70G邏輯卷

  --- Physical volume ---

  PV Name               /dev/sda2

  VG Name               centos

  PV Size               29.51 GiB / not usable 3.00 MiB

  Allocatable           yes

  … … …

"/dev/sda3" is a new physicalvolume of "70.00 GiB"

  --- NEW Physical volume ---

  PV Name               /dev/sda3

  VG Name              

  PV Size               70.00 GiB

  Allocatable           NO

  … … …

lvm> lvextend-L +70G /dev/centos/root 增加物理捲到根目錄,從上面的打印信息中可以看到根目錄是在/dev/centos/root

 

3. 以上只是卷擴容了,下面是文件系統的真正擴容,輸入以下命令:

xfs_growfs /dev/mapper/centos-root

 

4. 結果查看

[root@centos7dev~]# df -h

Filesystem               Size  Used Avail Use% Mounted on

/dev/mapper/centos-root   97G  12G   86G  12% /

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章