Filesystems: Difference between revisions

From Alpine Linux
(→‎Install: Add btrfs package)
m (added explanation on the process)
 
(24 intermediate revisions by 3 users not shown)
Line 1: Line 1:
[[Category:Storage]]
Alpine Linux supports a number of filesystems.  
Documentation how to use the Alpine distro to format HD/Floppy/Other.
 
== Filesystem Tools ==


== Install ==
Alpine has multiple storage media formatting packages available. Different packages/programs are used to format different types of filesystems.
Alpine has multiple storage media formatting packages available. Different packages/programs are used to format different types of filesystems.
* {{Pkg|dosfstools}} - For FAT12/FAT16/FAT32
* reiserfsprogs - For ReiserFS (Note: not available in Alpine repositories yet)
* {{Pkg|e2fsprogs}} - For ext3/ext4
* {{Pkg|xfsprogs}} - For XFS
* {{Pkg|jfsutils}} - For JFS
* {{Pkg|ntfs-3g}} - For NTFS (Note: ntfs-3g is a FUSE driver)
* {{Pkg|btrfs-progs}} - For BTRFS


In our example we want to format the floppy as vfat.
{| cellpadding="5" border="2" class="wikitable"
{{Cmd|apk add dosfstools}}
|-
! Tool
! Filesystem
! Brief Notes
|-
| {{Pkg|btrfs-progs}}
|[[Btrfs]]
|
|-
|{{Pkg|dosfstools}}  
|FAT12/FAT16/FAT32
|
|-
|{{Pkg|e2fsprogs}}
|ext2/ext3/ext4
|ext4 is current default
|-
|{{Pkg|f2fs-tools}}
|[[F2FS]]
|
|-
|{{Pkg|hfsprogs}}
|XFS HFS/HFS+
|Apple/Mac products
|-
|{{Pkg|jfsutils}}
|JFS
|-
|{{Pkg|ntfs-3g}}
|NTFS
|Microsoft/Windows FUSE driver
|-
|{{Pkg|xfsprogs}}
|XFS
|
|}
 
== Formatting Partitions ==


