Setting up disks manually: Difference between revisions

From Alpine Linux
 
(33 intermediate revisions by 11 users not shown)
Line 1: Line 1:


The menu choices that are provided by <code>setup-alpine</code> might not cover all needs, however, it's possible to:


For needs that are not covered by the choices that <code>setup-alpine</code> presents, it's possible to pass special options to the [[Alpine Setup Scripts]], or to set up the partitions and filesystems all manually.
* Call [[Alpine_setup_scripts#setup-disk|setup-disk]] directly, instead of through <code>setup-alpine</code>, and pass some specific partitioning parameters to it.
* Set up the partitions and filesystems manually (to the desired details) and [[Alpine_setup_scripts#Partitioning|tell setup-disk]] to install to the prepared target mountpoint.


(Beta reference: [https://docs.alpinelinux.org/user-handbook/0.1a/Installing/manual.html#_finalizing docs.alpinelinux.org] )


== Using setup-alpine (setup-disk) features ==


= Using setup-alpine (setup-disk) features =
=== For "diskless" and "data" disk mode installs ===


== For "diskless" and "data" disk mode installs ==
This requires some manual steps, as long as the setup-scripts auto-detect usable partitions only on '''removable''' devices (not internal harddisks). They do not support creating new, writable partitions to be used by Alpine.


The scripts seem to only automatically detect usable partitions on *removable* devices (not internal harddisks).
How to prepare writable storage space is explained in the section [[Setting_up_disks_manually#Manual_partitioning| manual partitioning]], below.


And they do not seem to support setting up new, writable partitions to be used by the alpine.
=== For "sys" disk mode installs ===
 
However, how to prepare writable storage space is explained in the section about [[Setting_up_disks_manually#Manual_partitioning| manual partitioning]] below.
 
== For "sys" disk mode installs ==


{{Draft|Some information on this page may be incomplete or outdate.}}
{{Draft|Some information on this page may be incomplete or outdate.}}


=== Disk layouts ===
==== Disk layouts ====


It is possible to have one or more of RAID, encryption, and/or LVM on your {{Path|/}} (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 file in the {{Path|/boot}} partition are configured properly.
It is possible to have one or more of RAID, encrypted, and/or Logical Volume on your {{Path|/}} (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 {{Path|/boot}} partition are configured properly.


Your {{Path|/boot}} cannot reside on an encrypted or LVM volume, at least not with Alpine's default bootloader (extlinux). (Grub2 can deal with {{Path|/boot}} being on an LVM volume.) The usual practice is to create a small partition for {{Path|/boot}}, and then devote the rest of your disk to a separate partition on which you layer one or more of RAID, encryption, and/or LVM.
Your {{Path|/boot}} directory cannot reside on an encrypted or LVM volume, at least not with Alpine's default bootloader (extlinux). (Grub2 can deal with {{Path|/boot}} being on an LVM volume.) The usual practice is to create a small partition for {{Path|/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 {{Path|/boot}} is also setup 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 {{Path|/boot}}, it gets written to multiple physical partitions. During the pre-init, bootloader phase, only one of those partitions will be read from.
Sometimes {{Path|/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 {{Path|/boot}}, it gets written to multiple physical partitions. During the pre-init, bootloader phase, only one of those partitions will be read from.


So, typical setups might look like this:
A typical setup might look like this:


<pre>
<pre>
Line 70: Line 70:
</pre>
</pre>


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


 
==== RAID ====
=== RAID ===


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


If you instead want to build your RAID array manually, see [[Setting up a software RAID array]]. Then you can add additional layers of encryption and/or LVM, or just assemble the RAID array, and supply the {{Path|/dev/md<i>i</i>}} device directly to [[setup-disk]]. When you're finished, be sure to disassemble the RAID array before rebooting.
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 {{Path|/dev/md<i>i</i>}} device directly to [[setup-disk]]. When you're finished, be sure to disassemble the RAID array before rebooting.


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


{{Cmd|1=echo "/sbin/mdadm" > $MNT/etc/mkinitfs/files.d/raid
{{Cmd|1=echo "/sbin/mdadm" > $MNT/etc/mkinitfs/files.d/raid
Line 96: Line 95:
You might also need to manually tweak {{Path|$MNT/etc/fstab}}. And you might need to copy {{Path|/usr/share/syslinux/mbr.bin}} to your disk's MBR.
You might also need to manually tweak {{Path|$MNT/etc/fstab}}. And you might need to copy {{Path|/usr/share/syslinux/mbr.bin}} to your disk's MBR.


=== Encryption ===
==== Encryption ====


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


If you install your {{Path|/}} (root) on an encrypted volume, you'll need to manually edit/rebuild your initram and your extlinux.conf file. The following assumes that <code>$MNT</code> holds the root directory you're installing into, that you've created the cryptvolume on the device {{Path|/dev/md2}}, and that you want to unlock the encrypted volume into a virtual volume named "crypt":
If you install your {{Path|/}} (root) on an encrypted volume, you'll need to manually edit/rebuild your initram and your extlinux.conf file. The following assumes that <code>$MNT</code> holds the root directory you're installing into, that you've created the cryptvolume on the device {{Path|/dev/md2}}, and that you want to unlock the encrypted volume into a virtual volume named "crypt":
Line 115: Line 114:
You might also need to manually tweak {{Path|$MNT/etc/fstab}}.
You might also need to manually tweak {{Path|$MNT/etc/fstab}}.


 
==== LVM ====
 
=== LVM ===


<code>setup-disk</code> will automatically build and use volumes in a LVM group if you supply the '''-L''' switch.
<code>setup-disk</code> will automatically build and use volumes in a LVM group if you supply the '''-L''' switch.
Line 127: Line 124:




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


{{Cmd|1=&#35; edit $MNT/etc/mkinitfs/mkinitfs.conf to make sure features="..."
{{Cmd|1=&#35; edit $MNT/etc/mkinitfs/mkinitfs.conf to make sure features="..."
Line 140: Line 137:
You might also need to manually tweak {{Path|$MNT/etc/fstab}}.
You might also need to manually tweak {{Path|$MNT/etc/fstab}}.


== Manual partitioning ==


=== For "diskless" and "data" disk mode installs ===


The installation image enviroment may have only the very basic busybox built-in <code>fdisk</code> command available. However, alpine allows you to install more complete partitioning tool packages like <code>sfdisk</code> (scriptable fdisk), <code>gptfdisk</code>, <code>parted</code> (CLI), <code>cfdisk</code> (text menus), or even <code>gparted</code> (after [[Installation#Post-Install|setting up a graphical environment]]).


= Manual partitioning =
The following example installs <code>cfdisk</code>, looks for existing partitions, and runs cfdisk against <code>/dev/sdX</code>:
 
 
== For "diskless" and "data" disk mode installs ==
 
The enviroment of the installation images may only have the very basic <code>fdisk</code> command available, but it should also allow to install other partitioning tools.
 
This, for example, installs <code>cfdisk</code>, looks for existing partitions, and starts to partition <code>/dev/sdX</code>:
  # apk add cfdisk
  # apk add cfdisk
  # blkid
  # blkid
Line 157: Line 150:
  # cfdisk /dev/sdX
  # cfdisk /dev/sdX


* Be aware of this Bug: {{Issue|11589|The APKOVL loading of diskless setups doesn't work on btrfs and xfs filesystems, or nvme-based devices}} => So, for the moment, use only ext4 filesystem partitions on classic drives to store diskless mode states.


* Be aware of this Bug: [https://gitlab.alpinelinux.org/alpine/aports/-/issues/11589 Diskless APKOVL loading doesn't work on btrfs and xfs filesystems, or nvme-based devices] => For the moment, use eg. an ext4 filesystem partition on classic drives.
The following creates an ext4 partition with disabled journaling, to reduce write operations and allow the disk to spin down after the .apkovl and the packages have been read from the partition during the boot.
 
This creates an ext4 partition with disabled journaling, to reduce write operations and allow the disk to spin down after the .apkovl and the packages have been read from the partition during the boot.
  # apk add e2fsprogs
  # apk add e2fsprogs
  # mkfs.ext4 -O ^has_journal /dev/sdXY  # the "-O ^has_journal" DISABLES journaling ("^" meaning "not")
  # mkfs.ext4 -O ^has_journal /dev/sdXY  # the "-O ^has_journal" DISABLES journaling ("^" means "not")


{{Note|IMPORTANT! There may be additional steps necessary to make proper use of the partition, see
[[Alpine_local_backup#Saving_and_loading_ISO_image_customizations|Saving and loading ISO image customizations]].
}}


IMPORTANT NOTE: There may still be some further steps necessary to make proper use of the partition, see
{{Note| mkfs.ext4 creates ext4 fs with 64bit feature enabled by default, but extlinux may not be able to boot with that, see Issue {{Issue|14895}}. You may need to add "-O ^has_journal,^64bit" to mkfs.ext4 to circumvent this.
[[Alpine_local_backup#Saving_and_loading_ISO_image_customizations|Saving_and_loading_ISO_image_customizations]].
}}


== For "sys" disk mode installs ==
=== For "sys" disk mode installs ===


<code>setup-disk</code> will by default set up a root partition, a separate /boot partition and a swap. If you want a different layout you can manually create the partitions, filesystems and mount them up on {{Path|/mnt}} (or any other mount point) and then run:
<code>setup-disk</code> will by default set up a root partition, a separate /boot partition and a swap partition. If you want a different layout, you can manually create the partitions, filesystems and mount them on {{Path|/mnt}} (or any other mount point) then run:


{{Cmd|setup-disk /mnt}}
{{Cmd|setup-disk /mnt}}


<code>setup-disk</code> will install your running system on the mounted root, detect your file system layout and generate a fstab.
<code>setup-disk</code> will install your running system on the mounted root, detect your file system layout and generate an fstab.


If you're going for MBR, you are responsible for making the proper partition bootable and make sure the MBR is OK for extlinux. If you're going for EFI, make sure you set <code>BOOTLOADER=grub</code> and <code>USE_EFI=1</code> and {{Pkg|grub-efi}} and {{Pkg|efibootmgr}} are installed before running <code>setup-disk</code>.
If you're using the MBR, you are responsible for making the proper partition bootable and make sure the MBR is OK for extlinux. If you're going to use EFI, make sure you mount <code>esp</code> partition on <code>/boot/efi</code> and set <code>BOOTLOADER=grub</code> and <code>USE_EFI=1</code>, and that {{Pkg|grub-efi}} and {{Pkg|efibootmgr}} are installed before running <code>setup-disk</code>. If your system still does not boot, you can try to manually create a boot entry with {{Pkg|efibootmgr}}, for which instructions can be found at [https://wiki.alpinelinux.org/wiki/Bootloaders#efibootmgr EFI Boot Stub].


See also [https://github.com/itoffshore/alpine-linux-scripts setup-partitions]
See also [https://github.com/itoffshore/alpine-linux-scripts setup-partitions]


=== Dual-booting ===
==== Dual-booting ====
See [[Installing Alpine on HDD dualbooting|Install to HDD with dual-boot]]
See [[Installing Alpine on HDD dualbooting|Install to HDD with dual-boot]]


=== Other needs ===
==== Other needs ====
* [[Installing Alpine Linux in a chroot]]
* [[Installing Alpine Linux in a chroot]]
* [[Replacing non-Alpine Linux with Alpine remotely]]
* [[Replacing non-Alpine Linux with Alpine remotely]]


<!--
<!--
Line 203: Line 197:
  rsync -ruav /lib/modules/* /mnt/lib/modules/
  rsync -ruav /lib/modules/* /mnt/lib/modules/
-->
-->


<!--
<!--
== Setting up the RAID ==
=== Setting up RAID ===
Set up a raid array as described [[Setting up a software RAID1 array|here]].
Set up a raid array as described [[Setting up a software RAID1 array|here]].
In this document two raid arrays are configured: md0 for swap (512MB) and md1 for /var.  
In this document, two raid arrays are configured: md0 for swap (512MB) and md1 for /var.  


== Create filesystem ==
=== Create filesystem ===
We need to install the software to create the filesystem ("format" the partition).
We need to install the software to create the filesystem ("format" the partition).
  apk_add e2fsprogs
  apk_add e2fsprogs
Line 235: Line 228:
  /dev/md1        /var            ext3    defaults 0 0
  /dev/md1        /var            ext3    defaults 0 0


== Move the data ==
=== Move the data ===
Now you should stop all services running that put anything in /var (syslog for example). If you have booted on a clean installation and not run setup-alpine, then no services should be running. However, some packages might have created dirs in /var so we need to backup /var mount the new and move all backed up dirs back to the raided /var.
Stop aall services running that put anything in /var (syslog for example). If you have booted on a clean installation and not run setup-alpine, then no services should be running. However, some packages might have created dirs in /var, so we need to backup /var, mount the new /var directory and move all backed up dirs to the raided /var.


  mv /var /var.tmp
  mv /var /var.tmp
Line 252: Line 245:
  /dev/md1              37977060    181056  35866876  1% /var
  /dev/md1              37977060    181056  35866876  1% /var


== Survive reboots ==
=== Survive reboots ===
Now we have everything up and running. We need to make sure that everything will be restored during next reboot.
Now we have everything up and running. We need to make sure that everything will be restored during next reboot.


Line 273: Line 266:
  chmod +x /etc/init.d/mountdisk
  chmod +x /etc/init.d/mountdisk


'''NOTE:''' Since Alpine-1.7.3 there is a ''localmount'' script shipped so you will not need to create your own ''mountdisk'' script.
'''NOTE:''' Since Alpine-1.7.3 a script named ''localmount'' is included so you will not need to create your own ''mountdisk'' script.


And that /var is mounted *after* raid is created. The -k option will make alpine to unmount the /Var partition during boot. Also add start of swap too boot
/var needs to be mounted *after* raid is created. The -k option will make alpine unmount the /var partition during boot. Add start swap to boot:
  rc_add -k -s 06 mountdisk
  rc_add -k -s 06 mountdisk
  rc_add -k -s 06 swap
  rc_add -k -s 06 swap


The /dev/md* device nodes will not be created automatically so we need to put the on floppy too.
The /dev/md* device nodes will not be created automatically, so we need to put them on floppy too.
  lbu include /dev/md*
  lbu include /dev/md*


Line 287: Line 280:
  ln -s /var/home/* /home/
  ln -s /var/home/* /home/


'''NOTE:''' You cannot just replace /home with a link that points to /var/home since the base has a /home directory. When the boot tries to copy the config from floppy it will fail because of the already existing /home directory.
'''NOTE:''' You cannot just replace /home with a link that points to /var/home since the base has a /home directory. When the system tries to copy the config from floppy it will fail because of the already existing /home directory.


Make sure the links are stored to floppy:
Make sure the links are stored to floppy:
Line 301: Line 294:
  lbu commit floppy
  lbu commit floppy


== Test it works ==
=== Operational Test ===
Reboot computer. Now should the raid start and /var should be mounted. Check with df:
Reboot computer. Now the raid should start and /var should be mounted. Check with df:
  ~ $ df
  ~ $ df
  Filesystem          1k-blocks      Used Available Use% Mounted on
  Filesystem          1k-blocks      Used Available Use% Mounted on
Line 310: Line 303:
  /dev/md1              37977060    180984  35866948  1% /var
  /dev/md1              37977060    180984  35866948  1% /var


== Upgrades ==
=== Upgrades ===
Since the package database is placed on disk, you cannot update by simply replacing the CDROM. You will have to either run the upgrade on the new CDROM or run ''apk_add -u ... && update-conf'' manually.
Since the package database is on disk, you cannot update by simply replacing the CDROM. You will have to either run the upgrade on the new CDROM or run ''apk_add -u ... && update-conf'' manually.
-->
-->


== Setting up swap ==
=== Setting up swap ===


# create partition with type "linux swap" (82) (If you're going to use an LVM logical volume for swap, skip this step and <code>lvcreate</code> that instead.)
# create a partition with the type set to "linux swap" (82) (If you're going to use a logical volume for swap, skip this step and <code>lvcreate</code> that instead.)
# <code>mkswap /dev/sda2</code>
# <code>mkswap /dev/sda2</code>
# <code>echo -e "/dev/sda2 none swap sw 0 0" >> /mnt/etc/fstab</code>
# <code>echo -e "/dev/sda2 none swap sw 0 0" >> /mnt/etc/fstab</code>
# <code>swapon /dev/sda2</code> (or <code>rc-service swap start</code>)
# <code>swapon /dev/sda2</code> (or <code>rc-service swap start</code>)


Then {{Cmd|free -m}} will show how much swap space is available (in MB).
{{Cmd|free -m}} will show how much swap space is available (in MB).


If you prefer maximum speed, you don't need configure any raid devices for swap. Just add 2 swap partitions on different disks and linux will stripe them automatically. The downside is that at the moment one disk fails, the system will go down. For better reliability, put swap on RAID1.  
If you prefer maximum speed, you don't need configure any raid devices for swap. Just add 2 swap partitions on different disks and linux will stripe them automatically. The downside is that the moment one disk fails, the system will go down. For better reliability, put swap on RAID1.  


{{Todo|Instructions for cryptswap?}}
{{Todo|Instructions for cryptswap?}}


= =
=== Custom boot partition size ===
* [https://beta.docs.alpinelinux.org/user-handbook/0.1a/Installing/manual.html#_finalizing beta.docs.alpinelinux.org] ''([http://archive.md/2KQPQ archive])''
 
The default boot partition size is under 40MB. This can cause errors if package updates require additional space on {{path|/boot}}.
Executing {{ic|export BOOT_SIZE{{=}}512}} before running {{ic|setup-disk}} will result in a 512MB boot partition.
 
== Expanding an existing disk ==
Unlike gnu `fdisk`, busybox `fdisk` is rather limited in edit operations. Instead, use `cfdisk` and `resize2fs` to resize the disk. This can be done while booted.  
 
Install tools:
[[File:Cfdisk screenshot alpine 2024-03-04 143916.png|thumb|cfdisk screenshot ]]
{{cmd|# apk add {{pkg|cfdisk|arch=}} {{pkg|e2fsprogs-extra|arch=}}}}
resize disk
{{cmd|# cfdisk {{path|/dev/sda}}}}
 
# Select the target partition, often {{path|/dev/sda3}}
# Select ''Resize'' from the bottom menu
# Select ''Write'', then ''Quit''
 
resize filesystem with -f (online mode), then reboot
{{cmd|# resize2fs -f {{path|/dev/sda3}}
&num; reboot}}


[[Category:Installation]]
[[Category:Installation]]
[[Category:Storage]]
[[Category:Storage]]

Latest revision as of 22:56, 4 March 2024

The menu choices that are provided by setup-alpine might not cover all needs, however, it's possible to:

  • Call setup-disk directly, instead of through setup-alpine, and pass some specific partitioning parameters to it.
  • Set up the partitions and filesystems manually (to the desired details) and tell setup-disk to install to the prepared target mountpoint.

(Beta reference: docs.alpinelinux.org )

Using setup-alpine (setup-disk) features

For "diskless" and "data" disk mode installs

This requires some manual steps, as long as the setup-scripts auto-detect usable partitions only on removable devices (not internal harddisks). They do not support creating new, writable partitions to be used by Alpine.

How to prepare writable storage space is explained in the section manual partitioning, below.

For "sys" disk mode installs

This material is work-in-progress ...

Some information on this page may be incomplete or outdate.
(Last edited by Alpinetony on 4 Mar 2024.)

Disk layouts

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.

Manual partitioning

For "diskless" and "data" disk mode installs

The installation image enviroment may have only the very basic busybox built-in fdisk command available. However, 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).

The following example installs cfdisk, looks for existing partitions, and runs cfdisk against /dev/sdX:

# apk add cfdisk
# blkid
/dev/sdX1: LABEL="some" UUID="..." TYPE="vfat"
/dev/sdX2: LABEL="other" UUID="..." TYPE="ext4"
# cfdisk /dev/sdX

The following creates an ext4 partition with disabled journaling, to reduce write operations and allow the disk to spin down after the .apkovl and the packages have been read from the partition during the boot.

# apk add e2fsprogs
# mkfs.ext4 -O ^has_journal /dev/sdXY   # the "-O ^has_journal" DISABLES journaling ("^" means "not")
Note: IMPORTANT! There may be additional steps necessary to make proper use of the partition, see

Saving and loading ISO image customizations.

Note: mkfs.ext4 creates ext4 fs with 64bit feature enabled by default, but extlinux may not be able to boot with that, see Issue #14895. You may need to add "-O ^has_journal,^64bit" to mkfs.ext4 to circumvent this.

For "sys" disk mode installs

setup-disk will by default set up a root partition, a separate /boot partition and a swap partition. If you want a different layout, you can manually create the partitions, filesystems and mount them on /mnt (or any other mount point) then run:

setup-disk /mnt

setup-disk will install your running system on the mounted root, detect your file system layout and generate an fstab.

If you're using the MBR, you are responsible for making the proper partition bootable and make sure the MBR is OK for extlinux. If you're going to use EFI, make sure you mount esp partition on /boot/efi and set BOOTLOADER=grub and USE_EFI=1, and that grub-efi and efibootmgr are installed before running setup-disk. If your system still does not boot, you can try to manually create a boot entry with efibootmgr, for which instructions can be found at EFI Boot Stub.

See also setup-partitions

Dual-booting

See Install to HDD with dual-boot

Other needs


Setting up swap

  1. create a partition with the type set to "linux swap" (82) (If you're going to use a logical volume for swap, skip this step and lvcreate that instead.)
  2. mkswap /dev/sda2
  3. echo -e "/dev/sda2 none swap sw 0 0" >> /mnt/etc/fstab
  4. swapon /dev/sda2 (or rc-service swap start)

free -m

will show how much swap space is available (in MB).

If you prefer maximum speed, you don't need configure any raid devices for swap. Just add 2 swap partitions on different disks and linux will stripe them automatically. The downside is that the moment one disk fails, the system will go down. For better reliability, put swap on RAID1.

Todo: Instructions for cryptswap?


Custom boot partition size

The default boot partition size is under 40MB. This can cause errors if package updates require additional space on /boot. Executing export BOOT_SIZE=512 before running setup-disk will result in a 512MB boot partition.

Expanding an existing disk

Unlike gnu `fdisk`, busybox `fdisk` is rather limited in edit operations. Instead, use `cfdisk` and `resize2fs` to resize the disk. This can be done while booted.

Install tools:

cfdisk screenshot

# apk add cfdisk e2fsprogs-extra

resize disk

# cfdisk /dev/sda

  1. Select the target partition, often /dev/sda3
  2. Select Resize from the bottom menu
  3. Select Write, then Quit

resize filesystem with -f (online mode), then reboot

# resize2fs -f /dev/sda3 # reboot