diff --git a/examples/cadvisor.yml b/examples/cadvisor.yml index 7206d9366..66e87d019 100644 --- a/examples/cadvisor.yml +++ b/examples/cadvisor.yml @@ -15,7 +15,7 @@ onboot: - name: sysfs image: linuxkit/sysfs:23a13bbf83bf666ef6a3ba7b3ebba35d2daead98 - name: format - image: linuxkit/format:8f487d728959192289e0783784fc2b185eadbc82 + image: linuxkit/format:ced02d849206371b6983eff1eb28f9515406fef0 - name: mount image: linuxkit/mount:2a507ef30302693682f9f612289028df00c58ac5 command: ["/usr/bin/mountie", "/var/lib/docker"] diff --git a/examples/dm-crypt-loop.yml b/examples/dm-crypt-loop.yml index e762d588b..dfb990705 100644 --- a/examples/dm-crypt-loop.yml +++ b/examples/dm-crypt-loop.yml @@ -13,7 +13,7 @@ onboot: image: linuxkit/dhcpcd:f46134c05f9665d8865a9fbebd5be0995057af28 command: ["/sbin/dhcpcd", "--nobackground", "-f", "/dhcpcd.conf", "-1"] - name: format - image: linuxkit/format:8f487d728959192289e0783784fc2b185eadbc82 + image: linuxkit/format:ced02d849206371b6983eff1eb28f9515406fef0 command: ["/usr/bin/format", "/dev/sda"] - name: mount image: linuxkit/mount:2a507ef30302693682f9f612289028df00c58ac5 diff --git a/examples/dm-crypt.yml b/examples/dm-crypt.yml index 4dc1f69ac..94322d349 100644 --- a/examples/dm-crypt.yml +++ b/examples/dm-crypt.yml @@ -13,7 +13,7 @@ onboot: image: linuxkit/dhcpcd:f46134c05f9665d8865a9fbebd5be0995057af28 command: ["/sbin/dhcpcd", "--nobackground", "-f", "/dhcpcd.conf", "-1"] - name: format - image: linuxkit/format:8f487d728959192289e0783784fc2b185eadbc82 + image: linuxkit/format:ced02d849206371b6983eff1eb28f9515406fef0 command: ["/usr/bin/format", "/dev/sda"] - name: dm-crypt image: linuxkit/dm-crypt:ad2a05dcffa28ef809a61aa27ba230c82f02f603 diff --git a/examples/docker-for-mac.yml b/examples/docker-for-mac.yml index 2a31d6bd7..70ab1d368 100644 --- a/examples/docker-for-mac.yml +++ b/examples/docker-for-mac.yml @@ -20,7 +20,7 @@ onboot: image: linuxkit/binfmt:564e110729c8d8ecc365979a7d149e2851942883 # Format and mount the disk image in /var/lib/docker - name: format - image: linuxkit/format:8f487d728959192289e0783784fc2b185eadbc82 + image: linuxkit/format:ced02d849206371b6983eff1eb28f9515406fef0 - name: mount image: linuxkit/mount:2a507ef30302693682f9f612289028df00c58ac5 command: ["/usr/bin/mountie", "/var/lib"] diff --git a/examples/docker.yml b/examples/docker.yml index 80bef156a..38583d173 100644 --- a/examples/docker.yml +++ b/examples/docker.yml @@ -12,7 +12,7 @@ onboot: - name: sysfs image: linuxkit/sysfs:23a13bbf83bf666ef6a3ba7b3ebba35d2daead98 - name: format - image: linuxkit/format:8f487d728959192289e0783784fc2b185eadbc82 + image: linuxkit/format:ced02d849206371b6983eff1eb28f9515406fef0 - name: mount image: linuxkit/mount:2a507ef30302693682f9f612289028df00c58ac5 command: ["/usr/bin/mountie", "/var/lib/docker"] diff --git a/examples/swap.yml b/examples/swap.yml index 247cf2ddb..e3f0b942a 100644 --- a/examples/swap.yml +++ b/examples/swap.yml @@ -13,7 +13,7 @@ onboot: image: linuxkit/dhcpcd:f46134c05f9665d8865a9fbebd5be0995057af28 command: ["/sbin/dhcpcd", "--nobackground", "-f", "/dhcpcd.conf", "-1"] - name: format - image: linuxkit/format:8f487d728959192289e0783784fc2b185eadbc82 + image: linuxkit/format:ced02d849206371b6983eff1eb28f9515406fef0 - name: mount image: linuxkit/mount:2a507ef30302693682f9f612289028df00c58ac5 command: ["/usr/bin/mountie", "/var/external"] diff --git a/pkg/format/format.go b/pkg/format/format.go index baacd50fc..adb5b405d 100644 --- a/pkg/format/format.go +++ b/pkg/format/format.go @@ -20,13 +20,14 @@ const ( ) var ( - labelVar string - fsTypeVar string - partTypeVar string - forceVar bool - verboseVar bool - drives map[string]bool - driveKeys []string + labelVar string + fsTypeVar string + partTypeVar string + forceVar bool + verboseVar bool + drives map[string]bool + partitionLayoutVar string + driveKeys []string ) func hasPartitions(d string) bool { @@ -73,7 +74,7 @@ func isEmptyDevice(d string) (bool, error) { return isEmpty, nil } -func autoformat(label, fsType string, partType string) error { +func autoformat(label, fsType string, partType string, partitionLayoutVar string) error { var first string for _, d := range driveKeys { if verboseVar { @@ -94,7 +95,7 @@ func autoformat(label, fsType string, partType string) error { return fmt.Errorf("No eligible disks found") } - return format(first, label, fsType, partType, false) + return format(first, label, fsType, partType, partitionLayoutVar, false) } func refreshDevicesAndWaitFor(awaitedDevice string) error { @@ -129,7 +130,7 @@ func refreshDevicesAndWaitFor(awaitedDevice string) error { return nil } -func format(d, label, fsType string, partType string, forced bool) error { +func format(d, label, fsType string, partType string, partitionLayoutVar string, forced bool) error { if forced { // clear partitions on device if forced format and they exist if hasPartitions(d) { @@ -137,7 +138,7 @@ func format(d, label, fsType string, partType string, forced bool) error { log.Printf("Clearing partitions on %s because forced format was requested", d) } partCmd := exec.Command("sfdisk", "--quiet", "--delete", d) - partCmd.Stdin = strings.NewReader(";") + partCmd.Stdin = strings.NewReader(partitionLayoutVar) if out, err := partCmd.CombinedOutput(); err != nil { return fmt.Errorf("Error deleting partitions with sfdisk: %v\n%s", err, out) } @@ -169,7 +170,7 @@ func format(d, label, fsType string, partType string, forced bool) error { // format one large partition partCmd := exec.Command("sfdisk", "--quiet", d) - partCmd.Stdin = strings.NewReader(";") + partCmd.Stdin = strings.NewReader(partitionLayoutVar) if out, err := partCmd.CombinedOutput(); err != nil { return fmt.Errorf("Error running sfdisk: %v\n%s", err, out) } @@ -267,6 +268,7 @@ func init() { flag.StringVar(&labelVar, "label", "", "Disk label to apply") flag.StringVar(&fsTypeVar, "type", "ext4", "Type of filesystem to create") flag.StringVar(&partTypeVar, "partition", "dos", "Type of partition table to create") + flag.StringVar(&partitionLayoutVar, "layout", ";", "Partition layout for sfdisk invocation") flag.BoolVar(&verboseVar, "verbose", false, "Enable verbose output (default false)") } @@ -292,7 +294,7 @@ func main() { if flag.NArg() == 0 { // auto-detect drives if a device to format is not explicitly specified findDrives() - if err := autoformat(labelVar, fsTypeVar, partTypeVar); err != nil { + if err := autoformat(labelVar, fsTypeVar, partTypeVar, partitionLayoutVar); err != nil { log.Fatalf("%v", err) } } else { @@ -303,13 +305,13 @@ func main() { } if forceVar == true { - if err := format(candidateDevice, labelVar, fsTypeVar, partTypeVar, forceVar); err != nil { + if err := format(candidateDevice, labelVar, fsTypeVar, partTypeVar, partitionLayoutVar, forceVar); err != nil { log.Fatalf("%v", err) } } else { // add the deviceVar to the array of devices to consider autoformatting driveKeys = []string{candidateDevice} - if err := autoformat(labelVar, fsTypeVar, partTypeVar); err != nil { + if err := autoformat(labelVar, fsTypeVar, partTypeVar, partitionLayoutVar); err != nil { log.Fatalf("%v", err) } } diff --git a/projects/compose/compose-dynamic.yml b/projects/compose/compose-dynamic.yml index a593d80bb..b6963302c 100644 --- a/projects/compose/compose-dynamic.yml +++ b/projects/compose/compose-dynamic.yml @@ -15,7 +15,7 @@ onboot: image: linuxkit/dhcpcd:f46134c05f9665d8865a9fbebd5be0995057af28 command: ["/sbin/dhcpcd", "--nobackground", "-f", "/dhcpcd.conf", "-1"] - name: format - image: linuxkit/format:8f487d728959192289e0783784fc2b185eadbc82 + image: linuxkit/format:ced02d849206371b6983eff1eb28f9515406fef0 - name: mount image: linuxkit/mount:2a507ef30302693682f9f612289028df00c58ac5 command: ["/usr/bin/mountie", "/var/lib/docker"] diff --git a/projects/compose/compose-static.yml b/projects/compose/compose-static.yml index 40bf3aeaa..65d54f897 100644 --- a/projects/compose/compose-static.yml +++ b/projects/compose/compose-static.yml @@ -15,7 +15,7 @@ onboot: image: linuxkit/dhcpcd:f46134c05f9665d8865a9fbebd5be0995057af28 command: ["/sbin/dhcpcd", "--nobackground", "-f", "/dhcpcd.conf", "-1"] - name: format - image: linuxkit/format:8f487d728959192289e0783784fc2b185eadbc82 + image: linuxkit/format:ced02d849206371b6983eff1eb28f9515406fef0 - name: mount image: linuxkit/mount:2a507ef30302693682f9f612289028df00c58ac5 command: ["/usr/bin/mountie", "/var/lib/docker"] diff --git a/test/cases/030_security/000_docker-bench/test.yml b/test/cases/030_security/000_docker-bench/test.yml index 6509cd488..47a00d119 100644 --- a/test/cases/030_security/000_docker-bench/test.yml +++ b/test/cases/030_security/000_docker-bench/test.yml @@ -12,7 +12,7 @@ onboot: - name: sysfs image: linuxkit/sysfs:23a13bbf83bf666ef6a3ba7b3ebba35d2daead98 - name: format - image: linuxkit/format:8f487d728959192289e0783784fc2b185eadbc82 + image: linuxkit/format:ced02d849206371b6983eff1eb28f9515406fef0 - name: mount image: linuxkit/mount:2a507ef30302693682f9f612289028df00c58ac5 command: ["/usr/bin/mountie", "/var/lib/docker"] diff --git a/test/cases/040_packages/003_containerd/test.yml b/test/cases/040_packages/003_containerd/test.yml index 9fc25e3de..7566d2f9a 100644 --- a/test/cases/040_packages/003_containerd/test.yml +++ b/test/cases/040_packages/003_containerd/test.yml @@ -13,7 +13,7 @@ onboot: - name: sysctl image: linuxkit/sysctl:112fe3d480ccb6cd115d9d6c446f9d833f6b8e68 - name: format - image: linuxkit/format:8f487d728959192289e0783784fc2b185eadbc82 + image: linuxkit/format:ced02d849206371b6983eff1eb28f9515406fef0 - name: mount image: linuxkit/mount:2a507ef30302693682f9f612289028df00c58ac5 command: ["/usr/bin/mountie", "/var/lib"] diff --git a/test/cases/040_packages/005_extend/000_ext4/test-create.yml b/test/cases/040_packages/005_extend/000_ext4/test-create.yml index 0039323d1..e86f663ae 100644 --- a/test/cases/040_packages/005_extend/000_ext4/test-create.yml +++ b/test/cases/040_packages/005_extend/000_ext4/test-create.yml @@ -6,7 +6,7 @@ init: - linuxkit/runc:8b5af3365fc7d015db4e44113d93c7b1f8e2d2ab onboot: - name: format - image: linuxkit/format:8f487d728959192289e0783784fc2b185eadbc82 + image: linuxkit/format:ced02d849206371b6983eff1eb28f9515406fef0 - name: mount image: linuxkit/mount:2a507ef30302693682f9f612289028df00c58ac5 command: ["/usr/bin/mountie", "/var/lib/docker"] diff --git a/test/cases/040_packages/005_extend/001_btrfs/test-create.yml b/test/cases/040_packages/005_extend/001_btrfs/test-create.yml index 4a0c75746..148f2ccd6 100644 --- a/test/cases/040_packages/005_extend/001_btrfs/test-create.yml +++ b/test/cases/040_packages/005_extend/001_btrfs/test-create.yml @@ -9,7 +9,7 @@ onboot: image: linuxkit/modprobe:fad39ef443853ef02520052cdbf6acbeb4ec7799 command: ["modprobe", "btrfs"] - name: format - image: linuxkit/format:8f487d728959192289e0783784fc2b185eadbc82 + image: linuxkit/format:ced02d849206371b6983eff1eb28f9515406fef0 command: ["/usr/bin/format", "-type", "btrfs" ] - name: mount image: linuxkit/mount:2a507ef30302693682f9f612289028df00c58ac5 diff --git a/test/cases/040_packages/005_extend/002_xfs/test-create.yml b/test/cases/040_packages/005_extend/002_xfs/test-create.yml index 211709a11..1f3f9694d 100644 --- a/test/cases/040_packages/005_extend/002_xfs/test-create.yml +++ b/test/cases/040_packages/005_extend/002_xfs/test-create.yml @@ -6,7 +6,7 @@ init: - linuxkit/runc:8b5af3365fc7d015db4e44113d93c7b1f8e2d2ab onboot: - name: format - image: linuxkit/format:8f487d728959192289e0783784fc2b185eadbc82 + image: linuxkit/format:ced02d849206371b6983eff1eb28f9515406fef0 command: ["/usr/bin/format", "-type", "xfs"] - name: mount image: linuxkit/mount:2a507ef30302693682f9f612289028df00c58ac5 diff --git a/test/cases/040_packages/005_extend/003_gpt/test-create.yml b/test/cases/040_packages/005_extend/003_gpt/test-create.yml index c186225fc..47171bb9d 100644 --- a/test/cases/040_packages/005_extend/003_gpt/test-create.yml +++ b/test/cases/040_packages/005_extend/003_gpt/test-create.yml @@ -6,7 +6,7 @@ init: - linuxkit/runc:8b5af3365fc7d015db4e44113d93c7b1f8e2d2ab onboot: - name: format - image: linuxkit/format:8f487d728959192289e0783784fc2b185eadbc82 + image: linuxkit/format:ced02d849206371b6983eff1eb28f9515406fef0 command: ["/usr/bin/format", "-partition", "gpt"] - name: mount image: linuxkit/mount:2a507ef30302693682f9f612289028df00c58ac5 diff --git a/test/cases/040_packages/006_format_mount/000_auto/test.yml b/test/cases/040_packages/006_format_mount/000_auto/test.yml index a1cbb8daa..3ca2672b8 100644 --- a/test/cases/040_packages/006_format_mount/000_auto/test.yml +++ b/test/cases/040_packages/006_format_mount/000_auto/test.yml @@ -6,7 +6,7 @@ init: - linuxkit/runc:8b5af3365fc7d015db4e44113d93c7b1f8e2d2ab onboot: - name: format - image: linuxkit/format:8f487d728959192289e0783784fc2b185eadbc82 + image: linuxkit/format:ced02d849206371b6983eff1eb28f9515406fef0 command: ["/usr/bin/format"] - name: mount image: linuxkit/mount:2a507ef30302693682f9f612289028df00c58ac5 diff --git a/test/cases/040_packages/006_format_mount/001_by_label/test.yml b/test/cases/040_packages/006_format_mount/001_by_label/test.yml index cb1053669..9bfd20298 100644 --- a/test/cases/040_packages/006_format_mount/001_by_label/test.yml +++ b/test/cases/040_packages/006_format_mount/001_by_label/test.yml @@ -6,7 +6,7 @@ init: - linuxkit/runc:8b5af3365fc7d015db4e44113d93c7b1f8e2d2ab onboot: - name: format - image: linuxkit/format:8f487d728959192289e0783784fc2b185eadbc82 + image: linuxkit/format:ced02d849206371b6983eff1eb28f9515406fef0 command: ["/usr/bin/format", "-label", "docker"] - name: mount image: linuxkit/mount:2a507ef30302693682f9f612289028df00c58ac5 diff --git a/test/cases/040_packages/006_format_mount/002_by_name/test.yml.in b/test/cases/040_packages/006_format_mount/002_by_name/test.yml.in index 71053597d..08534b6dd 100644 --- a/test/cases/040_packages/006_format_mount/002_by_name/test.yml.in +++ b/test/cases/040_packages/006_format_mount/002_by_name/test.yml.in @@ -6,7 +6,7 @@ init: - linuxkit/runc:8b5af3365fc7d015db4e44113d93c7b1f8e2d2ab onboot: - name: format - image: linuxkit/format:8f487d728959192289e0783784fc2b185eadbc82 + image: linuxkit/format:ced02d849206371b6983eff1eb28f9515406fef0 command: ["/usr/bin/format", "@DEVICE@"] - name: mount image: linuxkit/mount:2a507ef30302693682f9f612289028df00c58ac5 diff --git a/test/cases/040_packages/006_format_mount/003_btrfs/test.yml b/test/cases/040_packages/006_format_mount/003_btrfs/test.yml index ebe836c4e..aa835afbd 100644 --- a/test/cases/040_packages/006_format_mount/003_btrfs/test.yml +++ b/test/cases/040_packages/006_format_mount/003_btrfs/test.yml @@ -9,7 +9,7 @@ onboot: image: linuxkit/modprobe:fad39ef443853ef02520052cdbf6acbeb4ec7799 command: ["modprobe", "btrfs"] - name: format - image: linuxkit/format:8f487d728959192289e0783784fc2b185eadbc82 + image: linuxkit/format:ced02d849206371b6983eff1eb28f9515406fef0 command: ["/usr/bin/format", "-type", "btrfs" ] - name: mount image: linuxkit/mount:2a507ef30302693682f9f612289028df00c58ac5 diff --git a/test/cases/040_packages/006_format_mount/004_xfs/test.yml b/test/cases/040_packages/006_format_mount/004_xfs/test.yml index 557efe2cf..fb214e667 100644 --- a/test/cases/040_packages/006_format_mount/004_xfs/test.yml +++ b/test/cases/040_packages/006_format_mount/004_xfs/test.yml @@ -6,7 +6,7 @@ init: - linuxkit/runc:8b5af3365fc7d015db4e44113d93c7b1f8e2d2ab onboot: - name: format - image: linuxkit/format:8f487d728959192289e0783784fc2b185eadbc82 + image: linuxkit/format:ced02d849206371b6983eff1eb28f9515406fef0 command: ["/usr/bin/format", "-type", "xfs" ] - name: mount image: linuxkit/mount:2a507ef30302693682f9f612289028df00c58ac5 diff --git a/test/cases/040_packages/006_format_mount/005_by_device_force/test.yml b/test/cases/040_packages/006_format_mount/005_by_device_force/test.yml index de1dbd421..f46c6b42c 100644 --- a/test/cases/040_packages/006_format_mount/005_by_device_force/test.yml +++ b/test/cases/040_packages/006_format_mount/005_by_device_force/test.yml @@ -6,19 +6,19 @@ init: - linuxkit/runc:8b5af3365fc7d015db4e44113d93c7b1f8e2d2ab onboot: - name: format - image: linuxkit/format:8f487d728959192289e0783784fc2b185eadbc82 + image: linuxkit/format:ced02d849206371b6983eff1eb28f9515406fef0 command: ["/usr/bin/format", "-verbose", "-type", "ext4", "/dev/sda"] - name: format - image: linuxkit/format:8f487d728959192289e0783784fc2b185eadbc82 + image: linuxkit/format:ced02d849206371b6983eff1eb28f9515406fef0 command: ["/usr/bin/format", "-verbose", "-type", "ext4", "/dev/sdb"] - name: format - image: linuxkit/format:8f487d728959192289e0783784fc2b185eadbc82 + image: linuxkit/format:ced02d849206371b6983eff1eb28f9515406fef0 command: ["/usr/bin/format", "-verbose", "-type", "xfs", "/dev/sda"] - name: format - image: linuxkit/format:8f487d728959192289e0783784fc2b185eadbc82 + image: linuxkit/format:ced02d849206371b6983eff1eb28f9515406fef0 command: ["/usr/bin/format", "-verbose", "-force", "-type", "xfs", "/dev/sdb"] - name: test - image: linuxkit/format:8f487d728959192289e0783784fc2b185eadbc82 + image: linuxkit/format:ced02d849206371b6983eff1eb28f9515406fef0 binds: - /check.sh:/check.sh command: ["sh", "./check.sh"] diff --git a/test/cases/040_packages/006_format_mount/006_gpt/test.yml b/test/cases/040_packages/006_format_mount/006_gpt/test.yml index c75379f0b..671d668ac 100644 --- a/test/cases/040_packages/006_format_mount/006_gpt/test.yml +++ b/test/cases/040_packages/006_format_mount/006_gpt/test.yml @@ -6,7 +6,7 @@ init: - linuxkit/runc:8b5af3365fc7d015db4e44113d93c7b1f8e2d2ab onboot: - name: format - image: linuxkit/format:8f487d728959192289e0783784fc2b185eadbc82 + image: linuxkit/format:ced02d849206371b6983eff1eb28f9515406fef0 command: ["/usr/bin/format", "-partition", "gpt"] - name: mount image: linuxkit/mount:2a507ef30302693682f9f612289028df00c58ac5 diff --git a/test/cases/040_packages/006_format_mount/010_multiple/test.yml b/test/cases/040_packages/006_format_mount/010_multiple/test.yml index 0980c1f56..b7b77e08f 100644 --- a/test/cases/040_packages/006_format_mount/010_multiple/test.yml +++ b/test/cases/040_packages/006_format_mount/010_multiple/test.yml @@ -6,10 +6,10 @@ init: - linuxkit/runc:8b5af3365fc7d015db4e44113d93c7b1f8e2d2ab onboot: - name: format - image: linuxkit/format:8f487d728959192289e0783784fc2b185eadbc82 + image: linuxkit/format:ced02d849206371b6983eff1eb28f9515406fef0 command: ["/usr/bin/format", "-label", "docker"] - name: format - image: linuxkit/format:8f487d728959192289e0783784fc2b185eadbc82 + image: linuxkit/format:ced02d849206371b6983eff1eb28f9515406fef0 command: ["/usr/bin/format", "-label", "foo"] - name: mount image: linuxkit/mount:2a507ef30302693682f9f612289028df00c58ac5