├── README.md ├── debian ├── finishing.cfg ├── apt.cfg ├── timezone.cfg ├── location.cfg ├── packages.cfg ├── accounts.cfg └── partitioning.cfg ├── LICENSE └── centos └── centos7.ks /README.md: -------------------------------------------------------------------------------- 1 | # Snippets 2 | 3 | This project provides snippets (for RedHat/CentOS and Debian) to create dynamic partitioning scheme. 4 | -------------------------------------------------------------------------------- /debian/finishing.cfg: -------------------------------------------------------------------------------- 1 | # Avoid that last message about the install being complete 2 | d-i finish-install/reboot_in_progress note 3 | 4 | -------------------------------------------------------------------------------- /debian/apt.cfg: -------------------------------------------------------------------------------- 1 | # Use contrib software? 2 | d-i apt-setup/contrib boolean true 3 | 4 | # Use non-free software? 5 | d-i apt-setup/non-free boolean true 6 | 7 | -------------------------------------------------------------------------------- /debian/timezone.cfg: -------------------------------------------------------------------------------- 1 | # You may set this to any valid setting for $TZ; see the contents of 2 | # /usr/share/zoneinfo/ for valid values. 3 | d-i time/zone string America/Sao_Paulo 4 | 5 | -------------------------------------------------------------------------------- /debian/location.cfg: -------------------------------------------------------------------------------- 1 | # Preseeding only locale sets language, country and locale 2 | d-i debian-installer/locale string en_US 3 | 4 | # keymap is an alias for keyboard-configuration/xkb-keymap 5 | d-i keyboard-configuration/xkb-keymap select us 6 | 7 | -------------------------------------------------------------------------------- /debian/packages.cfg: -------------------------------------------------------------------------------- 1 | # Individual additional packages to install 2 | d-i pkgsel/include string openssh-server vim wget ftp 3 | 4 | # Whether to upgrade packages after debootstrap. 5 | # Allowed values: none, safe-upgrade, full-upgrade 6 | d-i pkgsel/upgrade select safe-upgrade 7 | 8 | -------------------------------------------------------------------------------- /debian/accounts.cfg: -------------------------------------------------------------------------------- 1 | # Create a normal user account now? 2 | d-i passwd/make-user boolean false 3 | 4 | # Root password in clear text 5 | d-i passwd/root-password password 123change 6 | d-i passwd/root-password-again password 123change 7 | 8 | # Root password or encrypted using an MD5 hash 9 | #d-i passwd/root-password-crypted password $1$7ojVZiSU$waRLGUidI0k/.z16SzHDn1 10 | 11 | # The following command can be used to generate an MD5 12 | # hash for a password: 13 | # 14 | # printf "123change" | mkpasswd -s -m md5 15 | # 16 | 17 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Claudio Borges da Silva Filho 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is furnished 10 | to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /centos/centos7.ks: -------------------------------------------------------------------------------- 1 | #version=RHEL7 2 | # Install OS instead of upgrade 3 | install 4 | 5 | # Reboot after installation 6 | reboot --eject 7 | 8 | # Use network installation 9 | url --url="http://mirror-centos.locaweb.com.br/7/os/x86_64/" 10 | 11 | # License agreement 12 | eula --agreed 13 | 14 | # Use graphical install 15 | #graphical 16 | 17 | # Use text mode install 18 | text 19 | 20 | # Do not configure the X Window System 21 | skipx 22 | 23 | # Run the Setup Agent on first boot 24 | firstboot --enable 25 | 26 | # Keyboard layouts 27 | keyboard --vckeymap=us --xlayouts='us' 28 | 29 | # System language 30 | lang en_US.UTF-8 31 | 32 | # Network information 33 | network --bootproto=dhcp --noipv6 --activate 34 | network --hostname=centos7.claudioborges.org 35 | 36 | # Root password 37 | rootpw --iscrypted $6$3jbQnNUNY/.1hlbg$ellrx8S7vY7NyXVy7z4PoqA15gGagIY6UdxvxDU26T2cMa0NqOIgISpP9Gby0Exr5qd6WrLYpQQ2FJXzHG7Kj. 38 | 39 | # System services 40 | services --enabled="NetworkManager,sshd,chronyd" 41 | 42 | # System timezone 43 | timezone America/Sao_Paulo --isUtc --ntpservers=3.centos.pool.ntp.org,0.centos.pool.ntp.org,2.centos.pool.ntp.org,1.centos.pool.ntp.org 44 | 45 | # Clear the Master Boot Record 46 | zerombr 47 | 48 | # Include partition scheme 49 | %include /tmp/partitioning.txt 50 | 51 | %pre 52 | !/bin/bash 53 | # Use RAID+LVM or just LVM to partition the disk 54 | 55 | # Partitioning scheme: 56 | # 57 | # /dev/md0 - 512Mb - /boot xfs 58 | # /dev/md1 - raid device + LVM VolGroup00 (if you have 2 or more disks) 59 | # /dev/mapper/VolGroup00/lv_swap - the swap is calculated over the amount 60 | # of RAM in the system, ex: 61 | # if RAM < 2GB then SWAP = 2x physical RAM 62 | # if RAM > 2GB or MEM < 8GB then SWAP = Equal to the amount of RAM 63 | # if RAM > 8GB then SWAP = At least 4 GB 64 | # /dev/mapper/VolGroup00/lv_root - 3Gb - / xfs 65 | # /dev/mapper/VolGroup00/lv_tmp - 512Mb - /tmp xfs 66 | # /dev/mapper/VolGroup00/lv_var - 1Gb - /var xfs 67 | 68 | # Get the disks 69 | COUNT=0 70 | for DISK in $(awk '{if ($NF ~ "^(s|h)d|cciss" && $NF !~ "((s|h)d|c.d.)[a-z][0-9]$") print $4}' /proc/partitions); do 71 | DEVS[${COUNT}]="${DISK}" 72 | DISKS[${COUNT}]="${DISK//\/dev\/}" 73 | let COUNT++ 74 | done 75 | 76 | # Define the RAID level 77 | if [ ${COUNT} -eq "1" ]; then 78 | LEVEL=-1 79 | elif [ ${COUNT} -eq "2" ]; then 80 | LEVEL=1 81 | elif [ ${COUNT} -eq "3" ]; then 82 | LEVEL=5 83 | elif [ ${COUNT} -ge "4" ]; then 84 | LEVEL=10 85 | fi 86 | 87 | # Calculate the SWAP size over the amount of RAM 88 | MEM=$(($(sed -n 's/^MemTotal: \+\([0-9]*\) kB/\1/p' /proc/meminfo) / 1024)) 89 | if [ "${MEM}" -lt "2048" ]; then 90 | SWAP=$((MEM * 2)) 91 | elif [ "${MEM}" -gt "2048" ] || [ "${MEM}" -le "8192" ]; then 92 | SWAP=${MEM} 93 | elif [ "${MEM}" -ge "8192" ]; then 94 | SWAP=4096 95 | fi 96 | 97 | # If the system has two disks (or more), it will create the RAID + LVM 98 | if [ ${LEVEL} -ge "1" ]; then 99 | x=${#DEVS[@]} 100 | DEVS=${DEVS[@]:0} 101 | DISKS=${DISKS[@]:0} 102 | echo "ignoredisk --only-use=${DISKS// /,}" > /tmp/partitioning.txt 103 | echo "clearpart --all --initlabel --drives=${DISKS// /,}" >> /tmp/partitioning.txt 104 | for ((i=0; i < ${#DEVS[@]}; i++)); do 105 | echo "part raid.0${i} --fstype=\"mdmember\" --size=512 --ondisk=${DISK[$i]}" >> /tmp/partitioning.txt 106 | echo "part raid.0${x} --fstype=\"mdmember\" --grow --ondisk=${DISK[$i]}" >> /tmp/partitioning.txt 107 | RAIDPARTS1[$i]="raid.0${i}" 108 | RAIDPARTS2[$x]="raid.0${x}" 109 | let x++ 110 | done 111 | echo "raid /boot --device=0 --fstype=\"xfs\" --level=raid${LEVEL} ${RAIDPARTS1[@]:0}" >> /tmp/partitioning.txt 112 | echo "raid pv.00 --device=1 --fstype=\"lvmpv\" --level=raid${LEVEL} ${RAIDPARTS2[@]:0}" >> /tmp/partitioning.txt 113 | # Otherwise, it will use just LVM 114 | else 115 | echo "part /boot --fstype=\"xfs\" --size=512" >> /tmp/partitioning.txt 116 | echo "part pv.00 --fstype=\"lvmpv\" --ondisk=${DISK[@]:0}" >> /tmp/partitioning.txt 117 | fi 118 | 119 | # Define the volume group and logical volumes 120 | cat >> /tmp/partitioning.txt < 2GB or MEM < 8GB then SWAP = Equal to the amount of RAM 10 | # if RAM > 8GB then SWAP = At least 4 GB 11 | # /dev/mapper/VolGroup00/lv_root - 512Mb to 15Gb - / ext4 12 | # /dev/mapper/VolGroup00/lv_tmp - 256Mb to 4Gb - /tmp ext4 13 | # /dev/mapper/VolGroup00/lv_var - 512Mb to 15Gb - /var ext4 14 | # /dev/mapper/VolGroup00/lv_delete - all remaining space. This logical 15 | # volume was created because the Debian installer has a bug. It allocates 16 | # all remaining space to the last logical volume. The late_command will 17 | # execute a lvremove VolGroup00/lv_delete and give back this space to the 18 | # volume group. 19 | 20 | # The options used in the partitioning can be found in the following url: 21 | # https://wikitech.wikimedia.org/wiki/PartMan 22 | 23 | # These commands will run immediately before the partitioner starts. 24 | d-i partman/early_command string \ 25 | COUNT=0; \ 26 | SPARE=0; \ 27 | for DISK in $(list-devices disk); do \ 28 | DISKS="${DISKS} ${DISK}"; \ 29 | if [ "$(echo ${DISK} | cut -d'/' -f3)" = "cciss" ]; then \ 30 | DEVS="${DEVS}${DISK}p1#"; \ 31 | SPARE_DEV="${DISK}p1"; \ 32 | else \ 33 | DEVS="${DEVS}${DISK}1#"; \ 34 | SPARE_DEV="${DISK}1"; \ 35 | fi; \ 36 | COUNT=$((COUNT + 1)); \ 37 | done; \ 38 | DISKS=$(echo ${DISKS} | sed "s/^ //g"); \ 39 | DEVS=$(echo ${DEVS} | sed "s/#$//g"); \ 40 | if [ "${COUNT}" -eq "1" ]; then \ 41 | RAID="-1"; \ 42 | elif [ "${COUNT}" -eq "2" ]; then \ 43 | RAID="1"; \ 44 | elif [ "${COUNT}" -eq "3" ]; then \ 45 | RAID="5"; \ 46 | elif [ "${COUNT}" -ge "4" ]; then \ 47 | RAID="10"; \ 48 | SPARE=$((COUNT % 2));\ 49 | fi; \ 50 | if [ ${SPARE} -eq "1" ]; then \ 51 | COUNT=$((COUNT - 1)); \ 52 | DEVS=$(echo ${DEVS} | sed -e "s|${SPARE_DEV}||g;s/#$//g"); \ 53 | else \ 54 | SPARE_DEV=""; \ 55 | fi; \ 56 | MEM=$(($(sed -n 's/^MemTotal: \+\([0-9]*\) kB/\1/p' /proc/meminfo) / 1024)); \ 57 | if [ "${MEM}" -lt "2048" ]; then \ 58 | SWAP=$((MEM * 2)); \ 59 | elif [ "${MEM}" -gt "2048" ] || [ "${MEM}" -le "8192" ]; then \ 60 | SWAP=${MEM}; \ 61 | elif [ "${MEM}" -ge "8192" ]; then \ 62 | SWAP=4096; \ 63 | fi; \ 64 | debconf-set partman-auto/disk "$DISKS"; \ 65 | if [ "${RAID}" -ge "1" ]; then \ 66 | debconf-set partman-auto/method "raid"; \ 67 | debconf-set partman-auto-raid/recipe "${RAID} ${COUNT} ${SPARE} lvm - ${DEVS} ${SPARE_DEV} ."; \ 68 | debconf-set partman-auto/expert_recipe "multiraid :: \ 69 | 0 0 0 raid \ 70 | \$lvmignore{ } \ 71 | \$primary { } \ 72 | method{ raid } . \ 73 | 256 256 ${SWAP} linux-swap \ 74 | \$defaultignore{ } \ 75 | \$lvmok{ } \ 76 | lv_name{ lv_swap } \ 77 | method{ swap } \ 78 | format{ } . \ 79 | 512 40960 15360 ext4 \ 80 | \$defaultignore{ } \ 81 | \$lvmok{ } \ 82 | lv_name{ lv_root } \ 83 | method{ format } \ 84 | format{ } \ 85 | use_filesystem{ } \ 86 | filesystem{ ext4 } \ 87 | mountpoint{ / } . \ 88 | 256 5120 4096 ext4 \ 89 | \$defaultignore{ } \ 90 | \$lvmok{ } \ 91 | lv_name{ lv_tmp } \ 92 | method{ format } \ 93 | format{ } \ 94 | use_filesystem{ } \ 95 | filesystem{ ext4 } \ 96 | mountpoint{ /tmp } . \ 97 | 512 40960 15360 ext4 \ 98 | \$defaultignore{ } \ 99 | \$lvmok{ } \ 100 | lv_name{ lv_var } \ 101 | method{ format } \ 102 | format{ } \ 103 | use_filesystem{ } \ 104 | filesystem{ ext4 } \ 105 | mountpoint{ /var } . \ 106 | 1024 1024 1024 ext4 \ 107 | \$defaultignore{ } \ 108 | \$lvmok{ } \ 109 | lv_name{ lv_delete } ."; \ 110 | else \ 111 | debconf-set partman-auto/method "lvm"; \ 112 | debconf-set partman-auto/expert_recipe "root :: \ 113 | 256 256 ${SWAP} linux-swap \ 114 | \$defaultignore{ } \ 115 | \$lvmok{ } \ 116 | lv_name{ lv_swap } \ 117 | method{ swap } \ 118 | format{ } . \ 119 | 512 40960 15360 ext4 \ 120 | \$defaultignore{ } \ 121 | \$lvmok{ } \ 122 | lv_name{ lv_root } \ 123 | method{ format } \ 124 | format{ } \ 125 | use_filesystem{ } \ 126 | filesystem{ ext4 } \ 127 | mountpoint{ / } . \ 128 | 256 5120 4096 ext4 \ 129 | \$defaultignore{ } \ 130 | \$lvmok{ } \ 131 | lv_name{ lv_tmp } \ 132 | method{ format } \ 133 | format{ } \ 134 | use_filesystem{ } \ 135 | filesystem{ ext4 } \ 136 | mountpoint{ /tmp } . \ 137 | 512 40960 15360 ext4 \ 138 | \$defaultignore{ } \ 139 | \$lvmok{ } \ 140 | lv_name{ lv_var } \ 141 | method{ format } \ 142 | format{ } \ 143 | use_filesystem{ } \ 144 | filesystem{ ext4 } \ 145 | mountpoint{ /var } . \ 146 | 1024 1024 1024 ext4 \ 147 | \$defaultignore{ } \ 148 | \$lvmok{ } \ 149 | lv_name{ lv_delete } ."; \ 150 | fi 151 | 152 | # Install grub in the first device (assuming it is not a USB stick) 153 | d-i grub-installer/bootdev string default 154 | 155 | # Continue installation without /boot partition? 156 | d-i partman-auto-lvm/no_boot boolean true 157 | 158 | # Name of the volume group for the new system 159 | d-i partman-auto-lvm/new_vg_name string VolGroup00 160 | 161 | # Remove existing software RAID partitions? 162 | d-i partman-md/device_remove_md boolean true 163 | 164 | # Remove existing logical volume data? 165 | d-i partman-lvm/device_remove_lvm boolean true 166 | 167 | # Unable to automatically remove LVM data 168 | d-i partman-lvm/device_remove_lvm_span boolean true 169 | 170 | # Dummy template for preseeding unavailable questions 171 | d-i partman-auto/purge_lvm_from_device boolean true 172 | 173 | # Write the changes to the storage devices and configure RAID? 174 | d-i partman-md/confirm boolean true 175 | d-i partman-md/confirm_nooverwrite boolean true 176 | 177 | # Write the changes to disks and configure LVM? 178 | d-i partman-lvm/confirm boolean true 179 | d-i partman-lvm/confirm_nooverwrite boolean true 180 | 181 | # Write the changes to disks? 182 | d-i partman/confirm boolean true 183 | d-i partman/confirm_nooverwrite boolean true 184 | 185 | # Finish partitioning and write changes to disk 186 | d-i partman/choose_partition select finish 187 | 188 | # This command is run just before the install finishes, and it will remove the lv_delete 189 | d-i preseed/late_command string lvremove -f /dev/VolGroup00/lv_delete > /dev/null 2>&1 190 | 191 | --------------------------------------------------------------------------------