No more need to compile Wubi when creating customs liveCD

Hi everybody,

If some one is interested, I've manage to make both remastersys and wubi working together.
I'm using a self modified version of wubi and remastersys.
First part is for Wubi.

Wubi is designed to use embedded files. The content of this embedded files is filled at compilation time. For my needs, I want a 'none power user' to be able to backup an existing system as a live CD with installation features and why not wubi features.
The main problem to do this was the need to setup and compile Wubi each time a new livecd is build. Now, you only need to do it one time.

The first step is to modify wubi to use external isolist.ini files.
To do this:
If not installed, download packages necessary to compile wubi
Code:
	sudo apt-get update
	sudo apt-get install build-essential unzip p7zip-full bzr-svn bzr gettext
	
and depending of your installation, maybe some other packages

Download the wubi sources.

More explaination are given in
http://ubuntuforums.org/showthread.p...t=wubi+compile if needed

Code:
	mkdir wubi
	cd wubi
	bzr branch http://bazaar.launchpad.net/~ubuntu-...ler/wubi/hardy
	cd hardy
	
Compile wubi without modifications to check if everything is OK
Code:
	sudo make prerequisites
	
note: when running this command, it stalled when trying to download libcurl sources. Maybe it because of a maintenance roll on the http://curl.haxx.se site
if getting this problem, edit src/metadl/Makefile and change http://curl.haxx.se/download/ with a mirror (eg http://www.mirrorspace.org/curl/)
Code:
	make clean
	make
	make test
	
If every thing is allright, modify the wubi code to use an external isolist.ini
in wubi/src/variables.nsh
add
Code:
	var INIDIR
	var plugin_ini
	
in wubi/src/main_page.nsh
in function
Function PopulateDistroList
change
Code:
	         ${GetSectionNames} "$PLUGINSDIR\data\isolist.ini" "AddDistroToList"
	
for
Code:
	         ${GetSectionNames} "$INIDIR\isolist.ini" "AddDistroToList"
	
in wubi/src/info.nsh

in function Function GetDistroInfo

change
Code:
	    ReadINIStr $isoName $PLUGINSDIR\data\IsoList.ini "$distroFullName" "IsoName"
	ReadINIStr $isoSize $PLUGINSDIR\data\IsoList.ini "$distroFullName" "IsoSize"
	ReadINIStr $minIsoSize $PLUGINSDIR\data\IsoList.ini "$distroFullName" "MinIsoSize"
	ReadINIStr $isoKernel $PLUGINSDIR\data\IsoList.ini "$distroFullName" "kernel"
	ReadINIStr $isoInitrd $PLUGINSDIR\data\IsoList.ini "$distroFullName" "initrd"
	ReadINIStr $metalinkUrl $PLUGINSDIR\data\IsoList.ini "$distroFullName" "metalink"
	ReadINIStr $metalinkUrl2 $PLUGINSDIR\data\IsoList.ini "$distroFullName" "metalink2"
	ReadINIStr $distroPackages $PLUGINSDIR\data\IsoList.ini "$distroFullName" "packages"
	ReadINIStr $distroVersion $PLUGINSDIR\data\IsoList.ini "$distroFullName" "version"
	ReadINIStr $distroSubVersion $PLUGINSDIR\data\IsoList.ini "$distroFullName" "subversion"
	ReadINIStr $md5sums_filename $PLUGINSDIR\data\IsoList.ini "$distroFullName" "md5sums"
	ReadINIStr $md5sums_signature $PLUGINSDIR\data\IsoList.ini "$distroFullName" "md5sums_signature"
	ReadINIStr $cdFileCheck $PLUGINSDIR\data\IsoList.ini "$distroFullName" "cdFileCheck"
	ReadINIStr $cdmd5sums $PLUGINSDIR\data\IsoList.ini "$distroFullName" "cdmd5sums"
	
