Index: uspace/app/sysinst/sysinst.c
===================================================================
--- uspace/app/sysinst/sysinst.c	(revision 90ee33847a253e914f7c550243adfa34c9742fdb)
+++ uspace/app/sysinst/sysinst.c	(revision 3acb63b555e98b449accd3797d713fed52137860)
@@ -42,4 +42,6 @@
 #include <fdisk.h>
 #include <futil.h>
+#include <gfx/render.h>
+#include <io/log.h>
 #include <loc.h>
 #include <stdio.h>
@@ -48,4 +50,7 @@
 #include <str_error.h>
 #include <system.h>
+#include <ui/msgdialog.h>
+#include <ui/ui.h>
+#include <ui/window.h>
 #include <vfs/vfs.h>
 #include <vol.h>
@@ -54,4 +59,7 @@
 #include "rdimg.h"
 #include "volume.h"
+#include "sysinst.h"
+
+#define NAME "sysinst"
 
 /** Device to install to
@@ -96,6 +104,4 @@
 };
 
-static bool restart = false;
-
 static fibril_mutex_t shutdown_lock;
 static fibril_condvar_t shutdown_cv;
@@ -110,4 +116,262 @@
 	.shutdown_failed = sysinst_shutdown_failed
 };
+
+static void wnd_close(ui_window_t *, void *);
+static errno_t bg_wnd_paint(ui_window_t *, void *);
+
+static ui_window_cb_t bg_window_cb = {
+	.close = wnd_close,
+	.paint = bg_wnd_paint
+};
+
+static ui_window_cb_t progress_window_cb = {
+	.close = wnd_close
+};
+
+static void sysinst_confirm_button(ui_msg_dialog_t *, void *, unsigned);
+static void sysinst_confirm_close(ui_msg_dialog_t *, void *);
+
+static ui_msg_dialog_cb_t sysinst_confirm_cb = {
+	.button = sysinst_confirm_button,
+	.close = sysinst_confirm_close
+};
+
+static errno_t sysinst_restart_dlg_create(sysinst_t *);
+static void sysinst_restart_dlg_button(ui_msg_dialog_t *, void *, unsigned);
+static void sysinst_restart_dlg_close(ui_msg_dialog_t *, void *);
+
+static ui_msg_dialog_cb_t sysinst_restart_dlg_cb = {
+	.button = sysinst_restart_dlg_button,
+	.close = sysinst_restart_dlg_close
+};
+
+static int sysinst_start(sysinst_t *);
+static errno_t sysinst_restart(sysinst_t *);
+static void sysinst_progress_destroy(sysinst_progress_t *);
+static void sysinst_action(sysinst_t *, const char *);
+static void sysinst_error(sysinst_t *, const char *);
+static void sysinst_debug(sysinst_t *, const char *);
+
+static void sysinst_futil_copy_file(void *, const char *, const char *);
+static void sysinst_futil_create_dir(void *, const char *);
+
+static futil_cb_t sysinst_futil_cb = {
+	.copy_file = sysinst_futil_copy_file,
+	.create_dir = sysinst_futil_create_dir
+};
+
+static void sysinst_error_msg_button(ui_msg_dialog_t *, void *, unsigned);
+static void sysinst_error_msg_close(ui_msg_dialog_t *, void *);
+
+static ui_msg_dialog_cb_t sysinst_error_msg_cb = {
+	.button = sysinst_error_msg_button,
+	.close = sysinst_error_msg_close
+};
+
+/** Close window.
+ *
+ * @param window Window
+ * @param arg Argument (sysinst_t *)
+ */
+static void wnd_close(ui_window_t *window, void *arg)
+{
+	(void)window;
+	(void)arg;
+}
+
+/** Paint background window.
+ *
+ * @param window Window
+ * @param arg Argument (sysinst_t *)
+ */
+static errno_t bg_wnd_paint(ui_window_t *window, void *arg)
+{
+	sysinst_t *sysinst = (sysinst_t *)arg;
+	gfx_rect_t app_rect;
+	gfx_context_t *gc;
+	errno_t rc;
+
+	gc = ui_window_get_gc(window);
+
+	rc = gfx_set_color(gc, sysinst->bg_color);
+	if (rc != EOK)
+		return rc;
+
+	ui_window_get_app_rect(window, &app_rect);
+
+	rc = gfx_fill_rect(gc, &app_rect);
+	if (rc != EOK)
+		return rc;
+
+	rc = gfx_update(gc);
+	if (rc != EOK)
+		return rc;
+
+	return EOK;
+}
+
+/** Installation confirm dialog OK button press.
+ *
+ * @param dialog Message dialog
+ * @param arg Argument (sysinst_t *)
+ * @param btn Button number
+ * @param earg Entry argument
+ */
+static void sysinst_confirm_button(ui_msg_dialog_t *dialog, void *arg,
+    unsigned btn)
+{
+	sysinst_t *sysinst = (sysinst_t *) arg;
+
+	ui_msg_dialog_destroy(dialog);
+
+	switch (btn) {
+	case 0:
+		/* OK */
+		sysinst_start(sysinst);
+		break;
+	default:
+		/* Cancel */
+		ui_quit(sysinst->ui);
+		break;
+	}
+}
+
+/** Installation confirm dialog close request.
+ *
+ * @param dialog Message dialog
+ * @param arg Argument (sysinst_t *)
+ */
+static void sysinst_confirm_close(ui_msg_dialog_t *dialog, void *arg)
+{
+	sysinst_t *sysinst = (sysinst_t *) arg;
+
+	ui_msg_dialog_destroy(dialog);
+	ui_quit(sysinst->ui);
+}
+
+/** Restart system dialog OK button press.
+ *
+ * @param dialog Message dialog
+ * @param arg Argument (sysinst_t *)
+ * @param btn Button number
+ * @param earg Entry argument
+ */
+static void sysinst_restart_dlg_button(ui_msg_dialog_t *dialog, void *arg,
+    unsigned btn)
+{
+	sysinst_t *sysinst = (sysinst_t *) arg;
+
+	ui_msg_dialog_destroy(dialog);
+
+	(void)sysinst;
+
+	switch (btn) {
+	case 0:
+		/* OK */
+		(void)sysinst_restart(sysinst);
+		break;
+	default:
+		/* Cancel */
+		ui_quit(sysinst->ui);
+		break;
+	}
+}
+
+/** Restat system dialog close request.
+ *
+ * @param dialog Message dialog
+ * @param arg Argument (sysinst_t *)
+ */
+static void sysinst_restart_dlg_close(ui_msg_dialog_t *dialog, void *arg)
+{
+	sysinst_t *sysinst = (sysinst_t *) arg;
+
+	ui_msg_dialog_destroy(dialog);
+	ui_quit(sysinst->ui);
+}
+
+/** Installation error message dialog button press.
+ *
+ * @param dialog Message dialog
+ * @param arg Argument (sysinst_t *)
+ * @param bnum Button number
+ */
+static void sysinst_error_msg_button(ui_msg_dialog_t *dialog,
+    void *arg, unsigned bnum)
+{
+	sysinst_t *sysinst = (sysinst_t *) arg;
+
+	ui_msg_dialog_destroy(dialog);
+	ui_quit(sysinst->ui);
+}
+
+/** Installation error message dialog close request.
+ *
+ * @param dialog Message dialog
+ * @param arg Argument (shutdown_dlg_t *)
+ */
+static void sysinst_error_msg_close(ui_msg_dialog_t *dialog, void *arg)
+{
+	sysinst_t *sysinst = (sysinst_t *) arg;
+
+	ui_msg_dialog_destroy(dialog);
+	ui_quit(sysinst->ui);
+}
+
+/** Create error message dialog.
+ *
+ * @param sysinst System installer
+ * @return EOK on success or an error code
+ */
+static errno_t sysinst_error_msg_create(sysinst_t *sysinst)
+{
+	ui_msg_dialog_params_t params;
+	ui_msg_dialog_t *dialog;
+	errno_t rc;
+
+	ui_msg_dialog_params_init(&params);
+	params.caption = "Error";
+	params.text = sysinst->errmsg;
+	params.flags |= umdf_topmost | umdf_center;
+
+	rc = ui_msg_dialog_create(sysinst->ui, &params, &dialog);
+	if (rc != EOK)
+		return rc;
+
+	ui_msg_dialog_set_cb(dialog, &sysinst_error_msg_cb, (void *)sysinst);
+
+	return EOK;
+}
+
+/** Called when futil is starting to copy a file.
+ *
+ * @param arg Argument (sysinst_t *)
+ * @param src Source path
+ * @param dest Destination path
+ */
+static void sysinst_futil_copy_file(void *arg, const char *src,
+    const char *dest)
+{
+	sysinst_t *sysinst = (sysinst_t *)arg;
+	char buf[128];
+
+	(void)src;
+	snprintf(buf, sizeof(buf), "Copying %s.", dest);
+	sysinst_action(sysinst, buf);
+}
+
+/** Called when futil is about to create a directory.
+ *
+ * @param arg Argument (sysinst_t *)
+ * @param dest Destination path
+ */
+static void sysinst_futil_create_dir(void *arg, const char *dest)
+{
+	sysinst_t *sysinst = (sysinst_t *)arg;
+	char buf[128];
+
+	snprintf(buf, sizeof(buf), "Creating %s.", dest);
+	sysinst_action(sysinst, buf);
+}
 
 /** System shutdown complete.
@@ -162,4 +426,5 @@
 /** Label the destination device.
  *
+ * @param sysinst System installer
  * @param dev Disk device to label
  * @param psvc_id Place to store service ID of the created partition
@@ -167,5 +432,6 @@
  * @return EOK on success or an error code
  */
