Resync helpers for better disk cleaning

This commit is contained in:
James Page 2014-04-14 15:40:20 +01:00
parent 89b1b74f2e
commit e75f199ba0
1 changed files with 12 additions and 3 deletions

View File

@ -2,7 +2,9 @@ from os import stat
from stat import S_ISBLK
from subprocess import (
check_call
check_call,
check_output,
call
)
@ -22,5 +24,12 @@ def zap_disk(block_device):
:param block_device: str: Full path of block device to clean.
'''
check_call(['sgdisk', '--zap-all', '--clear',
'--mbrtogpt', block_device])
# sometimes sgdisk exits non-zero; this is OK, dd will clean up
call(['sgdisk', '--zap-all', '--mbrtogpt',
'--clear', block_device])
dev_end = check_output(['blockdev', '--getsz', block_device])
gpt_end = int(dev_end.split()[0]) - 100
check_call(['dd', 'if=/dev/zero', 'of=%s'%(block_device),
'bs=1M', 'count=1'])
check_call(['dd', 'if=/dev/zero', 'of=%s'%(block_device),
'bs=512', 'count=100', 'seek=%s'%(gpt_end)])