![在 centos 中将空间从 /home 转移到 /var](https://linux22.com/image/1413699/%E5%9C%A8%20centos%20%E4%B8%AD%E5%B0%86%E7%A9%BA%E9%97%B4%E4%BB%8E%20%2Fhome%20%E8%BD%AC%E7%A7%BB%E5%88%B0%20%2Fvar.png)
我想增加 /var 文件夹的空间。df -h 的输出是
[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_livecd-lv_root 50G 33G 16G 68% /
tmpfs 5.8G 296K 5.8G 1% /dev/shm
/dev/sda1 485M 127M 334M 28% /boot
/dev/mapper/vg_livecd-lv_home 862G 9.3G 809G 2% /home
[root@localhost ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sda2 vg_livecd lvm2 a-- 931.02g 0
[root@localhost ~]# vgs
VG #PV #LV #SN Attr VSize VFree
vg_livecd 1 3 0 wz--n- 931.02g 0
[root@localhost ~]# lvs
LV VG Attr LSize Pool Origin Data% Move Log Cpy%Sync Convert
lv_home vg_livecd -wi-ao---- 875.20g
lv_root vg_livecd -wi-ao---- 50.00g
lv_swap vg_livecd -wi-ao---- 5.82g
我尝试搜索,但无法解决我的问题。有人能给我指出正确的方向吗?提前谢谢
答案1
下面是我找到的一个脚本,过去曾成功使用过,用于从 /tmp 分区窃取空间并添加到其他分区。使用前面评论中提到的 LVM 管理指南并调整以下内容以满足您的需求:
#!/bin/sh
#
# Script to re-allocate space from tmpVol to auditVol and varVol
#
################################################################
ROOTVG=VolGroup00
TMPVOL=${ROOTVG}/tmpVol
VARVOL=${ROOTVG}/varVol
AUDVOL=${ROOTVG}/auditVol
# Verify that /tmp is now of type "tmpfs"
df -Pt tmpfs /tmp > /dev/null 2>&1
if [ $? -ne 0 ]
then
echo "/tmp is not of type 'tmpfs'. Exiting..."
exit
fi
# Compute blocks for re-allocation
FREEVOL=`lvdisplay ${TMPVOL} | awk '/Current LE/{print $3}'`
HALFREE=`expr ${FREEVOL} / 2`
# Nuke the old /tmp volume
lvremove -f ${TMPVOL}
# Resize the remaining logical volumes
lvresize -l +${HALFREE} ${VARVOL}
lvresize -l +${HALFREE} ${AUDVOL}
# Resize the filesystems
resize2fs /dev/${VARVOL}
resize2fs /dev/${AUDVOL}