centos7扩展磁盘空间
准备vmware安装centos7,在lvm下和非lvm下分别进行测试虚拟机扩展硬盘容量选择扩展将原来的20g扩展到100g非lvm下如何扩展磁盘fdisk -l发现只有一个盘/dev/sda,分成了3个区,sda1,sda2,sda3Disk /dev/sda: 20.4 GBUnits = sectors of 1 * 512 = 512 bytesSect...
准备
vmware安装centos7,在lvm下和非lvm下分别进行测试
虚拟机扩展硬盘容量
选择扩展将原来的20g扩展到100g
非lvm下如何扩展磁盘
fdisk -l发现只有一个盘/dev/sda,分成了3个区,sda1,sda2,sda3
Disk /dev/sda: 20.4 GB
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: 0x000bbf20
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 616447 307200 83 Linux
/dev/sda2 616448 4810751 2097152 82 Linux swap / Solaris
/dev/sda3 4810752 41943039 18566144 83 Linux
开始分区
[root@promote ~]# 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): m
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
g create a new empty GPT partition table
G create an IRIX (SGI) partition table
l list known partition types
m print this menu
n add a new partition
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition's system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)
输入n 新建分区;
然后输入p,新建主分区;
输入分区编号4(已经有1,2,3了,所以新建的是4);
之后一直按enter键,设置新建分区默认大小;
最后输入w 保存。
同步分区
partprobe
如果没有这一步,后面的格式化会提示下面错误
/dev/sda4: No such file or directory
格式化
mkfs.xfs /dev/sda4
挂载目录
[root@promote home]# mkdir /sda4
[root@promote home]# mount /dev/sda4 /sda4
新创建的分区不能开机自动挂载,每次重启机器都要手动挂载。
设置开机自动挂载需要修改/etc/fstab文件
cat /etc/fstab
UUID=6ead5f9b-3451-499c-947a-08e2dc947304 / xfs defaults 0 0
UUID=d5ba0def-f729-4180-b7ff-584396e36bc0 /boot xfs defaults 0 0
UUID=6f708491-e4b1-44ea-bd4b-d33876fa650c swap swap defaults 0 0
查看分区uuid
[root@promote ~]# blkid /dev/sda4
/dev/sda4: UUID="818f6627-a91a-459c-aacb-220929178ba5" TYPE="xfs"
在文件的最后增加一行
UUID=818f6627-a91a-459c-aacb-220929178ba5 /sda4 xfs defaults 0 0
验证
[root@promote ~]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda3 xfs 18G 8.0G 9.8G 45% /
devtmpfs devtmpfs 970M 0 970M 0% /dev
tmpfs tmpfs 984M 160K 984M 1% /dev/shm
tmpfs tmpfs 984M 9.0M 975M 1% /run
tmpfs tmpfs 984M 0 984M 0% /sys/fs/cgroup
/dev/sda4 xfs 80G 33M 80G 1% /sda4
/dev/sda1 xfs 297M 152M 146M 51% /boot
tmpfs tmpfs 197M 8.0K 197M 1% /run/user/42
tmpfs tmpfs 197M 8.0K 197M 1% /run/user/0
看到sda4为80g,恭喜自己成功了。
lvm下如何扩展磁盘
开始分区
注意类型是8e的
[root@promote qiu]# 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): n 新建
Partition type:
p primary (2 primary, 0 extended, 2 free)
e extended
Select (default p): p 主分区
Partition number (3,4, default 3): 3 分区编码
First sector (41943040-209715199, default 41943040): 回车键默认扇区大小
Using default value 41943040
Last sector, +sectors or +size{K,M,G} (41943040-209715199, default 209715199): 回车键默认扇区大小
Using default value 209715199
Partition 3 of type Linux and of size 80 GiB is set
Command (m for help): t 修改分区类型
Partition number (1-3, default 3): 3 修改指定分区
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'
Command (m for help): w
同步分区
partprobe
格式化
mkfs.xfs /dev/sda3
创建pv
pvcreate /dev/sda3
加入vg
vgextend cl /dev/sda3
扩展逻辑卷大小
[root@promote qiu]# lvdisplay
--- Logical volume ---
LV Path /dev/cl/swap
LV Name swap
VG Name cl
LV UUID LRdTFN-ALQF-YZ2D-Ayj1-Mati-bY5H-meOPcv
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2018-06-30 07:00:29 -0700
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 u2AL50-gvWQ-OLsx-Lpc6-Z0g0-gPLL-VT6Jxm
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2018-06-30 07:00:30 -0700
LV Status available
# open 1
LV Size 80.00 GiB
Current LE 20480
Segments 2
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:0
lvextend -L 80g /dev/cl/root 扩展到80g
同步文件系统
xfs_growfs /dev/cl/root
验证
[root@promote qiu]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/cl-root xfs 80G 4.7G 76G 6% /
devtmpfs devtmpfs 969M 0 969M 0% /dev
tmpfs tmpfs 984M 144K 984M 1% /dev/shm
tmpfs tmpfs 984M 9.0M 975M 1% /run
tmpfs tmpfs 984M 0 984M 0% /sys/fs/cgroup
/dev/sda1 xfs 1014M 173M 842M 18% /boot
tmpfs tmpfs 197M 16K 197M 1% /run/user/0
看到root逻辑卷大小为80g,恭喜自己成功了。
其他
删除分区
[root@promote qiu]# 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): d
Partition number (1-3, default 3): 3
Partition 3 is deleted
Command (m for help): w
查看分区
Command (m for help): p
Disk /dev/sda: 107.4 GB, 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: 0x000c58a8
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 41943039 19921920 8e Linux LVM
更多推荐
所有评论(0)