Browse code

Moving the system and installer in the iso inside the initrd.

* Cleaner way of booting from the iso.
* Useful for PXE-boot and kickstart support.

Mahmoud Bassiouny authored on 2015/06/17 04:01:58
Showing 16 changed files
1 1
deleted file mode 100755
... ...
@@ -1,20 +0,0 @@
1
-#!/bin/sh
2
-
3
-dev_ram=/dev/ram1
4
-dir_needwrite=/fake/needwrite
5
-directory_list="var/log tmp "
6
-
7
-echo -e "Creating ext2fs on $dev_ram ...              \n"
8
-/sbin/mke2fs -m 0 -i 1024 -q $dev_ram > /dev/null 2>&1
9
-
10
-
11
-echo -e "Mounting ramdisk on $dir_needwrite ...         \n"
12
-mount -n $dev_ram $dir_needwrite
13
-
14
-for directory in $directory_list
15
-do
16
-mkdir -p $dir_needwrite/$directory
17
-echo -e "Created directory.. $directory on $dir_ramdisk \n"
18
-done
19
-
20
-
... ...
@@ -3,4 +3,4 @@ label install
3 3
 	menu label ^Install
4 4
 	menu default
5 5
 	kernel vmlinuz
6
-	append initrd=initrd.gz root=/dev/ram0 init=/linuxrc ramdisk_size=16384 loglevel=3
6
+	append initrd=initrd.img root=/dev/ram0 loglevel=3
7 7
deleted file mode 100755
... ...
@@ -1,103 +0,0 @@
1
-#!/bin/sh
2
-
3
-
4
-#ID is the volume id / label of the PHOTON boot CD that will be looked for.
5
-ID="PHOTON_VMWARE_CD"
6
-TMP_MOUNT="/mnt"
7
-
8
-PATH="/bin:/sbin:/usr/bin:/usr/sbin"
9
-
10
-#this script searches for cdrom devices and then tries to find
11
-#the PHOTON boot CD in order to mount it as / (rootfs)
12
-
13
-#you need following programs:
14
-#- /bin/sh (e.g. bash)
15
-#- echo
16
-#- [ (which is linked to test)
17
-#- mount
18
-#- umount
19
-#- grep
20
-#- pivot_root
21
-#- chroot
22
-
23
-#you need following devices:
24
-#- /dev/hd*, /dev/sd*, /dev/sr* or /dev/cdrom*
25
-#- /dev/null
26
-
27
-#you need following directories:
28
-#- /proc
29
-#- $TMP_MOUNT
30
-
31
-CHECK_TYPE="try_mount"
32
-
33
-if [ ! -d "/proc/" ]; then
34
-  mkdir /proc
35
-fi
36
-
37
-mount -n proc /proc -t proc
38
-
39
-#1. Create a list of possible cdrom devices.
40
-
41
-CDROM_LIST="/dev/sr0 /dev/sr1 /dev/cdrom /dev/hda /dev/hdb /dev/hdc /dev/hdd
42
-/dev/hde /dev/sda /dev/sdb"
43
-
44
-#2. now we try to find the PHOTON boot CD (we use ID as identification)
45
-
46
-PHOTON_CDROM_DEVICE=""
47
-echo "Using $CHECK_TYPE"
48
-for cdrom_device in $CDROM_LIST
49
-do
50
-  echo -n "Checking $cdrom_device ... "
51
-
52
-  if [ "$CHECK_TYPE" = "try_mount" ]; then
53
-    mount -n -t iso9660 $cdrom_device $TMP_MOUNT > /dev/null 2>&1
54
-    media_found=$?
55
-  fi
56
-
57
-  if [ $media_found -eq 0 ]; then
58
-
59
-    echo -n "media found"
60
-    if [ "$CHECK_TYPE" = "try_mount" ]; then
61
-      [ -e "$TMP_MOUNT/$ID" ]
62
-      media_photon=$?
63
-    fi
64
-
65
-    if [ "$CHECK_TYPE" = "try_mount" ]; then
66
-      umount -n $cdrom_device > /dev/null 2>&1
67
-    fi
68
-
69
-    if [ $media_photon -eq 0 ]; then
70
-      echo ", PHOTON boot CD found. Ready!"
71
-      PHOTON_CDROM_DEVICE="$cdrom_device"
72
-      break;
73
-    else
74
-      echo ", not PHOTON boot CD."
75
-    fi
76
-
77
-  else
78
-    echo "no media "
79
-  fi
80
-done
81
-
82
-
83
-#3. mount PHOTON CD as / (root fs)
84
-if [ "$PHOTON_CDROM_DEVICE" = "" ]; then
85
-
86
-  echo "No PHOTON boot CD found!!!  You will have to fix this to continue"
87
-  echo "do: mount -n -o ro -t iso9660 'your cd device' $TMP_MOUNT"
88
-  echo "Then exit shell to continue"
89
-  bash
90
-
91
-else
92
-
93
-  echo "Booting from $PHOTON_CDROM_DEVICE ...                  "
94
-
95
-  mount -n -o ro -t iso9660 $PHOTON_CDROM_DEVICE $TMP_MOUNT
96
-
97
-  cd $TMP_MOUNT
98
-  pivot_root . mnt
99
-  mount -t proc proc /proc 
100
-  exec /usr/sbin/chroot . sh -c 'umount /mnt/proc >/dev/null 2>&1;umount /mnt/dev;umount /mnt;exec -a init.new /lib/systemd/systemd' <dev/console > dev/console 2>&1
101
-#umount /mnt/proc;umount /mnt/dev;umount /mnt;exec -a init.new /sbin/init 3' <dev/console >dev/console 2>&1
102
-
103
-fi
... ...
@@ -1,6 +1,5 @@
1 1
 #	Editable variables follow
