{"id":1653,"date":"2020-05-20T18:54:21","date_gmt":"2020-05-20T23:54:21","guid":{"rendered":"https:\/\/blog.iqonda.net\/?p=1653"},"modified":"2020-05-20T18:54:21","modified_gmt":"2020-05-20T23:54:21","slug":"systemctl-with-docker-and-zfs","status":"publish","type":"post","link":"https:\/\/blog.ls-al.com\/systemctl-with-docker-and-zfs\/","title":{"rendered":"Systemctl With Docker and ZFS"},"content":{"rendered":"

I previously wrote about Ubuntu 20.04 as a rpool(boot volume) on OCI (Oracle Cloud Infrastucture). If using a ZFS rpool you probably wont have this silly race condition I am writing about here.<\/p>\n

So for this POC I was using Docker and an isci mounted disk for the Docker root folder. Unfortunately there are a couple issues. The first one not related to Docker just booting up and the zpool not being imported. Fix A is for that. The second issue is that Docker may not wait for the zpool to be ready before it starts and just automatically lay down its docker<\/em> folder you specified in daemon.json. And of course then zfs will not mount even if it was imported with fix A.<\/p>\n

Fix A<\/h2>\n
\n

If you don't know yet please create your zpool with the by-id<\/strong> device name not for example \/dev\/sdb. If this zpool was already created you can fix this after the fact with export and import and updating the cache. <\/p>\n<\/blockquote>\n

You can look at systemctl status zfs-import-cache.service<\/em> to see what happened at boot with this zpool. There are many opinions on how to fix this; suffice to say this is what I used and it works reliably for me so far.<\/p>\n

Create service<\/h2>\n
# cat \/etc\/systemd\/system\/tank01-pool.service\n[Unit]\nDescription=Zpool start service\nAfter=dev-disk-by\\x2did-wwn\\x2d0x6081a22b818449d287b13b59a47bc407.device\n\n[Service]\nType=simple\nExecStart=\/usr\/sbin\/zpool import tank01\nExecStartPost=\/usr\/bin\/logger \"started ZFS pool tank01\"\n\n[Install]\nWantedBy=dev-disk-by\\x2did-wwn\\x2d0x6081a22b818449d287b13b59a47bc407.device\n\n# systemctl daemon-reload\n# systemctl enable tank01-pool.service\n\n# systemctl status tank01-pool.service\n\u25cf tank01-pool.service - Zpool start service\n     Loaded: loaded (\/etc\/systemd\/system\/tank01-pool.service; enabled; vendor preset: enabled)\n     Active: inactive (dead) since Tue 2020-05-19 02:18:05 UTC; 5min ago\n   Main PID: 1018 (code=exited, status=0\/SUCCESS)\n\nMay 19 02:18:01 usph-vmli-do01 systemd[1]: Starting Zpool start service...\nMay 19 02:18:01 usph-vmli-do01 root[1019]: started ZFS pool tank01\nMay 19 02:18:01 usph-vmli-do01 systemd[1]: Started Zpool start service.\nMay 19 02:18:05 usph-vmli-do01 systemd[1]: tank01-pool.service: Succeeded.<\/code><\/pre>\n

To find your exact device<\/h2>\n
# systemctl list-units --all --full | grep disk | grep tank01\n      dev-disk-by\\x2did-scsi\\x2d36081a22b818449d287b13b59a47bc407\\x2dpart1.device                                                                                       loaded    active   plugged   BlockVolume tank01                                                           \n      dev-disk-by\\x2did-wwn\\x2d0x6081a22b818449d287b13b59a47bc407\\x2dpart1.device                                                                                       loaded    active   plugged   BlockVolume tank01                                                           \n      dev-disk-by\\x2dlabel-tank01.device                                                                                                                                loaded    active   plugged   BlockVolume tank01                                                           \n      dev-disk-by\\x2dpartlabel-zfs\\x2d9eb05ecca4da97f6.device                                                                                                           loaded    active   plugged   BlockVolume tank01                                                           \n      dev-disk-by\\x2dpartuuid-d7d69ee0\\x2d4e45\\x2d3148\\x2daa7a\\x2d7cf375782813.device                                                                                   loaded    active   plugged   BlockVolume tank01                                                           \n      dev-disk-by\\x2dpath-ip\\x2d169.254.2.2:3260\\x2discsi\\x2diqn.2015\\x2d12.com.oracleiaas:16bca793\\x2dc861\\x2d49e8\\x2da903\\x2dd6b3809fe694\\x2dlun\\x2d1\\x2dpart1.device loaded    active   plugged   BlockVolume tank01                                                           \n      dev-disk-by\\x2duuid-9554707573611221628.device                                                                                                                    loaded    active   plugged   BlockVolume tank01                                                           \n\n# ls -l \/dev\/disk\/by-id\/ | grep sdb\n    lrwxrwxrwx 1 root root  9 May 18 22:32 scsi-36081a22b818449d287b13b59a47bc407 -> ..\/..\/sdb\n    lrwxrwxrwx 1 root root 10 May 18 22:32 scsi-36081a22b818449d287b13b59a47bc407-part1 -> ..\/..\/sdb1\n    lrwxrwxrwx 1 root root 10 May 18 22:33 scsi-36081a22b818449d287b13b59a47bc407-part9 -> ..\/..\/sdb9\n    lrwxrwxrwx 1 root root  9 May 18 22:32 wwn-0x6081a22b818449d287b13b59a47bc407 -> ..\/..\/sdb\n    lrwxrwxrwx 1 root root 10 May 18 22:32 wwn-0x6081a22b818449d287b13b59a47bc407-part1 -> ..\/..\/sdb1\n    lrwxrwxrwx 1 root root 10 May 18 22:33 wwn-0x6081a22b818449d287b13b59a47bc407-part9 -> ..\/..\/sdb9<\/code><\/pre>\n

Fix B<\/h2>\n

This was done before and just showing for reference how you enable the docker zfs storage.<\/p>\n

# cat \/etc\/docker\/daemon.json\n{ \n  \"storage-driver\": \"zfs\",\n  \"data-root\": \"\/tank01\/docker\"\n}<\/code><\/pre>\n

For the timing issue you have many options in systemctl and probably better than this. For me just delaying a little until isci and zpool import\/mount is done works OK.<\/p>\n

# grep sleep \/etc\/systemd\/system\/multi-user.target.wants\/docker.service \nExecStartPre=\/bin\/sleep 60\n\n# systemctl daemon-reload<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"

I previously wrote about Ubuntu 20.04 as a rpool(boot volume) on OCI (Oracle Cloud Infrastucture). If using a ZFS rpool<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[69,30],"tags":[],"class_list":["post-1653","post","type-post","status-publish","format-standard","hentry","category-docker","category-zfs"],"_links":{"self":[{"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/posts\/1653","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/comments?post=1653"}],"version-history":[{"count":0,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/posts\/1653\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/media?parent=1653"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/categories?post=1653"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/tags?post=1653"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}