int diskutil_grub_files(const char *mnt_pt, const int part, const char *kernel, const char *ramdisk)
{
    char *output = NULL;
    char *kfile = "euca-vmlinuz";
    char *rfile = "euca-initrd";
    char buf[1024] = { 0 };
    char buf2[1024] = { 0 };
    char initrd[1024] = { 0 };
    char grub_conf_path[EUCA_MAX_PATH] = { 0 };
    char menu_lst_path[EUCA_MAX_PATH] = { 0 };

    if (mnt_pt && kernel) {
        LOGINFO("installing kernel and ramdisk\n");
        output = pruntf(TRUE, "%s %s -p %s/boot/grub/", helpers_path[ROOTWRAP], helpers_path[MKDIR], mnt_pt);
        if (!output) {
            LOGERROR("failed to create grub directory\n");
            return (EUCA_ERROR);
        }
        EUCA_FREE(output);

        if (grub_version == 1) {
            output = pruntf(TRUE, "%s %s %s/*stage* %s/boot/grub", helpers_path[ROOTWRAP], helpers_path[CP], stage_files_dir, mnt_pt);
            if (!output) {
                LOGERROR("failed to copy stage files into grub directory\n");
                return (EUCA_ERROR);
            }
            EUCA_FREE(output);
        }

        output = pruntf(TRUE, "%s %s %s %s/boot/%s", helpers_path[ROOTWRAP], helpers_path[CP], kernel, mnt_pt, kfile);
        if (!output) {
            LOGERROR("failed to copy the kernel to boot directory\n");
            return (EUCA_ERROR);
        }
        EUCA_FREE(output);

        if (ramdisk) {
            output = pruntf(TRUE, "%s %s %s %s/boot/%s", helpers_path[ROOTWRAP], helpers_path[CP], ramdisk, mnt_pt, rfile);
            if (!output) {
                LOGERROR("failed to copy the ramdisk to boot directory\n");
                return (EUCA_ERROR);
            }
            EUCA_FREE(output);
        }

        if (grub_version == 1) {
            snprintf(menu_lst_path, sizeof(menu_lst_path), "%s/boot/grub/menu.lst", mnt_pt);
            snprintf(grub_conf_path, sizeof(grub_conf_path), "%s/boot/grub/grub.conf", mnt_pt);

            snprintf(buf, sizeof(buf), "default=0\n" "timeout=2\n\n" "title TheOS\n" "root (hd0,%d)\n" "kernel /boot/%s root=/dev/sda1 ro\n", part, kfile); // grub 1 expects 0 for first partition
            if (ramdisk) {
                snprintf(buf2, sizeof(buf2), "initrd /boot/%s\n", rfile);
                strncat(buf, buf2, sizeof(buf) - 1);
            }

            if (diskutil_write2file(menu_lst_path, buf) != EUCA_OK) {
                return (EUCA_ERROR);
            }

        } else if (grub_version == 2) {
            snprintf(grub_conf_path, sizeof(grub_conf_path), "%s/boot/grub/grub.cfg", mnt_pt);
            if (ramdisk) {
                snprintf(initrd, sizeof(initrd), "  initrd /boot/%s\n", rfile);
            }
            snprintf(buf, sizeof(buf), "set default=0\n" "set timeout=2\n" "insmod part_msdos\n" "insmod ext2\n" "set root='(hd0,%d)'\n" "menuentry 'TheOS' --class os {\n" "  linux /boot/%s root=/dev/sda1 ro\n" "%s" "}\n", part + 1, kfile, initrd);    // grub 2 expects 1 for first partition
        }

        if (diskutil_write2file(grub_conf_path, buf) != EUCA_OK) {
            return (EUCA_ERROR);
        }

        return (EUCA_OK);
    }

    return (EUCA_INVALID_ERROR);
}
int diskutil_grub_files(const char *mnt_pt, const int part, const char *kernel, const char *ramdisk)
{
    char *output = NULL;
    char *kfile = "euca-vmlinuz";
    char *rfile = "euca-initrd";
    char buf[1024] = { 0 };
    char buf2[1024] = { 0 };
    char initrd[1024] = { 0 };
    char grub_conf_path[EUCA_MAX_PATH] = { 0 };
    char menu_lst_path[EUCA_MAX_PATH] = { 0 };

    if (mnt_pt && kernel) {
        LOGINFO("installing kernel and ramdisk\n");
        output = pruntf(TRUE, "%s %s -p %s/boot/grub/", helpers_path[ROOTWRAP], helpers_path[MKDIR], mnt_pt);
        if (!output) {
            LOGERROR("failed to create grub directory\n");
            return (EUCA_ERROR);
        }
        EUCA_FREE(output);

        if (grub_version == 1) {
            output = pruntf(TRUE, "%s %s %s/*stage* %s/boot/grub", helpers_path[ROOTWRAP], helpers_path[CP], stage_files_dir, mnt_pt);
            if (!output) {
                LOGERROR("failed to copy stage files into grub directory\n");
                return (EUCA_ERROR);
            }
            EUCA_FREE(output);
        }

        output = pruntf(TRUE, "%s %s %s %s/boot/%s", helpers_path[ROOTWRAP], helpers_path[CP], kernel, mnt_pt, kfile);
        if (!output) {
            LOGERROR("failed to copy the kernel to boot directory\n");
            return (EUCA_ERROR);
        }
        EUCA_FREE(output);

        if (ramdisk) {
            output = pruntf(TRUE, "%s %s %s %s/boot/%s", helpers_path[ROOTWRAP], helpers_path[CP], ramdisk, mnt_pt, rfile);
            if (!output) {
                LOGERROR("failed to copy the ramdisk to boot directory\n");
                return (EUCA_ERROR);
            }
            EUCA_FREE(output);
        }

        if (grub_version == 1) {
            snprintf(menu_lst_path, sizeof(menu_lst_path), "%s/boot/grub/menu.lst", mnt_pt);
            snprintf(grub_conf_path, sizeof(grub_conf_path), "%s/boot/grub/grub.conf", mnt_pt);

            snprintf(buf, sizeof(buf), "default=0\n" "timeout=2\n\n" "title TheOS\n" "root (hd0,%d)\n" "kernel /boot/%s root=/dev/sda1 ro\n", part, kfile);  
            if (ramdisk) {
                snprintf(buf2, sizeof(buf2), "initrd /boot/%s\n", rfile);
                strncat(buf, buf2, sizeof(buf) - 1);
            }

            if (diskutil_write2file(menu_lst_path, buf) != EUCA_OK) {
                return (EUCA_ERROR);
            }

        } else if (grub_version == 2) {
            snprintf(grub_conf_path, sizeof(grub_conf_path), "%s/boot/grub/grub.cfg", mnt_pt);
            if (ramdisk) {
                snprintf(initrd, sizeof(initrd), "  initrd /boot/%s\n", rfile);
            }
            snprintf(buf, sizeof(buf), "set default=0\n" "set timeout=2\n" "insmod part_msdos\n" "insmod ext2\n" "set root='(hd0,%d)'\n" "menuentry 'TheOS' --class os {\n" "  linux /boot/%s root=/dev/sda1 ro\n" "%s" "}\n", part + 1, kfile, initrd);     
        }

        if (diskutil_write2file(grub_conf_path, buf) != EUCA_OK) {
            return (EUCA_ERROR);
        }

        return (EUCA_OK);
    }

    return (EUCA_INVALID_ERROR);
}