== Format ==
Whenever a partition is [[Setting_up_disks_manually#Manual_partitioning|created]], the partition must be formatted first before using it.  Depending on the filesystem to be used, the necessary [[Filesystems#Filesystem_Tools|formatting tool]] for the filesystem must be installed first. The various formatting tools like <code> mkfs.ext4</code>, <code>mkfs.vfat</code>, <code>mkfs.btrfs</code> are part of file system tools {{pkg|dosfstools|repo=main}}, {{pkg|e2fsprogs|repo=main}}, {{pkg|btrfs-progs|repo=main}}.  Install the [[Filesystems#Filesystem_Tools|filesystem tools]] first, if not done already.
Here are some examples on how to use the formatting tools:


=== dosfstools ===
The following examples show how to use the formatting tools for different filesystems:
{{Cmd|mkfs.vfat /dev/fd0}}
 
{{Warning|The {{Path|/dev/sdXY}} is only an example. Make sure you choose the right partition to format!  If you choose the wrong partition, your will lose your data. Make a backup first and do not proceed, if you are unsure.}}


=== e2fsprogs ===
=== e2fsprogs ===
{{Cmd|mkfs.ext2 /dev/fd0
ext4 is the default filesystem in Alpine Linux.
mkfs.ext3 /dev/fd0}}
{{Cmd|# mkfs.ext4 /dev/sdaXY}}


=== btrfs-progs ===
=== btrfs-progs ===
{{Cmd|mkfs.btrfs /dev/fd0}}
{{Cmd|# mkfs.btrfs /dev/sdaXY}}
 
=== dosfstools ===
{{Cmd|# mkfs.vfat /dev/sdaXY}}
 
=== f2fs-tools ===
{{Cmd|# mkfs.f2fs /dev/sdaXY}}
 
== Swap Partition ==
 
Swap space is used for two purposes
# Extend the virtual memory beyond the installed physical memory (RAM) to avoid [https://en.wikipedia.org/wiki/Out_of_memory Out of memory] condition 
# Suspend-to-disk or Hibernation support


== Other devices ==
Below Instructions explain how to use a seperate partition for swap:
In our case we want to format a floppy disk. (/dev/fd0) You can change /dev/fd0 to the device you want to format.


== Partitions ==
The following commands prepares the unmounted partition (/dev/sda2) for swap space, activates the prepared swap space and starts the swap service to manage swap space immediately:
If you need to change or make a partition table on a Hard Drive you want to format, you can use:


=== fdisk ===
# mkswap /dev/sda2
{{Cmd|fdisk /dev/hdc}}
# swapon /dev/sda2
# rc-service swap start
 
The command {{Codeline|free -m}} will show how much swap space is available (in MB).
 
To make the swap persistent across reboots, enable automatic start of swap:
 
# echo -e "/dev/sda2 none swap sw 0 0" >> /mnt/etc/fstab
# rc-update add swap
 
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.
 
{{Tip|Instead of using a separate partition for swap, [[Zram|zram]] based swap file can be used.}}
 
== Encrypted swap ==
The below steps explains the steps to enable crypt-swap or Encrypted swap parition.
 
Edit the file {{Path|/etc/conf.d/dmcrypt}} to enable crypt-swap. '''Ensure that source device name is correct.''' :
{{Cat|/etc/conf.d/dmcrypt|
swap{{=}}crypt-swap
source{{=}}'/dev/nvme0nXXX'
}}
 
To use dmcrypt, start dmcrypt service and enable swap immediately:
# /etc/init.d/dmcrypt start
# swapon /dev/mapper/crypt-swap
 
To make the encrypted swap persistent across reboots, enable automatic start of encryption & swap:
 
# rc-update add dmcrypt
# rc-update add swap
 
To enable automatic swapon, add the relevant entry to {{Path|/etc/fstab}}
 
{{Cmd|# echo /dev/mapper/crypt-swap swap swap defaults 0 0 >> /etc/fstab}}
 
{{Note|The above instructions will reset/re-encrypt swap on every boot and thus no suspend to disk works with it.}}
 
== See Also ==
 
* [https://www.nico.schottelius.org/blog/2024-10-10-how-to-enable-encrypted-swap-in-alpine-linux/ How to enable encrypted swap in Alpine Linux]
 
[[Category:Storage]]
[[Category:Installation]]
[[Category:Filesystems]]

Latest revision as of 08:52, 24 October 2024

Alpine Linux supports a number of filesystems.

Filesystem Tools

Alpine has multiple storage media formatting packages available. Different packages/programs are used to format different types of filesystems.

Tool Filesystem Brief Notes
btrfs-progs Btrfs
dosfstools FAT12/FAT16/FAT32
e2fsprogs ext2/ext3/ext4 ext4 is current default
f2fs-tools F2FS
hfsprogs XFS HFS/HFS+ Apple/Mac products
jfsutils JFS
ntfs-3g NTFS Microsoft/Windows FUSE driver
xfsprogs XFS

Formatting Partitions

Whenever a partition is created, the partition must be formatted first before using it. Depending on the filesystem to be used, the necessary formatting tool for the filesystem must be installed first. The various formatting tools like mkfs.ext4, mkfs.vfat, mkfs.btrfs are part of file system tools dosfstools, e2fsprogs, btrfs-progs. Install the filesystem tools first, if not done already.

The following examples show how to use the formatting tools for different filesystems:

Warning: The /dev/sdXY is only an example. Make sure you choose the right partition to format! If you choose the wrong partition, your will lose your data. Make a backup first and do not proceed, if you are unsure.


e2fsprogs

ext4 is the default filesystem in Alpine Linux.

# mkfs.ext4 /dev/sdaXY

btrfs-progs

# mkfs.btrfs /dev/sdaXY

dosfstools

# mkfs.vfat /dev/sdaXY

f2fs-tools

# mkfs.f2fs /dev/sdaXY

Swap Partition

Swap space is used for two purposes

  1. Extend the virtual memory beyond the installed physical memory (RAM) to avoid Out of memory condition
  2. Suspend-to-disk or Hibernation support

Below Instructions explain how to use a seperate partition for swap:

The following commands prepares the unmounted partition (/dev/sda2) for swap space, activates the prepared swap space and starts the swap service to manage swap space immediately:

# mkswap /dev/sda2
# swapon /dev/sda2 
# rc-service swap start

The command free -m will show how much swap space is available (in MB).

To make the swap persistent across reboots, enable automatic start of swap:

# echo -e "/dev/sda2 none swap sw 0 0" >> /mnt/etc/fstab
# rc-update add swap 

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.

Tip: Instead of using a separate partition for swap, zram based swap file can be used.

Encrypted swap

The below steps explains the steps to enable crypt-swap or Encrypted swap parition.

Edit the file /etc/conf.d/dmcrypt to enable crypt-swap. Ensure that source device name is correct. :

Contents of /etc/conf.d/dmcrypt

swap=crypt-swap source='/dev/nvme0nXXX'

To use dmcrypt, start dmcrypt service and enable swap immediately:

# /etc/init.d/dmcrypt start
# swapon /dev/mapper/crypt-swap

To make the encrypted swap persistent across reboots, enable automatic start of encryption & swap:

# rc-update add dmcrypt
# rc-update add swap

To enable automatic swapon, add the relevant entry to /etc/fstab

# echo /dev/mapper/crypt-swap swap swap defaults 0 0 >> /etc/fstab

Note: The above instructions will reset/re-encrypt swap on every boot and thus no suspend to disk works with it.

See Also