2008-10-08 14:30:16 +00:00
|
|
|
#!/bin/sh -e
|
|
|
|
#
|
2011-09-14 18:01:55 +00:00
|
|
|
# Copyright (C) 2008-2011 Intel
|
2008-10-08 14:30:16 +00:00
|
|
|
#
|
|
|
|
# install.sh [device_name] [rootfs_name] [video_mode] [vga_mode]
|
|
|
|
#
|
|
|
|
|
2011-09-15 22:41:37 +00:00
|
|
|
PATH=/sbin:/bin:/usr/sbin:/usr/bin
|
|
|
|
|
2008-10-08 14:30:16 +00:00
|
|
|
# We need 20 Mb for the boot partition
|
|
|
|
boot_size=20
|
|
|
|
|
|
|
|
# 5% for the swap
|
|
|
|
swap_ratio=5
|
|
|
|
|
2013-08-16 09:38:09 +00:00
|
|
|
# Get a list of hard drives
|
|
|
|
hdnamelist=""
|
|
|
|
live_dev_name=${1%%/*}
|
2014-07-31 00:49:31 +00:00
|
|
|
live_dev_name=${live_dev_name%%[0-9]*}
|
2013-08-16 09:38:09 +00:00
|
|
|
|
|
|
|
echo "Searching for hard drives ..."
|
|
|
|
|
|
|
|
for device in `ls /sys/block/`; do
|
|
|
|
case $device in
|
|
|
|
loop*)
|
|
|
|
# skip loop device
|
|
|
|
;;
|
2014-07-31 00:49:32 +00:00
|
|
|
sr*)
|
|
|
|
# skip CDROM device
|
|
|
|
;;
|
2013-08-16 09:38:09 +00:00
|
|
|
ram*)
|
|
|
|
# skip ram device
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
# skip the device LiveOS is on
|
|
|
|
# Add valid hard drive name to the list
|
|
|
|
if [ $device != $live_dev_name -a -e /dev/$device ]; then
|
|
|
|
hdnamelist="$hdnamelist $device"
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
2008-10-08 14:30:16 +00:00
|
|
|
|
2013-08-16 09:38:09 +00:00
|
|
|
TARGET_DEVICE_NAME=""
|
|
|
|
for hdname in $hdnamelist; do
|
|
|
|
# Display found hard drives and their basic info
|
|
|
|
echo "-------------------------------"
|
|
|
|
echo /dev/$hdname
|
|
|
|
if [ -r /sys/block/$hdname/device/vendor ]; then
|
|
|
|
echo -n "VENDOR="
|
|
|
|
cat /sys/block/$hdname/device/vendor
|
|
|
|
fi
|
2014-07-07 00:43:00 +00:00
|
|
|
if [ -r /sys/block/$hdname/device/model ]; then
|
|
|
|
echo -n "MODEL="
|
|
|
|
cat /sys/block/$hdname/device/model
|
|
|
|
fi
|
|
|
|
if [ -r /sys/block/$hdname/device/uevent ]; then
|
|
|
|
echo -n "UEVENT="
|
|
|
|
cat /sys/block/$hdname/device/uevent
|
|
|
|
fi
|
2013-08-16 09:38:09 +00:00
|
|
|
echo
|
|
|
|
# Get user choice
|
|
|
|
while true; do
|
|
|
|
echo -n "Do you want to install this image there? [y/n] "
|
|
|
|
read answer
|
|
|
|
if [ "$answer" = "y" -o "$answer" = "n" ]; then
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
echo "Please answer y or n"
|
|
|
|
done
|
|
|
|
if [ "$answer" = "y" ]; then
|
|
|
|
TARGET_DEVICE_NAME=$hdname
|
|
|
|
break
|
|
|
|
fi
|
2008-10-08 14:30:16 +00:00
|
|
|
done
|
|
|
|
|
2013-08-16 09:38:09 +00:00
|
|
|
if [ -n "$TARGET_DEVICE_NAME" ]; then
|
|
|
|
echo "Installing image on /dev/$TARGET_DEVICE_NAME ..."
|
|
|
|
else
|
|
|
|
echo "No hard drive selected. Installation aborted."
|
|
|
|
exit 1
|
2008-10-08 14:30:16 +00:00
|
|
|
fi
|
|
|
|
|
2013-08-16 09:38:09 +00:00
|
|
|
device=$TARGET_DEVICE_NAME
|
2008-10-08 14:30:16 +00:00
|
|
|
|
2009-05-26 21:56:03 +00:00
|
|
|
#
|
|
|
|
# The udev automounter can cause pain here, kill it
|
|
|
|
#
|
2013-03-26 06:08:19 +00:00
|
|
|
rm -f /etc/udev/rules.d/automount.rules
|
2009-05-26 21:56:03 +00:00
|
|
|
rm -f /etc/udev/scripts/mount*
|
|
|
|
|
|
|
|
#
|
|
|
|
# Unmount anything the automounter had mounted
|
|
|
|
#
|
2012-05-02 04:14:18 +00:00
|
|
|
umount /dev/${device}* 2> /dev/null || /bin/true
|
2009-05-26 21:56:03 +00:00
|
|
|
|
2008-10-08 14:30:16 +00:00
|
|
|
if [ ! -b /dev/loop0 ] ; then
|
|
|
|
mknod /dev/loop0 b 7 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
mkdir -p /tmp
|
2014-06-05 02:18:49 +00:00
|
|
|
if [ ! -L /etc/mtab ]; then
|
|
|
|
cat /proc/mounts > /etc/mtab
|
|
|
|
fi
|
2008-10-08 14:30:16 +00:00
|
|
|
|
|
|
|
disk_size=$(parted /dev/${device} unit mb print | grep Disk | cut -d" " -f 3 | sed -e "s/MB//")
|
|
|
|
|
2012-07-03 20:02:50 +00:00
|
|
|
swap_size=$((disk_size*swap_ratio/100))
|
2008-10-08 14:30:16 +00:00
|
|
|
rootfs_size=$((disk_size-boot_size-swap_size))
|
|
|
|
|
2012-07-03 23:21:57 +00:00
|
|
|
rootfs_start=$((boot_size))
|
2008-10-08 14:30:16 +00:00
|
|
|
rootfs_end=$((rootfs_start+rootfs_size))
|
2012-07-03 23:21:57 +00:00
|
|
|
swap_start=$((rootfs_end))
|
2008-10-08 14:30:16 +00:00
|
|
|
|
2012-05-02 04:14:18 +00:00
|
|
|
# MMC devices are special in a couple of ways
|
|
|
|
# 1) they use a partition prefix character 'p'
|
|
|
|
# 2) they are detected asynchronously (need rootwait)
|
|
|
|
rootwait=""
|
|
|
|
part_prefix=""
|
|
|
|
if [ ! "${device#mmcblk}" = "${device}" ]; then
|
|
|
|
part_prefix="p"
|
|
|
|
rootwait="rootwait"
|
|
|
|
fi
|
|
|
|
bootfs=/dev/${device}${part_prefix}1
|
|
|
|
rootfs=/dev/${device}${part_prefix}2
|
|
|
|
swap=/dev/${device}${part_prefix}3
|
2008-10-08 14:30:16 +00:00
|
|
|
|
|
|
|
echo "*****************"
|
2012-05-02 04:14:18 +00:00
|
|
|
echo "Boot partition size: $boot_size MB ($bootfs)"
|
|
|
|
echo "Rootfs partition size: $rootfs_size MB ($rootfs)"
|
|
|
|
echo "Swap partition size: $swap_size MB ($swap)"
|
2008-10-08 14:30:16 +00:00
|
|
|
echo "*****************"
|
|
|
|
echo "Deleting partition table on /dev/${device} ..."
|
|
|
|
dd if=/dev/zero of=/dev/${device} bs=512 count=2
|
|
|
|
|
|
|
|
echo "Creating new partition table on /dev/${device} ..."
|
|
|
|
parted /dev/${device} mklabel msdos
|
|
|
|
|
2012-05-02 04:14:18 +00:00
|
|
|
echo "Creating boot partition on $bootfs"
|
2012-07-03 23:21:57 +00:00
|
|
|
parted /dev/${device} mkpart primary 0% $boot_size
|
2008-10-08 14:30:16 +00:00
|
|
|
|
2012-05-02 04:14:18 +00:00
|
|
|
echo "Creating rootfs partition on $rootfs"
|
2011-08-10 14:35:59 +00:00
|
|
|
parted /dev/${device} mkpart primary $rootfs_start $rootfs_end
|
2008-10-08 14:30:16 +00:00
|
|
|
|
2012-05-02 04:14:18 +00:00
|
|
|
echo "Creating swap partition on $swap"
|
2012-07-03 23:21:57 +00:00
|
|
|
parted /dev/${device} mkpart primary $swap_start 100%
|
2008-10-08 14:30:16 +00:00
|
|
|
|
|
|
|
parted /dev/${device} print
|
|
|
|
|
2012-07-03 20:26:00 +00:00
|
|
|
echo "Formatting $bootfs to ext3..."
|
2008-10-08 14:30:16 +00:00
|
|
|
mkfs.ext3 $bootfs
|
|
|
|
|
2012-05-02 04:14:18 +00:00
|
|
|
echo "Formatting $rootfs to ext3..."
|
2008-10-08 14:30:16 +00:00
|
|
|
mkfs.ext3 $rootfs
|
|
|
|
|
2012-05-02 04:14:18 +00:00
|
|
|
echo "Formatting swap partition...($swap)"
|
2008-10-08 14:30:16 +00:00
|
|
|
mkswap $swap
|
|
|
|
|
2013-08-16 09:38:10 +00:00
|
|
|
mkdir /tgt_root
|
|
|
|
mkdir /src_root
|
|
|
|
mkdir -p /boot
|
2008-10-08 14:30:16 +00:00
|
|
|
|
2013-08-16 09:38:10 +00:00
|
|
|
# Handling of the target root partition
|
|
|
|
mount $rootfs /tgt_root
|
2014-05-15 09:36:17 +00:00
|
|
|
mount -o rw,loop,noatime,nodiratime /run/media/$1/$2 /src_root
|
2008-10-08 14:30:16 +00:00
|
|
|
echo "Copying rootfs files..."
|
2013-08-16 09:38:10 +00:00
|
|
|
cp -a /src_root/* /tgt_root
|
|
|
|
if [ -d /tgt_root/etc/ ] ; then
|
|
|
|
echo "$swap swap swap defaults 0 0" >> /tgt_root/etc/fstab
|
|
|
|
echo "$bootfs /boot ext3 defaults 1 2" >> /tgt_root/etc/fstab
|
2008-10-08 14:30:16 +00:00
|
|
|
# We dont want udev to mount our root device while we're booting...
|
2013-08-16 09:38:10 +00:00
|
|
|
if [ -d /tgt_root/etc/udev/ ] ; then
|
|
|
|
echo "/dev/${device}" >> /tgt_root/etc/udev/mount.blacklist
|
2008-10-08 14:30:16 +00:00
|
|
|
fi
|
|
|
|
fi
|
2013-08-16 09:38:10 +00:00
|
|
|
umount /tgt_root
|
|
|
|
umount /src_root
|
2008-10-08 14:30:16 +00:00
|
|
|
|
2013-08-16 09:38:10 +00:00
|
|
|
# Handling of the target boot partition
|
|
|
|
mount $bootfs /boot
|
|
|
|
echo "Preparing boot partition..."
|
2014-05-20 02:49:47 +00:00
|
|
|
if [ -f /etc/grub.d/00_header ] ; then
|
2011-09-14 18:01:55 +00:00
|
|
|
echo "Preparing custom grub2 menu..."
|
2013-08-16 09:38:10 +00:00
|
|
|
GRUBCFG="/boot/grub/grub.cfg"
|
2013-02-21 17:28:02 +00:00
|
|
|
mkdir -p $(dirname $GRUBCFG)
|
2014-05-20 02:49:47 +00:00
|
|
|
cat >$GRUBCFG <<_EOF
|
|
|
|
menuentry "Linux" {
|
|
|
|
set root=(hd0,1)
|
|
|
|
linux /vmlinuz root=$rootfs $rootwait rw $5 $3 $4 quiet
|
|
|
|
}
|
|
|
|
_EOF
|
2013-02-21 17:28:02 +00:00
|
|
|
chmod 0444 $GRUBCFG
|
2011-09-14 18:01:55 +00:00
|
|
|
fi
|
2013-08-16 09:38:10 +00:00
|
|
|
grub-install /dev/${device}
|
|
|
|
echo "(hd0) /dev/${device}" > /boot/grub/device.map
|
2008-10-08 14:30:16 +00:00
|
|
|
|
2013-02-21 17:28:02 +00:00
|
|
|
# If grub.cfg doesn't exist, assume GRUB 0.97 and create a menu.lst
|
2013-08-16 09:38:10 +00:00
|
|
|
if [ ! -f /boot/grub/grub.cfg ] ; then
|
2011-09-14 18:01:55 +00:00
|
|
|
echo "Preparing custom grub menu..."
|
2013-08-16 09:38:10 +00:00
|
|
|
echo "default 0" > /boot/grub/menu.lst
|
|
|
|
echo "timeout 30" >> /boot/grub/menu.lst
|
|
|
|
echo "title Live Boot/Install-Image" >> /boot/grub/menu.lst
|
|
|
|
echo "root (hd0,0)" >> /boot/grub/menu.lst
|
|
|
|
echo "kernel /vmlinuz root=$rootfs rw $3 $4 quiet" >> /boot/grub/menu.lst
|
2011-09-14 18:01:55 +00:00
|
|
|
fi
|
2008-10-08 14:30:16 +00:00
|
|
|
|
2014-05-15 09:36:17 +00:00
|
|
|
cp /run/media/$1/vmlinuz /boot/
|
2013-08-16 09:38:10 +00:00
|
|
|
|
|
|
|
umount /boot
|
2008-10-08 14:30:16 +00:00
|
|
|
|
|
|
|
sync
|
|
|
|
|
|
|
|
echo "Remove your installation media, and press ENTER"
|
|
|
|
|
|
|
|
read enter
|
|
|
|
|
|
|
|
echo "Rebooting..."
|
|
|
|
reboot -f
|