better now
This commit is contained in:
parent
3c9e5fe87c
commit
82dbe944cf
3
build.ubuntu.vmimg/.gitignore
vendored
Normal file
3
build.ubuntu.vmimg/.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
.vagrant
|
||||||
|
*.bz2
|
||||||
|
*.qcow2
|
@ -1,8 +1,18 @@
|
|||||||
|
YYYYMMDD := $(shell date +%Y%m%d)
|
||||||
|
|
||||||
default: gen
|
default: gen
|
||||||
|
|
||||||
gen:
|
clean:
|
||||||
|
rm -f *.bz2 *.qcow2
|
||||||
|
|
||||||
|
gen: clean
|
||||||
vagrant destroy -f
|
vagrant destroy -f
|
||||||
vagrant up
|
vagrant up
|
||||||
|
vagrant ssh -- cat saucy64.qcow2 | pv > .tmp.qcow2
|
||||||
|
mv .tmp.qcow2 saucy64-$(YYYYMMDD).qcow2
|
||||||
|
rsync -azvP saucy64-$(YYYYMMDD).qcow2 \
|
||||||
|
root@nue1d0.datavibe.net:/storage/images/
|
||||||
|
|
||||||
sync:
|
sync:
|
||||||
rsync -avP ./make.sh root@nue1d0.datavibe.net:/storage/buildimage/make.sh
|
rsync -avP ./*.sh \
|
||||||
|
root@nue1d0.datavibe.net:/storage/buildimage/
|
||||||
|
@ -1,10 +1,14 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -e
|
||||||
|
set -v
|
||||||
|
set -x
|
||||||
|
|
||||||
R="saucy" # release
|
R="saucy" # release
|
||||||
MR="./roottemp" # mounted root
|
MR="./roottemp" # mounted root
|
||||||
RI="./raw.img" # raw image
|
RI="./raw.img" # raw image
|
||||||
VGN="vmvg0" # volume group name
|
VGN="vmvg0" # volume group name
|
||||||
DSIZE="8G" # disk size
|
DSIZE="25G" # disk size
|
||||||
|
|
||||||
DATE="$(date +%Y%m%d)"
|
DATE="$(date +%Y%m%d)"
|
||||||
LOOPDEV="/dev/loop5"
|
LOOPDEV="/dev/loop5"
|
||||||
@ -20,7 +24,15 @@ function detect_local_mirror () {
|
|||||||
UM="http://${NAME}:${PORT}/ubuntu/"
|
UM="http://${NAME}:${PORT}/ubuntu/"
|
||||||
fi
|
fi
|
||||||
if [ -z "$UM" ]; then
|
if [ -z "$UM" ]; then
|
||||||
echo "http://archive.ubuntu.com/ubuntu/"
|
# maybe try hetzner mirror?
|
||||||
|
UM="http://mirror.hetzner.de/ubuntu/packages/"
|
||||||
|
TF="${UM}/dists/${R}/Release"
|
||||||
|
MOK="$(curl --head ${TF} 2>&1 | grep '200 OK' | wc -l)"
|
||||||
|
if [ $MOK -gt 0 ]; then
|
||||||
|
echo "$UM"
|
||||||
|
else
|
||||||
|
echo "http://archive.ubuntu.com/ubuntu/"
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
echo "$UM"
|
echo "$UM"
|
||||||
fi
|
fi
|
||||||
@ -28,7 +40,6 @@ function detect_local_mirror () {
|
|||||||
|
|
||||||
UM="$(detect_local_mirror)"
|
UM="$(detect_local_mirror)"
|
||||||
|
|
||||||
set -e
|
|
||||||
dd if=/dev/zero of=$RI bs=1 count=0 seek=$DSIZE
|
dd if=/dev/zero of=$RI bs=1 count=0 seek=$DSIZE
|
||||||
parted -s $RI mklabel msdos
|
parted -s $RI mklabel msdos
|
||||||
parted -a optimal $RI mkpart primary 0% 200MiB
|
parted -a optimal $RI mkpart primary 0% 200MiB
|
||||||
@ -43,10 +54,12 @@ vgcreate $VGN /dev/mapper/${LDBASE}p2
|
|||||||
lvcreate -l 100%FREE -n root $VGN
|
lvcreate -l 100%FREE -n root $VGN
|
||||||
mkfs.ext4 -L ROOT /dev/$VGN/root
|
mkfs.ext4 -L ROOT /dev/$VGN/root
|
||||||
mkdir -p $MR
|
mkdir -p $MR
|
||||||
|
MR="$(readlink -f $MR)"
|
||||||
mount /dev/$VGN/root $MR
|
mount /dev/$VGN/root $MR
|
||||||
mkdir $MR/boot
|
mkdir $MR/boot
|
||||||
mount /dev/mapper/${LDBASE}p1 $MR/boot
|
mount /dev/mapper/${LDBASE}p1 $MR/boot
|
||||||
|
|
||||||
|
echo "*** installing base $R system from $UM..."
|
||||||
# install base:
|
# install base:
|
||||||
debootstrap --arch amd64 $R $MR $UM
|
debootstrap --arch amd64 $R $MR $UM
|
||||||
|
|
||||||
@ -57,6 +70,11 @@ for P in updates backports security ; do
|
|||||||
echo "deb $UM $R-$P $RPS" >> $MR/etc/apt/sources.list
|
echo "deb $UM $R-$P $RPS" >> $MR/etc/apt/sources.list
|
||||||
done
|
done
|
||||||
|
|
||||||
|
cat > $MR/etc/apt/apt.conf.d/99-vm-no-extras-please <<EOF
|
||||||
|
APT::Install-Recommends "false";
|
||||||
|
APT::Install-Suggest "false";
|
||||||
|
EOF
|
||||||
|
|
||||||
cp /etc/resolv.conf $MR/etc/resolv.conf
|
cp /etc/resolv.conf $MR/etc/resolv.conf
|
||||||
|
|
||||||
cat > $MR/etc/environment <<EOF
|
cat > $MR/etc/environment <<EOF
|
||||||
@ -76,9 +94,11 @@ RUUID="$(blkid -s UUID -o value /dev/${VGN}/root)"
|
|||||||
|
|
||||||
# this has to come before packages:
|
# this has to come before packages:
|
||||||
cat > $MR/etc/fstab <<EOF
|
cat > $MR/etc/fstab <<EOF
|
||||||
proc /proc proc defaults 0 0
|
proc /proc proc defaults 0 0
|
||||||
/dev/mapper/$VGN-root / ext4 noatime,errors=remount-ro 0 1
|
/dev/mapper/$VGN-root / ext4 noatime,errors=remount-ro 0 1
|
||||||
UUID=$BUUID /boot ext4 noatime 0 2
|
UUID=$BUUID /boot ext4 noatime 0 2
|
||||||
|
none /tmp tmpfs defaults 0 0
|
||||||
|
none /var/tmp tmpfs defaults 0 0
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
cat > $MR/etc/network/interfaces <<EOF
|
cat > $MR/etc/network/interfaces <<EOF
|
||||||
@ -88,12 +108,10 @@ iface lo inet loopback
|
|||||||
auto eth0
|
auto eth0
|
||||||
iface eth0 inet dhcp
|
iface eth0 inet dhcp
|
||||||
EOF
|
EOF
|
||||||
HOSTNAME="${R}64-$DATE"
|
echo "localhost" > $MR/etc/hostname
|
||||||
echo "$HOSTNAME" > $MR/etc/hostname
|
|
||||||
|
|
||||||
cat > $MR/etc/hosts <<EOF
|
cat > $MR/etc/hosts <<EOF
|
||||||
127.0.0.1 localhost
|
127.0.0.1 localhost
|
||||||
127.0.1.1 $HOSTNAME
|
|
||||||
::1 localhost ip6-localhost ip6-loopback
|
::1 localhost ip6-localhost ip6-loopback
|
||||||
fe00::0 ip6-localnet
|
fe00::0 ip6-localnet
|
||||||
ff00::0 ip6-mcastprefix
|
ff00::0 ip6-mcastprefix
|
||||||
@ -108,15 +126,28 @@ mount --bind /proc $MR/proc
|
|||||||
mount --bind /dev $MR/dev
|
mount --bind /dev $MR/dev
|
||||||
mount --bind /sys $MR/sys
|
mount --bind /sys $MR/sys
|
||||||
|
|
||||||
|
cat > $MR/usr/sbin/policy-rc.d <<EOF
|
||||||
|
#!/bin/bash
|
||||||
|
exit 101
|
||||||
|
EOF
|
||||||
|
chmod +x $MR/usr/sbin/policy-rc.d
|
||||||
|
|
||||||
chroot $MR <<EOF
|
chroot $MR <<EOF
|
||||||
export DEBIAN_FRONTEND=noninteractive
|
export DEBIAN_FRONTEND=noninteractive
|
||||||
export RUNLEVEL=1 apt-get -y update
|
export RUNLEVEL=1
|
||||||
|
apt-get -y update
|
||||||
|
|
||||||
PACKAGES="
|
PACKAGES="
|
||||||
linux-image-server
|
linux-image-server
|
||||||
lvm2
|
lvm2
|
||||||
acpid
|
acpid
|
||||||
avahi-utils
|
avahi-utils
|
||||||
|
jq
|
||||||
|
curl
|
||||||
|
wget
|
||||||
|
openssh-server
|
||||||
|
grub2
|
||||||
|
grub-pc
|
||||||
"
|
"
|
||||||
apt-get -y install \$PACKAGES
|
apt-get -y install \$PACKAGES
|
||||||
EOF
|
EOF
|
||||||
@ -159,14 +190,52 @@ EOF
|
|||||||
chroot $MR /bin/bash -c \
|
chroot $MR /bin/bash -c \
|
||||||
"DEBIAN_FRONTEND=noninteractive RUNLEVEL=1 apt-get -y upgrade"
|
"DEBIAN_FRONTEND=noninteractive RUNLEVEL=1 apt-get -y upgrade"
|
||||||
|
|
||||||
|
#FIXME remove for slim image
|
||||||
|
export PACKAGES="
|
||||||
|
build-essential
|
||||||
|
byobu
|
||||||
|
command-not-found
|
||||||
|
daemontools
|
||||||
|
duplicity
|
||||||
|
git-core
|
||||||
|
htop
|
||||||
|
iftop
|
||||||
|
iotop
|
||||||
|
iptraf
|
||||||
|
lsof
|
||||||
|
make
|
||||||
|
make
|
||||||
|
man-db
|
||||||
|
pciutils
|
||||||
|
psmisc
|
||||||
|
pv
|
||||||
|
python-pip
|
||||||
|
rsync
|
||||||
|
screen
|
||||||
|
strace
|
||||||
|
tcpdump
|
||||||
|
traceroute
|
||||||
|
vim
|
||||||
|
"
|
||||||
|
chroot $MR apt-get -y install $PACKAGES
|
||||||
|
|
||||||
|
rm $MR/usr/sbin/policy-rc.d
|
||||||
|
|
||||||
#####################################################
|
#####################################################
|
||||||
### Local Modifications
|
### Local Modifications
|
||||||
#####################################################
|
#####################################################
|
||||||
|
|
||||||
|
cat > $MR/etc/dhcp/dhclient-exit-hooks.d/hostname <<EOF
|
||||||
|
hostname \$new_host_name
|
||||||
|
EOF
|
||||||
|
|
||||||
# install ssh key
|
# install ssh key
|
||||||
mkdir -p $MR/root/.ssh
|
mkdir -p $MR/root/.ssh
|
||||||
cp /root/.ssh/authorized_keys $MR/root/.ssh/
|
cp /root/.ssh/authorized_keys $MR/root/.ssh/
|
||||||
|
|
||||||
|
echo "PasswordAuthentication no" >> $MR/etc/ssh/sshd_config
|
||||||
|
echo "UseDNS no" >> $MR/etc/ssh/sshd_config
|
||||||
|
|
||||||
# clean apt cache
|
# clean apt cache
|
||||||
rm $MR/var/cache/apt/archives/*.deb
|
rm $MR/var/cache/apt/archives/*.deb
|
||||||
|
|
||||||
@ -181,37 +250,43 @@ done
|
|||||||
# clear issue
|
# clear issue
|
||||||
echo "clear > /etc/issue" | chroot $MR
|
echo "clear > /etc/issue" | chroot $MR
|
||||||
|
|
||||||
# run firstboot on boot if exists
|
# remove instance ssh host keys
|
||||||
echo "if test -x /firstboot.sh ; then /firstboot.sh ; fi" \
|
rm $MR/etc/ssh/*key*
|
||||||
>> $MR/etc/rc.local
|
|
||||||
|
|
||||||
# write firstboot file
|
# regenerate them on first boot
|
||||||
cat > $MR/firstboot.sh <<EOF
|
cat > $MR/etc/rc.local <<EOF
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
apt-get update
|
test -f /etc/ssh/ssh_host_dsa_key || dpkg-reconfigure openssh-server
|
||||||
apt-get -y install openssh-server
|
exit 0
|
||||||
rm /firstboot.sh
|
|
||||||
EOF
|
EOF
|
||||||
chmod +x $MR/firstboot.sh
|
chmod +x $MR/etc/rc.local
|
||||||
|
|
||||||
#####################################################
|
|
||||||
### Clean Up and Write Image
|
|
||||||
#####################################################
|
|
||||||
|
|
||||||
echo "******************************************************"
|
echo "******************************************************"
|
||||||
echo "*** Almost done. Cleaning up..."
|
echo "*** Almost done. Cleaning up..."
|
||||||
echo "******************************************************"
|
echo "******************************************************"
|
||||||
|
|
||||||
set +e
|
|
||||||
while grep roottemp /proc/mounts ; do
|
umount $MR/proc
|
||||||
for MP in $(cat /proc/mounts | grep roottemp | awk '{print $2}') ; do
|
umount $MR/sys
|
||||||
umount -l $MP
|
|
||||||
done
|
# udev insists on sticking around, kill it:
|
||||||
sleep 1
|
fuser -m $MR -k
|
||||||
done
|
sleep 1
|
||||||
set -e
|
umount $MR/dev
|
||||||
|
|
||||||
|
# zero space on boot:
|
||||||
|
dd if=/dev/zero of=$MR/boot/zerofile bs=1M || true
|
||||||
|
rm $MR/boot/zerofile
|
||||||
|
umount $MR/boot
|
||||||
|
|
||||||
|
# zero space on root:
|
||||||
|
dd if=/dev/zero of=$MR/zerofile bs=1M || true
|
||||||
|
rm $MR/zerofile
|
||||||
|
|
||||||
|
umount $MR
|
||||||
|
|
||||||
rmdir $MR
|
rmdir $MR
|
||||||
|
|
||||||
vgchange -a n $VGN
|
vgchange -a n $VGN
|
||||||
kpartx -dv $LOOPDEV
|
kpartx -dv $LOOPDEV
|
||||||
losetup -d $LOOPDEV
|
losetup -d $LOOPDEV
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
MR="./mr"
|
MR="./roottemp"
|
||||||
L="/dev/loop5"
|
L="/dev/loop5"
|
||||||
losetup -d /dev/loop6
|
losetup -d /dev/loop6
|
||||||
umount $MR/sys
|
umount $MR/sys
|
||||||
@ -10,4 +10,6 @@ umount $MR
|
|||||||
vgchange -a n vmvg0
|
vgchange -a n vmvg0
|
||||||
kpartx -dv $L
|
kpartx -dv $L
|
||||||
losetup -d $L
|
losetup -d $L
|
||||||
rm -rf mr raw.img
|
rmdir $MR
|
||||||
|
rm raw.img
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user