虛擬機空間:現sda大小20G,因課程需要擴容
在虛擬機擴容中,
新增一塊硬盤 和 直接在原有硬盤基礎上擴容是一樣的(只不過在原有硬盤上擴容需要關機才可以執行);
但兩者都最好先做數據備份或快照,再進行擴容操作;(不建議快照,因為擴展不支持)
查看磁盤情況
?
新增磁盤擴容lvm分區
1、Centos 關機,選擇編輯虛擬機設置,硬盤,在實用工具那里選擇“擴展”(不建議快照,因為擴展不支持)
?
提示磁盤已成功擴展。您必須從客戶機操作系統內部對磁盤重新進行分區和擴展文件系統。擴展的磁盤空間還沒生效,需要在操作系統里面進行設置后才能使用。?
2、啟動客戶機操作系統Centos,查看磁盤情況
新增或擴容后,可以通過命令:lsblk 或fdisk -l 對磁盤大小的變化來判斷是否有加載成功;
?
3、創建分區 sda3
輸入指令 ?fdisk /dev/sda
根據命令提示創建分區,具體見以下 # 后面的注釋
[root@hadoop1 ~]# fdisk /dev/sda
歡迎使用 fdisk (util-linux 2.23.2)。更改將停留在內存中,直到您決定將更改寫入磁盤。
使用寫入命令前請三思。命令(輸入 m 獲取幫助):m
命令操作a toggle a bootable flagb edit bsd disklabelc toggle the dos compatibility flagd delete a partitiong create a new empty GPT partition tableG create an IRIX (SGI) partition tablel list known partition typesm print this menun add a new partitiono create a new empty DOS partition tablep print the partition tableq quit without saving changess create a new empty Sun disklabelt change a partition's system idu change display/entry unitsv verify the partition tablew write table to disk and exitx extra functionality (experts only)命令(輸入 m 獲取幫助):n # 輸入 n 表示創建新分區
Partition type:p primary (2 primary, 0 extended, 2 free)e extended
Select (default p): p #
分區號 (3,4,默認 3):3 # 輸入 3 表示sda3,因為前面已經有兩個了
起始 扇區 (41943040-104857599,默認為 41943040): # 回車,按默認值
將使用默認值 41943040
Last 扇區, +扇區 or +size{K,M,G} (41943040-104857599,默認為 104857599): # 回車,按默認值
將使用默認值 104857599
分區 3 已設置為 Linux 類型,大小設為 30 GiB命令(輸入 m 獲取幫助):w # 輸入 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)
正在同步磁盤。
?再次查看分區情況:fdisk -l
[root@hadoop1 ~]# fdisk -l設備 Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 41943039 19921920 8e Linux LVM
/dev/sda3 41943040 1
?分區已變為3個了,但這時還沒掛載,還不能用
4、重啟操作系統?
? ? Init 6 ??或 ???reboot
5、格式化新分區為sda3
mkfs -t ext3 /dev/sda3
[root@hadoop1 ~]# mkfs -t 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
1966080 inodes, 7864320 blocks
393216 blocks (5.00%) reserved for the super user
第一個數據塊=0
Maximum filesystem blocks=4294967296
240 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, 4096000Allocating group tables: 完成
正在寫入inode表: 完成
Creating journal (32768 blocks): 完成
Writing superblocks and filesystem accounting information: 完成
6、將物理硬盤分區初始化為物理卷,以便被LVM使用,輸入指令
lvs
pvcreate /dev/sda3
[root@hadoop1 ~]# lvsLV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convertroot centos -wi-ao---- <17.00g swap centos -wi-ao---- 2.00g
[root@hadoop1 ~]# pvcreate /dev/sda3
WARNING: ext3 signature detected on /dev/sda3 at offset 1080. Wipe it? [y/n]: yWiping ext3 signature on /dev/sda3.Physical volume "/dev/sda3" successfully created.
7、向卷組中添加物理卷來增加卷組的容量
查看lvm組名,輸入指令 df -h
[root@hadoop1 ~]# df -h
文件系統 容量 已用 可用 已用% 掛載點
devtmpfs 894M 0 894M 0% /dev
tmpfs 910M 0 910M 0% /dev/shm
tmpfs 910M 11M 900M 2% /run
tmpfs 910M 0 910M 0% /sys/fs/cgroup
/dev/mapper/centos-root 17G 14G 3.5G 80% /
/dev/sda1 1014M 184M 831M 19% /boot
tmpfs 182M 4.0K 182M 1% /run/user/42
tmpfs 182M 20K 182M 1% /run/user/0
/dev/sr0 4.4G 4.4G 0 100% /run/media/root/CentOS 7 x86_64
其中,centos ?就是 根 所在的組名
輸入指令,增加卷組的容量??vgextend centos /dev/sda3
[root@hadoop1 ~]# vgextend centos /dev/sda3Volume group "centos" successfully extended
查看可拓展的空間大小
輸入指令,顯示LNM卷組的元數據信息?vgdisplay
?
9、擴充磁盤空間
?lvextend -l +100%FREE /dev/mapper/centos-root
root@hadoop1 ~]# lvextend -l +100%FREE /dev/mapper/centos-rootSize of logical volume centos/root changed from <17.00 GiB (4351 extents) to 46.99 GiB (12030 extents).Logical volume centos/root successfully resized.
10、使用?指令檢查文件系統錯誤??xfs_growfs /dev/mapper/centos-root
[root@hadoop1 ~]# 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 12318720
11、使用指令來增大或者收縮未加載的 文件系統的大小
?xfs_growfs -d /dev/mapper/centos-root
[root@hadoop1 ~]# xfs_growfs -d /dev/mapper/centos-root
meta-data=/dev/mapper/centos-root isize=512 agcount=12, agsize=1113856 blks= sectsz=512 attr=2, projid32bit=1= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=12318720, 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 size unchanged, skipping
12、查看擴展空間后的結果
[root@hadoop1 ~]# df -h
文件系統 容量 已用 可用 已用% 掛載點
devtmpfs 894M 0 894M 0% /dev
tmpfs 910M 0 910M 0% /dev/shm
tmpfs 910M 11M 900M 2% /run
tmpfs 910M 0 910M 0% /sys/fs/cgroup
/dev/mapper/centos-root 47G 14G 34G 29% /
/dev/sda1 1014M 184M 831M 19% /boot
tmpfs 182M 4.0K 182M 1% /run/user/42
tmpfs 182M 20K 182M 1% /run/user/0
/dev/sr0 4.4G 4.4G 0 100% /run/media/root/CentOS 7 x86_64
?或者通過命令:?lsblk 或fdisk -l 對磁盤大小的變化來判斷是否有加載成功;
[root@hadoop1 ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 50G 0 disk
├─sda1 8:1 0 1G 0 part /boot
├─sda2 8:2 0 19G 0 part
│ ├─centos-root 253:0 0 47G 0 lvm /
│ └─centos-swap 253:1 0 2G 0 lvm [SWAP]
└─sda3 8:3 0 30G 0 part └─centos-root 253:0 0 47G 0 lvm /
sr0 11:0 1 4.4G 0 rom /run/media/root/CentOS 7 x86_64