2009年10月22日 星期四

Find out All Online Hosts on the Same LAN on Linux

1. ping allow pinging a broadcast address

ping -b 192.168.0.255

but windows host does not reply broadcast ping

2. use network mapper, nmap

nmap -sP 192.168.0.0/24

-sP: ping scan

3. if a host be set to discard ping request, try to use arping with loop

2009年8月16日 星期日

Convert Video on Linux for Nokia N97

you can save different configurations as profiles for mencoder use.

1. create configuration file ~/.mplayer/mencoder.conf if there is not.
if in windows, the file should be put in the same folder with config and input.conf

2. edit mencoder.conf

[n97]
profile-desc="MPEG4/AAC"
vf=scale=640:-3,harddup
ovc=lavc=yes
oac=lavc=yes
lavcopts=aglobal=1:vglobal=1:acodec=libfaac:vcodec=mpeg4:abitrate=96:vbitrate=896
af=lavcresample=44100
ofps=25
of=lavf=yes
lavfopts=format=mp4

[profile2]
..
..

the quality of video from the above setting is good enough. but you still can adjust them in the suitable range
abitrate: 96 ~ 192
vbitrate: 896 ~ 4000

3. specify which profile to use

mencoder -profile n97 -o output.mp4 input_file

2009年8月12日 星期三

Change the Default Sound Card on Arch Linux

i found the sound module of my tv card was the default sound device because i tried to run amixer and got no master or pcm controls.

1. discover your sound card model name with lspci and your ALSA driver module names with ls

$ ls -l /sys/module/snd/holders
total 0
lrwxrwxrwx 1 root root 0 2009-08-13 09:21 saa7134_alsa -> ../../saa7134_alsa
lrwxrwxrwx 1 root root 0 2009-08-13 09:21 snd_hda_codec -> ../../snd_hda_codec
lrwxrwxrwx 1 root root 0 2009-08-13 09:21 snd_hda_codec_realtek -> ../../snd_hda_codec_realtek
lrwxrwxrwx 1 root root 0 2009-08-13 09:21 snd_hda_intel -> ../../snd_hda_intel
lrwxrwxrwx 1 root root 0 2009-08-13 09:21 snd_hwdep -> ../../snd_hwdep
lrwxrwxrwx 1 root root 0 2009-08-13 09:21 snd_mixer_oss -> ../../snd_mixer_oss
lrwxrwxrwx 1 root root 0 2009-08-13 09:21 snd_pcm -> ../../snd_pcm
lrwxrwxrwx 1 root root 0 2009-08-13 09:21 snd_pcm_oss -> ../../snd_pcm_oss
lrwxrwxrwx 1 root root 0 2009-08-13 09:21 snd_rawmidi -> ../../snd_rawmidi
lrwxrwxrwx 1 root root 0 2009-08-13 09:21 snd_seq -> ../../snd_seq
lrwxrwxrwx 1 root root 0 2009-08-13 09:21 snd_seq_device -> ../../snd_seq_device
lrwxrwxrwx 1 root root 0 2009-08-13 09:21 snd_seq_oss -> ../../snd_seq_oss
lrwxrwxrwx 1 root root 0 2009-08-13 09:21 snd_timer -> ../../snd_timer
lrwxrwxrwx 1 root root 0 2009-08-13 09:21 snd_usb_audio -> ../../snd_usb_audio

2. add order setting for the module of main soundcard to modprobe.conf

vi /etc/modprobe.d/modprobe.conf
--

options snd_hda_intel index=0

3. make your user be able to use the sound card

gpasswd -a username audio

3. reboot then make sure the sound modules have been loaded

lsmod | grep ^snd_

4. the current version of alsa installs with all channels muted by default. use alsamixer to unmute the channels and adjust volume manually

5. run alsactl once to create /etc/asound.state

alsactl store
# restore
# alsactl restore

6. add alsa to daemons in rc.conf to store the mixer settings on every shutdown and restore them when you boot.

2009年8月5日 星期三

Mount Windows Partition with Correct Character Setting on Linux


mount -t cifs -o iocharset=utf8,username="username",password="password" //ip/share /mountpoint

2009年8月3日 星期一

New Method of GRUB4DOS to Create a Bootable USB Stick

1. download grub4dos from http://download.gna.org/grub4dos/ and fbinst from
http://download.gna.org/grubutil/

2. if you are using vista, remember to run cmd as administrator

3. display help message

fbinst.exe -h

4. get the device number of usb storage

fbinst.exe -l

5. format the device

fbinst.exe (hd1) format --force --extended 4M

it will create mbr with 8mb primary(default) and 4mb extended area of hidden space, and a normal fat partition
you can format as usb-zip instead by --zip
because mbr and partition have been changed, unplug and plug the device for the following steps

6. extract grldr from grub4dos then copy it to device

fbinst.exe (hd1) add grldr c:\grldr

7. extract ldlinux.bin from http://www.kernel.org/pub/linux/utils/boot/syslinux/ then copy it to device with the parameter, --syslinux because syslinux must be put in extended data area

fbinst.exe (hd1) add --syslinux ldlinux.bin c:\ldlinux.bin

8. copy ntldr, NT boot loader to device

fbinst.exe (hd1) add ntldr c:\ntldr

9. create a text file named fb.txt

default 0
timeout 5
text "F1: GRUB"
menu F1 grldr grldr
text "F2: SYSLINUX"
menu F2 syslinux ldlinux.bin
text "F3: NTLDR"
menu F3 grldr ntldr

10. put it into your device as menu

fbinst (hd1) add-menu fb.cfg c:\fb.txt

11. you can show disk information to check these files

fbinst (hd1) info

2009年6月21日 星期日

Secure your Linux Server

1. disable ssh login as root

vi /etc/ssh/sshd_config
--

..
PermitRootLogin no
..

2. disable root login in phpmyadmin

vi config.inc.php
--

..
$cfg['Servers'][$i]['AllowRoot'] = FALSE;
..

2009年6月15日 星期一

MySQL Backup and Recovery with Command-Line

the mysqldump client is a backup program which can be used to dump a database or a collection of databases for backup or transfer to another sql server. the dump typically contains sql statements to create the table, populate it, or both.

backup an entire database

mysqldump -u username -p db_name > backup.sql

-p, --password
-u, --user=username

backup a table

mysqldump db_name table > backup.sql

dump several databases with one command

mysqldump --databse db_name1 db_name2 .. > databases.sql

dump all databases

mysqldump --all-databases > all_databases.sql



you need to create the databases manually if your target mysql server has no database with same name before recovery

mysql> create database db_name;

restore

mysql -u username -p < backup.sql