顯示具有 rhel 標籤的文章。 顯示所有文章
顯示具有 rhel 標籤的文章。 顯示所有文章

2013年6月4日 星期二

foremost recovery deleted cpp source code

1. download
   http://apt.sw.be/redhat/el6/en/x86_64/rpmforge/RPMS/foremost-1.5.7-1.el6.rf.x86_64.rpm

2. install
    rpm -ivh foremost-1.5.7-1.el6.rf.x86_64.rpm

3. make sure the location of your deleted files
    /home/user/<path-to-deleted-file>

[root@master01 ~]# df
Àɮרt²Î               1K-°Ï¬q      ¤w¥Î     ¥i¥Î ¤w¥Î% ±¾¸üÂI
/dev/sda2             20642428   2524600  17069252  13% /
tmpfs                  1027468         0   1027468   0% /dev/shm
/dev/sda1               198337     27712    160385  15% /boot
/dev/sda3            181515576    191876 172103248   1% /opt/kccs1
nfssvr:/home/nfs      20642432   2055808  17538048  11% /mnt/nfssvr
 
   /home/user/<path-to-deleted-file> belongs to /dev/sda2

4. recoverying the deleted files
   cd /home/user
   mkdir output
   foremost -vqQ -o output -t cpp -i /dev/sda2

5. lookup results
    ls -l /home/user/output


reference: http://www.unixmen.com/recover-deleted-files-with-foremost/
               http://maitnoobsatwork.blogspot.tw/2012/04/recover-lost-data-using-foremost.html

2013年1月29日 星期二

LVM resize


shell> df
   :

/dev/mapper/VolGroup-lv_home           3783762960     200968     3591357808  1%  /home
   :


shell> umount /home

shell> resize2fs /dev/VolGroup/lv_home 1024G
Please run 'e2fsck -f /dev/VolGroup/lv_home' first

shell> e2fsck -f /dev/VolGroup/lv_home


shell> resize2fs /dev/VolGroup/lv_home 1024G

shell> lvreduce -L 1024G  /dev/VolGroup/lv_home

shell> mount /home

shell> df
   :

/dev/mapper/VolGroup-lv_home           1056894132     204056     1003002988  1%  /home

packagekitd locked



今天在系統發現 packagekitd CPU拉高, 連同yum 以及system-> administrator -> software update都無法正常執行,
查了一些資料, 發現這是系統自我檢查軟體更新, 到一半時當掉所造成
當下解決方法 kill pid or kill -9 pid
取消自我檢查軟體更新 system -> preferences -> software updates , 把Check for updates 改成never

reference: http://itgroup.blueshop.com.tw/towns/hc?n=wodvew&i=405

2012年8月4日 星期六

yum download cache & yum.conf

Sometimes, we always want to keep what you just download the packages (.rpm) via yum install ... command. Once you cloud change working directory to /var/cache/yum/.../... , and then all packages had gone after yum was completed.
/etc/yum.conf allow you to keep the cached packages and other parameter for more functions.

cachedir=/var/cache/yum    #cached packages destination
keepcache=0                #1 for keeping packages, 0 will remove the package after installed
metadata_expire=1800   # in seconds

Otherwise, you could man yum.conf for more information .

2012年7月27日 星期五

fwrite 2GB file size limitation in Linux

Today our system popped a error message , about file size exceed limitation, and something wrong with login process. I just think about some software could store their data/logs over 2GB. Then "google" tell me why !!

[Question]

#include

int main(void) {
    char c[] = "abcdefghij";
    size_t rez;
    FILE *f = fopen("filldisk.dat", "wb");
    while (1) {
        rez = fwrite(c, 1, sizeof(c), f);
        if (!rez) break;
    }
    fclose(f);
    return 0;
}

When I run the program (in Linux), it stops when the file reaches 2GB

[Answers]

