@@ -46,9 +46,8 @@ var installCommand = cli.Command{
4646 },
4747 cli.StringFlag {
4848 Name : "install-type, t" ,
49- Usage : `generic: (Default) Creates 1 ext4 partition and installs RancherOS
49+ Usage : `generic: (Default) Creates 1 ext4 partition and installs RancherOS (syslinux)
5050 amazon-ebs: Installs RancherOS and sets up PV-GRUB
51- syslinux: partition and format disk (mbr), then install RnancherOS and setup Syslinux
5251 gptsyslinux: partition and format disk (gpt), then install RnancherOS and setup Syslinux
5352 ` ,
5453 },
@@ -137,19 +136,18 @@ func runInstall(image, installType, cloudConfig, device, kappend string, force,
137136 diskType = "gpt"
138137 }
139138
140- if installType == "generic" ||
141- installType == "syslinux" ||
142- installType == "gptsyslinux" {
143-
144139 // Versions before 0.8.0-rc2 use the old calling convention (from the lay-down-os shell script)
145140 imageVersion := strings .TrimPrefix (image , "rancher/os:v" )
146141 if image != imageVersion {
142+ log .Infof ("user spcified different install image: %s != %s" , image , imageVersion )
147143 imageVersion = strings .Replace (imageVersion , "-" , "." , - 1 )
148144 vArray := strings .Split (imageVersion , "." )
149145 v , _ := strconv .ParseFloat (vArray [0 ]+ "." + vArray [1 ], 32 )
150146 if v < 0.8 || imageVersion == "0.8.0-rc1" {
151147 log .Infof ("starting installer container for %s" , image )
152- if installType == "generic" {
148+ if installType == "generic" ||
149+ installType == "syslinux" ||
150+ installType == "gptsyslinux" {
153151 cmd := exec .Command ("system-docker" , "run" , "--net=host" , "--privileged" , "--volumes-from=all-volumes" ,
154152 "--entrypoint=/scripts/set-disk-partitions" , image , device , diskType )
155153 cmd .Stdout , cmd .Stderr = os .Stdout , os .Stderr
@@ -158,7 +156,8 @@ func runInstall(image, installType, cloudConfig, device, kappend string, force,
158156 }
159157 }
160158 cmd := exec .Command ("system-docker" , "run" , "--net=host" , "--privileged" , "--volumes-from=user-volumes" ,
161- "--volumes-from=command-volumes" , image , "-d" , device , "-t" , installType , "-c" , cloudConfig , "-a" , kappend )
159+ "--volumes-from=command-volumes" , image , "-d" , device , "-t" , installType , "-c" , cloudConfig ,
160+ "-a" , kappend )
162161 cmd .Stdout , cmd .Stderr = os .Stdout , os .Stderr
163162 if err := cmd .Run (); err != nil {
164163 return err
@@ -195,7 +194,7 @@ func runInstall(image, installType, cloudConfig, device, kappend string, force,
195194 "run" , "--rm" , "--net=host" , "--privileged" ,
196195 // bind mount host fs to access its ros, vmlinuz, initrd and /dev (udev isn't running in container)
197196 "-v" , "/:/host" ,
198- "--volumes-from=user-volumes" , "--volumes-from=command -volumes" ,
197+ "--volumes-from=all -volumes" ,
199198 image ,
200199 "install" ,
201200 "-t" , installType ,
@@ -239,8 +238,14 @@ func runInstall(image, installType, cloudConfig, device, kappend string, force,
239238
240239 log .Infof ("running installation" )
241240
242- if installType == "generic" {
243- err := setDiskpartitions (device )
241+ if installType == "generic" ||
242+ installType == "syslinux" ||
243+ installType == "gptsyslinux" {
244+ diskType := "msdos"
245+ if installType == "gptsyslinux" {
246+ diskType = "gpt"
247+ }
248+ err := setDiskpartitions (device , diskType )
244249 if err != nil {
245250 log .Errorf ("error setDiskpartitions %s" , err )
246251 return err
@@ -271,12 +276,23 @@ func runInstall(image, installType, cloudConfig, device, kappend string, force,
271276}
272277
273278func mountBootIso () error {
274- // TODO: need to add a label to the iso and mount using that.
275- // ARGH! need to mount this in the host - or share it as a volume..
276- os .MkdirAll ("/bootiso" , 0755 )
277-
278279 deviceName := "/dev/sr0"
279280 deviceType := "iso9660"
281+ { // force the defer
282+ mountsFile , err := os .Open ("/proc/mounts" )
283+ if err != nil {
284+ log .Errorf ("failed to read /proc/mounts %s" , err )
285+ return err
286+ }
287+ defer mountsFile .Close ()
288+
289+ if partitionMounted (deviceName , mountsFile ) {
290+ return nil
291+ }
292+ }
293+
294+ os .MkdirAll ("/bootiso" , 0755 )
295+
280296 // find the installation device
281297 cmd := exec .Command ("blkid" , "-L" , "RancherOS" )
282298 log .Debugf ("Run(%v)" , cmd )
@@ -337,7 +353,16 @@ func layDownOS(image, installType, cloudConfig, device, kappend string) error {
337353 // unmount on trap
338354 defer util .Unmount (baseName )
339355
356+ diskType := "msdos"
357+ if installType == "gptsyslinux" {
358+ diskType = "gpt"
359+ }
360+
340361 switch installType {
362+ case "syslinux" :
363+ fallthrough
364+ case "gptsyslinux" :
365+ fallthrough
341366 case "generic" :
342367 log .Debugf ("formatAndMount" )
343368 var err error
@@ -349,7 +374,7 @@ func layDownOS(image, installType, cloudConfig, device, kappend string) error {
349374 //log.Infof("installGrub")
350375 //err = installGrub(baseName, device)
351376 log .Debugf ("installSyslinux" )
352- err = installSyslinux (device , baseName , bootDir )
377+ err = installSyslinux (device , baseName , bootDir , diskType )
353378
354379 if err != nil {
355380 log .Errorf ("%s" , err )
@@ -399,15 +424,15 @@ func layDownOS(image, installType, cloudConfig, device, kappend string) error {
399424 return err
400425 }
401426 createbootDirs (baseName , bootDir )
402- installSyslinux (device , baseName , bootDir )
427+ installSyslinux (device , baseName , bootDir , diskType )
403428 case "raid" :
404429 var err error
405430 bootDir , err = mountdevice (baseName , bootDir , partition , false )
406431 if err != nil {
407432 return err
408433 }
409434 createbootDirs (baseName , bootDir )
410- installSyslinuxRaid (baseName , bootDir )
435+ installSyslinuxRaid (baseName , bootDir , diskType )
411436 case "bootstrap" :
412437 CONSOLE = "ttyS0"
413438 var err error
@@ -496,7 +521,7 @@ func seedData(baseName, cloudData string, files []string) error {
496521}
497522
498523// set-disk-partitions is called with device == **/dev/sda**
499- func setDiskpartitions (device string ) error {
524+ func setDiskpartitions (device , diskType string ) error {
500525 log .Debugf ("setDiskpartitions" )
501526
502527 d := strings .Split (device , "/" )
@@ -590,23 +615,16 @@ func setDiskpartitions(device string) error {
590615 return err
591616 }
592617
593- r , w := io .Pipe ()
594- go func () {
595- w .Write ([]byte (`n
596- p
597- 1
598-
599-
600- a
601- 1
602- w
603- ` ))
604- w .Close ()
605- }()
606- log .Debugf ("running fdisk" )
607- cmd = exec .Command ("fdisk" , device )
608- cmd .Stdin = r
609- //cmd.Stdout, cmd.Stderr = os.Stdout, os.Stderr
618+ bootflag := "boot"
619+ if diskType == "gpt" {
620+ bootflag = "legacy_boot"
621+ }
622+ log .Debugf ("running parted" )
623+ cmd = exec .Command ("parted" , "-s" , "-a" , "optimal" , device ,
624+ "mklabel " + diskType , "--" ,
625+ "mkpart primary ext4 1 -1" ,
626+ "set 1 " + bootflag + " on" )
627+ cmd .Stdout , cmd .Stderr = os .Stdout , os .Stderr
610628 if err := cmd .Run (); err != nil {
611629 log .Errorf ("%s" , err )
612630 return err
@@ -714,13 +732,18 @@ func createbootDirs(baseName, bootDir string) error {
714732 return nil
715733}
716734
717- func installSyslinux (device , baseName , bootDir string ) error {
735+ func installSyslinux (device , baseName , bootDir , diskType string ) error {
718736 log .Debugf ("installSyslinux" )
719737
738+ mbrFile := "mbr.bin"
739+ if diskType == "gpt" {
740+ mbrFile = "gptmbr.bin"
741+ }
742+
720743 //dd bs=440 count=1 if=/usr/lib/syslinux/mbr/mbr.bin of=${device}
721744 // ubuntu: /usr/lib/syslinux/mbr/mbr.bin
722745 // alpine: /usr/share/syslinux/mbr.bin
723- cmd := exec .Command ("dd" , "bs=440" , "count=1" , "if=/usr/share/syslinux/mbr.bin" , "of=" + device )
746+ cmd := exec .Command ("dd" , "bs=440" , "count=1" , "if=/usr/share/syslinux/" + mbrFile , "of=" + device )
724747 //cmd.Stdout, cmd.Stderr = os.Stdout, os.Stderr
725748 log .Debugf ("Run(%v)" , cmd )
726749 if err := cmd .Run (); err != nil {
@@ -750,19 +773,24 @@ func installSyslinux(device, baseName, bootDir string) error {
750773 return nil
751774}
752775
753- func installSyslinuxRaid (baseName , bootDir string ) error {
776+ func installSyslinuxRaid (baseName , bootDir , diskType string ) error {
754777 log .Debugf ("installSyslinuxRaid" )
755778
779+ mbrFile := "mbr.bin"
780+ if diskType == "gpt" {
781+ mbrFile = "gptmbr.bin"
782+ }
783+
756784 //dd bs=440 count=1 if=/usr/lib/syslinux/mbr/mbr.bin of=/dev/sda
757785 //dd bs=440 count=1 if=/usr/lib/syslinux/mbr/mbr.bin of=/dev/sdb
758786 //cp /usr/lib/syslinux/modules/bios/* ${baseName}/${bootDir}syslinux
759787 //extlinux --install --raid ${baseName}/${bootDir}syslinux
760- cmd := exec .Command ("dd" , "bs=440" , "count=1" , "if=/usr/share/syslinux/mbr.bin" , "of=/dev/sda" )
788+ cmd := exec .Command ("dd" , "bs=440" , "count=1" , "if=/usr/share/syslinux/" + mbrFile , "of=/dev/sda" )
761789 if err := cmd .Run (); err != nil {
762790 log .Errorf ("%s" , err )
763791 return err
764792 }
765- cmd = exec .Command ("dd" , "bs=440" , "count=1" , "if=/usr/share/syslinux/mbr.bin" , "of=/dev/sdb" )
793+ cmd = exec .Command ("dd" , "bs=440" , "count=1" , "if=/usr/share/syslinux/" + mbrFile , "of=/dev/sdb" )
766794 if err := cmd .Run (); err != nil {
767795 log .Errorf ("%s" , err )
768796 return err
0 commit comments