Boot/Scripts
| Questo articolo o questo paragrafo fanno riferimento alla versione '11.0', che attualmente è obsoleta! Per favore fai riferimento alla pagina di discussione di questo articolo per maggiori informazioni. |
Indice
Script Vari
Script per avviare il processo bootchart dal livello 1 di Init
I seguenti script si possono utilizzare per analizzare la fase di boot e i relativi tempi di avvio, usando bootchart. Questi script permettono agli utenti di riavviare il sistema andando al livello 1 di Init, e successivamente tornare al livello 5. Ciò sopperà bootchart quando gdmgreeter sarà caricato.
Questi script saranno presto disponibili anche tramite file downloadabili, ma per il momento bisogna usare copia/incolla e compilarli manualmente.
flush-disk.c è stato sritto da Robert Love @ Novell e è rilasciato sotto la licenza GNU GPL versione 2.
Istruzioni per l'Installazione
Scaricare i file qui sotto e dopo seguire i seguenti passi:
Compila tutti i file,usando Makefile e rendendo i file eseguibili (chmod 755 nomefile);
Posiziona bchart-init e bchart-stop nella cartella /etc/init.d
Posiziona bchart.sh in /root/bin
Nella directory dove sono posizionati flush-disk.c e il Makefile, lanciare il comando make, successivamente copia flush-disk nella cartella /sbin.
Uso
Chiudere tutti i programmi aperti;
Aprire un terminale
Accedi come superuser (su - ), poi avvia /root/bin/bchart.sh
L'ambiente grafico verrà riavviato, quindi aspetta che ricarichi il login grafico.
Entra nel desktop
Apri un terminale
Lancia: java -jar /usr/share/java/bootchart.jar /tmp/bootchart.tgz
Visualizza il file bootchart.png con un visualizzatore di immagini a tua scelta.
File e Sorgenti
bchart-init
#! /bin/bash
#
# Author: Magnus Boman <mboman@novell.com>
# Version: 20061017-0.1
#
# /etc/init.d/bchart-init
#
# A script to analyze system startup times with bootchartd
# Certain bits and pieces of "single" has been put in to this script as well
#
### BEGIN INIT INFO
# Provides: bchart-init
# Required-Start: $all
# Required-Stop:
# Default-Start: 1 S
# Default-Stop:
# Description: Setup the system to analyze startup times with bootchartd
### END INIT INFO
case "$1" in
start)
## Make sure we don't run again
chkconfig bchart-init off
## Make sure our "stop" script will run
chkconfig bchart-stop on
## We need to find out about all running processes. We then need to use this information to remove all those processes
## from the bootchartd results. Otherwise we end up with useless stats
ps ax -o command=|grep -vix rc|cut -d" " -f 1|tr -d [] >/tmp/running-processes.tmp
## Flush disk buffers
sync
sync
for i in `mount | awk '{print $1}' | grep ^"\/dev\/"`; do
/sbin/flush-disk $i
done
## Free pagecache, dentries and inodes
echo 3 > /proc/sys/vm/drop_caches
## Start the bootchart deamon
bootchartd start
## Switch to init level 5
telinit 5
;;
stop)
;;
*)
exit 1
;;
esac
bchart-stop
#! /bin/bash
#
# Author: Magnus Boman <mboman@novell.com>
# Version: 20061017-0.1
#
# /etc/init.d/bchart-stop
#
# A script to analyze system startup times with bootchartd
#
### BEGIN INIT INFO
# Provides: bchart-stop
# Required-Start: xdm
# Required-Stop:
# Default-Start: 5
# Default-Stop:
# Description: Setup the system to analyze startup times with bootchartd
### END INIT INFO
case "$1" in
start)
## Enable "single"
chkconfig single on
## Make sure we don't run again
chkconfig bchart-stop off
while [ "`pidof gdmgreeter`" = "" ]; do
sleep 1
done
## Stop the bootchart deamon
bootchartd stop
## Wait a couple of seconds to make sure that the bootchart files have been written
sleep 2
## Fix up the bootchart process list
tar xvf /var/log/bootchart.tgz -C /tmp
## Remove directory path from name in running processes
for i in `grep ^/ /tmp/running-processes.tmp`; do basename "$i"; done >/tmp/running-processes
## Get running processes that does not start with a /
grep -vi ^/ /tmp/running-processes.tmp >>/tmp/running-processes
echo -n "cat /tmp/proc_ps.log" >/tmp/bootchartd-fixup.sh
awk '{ printf "|grep -iv \"(" $1 ")\"" }' </tmp/running-processes >>/tmp/bootchartd-fixup.sh
echo " >/tmp/fixed_proc_ps.log" >>/tmp/bootchartd-fixup.sh
chmod 755 /tmp/bootchartd-fixup.sh
/tmp/bootchartd-fixup.sh
mv /tmp/fixed_proc_ps.log /tmp/proc_ps.log
tar -zcvf /tmp/bootchart.tgz -C /tmp proc_ps.log proc_diskstats.log proc_stat.log header
## This doesn't work as bootchart.jar requires an X connection
## So it needs to be run manually
# cd /tmp
# java -jar /usr/share/java/bootchart.jar /tmp/bootchart.tgz
;;
stop)
;;
*)
exit 1
;;
esac
bchart.sh
#!/bin/bash # # Author: Magnus Boman <mboman@novell.com> # Version: 20061010-0.1 # # /root/bin/bchart.sh # # A script to analyze system startup times with bootchartd # Disable "single" or our script will be terminated once we reached init level 1 chkconfig single off # Make sure that our script starts when we reach init level 1 chkconfig bchart-init on # Go to init level 1 telinit 1
Makefile
CFLAGS = -Wall -g LDFLAGS = -g prefix = $(HOME) targets = flush-disk objs = flush-disk.o all : $(targets) flush-disk : $(objs) clean : rm -f $(targets) $(objs)
flush-disk.c
/*
* flush-disk.c - flush the buffer cache of a given blkdev
*
* Robert "Spunky" Love <rml@novell.com>
*/
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <linux/fs.h>
int main (int argc, char *argv[])
{
char *blkdev;
int fd, ret;
if (argc < 2) {
fprintf (stderr, "usage: %s <disk to flush>\n", argv[0]);
return 1;
}
blkdev = argv[1];
fd = open (blkdev, O_RDONLY);
if (fd < 0) {
perror ("open");
return 1;
}
ret = ioctl (fd, BLKFLSBUF);
if (ret) {
perror ("ioctl");
return 1;
}
return 0;
}