Tips: Configurar apt.conf para no instalar paquetes recomendados/sugeridos en Debian

i_love_debian
Despues de tantos años de utilizar Debian en servidores y Desktops he llegado a tener un checklist de tareas que cumplo a rajatabla cada vez que necesito hacer una nueva instalación.

Este post tiene como finalidad compartir uno de estos tips:

Administración de paquetes

Amo Debian… Hago alarde de un verdadero derroche de satisfacción al utilizar Debian dia a dia pero no todo es color de rosas y como sabemos la perfección no existe.
Y es verdad que tengo que darle la razón a amigos que cordial y salvajemente me recuerdan a la mínima posibilidad de lo poco optimizado que está implementado el sistema de dependencias en Debian (y derivados), no es ningún secreto que una instalación promedio instala muchas mas cosas de las necesarias y eso hasta a mí me molesta porque con el tiempo la cantidad de librerias innecesarias crece incesantemente y los updates/upgrades bajan cada vez mayor cantidad de paquetes.

Por ese motivo incluso cuando instalo Debian desde cero en una notebook/desktop y siempre con el netinstaller, nunca jamás selecciono la opción “Desktop Environment”, sino que sólo dejo tildada la opción “Standard System Utilities”

Wheezy Virtual Machine_501

Siempre! hago un párate y termino la instalación con lo mínimo e indispensable, cuando reinicio por primera vez lo primero que hago es editar/crear el archivo /etc/apt/apt.conf y le agrego estas opciones:

1
2
APT::Install-Recommends "0";
APT::Install-Suggests "0";
APT::Install-Recommends "0";
APT::Install-Suggests "0";

En qué cambia todo…?
Es mucho mejor explicarlo con un ejemplo, algo que automáticamente hago apenas tengo shell post-instalación disponible es instalar esta lista de paquetes:

1
2
3
4
5
6
7
8
root@wheezy:~# aptitude install ssh screen rsync sysv-rc-conf less telnet dnsutils whois mc mlocate sudo vim iperf iftop iptraf zip unzip bzip2
The following NEW packages will be installed:
  iftop iperf iptraf libcurses-perl{a} libcurses-ui-perl{a} libffi5{a} libglib2.0-0{a} 
  libglib2.0-data{a} libpcap0.8{a} libterm-readkey-perl{a} mc mc-data{a} rsync screen 
  shared-mime-info{a} sudo sysv-rc-conf unzip vim vim-runtime{a} zip 
0 packages upgraded, 21 newly installed, 0 to remove and 0 not upgraded.
Need to get 14.3 MB of archives. After unpacking 54.2 MB will be used.
Do you want to continue? [Y/n/?]
root@wheezy:~# aptitude install ssh screen rsync sysv-rc-conf less telnet dnsutils whois mc mlocate sudo vim iperf iftop iptraf zip unzip bzip2
The following NEW packages will be installed:
  iftop iperf iptraf libcurses-perl{a} libcurses-ui-perl{a} libffi5{a} libglib2.0-0{a} 
  libglib2.0-data{a} libpcap0.8{a} libterm-readkey-perl{a} mc mc-data{a} rsync screen 
  shared-mime-info{a} sudo sysv-rc-conf unzip vim vim-runtime{a} zip 
0 packages upgraded, 21 newly installed, 0 to remove and 0 not upgraded.
Need to get 14.3 MB of archives. After unpacking 54.2 MB will be used.
Do you want to continue? [Y/n/?]

14.3 MB con un apt.conf vacío, veamos cuántos MBs bajaría indicándole al sistema que no instale recomendados ni sugeridos.

1
2
3
4
5
6
7
8
9
10
root@wheezy:~# aptitude install ssh screen rsync sysv-rc-conf less telnet dnsutils whois mc mlocate sudo vim iperf iftop iptraf zip unzip bzip2 
The following NEW packages will be installed:
  iftop iperf iptraf libcurses-perl{a} libcurses-ui-perl{a} libffi5{a} libglib2.0-0{a} 
  libpcap0.8{a} libterm-readkey-perl{a} mc mc-data{a} rsync screen sudo sysv-rc-conf unzip vim 
  vim-runtime{a} zip 
The following packages are RECOMMENDED but will NOT be installed:
  libglib2.0-data shared-mime-info 
