Setting up disks manually: Difference between revisions

From Alpine Linux
(Added numbered points to make the process easier to follow)
(added note about the optional nature of partitions other than /)
Line 31: Line 31:
===== Custom Layout =====
===== Custom Layout =====


To perform a traditional hard-disk installation, <code>setup-disk</code> must be called with a MOUNTPOINT, so it install Alpine Linux with MOUNTPOINT as root.
To perform a traditional hard-disk installation, <code>setup-disk</code> must be called with a MOUNTPOINT, so it can install Alpine Linux with MOUNTPOINT as root. For Alpine Linux, except '''/ (root)''' partition, all other partitions are optional, so the steps 5, 6 and 7 related to EFI and Swap partitions are also optional. 
 
# Follow the [[Installation#General_course_of_action|Installation guide]] to complete the [[#Base_configuration|base configuration]].  
# Follow the [[Installation#General_course_of_action|Installation guide]] to complete the [[#Base_configuration|base configuration]].  
# If necessary partition(s) are unavailable, manually [[#Creating_partitions|create]] them first. Except /(root) partition, all other partitions are optional.
# If necessary partition(s) are unavailable, manually [[#Creating_partitions|create]] them first.  
# [[#Formatting_partitions|Format]] the partitions with appropriate [[Filesystems|filesystem]] tools and note that the installation uses the  used during formatting.  
# [[#Formatting_partitions|Format]] the partitions with appropriate [[Filesystems|filesystem]] tools and note that the installation uses the  used during formatting.  
# Mount the root partition on a mount point i.e say {{Path|/mnt}} or any other as follows: {{Cmd|# mount /dev/sdXY /mnt}}
# Mount the '''/ (root)'''  partition on a mount point i.e say {{Path|/mnt}} or any other as follows: {{Cmd|# mount /dev/sdXY /mnt}}
# If you're using EFI, make sure you create a mount point <code>/mnt/boot</code>.  {{Cmd|# mkdir -p /mnt/boot}}
# If you're using EFI, make sure you create a mount point <code>/mnt/boot</code>.  {{Cmd|# mkdir -p /mnt/boot}}
# Find the correct partition name for <code>esp</code> partition and mount it on the above mount point: {{Cmd|# mount /dev/sdXY /mnt/boot}}
# Find the correct partition name for <code>esp</code> partition and mount it on the above mount point: {{Cmd|# mount /dev/sdXY /mnt/boot}}

Revision as of 05:31, 4 November 2024

Alpine Linux can be installed to run in Diskless, Data and system Disk modes using setup-disk script. For traditional or classic harddisk install, refer System Disk Mode Installation.

Data Disk Mode

In Data Disk mode also the operating system runs from system RAM, thus it enjoys the same accelerated operation speed as "diskless" mode. However, swap storage and the entire /var directory tree get mounted from a persistent storage device (two newly created partitions). The directory /var holds e.g. all log files, mailspools, databases, etc., as well as lbu backup commits and the package cache. This mode is useful for having RAM accelerated servers with variable amounts of user-data that exceed the available RAM size. It enables the entire current system state (not just the boot state) to survive a system crash in accordance with the particular filesystem guarantees.

Data Disk Mode Installation

Following the Installation steps to complete the base configuration completes the pre-setup of "diskless" Alpine Linux system. In data disk mode, the boot device may also remain the initial (and possibly read-only) installation media, or be copied to a partition (e.g. /dev/sdXY) with setup-bootable. Refer Creating a bootable device for creating a bootable medium to boot the Data Disk Mode Installation.

As per Bug: #10474, setup-alpine script will create the data partition and mount it as /var, but setup-alpine's "data" disk mode can not yet configure lbu config storage settings automatically. The current workaround, is to select "none" at the 'where to store configs' prompt (as the new data partition is not listed anyway) and configure lbu manually after setup-alpine exits, and before rebooting:

  1. Identify the created data partition, e.g. /dev/sdXY, and its filesystemtype, e.g. using lsblk
  2. Manually edit the lbu backups location in /etc/lbu/lbu.conf and configure LBU_MEDIA=sdXY (according to the previous findings).
  3. Save the configuration on that partition for the next boot with lbu commit.
  4. If (a new) partition fails to get mounted, execute: mkdir /media/sdXY ; echo "/dev/sdXY /media/sdXY fstype noauto,rw 0 0" >> /etc/fstab, and try lbu commit again.

