Alpine Linux is a security-oriented, lightweight Linux distribution based on musl libc and busybox.
查看具体磁盘信息:
进入 救援模式后,我们输入以下命令查看具体磁盘名字:
会出现类似于图示:
1 2 3 4 5 6 7 8 9 10 11 12 13
| rescue # fdisk -l Disk /dev/vda: 20 GiB, 21474836480 bytes, 41943040 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk /dev/vdb: 1.1 GiB, 1181116416 bytes, 2306868 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disklabel type: dos Disk identifier: 0xb52fd1c0 Device Boot Start End Sectors Size Id Type /dev/vdb1 * 2048 2304511 2302464 1.1G 83 Linux
|
磁盘最大的那块就是主磁盘,我们这里是/dev/vda
,记住这个磁盘。
开始安装:
下面 /dev/vda部分请替换为上面fdisk查出来的磁盘信息!
- 格式化分区(遇到提示,输入y确定)
- 去掉ext4的64bit,因为引导syslinux不支持
- 创建目录并挂载
1
| mkdir /mnt/custom;mount /dev/vda /mnt/custom/
|
- 下载
alpine linux apk tools
(无法下载请谷歌搜索此文件apk-tools-static-2.10.4-r3.apk进行寻找)
1
| apt update;apt install wget -y;wget https://mirror.netcologne.de/alpine/edge/main/x86/apk-tools-static-2.10.4-r3.apk
|
- 解压
1
| tar xzvf apk-tools-static-2.10.4-r3.apk
|
- 安装alpine linux
1
| ./sbin/apk.static -X http://dl-cdn.alpinelinux.org/alpine/latest-stable/main -U --allow-untrusted --root /mnt/custom/ --initdb add alpine-base
|
- 复制文件resolv.conf,解析域名
1
| cp /etc/resolv.conf /mnt/custom/etc/
|
- 创建用户 root 目录
1
| mkdir -p /mnt/custom/root
|
- 创建 apk 配置目录
1
| mkdir -p /mnt/custom/etc/apk
|
- 设置apk更新镜像网址
1
| echo "http://dl-cdn.alpinelinux.org/alpine/latest-stable/main" > /mnt/custom/etc/apk/repositories
|
- 创建相应设备目录:
1 2 3 4 5 6
| 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
|
- 挂载目录
1 2 3
| mount -t proc none /mnt/custom/proc mount -o bind /sys /mnt/custom/sys mount -o bind /dev /mnt/custom/dev
|
- chroot 到 apline 文件所在目录
1
| chroot /mnt/custom /bin/sh -l
|
- 创建IP配置文件(可以使用原VPS的
/etc/network/interfaces
文件)
- 安装openssh
- 开启root登陆,并修改root密码
1 2
| sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/g' /etc/ssh/sshd_config passwd
|
- 添加普通用户liujia,以可远程登录
1
| adduser liujia -s /bin/ash
|
- 将用户添加到wheel组,可使用su
- 设置可启动的服务
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| 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
|
- 安装内核和引导
1
| apk add linux-vanilla syslinux
|
- 将mbr引导写到磁盘中
1
| dd bs=440 count=1 if=/usr/share/syslinux/mbr.bin of=/dev/vda
|
- 查看具体boot分区,方便第23步使用:
- 查看设备uid,请把/dev/vda路径替换为22步获取的路径,并记录下显示的UUID信息
- 将磁盘uuid写到启动配置文件中,务必替换自己的UUID值,UUID后的
:
要保留!*
1
| sed -i -e "s:^root=.*:root=UUID=bb5b133e-4702-4c3b-b6ae-66cde61cf27a:" /etc/update-extlinux.conf
|
- 添加 ext4支持
1
| sed -i -e "s:^modules=.*:modules=sd-mod,usb-storage,ext3,ext4:" /etc/update-extlinux.conf
|
- 更新引导配置
- 将磁盘信息写到文件系统配置文件中,UUID替换为自己的
1
| echo "UUID=66ea5797-490e-4cf5-8743-61525af5bfbc / ext4 defaults 1 1" > /etc/fstab
|
- 关闭rescue模式,静等vps开机