900字范文,内容丰富有趣,生活中的好帮手!
900字范文 > centos7扩展磁盘空间

centos7扩展磁盘空间

时间:2021-01-26 09:23:43

相关推荐

centos7扩展磁盘空间

文章目录

准备虚拟机扩展硬盘容量非lvm下如何扩展磁盘开始分区同步分区格式化挂载目录验证lvm下如何扩展磁盘开始分区创建pv加入vg扩展逻辑卷大小同步文件系统验证其他

准备

vmware安装centos7,在lvm下和非lvm下分别进行测试

虚拟机扩展硬盘容量

选择扩展将原来的20g扩展到100g

非lvm下如何扩展磁盘

fdisk -l发现只有一个盘/dev/sda,分成了3个区,sda1,sda2,sda3

Disk /dev/sda: 20.4 GBUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk label type: dosDisk identifier: 0x000bbf20Device BootStart EndBlocks Id System/dev/sda1 * 2048616447307200 83 Linux/dev/sda261644848107512097152 82 Linux swap / Solaris/dev/sda3 4810752 41943039 18566144 83 Linux

开始分区

[root@promote ~]# fdisk /dev/sdaWelcome 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 mand (m for help): mCommand actiona 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)

输入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 / xfsdefaults 0 0UUID=d5ba0def-f729-4180-b7ff-584396e36bc0 /boot xfsdefaults 0 0UUID=6f708491-e4b1-44ea-bd4b-d33876fa650c swapswap 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 -ThFilesystemTypeSize Used Avail Use% Mounted on/dev/sda3xfs 18G 8.0G 9.8G 45% /devtmpfs devtmpfs 970M0 970M 0% /devtmpfstmpfs984M 160K 984M 1% /dev/shmtmpfstmpfs984M 9.0M 975M 1% /runtmpfstmpfs984M0 984M 0% /sys/fs/cgroup/dev/sda4xfs 80G 33M 80G 1% /sda4/dev/sda1xfs 297M 152M 146M 51% /boottmpfstmpfs197M 8.0K 197M 1% /run/user/42tmpfstmpfs197M 8.0K 197M 1% /run/user/0

看到sda4为80g,恭喜自己成功了。

lvm下如何扩展磁盘

开始分区

注意类型是8e的

[root@promote qiu]# fdisk /dev/sdaWelcome 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 mand (m for help): n 新建Partition type: p primary (2 primary, 0 extended, 2 free)e extendedSelect (default p): p主分区Partition number (3,4, default 3): 3 分区编码First sector (41943040-209715199, default 41943040): 回车键默认扇区大小Using default value 41943040Last sector, +sectors or +size{K,M,G} (41943040-209715199, default 209715199): 回车键默认扇区大小Using default value 209715199Partition 3 of type Linux and of size 80 GiB is setCommand (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/swapLV NameswapVG NameclLV UUIDLRdTFN-ALQF-YZ2D-Ayj1-Mati-bY5H-meOPcvLV Write Access read/writeLV Creation host, time localhost.localdomain, -06-30 07:00:29 -0700LV Status available# open 2LV Size2.00 GiBCurrent LE 512Segments1Allocation inheritRead ahead sectorsauto- currently set to8192Block device 253:1--- Logical volume ---LV Path/dev/cl/rootLV NamerootVG NameclLV UUIDu2AL50-gvWQ-OLsx-Lpc6-Z0g0-gPLL-VT6JxmLV Write Access read/writeLV Creation host, time localhost.localdomain, -06-30 07:00:30 -0700LV Status available# open 1LV Size80.00 GiBCurrent LE 20480Segments2Allocation inheritRead ahead sectorsauto- currently set to8192Block device 253:0

lvextend -L 80g /dev/cl/root 扩展到80g

同步文件系统

xfs_growfs /dev/cl/root

验证

[root@promote qiu]# df -ThFilesystemTypeSize Used Avail Use% Mounted on/dev/mapper/cl-root xfs 80G 4.7G 76G 6% /devtmpfs devtmpfs 969M0 969M 0% /devtmpfstmpfs984M 144K 984M 1% /dev/shmtmpfstmpfs984M 9.0M 975M 1% /runtmpfstmpfs984M0 984M 0% /sys/fs/cgroup/dev/sda1 xfs1014M 173M 842M 18% /boottmpfstmpfs197M 16K 197M 1% /run/user/0

看到root逻辑卷大小为80g,恭喜自己成功了。

其他

删除分区

[root@promote qiu]# fdisk /dev/sdaWelcome 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 mand (m for help): dPartition number (1-3, default 3): 3Partition 3 is deletedCommand (m for help): w

查看分区

Command (m for help): pDisk /dev/sda: 107.4 GB, 107374182400 bytes, 209715200 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk label type: dosDisk identifier: 0x000c58a8Device BootStart EndBlocks Id System/dev/sda1 * 204820991991048576 83 Linux/dev/sda2 2099200 41943039 19921920 8e Linux LVM

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。