當初裝gentoo的時候以爲gentoo和arch一樣,把軟件包的各種信息和緩存都放到/var,就給/分了10g,/var分了6g,後來用着才發現,gentoo的portage在/usr/portage下,下載的包也在/usr/portage下,結果用了不長時間/就滿了,各種悲催……上linuxsir問了問老鳥,有人提議清理緩存,有人提議用squashfs把portage壓縮,那時正好比較忙,沒時間折騰,就採用了清理緩存這個辦法,直到前幾天,/又滿了,看來portage這個東西必須得處理下了,linuxsir上那位前輩給提供了幾個鏈接,從這樣做的原理到做法都有,帖子地址在這裏,不過不知道論壇升級後這地址還能不能正常看。
具體原因我這裏就不說了,那帖子裏說的很明白,只說說我折騰的具體過程。
官方wiki在這裏。
首先,當然是看官方wiki,不過由於我升級到一半/滿了,導致無法進系統,懶得先修它,就用arch chroot了。
第一步,按照wiki裏的說法,先安裝squashfs-tools和aufs3(2.x的內核裝aufs2),其中aufs3要修改use,執行:
echo sys-fs/squashfs-tools kernel-patch >> /etc/portage/package.use
然後再emerge安裝aufs3,裝完aufs3按提示重新編譯內核,編譯內核的時候要保證下面的這些被選中:
Device Drivers --->
Block Devices --->
<M> Loopback device support
File systems --->
Miscellaneous Filesystems --->
<M> SquashFS
上面是wiki推薦的,我不喜歡把這種每次都要用的東西編譯成模塊,所以直接編譯進了內核。
第二步,修改幾個配置文件,挪幾個文件夾,具體如下:
1.創建/var/portage文件夾
2.將/usr/portage/distfiles文件夾挪到/var/portage/
3.將/var/lib/layman文件夾挪到/var/portage/(這個我覺得我用不太着,不過官方wiki這麼說我就這麼做吧,以前有過一次亂搞portage出錯的經歷,不這麼做說不準會出啥問題)
4./etc/make.conf文件:
DISTDIR="/var/portage/distfiles"
source /var/portage/layman/make.conf
5./var/portage/layman/make.conf文件:
將所有/var/lib/xxx改成/var/portage/xxx
完成上述步驟後,準備工作就算完成了,下面是生成sqfs,並將這個壓縮的portage tree 用起來
第一步,添加/etc/init.d/squash_portage ,這個文件的內容如下:
#!/sbin/runscript
# Copyright 1999-2006 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $
#
# /etc/init.d/squash_portage allows efficient compression of
# Gentoo portage arborescence
#
# It requires support for the loop device and squashfs enabled in the kernel,
# module autoloading is also *highly* recommended.
# sys-fs/squashfs and sys-fs/aufs are necessary for read-write support.
#
# Author: Mathias Laurin <[email protected]>
# 2006-11-28, v.0.1.5(4)
# 2009-02-24, v.0.1.6(1) Weedy <[email protected]>
# 2009-03-20, v.0.1.7(1) j0inty <[email protected]>
# 2009-07-10, v.0.1.8(1) j0inty
# 2009-09-01. v.0.1.9(1) nall <[email protected]>
extra_started_commands="sync"
source /etc/make.globals
source /etc/make.conf
SQFS_CUR="$SQFS_DIRNAME/portage.sqfs"
SQFS_NEW="$SQFS_DIRNAME/portage-current.sqfs"
SQFS_OLD="$SQFS_DIRNAME/portage-old.sqfs"
DEF_RW="/dev/shm/.portage-rw"
SQFS_OPTS="-force-uid portage -force-gid portage -no-duplicates"
depend() {
need localmount modules
}
check_support() {
if ! [ -x /usr/bin/mksquashfs ] ; then
eerror "ERROR: sys-fs/squashfs-tools is not installed."
return 1
fi
if ! [ -w /dev/loop0 ] ; then
eerror "ERROR: loopback support is not available."
return 1
fi
if ! [[ $(grep -s $'\taufs$' /proc/filesystems) ]] ; then
eerror "ERROR: aufs filesystem support is not available."
return 1
fi
if ! [[ $(grep -s $'\tsquashfs$' /proc/filesystems) ]] ; then
eerror "ERROR: squashfs filesystem support is not available."
return 1
fi
return 0
}
makeImage() {
mksquashfs $PORTDIR $SQFS_NEW $SQFS_OPTS # 2>/dev/null
retval=$?
ln -sf $SQFS_NEW $SQFS_CUR
eend $retval
}
sync() {
ebegin "Syncing portage tree"
eval $SYNC_CMDS
#svc_stop; svc_start
stop
start
eend 0
}
start() {
check_support || return 1
if [ -f "$SQFS_CUR" ]; then
ebegin "SQFS-PORTAGE: Mounting read-only squashfs image"
mount -rt squashfs -o loop,nodev,noexec $SQFS_CUR $PORTDIR
retval=$?
[ $retval -ne 0 ] && return $retval
else
if [ ! -f "/usr/portage/metadata/timestamp.chk" ]; then
ebegin "SQFS-PORTAGE: $PORTDIR looks empty or corrupted, syncing"
eval $SYNC_CMDS
fi
einfo " $SQFS_CUR does not exist, creating"
mkdir -p $SQFS_DIRNAME
makeImage
[ $? -ne 0 ] && eerror "ERROR: failed to create initial tree image"
einfo "Clearing ${PORTDIR}"
rm -r ${PORTDIR}
mkdir ${PORTDIR}
start
eend 0
fi
ebegin "Mounting read-write with aufs"
if [ ! $PORTAGE_RW ] ; then
einfo " mounted in tmpfs (RAM)"
PORTAGE_RW="${DEF_RW}"
fi
[ -d $PORTAGE_RW ] || mkdir -p $PORTAGE_RW
chmod 0750 $PORTAGE_RW
chown portage:portage $PORTAGE_RW
mount -t aufs -o nodev,noexec,br=$PORTAGE_RW=rw:$PORTDIR=ro aufs $PORTDIR
eend $?
if [ "$DISTDIR" == "/usr/portage/distfiles" ]; then
mkdir -p /usr/local/distfiles
mount -o bind /usr/local/distfiles /usr/portage/distfiles
ewarn "DISTDIR is currently inside the portage tree. It has been bind
mounted to keep the SquashFS image small."
fi
}
stop() {
ebegin "SQFS-PORTAGE: Stopping and unmounting"
[ ! $PORTAGE_RW ] && PORTAGE_RW="${DEF_RW}"
if [ $(du -s --exclude=.w* $PORTAGE_RW | cut -f 1) -gt 4 ]; then
einfo " Changes detected, updating image."
mv -f $SQFS_NEW $SQFS_OLD
makeImage
rm -f $SQFS_OLD
else
einfo " No changes detected, skipping update."
eend 0
fi
if [ "$DISTDIR" == "/usr/portage/distfiles" ]; then
einfo " Unmounting distfiles"
umount /usr/local/distfiles
fi;
einfo " Unmounting the tree"
umount -t aufs $PORTDIR
umount -t squashfs $PORTDIR
rm -rf $PORTAGE_RW
eend 0
}
使之可執行:
#chmod 755 /etc/init.d/squashfs_portage
將其添加到default runlevel:
#rc-update add squash_portage default
第二步,添加文件/etc/conf.d/squash_portage:
# /etc/conf.d/squash_portage
# SQFS_DIRNAME points to the directory that will contain the sqfs
# images, recommended value is /var/portage
SQFS_DIRNAME="/var/portage"
# Leave PORTAGE_RW empty for use with tmpfs, a ram-based filesystem,
# This is recommended unless you are short of RAM
PORTAGE_RW=""
# If you need more then just emerge --sync, or are using another
# package manager add them here. Example SYNC_CMDS="/usr/bin/layman -S; /usr/bin/eix-sync"
SYNC_CMDS="emerge --sync"
第三步(不是每人都用):我用的是openrc,所以還要修改一下/etc/config.d/modules:在modules="nvidia vboxdrv ..."里加上aufs。
這樣重新啓動應該就好了(爲啥說應該呢?因爲我第一次啓動前忘了第三步,所以我的squash_portage啓動失敗了,sqfs文件是啓動後自己手動生成的),第一次啓動需要生成一個portage.sqfs文件,我的這個文件有2.2G,這文件大小是因人而異的,所以生成速度也不一樣,據說有人的只有幾十M……
sync的時候執行/etc/init.d/squash_portage sync,其它的按原來的習慣正常使用就成。