1
0
mirror of https://github.com/rancher/os.git synced 2025-08-31 06:11:12 +00:00

Merge pull request #1890 from SvenDowideit/resize_and_autoformat

Test resize, and update docs
This commit is contained in:
Sven Dowideit
2017-06-05 15:46:13 +10:00
committed by GitHub
7 changed files with 74 additions and 15 deletions

View File

@@ -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)
}
}

View File

@@ -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)
}
}

View File

@@ -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.

View File

@@ -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
```

View File

@@ -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 {

View File

@@ -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

View File

@@ -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)
}