NoPaste

01-start.sh

von ren22
Beschreibung:
debootstrap start script
Snippet erstellt:
16.02.2019 14:15:43
Snippet wird automatisch gelöscht:
Niemals

Dein Code:
  1. #!/bin/bash
  2.  
  3. # set here the device for partitioning and bootstrapping
  4. DEVICE="/dev/sdc"
  5. # which arch
  6. ARCH="amd64"
  7. #which directory to use for debootstrap
  8. MOUNTPOINT="/mnt/debinst"
  9.  
  10.  
  11. # umount partitions on $DEVICE if mounted
  12. for i in $(mount | grep $DEVICE | awk '{print $1}'); do
  13.     sudo umount -l $i
  14. done
  15.  
  16. if grep -qs "$MOUNTPOINT/dev/pts" /proc/mounts; then
  17.     umount -l "$MOUNTPOINT/dev/pts"
  18. fi
  19. if grep -qs "$MOUNTPOINT/dev" /proc/mounts; then
  20.     umount -l "$MOUNTPOINT/dev"
  21. fi
  22. if grep -qs "$MOUNTPOINT/proc" /proc/mounts; then
  23.     umount -l "$MOUNTPOINT/proc"
  24. fi
  25. if grep -qs "$MOUNTPOINT/sys" /proc/mounts; then
  26.     umount -l "$MOUNTPOINT/sys"
  27. fi
  28.  
  29. # trap error EXIT function
  30. err_report(){
  31.     echo "Error Aborting. line: $1"
  32.  
  33.     # umount partitions on $DEVICE if mounted
  34.    for i in $(mount | grep $DEVICE | awk '{print $1}'); do
  35.         sudo umount -l "$i"
  36.     done
  37.     if grep -qs "$MOUNTPOINT/dev/pts" /proc/mounts; then
  38.         umount -l "$MOUNTPOINT/dev/pts"
  39.     fi
  40.     if grep -qs "$MOUNTPOINT/dev" /proc/mounts; then
  41.         umount -l "$MOUNTPOINT/dev"
  42.     fi
  43.     if grep -qs "$MOUNTPOINT/proc" /proc/mounts; then
  44.         umount -l "$MOUNTPOINT/proc"
  45.     fi
  46.     if grep -qs "$MOUNTPOINT/sys" /proc/mounts; then
  47.         umount -l "$MOUNTPOINT/sys"
  48.     fi
  49.  
  50.     sudo swapoff "${DEVICE}10"
  51.  
  52.     # delete old stuff
  53.    if [ -d $MOUNTPOINT ]; then
  54.         sudo rm -rf $MOUNTPOINT
  55.     fi
  56.  
  57.     # syncing
  58.    sudo sync
  59.  
  60.     # exit now
  61.    exit 1
  62. }
  63. trap 'err_report $LINENO' ERR
  64.  
  65.  
  66. # delete device
  67. echo "Cleaning Partition Signatur..."
  68. for i in $(sudo fdisk -l | grep $DEVICE | sed -e "s/\$DEVICE\(.*\)/\1/" | cut -d' ' -f1 | tail -n +2); do #"
  69.    sudo wipefs --all --force "$i" > /dev/null
  70. done
  71.  
  72. sudo sync
  73. echo "Creating Partitions..."
  74. # create partitions
  75. #2GB    /
  76. #3GB    /boot
  77. #4GB    /home
  78. #5GB    /usr
  79. #6GB    /var
  80. #7GB    /tmp
  81. #8GB    swap
  82. sudo fdisk $DEVICE <<EOF > /dev/null
  83. o
  84. n
  85. p
  86. 1
  87.  
  88. +2G
  89. n
  90. e
  91. 2
  92.  
  93.  
  94. n
  95.  
  96. +3G
  97. n
  98.  
  99. +4G
  100. n
  101.  
  102. +5G
  103. n
  104.  
  105. +6G
  106. n
  107.  
  108. +7G
  109. n
  110.  
  111. +8G
  112. a
  113. 1
  114. t
  115. 10
  116. 82
  117. w
  118. EOF
  119. sudo sync
  120.  
  121. # create filesystem ext3 on partitions
  122. echo "Creating filesystem on partitions..."
  123. for i in {1,5,6,7,8,9}; do
  124.     sudo mke2fs -q -j "${DEVICE}$i"
  125.     wait
  126.     sudo sync
  127. done
  128.  
  129. # create swapfs
  130. sudo mkswap "${DEVICE}10" > /dev/null
  131. sync
  132. sudo swapon "${DEVICE}10"
  133. sudo sync
  134. set -x
  135. # create mountdir
  136. if [ ! -d $MOUNTPOINT ]; then
  137.     sudo mkdir -p $MOUNTPOINT || (echo "error while creating $MOUNTPOINT" && exit 1)
  138.     sudo sync
  139. fi
  140.  
  141. # mount partitions
  142. # mount /
  143. sudo mount "${DEVICE}1" "$MOUNTPOINT/"
  144. sudo sync
  145.  
  146. # create additional directorys
  147. sudo mkdir -p $MOUNTPOINT/{boot,home,usr,var,tmp}
  148.  
  149. # mount additional directorys
  150. sudo mount "${DEVICE}5" "$MOUNTPOINT/boot"
  151. sudo sync
  152. sudo mount "${DEVICE}6" "$MOUNTPOINT/home"
  153. sudo sync
  154. sudo mount "${DEVICE}7" "$MOUNTPOINT/usr"
  155. sudo sync
  156. sudo mount "${DEVICE}8" "$MOUNTPOINT/var"
  157. sudo sync
  158. sudo mount "${DEVICE}9" "$MOUNTPOINT/tmp"
  159. sudo sync
  160.  
  161. # install base system
  162. echo "Doing debootstrap..."
  163. sudo /usr/sbin/debootstrap --arch $ARCH --variant=minbase stretch "$MOUNTPOINT" http://ftp.de.debian.org/debian
  164. sudo sync
  165.  
  166. # mount sysfs proc dev pts
  167. sudo mount -t sysfs sysfs "$MOUNTPOINT/sys"
  168. sudo sync
  169. sudo mount -t proc proc "$MOUNTPOINT/proc"
  170. sudo sync
  171. sudo mount -o bind /dev "$MOUNTPOINT/dev"
  172. sudo sync
  173. sudo mount -o bind /dev/pts "$MOUNTPOINT/dev/pts"
  174. sudo sync
  175.  
  176. # set nameserver
  177. sudo echo "nameserver 192.168.123.254" > "$MOUNTPOINT/etc/resolv.conf"
  178.  
  179. # set hostname
  180. sudo echo "deboot" > "$MOUNTPOINT/etc/hostname"
  181.  
  182. # create fstab
  183. sudo bash -c "cat > "$MOUNTPOINT/etc/fstab" << EOF
  184. #file system    mount point     type    options         dump pass
  185. UUID=$(sudo blkid -s UUID -o value "${DEVICE}1") /       ext3    defaults               0 1
  186. UUID=$(sudo blkid -s UUID -o value "${DEVICE}5") /boot   ext3    ro,nosuid,nodev        0 2
  187. UUID=$(sudo blkid -s UUID -o value "${DEVICE}6") /home   ext3    rw,nosuid,nodev        0 2
  188. UUID=$(sudo blkid -s UUID -o value "${DEVICE}7") /usr    ext3    rw,nodev               0 2
  189. UUID=$(sudo blkid -s UUID -o value "${DEVICE}8") /var    ext3    rw,nosuid,nodev        0 2
  190. UUID=$(sudo blkid -s UUID -o value "${DEVICE}9") /tmp    ext3    rw,nosuid,nodev        0 2
  191. UUID=$(sudo blkid -s UUID -o value "${DEVICE}10") none   swap    sw                     0 0
  192. proc                                        /proc   proc    defaults            0 0
  193. EOF"
  194. cat "$MOUNTPOINT/etc/fstab"
  195.  
  196. # copy chroot script
  197. sudo cp -f chroot.sh "$MOUNTPOINT/root/chroot.sh"
  198. chmod +x "$MOUNTPOINT/root/chroot.sh"
  199.  
  200. #abc
  201. # run chroot script
  202. sudo LANG=C.UTF-8 chroot "$MOUNTPOINT" /root/chroot.sh
  203.  
  204. # replace UUID in grub.cfg for correct boot root
  205. #WrongUUID=$(cat /etc/fstab | grep UUID | grep -w "/" | awk '{print $1}' | cut -d"=" -f2)
  206. #RootUUID=$(cat $MOUNTPOINT/etc/fstab | grep -w "/" | awk '{print $1}' | cut -d"=" -f2)
  207. #sed -i "s/$WrongUUID/$RootUUID/g" "$MOUNTPOINT/boot/grub/grub.cfg"
  208.  
  209. grub-install --root-directory=$MOUNTPOINT --no-floppy --recheck $DEVICE
  210.  
  211.  
  212. echo "done."
  213.  
  214. # umount all
  215. for i in $(mount | grep "$DEVICE" | awk '{print $1}'); do
  216.     sudo umount -l "$i"
  217. done
  218.  
  219. if grep -qs "$MOUNTPOINT/dev/pts" /proc/mounts; then
  220.     umount -l "$MOUNTPOINT/dev/pts"
  221. fi
  222. if grep -qs "$MOUNTPOINT/dev" /proc/mounts; then
  223.     umount -l "$MOUNTPOINT/dev"
  224. fi
  225. if grep -qs "$MOUNTPOINT/proc" /proc/mounts; then
  226.     umount -l "$MOUNTPOINT/proc"
  227. fi
  228. if grep -qs "$MOUNTPOINT/sys" /proc/mounts; then
  229.     umount -l "$MOUNTPOINT/sys"
  230. fi
  231.  
  232. echo "debootstrapping done. Have PhuN :-)"

Quellcode

Hier kannst du den Code kopieren und ihn in deinen bevorzugten Editor einfügen. Alternativ kannst du den gesamten Eintrag auch als Datei herunterladen.