Guest User

Untitled

a guest
Feb 19th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.93 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. SCRIPT="2part.sh"
  4.  
  5. case "$1" in
  6.     installer)
  7.         # Substitute partman with this script
  8.         sed -i "s|partman|/tmp/$SCRIPT partman|" /var/lib/dpkg/info/partman-base.postinst
  9.         logger "Modified partman-base.postinst. Partitioning will be handled by /tmp/$SCRIPT instead of partman."
  10.     ;;
  11.  
  12.     partman)
  13.         logger "$SCRIPT partition configuration progress started"
  14.  
  15.         # Ensure that the device mapper module is loaded
  16.         modprobe dm_mod
  17.  
  18.         # Wipe the MBR and initialise a new partition table
  19.         dd if=/dev/zero of=/dev/sda bs=512 count=1
  20.         parted -s /dev/sda -- mklabel msdos
  21.  
  22.         # Create a 2G partition for the root filesystem. Use the rest for LVM.
  23.         parted -s /dev/sda -- mkpart primary 2048s 4196351s
  24.         parted -s /dev/sda -- mkpart primary 4196352s -1s
  25.         parted -s /dev/sda -- toggle 2 lvm
  26.  
  27.         # Create a single physical volume then create a volume group with it
  28.         pvcreate -ff -y /dev/sda2
  29.         vgcreate vg0 /dev/sda2
  30.  
  31.         # Allocate 10G for /usr
  32.         lvcreate -L10G -nusr vg0
  33.  
  34.         # Allocate as much space as possible for /var but leave 100G free. It
  35.         # gives us room to maneuver and also allows for snapshotting.
  36.         LVM2_VG_FREE=`vgs --noheadings --units m -o vg_free vg0 | cut -d. -f1`
  37.         VAR_SIZE=`expr $VG_FREE - 1000000`
  38.         lvcreate -nvar -L${VAR_SIZE}M vg0
  39.  
  40.         # Create and mount the root filesystem
  41.         mkfs.ext4 -q -FF /dev/sda1
  42.         mkdir /target
  43.         mount /dev/sda1 /target
  44.  
  45.         # Create and mount the other filesystems
  46.         for fs in usr var; do
  47.             mkfs.xfs -q -f /dev/vg0/$fs
  48.             mkdir -p /target/$fs
  49.             mount /dev/vg0/$fs /target/$fs
  50.         done
  51.  
  52.         # Create fstab ... TODO
  53.  
  54.     ;;
  55.  
  56.     *)
  57.         echo "$0: This script is destructive and should only be run as part of the debian-installer process!"
  58.     ;;
  59. esac
Add Comment
Please, Sign In to add comment