In this article i am showing step by step to create a custom site defination with costom master page for MOSS 2007.
1) Copy any of the existing site tepmplate and paste it in SiteTempalte folder of the server computer.
Copy th team site tempale from folder C:\Program Files\Common Files\Microsoft shared\web server extensions\12\TEMPLATE\SiteTemplates and paste it at the same folder level. Rename it to MOSSSITE. So its full path will be now C:\Program Files\Common Files\Microsoft shared\web server extensions\12\TEMPLATE\SiteTemplates\MOSSSITE.
2) Now copy the custom master page which you have mosssite.master to the newly created site definations root folder. i.e. to C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\SiteTemplates\MOSSSITE
3) In the C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\SiteTemplates\MOSSSITE folder for both default.aspx and defaultdws.aspx file change the master page to a new master page i.e custom.master like below

Note : This not the master page.We are going to configure Share point to do a string replacement of this custom.master with mosssite.master in later steps.
4) Modify the onet.xml file
This is the file that tells share point how to create the site defination.We are going to do specify all the required modification here.
a)Open the onet.xml file from the path C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\SiteTemplates\MOSSSITE\xml and remove the unwanted code-snippets
i) Identify the Configurations XML node and remove the entire nodes corresponding to
ID = 1 - Representing Blank
ID = 2 - Representing DWS
ii) Scrowl down to Modules xml node and remove 2 modules namely DefaultBlank and DWS
b) Now add the following code snippets
i) Identify the configuration element with id=0 and add the following attributes

ii) Locate the module child element within the configuration element and add the following Module element

iii) Locate the module child element ouside the configuration element and add the following module and file elements

1) Copy any of the existing site tepmplate and paste it in SiteTempalte folder of the server computer.
Copy th team site tempale from folder C:\Program Files\Common Files\Microsoft shared\web server extensions\12\TEMPLATE\SiteTemplates and paste it at the same folder level. Rename it to MOSSSITE. So its full path will be now C:\Program Files\Common Files\Microsoft shared\web server extensions\12\TEMPLATE\SiteTemplates\MOSSSITE.
2) Now copy the custom master page which you have mosssite.master to the newly created site definations root folder. i.e. to C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\SiteTemplates\MOSSSITE
3) In the C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\SiteTemplates\MOSSSITE folder for both default.aspx and defaultdws.aspx file change the master page to a new master page i.e custom.master like below
Note : This not the master page.We are going to configure Share point to do a string replacement of this custom.master with mosssite.master in later steps.
4) Modify the onet.xml file
This is the file that tells share point how to create the site defination.We are going to do specify all the required modification here.
a)Open the onet.xml file from the path C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\SiteTemplates\MOSSSITE\xml and remove the unwanted code-snippets
i) Identify the Configurations XML node and remove the entire nodes corresponding to
ID = 1 - Representing Blank
ID = 2 - Representing DWS
ii) Scrowl down to Modules xml node and remove 2 modules namely DefaultBlank and DWS
b) Now add the following code snippets
i) Identify the configuration element with id=0 and add the following attributes
ii) Locate the module child element within the configuration element and add the following Module element
iii) Locate the module child element ouside the configuration element and add the following module and file elements
Save all these changes of onet.xml file.
5) So far, we have successfully created a site definition. All we have to do now is to register this definition to the site definition list. To do this, create "WEBTEMPMOSSSITE.XML" file in "C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\1033\XML" folder.
6) Write the following code in this file and Save the file.

7)To make sure that our new Site Definition has all the right pieces and parts, navigate to the \12\Template\Features\BaseSiteStapling folder and open BaseSiteStapling.xml.

5) So far, we have successfully created a site definition. All we have to do now is to register this definition to the site definition list. To do this, create "WEBTEMPMOSSSITE.XML" file in "C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\1033\XML" folder.
6) Write the following code in this file and Save the file.
7)To make sure that our new Site Definition has all the right pieces and parts, navigate to the \12\Template\Features\BaseSiteStapling folder and open BaseSiteStapling.xml.
It should look something like this
Since our new Site Definition needs to behave exactly as the STS definition does,we must create a <> for each Feature that STS is associated with, like so:
Simply go through BaseSiteStapling.xml and each time you see an ID associated with STS#0 add an entry for MOSSSITE like below
8) Do the same thing in these 2 files
i)premiumsitestapling.xml located in C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\TEMPLATE\FEATURES\PremiumSiteStapling folder
ii)featurestapling.xml located in C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\TEMPLATE\FEATURES\StapledWorkflows folder
9) Save all the stuffs and do an iisreset
10)Now go to any site and select create site option . Under MOSS tab you will find the template
like below
Thats it :) .