-static errno_t sysinst_label_dev(const char *dev, service_id_t *psvc_id)
+static errno_t sysinst_label_dev(sysinst_t *sysinst, const char *dev,
+    service_id_t *psvc_id)
 {
 	fdisk_t *fdisk;
@@ -178,14 +444,15 @@
 	errno_t rc;
 
-	printf("sysinst_label_dev(): get service ID '%s'\n", dev);
+	sysinst_debug(sysinst, "sysinst_label_dev(): get service ID");
+
 	rc = loc_service_get_id(dev, &sid, 0);
 	if (rc != EOK)
 		return rc;
 
-	printf("sysinst_label_dev(): open device\n");
+	sysinst_debug(sysinst, "sysinst_label_dev(): open device");
 
 	rc = fdisk_create(&fdisk);
 	if (rc != EOK) {
-		printf("Error initializing fdisk.\n");
+		sysinst_error(sysinst, "Error initializing fdisk.");
 		return rc;
 	}
@@ -193,27 +460,30 @@
 	rc = fdisk_dev_open(fdisk, sid, &fdev);
 	if (rc != EOK) {
-		printf("Error opening device.\n");
-		return rc;
-	}
-
-	printf("sysinst_label_dev(): create mount directory\n");
+		sysinst_error(sysinst, "Error opening device.");
+		return rc;
+	}
+
+	sysinst_debug(sysinst, "sysinst_label_dev(): create mount directory");
 
 	rc = vfs_link_path(MOUNT_POINT, KIND_DIRECTORY, NULL);
