前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Reinstalling Alpine Linux on a Lighthouse Instance

Reinstalling Alpine Linux on a Lighthouse Instance

原创
作者头像
用户9453034
发布2022-02-16 15:38:47
9430
发布2022-02-16 15:38:47
举报

Create an instance with Debian or whatever flavour of your choice. Log in.

Download Arch Linux ISO for booting. Alpine's own boot iso will not work as smooth but you are always welcomed to try.

代码语言:shell
复制
wget https://mirrors.cqu.edu.cn/archlinux/iso/latest/archlinux-2022.02.01-x86_64.iso -O /archlinux.iso

Download Alpine Linux minirootfs.

代码语言:shell
复制
wget https://mirrors.tuna.tsinghua.edu.cn/alpine/v3.15/releases/x86_64/alpine-minirootfs-3.15.0-x86_64.tar.gz -O /alpine.tar.gz

Put this in /boot/grub/grub.cfg after the default Debian session.

代码语言:shell
复制
menuentry "Archlinux Live (x86_64)" {
     insmod iso9660
     set isofile=/archlinux.iso
     loopback lo0 ${isofile}
     linux (lo0)/arch/boot/x86_64/vmlinuz-linux img_dev=/dev/vda1 img_loop=${isofile} earlymodules=loop
     initrd (lo0)/arch/boot/x86_64/initramfs-linux.img
}

Now open your VNC session on the web page and reboot the instance. Choose the newly created entry in Grub.

Inside the Arch Linux boot disc shell, remount /dev/vda1 read-write, remove anything but the boot disc and Alpine Linux minirootfs, mount /dev/vda1 to /mnt, then extract the minirootfs.

We will keep the boot disc in case anything goes wrong, we can boot it in the new Grub to fix things.

代码语言:shell
复制
mount -o rw,remount /dev/vda1
mv /run/archiso/img_dev/archlinux.iso /tmp/
mv /run/archiso/img_dev/alpine.tar.gz /tmp/
rm -rf /run/archiso/img_devpas/*
mount /dev/vda1 /mnt
mv /tmp/archlinux.iso /mnt/
mv /tmp/alpine.tar.gz /mnt/
tar -xf /mnt/alpine.tar.gz -C /mnt

Chroot.

代码语言:shell
复制
mount -t proc /proc /mnt/proc
mount --rbind --make-rslave /dev /mnt/dev
mount --rbind --make-rslave /sys /mnt/sys
cp -L /etc/resolv.conf /mnt/etc/resolv.conf
chroot /mnt /bin/sh

Set up Alpine repository.

代码语言:shell
复制
source /etc/profile
cat > /etc/apk/repositories << EOF
https://mirrors.tuna.tsinghua.edu.cn/alpine/v3.15/main
https://mirrors.tuna.tsinghua.edu.cn/alpine/v3.15/community
EOF

Update, upgrade, and install the base package.

代码语言:shell
复制
apk update
apk upgrade
apk add alpine-base

Install Grub. Make sure to set rootfstype=ext4 in Linux cmdline or /dev/vda1 mounting will fail.

代码语言:shell
复制
apk add grub-bios
echo 'GRUB_CMDLINE_LINUX="rootfstype=ext4"' >> /etc/default/grub

Install linux-firmware-none to avoid unnecessary firmware installation.

We are also using linux-virt.

/boot/grub/grub.cfg is automatically created. No need to run grub-mkconfig.

代码语言:shell
复制
grub-install /dev/vda
apk add linux-firmware-none
apk add linux-virt

Install e2fsprogs for fsck.ext4.

代码语言:shell
复制
apk add e2fsprogs

Setup fstab.

代码语言:shell
复制
echo "/dev/vda1 / ext4 defaults 0 1" > /etc/fstab

Setup network.

代码语言:shell
复制
cat > /etc/network/interfaces << EOF
auto lo
iface lo inet loopback

auto eth0
iface eth0 inet dhcp
EOF

Setup OpenRC runlevels.

代码语言:shell
复制
for i in bootmisc hostname hwclock loadkmap loopback modules networking swap sysctl syslog urandom; do
	ln -s /etc/init.d/$i /etc/runlevels/boot/
done

for i in devfs dmesg hwdrivers mdev; do
	ln -s /etc/init.d/$i /etc/runlevels/sysinit/
done

for i in acpid sshd; do
	ln -s /etc/init.d/$i /etc/runlevels/default/
done

for i in killprocs mount-ro savecache; do
	ln -s /etc/init.d/$i /etc/runlevels/shutdown/
done

Reset root password.

代码语言:shell
复制
passwd

Now reboot to your glorious Alpine Linux.

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档