Alpine Linux: Difference between revisions

From Leo's Notes
This page was last edited on 30 December 2021, at 21:13.
m Text replacement - "Category:Linux" to "Category:Linux{{Navbox Linux}}"
service management
 
(7 intermediate revisions by the same user not shown)
Line 1: Line 1:
Alpine Linux is a small Linux distribution based on musl libc and busybox. This distribution is ideal for docker images because using Musl + BusyBox:
Alpine Linux is a lightweight Linux distribution based on musl libc and Busybox.
# reduces the size of the OS (lighter libc and a less utility binaries)
# reduces the risk of breakage on different hosts with different kernels as things are statically linked.


== Package Management ==
This distribution is commonly found as the base OS for container images due to its small footprint. It's also an attractive option as a minimal Linux distribution since everything is kept minimalistic (no systemd).
Use the {{code|apk}} utility. Search with {{code|apk search}} and install with {{code|apk add}}.


== See Also ==
==Package Management==
* https://wiki.alpinelinux.org/wiki/Main_Page
Packages are handled using the <code>apk</code> utility.
* https://wiki.alpinelinux.org/wiki/Alpine_Linux_package_management
{| class="wikitable"
! style="width: 25%" |Command
!Description
|-
|<code>apk update</code>
|Update repo metadata
|-
|<code>apk upgrade</code>
|Upgrades all installed packages on the system
|-
|<code>apk search $package</code>
|Search for a specific package
|-
|<code>apk add $package [$package2 ...]</code>
|Installs or updates the packages
|-
|<code>apk add --no-cache $packages</code>
|Install without relying on any local caches (otherwise, you may need to delete <code>/var/cache/apk/*</code> to maintain small container/VM images)
|-
|<code>apk add --update-cache $packages</code>
|Update metadata first before installing or updating packages.
|-
|<code>apk add --virtual=$name $packages</code>
|Install packages under a virtual package name. All packages installed will be collected in this virtual package name. This is useful if you need to later uninstall this collection of packages as you only need to uninstall the virtual package.
|-
|<code>apk del $package</code>
|Uninstalls a package
|-
|<code>apk del --purge $name</code>
|Uninstalls packages including all configuration files and any other files from cache.
|}


[[Category:Linux]]{{Navbox Linux}}
== Service Management ==
{| class="wikitable"
! style="width: 25%" |Command
!Description
|-
|<code>rc-status</code>
|Show the current runlevel
|-
|<code>rc-status --list</code>
|Show all available runlevels
|-
|<code>rc $runlevel</code>
|Change the current runlevel
|-
|<code>rc-service --list</code>
|List all services
|-
|<code>rc-update add $service [$runlevel]</code>
|Enable a service on the specified runlevel (or default if not given)
|-
|<code>rc-update del $service</code>
|Remove the service from the default runlevel
|-
|<code>rc-service $service start</code>
<code>/etc/init.d/$service start</code>
|Start a service
|-
|<code>rc-service $service restart</code>
<code>/etc/init.d/$service restart</code>
|Restart a service
|-
|<code>rc-service $service stop</code>
<code>/etc/init.d/$service stop</code>
|Stop a service
|}
 
==Tasks==
 
===Removing unnecessary firmware files===
Alpine Linux installs a bunch of unnecessary firmware packages. You can remove these by running:
{{Highlight
| code = # apk add linux-firmware-none
| lang = terminal
}}
 
===Update Kernel parameters===
Edit <code>/etc/update-extlinux.conf</code>, and change the value at <code>default_kernel_opts</code>.
 
Run <code>update-extlinux</code> to update grub.
 
===Set a static IP address===
Network configuration in Alpine Linux is set in <code>/etc/network/interfaces</code>.
 
If you are using DHCP:
{{Highlight
| code = auto eth0
iface eth0 inet dhcp
| lang = text
}}
If you want to set a static IP address:
{{Highlight
| code = auto eth0
iface eth0 inet static
        address 10.1.2.101/22
        gateway 10.1.1.1
        hostname alpine-vm1
| lang = terminal
}}
Apply changes by restarting networking:
{{Highlight
| code = # /etc/init.d/networking restart
 
## or with service
# service networking restart
| lang = terminal
}}
 
==See Also==
 
*https://wiki.alpinelinux.org/wiki/Main_Page
*https://wiki.alpinelinux.org/wiki/Alpine_Linux_package_management
 
{{Navbox Linux}}
[[Category:Linux]]
[[Category:Operating_Systems]]

Latest revision as of 21:13, 30 December 2021

Alpine Linux is a lightweight Linux distribution based on musl libc and Busybox.

This distribution is commonly found as the base OS for container images due to its small footprint. It's also an attractive option as a minimal Linux distribution since everything is kept minimalistic (no systemd).

Package Management

Packages are handled using the apk utility.

Command Description
apk update Update repo metadata
apk upgrade Upgrades all installed packages on the system
apk search $package Search for a specific package
apk add $package [$package2 ...] Installs or updates the packages
apk add --no-cache $packages Install without relying on any local caches (otherwise, you may need to delete /var/cache/apk/* to maintain small container/VM images)
apk add --update-cache $packages Update metadata first before installing or updating packages.
apk add --virtual=$name $packages Install packages under a virtual package name. All packages installed will be collected in this virtual package name. This is useful if you need to later uninstall this collection of packages as you only need to uninstall the virtual package.
apk del $package Uninstalls a package
apk del --purge $name Uninstalls packages including all configuration files and any other files from cache.

Service Management

Command Description
rc-status Show the current runlevel
rc-status --list Show all available runlevels
rc $runlevel Change the current runlevel
rc-service --list List all services
rc-update add $service [$runlevel] Enable a service on the specified runlevel (or default if not given)
rc-update del $service Remove the service from the default runlevel
rc-service $service start

/etc/init.d/$service start

Start a service
rc-service $service restart

/etc/init.d/$service restart

Restart a service
rc-service $service stop

/etc/init.d/$service stop

Stop a service

Tasks

Removing unnecessary firmware files

Alpine Linux installs a bunch of unnecessary firmware packages. You can remove these by running:

# apk add linux-firmware-none

Update Kernel parameters

Edit /etc/update-extlinux.conf, and change the value at default_kernel_opts.

Run update-extlinux to update grub.

Set a static IP address

Network configuration in Alpine Linux is set in /etc/network/interfaces.

If you are using DHCP:

auto eth0
iface eth0 inet dhcp

If you want to set a static IP address:

auto eth0
iface eth0 inet static
        address 10.1.2.101/22
        gateway 10.1.1.1
        hostname alpine-vm1

Apply changes by restarting networking:

# /etc/init.d/networking restart

## or with service
# service networking restart

See Also