Saturday, January 5, 2013

Live USB F18 for Mac

The magic command:

livecd-iso-to-disk --format --efi Fedora-18-Beta-x86_64-Live-Desktop.iso /dev/sdx

Now I just have to wait for the final release :).


Monday, August 15, 2011

Apache zabbix monitoring

I found few scripts for zabbix apache monitoring and all of them wasn't suitable for me. There is my contribution :). It can do only one request per all of the checks. Source is here.

Friday, May 20, 2011

why not?

python -c "import telnetlib,time;tn = telnetlib.Telnet('127.0.0.1', 10031);tn.write('ppolicyFactory.modules[\'stats\'][0].STAT_DATA\r\n');time.sleep(1);output = [line for line in tn.read_until('}')];print ''.join(output).split()[4][0:-1]"

Sunday, February 13, 2011

C vs Python vs Perl sort comparison

First findings are:
  1. C is way faster in sorting then python.
  2. Python code is way shorter then C.
  3. Python is faster than Perl and less memory hungry.

Python source code: Python sort code
Perl source code: Perl sort code

C code was taken from here.
Heap sort in C: file_sort_heap.c.
Quick sort in C: file_sort_quick.c


Doc file is here.

Second findings are:
Python code could be a memory eater.
Explanation is here and here. For every string in the list is allocated 80 bytes=2288 MB of RAM for 30,000,000. Solution would be to use smarter data structure in the python (standard int is 24 bytes).
With the C we have 2 bytes short int which is little bit less :).

Python sorting file with 30,000,000 numbers took around 2-3GB of RAM (file with numbers was 150 MB). Which is too much memory. Solution is to use special sorting for big files for example something like here or C.

With perl I couldn't sort the 30,000,000 numbers file because of out of memory problems (4GB RAM and 2GB swap).

It'd be interesting to try python with psyco module. Unfortunately the rpm isn't present in the Fedora 14.

Saturday, February 20, 2010

Cryptography MIX

This is just a compilation of texts from wikipedia.
I'll extend this text little bit more later.
  1. Symmetric-key algorithm
    1. Triple DES
    2. Serpent
    3. Blowfish
    4. Twofish
  2. Asymmetric key algorithms
    1. Diffie–Hellman key exchange
    2. Digital Signature Algorithm (DSA)
    3. ElGamal encryption
    4. Cramer–Shoup cryptosystem
    5. Elliptic curve cryptography (ECC)
  3. Cryptographic hash function
    1. SHA hash functions
    2. MD5 (Message-Digest algorithm 5)
  4. Key size Brute force


Symmetric-key algorithm

Are a class of algorithms for cryptography that use trivially related, often identical, cryptographic keys for both decryption and encryption.

Symmetric-key algorithms can be divided into stream ciphers and block ciphers. Stream ciphers encrypt the bytes of the message one at a time, and block ciphers take a number of bytes and encrypt them as a single unit.

AES(Rijndael)

Standard adopted by the U.S. government
128, 192 and 256 bit. wiki

A related-key attack can break 256-bit AES with a complexity of 2119, which is faster than brute force but is still infeasible. 192-bit AES can also be defeated in a similar manner, but at a complexity of 2176. 128-bit AES is not affected by this attack. A chosen-plaintext attack can break 8 rounds of 192-bit and 256-bit AES, and 7 rounds of 128-bit AES, although the workload is impractical at 2128 - 2119. (Ferguson et al., 2000). wiki

DES
56 bits
Old. DES is now considered to be insecure for many applications.

Triple DES
168 bits (three 56-bit DES keys)
Triple DES provides a relatively simple method of increasing the key size of DES to protect against brute force attacks, without requiring a completely new block cipher algorithm. wiki

Serpent
128, 192 or 256 bits
The Serpent cipher has not been patented. It is completely in the public domain and can be freely used by anyone.
The XSL attack, if effective, would weaken Serpent (though not as much as it would weaken Rijndael, which became AES). However, many cryptanalysts believe that once implementation considerations are taken into account the XSL attack would be more expensive than a brute force attack.
The 32 rounds make Serpent have a higher security margin than Rijndael; however, Rijndael with 10 rounds is faster and easier to implement for small blocks. Hence, Rijndael was selected as the winner in the AES competition.
wiki

Blowfish
Variable key length from 32 up to 448 bits.
recommends using the more recent Twofish algorithm instead.
wiki

Twofish
128, 192 or 256 bits
On most software platforms Twofish is slightly slower than Rijndael (the chosen algorithm for Advanced Encryption Standard) for 128-bit keys, but somewhat faster for 256-bit keys.
The Twofish cipher has not been patented and the reference implementation has been placed in the public domain.

