Monday, March 12, 2007

How to Create a Bootable Linux Image on a USB stick



Create a Server Image on a usb stick ¶

Plug in the usb stick and use dmesg or 'tail -f /var/log/messages' to find the device name assigned.

Wipe the Device ¶

Zero the entire disk (or usb pen) including the partition table and boot sectors as follows:-
dd if=/dev/zero of=/dev/sda
(Use /dev/random or /dev/urandom to write random data to the disk)

Create the Partitions ¶

To view disk contents and create partitions type:-
fdisk /dev/sda
(cfdisk - graphical version)
In fdisk do the following:-
Type 'n' (to create a new partition)
Type 'p' (to make the new partition a primary partition)
Type '1' (to set the partition number to one)
Type Return (to select the default start block)
Type Return (to select the default end block)
Type 'a' (to toggle on the boot flag which makes the partition bootable)
Type 't' (to change the type of the partition)
Type 'b' (selects W95 FAT32 as the partition type)
Type 'w' (to write your changes to the usb stick and exit fdisk)
fdisk -l /dev/sda - lists the partitions on the device

Create the Boot Sector ¶

dd if=/usr/lib/syslinux/mbr.bin of=/dev/sda

Create the File System ¶

mkfs vfat /dev/sda1

Mount the file system ¶

mount /dev/sda1 /mnt/usbstick

Make the usb pen a bootable linux drive ¶

Create an empty file called 'livecd' to enable Gentoo to find the bootable disk.
touch /mnt/usbstick/livecd
umount /dev/sda1
Run syslinux on the bootable partition to place ldlinux.sys where the master boot record points:-
syslinux /dev/sda1
mount /dev/sda1 /mnt/usbstick
ls -l /mnt/usbstick
-r-xr--r-- 1 root root 9436 Mar 1 16:57 ldlinux.sys
-rwxr--r-- 1 root root 0 Mar 1 13:17 livecd
umount /dev/sda1

Tuesday, March 6, 2007

Setting the Build Number in AssemblyInfo.cs from Subversion using MSBuild

VS05 introduces msbuild, an xsd for the xml in the VS05 project files which allows developers to write their own tasks or use standard tasks to control the building of .net projects.

The following msbuild xsd xml was added to a c# project file (*.csproj) to produce a build revision number in its AssemblyInfo attributes based on the current subversion version number. The AssemblyInfo.cs file is auto-generated and should not be placed under source code control.

<import project="$(MSBuildExtensionsPath)\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets">
<propertygroup>
<major>1</major>
<minor>0</minor>
<build>0</build>
<revision>0</revision>
</propertygroup>
<target name="Version">
<svnversion localpath="$(MSBuildProjectDirectory)">
<output taskparameter="Revision" propertyname="Revision">
</svnversion>
<message text="Revision: $(Revision)">
<message text="Project File Name = $(MSBuildProjectFileName)">
<message text="Project Extension = $(MSBuildProjectExtension)">
<message text="Project Directory = $(MSBuildProjectDirectory)">
<message text="Bin Path = $(MSBuildBinPath)">
<message text="Extensions Path = $(MSBuildExtensionsPath)">
<message text="Version: $(Major).$(Minor).$(Build).$(Revision)">
<assemblyinfo codelanguage="CS" outputfile="$(MSBuildProjectDirectory)\Properties\AssemblyInfo.cs" assemblytitle="Your Assembly Title" assemblydescription="" assemblyconfiguration="" assemblycompany="Your Company" assemblyproduct="Your Product" assemblycopyright="Copyright © Your Company 2007" assemblytrademark="" assemblyculture="" comvisible="false" guid="Your Guid" assemblyversion="$(Major).$(Minor).$(Build).$(Revision)" assemblyfileversion="$(Major).$(Minor).$(Build).$(Revision)">
<createproperty value="$(Major).$(Minor).$(Build).$(Revision)">
<output taskparameter="Value" propertyname="ApplicationVersion">
</createproperty>
<createproperty value="$(Revision)">
<output taskparameter="Value" propertyname="ApplicationRevision">
</createproperty>
<message text="ApplicationVersion: $(ApplicationVersion)">
</target>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.-->
<target name="BeforeBuild">
<calltarget targets="Version">
</target>
<target name="AfterBuild">
<message text="ApplicationVersion: $(ApplicationVersion)">
</target>

The xml makes use of the following standard tasks that ship with msbuild:-

  1. Message
  2. CreateProperty
  3. CallTarget

Further information on these tasks can be found in the MSBuild Task Reference.

In addition, msbuild community tasks, an open source set of tasks for msbuild, is required, specifically the following tasks:-

  1. SvnVersion
  2. AssemblyInfo

The first line of code (the Import item) is used to include these tasks. The msbuild community tasks, together with their documentation, can be installed with the MSBuild.Community.Tasks.msi installer.

In order for the SvnVersion task to work the SubVersion command line tools must be installed.

The AfterBuild Target calls the Message task to output the ApplicationVersion at the end of the build. In order to see this message you must increase the verbosity of msbuild. In VS05 go to tools/options/projects and solutions/build and run and change the msbuild verbosity to normal to see the application version message at the end of the build output.

Add a new About Box class (included in the VS05 installed templates) to your project and instantiate an object of this type and call its ShowDialog() method in the click event handler for the help menu about item. The assembly build revision number shall be displayed by default in the dialog.