disk: Partition.Payload is now an Entity
Partition.Payload now supports every type of disk.Entity which enables creating PartitionTables with LUKS, LVM, and Btrfs. \o/ Co-Authored-By: Achilleas Koutsou <achilleas@koutsou.net>
This commit is contained in:
parent
206e030f2c
commit
d1b1e32b6e
5 changed files with 25 additions and 36 deletions
|
|
@ -15,7 +15,7 @@ type Partition struct {
|
|||
UUID string
|
||||
|
||||
// If nil, the partition is raw; It doesn't contain a payload.
|
||||
Payload *Filesystem
|
||||
Payload Entity
|
||||
}
|
||||
|
||||
func (p *Partition) IsContainer() bool {
|
||||
|
|
@ -27,24 +27,19 @@ func (p *Partition) Clone() Entity {
|
|||
return nil
|
||||
}
|
||||
|
||||
ent := p.Payload.Clone()
|
||||
var fs *Filesystem
|
||||
if ent != nil {
|
||||
fsEnt, cloneOk := ent.(*Filesystem)
|
||||
if !cloneOk {
|
||||
panic("Filesystem.Clone() returned an Entity that cannot be converted to *Filesystem; this is a programming error")
|
||||
}
|
||||
fs = fsEnt
|
||||
}
|
||||
|
||||
return &Partition{
|
||||
partition := &Partition{
|
||||
Start: p.Start,
|
||||
Size: p.Size,
|
||||
Type: p.Type,
|
||||
Bootable: p.Bootable,
|
||||
UUID: p.UUID,
|
||||
Payload: fs,
|
||||
}
|
||||
|
||||
if p.Payload != nil {
|
||||
partition.Payload = p.Payload.Clone()
|
||||
}
|
||||
|
||||
return partition
|
||||
}
|
||||
|
||||
func (pt *Partition) GetItemCount() uint {
|
||||
|
|
|
|||
|
|
@ -71,7 +71,8 @@ func NewQEMUAssemblerOptions(pt *disk.PartitionTable) QEMUAssemblerOptions {
|
|||
func NewQEMUPartition(p *disk.Partition) QEMUPartition {
|
||||
var fs *QEMUFilesystem
|
||||
if p.Payload != nil {
|
||||
f := NewQEMUFilesystem(p.Payload)
|
||||
// NOTE: Partition Payload for QEMU assembler should always be a Filesystem
|
||||
f := NewQEMUFilesystem(p.Payload.(*disk.Filesystem))
|
||||
fs = &f
|
||||
}
|
||||
return QEMUPartition{
|
||||
|
|
|
|||
|
|
@ -107,9 +107,13 @@ func NewGrub2InstStageOption(filename string, pt *disk.PartitionTable, platform
|
|||
if partition.Payload == nil {
|
||||
continue
|
||||
}
|
||||
if partition.Payload.GetMountpoint() == "/boot" {
|
||||
mnt, isMountable := partition.Payload.(disk.Mountable)
|
||||
if !isMountable {
|
||||
continue
|
||||
}
|
||||
if mnt.GetMountpoint() == "/boot" {
|
||||
bootIdx = idx
|
||||
} else if partition.Payload.GetMountpoint() == "/" {
|
||||
} else if mnt.GetMountpoint() == "/" {
|
||||
rootIdx = idx
|
||||
}
|
||||
}
|
||||
|
|
@ -123,7 +127,7 @@ func NewGrub2InstStageOption(filename string, pt *disk.PartitionTable, platform
|
|||
}
|
||||
|
||||
bootPart := pt.Partitions[bootIdx]
|
||||
bootPayload := bootPart.Payload
|
||||
bootPayload := bootPart.Payload.(disk.Mountable) // this is guaranteed by the search loop above
|
||||
prefixPath := "/boot/grub2"
|
||||
if bootPayload.GetMountpoint() == "/boot" {
|
||||
prefixPath = "/grub2"
|
||||
|
|
|
|||
|
|
@ -49,23 +49,7 @@ func NewGrub2StageOptions(pt *disk.PartitionTable,
|
|||
vendor string,
|
||||
install bool) *GRUB2StageOptions {
|
||||
|
||||
var bootFs, rootFs disk.Mountable
|
||||
for idx := range pt.Partitions {
|
||||
// NOTE: we only support having /boot at the top level of the partition
|
||||
// table (e.g., not in LUKS or LVM), so we don't need to descend into
|
||||
// VolumeContainer types. If /boot is on the root partition, then the
|
||||
// root partition needs to be at the top level.
|
||||
partition := &pt.Partitions[idx]
|
||||
if partition.Payload == nil {
|
||||
continue
|
||||
}
|
||||
if partition.Payload.GetMountpoint() == "/boot" {
|
||||
bootFs = partition.Payload
|
||||
} else if partition.Payload.GetMountpoint() == "/" {
|
||||
rootFs = partition.Payload
|
||||
}
|
||||
}
|
||||
|
||||
rootFs := pt.FindMountable("/")
|
||||
if rootFs == nil {
|
||||
panic("root filesystem must be defined for grub2 stage, this is a programming error")
|
||||
}
|
||||
|
|
@ -76,6 +60,7 @@ func NewGrub2StageOptions(pt *disk.PartitionTable,
|
|||
Legacy: legacy,
|
||||
}
|
||||
|
||||
bootFs := pt.FindMountable("/boot")
|
||||
if bootFs != nil {
|
||||
bootFsUUID := uuid.MustParse(bootFs.GetFSSpec().UUID)
|
||||
stageOptions.BootFilesystemUUID = &bootFsUUID
|
||||
|
|
|
|||
|
|
@ -42,9 +42,13 @@ func NewZiplInstStageOptions(kernel string, pt *disk.PartitionTable) *ZiplInstSt
|
|||
if partition.Payload == nil {
|
||||
continue
|
||||
}
|
||||
if partition.Payload.GetMountpoint() == "/boot" {
|
||||
mnt, isMountable := partition.Payload.(disk.Mountable)
|
||||
if !isMountable {
|
||||
continue
|
||||
}
|
||||
if mnt.GetMountpoint() == "/boot" {
|
||||
bootIdx = idx
|
||||
} else if partition.Payload.GetMountpoint() == "/" {
|
||||
} else if mnt.GetMountpoint() == "/" {
|
||||
rootIdx = idx
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue