Bootstrapping Alpine Linux: Difference between revisions

From Alpine Linux
(added main guideline)
(fixed wikitags, heading levels and changed some headings)
 
(12 intermediate revisions by 5 users not shown)
Line 1: Line 1:
This page provides the instructions to bootstrap Alpine Linux on any [https://en.wikipedia.org/wiki/Virtual_private_server VPS].


== Prerequisite ==


= VPS =
Download apk binary file for your architecture or boot from an Alpine live ISO. {{Cmd|$ wget https://gitlab.alpinelinux.org/api/v4/projects/5/packages/generic/v2.14.6/x86_64/apk.static}}
This section is to provide a means to bootstrap Alpine Linux on any VPS.


== Process ==
Assuming your alpine rootfs is mounted in '''/tmp/target''' and you downloaded apk binary (not using the live ISO).
=== Prepare ===
<ol>
<li>Download apk-tools-static for your architecture.</li>
<pre>wget https://gitlab.alpinelinux.org/api/v4/projects/5/packages/generic/v2.14.0/x86_64/apk.static</pre>


<li>Unpack .apk</li>
== Installation ==
<pre>tar zxf apk-tools-static-*.apk</pre>


</ol>
You may want to replace "latest-stable" from the URL by a specific version of Alpine (e.g. v3.20, v3.21).


=== Install ===
<code>sudo ./apk.static --arch $(arch) -X https://dl-cdn.alpinelinux.org/alpine/latest-stable/main/ -U --allow-untrusted --root /tmp/target --initdb add alpine-base</code>
 
Assuming your alpine rootfs is mounted in '''/tmp/target'''
 
<code>sudo ./sbin/apk.static --arch $(arch) -X http://dl-cdn.alpinelinux.org/alpine/latest-stable/main/ -U --allow-untrusted --root /tmp/target --initdb add alpine-base</code>


* edit /tmp/target/etc/fstab
* edit /tmp/target/etc/fstab
* edit /tmp/target/etc/inittab
* edit /tmp/target/etc/inittab
* edit /tmp/target/etc/mkinitfs/mkinitfs.conf
* edit /tmp/target/etc/resolv.conf
* edit /tmp/target/etc/resolv.conf
* mount proc/sys/dev
* mount proc/sys/dev
Line 30: Line 20:
* chroot into your new installation
* chroot into your new installation
<pre>chroot /tmp/target /bin/sh</pre>
<pre>chroot /tmp/target /bin/sh</pre>
 
* setup hostname
* setup repos (setup-apkrepos -f)
<pre>setup-hostname</pre>
* add a few base packages (apk update && apk add linux-lts acpi)
* setup network
* setup hostname (setup-hostname)
<pre>setup-interfaces</pre>
* setup network (setup-interfaces)
* setup repos
* add services
<pre>setup-apkrepos -f</pre>
* add a few base packages
<pre>apk update
apk add linux-lts linux-firmware-none acpi mkinitfs</pre>
* add services to boot
<pre>
<pre>
rc-update add acpid default
rc-update add acpid default
Line 55: Line 49:
</pre>
</pre>


=== Bootloader ===
== Bootloader ==
 
If you have bootstrapped Alpine Linux from an existing system in a different partition and intend to boot into it, you should always include the root filesystem type (rootfstype) in the kernel parameter (bootloader option), since by default kernel does not automatically load any filesystem modules for root partition, unless specified. That way mount will not complain about being unable to mount root partition on /sysroot.
 
Example bootloader option:
 
<code>root=UUID=AAAAAAAA-BBBB-CCCC-DDDD-EEEEEEEEEEEE rw rootfstype=ext4 vfat</code>


== See also ==


== References ==
* [https://www.linode.com/docs/tools-reference/custom-kernels-distros/running-a-custom-linux-distro-on-a-linode-vps Running a Custom Linux Distribution on a Linode]
* [https://www.linode.com/docs/tools-reference/custom-kernels-distros/running-a-custom-linux-distro-on-a-linode-vps Running a Custom Linux Distribution on a Linode]
* [https://www.linode.com/docs/tools-reference/custom-kernels-distros/run-a-custom-compiled-kernel-with-pvgrub Run a Custom Compiled Kernel with PV-GRUB]
* [https://www.linode.com/docs/tools-reference/custom-kernels-distros/run-a-custom-compiled-kernel-with-pvgrub Run a Custom Compiled Kernel with PV-GRUB]
* [[Replacing non-Alpine Linux with Alpine remotely]]
* [[Replacing non-Alpine Linux with Alpine remotely]]
* [[Install Alpine on Amazon EC2]]
* [[Install Alpine on Amazon EC2]]
* [[Install Alpine on coLinux]]
* [[Install Alpine on Rackspace]]
* [[Alpine setup scripts]]
* [[Alpine setup scripts]]
* [https://serverfault.com/questions/98950/how-do-i-chain-boot-from-grub-to-syslinux How do I chain boot from grub to syslinux?]
* [https://serverfault.com/questions/98950/how-do-i-chain-boot-from-grub-to-syslinux How do I chain boot from grub to syslinux?]

Latest revision as of 13:31, 23 February 2025

This page provides the instructions to bootstrap Alpine Linux on any VPS.

Prerequisite

Download apk binary file for your architecture or boot from an Alpine live ISO.

$ wget https://gitlab.alpinelinux.org/api/v4/projects/5/packages/generic/v2.14.6/x86_64/apk.static

Assuming your alpine rootfs is mounted in /tmp/target and you downloaded apk binary (not using the live ISO).

Installation

You may want to replace "latest-stable" from the URL by a specific version of Alpine (e.g. v3.20, v3.21).

sudo ./apk.static --arch $(arch) -X https://dl-cdn.alpinelinux.org/alpine/latest-stable/main/ -U --allow-untrusted --root /tmp/target --initdb add alpine-base

  • edit /tmp/target/etc/fstab
  • edit /tmp/target/etc/inittab
  • edit /tmp/target/etc/resolv.conf
  • mount proc/sys/dev
for a in proc sys dev; do mount -o bind /$a /tmp/target/$a; done
  • chroot into your new installation
chroot /tmp/target /bin/sh
  • setup hostname
setup-hostname
  • setup network
setup-interfaces
  • setup repos
setup-apkrepos -f
  • add a few base packages
apk update
apk add linux-lts linux-firmware-none acpi mkinitfs
  • add services to boot
rc-update add acpid default
rc-update add bootmisc boot
rc-update add crond default
rc-update add devfs sysinit
rc-update add dmesg sysinit
rc-update add hostname boot
rc-update add hwclock boot
rc-update add hwdrivers sysinit
rc-update add killprocs shutdown
rc-update add mdev sysinit
rc-update add modules boot
rc-update add mount-ro shutdown
rc-update add networking boot
rc-update add savecache shutdown
rc-update add seedrng boot
rc-update add swap boot

Bootloader

If you have bootstrapped Alpine Linux from an existing system in a different partition and intend to boot into it, you should always include the root filesystem type (rootfstype) in the kernel parameter (bootloader option), since by default kernel does not automatically load any filesystem modules for root partition, unless specified. That way mount will not complain about being unable to mount root partition on /sysroot.

Example bootloader option:

root=UUID=AAAAAAAA-BBBB-CCCC-DDDD-EEEEEEEEEEEE rw rootfstype=ext4 vfat

See also