Advanced Encryption Standard process
The Advanced Encryption Standard (AES), the block cipher ratified as a standard by National Institute of Standards and Technology of the United States.
Rijndael: 86 positive, 10 negative
Serpent : 59 positive, 7 negative
Twofish : 31 positive, 21 negative
RC6 : 23 positive, 37 negative
MARS : 13 positive, 83 negative
wiki

Asymmetric key algorithms

Diffie–Hellman key exchange
In practice, Diffie–Hellman is not used in this way, with RSA being the dominant public key algorithm. This is largely for historical and commercial reasons, namely that RSA created a Certificate Authority that became Verisign. Diffie–Hellman cannot be used to sign certificates, although the ElGamal and DSA signature algorithms are related to it.
wiki

Digital Signature Algorithm (DSA)
United States Federal Governmentstandard or FIPS for digital signatures.DSA is covered by U.S. Patent 5,231,668, filed July 26, 1991, and attributed to David W. Kravitz, a former NSA employee. This patent was given to "The United States of America as represented by the Secretary of Commerce, Washington, D.C." and the NIST has made this patent available worldwide.wiki

ElGamal encryption
ElGamal encryption is used in the free GNU Privacy Guard software, recent versions of PGP, and other cryptosystems.
wiki

RSA (Rivest, Shamir and Adleman)
It is the first algorithm known to be suitable for signing as well as encryption, and was one of the first great advances in public key cryptography. RSA is widely used in electronic commerce protocols, and is believed to be secure given sufficiently long keys and the use of up-to-date implementations.
wiki

Cramer–Shoup cryptosystem
It is an extension of the Elgamal cryptosystem. In contrast to Elgamal, which is extremely malleable, Cramer–Shoup adds additional elements to ensure non-malleability even against a resourceful attacker. This non-malleability is achieved through the use of a collision-resistant hash function and additional computations, resulting in a ciphertext which is twice as large as in Elgamal.
wiki


Elliptic curve cryptography (ECC)
At least one ECC scheme (ECMQV) and some implementation techniques are covered by patents.
128-bit security one needs a curve over F(q), where q 2^256. This can be contrasted with finite-field cryptography (e.g., DSA) which requires 3072-bit public keys and 256-bit private keys, and integer factorization cryptography (e.g., RSA) which requires 3072-bit public and private keys.
wiki


Cryptographic hash function

SHA hash functions
AlgorithmOutput size (bits)Collisions found
SHA-0160yes
SHA-1160None
SHA-2256/224None
SHA-2512/384None

wiki

MD5 (Message-Digest algorithm 5)

U. S. Department of Homeland Security said MD5 "should be considered cryptographically broken and unsuitable for further use,"and most U.S. government applications will be required to move to the SHA-2 family of hash functions by 2010.

is a widely used cryptographic hash function with a 128-bit hash value. As an Internet standard (RFC 1321),Recently, a number of projects have created MD5 rainbow tables which are easily accessible online, and can be used to reverse many MD5 hashes into strings that collide with the original input, usually for the purposes of password cracking. However, if passwords are combined with a salt before the MD5 digest is generated, rainbow tables become much less useful.
The use of MD5 in some websites' URLs means that Google can also sometimes function as a limited tool for reverse lookup of MD5 hashes. This technique is also rendered ineffective by the use of a salt.
wiki

Comparison of cryptographic hash functions


Key size
The security of an algorithm cannot exceed its key length (since any algorithm can be cracked by brute force), but it can be smaller.
A key should therefore be large enough that a brute force attack (possible against any encryption algorithm) is infeasible – i.e, would take too long to execute. Shannon's work on information theory showed that to achieve so called perfect secrecy, it is necessary for the key length to be at least as large as the message to be transmitted and only used once (this algorithm is called the One-time pad).

As each of these is of a different level of cryptographic complexity, it is usual to have different key sizes for the same level of security, depending upon the algorithm used. For example, the security available with a 1024-bit key using asymmetric RSA is considered approximately equal in security to an 80-bit key in a symmetric algorithm (Source: RSA Security).
With a key of length n bits, there are 2n possible keys.

This number grows very rapidly as n increases. Moore's law suggests that computing power doubles roughly every 18 to 24 months, but even this doubling effect leaves the larger symmetric key lengths currently considered acceptably well out of reach. The large number of operations (2128) required to try all possible 128-bit keys is widely considered to be out of reach for conventional digital computing techniques for the foreseeable future.

The Advanced Encryption Standard published in 2001 uses a key size of (at minimum) 128 bits. It also can use keys up to 256 bits (a specification requirement for submissions to the AES contest).
128 bits is currently thought, by many observers, to be sufficient for the foreseeable future for symmetric algorithms of AES's quality. The U.S. Government requires 192 or 256-bit AES keys for highly sensitive data.

