Adicionando um segundo hd, juntando tudo num RAID1, e com alguma sorte não perdendo nada.

1 – adicionar o segundo hd

root@ubuntu:/home/caio# fdisk -l

Disk /dev/sda: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x00008f89

Device Boot Start End Blocks Id System
/dev/sda1 * 1 993 7976241 83 Linux
/dev/sda2 994 1044 409657+ 5 Extended
/dev/sda5 994 1044 409626 82 Linux swap / Solaris

Disk /dev/sdb: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x00000000

Disk /dev/sdb doesn’t contain a valid partition table

2 – instalar suporte a raid

root@ubuntu:/home/caio# apt-cache search mdadm
mdadm – tool to administer Linux MD arrays (software RAID)
root@ubuntu:/home/caio# apt-get install mdadm
Reading package lists… Done
Building dependency tree
Reading state information… Done
Recommended packages:
mail-transport-agent
The following NEW packages will be installed:
mdadm
0 upgraded, 1 newly installed, 0 to remove and 266 not upgraded.
Need to get 220kB of archives.
After unpacking 627kB of additional disk space will be used.
Get:1 http://br.archive.ubuntu.com gutsy/main mdadm 2.6.2-1ubuntu2 [220kB]
Fetched 220kB in 2s (99.3kB/s)
Preconfiguring packages …
Selecting previously deselected package mdadm.
(Reading database … 92659 files and directories currently installed.)
Unpacking mdadm (from …/mdadm_2.6.2-1ubuntu2_i386.deb) …
Setting up mdadm (2.6.2-1ubuntu2) …
Generating mdadm.conf… done.
Removing any system startup links for /etc/init.d/mdadm-raid …
update-initramfs: deferring update (trigger activated)
* Starting MD monitoring service mdadm –monitor [ OK ]

Processing triggers for initramfs-tools …
update-initramfs: Generating /boot/initrd.img-2.6.22-14-generic

3 – clonar a a tabela de particao e salvar backup da tabela no arquivo setores-sdb.bak

root@ubuntu:/home/caio# sfdisk -d /dev/sda | sfdisk /dev/sdb -O setores-sdb.bak
Checking that no-one is using this disk right now …
OK

Disk /dev/sdb: 1044 cylinders, 255 heads, 63 sectors/track

sfdisk: ERROR: sector 0 does not have an msdos signature
/dev/sdb: unrecognized partition table type
Old situation:
No partitions found
New situation:
Units = sectors of 512 bytes, counting from 0

Device Boot Start End #sectors Id System
/dev/sdb1 * 63 15952544 15952482 83 Linux
/dev/sdb2 15952545 16771859 819315 5 Extended
/dev/sdb3 0 – 0 0 Empty
/dev/sdb4 0 – 0 0 Empty
/dev/sdb5 15952608 16771859 819252 82 Linux swap / Solaris
Successfully wrote the new partition table

Re-reading the partition table …

If you created or changed a DOS partition, /dev/foo7, say, then use dd(1)
to zero the first 512 bytes: dd if=/dev/zero of=/dev/foo7 bs=512 count=1
(See fdisk(8).)

4 – setar tipos de todas as particoes de /dev/sdb para FD (Linux raid autodetect), exceto a particao extendida

root@ubuntu:/home/caio# sfdisk –change-id /dev/sdb 1 FD
Done
root@ubuntu:/home/caio# sfdisk –change-id /dev/sdb 3 FD
Done
root@ubuntu:/home/caio# sfdisk –change-id /dev/sdb 4 FD
Done
root@ubuntu:/home/caio# sfdisk –change-id /dev/sdb 5 FD
Done

5 – criar RAID devices (modo degradado). md0 para a raiz e md1 para swap

root@ubuntu:/home/caio# mdadm -C /dev/md0 –level=raid1 –raid-devices=2 missing /dev/sdb1
mdadm: array /dev/md0 started.
root@ubuntu:/home/caio# mdadm -C /dev/md1 –level=raid1 –raid-devices=2 missing /dev/sdb5
mdadm: array /dev/md1 started.
root@ubuntu:/home/caio# cat /proc/mdstat
Personalities : [raid1]
md0 : active raid1 sdb1[1]
7976128 blocks [2/1] [_U]

md1 : active raid1 sdb5[1]
409536 blocks [2/1] [_U]

unused devices:

6 – criar swap no /dev/md1

root@ubuntu:/home/caio# mkswap /dev/md1
Setting up swapspace version 1, size = 419360 kB
no label, UUID=9e18cec6-63a5-434a-9581-f99b58fbaadd
root@ubuntu:/home/caio# swapon /dev/md1
root@ubuntu:/home/caio# swapon -s
Filename Type Size Used Priority
/dev/sda5 partition 409616 0 -1
/dev/md1 partition 409528 0 -2

