diff --git a/cmd/cloudinitexecute/cloudinitexecute.go b/cmd/cloudinitexecute/cloudinitexecute.go index a151602a..f77a0412 100644 --- a/cmd/cloudinitexecute/cloudinitexecute.go +++ b/cmd/cloudinitexecute/cloudinitexecute.go @@ -125,11 +125,15 @@ func WriteFiles(cfg *rancherConfig.CloudConfig, container string) { } func applyPreConsole(cfg *rancherConfig.CloudConfig) { - if _, err := os.Stat(resizeStamp); os.IsNotExist(err) && cfg.Rancher.ResizeDevice != "" { - if err := resizeDevice(cfg); err == nil { - os.Create(resizeStamp) + if cfg.Rancher.ResizeDevice != "" { + if _, err := os.Stat(resizeStamp); os.IsNotExist(err) { + if err := resizeDevice(cfg); err == nil { + os.Create(resizeStamp) + } else { + log.Errorf("Failed to resize %s: %s", cfg.Rancher.ResizeDevice, err) + } } else { - log.Errorf("Failed to resize %s: %s", cfg.Rancher.ResizeDevice, err) + log.Infof("Skipped resizing %s because %s exists", cfg.Rancher.ResizeDevice, resizeStamp) } } diff --git a/cmd/control/bootstrap.go b/cmd/control/bootstrap.go index 35f0405f..b069c8a3 100644 --- a/cmd/control/bootstrap.go +++ b/cmd/control/bootstrap.go @@ -45,10 +45,9 @@ func bootstrapAction(c *cli.Context) error { waitForRoot(cfg) } - autoformatDevices := cfg.Rancher.State.Autoformat - log.Debugf("bootstrapAction: Autoformat(%v)", cfg.Rancher.State.Autoformat) - if len(autoformatDevices) > 0 { - if err := autoformat(autoformatDevices); err != nil { + if len(cfg.Rancher.State.Autoformat) > 0 { + log.Infof("bootstrap container: Autoformat(%v) as %s", cfg.Rancher.State.Autoformat, "ext4") + if err := autoformat(cfg.Rancher.State.Autoformat); err != nil { log.Errorf("Failed to run autoformat: %v", err) } } diff --git a/docs/os/configuration/resizing-device-partition/index.md b/docs/os/configuration/resizing-device-partition/index.md index 428d73e9..92c70660 100644 --- a/docs/os/configuration/resizing-device-partition/index.md +++ b/docs/os/configuration/resizing-device-partition/index.md @@ -7,7 +7,7 @@ layout: os-default ## Resizing a Device Partition --- -The `resize_device` cloud config option can be used to automatically extend the first partition to fill the size of it's device. +The `resize_device` cloud config option can be used to automatically extend the first partition (assuming its `ext4`) to fill the size of it's device. Once the partition has been resized to fill the device, a `/var/lib/rancher/resizefs.done` file will be written to prevent the resize tools from being run again. If you need it to run again, delete that file and reboot. diff --git a/docs/os/storage/state-partition/index.md b/docs/os/storage/state-partition/index.md index aa81c33c..cacfe7cd 100644 --- a/docs/os/storage/state-partition/index.md +++ b/docs/os/storage/state-partition/index.md @@ -14,16 +14,23 @@ rancher: state: fstype: auto dev: LABEL=RANCHER_STATE - autoformat: - - /dev/sda - - /dev/vda ``` ### Autoformat -You can specify a list of devices to check to format on boot. If the state partition is already found, RancherOS will not try to auto format a partition. By default, auto-formatting is off. +You can specify a list of devices to check to format on boot. If the state partition is already found, RancherOS will not try to auto format a partition. By default, auto-formatting is off. -RancherOS will autoformat the partition to ext4 if the device specified in `autoformat`: +RancherOS will autoformat the partition to `ext4` (_not_ what is set in `fstype`) if the device specified in `autoformat`: * Contains a boot2docker magic string * Starts with 1 megabyte of zeros and `rancher.state.formatzero` is true + + +```yaml +#cloud-config +rancher: + state: + autoformat: + - /dev/sda + - /dev/vda +``` diff --git a/init/bootstrap.go b/init/bootstrap.go index a3ca9384..f1c8788d 100644 --- a/init/bootstrap.go +++ b/init/bootstrap.go @@ -58,7 +58,6 @@ func stopDocker(c chan interface{}) error { func bootstrap(cfg *config.CloudConfig) error { log.Info("Launching Bootstrap Docker") - log.Infof("bootstrap container: Autoformat(%v)", cfg.Rancher.State.Autoformat) c, err := startDocker(cfg) if err != nil { diff --git a/scripts/run b/scripts/run index bd230448..73cf0659 100755 --- a/scripts/run +++ b/scripts/run @@ -22,6 +22,10 @@ while [ "$#" -gt 0 ]; do QIND=0 REBUILD=0 ;; + --resizehd) + shift 1 + RESIZEHD=$1 + ;; --pxe) BOOT_PXE=1 ;; @@ -198,6 +202,10 @@ if [ "$QEMU" == "1" ] || [ "$BOOT_ISO" == "1" ] || [ "$BOOT_HD" == "1" ]; then fi fi fi + else + if [ "$RESIZEHD" != "" ]; then + qemu-img resize ${HD} ${RESIZEHD} + fi fi if [ "$SECOND_DRIVE" == "1" ]; then diff --git a/tests/installer_test.go b/tests/installer_test.go index 22a7fde6..e48dd52b 100755 --- a/tests/installer_test.go +++ b/tests/installer_test.go @@ -2,6 +2,7 @@ package integration import ( "fmt" + "strings" "time" . "gopkg.in/check.v1" @@ -117,3 +118,44 @@ sync s.CheckOutput(c, version, Equals, "sudo ros -v") s.Stop(c) } + +func (s *QemuSuite) TestAutoResize(c *C) { + runArgs := []string{ + "--iso", + "--fresh", + } + version := "" + disk := "/dev/vda1\n" + size := "" + { + s.RunQemuWith(c, runArgs...) + + version = s.CheckOutput(c, version, Not(Equals), "sudo ros -v") + fmt.Printf("installing %s", version) + + s.CheckCall(c, ` +set -ex +echo "ssh_authorized_keys:" > config.yml +echo " - $(cat /home/rancher/.ssh/authorized_keys)" >> config.yml +sudo ros install --force --no-reboot --device /dev/vda -c config.yml --append "rancher.resize_device=/dev/vda" +sync +`) + time.Sleep(500 * time.Millisecond) + s.CheckCall(c, "sudo mount "+strings.TrimSpace(disk)+" /mnt") + size = s.CheckOutput(c, size, Not(Equals), "df -h | grep "+strings.TrimSpace(disk)+" | head -n1 | sed 's/ \\+/;/g' | cut -d ';' -f 2") + s.Stop(c) + } + + // ./scripts/run --no-format --append "rancher.debug=true" + runArgs = []string{ + "--boothd", + "--resizehd", "+20G", + } + s.RunQemuWith(c, runArgs...) + + s.CheckOutput(c, version, Equals, "sudo ros -v") + s.CheckOutput(c, disk, Equals, "blkid | cut -f 1 -d ' ' | sed 's/://'") + s.CheckOutput(c, size, Not(Equals), "df -h | grep "+strings.TrimSpace(disk)+" | head -n1 | sed 's/ \\+/;/g' | cut -d ';' -f 2") + + s.Stop(c) +}