mirror of
https://github.com/clearlinux/clr-installer.git
synced 2026-10-03 23:48:23 +00:00
storage: remove logical volumes during wipe
Fixes: #623 If a whole disk is used that contains logical volumes, they need to be removed before re-using the disk. Signed-off-by: Mark D Horn <mark.d.horn@intel.com>
This commit is contained in:
@@ -109,6 +109,10 @@ msgstr "Test connectivity"
|
||||
msgid "Test Network Settings"
|
||||
msgstr "Test Network Settings"
|
||||
|
||||
#, c-format
|
||||
msgid "Removing logical disk volume: %s"
|
||||
msgstr "Removing logical disk volume: %s"
|
||||
|
||||
#, c-format
|
||||
msgid "Writing partition table to: %s"
|
||||
msgstr "Writing partition table to: %s"
|
||||
@@ -508,6 +512,9 @@ msgstr "Selected media will have partitions added."
|
||||
msgid "WARNING: New Partition table will be created."
|
||||
msgstr "WARNING: New Partition table will be created."
|
||||
|
||||
msgid "WARNING: Logical Volume will be removed."
|
||||
msgstr "WARNING: Logical Volume will be removed."
|
||||
|
||||
msgid "WARNING: Selected media will be erased."
|
||||
msgstr "WARNING: Selected media will be erased."
|
||||
|
||||
|
||||
@@ -109,6 +109,10 @@ msgstr "Conectividad de prueba"
|
||||
msgid "Test Network Settings"
|
||||
msgstr "Probar la configuración de red"
|
||||
|
||||
#, c-format
|
||||
msgid "Removing logical disk volume: %s"
|
||||
msgstr "Eliminando volumen de disco lógico: %s"
|
||||
|
||||
#, c-format
|
||||
msgid "Writing partition table to: %s"
|
||||
msgstr "Escribiendo la tabla de particiones en %s"
|
||||
@@ -508,6 +512,9 @@ msgstr "Se añadirán particiones a los medios seleccionados."
|
||||
msgid "WARNING: New Partition table will be created."
|
||||
msgstr "ADVERTENCIA: se creará una nueva tabla de particiones."
|
||||
|
||||
msgid "WARNING: Logical Volume will be removed."
|
||||
msgstr "ADVERTENCIA: se eliminará el volumen lógico."
|
||||
|
||||
msgid "WARNING: Selected media will be erased."
|
||||
msgstr "ADVERTENCIA: los medios seleccionados se borrarán."
|
||||
|
||||
|
||||
@@ -109,6 +109,10 @@ msgstr "测试连接"
|
||||
msgid "Test Network Settings"
|
||||
msgstr "测试网络设置"
|
||||
|
||||
#, c-format
|
||||
msgid "Removing logical disk volume: %s"
|
||||
msgstr "正在删除逻辑磁盘卷:% s"
|
||||
|
||||
#, c-format
|
||||
msgid "Writing partition table to: %s"
|
||||
msgstr "正在将分区表写入:%s"
|
||||
@@ -508,6 +512,9 @@ msgstr "选定的媒介将添加分区。"
|
||||
msgid "WARNING: New Partition table will be created."
|
||||
msgstr "警告: 将创建新的分区表。"
|
||||
|
||||
msgid "WARNING: Logical Volume will be removed."
|
||||
msgstr "警告:逻辑卷将被删除。"
|
||||
|
||||
msgid "WARNING: Selected media will be erased."
|
||||
msgstr "警告: 选定的媒介将被删除。"
|
||||
|
||||
|
||||
@@ -237,6 +237,78 @@ func getStartEndMB(start uint64, end uint64) string {
|
||||
return strStart + " " + strEnd
|
||||
}
|
||||
|
||||
func (bd *BlockDevice) removeLogicalVolume() error {
|
||||
if bd.Type != BlockDeviceTypeLVM2Volume {
|
||||
return errors.Errorf("Block Type is not logical volume")
|
||||
}
|
||||
|
||||
mesg := utils.Locale.Get("Removing logical disk volume: %s", bd.Name)
|
||||
prg := progress.NewLoop(mesg)
|
||||
log.Info(mesg)
|
||||
args := []string{
|
||||
"dmsetup",
|
||||
"remove",
|
||||
bd.Name,
|
||||
}
|
||||
|
||||
err := cmd.RunAndLog(args...)
|
||||
if err != nil {
|
||||
return errors.Wrap(err)
|
||||
}
|
||||
|
||||
prg.Success()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// findLogicalVolumes finds lvm2 volumes defined on this block device
|
||||
// called by WritePartitionTable to ensure we properly remove logical volumes
|
||||
// prior to wiping the disk partition table.
|
||||
func findLogicalVolumes(dryRun *[]string, blockDevices []*BlockDevice) error {
|
||||
var err error
|
||||
|
||||
for _, bd := range blockDevices {
|
||||
if bd.Type == BlockDeviceTypeLVM2Volume {
|
||||
if dryRun != nil {
|
||||
*dryRun = append(*dryRun, bd.Name+": "+utils.Locale.Get(LogicalVolumeWarning))
|
||||
} else {
|
||||
if err = bd.removeLogicalVolume(); err != nil {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if bd.Children != nil {
|
||||
if err = findLogicalVolumes(dryRun, bd.Children); err != nil {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func (bd *BlockDevice) removeAllLogicalVolumes(dryRun *[]string) error {
|
||||
var err error
|
||||
w := bytes.NewBuffer(nil)
|
||||
|
||||
err = cmd.Run(w, lsblkBinary, "-J", "-b", "-O", bd.GetDeviceFile())
|
||||
if err != nil {
|
||||
return fmt.Errorf("%s", w.String())
|
||||
}
|
||||
|
||||
bds, err := parseBlockDevicesDescriptor(w.Bytes())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := findLogicalVolumes(dryRun, bds); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// WritePartitionLabel make a device a 'gpt' partition type
|
||||
// Only call when we are wiping and reusing the entire disk
|
||||
func (bd *BlockDevice) WritePartitionLabel() error {
|
||||
@@ -271,6 +343,12 @@ func (bd *BlockDevice) WritePartitionTable(legacyBios bool, wholeDisk bool, dryR
|
||||
return errors.Errorf("Type is partition, disk required")
|
||||
}
|
||||
|
||||
if wholeDisk {
|
||||
if err := bd.removeAllLogicalVolumes(dryRun); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
var prg progress.Progress
|
||||
|
||||
//write the partition label
|
||||
|
||||
@@ -158,6 +158,9 @@ const (
|
||||
// PartitioningWarning specifies the warning message for writing partition table
|
||||
PartitioningWarning = "WARNING: New Partition table will be created."
|
||||
|
||||
// LogicalVolumeWarning specifies the warning message when removing a logical volume
|
||||
LogicalVolumeWarning = "WARNING: Logical Volume will be removed."
|
||||
|
||||
// DestructiveWarning specifies the warning message for destructive installation
|
||||
DestructiveWarning = "WARNING: Selected media will be erased."
|
||||
|
||||
|
||||
Reference in New Issue
Block a user