1. Moises Henriquez
  2. vinstall

Commits

M0E-lnx  committed 7e245d7

Add bootloader fixes, fix bug on fstab entries and adjust automatic.py to implement bootloader features

  • Participants
  • Parent commits 6ce1fc9
  • Branches master

Comments (0)

Files changed (3)

File vinstall/backend/bootloader.py

View file
 import subprocess, os, shutil
 from StringIO import StringIO
 from vinstall.backend import utils, media
+import os
+import tempfile
+import unittest
 
 
 LILO = object()
         self.config_path = "/etc/default/grub"
         self.type = GRUB2
         self.timeout = timeout
+        self.target = target
         self.vga_mode = None
     
     def set_vga_mode(self, resolution="800x600"):
                 "1280x1024": "1280x1024x16"}
         self.vga_mode = modes.get(resolution, "800x600")
 
-    def write_config(self):
+    def write_config(self, filepath="/etc/default/grub"):
         """The grub2 config file is automatically generated, so we use
         this method to save the values to /etc/default/grub which is 
         parsed while the config file is generated 
         
         """
-        f = open(self.config_path)
-        data = f.readlines()
-        f.close()
-        ndata = []
 
         # set the correct vga_mode value
         if not self.vga_mode:
             self.set_vga_mode()
-        
-        # check to make sure the file has the variables we need to set
-        vga = False
-        timeout = False
-        for line in data:
-            if "GRUB_GFXMODE=" in line:
-                vga = True
-            elif "GRUB_TIMEOUT=" in line:
-                timeout = True
-        
-        # Add the lines if we dont have them
-        if not vga:
-            data.append("GRUB_GFXMODE=\n")
-        if not timeout:
-            data.append("GRUB_TIMEOUT=\n")
-
-        # save the variables.
-        for line in data:
-            if "GRUB_GFXMODE=" in line:
-                line = "GRUB_GFXMODE=%s\n" % str(self.vga_mode)
-            elif "GRUB_TIMEOUT=" in line:
-                line = "GRUB_TIMEOUT=%s\n" % str(self.timeout)
-            ndata.append(line)
-
-        # make a backup copy of the file
-        bk = "%s.bak"% (self.config_path)
-        shutil.copy2(self.config_path, bk)
+
+        ndata = ["export GRUB_GFXMODE=%s"% self.vga_mode,
+                 "export GRUB_TERMINAL=gfxterm",
+                 "export GRUB_DISABLE_LINUX_UUID=true",
+                 "export GRUB_TIMEOUT=%s"% self.timeout,
+                 "if [ \"$GRUB_GFXMODE\" = \"1024x768x16\" ]; then",
+                 "    VGA=791 ",
+                 "elif [ \"$GRUB_GFXMODE\" = \"800x600x16\" ]; then",
+                 "    VGA=788 ",
+                 "elif [ \"$GRUB_GFXMODE\" = \"1280x1024x16\" ]; then",
+                 "    VGA=794 ",
+                 "else",
+                 "    VGA=normal",
+                 "fi",
+                 "# END OF /etc/default/grub",""]
 
         # save the new file
-        with open(self.config_path, "w") as f:
-            f.writelines("".join(ndata))
+        with open(filepath, "w") as f:
+            f.writelines("\n".join(ndata))
         
         # after these are set, we just need to run grub-mkconfig
         subprocess.check_call(["grub-mkconfig", "-o", "/boot/grub/grub.cfg"])
     root, boot, _, kernel, initrd, append = \
             [ i.strip() for i in line.split(":") ]
     return dict(root=root, kernel=kernel, initrd=initrd, append=append)
+
+
+class FakeDevice(unittest.TestCase):
+    def setUp(self):
+        (fd, self.path) = tempfile.mkstemp(prefix="fake-device-")
+        f = os.fdopen(fd)
+        f.seek(140000)
+        os.write(fd, "0")
+
+    def tearDown(self):
+        os.unlink(self.path)
+
+
+if __name__ == "__main__":
+    unittest.main()

File vinstall/backend/fstab.py

View file
             "ext2": "defaults 0 0",
             "ext3": "defaults 0 0",
             "ext4": "defaults 0 0",
+            "jfs": "defaults 0 0",
             "iso9660": "noauto,ro,user 0 0",
             "msdos": "defaults 0 0",
             "swap": "sw 0 0",
             "linux-swap": "sw 0 0",
             "linux-swap(v1)": "sw 0 0"
         }
-        return opts["swap"] if "swap" in self.filesystem else \
-                opts.get(self.filesystem, "defaults 0 0")
+        if self.filesystem in ("swap","none","linux-swap","linux-swap(v1)"):
+            return opts["swap"]
+        else:
+            return opts.get(self.filesystem, "defauls 0 0")
 
     def find_uuid(self):
         """ Find the uuid for the specified device
         sep = " "*5
         if entry.uuid is None:
             entry.uuid = entry.find_uuid()
-        if entry.filesystem is None:
-            entry.filesyatem = entry.find_filesystem()
         # Use UUID when possible
         if entry.uuid is None:
             part = entry.device

File vinstall/controller/automatic.py

View file
 from vinstall.backend import fstab
 from vinstall.backend import users
 from vinstall.backend import service
+from vinstall.backend import bootloader
 import vinstall.controller.intro as intro
 import os, subprocess
 import glob
 
     """
     # Controller interface
+    ROOT_FS="ext3"
 
     def init(self):
         """Initialize some objects
 
         """
         self.disks = self.find_disks()
