home *** CD-ROM | disk | FTP | other *** search
- /**
- * Module: inst_prepdisk.ycp
- *
- * Authors: Mathias Kettner (kettner@suse.de) (initial)
- * Stefan Schubert (schubi@suse.de)
- *
- * Purpose:
- * Displays a progress bar showing progress of disk preparation.
- * The user has the opportunity to cancel the installation. The
- * disks are partitioned. Swap is created and used. File systems
- * are created for the new partitions. Mount points are created
- * and mounted for the targets /mnt and /mnt/boot.
- *
- *
- *
- * user_settings read: "targets"
- *
- *
- * user_settings write: "boot_device"
- * "swap_device"
- * "root_device"
- *
- *
- * SCR: Write(.disk + topath("." + substring (targetdevice, 5)) + .partitions, targetpartitions)
- * Write (.exec.mkdir, [ <mountpoint>, 0755 ])
- * Shell ("/bin/mount <device> <mountpoint>")
- *
- * $Id: inst_prepdisk.ycp,v 1.69 2000/03/10 12:59:20 kkaempf Exp $
- */
-
- {
- any targets = lookup ( user_settings, "targets" );
- boolean test_mode = lookup ( user_settings, "test_mode", false );
- boolean this_is_for_real = ! test_mode;
-
-
- _debug ( "BEGINNING of inst_prepdisk" );
- // Define macro that creates a dialog with progressbar
-
- UI(``{
- define MakefsDialog() ``{
-
- // html-format
- // advise the user to wait for completion
- // part 1 of 2
- string helptext = _("\
- <p>
- Please stand by while your hard disk is prepared.</p>");
- // part 2 of 2
- helptext = helptext + _("\
- <p>
- Depending on the size of your hard disk and your processor speed, this action
- might take some time. 5 minutes are not unusal for disks larger than 4 GB.
- Often, the progress meter doesn't show a linear progress; even if it looks
- slow near the end (\"95 %\"), please be patient: the formatting tool has to
- perform various checks. </p><br>");
- // hard disk will be made ready for installing Linux
- SetWizardContents(_("Preparing Your Harddisk"),
- `VBox(
- `ProgressBar(`id(`progress), " ", 100),
- `HCenter(// button: cancel harddisk preparation
- `PushButton(`id(`cancel), _("&Cancel")))),
- helptext, false, false);
- };
- });
-
- // define macros for the ui that is called by the package
- // installer in order to update the progressbars.
-
-
- UI(``{
- define UpdateProgressBar(integer percent)
- ``{
- ChangeWidget(`id(`progress), `Value, percent);
- any r = PollInput();
- // popup window after 'cancel' pressed: make sure user wants to quit installation
- if (r == `Id(`cancel) && YesOrNo(_("Do you really want\nto quit the installation?")))
- return `cancel;
- return nil;
- };
- });
-
-
- UI(`MakefsDialog());
-
- // Begin with the actual work
- // 1. Partitioning all disks
-
-
- // remember special devices for LILO
- string boot_device = "";
- list swap_devices = [];
- string root_device = "";
-
- map running_swap = SCR(`Read(.run.swapon_s));
-
- foreach (`targetdevice,`target, targets, ``{
- // every disk
- any partitions = lookup ( target, "partitions" );
- _debug("Target: ", targetdevice );
- if ( this_is_for_real ) {
- boolean result =
- SCR(`Write(.disk + topath("." + substring (targetdevice, 5)) + .partitions, partitions));
-
- if ( !result ) {
- y2log (.error, "prepdisk", 1, "Oops, fdisk failed for device ", targetdevice);
- string showOops = sformat (UI(_("The disk has an unsupported partition table\nPlease re-partition disk %1")), targetdevice);
- UI(`DisplayMessage(showOops));
- return `back;
- }
- }
- foreach (`pentry, partitions, ``{
- string device = targetdevice + lookup (pentry, "nr");
- string mountpoint = lookup (pentry, "mount", "");
- boolean do_format = lookup (pentry, "format", false);
- if (!lookup (pentry, "delete", false)) { // only those which aren't deleted
- if (mountpoint == "/boot")
- boot_device = device;
- else if ((mountpoint == "swap")
- && (lookup (running_swap, substring (device, 4, size(device)), "") == ""))
- swap_devices = add (swap_devices, [ device, do_format]);
- else if (mountpoint == "/")
- root_device = device;
- }
- _debug (" Partition:",pentry );
- });
-
- if ( boot_device == "" ) boot_device = root_device;
-
- });
-
- // Remember the devices for later, when we must unmount them
-
- user_settings = add(user_settings, "boot_device", boot_device);
- if (size (swap_devices) > 0)
- user_settings = add(user_settings, "swap_device", select (select (swap_devices, 0), 0));
- user_settings = add(user_settings, "root_device", root_device);
-
- _debug("boot_device:", boot_device );
- _debug("swap_devices:", swap_devices );
- _debug("root_device:", root_device );
-
- if ( this_is_for_real ) {
- // 2. Create and use swap devices
- foreach (`swaplist, swap_devices, ``{
- string swapdev = select (swaplist, 0);
- if ((select (swaplist, 1) == true) // format == yes ?
- && (0 != Shell("mkswap "+ swapdev)))
- UI(`DisplayMessage(sformat(UI(_("Couldn't setup swap partition %1")), swapdev)));
- if (0 != Shell("swapon "+swapdev))
- UI(`DisplayMessage(sformat(UI(_("Couldn't setup swap partition %1")), swapdev)));
- });
-
- // 2.1 only 5% buffer vm
-
- // Shell ("echo 5 > /proc/sys/vm/bdflush");
- }
-
-
- // 3. Create filesystems
-
- boolean cancel = false;
- integer fsid_native = 131;
-
- foreach (`targetdevice,`target, targets, ``{
-
- // every disk
- any partitions = lookup ( target, "partitions" );
-
- foreach(`partition, partitions, ``{
-
- //every partition which is to be formatted
- boolean format = lookup ( partition, "format", false);
- string mountPoint = lookup (partition, "mount", "" );
-
- if ( !cancel
- && format
- && (partition != $[])
- && (mountPoint != "")
- && (mountPoint != "swap"))
- {
- // announce partition to be formatted
- string partitionName = targetdevice + lookup (partition, "nr", 0 );
- string mountPoint = lookup (partition, "mount", "" );
-
- UI(`ChangeWidget(`id(`progress), `Label, sformat(UI(_("Formatting %1 as %2")), partitionName, mountPoint)));
- any ret = `ok;
-
- if ( this_is_for_real )
- {
- // Format native (ext2fs and reiser) partitions
-
- if (lookup (partition, "fsid", 0) == fsid_native)
- {
- if (lookup (partition, "used_fs", `unknown) == `reiser )
- {
- ret = CallModule("makereiserfs", [``UpdateProgressBar, partitionName, 0, 0]);
- }
- else
- {
- ret = CallModule("makefs", [``UpdateProgressBar, partitionName, 0, 0]);
- }
- UI(`SetModulename("inst_prepdisk"));
- }
- else
- ret = `ok;
- }
- else
- {
- // Fake formatting
-
- integer progress = 0;
-
- while ( progress < 100 )
- {
- UI( `UpdateProgressBar ( progress ) );
- sleep ( 300 ); // millisec
- progress = progress + 3;
- }
- }
-
-
- if ( ret == `cancel )
- {
- cancel = true;
- }
- else if ( ret != `ok )
- {
- // report any formatting errors
- // UI(`DisplayMessage(sformat(UI(_("Couldn't format partition %1")), partitionName)));
- }
- }
- });
- });
-
-
- if ( cancel )
- return `cancel;
-
- if ( this_is_for_real ) {
-
- // 4. Mount "/" and "/boot" and all other targets with mountpoints
-
- // now mount all native partitions with a mountpoint
-
- map mountPoints = lookup(user_settings, "mountpoints", $[]);
-
- Mkdir("/mnt");
-
- foreach (`mountpoint,`mountval, mountPoints, ``{
- if ((mountpoint != "") && (mountpoint != "swap")) {
- SCR(`Write (.exec.mkdir, [ "/mnt"+mountpoint, 0755 ]));
- if (select (mountval, 1) == fsid_native) {
- Shell ("/bin/mount "+select (mountval, 0)+" /mnt"+mountpoint);
- }
- }
- });
- Mkdir("/mnt/proc");
- Shell ("/bin/mount -t proc proc /mnt/proc");
- if (lookup (user_settings, "usb_type", 0) != 0)
- Shell ("/bin/mount -t usbdevfs usbdevfs /mnt/proc/bus/usb");
- }
-
- _debug ("END inst_prepdisk.ycp");
-
- return `next;
- }
-