System Disk Mode

System Disk Mode is the traditional harddisk installation. This is the mode suitable for most use cases including generic desktop, development machines etc..

System Disk Mode Installation

If entire hard disk(s) is available for Alpine Linux and default layout is sufficient, using setup-alpine script with optional environment variables is the quickest and easiest way to install Alpine Linux. Refer custom layout for all other use cases.

Default Layout

All existing partitions on the chosen hard disk(s) are deleted and 3 partitions i.e (/)root partition, a /boot partition and a swap partition are created with ext4 filesystem. The setup-alpine script based installation runs the command setup-disk DISKDEV which supports only default layout. However, this can be customized by using the optional environment variables.

The manual pages of setup-disk refers this as DISKDEV mode, as entired Disk Device is used. If DISKDEV is specified, then setup-disk uses the specified disk(s) without asking. If multiple disks are specified then set them up in a RAID array. If there are more than 2 disks, then use raid level 5 instead of raid level 1.

Custom Layout

To perform a traditional hard-disk installation, setup-disk must be called with a MOUNTPOINT, so it can install Alpine Linux with MOUNTPOINT as root. For Alpine Linux, except / (root) partition, all other partitions are optional, so the steps 5, 6 and 7 related to EFI and Swap partitions are also optional.

  1. Follow the Installation guide to complete the base configuration.
  2. If necessary partition(s) are unavailable, manually create them first.
  3. Format the partitions with appropriate filesystem tools and note that the installation uses the used during formatting.
  4. Mount the / (root) partition on a mount point i.e say /mnt or any other as follows:

    # mount /dev/sdXY /mnt

  5. If you're using EFI, make sure you create a mount point /mnt/boot.

    # mkdir -p /mnt/boot

  6. Find the correct partition name for esp partition and mount it on the above mount point:

    # mount /dev/sdXY /mnt/boot

  7. If swap partition is available, you can also enable it now:

    # swapon /dev/sdXY

  8. Install Alpine Linux using the following command:

    # setup-disk -m sys /mnt

  9. setup-disk will perform a traditional disk install of Alpine Linux with MOUNTPOINT as root and generates /etc/fstab automatically.
  10. If BOOTLOADER environment variable is specified, the specified bootloader will be used. If no bootloader is specified, the default bootloader is syslinux except when EFI is detected or explicitly set by USE_EFI environment variable which will select grub.
  11. At the end of Installation, you can reboot to boot into the newly installed Alpine Linux and configure further:

    # reboot

Manual partitioning


Warning: Make sure to choose the correct disk device in the below section. If you choose the wrong device, you will lose your data. Make a backup first and do not proceed, if you are unsure.


Partitioning tools

The installation image enviroment may have only the very basic busybox built-in fdisk command available. Busybox `fdisk` is rather limited for edit operations. Instead, alpine allows you to install more complete partitioning tool packages like sfdisk (scriptable fdisk), gptfdisk, parted (CLI), cfdisk (text menus), or even gparted (after setting up a graphical environment). These tools can be installed even during Installation immediately after setting up base configuration.

Creating partitions

cfdisk will be used in all examples here as it is based on text menu without any dependencies. However, installing the package cfdisk requires network to be available if using Standard ISO boot image. Alternately, sfdisk is available and can be installed without network.

The following step installs the package cfdisk:

# apk add cfdisk

cfdisk will be used to create partitions. Before using cfdisk, the disk name must be identified by using blkid:

# blkid

/dev/sdX1: LABEL="some" UUID="..." TYPE="vfat"
/dev/sdX2: LABEL="other" UUID="..." TYPE="ext4"

When cfdisk is run as follows, it looks for existing partitions on the disk /dev/sdX :

# cfdisk /dev/sdX

For Alpine Linux, only the (/)root partition is mandatory to. Even a /boot partition and swap are optional, when using

Resizing an existing partition

cfdisk and resize2fs can be used to resize existing partitions of ext2/3/4 filsystem on the disk. For other filsystems, the necessary filesystem tools must be installed. This can be done while booted.

cfdisk screenshot

To resize disk, launch the cfdisk:

# cfdisk /dev/sda

  1. Select the target partition, here as per image /dev/sda3
  2. Select Resize from the bottom menu.
  3. Enter the new Size at the prompt.
  4. Select Write, then Quit

If a filesystem is resized with -f (online mode), then the system must be rebooted immediately after the change is made.

# resize2fs -f /dev/sda3 # reboot

Formatting partitions

Install the necessary filesystem tools to format the newly created partitions. Refer the filesystem page for the choices available in Alpine Linux.

Disk layouts

This material is work-in-progress ...

This entire section including RAID, Encryption and LVM needs to be updated.
(Last edited by Prabuanand on 4 Nov 2024.)

It is possible to have one or more of RAID, encrypted, and/or Logical Volume on your / (root) volume. However, the Alpine init script only knows how to handle them when they're layered in that order, and your initram and extlinux.conf files in the /boot partition are configured properly.

Your /boot directory cannot reside on an encrypted or LVM volume, at least not with Alpine's default bootloader (extlinux). (Grub2 can deal with /boot being on an LVM volume.) The usual practice is to create a small partition for /boot, then devote the rest of your disk to a separate partition on which you layer one or more of RAID, encryption, and/or Logical Volumes.

Sometimes /boot is also set up as a mirrored (RAID1) volume. However, this is just for post-init access. That way, when you write a new kernel or bootloader config file to /boot, it gets written to multiple physical partitions. During the pre-init, bootloader phase, only one of those partitions will be read from.

A typical setup might look like this:

One-disk system
---------------
  +------------------------------------------------+
  |  small partition (32--100M), holding           |
  |  only /boot, filesystem needn't be journaled   |
  +------------------------------------------------+
  |  rest of disk in second partition              |
  |  +------------------------------------------+  |
  |  | cryptsetup volume                        |  |
  |  |  +-------------------------------------+ |  |
  |  |  |  LVM PV, containing single VG,      | |  |
  |  |  |  containing multiple LVs, holding   | |  |
  |  |  |  /, /home, swap, etc                | |  |
  |  |  +-------------------------------------+ |  |
  |  +------------------------------------------+  |
  +------------------------------------------------+


Two-disk system
---------------
  +------------------------------------------------+  +------------------------------------------------+
  |  small partition (32--100M), holding           |  |  small partition (32--100M), holding           | These 2 partitions might
  |  only /boot, filesystem needn't be journaled   |  |  only /boot, filesystem needn't be journaled   | form a mirrored (RAID1)
  +------------------------------------------------+  +------------------------------------------------+ volume
  |  rest of disk in second partition              |  |  rest of disk in second partition              |
  | T================================================================================================T | These 2 partitions form
  | T +--------------------------------------------------------------------------------------------+ T | a second mirrored
  | T | cryptsetup volume                                                                          | T | (RAID1) volume
  | T |  +---------------------------------------------------------------------------------------+ | T |
  | T |  | LVM PV, containing single VG,                                                         | | T |
  | T |  | containing multiple LVs, holding                                                      | | T |
  | T |  | /, /home, swap, etc                                                                   | | T |
  | T |  +---------------------------------------------------------------------------------------+ | T |
  | T +--------------------------------------------------------------------------------------------+ T |
  | T================================================================================================T |
  |                                                |  |                                                |
  +------------------------------------------------+  +------------------------------------------------+

In a three-disk system, the /boot would still be RAID1, but the larger partition might, in that case, be RAID5.

RAID

setup-disk will automatically build a RAID array if you supply the -r switch, or if you specify more than one device.