0 packages upgraded, 19 newly installed, 0 to remove and 0 not upgraded.
Need to get 12.1 MB of archives. After unpacking 42.2 MB will be used.
Do you want to continue? [Y/n/?]
root@wheezy:~# aptitude install ssh screen rsync sysv-rc-conf less telnet dnsutils whois mc mlocate sudo vim iperf iftop iptraf zip unzip bzip2 
The following NEW packages will be installed:
  iftop iperf iptraf libcurses-perl{a} libcurses-ui-perl{a} libffi5{a} libglib2.0-0{a} 
  libpcap0.8{a} libterm-readkey-perl{a} mc mc-data{a} rsync screen sudo sysv-rc-conf unzip vim 
  vim-runtime{a} zip 
The following packages are RECOMMENDED but will NOT be installed:
  libglib2.0-data shared-mime-info 
0 packages upgraded, 19 newly installed, 0 to remove and 0 not upgraded.
Need to get 12.1 MB of archives. After unpacking 42.2 MB will be used.
Do you want to continue? [Y/n/?]

12.1 MB! sólo es una pequeña diferencia con tan poco paquetes, pero veamos hasta qué punto podemos optimizar esto instalando un entorno completo de escritorio como XFCE.

Selection_006

/etc/apt/apt.conf vacío

Selection_007

/etc/apt/apt.conf optimizado

Sin la optimización en /etc/apt/apt.conf toda la descarga de XFCE serían 562MB contra los 324MB si no instalamos paquetes recomendados ni sugeridos, creo que está mas que clara la ventaja de utilizar esta configuración en un servidor para no solamente ocupar menos espacio sino que al tener menos paquetes y librerias disminuimos las posibilidades de sufrir vulnerabilidades en nuestro sistema.

Fumados III

♬ Vanessa Paradis et -M- dans “La Seine”

Instalación de OpenVSwitch en Debian Wheezy

Dado que Debian Wheezy (actual testing) está a la vuelta de la esquina antes de pasar a ser la versión estable en reemplazo de Squeeze, ya estoy haciendo pruebas para poder reemplazar mis servidores en los cuales virtualizo con KVM para poder utilizar las nuevas versiones de qemu + libvirt + spice.

Una de las cosas que deseo hacer es dejar de utilizar bridge-utils y reemplazarlo por openvswitch que es mas versátil y me provee a futuro de mejores opciones de configuración si tengo que trabajar en entornos con VLANS, QOS, NetFlow, etc.

Habiendo infinidad de posts en internet explicando el proceso de instalación de openvswitch para Debian Wheezy este no pretende ser la panacea, sino servir de ayudamemoria y documentar algunos tips con los que me fui encontrando a medida que voy realizando pruebas.

openvswitch features

En Debian tenemos 2 modos de instalar los módulos correspondientes a openvswitch en el kernel, uno es instalando el paquete openvswitch-datapath-dkms el otro es con openvswitch-datapath-source, para ver las diferencias ejecutamos el siguiente comando.

1
2
3
root@zama:~# aptitude search openvswitch |grep openvswitch-datapath
p   openvswitch-datapath-dkms       - Open vSwitch datapath module source - DKMS
p   openvswitch-datapath-source     - Open vSwitch datapath module source - module-assistant version
root@zama:~# aptitude search openvswitch |grep openvswitch-datapath
p   openvswitch-datapath-dkms       - Open vSwitch datapath module source - DKMS
p   openvswitch-datapath-source     - Open vSwitch datapath module source - module-assistant version

Como allí se ve, con la primera opción instalamos el modulo en el kernel si este tiene soporte para DKMS (x default en Debian) o utilizando module-assistant, queda a criterio de cada uno elegir el método apropiado de todas maneras aqui veremos ambos ejemplos pero vale mencionar que es conveniente utilizar la opción DKMS por si cambiamos en algún momento de kernel asi evitamos volver a compilar el modulo correspondiente.

Para ambos casos es necesario primero instalar estos paquetes:

1
root@zama:~# aptitude install build-essential module-assistant linux-headers-`uname -r`
root@zama:~# aptitude install build-essential module-assistant linux-headers-`uname -r`

Utilizando openvswitch-datapath-dkms

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
root@zama:~# aptitude install openvswitch-datapath-dkms
The following NEW packages will be installed:
  dkms{a} openvswitch-datapath-dkms 
0 packages upgraded, 2 newly installed, 0 to remove and 0 not upgraded.
Need to get 2,036 kB of archives. After unpacking 12.6 MB will be used.
Do you want to continue? [Y/n/?] 
.
.
.
.
Creating symlink /var/lib/dkms/openvswitch/1.4.2+git20120612/source ->
                 /usr/src/openvswitch-1.4.2+git20120612
 
