Skip to content

Instantly share code, notes, and snippets.

@kmpm
Created April 20, 2012 11:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kmpm/2427821 to your computer and use it in GitHub Desktop.
Save kmpm/2427821 to your computer and use it in GitHub Desktop.
Install Ubuntu Core to a sda1
#!/bin/bash
#******************************************************
# A small script to help out install a Ubuntu Core
# Using a Live USB Ubuntu onto a HD
#
#******************************************************
# Copyright (c) 2012 Peter Magnusson <peter@birchroad.net>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal in
# the Software without restriction, including without limitation the rights to use, copy,
# modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
# and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
# DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
# OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#*****************************************************
DEVICE=/dev/sda
PART=/dev/sda1
ROOT_PATH=/mnt
FST=$ROOT_PATH/etc/fstab
CORE=ubuntu-core-12.04-beta2-core-i386.tar.gz
CORE_URL=http://cdimage.ubuntu.com/ubuntu-core/releases/precise/beta-2/$CORE
ROOT_SCRIPT=inchroot.sh
function pause {
read -p "Press any key to continue..." -n1 -s
echo
}
function message {
echo
echo $@
pause
}
#create script for running inside chroot
echo """
#!/bin/bash
adduser ubuntu
addgroup ubuntu adm
addgroup ubuntu sudo
apt-get update
apt-get install -y language-pack-en-base nano
dpkg-reconfigure locales
apt-get install -y grub-pc
apt-get install -y linux-image-generic-pae
grub-install /dev/sda
update-grub2
""">$ROOT_SCRIPT
if [ ! -f $CORE ]; then
echo
echo "downloading core"
pause
wget $CORE_URL
fi
if [ ! -f $CORE ]; then
echo "Error"
echo "No Core file: $CORE"
exit 1
fi
message "unmouting just to be shure"
sudo umount $ROOT_PATH
message "formating $PART"
sudo mkfs.ext4 $PART
message "mounting $PART to $ROOT_PATH"
sudo mount $PART $ROOT_PATH
mount
echo
echo "unpacking core"
pause
sudo tar -C $ROOT_PATH -zxvf $CORE
message "copying files to core environment"
sudo cp $ROOT_SCRIPT $ROOT_PATH/tmp
sudo /etc/resolv.conf $ROOT_PATH/etc
message 'moving /dev /sys /proc'
echo "echo '##chroot ' > $FST" | sudo sh
for f in /dev /sys /proc ; do
sudo mount --rbind $f $ROOT_PATH/$f
echo "echo '$f none rbind 0 0'>>$FST" | sudo sh
done
message 'starting chroot in $ROOT_PATH'
sudo chroot $ROOT_PATH sh /tmp/$ROOT_SCRIPT
message 'unmounting sys, proc, dev and mnt'
echo "cat /proc/mounts | awk '{print \$2}' | grep \"^$ROOT_PATH\" | sort -r | xargs umount" | sudo sh
echo
echo "Done!!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment