星期四, 5月 28, 2009

VMWare ESXi 4 小記

MWare ESXi 裝機log
  • 安裝 VMWare ESXi 4 for x86_64 完成

    HP dc5850

    AMD Athlon Dual Core 5200B

    IP: 147.1.1.217/16

    Gateway: 147.1.1.253

    最低硬體需求 記憶體 2GM(不包含顯示)

    BIOS SATA 設定

    使用 Native IDE Mode 才成功

    原本使用 Lengacy IDE Mode 會失敗

星期二, 5月 26, 2009

C語言入門 20090526 上課小記

************************20090526 陳惠堂 **************************

while(
條件)
{
敘述
}


for
很適合來做固定迴圈
while
比較適合做不固定或是無限迴圈(只知道結束條件, 不知道會跑幾圈)


Lab:

// include 引入 .h (標頭檔)
// header .h
要放在程式的最前面
//
引入 stdio.h stdlib.h
#include "stdio.h"
#include "stdlib.h"

#include "conio.h"

//進入主程式
int main()
{



char ch;

ch = getche();

// for(;ch!='\r';)
使用 for 的方式
//
當輸入字元不是 Enter \r Enter

while(ch != '\r')

{
ch=getche();
}

system("pause"); //執行系統內的 pause指令 暫停 宣告被寫在 stdlib.h
return 0;
}




Lab:

// include 引入 .h (標頭檔)
// header .h
要放在程式的最前面
//
引入 stdio.h stdlib.h
#include "stdio.h"
#include "stdlib.h"

#include "conio.h"

//進入主程式
int main()
{



// 宣告 字元 char
char ch;

printf("Enter your Password:");
//
當輸入的字元不等於 Enter 13 Enter 的內碼
while( (ch=getch()) != 13 )
//
列印出 * 字元
printf("*");

system("pause"); //執行系統內的 pause指令 暫停 宣告被寫在 stdlib.h
return 0;
}



Lab:
統計 點數

// include 引入 .h (標頭檔)
// header .h
要放在程式的最前面
//
引入 stdio.h stdlib.h
#include "stdio.h"
#include "stdlib.h"

#include "time.h"

//進入主程式
int main()
{



int r,s=0;
// Start Rand
亂數起始值 使用time(0) 去抓現在的時間
srand(time(0));

//
將亂數 除以6 求餘數 +1 , 因為除以6 會餘 0,1,2,3,4,5
for(int i=0;i<4;i++) r =" rand()%6+1;">//rand
的起始點都是固定
printf("%d\t",r);
}

printf("Sum=%d\n",s);

system("pause"); //執行系統內的 pause指令 暫停 宣告被寫在 stdlib.h
return 0;
}



Lab:
統計 點數, 14 點就停下來

// include 引入 .h (標頭檔)
// header .h
要放在程式的最前面
//
引入 stdio.h stdlib.h
#include "stdio.h"
#include "stdlib.h"

#include "time.h"

//進入主程式
int main()
{



//設定起始值 s=0
int r,s=0;
// Start Rand
亂數起始值 使用time(0) 去抓現在的時間
srand(time(0));

//
s 不等於 14 繼續執行
while(s != 14)
{
//
先訂定 s 起始值為0 注意這個是在 while 迴圈內
s=0;
//
將亂數 除以6 求餘數 +1 , 因為除以6 會餘 0,1,2,3,4,5
for(int i=0;i<4;i++) r =" rand()%6+1;"> // s = s + r
s += r;
//rand
的起始點都是固定
printf("%d\t",r);

}
//
列出 點數加總
printf(
"sum=%d\n",s);
}





system("pause"); //執行系統內的 pause指令 暫停 宣告被寫在 stdlib.h
return 0;
}



*do while
注意 while 後面要加上 ;
語法
do;
{
敘述
}while(
條件);



Lab:
使用 do while 的方式

// include 引入 .h (標頭檔)
// header .h
要放在程式的最前面
//
引入 stdio.h stdlib.h
#include "stdio.h"
#include "stdlib.h"