2 2
 BUILDROOT=/mnt/photon-root	# where to build photon
3
-PARENT="/usr/src/photon"	# where build syetm lives
4 3
 #	Edit partition and mnt_point for the correct values.
5 4
 #	Failing to do so will cause you grief as in overwriting your host system.
6 5
 #	You have been warned!
... ...
@@ -22,7 +22,7 @@ from window import Window
22 22
 from actionresult import ActionResult
23 23
 
24 24
 class Installer(object):
25
-    def __init__(self, install_config, maxy = 0, maxx = 0, iso_installer = False, local_install = False, tools_path = "../stage", rpm_path = "../stage/RPMS", log_path = "../stage/LOGS"):
25
+    def __init__(self, install_config, maxy = 0, maxx = 0, iso_installer = False, tools_path = "../stage", rpm_path = "../stage/RPMS", log_path = "../stage/LOGS"):
26 26
         self.install_config = install_config
27 27
         self.iso_installer = iso_installer
28 28
         self.tools_path = tools_path
... ...
@@ -35,23 +35,15 @@ class Installer(object):
35 35
         self.chroot_command = "./mk-run-chroot.sh"
36 36
         self.setup_grub_command = "./mk-setup-grub.sh"
37 37
         self.unmount_disk_command = "./mk-unmount-disk.sh"
38
-        self.local_install = local_install
39
-        print local_install
40
-        if local_install:
41
-            self.scripts_working_directory = "./"
42
-        elif self.iso_installer:
43
-            self.scripts_working_directory = "/usr/src/photon"
44
-        else:
45
-            self.scripts_working_directory = "./"
46 38
 
47 39
         if self.iso_installer:
48
-            self.photon_root = "/mnt/photon-root"
40
+            self.working_directory = "/mnt/photon-root"
49 41
         elif 'working_directory' in self.install_config:
50
-            self.photon_root = self.install_config['working_directory']
42
+            self.working_directory = self.install_config['working_directory']
51 43
         else:
52
-            self.photon_root = "/mnt/photon-root"
44
+            self.working_directory = "/mnt/photon-root"
45
+        self.photon_root = self.working_directory + "/photon-chroot";
53 46
 
54
-        self.photon_directory = self.photon_root + "/usr/src/photon"
55 47
         self.restart_command = "shutdown"
56 48
         self.hostname_file = self.photon_root + "/etc/hostname"
57 49
         self.hosts_file = self.photon_root + "/etc/hosts"
... ...
@@ -66,6 +58,7 @@ class Installer(object):
66 66
         else:
67 67
             self.output = None
68 68
 
69
+        self.install_factor = 3
69 70
         if self.iso_installer:
70 71
             #initializing windows
71 72
             self.maxy = maxy
... ...
@@ -102,15 +95,12 @@ class Installer(object):
102 102
 
103 103
     def unsafe_install(self, params):
104 104
 
105
-        self.prepare_files_rpms_list()
106
-
107 105
         if self.iso_installer:
108 106
             self.window.show_window()
109
-
110
-            self.progress_bar.initialize(self.total_size, 'Initializing installation...')
107
+            self.progress_bar.initialize('Initializing installation...')
111 108
             self.progress_bar.show()
112 109
 
113
-        self.pre_initialize_filesystem()
110
+        self.initialize_system()
114 111
 
115 112
         #install packages
116 113
         for rpm in self.rpms_tobeinstalled:
... ...
@@ -122,19 +112,17 @@ class Installer(object):
122 122
             return_value = self.install_package(rpm['package'])
123 123
             if return_value != 0:
124 124
                 self.exit_gracefully(None, None)
125
-            #time.sleep(0.05)
126 125
             if self.iso_installer:
127 126
                 self.progress_bar.increment(rpm['size'] * self.install_factor)
128 127
 
129 128
         if self.iso_installer:
130 129
             self.progress_bar.show_loading('Finalizing installation')
131
-        #finalize system
130
+
132 131
         self.finalize_system()
133
-        #time.sleep(5)
134 132
 
135
-        if not self.install_config['iso_system'] and not self.local_install:
133
+        if not self.install_config['iso_system']:
136 134
             # install grub
137
-            process = subprocess.Popen([self.setup_grub_command, '-w', self.photon_root, self.install_config['disk']['disk'], self.install_config['disk']['root']], stdout=self.output,  stderr=self.output)
135
+            process = subprocess.Popen([self.setup_grub_command, '-w', self.photon_root, self.install_config['disk']['disk'], self.install_config['disk']['root']], stdout=self.output)
138 136
             retval = process.wait()
139 137
 
140 138
             #update root password
... ...
@@ -146,7 +134,7 @@ class Installer(object):
146 146
             #update openssh config
147 147
             self.update_openssh_config()
148 148
 
149
-        process = subprocess.Popen([self.unmount_disk_command, '-w', self.photon_root], stdout=self.output,  stderr=self.output)
149
+        process = subprocess.Popen([self.unmount_disk_command, '-w', self.photon_root], stdout=self.output)
150 150
         retval = process.wait()
151 151
 
152 152
         if self.iso_installer:
... ...
@@ -156,49 +144,17 @@ class Installer(object):
156 156
 
157 157
         return ActionResult(True, None)
158 158
 
