home *** CD-ROM | disk | FTP | other *** search
- #!/usr/bin/perl
- ###################################
- #Name : lpdev_config
- #
- #Description: To create filesystems and setup loop devices for loop
- # device installs and create and linuxrc for the ramdisk used during
- # loadlin boot.
- #
- # lpdev_config should be invoked as follows
- # 1st arg: windows partition device to install cdl on
- # 2nd arg: size of root filesystem (in MB)
- # 3rd arg: size of swap filesystem (in MB)
- # 4th arg: 1 if we want badblock checking.
- #
- #Copyright (C) 1999 Corel Corporation
- #
- # EXHIBIT A -Corel Public License.
- #
- # The contents of this file are subject to the Corel Public License
- # Version 1.0 (the "License"); you may not use this file except in
- # compliance with the License. You may obtain a copy of the License at
- # linux.corel.com/linuxproducts/corellinux/license.htm.
- # Software distributed under the License is distributed on an "AS IS"
- # basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
- # License for the specific language governing rights and limitations
- # under the License.
- # The Original Code is lpdev_config.
- # The Initial Developer of the Original Code is Corel Corporation.
- # Portions created by Corel are Copyright (C) 1999 All Rights Reserved.
- # Contributor(s): ______________________________________.
- ###################################################################
-
- # to be safe and since we might have typos in variable names
- use strict;
-
- my( $TEMP_MOUNT, $DEV, $ROOT_SIZE, $SWAP_SIZE, $ROOT, $SWAP, $TARGET, $ROOT_LOOPDEV, $SWAP_LOOPDEV, $FSTYPE, $TEMP_MOUNT2, $BOOTDSK_IMG, $TMP_DIR, $KERNEL_PKG, $DOSUTILS, $BADBLOCKCHK) = ();
-
- $TEMP_MOUNT="/tmp/mnt";
- $TEMP_MOUNT2="/tmp/mnt2";
- $TMP_DIR="$TEMP_MOUNT/cdl_tmp";
- $DEV=$ARGV[0];
- $ROOT_SIZE=$ARGV[1];
- $SWAP_SIZE=$ARGV[2];
- $BADBLOCKCHK=$ARGV[3];
- $ROOT="$TEMP_MOUNT/cdl/system/root.img";
- $SWAP="$TEMP_MOUNT/cdl/system/swap.img";
- $TARGET="/target";
- $ROOT_LOOPDEV="/dev/loop1";
- $SWAP_LOOPDEV="/dev/loop2";
- $FSTYPE="";
- $BOOTDSK_IMG="/instmnt/boot/boot1440.img";
- $KERNEL_PKG="/instmnt/dists/stable/main/binary-i386/base/kernel-2.2.x.deb";
- #$INITRD="ws/initrd";
- $DOSUTILS="/instmnt/tools";
-
- # make sure we have a temp mount point ready
- `umount $TEMP_MOUNT`;
- `rm -fr $TEMP_MOUNT`;
- `mkdir $TEMP_MOUNT`;
-
- `umount $TEMP_MOUNT2`;
- `rm -fr $TEMP_MOUNT2`;
- `mkdir $TEMP_MOUNT2`;
-
- if( ! -e $DEV ) {
- die "$DEV not found: $!";
- }
-
- # mount the device properly depending on its partition type
- #if( `fdisk -l|grep $DEV|grep Win95` ) {
- $FSTYPE="vfat";
- #} elsif( `fdisk -l|grep $DEV|grep DOS` ) {
- # $FSTYPE="msdos";
- #}
-
- if( $BADBLOCKCHK == 1 ) {
- $BADBLOCKCHK="-c";
- } else {
- $BADBLOCKCHK="";
- }
-
- `mount -t $FSTYPE $DEV $TEMP_MOUNT`;
-
- # if an installation of cdl already exists move it to cdl-#
- # and update the linuxrc to use the modified directory
- if( -e "$TEMP_MOUNT/cdl" ) {
- my ($c, @linuxrc) = (0, (), "");
- for($c=1;(-e "$TEMP_MOUNT/cdl_$c");$c++)
- {
- }
- `mv $TEMP_MOUNT/cdl $TEMP_MOUNT/cdl_$c`;
-
- `gunzip $TEMP_MOUNT/cdl_$c/initrd.gz`;
- `mount -o loop $TEMP_MOUNT/cdl_$c/initrd $TEMP_MOUNT2`;
- @linuxrc = `cat $TEMP_MOUNT2/linuxrc`;
- foreach my $elem (@linuxrc)
- {
- $elem =~ s/\/cdl[_\d]*\//\/cdl_$c\//;
- }
-
- `rm $TEMP_MOUNT2/linuxrc`;
- open(FOUT, ">$TEMP_MOUNT2/linuxrc");
- print FOUT @linuxrc;
- close FOUT;
-
- # set proper permissions for linuxrc
- `chmod a+x $TEMP_MOUNT2/linuxrc`;
-
- `umount $TEMP_MOUNT2`;
- `gzip $TEMP_MOUNT/cdl_$c/initrd`;
- }
-
- `mkdir $TEMP_MOUNT/cdl`;
- `mkdir $TEMP_MOUNT/cdl/system`;
-
- # create the root/swap ``partitions''
- `dd if=/dev/zero of=$ROOT bs=1024 count=$ROOT_SIZE`;
- `dd if=/dev/zero of=$SWAP bs=1024 count=$SWAP_SIZE`;
-
- # unhook /dev/loopX (pray that they are not currently busy)
- `losetup -d $ROOT_LOOPDEV`;
- `losetup -d $SWAP_LOOPDEV`;
-
- # connect the root/swap ``partitions'' to loopback devices
- # (requires loopback device support in the kernel)
- `losetup $ROOT_LOOPDEV $ROOT`;
- `losetup $SWAP_LOOPDEV $SWAP`;
-
- `sync;sync`;
-
- #`e2label $SWAP_LOOPDEV cdl:`;
-
- # create the filesystems
- `mke2fs $BADBLOCKCHK $ROOT_LOOPDEV -L "cdl:/"`;
-
- `sync; sync`;
-
- `mkswap $BADBLOCKCHK $SWAP_LOOPDEV`;
-
- `sync; sync`;
-
- `swapon $SWAP_LOOPDEV`;
-
- `sync;sync`;
-
- # copy the compressed ramdisk image to the cdl dir on the windows
- # partition and uncompress it
- `mount -t ext2 -o loop $BOOTDSK_IMG $TEMP_MOUNT2`;
- `cp $TEMP_MOUNT2/boot/initrd.gz $TEMP_MOUNT/cdl`;
-
- # for now we use the install kernel as the runtime kernel
- `cp $TEMP_MOUNT2/boot/vmlinuz $TEMP_MOUNT/cdl`;
- `umount $TEMP_MOUNT2`;
-
- # copy the runtime kernel from a kernel deb pkg (should be added when
- # the runtime kernel pkg is ready)
- #`mkdir $TMP_DIR`;
- #`dpkg -x $KERNEL_PKG $TMP_DIR`;
-
- # this assume the dpkg extract puts the kernel into boot/vmlinuz. This
- # probably will need changing
- #`cp $TMP_DIR/boot/vmlinuz $TEMP_MOUNT/cdl`;
-
-
- `gunzip $TEMP_MOUNT/cdl/initrd.gz`;
-
- `sync; sync`;
-
- # mount the initrd image
- `mount -t ext2 -o loop $TEMP_MOUNT/cdl/initrd $TEMP_MOUNT2`;
-
- # write the proper linuxrc file
- open(FOUT, ">$TEMP_MOUNT2/linuxrc") or die "Cannot open $TEMP_MOUNT2/linuxrc: $!";
-
- print FOUT "#!/bin/kiss\n";
- print FOUT "mount -t $FSTYPE $DEV /mnt\n";
- print FOUT "echo \"linuxrc: DOS partition mounted!\"\n";
- print FOUT "/sbin/losetup $ROOT_LOOPDEV /mnt/cdl/system/root.img\n";
- print FOUT "/sbin/losetup $SWAP_LOOPDEV /mnt/cdl/system/swap.img\n";
- print FOUT "echo \"linuxrc: Loop devices attached!!\"\n";
-
- close FOUT;
-
- # set proper permissions for linuxrc
- `chmod a+x $TEMP_MOUNT2/linuxrc`;
-
- `sync;sync`;
- # umount the ramdisk image and recompress it
- `umount $TEMP_MOUNT2`;
- `gzip $TEMP_MOUNT/cdl/initrd`;
-
- # remove the temp dir
- `rm -fr $TMP_DIR`;
-
- # uncompress the loadlin binary and the batch file to start cdl from
- # the dos/windows partition
- `cp $DOSUTILS/loadlin.exe $TEMP_MOUNT/cdl`;
-
- open(FOUT, ">$TEMP_MOUNT/cdl/startcdl.bat") or die "Cannot open $TEMP_MOUNT/cdl/startcdl.bat: $!";
-
- print FOUT "echo Starting Corel Linux ...\r\n";
- print FOUT "loadlin vmlinuz root=$ROOT_LOOPDEV initrd=initrd.gz\r\n";
- close FOUT;
-
- `sync;sync`;
- `sync;sync`;
-