BuildVirtualHdFromDSLiso


Forum: DSL Tips and Tricks
Topic: BuildVirtualHdFromDSLiso
started by: wangji

Posted by wangji on Sep. 24 2006,20:28
I ve created a script allowing to build
a virtual_bootable_disk from livecd_iso.(A DSL_linux_image for qemu )
The requirements from your pc are very little:
presence of /lib/grub/i386-pc/stage*  grub stuffs, /mnt/test,
dsl-xx.iso  any xx  ,qemu
you run
1   mkdslvdsk  dslvdisk  200  
 (to create a virtual disk of 200Mb with grub installed,and inside it I store
an install_script "instvdsk"to be used in the follow)
2   invoke    
   qemu -m 256 -cdrom  dsl-xx.iso   -hdb dslvdisk
at boot:  prompt ,login console with user_dsl to preserve resource
    boot:  dsl 2
3 #mount /dev/hdb1 /mnt/hdb1  &&  /mnt/hdb1/instvdsk
this will install to virtual disk from livecd .at the end of the process (# prompt)
# umont  /mnt/hdb1
4 exit qemu instance,and launch now
  qemu dslvdisk    (you now start bootup dsl_on virtual disk !)
have fun
I check my script on 3 differents partitions(ubuntu-6,kanotix-9 and a homemade_scratchbox-toolkit,and it worked
but on another machine,I could not get a bootable vdsk !(damned fdisk,and geometry c-h-s stuffs !)

you need to run as root (because manipulations of virtual disk (dd,losetup,mount...)
The script is very short,self explanatory;I do not do anything on device,hdd....
mkdslvdsk.sh
-------------------------------cut-------
#!/bin/bash  
# excute: " mkdslvdsk vdsk 200 "    to create a virtual vdsk 200Mb bootable.
#this script creates a virtual bootble_disk,with an install script "instvdsk" in side the vdisk
#invoking "qemu -cdrom dsl-xx.iso -hdb vdsk" allows to install dsl_filesystem to vdsk by doing
#" qemu -m -cdrom dsl-xx.iso -hdb vdsk"  ;choose console boot: "dsl 2 " to get more resource  
#mount /dev/hdb1 /mnt/hdb1 && /mnt/hdb1/instvdsk  to install
#at the end,umount /mnt/hdb1 ;exit qemu instance
#On pc host now start another instance with virtual disk  :  qemu vdsk   !!!!
partit()
{
echo "create a vdisk size $2 Mbytes partition 1"
#qemu-img create $1 $2
cnt=`expr $2 \* 2000 `
dd if=/dev/zero of=$1 bs=512 count=$cnt

cy=`expr $cnt \/ 8258 `
#/usr/bin/expr ( $2 \/ 4 ) > cyl

echo "cyl= $cy"
fdisk -b512 -C $cy -H128 -S63 $1  << EOF  

n

p

1



a

1

w

EOF
}
fmtit()
{
echo " format ext2"
losetup -d /dev/loop0 2>&1 >/dev/null
losetup -o 32256 /dev/loop0  $1
mke2fs /dev/loop0
losetup -d /dev/loop0
}
grubit()
{
mount -oloop,offset=32256 $1 /mnt/test
mkdir /mnt/test/boot
mkdir /mnt/test/boot/grub

cp -a /lib/grub/i386-pc/stage*  /mnt/test/boot/grub

cat > /mnt/test/boot/grub/menu.lst << EOF
default 2
title DSL
kernel /boot/linux24 root=/dev/hda1 quiet vga=normal noacpi noapm nodma noscsi frugal
init=/etc/init
title DSL fb800x600
kernel /boot/linux24  root=/dev/hda1 quiet vga=788 noacpi noapm nodma noscsi frugal
init=/etc/init
title DSL fb1024x768
kernel /boot/linux24  root=/dev/hda1 quiet vga=791 noacpi noapm nodma noscsi frugal
init=/etc/init
title DSL fb1280x1024
kernel /boot/linux24  root=/dev/hda1 quiet vga=794 noacpi noapm nodma noscsi frugal
init=/etc/init

EOF
echo " (hd6)  $1" > devmap
grub --batch --no-floppy --device-map=devmap <<EOF  >log
root  (hd6,0)
setup  (hd6)
quit
EOF
umount /mnt/test
}
cr_isotohd()
{
mount -oloop,offset=32256 $1 /mnt/test
cat > /mnt/test/instvdsk << EOF
mv /mnt/hdb1/boot/grub/menu.lst /mnt/hdb1/boot/grub/menu.lst_org
cp -a /KNOPPIX/* /mnt/hdb1
cp -f /mnt/hdb1/boot/grub/menu.lst_org /mnt/hdb1/boot/grub/menu.lst
cp /KNOPPIX/.bash* /mnt/hdb1
cp /etc/fstab /mnt/hdb1/etc
echo  " x5:5:wait:/etc/init.d/xsession start" >> /mnt/hdb1/etc/inittab
sed s/cp/#cp/ /mnt/hdb1/etc/init.d/xsession > xsession0
mv -f xsession0 /mnt/hdb1/etc/init.d/xsession
chmod +x /mnt/hdb1/etc/init.d/xsession
cp /cdrom/boot/isolinux/linux24 /mnt/hdb1/boot
mkdir /mnt/hdb1/KNOPPIX
mkdir /mnt/hdb1/ramdisk
#this part was reminiscent of trying to keep as closely as possible to dsl-xx.iso
#meaning just modify the menu.lst from (iso)/KNOPPIX/boot/grub/
#cp /mnt/hdb1/boot/grub/menu.lst /mnt/hdb1/boot/grub/menu.lst_org
#sed s/hda2/hda1/g /mnt/hdb1/boot/grub/menu.lst > menuu
#sed s_initrd_init=/etc/init_g menuu > menuv
#sed s_/boot/minirt24.gz_ww_g menuv > menuw
#sed s/ww// menuw > menux
#cp -f menux /mnt/hdb1/boot/grub/menu.lst
cd /mnt/hdb1/KNOPPIX
ln -s ../bin bin
ln -s ../etc etc
EOF
chmod +x  /mnt/test/instvdsk
umount /mnt/test
}
#main
partit $1 $2
fmtit $1
grubit $1
cr_isotohd $1
exit

Powered by Ikonboard 3.1.2a
Ikonboard © 2001 Jarvis Entertainment Group, Inc.