挂载 /etc/
以下是linux扩展分区大小 rhel redhat.7.4(成功案例)
===========================================================
[root@r2019x ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/rhel-root 50G 45G 5.5G 90% /
devtmpfs 5.7G 0 5.7G 0% /dev
tmpfs 5.7G 0 5.7G 0% /dev/shm
tmpfs 5.7G 9.1M 5.7G 1% /run
tmpfs 5.7G 0 5.7G 0% /sys/fs/cgroup
/dev/mapper/rhel-home 143G 28G 115G 20% /home
/dev/sda1 1014M 179M 836M 18% /boot
tmpfs 1.2G 8.0K 1.2G 1% /run/user/42
tmpfs 1.2G 24K 1.2G 1% /run/user/0
/dev/sr0 3.8G 3.8G 0 100% /run/media/root/RHEL-7.4 Server.x86_64
[root@r2019x ~]# fdisk -l
Disk /dev/sda: 429.5 GB, 429496729600 bytes, 838860800 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: 0x000cedaa
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 419430399 208665600 8e Linux LVM
Disk /dev/sdb: 42.9 GB, 42949672960 bytes, 83886080 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 /dev/mapper/rhel-root: 53.7 GB, 53687091200 bytes, 104857600 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 /dev/mapper/rhel-swap: 7314 MB, 7314866176 bytes, 14286848 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 /dev/mapper/rhel-home: 152.7 GB, 152664276992 bytes, 298172416 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
[root@r2019x ~]# fdisk /dev/sdb
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.
Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0xcfc4fd02.
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)
Command (m for help): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p):
Using default response p
Partition number (1-4, default 1):
First sector (2048-83886079, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-83886079, default 83886079):
Using default value 83886079
Partition 1 of type Linux and of size 40 GiB is set
Command (m for help): t
Selected partition 1
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@r2019x ~]# fdisk -l
Disk /dev/sda: 429.5 GB, 429496729600 bytes, 838860800 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: 0x000cedaa
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 419430399 208665600 8e Linux LVM
Disk /dev/sdb: 42.9 GB, 42949672960 bytes, 83886080 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: 0xcfc4fd02
Device Boot Start End Blocks Id System
/dev/sdb1 2048 83886079 41942016 8e Linux LVM
Disk /dev/mapper/rhel-root: 53.7 GB, 53687091200 bytes, 104857600 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 /dev/mapper/rhel-swap: 7314 MB, 7314866176 bytes, 14286848 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 /dev/mapper/rhel-home: 152.7 GB, 152664276992 bytes, 298172416 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
[root@r2019x ~]# gedit /etc/fstab
[root@r2019x ~]# mkfs.ext4 /dev/sdb1
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
2621440 inodes, 10485504 blocks
524275 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2157969408
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: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
[root@r2019x ~]#
[root@r2019x ~]# pvcreate /dev/sdb
Device /dev/sdb not found (or ignored by filtering).
[root@r2019x ~]# pvcreate /dev/sdb1
WARNING: ext4 signature detected on /dev/sdb1 at offset 1080. Wipe it? [y/n]:
WARNING: Invalid input ''.
WARNING: ext4 signature detected on /dev/sdb1 at offset 1080. Wipe it? [y/n]:
WARNING: Invalid input ''.
WARNING: ext4 signature detected on /dev/sdb1 at offset 1080. Wipe it? [y/n]: y
Wiping ext4 signature on /dev/sdb1.
Physical volume "/dev/sdb1" successfully created.
[root@r2019x ~]# vgdisplay
--- Volume group ---
VG Name rhel
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 4
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 3
Open LV 3
Max PV 0
Cur PV 1
Act PV 1
VG Size <199.00 GiB
PE Size 4.00 MiB
Total PE 50943
Alloc PE / Size 50942 / 198.99 GiB
Free PE / Size 1 / 4.00 MiB
VG UUID 7HCW6t-VdW1-R8uZ-NMdW-AC2t-OmtC-9bWgB1
[root@r2019x ~]# gedit /etc/fstab
[root@r2019x ~]# mount /dev/sdb1 /
mount: unknown filesystem type 'LVM2_member'
[root@r2019x ~]# vgextend /dev/centos /dev/sdb1
Volume group "centos" not found
Cannot process volume group centos
[root@r2019x ~]# vgextend /dev/mapper/rhel-root /dev/sdb1
Volume group name "rhel/root" has invalid characters.
Cannot process volume group rhel/root
[root@r2019x ~]#
[root@r2019x ~]#
[root@r2019x ~]#
[root@r2019x ~]#
[root@r2019x ~]# gedit /etc/fstab
[root@r2019x ~]# vgextend /dev/mapper/rhel-root /dev/sdb1
Volume group name "rhel/root" has invalid characters.
Cannot process volume group rhel/root
[root@r2019x ~]# vgdisplay
--- Volume group ---
VG Name rhel
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 4
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 3
Open LV 3
Max PV 0
Cur PV 1
Act PV 1
VG Size <199.00 GiB
PE Size 4.00 MiB
Total PE 50943
Alloc PE / Size 50942 / 198.99 GiB
Free PE / Size 1 / 4.00 MiB
VG UUID 7HCW6t-VdW1-R8uZ-NMdW-AC2t-OmtC-9bWgB1
[root@r2019x ~]# vgextend /dev/rhel /dev/sdb1
Volume group "rhel" successfully extended
[root@r2019x ~]#
[root@r2019x ~]#
[root@r2019x ~]#
[root@r2019x ~]# vgdisplay
--- Volume group ---
VG Name rhel
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 5
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 3
Open LV 3
Max PV 0
Cur PV 2
Act PV 2
VG Size 238.99 GiB
PE Size 4.00 MiB
Total PE 61182
Alloc PE / Size 50942 / 198.99 GiB
Free PE / Size 10240 / 40.00 GiB
VG UUID 7HCW6t-VdW1-R8uZ-NMdW-AC2t-OmtC-9bWgB1
[root@r2019x ~]# lvextend -L +38G /dev/rhel/root
Size of logical volume rhel/root changed from 50.00 GiB (12800 extents) to 88.00 GiB (22528 extents).
Logical volume rhel/root successfully resized.
[root@r2019x ~]#
[root@r2019x ~]#
[root@r2019x ~]#
[root@r2019x ~]# resize2fs /dev/rhel/root
resize2fs 1.42.9 (28-Dec-2013)
resize2fs: Bad magic number in super-block while trying to open /dev/rhel/root
Couldn't find valid filesystem superblock.
[root@r2019x ~]#
[root@r2019x ~]#
[root@r2019x ~]#
[root@r2019x ~]#
[root@r2019x ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/rhel-root 50G 45G 5.5G 90% /
devtmpfs 5.7G 0 5.7G 0% /dev
tmpfs 5.7G 0 5.7G 0% /dev/shm
tmpfs 5.7G 9.0M 5.7G 1% /run
tmpfs 5.7G 0 5.7G 0% /sys/fs/cgroup
/dev/mapper/rhel-home 143G 28G 115G 20% /home
/dev/sda1 1014M 179M 836M 18% /boot
tmpfs 1.2G 32K 1.2G 1% /run/user/0
/dev/sr0 3.8G 3.8G 0 100% /run/media/root/RHEL-7.4 Server.x86_64
[root@r2019x ~]# xfs_growfs /dev/rhel/root
meta-data=/dev/mapper/rhel-root isize=512 agcount=4, agsize=3276800 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=13107200, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal bsize=4096 blocks=6400, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 13107200 to 23068672
[root@r2019x ~]#
[root@r2019x ~]#
[root@r2019x ~]#
[root@r2019x ~]#
[root@r2019x ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/rhel-root 88G 45G 44G 51% /
devtmpfs 5.7G 0 5.7G 0% /dev
tmpfs 5.7G 0 5.7G 0% /dev/shm
tmpfs 5.7G 9.0M 5.7G 1% /run
tmpfs 5.7G 0 5.7G 0% /sys/fs/cgroup
/dev/mapper/rhel-home 143G 28G 115G 20% /home
/dev/sda1 1014M 179M 836M 18% /boot
tmpfs 1.2G 32K 1.2G 1% /run/user/0
/dev/sr0 3.8G 3.8G 0 100% /run/media/root/RHEL-7.4 Server.x86_64
[root@r2019x ~]#
=====以下内容为转载 CentOS==========================
附原地址:
https://blog.csdn.net/eagle89/article/details/82978116
VMware下Linux根分区磁盘扩容
转载jerry-89 最后发布于2018-10-09 10:16:54 阅读数 2763 收藏
展开
1.缘由
由于需要对VMware虚拟机中的软件进行升级,执行yum update的时候,整个更新包在800MB以上,但是根分区的大小只剩下400MB不到,当时创建的时候也只分配了10G的空间。因此必须对根分区的大小进行扩容,网上找了很多方法,但是由于我的情况比较特殊,折腾来折腾去总算是弄好了,故此记录一下,进行分享。
之前安装虚拟机的时候是分配了20G的空间,但是分为了两个挂载点/和/home,所以一开始的想法是能不能将/home的空间分给/,想了想算了,想再扩大10G空间,/home并没有那么多,就打算再对虚拟机添加一块磁盘进行操作。麻烦就在:
虚拟机在D盘,D盘整个空间都不足了,所以需要使用C盘的空间,由于已经弄好了,下面演示扩容1GB的相关步骤。
2.步骤
1.先选中虚拟机,右击设置
2.选择添加->硬盘->下一步
3.一值点下一步,到设置容量大小,输入1,然后下一步,选择存储位置,这里我就要选择在C盘的空间了。
4.最后确定,进入系统。df -h查看当前系统文件系统情况
5.使用fdisk -l查看硬盘情况,可以看见我新增的那块硬盘区间
6.对新加的硬盘进行分区,格式化,因为我的磁盘名称是/dev/sdc,所以输入 fdisk /dev/sdc命令:
依次输入:m
n 添加新分区
p 创建为主分区,回车使用默认分区号
回车两次使用默认起始扇区和最后扇区
这里可以看见设置的类型是Linux类型,大小实际上不足1GB。但是我的根分区是Linux LVM类型的,所以还需要一次转换。
继续输入t,输入8e,回车。输入w,保存退出。
这个时候再输入fdisk -l,就可以看见创建的分区了。
7.注意不要将新建的磁盘分区挂载到Linux的文件系统中,我们是要对/进行扩容,而不是添加一个区。顺便记录一下,挂载命令是mount /dev/sdc1 /指定位置空文件夹/。如果要开机自动挂载,需要修改/etc/fstab文件的内容,添加一行:/dev/sdc1 /挂载文件夹 ext4 defaults 0 0.挂载使用之前,需要将磁盘先格式化:mkfs.ext4 /dev/sdc1 格式化成ext4,同理ext3,2就是修改一下数字。
回归正题。
创建物理卷:pvcreate /dev/sdc1
查看当前卷组情况:vgdisplay
扩展卷组:CentOS:vgextend /dev/centos /dev/sdc1
再查看就会发现VG的大小增加了:
最后就是要扩展我们的根目录容量了:
根分区叫root,最后一级,centos是卷组名称,命令如下:
扩展逻辑卷centos-root的容量:lvextend -L +1024M /dev/centos/root
可能会出现大小不够的情况,将1024稍微调小点就可以了。
重置根分区的容量:resize2fs /dev/centos/root.
《CentOS6、7 LVM逻辑卷分区自动扩容Shell脚本》,本来看到resize2fs感觉没啥新意,突然发现xfs_growfs ,赶紧仔细研读, (由于CentOS6和CentOS7在默认根文件系统的文件系统格式存在差异,需要判断是否为xfs,如果是xfs则应该使用xfs_growfs而 不是一味的使用resize2fs。) 一句话惊醒梦中人啊,查阅了几篇xfs的用法后,在系统下一试果然好使, [root@localhost home]# xfs_growfs /dev/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 9575424 [root@localhost home]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/centos-root 37G 17G 21G 45% / devtmpfs 476M 0 476M 0% /dev tmpfs 488M 0 488M 0% /dev/shm tmpfs 488M 7.7M 480M 2% /run tmpfs 488M 0 488M 0% /sys/fs/cgroup /dev/sda1 1014M 130M 885M 13% /boot tmpfs 98M 0 98M 0% /run/user/0
再使用df -h查看文件系统,就能看到扩容后的大小了。