As of 2003 RSA Security claims that 1024-bit RSA keys are equivalent in strength to 80-bit symmetric keys, 2048-bit RSA keys to 112-bit symmetric keys and 3072-bit RSA keys to 128-bit symmetric keys. RSA claims that 1024-bit keys are likely to become crackable some time between 2006 and 2010 and that 2048-bit keys are sufficient until 2030. An RSA key length of 3072 bits should be used if security is required beyond 2030. NIST key management guidelines further suggest that 15360-bit RSA keys are equivalent in strength to 256-bit symmetric keys.

One of the asymmetric algorithm types, elliptic curve cryptography, or ECC, appears to be secure with shorter keys than those needed by other asymmetric key algorithms.
NIST guidelines state that ECC keys should be twice the length of equivalent strength symmetric key algorithms. So, for example, a 224-bit ECC key would have roughly the same strength as a 112-bit symmetric key. These estimates assume no major breakthroughs in solving the underlying mathematical problems that ECC is based on. A message encrypted with an elliptic key algorithm using a 109-bit long key has been broken by brute force.

The amount of time required to break a 128-bit key is also daunting. Each of the 2128 (340,282,366,920,938,463,463,374,607,431,768,211,456) possibilities must be checked. A device that could check a billion billion keys (1018) per second would still require about 1013 years to exhaust the key space.
This is a thousand times longer than the age of the universe, which is about 13,000,000,000 (1.3×1010) years.

AES permits the use of 256-bit keys. Breaking a symmetric 256-bit key by brute force requires 2128 times more computational power than a 128-bit key. A device that could check a billion billion (1018) AES keys per second would require about 3×1051 years to exhaust the 256-bit key space.

An underlying assumption of this analysis is that the complete keyspace is used to generate keys, something that relies on an effective random number generator.
wiki

Sunday, October 18, 2009

Nefunkcni Mic F11

# amixer -c0 sset 'Input Source' 'Front Mic'
Simple mixer control 'Input Source',0
Capabilities: cenum
Items: 'Mic' 'Front Mic'
Item0: 'Front Mic'

Source http://www.linux-archive.org/fedora-desktop/285894-recording-front-mic-fedora-11-a.html

Monday, October 12, 2009

Bonding Red Hat

Nastaveni eth0

DEVICE=eth0
BOOTPROTO=none
USRCTL=no
MASTER=bond0
ONBOOT=yes
SLAVE=yes
TYPE=Ethernet

Nastaveni eth1

DEVICE=eth0
BOOTPROTO=none
USRCTL=no
MASTER=bond0
ONBOOT=yes
SLAVE=yes
TYPE=Ethernet

Nastaveni bond0

Vytvorit soubor ifcfg-bond0 /etc/sysconfig/network-scripts

DEVICE=bond0
BOOTPROTO=dhcp
ONBOOT=yes
# IPADDR=192.168.203.231
# NETMASK=255.255.255.0
USRCTL=no
# GATEWAY=192.168.203.1
TYPE=Ethernet
IPV6INIT=no
PEERDNS=yes

modprobe.conf
alias bond0 bonding
options bond0 miimon=80 mode=1 downdelay=200 updelay=200

mode=0 (balance-rr)
Round-robin policy: Transmit packets in sequential order from the first available slave through the last. This mode provides load balancing and fault tolerance.

mode=1 (active-backup)
Active-backup policy: Only one slave in the bond is active. A different slave becomes active if, and only if, the active slave fails. The bond's MAC address is externally visible on only one port (network adapter) to avoid confusing the switch. This mode provides fault tolerance. The primary option affects the behavior of this mode.