by
Code:
	    ReadINIStr $isoName $INIDIR\IsoList.ini "$distroFullName" "IsoName"
	ReadINIStr $isoSize $INIDIR\IsoList.ini "$distroFullName" "IsoSize"
	ReadINIStr $minIsoSize $INIDIR\IsoList.ini "$distroFullName" "MinIsoSize"
	ReadINIStr $isoKernel $INIDIR\IsoList.ini "$distroFullName" "kernel"
	ReadINIStr $isoInitrd $INIDIR\IsoList.ini "$distroFullName" "initrd"
	ReadINIStr $metalinkUrl $INIDIR\IsoList.ini "$distroFullName" "metalink"
	ReadINIStr $metalinkUrl2 $INIDIR\IsoList.ini "$distroFullName" "metalink2"
	ReadINIStr $distroPackages $INIDIR\IsoList.ini "$distroFullName" "packages"
	ReadINIStr $distroVersion $INIDIR\IsoList.ini "$distroFullName" "version"
	ReadINIStr $distroSubVersion $INIDIR\IsoList.ini "$distroFullName" "subversion"
	ReadINIStr $md5sums_filename $INIDIR\IsoList.ini "$distroFullName" "md5sums"
	ReadINIStr $md5sums_signature $INIDIR\IsoList.ini "$distroFullName" "md5sums_signature"
	ReadINIStr $cdFileCheck $INIDIR\IsoList.ini "$distroFullName" "cdFileCheck"
	ReadINIStr $cdmd5sums $INIDIR\IsoList.ini "$distroFullName" "cdmd5sums"
	
in function Function parse_command_line_parameters
add
Code:
	##begin of modified code
	strcpy $INIDIR $EXEDIR
	##messagebox mb_ok "$INIDIR"
	##messagebox mb_ok "$EXEDir"
	${StrStr} $str $CMDLINE "--plugin_ini"
	${if} "$str" != ""
	strcpy $plugin_ini true
	strcpy $INIDIR "$PLUGINSDIR\data"
	##messagebox mb_ok "$INIDIR"
	${endif}
	##end of modified code
	
Compile the modified wubi
Code:
	make clean
	make 
	make test
	
Now you have a wubi executable able to read an isolist.ini located in the same directory than the wubi executable itself. By this way, your don't need to compile a new wubi executable everytime you are creating a new live cd.
It is now very easy to create this isolist.ini to suite your own live cd. The easyest way to do it, is to make it being automaticaly created with remastersys.
The new wubi executable comes with a new command line option "--plugin_ini" to keep compatibility with build-in isolist.ini

What we need to use wubi with a live cd is
- wubi executable on the cd tree
- a correct isolist.ini in the same directory than the wubi executable
This isolist.ini must be formated with distro name and version informations.
Second part, modifing remastersys
As said before the isolist.ini will be created during the liveCD creation process with Remastersys.
First step in remastersys is to create new parameters that will be used to create the isolist.ini file

To create a live / dist cd remastersys use a CD label, and an iso file name.
- Cd label will be use as the the distro name.
- version don't exist so we need to add it
in remastersys_gui
in fonction modifymenu ()
add
Code:
	elif [ "$MODIFY" = "g" ]; then
	ISOVER=`$DIALOG $TITLE"Remastersys Backup" $ENTRY $TEXT"Enter new revision" $ENTRYTEXT"$ISOVER"`
	if [ "$ISOVER" = "" ]; then
	ISOVER="0.0.1"
	fi
	elif [ "$MODIFY" = "h" ]; then
	WUBIURL=`$DIALOG $TITLE"Remastersys Backup" $ENTRY $TEXT"Enter URL to use with wubi" $ENTRYTEXT"$WUBIURL"`
	if [ "$WUBIURL" = "" ]; then
	WUBIURL="http://something"
	fi
	
and modify line
Code:
	MODIFY=`$DIALOG $TITLE"Remastersys Backup" $MENU $TEXT"Please Select which option you would like to change?" a "Username = $LIVEUSER" b "Title = $LIVECDLABEL" c "Filename = $CUSTOMISO" d "Working Directory = $WORKDIR" e "Files to Exclude = $EXCLUDES" f "CD Boot Method = $CDBOOTTYPE" q "Go back to main menu"`
	
