@@ -1020,7 +1020,7 @@ def _unmount_all(self):
10201020 # only fstrim fs types that are supported to avoid error messages
10211021 # instead of filtering for the fs type we could use '--quiet-unsupported',
10221022 # but this is not implemented in older fstrim versions in Photon 3.0
1023- if p ['filesystem' ] in ['ext4' , 'btrfs' , 'xfs' ]:
1023+ if p ['filesystem' ] in ['ext4' , 'btrfs' , 'xfs' ] and p [ 'mountpoint' ] is not None :
10241024 mntpoint = os .path .join (self .photon_root , p ['mountpoint' ].strip ('/' ))
10251025 retval = self .cmd .run (["fstrim" , mntpoint ])
10261026
@@ -1148,31 +1148,36 @@ def _create_fstab(self, fstab_path=None):
11481148 else :
11491149 mountpoint = partition ['mountpoint' ]
11501150
1151- # Use PARTUUID/UUID instead of bare path.
1152- # Prefer PARTUUID over UUID as it is supported by kernel
1153- # and UUID only by initrd.
11541151 path = partition ['path' ]
1155- mnt_src = None
1156- partuuid = self ._get_partuuid (path )
1157- if partuuid != '' :
1158- mnt_src = f"PARTUUID={ partuuid } "
1152+ if partition .get ('mount_by' ) is None :
1153+ # Use PARTUUID/UUID instead of bare path.
1154+ # Prefer PARTUUID over UUID as it is supported by kernel
1155+ # and UUID only by initrd.
1156+ mnt_src = None
1157+ partuuid = self ._get_partuuid (path )
1158+ if partuuid != '' :
1159+ mnt_src = f"PARTUUID={ partuuid } "
1160+ else :
1161+ uuid = self ._get_uuid (path )
1162+ if uuid != '' :
1163+ mnt_src = f"UUID={ uuid } "
11591164 else :
1160- uuid = self ._get_uuid (path )
1161- if uuid != '' :
1162- mnt_src = f"UUID={ uuid } "
1165+ mount_by = partition ['mount_by' ]
1166+ if mount_by == "partuuid" :
1167+ mnt_src = "PARTUUID=" + self ._get_partuuid (path )
1168+ elif mount_by == "uuid" :
1169+ mnt_src = "UUID=" + self ._get_uuid (path )
1170+ elif mount_by == "partlabel" :
1171+ mnt_src = "PARTLABEL=" + partition .get ('partlabel' )
1172+ elif mount_by == "label" :
1173+ mnt_src = "LABEL=" + partition .get ('label' )
1174+ else :
1175+ raise InstallerConfigError (f"unsupported 'mount_by' '{ mount_by } '" )
1176+
11631177 if not mnt_src :
1164- raise RuntimeError (f"Cannot get PARTUUID/UUID of: { path } " )
1165-
1166- fstab_file .write (
1167- "{}\t {}\t {}\t {}\t {}\t {}\n " .format (
1168- mnt_src ,
1169- mountpoint ,
1170- partition ['filesystem' ],
1171- options ,
1172- dump ,
1173- fsck ,
1174- )
1175- )
1178+ raise RuntimeError (f"Cannot get mount source for: { path } " )
1179+
1180+ fstab_file .write (f"{ mnt_src } \t { mountpoint } \t { partition ['filesystem' ]} \t { options } \t { dump } \t { fsck } \n " )
11761181
11771182 if partition .get ('filesystem' , '' ) == "btrfs" and "btrfs" in partition and "subvols" in partition ["btrfs" ]:
11781183 self ._add_btrfs_subvolume_to_fstab (mnt_src , fstab_file , partition ["btrfs" ])
@@ -1247,6 +1252,8 @@ def _mount_partitions(self):
12471252 continue
12481253 if partition .get ('shadow' , False ):
12491254 continue
1255+ if partition ['mountpoint' ] is None :
1256+ continue
12501257
12511258 mntpoint = os .path .join (self .photon_root , partition ['mountpoint' ].strip ('/' ))
12521259 if not partition .get ('no_build_mount' , False ):
@@ -2116,13 +2123,19 @@ def _partition_disks(self):
21162123 else :
21172124 l2 ['partition' ]['path' ] = self ._get_partition_path (device , part_idx )
21182125
2126+ this_cmd = partition_cmd
21192127 if l2 ['size' ] == 0 :
21202128 last_partition = []
2121- last_partition . extend ([ f'-n { part_idx } ' ])
2122- last_partition . extend ([ f"-t { part_idx } : { l2 [ 'type' ] } " ] )
2129+ this_cmd = last_partition
2130+ this_cmd . append ( f'-n { part_idx } ' )
21232131 else :
2124- partition_cmd .extend ([f"-n{ part_idx } ::+{ l2 ['size' ]} M" ])
2125- partition_cmd .extend ([f"-t{ part_idx } :{ l2 ['type' ]} " ])
2132+ this_cmd .append (f"-n{ part_idx } ::+{ l2 ['size' ]} M" )
2133+
2134+ this_cmd .append (f"-t{ part_idx } :{ l2 ['type' ]} " )
2135+
2136+ if 'partition' in l2 and l2 ['partition' ].get ('partlabel' ) is not None :
2137+ this_cmd .append (f"-c{ part_idx } :{ l2 ['partition' ]['partlabel' ]} " )
2138+
21262139 part_idx += 1
21272140
21282141 # if extensible partition present, add it to the end of the disk
@@ -2188,23 +2201,35 @@ def _format_partitions(self):
21882201
21892202 # Format the filesystem
21902203 for partition in partitions :
2204+ # unformatted partition
2205+ if partition ['filesystem' ] is None :
2206+ continue
2207+
21912208 ptype = self ._get_partition_type (partition )
21922209 # Do not format BIOS boot partition
21932210 if ptype == PartitionType .BIOS :
21942211 continue
21952212 if ptype == PartitionType .SWAP :
2196- mkfs_cmd = [' mkswap' ]
2213+ mkfs_cmd = [" mkswap" ]
21972214 else :
2198- mkfs_cmd = [' mkfs' , '-t' , partition ['filesystem' ]]
2215+ mkfs_cmd = [" mkfs" , "-t" , partition ['filesystem' ]]
21992216
22002217 # Add force option to mkfs to override previously created partition
22012218 if partition ["filesystem" ] in ["btrfs" , "xfs" ]:
2202- mkfs_cmd .extend ([ '-f' ] )
2219+ mkfs_cmd .append ( "-f" )
22032220
22042221 if 'mkfs_options' in partition :
22052222 options = partition ['mkfs_options' ].split ()
22062223 mkfs_cmd .extend (options )
22072224
2225+ # fs level label
2226+ if partition .get ('label' ) is not None :
2227+ # label options are "-L" for all supqported filesystems including swap, except for vfat
2228+ if partition ["filesystem" ] == "vfat" :
2229+ mkfs_cmd .extend (["-n" , partition ['label' ]])
2230+ else :
2231+ mkfs_cmd .extend (["-L" , partition ['label' ]])
2232+
22082233 mkfs_cmd .extend ([partition ['path' ]])
22092234 retval = self .cmd .run (mkfs_cmd )
22102235
0 commit comments