mode=2 (balance-xor)
XOR policy: Transmit based on [(source MAC address XOR'd with destination MAC address) modulo slave count]. This selects the same slave for each destination MAC address. This mode provides load balancing and fault tolerance.

mode=3 (broadcast)
Broadcast policy: transmits everything on all slave interfaces. This mode provides fault tolerance.

mode=4 (802.3ad)
IEEE 802.3ad Dynamic link aggregation. Creates aggregation groups that share the same speed and duplex settings. Utilizes all slaves in the active aggregator according to the 802.3ad specification.
 Pre-requisites:
1. Ethtool support in the base drivers for retrieving
the speed and duplex of each slave.
2. A switch that supports IEEE 802.3ad Dynamic link
aggregation.
Most switches will require some type of configuration
to enable 802.3ad mode.
mode=5 (balance-tlb)
Adaptive transmit load balancing: channel bonding that does not require any special switch support. The outgoing traffic is distributed according to the current load (computed relative to the speed) on each slave. Incoming traffic is received by the current slave. If the receiving slave fails, another slave takes over the MAC address of the failed receiving slave.
 Prerequisite:
Ethtool support in the base drivers for retrieving the
speed of each slave.
mode=6 (balance-alb)
Adaptive load balancing: includes balance-tlb plus receive load balancing (rlb) for IPV4 traffic, and does not require any special switch support. The receive load balancing is achieved by ARP negotiation. The bonding driver intercepts the ARP Replies sent by the local system on their way out and overwrites the source hardware address with the unique hardware address of one of the slaves in the bond such that different peers use different hardware addresses for the server.

SELinux

Trocha Teorie

SELinux má tři základní typy (POLICIES)
  • Strict - vše zkázáno, pouze se povoluje
  • MLS(Multi Level Security) - RHEL 5 se speciální licencí
  • Targeted - pouze některé procesy(systémové) jsou omezeny
Standardně se používá targeted.

SELinux může být ve třech stavech
  • disable
  • permissive - pouze zaznamenává případné konflikty
  • enforcing - vynucuje pravidla
SELinux Labeling
SELinux přidává ke všemu(souborům, procesům, porty, pakety ....) toto:

user_u:role_r:types_t:MLS

např:
system_u:object_r:httpd_exec_t:s0

Jediné co se v targeted používá je types_t(Type Enforcement) a user_u(velice omezeně)

user_u práva
/usr/sbin/semanage login -l
Ukáže mapování uživatelů na SELinux

  • unconfined_u .. nevztahuje se na něj SELinux (takto spuštěné procesy se chovají stejně jako bez SELinuxu)
  • system_u .. standardní systémový uživatel (řídí se dle SELinux pravidel)
type_t práva
Vše co končí na _t patří do Type. Práva se dědí dle adresáře.

  • httpd_t .. základní jméno
  • httpd_sys_content_t .. static web
  • httpd_sys_script_exec_t .. skripty, které může Apache spouštět
  • httpd_sys_content_rw_t .. soubory do, kterých může zapisovat pouze httpd_sys_script_exec_t
  • httpd_sys_content_ra_t .. pouze přidávat
Nastavení se dají zjistit například nainstalováním SELinux devel

yum install selinux-policy-devel.noarch

A průzkumem jednotlivých konfiguráků v

/usr/share/selinux/devel/include

Pro jednotlivé adresáře jsou práva zadaná v

/etc/selinux/targeted/contexts/files/

SELinux transition
Některá pravidla slouží k tomu, aby měnila type_t spouštěných aplikací.

Například toto initrc_t, named_exec_t, named_t nám říká, pokud proces initrc_t spouští soubor named_exec_t mají přejít práva z initrc_t na named_t.
Normálně to co spustí proces initrc_t běží s právy initrc_t.

Příklad předávání práv:


Změna policy za běhu

Výpis všech nestavení, které se dají měnit za běhu
getsebool -a

Nastavení požadované hodnoty
setsebool ­-P virt_use_nfs [1|0]

Konfiguráky
/etc/selinux

Logy
/var/log/audit/audit.log

Zapnutí SELinuxu
Pro změnu z disable na permissive nebo enforcing je potřeba restartovat počítač.
Změna z permissive na enforcing a obráceně je možná za chodu.

Změnu lze provést zde
/etc/selinux/config

Změna za chodu (trvá pouze do restartu jinak se musí zapsat do konfiguráku)

Permissive na Enforcing
echo "1" > /selinux/enforce nebo setenforce 0

Enforcig na Permissive
echo "0" > /selinux/enforce nebo setenforce 1

Ověření stavu SELinuxu
sestatus

SELinux změněné příkazy
ls -Z, id -Z, ps auxZ, lsof -Z, find / -context

Moduly SELinuxu
Vypsání všech modulů
semodule -l

Změna SELinux práv na souborech
Krátkodobá (do restartu)
chcon -t type file-name

Trvalá (zapíše do souboru /etc/selinux/targeted/contexts/files/file_contexts.local)
Soubor
/usr/sbin/semanage fcontext -a -t samba_share_t /etc/file1
Adresář
/usr/sbin/semanage fcontext -a -t httpd_sys_content_t "/web(/.*)?"

Obnovení práv podle souborů v /etc/selinux/targeted/contexts/files/
/sbin/restorecon -R -v /adresar/

Práce se soubory
Kopírování
Zachování práv
cp -Z co kam
Přesun
Vždy si zachovává práva co měl.
Kontrola práv
Udělá kontrolu zda jsou nastavena práva dle definic.
/usr/sbin/matchpathcon -V Cesta

LinkFedora SELinux
http://fedoraproject.org/wiki/SELinux
Ceska Dokumentace
http://www.root.cz/knihy/ceska-dokumentace-pro-selinux/
Clanky Root
http://www.root.cz/serialy/jak-spravne-na-selinux/

Oprofile

Instalace
yum install oprofile

Pokud chceme profilovat i kernel musime nejdriv naistalovat kernel-debuginfo

yum install --enablerepo=rhel-debuginfo kernel-debuginfo

Zjistime kde ho mame
rpm -ql kernel-debuginfo | grep vmlinux

Nastaveni opcontrol pro profilovani s kernelem
opcontrol --vmlinux=`rpm -ql kernel-debuginfo | grep vmlinux`

Pokud nechceme profilovat kernel vystacime si s

opcontrol --no-vmlinux

Inicializace
opcontrol --init

Virtualni stroje

opcontrol --deinit
modprobe oprofile timer=1


Start demona a start profilovani
opcontrol --start

Vyresetovani dosud sebranych hodnot

opcontrol --reset

Zastaveni profilovani
opcontrol --stop

Zabiti demona

opcontrol --shutdown

Zapsani vsech vysledku do souboru

opcontrol --dump

Ulozeni stavajicich dat
opcontrol --save "jmeno"

Vysledky jsou ulezeny v
/var/lib/oprofile/samples/oprofiled.log

Pri novem spusteni se data pridavaji.

Reporty
Vše
opreport

Pouze binarky
opreport --exclude-dependent

Detailní profiling programu
Instalce debug verze programu
yum install --enablerepo=rhel-debuginfo balicek-debuginfo
Report
opreport -l cesta_k_binarce

Tuesday, September 22, 2009

Proklety cifs

Jak spravne pripojit samba share.

mount -t cifs //IP/Storage/C /mnt/disk/ -o iocharset=utf8,file_mode=0777,dir_mode=0777,noperm

Sakra kdo si ma tohle porad pamatovat.

Tuesday, September 8, 2009

VMware(winXp) do VirtualBoxu

Predelani vmware winXp do VirtualBoxu.

  1. Vytvoreni pouze jednoho vmdk souboru: vmware-vdiskmanager -r Windows\ XP\ Pro\ SP2.vmdk -t 2 singleXP.vmdk
  2. Konverze vmdk na raw: qemu-img convert -O raw singleXP-flat.vmdk winXP.raw
  3. Konverze raw na vdi: VBoxManage convertfromraw winXP.raw winXP.vdi
  4. Nastaveni ACPI tak jak bylo ve VMware (Enable IO APIC)
  5. Nastavani IDE na PII4
  6. Disable agp440.sys v recovery konsoli (disable agp440)
  7. Mozne problemy s activaci
Vytvoreni raw z realne masiny:
dd if=/dev/hda bs=15M conv=sync,noerror | ssh -o TCPKeepAlive=yes root@vmware_host_ip

Odkazy:
http://www.kleinfelter.com/node/135

Zenity Budik

Snaha o vytvoreni jedoducheho vyskakovaciho okna (na vareni uplne idalni vec :)) ). Uz jsem si to musel zapsat. Zjistovani jak to funguje mi zase sezralo hodinu :(.
echo 'export DISPLAY=":0.0";/usr/bin/zenity --info --text "Nejaky Vtipny Text"' | at now+1min

echo 'mpq321 /cesta/k/songu' | at now+1min

Saturday, April 11, 2009

Prilis komplikovana mys

Koupil jsem si prilis komplikovanou mys. 11 tlacitek celkem. Bohuzel funkcnost v linuxu je takova zvlastni. Novy evdev driver vsechna tlacitka pozna a umozni vyuzivat, ale s ostatnimi palikacemi je to trosku slozitejsi (naprosto nechapu kde je zakopany pes).K vyreseni tohoto problemu tu mame xev, xbindkeys, xmacroplay.

xev..ukaze po zmacknuti kod klavesy a vsechny veci s tim souvesijici (napriklad zda je klavesa detekovana)
xbindkeys..umozni po stisknuti urcite kombinace klaves spustit libovolny program
xmacroplay..umoznuje poslat klavesu nebo kombinaci klaves xservru

Spusteni xbindkeys v povidacim modu
xbindkeys -n -v

Muj .xbindkeysrc zatim spis prvni pokus.

# Control + mouse button 1 starts an xterm
# "xterm"
# Control + b:13

# Mappings for keys for MX Revo
# b:1 - left mouse button
# b:2 - left and right mouse button together
# b:3 - right mouse button
# b:4 - mouse wheel up
# b:5 - mouse wheel down
# b:6 - mouse wheel left
# b:7 - mouse wheel right
# b:8 - back button
# b:9 - forward button
# b:10 - -none-
# b:11 - -none-
# b:12 - -none-
# b:13 - media wheel up
# b:14 - -none-
# b:15 - media wheel down
# b:16 - media wheel press
# b:17 - -none-


"echo 'KeyStrPress KP_1 KeyStrRelease KP_1'| xmacroplay :0"
b:6
"echo 'KeyStrPress KP_2 KeyStrRelease KP_2' | xmacroplay :0"
b:7
"echo 'KeyStrPress KP_3 KeyStrRelease KP_3'| xmacroplay :0"
b:8
"echo 'KeyStrPress KP_4 KeyStrRelease KP_4' | xmacroplay :0"
b:9
"echo 'KeyStrPress KP_5 KeyStrRelease KP_5'| xmacroplay :0"
b:13
"echo 'KeyStrPress KP_6 KeyStrRelease KP_6' | xmacroplay :0"
b:15
"echo 'KeyStrPress KP_7 KeyStrRelease KP_7'| xmacroplay :0"
b:16
# "echo 'KeyStrPress KP_8 KeyStrRelease KP_8'| xmacroplay :0"
# c:0x1008ff1b

# Mapping for mousewheel right
#"echo 'KeyStrPress Control_L KeyStrPress Shift_L KeyStrPress Tab KeyStrRelease Tab KeyStrRelease Shift_L KeyStrRelease Control_L'| xmacroplay :0"
#b:6
#“echo 'KeyStrPress Control_L KeyStrPress Tab KeyStrRelease Tab KeyStrRelease Control_L' | xmacroplay :0″
#b:7

# Mappings for media wheel
#“echo 'KeyStrPress Control_L KeyStrPress t KeyStrRelease t KeyStrRelease Control_L' | xmacroplay :0″
#b:13
#“echo 'KeyStrPress Control_L KeyStrPress w KeyStrRelease w KeyStrRelease Control_L' | xmacroplay :0″
#b:15
#“echo 'KeyStrPress Alt_L KeyStrPress F9 KeyStrRelease F9 KeyStrRelease Alt_L' | xmacroplay :0″
#b:17

# Mappings for middle button
#“echo 'ButtonPress 2 ButtonRelease 2' | xmacroplay :0″
#c:0xE1

Sunday, March 29, 2009

qemu-kvm pres vnc na pozadi

qemu-kvm
-m 1024
-hdb /home/slune/Images/disk1.img
-vnc 127.0.0.1:1
-usbdevice tablet
-cdrom /home/slune/Images/F10-i686-Live.iso
-daemonize
/home/slune/Images/fedora.img

Pro paranoiky
ssh -L 5901:127.0.0.1:5901 w.x.y.z

Saturday, March 28, 2009

LVM sado maso hratky

Uvod:
LVM ma 3 zakladni vrstvy.
PV, VG, LV

PV-fyzicke disky(/dev/sdX)
VG-volume group(obdoba fyzickych disku)
LV-logicke jednotka(obdoba oddilu na disku)


Rozsireni stavajiciho oddilu o novy disk
Muzme nejdriv pouzit fdisk a vytvorit partiton (neni nutnost)
Incializujeme disk pro LVM.
pvcreate /dev/sdb1
(pvremove /dev/sdb1 nam oddil odstrani)
pvdisplay nam ukaze vsechny inicializovane disky.

Pridame disk do Grupy.
vgextend VolGroup00 /dev/sdb1

Ted mame ve skupine dva disky sda a sdb.
Pokud by jsme chteli jeden disk odstranit muzme pouzit
Presuneme data z sdb1 na sda1.
vgmove /dev/sdb1 /dev/sda1
Odstranime disk ze skupiny.
vgreduce VolGroup00 /dev/sdb1
Zrusime inicializaci LVM na disku.
pvremove /dev/sdb1

Pro rozsireni skupiny pouzijeme prikaz:
lvextend -l +100%PVS /dev/VolGroup00/LogVol00 /dev/sdb1
rozsirujeme o 100% velikosti /dev/sdb1

Odebrani disku
  1. nejdrive zmensime oddil o pozadovanou velikost
  2. nejdrive zmensime LV
  3. odstranime disk z VG
  4. odstranime z disku PV

ad.1
resize2fs /dev/VolGroup00/LogVol00 2048M
Tento bod musime dodrzet jinak si lehce zkorumpuje disk.Jde normalne pripojit, ale hlasi spatnou velikost.
Reseni je znovu VG rozsirit.
Bohuzel resize smerem dolu jde pouze pri odmontovanem disku.

ad 2.
Zjistime mnozstvi alokovanych PE (physical extent(nejmesi mozna adresovatelna jednotka LVM)) jednotek.
lvreduce -l -31 /dev/VolGroup00/LogVol00

ad 3.
Odstranime disk z VG.
vgreduce VolGroup00 /dev/sdb1


Problem
Situace:
Jak opravit situaci kdy jeden z linarne namapovanych disku prestane fyzicky existovat. Je treba ho odebrat z LVM a upravit velikost ext3 oddilu.

Odebrat disk z VG grupy



Seznam prikazu
lvmdiskscan - ukaze vsechna zarizeni pouzitelna pro LVM
pvs,lvs,vgs - informace o PV, LV,VG
pvscan, lvscna, vgscan - prohleda disky pro ...
pv(lv,vg)display - ukaze atributy ...
vgchange - zmeni attributy volume grupy
vgcfgbackup - zaloha LVM metadat

Linky:
http://www.redhat.com/docs/en-US/Red_Hat_Enterprise_Linux/5/html/Cluster_Logical_Volume_Manager/index.html
http://www.howtoforge.com/linux_lvm

Friday, February 20, 2009

co se vsechno zapisuje pri prihlaseni pres ssh

Otazka zni: kde se co zapisuje pri ssh prihlaseni u Fedory 10(asi to bude stejne pro RH obecne).

Pro zjisteni pouzijeme aide tak aby sledovala cely fs krome /dev a /proc .
  1. spustime aide -C (vytvori nam referencni soubor)
  2. prihlasime se a napiseme par prikazu
  3. aide -i > aide.diff

Zapsane soubory jsou tyto:
  1. /var/log/btmp
  2. /var/log/wtmp(utmp)
  3. /var/log/lastlog
  4. /var/log/secure
  5. /var/log/.bash_history
ad 1.
zaznamenava spatne loginy - binarni soubor. lastb pro zobrazeni.

ad 2.
zaznamenava vsechny loginy - binarni soubor. last pro zobrazeni

Oba zaznemenavaji cas a IP adresu

ad 3.
textovy soubor kde je zapis posledniho prihlaseni pro vsechny uzivatele. lastlog pro zobrazeni

ad 4.
textovy soubor se vsim moznym co se tyka bezpecnosti (zaznamenany spatny pokus o nalogovani)

ad 5.
textovy soubor s historii prikazu.





who
Shows a listing of currently logged-in users.
w
Shows who is logged on and what they are doing.
last
Shows a list of last logged-in users, including login time, logout time, login IP address, etc.
lastb
Same as last, except that by default it shows a log of the file /var/log/btmp, which contains all the bad login attempts.
lastlog
This command reports data maintained in /var/log/lastlog, which is a record of the last time a user logged in.
ac
Prints out the connect time in hours on a per-user basis or daily basis etc. This command reads /var/log/wtmp.
dump-utmp
Converts raw data from /var/run/utmp or /var/log/wtmp into ASCII-parsable format.

Saturday, February 14, 2009

Strapace se zmenou umisteni /usr

Tak si jsem zopakoval svou oblibenou chybu a priradil / malo mista. Co s tim?
Odpoved: premistit adresar /usr (je nejvetsi).

  1. live ubuntu
  2. prekopirovat adresar
  3. udelat symlink
  4. nabootovat
  5. zjistit ze symlink neni dobra volba(kupodivu spousta programu neumi se symlinky pracovat (man, plymounth ....), system nenajede do GUI
  6. co ted?
  7. pouzit mount a pripojit adreser jako adresar
  8. googlovani linksem

mount --bind odkud kam

/etc/fstab
odkud kam none rw,bind 0 0

Krasne stravne dopoledne :).

Friday, February 6, 2009

Fedora a WiFi

Maly navod jak zprovoznit WIFI ve fedore. Otazkou zustava k cemu mi bude navod na jak se dostat na net na netu :).

