sábado, octubre 23, 2010

FreeBSD Updating and Upgrading

FreeBSD Updating and Upgrading
Requerimientos:

FreeBSD instalado
Conexion a Internet

Ahora vamos sincronizar y/o actualizar las fuentes de FreeBSD (Kernel + World) con csup

Chapter 24 Updating and Upgrading FreeBSD
http://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook/updating-upgrading.html

---------------------------------------

24.4.3 Updating the Documentation Sources
# csup -h cvsup15.us.FreeBSD.org -g -L 2 /usr/share/examples/cvsup/doc-supfile

---------------------------------------

24.6 Synchronizing Your Source
A.6 Using CVSup
Note: The csup utility is a rewrite of the CVSup...
...if you are using FreeBSD 6.2 or later, you can use it out-of-the-box, since it is included in the base system.
# csup -h cvsup15.us.FreeBSD.org -g -L 2 /usr/share/examples/cvsup/standard-supfile <-(VIEW THE TIP)
---
TIP :
# cp /usr/share/examples/cvsup/standard-supfile /root
# edit /root/standard-supfile
Change the lines
*default host=CHANGE_THIS.FreeBSD.org
*default release=cvs tag=RELENG_7_1
for
*default host=cvsup15.us.FreeBSD.org
*default release=cvs tag=RELENG_8_1

Exit from editor and save changes (en edit, con "Esc" main menu, "a" leave editor, "a" save changes)

Note :
for FreeBSD 8.1 RELEASE use tag=RELENG_8_1, for FreeBSD 8.2 use tag=RELENG_8_2
http://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook/cvs-tags.html
http://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook/cvsup.html#CVSUP-MIRRORS

# csup -g -L 2 /root/standard-supfile
---

---------------------------------------

24.7 Rebuilding “world”

These concerns have led to the following recommended sequence. Note that the detailed sequence for particular updates may require additional steps, but this core process should remain unchanged for some time:

# cd /usr/src (hay que estar dentro de este directorio para el siguiente comando)

1. make buildworld
This first compiles the new compiler and a few related tools, then uses the new compiler to compile the rest of the new world. The result ends up in /usr/obj.

2. make buildkernel <-(VIEW THE TIP)
Unlike the older approach, using config(8) and make(1), this uses the new compiler residing in /usr/obj. This protects you against compiler-kernel mismatches.

3. make installkernel <-(VIEW THE TIP)
Place the new kernel and kernel modules onto the disk, making it possible to boot with the newly updated kernel.
---
TIP: Storing your kernel configuration file directly under /usr/src can be a bad idea. If you are experiencing problems it can be tempting to just delete /usr/src and start again. After doing this, it usually only takes a few seconds for you to realize that you have deleted your custom kernel configuration file. Also, do not edit GENERIC directly, as it may get overwritten the next time you update your source tree, and your kernel modifications will be lost.

You might want to keep your kernel configuration file elsewhere, and then create a symbolic link to the file in the i386 directory.

For example:
# cd /usr/src/sys/i386/conf
# mkdir /root/kernels
# cp GENERIC /root/kernels/MYKERNEL
# ln -s /root/kernels/MYKERNEL

8.6 The Configuration File
Now, edit MYKERNEL with your favorite text editor.
# edit MYKERNEL
Change the line:
ident GENERIC
for
ident MYKERNEL

Save an exit for editor (en edit, con "Esc" se abre el menu, "a" salir del editor, "a" guardar cambios)
8.5 Building and Installing a Custom Kernel
Building a Kernel
1. Change to the /usr/src directory:
# cd /usr/src
2. Compile the kernel:
# make buildkernel KERNCONF=MYKERNEL
3. Install the new kernel:
# make installkernel KERNCONF=MYKERNEL
---

4. Reboot into single user mode <-(VIEW THE TIP)
Single user mode minimizes problems from updating software that's already running. It also minimizes any problems from running the old world on a new kernel.
---

TIP:
24.7.5 Drop to Single User Mode

As the superuser, you can execute:

# shutdown now

from a running system, which will drop it to single user mode.

Alternatively, reboot the system, and at the boot prompt, select the “single user” option. The system will then boot single user. At the shell prompt you should then run:

# fsck -p
# mount -u /
# mount -a -t ufs
# swapon -a
---

5. mergemaster -p <-(VIEW THE NOTE)
This does some initial configuration file updates in preparation for the new world. For instance it may add new user groups to the system, or new user names to the password database. This is often necessary when new groups or special system-user accounts have been added since the last update, so that the installworld step will be able to use the newly installed system user or system group names without problems.
---
NOTE:
http://www.understudy.net/makeworld.html#mergemaster1

*** The directory specified for the temporary root environment,
/var/tmp/temproot, exists. This can be a security risk if untrusted users have access to the system.

Use 'd' to delete the old /var/tmp/temproot and continue
Use 't' to select a new temporary root directory
Use 'e' to exit mergemaster

Default is to use /var/tmp/temproot as is

How should I deal with this? [Use the existing /var/tmp/temproot]

Press Enter ( which means use /var/tmp/temproot ) and you should be good to go. This will keep the temporary root environment in /var/tmp/temproot. It will now start to compare a large number of files. And show you the differences between them.

Now it is going to start going through your /etc/ directory and /dev/MAKEDEV file .This is the beginning of the hellish part of Make World. Some notes on what you will see here. Mergemaster brings up the current file on the hard drive and the new version.If they are the same it smiles and moves on. If they are different it will point out the differences. It brings up what is different between the files and shows you just the things that are different in the file. It may not need to bring up everything in the file. The symbols used in Mergemaster:

--- 3 minus symbols in a row usually pertaining to the date of the file installation. I have only seen them at the top of a file that is to be changed. It means the line next to them really has to be removed.

