Difference between pages "Stacked Runlevels" and "System Administration Practice"

From Funtoo
(Difference between pages)
Jump to: navigation, search
 
 
Line 1: Line 1:
It is common for a laptop user to use DHCP most of the time; however, they may also need to periodially connect to network where a static network configuration is required. This is a situation where a Funtoo Linux machine will require '''multiple''' network configurations. Funtoo Linux supports this.
+
== Keep Portage Tree Up-To-Date ==
 +
Even if you're not doing a full update every day, you should sync the portage tree and overlays regularly. It will reduce the time that you need to sync tree before a system upgrade. Also, if you just want to install something, it will be installed with latest deps so you will not waste time on upgrading it later. Here is an example script to upgrade portage and overlay every day. Edit <code>/etc/cron.daily/autosync.sh</code> with your favorite text editor:
  
The recommended approach for doing this is to use multiple, stacked runlevels. To do this, you will need to create two new runlevels which are children of the <tt>default</tt> runlevel. This can be done like this:
+
<pre>
 +
#!/bin/bash
 +
log="/var/log/autosync.log"
 +
if [ ! -f $log ]; then
 +
touch $log
 +
chmod 600 $log
 +
chown root:root $log
 +
fi
  
<console># ##i##install -d /etc/runlevels/static
+
echo >> $log
# ##i##install -d /etc/runlevels/dynamic</console>
+
echo "*** autosync started! ($(date +'%d-%m-%Y %H:%M:%S'))" >> $log
Two new runlevels, <tt>static</tt> and <tt>dynamic</tt>, have now been created. Now, we will make these runlevels children of the <tt>default</tt> runlevel using the following commands:
+
echo "*** running emerge --sync" >> $log
 +
emerge -q --sync >> $log 2>&1
 +
if [ -f /usr/bin/layman ]; then
 +
echo >> $log
 +
echo "*** running layman -S" >> $log
 +
/usr/bin/layman -S --nocolor >> $log 2>&1
 +
fi
 +
</pre>
  
<console># ##i##rc-update --stack add default static
+
== Purge unused distfiles ==
# ##i##rc-update --stack add default dynamic</console>
+
Distfiles may take up a lot of space on disk, and if you do not clean them from time to time it may become an issue. There are many ways to clean them.  
Now, the runlevels <tt>static</tt> and <tt>dynamic</tt> will consist of anything in <tt>default</tt> '''plus''' any additional scripts you add to each new runlevel.
+
  
To complete our multiple network configuration, we would now do something like this:
+
* Remove distfiles which wasn't accessed in last 90 days. ('''WARNING''': It will not work if distfiles are on filesystem with '''noatime''' option. You may want think about '''relatime''').
  
<console># ##i##rc-update add netif.eth0 static
 
# ##i##rc-update add dhcpcd dynamic</console>
 
To switch to or between each runlevel, we would type:
 
 
<console># ##i##rc static</console>
 
Or:
 
 
<console># ##i##rc dynamic</console>
 
If we wanted to boot into <tt>dynamic</tt> by default, this could be done by editing <tt>/etc/inittab</tt> and modifying this line:
 
  
 
<pre>
 
<pre>
l3:3:wait:/sbin/rc default
+
#!bin/bash
 +
find /usr/portage/distfiles -maxdepth 1 -type f -atime +90 -exec rm {}
 
</pre>
 
</pre>
 +
Alternative is using <tt>eclean</tt> purge utility for distfiles and binary packages, it is part of <tt>app-portage/gentoolkit</tt> package.
 +
Let's say we want to purge distfiles in <tt>/usr/portage/distfiles</tt>
 +
<console>
 +
###i## eclean-dist -i
 +
</console>
 +
This command will prompt for each distfile and ask user's confirmation (can be slow). Example of advanced usage, let's clean all distfiles except for installed packages (exact version), those which are less than one month old, bigger than 50MB, or fetch-restricted:
 +
<console>
 +
###i## eclean-dist -d -t1m -s50M -f
 +
</console>
 +
Cron lovers :)
 +
clean packages in the safest mode, and then distfiles in deep mode but protecting files less than a week old, every sunday at 1am:
 +
<console>
 +
###i## 0 1 * * sun  eclean -C -q packages ; eclean -C -q -d -t1w distfiles
 +
</console>
  
To read as follows:
 
 
<pre>
 
l3:3:wait:/sbin/rc dynamic
 
</pre>
 
  
 
[[Category:HOWTO]]
 
[[Category:HOWTO]]

Latest revision as of 00:25, 19 February 2014

[edit] Keep Portage Tree Up-To-Date

Even if you're not doing a full update every day, you should sync the portage tree and overlays regularly. It will reduce the time that you need to sync tree before a system upgrade. Also, if you just want to install something, it will be installed with latest deps so you will not waste time on upgrading it later. Here is an example script to upgrade portage and overlay every day. Edit /etc/cron.daily/autosync.sh with your favorite text editor:

#!/bin/bash
log="/var/log/autosync.log"
if [ ! -f $log ]; then
	touch $log
	chmod 600 $log
	chown root:root $log
fi

echo >> $log
echo "*** autosync started! ($(date +'%d-%m-%Y %H:%M:%S'))" >> $log
echo "*** running emerge --sync" >> $log
emerge -q --sync >> $log 2>&1
if [ -f /usr/bin/layman ]; then
	echo >> $log
	echo "*** running layman -S" >> $log
	/usr/bin/layman -S --nocolor >> $log 2>&1
fi

[edit] Purge unused distfiles

Distfiles may take up a lot of space on disk, and if you do not clean them from time to time it may become an issue. There are many ways to clean them.

  • Remove distfiles which wasn't accessed in last 90 days. (WARNING: It will not work if distfiles are on filesystem with noatime option. You may want think about relatime).


#!bin/bash
find /usr/portage/distfiles -maxdepth 1 -type f -atime +90 -exec rm {} 

Alternative is using eclean purge utility for distfiles and binary packages, it is part of app-portage/gentoolkit package. Let's say we want to purge distfiles in /usr/portage/distfiles

# eclean-dist -i 

This command will prompt for each distfile and ask user's confirmation (can be slow). Example of advanced usage, let's clean all distfiles except for installed packages (exact version), those which are less than one month old, bigger than 50MB, or fetch-restricted:

# eclean-dist -d -t1m -s50M -f

Cron lovers :) clean packages in the safest mode, and then distfiles in deep mode but protecting files less than a week old, every sunday at 1am:

# 0 1 * * sun   eclean -C -q packages ; eclean -C -q -d -t1w distfiles