159
-    def prepare_files_rpms_list(self):
160
-        self.total_size = 0
161
-        self.install_factor = 3
162
-
163
-        tools_list = (JsonWrapper("tools_list.json")).read()
164
-        tools = tools_list['base_tools']
165
-        # Add the additional iso tools.
166
-        if self.install_config['iso_system']:
167
-            tools = tools + tools_list['iso_tools'] + [self.rpm_path]
168
-
169
-        self.files_tobecopied = []
170
-        for item in tools:
171
-            src = os.path.join(self.scripts_working_directory, item)
172
-            if os.path.isfile(src):
173
-                if item != '.hidden':
174
-                    size = os.path.getsize(src)
175
-                    self.total_size += size
176
-                    self.files_tobecopied.append({'name': item, 'path': src, 'size': size})
177
-                continue
178
-            for root, dirs, files in os.walk(src):
179
-                for name in files:
180
-                    file = os.path.join(root, name)
181
-                    size = os.path.getsize(file)
182
-                    self.total_size += size
183
-                    relative = None
184
-                    if name.endswith(".rpm"):
185
-                        relative = os.path.relpath(file, self.rpm_path)
186
-                        relative = os.path.join("RPMS", relative)
187
-                    self.files_tobecopied.append({'name': name, 'path': file, 'relative_path': relative, 'size': size})
188
-
189
-        # prepare the RPMs
190
-        # TODO: mbassiouny, do not copy the rpms twice
159
+    def copy_rpms(self):
160
+        # prepare the RPMs list
191 161
         rpms = []
192
-        for root, dirs, files in os.walk(os.path.join(self.scripts_working_directory, self.rpm_path)):
162
+        for root, dirs, files in os.walk(self.rpm_path):
193 163
             for name in files:
194 164
                 file = os.path.join(root, name)
195 165
                 size = os.path.getsize(file)
196
-                relative = os.path.relpath(file, self.rpm_path)
197
-                relative = os.path.join("RPMS", relative)
198
-                rpms.append({'name': name, 'path': file, 'relative_path': relative, 'size': size})
166
+                rpms.append({'name': name, 'path': file, 'size': size})
199 167
 
168
+        progressbar_num_items = 0
200 169
         self.rpms_tobeinstalled = []
201
-        # prepare the RPMs list
202 170
         selected_packages = self.install_config['packages']
203 171
         for package in selected_packages:
204 172
             pattern = package + '-[0-9]*.rpm'
... ...
@@ -206,69 +162,77 @@ class Installer(object):
206 206
                 if fnmatch.fnmatch(rpm['name'], pattern):
207 207
                     rpm['package'] = package
208 208
                     self.rpms_tobeinstalled.append(rpm)
209
-                    self.total_size += rpm['size'] + rpm['size'] * self.install_factor
209
+                    progressbar_num_items += rpm['size'] + rpm['size'] * self.install_factor
210 210
                     break
211 211
 
212
-    def copy_file(self, file):
213
-        if self.iso_installer:
214
-            message = 'Copying {0}...'.format(file['name'])
215
-            self.progress_bar.update_message(message)
216
-
217
-        if 'relative_path' in file and file['relative_path'] != None:
218
-            relative = file['relative_path']
219
-        else:
220
-            relative = os.path.relpath(file['path'], self.scripts_working_directory)
221
-
222
-        dst = os.path.join(self.photon_directory, relative)
223
-        if not os.path.exists(os.path.dirname(dst)):
224
-            os.makedirs(os.path.dirname(dst))
225
-        shutil.copy(file['path'], dst)
212
+        process = subprocess.Popen(['mkdir', '-p', self.photon_root + '/RPMS'], stdout=self.output)
213
+        retval = process.wait()
226 214
 
227
-    def copy_files(self):
228
-        for file in self.files_tobecopied:
229
-            self.copy_file(file)
230
-            #time.sleep(0.05)
231
-            if self.iso_installer:
232
-                self.progress_bar.increment(file['size'])
215
+        if self.iso_installer:
216
+            self.progress_bar.update_num_items(progressbar_num_items)
233 217
 
218
+        # Copy the rpms
234 219
         for rpm in self.rpms_tobeinstalled:
235
-            self.copy_file(rpm)
236
-            #time.sleep(0.05)
220
+            shutil.copy(rpm['path'], self.photon_root + '/RPMS/')
237 221
             if self.iso_installer:
238 222
                 self.progress_bar.increment(rpm['size'])
239 223
 
240
-    def pre_initialize_filesystem(self):
224
+    def copy_files(self):
225
+        # Make the photon_root directory if not exits
226
+        process = subprocess.Popen(['mkdir', '-p', self.photon_root], stdout=self.output)
227
+        retval = process.wait()
228
+
229
+        # Copy the installer files
230
+        process = subprocess.Popen(['cp', '-r', "../installer", self.photon_root], stdout=self.output)
231
+        retval = process.wait()
232
+
233
+        # get the RPMS dir form the cd
234
+        if self.rpm_path == 'cdrom':
235
+            # Mount the cd to get the RPMS
236
+            process = subprocess.Popen(['mkdir', '-p', '/mnt/cdrom'], stdout=self.output)
237
+            retval = process.wait()
238
+
239
+            process = subprocess.Popen(['mount', '/dev/cdrom', '/mnt/cdrom'], stdout=self.output)
240
+            retval = process.wait()
241
+            if retval != 0:
242
+                self.exit_gracefully(None, None)
243
+            self.rpm_path = '/mnt/cdrom/RPMS'
244
+            self.tools_path = '/mnt/cdrom'
245
+
246
+        self.copy_rpms()
247
+
248
+    def initialize_system(self):
241 249
         #Setup the disk
242
-        if (not self.install_config['iso_system']) and (not self.local_install):
243
-            process = subprocess.Popen([self.mount_command, '-w', self.photon_root, self.install_config['disk']['root']], stdout=self.output,  stderr=self.output)
250
+        if (not self.install_config['iso_system']):
251
+            process = subprocess.Popen([self.mount_command, '-w', self.photon_root, self.install_config['disk']['root']], stdout=self.output)
244 252
             retval = process.wait()
245
-        #Setup the filesystem basics
253
+        
246 254
         self.copy_files()