-	if (rc != EOK)
-		return rc;
-
-	printf("sysinst_label_dev(): create label\n");
+	if (rc != EOK) {
+		sysinst_error(sysinst, "Error creating mount directory.");
+		return rc;
+	}
+
+	sysinst_debug(sysinst, "sysinst_label_dev(): create label");
 
 	rc = fdisk_label_create(fdev, lt_mbr);
 	if (rc != EOK) {
-		printf("Error creating label: %s.\n", str_error(rc));
-		return rc;
-	}
-
-	printf("sysinst_label_dev(): create partition\n");
+		sysinst_error(sysinst, "Error creating label.");
+		return rc;
+	}
+
+	sysinst_debug(sysinst, "sysinst_label_dev(): create partition");
 
 	rc = fdisk_part_get_max_avail(fdev, spc_pri, &capa);
 	if (rc != EOK) {
-		printf("Error getting available capacity: %s.\n", str_error(rc));
+		sysinst_error(sysinst,
+		    "Error getting available capacity.");
 		return rc;
 	}
@@ -228,5 +498,5 @@
 	rc = fdisk_part_create(fdev, &pspec, &part);
 	if (rc != EOK) {
-		printf("Error creating partition.\n");
+		sysinst_error(sysinst, "Error creating partition.");
 		return rc;
 	}
@@ -234,9 +504,9 @@
 	rc = fdisk_part_get_info(part, &pinfo);
 	if (rc != EOK) {
-		printf("Error getting partition information.\n");
-		return rc;
-	}
-
-	printf("sysinst_label_dev(): OK\n");
+		sysinst_error(sysinst, "Error getting partition information.");
+		return rc;
+	}
+
+	sysinst_debug(sysinst, "sysinst_label_dev(): OK");
 	*psvc_id = pinfo.svc_id;
 	return EOK;