This is due to the libc (the standard C library), which by default on a x86 (IA-32) Linux system is 32-bit functions provided by glibc (GNU's C Library). So by default the file stream size is based upon 32-bits -- 2^(32-1).


[Solutions]
#define _FILE_OFFSET_BITS 64

#include
int main(void) {
    char c[] = "abcdefghij";
    size_t rez;
    FILE *f = fopen("filldisk.dat", "wb");
    while (1) {
        rez = fwrite(c, 1, sizeof(c), f);
        if ( rez < sizeof(c) ) {
            break;
        }
    }
    fclose(f);
    return 0;
}

Note: Most systems expect fopen (and off_t) to be based on 2^31 file size limit. Replacing them with off64_t and fopen64 makes this explicit, and depending on usage might be best way to go.


reference: http://stackoverflow.com/questions/730709/2gb-limit-on-file-size-when-using-fwrite-in-c
      http://www.suse.de/~aj/linux_lfs.html

2012年7月13日 星期五

mount cd-rom or iso-files

in Linux:
mount -t iso9660 -o loop [path to iso file] [dest path]
cdrom device : /dev/sr0

in Mac:

sudo mount_cd9660 [path to iso file] [dest path]

sudo mount -t hfs -o nodev,nosuid,ro [path to cd-rom device] [dest path]

cdrom device maybe linked to /dev/disk1s0s2 (@virtual machine)

2012年7月11日 星期三

mkisofs

一般我們在維護系統時, 總會經常使用iso檔來存取, 尤其當要掛載虛擬光碟或虛擬機使用
windows上我們常有用酒精或其他工具來產生iso檔,
那在linux上呢?

mkisofs便可以自定義想要產生的iso檔內容
mkisofs -o doc.iso ~/doc
如此便可以將你家目錄下的doc目錄內資料, 全部收錄到doc.iso的鏡像檔裡

那如果我要複雜一點呢
mkisofs -A "CENTOS6_BOOT" -V "CENTOS6_BOOT" -J -R -v -T -o centos6_boot.iso -b isolinux.bin -c boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table isolinux

這個是產生一個可以開機的iso檔,
注意: 在建立時,
    (1)目錄裡的TRANS.TBL若在錄製時有錯誤,請將他移除(上例中的isolinux/TRANS.TBL)
    (2)-b以及-c指定從錄製目標(dest)起算的檔案及路徑, 決定方法如下:
        假設你想要在 /var/ftp下(執行指令的位置),
        去錄製/var/ftp/pub成為centos.iso(實際燒錄資料,dest),
        isolinux的位置在 /var/ftp/pub/isolinux
        指令的內容應該
        [root@local /var/ftp ]# mkisofs .... -b isolinux/isolinux.bin -c isolinux/boot.cat .... /var/ftp/pub

以下舉例, 把原始的光碟, 不透過dd的指令, 而採用mkisofs來建立iso檔(此法可以用來建立自定義的安裝光碟, 光碟片一放進去便可自動安裝的方法快速部署光碟片, 當然在區域網路透過PXE - kickstart是較快的)
(1)假設CentOS整片光碟資料已在~/centos/目錄下(不管是mount光碟或備份一份)
(2)isolinux在~/centos/isolinux/下
(3)依照你想要的部分, 修改kickstart檔, 或者開機相關參數(這部分有機會我再PO文)
(4)如下建立centos.iso安裝鏡像檔(此時或許可以不用修改TRANS.TBL檔)
[root@local ~ ]mkisofs -A "CENTOS_DVD" -V "CENTOS_DVD" -J -R -v -T -o centos.iso -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table centos
    藍字粗體centos為要錄製的目標目錄

2011年2月7日 星期一

linux iso files

dd 是可以用來製作可燒錄的CD/DVD映像檔(ISO)!


用版大的例子(適用於僅含資料的光碟):

#dd if=/dev/cdrom of=file.iso
或
#cat /dev/cdrom > ~/file.iso

file.iso可以用cdrecord, k3b, 或是nero直接燒錄,


如果是音樂CD,就不能用上述的dd指令了!你得把每一軌(或每首歌)分開來拷貝而且要指定bs和count,有點複雜。用cdparanoia或是X-CdRoast還來的方便些!

----------------------------

可以用isoinfo來查詢CD上得iso資訊,例如:

> isoinfo -d -i /dev/cdrom

CD-ROM is in ISO 9660 format
System id: LINUX
Volume id: FC/3 x86_64
Volume set id:
Publisher id:
Data preparer id:
Application id: FC/3 x86_64
Copyright File id:
Abstract File id:
Bibliographic File id:
Volume set size is: 1
Volume set sequence number is: 1
Logical block size is: 2048
Volume size is: 326239
El Torito VD version 1 found, boot catalog is in sector 123
Joliet with UCS level 3 found
Rock Ridge signatures version 1 found
Eltorito validation header:
Hid 1
Arch 0 (x86)
ID ''
Key 55 AA
Eltorito defaultboot header:
Bootid 88 (bootable)
Boot media 0 (No Emulation Boot)
Load segment 0
Sys type 0
Nsect 4
Bootoff 7C 124

然後block size (bs) 和 volume size (count) 可以用來正確的,製作iso:

* 計算CD的check sum:

dd if=/dev/cdrom bs=2048 count=326239 conv=notrunc,noerror | md5sum

(Linux kernel 2.6: /media/cdrecorder)

* 製作 iso image:

dd if=/dev/cdrom bs=2048 count=326239 conv=notrunc,noerror > file-name.iso

-------------------

至於DVD,如果是DVD-5(單層片)或是DVD+/-R的資料片,可以用和CD同樣的方法來製作iso。雙層DVD-DL的資料片應該也是可以的,但是得用雙層片DVD-DL來燒錄。至於電影的DVD,應該也是可以的(自己沒試過,下面提供的網頁中有詳細的說明)

$ dd if=/dev/dvd of=DVD.iso bs=2048

不過現在的DVD大都是雙層片(DVD-9),你得用雙層片來燒錄。

-----------------------------

這些網頁有一些有關備份CD/DVD更詳細的資料:

http://www.yolinux.com/TUTORIALS/LinuxTutorialCDBurn.html

http://gentoo-wiki.com/HOWTO_Backup_a_DVD

----------------------

另外,Windows上也有 dd可以使用:
http://www.chrysocome.net/dd

Mounting ISO and DD Image Files

Most images downloaded from the Internet will be iso9660, Windows filesystems are normally ntfs, Linux are commonly ext2, and Macintosh are udf or hfs.

As a last resort, you can work your way down the list of filesystem types listed in the mount man pages.

After you know the filesystem type, you are ready to mount.
Note: replace <_type> with the filesystem type.

To mount the file livebootcd.iso with write enabled:

mount -t <_type> -o loop ./livebootcd.iso /mnt

To mount an image made from a Windows partition in read-only mode:

mount -t ntfs -o loop,ro,umask=0222 ./evidence.dd /mnt

2010年6月6日 星期日

rebuild yum server repodata

某些時候想要重建yum server的repository,要保持套件群組的關係,要依照下面作法
[1] server
cp /var/ftp/pub/VT/repodata/comps-rhel5-vt.xml /tmp/comps-rhel5-vt.xml
rm -rf /var/ftp/pub/VT/repodata/
rm -rf /var/ftp/pub/VT/.olddata
createrepo -g /tmp/comps-rhel5-vt.xml /var/ftp/pub/VT

備註:
如果沒有照上述重建,xml檔仍會產生出來,yum install也沒問題,但在GUI進行套件工具時
群組的關係會全部跑掉


[2] client
yum clean
server重建後,cleint應該要重新跟server取得xml的內容,所以要clean

2010年6月2日 星期三

initsript


在某些原因下,有些自己寫的程式不想放在/etc/init.d下當一個 service來啟動
而是放在/etc/inittab中來啟動
但此時如果要對這個daemon程式進行系統調整時,會有困難
例如ulimit的控制項
因為一般我們指令在執行ulimit都是當下狀況,在bash下產生的效果
而要讓這個ulimit發生效果之前,其實透過/etc/inittab啟動的程式,早就起來了
也就是先後順序的問題
所以應該要找到一個比/etc/inittab啟動前更早的東西來執行
原本是想,把這個daemon用一個scripts包起來
而這個daemon執行之前,先執行ulimit -n 8192(例如要把openfiles上限開到8192)
結果.....殘念,不知為何不能生效

後來才發現有一個叫 initscript的東西,可以man initscript來看看
也新增一個/etc/initscript來讓init在執行/etc/inittab前先執行/etc/initscript
這樣就能有效讓ulimit生效了
預設沒有/etc/initscript這個檔案,可以man initscript的內容,拿來新增這個檔案
#man initscript
:
:
#
# initscript Executed by init(8) for every program it
# wants to spawn like this:
#
# /bin/sh /etc/initscript
#

# Set umask to safe level, and enable core dumps.
umask 022
ulimit -c 2097151
PATH=/bin:/sbin:/usr/bin:/usr/sbin
export PATH

# Increase the hard filedescriptor limit for all processes
# to 8192. The soft limit is still 1024, but any unpriviliged
# process can increase it’s soft limit up to the hardlimit
# with "ulimit -Sn xxx" (needs a 2.2.13 or later Linux kernel).
ulimit -Hn 8192

# Execute the program.
eval exec "$4"
先把他存到/etc/initscript
然後,修改ulimit -Hn 8192成為ulimit -n 8192即可
eval exec "$4"這行不可以漏掉,否則/etc/inittab會沒執行到
#ls -l /etc/initscript
-rw-r--r-- 1 root root 581 6¤ë 17 2009 /etc/initscript

2010年5月26日 星期三

因為windows安裝使得 RHEL的grub設定失效

經常有一個經驗是當我安裝好Linux(RHEL)後
想在同一台機器再安裝另外一個OS(Windows)
結果裝好時,開機選單卻沒有Linux
原因很簡單,當然是開機選單不再走MBR了
所以這時候,在MBR還存在下
1.用linux rescue mode進入後,讓file system自動mount在/mnt/sysimage
2.chroot /mnt/sysimage,可以發現硬碟裡的linux資料都出現且位置都對
先別高興,這只是chroot後的假象
3.grub-install --recheck /dev/sda ,這裡/dev/sda是/boot所在的 partition磁碟代號
這個動作很掃很久,耐心等完後就完成啦

如果MBR不小心清掉了,例如
dd if=/dev/zeor of=/dev/sda bs=512 count=1
那就只能grub再灌一次了
shell> grub 用root進grub
grub> find /boot/grub/stage1
(hd0,0)
grub>root {hd0,0)
grub>setup (hd0)
grub>quit
如此再寫入MBR後再試看看開機狀況

2010年5月7日 星期五

linux block device uuid and major-minor number


1. uuid

1) vol_id
# sudo vol_id /dev/sda1

