Pesquisar neste blog

segunda-feira, 15 de fevereiro de 2016

Rescanning your SCSI bus to see new storage device

If you have added new storage to a running VM, you probably won’t see it. This is because the SCSI bus to which the storage devices are connected needs to be rescanned to make the new hardware visible.
How you rescan the SCSI bus depends on the operating system your Virtual Machine is running.
Instructions for common supported operating systems are as follows, these assume you have root or suitable privileges.

Linux, when adding a new disc

First find your host bus number

grep mpt /sys/class/scsi_host/host?/proc_name

Which should return a line like

/sys/class/scsi_host/host0/proc_name:mptspi

where host0 is the relevant field.
use this to rescan the bus with the following command

echo "- - -" > /sys/class/scsi_host/host0/scan

In the above command the the hyphens represent controller,channel,lun, so – - – indicates all controllers, all channels and all luns should be scanned.

Linux, when expanding an existing disc

Assuming you know the device name of the disc you have expanded (eg /dev/sda) then you can simply issue the following command to force the rereading of the disk geometry. NOte that this is not 100% reliable with LVM on older kernels but should work with current kernels

echo 1 > /sys/class/scsi_device/device/rescan

Windows Server

Windows should pickup the change in discs regardless of you adding or expanding discs however if not you can either use the gui or the command line to force this. Note that expanding the boot device will typically always require a reboot, and will require you to boot from an alternative boot device (a boot CD image) to actually expand the windows boot partition. All these method assume you are an administrator on the system.

GUI method – Server 2003

Open Computer Management (Local).
In the console tree, click Computer Management (Local), click Storage, and then click Disk Management.
Click Action, and then click Rescan Disks.

GUI method server 2008

Open Server Manager.
In the tree pane, double-click the Storage node, and select Disk Management.
Right-click Disk Management and select Rescan Disks.

Command line method

as an administrator, start a command prompt and type
diskpart
at the diskpart prompt, type
rescan
 
Source: blogs.it.ox.ac.uk

quarta-feira, 16 de dezembro de 2015

Comando TOP

Comando TOP

# top

http://2.bp.blogspot.com/-cmPCM6lA9hI/UrEFX9a3xeI/AAAAAAAACoY/6u92Bz5BZ4c/s1600/comando-TOP-header.png
O comando top no Linux exibe os processos em execução no sistema. Uma das ferramentas mais importantes para um administrador do sistema. É amplamente utilizado para monitorar a carga do sistema. Nesse artigo é explorado o comando top em detalhes, pois ele é um comando interativo; ou seja, muitos outros comandos estão disponíveis quando ele está executando. Sendo assim, domine o comando top!

I – SAÍDA DO COMANDO TOP

top
top - 23:18:09 up  1:45,  1 user,  load average: 0.76, 0.78, 0.76
Tasks: 192 total,   1 running, 190 sleeping,   0 stopped,   1 zombie
Cpu(s): 15.4%us,  5.7%sy,  0.0%ni, 78.8%id,  0.2%wa,  0.0%hi,  0.0%si,  0.0%st
Mem:   3058052k total,  2100524k used,   957528k free,   168696k buffers
Swap:  3481788k total,        0k used,  3481788k free,  1099720k cached
 
  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND                                                          
 3187 ricardo   20   0 1129m 403m  43m S   14 13.5  28:23.04 firefox                                                          
 1238 root      20   0 98840  27m 8876 S    6  0.9   4:45.38 Xorg                                                             
 2398 ricardo   20   0  429m  76m  29m S    4  2.6   3:01.05 compiz                                                           
 3352 ricardo   20   0  246m  53m  22m S    2  1.8   2:20.39 plugin-containe                                                  
 2431 ricardo   20   0  196m  25m  15m S    2  0.9   0:03.11 python                                                           
 2552 ricardo   20   0  166m  11m 8456 S    1  0.4   0:04.21 bamfdaemon                                                       
 2955 root      20   0     0    0    0 S    1  0.0   0:04.06 kworker/0:3                                                      
 2370 ricardo   20   0  6836 3352  632 S    1  0.1   0:14.33 dbus-daemon
Primeiramente, é preciso entender a saída do comando (mostrada acima). Ela exibe uma série de informações sobre o sistema em funcionamento. Então, é preciso ficar ciente das seções mostradas:

1 – Tempo de atividade e média de carga do sistema (Uptime and Load Averages)