Vypnout NetworkManager

Pro smazani a nahrani sitoveho modulu(po pouziti kismetu)
modprobe -r iwlagn
modprobe iwlagn

# detekce siti
iwlist scan

# nastaveni modu
iwconfig eth0 mode Managed

# nastaveni sesid
iwconfig eth0 essid homenet

# vytvoreni klice pro OPEN WEP
dd if=/dev/random bs=1 count=5 2>/dev/null | xxd -ps

# zadani klice
iwconfig eth0 key 967136deac
40b=5B=10 hexaznaku(64,104,128)

V /etc/sysconfig/network-scripts/ vytvorime ifcfg-wlan0 s
DEVICE=wlan0

dhclient wlan0

a nebo na stalo
V /etc/sysconfig/network-scripts/ vytvorime ifcfg-wlan0 s
DEVICE=wlan0
IPADDR=nejaka IP
NETMASK=255.255.255.0
ONBOOT=yes
BOOTPROTO=static(dhcp)
TYPE=Wireless
MODE=Managed
ESSID=homenet
KEY=967136deac(jsem zadat password asi)

Thursday, February 5, 2009

VYPNUTI CAPSLOCK DIK ZA TY DARY

xmodmap -e "remove lock = Caps_Lock"

Monday, February 2, 2009