7 – criar sistema de arquivos no md0

root@ubuntu:/home/caio# mkfs -t ext3 /dev/md0
mke2fs 1.40.2 (12-Jul-2007)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
997472 inodes, 1994032 blocks
99701 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2042626048
61 block groups
32768 blocks per group, 32768 fragments per group
16352 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632

Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 21 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.

8 – copiar todos arquivos para o novo device RAID

root@ubuntu:/home/caio# mkdir /mnt/md0
root@ubuntu:/home/caio# mount /dev/md0 /mnt/md0/
root@ubuntu:/# find . -xdev -print0 | cpio -0pdvum –sparse /mnt/md0

9 – alterar fstab

# /dev/sda1
#antes
#UUID=e40d8ae6-03c1-4519-91d9-2d2b17a23832 / ext3 defaults,errors=remount-ro 0 1
#depois
/dev/md0 / ext3 defaults,errors=remount-ro 0 1

# /dev/sda5
#antes
#UUID=e596805b-c899-4c46-981e-56d6dc6ae600 none swap sw 0 0
#depois
/dev/md1 /swap sw 0 0

10 – editar menu.lst

title Ubuntu 7.10, kernel 2.6.22-14-generic RAID
root (hd0,0)
kernel /boot/vmlinuz-2.6.22-14-generic root=/dev/md0 ro quiet nosplash
initrd /boot/initrd.img-2.6.22-14-generic-raid
quiet

11 – instalar o grub

grub> device (hd0) /dev/sdb
grub> root (hd0,0)
grub> setup (hd0)
Checking if “/boot/grub/stage1” exists… yes
Checking if “/boot/grub/stage2” exists… yes
Checking if “/boot/grub/e2fs_stage1_5” exists… yes
Running “embed /boot/grub/e2fs_stage1_5 (hd0)”… 17 sectors are embedded.
succeeded
Running “install /boot/grub/stage1 (hd0) (hd0)1+17 p (hd0,0)/boot/grub/stage2 /boot/grub/menu.lst”… succeeded
Done.
grub> quit

12 – criar novo initrd para o RAID

cd /mnt/md0
mount -o bind /proc ./proc
mount -o bind /dev ./dev
chroot /mnt/md0
mkinitramfs -r /dev/md0 -o initrd.img-2.6.22-14-generic-raid

13 – testar boot

entrar no grub, setar root como hd1,0
definir configfile como /boot/grub/menu.lst
bootar.
o sistema deve bootar normalmente mas pelo RAID (ainda em modo degraded)

14 – configurar as particoes do sda para RAID

root@ubuntu:/home/caio# sfdisk –change-id /dev/sda 1 FD
Done
root@ubuntu:/home/caio# sfdisk –change-id /dev/sda 3 FD
Done
root@ubuntu:/home/caio# sfdisk –change-id /dev/sda 4 FD
Done
root@ubuntu:/home/caio# sfdisk –change-id /dev/sda 5 FD
Done

15 – Adicionar os sda ao RAID

root@ubuntu:/home/caio# mdadm /dev/md0 -a /dev/sda1
mdadm: added /dev/sda1
root@ubuntu:/home/caio# mdadm /dev/md1 -a /dev/sda5
mdadm: Cannot open /dev/sda5: Device or resource busy

ops, o sda5 esta sendo usado para swap

root@ubuntu:/home/caio# swapon /dev/md1
root@ubuntu:/home/caio# swapon -s
Filename Type Size Used Priority
/dev/sda5 partition 409616 0 -1
/dev/md1 partition 409528 0 -2
root@ubuntu:/home/caio# swapoff /dev/sda5
root@ubuntu:/home/caio# swapon -s
Filename Type Size Used Priority
/dev/md1 partition 409528 0 -2

root@ubuntu:/home/caio# mdadm /dev/md1 -a /dev/sda5
mdadm: added /dev/sda5

agora sim. neste momento o RAID está sendo sincronizado.
verifique o status com:

root@ubuntu:/home/caio# cat /proc/mdstat
Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5] [raid4] [raid10]
md1 : active raid1 sda5[0] sdb5[1]
409536 blocks [2/2] [UU]

md0 : active raid1 sda1[0] sdb1[1]
7976128 blocks [2/2] [UU]

unused devices:

16 – reinstalar grub

grub>
device (hd0) /dev/sda
root (hd0,0)
setup (hd0)
quit

17 – bootar e certificar que tudo funciona e que o raid está integro

