Browsing the topic linux
Improving system speed, disk life and everything else in one small command
5 Comments | Filed under Linux-Planet devel english linux mandrivaI just noticed this days that, according to smartctl, the hard disk on my notebook has reached 365 days on Power_On_Hours variable. As the notebook itself has almost 2 years of age (I bought it in March of 2008), it is almost a double birthday-combo
.
However, at this age, it is obvious that the hard disk of the notebook was not prepared to endure such challenges nicely. Both of its speed (5400 RPMs), durability, capacity, and so on were targeted on a more light use.
On the other hand, the system has 3GB of RAM, which is more than enough for most of my tasks. So after some thinking, I’ve been using some small script to automatically improve the system performance by offloading the most I/O-consuming stuff to RAM for the past few months.
How does it works? Simple. I have a small script which grabs content of a disk directory which I expect to receive heavy use (for example, /usr/lib/firefox, or the rpm BUILD/ directories which receive lots of I/O when building packages, and so on), and converts them into a RAM disk. This way, when anything inside such directory is accessed, it requires absolutely no hard disk I/O, the seek times are non-existent as well, and the throughput is incredible.
For example, if I build mozilla-thunderbird by using real hard disk BUILD directory, it takes almost 2 hours to build. If I use ramdisk for just the BUILD directory, the time required for such task drops down to about 30 minutes. The firefox startup time (both cold and hot – e.g., the first execution and consecutive ones) have the same time of about 1 second; and so on.
So, without further words, this is the script I am using:
#!/bin/bash
#
# This script remounts a directory in tmpfs (ramdisk) to speed it up
#
DIR=$1
SIZE=$2
if [ ! "$UID" = "0" ]; then
# this script must run by root. Let's try sudo'ing to root..
exec sudo $0 $*
fi
if [ ! -d $DIR ]; then
echo "Usage: $0 <full path to a directory>"
exit 1
fi
if [ "a$SIZE" = "a" ]; then
OPTIONS=""
else
OPTIONS="-o size=$SIZE"
fi
# first, copy everything somewhere to reuse it later
TMP=`mktemp`
tar cpf $TMP $DIR
# remount dir as ramdisk
mount -t tmpfs $OPTIONS $DIR $DIR
# unpack everything back
(cd / && tar xpf $TMP)
rm -f $TMP
To use it, just save it under a name like toram and use it on the directory you want to move to ramdisk. The second optional parameter is the size of the ramdisk to use – as by default tmpfs mounts itself with 50% of available ram, sometimes you may want to use more or less memory.
Just some examples on how to use it:
# toram `pwd`/BUILD (will remount current BUILD directory in RAM)
# toram /usr/lib/firefox-3.6 (will remount firefox directory in ram)
I hope this could be useful to someone
.
Well, this question appeared quite frequently to me. However, I never bothered with it, as I was either on a LAN, or had a different source from which I could resume using wget, or a file was sufficiently small to redownload it again. However, this time these approaches did not work:
- The file was big (a DVD ISO)
- The only way to access it was over a SSH connection
- The only authentication method it supported was public key authentication
- The directory from where the file was downloaded was read-only
- The link was sloooow
- I already had downloaded about 70% of the file
So I started looking for solutions. Most of ideas I found on google suggested using ‘rsync –partial –rsh=ssh‘, and indeed it could work. However, rsync tried to create a temporary file on the server, and, as the directory was read-only, it failed. There probably is some option to make it work, but I don’t have plenty of rsync experience. And this approach just looked to be over complicated.
After a bit of more googling, I found out that curl supported sftp backend. And, after a few minutes trying to figure out how to make it work with public key authentication, I finally figured it out:
curl -C - --pubkey ~/.ssh/key.pub --key ~/.ssh/key \
sftp://eugeni@somewhere/mnt/.../i586/my_precious_iso.iso \
-o my_precious_iso.iso
To shorten it up, it is possible to write a simple wrapper function (or a script) for bash:
#!/bin/bash
function scp_resume() {
URL="$1"
FILE="$2"
if [ "a$FILE" == "a" ]; then
echo "Usage: scp_resume <sftp url> <local target>"
return 1
fi
# the magic
curl -C - $URL -o $FILE
}
function scp_resume_key() {
URL="$1"
FILE="$2"
KEY="$3"
if [ "a$FILE" == "a" ]; then
echo "Usage: scp_resume <sftp url> <local target> <key file name>"
return 1
fi
# the magic
curl -C - --key $HOME/.ssh/$KEY --pubkey $HOME/.ssh/${KEY}.pub $URL -o $FILE
}
so it did the trick.
Was just playing with Google Chrome for Linux on my Mandriva installation.
In a few words – it rocks! There are still a lot of issues and non-implemented features, but even not it is:
- extremely fast
- surprisingly stable
- opens most of my favorite sites without any problems
It works pretty fine on Mandriva 2009.1/cooker, the only necessary thing is to setup the right links in /usr/lib for its libraries. But after that, it just works. I just miss the firefox extensions, like adblock, mouse gestures, stylish, twitter and delicious.com integration, but.. one cannot had it all
.
I am using MPD to play my small collection of mp3:
[eugeni@eugeni 16:53:31 ~] $ mpc stats
Artists: 787
Albums: 747
Songs: 9112
Everything is controlled by keybinding – for example, to run the play command, I press < Super >+Up; to run next command I press < Super >+Right, and so on. These shortcuts start a small client to mpd, which is nothing more than a shell script which:
- Starts MPD if it is not running (I do not start it on startup to save a few seconds of boot time)
- Runs mpdscribble in background to update the LAST.FM statistics
- Runs all required MPD commands
- And displays the results in a nice way
And it is multi-distro-oriented by the way
.
#!/bin/bash
# Is mpd running
mpc status 2> /dev/null
ret=$?
if [ ! "$ret" = "0" ]; then
notify-send -i audio "Music" "Starting mpd.."
# are we on arch linux?
if [ -x "/etc/rc.d/mpd" ]; then
sudo /etc/rc.d/mpd start
else
sudo su -c "service mpd start"
fi
# starting mpdscribble
mpdscribble
# starting sonata
sonata --hidden
fi
mpc $*
# Some black magick to get a bit more advanced mpd status
# and convert it to shell variables
eval `echo -e 'status\ncurrentsong\nclose\n' | \
nc localhost 6600 | \
sed -e '/OK/d' -e 's/: \(.*\)/="\1"/g'`
# show the results
notify-send -i audio "$Artist - $Album - $Title" \
"$(mpc status | sed -e 's/&/and/g')"
Just yet one another script which contributes to world’s entropy
.
Realmente, não tem jeito de habilitar cairo-lcd no firefox-nightly. O firefox (na sua versão atual) está usando funcionalidades de cairo que não foram integradas ao repositório oficial ainda.
Embora o 3.1 (e o 3.2a1) são MUITO mais rápidos que o firefox 3 comum, a aparence do firefox3 usando system-cairo dá de 10×0 neles.
Ahh que dúvida difícil.. Será que fico com o firefox lento+bonitinho, ou rápido+pouco legível??
Descobriremos nos próximos capítulos de Eugeni vs Firefox!
O que a falta do que fazer não faz..
Estava eu, feliz e contente, usando Arch Linux (que, por definição, só vem com pacotes mais recentes) durante os últimos 2 anos, junto com o firefox-nightly compilado manualmente. Mas, recentemente, passei para mandriva 2009. Mas.. senti que falta alguma coisa nele. Como Mandriva 2009 é uma versão “estável”, as coisas novas demoram para aparecer.. O problema de firefox foi fácil de se resolver (já tem todos os scripts prontos para compilá-lo mesmo), mas e os outros pacotes??
A decisão foi passar para o cooker – versão unstable do Mandriva. Precisou baixar 700MB de pacotes, atualizar metade do sistema, e remover alguns dos programas que eu uso direto (por exemplo, texlive-latex e xfce-cpufreq-plugin). Mas nada impossível de resolver na mão. E também, alguns dos meus softwares favoritos do Arch não estavam inclusos na distro (mas também, nada que um rpmbuild não resolva).
O que eu tiro como conclusão parcial? Que o esquema de pacotes de Arch é o melhor que todos os outros, de longe! Mas, com um pouco de sacrifício, dá para se acostumar com os SPEC’s, e criar RPMs na mão.
Agora estou de volta à vida on-the-bleeding-edge!
Depois de longos meses usando os Nightly Builds do Firefox 3 (até o lançamento oficial dele), voltei à vida on-the-edge. Agora estou usando a versão do Firefox 3.1, compilada manualmente a partir do mercurial!
Isso sim é apelado
.
O pior é que até agora não consegui fazer com que ele usasse o system-cairo direito.. Daí as fontes ficam bem diferentes do resto do sistema..
Quem usa o netspeed-applet do gnome e atualizou ele para versão 0.15, descobriu que esta versão não permite mais modificar o tamanho da fonte. Para mim isso é essencial (as fontes que vem pode padrão são muito grandes), por isso decidi fazer um patch para dar suporte a isso.
Para quem usa ArchLinux, o PKGBUILD já está no AUR
.
Para quem não usa ele, esse é o patch:
netspeed-applet with editable font size option
diff -ru netspeed_applet-0.15.2/src/netspeed.c netspeed_applet-0.15.2.fontsize/src/netspeed.c
--- netspeed_applet-0.15.2/src/netspeed.c 2008-09-13 16:59:52.000000000 -0300
+++ netspeed_applet-0.15.2.fontsize/src/netspeed.c 2008-10-23 14:57:41.000000000 -0200
@@ -85,6 +85,7 @@
gboolean show_sum, show_bits;
gboolean change_icon, auto_change_device;
GdkColor in_color, out_color;
+ int font_size;
int width;
GtkWidget *inbytes_text, *outbytes_text;
@@ -664,8 +665,11 @@
/* Refresh the text of the labels and tooltip */
if (applet->show_sum) {
+ add_markup_size(&applet->devinfo.sum_rate, applet->font_size);
gtk_label_set_markup(GTK_LABEL(applet->sum_label), applet->devinfo.sum_rate);
} else {
+ add_markup_size(&applet->devinfo.rx_rate, applet->font_size);
+ add_markup_size(&applet->devinfo.tx_rate, applet->font_size);
gtk_label_set_markup(GTK_LABEL(applet->in_label), applet->devinfo.rx_rate);
gtk_label_set_markup(GTK_LABEL(applet->out_label), applet->devinfo.tx_rate);
}
@@ -891,6 +895,7 @@
return;
}
panel_applet_gconf_set_string(PANEL_APPLET(applet->applet), "device", applet->devinfo.name, NULL);
+ panel_applet_gconf_set_int(PANEL_APPLET(applet->applet), "font_size", applet->font_size, NULL);
panel_applet_gconf_set_bool(PANEL_APPLET(applet->applet), "show_sum", applet->show_sum, NULL);
panel_applet_gconf_set_bool(PANEL_APPLET(applet->applet), "show_bits", applet->show_bits, NULL);
panel_applet_gconf_set_bool(PANEL_APPLET(applet->applet), "change_icon", applet->change_icon, NULL);
@@ -901,6 +906,15 @@
applet->settings = NULL;
}
+/* Set the font size to the new value
+ */
+static void
+font_size_adjust_cb(GtkSpinButton *spinbutton, NetspeedApplet *applet)
+{
+ applet->font_size = gtk_spin_button_get_value_as_int(spinbutton);
+ applet->width = 0;
+}
+
/* Called when the showsum checkbutton is toggled...
*/
static void
@@ -944,7 +958,12 @@
GtkWidget *category_header_label;
GtkWidget *network_device_hbox;
GtkWidget *network_device_label;
+ GtkWidget *label_font_size_hbox;
+ GtkWidget *label_font_size_hbox2;
+ GtkWidget *label_font_size_label;
+ GtkWidget *label_font_size_spinbutton;
GtkWidget *indent_label;
+ GtkWidget *points_label;
GtkWidget *show_sum_checkbutton;
GtkWidget *show_bits_checkbutton;
GtkWidget *change_icon_checkbutton;
@@ -1033,6 +1052,31 @@
gtk_combo_box_set_active(GTK_COMBO_BOX(applet->network_device_combo), active);
g_object_set_data_full(G_OBJECT(applet->network_device_combo), "devices", devices, (GDestroyNotify)free_devices_list);
+ label_font_size_hbox = gtk_hbox_new(FALSE, 6);
+ gtk_box_pack_start(GTK_BOX(controls_vbox), label_font_size_hbox, TRUE, TRUE, 0);
+
+ label_font_size_label = gtk_label_new_with_mnemonic(_("Label _font size:"));
+ gtk_label_set_justify(GTK_LABEL(label_font_size_label), GTK_JUSTIFY_LEFT);
+ gtk_misc_set_alignment(GTK_MISC(label_font_size_label), 0.0f, 0.5f);
+ gtk_size_group_add_widget(category_label_size_group, label_font_size_label);
+ gtk_box_pack_start(GTK_BOX(label_font_size_hbox), label_font_size_label, FALSE, FALSE, 0);
+
+ label_font_size_hbox2 = gtk_hbox_new(FALSE, 6);
+ gtk_box_pack_start(GTK_BOX(label_font_size_hbox), label_font_size_hbox2, TRUE, TRUE, 0);
+
+ label_font_size_spinbutton = gtk_spin_button_new_with_range (5.0, 32.0, 1.0);
+ gtk_spin_button_set_value(GTK_SPIN_BUTTON(label_font_size_spinbutton), (double) applet->font_size);
+ gtk_spin_button_set_snap_to_ticks(GTK_SPIN_BUTTON(label_font_size_spinbutton), TRUE);
+ gtk_spin_button_set_digits(GTK_SPIN_BUTTON (label_font_size_spinbutton), 0);
+ gtk_label_set_mnemonic_widget(GTK_LABEL(label_font_size_label), label_font_size_spinbutton);
+ gtk_box_pack_start(GTK_BOX(label_font_size_hbox2), label_font_size_spinbutton, TRUE, TRUE, 0);
+
+ points_label = gtk_label_new(_("points"));
+ gtk_label_set_justify(GTK_LABEL (points_label), GTK_JUSTIFY_LEFT);
+ gtk_misc_set_alignment(GTK_MISC (points_label), 0.0f, 0.5f);
+ gtk_size_group_add_widget(category_units_size_group, points_label);
+ gtk_box_pack_start(GTK_BOX (label_font_size_hbox2), points_label, FALSE, FALSE, 0);
+
show_sum_checkbutton = gtk_check_button_new_with_mnemonic(_("Show _sum instead of in & out"));
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(show_sum_checkbutton), applet->show_sum);
gtk_box_pack_start(GTK_BOX(controls_vbox), show_sum_checkbutton, FALSE, FALSE, 0);
@@ -1048,6 +1092,9 @@
g_signal_connect(G_OBJECT (applet->network_device_combo), "changed",
G_CALLBACK(device_change_cb), (gpointer)applet);
+ g_signal_connect(G_OBJECT (label_font_size_spinbutton), "value-changed",
+ G_CALLBACK(font_size_adjust_cb), (gpointer)applet);
+
g_signal_connect(G_OBJECT (show_sum_checkbutton), "toggled",
G_CALLBACK(showsum_change_cb), (gpointer)applet);
@@ -1343,6 +1390,30 @@
}
}
+/* Tries to get the desktop font size out of gconf
+ * database
+ */
+static int
+get_default_font_size(void)
+{
+ int ret = 12;
+ char *buf, *ptr;
+
+ GConfClient *client = NULL;
+ client = gconf_client_get_default();
+ if (!client)
+ return 12;
+ buf = gconf_client_get_string(client, "/desktop/gnome/interface/font_name", NULL);
+ if (!buf)
+ return 12;
+ ptr = strrchr(buf, ' ');
+ if (ptr)
+ sscanf(ptr, "%d", &ret);
+ g_free(buf);
+
+ return ret;
+}
+
static gboolean
applet_button_press(GtkWidget *widget, GdkEventButton *event, NetspeedApplet *applet)
{
@@ -1526,6 +1597,7 @@
applet->show_sum = FALSE;
applet->show_bits = FALSE;
applet->change_icon = TRUE;
+ applet->font_size = -1;
applet->auto_change_device = TRUE;
/* Set the default colors of the graph
@@ -1553,6 +1625,9 @@
applet->show_bits = panel_applet_gconf_get_bool(applet_widget, "show_bits", NULL);
applet->change_icon = panel_applet_gconf_get_bool(applet_widget, "change_icon", NULL);
applet->auto_change_device = panel_applet_gconf_get_bool(applet_widget, "auto_change_device", NULL);
+ applet->font_size = panel_applet_gconf_get_int(applet_widget, "font_size", NULL);
+ if (!applet->font_size)
+ applet->font_size = -1;
tmp = panel_applet_gconf_get_string(applet_widget, "device", NULL);
if (tmp && strcmp(tmp, ""))
@@ -1587,6 +1662,9 @@
}
}
+ if (applet->font_size < 1)
+ applet->font_size = get_default_font_size();
+
if (!applet->devinfo.name) {
GList *ptr, *devices = get_available_devices();
ptr = devices;
Hoje decidi gastar um tempo para aprender a fazer panoramas (em outras palavras, fotos compostas de forma contínua a partir de fotos menores). Por exemplo, você quer tirar foto da paisagem inteira, mas.. a sua camera só consegue pegar 1/3 dela. Solução? Tirar 3 fotos e juntar todas elas depois.
Para fazer isso, usei o Hugin. Usei 2 fotos que eu tirei no fim da semana, juntando-as para formar uma paisagem só.
Para a minha surpresa, foi absurdamente fácil o processo. Demorou menos de 5 minutos, sendo que o Hugin conseguiu fazer tudo sozinho (encontrar os pontos comuns entre as figuras, juntar elas, ajustar a exposição, etc).
Dá para ver o resultado da brincadeira no flickr.
Ahh, e tutorial que ensina a fazer tudo isso está aqui.
Bem, hoje saiu nova versão “estável” de Mandriva – Mandriva 2009. Aproveitando que estava com conexão rápida, baixei o CD de instalação (Mandriva ONE, versão que vem com Gnome) e instalei no meu note.
Concluindo em poucas palavras – essa versão de Mandriva não se deu bem com o meu notebook (ASUS G1S). Logo após a instalação, na hora de reiniciar o micro, o notebook travou de vez. Ao bootar, ele pediu para adicionar usuários (eu já tinha montado o meu /home antigo na instalação), e decidi usar o mesmo UID para o meu usuário, para continuar com os arquivos que eu tenho. Assim que eu adicionei um usuário, ele ficou mexendo sem parar no disco, rodando algum comando gigante com um grep e consumindo 100% de CPU. Aparentemente, ele quis mudar todos os arquivos do meu $HOME (tem 100GB.. hehehe) para.. para.. para algo o que eu não consegui descobrir
. Quando matei o grep, tudo continuo normalmente, até carregar o gnome.
Carregando o gnome, a tela tornou-se pouca usável – ao mexer o mouse, o display fica cheio de pequenos pixels pretos (algo parecido acontecia com antigas placas de vídeo da S3, onde o driver de video corrompia a memória de vídeo das placas). Pelo que eu vi, Mandriva usa o driver beta de Nvidia, o que causa este problema. Entretanto, no meu notebook eu usei todos os drivers beta também (173.08, 173.14.09, 177.13, 177.67, 177.70, 177.78 e 177.80), e nunca deu esse problema.
Também por algum motivo ele detectou 2 bluetooth’es e não detectou placa de wireless (iwl4965). Durante o boot, dá a impressão de que ele fica se divertindo com o sistema – a tela apaga e acende, e depois fica com menos brilho (será que é o notebook mode?), a webcam integrada pisca, liga e desliga…
Enfim, a primeira impressão que eu tive é que o mandriva 2009 não gostou do meu notebook. Vou esperar alguns dias para sair updates, aí eu tento atualizar, para ver se melhora alguma coisa. No entanto, continuo com o meu querido Arch Linux já faz 1 ano e meio! Até então o recorde foi do Slackware (4 anos consecutivos), mas ele perdeu justamente para o Arch Linux.
Linus Torvalds, o criador de Linux, também tem um blog.
E, logo neste blog, ele anunciou mais um software que ele fez nos últimos tempos – tracker, um sistema para monitorar o tempo que as crianças ficam na internet, desconectando-as depois de um tempo determinado.
O cara realmente é demais.. Faz o kernel do Linux, num fim da semana faz o GIT, e no outro desenvolve mais um software simples e eficiente como esse..
Além disso, lá tem uma bom review dos novos discos SSD de Intel, falando bem a verdade sobre o estado dos SSDs hoje em dia. Realmente, até Intel entrar neste mercado, discos SSD eram mais “moda” de que tecnologia. Agora as coisas estão diferente – só acompanhar as notícias dos novos lançamentos que grandes empresas logo depois do lançamento dos modelos da Intel. Só esperar abaixar o preço agora (umas 10x
).
Depois de apanhar muito do openoffice (tanto 2.4.1 quanto do 3.00_m6), decidi experimentar o IBM Lotus Symphony – conjunto de aplicações de escritório de IBM. Diz a lenda que ele é baseado no OpenOffice 1.1.
A alma corajosa que tem vontade de ver como que ele funciona, precisa passar por diversos desafíos:
- Primeiro, é necessário baixar um arquivo de 300MB, passando por diversas páginas que pedem seu registro no IBM.
- Segundo, é necessário dar um jeito de instalar o arquivo auto-executável que vem com alguns problemas embutidos (por exemplo, mktemp usa alguns parâmetros que o meu ArchLinux não suporta.. Por isso precisei extrair os arquivos na mão – nada que less + awk não resolva
). - Finalmente, tem que instalar ele.
Bem, neste item 3 que começam os problemas. A aplicação inteira é em Java. Se você achava que o OpenOffice é lento (nota rápida – OpenOffice 3 é MUITO mais rápido que o 2.4!), você vai se delirar com o Lotus Symphony. Eu acho que ele foi o 1o software que conseguiu travar o meu asus g1s (core 2 duo 2.0, 3GB de RAM) por mais de 1 minuto só para se iniciar.
Logo após iniciar, ele conseguiu se confundir internamente, mostrando diversos exceptions na tela (não no log, no meio da tela mesmo!).
Testando ele com os arquivos do OpenOffice e Office, também não consegui muito sucesso. Os arquivos .DOC/.ODT ele abriu certo. Mas com as apresentações ele se confundiu feio. Perdeu toda a formatação, fontes, itens, etc.
Visualmente, a interface dele é bem diferente do OpenOffice, e é parecida com o StarOffice original (tem tipo um menu “Iniciar”, e todos os documentos ficam abertos em tabs). O lado bom é que ele tem um menu com ações mais comuns de lado direito – algo que faz falta no OpenOffice.
Na tentativa de fechar os tabs ou sair, ele deu diversos exceptions e permaneceu aberto, não querendo abandonar este mundo cruel e injusto
. Ele também é praticamente impossível de ser iniciado a partir da linha de comando – o comando para iniciar a aplicação é: /opt/ibm/lotus/Symphony/framework/shared/eclipse/plugins/com.ibm.productivity.tools.standalone.launcher.linux.x86_1.5.0.20080827-1548/IBM\ Lotus\ Symphony
Resumindo, depois dessa breve experiência negativa que eu tive com ele, acabei voltando para o OpenOffice 3 que estava usando. Ele tem seus problemas existenciais (não tem dicionários, não tem como definir a língua do documento de jeito “convencional”, documentos ODF que ele salva são parcialmente incompatíveis com o OpenOffice 2 e 1), mas pelo menos dá para usar ele sem precisar ficar treinando paciência.
Infelizmente, até agora o Office 2007 da Microsoft é o melhor ambiente de escritório que já usei
. Tirando Latex, é claro, mas aí já é outra história..
Apareceu hoje:
[29716.863265] TCP: Treason uncloaked! Peer 125.46.3.227:17140/60001 shrinks window 2742629828:2742629837. Repaired.
Essa é melhor que lp0 on fire!