247
-        process = subprocess.Popen([self.prepare_command, '-w', self.photon_root, self.tools_path], stdout=self.output,  stderr=self.output)
255
+        
256
+        #Setup the filesystem basics
257
+        process = subprocess.Popen([self.prepare_command, '-w', self.photon_root, self.tools_path], stdout=self.output)
248 258
         retval = process.wait()
249 259
 
250 260
     def finalize_system(self):
251 261
         #Setup the disk
252
-        process = subprocess.Popen([self.chroot_command, '-w', self.photon_root, self.finalize_command, '-w', self.photon_root], stdout=self.output,  stderr=self.output)
262
+        process = subprocess.Popen([self.chroot_command, '-w', self.photon_root, self.finalize_command, '-w', self.photon_root], stdout=self.output)
253 263
         retval = process.wait()
254 264
         if self.iso_installer:
255
-            # just copy the initrd /boot -> /photon_mnt/boot
265
+            # just copy the initramfs /boot -> /photon_mnt/boot
256 266
             shutil.copy('/boot/initrd.img-no-kmods', self.photon_root + '/boot/')
257
-        elif not self.local_install:
258
-            #Build the initrd
259
-            process = subprocess.Popen([self.chroot_command, '-w', self.photon_root, './mkinitramfs', '-n', '/boot/initrd.img-no-kmods'],  stdout=self.output,  stderr=self.output)
260
-            retval = process.wait()
261
-            process = subprocess.Popen(["./mk-initrd", '-w', self.photon_root],  stdout=self.output,  stderr=self.output)
267
+        else:
268
+            #Build the initramfs
269
+            process = subprocess.Popen([self.chroot_command, '-w', self.photon_root, './mkinitramfs', '-n', '/boot/initrd.img-no-kmods'],  stdout=self.output)
262 270
             retval = process.wait()
263 271
 
264 272
 
265 273
     def install_package(self,  package_name):
266 274
         rpm_params = ''
267 275
         
268
-        if 'type' in self.install_config and (self.install_config['type'] in ['micro', 'minimal']):
276
+        if ('type' in self.install_config and (self.install_config['type'] in ['micro', 'minimal'])) or self.install_config['iso_system']:
269 277
             rpm_params = rpm_params + ' --excludedocs '
270 278
 
271
-        process = subprocess.Popen([self.chroot_command, '-w', self.photon_root, self.install_package_command, '-w', self.photon_root, package_name, rpm_params],  stdout=self.output,  stderr=self.output)
279
+        process = subprocess.Popen([self.chroot_command, '-w', self.photon_root, self.install_package_command, '-w', self.photon_root, package_name, rpm_params],  stdout=self.output)
272 280
         return process.wait()
273 281
 
274 282
     def replace_string_in_file(self,  filename,  search_string,  replace_string):
... ...
@@ -311,7 +275,7 @@ class Installer(object):
311 311
             os.chmod(self.authorized_keys_filename, 0600)
312 312
 
313 313
             # Change the sshd config to allow root login
314
-            process = subprocess.Popen(["sed", "-i", "s/^\\s*PermitRootLogin\s\+no/PermitRootLogin yes/", self.sshd_config_filename], stdout=self.output,  stderr=self.output)
314
+            process = subprocess.Popen(["sed", "-i", "s/^\\s*PermitRootLogin\s\+no/PermitRootLogin yes/", self.sshd_config_filename], stdout=self.output)
315 315
             return process.wait()
316 316
 
317 317
 
... ...
@@ -17,12 +17,8 @@ from license import License
17 17
 
18 18
 class IsoInstaller(object):
19 19
 
20
-    def __init__(self, stdscreen, argv):
20
+    def __init__(self, stdscreen):
21 21
         self.screen = stdscreen
22
-        if len(argv) == 2:
23
-            local_install = True
24
-        else:
25
-            local_install = False
26 22
 
27 23
         # Init the colors
28 24
         curses.init_pair(1, curses.COLOR_WHITE, curses.COLOR_BLUE)
... ...
@@ -41,15 +37,8 @@ class IsoInstaller(object):
41 41
 
42 42
         license_agreement = License(self.maxy, self.maxx)
43 43
 
44
-        # skip the disk selection and partitioning if we are running with conf file in test environment.
45
-        if local_install == True:
46
-            # Read the conf file
47
-            self.install_config = (JsonWrapper(argv[1])).read()
48
-            self.install_config['iso_system'] = False
49
-        else:
50
-            self.install_config['iso_system'] = False
51
-            disk_partitioner = DiskPartitioner(self.maxy, self.maxx)
52
-            select_disk = SelectDisk(self.maxy, self.maxx, self.install_config)
44
+        self.install_config['iso_system'] = False
45
+        select_disk = SelectDisk(self.maxy, self.maxx, self.install_config)
53 46
 
54 47
         package_selector = PackageSelector(self.maxy, self.maxx, self.install_config)
55 48
         custom_package_selector = CustomPackageSelector(self.maxy, self.maxx, self.install_config)
... ...
@@ -59,10 +48,12 @@ class IsoInstaller(object):
59 59
         root_password_reader = WindowStringReader(self.maxy, self.maxx, 10, 70, True,  'Set up root password',
60 60
             'Root password:', 
61 61
             2, self.install_config)
62
-        installer = Installer(self.install_config, self.maxy, self.maxx, True, local_install, tools_path="/usr/src/photon", rpm_path="/usr/src/photon/RPMS", log_path="/var/log")
62
+        installer = Installer(self.install_config, self.maxy, self.maxx, True, tools_path=None, rpm_path='cdrom', log_path="/var/log")
63 63
 
64 64
         # This represents the installer screen, the bool indicated if I can go back to this window or not
