Immutable root with atomic upgrades: Difference between revisions

From Alpine Linux
(Immutable root with atomic upgrades)
 
No edit summary
Line 9: Line 9:
Read-only root and atomic upgrades with ability to easily rollback or boot previous configurations is a concept that got some popularity recently. Distributions providing and promoting such features, for example, are [https://silverblue.fedoraproject.org/ Fedora Silverblue], [https://microos.opensuse.org/ Opensuse MicroOS], [https://nixos.org NixOS] and [https://guix.gnu.org GNU Guix].
Read-only root and atomic upgrades with ability to easily rollback or boot previous configurations is a concept that got some popularity recently. Distributions providing and promoting such features, for example, are [https://silverblue.fedoraproject.org/ Fedora Silverblue], [https://microos.opensuse.org/ Opensuse MicroOS], [https://nixos.org NixOS] and [https://guix.gnu.org GNU Guix].
While Alpine Linux has it's killer features it lacks mentioned above ones on default setup. This is a proof of concept that it's possible to implement them in a minimal way on a minimal system.
While Alpine Linux has it's killer features it lacks mentioned above ones on default setup. This is a proof of concept that it's possible to implement them in a minimal way on a minimal system.
= Partitioning disks =
The first step is creating partition table on target device <code>/dev/sda</code>:
<pre># apk add gptfdisk
# gdisk /dev/sda
> o ↵
> y ↵
> w ↵
> y ↵
</pre>
Now we can define the partitions:
<pre># cgdisk /dev/sda</pre>
Partition creation process consists of several steps:
# Start sector - you can safely use default value by pressing ↵
# Size
# Type (as hex code) - EFI is ef00, Linux filesystem is 8300, Swap is 8200.
Result table:
<pre>Part.    #    Size        Partition Type            Partition Name
----------------------------------------------------------------
1              200.0 MiB  EFI System                EFI
2              200.0 GiB  Linux filesystem          ROOT
3              32.0 GiB    Linux swap                SWAP</pre>
<code>ROOT</code> partition name will later be used in rEFInd configuration to identify boot volume.
Next step is creating filesystems:
<pre># mkfs.vfat -F32 /dev/sda1
# mkfs.btrfs /dev/sda2
# mkswap /dev/sda3</pre>
Now we can mount our root volume:
<pre># mount /dev/sda2 /mnt</pre>
= File system structure =
= File system structure =
<pre>|--mnt
| |--commons
| |--current
| |--fstab
| |--links
| | |--20210411213742qwrXAJBz
| | | |--gen_0
| | | |--gen_1
| | | |--gen_2
| | | |--gen_3
| |--next
| |--snapshots
| | |--20210411212549sdBXyLxg
| | | |--@</pre>

Revision as of 09:27, 19 April 2021

This page is a work in progress ...

This page is still being developed.

What?

This article provides a basic guide to setting up a read-only-root-based Alpine Linux system with several boot environments and atomic upgrades using rEFInd and btrfs.

Why?

Read-only root and atomic upgrades with ability to easily rollback or boot previous configurations is a concept that got some popularity recently. Distributions providing and promoting such features, for example, are Fedora Silverblue, Opensuse MicroOS, NixOS and GNU Guix. While Alpine Linux has it's killer features it lacks mentioned above ones on default setup. This is a proof of concept that it's possible to implement them in a minimal way on a minimal system.

Partitioning disks

The first step is creating partition table on target device /dev/sda:

# apk add gptfdisk
# gdisk /dev/sda
> o ↵
> y ↵
> w ↵
> y ↵

Now we can define the partitions:

# cgdisk /dev/sda

Partition creation process consists of several steps:

  1. Start sector - you can safely use default value by pressing ↵
  2. Size
  3. Type (as hex code) - EFI is ef00, Linux filesystem is 8300, Swap is 8200.

Result table:

Part.     #     Size        Partition Type            Partition Name
----------------------------------------------------------------
1               200.0 MiB   EFI System                EFI
2               200.0 GiB   Linux filesystem          ROOT
3               32.0 GiB    Linux swap                SWAP

ROOT partition name will later be used in rEFInd configuration to identify boot volume. Next step is creating filesystems:

# mkfs.vfat -F32 /dev/sda1
# mkfs.btrfs /dev/sda2
# mkswap /dev/sda3

Now we can mount our root volume:

# mount /dev/sda2 /mnt

File system structure

|--mnt
| |--commons
| |--current
| |--fstab
| |--links
| | |--20210411213742qwrXAJBz
| | | |--gen_0
| | | |--gen_1
| | | |--gen_2
| | | |--gen_3
| |--next
| |--snapshots
| | |--20210411212549sdBXyLxg
| | | |--@