@@ -245,7 +515,8 @@
 /** Set up system volume structure.
  *
- * @return EOK on success or an error code
- */
-static errno_t sysinst_setup_sysvol(void)
+ * @param sysinst System installer
+ * @return EOK on success or an error code
+ */
+static errno_t sysinst_setup_sysvol(sysinst_t *sysinst)
 {
 	errno_t rc;
@@ -264,5 +535,5 @@
 		rc = vfs_link_path(path, KIND_DIRECTORY, NULL);
 		if (rc != EOK) {
-			printf("Error creating directory '%s'.\n", path);
+			sysinst_error(sysinst, "Error creating directory.");
 			goto error;
 		}
@@ -277,5 +548,6 @@
 
 	/* Copy initial configuration files */
-	rc = futil_rcopy_contents(CFG_FILES_SRC, CFG_FILES_DEST);
+	rc = futil_rcopy_contents(sysinst->futil, CFG_FILES_SRC,
+	    CFG_FILES_DEST);
 	if (rc != EOK)
 		return rc;
@@ -292,14 +564,15 @@
  * @return EOK on success or an error code
  */
-static errno_t sysinst_copy_boot_files(void)
-{
-	errno_t rc;
-
-	printf("sysinst_copy_boot_files(): copy bootloader files\n");
-	rc = futil_rcopy_contents(BOOT_FILES_SRC, MOUNT_POINT);
-	if (rc != EOK)
-		return rc;
-
-	printf("sysinst_copy_boot_files(): OK\n");
+static errno_t sysinst_copy_boot_files(sysinst_t *sysinst)
+{
+	errno_t rc;
+
+	log_msg(LOG_DEFAULT, LVL_NOTE,
+	    "sysinst_copy_boot_files(): copy bootloader files");
+	rc = futil_rcopy_contents(sysinst->futil, BOOT_FILES_SRC, MOUNT_POINT);
+	if (rc != EOK)
+		return rc;
+
+	sysinst_debug(sysinst, "sysinst_copy_boot_files(): OK");
 	return EOK;
 }
@@ -307,7 +580,8 @@
 /** Set up configuration in the initial RAM disk.
  *
- * @return EOK on success or an error code
- */
-static errno_t sysinst_customize_initrd(void)
+ * @param sysinst System installer
+ * @return EOK on success or an error code
+ */
+static errno_t sysinst_customize_initrd(sysinst_t *sysinst)
 {
 	errno_t rc;
@@ -321,5 +595,5 @@
 	rc = rd_img_open(MOUNT_POINT "/boot/initrd.img", &rdpath, &rd);
 	if (rc != EOK) {
-		printf("Error opening initial RAM disk image.\n");
+		sysinst_error(sysinst, "Error opening initial RAM disk image.");
 		goto error;
 	}
@@ -331,24 +605,28 @@
 	}
 
-	printf("Configuring volume server.\n");
+	sysinst_debug(sysinst, "Configuring volume server.");
+
 	rc = vol_volumes_create(path, &volumes);
 	if (rc != EOK) {
-		printf("Error creating volume server configuration.\n");
+		sysinst_error(sysinst,
+		    "Error creating volume server configuration.");
 		rc = EIO;
 		goto error;
 	}
 
-	printf("Configuring volume server: look up volume\n");
+	sysinst_debug(sysinst, "Configuring volume server: look up volume");
 	rc = vol_volume_lookup_ref(volumes, INST_VOL_LABEL, &volume);
 	if (rc != EOK) {
-		printf("Error creating volume server configuration.\n");
+		sysinst_error(sysinst,
+		    "Error creating volume server configuration.");
 		rc = EIO;
 		goto error;
 	}
 
-	printf("Configuring volume server: set mount point\n");
+	sysinst_debug(sysinst, "Configuring volume server: set mount point");
 	rc = vol_volume_set_mountp(volume, INST_VOL_MP);
 	if (rc != EOK) {
-		printf("Error creating system partition configuration.\n");
+		sysinst_error(sysinst,
+		    "Error creating system partition configuration.");
 		rc = EIO;
 		goto error;
@@ -357,12 +635,14 @@
 	rc = vol_volumes_sync(volumes);
 	if (rc != EOK) {
-		printf("Error saving volume confiuration.\n");
-		goto error;
-	}
-
-	printf("Configuring volume server: delete reference\n");
+		sysinst_error(sysinst, "Error saving volume confiuration.");
+		goto error;
+	}
+
+	log_msg(LOG_DEFAULT, LVL_NOTE,
+	    "Configuring volume server: delete reference");
 	vol_volume_del_ref(volume);
 	volume = NULL;
-	printf("Configuring volume server: destroy volumes object\n");
+	log_msg(LOG_DEFAULT, LVL_NOTE,
+	    "Configuring volume server: destroy volumes object");
 	vol_volumes_destroy(volumes);
 	volumes = NULL;
@@ -370,5 +650,5 @@
 	rc = rd_img_close(rd);
 	if (rc != EOK) {
-		printf("Error closing initial RAM disk image.\n");
+		sysinst_error(sysinst, "Error closing initial RAM disk image.");
 		rc = EIO;
 		goto error;
@@ -413,8 +693,9 @@
  * Install Grub's boot blocks.
  *
+ * @param sysinst System installer
  * @param devp Disk device
  * @return EOK on success or an error code
  */
-static errno_t sysinst_copy_boot_blocks(const char *devp)
+static errno_t sysinst_copy_boot_blocks(sysinst_t *sysinst, const char *devp)
 {
 	void *boot_img;
@@ -430,27 +711,39 @@
 	errno_t rc;
 
-	printf("sysinst_copy_boot_blocks: Read boot block image.\n");
-	rc = futil_get_file(BOOT_FILES_SRC "/boot/grub/i386-pc/boot.img",
+	log_msg(LOG_DEFAULT, LVL_NOTE,
+	    "sysinst_copy_boot_blocks: Read boot block image.");
+
+	rc = futil_get_file(sysinst->futil,
+	    BOOT_FILES_SRC "/boot/grub/i386-pc/boot.img",
 	    &boot_img, &boot_img_size);
 	if (rc != EOK || boot_img_size != 512)
 		return EIO;
 
-	printf("sysinst_copy_boot_blocks: Read GRUB core image.\n");
-	rc = futil_get_file(BOOT_FILES_SRC "/boot/grub/i386-pc/core.img",
+	log_msg(LOG_DEFAULT, LVL_NOTE,
+	    "sysinst_copy_boot_blocks: Read GRUB core image.");
+
+	rc = futil_get_file(sysinst->futil,
+	    BOOT_FILES_SRC "/boot/grub/i386-pc/core.img",
 	    &core_img, &core_img_size);
 	if (rc != EOK)
 		return EIO;
 
-	printf("sysinst_copy_boot_blocks: get service ID.\n");
+	log_msg(LOG_DEFAULT, LVL_NOTE,
+	    "sysinst_copy_boot_blocks: get service ID.");
+
 	rc = loc_service_get_id(devp, &sid, 0);
 	if (rc != EOK)
 		return rc;
 
-	printf("sysinst_copy_boot_blocks: block_init.\n");
+	log_msg(LOG_DEFAULT, LVL_NOTE,
+	    "sysinst_copy_boot_blocks: block_init.");
+
 	rc = block_init(sid);
 	if (rc != EOK)
 		return rc;
 
-	printf("sysinst_copy_boot_blocks: get block size\n");
+	log_msg(LOG_DEFAULT, LVL_NOTE,
+	    "sysinst_copy_boot_blocks: get block size");
+
 	rc = block_get_bsize(sid, &bsize);
 	if (rc != EOK)
@@ -458,9 +751,11 @@
 
 	if (bsize != 512) {
-		printf("Device block size != 512.\n");
+		sysinst_error(sysinst, "Device block size != 512.");
 		return EIO;
 	}
 
-	printf("sysinst_copy_boot_blocks: read boot block\n");
+	log_msg(LOG_DEFAULT, LVL_NOTE,
+	    "sysinst_copy_boot_blocks: read boot block");
+
 	rc = block_read_direct(sid, BOOT_BLOCK_IDX, 1, bbuf);
 	if (rc != EOK)
@@ -477,5 +772,6 @@
 		--bl;
 		if ((void *)bl < core_img) {
-			printf("No block terminator in core image.\n");
+			sysinst_error(sysinst,
+			    "No block terminator in core image.");
 			return EIO;
 		}
@@ -491,10 +787,14 @@
 	set_unaligned_u64le(bbuf + grub_boot_machine_kernel_sector, core_start);
 
-	printf("sysinst_copy_boot_blocks: write boot block\n");
+	log_msg(LOG_DEFAULT, LVL_NOTE,
+	    "sysinst_copy_boot_blocks: write boot block");
+
 	rc = block_write_direct(sid, BOOT_BLOCK_IDX, 1, bbuf);
 	if (rc != EOK)
 		return EIO;
 
-	printf("sysinst_copy_boot_blocks: write core blocks\n");
+	log_msg(LOG_DEFAULT, LVL_NOTE,
+	    "sysinst_copy_boot_blocks: write core blocks");
+
 	/* XXX Must pad last block with zeros */
 	rc = block_write_direct(sid, core_start, core_blocks, core_img);
@@ -502,5 +802,7 @@
 		return EIO;
 
-	printf("sysinst_copy_boot_blocks: OK.\n");
+	log_msg(LOG_DEFAULT, LVL_NOTE,
+	    "sysinst_copy_boot_blocks: OK.");
+
 	return EOK;
 }
@@ -508,7 +810,9 @@
 /** Eject installation volume.
  *
+ * @param sysinst System installer
  * @param psvc_id Partition service ID
- */
-static errno_t sysinst_eject_dev(service_id_t part_id)
+ * @return EOK on success or an error code
+ */
+static errno_t sysinst_eject_dev(sysinst_t *sysinst, service_id_t part_id)
 {
 	vol_t *vol = NULL;
@@ -517,5 +821,5 @@
 	rc = vol_create(&vol);
 	if (rc != EOK) {
-		printf("Error contacting volume service.\n");
+		sysinst_error(sysinst, "Error contacting volume service.");
 		goto out;
 	}
@@ -523,5 +827,5 @@
 	rc = vol_part_eject(vol, part_id, vef_physical);
 	if (rc != EOK) {
-		printf("Error ejecting volume.\n");
+		sysinst_error(sysinst, "Error ejecting volume.");
 		goto out;
 	}
@@ -535,7 +839,8 @@
 /** Restart the system.
  *
- * @return EOK on success or an error code
- */
-static errno_t sysinst_restart(void)
+ * @param sysinst System installer
+ * @return EOK on success or an error code
+ */
+static errno_t sysinst_restart(sysinst_t *sysinst)
 {
 	errno_t rc;
@@ -549,5 +854,6 @@
 	rc = system_open(SYSTEM_DEFAULT, &sysinst_system_cb, NULL, &system);
 	if (rc != EOK) {
-		printf("Failed opening system control service.\n");
+		sysinst_error(sysinst,
+		    "Failed opening system control service.");
 		return rc;
 	}
@@ -556,20 +862,22 @@
 	if (rc != EOK) {
 		system_close(system);
-		printf("Failed requesting system restart.\n");
+		sysinst_error(sysinst, "Failed requesting system restart.");
 		return rc;
 	}
 
 	fibril_mutex_lock(&shutdown_lock);
-	printf("The system is shutting down...\n");
+	sysinst_debug(sysinst, "The system is shutting down...");
+
 	while (!shutdown_stopped)
 		fibril_condvar_wait(&shutdown_cv, &shutdown_lock);
 
 	if (shutdown_failed) {
-		printf("Shutdown failed.\n");
+		sysinst_error(sysinst, "Shutdown failed.");
 		system_close(system);
 		return rc;
 	}
 
-	printf("Shutdown complete. It is now safe to remove power.\n");
+	log_msg(LOG_DEFAULT, LVL_NOTE,
+	    "Shutdown complete. It is now safe to remove power.");
 
 	/* Sleep forever */
@@ -586,55 +894,59 @@
 /** Install system to a device.
  *
+ * @parma sysinst System installer
  * @param dev Device to install to.
  * @return EOK on success or an error code
  */
-static errno_t sysinst_install(const char *dev)
+static errno_t sysinst_install(sysinst_t *sysinst, const char *dev)
 {
 	errno_t rc;
 	service_id_t psvc_id;
 
-	rc = sysinst_label_dev(dev, &psvc_id);
-	if (rc != EOK)
-		return rc;
-
-	printf("FS created and mounted. Creating system directory structure.\n");
-	rc = sysinst_setup_sysvol();
-	if (rc != EOK)
-		return rc;
-
-	printf("Directories created. Copying boot files.\n");
-	rc = sysinst_copy_boot_files();
-	if (rc != EOK)
-		return rc;
-
-	printf("Boot files done. Configuring the system.\n");
-	rc = sysinst_customize_initrd();
-	if (rc != EOK)
-		return rc;
-
-	printf("Boot files done. Installing boot blocks.\n");
-	rc = sysinst_copy_boot_blocks(dev);
-	if (rc != EOK)
-		return rc;
-
-	printf("Ejecting device.\n");
-	rc = sysinst_eject_dev(psvc_id);
-	if (rc != EOK)
-		return rc;
-
-	rc = sysinst_restart();
-	if (rc != EOK)
-		return rc;
-
-	return EOK;
-}
-
-int main(int argc, char *argv[])
-{
+	sysinst_action(sysinst, "Creating device label and file system.");
+
+	rc = sysinst_label_dev(sysinst, dev, &psvc_id);
+	if (rc != EOK)
+		return rc;
+
+	sysinst_action(sysinst, "Creating system directory structure.");
+	rc = sysinst_setup_sysvol(sysinst);
+	if (rc != EOK)
+		return rc;
+
+	sysinst_action(sysinst, "Copying boot files.");
+	rc = sysinst_copy_boot_files(sysinst);
+	if (rc != EOK)
+		return rc;
+
+	sysinst_action(sysinst, "Configuring the system.");
+	rc = sysinst_customize_initrd(sysinst);
+	if (rc != EOK)
+		return rc;
+
+	sysinst_action(sysinst, "Installing boot blocks.");
+	rc = sysinst_copy_boot_blocks(sysinst, dev);
+	if (rc != EOK)
+		return rc;
+
+	sysinst_action(sysinst, "Ejecting device.");
+	rc = sysinst_eject_dev(sysinst, psvc_id);
+	if (rc != EOK)
+		return rc;
+
+	return EOK;
+}
+
+/** Installation fibril.
+ *
+ * @param arg Argument (sysinst_t *)
+ * @return EOK on success or an error code
+ */
+static errno_t sysinst_install_fibril(void *arg)
+{
+	sysinst_t *sysinst = (sysinst_t *)arg;
 	unsigned i;
 	errno_t rc;
 
-	if (argc > 1 && str_cmp(argv[1], "-r") == 0)
-		restart = true;
+	(void)sysinst;
 
 	i = 0;
@@ -647,9 +959,430 @@
 
 	if (default_devs[i] == NULL) {
-		printf("Cannot determine installation device.\n");
+		sysinst_error(sysinst, "Cannot determine installation device.");
+		rc = ENOENT;
+		goto error;
+	}
+
+	rc = sysinst_install(sysinst, default_devs[i]);
+	if (rc != EOK)
+		goto error;
+
+	sysinst_progress_destroy(sysinst->progress);
+	rc = sysinst_restart_dlg_create(sysinst);
+	if (rc != EOK)
+		goto error;
+
+	return EOK;
+error:
+	ui_lock(sysinst->ui);
+	sysinst_progress_destroy(sysinst->progress);
+	(void)sysinst_error_msg_create(sysinst);
+	ui_unlock(sysinst->ui);
+	return rc;
+}
+
+/** Create installation progress window.
+ *
+ * @param sysinst System installer
+ * @param rprogress Place to store pointer to new progress window
+ * @return EOK on success or an error code
+ */
+static errno_t sysinst_progress_create(sysinst_t *sysinst,
+    sysinst_progress_t **rprogress)
+{
+	ui_wnd_params_t params;
+	ui_window_t *window = NULL;
+	gfx_rect_t rect;
+	gfx_rect_t arect;
+	ui_resource_t *ui_res;
+	sysinst_progress_t *progress;
+	ui_fixed_t *fixed = NULL;
+	errno_t rc;
+
+	ui_wnd_params_init(&params);
+	params.caption = "System Installation";
+	params.style &= ~ui_wds_titlebar;
+	params.flags |= ui_wndf_topmost;
+	params.placement = ui_wnd_place_center;
+	if (ui_is_textmode(sysinst->ui)) {
+		params.rect.p0.x = 0;
+		params.rect.p0.y = 0;
+		params.rect.p1.x = 64;
+		params.rect.p1.y = 5;
+	} else {
+		params.rect.p0.x = 0;
+		params.rect.p0.y = 0;
+		params.rect.p1.x = 500;
+		params.rect.p1.y = 60;
+	}
+
+	progress = calloc(1, sizeof(sysinst_progress_t));
+	if (progress == NULL) {
+		rc = ENOMEM;
+		sysinst_error(sysinst, "Out of memory.");
+		goto error;
+	}
+
+	rc = ui_window_create(sysinst->ui, &params, &window);
+	if (rc != EOK) {
+		sysinst_error(sysinst, "Error creating window.");
+		goto error;
+	}
+
+	ui_window_set_cb(window, &progress_window_cb, (void *)sysinst);
+
+	ui_res = ui_window_get_res(window);
+
+	rc = ui_fixed_create(&fixed);
+	if (rc != EOK) {
+		sysinst_error(sysinst, "Error creating fixed layout.");
+		goto error;
+	}
+
+	rc = ui_label_create(ui_res, "Installing system. Please wait...",
+	    &progress->label);
+	if (rc != EOK) {
+		sysinst_error(sysinst, "Error creating label.");
+		goto error;
+	}
+
+	ui_window_get_app_rect(window, &arect);
+
+	if (ui_is_textmode(sysinst->ui)) {
+		rect.p0.x = arect.p0.x;
+		rect.p0.y = arect.p0.y;
+		rect.p1.x = arect.p1.x;
+		rect.p1.y = 2;
+	} else {
+		rect.p0.x = arect.p0.x;
+		rect.p0.y = arect.p0.y;
+		rect.p1.x = arect.p1.x;
+		rect.p1.y = 30;
+	}
+	ui_label_set_rect(progress->label, &rect);
+	ui_label_set_halign(progress->label, gfx_halign_center);
+	ui_label_set_valign(progress->label, gfx_valign_center);
+
+	rc = ui_fixed_add(fixed, ui_label_ctl(progress->label));
+	if (rc != EOK) {
+		sysinst_error(sysinst, "Error adding control to layout.");
+		ui_label_destroy(progress->label);
+		progress->label = NULL;
+		goto error;
+	}
+
+	rc = ui_label_create(ui_res, "",
+	    &progress->action);
+	if (rc != EOK) {
+		sysinst_error(sysinst, "Error creating label.");
+		goto error;
+	}
+
+	if (ui_is_textmode(sysinst->ui)) {
+		rect.p0.x = arect.p0.x;
+		rect.p0.y = 3;
+		rect.p1.x = arect.p1.x;
+		rect.p1.y = arect.p1.y;
+	} else {
+		rect.p0.x = arect.p0.x;
+		rect.p0.y = 30;
+		rect.p1.x = arect.p1.x;
+		rect.p1.y = arect.p1.y;
+	}
+	ui_label_set_rect(progress->action, &rect);
+	ui_label_set_halign(progress->action, gfx_halign_center);
+	ui_label_set_valign(progress->action, gfx_valign_center);
+
+	rc = ui_fixed_add(fixed, ui_label_ctl(progress->action));
+	if (rc != EOK) {
+		sysinst_error(sysinst, "Error adding control to layout.");
+		ui_label_destroy(progress->label);
+		progress->label = NULL;
+		goto error;
+	}
+
+	ui_window_add(window, ui_fixed_ctl(fixed));
+	fixed = NULL;
+
+	rc = ui_window_paint(window);
+	if (rc != EOK) {
+		sysinst_error(sysinst, "Error painting window.");
+		goto error;
+	}
+
+	progress->window = window;
+	progress->fixed = fixed;
+	*rprogress = progress;
+	return EOK;
+error:
+	if (progress != NULL && progress->fixed != NULL)
+		ui_fixed_destroy(progress->fixed);
+	if (window != NULL)
+		ui_window_destroy(window);
+	if (progress != NULL)
+		free(progress);
+	return rc;
+}
+
+/** Destroy installation progress window.
+ *
+ * @param sysinst System installer
+ * @param rprogress Place to store pointer to new progress window
+ * @return EOK on success or an error code
+ */
+static void sysinst_progress_destroy(sysinst_progress_t *progress)
+{
+	if (progress == NULL)
+		return;
+
+	ui_window_destroy(progress->window);
+	free(progress);
+}
+
+/** Set current action message.
+ *
+ * @param sysinst System installer
+ * @param action Action text
+ */
+static void sysinst_action(sysinst_t *sysinst, const char *action)
+{
+	if (sysinst->progress == NULL)
+		return;
+
+	ui_label_set_text(sysinst->progress->action, action);
+	ui_label_paint(sysinst->progress->action);
+	log_msg(LOG_DEFAULT, LVL_NOTE, "%s", action);
+}
+
+/** Set current error message.
+ *
+ * @param sysinst System installer
+ * @param errmsg Error message
+ */
+static void sysinst_error(sysinst_t *sysinst, const char *errmsg)
+{
+	str_cpy(sysinst->errmsg, sizeof(sysinst->errmsg), errmsg);
+	log_msg(LOG_DEFAULT, LVL_ERROR, errmsg);
+}
+
+/** Log a debug message.
+ *
+ * @param sysinst System installer
+ * @param errmsg Error message
+ */
+static void sysinst_debug(sysinst_t *sysinst, const char *msg)
+{
+	log_msg(LOG_DEFAULT, LVL_ERROR, msg);
+}
+
+/** Start system installation.
+ *
+ * @param sysinst System installer
+ * @return EOK on success or an error code
+ */
+static int sysinst_start(sysinst_t *sysinst)
+{
+	errno_t rc;
+	fid_t fid;
+
+	rc = sysinst_progress_create(sysinst, &sysinst->progress);
+	if (rc != EOK)
+		return rc;
+
+	fid = fibril_create(sysinst_install_fibril, (void *)sysinst);
+	if (fid == 0) {
+		sysinst_error(sysinst, "Out of memory.");
+		return ENOMEM;
+	}
+
+	fibril_add_ready(fid);
+	return EOK;
+}
+
+/** Create installation confirmation dialog.
+ *
+ * @param sysinst System installer
+ * @return EOK on success or an error code
+ */
+static errno_t sysinst_confirm_create(sysinst_t *sysinst)
+{
+	ui_msg_dialog_params_t params;
+	ui_msg_dialog_t *dialog;
+	errno_t rc;
+
+	ui_msg_dialog_params_init(&params);
+	params.caption = "System installation";
+	params.text = "This will install HelenOS to your computer. Continue?";
+	params.choice = umdc_ok_cancel;
+	params.flags |= umdf_topmost | umdf_center;
+
+	rc = ui_msg_dialog_create(sysinst->ui, &params, &dialog);
+	if (rc != EOK)
+		return rc;
+
+	ui_msg_dialog_set_cb(dialog, &sysinst_confirm_cb, sysinst);
+	return EOK;
+}
+
+/** Create restart dialog.
+ *
+ * @param sysinst System installer
+ * @return EOK on success or an error code
+ */
+static errno_t sysinst_restart_dlg_create(sysinst_t *sysinst)
+{
+	ui_msg_dialog_params_t params;
+	ui_msg_dialog_t *dialog;
+	errno_t rc;
+
+	ui_msg_dialog_params_init(&params);
+	params.caption = "Restart System";
+	params.text = "Installation complete. Restart the system?";
+	params.choice = umdc_ok_cancel;
+	params.flags |= umdf_topmost | umdf_center;
+
+	rc = ui_msg_dialog_create(sysinst->ui, &params, &dialog);
+	if (rc != EOK)
+		return rc;
+
+	ui_msg_dialog_set_cb(dialog, &sysinst_restart_dlg_cb, sysinst);
+	return EOK;
+}
+
+/** Run system installer on display.
+ *
+ * @param display_spec Display specification
+ * @return EOK on success or an error code
+ */
+static errno_t sysinst_run(const char *display_spec)
+{
+	ui_t *ui = NULL;
+	sysinst_t *sysinst;
+	ui_wnd_params_t params;
+	errno_t rc;
+
+	sysinst = calloc(1, sizeof(sysinst_t));
+	if (sysinst == NULL)
+		return ENOMEM;
+
+	rc = futil_create(&sysinst_futil_cb, (void *)sysinst, &sysinst->futil);
+	if (rc != EOK) {
+		printf("Out of memory.\n");
+		goto error;
+	}
+
+	rc = ui_create(display_spec, &ui);
+	if (rc != EOK) {
+		printf("Error creating UI on display %s.\n", display_spec);
+		goto error;
+	}
+
+	sysinst->ui = ui;
+
+	ui_wnd_params_init(&params);
+	params.caption = "System Installation";
+	params.style &= ~ui_wds_decorated;
+	params.placement = ui_wnd_place_full_screen;
+	params.flags |= ui_wndf_topmost | ui_wndf_nofocus;
+
+	rc = ui_window_create(sysinst->ui, &params, &sysinst->bgwindow);
+	if (rc != EOK) {
+		printf("Error creating window.\n");
+		goto error;
+	}
+
+	ui_window_set_cb(sysinst->bgwindow, &bg_window_cb, (void *)sysinst);
+
+	if (ui_is_textmode(sysinst->ui)) {
+		rc = gfx_color_new_ega(0x17, &sysinst->bg_color);
+		if (rc != EOK) {
+			printf("Error allocating color.\n");
+			goto error;
+		}
+	} else {
+		rc = gfx_color_new_rgb_i16(0x8000, 0xc800, 0xffff, &sysinst->bg_color);
+		if (rc != EOK) {
+			printf("Error allocating color.\n");
+			goto error;
+		}
+	}
+
+	rc = ui_window_paint(sysinst->bgwindow);
+	if (rc != EOK) {
+		printf("Error painting window.\n");
+		goto error;
+	}
+
+	(void)sysinst_confirm_create(sysinst);
+
+	ui_run(ui);
+
+	if (sysinst->bgwindow != NULL)
+		ui_window_destroy(sysinst->bgwindow);
+	if (sysinst->system != NULL)
+		system_close(sysinst->system);
+	gfx_color_delete(sysinst->bg_color);
+	ui_destroy(ui);
+	free(sysinst);
+	return EOK;
+error:
+	if (sysinst->futil != NULL)
+		futil_destroy(sysinst->futil);
+	if (sysinst->system != NULL)
+		system_close(sysinst->system);
+	if (sysinst->bg_color != NULL)
+		gfx_color_delete(sysinst->bg_color);
+	if (sysinst->bgwindow != NULL)
+		ui_window_destroy(sysinst->bgwindow);
+	if (ui != NULL)
+		ui_destroy(ui);
+	free(sysinst);
+	return rc;
+}
+
+static void print_syntax(void)
+{
+	printf("Syntax: " NAME " [-d <display-spec>]\n");
+}
+
+int main(int argc, char *argv[])
+{
+	const char *display_spec = UI_ANY_DEFAULT;
+	errno_t rc;
+	int i;
+
+	i = 1;
+	while (i < argc && argv[i][0] == '-') {
+		if (str_cmp(argv[i], "-d") == 0) {
+			++i;
+			if (i >= argc) {
+				printf("Argument missing.\n");
+				print_syntax();
+				return 1;
+			}
+
+			display_spec = argv[i++];
+		} else {
+			printf("Invalid option '%s'.\n", argv[i]);
+			print_syntax();
+			return 1;
+		}
+	}
+
+	if (i < argc) {
+		print_syntax();
 		return 1;
 	}
 
-	return sysinst_install(default_devs[i]);
+	if (log_init(NAME) != EOK) {
+		printf(NAME ": Failed to initialize logging.\n");
+		return 1;
+	}
+
+	rc = sysinst_run(display_spec);
+	if (rc != EOK)
+		return 1;
+
+	return 0;
 }
 