+++ 3 plus symbols in a row usually pertaining to the date of the file installation. I have only seen them at the top of a file that is to be changed. It means the line next to them really has to be added (replace the existing line).

@@ means the line numbers that will be affected by the change. @@ -1,5 +1,24 @@ means line 1 and the next 4 lines will become line 1 and the next 24 lines. Look at the next symbols to understand.
+ means the line that will be added.

- means the line that will be replaced/ removed

. The mergemaster then brings up this dialogue.

Use 'd' to delete the temporary .name of file
Use 'i' to install the temporary .name of file
Use 'm' to merge the temporary and installed versions or parts of them.
Use 'v' to view the diff results again

Default is to leave the temporary file to deal with by hand

How should I deal with this? [Leave it for later]

'd' will remove any new lines for the file leaving it the way it was. No changes.
'i' will install all of the new lines and remove all of the old lines.
'm' will place both old and /or new lines in the file.
'v' lets you look at it again.

Use 'i' if you want to upgrade. Use 'd' if you don't. Use 'm' if you want to screw with things. And do it without the quotes.

Okay important notes here. If you have custom files in the /etc/ directory And you just click through this without checking. I can assure you they will be gone when your trip to Make World is done. and you will not have had a good time on the rides.You did remember to backup didn't you?
So how do I know what to upgrade and what to not upgrade? And what to merge?

My rules of thumb on this is:

The 'd' is for files that I have customized. Files I don't want changes in. Files like ppp.conf.
---

*** Comparison complete
Do you wish to delete what is left of /var/tmp/temproot? [no] (dar enter)


# cd /usr/src (hay que estar dentro de este directorio para el siguiente comando)

6. make installworld
Copies the world from /usr/obj. You now have a new kernel and new world on disk.

7. mergemaster
Now you can update the remaining configuration files, since you have a new world on disk.
---
Default is to use /var/tmp/temproot as is

How should I deal with this? [Use the existing /var/tmp/temproot] (dar enter)

The presence of stale files in this directory can cause the
dreaded unpredictable results, and therefore it is highly
recommended that you delete them.

*** Delete them now? [n] yes (poner 'yes' y dar enter)

Default is to leave the temporary file to deal with by hand

How should I deal with this? [Leave it for later] ( si es un archivo que hemos modificado como ppp.conf doy 'd', pero si me sirve el nuevo poner 'i' y dar enter)

Do you wish to delete what is left of /var/tmp/temproot? [no] yes (poner yes y dar enter)
---

8. reboot
A full machine reboot is needed now to load the new kernel and new world with new configuration files.

---------------------------------------

Para verificar que version de kernel tenemos, usamos el comando:
# uname -a
FreeBSD pruebas.alpha.telemedellin.tv 8.1-RELEASE-p1 FreeBSD 8.1-RELEASE-p1 #0: Thu Oct 21 07:44:33 COT 2010 angel@pruebas.alpha.telemedellin.tv:/usr/obj/usr/src/sys/MYKERNEL i386

Si hemos actualizado la version de FreeBSD modificando el RELENG_X_Y puede que tengamos que recompilar e instalar todos los ports que tengamos actualmente instalados, para hacer esto ejecutamos
# portupgrade -af

Si quisieramos desistalar todos los ports que tengamos en un solo comando, puedemos ejecutar
# cd /var/db/pkg
# pkg_delete *

---------------------------------------

Si algo sale mal y el nuevo kernel no funciona bien, puedo regresar al anterior
Al iniciar el equipo nos muestra el listado de opciones de inicio de FreeBSD

6. Escape to loader prompt
Type '?' for a list of commands, 'help' for more detailed help.
OK

(escribimos)
unload kernel (enter)
(escribimos)
boot /boot/kernel.old/kernel (enter)

Luego podemos renombrar el kernel problematico y renombrar el kernel anterior que funciona (kernel.old)
# mv /boot/kernel /boot/kernel.bad
# mv /boot/kernel.old /boot/kernel

---------------------------------------

Ahora vamos a actualizar el arbol de ports

# csup -h cvsup15.us.FreeBSD.org -g -L 2 /usr/share/examples/cvsup/ports-supfile <-(VIEW THE TIP)
---
TIP :
# cp /usr/share/examples/cvsup/ports-supfile /root
# edit /root/ ports-supfile
Change the lines
*default host=CHANGE_THIS.FreeBSD.org
for
*default host=cvsup15.us.FreeBSD.org

Exit from editor and save changes (en edit, con "Esc" main menu, "a" leave editor, "a" save changes)

# csup -h cvsup15.us.FreeBSD.org -g -L 2 /root/ports-supfile

Note :
http://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook/cvsup.html#CVSUP-MIRRORS
---

---------------------------------------

Ejemplo de como se usan los ports, aqui instalaremos portupgrade, es una utilidad para mantener actualizados los ports que se instalen luego y hasta portupgrade mismo.

Instalar nuestro primer port, portupgrade:
# whereis portupgrade
portupgrade: /usr/ports/ports-mgmt/portupgrade
# cd /usr/ports/ports-mgmt/portupgrade
# make install clean
Options for portupgrade 2.4.6_4,2
[X] BDB4 Use Berkeley DB >=2 as backend
[ OK ]

Suele pasar que luego de instalar algun port, al ejecutar el comando, nos muestre
Command not found.

Hay dos formas de hacer que permita usar el port:

Ejecutar el comando
# rehash

Tambien podemos simplemente salir de la sesion (exit), iniciar de nuevo sesion y ejecutar el comando de nuevo

Comandos basicos de portupgrade:
# pkg_version -v <- Imprime como estan las versiones
# portupgrade -a <- Actualiza los ports instalados
# portsclean -DD <- Limpia los ports viejos guardados en /usr/ports/distfiles