[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [Fedora-livecd-list] goals/status?



On Sun, 2006-10-22 at 01:26 -0500, Jasper Hartline wrote:
> One of Kadischi's priorities are installing a system from a LiveCD.

Sorry, but I don't think just running anaconda from a live cd
environment consuming RPM packages shipped side-by-side with the live cd
file system qualifies as "installable livecd". At least you can't do
anything interesting in 700MB without requiring network access. 

For the record, I do have an "installable livecd" with pilgrim now
though the code needs to be cleaned up, see attached for current code
dump. It should be self-explanatory more or less. With this I'm able to
install from the LiveCD in ca. 5-6 minutes. It works pretty nice... but
then again, I don't have much time (nor the inclination but that's
another matter) to hack on this (let alone time to participate on this
list) these days but at least I was hoping someone would pick up this
train of thought as I do believe the current Kadischi livecd
installation is sub optimal.

So.. It's a little sad we can't seem to find agreement on the simple
definition of what a "installable livecd" is... and I still do think
that doing work which is clearly not on par with the distributions that
Fedora competes with... is not the path we want Fedora to be on.
Something for Greg and co. to think about I guess.

Anyway, enough flaming from me. Perfect is the enemy of the Good or
whatever it is they say. Good luck.

     David

#!/usr/bin/python -t

import dbus
import dbus.service
import dbus.glib
import gobject
import os
import subprocess

