Skip to content

Instantly share code, notes, and snippets.

@rwcitek
Created November 29, 2014 18:37
Show Gist options
  • Save rwcitek/6d63f8dcdde18f63c8d9 to your computer and use it in GitHub Desktop.
Save rwcitek/6d63f8dcdde18f63c8d9 to your computer and use it in GitHub Desktop.
Mostly automated install of Ubuntu Precise (12.04) and upgrade to Trusty (14.04) in a VirtualBox VM using Knoppix 7.2 and debootstrap
# based in part on information from here:
# http://www.linuxquestions.org/questions/debian-26/how-to-install-debian-using-debootstrap-4175465295/
# https://wiki.ubuntu.com/FoundationsTeam/Specs/KarmicLandscapeReleaseUpgrades
#### Part 1 - Knoppix
# boot Knoppix 7.2
knoppix64 2 noaudio
# configure networking
passwd
/etc/init.d/ssh restart
ip addr
# ssh into knoppix
#### Part 2 - disk setup
# reset disk partitions and mountpoints
ls /dev/sda* | xargs -r -i dd if=/dev/zero bs=1M count=1 of={}
echo -e "o\np\nw" | fdisk /dev/sda
rm -rf /mnt/deboot
# partition disk
echo -e "o\nn\np\n1\n\n\np\nw" | fdisk /dev/sda
sleep 5
mkfs.ext4 /dev/sda1
mkdir /mnt/deboot
mount /dev/sda1 /mnt/deboot
ls -la /mnt/deboot/lost+found/ || exit
#### Part 3 - debootstrap
# run debootstrap
debootstrap --arch amd64 precise /mnt/deboot http://archive.ubuntu.com/ubuntu
#### Part 4 - chroot
# mount
mount -o bind /dev /mnt/deboot/dev
mount -o bind /proc /mnt/deboot/proc
mount -o bind /sys /mnt/deboot/sys
mount | grep deboot
{ cat <<'xeof'
# configure mounts
grep -v rootfs /proc/mounts > /etc/mtab
getuuid=$(blkid | grep /dev/sda1 | cut -d '"' -f2) && echo "UUID=$getuuid / ext4 defaults 0 1" >> /etc/fstab
# install minimal extra packages
export LC_ALL=C
apt-get update
apt-get install -y grub linux-image openssh-server update-manager-core
# configure grub
grub-install /dev/sda
update-grub -y
# install an initial user - password == 123456
useradd -m -s /bin/bash -G sudo ubuntu
usermod -p '$6$gPYxIBPl$T7GdADne..st6WUgxX2Ea7uIW3dqbsE0Zbl8zfcMQvrwIIdRmEHycC24fU5RRFu0eVdFrZoq0x6wZ.4l3XfqM0' ubuntu
# configure networking
cat <<'eof' >> /etc/network/interfaces
auto eth0
iface eth0 inet dhcp
eof
echo "test.example.com" > /etc/hostname
# upgrade to trusty
do-release-upgrade --devel-release --frontend=DistUpgradeViewNonInteractive
xeof
} > /mnt/deboot/tmp/setup.sh
# enter chroot environment
chroot /mnt/deboot /bin/bash -x -c 'source /tmp/setup.sh'
#### Part 5 - finish
# clean up
cd
> /mnt/deboot/root/.bash_history
umount /mnt/deboot/{sys,proc,dev}
umount /mnt/deboot/
# reboot
{ sleep 3 ; reboot ; } & exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment