Skip to content

Commit 65d1076

Browse files
author
Tycho Andersen
committed
lxd container type: use ZFS by default
Signed-off-by: Tycho Andersen <[email protected]>
1 parent c94ace2 commit 65d1076

File tree

1 file changed

+38
-1
lines changed

1 file changed

+38
-1
lines changed

container/lxd/initialisation.go

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ var requiredPackages = []string{
2828
"lxd",
2929
}
3030

31+
var xenialPackages = []string{
32+
"zfsutils-linux",
33+
}
34+
3135
type containerInitialiser struct {
3236
series string
3337
}
@@ -48,7 +52,16 @@ func (ci *containerInitialiser) Initialise() error {
4852
return err
4953
}
5054

51-
return configureLXDBridge()
55+
err = configureLXDBridge()
56+
if err != nil {
57+
return err
58+
}
59+
60+
if ci.series >= "xenial" {
61+
configureZFS()
62+
}
63+
64+
return nil
5265
}
5366

5467
// getPackageManager is a helper function which returns the
@@ -63,6 +76,24 @@ func getPackagingConfigurer(series string) (config.PackagingConfigurer, error) {
6376
return config.NewPackagingConfigurer(series)
6477
}
6578

79+
func configureZFS() {
80+
/* create a 100 GB pool by default (sparse, so it won't actually fill
81+
* that immediately)
82+
*/
83+
output, err := exec.Command(
84+
"lxd",
85+
"init",
86+
"--auto",
87+
"--storage-backend", "zfs",
88+
"--storage-pool", "lxd",
89+
"--storage-create-loop", "100",
90+
).CombinedOutput()
91+
92+
if err != nil {
93+
logger.Warningf("configuring zfs failed with %s: %s", err, string(output))
94+
}
95+
}
96+
6697
func configureLXDBridge() error {
6798
f, err := os.OpenFile(lxdBridgeFile, os.O_RDWR, 0777)
6899
if err != nil {
@@ -219,5 +250,11 @@ func ensureDependencies(series string) error {
219250
}
220251
}
221252

253+
if series >= "xenial" {
254+
for _, pack := range xenialPackages {
255+
pacman.Install(fmt.Sprintf("--no-install-recommends %s", pack))
256+
}
257+
}
258+
222259
return err
223260
}

0 commit comments

Comments
 (0)