13
16
:returns: boolean: True if path is a block device, False if not.
15
return S_ISBLK(stat(path).st_mode)
18
if not os.path.exists(path):
20
return S_ISBLK(os.stat(path).st_mode)
18
23
def zap_disk(block_device):
23
28
:param block_device: str: Full path of block device to clean.
25
check_call(['sgdisk', '--zap-all', '--clear',
26
'--mbrtogpt', block_device])
30
# sometimes sgdisk exits non-zero; this is OK, dd will clean up
31
call(['sgdisk', '--zap-all', '--mbrtogpt',
32
'--clear', block_device])
33
dev_end = check_output(['blockdev', '--getsz', block_device])
34
gpt_end = int(dev_end.split()[0]) - 100
35
check_call(['dd', 'if=/dev/zero', 'of=%s' % (block_device),
37
check_call(['dd', 'if=/dev/zero', 'of=%s' % (block_device),
38
'bs=512', 'count=100', 'seek=%s' % (gpt_end)])
40
def is_device_mounted(device):
41
'''Given a device path, return True if that device is mounted, and False
44
:param device: str: Full path of the device to check.
45
:returns: boolean: True if the path represents a mounted device, False if
48
out = check_output(['mount'])
49
return bool(re.search(device + r"[0-9]+\b", out))