2) ls
# ls -l /dev/disk/by-uuid/

3) blkid
# blkid /dev/sda1

software raid
#mdadm -d /dev/md0

refer to: http://www.cyberciti.biz/faq/linux-finding-using-uuids-to-update-fstab/

2.major-minor number
1)
# cat /proc/partitions
major minor #blocks name

8 0 286513152 sda
8 1 104391 sda1
8 2 286390755 sda2
8 16 488243200 sdb
8 17 488239416 sdb1
8 32 976588800 sdc
8 33 976583286 sdc1
253 0 284327936 dm-0
253 1 2031616 dm-1

2)
# cat /sys/block/sda/sda1/dev
8:1
# cat /sys/block/sda/sda2/dev
8:2

2010年3月7日 星期日

Error Downloading Kickstart File

今天用RHEL 5.1在實作LAB時,一開始就很不順了
每次都停在"Error Downloading Kickstart File"
試了幾下,怪事就來了, 除了我的新pc以外,其他nb用Kickstart安裝就沒事
想了又想,最後在Kickstart一開始安裝時,按Alt-Ctrl-F3觀察到,
原來這個版本Kickstart不支援RTL8111/8168系列的晶片,
想說那剛好多了一張DEF-530,就把他換上去,一樣抓不到
巧合的就這樣發生

後來換了1張RHEL5.4開機片,來抓rhel 5.1的Kickstart File就過了
可是Kickstart過了,只是開始,裝完os後,換 kernel預設沒這個driver
糟,最不想的就是這個.
硬著頭皮,找谷哥商量,今天谷哥心情好,給小弟一點面子
還是讓我找到了RTL8168的tarball版driver

tar jxvf r8168-8.005.00.tar.bz2
cd r8168-8.005.00
make clean modules
make install
depmod -a
insmod ./src/r8168.ko (若是kernel-2.4.x 則為 insmod ./src/r8168.o )
( 可用 uname-r 查知kernel版本 )
再看看驅動程式是否已掛載進來?
lsmod grep r8168


service network restart就一切ok了
ps.網路上找到的kickstart error都集中在討論PXE+Kickstart的安裝下,
設定異常所導致的比較多,這次2個lan driver都不支援的算少數機率吧

文章分類