to
Code:
	MODIFY=`$DIALOG $TITLE"Remastersys Backup" $MENU $TEXT"Please Select which option you would like to change?" a "Username = $LIVEUSER" b "Title = $LIVECDLABEL" g "Version =$ISOVER" h "Url =$URL" c "Filename = $CUSTOMISO" d "Working Directory = $WORKDIR" e "Files to Exclude = $EXCLUDES" f "CD Boot Method = $CDBOOTTYPE" q "Go back to main menu"`
	
add also the new parameter in the remastersys config file template in the same file (below cat > /etc/remastersys.conf <<FOO)
Code:
	# Here you can give a revision number
	ISOVER="$ISOVER"
	# Here you can give a URL to use with Wubi to download the iso
	WUBIURL="$WUBIURL"
	
Now that this parameters are created , they must be filled to suite the X.Y.Z format needed by wubi

For convenience, the iso file name will be compose with the file name given plus the version plus ".iso":it no more needed to add the file extention


In remastersys, add some code to create isolist.ini
first create /etc/remastersys/wubi directory and add an isolist.ini template in /etc/remastersys/wubi
Code:
	[__DISTRO__-i386]
	version=__VERSION__
	subversion=
	isoName=
	packages=
	kernel=casper\vmlinuz
	initrd=casper\initrd.gz
	metalink=__URL__/__DISTRO__-__VERSION__-i386.metalink
	metalink2=
	md5sums=MD5SUMS-metalink
	md5sums_signature=MD5SUMS-metalink.gpg
	isoSize=
	minIsoSize=600000000
	cdFileCheck=casper\filesystem.squashfs
	cdmd5sums=md5sum.txt
	[__DISTRO__-amd64]
	version=__VERSION__
	subversion=
	isoName=
	packages=
	kernel=casper\vmlinuz
	initrd=casper\initrd.gz
	metalink=__URL__/__DISTRO__-__VERSION__-amd64.metalink
	metalink2=
	md5sums=
	md5sums_signature=
	isoSize=
	minIsoSize=
	cdFileCheck=casper\filesystem.squashfs
	cdmd5sums=md5sum.txt
	
If you want, add also an autorun.inf in the same directory to get autostart cd features
Code:
	[autorun]
	open=Wubi.exe
	icon=Wubi.exe
	
And the most important, copy the wubi executable you get in first step to /etc/remastersys/wubi/wubi.exe

Now it is time to add some new stuff to remastersys
after
Code:
	if [ "$LIVECDLABEL" = "" ]; then
	LIVECDLABEL="Custom Live CD"
	fi
	
add
Code:
	if [ "$ISOVER" = "" ]; then
	ISOVER="0.0.1"
	fi
	if [ "$WUBIURL" = "" ]; then
	WUBIURL="http://something/"
	fi
	
