Setting up LVM on GPT-labeled disks

From Alpine Linux

This document describes how to set up a system booting from a logical volume in Alpine using lvm2 and GPT-labeled disks.

Begin by booting from Alpine installation media in the usual way. Log in as `root`, run `setup-alpine`, and answer `none` when asked to choose a disk.

Partitioning

We need to install some tools:

apk add parted lvm2

Now we can create the partition table:

parted -a optimal /dev/sda

unit MiB
mkpart 1 1 256
name 1 boot
set 1 legacy_boot on
mkpart 2 256 100%
set 2 lvm on

Now, exit `parted` and reboot to force a reread of the partition table (for some reason, `partprobe` doesn't work here). (Or, instead of rebooting, maybe try running `mdev -s`.)

LVM Creation

Once you've rebooted, run through `setup-alpine` again.

Install some more necessary tools:

apk add lvm2 e2fsprogs syslinux

Create a PV, VG, and a LV for the root partition:

pvcreate /dev/sda2

vgcreate vg0 /dev/sda2

lvcreate -n myhost.root -L 8G vg0

rc-update add lvm

vgchange -ay

Create file systems:

mkfs.ext3 /dev/sda1

mkfs.ext4 /dev/vg0/myhost.root

Mount the file systems:

mount -t ext4 /dev/vg0/myhost.root /target

mkdir /target/boot

mount -t ext3 /dev/sda1 /target/boot

Now you can run `setup-disk` to install Alpine:

setup-disk -m sys /target

Finally, install `syslinux` (note that we are installing to `/dev/sda`, *not* `/dev/sda1`):

dd bs=440 conv=notrunc count=1 if=/usr/share/syslinux/gptmbr.bin of=/dev/sda

Reboot and enjoy your new Alpine installation!