If you want to build your RAID array manually, see Setting up a software RAID array. Then you can add additional layers of encryption and/or Logical Volumes, or just assemble the RAID array, and supply the /dev/mdi device directly to setup-disk. When you're finished, be sure to disassemble the RAID array before rebooting.

If setup-disk sees that you're using RAID, either because you gave it the -r switch, or multiple devices, or a /dev/mdi device, then it will set up your initramfs and extlinux.conf file properly. However, in other cases, such as when you're also using encryption, or you invoke setup-disk with a mounted directory argument, these might not be properly set up for RAID. In that case, you may need to manually edit/rebuild them. The following assumes that $MNT holds the root directory you're installing into:

echo "/sbin/mdadm" > $MNT/etc/mkinitfs/files.d/raid echo "/etc/mdadm.conf" >> $MNT/etc/mkinitfs/files.d/raid # edit $MNT/etc/mkinitfs/mkinitfs.conf to make sure features="..." # includes raid (this field is space-separated and quoted) mkinitfs -c $MNT/etc/mkinitfs/mkinitfs.conf -b $MNT # edit $MNT/etc/update-extlinux.conf to make sure modules=... contains # raid1 or raid456 (whichever your / is on; this field is comma-separated) # also check the root= setting extlinux --raid --install $MNT/boot --update

Todo: Does adding the --update option to extlinux ... suffice to make /boot/extlinux.conf be regenerated? Or do we need to manually tweak that file, or run update-extlinux, as well?


You might also need to manually tweak $MNT/etc/fstab. And you might need to copy /usr/share/syslinux/mbr.bin to your disk's MBR.

Encryption

See Setting up encrypted volumes with LUKS. You can add an additional Logical Volume layer, or just unlock the volume you've created (using cryptsetup luksOpen ...), and supply the /dev/mapper/something device directly to setup-disk. When you're finished, be sure to relock the volume (using cryptsetup luksClose ...) before rebooting.

If you install your / (root) on an encrypted volume, you'll need to manually edit/rebuild your initram and your extlinux.conf file. The following assumes that $MNT holds the root directory you're installing into, that you've created the cryptvolume on the device /dev/md2, and that you want to unlock the encrypted volume into a virtual volume named "crypt":

# edit $MNT/etc/mkinitfs/mkinitfs.conf to make sure features="..." # includes cryptsetup (this field is space-separated and quoted) mkinitfs -c $MNT/etc/mkinitfs/mkinitfs.conf -b $MNT # edit $MNT/etc/update-extlinux.conf to make sure default_kernel_opts="..." # contains cryptroot=/dev/md1 and cryptdm=crypt (this field is also space-separated and quoted) # also check the root= setting extlinux --install $MNT/boot --update

Todo: Does adding the --update option to extlinux ... suffice to make /boot/extlinux.conf be regenerated? Or do we need to manually tweak that file, or run update-extlinux, as well?


You might also need to manually tweak $MNT/etc/fstab.

LVM

setup-disk will automatically build and use volumes in a LVM group if you supply the -L switch.

If you instead want to build your LVM system manually, see Setting up Logical Volumes with LVM. Then vgchange -ay, format and mount your volumes, and supply the root mountpoint to setup-disk. When you're finished, be sure to

umount ... vgchange -an

before rebooting.


If setup-disk sees that you're using LVM, perhaps because you gave it the -L switch, then it will set up your initram and extlinux.conf file properly. However, in other cases, these might not be properly set up. In that case, you may need to manually edit/rebuild them. The following assumes that $MNT holds the root directory you're installing into:

# edit $MNT/etc/mkinitfs/mkinitfs.conf to make sure features="..." # includes lvm (this field is space-separated and quoted) mkinitfs -c $MNT/etc/mkinitfs/mkinitfs.conf -b $MNT # edit $MNT/etc/update-extlinux.conf to make sure root= is set correctly extlinux --install $MNT/boot --update

Todo: Does adding the --update option to extlinux ... suffice to make /boot/extlinux.conf be regenerated? Or do we need to manually tweak that file, or run update-extlinux, as well?


You might also need to manually tweak $MNT/etc/fstab.


see also