Somewere in part "STEP3 of remastersys add
Code:
	## creation fichier ./disk/info
	mkdir -p $WORKDIR/ISOTMP/.disk
	echo "$LIVECDLABEL $ISOVER "'"HH"'" - Release i386 ($(date +%d%m%y))" > $WORKDIR/ISOTMP/.disk/info
	## fin
	## creation repository pour lupin-support et wubi
	apt-get -d -y --reinstall install lupin-support
	mkdir -p $WORKDIR/ISOTMP/pool
	mkdir -p $WORKDIR/ISOTMP/pool/lupin
	cp /var/cache/apt/archives/lupin-support*.deb $WORKDIR/ISOTMP/pool/lupin/
	mkdir -p $WORKDIR/ISOTMP/dists
	mkdir -p $WORKDIR/ISOTMP/dists/hardy
	mkdir -p $WORKDIR/ISOTMP/dists/hardy/main
	mkdir -p $WORKDIR/ISOTMP/dists/hardy/main/binary-i386
	dpkg-scanpackages $WORKDIR/ISOTMP/pool/lupin /dev/null > $WORKDIR/ISOTMP/dists/hardy/main/binary-i386/Packages
	sed -i s#$WORKDIR/ISOTMP/## $WORKDIR/ISOTMP/dists/hardy/main/binary-i386/Packages
	cat $WORKDIR/ISOTMP/dists/hardy/main/binary-i386/Packages | gzip -9c > $WORKDIR/ISOTMP/dists/hardy/main/binary-i386/Packages.gz
	cp /etc/remastersys/wubi/* $WORKDIR/ISOTMP/
	sed -i 's#__VERSION__#'"$ISOVER"'#g' $WORKDIR/ISOTMP/isolist.ini
	sed -i 's#__DISTRO__#'"$LIVECDLABEL"'#g' $WORKDIR/ISOTMP/isolist.ini
	sed -i 's#__URL__#'"$WUBIURL"'#g' $WORKDIR/ISOTMP/isolist.ini
	##fin
	
another modification (not related to wubi usage) is to be donne in part step 5 of remastersys to make persistent mode available with ubuntu 8.04
Code:
	  
	# Step 5 plus :correction du bug casper
	rm -rf $WORKDIR/initrd-remake
	mkdir $WORKDIR/initrd-remake
	cd $WORKDIR/initrd-remake
	mkdir initrd-old
	cp $WORKDIR/ISOTMP/casper/initrd.gz initrd_old.gz
	cd initrd-old
	gunzip < ../initrd_old.gz | cpio -i --make-directories
	cd scripts
	#editer casper et enlever ,mode=755
	#vi casper
	sed -i s/,mode=755// casper
	cd ..
	find ./ | cpio -H newc -o > ../initrd
	cd ..
	gzip initrd
	cp initrd.gz $WORKDIR/ISOTMP/casper/
	cd ..
	#fin du step5 plus
	
And finaly, modify step 8 of remastersys to add $ISOVER to the filename and label of the CD where necessary
$LIVECDLABEL -> $LIVECDLABEL-$ISOVER
$CUSTOMISO -> $CUSTOMISO-$ISOVER.iso
Code:
	# Step 8 - Make the ISO file
	# ajout "-$ISOVER au bout de $LIVECDLABEL
	# Step 8 - Make the ISO file
	echo "Creating $CUSTOMISO-$ISOVER.iso in $WORKDIR"
	$CREATEISO    \
	-quiet \
	-r    \
	-V "$LIVECDLABEL-$ISOVER"    \
	-cache-inodes    \
	-J    \
	-l    \
	-b isolinux/isolinux.bin    \
	-c isolinux/boot.cat    \
	-no-emul-boot    \
	-boot-load-size 4    \
	-boot-info-table    \
	-o $WORKDIR/$CUSTOMISO-$ISOVER.iso "$WORKDIR/ISOTMP" 2>>$WORKDIR/remastersys.log 1>>$WORKDIR/remastersys.log
	else
	#grub mode
	# remove files that change and cause problems with checking the disk
	sed -e '/boot/d' md5sum.txt > md5sum.txt.new
	sed -e '/md5sum/d' md5sum.txt.new > md5sum.txt
	rm -f md5sum.txt.new
	sleep 1
	# ajout "-$ISOVER au bout de $LIVECDLABEL
	# Step 8 - Make the ISO file
	echo "Creating $CUSTOMISO-$ISOVER.iso in $WORKDIR"
	$CREATEISO    \
	-quiet \
	-r    \
	-V "$LIVECDLABEL-$ISOVER"    \
	-cache-inodes    \
	-J    \
	-l    \
	-b boot/grub/stage2_eltorito    \
	-no-emul-boot    \
	-boot-load-size 4    \
	-boot-info-table    \
	-o $WORKDIR/$CUSTOMISO-$ISOVER.iso "$WORKDIR/ISOTMP" 2>>$WORKDIR/remastersys.log 1>>$WORKDIR/remastersys.log
	fi
	# create the md5 sum file so the user doesn't have to - this is good so the iso file can later be tested to ensure it hasn't become corrupted
	echo "Creating $CUSTOMISO-$ISOVER.iso.md5 in $WORKDIR"
	md5sum $WORKDIR/$CUSTOMISO-$ISOVER.iso > $WORKDIR/$CUSTOMISO-$ISOVER.iso.md5
	sleep 1
	echo "$WORKDIR/$CUSTOMISO-$ISOVER.iso is ready to be burned or tested in a virtual machine."
	echo " "
	echo "Check the size and if it is larger than 700MB you will need to burn it to a dvd"
	echo " "
	ls -hs $WORKDIR/$CUSTOMISO-$ISOVER.iso
	echo " " 
	echo "It is recommended to run 'sudo remastersys clean' once you have burned and tested the $CUSTOMISO"
	echo " "
	
If every thing is ok , remastersys will be able to create some backups/live/dist CD that can be installed easyly in XP/VISTA PC's with wubi

In addition, some little thing may to be done to work properly:
- it seems that lupin-support / casper-lupin need to be installed on the system before creating the live cd with remastersys,
even if , like it done in the modified remastersys script, a mini repository with the package is embeded in the live CD
- depending the way boot menu of the livecd is set by remastersys, add options to start live cd in installation mode. Here is the config file I am using with my customized gfxboot bootmenu manager
Code:
	DEFAULT live
	GFXBOOT bootlogo
	APPEND  file=/cdrom/preseed/custom.seed boot=casper initrd=/casper/initrd.gz quiet splash --
	LABEL live
	menu label ^Live CD
	kernel /casper/vmlinuz
	append  file=/cdrom/preseed/custom.seed boot=casper initrd=/casper/initrd.gz quiet splash --
	LABEL install
	menu label ^Installation 
	kernel /casper/vmlinuz
	append  file=/cdrom/preseed/custom.seed boot=casper only-ubiquity initrd=/casper/initrd.gz quiet splash --
	LABEL persistent
	menu label ^Live CD Persistent
	kernel /casper/vmlinuz
	append  file=/cdrom/preseed/custom.seed boot=casper persistent initrd=/casper/initrd.gz quiet splash --
	LABEL vesapersistent
	menu label ^Live CD Persistent mode vesa
	kernel /casper/vmlinuz
	append  file=/cdrom/preseed/custom.seed boot=casper xforcevesa persistent initrd=/casper/initrd.gz quiet splash --
	LABEL vesa
	menu label ^Live CD mode vesa
	kernel /casper/vmlinuz
	append  file=/cdrom/preseed/custom.seed boot=casper xforcevesa initrd=/casper/initrd.gz quiet splash --
	LABEL check
	menu label ^Verification CD
	kernel /casper/vmlinuz
	append  boot=casper integrity-check initrd=/casper/initrd.gz quiet splash --
	LABEL memtest
	menu label ^Test memoire
	kernel /isolinux/memtest
	append -
	LABEL hd
	menu label ^Demarrage HD
	localboot 0x80
	append -
	DISPLAY isolinux.txt
	TIMEOUT 300
	PROMPT 1
	F1 f1.txt
	F2 f2.txt
	F3 f3.txt
	F4 f4.txt
	F5 f5.txt
	F6 f6.txt
	F7 f7.txt
	F8 f8.txt
	F9 f9.txt
	F0 f10.txt
	
- If like me ( i'm using lxde) , you want to use other window manager than Metacity (gnome), Kde or flux box, you will need to modify the ubiquity script in order to start lxde properly before installing the system.
in /usr/bin/ubiquity-dm
after
Code:
	            elif osextras.find_on_path('xfwm4'):
	wm = subprocess.Popen('xfwm4',
	stdin=null, stdout=logfile, stderr=logfile,
	**maybe_drop_privileges)
	
add code to start openbox (replace by your own window manager if needed)
Code:
	            elif osextras.find_on_path('openbox'):
	wm = subprocess.Popen('openbox',
	stdin=null, stdout=logfile, stderr=logfile,
	**maybe_drop_privileges)
	

This howto have been written after the job was done (and worked), maybe some small mistakes may be found in the codes given.
Any feedback will be welcome in order to correct this post.

One usage I have done was to install UbuntuStudio (Ubuntustudio distro CD don't support wubi) on XP computer with wubi.
-Virtual machine installation of UbuntuStudio
-Wubi enabled live CD with Remastersys creation
-Ubuntustudio installation on NTFS partition with wubi

 

 

Thanks  Ref : http://ubuntuforums.org/showthread.php?t=1062504