Skip to content

Instantly share code, notes, and snippets.

@kemadz
Last active October 3, 2015 20:07
Show Gist options
  • Save kemadz/2517445 to your computer and use it in GitHub Desktop.
Save kemadz/2517445 to your computer and use it in GitHub Desktop.
Chroot Part of ArchLinux Virtualbox Guest Install Script
#!/bin/sh
# Chroot Part of ArchLinux Virtualbox Guest Install Script
# timezone and hwclock
echo 'Asia/Shanghai' > /etc/timezone
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
# hardware clock in local time
hwclock --systohc --localtime
# hostname
echo 'arch' > /etc/hostname
sed -i '6,7s/$/\tarch/' /etc/hosts
# network
cat > /etc/netctl/eth0 <<DELIM
Description='A basic static ethernet connection'
Interface=eth0
Connection=ethernet
IP=static
Address=('10.0.2.15/24')
Gateway='10.0.2.2'
DNS=('114.114.114.114')
DELIM
# workaround for eth0 renaming
ln -s /dev/null /etc/udev/rules.d/80-net-setup-link.rules
# locale
echo 'LANG=zh_CN.UTF-8' > /etc/locale.conf
source /etc/profile
# locale-gen
sed -i \
-e '/^#en_US ISO-8859-1/s/#//' \
-e '/^#en_US.UTF-8 UTF-8/s/#//' \
-e '/^#zh_CN.GB18030 GB18030/s/#//' \
-e '/^#zh_CN.GBK GBK/s/#//' \
-e '/^#zh_CN.UTF-8 UTF-8/s/#//' \
-e '/^#zh_CN GB2312/s/#//' \
/etc/locale.gen
locale-gen
# modprobe
cat > /etc/modprobe.d/virtualbox.conf <<DELIM
blacklist i2c_piix4
blacklist lpc_ich
DELIM
# mkinitcpio
sed -i '/#COMPRESSION="xz"/s/^#//' /etc/mkinitcpio.conf
mkinitcpio -p linux
# bash
URL_BASHRC=http://mirrors.163.com/gentoo-portage/app-shells/bash/files/bashrc
wget -q $URL_BASHRC -O /etc/bash.bashrc
sed -i 's/#GNU#@//' /etc/bash.bashrc
sed -i '7,9d' /etc/skel/.bashrc
# users
mkdir ~/.ssh
wget -q https://gist.githubusercontent.com/kemadz/5212068/raw -O ~/.ssh/authorized_keys
# curl -s -L --resolve 'gist.github.com:443:192.30.252.140' https://gist.github.com/kemadz/5212068/raw > ~/.ssh/authorized_keys
useradd -m -G users,wheel -s /bin/bash zhong
mkdir /home/zhong/.ssh
cp ~/.ssh/authorized_keys /home/zhong/.ssh/
chown -R zhong.zhong /home/zhong/.ssh
# grub
sed -i \
-e '/^#GRUB_DISABLE_LINUX_UUID/s/#//' \
-e '/^#GRUB_COLOR/s/#//' \
-e '/GRUB_CMDLINE_LINUX/s/""/"ipv6.disable=1"/' \
/etc/default/grub
grub-mkconfig -o /boot/grub/grub.cfg
grub-install /dev/sda
# services
# netctl@eth0
cat > /etc/systemd/system/netctl\@eth0.service <<DELIM
.include /usr/lib/systemd/system/netctl@.service
[Unit]
Description=A basic static ethernet connection
BindsTo=sys-subsystem-net-devices-eth0.device
After=sys-subsystem-net-devices-eth0.device
DELIM
SYSD=/etc/systemd/system/multi-user.target.wants
ln -s '/etc/systemd/system/netctl@eth0.service' "$SYSD/netctl@eth0.service"
# sshd
ln -s '/usr/lib/systemd/system/sshd.service' "$SYSD/sshd.service"
# cronie
ln -s '/usr/lib/systemd/system/cronie.service' "$SYSD/cronie.service"
# postfix
newaliases # for local users
ln -s '/usr/lib/systemd/system/postfix.service' "$SYSD/postfix.service"
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment