CentOS7.5磁碟空間轉移
阿新 • • 發佈:2018-11-28
安裝虛擬機器時,磁碟200G,未手動分配磁碟空間,預設安裝後發現/home容量過大,而/root容量太小,現在把/home容量轉移到/root下;
1、顯示磁碟掛載資訊
從下圖可以看到,/root容量為53.7G,而/home容量為153.7G,下面轉移130G容量;
[[email protected] ~]# 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
[[email protected] ~]# 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容量
[[email protected] ~]# 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容量
[[email protected] ~]# 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、重新整理磁碟
[[email protected] ~]# 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
[[email protected] ~]# 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;
[[email protected] ~]# 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
[[email protected] ~]# 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
完結撒花~~~