{"id":13875839,"url":"https://github.com/johnramsden/zedenv-grub","last_synced_at":"2025-04-09T21:31:52.404Z","repository":{"id":102820999,"uuid":"135951723","full_name":"johnramsden/zedenv-grub","owner":"johnramsden","description":"zedenv plugin for GRUB","archived":false,"fork":false,"pushed_at":"2020-02-16T22:40:20.000Z","size":361,"stargazers_count":11,"open_issues_count":0,"forks_count":4,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-02T06:37:23.962Z","etag":null,"topics":["linux","python","python3","zfs","zfsonlinux"],"latest_commit_sha":null,"homepage":"https://zedenv.readthedocs.io/en/latest/plugins.html#grub","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/johnramsden.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2018-06-04T00:31:50.000Z","updated_at":"2023-05-11T02:57:59.000Z","dependencies_parsed_at":"2024-01-13T19:38:54.527Z","dependency_job_id":"1147f6cf-5992-4e38-a49e-a533bd428b47","html_url":"https://github.com/johnramsden/zedenv-grub","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johnramsden%2Fzedenv-grub","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johnramsden%2Fzedenv-grub/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johnramsden%2Fzedenv-grub/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johnramsden%2Fzedenv-grub/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/johnramsden","download_url":"https://codeload.github.com/johnramsden/zedenv-grub/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248114745,"owners_count":21050102,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["linux","python","python3","zfs","zfsonlinux"],"created_at":"2024-08-06T06:00:45.376Z","updated_at":"2025-04-09T21:31:52.040Z","avatar_url":"https://github.com/johnramsden.png","language":"Python","funding_links":[],"categories":["Python","python3"],"sub_categories":[],"readme":"==================\nzedenv GRUB Plugin\n==================\n\nzedenv - ZFS boot environment manager - GRUB plugin\n\nInstall\n-------\n\nInstall ``zedenv`` then ``zedenv-grub``.\n\nSetup\n-----\n\nOne of two types of setup needs to be used with grub.\n\n* Boot on ZFS - separate ``grub`` dataset needed.\n* Separate partition for kernels\n\nBoot on ZFS (Recommended)\n#########################\n\nTo use boot on ZFS:\n\n* A ``grub`` dataset is needed. It should be mounted at ``/boot/grub``.\n* ``org.zedenv.grub:bootonzfs`` should be set to ``yes``\n* Individual boot environments should contain their kernels in ``/boot``, which should be part of the root dataset.\n\nTo convert an existing grub install, set up the ``grub`` dataset, and mount it. Then install grub again. \n\n.. code-block:: shell\n\n    zfs create -o canmount=off zroot/boot\n    zfs create -o mountpoint=legacy zroot/boot/grub\n    mount -t zfs zroot/boot/grub /boot/grub\n\n    # efi\n    mount ${esp} /boot/efi\n    grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=GRUB\n\n    # or for BIOS\n    grub-install --target=i386-pc /dev/sdx --recheck\n\nIf you get:\n\n.. code-block:: shell\n\n    /dev/sda\n    Installing for i386-pc platform.\n    grub-install: error: failed to get canonical path of `/dev/ata-SAMSUNG_SSD_830_Series_S0VVNEAC702110-part2'.\n\nA workaround is to symlink the expected partition to the id\n\n.. code-block:: shell\n    \n    ln -s /dev/sda2 /dev/ata-SAMSUNG_SSD_830_Series_S0VVNEAC702110-part2\n\nSeparate Partition for Kernels\n###############################\n\nAn example system on Arch Linux with a separate partition for kernels would be the following:\n\n* Boot partition mounted to ``/mnt/boot``. \n* The directory containing kernels for the active boot environment, ``/mnt/boot/env/zedenv-${boot_env}`` bind mounted to ``/boot``. \n* The grub directory ``/mnt/boot/grub`` bindmounted to ``/boot/grub``\n* ``org.zedenv.grub:bootonzfs`` should be set to ``no`` with ``zedenv set org.zedenv.grub:bootonzfs=no``\n\nWhat this would look like during an arch Linux install would be the following: \n\n.. code-block:: shell\n\n    zpool import -d /dev/disk/by-id -R /mnt vault\n\n    mkdir -p /mnt/mnt/boot /mnt/boot\n    mount /dev/sda1 /mnt/mnt/boot\n\n    mkdir /mnt/mnt/boot/env/zedenv-default /mnt/boot/grub\n    mount --bind /mnt/mnt/boot/env/zedenv-default /mnt/boot\n    mount --bind /mnt/mnt/boot/grub /mnt/boot/grub\n\n    genfstab -U -p /mnt \u003e\u003e /mnt/etc/fstab\n\n    arch-chroot /mnt /bin/bash\n\nIn chroot\n\n.. code-block:: shell\n\n    export ZPOOL_VDEV_NAME_PATH=1\n\n    grub-install --target=x86_64-efi --efi-directory=/mnt/boot --bootloader-id=GRUB\n    grub-mkconfig -o /boot/grub/grub.cfg\n\nAn example generated grub.cfg looks like:\n\n.. code-block:: shell\n\n    ### BEGIN /etc/grub.d/10_linux ###\n    menuentry 'Arch Linux' --class arch --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-simple-a1b916c0819a1863' {\n            load_video\n            set gfxpayload=keep\n            insmod gzio\n            insmod part_gpt\n            insmod fat\n            set root='hd0,gpt1'\n            if [ x$feature_platform_search_hint = xy ]; then\n              search --no-floppy --fs-uuid --set=root --hint-bios=hd0,gpt1 --hint-efi=hd0,gpt1 --hint-baremetal=ahci0,gpt1  B11F-0328\n            else\n              search --no-floppy --fs-uuid --set=root B11F-0328\n            fi\n            echo    'Loading Linux linux ...'\n            linux   /env/zedenv-default/vmlinuz-linux root=ZFS=vault/sys/zedenv/ROOT/default rw  quiet\n            echo    'Loading initial ramdisk ...'\n            initrd  /env/zedenv-default/initramfs-linux.img\n    }\n\nConverting Existing System\n~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nCreate a backup. \n\n.. code-block:: shell\n\n    cp -a /boot /boot.bak\n\nUnmount ``/boot``, and remount it at ``/mnt/boot``.\n\n.. code-block:: shell\n\n    mkdir -p /mnt/boot\n    mount /dev/sdxY /mnt/boot\n\nThen you want to move your current kernel to ``/mnt/boot/env/zedenv-${boot_env_name}``\n\n.. code-block:: shell\n\n    mkdir /mnt/boot/env/zedenv-default\n    mv /mnt/boot/* /mnt/boot/env/zedenv-default \n\nMove the grab directory back if it was also moved (or don't move it in the first place).\n\n.. code-block:: shell\n\n    mv /mnt/boot/env/zedenv-default/grub /mnt/boot/grub\n\nNow bindmount the current kernel directory to ``/boot`` so that everything is where the system expects it.\n\n.. code-block:: shell\n\n    mount --bind /mnt/boot/env/zedenv-default /boot\n\nSame thing with the grub directory \n\n.. code-block:: shell\n\n    mount --bind /mnt/boot/grub /boot/grub \n\nNow everything is back to appearing how it looked originally, but things are actually stored in a different place. \n\n--- \n\nYou're also probably going to want to update your fstab, if you're using Arch you can use genfstab, which requires ``arch-install-scripts``. \n\n.. code-block:: shell\n\n    genfstab -U -p / \n\nYou'll need to add the output to ``/etc/fstab.`` \n\nThis is what an example looks like.\n\n.. code-block:: shell\n\n    # /dev/sda1\n    UUID=B11F-0328          /mnt/boot       vfat            rw,relatime,fmask=0022,dmask=0022,codepage=437,iocharset=iso8859-1,shortname=mixed,utf8,errors=remount-ro       0 2\n\n    /mnt/boot/env/zedenv-grub-test-3        /boot           none            rw,fmask=0022,dmask=0022,codepage=437,iocharset=iso8859-1,shortname=mixed,utf8,errors=remount-ro,bind   0 0\n    /mnt/boot/grub          /boot/grub      none            rw,fmask=0022,dmask=0022,codepage=437,iocharset=iso8859-1,shortname=mixed,utf8,errors=remount-ro,bind   0 0 \n\n\nPost Setup\n-------------\n\nAfter install, run ``zedenv --plugins``, you should see ``grub``.\n\nSet bootloader config, options can be queried with ``zedenv get --defaults``: \n\n.. code-block:: shell \n\n    $ zedenv get --defaults\n    PROPERTY                    DEFAULT    DESCRIPTION              \n    org.zedenv:bootloader                  Set a bootloader plugin. \n    org.zedenv.systemdboot:esp  /mnt/efi   Set location for esp.    \n    org.zedenv.grub:boot        /mnt/boot  Set location for boot.   \n    org.zedenv.grub:bootonzfs   yes\n\nSet the bootloader so it doesn't have to be declared on every usage with the ``-b`` flag.\n\n.. code-block:: shell \n\n    # zedenv set org.zedenv:bootloader=grub\n    \n``zedenv`` will do its best to decide whether or not you are booting off of an all ZFS system, but it can also be set explicitly with ``org.zedenv.grub:bootonzfs=yes``.\n\nAny values you have set explicitly will show up with ``zedenv get``.\n\nNow create a new boot environment:\n\n.. code-block:: shell \n\n    # zedenv create linux-4.18.12\n    # zfs list\n    NAME                       USED  AVAIL  REFER  MOUNTPOINT\n    zroot                     2.43G  36.1G    29K  none\n    zroot/ROOT                2.42G  36.1G    29K  none\n    zroot/ROOT/default        2.42G  36.1G  2.42G  /\n    zroot/ROOT/linux-4.18.12     1K  36.1G  2.42G  /\n    zroot/data                9.36M  36.1G    29K  none\n    zroot/data/home           9.33M  36.1G  9.33M  legacy\n\nYou may want to disable all of the grub generators in ``/etc/grub.d/`` except for ``00_header`` and the zedenv generator ``05_zfs_linux.py`` by removing the executable bit.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjohnramsden%2Fzedenv-grub","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjohnramsden%2Fzedenv-grub","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjohnramsden%2Fzedenv-grub/lists"}