通过急救系统里往硬盘里安装 alpine linux
有的用户想使用 alpine linux,但一般主机商没有该系统模板,但一般主机商有提供急救系统(如 system-rescue-cd),可通过急救系统安装 alpine linux。
本例磁盘 /dev/sda1 已有Linux系统。当前 alpine linux 最新版本是 3.8。
过程:
1.mkfs.ext4 /dev/sda1
# 格式化分区
2.resize2fs -s /dev/sda1
# 去掉ext4的64bit,因为引导syslinux不支持
3.mount /dev/sda1 /mnt/custom/
# 挂载
4.wget http://dl-cdn.alpinelinux.org/alpine/latest-stable/main/x86_64/apk-tools-static-2.10.1-r0.apk
# 下载 alpine linux apk tools
5.tar xzvf apk-tools-static-2.10.1-r0.apk
# 解压
6../sbin/apk.static -X http://dl-cdn.alpinelinux.org/alpine/latest-stable/main -U --allow-untrusted --root /mnt/custom/ --initdb add alpine-base
# 安装alpine linux
7.cp /etc/resolv.conf /mnt/custom/etc/
# 复制文件resolv.conf,解析域名
8.mkdir -p /mnt/custom/root
# 创建用户 root 目录
9.mkdir -p /mnt/custom/etc/apk
# 创建 apk 配置目录
10.echo "http://dl-cdn.alpinelinux.org/alpine/latest-stable/main" > /mnt/custom/etc/apk/repositories
# 设置apk更新镜像网址
11.创建相应设备目录:
mknod -m 666 /mnt/custom/dev/full c 1 7
mknod -m 666 /mnt/custom/dev/ptmx c 5 2
mknod -m 644 /mnt/custom/dev/random c 1 8
mknod -m 644 /mnt/custom/dev/urandom c 1 9
mknod -m 666 /mnt/custom/dev/zero c 1 5
mknod -m 666 /mnt/custom/dev/tty c 5 0
12.挂载目录
mount -t proc none /mnt/custom/proc
mount -o bind /sys /mnt/custom/sys
mount -o bind /dev /mnt/custom/dev
13.chroot /mnt/custom /bin/sh -l
# chroot 到 apline 文件所在目录
14.vi /etc/network/interfaces
# 创建IP配置文件
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
address 144.172.126.32
netmask 255.255.255.0
post-up route add 144.172.126.1 dev eth0
post-up route add default gw 144.172.126.1
post-down route del default gw 144.172.126.1
post-down route del 144.172.126.1 dev eth0
15.setup-sshd
# 安装openssh
16.passwd
# 修改 root 密码
17.adduser liujia -s /bin/ash
# 添加普通用户liujia,以可远程登录
18.addgroup liujia wheel
# 将用户添加到wheel组,可su
19.设置可启动的服务
rc-update add devfs sysinit
rc-update add dmesg sysinit
rc-update add mdev sysinit
rc-update add hwclock boot
rc-update add modules boot
rc-update add sysctl boot
rc-update add hostname boot
rc-update add bootmisc boot
rc-update add syslog boot
rc-update add mount-ro shutdown
rc-update add killprocs shutdown
rc-update add savecache shutdown
rc-update add networking boot
rc-update add urandom boot
rc-update add acpid default
rc-update add hwdrivers sysinit
rc-update add crond default
20.apk add linux-vanilla syslinux
# 安装内核和引导
21.dd bs=440 count=1 if=/usr/share/syslinux/mbr.bin of=/dev/sda
# 将mbr引导写到磁盘中
22.extlinux -i /boot
23.blkid /dev/sda1
# 查看设备uid,如本例是:66ea5797-490e-4cf5-8743-61525af5bfbc
24.sed -i -e "s:^root=.*:root=UUID=66ea5797-490e-4cf5-8743-61525af5bfbc:" /etc/update-extlinux.conf
# 将磁盘uuid写到启动配置文件中
25.sed -i -e "s:^modules=.*:modules=sd-mod,usb-storage,ext3,ext4:" /etc/update-extlinux.conf
# 添加 ext4支持
26.update-extlinux
# 更新引导配置
27.echo "UUID=66ea5797-490e-4cf5-8743-61525af5bfbc / ext4 defaults 1 1" > /etc/fstab
# 将磁盘信息写到文件系统配置文件中
28.重启机子
29.远程ssh连接,正常
参考: