Set Up New Disk Partitions for Mountpoints in Alpine Linux
Guide to set up new disk partitions for mountpoints in Alpine Linux
Assumptions
| Item | Details |
|---|---|
| Operating system | Alpine Linux with OpenRC |
| First disk | /dev/sda — existing root disk |
| Second disk | /dev/sdb — RAW, unused |
| New partition | /dev/sdb1 |
| Filesystem | ext4 |
| Mount point | /mountpoint01 |
| Persistence | Automatically mount on boot using /etc/fstab |
| Partition table | GPT |
Inspect Existing Utilities / Install Missing Ones
Inspect which utilities are available
for cmd in fdisk sfdisk parted mkfs.ext4 blkid mount; do
if command -v "$cmd" >/dev/null 2>&1; then
echo "$cmd: available"
else
echo "$cmd: NOT FOUND"
fi
doneThe essential utilities are:
| Utility | Purpose | Typical source |
|---|---|---|
| fdisk | Create disk partitions | BusyBox or util-linux |
| sfdisk | Scriptable partition creation | util-linux |
| mkfs.ext4 | Create ext4 filesystem | e2fsprogs |
| blkid | Retrieve filesystem UUID | BusyBox or util-linux |
| mount | Mount filesystem | BusyBox or util-linux |
| lsblk | Inspect disks | util-linux |
Install additional packages, if needed
| Package | Why it is useful |
|---|---|
| util-linux | Provides modern disk utilities, including partitioning and inspection tools |
| e2fsprogs | Provides ext2/ext3/ext4 filesystem creation, checking, and maintenance tools |
apk add util-linux
apk add e2fsprogsCreate First New Partition
Check available disks and utilities
lsblk -o NAME,SIZE,TYPE,FSTYPE,MOUNTPOINTSCreate a GPT partition
This initialises a GPT partition table and creates one Linux filesystem occupying 10GiB of disk space.
/dev/sdb is the intended unused disk.printf 'label: gpt\nsize=10GiB, type=L\n' | sfdisk /dev/sdb
lsblk /dev/sdbFormat partition
mkfs.ext4 -L data01 /dev/sdb1For a dedicated Linux data disk, ext4 is generally the simplest and most dependable choice. For general storage, Docker volumes, application data, or backups on Alpine, choose ext4, unless there is a specific requirement for snapshots, compression, or other advanced features.
| Filesystem | Advantages | Disadvantages | Additional utilities |
|---|---|---|---|
| ext4 | Mature, reliable, journaling, excellent Linux support | Less advanced snapshot functionality | e2fsprogs for formatting |
| XFS | Strong for large files and high-throughput workloads | Cannot shrink filesystem | xfsprogs |
| Btrfs | Snapshots, compression, checksums | More operational complexity | btrfs-progs |
| ext2 | Simple, minimal overhead | No journaling; less resilient to unexpected shutdowns | e2fsprogs |
| FAT32 | Broad compatibility | 4 GiB maximum individual file size; no Unix permissions | dosfstools |
Create the mountpoint
mkdir -p /mountpoint01Backup fstab, if needed
cp -p /etc/fstab /etc/fstab.bakConfigure the persistent mounting
blkid -s UUID -o value /dev/sdb1
UUID=$(blkid -s UUID -o value /dev/sdb1)
printf 'UUID=%s /mountpoint01 ext4 defaults 0 2\n' "$UUID" >> /etc/fstabMount and verify
mount /mountpoint01
df -h /mountpoint01Append Second New Partition
Create new partition
Assuming you want a second 25GiB partition.
printf 'size=25GiB, type=L\n' | sfdisk --append --no-reread /dev/sdb- --append preserves existing partitions and adds another partition
- size=25GiB specifies the desired size
- type=L specifies a Linux filesystem partition
- --no-reread suppresses the initial kernel partition-table reread check
Inform kernel about second partition
partx -a -n 2 /dev/sdb
lsblk /dev/sdbpartx is supplied by util-linux. It can register the new partition without requiring the existing partition to be unmounted.
If the kernel refuses to recognize the new partition, reboot before formatting. Do not format a partition until its device node and boundaries are correct.
Backup fstab, if needed
cp -p /etc/fstab /etc/fstab.bakFormat and mount the second partition
UUID=$(blkid -s UUID -o value /dev/sdb2)
printf 'UUID=%s /mountpoint02 ext4 defaults 0 2\n' "$UUID" >> /etc/fstab
mount /mountpoint02
df -h /mountpoint01 /mountpoint02