-        self.ROOT_FS = "ext3"
-        self.fstab_entries = []
 
     def render(self):
         """Show available disks for user selection
         for package in self.packages():
             yield self.installpkg, (package, disk)
         yield self.postinstall, tuple()
+        # Bind mounts
+        yield self.set_bind_mounts, tuple()
 
-        yield self.fstab, (disk,)
-        yield self.bootloader, (disk,)
+        yield self.fstab, (disk,)        
+        yield self.setup_services, tuple()
+        yield self.bootloader, (disk.path(),)
+
+        # Clear bind mounts at the very end
+        yield self.clear_bind_mounts, tuple()
 
     def previous(self):
         """Go back to the first screen
             swap_size = int(available_ram / 2)
 
         disk_size = disk.size(unit="MB")
-        #root_size = disk_size - swap_size
+
         partitioner = partitioning.DiskPartitioner(disk)
         partitioner.delete_all_partitions()
         root_size = disk.free_space("MB") - swap_size
         # Read how much space is left on the device.
         swap_size = disk.free_space("MB")
         partitioner.add_partition(size_mb = swap_size)
-        self.fstab_entries.append(("%s1" % disk.path(), "/", "defaults 0 1"))
-        self.fstab_entries.append(("%s2" % disk.path(), "none",
-            "swap     sw            0    0"))
 
     def format_partitions(self, disk):
         """Format partitions in disk with the default filesystem
 
         """
         print "Looking for packages"
-        excluded =("vlsetup", "aaa_base")
+        excluded =("vlconfig2", "vlsetup", "aaa_base")
         for root, dirs, files in os.walk("/mnt/SOURCE/packages"):
             for file in files:
                 if file.endswith("txz"):
         """
         print "Installing fstab in", disk
         fstab_obj = fstab.Fstab("/mnt/TARGET/etc/fstab")
-        for item in self.fstab_entries:
-            device, mntpoint, options = item
-            entry = fstab.FstabEntry(device, mntpoint, options)
+        root_entry = fstab.FstabEntry(device = "%s1" % disk.path(),
+                                      mountpoint = "/",
+                                      filesystem = self.ROOT_FS)
+        swap_entry = fstab.FstabEntry(device = "%s2" % disk.path(),
+                                      mountpoint = "none",
+                                      filesystem="swap")
+        for entry in (root_entry, swap_entry):
             fstab_obj.add_entry(entry)
 
 
+    def set_bind_mounts(self):
+        """Bind mount some paths into the target.
+        Later steps will need this when we chroot there """
+        
+        for point in ("sys","proc","dev"):
+            subprocess.check_call(["mount","-o","bind","/%s"% point,"/mnt/TARGET/%s"%point])
+        return
+
+    def clear_bind_mounts(self):
+        """Clear the mountpoints that were mounted for the configuration"""
+        for point in ("sys","proc","dev"):
+            subprocess.check_call(["umount","-f","/mnt/TARGET/%s"%point])
+        return
+    
+    def setup_services(self):
+        """Setup default system services"""
+        #FIXME:  Define the default set of services for each runlevel
+        # At some other location so they can be used by advanced.py too
+
+        svcbasic = [ "cron","portmap","lm_sensors","gpm","inetd" ]
+        svc2 = svcbasic
+        svc3 = svcbasic
+        svc3.extend(["samba","cups","sshd"])
+        svc4 = svcbasic
+        svc4.extend(["bluetooth","fuse","cups"])
+        svc5 = svc3
+        svc5.extend(["bluetooth","fuse"])
+
+        
+        for svc in service.Service.all("/mnt/TARGET"):
+            for model, runlevel in ((svc2, 2), (svc3, 3), (svc4, 4), (svc5, 5)):
+                if svc.name in model:
+                    svc.enable(runlevel)
+        return
+
+
     def bootloader(self, disk):
         """Install the default bootloader in disk
 
         """
+
         print "Installing bootloader in", disk
+	print " installing to MBR in ", disk
+        vga_size = "800x600" # screen resolution
+        vga_quality = "16" # color depth
+        timeout = 5 # seconds
+        grub = bootloader.Grub2(target=disk,
+                               vga_size = vga_size,
+                               vga_quality = vga_quality,
+                               timeout = timeout)
+        with utils.Chroot("/mnt/TARGET"):
+            grub.write_config("/etc/default/grub")
+            grub.install()
 
     def _check_continue(self):
         return 'I_MEAN_IT' in os.environ
 
         """
         print "Creating user and setting passwords:", username, password, rootpassword
-        # Set the root password
         yield self.set_root_password, (rootpassword,)
         yield self.create_user_account, (username, password)
-        yield self.setup_services, tuple()
-    
-    def setup_services(self):
-        """Setup default system services"""
-        #FIXME:  Define the default set of services for each runlevel
-        # At some other location so they can be used by advanced.py too
-
-        svcbasic = [ "cron","portmap","lm_sensors","gpm","inetd" ]
-        svc2 = svcbasic
-        svc3 = svcbasic
-        svc3.extend(["samba","cups","sshd"])
-        svc4 = svcbasic
-        svc4.extend(["bluetooth","fuse","cups"])
-        svc5 = svc3
-        svc5.extend(["bluetooth","fuse"])
-
-        
-        for svc in service.Service.all("/mnt/TARGET"):
-            for model, runlevel in ((svc2, 2), (svc3, 3), (svc4, 4), (svc5, 5)):
-                if svc.name in model:
-                    svc.enable(runlevel)
-        return
     
     def set_root_password(self, rootpassword):
         """Set the root password"""
             account.create()
         
         return
+