DKMS: add completed.
 
Kernel preparation unnecessary for this kernel.  Skipping...
 
Building module:
cleaning build area....(bad exit status: 2)
./configure --with-linux='/lib/modules/3.2.0-4-amd64/build' && make -C datapath/linux..........
cleaning build area....(bad exit status: 2)
 
DKMS: build completed.
 
openvswitch_mod:
Running module version sanity check.
 - Original module
   - No original module exists within this kernel
 - Installation
   - Installing to /lib/modules/3.2.0-4-amd64/updates/dkms/
 
brcompat_mod.ko:
Running module version sanity check.
 - Original module
   - No original module exists within this kernel
 - Installation
   - Installing to /lib/modules/3.2.0-4-amd64/updates/dkms/
 
depmod...a.ptit.
 
DKMS: install completed.
root@zama:~# aptitude install openvswitch-datapath-dkms
The following NEW packages will be installed:
  dkms{a} openvswitch-datapath-dkms 
0 packages upgraded, 2 newly installed, 0 to remove and 0 not upgraded.
Need to get 2,036 kB of archives. After unpacking 12.6 MB will be used.
Do you want to continue? [Y/n/?] 
.
.
.
.
Creating symlink /var/lib/dkms/openvswitch/1.4.2+git20120612/source ->
                 /usr/src/openvswitch-1.4.2+git20120612

DKMS: add completed.

Kernel preparation unnecessary for this kernel.  Skipping...

Building module:
cleaning build area....(bad exit status: 2)
./configure --with-linux='/lib/modules/3.2.0-4-amd64/build' && make -C datapath/linux..........
cleaning build area....(bad exit status: 2)

DKMS: build completed.

openvswitch_mod:
Running module version sanity check.
 - Original module
   - No original module exists within this kernel
 - Installation
   - Installing to /lib/modules/3.2.0-4-amd64/updates/dkms/

brcompat_mod.ko:
Running module version sanity check.
 - Original module
   - No original module exists within this kernel
 - Installation
   - Installing to /lib/modules/3.2.0-4-amd64/updates/dkms/

depmod...a.ptit.

DKMS: install completed.

Con el comando anterior tenemos disponible el soporte para openvswitch en nuestro kernel, resta solamente instalar los paquetes restantes y habilitar la carga del modulo brcomp en el inicio del sistema.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
root@zama:~# aptitude install openvswitch-brcompat openvswitch-common openvswitch-switch
.
.
.
.
[ ok ] Inserting openvswitch module.
[warn] /var/lib/openvswitch/conf.db does not exist ... (warning).
[ ok ] Creating empty database /var/lib/openvswitch/conf.db.
[ ok ] Starting ovsdb-server.
[ ok ] Configuring Open vSwitch system IDs.
[ ok ] Starting ovs-vswitchd.
Setting up openvswitch-brcompat (1.4.2+git20120612-9) ...
[ ok ] ovsdb-server is already running.
[ ok ] ovs-vswitchd is already running.
root@zama:~# aptitude install openvswitch-brcompat openvswitch-common openvswitch-switch
.
.
.
.
[ ok ] Inserting openvswitch module.
[warn] /var/lib/openvswitch/conf.db does not exist ... (warning).
[ ok ] Creating empty database /var/lib/openvswitch/conf.db.
[ ok ] Starting ovsdb-server.
[ ok ] Configuring Open vSwitch system IDs.
[ ok ] Starting ovs-vswitchd.
Setting up openvswitch-brcompat (1.4.2+git20120612-9) ...
[ ok ] ovsdb-server is already running.
[ ok ] ovs-vswitchd is already running.

Una vez instalados estos paquetes editamos el archivo /etc/default/openvswitch-switch descomentamos y cambiamos a “yes” la siguiente variable

1
BRCOMPAT=yes
BRCOMPAT=yes

Cargamos el modulo brcomp y verificamos el estatus de los diferentes servicios.

1
2
3
4
5
6
7
8
9
root@zama:~# modprobe brcomp
root@zama:~# lsmod |grep brcomp
brcompat_mod           13031  0 
openvswitch_mod        67948  1 brcompat_mod
 
root@zama:~# /etc/init.d/openvswitch-switch status
ovsdb-server is running with pid 2627
ovs-vswitchd is running with pid 2686
ovs-brcompatd is running with pid 2727
root@zama:~# modprobe brcomp
root@zama:~# lsmod |grep brcomp
brcompat_mod           13031  0 
openvswitch_mod        67948  1 brcompat_mod

