First commit
This commit is contained in:
parent
450ab53d74
commit
75891d0d4e
6 changed files with 87 additions and 144 deletions
17
ANSWERFILE
Normal file
17
ANSWERFILE
Normal file
|
@ -0,0 +1,17 @@
|
|||
KEYMAPOPTS="us us"
|
||||
HOSTNAMEOPTS="-n cvoges12home-desktop-0"
|
||||
INTERFACESOPTS="auto lo
|
||||
iface lo inet loopback
|
||||
|
||||
auto eth0
|
||||
iface eth0 inet dhcp
|
||||
hostname cvoges12home-desktop-0
|
||||
gateway eth0
|
||||
"
|
||||
DNSOPTS="-n 9.9.9.9"
|
||||
TIMEZONEOPTS="-z UTC"
|
||||
PROXYOPTS="none"
|
||||
APKREPOSOPTS="-f"
|
||||
SSHDOPTS="-c openssh"
|
||||
NTPOPTS="-c chrony"
|
||||
DISKOPTS="none"
|
10
README.md
Normal file
10
README.md
Normal file
|
@ -0,0 +1,10 @@
|
|||
# Alpine Chroot
|
||||
|
||||
To create a base alpine chroot on any alpine system, run:
|
||||
|
||||
```sh
|
||||
chmod +x *.sh
|
||||
./alpine_init.sh
|
||||
```
|
||||
|
||||
Assuming your current working directory is the directory of the cloned repository.
|
42
alpine_init.sh
Normal file
42
alpine_init.sh
Normal file
|
@ -0,0 +1,42 @@
|
|||
setup-alpine -f ANSWERFILE
|
||||
|
||||
# setting fastest edge repos in repo list
|
||||
grep "edge" /etc/apk/repositories | sed "s/^#//" > repositories
|
||||
mv repositories /etc/apk/repositories
|
||||
|
||||
# setting the mirror
|
||||
apk add curl
|
||||
curl -LO http://nl.alpinelinux.org/alpine/MIRRORS.txt
|
||||
mirror=`grep $(head -n 1 /etc/apk/repositories) | sed -e "s/.*\/\///" | sed -e "s/\//\ /" | awk '{print $1}') MIRRORS.txt`
|
||||
rm MIRRORS.txt
|
||||
|
||||
# setting the chroot dir
|
||||
mkdir -p /mnt/chroot
|
||||
chroot_dir="/mnt/chroot"
|
||||
|
||||
# setting the arch (change if needed)
|
||||
arch=$(uname -m)
|
||||
|
||||
|
||||
# set up apk
|
||||
version="edge"
|
||||
curl -LO ${mirror}/latest-stable/main/${arch}/apk-tools-static-${version}.apk
|
||||
tar -xzf apk-tools-static-*.apk
|
||||
|
||||
# install the alpine base installation onto the chroot
|
||||
./sbin/apk.static -X ${mirror}/latest-stable/main -U --allow-untrusted -p ${chroot_dir} --initdb add alpine-base
|
||||
|
||||
# seting up the chroot
|
||||
mount -o bind /dev ${chroot_dir}/dev
|
||||
mount -t proc none ${chroot_dir}/proc
|
||||
mount -o bind /sys ${chroot_dir}/sys
|
||||
|
||||
# set up name resolution
|
||||
cp -L /etc/resolv.conf ${chroot_dir}/etc/
|
||||
|
||||
# prepare the APK repositories
|
||||
branch=$version # change if you want a specific version
|
||||
mkdir -p ${chroot_dir}/etc/apk
|
||||
echo "${mirror}/${branch}/main" > ${chroot_dir}/etc/apk/repositories
|
||||
|
||||
chroot ${chroot_dir} chroot_init.sh
|
18
chroot_init.sh
Normal file
18
chroot_init.sh
Normal file
|
@ -0,0 +1,18 @@
|
|||
# preparing init services
|
||||
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
|
||||
|
||||
# login shell
|
||||
sh -l
|
135
main.sh
135
main.sh
|
@ -1,135 +0,0 @@
|
|||
#!/usr/bin/env ash
|
||||
|
||||
format_disk(){
|
||||
echo "===FORMATTING DISK==="
|
||||
apk add parted e2fsprogs
|
||||
|
||||
ram="8" # in whole number GiB (round up)
|
||||
table="EFI-GPT" # EFI-GPT or MBR or BIOS-GPT
|
||||
|
||||
[ "$table" == "MBR" ] && \
|
||||
parted -s /dev/sda \
|
||||
mklabel msdos \
|
||||
mkpart primary linux-swap 2MiB ${ram}GiB \
|
||||
mkpart primary ext4 ${ram}GiB 100% \
|
||||
set 2 boot on \
|
||||
&& mkswap -L SWAP /dev/sda1 \
|
||||
&& swapon /dev/sda1 \
|
||||
&& mkfs.ext4 -n ROOT /dev/sda2
|
||||
|
||||
[ "$table" == "EFI-GPT" ] && \
|
||||
parted -s /dev/sda \
|
||||
mklabel gpt \
|
||||
mkpart primary fat32 1MiB +260MiB \
|
||||
mkpart primary linux-swap 260MiB +${ram}GiB \
|
||||
mkpart primary ext4 ${ram}GiB 100% \
|
||||
set 1 esp on \
|
||||
set 3 boot on \
|
||||
&& mkdosfs -n EFI /dev/sda1 \
|
||||
&& mkswap -L SWAP /dev/sda2 \
|
||||
&& swapon /dev/sda2 \
|
||||
&& mkfs.ext4 -n ROOT /dev/sda3
|
||||
|
||||
[ "$table" == "BIOS-GPT" ] && \
|
||||
parted -s /dev/sda \
|
||||
mklabel gpt \
|
||||
mkpart primary fat32 1MiB 2MiB \
|
||||
mkpart primary linux-swap 100MiB ${ram}GiB \
|
||||
mkpart primary ext4 ${ram}GiB 100% \
|
||||
set 1 bios_grub on \
|
||||
set 3 boot on \
|
||||
&& mkdosfs -n EFI /dev/sda1 \
|
||||
&& mkswap -L SWAP /dev/sda2 \
|
||||
&& swapon /dev/sda2 \
|
||||
&& mkfs.ext4 -n ROOT /dev/sda3
|
||||
|
||||
echo -e "\n\n"
|
||||
}
|
||||
|
||||
chroot_dir=""
|
||||
arch=""
|
||||
mirror=""
|
||||
branch="latest-stable"
|
||||
version=""
|
||||
|
||||
set_chroot_dir(){
|
||||
echo "===CHROOT DIRECTORY==="
|
||||
mkdir -p /mnt/chroot
|
||||
chroot_dir="/mnt/chroot"
|
||||
}
|
||||
|
||||
set_arch(){
|
||||
arch=`uname -m`
|
||||
}
|
||||
|
||||
set_mirror(){
|
||||
echo "===SETTING MIRROR==="
|
||||
data=""
|
||||
for s in $(wget -qO - \
|
||||
http://rsync.alpinelinux.org/alpine/MIRRORS.txt)
|
||||
do
|
||||
t=$(time -f "%E" wget -q $s/MIRRORS.txt -T 2 -O /dev/null 2>&1)
|
||||
echo "$s was $t"
|
||||
data="$data$t $s\n"
|
||||
done
|
||||
|
||||
mirror=`echo -e $data \
|
||||
| sort \
|
||||
| grep "http" \
|
||||
| head -n 1 \
|
||||
| awk '{print $3}'`
|
||||
echo "${mirror}/${branch}/main" >> /etc/apk/repositories
|
||||
apk upgrade && apk upgrade
|
||||
echo "==RESULTS=="
|
||||
echo -e "${mirror}\n\n"
|
||||
}
|
||||
|
||||
set_version(){
|
||||
version=`wget -O - -o /dev/null \
|
||||
${mirror}/${branch}/main/${arch}/ \
|
||||
| grep "apk-tools-static" \
|
||||
| sed -e 's/.*apk-tools-static-//' \
|
||||
| sed -e 's/\.apk.*//'`
|
||||
}
|
||||
|
||||
get_alpine(){
|
||||
wget \
|
||||
${mirror}/${branch}/main/${arch}\
|
||||
/apk-tools-static-${version}.apk
|
||||
tar -xzf apk-tools-static-*.apk
|
||||
./sbin/apk.static -X ${mirror}/${branch}/main -U \
|
||||
--allow-untrusted --root ${chroot_dir} --initdb add alpine-base
|
||||
}
|
||||
|
||||
mk_chroot(){
|
||||
# dev mounts
|
||||
mount /dev/ ${chroot_dir}/dev/ --bind
|
||||
mount -o remount,ro,bind ${chroot_dir}/dev
|
||||
|
||||
# proc and sysfs
|
||||
mount -t proc none ${chroot_dir}/proc
|
||||
mount -o bind /sys ${chroot_dir}/sys
|
||||
|
||||
# dns
|
||||
cp -L /etc/resolv.conf ${chroot_dir}/etc/
|
||||
mkdir -p ${chroot_dir}/root
|
||||
|
||||
# apk sources
|
||||
mkdir -p ${chroot_dir}/etc/apk
|
||||
echo "${mirror}/${branch}/main" > \
|
||||
${chroot_dir}/etc/apk/repositories
|
||||
}
|
||||
|
||||
set_mirror && \
|
||||
# fix the start and end
|
||||
format_disk && \
|
||||
set_chroot_dir #&& \
|
||||
#set_arch && \
|
||||
#set_version && \
|
||||
#get_alpine && \
|
||||
#mk_chroot
|
||||
|
||||
#cat << EOF | chroot ${chroot_dir} ash -l
|
||||
#mkdir boop
|
||||
#echo "did it work?"
|
||||
#EOF
|
|
@ -1,9 +0,0 @@
|
|||
apk add wireless-tools wpa_supplicant openssh
|
||||
ip link set wlan0 up
|
||||
iwconfig wlan0 essid "TheFoundry"
|
||||
wpa_passphrase "TheFoundry" "somethingclever" > /etc/wpa_supplicant/wpa_supplicant.conf
|
||||
wpa_supplicant -B -i wlan0 -c /etc/wpa_supplicant/wpa_supplicant.conf
|
||||
udhcpc -i wlan0
|
||||
# change /etc/ssh/sshd_config to have "PermitRootLogin yes"
|
||||
passwd #t
|
||||
rc-service sshd restart
|
Loading…
Reference in a new issue