Gentoo Experiment

Ukol:
Naistalovat Linux z jineho linuxu a spustit ho pomoci kvm.

Kroky:
  1. Vytvorit obraz
  2. Naformatovat obraz na dve casti (/,tmp)
  3. Nainstalovat system
  4. Spustit

Ad 1.

Vytvoreni 4GB obrazu.
dd if=/dev/zero of=/home/slune/Image/gentoo.img bs=1M count=4096 .

Ad 2.

Nejjednodussi zpusob je pouzit mkfs.ext3 /home/slune/Images/gentoo.img.
Tim sice vznikne pripojitelny a zapisovatelny obraz, ale pro fdisk naprosto nepozitelny (vyzaduje block device).
Zpusob jako toto obejit vede zrejme losetup /dev/loop1 /home/slune/Images/gentoo.img a fdisk /dev/loop1. Navody zde a zde.
Po vytvoreni struktury fdiskem zkoukneme jak nam to vypada

fdisk -ul /dev/loop1

Disk /dev/loop1: 4294 MB, 4294967296 bytes
255 heads, 63 sectors/track, 522 cylinders, total 8388608 sectors
Units = sectors of 1 * 512 = 512 bytes
Disk identifier: 0x2cdb556f

Device Boot Start End Blocks Id System
/dev/loop1p1 * 63 6313544 3156741 83 Linux
/dev/loop1p2 6313545 8385929 1036192+ 83 Linux