//進入主程式
int main()
{



//設定起始值 s=0
int r,s=0;
// Start Rand
亂數起始值 使用time(0) 去抓現在的時間
srand(time(0));


//
使用 do while 的方式, 先執行敘述 再判斷
do
{ //
先訂定 s 起始值為0 注意這個是在 while 迴圈內
s=0;
//
將亂數 除以6 求餘+1 , 因為除以6 會餘 0,1,2,3,4,5
for(int i=0;i<4;i++)
{
r = rand()%6+1;
// s = s + r
s += r;
//rand
的起始點都是固定
printf("%d\t",r);

}
//
列出 點數加總
printf("sum=%d\n",s);
//
s 不等於 14 繼續執行, 注意 do while 後面的 while要加上 ;
}while(s != 14);

system("pause"); //執行系統內的 pause指令 暫停 宣告被寫在 stdlib.h
return 0;
}




Lab:
使用 do while 的方式

// include 引入 .h (標頭檔)
// header .h
要放在程式的最前面
//
引入 stdio.h stdlib.h
#include "stdio.h"
#include "stdlib.h"

//進入主程式
int main()
{



//設定起始值 s=0 t=0 來算次數
int r,s=0,t=0;
// Start Rand
亂數起始值 使用time(0) 去抓現在的時間
srand(time(0));


//
使用 do while 的方式, 先執行敘述 再判斷
do
{ //
先訂定 s 起始值為0 注意這個是在 while 迴圈內
s=0;
//
將亂數 除以6 求餘+1 , 因為除以6 會餘 0,1,2,3,4,5
for(int i=0;i<4;i++)
{
r = rand()%6+1;
// s = s + r
s += r;
//rand
的起始點都是固定
printf("%d\t",r);

}
//
列出 點數加總
printf("sum=%d\n",s);


//
每執行一次 t + 1
t++;

//
s 不等於 14 繼續執行
}while(s != 14);

//
列出執行的次數
printf("Play Time counts: %d\n",t);

system("pause"); //執行系統內的 pause指令 暫停 宣告被寫在 stdlib.h
return 0;
}




Lab:

// include 引入 .h (標頭檔)
// header .h
要放在程式的最前面
//
引入 stdio.h stdlib.h
#include "stdio.h"
#include "stdlib.h"

//進入主程式
int main()
{



//定義一個 for 迴圈 i 要小於 3 才執行
for(int i=0; i<3;i++)
{
//
執行另一個 子迴圈 for , j 要小於 5 才執行
for(int j=0; j<5;j++)

//
列印出 i 還有 j 的值
printf("i=%d,j=%d\n",i,j);
printf("\n");
}

system("pause"); //執行系統內的 pause指令 暫停 宣告被寫在 stdlib.h
return 0;
}


*IF
語法
if(
條件)
{
敘述
}
else
{
敘述
}



Lab: if

// include 引入 .h (標頭檔)
// header .h
要放在程式的最前面
//
引入 stdio.h stdlib.h
#include "stdio.h"
#include "stdlib.h"

//進入主程式
int main()
{



//定義一個整數
int n;

printf("Enter Number:");

//
等使用者輸入 輸入為 n 的值
scanf("%d",&n);

//
抓餘數 是否為0 因為 偶數可以被 2 整除
if(n%2 == 0)

//
可以被整除 列印出 Even 偶數
printf("Even\n");

//
如果 餘數不等於 0
else
//
列印出 Odd 奇數
printf("Odd");

system("pause"); //執行系統內的 pause指令 暫停 宣告被寫在 stdlib.h
return 0;
}



Lab:
四個一樣才停止

// include 引入 .h (標頭檔)
// header .h
要放在程式的最前面
//
引入 stdio.h stdlib.h
#include "stdio.h"
#include "stdlib.h"

//進入主程式
int main()
{



//設定起始值 s=0 t=0 來算次數
int r,s=0,t=0,p=0;
// Start Rand
亂數起始值 使用time(0) 去抓現在的時間
srand(time(0));


//
使用 do while 的方式, 先執行敘述 再判斷
do
{ //
先訂定 s 起始值為0 注意這個是在 while 迴圈內
s=0;
//
將亂數 除以6 求餘+1 , 因為除以6 會餘 0,1,2,3,4,5
for(int i=0;i<4;i++)
{
r = rand()%6+1;

//
針對第一次執行
if(i == 0)
{
//p
等於丟出來的點數
p=r;
printf("p=%d\n",p);
}
//
如果 r 等於 p (因為第2r會再產生), 次數 再加 1
if(r == p)
s++;
//rand
的起始點都是固定
printf("%d\t",r);

}

printf("\n",s);
//
每執行一次 t + 1
t++;

//
s 不等於 4 繼續執行, 也就是沒有四顆一樣
}while(s != 4);

//
列出執行的次數
printf("Play Time counts: %d\n",t);

system("pause"); //執行系統內的 pause指令 暫停 宣告被寫在 stdlib.h
return 0;
}