caio@ubuntu:~$ cat /proc/mounts
rootfs / rootfs rw 0 0
none /sys sysfs rw,nosuid,nodev,noexec 0 0
none /proc proc rw,nosuid,nodev,noexec 0 0
udev /dev tmpfs rw 0 0
fusectl /sys/fs/fuse/connections fusectl rw 0 0
/dev/md0 / ext3 rw,data=ordered 0 0
/dev/md0 /dev/.static/dev ext3 rw,data=ordered 0 0
tmpfs /var/lock tmpfs rw,nosuid,nodev,noexec 0 0
tmpfs /lib/modules/2.6.22-14-generic/volatile tmpfs rw 0 0
tmpfs /dev/shm tmpfs rw 0 0
devpts /dev/pts devpts rw 0 0
tmpfs /var/run tmpfs rw,nosuid,nodev,noexec 0 0
tmpfs /var/lock tmpfs rw,nosuid,nodev,noexec 0 0
securityfs /sys/kernel/security securityfs rw 0 0
caio@ubuntu:~$ cat /proc/mdstat
Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5] [raid4] [raid10]
md1 : active raid1 sda5[0] sdb5[1]
409536 blocks [2/2] [UU]

md0 : active raid1 sda1[0] sdb1[1]
7976128 blocks [2/2] [UU]

unused devices: <none>

Advertisements

Terminou hoje o julgamento do caso do The Pirate Bay.
Por se tratar de um caso “complexo”, a sentença só será dada em 14 de abril de 2009 às 10:00 UTC.

Demostre seu apoio assim:

– Envie tweets com a keyword #spectrial

– Abra uma conta em http://www.bambuser.com e poste um video. Ele poderá ser passado no onibus estacionado do lado de fora do forum em Stockholm.
Veja como faze-lo:

– Assista a coletiva? de imprensa na integra aqui:
http://bambuser.com/channel/Spectrial/broadcast/73736

– Assista aos videos de Anna Oscarsson, RP? do TPB aqui:
http://bambuser.com/channel/Spectrial

– Acompanhe o blog do TPB sobre o julgamento aqui:
http://trial.thepiratebay.org/

one finger technique

8, February, 2009

Permissões de arquivos as vezes geram duvidas quanto sua correta aplicacao. Isso ocorre pelo não entendimento de alguns detalhes importantes do sistema de permissões de arquivos.

gafanhoto@backup:~$ ls -l
-rwxr----- 1 gafanhoto estagiarios 0 2008-05-04 23:42 arquivoprivado
gafanhoto@backup:~$

gafanhoto@backup:~$ cat arquivoprivado
#!/bin/bash
echo "$0 foi executado"
gafanhoto@backup:~$

Geralmente as permissões de “arquivoprivado” são lidas da seguinte forma:

1 – O usuario gafanhoto tem permissoes de leitura, escrita e execucao deste arquivo.
2 – Os usuarios do grupo “estagiarios” só tem permissão de leitura e nao pode modificar ou executar este arquivo.
3 – Os demais usuarios não tem qualquer permissão sobre o arquivo. Não podem lê-lo, escrevê-lo, apaga-lo ou executa-lo.

Correto? Não, ERRADO!!!

Os “estagiarios” podem executar este arquivo pois o bit de execução do arquivo diz respeito à sua capacidade de execucao direta (vide shebang).

barata@backup:/home/gafanhoto$ ./arquivoprivado
-sh: ./arquivoprivado: Permission denied
barata@backup:/home/gafanhoto$

barata@backup:/home/gafanhoto$ /bin/bash arquivoprivado
arquivoprivado foi executado
barata@backup:/home/gafanhoto$

UUID de discos – novo HD

8, February, 2009

UUID = Universally Unique Identifier

A utilizacao de UUIDs nas tabelas de montagem de discos (/etc/fstab) permite que dispositivos hotplug sejam identificados sempre pelo mesmo nome, mesmo que estejam em outro barramento.

Permite tambem que se altere as conexoes fisicas de hds já existentes sem alterar a tabela de montagem ou mesmo a configuracao da ordem de boot, uma vez que identificando o device pelo UUID, nao importa se ele é master, slave, se está na ide primaria ou secundaria.

Novos dispositivos que por algum motivo ainda nao tenham uuid gerados automagicamente precisam ter seus UUIDs criados para que se faca utilizacao deste recurso.

uuidgen
tune2fs /dev/sdaX -U numero-gerado-pelo-uuidgen

para descobrir um uuid de um device
blkid /dev/sdaX

depois é só adicionar a entrada no /etc/fstab
# /dev/hdc1
UUID=b4a4fa24-46c5-47a4-8c8d-afde3f7174f9 /media/300GB2 ext3 defaults,noatime,errors=remount-ro 0 1

bootar e verificar que está tudo certo