root@zama:~# /etc/init.d/openvswitch-switch status
ovsdb-server is running with pid 2627
ovs-vswitchd is running with pid 2686
ovs-brcompatd is running with pid 2727

Y listo! con eso tenemos soporte completo para openvswitch en nuestro servidor.

Utilizando openvswitch-datapath-source

Con este método utilizaremos module-assistant para compilar el modulo para nuestro kernel, comenzaremos instalando los paquetes apropiados.

1
root@zama:~# aptitude install openvswitch-datapath-source
root@zama:~# aptitude install openvswitch-datapath-source

Ejecutamos module-assistant donde en algún momento del proceso veremos algo como esto:

building_openvswitch

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
root@zama:~# module-assistant auto-install openvswitch-datapath
.
.
.
.
Updated infos about 1 packages
unpack 
Extracting the package tarball, /usr/src/openvswitch-datapath.tar.bz2, please wait...
"/usr/share/modass/packages/default.sh" build KVERS=3.2.0-4-amd64 KSRC=/lib/modules/3.2.0-4-amd64/build KDREV=3.2.39-2 kdist_image
Done with /usr/src/openvswitch-datapath-module-3.2.0-4-amd64_1.4.2+git20120612-9_amd64.deb .
dpkg -Ei /usr/src/openvswitch-datapath-module-3.2.0-4-amd64_1.4.2+git20120612-9_amd64.deb 
Selecting previously unselected package openvswitch-datapath-module-3.2.0-4-amd64.
(Reading database ... 51924 files and directories currently installed.)
Unpacking openvswitch-datapath-module-3.2.0-4-amd64 (from .../openvswitch-datapath-module-3.2.0-4-amd64_1.4.2+git20120612-9_amd64.deb) ...
Setting up openvswitch-datapath-module-3.2.0-4-amd64 (1.4.2+git20120612-9)
root@zama:~# module-assistant auto-install openvswitch-datapath
.
.
.
.
Updated infos about 1 packages
unpack 
Extracting the package tarball, /usr/src/openvswitch-datapath.tar.bz2, please wait...
"/usr/share/modass/packages/default.sh" build KVERS=3.2.0-4-amd64 KSRC=/lib/modules/3.2.0-4-amd64/build KDREV=3.2.39-2 kdist_image
Done with /usr/src/openvswitch-datapath-module-3.2.0-4-amd64_1.4.2+git20120612-9_amd64.deb .
dpkg -Ei /usr/src/openvswitch-datapath-module-3.2.0-4-amd64_1.4.2+git20120612-9_amd64.deb 
Selecting previously unselected package openvswitch-datapath-module-3.2.0-4-amd64.
(Reading database ... 51924 files and directories currently installed.)
Unpacking openvswitch-datapath-module-3.2.0-4-amd64 (from .../openvswitch-datapath-module-3.2.0-4-amd64_1.4.2+git20120612-9_amd64.deb) ...
Setting up openvswitch-datapath-module-3.2.0-4-amd64 (1.4.2+git20120612-9)

Haciendo esto vemos que se ha generado un *.deb y se ha instalado.

1
2
3
4
5
root@zama:~# aptitude search openvswitch |grep datapath
p   openvswitch-datapath-dkms       - Open vSwitch datapath module source - DKMS
v   openvswitch-datapath-module     -                                           
i   openvswitch-datapath-module-3.2 - Open vSwitch Linux datapath kernel module 
i   openvswitch-datapath-source     - Open vSwitch datapath module source - module-assistant version
root@zama:~# aptitude search openvswitch |grep datapath
p   openvswitch-datapath-dkms       - Open vSwitch datapath module source - DKMS
v   openvswitch-datapath-module     -                                           
i   openvswitch-datapath-module-3.2 - Open vSwitch Linux datapath kernel module 
i   openvswitch-datapath-source     - Open vSwitch datapath module source - module-assistant version

Sólo resta instalar los paquetes openvswitch-brcompat openvswitch-common openvswitch-switch editar el archivo /etc/default/openvswitch-switch, cargar el modulo brcomp y reiniciar para verificar que todo esté ok.

Este post me ha sido de ayuda para publicar mi propio tutorial explicando ambos métodos para instalar openvswitch:

http://phenobarbital.wordpress.com/2012/12/08/instalando-y-usando-openvswitch-en-debian-gnulinux/

♬ Lhasa De Sela – El Desierto