class LiveCDInstaller(dbus.service.Object):
    def __init__(self, bus_name):
        dbus.service.Object.__init__(self,
                                     bus_name,
                                     "/com/redhat/LiveCDInstaller")

    def cleanupIso(self):
        os.system("/bin/umount /mnt/puritan_squash")
        os.system("/sbin/losetup -d /dev/loop4")
        os.system("/bin/umount /mnt/puritan_iso")
        os.system("/sbin/losetup -d /dev/loop3")
        os.system("/bin/rmdir /mnt/puritan_squash")
        os.system("/bin/rmdir /mnt/puritan_iso")

    def cleanupTarget(self):
        bind_mount = ["dev", "dev/pts", "dev/shm", "proc", "sys", "selinux"]
        bind_mount.reverse()
        for b in bind_mount:
            os.system("/bin/umount /mnt/puritan_target/" + b)
        os.system("/bin/umount /mnt/puritan_target")
        os.system("/bin/rmdir /mnt/puritan_target")

    @dbus.service.signal("com.redhat.LiveCDInstaller", signature = "ssttd")
    def InstallActivityChanged(self,
                               activity_id,                # string
                               activity_obj_name,          # string
                               activity_obj_pos,           # uint64
                               activity_obj_size,          # uint64
                               activity_overall_progress): # double
        pass

    @dbus.service.method("com.redhat.LiveCDInstaller",
                         in_signature="ssstsbs",
                         out_signature = "")
    def Install(self,
                sourceIso,       # string
                diskDeviceFile,  # string
                swapDeviceFile,  # string
                swapFileSize,    # uint64
                rootDeviceFile,  # string
                useMBR,          # boolean
                rootPassword):   # string
        print "sourceIso      ", sourceIso
        print "diskDeviceFile ", diskDeviceFile
        print "swapDeviceFile ", swapDeviceFile
        print "swapFileSize   ", swapFileSize
        print "rootDeviceFile ", rootDeviceFile
        print "useMBR         ", useMBR
        print "rootPassword   ", rootPassword

        osImage = "/mnt/squashfs/os.img"

        # todo: sanity check parameters

        # Figure out grub device name
        grubDevNumber=int(rootDeviceFile[diskDeviceFile.__len__():]) - 1
        grubDev="(hd0,%s)"%grubDevNumber


        self.InstallActivityChanged("starting",
                                    "",
                                    0,
                                    0,
                                    -1.0)

        # Copy image
        try:
            if sourceIso != "":
                self.InstallActivityChanged("mounting-iso", "", 0, 0, -1.0)
                if os.system("mkdir /mnt/puritan_iso") != 0:
                    raise Exception()
                if os.system("mkdir /mnt/puritan_squash") != 0:
                    raise Exception()
                if os.system("/sbin/losetup /dev/loop3 " + sourceIso) != 0:
                    raise Exception()
                if os.system("/bin/mount -t iso9660 -o ro /dev/loop3 /mnt/puritan_iso") != 0:
                    raise Exception()
                if os.system("/sbin/losetup /dev/loop4 /mnt/puritan_iso/squashfs.img") != 0:
                    raise Exception()
                if os.system("/bin/mount -t squashfs -o ro /dev/loop4 /mnt/puritan_squash") != 0:
                    raise Exception()
                osImage = "/mnt/puritan_squash/os.img"

            print "Using OS image '%s'"%osImage

            osImageSize = os.stat(osImage).st_size
            print osImageSize

            self.InstallActivityChanged(
                "copying-payload",
                "",
                0,
                osImageSize/1048576,
                0.0)


            srcFd = os.open(osImage, os.O_RDONLY)
            if (srcFd < 0):
                raise Exception()
            os.lseek (srcFd, 31744, 0)

            dstFd = os.open(rootDeviceFile, os.O_RDWR)
            if (dstFd < 0):
                os.close(srcFd)
                raise Exception()


            numBytesCopied = 0
            len = 1
            while len > 0:
                buf = os.read(srcFd, 5 * 1024*1024)
                len = os.write(dstFd, buf)
                numBytesCopied = numBytesCopied + len

                self.InstallActivityChanged(
                    "copying-payload",
                    "",
                    numBytesCopied,
                    osImageSize,
                    1.0 * numBytesCopied / osImageSize)

            os.close(srcFd)
            os.close(dstFd)

        except Exception, e:
            if sourceIso != "":
                self.cleanupIso()
            raise e

        if sourceIso != "":
            self.cleanupIso()

        self.InstallActivityChanged("checking-rootfs",
                                    "",
                                    0,
                                    0,
                                    -1.0)

        # fix up rootfs (resize, label, uuid)
        os.system("/sbin/e2fsck -f " + rootDeviceFile)
        uuid = subprocess.Popen(["/usr/bin/uuidgen"], stdout=subprocess.PIPE).communicate()[0].strip()
        os.system("/sbin/tune2fs -U " + uuid + " " + rootDeviceFile)
        os.system("/sbin/tune2fs -L " + "\"Fedora Core\"" + " " + rootDeviceFile)

        self.InstallActivityChanged("resizing-rootfs",
                                    "",
                                    0,
                                    0,
                                    -1.0)

        os.system("/sbin/resize2fs " + rootDeviceFile)

        # mount rootfs and configure it for installed environment
        try:
            if os.system("mkdir /mnt/puritan_target") != 0:
                raise Exception()
            if os.system("/bin/mount " + rootDeviceFile + " /mnt/puritan_target") != 0:
                raise Exception()

            bind_mount = ["dev", "dev/pts", "dev/shm", "proc", "sys", "selinux"]
            for b in bind_mount:
                if os.system("/bin/mount --bind /" + b  + " /mnt/puritan_target/" + b) != 0:
                    raise Exception()

            os.system("/bin/rm -f /mnt/puritan_target/etc/mtab")
            os.system("/bin/rm -f /mnt/puritan_target/etc/resolv.conf")
            os.system("/bin/ln -s ../proc/mounts /mnt/puritan_target/etc/mtab")
            os.system("/bin/cp /etc/resolv.conf /mnt/puritan_target/etc/resolv.conf")

            self.InstallActivityChanged("creating-swap",
                                        "",
                                        0,
                                        0,
                                        -1.0)

            # create swap (swapfile or swap device)
            if swapFileSize > 0:
                os.system("/usr/sbin/chroot /mnt/puritan_target dd if=/dev/zero of=/var/cache/SWAP bs=1048576 count=%s"%(swapFileSize / 1048576))
                os.system("/usr/sbin/chroot /mnt/puritan_target /sbin/mkswap /var/cache/SWAP")
                os.system("/usr/sbin/chroot /mnt/puritan_target /sbin/setfiles /etc/selinux/targeted/contexts/files/file_contexts /var/cache/SWAP")
            elif swapDeviceFile != "":
                swap_label = "SWAP-" + subprocess.Popen(["/usr/bin/uuidgen"], stdout=subprocess.PIPE).communicate()[0].strip()[0:10]
                os.system("/usr/sbin/chroot /mnt/puritan_target /sbin/mkswap -L " + swap_label + " " + swapDeviceFile)

            self.InstallActivityChanged("post-install-configuration",
                                        "",
                                        0,
                                        0,
                                        -1.0)

            # write out /etc/fstab
            fstab = open("/mnt/puritan_target/etc/fstab", "w")
            fstab.write("UUID=%s  /    ext3    defaults        1 1\n"%uuid)
            if swapDeviceFile != "":
                fstab.write("LABEL=%s   swap                    swap    defaults        0 0\n"%swap_label)
            else:
                fstab.write("/var/cache/SWAP         swap                    swap    defaults        0 0\n")
            fstab.write("devpts                  /dev/pts                devpts  gid=5,mode=620  0 0\n")
            fstab.write("tmpfs                   /dev/shm                tmpfs   defaults        0 0\n")
            fstab.write("proc                    /proc                   proc    defaults        0 0\n")
            fstab.write("sysfs                   /sys                    sysfs   defaults        0 0\n")
            fstab.close()

            # clean up after livecd
            os.system("rm -f /mnt/puritan_target/boot/vmlinuz")
            os.system("rm -f /mnt/puritan_target/boot/initrd.img")
            os.system("rm -f /mnt/puritan_target/etc/udev/rules.d/00-livecd.rules")
            os.system("rm -f /mnt/puritan_target/etc/init.d/livecd")
            os.system("rm -f /mnt/puritan_target/etc/rc5.d/S00livecd")

            # guaranteed to only have one kernel installed at this point
            kver = subprocess.Popen(["/bin/ls", "/mnt/puritan_target/lib/modules/"], stdout=subprocess.PIPE).communicate()[0].strip()
            print "Kernel version is %s"%kver

            self.InstallActivityChanged("creating-initramfs",
                                        "",
                                        0,
                                        0,
                                        -1.0)

            # mkinitrd uses /etc/mtab to find rootfs
            os.system("/bin/rm -f /mnt/puritan_target/etc/mtab")
            mtab = open("/mnt/puritan_target/etc/mtab", "w")
            mtab.write("%s / ext3 rw 0 0\n"%rootDeviceFile)
            mtab.close()

            # create new initramfs
            os.system("/usr/sbin/chroot /mnt/puritan_target /sbin/mkinitrd -v --with=usb-storage -f /boot/initrd-%s.img %s"%(kver, kver))


            self.InstallActivityChanged("installing-bootloader",
                                        "",
                                        0,
                                        0,
                                        -1.0)

            # create grub.conf (see above how grubDev is computed)
            grub = open("/mnt/puritan_target/boot/grub/grub.conf", "w")
            grub.write("default=0\n")
            grub.write("timeout=5\n")
            grub.write("splashimage=%s/boot/grub/splash.xpm.gz\n"%grubDev)
            grub.write("hiddenmenu\n")
            grub.write("title Fedora Core (%s)\n"%kver)
            grub.write("    root %s\n"%grubDev)
            grub.write("    kernel /boot/vmlinuz-%s ro quiet root=UUID=%s\n"%(kver, uuid))
            grub.write("    initrd /boot/initrd-%s.img\n"%kver)
            grub.close()
            os.system("rm -f /mnt/puritan_target/etc/grub.conf")
            os.system("ln -s ../boot/grub/grub.conf /mnt/puritan_target/etc/grub.conf")
            os.system("cat /mnt/puritan_target/etc/grub.conf")

            # install grub
            if useMBR:
                grubMbrParam = "(hd0)"
            else:
                grubMbrParam = grubDev
            f = os.popen("/usr/sbin/chroot /mnt/puritan_target /sbin/grub  --verbose --batch --device-map=/dev/null", "w")
            f.write("device (hd0) %s\n"%diskDeviceFile)
            f.write("root %s\n"%grubDev)
            f.write("setup --stage2=/boot/grub/stage2 --prefix=/boot/grub %s\n"%grubMbrParam)
            f.write("quit\n")
            f.flush()
            f.close()

            # as a final thing... clean up mtab and resolv.conf
            os.system("/bin/rm -f /mnt/puritan_target/etc/mtab")
            os.system("/bin/touch /mnt/puritan_target/etc/mtab")
            os.system("/bin/rm -f /mnt/puritan_target/etc/resolv.conf")
            os.system("/bin/touch /mnt/puritan_target/etc/resolv.conf")

        except Exception, e:
            self.cleanupTarget()
            raise e
        self.cleanupTarget()

        self.InstallActivityChanged("finished",
                                    "",
                                    0,
                                    0,
                                    -1.0)
        print "=== Done with installation"
        print ""


def lockHalDrive(drive_path):
    bus = dbus.SystemBus()

    hal_manager = dbus.Interface(bus.get_object("org.freedesktop.Hal",
                                                "/org/freedesktop/Hal/Manager"),
                                 "org.freedesktop.Hal.Manager")
    storage_udis = hal_manager.FindDeviceStringMatch("block.device", drive_path)

    if len(storage_udis) != 1:
        raise Exception()

    storage_udi = storage_udis[0]

    hal_drive_device = dbus.Interface(bus.get_object("org.freedesktop.Hal",
                                                storage_udi),
                                      "org.freedesktop.Hal.Device")
    got_lock = hal_drive_device.Lock("Installing to drive")

    

def main():
    gobject.threads_init()
    dbus.glib.threads_init()

    bus = dbus.SystemBus()
    name = dbus.service.BusName("com.redhat.LiveCDInstaller", bus=bus)
    object = LiveCDInstaller(name)

    lockHalDrive("/dev/sdb");

    mainloop = gobject.MainLoop()
    mainloop.run()

if __name__ == "__main__":
    main()

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]