Aby jsme mohli disky naformatovat musime je nejdriv pripojit.
(63*512)=32256
(6313545*512)=
3232535040

Pripojime vytvorene disky
losetup -o 32256 /dev/loop2 /dev/loop1
losetup -o 3232535040 /dev/loop3 /dev/loop1

Pozn:
Prvni disk se ale pripoji s velikosti celeho obrazu. Zrejme je potreba urcit i horni velikost.
Nejak takhle
losetup -o 32256 --sizelimit 3232502272 /dev/loop1 /dev/loop0. Pokud jsem to neudelal
mkfs mi pak "spatne" naformatoval system (nastavil spatnou velikost disku).


Naformatujeme disky
mkfs.ext3 /dev/loop2
mkswap /dev/loop3

Pozn:
Gentoo potrebuje pro instalaci velke mnozstvi inodu (vice nez 200 000) pro instalaci na mensi
disky je potreba
mkfs.ext3 -N (velke cislo) /dev/loop2.

Pozn:
Je potreba stahnout portage a satge3 viz. link a rozbalit je.
Portage se musi rozbalit do adresare usr.
(Neco takoveho
tar xvjf /mnt/gentoo/portage-latest.tar.bz2 -C /mnt/gentoo/usr)

Dalsi krok je pripojeni systemovych adresaru
mount -t proc none /mnt/gentoo/proc/
mount -o bind /dev /mnt/gentoo/dev/

