Change-Id: I99004669d3b2896beccfa2549f6d62d196e05a72
Reviewed-on: http://photon-jenkins.eng.vmware.com:8082/2521
Tested-by: gerrit-photon <photon-checkins@vmware.com>
Reviewed-by: Alexey Makhalov <amakhalov@vmware.com>
| ... | ... |
@@ -24,7 +24,9 @@ from actionresult import ActionResult |
| 24 | 24 |
from __builtin__ import isinstance |
| 25 | 25 |
|
| 26 | 26 |
class Installer(object): |
| 27 |
- def __init__(self, install_config, maxy = 0, maxx = 0, iso_installer = False, rpm_path = "../stage/RPMS", log_path = "../stage/LOGS", ks_config = None): |
|
| 27 |
+ def __init__(self, install_config, maxy = 0, maxx = 0, iso_installer = False, |
|
| 28 |
+ rpm_path = "../stage/RPMS", log_path = "../stage/LOGS", |
|
| 29 |
+ ks_config = None): |
|
| 28 | 30 |
self.install_config = install_config |
| 29 | 31 |
self.ks_config = ks_config |
| 30 | 32 |
self.iso_installer = iso_installer |
| ... | ... |
@@ -149,15 +151,38 @@ class Installer(object): |
| 149 | 149 |
if self.iso_installer and os.path.isdir("/sys/firmware/efi"):
|
| 150 | 150 |
self.install_config['boot'] = 'efi' |
| 151 | 151 |
# install grub |
| 152 |
+ if 'boot_partition_number' not in self.install_config['disk']: |
|
| 153 |
+ self.install_config['disk']['boot_partition_number'] = 1 |
|
| 154 |
+ |
|
| 152 | 155 |
try: |
| 153 | 156 |
if self.install_config['boot'] == 'bios': |
| 154 |
- process = subprocess.Popen([self.setup_grub_command, '-w', self.photon_root, "bios", self.install_config['disk']['disk'], self.install_config['disk']['root'], self.install_config['disk']['boot'], self.install_config['disk']['bootdirectory']], stdout=self.output) |
|
| 157 |
+ process = subprocess.Popen( |
|
| 158 |
+ [self.setup_grub_command, '-w', self.photon_root, |
|
| 159 |
+ "bios", self.install_config['disk']['disk'], |
|
| 160 |
+ self.install_config['disk']['root'], |
|
| 161 |
+ self.install_config['disk']['boot'], |
|
| 162 |
+ self.install_config['disk']['bootdirectory'], |
|
| 163 |
+ str(self.install_config['disk']['boot_partition_number'])], |
|
| 164 |
+ stdout=self.output) |
|
| 155 | 165 |
elif self.install_config['boot'] == 'efi': |
| 156 |
- process = subprocess.Popen([self.setup_grub_command, '-w', self.photon_root, "efi", self.install_config['disk']['disk'], self.install_config['disk']['root'], self.install_config['disk']['boot'], self.install_config['disk']['bootdirectory']], stdout=self.output) |
|
| 166 |
+ process = subprocess.Popen( |
|
| 167 |
+ [self.setup_grub_command, '-w', self.photon_root, |
|
| 168 |
+ "efi", self.install_config['disk']['disk'], |
|
| 169 |
+ self.install_config['disk']['root'], |
|
| 170 |
+ self.install_config['disk']['boot'], |
|
| 171 |
+ self.install_config['disk']['bootdirectory'], |
|
| 172 |
+ str(self.install_config['disk']['boot_partition_number'])], |
|
| 173 |
+ stdout=self.output) |
|
| 157 | 174 |
except: |
| 158 | 175 |
#install bios if variable is not set. |
| 159 |
- process = subprocess.Popen([self.setup_grub_command, '-w', self.photon_root, "bios", self.install_config['disk']['disk'], self.install_config['disk']['root'], self.install_config['disk']['boot'], self.install_config['disk']['bootdirectory']], stdout=self.output) |
|
| 160 |
- |
|
| 176 |
+ process = subprocess.Popen( |
|
| 177 |
+ [self.setup_grub_command, '-w', self.photon_root, |
|
| 178 |
+ "bios", self.install_config['disk']['disk'], |
|
| 179 |
+ self.install_config['disk']['root'], |
|
| 180 |
+ self.install_config['disk']['boot'], |
|
| 181 |
+ self.install_config['disk']['bootdirectory'], |
|
| 182 |
+ str(self.install_config['disk']['boot_partition_number'])], |
|
| 183 |
+ stdout=self.output) |
|
| 161 | 184 |
retval = process.wait() |
| 162 | 185 |
|
| 163 | 186 |
self.update_fstab() |
| ... | ... |
@@ -23,16 +23,16 @@ grub_efi_install() |
| 23 | 23 |
then |
| 24 | 24 |
BOOT_PARTITION=/dev/mapper/`basename ${HDD}`p1
|
| 25 | 25 |
else |
| 26 |
- BOOT_PARTITION=${HDD}2
|
|
| 26 |
+ BOOT_PARTITION=${HDD}1
|
|
| 27 | 27 |
fi |
| 28 |
- mkfs.vfat $BOOT_PARTITION |
|
| 28 |
+ mkfs.fat $BOOT_PARTITION |
|
| 29 | 29 |
mount -t vfat $BOOT_PARTITION $BUILDROOT/boot/efi |
| 30 | 30 |
cp boot/unifont.pf2 /usr/share/grub/ |
| 31 | 31 |
grub2-efi-install --target=x86_64-efi --efi-directory=$BUILDROOT/boot/efi --bootloader-id=Boot --root-directory=$BUILDROOT --recheck |
| 32 | 32 |
rm $BUILDROOT/boot/efi/EFI/Boot/grubx64.efi |
| 33 | 33 |
cp EFI/BOOT/* $BUILDROOT/boot/efi/EFI/Boot/ |
| 34 | 34 |
mkdir -p $BUILDROOT/boot/efi/boot/grub2 |
| 35 |
- echo "configfile (hd0,gpt1)/boot/grub2/grub.cfg" > $BUILDROOT/boot/efi/boot/grub2/grub.cfg |
|
| 35 |
+ echo "configfile (hd0,gpt${BOOT_PARTITION_NUMBER})${BOOT_DIRECTORY}grub2/grub.cfg" > $BUILDROOT/boot/efi/boot/grub2/grub.cfg
|
|
| 36 | 36 |
umount $BUILDROOT/boot/efi |
| 37 | 37 |
} |
| 38 | 38 |
|
| ... | ... |
@@ -53,13 +53,14 @@ ARCH=$(uname -m) # host architecture |
| 53 | 53 |
> ${LOGFILE} # clear/initialize logfile
|
| 54 | 54 |
|
| 55 | 55 |
# Check if passing a HHD and partition |
| 56 |
-if [ $# -eq 5 ] |
|
| 56 |
+if [ $# -eq 6 ] |
|
| 57 | 57 |
then |
| 58 | 58 |
BOOTMODE=$1 |
| 59 | 59 |
HDD=$2 |
| 60 | 60 |
ROOT_PARTITION_PATH=$3 |
| 61 | 61 |
BOOT_PARTITION_PATH=$4 |
| 62 | 62 |
BOOT_DIRECTORY=$5 |
| 63 |
+ BOOT_PARTITION_NUMBER=$6 |
|
| 63 | 64 |
fi |
| 64 | 65 |
|
| 65 | 66 |
# |
| ... | ... |
@@ -44,9 +44,16 @@ def partition_disk(disk, partitions): |
| 44 | 44 |
# Partitioning the disk |
| 45 | 45 |
extensible_partition = None |
| 46 | 46 |
partitions_count = len(partitions) |
| 47 |
- partition_number = 1 |
|
| 47 |
+ partition_number = 2 |
|
| 48 |
+ # Add part size and grub flags |
|
| 49 |
+ grub_flag = ':ef02' |
|
| 50 |
+ part_size = '+2M' |
|
| 51 |
+ if os.path.isdir("/sys/firmware/efi"):
|
|
| 52 |
+ grub_flag = ':ef00' |
|
| 53 |
+ part_size = '+3M' |
|
| 54 |
+ |
|
| 48 | 55 |
# Adding the bios partition |
| 49 |
- partition_cmd = ['sgdisk', '-n', `partitions_count + 1` + ':-2M:'] |
|
| 56 |
+ partition_cmd = ['sgdisk', '-n 1::' + part_size] |
|
| 50 | 57 |
# Adding the known size partitions |
| 51 | 58 |
for partition in partitions: |
| 52 | 59 |
if partition['size'] == 0: |
| ... | ... |
@@ -77,12 +84,7 @@ def partition_disk(disk, partitions): |
| 77 | 77 |
log(LOG_ERROR, "Faild partition disk, command: {0}". format(partition_cmd))
|
| 78 | 78 |
return None |
| 79 | 79 |
|
| 80 |
- # Add the grub flags |
|
| 81 |
- grub_flag = ':ef02' |
|
| 82 |
- if os.path.isdir("/sys/firmware/efi"):
|
|
| 83 |
- grub_flag = ':ef00' |
|
| 84 |
- |
|
| 85 |
- process = subprocess.Popen(['sgdisk', '-t' + `partitions_count + 1` + grub_flag, disk], stdout = output) |
|
| 80 |
+ process = subprocess.Popen(['sgdisk', '-t1' + grub_flag, disk], stdout = output) |
|
| 86 | 81 |
retval = process.wait() |
| 87 | 82 |
if retval != 0: |
| 88 | 83 |
log(LOG_ERROR, "Failed to setup grub partition") |
| ... | ... |
@@ -93,8 +95,10 @@ def partition_disk(disk, partitions): |
| 93 | 93 |
if "mountpoint" in partition: |
| 94 | 94 |
if partition['mountpoint'] == '/': |
| 95 | 95 |
partitions_data['root'] = partition['path'] |
| 96 |
+ partitions_data['root_partition_number'] = partition['partition_number'] |
|
| 96 | 97 |
elif partition['mountpoint'] == '/boot': |
| 97 | 98 |
partitions_data['boot'] = partition['path'] |
| 99 |
+ partitions_data['boot_partition_number'] = partition['partition_number'] |
|
| 98 | 100 |
partitions_data['bootdirectory'] = '/' |
| 99 | 101 |
if partition['filesystem'] == "swap": |
| 100 | 102 |
process = subprocess.Popen(['mkswap', partition['path']], stdout = output) |
| ... | ... |
@@ -116,10 +120,11 @@ def partition_disk(disk, partitions): |
| 116 | 116 |
|
| 117 | 117 |
if not 'boot' in partitions_data: |
| 118 | 118 |
partitions_data['boot'] = partitions_data['root'] |
| 119 |
+ partitions_data['boot_partition_number'] = partitions_data['root_partition_number'] |
|
| 119 | 120 |
partitions_data['bootdirectory'] = '/boot/' |
| 120 | 121 |
|
| 121 | 122 |
partitions.sort(lambda p1,p2: partition_compare(p1, p2)) |
| 122 |
- |
|
| 123 |
+ |
|
| 123 | 124 |
return partitions_data |
| 124 | 125 |
|
| 125 | 126 |
def replace_string_in_file(filename, search_string, replace_string): |