aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSilvio Rhatto <rhatto@riseup.net>2012-04-10 12:56:19 -0300
committerSilvio Rhatto <rhatto@riseup.net>2012-04-10 12:56:19 -0300
commit3577626b1014036e0df1786b616ddd53c6225081 (patch)
treea1f61e3921072ec9c6583f9dbc64ce7067a4a60e
parentbd1f77aff5de50c8b2993d30aa9412700d9a4f5c (diff)
downloadhydra-3577626b1014036e0df1786b616ddd53c6225081.tar.gz
hydra-3577626b1014036e0df1786b616ddd53c6225081.tar.bz2
Provision: using parted for automatic partitioning; option to not use a swap device
-rwxr-xr-xshare/hydractl/provision78
1 files changed, 46 insertions, 32 deletions
diff --git a/share/hydractl/provision b/share/hydractl/provision
index f12bb5a..26abd8e 100755
--- a/share/hydractl/provision
+++ b/share/hydractl/provision
@@ -22,7 +22,7 @@ hydra_config_load
# Setup.
hydra_user_input device /dev/sdb "Destination device"
-hydra_user_input swap_device /dev/sda1 "Final swap device"
+hydra_user_input swap y "Use swap? (y/n)"
hydra_user_input encrypt y "Encrypt system and storage volumes? (y/n)"
hydra_user_input garbage y "Pre-fill volumes with garbage? (y/n)"
hydra_user_input hostname $HOSTNAME "Hostname"
@@ -34,43 +34,51 @@ hydra_user_input grub n "Setup GRUB? (y/n)"
hydra_user_input mirror http://cdn.debian.net/debian/ "Debian mirror"
# Check for requirements.
-for req in debootstrap cryptsetup grub-pc lvm2; do
+for req in debootstrap cryptsetup grub-pc lvm2 parted; do
hydra_install_package $req
done
# Warning.
cat <<-EOF
-Make sure you have chosen the right parameters and that $device has the needed partitions:
-
- # fdisk -l $device
- Disk /dev/sdb: 1000.2 GB, 1000204886016 bytes
- 255 heads, 63 sectors/track, 121601 cylinders
- Units = cilindros of 16065 * 512 = 8225280 bytes
- Disk identifier: 0x00000000
-
- Dispositivo Boot Start End Blocks Id System
- ${device}1 1 249 2000061 82 Linux swap
- ${device}2 * 250 273 192780 83 Linux
- ${device}3 274 121601 974567160 8e Linux LVM
-
-The number of blocks are figurative: the important thing is to have the
-partition layout listed above.
-
+WARNING: about to partition $device!
Press ENTER to continue, Ctrl-C to abort."
EOF
read answer
+# Disk partitioning.
+if [ "$swap" == "y" ]; then
+ parted -s -- $device unit MB mkpart primary linux-swap 0 2000
+ parted -s -- $device unit MB mkpart primary ext2 2000 2200
+ parted -s -- $device unit MB mkpart primary ext2 2200 -1
+ parted -s -- set 2 boot on
+ parted -s -- set 3 lvm on
+
+ # Change devices to absolute path names.
+ swap_device="$device"1
+ boot_device="$device"2
+ syst_device="$device"3
+else
+ parted -s -- $device unit MB mkpart primary ext2 0 200
+ parted -s -- $device unit MB mkpart primary ext2 200 -1
+ parted -s -- set 1 boot on
+ parted -s -- set 2 lvm on
+
+ # Change devices to absolute path names.
+ boot_device="$device"1
+ syst_device="$device"2
+fi
+
# Create volumes.
echo "Creating the needed disk volumes..."
-if ! pvdisplay "$device"3 &> /dev/null; then
+if ! pvdisplay $syst_device &> /dev/null; then
echo "Creating physical volume..."
- pvcreate "$device"3
+ pvcreate $syst_device
fi
if ! vgdisplay $vg &> /dev/null; then
echo "Creating volume group..."
- vgcreate $vg "$device"3
+ vgcreate $vg $syst_device
fi
if ! lvdisplay $vg/root &> /dev/null; then
@@ -84,7 +92,9 @@ vgchange -a y $vg
if [ "$garbage" == "y" ]; then
echo "Filling volumes with garbage..."
dd if=/dev/urandom of=/dev/$vg/root
- dd if=/dev/urandom of="$device"1
+ if [ "$swap" == "y" ]; then
+ dd if=/dev/urandom of=$swap_device
+ fi
fi
# Setup mountpoint and make sure it's not mounted due to a failed install.
@@ -138,14 +148,17 @@ chroot /tmp/debootstrap/ apt-get install locales cryptsetup lvm2 initramfs-tools
# Crypttab.
echo "Configuring crypttab..."
+echo "" > /tmp/debootstrap/etc/crypttab
+
if [ "$encrypt" == "y" ]; then
cat > /tmp/debootstrap/etc/crypttab <<-EOF
# <target name> <source device> <key file> <options>
root /dev/mapper/vg-root none luks,cipher=aes-cbc-essiv:sha256
-cswap $swap_device /dev/random swap,cipher=aes-cbc-essiv:sha256
EOF
-else
- cat > /tmp/debootstrap/etc/crypttab <<-EOF
+fi
+
+if [ "$swap" == "y" ]; then
+ cat >> /tmp/debootstrap/etc/crypttab <<-EOF
# <target name> <source device> <key file> <options>
cswap $swap_device /dev/random swap,cipher=aes-cbc-essiv:sha256
EOF
@@ -153,24 +166,25 @@ fi
# Fstab.
echo "Configuring fstab..."
+echo "" > /tmp/debootstrap/etc/fstab
if [ "$encrypt" == "y" ]; then
cat > /tmp/debootstrap/etc/fstab <<-EOF
-/dev/mapper/cswap none swap sw 0 0
/dev/mapper/root / ext3 defaults,errors=remount-ro 0 1
EOF
-else
- cat > /tmp/debootstrap/etc/fstab <<-EOF
+fi
+
+if [ "$swap" == "y" ]; then
+ cat >> /tmp/debootstrap/etc/fstab <<-EOF
/dev/mapper/cswap none swap sw 0 0
-/dev/vg/root / ext3 defaults,errors=remount-ro 0 1
EOF
fi
# Grub.
if [ "$grub" == "y" ]; then
echo "Boot device setup..."
- mkfs.ext3 "$device"2
- mount "$device"2 /tmp/debootstrap/boot
- echo "$device""2 /boot ext3 defaults,errors=remount-ro 0 2" >> /tmp/debootstrap/etc/fstab
+ mkfs.ext3 $boot_device
+ mount $boot_device /tmp/debootstrap/boot
+ echo "$boot_device /boot ext3 defaults,errors=remount-ro 0 2" >> /tmp/debootstrap/etc/fstab
echo "Setting up GRUB..."
chroot /tmp/debootstrap/ apt-get install grub-pc -y