【大数据集群运维】VMware虚拟机扩展Linux的root根目录磁盘空间(Centos7)
一、Centos 关机,选择编辑虚拟机设置,硬盘,在实用工具那里选择“扩展”二、启动客户机操作系统Centos,在操作系统内部对磁盘重新分区和扩容1 fdisk -lDisk /dev/loop0: 107.4 GB, 107374182400 bytes255 heads, 63 sectors/track, 13054 cylindersUnits = cylinders of 16065 *
·
一、Centos 关机,选择编辑虚拟机设置,硬盘,在实用工具那里选择“扩展”
二、启动客户机操作系统Centos,在操作系统内部对磁盘重新分区和扩容
1 fdisk -l
Disk /dev/loop0: 107.4 GB, 107374182400 bytes
255 heads, 63 sectors/track, 13054 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Disk /dev/loop1: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Disk /dev/sda: 37.6 GB, 37580963840 bytes
255 heads, 63 sectors/track, 4568 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000c8278
Device Boot Start End Blocks Id System
/dev/sda1 * 1 64 512000 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 64 1306 9972736 8e Linux LVM
Disk /dev/mapper/vg_test001-lv_root: 9135 MB, 9135194112 bytes
255 heads, 63 sectors/track, 1110 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Disk /dev/mapper/vg_test001-lv_swap: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Disk /dev/mapper/docker-253:0-264224-pool: 107.4 GB, 107374182400 bytes
255 heads, 63 sectors/track, 13054 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 65536 bytes
Disk identifier: 0x00000000
2其中,可以看到现在的分区情况如下
Device Boot Start End Blocks Id System
/dev/sda1 * 1 64 512000 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 64 1306 9972736 8e Linux LVM
3、创建分区 sda3fdisk /dev/sda
WARNING: DOS-compatible mode is deprecated. It s strongly recommended to
switch off the mode (command 'c') and change display units to
sectors (command 'u').
Command (m for help): n # 输入 n 表示创建新分区
Command action
e extended
p primary partition (1-4)
p # 默认输入P
Partition number (1-4): 3 # 输入 3 表示sda3,因为前面已经有两个了
First cylinder (1306-4568, default 1306): # 回车,按默认值
Using default value 1306
Last cylinder, +cylinders or +size{K,M,G} (1306-4568, default 4568): # 回车,按默认值
Using default value 4568
Command (m for help): 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: 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.
再次查看分区情况 fdisk -l
Disk /dev/loop0: 107.4 GB, 107374182400 bytes
255 heads, 63 sectors/track, 13054 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Disk /dev/loop1: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Disk /dev/sda: 37.6 GB, 37580963840 bytes
255 heads, 63 sectors/track, 4568 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000c8278
Device Boot Start End Blocks Id System
/dev/sda1 * 1 64 512000 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 64 1306 9972736 8e Linux LVM
/dev/sda3 1306 4568 26206700 83 Linux
Disk /dev/mapper/vg_test001-lv_root: 9135 MB, 9135194112 bytes
255 heads, 63 sectors/track, 1110 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Disk /dev/mapper/vg_test001-lv_swap: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Disk /dev/mapper/docker-253:0-264224-pool: 107.4 GB, 107374182400 bytes
255 heads, 63 sectors/track, 13054 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 65536 bytes
Disk identifier: 0x00000000
其中,分区已变为3个(/dev/sda1,/dev/sda2,/dev/sda3)了,但这时还没挂载,还不能用,
4、重启操作系统
5、格式化新分区为ext3
mkfs -t ext3 /dev/sda3
[root@shuang ~]# 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
1310720 inodes, 5242880 blocks
262144 blocks (5.00%) reserved for the super user
第一个数据块=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: 完成
正在写入inode表: 完成
Creating journal (32768 blocks): 完成
Writing superblocks and filesystem accounting information: 完成
6、将物理硬盘分区初始化为物理卷,以便被LVM使用,输入指令
[root@shuang ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
root centos_shuang -wi-ao---- <17.00g
swap centos_shuang -wi-ao---- 2.00g
[root@shuang ~]# lvs
pvcreate /dev/sda3 LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
root centos_shuang -wi-ao---- <17.00g
swap centos_shuang -wi-ao---- 2.00g
[root@shuang ~]# pvcreate /dev/sda3
WARNING: ext3 signature detected on /dev/sda3 at offset 1080. Wipe it? [y/n]:
WARNING: Invalid input ''.
WARNING: ext3 signature detected on /dev/sda3 at offset 1080. Wipe it? [y/n]: ^H^H^Hy
WARNING: Invalid input 'y'.
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.
7、向卷组中添加物理卷来增加卷组的容量
[root@shuang ~]# df -h
文件系统 容量 已用 可用 已用% 挂载点
devtmpfs 1.2G 0 1.2G 0% /dev
tmpfs 1.2G 0 1.2G 0% /dev/shm
tmpfs 1.2G 9.9M 1.2G 1% /run
tmpfs 1.2G 0 1.2G 0% /sys/fs/cgroup
/dev/mapper/centos_shuang-root 17G 6.4G 11G 38% /
/dev/sda1 1014M 184M 831M 19% /boot
tmpfs 229M 0 229M 0% /run/user/0
其中centos_shuang是组名
[root@shuang ~]# vgextend centos_shuang-root /dev/sda3
Volume group "centos_shuang-root" not found
Cannot process volume group centos_shuang-root
[root@shuang ~]# vgextend centos_shuang /dev/sda3
Volume group "centos_shuang" successfully extended
8、查看可扩展的空间大小
vgdisplay
vgdisplay
--- Volume group ---
VG Name centos_shuang
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 38.99 GiB
PE Size 4.00 MiB
Total PE 9982
Alloc PE / Size 4863 / <19.00 GiB
Free PE / Size 5119 / <20.00 GiB
VG UUID B8mmPl-Nyh8-N9yN-7OQf-in8I-neL7-zFrK2P
其中 Free PE / Size 就是可供分配的自由空间,最多有 19G,在扩展时输入小于该值
9、扩充磁盘空间
lvextend -L+19G /dev/mapper/centos_shuang-root /dev/sda3
lvextend -L+19G /dev/mapper/centos_shuang-root /dev/sda3
Size of logical volume centos_shuang/root changed from <17.00 GiB (4351 extents) to <36.00 GiB (9215 extents).
Logical volume centos_shuang/root successfully resized.
10、使用e2fsck指令检查文件系统错误
e2fsck -a /dev/mapper/centos_shuang-root
e2fsck -a /dev/mapper/centos_shuang-root
/dev/mapper/centos_shuang-root is mounted.
e2fsck: 无法继续, 中止.
查看lv空间是否扩充成功
lvdisplay
[root@shuang ~]# lvdisplay
--- Logical volume ---
LV Path /dev/centos_shuang/swap
LV Name swap
VG Name centos_shuang
LV UUID bc72KO-b6hy-IvVN-MXSk-OUKM-7JTV-EcPJ2E
LV Write Access read/write
LV Creation host, time shuang, 2020-01-09 13:54:14 +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/centos_shuang/root
LV Name root
VG Name centos_shuang
LV UUID j37rXa-Ug0E-Y2sE-hz6m-QpEw-LX1X-LLCgTo
LV Write Access read/write
LV Creation host, time shuang, 2020-01-09 13:54:15 +0800
LV Status available
# open 1
LV Size <36.00 GiB
Current LE 9215
Segments 2
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:0
11、使用Centeros7指令 xfs_growfs /dev/mapper/centos_shuang-root
将LV空间同步到文件系统根目录中
xfs_growfs /dev/mapper/centos_shuang-root
meta-data=/dev/mapper/centos_shuang-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 9436160
12 验证查看是否同步成功
在CenterOS7系列中xfs同步要用下面这个命令
xfs_growfs
CenterOS6系列中xfs同步要用下面这两个命令都可
dumpe2fs
resize2fs -f
[root@shuang ~]# df -h
文件系统 容量 已用 可用 已用% 挂载点
devtmpfs 1.2G 0 1.2G 0% /dev
tmpfs 1.2G 0 1.2G 0% /dev/shm
tmpfs 1.2G 9.9M 1.2G 1% /run
tmpfs 1.2G 0 1.2G 0% /sys/fs/cgroup
/dev/mapper/centos_shuang-root 36G 6.4G 30G 18% /
/dev/sda1 1014M 184M 831M 19% /boot
tmpfs 229M 0 229M 0% /run/user/0
根目录 36G,扩容成功!
更多推荐
已为社区贡献1条内容
所有评论(0)