*
巢狀 IF
語法
if(
條件1)
{
敘述1
}
else if(
條件2)
{
敘述2
}
else if(
條件n)
{
敘述n
}
else
敘述


Lab: BMI
計算 + IF

// include 引入 .h (標頭檔)
// header .h
要放在程式的最前面
//
引入 stdio.h stdlib.h
#include "stdio.h"
#include "stdlib.h"
#include "math.h"

//進入主程式
int main()
{



float w,h,bmi;

printf("Please input your Height(cm)\n");
//
利用scan 定義 h 記得要使用位置 所以前面要加上 & 符號
scanf("%f",&h);

printf("Please input your Weight(KG)\n");

//
利用scan 定義 w 記得要使用位置 所以前面要加上 & 符號
scanf("%f",&w);

//
計算 BMI pow(, 次方)
//BMI
為 體重/身高的2次方
//pow
必須 #include "math.h"
bmi = w/pow(h/100,2);

//
列印出BMI 值取到 小數點2
printf("Your BMI is: %.2f\n",bmi);



//利用巢狀 IF 來告知 體重BMI狀況
if(bmi <>
printf("
您的體重為 過輕\n");
else if(bmi <>
printf("
您的體重為 標準\n");
else if(bmi <>
printf("
您的體重為 過重\n");
else if(bmi <>
printf("
您的體重為 輕度肥胖\n");
else if(bmi <>
printf("
您的體重為 中度肥胖\n");
else
printf("
您的體重為 重度肥胖\n");





system("pause"); //執行系統內的 pause指令 暫停 宣告被寫在 stdlib.h
return 0;
}



***************************************************************


星期日, 5月 24, 2009

[轉貼] Install ESXi 3.5 to an IDE drive

Install ESXi 3.5 to an IDE drive

By default, if the ESXi install can not find a supported device to install to, then the installer will quit with the error message: "Unable to find a supported device to write the VMware ESX Server 3i 3.5.0 image to." If it is the case that the IDE drive in your host is recognized by ESXi, then you will be able to modify the install script TargetFilter.py to recognize your IDE device as a supported install device. You can find the list of devices that ESXi can recognize here.

The install process for this can be found below, and a video of the process can be found at the bottom of this page. This demo was created using a VMware Workstation VM which only had a 4 GB IDE drive.

ESX IDE install error

Install Process

1) If you have encountered the error shown above, you can press ALT-F1 to access the console of the ESXi install. You'll be prompted for a login and you can use 'root'. The password for root with be blank. As mentioned above, this process assumes you have an IDE drive that ESXi can recognize. You can use the command lspci to show the list of devices that ESXi can recognize and then compare that with this list of devices. Also if you run fdisk -l, you should see your IDE drive listed.
2) After you have console access you will enter the command vi /usr/lib/vmware/installer/Core/TargetFilter.py (note that the path and filename are case-sensitive).
3) Scroll down in the document until you find the section "def IDEFilter(lun)". You will be changing the text:

return interface.GetInterfaceType() == ScsiInterface.SCSI_IFACE_TYPE_IDE
to
return interface.GetInterfaceType() == ScsiInterface.SCSI_IFACE_TYPE_ISCSI

If you have not used vi before, move the cursor to the end of "TYPE_IDE" and the press the Insert key. The press backspace to delete IDE and type in ISCSI. Then press the ESC key, type in the command :wq and press Enter to save the file and exit.

4) You will now be back at the console. If you had stopped the installer at the screen show below, you can press ALT-F2 to return to the screen and press Enter to start the install, but it will still generate the error shown in the image above. You will need to press ALT-F1 and then type in install and press enter.
5) When you run the install command, it is important to note that the installer will switch you back to the ALT-F2 (DCUI) screen. Press ALT-F1 to return to the console again. You will see the below screen again with the prompt to press Enter to install. Do so and the install will proceed.

ESXi Install Screen

6) Press F11 on the next screen and you should then see your IDE drive as show below. Press Enter to continue and after a few minutes the install should complete and you will be prompted to reboot.

ESXi IDE instal drive list

7) After the reboot, you will be able to connect with the VI client and see that ESXi has installed to and created a VMFS partition on your IDE drive.

ESXi on IDE drive