top - 23:18:09 up  1:45,  1 user,  load average: 0.76, 0.78, 0.76
Na parte superior do comando top é apresentada a saída similar ao comando uptime.
* O tempo atual 
* O tempo que seu sistema está funcionando
 
* Número de usuários autenticados no sistema no momento
 
* Média de carga de 5, 10 e 15 minutos respectivamente.

2 – Tarefas (Tasks)

Tasks: 192 total,   1 running, 190 sleeping,   0 stopped,   1 zombie
A segunda linha mostra resumo das tarefas ou processos. Os processos podem ser em diferentes estados. Ela mostra o número total de processos. Destes, os processos podem estar executando (running), dormindo (sleeping), parado (stopped) ou modo zumbi (zombie)

3 – Estados da CPU (CPU States)

Cpu(s): 15.4%us,  5.7%sy,  0.0%ni, 78.8%id,  0.2%wa,  0.0%hi,  0.0%si,  0.0%st
Em seguida é apresentado o estado da CPU. O significado dos diferentes tempos de CPU são:
* us, usuário (user): tempo de CPU na execução dos processos de usuário 
* Sy, sistema (sytem): tempo de CPU na execução de processos do kernel
 
* Id, ocioso (idle): tempo de CPU em inatividade
 

* Wa, tempo para I/O: tempo de CPU esperando a conclusão de operação de entrada/saída no disco (I/O)
 
* hi: CPU tempo servindo interrupções de hardware
 
* Si: tempo de CPU servindo interrupções de software

4 – Uso da memória (Memory Usage)

Mem:   3058052k total,  2100524k used,   957528k free,   168696k buffers
Swap:  3481788k total,        0k used,  3481788k free,  1099720k cached
Estes mostram o uso de memória, um pouco do comando “free”. A primeira linha refere-se a memória física e a segunda linha a memória virtual (swap). A memória física é apresentada como: memória total disponível, memória usada, memória livre e memória usada para buffers. Da mesma forma, a swap: total, usada, espaço de troca livre e em cache. Todas em unidade Kilobyte

5 – Colunas

 PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND                                                          
 3187 ricardo   RT   0 1129m 403m  43m S   14 13.5  28:23.04 firefox                                                          
 1238 root      20   0 98840  27m 8876 S    6  0.9   4:45.38 Xorg                                                             
 2398 ricardo   20   0  429m  76m  29m S    4  2.6   3:01.05  compiz
Nesta seção, os processos são apresentados em colunas. As diferentes colunas representam diferentes propriedades exibidas abaixo:
PID (Identificador do processo) 
A identificação do processo (identificador único)
USUÁRIO (USER) 
Usuário proprietário do processo.
PR (Prioridade) 
A prioridade de agendamento do processo. Alguns valores neste campo são ‘ RT ‘ . Isso significa que o processo está sendo executado em tempo real (Real Time).
NI 
Os valores mais baixos significam maior prioridade.
VIRT 
A quantidade de memória virtual usada pelo processo.
RES 
O tamanho da memória usada. Residente na memória física e não na área de troca (swap).
SHR (Share – compartilhada) 
SHR é a memória compartilhada usada pelo processo.
S (State – estado)
Este é o estado do processo . Ele pode ter um dos seguintes valores :
D – ininterrupto 

R – executando
 
S – dormindo
 
T – rastreado ou parado
 
Z – zumbi
% CPU 
É a porcentagem de tempo de CPU que a tarefa tem usado desde a última atualização.
% MEM 
Percentagem de memória física disponível usada pelo processo.
TEMPO + 
O tempo total de CPU que a tarefa tem usado desde o início (precisão de centésimo de segundo)
COMANDO 
Descrição do comando que foi utilizado para iniciar o processo.

II – OPÇÕES DO COMANDO

1 – Resultado enxuto

top -b

2 – Tempo de atualização (a cada 2 segundos)

top -d 2

3 – Somente processos executando

top -i

4 – Limite de iteração

top -n 3

5 – Especificando o usuário

top -u “nome_usuario”

III – COMANDOS INTERATIVOS

Esses comandos serão usados durante a execução do comando TOP.

1 – ‘h’: Help