ls /dev/disk//by-uuid/
5ab22b6e-0219-4117-9690-00aaaea0f0d7 b4a4fa24-46c5-47a4-8c8d-afde3f7174f9 f4f9656c-7257-412d-9c00-4d466e42f7bf

mount
...
/dev/hdc1 on /media/300GB2 type ext3 (rw,noatime,errors=remount-ro)
...

Baixe o iphone sdk em:
http://developer.apple.com/iphone/download.action?path=/iphone/iphone_sdk_for_iphone_os_2.2__9m2621__final/iphone_sdk_for_iphone_os_2.2_9m2621_final.dmg

Crie seu proprio certificado para assinar os aplicativos como explicado aqui:
http://developer.apple.com/documentation/Security/Conceptual/CodeSigningGuide/Procedures/chapter_3_section_2.html

edite o arquivo /Developer/Platforms/iPhoneOS.platform/Info.plist e adicione os seguintes parametros na secao DefaultProperties

PROVISIONING_PROFILE_ALLOWED
NO
PROVISIONING_PROFILE_REQUIRED
NO

ps.: se voce ainda tem o sdk 2.1 ou inferior as opcoes de PROVISIONING estao lá, mas como padrao YES, entao apenas mude-as.

no Xcode, vá em “Project -> Edit Project Settings” e coloque o nome do certificado que voce criou em “Code Signing Identity->Any iPhone OS Device”

agora voce pode compilar o aplicativo para rodar no seu (ou qqer outro) iPhone.

ps. Se o Xcode estiver aberto e voce conectar seu iPhone ele perguntará se voce deseja provisiona-lo como aparelho de desenvolvimento. Clique “NO” se voce preza pelo trabalho que teve em fazer o jailbreak e/ou desbloqueio.

apos compilado basta copiar seu aplicativo para o iphone e faze-lo executavel, mais ou menos assim:

scp -r meuaplicativo.app root@enderecoipdoiphone:/Applications/
ssh root@enderecoipdoiphone
chmod +x /Applications/meuaplicativo.app/meuaplicativo

faça um “fast respring” ou “reboot” e o icode do aplicativo vai aparecer.

expressao aritmetica em bash

18, November, 2008

cançado de escrever :

~# a=5
~#b=6
~#c=`expr $a + $b`
~#echo $c
11

seus problemas acabaram!

~# a=5
~# b=6
~# c=$(($a+$b))
~# echo $c
11

começa agora…

27, October, 2008

[Mon Oct 27 01:49:00 BRST 2008]
0 segundos elapsed.

[Tue Nov 18 11:17:14 BRST 2008]
1931294 seconds elapsed.

echo [`date`] ; inicio=`date --date='Mon Oct 27 01:49:00' +%s` ; agora=`date +%s` ; elapsed=$(($agora-$inicio)) ; echo $elapsed seconds elapsed

ninja reboot

13, October, 2008

If you have ever had a hard drive fail on a remote server you may remember the feeling you had after trying to issue the following commands:

    # reboot
    bash: /sbin/reboot: Input/output error
    # shutdown -r now
    bash: /sbin/shutdown: Input/output error

Obviously, there is a problem with your drive. These commands are failing because the kernel is unable to load the /sbin/reboot and /sbin/shutdown binaries from the disk so that it can execute them.

A fsck on the next boot might be able to correct whatever is wrong with the disk, but first you need to get the system to reboot. If your machine is located at a managed hosting provider then you could submit a reboot ticket, but you’ll have to wait for someone to take responsibility.

Wouldn’t it be nice if there was a way to ask the kernel to reboot without needing to access the failing drive? Well, there is a way, and it is remarkably simple.

The “magic SysRq key” provides a way to send commands directly to the kernel through the /proc filesystem. It is enabled via a kernel compile time option, CONFIG_MAGIC_SYSRQ, which seems to be standard on most distributions. First you must activate the magic SysRq option:

    echo 1 > /proc/sys/kernel/sysrq

When you are ready to reboot the machine simply run the following:

    echo b > /proc/sysrq-trigger

This does not attempt to unmount or sync filesystems, so it should only be used when absolutely necessary, but if your drive is already failing then that may not be a concern.

In addition to rebooting the system the sysrq trick can be used to dump memory information to the console, sync all filesystems, remount all filesystems in read-only mode, send SIGTERM or SIGKILL to all processes except init, or power off the machine entirely, among other things.

Also, instead of echoing into /proc/sys/kernel/sysrq each time you can activate the magic SysRq key at system boot time using sysctl, where supported:

    echo "kernel.sysrq = 1" >> /etc/sysctl.conf

If you would like to learn more about magic SysRq you can read the sysrq.txt file in the kernel documentation.

from:http://www.linuxjournal.com/content/rebooting-magic-way