Installing on GPT LVM: Difference between revisions

From Alpine Linux
(→‎Partitioning: fix gptfdisk)
(use internal link)
 
(7 intermediate revisions by 4 users not shown)
Line 1: Line 1:
This is updated version of this Howto [http://wiki.alpinelinux.org/wiki/Setting_up_LVM_on_GPT-labeled_disks Setting up LVM on GPT-labeled disks].
This is an updated version of: [[Setting_up_LVM_on_GPT-labeled_disks|Setting up LVM on GPT-labeled disks]].


This document describes how to set up a system booting from a logical volume in Alpine using lvm2 and GPT-labeled disks.
This document describes how to set up an Alpine Linux system booting from a logical volume 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.  
Begin by booting from the Alpine Linux installation media in the usual way. Log in as `root`, run `setup-alpine`, and answer `none` when asked to choose a disk.  


=== Info ===
=== Info ===
Alpinelinux ISO used in this installation: alpine-2.7.2-x86.iso
Alpine Linux ISO used in this installation: alpine-vanilla-3.7.0-x86_64.iso


This PC have BIOS and not UEFI(uefi installation may differ)
This PC has BIOS, not UEFI (UEFI installation may differ)


Tested on ALIX.3D3 with CF from 8GB.
Tested on APU4C with 30GB Kingston mSata SSD (SMS200S3/30G).




=== Partitioning ===
=== Partitioning ===
We need to install some tools, as 'gptfdisk' is now part of main we do not need to add @edge/testing repository, but need to add one more mirror just in case mirror did not sync:
We need to install some tools. i.e. 'gptfdisk' and 'sgdisk'.
Firstly we need to add second mirror to /etc/apk/repositories
{{Cmd|vi /etc/apk/repositories}}
@edge http://nl.alpinelinux.org/alpine/edge/main
Now we can install it
{{Cmd|apk add -U gptfdisk@edge}}


Create some partition. In my case disk is found as sda, so I will use it in whole process.
Install gptfdisk.
{{Cmd|apk add -U gptfdisk sgdisk}}
 
Create partitions. In my case the SSD disk is found as sda, so I will use 'sda' throughout the process.
{{Cmd|gdisk /dev/sda}}
{{Cmd|gdisk /dev/sda}}
  # create a new empty GUID partition table (GPT) with 'o'
  # create a new empty GUID partition table (GPT) with 'o'
  o # then 'y' to confirm
  o # then 'y' to confirm
  # create some partition: BIOS (needed only for GRUB2), Boot (needed by SYSLINUX), and rest LVM
  # create partitions: BIOS (needed only for GRUB2), Boot (needed by SYSLINUX), and LVM
  n
  n
  1
  1
Line 41: Line 39:
  <enter>
  <enter>
  8e00
  8e00
  # print the partition table with 'p'
  # print the partition with 'p'


You should get something like this:
You should get something like this:
Line 49: Line 47:
   3          210944        15662270  7.4 GiB    8E00  Linux LVM
   3          210944        15662270  7.4 GiB    8E00  Linux LVM


We need to set the 'legacy BIOS bootable' flag on our boot partition, which can be done in gdisk by first entering expert mode with 'x' and then edit attributes with 'a'. It's used by SYSLINUX's GPT support to identify a partition that holds second-stage boot code.
We need to set the 'legacy BIOS bootable' flag on our boot partition. That can be done in gdisk by first entering expert mode with 'x' then editing attributes with 'a'. It's used by SYSLINUX's GPT support to identify a partition that holds the second-stage boot code.
  x
  x
  a
  a
Line 76: Line 74:
  2 (legacy BIOS bootable)
  2 (legacy BIOS bootable)


Write table to disk with and exit gdisk with 'w'.
Press 'Enter' to exit the expert mode and then write the table to disk. Exit gdisk with 'w'.


You can verify the legacy_boot flag with sgdisk (also part of the gptfdisk)
You can verify the legacy_boot flag with sgdisk (also part of gptfdisk).


{{Cmd|1=sgdisk /dev/sda --attributes=1:show}}
{{Cmd|1=sgdisk /dev/sda --attributes=1:show}}
Line 84: Line 82:
  2:2:1 (legacy BIOS bootable)
  2:2:1 (legacy BIOS bootable)
{{Cmd|1=sgdisk /dev/sda --attributes=3:show}}
{{Cmd|1=sgdisk /dev/sda --attributes=3:show}}
Remove gptfdisk (if not needed anymore).
{{Cmd|apk del gptfdisk sgdisk}}


=== LVM Setup ===
=== LVM Setup ===
Now we can setup LVM on the third partition created in above process.
Now we can setup LVM on the third partition created in the process above.
  {{Cmd|apk add lvm2 e2fsprogs syslinux}}
  {{Cmd|apk add lvm2 e2fsprogs syslinux}}


{{Cmd|pvcreate /dev/sda3}}
{{Cmd|pvcreate /dev/sda3}}
   Physical volume "/dev/sda3" successfully created
   Physical volume "/dev/sda3" successfully created
{{Cmd|vgcreate vg0 /dev/sda3}}
{{Cmd|vgcreate vg00 /dev/sda3}}
   Volume group "vg0" successfully created
   Volume group "vg00" successfully created
{{Cmd|lvcreate -n alpine.rootfs -L 1G vg0}}
{{Cmd|lvcreate -n alpine_rootfs -L4G vg00}}
   Logical volume "alpine.rootfs" created
   Logical volume "alpine_rootfs" created
{{Cmd|lvcreate -n swap -C y -L 512M vg0}}
{{Cmd|lvcreate -n swap -C y -L 512M vg00}}
   Logical volume "swap" created
   Logical volume "swap" created
{{Cmd|rc-update add lvm}}
{{Cmd|rc-update add lvm}}
  * service lvm added to runlevel default
  * service lvm added to runlevel default
{{Cmd|vgchange -ay}}
{{Cmd|vgchange -ay}}
   2 logical volume(s) in volume group "vg0" now active
   2 logical volume(s) in volume group "vg00" now active


Format new logical volume and activate swap
Format new logical volume and activate swap.
{{Cmd|mkfs.ext3 /dev/sda2}}
{{Cmd|mkfs.ext3 /dev/sda2}}
{{Cmd|mkfs.ext4 /dev/vg0/alpine.rootfs}}
{{Cmd|mkfs.ext4 /dev/vg00/alpine_rootfs}}
{{Cmd|mkswap /dev/vg0/swap}}
{{Cmd|mkswap /dev/vg0/swap}}


Mount for finishing alpinelinux installation.
Mount for finishing Alpine Linux installation.
{{Cmd|mount -t ext4 /dev/vg0/alpine.rootfs /mnt}}
{{Cmd|mount -t ext4 /dev/vg00/alpine_rootfs /mnt}}
{{Cmd|mkdir /mnt/boot}}
{{Cmd|mkdir /mnt/boot}}
{{Cmd|mount -t ext3 /dev/sda2 /mnt/boot}}
{{Cmd|mount -t ext3 /dev/sda2 /mnt/boot}}


=== Finish installation ===
=== Finish installation ===
Run this command to finish installing alpinelinux to our newly mounted partition on /mnt
Run this command to finish installing Alpine Linux to our newly mounted partition:
{{Cmd|setup-disk -m sys /mnt}}
{{Cmd|setup-disk -m sys /mnt}}


Output of setup-disk should be like this
Output of setup-disk should look like this:
  Installing system on /dev/vg0/alpine.rootfs:
  Installing system on /dev/vg00/alpine_rootfs:
  /mnt/boot is device /dev/sda2
  /mnt/boot is device /dev/sda2
  /boot is device /dev/sda2
  /boot is device /dev/sda2
Line 124: Line 125:


=== Syslinux ===
=== Syslinux ===
Install the MBR:
Install the MBR.
{{Cmd|1=dd bs=440 conv=notrunc count=1 if=/usr/share/syslinux/gptmbr.bin of=/dev/sda}}
{{Cmd|1=dd bs=440 conv=notrunc count=1 if=/usr/share/syslinux/gptmbr.bin of=/dev/sda}}




Reboot and enjoy your new Alpine installation!
Reboot and enjoy your new Alpine Linux installation!
 
[[Category:Installation]]

Latest revision as of 10:55, 7 August 2023

This is an updated version of: Setting up LVM on GPT-labeled disks.

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

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

Info

Alpine Linux ISO used in this installation: alpine-vanilla-3.7.0-x86_64.iso

This PC has BIOS, not UEFI (UEFI installation may differ)

Tested on APU4C with 30GB Kingston mSata SSD (SMS200S3/30G).


Partitioning

We need to install some tools. i.e. 'gptfdisk' and 'sgdisk'.

Install gptfdisk.

apk add -U gptfdisk sgdisk

Create partitions. In my case the SSD disk is found as sda, so I will use 'sda' throughout the process.

gdisk /dev/sda

# create a new empty GUID partition table (GPT) with 'o'
o # then 'y' to confirm
# create partitions: BIOS (needed only for GRUB2), Boot (needed by SYSLINUX), and LVM
n
1
<enter>
+2M
ef02
n
2
<enter>
+100M
8300
n
3
<enter>
<enter>
8e00
# print the partition with 'p'

You should get something like this:

Number  Start (sector)    End (sector)  Size       Code  Name
  1            2048            6143   2.0 MiB     EF02  BIOS boot partition
  2            6144          210943   100.0 MiB   8300  Linux filesystem
  3          210944        15662270   7.4 GiB     8E00  Linux LVM

We need to set the 'legacy BIOS bootable' flag on our boot partition. That can be done in gdisk by first entering expert mode with 'x' then editing attributes with 'a'. It's used by SYSLINUX's GPT support to identify a partition that holds the second-stage boot code.

x
a
2
2

It looks like this:

Command (? for help): x
Expert command (? for help): a
Partition number (1-3): 2
Known attributes are:
0: system partition
1: hide from EFI
2: legacy BIOS bootable
60: read-only
62: hidden
63: do not automount
Attribute value is 0000000000000000. Set fields are:
 No fields set
Toggle which attribute field (0-63, 64 or <Enter> to exit): 2
Have enabled the 'legacy BIOS bootable' attribute.
Attribute value is 0000000000000004. Set fields are:
2 (legacy BIOS bootable)

Press 'Enter' to exit the expert mode and then write the table to disk. Exit gdisk with 'w'.

You can verify the legacy_boot flag with sgdisk (also part of gptfdisk).

sgdisk /dev/sda --attributes=1:show

sgdisk /dev/sda --attributes=2:show

2:2:1 (legacy BIOS bootable)

sgdisk /dev/sda --attributes=3:show

Remove gptfdisk (if not needed anymore).

apk del gptfdisk sgdisk

LVM Setup

Now we can setup LVM on the third partition created in the process above.

apk add lvm2 e2fsprogs syslinux

pvcreate /dev/sda3

 Physical volume "/dev/sda3" successfully created

vgcreate vg00 /dev/sda3

 Volume group "vg00" successfully created

lvcreate -n alpine_rootfs -L4G vg00

 Logical volume "alpine_rootfs" created

lvcreate -n swap -C y -L 512M vg00

 Logical volume "swap" created

rc-update add lvm

* service lvm added to runlevel default

vgchange -ay

 2 logical volume(s) in volume group "vg00" now active

Format new logical volume and activate swap.

mkfs.ext3 /dev/sda2

mkfs.ext4 /dev/vg00/alpine_rootfs

mkswap /dev/vg0/swap

Mount for finishing Alpine Linux installation.

mount -t ext4 /dev/vg00/alpine_rootfs /mnt

mkdir /mnt/boot

mount -t ext3 /dev/sda2 /mnt/boot

Finish installation

Run this command to finish installing Alpine Linux to our newly mounted partition:

setup-disk -m sys /mnt

Output of setup-disk should look like this:

Installing system on /dev/vg00/alpine_rootfs:
/mnt/boot is device /dev/sda2
/boot is device /dev/sda2
You might need fix the MBR to be able to boot


Syslinux

Install the MBR.

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


Reboot and enjoy your new Alpine Linux installation!