VM虛擬機器安裝CentOS7擴充套件儲存空間的方法
阿新 • • 發佈:2019-01-07
VM虛擬機器安裝CentOS7擴充套件儲存空間的方法
1.在關機狀態下,在Vm裡面設定系統大小到需要的數值 60G;
2.使用root許可權登陸linux,df -h檢視系統情況;
# fdisk -l
3.沒有找到掛載點,預設是/dev/sda必須要先試用fdisk格式化,初始化掛載磁碟才可以使用
# fdisk /dev/sda
具體如下所示:
[[email protected] ~]# fdisk -l
磁碟 /dev/sda:64.4 GB, 64424509440 位元組,125829120 個扇區
Units = 扇區 of 1 * 512 = 512 bytes
扇區大小(邏輯/物理):512 位元組 / 512 位元組
I/O 大小(最小/最佳):512 位元組 / 512 位元組
磁碟標籤型別:dos
磁碟識別符號:0x000a89c1
裝置 Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 41943039 19921920 8e Linux LVM
磁碟 /dev/mapper/cl-root:18.2 GB, 18249416704 位元組,35643392 個扇區
Units = 扇區 of 1 * 512 = 512 bytes
扇區大小(邏輯/物理):512 位元組 / 512 位元組
I/O 大小(最小/最佳):512 位元組 / 512 位元組
磁碟 /dev/mapper/cl-swap:2147 MB, 2147483648 位元組,4194304 個扇區
Units = 扇區 of 1 * 512 = 512 bytes
扇區大小(邏輯/物理):512 位元組 / 512 位元組
I/O 大小(最小/最佳):512 位元組 / 512 位元組
[ [email protected] ~]# fdisk /dev/sda
歡迎使用 fdisk (util-linux 2.23.2)。
更改將停留在記憶體中,直到您決定將更改寫入磁碟。
使用寫入命令前請三思。
命令(輸入 m 獲取幫助):p
磁碟 /dev/sda:64.4 GB, 64424509440 位元組,125829120 個扇區
Units = 扇區 of 1 * 512 = 512 bytes
扇區大小(邏輯/物理):512 位元組 / 512 位元組
I/O 大小(最小/最佳):512 位元組 / 512 位元組
磁碟標籤型別:dos
磁碟識別符號:0x000a89c1
裝置 Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 41943039 19921920 8e Linux LVM
命令(輸入 m 獲取幫助):n
Partition type:
p primary (2 primary, 0 extended, 2 free)
e extended
Select (default p): p
分割槽號 (3,4,預設 3):3
起始 扇區 (41943040-125829119,預設為 41943040):
將使用預設值 41943040
Last 扇區, +扇區 or +size{K,M,G} (41943040-125829119,預設為 125829119):
將使用預設值 125829119
分割槽 3 已設定為 Linux 型別,大小設為 40 GiB
命令(輸入 m 獲取幫助):t
分割槽號 (1-3,預設 3):3
Hex 程式碼(輸入 L 列出所有程式碼):8e
已將分割槽“Linux”的型別更改為“Linux LVM”
命令(輸入 m 獲取幫助):w
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: 裝置或資源忙.
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)
正在同步磁碟。
[ [email protected] ~]#
4.重啟機器;
[[email protected] ~]# fdisk -l 磁碟 /dev/sda:64.4 GB, 64424509440 位元組,125829120 個扇區 Units = 扇區 of 1 * 512 = 512 bytes 扇區大小(邏輯/物理):512 位元組 / 512 位元組 I/O 大小(最小/最佳):512 位元組 / 512 位元組 磁碟標籤型別:dos 磁碟識別符號:0x000a89c1 裝置 Boot Start End Blocks Id System /dev/sda1 * 2048 2099199 1048576 83 Linux /dev/sda2 2099200 41943039 19921920 8e Linux LVM /dev/sda3 41943040 125829119 41943040 8e Linux LVM 磁碟 /dev/mapper/cl-root:18.2 GB, 18249416704 位元組,35643392 個扇區 Units = 扇區 of 1 * 512 = 512 bytes 扇區大小(邏輯/物理):512 位元組 / 512 位元組 I/O 大小(最小/最佳):512 位元組 / 512 位元組 磁碟 /dev/mapper/cl-swap:2147 MB, 2147483648 位元組,4194304 個扇區 Units = 扇區 of 1 * 512 = 512 bytes 扇區大小(邏輯/物理):512 位元組 / 512 位元組 I/O 大小(最小/最佳):512 位元組 / 512 位元組
5.格式化分割槽,mkfs.ext3 /dev/sda3一直掛載的分割槽是sda3;
[[email protected] ~]# mkfs.ext3 /dev/sda3
mke2fs 1.42.9 (28-Dec-2013)
檔案系統標籤=
OS type: Linux
塊大小=4096 (log=2)
分塊大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
2621440 inodes, 10485760 blocks
524288 blocks (5.00%) reserved for the super user
第一個資料塊=0
Maximum filesystem blocks=4294967296
320 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
Allocating group tables: 完成
正在寫入inode表: 完成
Creating journal (32768 blocks): 完成
Writing superblocks and filesystem accounting information: 完成
6.輸入以下指令:
lvm //進入lvm管理
lvm>pvcreate /dev/sda3
lvm>vgextend cl /dev/sda3 //將初始化過的分割槽加入到虛擬卷組centos
lvm>vgdisplay -v
lvm>lvextend -l+10239 /dev/mapper/cl-root
lvm>pvdisplay //檢視卷容量
lvm>quit
具體如下操作:
[[email protected] ~]# 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 cl /dev/sda3
Volume group "cl" successfully extended
lvm> vgdisplay -v
--- Volume group ---
VG Name cl
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 58.99 GiB
PE Size 4.00 MiB
Total PE 15102
Alloc PE / Size 4863 / 19.00 GiB
Free PE / Size 10239 / 40.00 GiB
VG UUID on4380-dNuw-urE1-TJDY-35tA-4vfc-GpyR2G
--- Logical volume ---
LV Path /dev/cl/swap
LV Name swap
VG Name cl
LV UUID ZsoXDE-3M6U-G8y4-ciui-t4ZU-369P-LGDrfW
LV Write Access read/write
LV Creation host, time code, 2018-08-28 22:25:06 +0800
LV Status available
# open 2
LV Size 2.00 GiB
Current LE 512
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:1
--- Logical volume ---
LV Path /dev/cl/root
LV Name root
VG Name cl
LV UUID 6uJJVw-T2Ki-XTRF-ARJA-EkVl-3qz0-l86XMp
LV Write Access read/write
LV Creation host, time code, 2018-08-28 22:25:06 +0800
LV Status available
# open 1
LV Size 17.00 GiB
Current LE 4351
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:0
--- Physical volumes ---
PV Name /dev/sda2
PV UUID iFb3r2-umXf-IfjS-LCvb-pldM-x3Me-BHnhkJ
PV Status allocatable
Total PE / Free PE 4863 / 0
PV Name /dev/sda3
PV UUID WpJpn3-0ZO0-n52O-yLOo-I3Ki-f5SU-SQCKFY
PV Status allocatable
Total PE / Free PE 10239 / 10239
lvm> lvextend -l+1298 /dev/mapper/cl-root
Size of logical volume cl/root changed from 17.00 GiB (4351 extents) to 22.07 GiB (5649 extents).
Logical volume cl/root successfully resized.
lvm> vgdisplay -v
--- Volume group ---
VG Name cl
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 58.99 GiB
PE Size 4.00 MiB
Total PE 15102
Alloc PE / Size 6161 / 24.07 GiB
Free PE / Size 8941 / 34.93 GiB
VG UUID on4380-dNuw-urE1-TJDY-35tA-4vfc-GpyR2G
--- Logical volume ---
LV Path /dev/cl/swap
LV Name swap
VG Name cl
LV UUID ZsoXDE-3M6U-G8y4-ciui-t4ZU-369P-LGDrfW
LV Write Access read/write
LV Creation host, time code, 2018-08-28 22:25:06 +0800
LV Status available
# open 2
LV Size 2.00 GiB
Current LE 512
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:1
--- Logical volume ---
LV Path /dev/cl/root
LV Name root
VG Name cl
LV UUID 6uJJVw-T2Ki-XTRF-ARJA-EkVl-3qz0-l86XMp
LV Write Access read/write
LV Creation host, time code, 2018-08-28 22:25:06 +0800
LV Status available
# open 1
LV Size 22.07 GiB
Current LE 5649
Segments 2
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:0
--- Physical volumes ---
PV Name /dev/sda2
PV UUID iFb3r2-umXf-IfjS-LCvb-pldM-x3Me-BHnhkJ
PV Status allocatable
Total PE / Free PE 4863 / 0
PV Name /dev/sda3
PV UUID WpJpn3-0ZO0-n52O-yLOo-I3Ki-f5SU-SQCKFY
PV Status allocatable
Total PE / Free PE 10239 / 8941
lvm> lvextend -l+8941 /dev/mapper/cl-root
Size of logical volume cl/root changed from 22.07 GiB (5649 extents) to 56.99 GiB (14590 extents).
Logical volume cl/root successfully resized.
lvm> pvdisplay
--- Physical volume ---
PV Name /dev/sda2
VG Name cl
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 iFb3r2-umXf-IfjS-LCvb-pldM-x3Me-BHnhkJ
--- Physical volume ---
PV Name /dev/sda3
VG Name cl
PV Size 40.00 GiB / not usable 4.00 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 10239
Free PE 0
Allocated PE 10239
PV UUID WpJpn3-0ZO0-n52O-yLOo-I3Ki-f5SU-SQCKFY
lvm> quit
Exiting.
[[email protected] ~]#
7.使用命令xfs_growfs /dev/mapper/cl-root擴充套件容量。
8.使用df -h可以看到擴充套件成功。
[[email protected] ~]# xfs_growfs /dev/mapper/cl-root
meta-data=/dev/mapper/cl-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 14940160
[[email protected] ~]# df -h
檔案系統 容量 已用 可用 已用% 掛載點
/dev/mapper/cl-root 57G 4.8G 53G 9% /
devtmpfs 902M 0 902M 0% /dev
tmpfs 912M 0 912M 0% /dev/shm
tmpfs 912M 8.6M 904M 1% /run
tmpfs 912M 0 912M 0% /sys/fs/cgroup
/dev/sda1 1014M 139M 876M 14% /boot
tmpfs 183M 0 183M 0% /run/user/0
[[email protected] ~]#
—the–end—