Help for Interactive Commands - procps version 3.2.8
Window 1:Def: Cumulative mode Off.  System: Delay 3.0 secs; Secure mode Off.
 
  Z,B       Global: 'Z' change color mappings; 'B' disable/enable bold
  l,t,m     Toggle Summaries: 'l' load avg; 't' task/cpu stats; 'm' mem info
  1,I       Toggle SMP view: '1' single/separate states; 'I' Irix/Solaris mode
 
  f,o     . Fields/Columns: 'f' add or remove; 'o' change display order
  F or O  . Select sort field
       . Move sort field: '' next col right
  R,H     . Toggle: 'R' normal/reverse sort; 'H' show threads
  c,i,S   . Toggle: 'c' cmd name/line; 'i' idle tasks; 'S' cumulative time
  x,y     . Toggle highlights: 'x' sort field; 'y' running tasks
  z,b     . Toggle: 'z' color/mono; 'b' bold/reverse (only if 'x' or 'y')
  u       . Show specific user only
  n or #  . Set maximum tasks displayed

2 – ‘ENTER’: Atualizar a amostragem

3 – ‘d’: Informe o tempo de atualização

top - 00:25:27 up  2:52,  1 user,  load average: 0.70, 0.65, 0.62
Tasks: 190 total,   2 running, 187 sleeping,   0 stopped,   1 zombie
Cpu(s): 13.5%us,  3.9%sy,  4.3%ni, 76.8%id,  1.4%wa,  0.0%hi,  0.1%si,  0.0%st
Mem:   3058052k total,  2106460k used,   951592k free,   177340k buffers
Swap:  3481788k total,        0k used,  3481788k free,  1086764k cached
Change delay from 3.0 to: 
  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND                                                          
 3187 ricardo   22   2 1216m 418m  43m S   20 14.0  50:26.41 firefox 

4 – ‘f’: Controle quais valores devem ser exibidos

Current Fields:  AEHIOQTWKNMbcdfgjplrsuvyzX  for window 1:Def
Toggle fields via field letter, type any other key to return 
 
* A: PID        = Process Id                                     0x00100000  PF_USEDFPU (thru 2.4)
* E: USER       = User Name
* H: PR         = Priority
* I: NI         = Nice value
* O: VIRT       = Virtual Image (kb)
* Q: RES        = Resident size (kb)
* T: SHR        = Shared Mem size (kb)
* W: S          = Process Status
* K: %CPU       = CPU usage
* N: %MEM       = Memory usage (RES)
* M: TIME+      = CPU Time, hundredths
  b: PPID       = Parent Process Pid
  c: RUSER      = Real user name
  d: UID        = User Id
  f: GROUP      = Group Name
  g: TTY        = Controlling Tty
  j: P          = Last used cpu (SMP)

5 – ‘i’: Apenas processos em execução

6 – ‘k’: Matar processos pelo identificador (ID)




Resident and Virtual memory on Linux: A short example


Tools like top show processes using two kinds of memory:
·         Resident memory, labelled RES: How much physical memory, how much RAM, your process is using. RES is the important number.
·         Virtual memory, labelled VIRT: How much memory your process thinks it’s using. Usually much bigger than RES, thanks to the Linux kernel’s clever memory management.


Here’s a short C program to illustrate the difference:
#include <stdio.h>
#include <stdlib.h>

void fill(unsigned char* addr, size_t amount) {
    unsigned long i;
    for (i = 0; i < amount; i++) {
        *(addr + i) = 42;
    }
}

int main(int argc, char **argv) {

    unsigned char *result;
    char input;
    size_t s = 1<<30;

    result = malloc(s);
    printf("Addr: %p\n", result);
    //fill(result, s);

    scanf("%c", &input);
    return 0;
}
Save it as mem.c, compile it cc -Wall -g mem.c -o mem and run it.
It requests 1 Gig of memory (1 << 30), but doesn’t use it. With top (or htop, which is much nicer), or even ps -Ao rsz,vsz,cmd | grep mem view it’s memory usage. The resident size should be quite small (~280k for me), but the virtual size will be the full 1 Gig we requested.
Uncomment the fill line, compile and run it again. You should see the resident size get much bigger, as we’re actually using the memory we requested (we’re filling it with the number 42). The kernel has to give us real memory to work with.
We can request far more virtual memory than the machine can handle. Here’s a screenshot where I’ve requested 16 Gig of memory, on a machine with only 3 Gig of RAM and 3 Gig of swap. The VIRT’s sum up to way more than that machine can handle. At the top left of the screenshot you can see none of that memory has really been allocated. The kernel won’t allocate it until we use it.
http://www.darkcoding.net/files/2012/10/htop.png
In summary, virtual size can largely be ignored. Resident size is the important number.