Last active
August 29, 2015 14:09
-
-
Save knakayama/c460b7ed21bb09a802e3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# not work | |
set -o xtrace | |
set -o errexit | |
{ | |
if [ ! -f "/etc/apt/sources.list.d/zfs-native-stable-trusty.list" ]; then | |
apt-add-repository -y ppa:zfs-native/stable | |
fi | |
apt-get update --yes | |
apt-get install --yes debootstrap spl-dkms zfs-dkms ubuntu-zfs | |
if ! lsmod | grep -qF 'zfs'; then | |
modprobe zfs | |
fi | |
dmesg | grep -F 'ZFS:' | |
## create partition | |
#if [ ! -f "/root/partitioned.txt" ]; then | |
# first_disk="$(lsblk | awk '$1~/^[hs]d[a-z]/ && $NF~/disk/ {printf "/dev/%s\n", $1}' | head -n1)" | |
# for p_num in $(ls ${first_disk}* | grep -Eo '[0-9]+$' | sort -nr); do | |
# printf "d\n%d\nw\n" "$p_num" | fdisk "$first_disk" || true | |
# done | |
# printf "n\np\n1\n\n+256MB\na\n1\nt\nbe\nn\np\n2\n\n\nt\n2\nbf\np\nw\n" | fdisk "$first_disk" || true | |
# | |
# for disk in $(lsblk | awk '$1~/^[hs]d[a-z]/ && $NF~/disk/ {printf "/dev/%s\n", $1}'); do | |
# echo "${disk}" | grep -q "$first_disk" && continue | |
# sfdisk --dump "$first_disk" | sfdisk "${disk}" | |
# done | |
# touch "/root/partitioned.txt" | |
#fi | |
# | |
# create a boot partition that has stage1 GRUB support | |
if [ ! -f "/root/boot-partition-created.txt" ]; then | |
sleep 3 | |
for disk in $(lsblk | awk '$1~/^[hs]d[a-z]/ && $NF~/disk/ {printf "/dev/%s\n", $1}'); do | |
mkfs.ext2 -m 0 -L "/boot/grub" "${disk}1" | |
done | |
touch "/root/boot-partition-created.txt" | |
fi | |
# create root pool | |
if ! zpool list | grep -qF 'rpool'; then | |
zpool create -f -o ashift=9 rpool mirror \ | |
$(ls -l /dev/disk/by-id/ | awk '$NF~/[hs]d[a-z]/ && $9~/ata.*-part2$/ {printf "/dev/disk/by-id/%s ", $9} END {printf "\n"}') | |
zfs create "rpool/ROOT" | |
zfs create "rpool/ROOT/ubuntu-1" | |
fi | |
# Dismount all ZFS filesystems | |
if [ ! -f "/root/mounted.txt" ]; then | |
zfs umount -a | |
touch "/root/mounted.txt" | |
fi | |
# Set the mountpoint property on the root filesystem | |
if ! zfs list | grep -E '^rpool/ROOT/ubuntu-1' | grep -qE '/$'; then | |
zfs set mountpoint=/ rpool/ROOT/ubuntu-1 | |
fi | |
# Set the bootfs property on the root pool | |
if ! zpool get all | grep -F 'bootfs' | grep -qF 'rpool/ROOT/ubuntu-1'; then | |
zpool set bootfs=rpool/ROOT/ubuntu-1 rpool | |
fi | |
# export and import | |
if [ ! -f "/root/export-and-import.txt" ]; then | |
zpool export rpool | |
zpool import -d "/dev/disk/by-id" -R "/mnt" \ | |
"$(zpool import | grep -A2 'pool: rpool' | grep -B1 'ONLINE' | awk '$1~/id/ {print $NF}')" | |
touch "/root/export-and-import.txt" | |
fi | |
# Mount the small boot filesystem for GRUB | |
[ -d "/mnt/boot/grub" ] || mkdir -p "/mnt/boot/grub" | |
if ! mount | grep -qF '/mnt/boot/grub'; then | |
mount "$(ls -l /dev/disk/by-id | grep -m1 -F 'sda1' | awk '{printf "/dev/disk/by-id/%s\n", $9}')" "/mnt/boot/grub" | |
fi | |
# Install the minimal system | |
if [ ! -d "/mnt/home" ]; then | |
debootstrap trusty /mnt | |
fi | |
# Copy these files from the LiveCD environment to the new system | |
if [ "$(md5sum "/etc/hostname" | awk '{print $1}')" != "$(md5sum "/mnt/etc/hostname" | awk '{print $1}')" ]; then | |
cp /etc/hostname /mnt/etc/ | |
fi | |
if [ "$(md5sum "/etc/hosts" | awk '{print $1}')" != "$(md5sum "/mnt/etc/hosts" | awk '{print $1}')" ]; then | |
cp /etc/hosts /mnt/etc/ | |
fi | |
# fstab | |
if ! grep -qF '/dev/disk/by-id' "/mnt/etc/fstab"; then | |
printf "$(ls -l /dev/disk/by-id | grep -m1 -F 'sda1' | awk '{printf "/dev/disk/by-id/%s\n", $9}') \ | |
/boot/grub auto defaults 0 1\n" >> "/mnt/etc/fstab" | |
fi | |
# interfaces | |
if ! grep -qF 'iface eth0 inet dhcp' "/mnt/etc/network/interfaces"; then | |
cat <<'EOT' >> "/mnt/etc/network/interfaces" | |
# interfaces(5) file used by ifup(8) and ifdown(8) | |
auto lo | |
iface lo inet loopback | |
auto eth0 | |
iface eth0 inet dhcp | |
EOT | |
fi | |
## Make virtual filesystem in the LiveCD environment visible to the new system and chroot into it | |
#mount --bind /dev /mnt/dev | |
#mount --bind /proc /mnt/proc | |
#mount --bind /sys /mnt/sys | |
#chroot /mnt /bin/bash --login | |
## Install PPA support in the chroot environment | |
#locale-gen en_US.UTF-8 | |
#apt-get update --yes | |
#apt-get install --yes ubuntu-minimal software-properties-common | |
# | |
## Install ZFS in the chroot environment for the new system | |
#if [ ! -f "/etc/apt/sources.list.d/zfs-native-stable-trusty.list.save" ]; then | |
# apt-add-repository --yes ppa:zfs-native/stable | |
#fi | |
#if [ ! -f "/etc/apt/sources.list.d/zfs-native-grub-trusty.list" ]; then | |
# apt-add-repository --yes ppa:zfs-native/grub | |
#fi | |
#apt-get update --yes || true | |
#apt-get install --yes --no-install-recommends linux-image-generic linux-headers-generic | |
#apt-get install --yes ubuntu-zfs | |
#apt-get install --yes grub2-common grub-pc | |
#apt-get install --yes zfs-initramfs | |
#apt-get dist-upgrade --yes | |
## passwd root | |
} | tee "/root/install.log" 2>&1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
damepo