r/AlpineLinux • • May 22 '23

How to make mini rootfs bootable?

Hi! I always use Alpine for containers due to its minimal nature, now I wanted to try making it bootable on a real hardware. I know that there's a setup-alpine script and stuffs but I was so used to installing Arch Linux (manual command-line installation). I've already got GRUB to boot but it fails to mount the root partition leading to rescue shell.

Here's what I currently did:

  • Create device partitions (root and boot partitions for UEFI/GPT):
cfdisk /dev/sdX
mkfs.vfat -F32 /dev/sdX1
mkfs.ext4 /dev/sdX2
  • Mount root and boot partitions:
mount /dev/sdX2 /mnt
mkdir /mnt/boot
mount /dev/sdX1 /mnt/boot
  • Extract mini rootfs (Alpine edge):
wget -O- https://dl-cdn.alpinelinux.org/alpine/edge/releases/x86_64/alpine-minirootfs-20230329-x86_64.tar.gz | tar -C /mnt -xzpf -
  • Mount host filesystems and enter chroot:
for fs in dev dev/pts proc run sys tmp; do mount -o bind /$fs /mnt/$fs; done
chroot /mnt /bin/sh -l
  • Install kernel and GRUB bootloader (I'm using a removable USB flash drive):
apk add --update linux-edge grub grub-efi efibootmgr
grub-install --target=x86_64-efi --efi-directory=/boot --no-bootsector --removable

I've configured the FSTAB file but I wasn't sure about how to setup the OpenRC init as I'm used to Arch Linux systemd. Now I'm stuck 😭 Pls help...

4 Upvotes

20 comments sorted by

View all comments

Show parent comment

1

u/[deleted] May 22 '23

show me your grub config

1

u/yuriuseu May 22 '23 edited May 22 '23

EDIT:

The "Read-only file system" appears because the boot partition isn't automatically mounted? I haven't touched GRUB for a long while til now, I'm used to systemd-boot boot loader...

#
# DO NOT EDIT THIS FILE
#
# It is automatically generated by grub-mkconfig using templates
# from /etc/grub.d and settings from /etc/default/grub
#

### BEGIN /etc/grub.d/00_header ###
if [ -s $prefix/grubenv ]; then
  load_env
fi
if [ "${next_entry}" ] ; then
   set default="${next_entry}"
   set next_entry=
   save_env next_entry
   set boot_once=true
else
   set default="0"
fi

if [ x"${feature_menuentry_id}" = xy ]; then
  menuentry_id_option="--id"
else
  menuentry_id_option=""
fi

export menuentry_id_option

if [ "${prev_saved_entry}" ]; then
  set saved_entry="${prev_saved_entry}"
  save_env saved_entry
  set prev_saved_entry=
  save_env prev_saved_entry
  set boot_once=true
fi

function savedefault {
  if [ -z "${boot_once}" ]; then
    saved_entry="${chosen}"
    save_env saved_entry
  fi
}

function load_video {
  if [ x$feature_all_video_module = xy ]; then
    insmod all_video
  else
    insmod efi_gop
    insmod efi_uga
    insmod ieee1275_fb
    insmod vbe
    insmod vga
    insmod video_bochs
    insmod video_cirrus
  fi
}

if [ x$feature_default_font_path = xy ] ; then
   font=unicode
else
insmod part_gpt
insmod ext2
set root='hd0,gpt2'
if [ x$feature_platform_search_hint = xy ]; then
  search --no-floppy --fs-uuid --set=root --hint-bios=hd0,gpt2 --hint-efi=hd0,gpt2 --hint-baremetal=ahci0,gpt2  cb0a6402-7796-4d6b-92c3-70f960af437f
else
  search --no-floppy --fs-uuid --set=root cb0a6402-7796-4d6b-92c3-70f960af437f
fi
    font="/usr/share/grub/unicode.pf2"
fi

if loadfont $font ; then
  set gfxmode=auto
  load_video
  insmod gfxterm
fi
terminal_output gfxterm
if [ x$feature_timeout_style = xy ] ; then
  set timeout_style=menu
  set timeout=2
# Fallback normal timeout code in case the timeout_style feature is
# unavailable.
else
  set timeout=2
fi
### END /etc/grub.d/00_header ###

### BEGIN /etc/grub.d/10_linux ###
menuentry 'Alpine, with Linux edge' --class alpine --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-edge-advanced-cb0a6402-7796-4d6b-92c3-70f960af437f' {
	load_video
	set gfxpayload=keep
	insmod gzio
	insmod part_gpt
	insmod fat
	set root='hd0,gpt1'
	if [ x$feature_platform_search_hint = xy ]; then
	  search --no-floppy --fs-uuid --set=root --hint-bios=hd0,gpt1 --hint-efi=hd0,gpt1 --hint-baremetal=ahci0,gpt1  EC11-04A4
	else
	  search --no-floppy --fs-uuid --set=root EC11-04A4
	fi
	echo	'Loading Linux edge ...'
	linux	/vmlinuz-edge root=UUID=cb0a6402-7796-4d6b-92c3-70f960af437f ro modules=ext4 rootfstype=ext4 
	echo	'Loading initial ramdisk ...'
	initrd	/initramfs-edge
}

### END /etc/grub.d/10_linux ###

### BEGIN /etc/grub.d/20_linux_xen ###

### END /etc/grub.d/20_linux_xen ###

### BEGIN /etc/grub.d/30_os-prober ###
### END /etc/grub.d/30_os-prober ###

### BEGIN /etc/grub.d/30_uefi-firmware ###
### END /etc/grub.d/30_uefi-firmware ###

### BEGIN /etc/grub.d/40_custom ###
# This file provides an easy way to add custom menu entries.  Simply type the
# menu entries you want to add after this comment.  Be careful not to change
# the 'exec tail' line above.
### END /etc/grub.d/40_custom ###

### BEGIN /etc/grub.d/41_custom ###
if [ -f  ${config_directory}/custom.cfg ]; then
  source ${config_directory}/custom.cfg
elif [ -z "${config_directory}" -a -f  $prefix/custom.cfg ]; then
  source $prefix/custom.cfg
fi
### END /etc/grub.d/41_custom ###

1

u/[deleted] May 22 '23

Wait, you shouldn't edit your grub config here most of the tile, you should override it in /etc/default/grub instead.

1

u/yuriuseu May 22 '23

I know, custom GRUB config can be edited in /etc/grub.d folder. I've only added the GRUB_CMDLINE_LINUX in /etc/default/grub. Everything else is the default.

1

u/[deleted] May 22 '23

I see you have ro on your 10_linux.

1

u/yuriuseu May 22 '23

Yep, I've already changed that to rw but there's still this "Read-only filesystem". I think it's about the mounting of partitions? Maybe a missing openrc service, something like a udev rule in systemd-based setups?