Gentoo 历程(7):压缩portage树,并放到/var

来源:互联网 发布:touch4怎么找老版软件 编辑:程序博客网 时间:2024/05/22 05:58

    当初装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 supportFile 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 <mathias_laurin@users.sourceforge.net># 2006-11-28, v.0.1.5(4)# 2009-02-24, v.0.1.6(1) Weedy <weedy2887@gmail.com># 2009-03-20, v.0.1.7(1) j0inty <j0inty@stollfuss.net># 2009-07-10, v.0.1.8(1) j0inty# 2009-09-01. v.0.1.9(1) nall <soir@fuzzysock.net>extra_started_commands="sync"source /etc/make.globalssource /etc/make.confSQFS_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 ] ; theneerror "ERROR: sys-fs/squashfs-tools is not installed."return 1fiif ! [ -w /dev/loop0 ] ; theneerror "ERROR: loopback support is not available."return 1fiif ! [[ $(grep -s $'\taufs$' /proc/filesystems) ]] ; theneerror "ERROR: aufs filesystem support is not available."return 1fiif ! [[ $(grep -s $'\tsquashfs$' /proc/filesystems) ]] ; theneerror "ERROR: squashfs filesystem support is not available."return 1fireturn 0}makeImage() {mksquashfs $PORTDIR $SQFS_NEW $SQFS_OPTS # 2>/dev/nullretval=$?ln -sf $SQFS_NEW $SQFS_CUR eend $retval}sync() {ebegin "Syncing portage tree"eval $SYNC_CMDS #svc_stop; svc_startstopstarteend 0}start() {check_support || return 1if [ -f "$SQFS_CUR" ]; thenebegin "SQFS-PORTAGE: Mounting read-only squashfs image"mount -rt squashfs -o loop,nodev,noexec $SQFS_CUR $PORTDIRretval=$?[ $retval -ne 0 ] && return $retvalelseif [ ! -f "/usr/portage/metadata/timestamp.chk" ]; thenebegin "SQFS-PORTAGE: $PORTDIR looks empty or corrupted, syncing"eval $SYNC_CMDSfieinfo "  $SQFS_CUR does not exist, creating"mkdir -p $SQFS_DIRNAMEmakeImage[ $? -ne 0 ] && eerror "ERROR: failed to create initial tree image"einfo "Clearing ${PORTDIR}"rm -r ${PORTDIR}mkdir ${PORTDIR}starteend 0fiebegin "Mounting read-write with aufs"if [ ! $PORTAGE_RW ] ; theneinfo "  mounted in tmpfs (RAM)"PORTAGE_RW="${DEF_RW}"fi[ -d $PORTAGE_RW ] || mkdir -p $PORTAGE_RWchmod 0750 $PORTAGE_RWchown portage:portage $PORTAGE_RWmount -t aufs -o nodev,noexec,br=$PORTAGE_RW=rw:$PORTDIR=ro aufs $PORTDIReend $?if [ "$DISTDIR" == "/usr/portage/distfiles" ]; thenmkdir -p /usr/local/distfiles mount -o bind /usr/local/distfiles /usr/portage/distfilesewarn "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 ]; theneinfo "  Changes detected, updating image."mv -f $SQFS_NEW $SQFS_OLDmakeImagerm -f $SQFS_OLDelseeinfo "  No changes detected, skipping update."eend 0fiif [ "$DISTDIR" == "/usr/portage/distfiles" ]; theneinfo "  Unmounting distfiles"umount /usr/local/distfilesfi;einfo "  Unmounting the tree"umount -t aufs  $PORTDIRumount -t squashfs $PORTDIRrm -rf $PORTAGE_RWeend 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/portageSQFS_DIRNAME="/var/portage"# Leave PORTAGE_RW empty for use with tmpfs, a ram-based filesystem,# This is recommended unless you are short of RAMPORTAGE_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,其它的按原来的习惯正常使用就成。

原创粉丝点击