zfsinstall.sh 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. #!/bin/sh
  2. DESTDISK="ada0"
  3. DESTDIR="/mnt/zfs"
  4. ZPOOL="zroot"
  5. SCRIPTBASE=${PWD}
  6. # check if the zpool already exists
  7. ZPOOL_EXISTS=` zpool list -H | cut -f 1 | grep "${ZPOOL}"`
  8. if [ "${?}" -ne 1 ]; then
  9. echo "One zpool called ${ZPOOL} already exists, you have to destroy it first:"
  10. echo " # zpool destroy ${ZPOOL}"
  11. exit 1
  12. fi
  13. # check if the disk is ok for writing
  14. echo checking sanity ${DESTDISK}
  15. echo =============
  16. gpart show ${DESTDISK} 1>/dev/null
  17. if [ "${?}" -eq 0 ]; then
  18. gpart destroy -F ${DESTDISK}
  19. if [ "${?}" -ne 0 ]; then
  20. echo unable to reset ${DESTDISK}
  21. exit 1
  22. fi
  23. fi
  24. echo partitioning ${DESTDISK}
  25. echo =============
  26. gpart create -s gpt ${DESTDISK}
  27. gpart add -a 1m -t freebsd-boot -s 128k -l boot ${DESTDISK}
  28. gpart add -a 1m -s 32G -t freebsd-swap -l swap ${DESTDISK}
  29. gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 1 ${DESTDISK}
  30. gpart add -a 1m -t freebsd-zfs -l syszfs ${DESTDISK}
  31. gpart show ${DESTDISK} 1>/dev/null
  32. sysctl vfs.zfs.min_auto_ashift=12
  33. echo set up zfs pool: ${ZPOOL} alt mount: ${DESTDIR}
  34. echo =================
  35. zpool create -m none -f -R ${DESTDIR} ${ZPOOL} ${DESTDISK}p3
  36. if [ "${?}" -ne 0 ]; then
  37. echo "unable to create zpool"
  38. exit 1
  39. fi
  40. for I in ROOT VAR HOME; do
  41. zfs create -o mountpoint=none -o canmount=off ${ZPOOL}/${I}
  42. done
  43. zfs create -o atime=off -o mountpoint=/ ${ZPOOL}/ROOT/master
  44. zfs create -o mountpoint=/usr/obj ${ZPOOL}/ROOT/obj
  45. zfs create -o compression=off -o mountpoint=/usr/src ${ZPOOL}/ROOT/src
  46. # useless ? as far /tmp mountpoint will be mounted by tmpfs
  47. zfs create -o mountpoint=/tmp ${ZPOOL}/ROOT/tmp
  48. zfs create -o mountpoint=/usr/local ${ZPOOL}/LOCAL
  49. zfs create -o mountpoint=/usr/local/etc ${ZPOOL}/LOCAL/config
  50. zfs create -o copies=1 -o mountpoint=/usr/src -o compression=off ${ZPOOL}/src
  51. zfs create -o copies=1 -o mountpoint=/usr/doc -o compression=on ${ZPOOL}/doc
  52. zfs create -o copies=1 -o mountpoint=/usr/obj -o compression=on ${ZPOOL}/obj
  53. zfs create -o mountpoint=/var ${ZPOOL}/VAR/master
  54. zfs create -o mountpoint=/var/crash ${ZPOOL}/VAR/crash
  55. zfs create -o exec=off -o setuid=off -o mountpoint=/var/db ${ZPOOL}/VAR/db
  56. zfs create -o compression=lz4 -o exec=on -o setuid=off -o mountpoint=/var/db/pkg ${ZPOOL}/VAR/db/pkg
  57. zfs create -o compression=on -o exec=off -o setuid=off -o mountpoint=/var/mail ${ZPOOL}/VAR/mail
  58. zfs create -o compression=on -o exec=off -o setuid=off -o mountpoint=/var/log ${ZPOOL}/VAR/log
  59. zfs create -o exec=off -o setuid=off -o mountpoint=/var/run ${ZPOOL}/VAR/run
  60. zfs create -o exec=off -o setuid=off -o mountpoint=/var/tmp ${ZPOOL}/VAR/tmp
  61. zfs create -o mountpoint=/usr/home ${ZPOOL}/HOME/master
  62. chmod 1777 ${DESTDIR}/tmp ${DESTDIR}/var/tmp
  63. zfs list -r ${ZPOOL}
  64. cd ${DESTDIR}/tmp
  65. if [ "${?}" -ne 0 ]; then
  66. echo zfs mountpoints arent ready
  67. exit 1
  68. fi
  69. echo Fetching and Extracting base files into ${DESTDIR}
  70. echo =======================================
  71. for I in base.txz kernel.txz lib32.txz; do
  72. fetch http://ftp.freebsd.org/pub/FreeBSD/snapshots/amd64/12.0-ALPHA8/${I}
  73. tar --unlink -pJxf ${I} -C ${DESTDIR}
  74. done
  75. echo writing configuration files
  76. echo ==========================
  77. cat << EOF >> ${DESTDIR}/etc/fstab
  78. /dev/${DESTDISK}p2 none swap sw 0 0
  79. tmpfs /tmp tmpfs rw,mode=1777 0 0
  80. EOF
  81. cat << EOF >> ${DESTDIR}/boot/loader.conf
  82. zfs_load=YES
  83. tmpfs_load=YES
  84. EOF
  85. cat << EOF >> ${DESTDIR}/boot/loader.conf.local
  86. vfs.root.mountfrom="zfs:${ZPOOL}/ROOT/master"
  87. EOF
  88. cat << EOF >> ${DESTDIR}/etc/rc.conf
  89. sshd_enable="YES"
  90. sendmail_enable="NONE"
  91. kld_list="vmm cuse4bsd cpuctl filemon"
  92. ntpd_enable="YES"
  93. # Set dumpdev to "AUTO" to enable crash dumps, "NO" to disable
  94. dumpdev="AUTO"
  95. zfs_enable="YES"
  96. EOF
  97. cd ${SCRIPTBASE}
  98. for I in resolv.conf rc.conf.local; do
  99. if [ -r "${I}" ]; then
  100. echo installing ${I}
  101. install -o root -g wheel -m 0644 ${I} ${DESTDIR}/etc/
  102. fi
  103. done
  104. for I in loader.conf.local; do
  105. if [ -r "${I}" ]; then
  106. echo installing ${I}
  107. install -o root -g wheel -m 0644 ${I} ${DESTDIR}/boot/
  108. fi
  109. done
  110. echo installing rc.conf.d
  111. install -o root -g wheel -d -m 0755 ${DESTDIR}/etc/rc.conf.d
  112. if [ -d "./rc.conf.d" ]; then
  113. echo installing files into rc.conf.d
  114. install -o root -g wheel -m 0644 ./rc.conf.d/* ${DESTDIR}/etc/rc.conf.d/
  115. fi
  116. chroot ${DESTDIR} passwd
  117. chroot ${DESTDIR} adduser
  118. read -p "Do you wish to open a shell ?" yn
  119. case $yn in
  120. [Nn]* ) exit 0;;
  121. [Yy]* ) ;;
  122. * ) echo "Please answer yes or no.";;
  123. esac
  124. chroot ${DESTDIR} tcsh
  125. exit 0