Dualbooting: Difference between revisions

From Alpine Linux
Line 110: Line 110:


I edited the file to look something like this:
I edited the file to look something like this:
<pre>#!/bin/sh
{{Cat|/etc/grub.d/40_custom|<nowiki>#!/bin/sh
echo "Adding Alpine" >&2
echo "Adding Alpine" >&2
cat << EOF
cat << EOF
Line 118: Line 118:
  initrd /boot/initramfs-lts
  initrd /boot/initramfs-lts
}
}
EOF</pre>
EOF</nowiki>}}
{{Note|The root, linux, initrd, and UUID values mentioned above should be replaced with those of your system, e.g. the UUID you got when running the 'blkid' command.}}
{{Note|The root, linux, initrd, and UUID values mentioned above should be replaced with those of your system, e.g. the UUID you got when running the 'blkid' command.}}
Finally the configuration changes need to be applied to the grub2 bootloader:
Finally the configuration changes need to be applied to the grub2 bootloader:

Revision as of 21:58, 2 July 2023

It's assumed you have a box where you already run another operating system, and would like to be able to boot either the installed system or Alpine.

Prepare your hardware

Alpine needs a separate partition where it can be installed to. If you don't already have one free, you need to create a primary partition with enough space for your Alpine installation.

For this, see: Manual_partitioning

Make note of what partition you will use for your Alpine installation. In this example we are going to install Alpine on /dev/sdXY.

Installing Alpine on an HDD partition

Now it's time to install Alpine. Boot your system with a CD containing the latest Alpine Standard from Downloads.

Format and mount the HDD partition

First format your partition. We will need some tools for doing the formatting. After you are done the tools can be removed.

Warning: Make sure you format the right partition! The /dev/sdXY is only a example. If you choose the wrong partition, your data will be gone. Make a backup first if you are unsure.


apk add e2fsprogs mkfs.ext4 /dev/sdXY apk del e2fsprogs

Then mount the newly formatted partition. After mounting, the partition will be available at /mnt.

mount -t ext4 /dev/sdXY /mnt

Basic setup

First, set up Alpine without installing to a disk.

To do this, either run

setup-alpine

and when to prompted "Which disks do you like to use?" make sure to answer "none". Answer "none" to the remaining prompts about storing configs and the apk cache directory.

Or, run this command sequence:

setup-timezone setup-alpine -q setup-sshd setup-ntp

See setup-alpine for more details.


Install Alpine

Now it's time to copy the prepared system to the prepared partition(s) that were mounted below /mnt.


In Alpine 2.2.3 or newer

setup-disk -m sys /mnt

See setup-disk for more details.


Tip: If you use extlinux (default) and didn't create a separate boot partition, (/boot resides on the root partition /).

You might need to adjust the paths to the boot files in /boot/extlinux.conf, eg.:

[...]
LABEL hardened
  MENU DEFAULT
  MENU LABEL Linux hardened
  LINUX /boot/vmlinuz-lts
  INITRD /boot/initramfs-lts
[...]

Check that the LINUX and INITRD paths actually point to the files shipped in your Alpine Linux release.

With older Alpine versions up to 2.2.3

If you're using an earlier version of Alpine Linux, you'll need to install the files and bootloader manually.

Tip: If you're using a version of Alpine Linux older than 2.2.0, replace /etc/apk/world in the last line with /var/lib/apk/world

lbu package - | tar -C /mnt -xzf - apk add --root /mnt --initdb --repositories-file /etc/apk/repositories --keys-dir \ /etc/apk/keys $(cat /etc/apk/world) acct linux-hardened alpine-base

Your system is now on /dev/sdXY.

Configuring the bootloader

There are different ways to get a boot menu that allows selecting the operating system to boot.

It is easiest on (U)EFI based hardware platforms, where one may simply install the rEFInd boot menu, as explained in Bootloaders.


Otherwise, one may adjust the bootloader that has already been installed (by the other operating system).


Because bootloaders vary, you'll need to figure out how to make yours boot your Alpine install.

Hopefully you can get some ideas from the following example, adjusting Grub2 to boot Alpine:

Reboot your system (start Ubuntu).

Start a 'terminal' (ALT-F2 + "terminal" + [Run])

Take notes of the UUID of the partition you are planning to use:

sudo blkid /dev/sdXY

Start editing the grub2 configuration

gksudo gedit /etc/grub.d/40_custom

I edited the file to look something like this:

Contents of /etc/grub.d/40_custom

#!/bin/sh echo "Adding Alpine" >&2 cat << EOF menuentry "Alpine Linux" { set root=(hd0,3) linux /boot/vmlinuz-lts root=UUID=8de6973a-4a8c-40ed-b710-c4e2b42d6b7a modules=sd-mod,usb-storage,ext4 quiet initrd /boot/initramfs-lts } EOF
Note: The root, linux, initrd, and UUID values mentioned above should be replaced with those of your system, e.g. the UUID you got when running the 'blkid' command.

Finally the configuration changes need to be applied to the grub2 bootloader:

update-grub2

Now it's time to test. Reboot your box.

Note: You might need to press SHIFT when booting your box in order to see the grub-menu.

Windows

For Windows partitions to be detected with grub, you need `os-prober` and `grub-mount` installed at the time grub-mkconfig runs.