growpart/rootgrow
Robert Schweikert b71ffcb776 - Update to version 0.30 (bsc#1064755)
+ improved error messages on failure.
  + ignore sfdisk failure in 2.28.1 when due to reread failing
   (LP: #1619285)
  + Add service file to start growpart via systemd
  + Add rootgrow script to wrap growpart

OBS-URL: https://build.opensuse.org/package/show/Cloud:Tools/growpart?expand=0&rev=7
2018-01-23 13:48:13 +00:00

58 lines
1.5 KiB
Python

#!/usr/bin/python3
import os
import re
import syslog
split_dev = re.compile('([a-z/]*)(\d*)')
mounts = open('/proc/mounts' ,'r').readlines()
def get_mount_point(device):
for mount in mounts:
if mount.startswith(device):
return mount.split(' ')[1]
def resize_fs(fs_type, device):
if fs_type.startswith('ext'):
cmd = 'resize2fs %s' % device
syslog.syslog(
syslog.LOG_INFO,
'Resizing: "%s"' %cmd
)
os.system(cmd)
elif fs_type == 'xfs':
mnt_point = get_mount_point(device)
cmd = 'xfs_growfs %s' % mnt_point
syslog.syslog(
syslog.LOG_INFO,
'Resizing: "%s"' %cmd
)
os.system(cmd)
for mount in mounts:
if ' / ' in mount:
mount_dev = mount.split(' ')[0]
fs = mount.split(' ')[2]
try:
dev, partition = split_dev.match(mount_dev).groups()
except:
syslog.syslog(
syslog.LOG_ERR,
'match exception for "%s"' % mount
)
break
if dev and partition:
cmd = '/usr/sbin/growpart %s %s' %(dev, partition)
syslog.syslog(
syslog.LOG_INFO,
'Executing: "%s"' % cmd
)
os.system(cmd)
resize_fs(fs, mount_dev)
else:
syslog.syslog(
syslog.LOG_ERR,
'could not match device and partition in "%s"' % mount
)