diff options
Diffstat (limited to 'cloudinit/config/cc_disk_setup.py')
-rw-r--r-- | cloudinit/config/cc_disk_setup.py | 36 |
1 files changed, 13 insertions, 23 deletions
diff --git a/cloudinit/config/cc_disk_setup.py b/cloudinit/config/cc_disk_setup.py index 0c4b794d..38df13ab 100644 --- a/cloudinit/config/cc_disk_setup.py +++ b/cloudinit/config/cc_disk_setup.py @@ -1,21 +1,9 @@ -# vi: ts=4 expandtab -# -# Copyright (C) 2009-2010 Canonical Ltd. -# Copyright (C) 2012 Hewlett-Packard Development Company, L.P. -# -# Author: Ben Howard <ben.howard@canonical.com> -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License version 3, as -# published by the Free Software Foundation. +# Copyright (C) 2009-2010 Canonical Ltd. +# Copyright (C) 2012 Hewlett-Packard Development Company, L.P. # -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. +# Author: Ben Howard <ben.howard@canonical.com> # -# You should have received a copy of the GNU General Public License -# along with this program. If not, see <http://www.gnu.org/licenses/>. +# This file is part of cloud-init. See LICENSE file for license information. """ Disk Setup @@ -436,14 +424,13 @@ def get_dyn_func(*args): def get_mbr_hdd_size(device): - size_cmd = [SFDISK_CMD, '--show-size', device] - size = None try: - size, _err = util.subp(size_cmd) + size_in_bytes, _ = util.subp([BLKDEV_CMD, '--getsize64', device]) + sector_size, _ = util.subp([BLKDEV_CMD, '--getss', device]) except Exception as e: raise Exception("Failed to get %s size\n%s" % (device, e)) - return int(size.strip()) + return int(size_in_bytes) / int(sector_size) def get_gpt_hdd_size(device): @@ -588,7 +575,7 @@ def get_partition_mbr_layout(size, layout): raise Exception("Partition was incorrectly defined: %s" % part) percent, part_type = part - part_size = int((float(size) * (float(percent) / 100)) / 1024) + part_size = int(float(size) * (float(percent) / 100)) if part_num == last_part_num: part_definition.append(",,%s" % part_type) @@ -692,7 +679,7 @@ def exec_mkpart_mbr(device, layout): types, i.e. gpt """ # Create the partitions - prt_cmd = [SFDISK_CMD, "--Linux", "-uM", device] + prt_cmd = [SFDISK_CMD, "--Linux", "--unit=S", "--force", device] try: util.subp(prt_cmd, data="%s\n" % layout) except Exception as e: @@ -909,7 +896,8 @@ def mkfs(fs_cfg): LOG.debug("Error in device identification handling.") return - LOG.debug("File system %s will be created on %s", label, device) + LOG.debug("File system type '%s' with label '%s' will be created on %s", + fs_type, label, device) # Make sure the device is defined if not device: @@ -958,3 +946,5 @@ def mkfs(fs_cfg): util.subp(fs_cmd) except Exception as e: raise Exception("Failed to exec of '%s':\n%s" % (fs_cmd, e)) + +# vi: ts=4 expandtab |