此方法存在bug,系统重启后无法正常进入系统!!!
前阵儿虚拟机默认装系统后,磁盘空间分配不均,就想上网找帖子把这个问题解决了,找到了好多一模一样的帖子,真是福气,就算转载,你先自己验证一下能否操作再转,不。。。转载的帖子各种错误,各种坑,也不知道没脑子转载的那些人是怎么想的!
我也是小白,我也得从网上找解决办法,就找了好几篇文章,然后到自己的虚拟机里测试,当时测试是挺好的,后来就遇到虚拟机重启后无法进入系统的问题,当时都没有往这里想;
一直不知道是哪里的错误,后来才发现问题的根源在这里!
所以在这里记录一下,等后续有时间了再研究怎么解决这个问题!
我目前的解决方案是,在安装虚拟机装系统时,自行分区,不使用默认分区即可!
************************************************************************************************************************************************
************************************************************************************************************************************************
以下是原贴:
安装虚拟机时,磁盘200G,未手动分配磁盘空间,默认安装后发现/home容量过大,而/root容量太小,现在把/home容量转移到/root下;
1、显示磁盘挂载信息
从下图可以看到,/root容量为53.7G,而/home容量为153.7G,下面转移130G容量;
[root@server1 ~]# fdisk -l
Disk /dev/sda: 214.7 GB, 214748364800 bytes, 419430400 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: 0x000023f5
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 419430399 208665600 8e Linux LVM
Disk /dev/mapper/centos-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/centos-swap: 6308 MB, 6308233216 bytes, 12320768 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/centos-home: 153.7 GB, 153670909952 bytes, 300138496 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@server1 ~]# df -lh
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 50G 26G 25G 51% /
devtmpfs 2.9G 0 2.9G 0% /dev
tmpfs 2.9G 12K 2.9G 1% /dev/shm
tmpfs 2.9G 121M 2.8G 5% /run
tmpfs 2.9G 0 2.9G 0% /sys/fs/cgroup
/dev/mapper/centos-home 144G 37M 144G 1% /home
/dev/sda1 1014M 170M 845M 17% /boot
tmpfs 579M 12K 579M 1% /run/user/42
tmpfs 579M 0 579M 0% /run/user/0
2、减少/centos-home磁盘130G容量
[root@server1 ~]# lvreduce -L -130G /dev/mapper/centos-home
WARNING: Reducing active and open logical volume to <13.12 GiB.
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce centos/home? [y/n]: y
Size of logical volume centos/home changed from <143.12 GiB (36638 extents) to <13.12 GiB (3358 extents).
Logical volume centos/home successfully resized.
3、增加/centos-root磁盘130G容量
[root@server1 ~]# lvextend -L +130G /dev/mapper/centos-root
Size of logical volume centos/root changed from 50.00 GiB (12800 extents) to 180.00 GiB (46080 extents).
Logical volume centos/root successfully resized.
4、刷新磁盘
[root@server1 ~]# xfs_growfs /dev/mapper/centos-home
meta-data=/dev/mapper/centos-home isize=512 agcount=4, agsize=9379328 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=37517312, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal bsize=4096 blocks=18319, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data size 3438592 too small, old size is 37517312
[root@server1 ~]# xfs_growfs /dev/mapper/centos-root
meta-data=/dev/mapper/centos-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 47185920
5、显示磁盘挂载信息
可以看到,/centos-root容量增加到193.3G,/centos-home容量减少到14.1G;
[root@server1 ~]# fdisk -l
Disk /dev/sda: 214.7 GB, 214748364800 bytes, 419430400 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: 0x000023f5
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 419430399 208665600 8e Linux LVM
Disk /dev/mapper/centos-root: 193.3 GB, 193273528320 bytes, 377487360 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/centos-swap: 6308 MB, 6308233216 bytes, 12320768 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/centos-home: 14.1 GB, 14084472832 bytes, 27508736 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@server1 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 180G 26G 155G 15% /
devtmpfs 2.9G 0 2.9G 0% /dev
tmpfs 2.9G 12K 2.9G 1% /dev/shm
tmpfs 2.9G 121M 2.8G 5% /run
tmpfs 2.9G 0 2.9G 0% /sys/fs/cgroup
/dev/mapper/centos-home 144G 37M 144G 1% /home
/dev/sda1 1014M 170M 845M 17% /boot
tmpfs 579M 12K 579M 1% /run/user/42
tmpfs 579M 0 579M 0% /run/user/0
完结撒花~~~