Tady bych to chtel vic prozkoumat

Chroot do noveho prostredi
chroot /mnt/gentoo /bin/bash
env-update
source /etc/profile
# zmena promptu
export PS1="(chroot) $PS1"


Tady bych to chtel taky vic prozkouma

dalsi kroky jsou popsany v gentoo wiki.

Pokracovani stahneme si nejaky kernel(treba vanilla) rozbalime do
/usr/src/.
Udalame link ln -s /usr/src/neco /usr/src/linux (nebo jsme liny a emergneme celou tu potvoru
emerge vanilla-sources).

A ted troska srandy
cd /usr/src/linux

make menuconfig

Zkusime nastavit vse co je potreba coz se nemuze nikdy na poprve povest.

Instalace zprasenho kernelu
make && make modules_install

Poznamka pokud kompilujeme x86 na x64 pak je treba make ARCH=i386

Tento postup opakujem tak dlouho dokud nam nenabehne system (dost dlouho)

Insalace grubu

Grub potrebuje k zivotu nekolik souboru.
  1. stage1
  2. stage2
  3. grub.conf
  4. bzImage kernelu

Stage1 a Stage2 jsou umisteny ve Fedore tady /usr/share/grub/ a nakopirujeme je do /boot/grub/

grub.conf muze vypadat treba takto

default 0
timeout 30
title Gentoo
root (hd0,0)
kernel /boot/kernel root=/dev/sda1

bzImage kernelu je v /usr/src/linux/arch/i386/boot. Nakopirujeme ho do /boot/
a prejmenujeme dle libosti treba na kernel.
Instalace Grubu
Momentalne se grub nechce nechat primo naistalovat na loop device. Musime mu tedy trosku pomoci.

grub --device-map=/dev/null


device (hd0) /cesta/k/obrazu
root (hd0,0)
setup (hd0)

A je to hotove ted uz jenom qemu-kvm -m 1024 /home/slune/Images/gentoo.img.