mirror of
https://github.com/rancher/os.git
synced 2025-09-02 15:24:32 +00:00
Merge pull request #1890 from SvenDowideit/resize_and_autoformat
Test resize, and update docs
This commit is contained in:
@@ -125,11 +125,15 @@ func WriteFiles(cfg *rancherConfig.CloudConfig, container string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func applyPreConsole(cfg *rancherConfig.CloudConfig) {
|
func applyPreConsole(cfg *rancherConfig.CloudConfig) {
|
||||||
if _, err := os.Stat(resizeStamp); os.IsNotExist(err) && cfg.Rancher.ResizeDevice != "" {
|
if cfg.Rancher.ResizeDevice != "" {
|
||||||
if err := resizeDevice(cfg); err == nil {
|
if _, err := os.Stat(resizeStamp); os.IsNotExist(err) {
|
||||||
os.Create(resizeStamp)
|
if err := resizeDevice(cfg); err == nil {
|
||||||
|
os.Create(resizeStamp)
|
||||||
|
} else {
|
||||||
|
log.Errorf("Failed to resize %s: %s", cfg.Rancher.ResizeDevice, err)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
log.Errorf("Failed to resize %s: %s", cfg.Rancher.ResizeDevice, err)
|
log.Infof("Skipped resizing %s because %s exists", cfg.Rancher.ResizeDevice, resizeStamp)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -45,10 +45,9 @@ func bootstrapAction(c *cli.Context) error {
|
|||||||
waitForRoot(cfg)
|
waitForRoot(cfg)
|
||||||
}
|
}
|
||||||
|
|
||||||
autoformatDevices := cfg.Rancher.State.Autoformat
|
if len(cfg.Rancher.State.Autoformat) > 0 {
|
||||||
log.Debugf("bootstrapAction: Autoformat(%v)", cfg.Rancher.State.Autoformat)
|
log.Infof("bootstrap container: Autoformat(%v) as %s", cfg.Rancher.State.Autoformat, "ext4")
|
||||||
if len(autoformatDevices) > 0 {
|
if err := autoformat(cfg.Rancher.State.Autoformat); err != nil {
|
||||||
if err := autoformat(autoformatDevices); err != nil {
|
|
||||||
log.Errorf("Failed to run autoformat: %v", err)
|
log.Errorf("Failed to run autoformat: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -7,7 +7,7 @@ layout: os-default
|
|||||||
## Resizing a Device Partition
|
## 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.
|
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.
|
||||||
|
|
||||||
|
@@ -14,16 +14,23 @@ rancher:
|
|||||||
state:
|
state:
|
||||||
fstype: auto
|
fstype: auto
|
||||||
dev: LABEL=RANCHER_STATE
|
dev: LABEL=RANCHER_STATE
|
||||||
autoformat:
|
|
||||||
- /dev/sda
|
|
||||||
- /dev/vda
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### Autoformat
|
### 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
|
* Contains a boot2docker magic string
|
||||||
* Starts with 1 megabyte of zeros and `rancher.state.formatzero` is true
|
* Starts with 1 megabyte of zeros and `rancher.state.formatzero` is true
|
||||||
|
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
#cloud-config
|
||||||
|
rancher:
|
||||||
|
state:
|
||||||
|
autoformat:
|
||||||
|
- /dev/sda
|
||||||
|
- /dev/vda
|
||||||
|
```
|
||||||
|
@@ -58,7 +58,6 @@ func stopDocker(c chan interface{}) error {
|
|||||||
|
|
||||||
func bootstrap(cfg *config.CloudConfig) error {
|
func bootstrap(cfg *config.CloudConfig) error {
|
||||||
log.Info("Launching Bootstrap Docker")
|
log.Info("Launching Bootstrap Docker")
|
||||||
log.Infof("bootstrap container: Autoformat(%v)", cfg.Rancher.State.Autoformat)
|
|
||||||
|
|
||||||
c, err := startDocker(cfg)
|
c, err := startDocker(cfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@@ -22,6 +22,10 @@ while [ "$#" -gt 0 ]; do
|
|||||||
QIND=0
|
QIND=0
|
||||||
REBUILD=0
|
REBUILD=0
|
||||||
;;
|
;;
|
||||||
|
--resizehd)
|
||||||
|
shift 1
|
||||||
|
RESIZEHD=$1
|
||||||
|
;;
|
||||||
--pxe)
|
--pxe)
|
||||||
BOOT_PXE=1
|
BOOT_PXE=1
|
||||||
;;
|
;;
|
||||||
@@ -198,6 +202,10 @@ if [ "$QEMU" == "1" ] || [ "$BOOT_ISO" == "1" ] || [ "$BOOT_HD" == "1" ]; then
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
else
|
||||||
|
if [ "$RESIZEHD" != "" ]; then
|
||||||
|
qemu-img resize ${HD} ${RESIZEHD}
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$SECOND_DRIVE" == "1" ]; then
|
if [ "$SECOND_DRIVE" == "1" ]; then
|
||||||
|
@@ -2,6 +2,7 @@ package integration
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
. "gopkg.in/check.v1"
|
. "gopkg.in/check.v1"
|
||||||
@@ -117,3 +118,44 @@ sync
|
|||||||
s.CheckOutput(c, version, Equals, "sudo ros -v")
|
s.CheckOutput(c, version, Equals, "sudo ros -v")
|
||||||
s.Stop(c)
|
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)
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user