65 65
         items = [
66
+                    (license_agreement.display, False),
67
+                    (select_disk.display, True),
66 68
                     (package_selector.display, True),
67 69
                     (custom_package_selector.display, False),
68 70
                     (hostname_reader.get_user_string, True),
... ...
@@ -70,14 +61,6 @@ class IsoInstaller(object):
70 70
                     (installer.install, False)
71 71
                 ]
72 72
 
73
-        # Include disk selection and partitioning in state machine when there is no extra param.
74
-        if local_install == False:
75
-            items = [
76
-                        #(disk_partitioner.display, True),
77
-                        (select_disk.display, True)
78
-                    ] + items
79
-        items = [(license_agreement.display, False)] + items
80
-
81 73
         index = 0
82 74
         params = None
83 75
         while True:
... ...
@@ -94,7 +77,5 @@ class IsoInstaller(object):
94 94
                 if index < 0:
95 95
                     index = 0
96 96
 
97
-# Call this script without any parameter to install from iso
98
-# or pass a conf file to install on local sdb for testing.
99 97
 if __name__ == '__main__':
100
-    curses.wrapper(IsoInstaller, sys.argv)
98
+    curses.wrapper(IsoInstaller)
... ...
@@ -19,8 +19,7 @@ PRGNAME=${0##*/}	# script name minus the path
19 19
 LOGFILE=/var/log/"${PRGNAME}-${LOGFILE}"	#	set log file name
20 20
 #LOGFILE=/dev/null		#	uncomment to disable log file
21 21
 [ ${EUID} -eq 0 ] 	|| fail "${PRGNAME}: Need to be root user: FAILURE"
22
-[ -z ${PARENT} ]	&& fail "${PRGNAME}: PARENT not set: FAILURE"
23
-[ -z ${BUILDROOT} ]	&& fail "${PRGNAME}: Build root not set: FAILURE"
22
+
24 23
 /sbin/ldconfig
25 24
 /usr/sbin/pwconv
26 25
 /usr/sbin/grpconv
27 26
deleted file mode 100755
... ...
@@ -1,68 +0,0 @@
1
-#!/bin/bash
2
-#################################################
3
-#       Title:  mk-initrd                       #
4
-#        Date:  2015-04-08                      #
5
-#     Version:  1.0                             #
6
-#      Author:  dthaluru@vmware.com             #
7
-#     Options:                                  #
8
-#################################################
9
-#	Overview
10
-#		Creates initial ramdisk
11
-#	End
12
-#
13
-
14
-source config.inc		#	configuration parameters
15
-source function.inc		#	commonn functions
16
-
17
-
18
-if [ -d ${BUILDROOT} ] ; then
19
-	[ -e ${BUILDROOT}/dev/ram0 ]    || mknod ${BUILDROOT}/dev/ram0 b 1 0
20
-	# Try to reduce this size to 8G or less later...maybe strip debug symbols off.
21
-	dd if=/dev/zero of=${BUILDROOT}/boot/initrd bs=1024 count=16384
22
-	mke2fs -m 0 -i 1024 -F ${BUILDROOT}/boot/initrd
23
-        mount -o loop ${BUILDROOT}/boot/initrd ${BUILDROOT}/mnt
24
-        cp BUILD_DVD/linuxrc ${BUILDROOT}/mnt/
25
-	cp BUILD_DVD/fstab ${BUILDROOT}/mnt/
26
-	pushd ${BUILDROOT}/mnt
27
-	mkdir bin lib dev proc mnt etc
28
-	ln -s lib lib64
29
-	ln -s bin sbin
30
-	popd
31
-	mknod ${BUILDROOT}/mnt/dev/ram0    b  1  0
32
-	mknod ${BUILDROOT}/mnt/dev/null    c  1  3
33
-	mknod ${BUILDROOT}/mnt/dev/zero    c  1  5
34
-	mknod ${BUILDROOT}/mnt/dev/console c  5  1
35
-	mknod ${BUILDROOT}/mnt/dev/ttyS0   c  4 64
36
-	mknod ${BUILDROOT}/mnt/dev/sr0     b 11  0
37
-	mknod ${BUILDROOT}/mnt/dev/sr1     b 11  1
38
-	mknod ${BUILDROOT}/mnt/dev/sda     b  8  0
39
-	mknod ${BUILDROOT}/mnt/dev/sdb     b  16  0
40
-	mknod ${BUILDROOT}/mnt/dev/sdc     b  32  0
41
-	mknod ${BUILDROOT}/mnt/dev/sdd     b  48  0
42
-	mknod ${BUILDROOT}/mnt/dev/hda     b  3  0
43
-	mknod ${BUILDROOT}/mnt/dev/hdb     b  3  64
44
-	mknod ${BUILDROOT}/mnt/dev/hdc     b  22  0
45
-	mknod ${BUILDROOT}/mnt/dev/hdd     b  22 64
46
-	mknod ${BUILDROOT}/mnt/dev/hde     b  33  0
47
-	cp ${BUILDROOT}/bin/{bash,mount,grep,umount,echo} ${BUILDROOT}/mnt/bin/
48
-	cp ${BUILDROOT}/usr/sbin/chroot ${BUILDROOT}/mnt/bin/
49
-	cp ${BUILDROOT}/sbin/pivot_root ${BUILDROOT}/mnt/bin/
50
-	ln -s bash ${BUILDROOT}/mnt/bin/sh
51
-	cp ${BUILDROOT}/lib/{libncursesw.so.*,libreadline.so.*} ${BUILDROOT}/mnt/lib/
52
-	cp ${BUILDROOT}/lib/{libhistory.so.*,libblkid.so.*,libuuid.so.*,libmount.so.*} ${BUILDROOT}/mnt/lib/
53
-	cp ${BUILDROOT}/usr/lib/libgcc_s.so.1 ${BUILDROOT}/mnt/lib/
54
-	ln -s libgcc_s.so.1 ${BUILDROOT}/mnt/lib/libgcc_s_so
55
-	for f in "ld-linux-x86-64.so.2" "libc.so.6" "libdl.so.2" "libpthread.so.0"
56
-	do
57
-		orig=$(readlink ${BUILDROOT}/lib/$f)
58
-    		orig_basename="${orig##*/}"
59
-    		cp ${BUILDROOT}/lib/$f ${BUILDROOT}/mnt/lib/$orig_basename
60
-		ln -sfv $orig_basename ${BUILDROOT}/mnt/lib/$f
61
-	done
62
-	cp ${BUILDROOT}/bin/{cat,sleep,mknod} ${BUILDROOT}/mnt/bin/
63
-	chmod 0755 ${BUILDROOT}/mnt/linuxrc
64
-	sleep 1
65
-	umount ${BUILDROOT}/mnt
66
-	gzip ${BUILDROOT}/boot/initrd
67
-fi
68
-
... ...
@@ -28,34 +28,25 @@ if [ $# -lt 2 ]
28 28
 fi
29 29
 ISO_OUTPUT_NAME=$1
30 30
 TOOLS_PATH=$2
31
-PACKAGE_LIST_FILE=$3
31
+RPMS_PATH=$3
32
+PACKAGE_LIST_FILE=$4
32 33
 
33 34
 
34 35
 #- Step 3 Setting up the boot loader
36
+WORKINGDIR=${BUILDROOT}
37
+BUILDROOT=${BUILDROOT}/photon-chroot
35 38
 
36
-mkdir ${BUILDROOT}/isolinux
37
-cp BUILD_DVD/isolinux/* ${BUILDROOT}/isolinux/
39
+mkdir ${WORKINGDIR}/isolinux
40
+cp BUILD_DVD/isolinux/* ${WORKINGDIR}/isolinux/
38 41
 
39
-mv ${BUILDROOT}/boot/* ${BUILDROOT}/isolinux/
40
-rmdir ${BUILDROOT}/boot
41
-ln -s isolinux ${BUILDROOT}/boot
42
+find ${BUILDROOT} -name linux-[0-9]*.rpm | head -1 | xargs rpm2cpio | cpio -iv --to-stdout ./boot/vmlinuz* > ${WORKINGDIR}/isolinux/vmlinuz
42 43
 
43
-find ${BUILDROOT} -name linux-[0-9]*.rpm | head -1 | xargs rpm2cpio | cpio -iv --to-stdout ./boot/vmlinuz* > ${BUILDROOT}/boot/vmlinuz
44
-
45
-cp -r ../installer ${BUILDROOT}/${PARENT}
44
+rm -f ${BUILDROOT}/installer/*.pyc
46 45
 # replace default package_list with specific one
47
-cp $PACKAGE_LIST_FILE ${BUILDROOT}/${PARENT}/installer/package_list.json
48
-rm -f ${BUILDROOT}/${PARENT}/installer/*.pyc
46
+cp $PACKAGE_LIST_FILE ${BUILDROOT}/installer/package_list.json
49 47
 
50 48
 #ID in the initrd.gz now is PHOTON_VMWARE_CD . This is how we recognize that the cd is actually ours. touch this file there.
51
-touch ${BUILDROOT}/PHOTON_VMWARE_CD
52
-
53
-#- Step 4 - Move /etc /var /root /home to /fake/needwrite
54
-
55
-mkdir -p ${BUILDROOT}/fake/{needwrite,ramdisk}
56
-mv ${BUILDROOT}/var/ ${BUILDROOT}/tmp ${BUILDROOT}/fake/needwrite/
57
-ln -s fake/needwrite/var ${BUILDROOT}/var
58
-ln -s fake/needwrite/tmp ${BUILDROOT}/tmp
49
+touch ${WORKINGDIR}/PHOTON_VMWARE_CD
59 50
 
60 51
 # Step 4.5 Create necessary devices
61 52
 mkfifo ${BUILDROOT}/dev/initctl
... ...
@@ -68,7 +59,6 @@ mknod ${BUILDROOT}/dev/sda b 8 0
68 68
 
69 69
 #- Step 5 - Creating the boot script
70 70
 mkdir -p ${BUILDROOT}/etc/systemd/scripts
71
-cp BUILD_DVD/create_ramdisk ${BUILDROOT}/bin/create_ramdisk
72 71
 
73 72
 # Step 6 create fstab
74 73
 
... ...
@@ -78,37 +68,55 @@ cp BUILD_DVD/fstab ${BUILDROOT}/etc/fstab
78 78
 
79 79
 cat >> ${BUILDROOT}/bin/bootphotoninstaller << EOF
80 80
 #!/bin/bash
81
-create_ramdisk
82
-cd ${PARENT}/installer
81
+cd /installer
83 82
 ./isoInstaller.py 2> /var/log/installer && shutdown -r now
84 83
 /bin/bash
85 84
 EOF
86 85
 
87 86
 chmod 755 ${BUILDROOT}/bin/bootphotoninstaller
88 87
 
88
+cat >> ${BUILDROOT}/init << EOF
89
+mount -t proc proc /proc
90
+/lib/systemd/systemd
91
+EOF
92
+chmod 755 ${BUILDROOT}/init
93
+
89 94
 #adding autologin to the root user
90 95
 sed -i "s/ExecStart.*/ExecStart=-\/sbin\/agetty --autologin root --noclear %I $TERM/g" ${BUILDROOT}/lib/systemd/system/getty@.service
91 96
 
92 97
 sed -i "s/root:.*/root:x:0:0:root:\/root:\/bin\/bootphotoninstaller/g" ${BUILDROOT}/etc/passwd
93 98
 
94
-mkdir -p ${BUILDROOT}/mnt/photon-root
95
-cp $TOOLS_PATH/tools.tar.gz ${BUILDROOT}/${PARENT}/
99
+mkdir -p ${BUILDROOT}/mnt/photon-root/photon-chroot
100
+rm -rf ${BUILDROOT}/RPMS
101
+cp -r ${RPMS_PATH} ${WORKINGDIR}/
102
+cp $TOOLS_PATH/tools.tar.gz ${WORKINGDIR}/
96 103
 
97 104
 #creating rpm repo in cd..
98
-createrepo --database ${BUILDROOT}/${PARENT}/RPMS
105
+createrepo --database ${WORKINGDIR}/RPMS
99 106
 
100
-rm -rf ${BUILDROOT}/${PARENT}/LOGS
107
+rm -rf ${BUILDROOT}/LOGS
101 108
 
102 109
 #Remove our rpm database as it fills up the ramdisk
103 110
 rm -rf ${BUILDROOT}/var/lib/rpm
104
-find "$BUILDROOT"/{,usr/}lib -type f -exec strip --strip-debug '{}' ';' > /dev/null 2>&1
105
-find "$BUILDROOT"/{,usr/}{bin,sbin} -type f -exec strip --strip-unneeded '{}' ';' > /dev/null 2>&1
111
+# TODO: mbassiouny, Find a clean way to do that
112
+for i in `ls ${BUILDROOT}/usr/share/`; do
113
+	if [ $i != 'terminfo' -a $i != 'cracklib' -a $i != 'grub' ]; then
114
+		rm -rf ${BUILDROOT}/usr/share/$i
115
+	fi
116
+done
106 117
 rm -rf $BUILDROOT/tools
107
-#Step 9 Generate the ISO!!!!
118
+
119
+# Generate the intird
108 120
 pushd $BUILDROOT
121
+(find . | cpio -o -H newc --quiet | gzip -9 ) > ${WORKINGDIR}/isolinux/initrd.img
122
+popd
123
+rm -rf $BUILDROOT
124
+
125
+#Step 9 Generate the ISO!!!!
126
+pushd $WORKINGDIR
109 127
 mkisofs -R -l -L -D -b isolinux/isolinux.bin -c isolinux/boot.cat \
110 128
 		-no-emul-boot -boot-load-size 4 -boot-info-table -V "PHOTON_$(date +%Y%m%d)" \
111
-		$BUILDROOT >$ISO_OUTPUT_NAME
129
+		$WORKINGDIR >$ISO_OUTPUT_NAME
112 130
 
113 131
 popd
114 132
 
... ...
@@ -25,10 +25,8 @@ if [ $# -ge 2 ]
25 25
 fi
26 26
 
27 27
 [ ${EUID} -eq 0 ] 	|| fail "${PRGNAME}: Need to be root user: FAILURE"
28
-[ -z ${PARENT} ]	&& fail "${PRGNAME}: PARENT not set: FAILURE"
29
-[ -z ${BUILDROOT} ]		&& fail "${PRGNAME}: BUILDROOT not set: FAILURE"
30 28
 RPMPKG=""
31
-RPMPKG=$(find RPMS -name "$1-[0-9]*.rpm" -print)
29
+RPMPKG=$(find ../RPMS -name "$1-[0-9]*.rpm" -print)
32 30
 [ -z $RPMPKG ] && fail "installation error: rpm package not found\n"
33 31
 case $1 in
34 32
 	linux-dev | linux-docs | glibc | gmp | gcc | bzip2 | ncurses | util-linux | e2fsprogs | shadow | bison | perl | texinfo | vim | linux | udev | rpm | dbus)
... ...
@@ -28,7 +28,6 @@ LOGFILE=/var/log/"${PRGNAME}-${LOGFILE}"	#	set log file name
28 28
 #LOGFILE=/dev/null		#	uncomment to disable log file
29 29
 
30 30
 [ ${EUID} -eq 0 ] 	|| fail "${PRGNAME}: Need to be root user: FAILURE"
31
-[ -z ${PARENT} ]	&& fail "${PRGNAME}: PARENT not set: FAILURE"
32 31
 [ -z ${BUILDROOT} ]	&& fail "${PRGNAME}: Build root not set: FAILURE"
33 32
 
34 33
 if mountpoint ${BUILDROOT}/run	>/dev/null 2>&1; then umount ${BUILDROOT}/run; fi
... ...
@@ -50,7 +49,7 @@ if mountpoint ${BUILDROOT}/dev	>/dev/null 2>&1; then umount ${BUILDROOT}/dev; fi
50 50
     fi
51 51
     PATH=$PATH:/tools/bin
52 52
     }
53
-cd ${BUILDROOT}${PARENT}	|| fail "${PRGNAME}: Change directory: ${BUILDROOT}${PARENT}: FAILURE"
53
+cd ${BUILDROOT} || fail "${PRGNAME}: Change directory: ${BUILDROOT}: FAILURE"
54 54
 #
55 55
 #	Setup the filesystem for chapter 06
56 56
 #
... ...
@@ -19,7 +19,6 @@ PRGNAME=${0##*/}	# script name minus the path
19 19
 LOGFILE=/var/log/"${PRGNAME}-${LOGFILE}"	#	set log file name
20 20
 #LOGFILE=/dev/null		#	uncomment to disable log file
21 21
 [ ${EUID} -eq 0 ] 	|| fail "${PRGNAME}: Need to be root user: FAILURE"
22
-[ -z ${PARENT} ]	&& fail "${PRGNAME}: PARENT not set: FAILURE"
23 22
 [ -z ${BUILDROOT} ]	&& fail "${PRGNAME}: Build root not set: FAILURE"
24 23
 
25 24
 # Remove the name of this script from our argument list
... ...
@@ -34,6 +33,6 @@ chroot "${BUILDROOT}" \
34 34
 	TERM="$TERM" \
35 35
 	PS1='\u:\w\$ ' \
36 36
 	PATH=/bin:/usr/bin:/sbin:/usr/sbin:/tools/bin \
37
-	/tools/bin/bash --login +h -c "cd ${PARENT};$*"
37
+	/tools/bin/bash --login +h -c "cd installer;$*"
38 38
 
39 39
 exit 0
... ...
@@ -21,7 +21,6 @@ source function.inc		#	commonn functions
21 21
 LOGFILE=/var/log/"${PRGNAME}-${LOGFILE}"	#	set log file name
22 22
 #LOGFILE=/dev/null		#	uncomment to disable log file
23 23
 ARCH=$(uname -m)	# host architecture
24
-RPMDIR=${PARENT}	# where rpms are stored on the host system
25 24
 [ ${EUID} -eq 0 ]	|| fail "${PRGNAME}: Need to be root user: FAILURE"
26 25
 > ${LOGFILE}		#	clear/initialize logfile
27 26
 
... ...
@@ -72,8 +71,7 @@ EOF
72 72
 sed -i "s/UUID_PLACEHOLDER/$UUID/" "$BUILDROOT"/boot/grub/grub.cfg > ${LOGFILE}	
73 73
 
74 74
 #Cleanup the workspace directory
75
-#find "$BUILDROOT"/{,usr/}{lib,bin,sbin} -type f -exec strip --strip-debug --strip-unneeded '{}' ';' > /dev/null 2>&1
76 75
 rm -rf "$BUILDROOT"/tools
77
-rm -rf "$BUILDROOT""$PARENT"
76
+rm -rf "$BUILDROOT"/RPMS
78 77
 
79 78
 #umount $BUILDROOT
... ...
@@ -19,7 +19,6 @@ PRGNAME=${0##*/}	# script name minus the path
19 19
 LOGFILE=/var/log/"${PRGNAME}-${LOGFILE}"	#	set log file name
20 20
 #LOGFILE=/dev/null		#	uncomment to disable log file
21 21
 [ ${EUID} -eq 0 ] 	|| fail "${PRGNAME}: Need to be root user: FAILURE"
22
-[ -z ${PARENT} ]	&& fail "${PRGNAME}: PARENT not set: FAILURE"
23 22
 [ -z ${BUILDROOT} ]		&& fail "${PRGNAME}: BUILDROOT not set: FAILURE"
24 23
 if mountpoint ${BUILDROOT}/run	>/dev/null 2>&1; then umount ${BUILDROOT}/run; fi
25 24
 if mountpoint ${BUILDROOT}/sys	>/dev/null 2>&1; then umount ${BUILDROOT}/sys; fi
... ...
@@ -88,6 +88,7 @@ if __name__ == '__main__':
88 88
     parser.add_option("-v", "--vmdk-path", dest="vmdk_path")
89 89
     parser.add_option("-w",  "--working-directory",  dest="working_directory", default="/mnt/photon-root")
90 90
     parser.add_option("-t",  "--tools-path",  dest="tools_path", default="../stage")
91
+    parser.add_option("-r",  "--rpm-path",  dest="rpm_path", default="../stage/RPMS")
91 92
     parser.add_option("-f", "--force", action="store_true", dest="force", default=False)
92 93
     parser.add_option("-p", "--package-list-file", dest="package_list_file", default="package_list.json")
93 94
     
... ...
@@ -164,12 +165,12 @@ if __name__ == '__main__':
164 164
     config['working_directory'] = options.working_directory
165 165
 
166 166
     # Run the installer
167
-    package_installer = Installer(config, local_install = not (options.iso_path or options.vmdk_path), tools_path = options.tools_path, rpm_path = options.tools_path + "/RPMS", log_path = options.tools_path + "/LOGS")
167
+    package_installer = Installer(config, tools_path = options.tools_path, rpm_path = options.rpm_path, log_path = options.tools_path + "/LOGS")
168 168
     package_installer.install(None)
169 169
 
170 170
     # Making the iso if needed
171 171
     if config['iso_system']:
172
-        process = subprocess.Popen(['./mk-install-iso.sh', '-w', options.working_directory, options.iso_path, options.tools_path, options.package_list_file])
172
+        process = subprocess.Popen(['./mk-install-iso.sh', '-w', options.working_directory, options.iso_path, options.tools_path, options.rpm_path, options.package_list_file])
173 173
         retval = process.wait()
174 174
 
175 175
     # Cleaning up for vmdk
... ...
@@ -31,14 +31,17 @@ class ProgressBar(object):
31 31
         self.panel.hide()
32 32
         panel.update_panels()
33 33
 
34
-    def initialize(self, num_items, init_message):
35
-        self.num_items = num_items
34
+    def initialize(self, init_message):
35
+        self.num_items = 0
36 36
         self.message = init_message
37 37
         self.time_elapsed = 0
38 38
         self.time_remaining = 60
39 39
         self.timer = threading.Timer(1, self.update_time)
40 40
         self.timer.start()
41 41
 
42
+    def update_num_items(self, num_items):
43
+        self.num_items = num_items
44
+
42 45
     def update_message(self, message):
43 46
         self.message = message
44 47
         self.render_message()
... ...
@@ -66,6 +69,8 @@ class ProgressBar(object):
66 66
         self.window.refresh()
67 67
 
68 68
     def render_progress(self):
69
+        if self.num_items == 0:
70
+            return
69 71
         completed = self.progress * 100 / self.num_items
70 72
         completed_width = completed * self.width / 100
71 73
         completed_str, remaining_str = self.get_spaces(completed_width, self.width, completed)