├── 0HOWTO-install-these-scripts.txt ├── Demo_df-rootusage.yml ├── OSX ├── . .. ├── bkp-home-rclone-macmini-2qotom-proxmox-ztosh10.sh ├── dbi-commasep-osx.sh ├── disks-only-osx.sh ├── disks-osx.sh ├── drivemap-osx.sh ├── extended-attribs--osx.sh ├── findmedia-osx.sh ├── freshinstall-mac.sh ├── freshinstall-macports.sh ├── gig-ether--speedup--osx.sh ├── iscsi-osx-list-luns.sh ├── iscsi-osx-mapdrives.sh ├── jumboframes-osx.sh ├── macfanstemps.sh ├── macos-download-monterey-installer.sh ├── mk-high-sierra-1013-bootable-iso.sh ├── mk-monterey-install-media.sh ├── mk-sonoma14-install-media.sh ├── mkgpt-osx.sh ├── norecovhdmounts.sh ├── osx-delete-apfs-snapshots.sh ├── osx-extended-metadata-attributes-hfsplus.sh ├── osx-flush-dns-cache.sh ├── osx-get-disk-wwn.sh ├── osx-partitiondisk-500GB.sh ├── osx-partitiondisk.sh ├── osx-restart-sshd.sh ├── osx-unmount-time-machine-df.sh ├── osx-zfs-extended-attribs-demo.sh ├── tmpdel-cleanup.sh ├── webp2png-photos.sh ├── zfs-fix-shares-osx.sh ├── zfs-osx-diskinfo.sh ├── zfs-osx-mount-snapshot.sh ├── zfs-osx-unmount-snapshots.sh ├── zfs-prioritize-resilver-io--osx--boojum.sh ├── zfs-show-my-shares--osx.sh ├── zfs-test-encryption-speeds--osx--copy-iso.sh ├── zfs-test-encryption-speeds--osx.sh ├── zpool-copy-2-nclisten.sh ├── zpool-copy.sh └── zpool-create-dual-boot-compatible-v207.sh ├── README.md ├── SMART ├── . .. ├── monthly-smart.sh ├── osx-get-disk-wwn.sh ├── scandisk-bigdrive-2tb+.sh ├── smart-osx-shortreport.sh ├── smart-osx.sh ├── smart-shortreport.sh ├── smarttest-wrapper-linux.sh └── smarttest-wrapper.sh ├── VIRTBOX ├── 0HOWTO-bare-metal-restore-linux-root.txt ├── BKPDEST.mrg ├── RESTORE-fsarchive-root-xfs.sh ├── RESTORE-fsarchive-root.sh ├── STOPALLVMS.sh ├── bkpcrit-rpmbased.sh ├── bkpcrit.sh ├── bkphome.sh ├── bkpsys-2fsarchive ├── bkpsys-2fsarchive.sh ├── debian-fix-low-ram.sh ├── faildisk.sh ├── mkrestoredvdiso-osx.sh ├── mkrestoredvdiso.sh ├── vb-change-HD-uuid.sh ├── vb-convert-vmdk.sh ├── vb-discover-virtmachines.sh ├── vb-registerISOs.sh ├── vb-resize-disk.sh ├── vb-virtmedia-cleanup.sh ├── vbox-attach-existing-disk.sh ├── vbox-boot-from-usbdisk.sh ├── vbox-cleanup-vms.sh ├── vbox-delay-boot.sh ├── vbox-discover-vms.ps1 ├── vbox-install-extpack.sh ├── vbox-list-all-snapshots.sh ├── vbox-make-rawdisk.sh ├── vbox-registerISOs-2dirs.ps1 ├── vbox-registerISOs.ps1 ├── vbox-reown-usb-rawdisk.sh ├── vbox-resizehd.sh ├── vbox-selectvm-statechange-verticalsort.sh ├── vbox-selectvm-statechange.sh ├── vbox-virtmedia-cleanup-osx.sh └── vbox-wheredoesvmlive.sh ├── ZFS ├── boojum-1week-snapshot.sh ├── boojum-expand-raidz.sh ├── boojum-expand-raidz2.sh ├── boojum-monthly-scrub.sh ├── clearcache.sh ├── draid-pooldisks-assoc.sh ├── drive-slicer-get-longform.sh ├── fix-zfs-compile.sh ├── install-samba.sh ├── iscsi-server-config.tar ├── iscsi-vm-configs.tar ├── mkdynamic-grow-pool-boojum.sh ├── mkdynpoolbigger-inplace--boojum.sh ├── mkgpt.sh ├── mkzfsraid10.sh ├── mon1.sh ├── mon96.sh ├── mount-zvol-partitioned-as-disk.sh ├── move-home-to-zfs.sh ├── newzfs-pool-n-datasets.sh ├── pokedisk.sh ├── prepvm.sh ├── proxmox-lmde-create-zfs-disks.sh ├── replacedrives-withbigger--boojum.sh ├── rescan-scsi-bus.sh ├── run-qemu.sh ├── samba-show-current-users.sh ├── scrubwatch.sh ├── spinup.sh ├── ssh-into-qemu-vm.sh ├── test-zfs-21-Draid--90drives.vbox ├── test-zfs-21-Draid--xfs.vbox ├── vbox-create-n-attach-disks-SAS90.sh ├── vbox-create-n-attach-disks-SAS96.sh ├── zfs-1week-snapshot.sh ├── zfs-draid-configs.xlsx ├── zfs-drive-slicer-xargs-simplified.sh ├── zfs-drive-slicer.sh ├── zfs-emergency-free-space.sh ├── zfs-feature-flags-compatible-dual-boot-zpool.ods ├── zfs-fix-smb-conf.sh ├── zfs-killmonth-snaps-debianfix.sh ├── zfs-killmonth-snaps.sh ├── zfs-killsnaps.sh ├── zfs-list-snaps--boojum.sh ├── zfs-list-used-space-by-snapshots.sh ├── zfs-list-used-space-concise.sh ├── zfs-mk-draid-2-vdevs--24d.sh ├── zfs-mk-draid-3-vdevs--24d.sh ├── zfs-mk-draid-32drives.sh ├── zfs-mk-draid-4-vdevs--24d.sh ├── zfs-mk-draid-90drives.sh ├── zfs-mk-draid-96drives.sh ├── zfs-mk-draid-qemu-24d.sh ├── zfs-mk-draid.sh ├── zfs-newds-encrypted.sh ├── zfs-newds-zstd.sh ├── zfs-newds.sh ├── zfs-on-optical-disc.sh ├── zfs-parts-list-60TB-backup-raidz1.xlsx ├── zfs-show-my-shares.sh ├── zfs-shrinkpool-demo-linux.sh ├── zfs-shrinkpool-demo.sh ├── zfs-space-calculator-simulator.sh ├── zfs-test-encryption-speeds--linux--copy-iso.sh ├── zfs-test-encryption-speeds-v3.sh ├── zfs-watchresilver-boojum.sh ├── zfsdemo-zredpool-probox-1-drive-to-4-raid10.sh ├── ziostatt.sh ├── zpool-create-dual-boot-compatible.sh ├── zpool-create-raidz-for-expansion.sh ├── zpool-create-raidz2-for-expansion.sh ├── zpool-expand-raidz-example.sh ├── zpool-export-fast.sh ├── zpool-import-ro.sh ├── zpool-raid10-resize-up.sh ├── zpool-resizeup-mirror--no-degradation--raid10.sh └── zpool-show-last-scrub.sh ├── ans-reboot-server-copypasta.sh ├── ans-reboot-server.sh ├── ans-run-demo-lowercase-sr.sh ├── ans-safe-delete-file-dir.sh ├── awk-print-col-numbers-for-input.sh ├── awkinput-printcolumns.txt ├── awktips.txt ├── bkp-davebin.tar.gz ├── burnUDFsystem2DVD+R ├── burncda2 ├── clearcache.sh ├── commasep-num.mrg ├── convert-man-pages-to-postscript-for-printing.sh ├── countdown.sh ├── debian-compile-zfs--boojum.sh ├── demo-ansible-lowercase-search-replace.yml ├── dot-jstarrc ├── dot-screenrc-mon1-combined ├── dot-screenrc-nonroot ├── dot-screenrc-root ├── dot-vimrc ├── drivemap.sh ├── failexit.mrg ├── ffproxy-config.tgz ├── fix-console-resolution.sh ├── fixetchosts.sh ├── fixfont ├── flist-reconcile.sh ├── flist.sh ├── freebsd └── freshinstall-freebsd.sh ├── freshinstall-debian.sh ├── freshinstall-freebsd.sh ├── freshinstall-suse-rpm.sh ├── freshinstall-ubuntu.yml ├── freshinstall-void.sh ├── getdrive-byids ├── gig-ether--speedup-linux.sh ├── gnu-screen-to-tmux-translation.docx ├── hd-power-status ├── hdps-match.sh ├── id-get-groups.sh ├── increase-swap-partition.yml ├── ipreset ├── iscsi-server-config.tar ├── iscsi-vm-configs.tar ├── iscsi.conf ├── logecho.mrg ├── manTtoPS.sh ├── mk-index-jpg.sh ├── mon1-df-short ├── mon1-tmux-4pane.sh ├── mount-var-cache-apt-sshfs.sh ├── multiple-sed-example.sh ├── newudf.sh ├── powershell ├── 2023-Apr.csv ├── 2023-Aug.csv ├── 2023-Dec.csv ├── 2023-Feb.csv ├── 2023-Jan.csv ├── 2023-Jul.csv ├── 2023-Jun.csv ├── 2023-Mar.csv ├── 2023-May.csv ├── 2023-Nov.csv ├── 2023-Oct.csv ├── 2023-Sep.csv ├── DVDs.csv ├── calendartest.ps1 ├── cdarg.ps1 ├── create-output-from-variable-csv-input.ps1 ├── example-output--parse-df-autosize.txt ├── hats.csv ├── iterate-2-arrays.ps1 ├── pants.csv ├── parse-df-autosize.ps1 ├── parse-df-ls-funcs-sourceme.ps1 ├── shirts.csv ├── test-progressbar-ls.ps1 └── win-show-error-log-common--RUN-AS-ADMIN.ps1 ├── proxmox ├── BKPDEST.mrg ├── HOWTO-make-a-file-backed-backup-of-proxmox-rpool.docx ├── RESTORE-fsarchive-root-proxmox--EFI.sh ├── RESTORE-fsarchive-root-proxmox--NO-EFI.sh ├── bkpcrit-proxmox.sh ├── bkpsys-2fsarchive ├── cluster-3-node-with-pi-or-vm-qdevice.sh ├── convert-vdi-disks-to-qcow2.sh ├── dot-config-htop-htoprc ├── freshinstall-proxmox.sh ├── get-latest-zfsbootmenu.sh ├── importvm-win10.sh ├── ipreset ├── lxc-fix-timezone.sh ├── mkefi.sh ├── newvm-proxmox.sh ├── nvme-check-namespace-relative-performance.sh ├── oom-killer-adjust.sh ├── proxmox-BULK-RESTORE-VMS--PARALLEL.sh ├── proxmox-BULK-RESTORE-VMS.sh ├── proxmox-HIBER-RUNNING-VMS.sh ├── proxmox-SHUTDOWN-RUNNING-VMS.sh ├── proxmox-START-VMS-parallel.sh ├── proxmox-UNCLUSTER-me.sh ├── proxmox-backup-veeam-agent-setup.sh ├── proxmox-backup-zfs-bootroot.sh ├── proxmox-bkp-host-to-pbs.sh ├── proxmox-clone-zfs-bootroot-to-mirror.sh ├── proxmox-cluster-delete-all-snapshots-for-vm.sh ├── proxmox-cpu-cores-in-use-by-running-vms.sh ├── proxmox-create-additional-lvm-thin.sh ├── proxmox-create-lvm-thin.sh ├── proxmox-create-lxc-xrdp-icewm-thunderbird-debian.sh ├── proxmox-create-zfs-boot-disk-partitions.sh ├── proxmox-del-fleece-datasets.sh ├── proxmox-delete-all-snapshots-for-thisvm.sh ├── proxmox-deploy-lxc-debian-icewm-thunderbird.sh ├── proxmox-destroy-ctr.sh ├── proxmox-df-container-storage.sh ├── proxmox-enter-container.sh ├── proxmox-expand-lvm-thinpool.sh ├── proxmox-find-latest-backup.sh ├── proxmox-fix-10gig-driver-compile.sh ├── proxmox-fix-pbs-storage-down-spamming-logs.sh ├── proxmox-fix-vmbr0-nic.sh ├── proxmox-get-lxc-container-ips.sh ├── proxmox-get-vm-cpu-usage.sh ├── proxmox-grub-rescue-fix.sh ├── proxmox-list-containers.sh ├── proxmox-list-vm-snapshots.sh ├── proxmox-lvm-convert-to-thin-pool.sh ├── proxmox-lxc-assign-cpu-cores-6-vcpu--8-pcpu.sh ├── proxmox-migrate-disk-storage.sh ├── proxmox-mkiso-unattended-install.sh ├── proxmox-mount-lxc-ctr-root-on-host.sh ├── proxmox-mount-vm-lvm-disk-on-host.sh ├── proxmox-qcow2-actual-disk-in-use-size-report.sh ├── proxmox-query-vm-agents.sh ├── proxmox-recover-vm-disks-without-backup.sh ├── proxmox-refresh-ctr-templates.sh ├── proxmox-replace-zfs-ashift9-boot-disk-with-ashift12.sh ├── proxmox-replace-zfs-mirror-boot-disks-with-bigger.sh ├── proxmox-replace-zfs-mirror-boot-disks-with-smaller.sh ├── proxmox-scan-samba-server-for-shares.sh ├── proxmox-selectvm-statechange-verticalsort.sh ├── proxmox-storage-report.sh ├── proxmox-sync-windows-time-beyond-48hrs.sh ├── proxmox-unattended-install.toml ├── proxmox-unlock-vm.sh ├── proxmox-vm-assign-cpu-cores-6-vcpu--8-pcpu.sh ├── proxmox-vm-assign-cpu-cores.sh ├── proxmox-win10-vm-sync-time.sh ├── proxmox-windows-vm-free-disk-space.sh ├── proxmox-zfs-bootroot-restore-from-mirrorfile.sh ├── proxmox-zfs-test-draid-vm-create-disks.sh ├── psax ├── psthreads.sh ├── rc.local ├── real-du.sh ├── resize-lvm-thin-pool.sh ├── symlink-samba-isos.sh ├── zpo.sh └── zpool-add-to-proxmox-gui.sh ├── reboot-and-wait.yml ├── redhat-alma-rocky ├── freshinstall-alma-rpm.sh └── vdo-create-volume.sh ├── ren-from-csv.sh ├── ripcd.sh ├── rootbin.tgz ├── rpmsortinst.sh ├── run-qemu.sh ├── s3-bucket-unique-name.sh ├── safe-dd.sh ├── saferm.sh ├── server-naming-translator-general.sh ├── setproxy.sh ├── simplewebserver.sh ├── ssh-into-qemu-vm.sh ├── ssh-speed-test-localhost.sh ├── ssh-wait4.sh ├── sysadmin-bkp-edit.sh ├── timesync ├── timesync.sh ├── topscrn4-10.sh ├── topscrn4-xterm.sh ├── topterm9.sh ├── toptmux4-10.sh ├── tutorial-xargs.sh ├── ubuntu_zfs_build_install.sh ├── unpass.sh ├── updt-suse.sh ├── wav2mp3.sh ├── winstuff ├── HALT.cmd ├── REBOOT.cmd ├── chocolatey-install.cmd ├── fix-powershell-running-scripts-disabled.cmd ├── freshinstall-chocolatey-win.cmd ├── make-win-use-utc-time.cmd ├── noatime.cmd ├── noscreensaver.bat ├── sfc-scannow-dism.cmd ├── ssh-2p5gig-squidvm-portfwd-squid.cmd ├── win10-firewall-allow-ping.cmd ├── win10-upgrade-switches.cmd ├── win11-MediaCreationTool.bat └── winupdates-set-proxy-ie.cmd ├── zfs-install-redhat-alma.sh ├── zfs-mk-draid-qemu-24d.sh ├── zfs-test-encryption-speeds-v2.sh └── zombieprocs.sh /0HOWTO-install-these-scripts.txt: -------------------------------------------------------------------------------- 1 | Click the green Code button and download the .zip 2 | 3 | https://github.com/kneutron/ansitest/tree/master 4 | 5 | Code: 6 | mkdir -pv /root/bin/boojum 7 | 8 | Put the BKPDEST.mrg in that directory, the rest can run from /root/bin if you want. 9 | Install midnight commander if you want an easy way to copy/move things around (it's also the safest way to recursively delete directories) 10 | 11 | If /root/bin is not already in your PATH ( echo $PATH # to check ) you will need to add something like this to /root/.bashrc: 12 | 13 | 14 | Code: 15 | export PATH=/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin:/usr/local/games:/usr/games:/root/bin:/root/bin/boojum:/usr/X11R6/bin:/usr/NX/bin: 16 | 17 | and then ' source ~/.bashrc '# for it to take effect in the current shell 18 | 19 | For good measure, ' chmod -R 750 /root/bin ' # make scripts executable 20 | 21 | Then you want to edit /root/bin/boojum/BKPDEST.mrg and define the target for your backups. 22 | This will probably also need to be a mountpoint defined in /etc/fstab, unless you're using sshfs. 23 | The BKPDEST will attempt to mount it if it isn't already active. 24 | 25 | This target mountpoint CANNOT be root on the same system (or preferably, not even a separate partition on the same root disk) - needs to be separate media or NAS. 26 | (If your root disk dies, you still want access to the backup.) 27 | 28 | Now, you should be able to run the bkpcrit script. 29 | I recommend that you put it nightly in cron, and also run it ad hoc before ANY system changes - this includes package upgrades. 30 | -------------------------------------------------------------------------------- /Demo_df-rootusage.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - hosts: all 3 | gather_facts: no 4 | 5 | tasks: 6 | - name: ZFSaware Root FS usage 7 | shell: zpool list rpool |grep -v ALLOC |awk '{print $3}' 8 | register: dfrootz 9 | - name: nonzfs rootfs usage 10 | shell: df -h / |grep -v "Use" |awk '{print $5}' 11 | register: dfrootnz 12 | 13 | - debug: 14 | msg: "System {{ inventory_hostname }}'s root FS utilization is {{ dfrootz.stdout }} {{ dfrootnz.stdout }}" 15 | -------------------------------------------------------------------------------- /OSX/. ..: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /OSX/bkp-home-rclone-macmini-2qotom-proxmox-ztosh10.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # bkp macmini home to qotom proxmox ztosh10 4 | # REF: https://rclone.org/sftp/ 5 | #eval `ssh-agent -s` && ssh-add -A 6 | eval `ssh-agent -s` && ssh-add -k ~/.ssh/id_rsa 7 | 8 | # dest: /Volumes/zsgtera2/shrcompr-bkphome-zsgtera2/bkphome-macpro2-lmde6 9 | 10 | date 11 | # -i = interactive 12 | # skip -- --copy-links 13 | # -c = check hashes 14 | # REF: https://rclone.org/sftp/#sftp-disable-hashcheck 15 | # ^REF: https://forum.rclone.org/t/ignore-checksum-not-honored/13397/3 16 | 17 | # xfrs=3 single disk increased to 6 for mirror 2024.0413 18 | # REMEMBER shr/notshr are SYMLINKS, dont dup content! 19 | #time rclone sync -P --copy-links --retries=2 --low-level-retries=2 \ 20 | #time rclone sync -P --skip-links --delete-before --retries=2 --low-level-retries=2 \ 21 | # --exclude=dvdrips-shr/** --exclude=.fseventsd/** \ 22 | time rclone sync -P --skip-links --retries=2 --low-level-retries=2 \ 23 | --sftp-disable-hashcheck \ 24 | --transfers=3 --stats=2s \ 25 | --no-update-modtime --update \ 26 | /Users/ \ 27 | qotom-proxmox-25g:/ztoshtera10/bkp-home-macmini-rclone \ 28 | --log-file ~/bkp-home-rclone-macmini-errors.log 29 | # 2>~/rclone-error.log 30 | 31 | date 32 | eval `ssh-agent -k` 33 | 34 | exit; 35 | 36 | o Run rclone config to setup. See rclone config docs (https://rclone.org/docs/) for more details. 37 | Type: 47 / SSH/SFTP Connection 38 | 39 | NOTE REQUIRES ssh-copy-id dave@ip 1st!! 40 | 41 | REF: A note on exclude- 42 | https://rclone.org/filtering/ 43 | 44 | REF: Helpful tips: 45 | https://dshark3y.medium.com/the-best-tool-youre-not-using-15ba2d238515 46 | 47 | No worky: 48 | 10.9.7.12:/zwd6t/bkp-osx-zsgtera4/zsgtera4 \ 49 | -------------------------------------------------------------------------------- /OSX/disks-only-osx.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | DBS=/var/run/disk/by-serial 4 | 5 | # w/o partitions 6 | ls -l $DBS |egrep -v 'disk.s|disk..s' |awk '{print $9,$10,$11}' |gsed 's#disk#disk #g' |sort -h -k 4 |column -t 7 | 8 | exit; 9 | 10 | # Sample output 11 | ST3500418AS-5VMSTS -> /dev/disk 0 12 | 004-2E4164-Z521TR -> /dev/disk 1 13 | Portable_SSD_T5-S49WNP0N12051 -> /dev/disk 2 14 | HDWR460UZSVB-13T0A01HF1 -> /dev/disk 3 15 | 16 | 17 | la $DBS |egrep -v 'disk.s|disk..s' |sort -h -k 11 18 | drwxr-xr-x 7 root daemon 224 Nov 17 23:43 .. 19 | drwxr-xr-x 63 root daemon 2016 Nov 17 22:42 . 20 | lrwxr-xr-x 1 root daemon 10 Nov 17 22:42 APPLE_SSD_SM1024G-S32YNY0M200366 -> /dev/disk0 21 | lrwxr-xr-x 1 root daemon 10 Nov 17 22:42 HGST_HUS726060ALE614-K8JAPRGN -> /dev/disk5 22 | lrwxr-xr-x 1 root daemon 10 Nov 17 22:42 PSSD_T7_Shield-X17960CT0SNLS6S -> /dev/disk2 23 | lrwxr-xr-x 1 root daemon 10 Nov 17 22:42 ST4000VN000-1H4168-Z3076XVL -> /dev/disk6 24 | lrwxr-xr-x 1 root daemon 10 Nov 17 22:42 ST6000VN001-2BB186-ZR112FRW -> /dev/disk9 25 | lrwxr-xr-x 1 root daemon 10 Nov 17 22:42 TOSHIBA_HDWG11A-Y1A0A01AFBDG -> /dev/disk7 26 | lrwxr-xr-x 1 root daemon 11 Nov 17 22:42 ST4000VN000-2AH166-WDH0SB5N -> /dev/disk11 27 | lrwxr-xr-x 1 root daemon 11 Nov 17 22:42 ST4000VN008-2DR166-ZGY9F4M8 -> /dev/disk10 28 | -------------------------------------------------------------------------------- /OSX/disks-osx.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # NOTE osx does not seem to have a concept of wwn anywhere that I can find (smartctl, diskutil, dev/*) 4 | 5 | DBI=/var/run/disk/by-id 6 | DBP=/var/run/disk/by-path 7 | DBS=/var/run/disk/by-serial 8 | 9 | ls -l $DBI $DBP $DBS |egrep -v 'var/|s[0-9]|total' |column -t |sort -k 11 |awk '{ print $11" "$10" "$9 }' 10 | 11 | diskutil list |grep -A 2 physical 12 | 13 | exit; 14 | 15 | # Sample output 16 | /dev/disk0 -> PCI0@0-SATA@1F,2-PRT0@0-PMP@0-@0:0 17 | /dev/disk0 -> ST3500418AS-5VMSTS 18 | /dev/disk1 -> 004-2E4164-Z521TR 19 | /dev/disk1 -> PCI0@0-RP03@1C,2-FRWR@0-node@30e0c84631304a-sbp-2@4008-@1:0 20 | /dev/disk1 -> device-030ffffffe0ffffffc84631304a 21 | /dev/disk2 -> PCI0@0-EHC1@1D,7-@4:0 22 | /dev/disk2 -> Portable_SSD_T5-S49WNP0N12051 23 | /dev/disk3 -> HDWR460UZSVB-13T0A01HF1 24 | /dev/disk3 -> PCI0@0-RP03@1C,2-FRWR@0-node@30e0c84631304a-sbp-2@4008-@0:0 25 | /dev/disk4 -> media-03EC333F-F868-4677-9B79-F1AC28924999 26 | /dev/disk5 -> media-A30E1D81-CBD1-4228-B896-E5084F8A2D74 27 | /dev/disk0 (internal, physical): 28 | #: TYPE NAME SIZE IDENTIFIER 29 | 0: GUID_partition_scheme *500.1 GB disk0 30 | -- 31 | /dev/disk1 (external, physical): 32 | #: TYPE NAME SIZE IDENTIFIER 33 | 0: GUID_partition_scheme *2.0 TB disk1 34 | -- 35 | /dev/disk2 (external, physical): 36 | #: TYPE NAME SIZE IDENTIFIER 37 | 0: GUID_partition_scheme *500.1 GB disk2 38 | -- 39 | /dev/disk3 (external, physical): 40 | #: TYPE NAME SIZE IDENTIFIER 41 | 0: GUID_partition_scheme *6.0 TB disk3 42 | -------------------------------------------------------------------------------- /OSX/extended-attribs--osx.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # works on ZFS and HFS+ 4 | 5 | # REF: https://en.wikipedia.org/wiki/Extended_file_attributes 6 | #/Volumes/zsam52/shrcompr-zsam52 $ 7 | xattr -lv * 8 | #testfile: xattrib1: test extended attrib 9 | 10 | exit; 11 | 12 | # Linux: use Extended attributes can be accessed and modified using the 13 | getfattr and setfattr commands from the attr package on most 14 | distributions.[16] The APIs are called getxattr and setxattr. 15 | -------------------------------------------------------------------------------- /OSX/findmedia-osx.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | DBI=/var/run/disk/by-id 4 | DBP=/var/run/disk/by-path 5 | DBS=/var/run/disk/by-serial 6 | 7 | # 2019.0430 by-path is kinda useless, but re-enable if needed 8 | #ls -lR $DBI $DBP $DBS |grep $1 9 | ls -lR $DBI $DBS |grep $1 |awk '{ print $11" "$10" "$9 }' |column -t 10 | 11 | -------------------------------------------------------------------------------- /OSX/freshinstall-mac.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # /opt/local/bin/bash 3 | 4 | port-install.sh -N bash bwm-ng sysstat joe 5 | #port-install.sh -N mc +sftp 6 | 7 | port-install.sh -N grsync xaos md5sha1sum openjdk11 mutt mediainfo geeqie \ 8 | putty shellcheck gawk jc jq sxiv unison lf inetutils nomacs kitty \ 9 | tmux byobu html2text flock gptfdisk gsed pv watch parallel findutils \ 10 | nmap imagemagick buffer lame veracrypt git rclone mediainfo 11 | 12 | # TODO ntp 13 | # ristretto build fail 2023.0321 14 | # atom no longer avail 15 | -------------------------------------------------------------------------------- /OSX/freshinstall-macports.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # no usrlocalbin - that 4 brew 4 | PATH=/var/root/bin:/var/root/bin/boojum:/sbin:/usr/sbin:/bin:/usr/bin:/usr/X11R6/bin:/opt/local/bin: 5 | 6 | # avoid conflicts/errs with brewstuff 7 | mv -v /usr/local/include /usr/local/notinclude 8 | 9 | # no lsof; hfstar build failed 10 | port -N install autossh bash bwm-ng bzip2 cmatrix coreutils curl detox ffmpeg flock gnutar gptfdisk grsync \ 11 | gsmartcontrol gstreamer1 htop iftop imagemagick iperf3 joe lame lftp lz4 lzma lzo2 lzop nmap p7zip \ 12 | parallel pidof pigz pstree pv smartmontools ssh-copy-id sshfs util-linux watch youtube-dl yt-dlp \ 13 | wget zstd 14 | 15 | #port uninstall mc 16 | #port clean mc 17 | #port install mc +sftp 18 | 19 | [ -e /usr/local/notinclude ] && mv -v /usr/local/notinclude /usr/local/include 20 | 21 | date 22 | 23 | exit; 24 | -------------------------------------------------------------------------------- /OSX/gig-ether--speedup--osx.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # http://fasterdata.es.net/host-tuning/linux/ 4 | 5 | # REF: https://www.atto.com/software/files/other/osx_fastframe_readme_v7_20.pdf 6 | 7 | # REF: https://hints.macworld.com/article.php?story=20060616112919669 ## OLD 8 | # If you would like these changes to be preserved across reboots you can edit /etc/sysctl.conf. 9 | # 10 | 11 | sysctl -w kern.ipc.maxsockbuf=4194304 12 | # will not go higher in OSX due to system limitations. 13 | 14 | sysctl -w net.inet.tcp.sendspace=2097152 15 | sysctl -w net.inet.tcp.recvspace=2097152 16 | sysctl -w net.inet.tcp.maxseg_unacked=32 17 | sysctl -w net.inet.tcp.delayed_ack=2 18 | sysctl -w kern.maxnbuf=60000 19 | sysctl -w kern.maxvnodes=280000 20 | sysctl -w net.inet.tcp.sack=1 21 | 22 | 23 | # determine interfaces found OTF xxx 2017.0319 24 | #for e in `ifconfig -a |grep HW |awk '{print $1}'`; do 25 | # ifconfig $e txqueuelen 5000 26 | #ifconfig eth1 txqueuelen 5000 27 | #done 28 | 29 | #http://datatag.web.cern.ch/datatag/howto/tcp.html 30 | #sysctl sys.net.core.netdev_max_backlog=2000 # unknown 31 | ##sysctl net.ipv4.tcp_sack=0 32 | 33 | ifconfig -a > /var/root/ifconfig-a.txt 34 | chmod 500 /var/root/ifconfig-a.txt 35 | 36 | exit; 37 | 38 | ifconfig en0 mediaopt full-duplex 39 | [ davesimac513.local (scrn=1) ] 40 | 41 | # ifconfig en0 42 | en0: flags=8863 mtu 1500 43 | options=10b 44 | ether 3c:07:54:64:eb:10 45 | inet6 fe80::4f2:bbae:d379:1882%en0 prefixlen 64 secured scopeid 0x6 46 | inet 10.9.13.4 netmask 0xff000000 broadcast 10.255.255.255 47 | nd6 options=201 48 | media: autoselect (1000baseT ) 49 | status: active 50 | -------------------------------------------------------------------------------- /OSX/iscsi-osx-list-luns.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # REQUIRES: https://github.com/sahlberg/libiscsi 4 | 5 | ip=10.9.7.12 # dellap lmde, iscsi host/target 6 | 7 | iscsi-ls iscsi://$ip 8 | iscsi-ls -s iscsi://iscsi-user%password@$ip 9 | #iscsi-ls -s iscsi://@$ip 10 | -------------------------------------------------------------------------------- /OSX/iscsi-osx-mapdrives.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | firstrun=0 4 | # REQUIRES: https://github.com/iscsi-osx/iSCSIInitiator , XCODE 5 | 6 | # REF: https://github.com/iscsi-osx/iSCSIInitiator/wiki/Target-Discovery 7 | # REF: https://github.com/iscsi-osx/iSCSIInitiator/wiki/Authentication 8 | 9 | # NOTE use iscsi-osx-list-luns.sh 1st 10 | #iscsictl add target iqn.2015-01.com.example:target,192.168.1.100:3260 -interface en0 11 | iscsictl add target iqn.2021-07.example.com:lun1,10.9.7.12:3260 -interface en0 12 | # dellap lmde 13 | 14 | iscsictl list targets 15 | 16 | if [ $firstrun -gt 0 ]; then 17 | iscsictl modify initiator-config -CHAP-name iscsi-user 18 | iscsictl modify initiator-config -CHAP-secret 19 | # ^ Will prompt for password - should only need to do once 20 | 21 | iscsictl modify initiator-config -authentication CHAP 22 | fi 23 | 24 | if [ "$1" = "unmap" ]; then 25 | # NOTE all zpools must be exported and indiv drives unmounted 1st 26 | iscsictl logout iqn.2021-07.example.com:lun1,10.9.7.12 27 | exit $? # early 28 | fi 29 | 30 | iscsictl login iqn.2021-07.example.com:lun1,10.9.7.12:3260 \ 31 | -authentication CHAP \ 32 | -CHAP-name iscsi-user \ 33 | -CHAP-secret 34 | # password 35 | 36 | echo PK 37 | read -n 1 38 | 39 | diskutil list |less 40 | -------------------------------------------------------------------------------- /OSX/jumboframes-osx.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [ "$1" = "" ]; then 4 | echo "Config for jumbo frames 9000" 5 | ifconfig en0 mtu 9000 6 | else 7 | echo "Config for std frames 1500" 8 | ifconfig en0 mtu 1500 9 | fi 10 | 11 | echo "$(date) - Waiting for interface to come back online" 12 | result=1 13 | while [ $result -gt 0 ]; do 14 | result=$(ifconfig en0 |grep -c inactive) 15 | sleep .5 16 | done 17 | 18 | date 19 | ifconfig en0 20 | -------------------------------------------------------------------------------- /OSX/macfanstemps.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # NOTE this script is for linux - run as root 4 | modprobe applesmc 5 | 6 | outfile=/tmp/macfans.txt 7 | 8 | source ~/bin/failexit.mrg 9 | 10 | cd /sys/devices/platform/applesmc.768 || failexit 101 "Apple SMC fan control not found!" 11 | 12 | # set fan speed 13 | echo 3000 >fan3_min 14 | 15 | (for fyl in fan*; do echo $fyl `cat $fyl`;done) > $outfile 16 | 17 | sensors -f >> $outfile 18 | 19 | tail -n 20 /var/log/macfanctl.log >> $outfile 20 | 21 | less $outfile 22 | 23 | -------------------------------------------------------------------------------- /OSX/macos-download-monterey-installer.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # REF: https://discussions.apple.com/thread/255859460?sortBy=rank 4 | # https://www.macworld.com/article/673697/what-version-of-macos-can-my-mac-run.html 5 | 6 | cd ~/Downloads 7 | 8 | softwareupdate --list-full-installers 9 | 10 | echo "Enter version" 11 | read instversion 12 | 13 | [ "$instversion" = "" ] && exit 99; 14 | 15 | # As of Nov 25, 2024 - Monterey 16 | time softwareupdate -d --fetch-full-installer --full-installer-version $instversion # 12.7.6 17 | date 18 | -------------------------------------------------------------------------------- /OSX/mk-high-sierra-1013-bootable-iso.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # failexit.mrg 4 | function failexit () { 5 | echo '! Something failed! Code: '"$1 $2" # code # (and optional description) 6 | exit $1 7 | } 8 | 9 | # xxx TODO EDITME 10 | dest=/Volumes/zmac5int/zmac5intcompshr 11 | 12 | cd $dest || failexit 101 "check $dest" 13 | 14 | time hdiutil create -o HighSierra.cdr -size 6000m -layout SPUD -fs HFS+J && \ 15 | hdiutil attach HighSierra.cdr.dmg -noverify -mountpoint /Volumes/install_build 16 | 17 | sudo $HOME/Downloads/Install\ macOS\ High\ Sierra.app/Contents/Resources/createinstallmedia --volume /Volumes/install_build 18 | 19 | mv -v HighSierra.cdr.dmg HighSierra.dmg 20 | 21 | hdiutil detach /Volumes/Install\ macOS\ High\ Sierra 22 | hdiutil detach /Volumes/install_build 23 | 24 | time hdiutil convert HighSierra.dmg -format UDTO -o HighSierra.iso && mv -v HighSierra.iso.cdr HighSierra.iso 25 | date 26 | ls -alh *.iso 27 | -------------------------------------------------------------------------------- /OSX/mk-monterey-install-media.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Make bootable MacOS / OSX 12.7 install media 4 | # REF: https://krypted.com/mac-os-x/create-bootable-installation-media-high-sierra-installations/ 5 | # REF: https://osxdaily.com/2022/02/23/make-macos-monterey-boot-install-drive/ 6 | 7 | # NOTE usb media must be pre-erased and mounted at /Volumes/macosinstall 8 | # Use Disk Utility, Erase, Mac OS Extended Journaled, GUID partition 9 | # NOTE monterey needs 16GB 10 | 11 | source ~/bin/failexit.mrg 12 | 13 | [ $(df |grep -c /Volumes/macosinstall) -gt 0 ] || failexit 40 "/Volumes/macosinstall not mounted/found - need to have pre-formatted USB mounted" 14 | 15 | #cd ~/Downloads && \ 16 | set -x 17 | cd /Volumes/Monterey-Latest-App && \ 18 | cd "Install macOS Monterey.app" && \ 19 | Contents/Resources/createinstallmedia \ 20 | --volume /Volumes/macosinstall --nointeraction 21 | -------------------------------------------------------------------------------- /OSX/mk-sonoma14-install-media.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Make bootable MacOS / OSX 14.7.2 install media 4 | # REF: https://support.apple.com/en-us/101578 5 | # REF: https://osxdaily.com/2022/02/23/make-macos-monterey-boot-install-drive/ 6 | 7 | # NOTE usb media must be pre-erased and mounted at /Volumes/macosinstall 8 | # Use Disk Utility, Erase, Mac OS Extended Journaled, GUID partition 9 | # NOTE monterey needs 16GB 10 | 11 | source ~/bin/failexit.mrg 12 | 13 | #[ $(df |grep -c /Volumes/macos-sonoma14-bootable-installer) -gt 0 ] || failexit 40 "/Volumes/macos-sonoma14-bootable-installer not mounted/found - need to have pre-formatted USB mounted" 14 | [ $(df |grep -c "/Volumes/Install macOS Sonoma") -gt 0 ] || failexit 40 "/Volumes/macos-sonoma14-bootable-installer not mounted/found - need to have pre-formatted USB mounted" 15 | 16 | #cd ~/Downloads && \ 17 | # where the installer lives - currently on 32GB sdcard 18 | set -x 19 | #cd /Volumes/macos-sonoma-14-installer && \ 20 | #cd /Users/dave2/Downloads/ && \ 21 | cd /Applications && \ 22 | cd "Install macOS Sonoma.app" && \ 23 | Contents/Resources/createinstallmedia \ 24 | --volume "/Volumes/Install macOS Sonoma" --nointeraction 25 | # --volume /Volumes/macos-sonoma14-bootable-installer --nointeraction 26 | 27 | date; 28 | 29 | #Sonoma sudo 30 | #/Applications/Install\ macOS\ Sonoma.app/Contents/Resources/createinstallmedia --volume /Volumes/MyVolume 31 | -------------------------------------------------------------------------------- /OSX/norecovhdmounts.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # umount extra recovery HDs 4 | for u in `df |grep Recovery |awk '{print $1}'`; do 5 | echo $u 6 | diskutil unmount $u 7 | done 8 | 9 | diskutil unmount /Volumes/*CCCRESTORE 10 | diskutil unmount /Volumes/*cccrestore 11 | diskutil unmount /Volumes/CCCrestore* 12 | diskutil unmount "/Volumes/Install macOS High Sierra" 13 | diskutil unmount "/Volumes/CCCrestore-imac5-old-hs1013" 14 | diskutil unmount "/Volumes/OLDERosxint5001013" 15 | 16 | diskutil umount "/Volumes/Untitled" 17 | diskutil umount "/Volumes/Untitled 1" 18 | diskutil umount "/Volumes/Untitled 2" 19 | 20 | # internal SSD - macmini 21 | diskutil umount "/Volumes/Macintosh HD" 22 | diskutil umount "/Volumes/Macintosh HD - Data" 23 | diskutil umount "/Volumes/Update" 24 | 25 | # other beetle with Monterey 26 | diskutil umount "/Volumes/skhynix-1tb-macmini - Data" 27 | diskutil umount "/Volumes/skhynix-1tb-macmini" 28 | 29 | # older install 30 | diskutil umount /Volumes/hynix2-ventura-13-macmini 31 | diskutil umount "/Volumes/hynix2-ventura-13-macmini - Data" 32 | diskutil umount /Volumes/cccbkp-ventura-13-macmini-wd6T 33 | 34 | #/dev/disk3s1 apfs 233G 33G 201G 14% /Volumes/Samt7-Monterey - Data 35 | #/dev/disk3s3 apfs 233G 33G 201G 14% /Volumes/Samt7-Monterey 36 | #/dev/disk4s1 apfs 230G 86G 145G 38% /Volumes/cccrestore-samt7-mont 37 | 38 | diskutil unmount "/Volumes/Samt7-Monterey - Data" 39 | diskutil unmount "/Volumes/Samt7-Monterey" 40 | diskutil unmount /Volumes/cccrestore-samt7-mont 41 | 42 | # might as well run this too 43 | gig-ether--speedup--osx.sh 44 | 45 | # and this xxx 2024.1204 46 | /var/root/bin/boojum/zfs-osx-sysctl-fixes.sh 47 | 48 | gdf -hT 49 | -------------------------------------------------------------------------------- /OSX/osx-delete-apfs-snapshots.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | tmutil listlocalsnapshots /Volumes/iscsi-macosmont12-davemacpro\ -\ Data 4 | 5 | echo "SEE SOURCE" 6 | exit; 7 | 8 | # REF: https://www.google.com/search?q=monterey+delete+apfs+snapshot+commandline&num=10&sca_esv=fb0328165e44674a&rlz=1C5CHFA_enUS1050US1082&sxsrf=ADLYWIInlgRBKpZsnFqWtPdDbIPHgIviyw%3A1732216760856&ei=uIc_Z_z2M-Tfp84P5I6d0As&ved=0ahUKEwj8stGlku6JAxXk78kDHWRHB7oQ4dUDCBA&uact=5&oq=monterey+delete+apfs+snapshot+commandline&gs_lp=Egxnd3Mtd2l6LXNlcnAiKW1vbnRlcmV5IGRlbGV0ZSBhcGZzIHNuYXBzaG90IGNvbW1hbmRsaW5lMgcQIRigARgKMgcQIRigARgKMgcQIRigARgKMgcQIRigARgKMgcQIRigARgKSNcSULADWK8RcAF4AZABAZgBzAKgAfANqgEIMC4xMS4wLjG4AQPIAQD4AQGYAgygAugMwgIKEAAYsAMY1gQYR8ICBRAhGKABwgIFECEYqwLCAgUQIRifBcICBxAjGLACGCfCAggQABiABBiiBMICCBAAGKIEGIkFmAMAiAYBkAYIkgcIMS4xMC4wLjGgB4JC&sclient=gws-wiz-serp 9 | 10 | tmutil listlocalsnapshots 11 | tmutil deletelocalsnapshots /Volumes/iscsi-macosmont12-davemacpro\ -\ Data 2024-10-08-181025 12 | tmutil deletelocalsnapshots /Volumes/iscsi-macosmont12-davemacpro\ -\ Data 13 | tmutil deletelocalsnapshots /Volumes/iscsi-macosmont12-davemacpro 14 | tmutil listlocalsnapshots /Volumes/iscsi-macosmont12-davemacpro\ -\ Data 15 | tmutil deletelocalsnapshots 2024-10-08-181025 16 | -------------------------------------------------------------------------------- /OSX/osx-extended-metadata-attributes-hfsplus.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # REF: https://apple.stackexchange.com/questions/85699/any-risks-in-creating-custom-os-x-extended-attributes 4 | # store *sum information along with the file for future backup/comparison 5 | 6 | if [ "$1" = "" ]; then 7 | outf=metadata-test 8 | cd /tmp 9 | else 10 | outf="$1" 11 | fi 12 | 13 | [ "$outf" = "metadata-test" ] && echo "thys be randome texte" >$outf 14 | #ls -alh $outf 15 | 16 | # see ' man xattr ' 17 | # copy the md5sum for the file to its own metadata 18 | xattr -w md5 $(md5sum $outf |awk '{print $1}') $outf 19 | 20 | #79a6a33cf17bf7550486c58836928193 metadata-test 21 | # ^ md5sum output 22 | 23 | #xattr -l $outf 24 | #md5: 79a6a33cf17bf7550486c58836928193 25 | 26 | xattr -w sha1 $(sha1sum $outf |awk '{print $1}') $outf 27 | 28 | set -x 29 | xattr -l $outf 30 | ls -lh@ $outf 31 | 32 | -------------------------------------------------------------------------------- /OSX/osx-flush-dns-cache.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | dscacheutil -flushcache && killall -HUP mDNSResponder 3 | say cache flushed 4 | 5 | # REF: https://macpaw.com/how-to/el-capitan-slow-5-tips-to-speed-up-osx-10-11 6 | 7 | -------------------------------------------------------------------------------- /OSX/osx-get-disk-wwn.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # OSX /dev and /var/run/disk/by-* does not have a concept of WWN IDs so we get it from SMART 4 | #egrep ' /dev|WWN' ~/smartlog-boojum.log 5 | # ^ is a cheat and we can't depend on it existing or being up to date 6 | 7 | # DEPENDS: smartctl being installed from brew or macports 8 | 9 | # NOTE: Pass "1" as arg to print extended disk translation table 10 | 11 | # we want physical disks only or Weird S--t Happens 12 | for d in $(diskutil list |grep phys |awk '{print $1}'); do 13 | wwnid=$(smartctl -i $d |grep WWN |awk '{print "wwn-0x"$5$6$7}') 14 | 15 | [ "$1" = "1" ] && xtd=$(ls -l /var/run/disk/by-serial |grep -w $d |awk '{print $9}') # print extended trans tbl 16 | 17 | if [ "$1" = "1" ]; then 18 | tmp1=$(smartctl -i $d |egrep 'Device Model|Serial Number' |paste - -) 19 | #Device Model: ST4000VN000-2AH166 20 | #Serial Number: WDH0SB 21 | # paste = combine lines 22 | #Device Model: ST4000VN000-2AH166 Serial Number: WDH0SB 23 | # 1 2 3 4 5 6 24 | 25 | # xstd2=${xstd2/Device Model:/} # bash inline sed, replace string with blank 26 | # xstd2=${xstd2/Serial Number:/} # bash inline sed, replace string with blank 27 | xstd2=$(echo "$tmp1" |awk '{print $3"-"$6}') # strip out devmod/ser # dont need replace, just fields + dash 28 | fi 29 | 30 | echo "$d = $wwnid $xtd $xstd2" 31 | done 32 | 33 | exit; 34 | 35 | 36 | linux format /dev/disk/by-id: 37 | wwn-0x50004cf2084c33d0 -> ../../sdi 38 | 39 | osx: 40 | NewerTch__Voyage-WDH0SB = /dev/disk3 41 | LU WWN Device Id: 5 000c50 09d1a789b 42 | ^ raw from SMART 43 | 44 | result of this script: 45 | /dev/disk0 = wwn-0x5000c500380c8768 46 | /dev/disk1 = wwn-0x5002538e00000000 47 | /dev/disk2 = wwn-0x5000c5009d1a789b 48 | 49 | extended table (pass 1 as arg) 50 | /dev/disk0 = wwn-0x5000c500380c8768 ST3500418AS-5VMSTS ST3500418AS-5VMSTS 51 | /dev/disk1 = wwn-0x5002538e00000000 Portable_SSD_T5-S49WNP0N12051 Samsung-T5 52 | /dev/disk2 = wwn-0x5000c5009d1a789b ST4000VN000-2AH166-WDH0SB 53 | 54 | # BUG in high sierra 10.13, disk2 physical only has partitions in DBS and will not -w word match, 55 | # disk3 does match but does not line up with ' diskutil list ' 56 | -------------------------------------------------------------------------------- /OSX/osx-restart-sshd.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | launchctl stop com.openssh.sshd ; launchctl start com.openssh.sshd 4 | -------------------------------------------------------------------------------- /OSX/osx-unmount-time-machine-df.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # REF: https://www.reddit.com/r/MacOS/comments/acxkkw/lots_of_mounts_for_time_machine_backups/ 4 | # clear up ' df ' 5 | 6 | #df -kh |grep com.apple.TimeMachine |awk '{print $9}' |xargs umount 7 | df -kh |grep com.apple.TimeMachine |awk '{print $1}' |xargs umount 8 | gdf -hT 9 | 10 | # removes clutter: 11 | # com.apple.TimeMachine.2024-12-20-060239.backup@/dev/disk20s2 apfs 600G 180G 421G 30% /Volumes/.timemachine/B9CED783-42ED-4388-BA8E-B6BEAE63126F/2024-12-20-060239.backup 12 | -------------------------------------------------------------------------------- /OSX/tmpdel-cleanup.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash5 2 | 3 | # mod for osx - clean out backup files in bin 4 | # REQUIRES: gfind from ports/brew, bash 5.x 5 | 6 | PATH=/opt/local/bin:/opt/local/sbin:/Users/dave/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/Users/dave/Library/Python/3.8/bin 7 | 8 | keepdays=15 9 | 10 | cd $HOME/tmpdel || mkdir -pv $HOME/tmpdel 11 | cd $HOME/tmpdel || exit 99; 12 | 13 | logf=$HOME/tmpdel-cleanup.log 14 | 15 | # auto log rotate 1st of month 16 | chkdate=$(date |awk '{print $3}') 17 | [ "$chkdate" = "1" ] && mv -f $logf $logf--old 18 | 19 | 20 | echo "CLEAN $(date)" >> $logf 21 | 22 | mv -f $HOME/bin/*~ $HOME/tmpdel 23 | 24 | chkid=$(id |awk '{print $1}') 25 | if [ "chkid" = "uid=0(root)" ]; then 26 | mv -f $HOME/bin/boojum/*~ $HOME/tmpdel 27 | fi 28 | 29 | # in tmpdel 30 | gfind . -name '*~' -mtime +$keepdays -print -delete >> $logf 31 | 32 | 33 | #crontab 34 | # Every day at 11pm clean out tmpdel *~ files older than 30 days 35 | #0 23 * * * /Users/dave/bin/tmpdel-cleanup.sh 36 | -------------------------------------------------------------------------------- /OSX/webp2png-photos.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 2024.Sep kneutron 4 | 5 | # REQUIRES ncurses-bin webp detox (macports / brew) 6 | # NOTE can still convert BAD images using rt-click, Quick Actions, Convert image in Finder! 7 | 8 | stime=$(date) 9 | 10 | #[ $(which dwebp |wc -l) -gt 0 ] && sudo apt-get install -y webp 11 | #[ $(which detox |wc -l) -gt 0 ] && sudo apt-get install -y detox 12 | 13 | # need to cd source 1st 14 | outdir=$HOME/tmpdel-photos/webp2png 15 | mkdir -pv "$outdir" 16 | mkdir -pv $HOME/tmpdel-photos/BAD 17 | 18 | cd ~/tmpdel-photos/ || exit 99; 19 | pwd 20 | detox -v $PWD 21 | find ~/tmpdel-photos/ -iname \*'(1)'\* -print -delete 22 | 23 | # print blank lines 24 | clear 25 | #for L in 1 2 3 4 5; do echo ""; done 26 | #origpos=$(tput sc) # save current cursor pos, 5 lines down 27 | 28 | skip=0 29 | done=0 30 | for f in *.webp; do 31 | if [ -e "$outdir/$f.png" ]; then 32 | ((skip++)) 33 | # tput cuu 2 # up 2 lines 34 | # tput home 35 | 36 | # Only every 5! speedup - check modulo 37 | # REF: https://unix.stackexchange.com/questions/423389/compare-bash-variable-to-see-if-divisible-by-5 38 | remainder=$(( skip % 5 )) 39 | if [ "$remainder" -eq 0 ]; then 40 | tput home 41 | echo -n "SKIP = $skip" 42 | tput el # erase to EOL 43 | # echo -n "SKIP $f = $skip"; tput el # erase to EOL 44 | echo ""; tput el; tput rc 45 | fi 46 | else 47 | tput home 48 | tput cud 1 # down 1 line to not overwrite skip 49 | echo -n "Processing $f = $((++done))"; tput el 50 | time dwebp "$f" -o "$outdir/$f.png" 2>>~/webp2png-err.log || ( mv -v $f BAD/; ((done--)) ) # subtract if processing failed 51 | tput el #; tput rc 52 | fi 53 | done 54 | # dwebp -mt # may be buggy code 55 | 56 | tput home 57 | echo -n "TOTAL SKIP = $skip" 58 | tput el # erase to EOL 59 | 60 | ls -alrth "$outdir" |tail 61 | echo "BEGIN = $stime -- $(date) -- DONE= $done / Skip= $skip" 62 | 63 | #rsync-tmpdel-to-xrdp.sh 64 | exit; 65 | 66 | # REF: https://stackoverflow.com/questions/55161334/convert-webp-images-to-png-by-linux-command 67 | 68 | # REF: https://linuxcommand.org/lc3_adv_tput.php 69 | -------------------------------------------------------------------------------- /OSX/zfs-fix-shares-osx.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | function fixman () { 4 | for share in $(zfs-show-my-shares--osx.sh |grep 'sharesmb on' |awk '{print $1}'); do 5 | echo "Fixing $share" 6 | zfs set sharesmb=on $share 7 | done 8 | } 9 | 10 | # 2019.0924 try this instead 11 | zfs share -a 12 | fixman 13 | 14 | #zmac320/sharecompr-320int sharesmb on local 15 | #zredteraB/shrcompr-zrtB sharesmb on local 16 | 17 | zfs-show-my-shares--osx.sh 18 | -------------------------------------------------------------------------------- /OSX/zfs-osx-diskinfo.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # REF: https://openzfsonosx.org/forum/viewtopic.php?f=26&t=3115 4 | 5 | # NOTE Pass media- arg from 'zpool list -v' 6 | diskutil info $(ls -l /var/run/disk/by-id | grep "$1" | awk -F" " '{print $11}' \ 7 | | sed 's/s1//' \ 8 | | sed 's|\/dev\/||') \ 9 | | egrep '(Device Identifier:)|(Whole:)|(Device / Media Name)|(Disk Size:)|(Device Block Size:)' 10 | 11 | exit; 12 | 13 | # ls -al /var/run/disk/by-id|grep -w /dev/disk. 14 | lrwxr-xr-x 1 root daemon 10 Mar 19 23:48 media-ACDA6BAE-722B-42B8-9B55-EC47162D959C -> /dev/disk3 15 | 16 | # zfs-osx-diskinfo.sh media-ACDA6BAE-722B-42B8-9B55-EC47162D959C 17 | Device Identifier: disk3 18 | Whole: Yes 19 | Part of Whole: disk3 20 | Device / Media Name: ST4000VN000-2AH166 21 | Disk Size: 61.9 GB (61865783296 Bytes) (exactly 120831608 512-Byte-Units) 22 | Device Block Size: 4096 Bytes 23 | -------------------------------------------------------------------------------- /OSX/zfs-osx-unmount-snapshots.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | for zds in $(df|grep '.zfs' |awk '{print $1}'); do 4 | zfs umount $zds 5 | done 6 | 7 | df -h 8 | 9 | exit; 10 | 11 | zmacsg2t/virtbox-virtmachines@boojumDOM06 12 | zmacsg2t/virtbox-virtmachines@Wed 13 | zmacsg2t/virtbox-virtmachines@boojumDOM10 14 | zmacsg2t/virtbox-virtmachines@Sun 15 | zmacsg2t/virtbox-virtmachines@boojumDOM16 16 | zmacsg2t/virtbox-virtmachines@Sat 17 | -------------------------------------------------------------------------------- /OSX/zfs-prioritize-resilver-io--osx--boojum.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | sysctl -w kstat.zfs.darwin.tunable.zfs_resilver_delay=0 4 | sysctl -w kstat.zfs.darwin.tunable.zfs_top_maxinflight=512 5 | 6 | exit; 7 | 8 | echo 0 > /sys/module/zfs/parameters/zfs_resilver_delay 9 | echo 512 > /sys/module/zfs/parameters/zfs_top_maxinflight 10 | echo 8000 > /sys/module/zfs/parameters/zfs_resilver_min_time_ms 11 | 12 | exit; 13 | 14 | # Orig values: 15 | 16 | echo 2 > /sys/module/zfs/parameters/zfs_resilver_delay 17 | echo 32 > /sys/module/zfs/parameters/zfs_top_maxinflight 18 | echo 3000 > /sys/module/zfs/parameters/zfs_resilver_min_time_ms 19 | 20 | exit; 21 | 22 | # REF: https://www.reddit.com/r/zfs/comments/4192js/resilvering_raidz_why_so_incredibly_slow/ 23 | 24 | # sysctl -a|grep zfs|egrep 'resilver_delay|top_maxinflight|resilver' 25 | kstat.zfs.darwin.tunable.zfs_top_maxinflight: 32 26 | kstat.zfs.darwin.tunable.zfs_resilver_delay: 2 27 | 28 | REF: https://openzfsonosx.org/wiki/Performance 29 | 30 | sysctl -w kstat.zfs.darwin.tunable.zfs_arc_max= 31 | -------------------------------------------------------------------------------- /OSX/zfs-show-my-shares--osx.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #smbclient -N -L localhost 3 | 4 | # in linux guest: smbclient -U userid -L hostIP 5 | 6 | outfile=/tmp/sharing.txt 7 | 8 | zfs get sharesmb |grep ' on ' > $outfile 9 | 10 | # REF: https://superuser.com/questions/499075/view-shared-folders-from-terminal 11 | #sharing -l >> $outfile 12 | sharing -l |grep -A 1 smb |grep -v smb >> $outfile 13 | 14 | #less $outfile 15 | grep -v '^--' $outfile 16 | -------------------------------------------------------------------------------- /OSX/zfs-test-encryption-speeds--osx--copy-iso.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # osx 4 | # basic copy ISO to test each ZFS cipher's encryption speed after running zfs-test-encryption-speeds--osx (which creates the datasets) 5 | 6 | stime=$(date) 7 | 8 | # TODO editme 9 | zp=zint500 # This is where the Test-aes* datasets live 10 | 11 | tmpfile=$HOME/zfstestencrspeeds.txt 12 | outfile=$HOME/zfs-test-encryption-speeds-results.log 13 | 14 | #source ~/bin/failexit.mrg 15 | # failexit.mrg 16 | function failexit () { 17 | echo '! Something failed! Code: '"$1 $2" # code # (and optional description) 18 | exit $1 19 | } 20 | 21 | useramdisk=1 22 | [ $useramdisk -eq 0 ] && isopath=/Volumes/zsgtera4/shrcompr-zsgt2B/ISO # use if < 6GB RAM installed 23 | # xxx TODO EDITME ^^ 24 | [ "$isopath" = "" ] && isopath=/Volumes/ramdisk 25 | 26 | [ -e "$isopath" ] || failexit 101 "! Ramdisk or ISO source not detected - run zfs-test-encryption-speeds--osx to create it" 27 | 28 | cd "$isopath" && pwd 29 | 30 | function ttime () { 31 | result=$(date -j -f "%a %b %d %T %Z %Y" "$(date)" "+%s") 32 | # see ' man date ' -- seconds 33 | } 34 | 35 | # blankit 36 | > $tmpfile 37 | echo "$(date) - Copying ISO file to each encrypted dataset" 38 | for d in /Volumes/$zp/Test-aes*; do 39 | date; ttime; tstart=$result 40 | time cp -vf *.iso $d 41 | date; ttime; tend=$result 42 | ntime=$(date) 43 | 44 | let csecs=$tend-$tstart 45 | echo "$csecs Seconds to Copy ISO to $d" |tee -a $tmpfile 46 | sleep 10 47 | purge # OSX doesnt really have a sync, this is close 48 | done 49 | 50 | echo "o Start time: $stime -- End time: $ntime" 51 | sort -n $tmpfile > $outfile && rm -f $tmpfile 52 | ls -al $outfile 53 | 54 | exit; 55 | -------------------------------------------------------------------------------- /OSX/zpool-copy-2-nclisten.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # copy 1 zpool/datasets to another destination pool+dataset 4 | 5 | # TODO editme if you have an @NOW snap 6 | zsnap=zintmacpro2@Sat 7 | dest=zsgtera6bkp 8 | destip=10.9.12.12 9 | 10 | #(HOST) 11 | time zfs send -L -R -e $zsnap \ 12 | |pv -t -r -b -W -i 2 -B 250M \ 13 | |nc -w 10 $destip 32100 14 | 15 | date 16 | # |zfs recv -Fev $dest; date 17 | # |zfs recv -Fevn $dest; date 18 | #(VM/dest) 19 | # TODO Remove the "n" for live xmit! Otherwise test run - can ^C after ~10 sec! 20 | 21 | # |zfs recv -evn $dest; date 22 | # time nc -l -p 32100 |zfs recv -Fev zhome/home; date 23 | 24 | exit; 25 | 26 | NOTE the below results in: 27 | 28 | zhgstsas4 zfs 2.9T 128K 2.9T 1% /zhgstsas4 29 | zhgstsas4/shrcompr zfs 3.0T 101G 2.9T 4% /zhgstsas4/shrcompr 30 | zhgstsas4/notshrnotcompr zfs 2.9T 128K 2.9T 1% /zhgstsas4/notshrnotcompr 31 | zhgstsas4/notshrcompr zfs 2.9T 128K 2.9T 1% /zhgstsas4/notshrcompr 32 | zhgstsas4/NEVERLOSE-notshrcompr zfs 2.9T 291M 2.9T 1% /zhgstsas4/NEVERLOSE-notshrcompr 33 | zhgstsas4/BURNME-shrcompr zfs 3.5T 622G 2.9T 18% /zhgstsas4/BURNME-shrcompr 34 | zwd6t/zhgstsas4 zfs 4.4T 128K 4.4T 1% /zwd6t/zhgstsas4 35 | zwd6t/zhgstsas4/BURNME-shrcompr zfs 5.0T 622G 4.4T 13% /zwd6t/zhgstsas4/BURNME-shrcompr 36 | zwd6t/zhgstsas4/NEVERLOSE-notshrcompr zfs 4.4T 291M 4.4T 1% /zwd6t/zhgstsas4/NEVERLOSE-notshrcompr 37 | zwd6t/zhgstsas4/notshrcompr zfs 4.4T 128K 4.4T 1% /zwd6t/zhgstsas4/notshrcompr 38 | zwd6t/zhgstsas4/notshrnotcompr zfs 4.4T 128K 4.4T 1% /zwd6t/zhgstsas4/notshrnotcompr 39 | zwd6t/zhgstsas4/shrcompr zfs 4.5T 101G 4.4T 3% /zwd6t/zhgstsas4/shrcompr 40 | 41 | zsnap=zhgstsas4@Sat 42 | dest=zwd6t 43 | 44 | #(HOST) 45 | time zfs send -L -R -e $zsnap \ 46 | |zfs recv -Fev $dest; date 47 | -------------------------------------------------------------------------------- /OSX/zpool-copy.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # copy 1 zpool/datasets to another destination pool+dataset 4 | 5 | # TODO editme if you have an @NOW snap 6 | zsnap=zhgstsas4@Sat 7 | dest=zwd6t 8 | 9 | #(HOST) 10 | time zfs send -L -R -e $zsnap \ 11 | |pv -t -r -b -W -i 2 -B 250M \ 12 | |zfs recv -Fev $dest; date 13 | # |zfs recv -Fevn $dest; date 14 | #(VM/dest) 15 | # TODO Remove the "n" for live xmit! Otherwise test run - can ^C after ~10 sec! 16 | 17 | # |zfs recv -evn $dest; date 18 | # time nc -l -p 32100 |zfs recv -Fev zhome/home; date 19 | 20 | exit; 21 | 22 | NOTE the below results in: 23 | 24 | zhgstsas4 zfs 2.9T 128K 2.9T 1% /zhgstsas4 25 | zhgstsas4/shrcompr zfs 3.0T 101G 2.9T 4% /zhgstsas4/shrcompr 26 | zhgstsas4/notshrnotcompr zfs 2.9T 128K 2.9T 1% /zhgstsas4/notshrnotcompr 27 | zhgstsas4/notshrcompr zfs 2.9T 128K 2.9T 1% /zhgstsas4/notshrcompr 28 | zhgstsas4/NEVERLOSE-notshrcompr zfs 2.9T 291M 2.9T 1% /zhgstsas4/NEVERLOSE-notshrcompr 29 | zhgstsas4/BURNME-shrcompr zfs 3.5T 622G 2.9T 18% /zhgstsas4/BURNME-shrcompr 30 | zwd6t/zhgstsas4 zfs 4.4T 128K 4.4T 1% /zwd6t/zhgstsas4 31 | zwd6t/zhgstsas4/BURNME-shrcompr zfs 5.0T 622G 4.4T 13% /zwd6t/zhgstsas4/BURNME-shrcompr 32 | zwd6t/zhgstsas4/NEVERLOSE-notshrcompr zfs 4.4T 291M 4.4T 1% /zwd6t/zhgstsas4/NEVERLOSE-notshrcompr 33 | zwd6t/zhgstsas4/notshrcompr zfs 4.4T 128K 4.4T 1% /zwd6t/zhgstsas4/notshrcompr 34 | zwd6t/zhgstsas4/notshrnotcompr zfs 4.4T 128K 4.4T 1% /zwd6t/zhgstsas4/notshrnotcompr 35 | zwd6t/zhgstsas4/shrcompr zfs 4.5T 101G 4.4T 3% /zwd6t/zhgstsas4/shrcompr 36 | 37 | zsnap=zhgstsas4@Sat 38 | dest=zwd6t 39 | 40 | #(HOST) 41 | time zfs send -L -R -e $zsnap \ 42 | |zfs recv -Fev $dest; date 43 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ansitest 2 | ansible test stuff and root/bin bash scripts 3 | 4 | Thank you for using kneutron sysadmin scripts. If you appreciate them and wish to send some support, please visit: 5 | 6 | https://ko-fi.com/kingneutron 7 | -------------------------------------------------------------------------------- /SMART/. ..: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /SMART/monthly-smart.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Linux version 4 | # to be run every month 17th and 27th ~9:35pm to not conflict with snapshots 5 | 6 | PATH=/sbin:/root/bin:/root/bin/boojum:/usr/local/bin:/usr/local/sbin:/usr/sbin:/bin:/usr/bin:/usr/X11R6/bin 7 | 8 | log=/root/smartlog.log 9 | 10 | mv -vf $log $log--old 11 | 12 | if [ "$1" = "stage2" ]; then 13 | myd=$(date) 14 | 15 | echo "=========================================" |tee -a $log 16 | echo "o BEGIN STAGE2 SMART report: $myd" |tee -a $log 17 | 18 | for i in /dev/sd?;do 19 | drvonly=$(echo $i |awk -F/ '{ print $3 }') # sda 20 | bid=$(ls -l /dev/disk/by-id |grep $drvonly |grep -v part) 21 | 22 | echo $i |tee -a $log 23 | echo "$bid" |tee -a $log 24 | fdisk -l $i |tee -a $log 25 | smartctl -a $i |tee -a $log 26 | done 27 | 28 | echo "=========================================" |tee -a $log 29 | echo "o END STAGE2 SMART report: $myd" |tee -a $log 30 | 31 | # run in BG 32 | smart-shortreport.sh & 33 | 34 | exit 0; # skip test 35 | fi 36 | 37 | # (to syslog) 38 | logger "FYI -- SMART testing of all drives are in progress - see $log" 39 | 40 | echo "=========================================" |tee -a $log 41 | echo "o BEGIN STAGE1 SMART testing: $myd" |tee -a $log 42 | 43 | # SMART testing 44 | for i in /dev/sd?;do 45 | drvonly=$(echo $i |awk -F/ '{ print $3 }') # sda 46 | bid=$(ls -l /dev/disk/by-id |grep $drvonly |grep -v part) 47 | 48 | echo $i |tee -a $log 49 | echo "$bid" |tee -a $log 50 | fdisk -l $i |tee -a $log 51 | smartctl -t long $i |tee -a $log 52 | done 53 | 54 | echo "=========================================" |tee -a $log 55 | 56 | -------------------------------------------------------------------------------- /SMART/osx-get-disk-wwn.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # OSX /dev and /var/run/disk/by-* does not have a concept of WWN IDs so we get it from SMART 4 | #egrep ' /dev|WWN' ~/smartlog-boojum.log 5 | # ^ is a cheat and we can't depend on it existing or being up to date 6 | 7 | # DEPENDS: smartctl being installed from brew or macports 8 | 9 | # NOTE: Pass "1" as arg to print extended disk translation table 10 | 11 | # we want physical disks only or Weird S--t Happens 12 | for d in $(diskutil list |grep phys |awk '{print $1}'); do 13 | wwnid=$(smartctl -i $d |grep WWN |awk '{print "wwn-0x"$5$6$7}') 14 | 15 | [ "$1" = "1" ] && xtd=$(ls -l /var/run/disk/by-serial |grep -w $d |awk '{print $9}') # print extended trans tbl 16 | 17 | if [ "$1" = "1" ]; then 18 | tmp1=$(smartctl -i $d |egrep 'Device Model|Serial Number' |paste - -) 19 | #Device Model: ST4000VN000-2AH166 20 | #Serial Number: WDH0SB 21 | # paste = combine lines 22 | #Device Model: ST4000VN000-2AH166 Serial Number: WDH0SB 23 | # 1 2 3 4 5 6 24 | 25 | # xstd2=${xstd2/Device Model:/} # bash inline sed, replace string with blank 26 | # xstd2=${xstd2/Serial Number:/} # bash inline sed, replace string with blank 27 | xstd2=$(echo "$tmp1" |awk '{print $3"-"$6}') # strip out devmod/ser # dont need replace, just fields + dash 28 | fi 29 | 30 | echo "$d = $wwnid $xtd $xstd2" 31 | done 32 | 33 | exit; 34 | 35 | 36 | linux format /dev/disk/by-id: 37 | wwn-0x50004cf2084c33d0 -> ../../sdi 38 | 39 | osx: 40 | NewerTch__Voyage-WDH0SB = /dev/disk3 41 | LU WWN Device Id: 5 000c50 09d1a789b 42 | ^ raw from SMART 43 | 44 | result of this script: 45 | /dev/disk0 = wwn-0x5000c500380c8768 46 | /dev/disk1 = wwn-0x5002538e00000000 47 | /dev/disk2 = wwn-0x5000c5009d1a789b 48 | 49 | extended table (pass 1 as arg) 50 | /dev/disk0 = wwn-0x5000c500380c8768 ST3500418AS-5VMSTS ST3500418AS-5VMSTS 51 | /dev/disk1 = wwn-0x5002538e00000000 Portable_SSD_T5-S49WNP0N12051 Samsung-T5 52 | /dev/disk2 = wwn-0x5000c5009d1a789b ST4000VN000-2AH166-WDH0SB 53 | 54 | # BUG in high sierra 10.13, disk2 physical only has partitions in DBS and will not -w word match, 55 | # disk3 does match but does not line up with ' diskutil list ' 56 | -------------------------------------------------------------------------------- /SMART/smarttest-wrapper-linux.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # grab dates when smart tests will complete, convert to seconds, sort and display latest time 4 | 5 | PATH=/sbin:/root/bin:/root/bin/boojum:/usr/local/bin:/usr/local/sbin:/usr/sbin:/bin:/usr/bin:/usr/X11R6/bin 6 | 7 | # TODO comment if smart already running 8 | monthly-smart.sh 9 | sleep 2 10 | 11 | sortf=/tmp/smartdates.txt 12 | tmpf=/tmp/smartdates-tmp.txt 13 | sorted=/tmp/smartdates-seconds.txt 14 | # clearit 15 | > $sortf 16 | > $tmpf 17 | > $sorted 18 | 19 | grep 'will complete' ~/smartlog.log > $sortf 20 | 21 | # convert dates to seconds and sort 22 | 23 | OIFS=$IFS 24 | IFS=' 25 | ' 26 | # REF: https://stackoverflow.com/questions/1092631/get-current-time-in-seconds-since-the-epoch-on-linux-bash 27 | for dt in $(awk '{print $6" "$7" "$8" "$9}' $sortf); do 28 | dtos=$(date -d "$dt" +%s) 29 | # echo "$dtos,$dt" |tee -a $tmpf 30 | echo "$dtos,$dt" >> $tmpf 31 | done 32 | 33 | sort -n $tmpf -o $sorted 34 | tail -n 1 $sorted |awk -F',' '{print "Check SMART logs after: "$2}' |tee -a ~/smartlog.log 35 | 36 | # TODO schedule stage2 ~15 minutes after latest (convert to seconds) 37 | nrsecs=$(tail -n 1 $sorted |awk -F',' '{print $1}') 38 | let nrsecs=$nrsecs+900 # add 15 min (15*60) 39 | 40 | ftrdt=$(date --date @"$nrsecs") 41 | # Sun Jan 14 01:34:06 CST 2018 42 | #at -M 43 | 44 | # cleanup 45 | /bin/rm -f $tmpf $sortf 46 | 47 | IFS=$OIFS 48 | 49 | exit; 50 | 51 | 1 2 3 4 5 6 7 8 9 52 | Test will complete after Sun Jan 14 01:17:06 2018 53 | Test will complete after Sat Jan 13 22:59:06 2018 54 | Test will complete after Sat Jan 13 22:55:06 2018 55 | Test will complete after Sat Jan 13 21:33:06 2018 56 | Test will complete after Sun Jan 14 01:19:06 2018 57 | Test will complete after Sat Jan 13 22:11:06 2018 58 | 59 | Check SMART logs after: 01:19:06 60 | 61 | TODO @ xx:xx # monthly-smart.sh stage2; less ~/smartlog-attrib-shortreport.log 62 | -------------------------------------------------------------------------------- /SMART/smarttest-wrapper.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # NOTE this is OSX / MacOS version 4 | # grab dates when smart tests will complete, convert to seconds, sort and display latest time 5 | 6 | PATH=/sbin:/var/root/bin:/var/root/bin/boojum:/root/bin:/root/bin/boojum:/usr/local/bin:/usr/local/sbin:/usr/sbin:/bin:/usr/bin:/usr/X11R6/bin 7 | 8 | # TODO comment if smart already running 9 | monthly-smart.sh 10 | sleep 2 11 | 12 | sortf=/tmp/smartdates.txt 13 | tmpf=/tmp/smartdates-tmp.txt 14 | sorted=/tmp/smartdates-seconds.txt 15 | # clearit 16 | > $sortf 17 | > $tmpf 18 | > $sorted 19 | 20 | grep 'will complete' ~/smartlog.log > $sortf 21 | 22 | # convert dates to seconds and sort 23 | 24 | OIFS=$IFS 25 | IFS=' 26 | ' 27 | # REF: https://stackoverflow.com/questions/1092631/get-current-time-in-seconds-since-the-epoch-on-linux-bash 28 | for dt in $(awk '{print $6" "$7" "$8" "$9}' $sortf); do 29 | dtos=$(date -d "$dt" +%s) 30 | # echo "$dtos,$dt" |tee -a $tmpf 31 | echo "$dtos,$dt" >> $tmpf 32 | done 33 | 34 | sort -n $tmpf -o $sorted 35 | tail -n 1 $sorted |awk -F',' '{print "Check SMART logs after: "$2}' |tee -a ~/smartlog.log 36 | 37 | # TODO schedule stage2 ~15 minutes after latest (convert to seconds) 38 | nrsecs=$(tail -n 1 $sorted |awk -F',' '{print $1}') 39 | let nrsecs=$nrsecs+900 # add 15 min (15*60) 40 | 41 | ftrdt=$(date --date @"$nrsecs") 42 | # Sun Jan 14 01:34:06 CST 2018 43 | #at -M 44 | 45 | # cleanup 46 | /bin/rm -f $tmpf $sortf 47 | 48 | IFS=$OIFS 49 | 50 | exit; 51 | 52 | 1 2 3 4 5 6 7 8 9 53 | Test will complete after Sun Jan 14 01:17:06 2018 54 | Test will complete after Sat Jan 13 22:59:06 2018 55 | Test will complete after Sat Jan 13 22:55:06 2018 56 | Test will complete after Sat Jan 13 21:33:06 2018 57 | Test will complete after Sun Jan 14 01:19:06 2018 58 | Test will complete after Sat Jan 13 22:11:06 2018 59 | 60 | Check SMART logs after: 01:19:06 61 | 62 | TODO @ xx:xx # monthly-smart.sh stage2; less ~/smartlog-attrib-shortreport.log 63 | -------------------------------------------------------------------------------- /VIRTBOX/BKPDEST.mrg: -------------------------------------------------------------------------------- 1 | # bash - this defines where backup tars, etc will be stored 2 | # this lives in /root/bin/boojum - multiple scripts look for it there and source it, so dont do 'exit' at end 3 | 4 | #export bkpdest=/mnt/milterausb3 5 | # if calling script has an override, we still provide value by checking for mount 6 | #[ "$bkpdest" = "" ] && export bkpdest=/mnt/imacdual 7 | #[ "$bkpdest" = "" ] && export bkpdest=/mnt/imac5 ## shared drive 8 | [ "$bkpdest" = "" ] && export bkpdest=/zsg25lap1 9 | # xxx TODO EDITME - should not be same disk as root! 10 | 11 | [ $(echo $bkpdest |grep -c "/mnt/") -gt 0 ] && mount $bkpdest # mount if not ZFS! 12 | [ $(echo $bkpdest |grep -c "/media/") -gt 0 ] && mount $bkpdest # mount if not ZFS! 13 | 14 | # from failexit.mrg 15 | function failexit () { 16 | echo '! Something failed! Code: '"$1 $2" # code # (and optional description) 17 | exit $1 18 | } 19 | 20 | 21 | [ -e "$bkpdest/NOTHERE" ] && failexit 99 "$bkpdest NOTHERE -- NOT MOUNTED" 22 | # "If" checking for NOTHERE file under non-mounted dir... 0ldsk00l hax 23 | 24 | chkmount=$(df |grep -c $bkpdest) 25 | [ $chkmount -gt 0 ] || failexit 99 "$bkpdest NOT MOUNTED" 26 | 27 | # NOTE code 199 is generally could not cd to dir 28 | 29 | export myhn=$(hostname) 30 | -------------------------------------------------------------------------------- /VIRTBOX/STOPALLVMS.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash5 2 | 3 | vbm=VBoxManage 4 | 5 | $vbm list runningvms 6 | 7 | for vm in $($vbm list runningvms |awk '{print $2}' |tr -d '{}'); do 8 | echo "$(date) - Stopping $vm" 9 | $vbm controlvm $vm savestate 10 | sleep 2 # allow disk to catch up a bit 11 | done 12 | 13 | date 14 | -------------------------------------------------------------------------------- /VIRTBOX/bkphome.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # DEPENDS: pv, tar, flist.sh, /root/bin/boojum/BKPDEST.mrg (up to date with valid destination dir) 4 | 5 | source /root/bin/boojum/BKPDEST.mrg # now provides mount test 6 | bkpath=$bkpdest/notshrcompr 7 | 8 | pathh="$bkpath/bkp-home" 9 | mkdir -p -v $pathh 10 | cd $pathh || failexit 199 "! Could not CD to $pathh"; 11 | ls -lh 12 | 13 | bkpdate=$(date +%Y%m%d) 14 | bkpfname="bkp-home--$myhn--NORZ--$bkpdate" 15 | 16 | # free up some space 1st 17 | # http://bashshell.net/utilities/find-with-multiple-expressions/ 18 | # find with OR == works 19 | 20 | #cd $pathh && find $pathh/* -type f -mtime +28 -exec rm {} \; 21 | # !! find bkp-gz and flist files more than 20 days old and delete 22 | # SKIP, shared dir with multiple home sources 23 | #echo 'o Autocleaning old bkps for free space' 24 | #cd $pathh && \ 25 | # find $pathh/* \( -name "bkp*gz" -o -name "bkp*bz2" -o -name "bkp*lzop" -o -name "flist*" \) -type f -mtime +20 -exec /bin/rm -v {} \; 26 | 27 | echo "==Backing up HOME to $pathh" 28 | df -hT /home $bkpdest 29 | 30 | # comprdest 31 | time tar \ 32 | -cpf - /home/* \ 33 | | pv -t -r -b -W -i 2 -B 50M \ 34 | > $bkpfname.tar 35 | # | lzop \ 36 | # > $bkpfname.tar.lzop 37 | 38 | ls -lh 39 | pwd 40 | #echo $pathh 41 | 42 | # fire off in BG 43 | flist.sh & 44 | #time tar tzvf $bkpfname.tar1.gz > flist--$bkpfname.txt & 45 | 46 | echo "$0 done - $(date)" 47 | -------------------------------------------------------------------------------- /VIRTBOX/debian-fix-low-ram.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Unload modules + daemons for low RAM - debian/devuan 4 | free -h 5 | 6 | service apparmor stop 7 | service bluetooth stop 8 | service brltty stop 9 | service cups stop 10 | service cups-browsed stop 11 | service exim4 stop 12 | service gpm stop 13 | service saned stop 14 | 15 | 16 | modprobe -r bluetooth 17 | modprobe -r parport_pc 18 | modprobe -r ppdev 19 | modprobe -r lp 20 | modprobe -r parport 21 | modprobe -r joydev 22 | modprobe -r pcspkr 23 | modprobe -r serio_raw 24 | 25 | lsmod 26 | (service --status-all 2>&1) |grep + 27 | 28 | free -h -------------------------------------------------------------------------------- /VIRTBOX/faildisk.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # arg = shortname disk e.g. sdc , omit the /dev 3 | 4 | # Primarily used in ZFS VM to simulate disk failures in a zpool / test RAIDZx / DRAID recovery scenarios 5 | # NOTE rebooting will fix the failed disks 6 | 7 | echo "Failing $1" 8 | echo offline > /sys/block/$1/device/state 9 | echo 1 > /sys/block/$1/device/delete 10 | 11 | sleep 2 12 | dmesg|grep $1 13 | -------------------------------------------------------------------------------- /VIRTBOX/mkrestoredvdiso-osx.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # mod for osx 2019.0818 4 | # make a restore DVD from .fsarchive + restore script(s) 5 | # NOTE this does not need to be run as root 6 | # NOTE mkisofs is BROKEN on osx (macports and brew) 7 | # REF: https://www.makeuseof.com/tag/how-to-create-windows-compatible-iso-disc-images-in-mac-os-x/ 8 | # REF: http://osxdaily.com/2012/03/16/create-iso-images-from-the-command-line/ 9 | 10 | # this is where the .fsarchive backup + restore scripts live, pass as arg 11 | d2b="$1" 12 | cd "$d2b" 13 | 14 | ls -alh 15 | pwd 16 | 17 | echo "$(date) - Writing UDF ISO from $d2b to $HOME - PK:" 18 | #read 19 | 20 | hdiutil makehybrid -verbose -iso -joliet -udf -print-size "$d2b" 21 | echo "Sawright?" 22 | #read -n 1 23 | 24 | time hdiutil makehybrid -verbose -iso -joliet -udf -o $HOME/restoreUDF.iso "$d2b" 25 | chmod a+rx $HOME/restoreUDF.iso 26 | 27 | ls -lh $HOME/restoreUDF.iso 28 | 29 | exit; 30 | 31 | 32 | #mkisofs -r -f -U -v -o - * \ 33 | 34 | isopts="-iso-level 3 -J -joliet-long -r -T -v " 35 | #isopts="-iso-level 3 -T -v " 36 | 37 | # how big willit be 38 | mkisofs $isopts -udf -print-size * 39 | echo Sawright? 40 | read -n 1 41 | 42 | time \ 43 | mkisofs -iso-level 3 -allow-lowercase -d -D -f -J -joliet-long -max-iso9660-filenames -N -r -T -udf -v \ 44 | -o $HOME/restoreUDF.iso * 45 | 46 | chown dave /home/restoreUDF.iso 47 | chmod a+rx /home/restoreUDF.iso 48 | 49 | ls -lh $HOME/*.iso 50 | -------------------------------------------------------------------------------- /VIRTBOX/mkrestoredvdiso.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Linux version 4 | # make a restore DVD from .fsarchive bare-metal backup + restore script(s): RESTORE-fsarchive-root.sh // and/or to-XFS version 5 | # mount the resulting ISO in a systemrescuecd environment on 2nd dvd drive 6 | 7 | # xxx TODO editme 8 | user=dave 9 | outfile=/home/$user/restoreUDF.iso 10 | 11 | # This is where the fsarchive backup and restore script lives, pass as parm 12 | d2b="$1" 13 | cd "$d2b" 14 | 15 | ls -alh 16 | pwd 17 | 18 | echo "Creating UDF ISO from $d2b ..." #PK: 19 | #read 20 | 21 | # how big willit be 22 | mkisofs -d -D -f -l -J -N -r -T -v -print-size * 23 | echo Sawright? 24 | #read 25 | 26 | time \ 27 | mkisofs -allow-lowercase -apple -d -D -f -l -J -joliet-long -max-iso9660-filenames -N -r -R -T -udf -v \ 28 | -o $outfile * 29 | 30 | chown $user $outfile 31 | chmod a+rx $outfile 32 | 33 | ls -lh /home/$user/*.iso 34 | 35 | exit; 36 | 37 | # 2021 Dave Bechtel 38 | -------------------------------------------------------------------------------- /VIRTBOX/vb-change-HD-uuid.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # REF: https://stackoverflow.com/questions/44114854/virtualbox-cannot-register-the-hard-disk-already-exists 4 | # use $PWD/name.vdi if needed 5 | VBoxManage internalcommands sethduuid "$1" 6 | -------------------------------------------------------------------------------- /VIRTBOX/vb-convert-vmdk.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | echo "o NOTE .vmdk must be removed from VM 1st!!" 4 | 5 | # REF: https://nfolamp.wordpress.com/2010/06/10/converting-vmdk-files-to-vdi-using-vboxmanage/ 6 | 7 | #VBoxManage clonehd --format VDI myserver.vmdk \ 8 | # VirtualBox/HardDisks/myserver.vdi 9 | 10 | outdir=/Volumes/tmpdel/vmdisks 11 | mkdir -pv $outdir 12 | 13 | time VBoxManage clonehd --format VDI "$1" $outdir/"$1.to.vdi" 14 | ls -alh $outdir/* 15 | date 16 | 17 | -------------------------------------------------------------------------------- /VIRTBOX/vb-discover-virtmachines.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Discover existing virtualbox vms and add them to the GUI 4 | # If GUI is already running, they should populate in realtime 5 | 6 | # REF: https://www.virtualbox.org/manual/ch08.html#vboxmanage-general 7 | 8 | #source ~/bin/failexit.mrg 9 | # failexit.mrg 10 | function failexit () { 11 | echo '! Something failed! Code: '"$1 $2" # code # (and optional description) 12 | exit $1 13 | } 14 | 15 | vbm=$(which VBoxManage) 16 | 17 | function discregis () { 18 | find . -name *.vbox -type f -exec $vbm registervm "$PWD/{}" \; 19 | } 20 | 21 | # xxx TODO EDITME put your VM directory here 22 | cd /Volumes/zsgtera4/virtbox-virtmachines || failexit 101 "! Cannot cd to VM dir" 23 | discregis 24 | 25 | # 2ndary VM dir 26 | #cd /zdell500/virtbox-virtmachines || failexit 102 "! Cannot cd to VM dir" 27 | #discregis 28 | 29 | 30 | VBoxManage list vms 31 | 32 | echo "PK to call vb-registerISOs.sh, or ^C to skip" 33 | read -n 1 34 | vb-registerISOs.sh 35 | 36 | exit; 37 | 38 | # 2021 Dave Bechtel -------------------------------------------------------------------------------- /VIRTBOX/vb-registerISOs.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # This is a nice little hack to create a dummy VM and attach known ISOs to it to populate Media Manager 4 | # REF: http://www.allgoodbits.org/articles/view/54 5 | # REF: https://superuser.com/questions/741734/virtualbox-how-can-i-add-mount-a-iso-image-file-from-command-line 6 | 7 | vmname=dummyisofinder 8 | 9 | VBoxManage createvm --name "$vmname" --ostype 'Linux_64' --basefolder "$HOME" --register 10 | VBoxManage modifyvm "$vmname" --description "NOTE this is just a temp VM used to conveniently register ISOs with vbox media manager - it was created with $0" 11 | 12 | VBoxManage storagectl $vmname --name IDE --add ide --controller piix3 --portcount 2 --bootable on 13 | #VBoxManage storageattach "$vmname" --storagectl IDE --port 0 --device 0 --type dvddrive --medium emptydrive #"X:\Folder\containing\the.iso" 14 | #VBoxManage showvminfo "$vmname" 15 | 16 | function registeriso () { 17 | for this in *.iso; do 18 | echo $PWD/${this} 19 | VBoxManage storageattach "$vmname" --storagectl IDE --port 0 --device 0 --type dvddrive --medium $PWD/${this} 20 | # VBoxManage modifyvm $vmname --dvd $PWD/${this} 21 | done 22 | } 23 | 24 | # xxx TODO EDITME, this is where your ISOs live 25 | cd /Volumes/zsgtera4/shrcompr-zsgt2B/ISO && registeriso 26 | 27 | # shared drive, use if mounted 28 | if [ $(df |grep /mnt/imac5 |wc -l) -gt 0 ]; then 29 | cd /mnt/imac5/ISO 30 | registeriso 31 | fi 32 | 33 | # eject 34 | VBoxManage storageattach "$vmname" --storagectl IDE --port 0 --device 0 --type dvddrive --medium emptydrive 35 | 36 | exit; 37 | 38 | # 2021 Dave Bechtel 39 | -------------------------------------------------------------------------------- /VIRTBOX/vb-resize-disk.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | date 4 | time VBoxManage modifymedium disk "$1" --resize "$2" 5 | date 6 | -------------------------------------------------------------------------------- /VIRTBOX/vb-virtmedia-cleanup.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # cleanup inaccessible disks in VMM 4 | vboxmanage list hdds > /tmp/vbox-hds-all.txt 5 | 6 | vboxmanage list hdds |grep -B 2 'State: inaccessible' \ 7 | |egrep -v 'Parent|State|--' >/tmp/infile-vboxdel.txt 8 | #zfs-SAS-T5-12*.vdi > /tmp/infile.txt 9 | 10 | #set -x 11 | while read line; do 12 | delme=$(echo "$line" |awk '{print $2}') 13 | echo "$delme" >> /tmp/vbox-hd-inacc-del.log 14 | 15 | vboxmanage closemedium disk "$delme" --delete 16 | done < /tmp/infile-vboxdel.txt 17 | 18 | date; 19 | -------------------------------------------------------------------------------- /VIRTBOX/vbox-attach-existing-disk.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # REF:https://serverfault.com/questions/171665/how-to-attach-a-virtual-hard-disk-using-vboxmanage 4 | 5 | # VBoxManage storageattach my-vm-name \ 6 | # --storagectl "SATA Controller" \ 7 | # --device 0 \ 8 | # --port 0 \ 9 | # --type hdd \ 10 | # --medium /path/to/my-new.vdi 11 | 12 | VBoxManage list vms 13 | echo 'Paste vmname' 14 | read myvmname 15 | 16 | # EDITME 17 | diskk="" 18 | 19 | VBoxManage storageattach $myvmname \ 20 | --storagectl "SATA" \ 21 | --device 0 \ 22 | --port 0 \ 23 | --type hdd \ 24 | --medium $diskk 25 | -------------------------------------------------------------------------------- /VIRTBOX/vbox-cleanup-vms.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash5 2 | 3 | # useful if backing store changed, get rid of inacc vms 4 | 5 | # vbm unregistervm 6 | vmallfile=/tmp/vbox-allvms.txt 7 | #vmrunningfile=/tmp/vbox-running.txt 8 | 9 | debugg=0 10 | vbm=VBoxManage 11 | 12 | logfile=$HOME/vbox-unregistered-vms.log 13 | 14 | # failexit.mrg 15 | # REF: https://sharats.me/posts/shell-script-best-practices/ 16 | function failexit () { 17 | echo '! Something failed! Code: '"$1 $2" >&2 # code (and optional description) 18 | exit $1 19 | } 20 | 21 | # define array 22 | declare -a vmlist 23 | declare -a runningvms 24 | 25 | vmlist=$($vbm list vms |grep inaccessible |tr -d '<>{}\"' |column -t) 26 | #"" {e54ed6b4-c464-46a7-9d34-8c429b932edc} 27 | #inaccessible e54ed6b4-c464-46a7-9d34-8c429b932edc 28 | 29 | #dummyisofinder e15815e6-6be7-4628-9093-bbadbf4ec6f7 30 | 31 | #echo "All VMs" 32 | #echo "$vmlist" |tee $vmallfile 33 | echo "$vmlist" > $vmallfile 34 | 35 | runningvms=$($vbm list runningvms |tr -d '{}\"' |column -t) 36 | echo "o Running: " 37 | echo "$runningvms" |tee $vmrunningfile 38 | 39 | cat $vmallfile 40 | echo "Found these vms that need to be cleaned up - PK or ^C" 41 | read 42 | 43 | declare -i result=0 44 | # REF:https://www.virtualbox.org/ticket/17215 45 | while read vmname vmuuid; do 46 | echo "Vmname $vmname - UUID $vmuuid" 47 | 48 | result=$(grep -c $vname $vmrunningfile) 2>/dev/null 49 | if [ $result -gt 0 ]; then 50 | echo "VM already running" 51 | else 52 | echo "$(date) - Unregistering ${vmuuid} as inacessible" |tee -a $logfile 53 | 54 | $vbm unregistervm ${vmuuid} || failexit 101 "Failed to unregister $vmuuid" 55 | fi 56 | # call external bin 57 | done < $vmallfile 58 | 59 | date 60 | echo "Recommended to run vb-discover-virtmachines.sh and vb-registerISOs.sh now" 61 | -------------------------------------------------------------------------------- /VIRTBOX/vbox-delay-boot.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # REF: https://blog.jasonantman.com/2012/04/adjusting-the-virtualbox-f12-bios-boot-prompt-timeout/ 4 | 5 | VBoxManage list vms 6 | 7 | vmname="$1" 8 | VBoxManage modifyvm "$vmname" --bioslogodisplaytime 10000 9 | -------------------------------------------------------------------------------- /VIRTBOX/vbox-discover-vms.ps1: -------------------------------------------------------------------------------- 1 | <# Discover virtualbox vms in dir and add them to gui #> 2 | <# 2023.Nov kingneutron #> 3 | <# Adapted from bash code #> 4 | 5 | # TODO EDITME for where your VMs live 6 | D: 7 | cd virtbox-vms 8 | 9 | $vbm="C:\Program Files\Oracle\VirtualBox\vboxmanage.exe" 10 | $result=get-childitem -Recurse *.vbox 11 | 12 | # $result.fullname 13 | # D:\virtbox-vms\almalinux-test-centos-replacement-rhel8\almalinux-test-centos-replacement-rhel8.vbox 14 | 15 | foreach ($thisvm in $result.fullname) { 16 | Write-Output $thisvm 17 | & $vbm registervm $thisvm 18 | 19 | } 20 | 21 | & $vbm list vms 22 | get-date 23 | Write-Output "Recommended to run vbox-registerISOs now" 24 | 25 | <# 26 | $result 27 | Directory: D:\virtbox-vms\XPvm 28 | 29 | Mode LastWriteTime Length Name 30 | ---- ------------- ------ ---- 31 | -a--- 4/6/2023 2:39 PM 11447 XPvm.vbox 32 | #> -------------------------------------------------------------------------------- /VIRTBOX/vbox-install-extpack.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | ls Oracle_VM_VirtualBox_Extension* 4 | 5 | if [ "$1" = "" ]; then 6 | echo 'o Enter which one to install' 7 | read instme 8 | else 9 | instme="$1" 10 | fi 11 | 12 | VBoxManage extpack install --replace "$instme" # [--accept-license=sha256] -------------------------------------------------------------------------------- /VIRTBOX/vbox-list-all-snapshots.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash5 2 | 3 | result=$(VBoxManage list vms) 4 | 5 | # do it by GUID 6 | for vm in $( VBoxManage list vms |awk '{print $2}' |tr -d '{}'); 7 | do echo "$result" |grep $vm 8 | VBoxManage snapshot $vm list --machinereadable 9 | echo '' 10 | done 11 | 12 | exit; 13 | 14 | "centos7-testvm-LVMpartresize" {7ed11c65-9fa2-43b2-811e-6295f172506c} 15 | SnapshotName="Snapshot 4 - b4 script" 16 | SnapshotUUID="1c8013c2-fe09-46ae-b6fd-415038315511" 17 | SnapshotName-1="Snapshot - wiped btrfs on sdb3 and fixed vgname" 18 | SnapshotUUID-1="d51d5f42-0353-4ed3-841a-e7de66061c1e" 19 | SnapshotName-1-1="Snapshot - wiped btrfs on b3, fixed swap uuid" 20 | SnapshotUUID-1-1="c449b5de-96a0-4e66-b6f1-6d3f842f19b1" 21 | SnapshotName-1-1-1="Snapshot - finalizing code, b4 script run" 22 | SnapshotUUID-1-1-1="3f1da271-da20-44ed-9d1c-33aa9bcb50e4" 23 | SnapshotName-1-1-1-1="Snapshot - finalizing code" 24 | SnapshotUUID-1-1-1-1="cd2a4d75-3754-4aab-8b8d-d2a361f1d456" 25 | CurrentSnapshotName="Snapshot - finalizing code" 26 | CurrentSnapshotUUID="cd2a4d75-3754-4aab-8b8d-d2a361f1d456" 27 | CurrentSnapshotNode="SnapshotName-1-1-1-1" 28 | 29 | "p2v-imac5-ubuntu1804firewire" {39d78e39-3d04-486e-a61d-10a7e4755657} 30 | This machine does not have any snapshots 31 | -------------------------------------------------------------------------------- /VIRTBOX/vbox-make-rawdisk.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # EDITME - diskutil list 1st 4 | 5 | # REF: https://www.serverwatch.com/server-tutorials/using-a-physical-hard-drive-with-a-virtualbox-vm.html 6 | # REF: https://apple.stackexchange.com/questions/192292/how-to-do-raw-device-access-with-virtualbox 7 | 8 | # REF: https://digitalsprouts.org/using-raw-disk-access-with-virtualbox-in-mac-os/ 9 | 10 | # NOTE - eject/umount diskXsX 1st! 11 | # NOTE - may need to chown $USER or :admin /dev/diskX 1st 12 | 13 | usedev=disk6 14 | 15 | diskutil list /dev/$usedev 16 | 17 | sudo chown root:admin /dev/$usedev 18 | sudo chmod 660 /dev/$usedev 19 | 20 | ls -al /dev/$usedev 21 | VBoxManage internalcommands createrawvmdk -rawdisk /dev/$usedev -filename "$HOME/vbox-raw-sgtera2tb.vmdk" 22 | ls -l ~/*.vmdk 23 | -------------------------------------------------------------------------------- /VIRTBOX/vbox-registerISOs-2dirs.ps1: -------------------------------------------------------------------------------- 1 | <# Register known ISOs to virtualbox media manager #> 2 | <# 2023.Nov kingneutron #> 3 | <# Adapted from bash code #> 4 | <# dont know why, but the Samba mount dir currently doesnt work #> 5 | 6 | $vmname="dummyisofinder" 7 | 8 | # xxx TODO EDITME 9 | $vmdir="D:\virtbox-vms" 10 | $isodir="D:\ISO" 11 | $isodir2="Z:\ISO" # NAS / network mount 12 | 13 | $vbm="C:\Program Files\Oracle\VirtualBox\vboxmanage.exe" 14 | 15 | & $vbm createvm --name "$vmname" --ostype 'Linux_64' --basefolder "$vmdir" --register 16 | & $vbm modifyvm "$vmname" --description "NOTE this is just a temp VM used to conveniently register ISOs" 17 | 18 | & $vbm storagectl "$vmname" --name IDE --add ide --controller piix3 --portcount 2 --bootable on 19 | #VBoxManage storageattach "$vmname" --storagectl IDE --port 0 --device 0 --type dvddrive --medium emptydrive #"X:\Folder\containing\the.iso" 20 | #VBoxManage showvminfo "$vmname" 21 | 22 | cd $isodir 23 | 24 | # Define complex array 25 | $result=[System.Collections.ArrayList]@() 26 | 27 | $result=get-childitem -Recurse *.iso 28 | 29 | cd $isodir2 30 | $result+=get-childitem -Recurse *.iso 31 | 32 | Write-Output $result.fullname 33 | # brkpt 34 | 35 | foreach ($thisiso in $result.FullName) { 36 | Write-Output "$thisiso" 37 | & $vbm storageattach "$vmname" --storagectl IDE --port 0 --device 0 --type dvddrive --medium "$thisiso" 38 | # VBoxManage modifyvm $vmname --dvd $PWD/${this} 39 | } 40 | 41 | # eject 42 | & $vbm storageattach "$vmname" --storagectl IDE --port 0 --device 0 --type dvddrive --medium emptydrive 43 | -------------------------------------------------------------------------------- /VIRTBOX/vbox-registerISOs.ps1: -------------------------------------------------------------------------------- 1 | <# Register known ISOs to virtualbox media manager #> 2 | <# 2023.Nov kingneutron #> 3 | <# Adapted from bash code #> 4 | 5 | $vmname="dummyisofinder" 6 | 7 | # xxx TODO EDITME 8 | $vmdir="D:\virtbox-vms" 9 | $isodir="D:\ISO" 10 | 11 | $vbm="C:\Program Files\Oracle\VirtualBox\vboxmanage.exe" 12 | 13 | & $vbm createvm --name "$vmname" --ostype 'Linux_64' --basefolder "$vmdir" --register 14 | & $vbm modifyvm "$vmname" --description "NOTE this is just a temp VM used to conveniently register ISOs" 15 | 16 | & $vbm storagectl "$vmname" --name IDE --add ide --controller piix3 --portcount 2 --bootable on 17 | #VBoxManage storageattach "$vmname" --storagectl IDE --port 0 --device 0 --type dvddrive --medium emptydrive #"X:\Folder\containing\the.iso" 18 | #VBoxManage showvminfo "$vmname" 19 | 20 | cd $isodir 21 | $result=get-childitem -Recurse *.iso 22 | 23 | foreach ($thisiso in $result.FullName) { 24 | Write-Output $thisiso 25 | & $vbm storageattach "$vmname" --storagectl IDE --port 0 --device 0 --type dvddrive --medium $thisiso 26 | # VBoxManage modifyvm $vmname --dvd $PWD/${this} 27 | } 28 | 29 | # eject 30 | & $vbm storageattach "$vmname" --storagectl IDE --port 0 --device 0 --type dvddrive --medium emptydrive 31 | -------------------------------------------------------------------------------- /VIRTBOX/vbox-reown-usb-rawdisk.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | mydisk=/dev/disk1 4 | myuser=dave 5 | 6 | sudo chown -R $myuser $mydisk* 7 | diskutil unmount $mydisk''s1 8 | 9 | ls -al /dev/disk* 10 | -------------------------------------------------------------------------------- /VIRTBOX/vbox-resizehd.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | time VBoxManage modifyhd $1.vdi --resize $2 # size in MB 4 | 5 | -------------------------------------------------------------------------------- /VIRTBOX/vbox-wheredoesvmlive.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | VBoxManage list --long -s vms |egrep 'Name:|Config file:' |egrep -v 'Snap|Filter' |paste - - 4 | # Note GUI setting = rt-click on right pane, General / Location √ 5 | -------------------------------------------------------------------------------- /ZFS/boojum-expand-raidz.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 2025.Jan kneutron 4 | # Expand raidz with 1-2 disks for more free space 5 | 6 | echo "o NOTE zfs-2.3.0-1 or higher is required!" 7 | zfs -V 8 | 9 | # checkver 10 | # zfs -V |head -n 1 |tr -d 'zfs-' |tr -d '.-' 11 | #2301 12 | 13 | # xxx TODO EDITME 14 | usedisk=vdg 15 | #usedisk=vdh # 2nd run, comment above and uncomment thisline 16 | zp=zraidzexpandtest 17 | 18 | # zpool attach tank raidz1-0 sda 19 | # REF: https://github.com/openzfs/zfs/pull/15022 20 | # REF: https://arstechnica.com/gadgets/2021/06/raidz-expansion-code-lands-in-openzfs-master/ 21 | 22 | zpool status -v |awk 'NF>0' 23 | 24 | echo '=====' 25 | echo "Enter to proceed expanding $zp with disk $usedisk / $(ls -l /dev/disk/by-path |grep $usedisk |head -n 1 |awk '{print $9}')" 26 | read -n 1 27 | 28 | time zpool attach $zp raidz1-0 $usedisk 29 | echo "Enter to watch resilver or ^C" 30 | read 31 | zfs-watchresilver-boojum.sh 32 | 33 | date 34 | -------------------------------------------------------------------------------- /ZFS/boojum-expand-raidz2.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 2025.Jan kneutron 4 | # Expand raidz2 with 1-2 disks for more free space 5 | 6 | # NOTE zfs-2.3.0-1 or higher is required! 7 | 8 | # xxx TODO EDITME 9 | usedisk=vdo 10 | #usedisk=vdp # 2nd run, comment above line and uncomment thisline 11 | zp=zraidz2expandtest 12 | 13 | # zpool attach tank raidz2-0 sda 14 | # REF: https://github.com/openzfs/zfs/pull/15022 15 | # REF: https://arstechnica.com/gadgets/2021/06/raidz-expansion-code-lands-in-openzfs-master/ 16 | 17 | zpool status -v |awk 'NF>0' 18 | 19 | echo '=====' 20 | echo "Enter to proceed expanding $zp with disk $usedisk / $(ls -l /dev/disk/by-path |grep $usedisk |head -n 1 |awk '{print $9}')" 21 | echo " or ^C to stop" 22 | read -n 1 23 | 24 | time zpool attach $zp raidz2-0 $usedisk 25 | #echo "PK to watch resilver" 26 | #read 27 | zfs-watchresilver-boojum.sh $zp 28 | 29 | date 30 | -------------------------------------------------------------------------------- /ZFS/clearcache.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # free up cache RAM 4 | # http://linux-mm.org/Drop_Caches 5 | 6 | free 7 | time sync 8 | 9 | echo 1 > /proc/sys/vm/drop_caches # free pagecache 10 | free 11 | 12 | #To free dentries and inodes: 13 | [ "$*" = "2" ] && echo 2 > /proc/sys/vm/drop_caches 14 | 15 | #To free pagecache, dentries and inodes: 16 | [ "$*" = "3" ] && echo 3 > /proc/sys/vm/drop_caches 17 | #echo 3 > /proc/sys/vm/drop_caches 18 | -------------------------------------------------------------------------------- /ZFS/drive-slicer-get-longform.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 2021 Dave Bechtel 4 | # REQUIRES output file from zfs-drive-slicer.sh, sed, awk, grep, head 5 | 6 | # Translate short-form disks 7 | #sdb sdc sdd sde sdf sdg sdh sdi sdj sdk sdl 8 | # To long-form: 9 | #pci-0000:00:16.0-sas-phy0-lun-0 pci-0000:00:16.0-sas-phy1-lun-0 pci-0000:00:16.0-sas-phy2-lun-0 pci-0000:00:16.0-sas-phy3-lun-0 pci-0000:00:16.0-sas-phy4-lun-0 pci-0000:00:16.0-sas-phy5-lun-0 pci-0000:00:16.0-sas-phy6-lun-0 pci-0000:00:16.0-sas-phy7-lun-0 pci-0000:00:16.0-sas-phy8-lun-0 pci-0000:00:16.0-sas-phy9-lun-0 pci-0000:00:16.0-sas-phy10-lun-0 10 | 11 | # Useful when creating ZFS arrays 12 | # Pseudocode: 13 | # get zfs-drive-slicer output file 14 | # use sed to delete line cont chars out 15 | # read a line 16 | ## for every word in line; lookup + print dev/disk/by-path equivalent no-newline 17 | # at line end print line continuation char 18 | 19 | DBP=/dev/disk/by-path 20 | DBI=/dev/disk/by-id 21 | usetype=$DBP 22 | # ^^ TODO EDITME 23 | 24 | # NOTE WARNING when using SAS disks we are NOT guaranteed an entry in disk-by-id! 25 | 26 | infile=/tmp/zfsds.txt 27 | [ "$1" = "" ] || infile="$1" # override, if 1st arg passed 28 | 29 | sed -i 's/\\//g' "$infile" # remove line-continuation chars 30 | 31 | # set -x ## DEBUG 32 | while read inline; do 33 | for word in $inline; do 34 | printf $(ls -l $usetype |grep -w /$word |awk '{print $9}' |head -n 1)" " 35 | done 36 | echo ' \' 37 | done < $infile 38 | # NOTE ^^ this may be inaccurate, no error checking for missing disks, just print what we find 39 | 40 | #lrwxrwxrwx 1 root root 9 Jul 12 23:10 pci-0000:00:16.0-sas-phy9-lun-0 -> ../../sdk 41 | # 1 2 3 4 5 j 7 8 9 42 | -------------------------------------------------------------------------------- /ZFS/fix-zfs-compile.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # REF: https://github.com/openzfs/zfs/issues/9935 4 | # Fix compile issues on Debian 5 | 6 | # arg1=kernel ver e.g. 4.19.9 7 | cd /usr/src/linux-headers-$1-common/include/linux 8 | td=$PWD; [ "$td" = "" ] && exit 404; 9 | 10 | cd /usr/src/linux-headers-$1-amd64/include && \ 11 | ln -sfn $td . 12 | 13 | ls -alh 14 | -------------------------------------------------------------------------------- /ZFS/install-samba.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | apt install samba smbclient cifs-utils 4 | 5 | exit; 6 | 7 | The following additional packages will be installed: 8 | attr ibverbs-providers libboost-atomic1.67.0 libboost-iostreams1.67.0 libboost-regex1.67.0 libboost-system1.67.0 9 | libboost-thread1.67.0 libcephfs2 libgfapi0 libgfrpc0 libgfxdr0 libglusterfs0 libibverbs1 librados2 libtirpc-common 10 | libtirpc3 python-crypto python-dnspython python-gpg python-ldb python-samba python-tdb samba-common 11 | samba-common-bin samba-dsdb-modules samba-vfs-modules tdb-tools 12 | Suggested packages: 13 | keyutils winbind python-crypto-doc bind9 bind9utils ctdb ldb-tools ntp | chrony smbldap-tools ufw heimdal-clients 14 | The following NEW packages will be installed: 15 | attr cifs-utils ibverbs-providers libboost-atomic1.67.0 libboost-iostreams1.67.0 libboost-regex1.67.0 16 | libboost-system1.67.0 libboost-thread1.67.0 libcephfs2 libgfapi0 libgfrpc0 libgfxdr0 libglusterfs0 libibverbs1 17 | librados2 libtirpc-common libtirpc3 python-crypto python-dnspython python-gpg python-ldb python-samba python-tdb 18 | samba samba-common samba-common-bin samba-dsdb-modules samba-vfs-modules smbclient tdb-tools 19 | 0 upgraded, 30 newly installed, 0 to remove and 0 not upgraded. 20 | Need to get 21.4 MB of archives. 21 | After this operation, 81.4 MB of additional disk space will be used. 22 | Do you want to continue? [Y/n] ^C 23 | -------------------------------------------------------------------------------- /ZFS/mkgpt.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # DEPENDS: smartctl, parted, fdisk 4 | 5 | echo "Parameter: Supply short device name [sdb], etc" 6 | echo "MAKE SURE you supply the right disk device - author takes NO RESPONSIBILITY for data loss!" 7 | echo "Use at your own risk!" 8 | argg=$1 9 | 10 | [ $(which parted |wc -l) -gt 0 ] || apt-get install -y parted 11 | 12 | #source ~/bin/failexit.mrg 13 | # failexit.mrg 14 | function failexit () { 15 | echo '! Something failed! Code: '"$1 $2" # code # (and optional description) 16 | exit $1 17 | } 18 | 19 | 20 | smartctl -a /dev/$argg |head -n 16 21 | fdisk -l /dev/$argg 22 | 23 | ls -l /dev/disk/by-id |grep $argg 24 | 25 | echo "THIS WILL DESTRUCTIVELY APPLY A GPT LABEL to /dev/$argg - ARE YOU SURE - Enter to proceed OR ^C" 26 | read 27 | 28 | parted -s /dev/$argg mklabel gpt || failexit 99 "! Failed to apply GPT label to /dev/$argg" 29 | 30 | fdisk -l /dev/$argg 31 | 32 | exit; 33 | -------------------------------------------------------------------------------- /ZFS/mkzfsraid10.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Example create 4-drive mirror pool, create and chown a samba shared dataset and associated userid for it 4 | # userid needs to exist (useradd/adduser) first 5 | 6 | zp=zsgtera4compr 7 | 8 | zpool create -f -o ashift=12 -o autoexpand=on -O atime=off -O compression=lz4 $zp \ 9 | mirror ata-ST4000VN000-1H4168_Z3073Z29 ata-ST4000VN000-1H4168_Z306G0K3 \ 10 | mirror ata-ST4000VN000-1H4168_Z3073ZAY ata-ST4000VN000-1H4168_Z306G7H8 11 | 12 | pdir=dave; zfs create -o atime=off -o sharesmb=on $zp/$pdir; chown $pdir:dave /$zp/$pdir 13 | ls -al /$pname/$pdir 14 | 15 | zpool status 16 | 17 | (set -r 18 | smbpasswd -a $pdir 19 | ) 20 | 21 | -------------------------------------------------------------------------------- /ZFS/mon1.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # for 1440x900 4 | # Useful to monitor I/O for ZFS 96 disks 5 | 6 | # For icewm all-desktops - see ~/.icewm/winoptions 7 | #http://www.osnews.com/story.php/7774/IceWM--The-Cool-Window-Manager/page5/ 8 | 9 | # Setup 3 xxterms for monitoring on 2ndary scrn 10 | # Used ' xwininfo ' to get geom 11 | # Occupy-all 12 | 13 | xterm -bg black -fg green -sl 1 -rightbar -geometry 87x29+0+0 \ 14 | -name montop \ 15 | -e top -d 7& 16 | 17 | 18 | xterm -bg black -fg green -rightbar -geometry 104x29-0-33 \ 19 | -name mondf \ 20 | -e "watch -n 61 'df -T -h |grep -v tmpfs'" & 21 | 22 | 23 | # 4MAC 24 | xterm -bg black -fg green -rightbar -geometry 61x24+1092+0 \ 25 | -name mac-tempwatch \ 26 | -e ~/bin/mac-tempwatch.sh & 27 | 28 | # switch to virtual desktop #2 29 | sleep 1; wmctrl -s 1; mon96.sh 30 | -------------------------------------------------------------------------------- /ZFS/mon96.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 2021 Dave Bechtel 4 | # for 1440x900 5 | 6 | # Setup 4 xterms for monitoring I/O for (90) drives 7 | # Used ' xwininfo ' to get geom 8 | # Occupy-all 9 | 10 | cmdstr="iostat -k 5 --dec=0 -y -z sd{a..z}" 11 | xterm -bg black -fg green -sl 2000 -rightbar -geometry 72x33+0+31 \ 12 | -name IOSTAT \ 13 | -e "$cmdstr" & 14 | 15 | cmdstr="iostat -k 5 --dec=0 -y -z sda{a..z}" 16 | xterm -bg black -fg green -sl 2000 -rightbar -geometry 72x33+0-0 \ 17 | -name IOSTAT \ 18 | -e "$cmdstr" & 19 | 20 | cmdstr="iostat -k 5 --dec=0 -y -z sdb{a..z}" 21 | xterm -bg black -fg green -sl 2000 -rightbar -geometry 72x33-0+31 \ 22 | -name IOSTAT \ 23 | -e "$cmdstr" & 24 | 25 | cmdstr="iostat -k 5 --dec=0 -y -z sdc{a..z}" 26 | xterm -bg black -fg green -sl 2000 -rightbar -geometry 72x33-0-0 \ 27 | -name IOSTAT \ 28 | -e "$cmdstr" & 29 | 30 | 31 | cmdstr='bwm 2' # Check for bwm-ng and use it if there 32 | [ -e /usr/bin/bwm-ng ] && cmdstr='bwm-ng -t 2000' 33 | xterm -bg black -fg green -sl 1 -rightbar -geometry 80x13+536+0 \ 34 | -name monbwm \ 35 | -e $cmdstr & 36 | 37 | cmdstr="watch -n 5 /sbin/zpool status -v|awk 'NF>0'" 38 | xterm -bg black -fg green -sl 1 -rightbar -geometry 92x57+434-28 \ 39 | -name zps \ 40 | -e $cmdstr & 41 | -------------------------------------------------------------------------------- /ZFS/mount-zvol-partitioned-as-disk.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # TODO EDITME do not run blind 4 | 5 | exit; 6 | 7 | # This is for when you have a 64GB 'dd' backup and want to access the partitions without restoring to original media 8 | # dd if=/dev/sdXX of=dd-pny-64gig-b4-reimage-with-memtest-20221108.dd bs=1M 9 | 10 | zp=zseatera2 11 | size=64 # GB 12 | zfs create -sV "$size"g $zp/zvol01 13 | 14 | # restore to compressed zvol (compression is inherited from pool level but can be set OTF) 15 | # zfs set compression=zstd-3 $zp/zvol01 16 | # time dd if=dd-pny-64gig-b4-reimage-with-memtest-20221108.dd of=/dev/zvol/$zp/zvol01 bs=1M 17 | 18 | fdisk -l /dev/zvol/$zp/zvol01 19 | 20 | # ISSUE: 21 | # mount /dev/zvol/zseatera2/zvol01p5 /mnt/tmp 22 | #mount: special device /dev/zvol/zseatera2/zvol01p5 does not exist 23 | 24 | #FIX: REF: https://www.golinuxcloud.com/losetup-command-in-linux/#1_Create_a_loop_device_with_losetup 25 | losetup -P -f /dev/zvol/$zp/zvol01 # need -P for partitions 26 | 27 | losetup 28 | #NAME SIZELIMIT OFFSET AUTOCLEAR RO BACK-FILE DIO 29 | #/dev/loop0 0 0 0 0 /dev/zd0 0 30 | 31 | # TODO grep ls /dev/zvol/$zp/zvol01 for the right one, its a symlink 32 | mydev=$(losetup |grep zd0 |awk '{print $1}') 33 | fdisk -l $mydev # /dev/loop0 34 | 35 | mkdir -pv /mnt/tmp 36 | mount /dev/"$mydev"p5 /mnt/tmp -oro # rw,noatime 37 | -------------------------------------------------------------------------------- /ZFS/pokedisk.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Keep firewire dock drives spinning or they go to sleep WAY too fast 4 | 5 | # TODO check 1st char Z = zpool, otherwise check all mounted fs for existing file and poke dem 6 | 7 | # easy way 8 | #zp=zredtera1 9 | 10 | #zp=`zfs list -H -d 0 |awk '{print $1}'` 11 | #zmac5int 12 | #zsgtera2 13 | 14 | # KDS format = /zredtera1/.keepThisDriveSpinning 15 | # 2019-05-05 16:10:49 CDT 16 | 17 | PATH=/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin:/usr/local/games:/usr/games:/root/bin:/root/bin/boojum:/usr/X11R6/bin:/usr/NX/bin: 18 | 19 | while [ true ]; do 20 | mydate=`date +%Y-%m-%d" "%R":"%S" "%Z` 21 | # 2019-05-05 16:53:07 CDT 22 | 23 | for zr in `zfs list -H -d 0 |awk '{print $1}'`; do 24 | echo $mydate > /$zr/.keepThisDriveSpinning 25 | done 26 | sleep 60 27 | done 28 | 29 | # 2019.0607 TODO do one better - change OTF 30 | -------------------------------------------------------------------------------- /ZFS/prepvm.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 2021 Dave Bechtel 4 | # NOTE VM MUST NOT BE RUNNING 5 | # This runs on virtualbox host to prep VM for upload 6 | # REQUIRES: virtualbox, 7zip, md5sum, sha1sum 7 | 8 | ls -alh 9 | vbm="VBoxManage" # Virtualbox 10 | # Shrinkydink rootdisk 11 | #time $vbm modifymedium --compact test-zfs-21-Draid-sata0-0-roothomeswap.vdi 12 | time $vbm modifymedium --compact test-zfs-21-Draid-sata0-0.vdi 13 | ls -alh 14 | 15 | # Cleanup 16 | /bin/rm -f Logs/* 17 | mkdir -pv ~/tmpdel; /bin/mv *~ ~/tmpdel 18 | 19 | # use 7zip instead 20 | 21 | dirtobkp="test-zfs-21-Draid--xfs" 22 | outfile="$dirtobkp.7z" 23 | 24 | cd .. 25 | /bin/rm -f $outfile 26 | 27 | time 7z \ 28 | a \ 29 | -mx=9 \ 30 | -ms=on \ 31 | $outfile \ 32 | $dirtobkp 33 | 34 | time md5sum -b $outfile > $dirtobkp.md5 35 | time sha1sum -b $outfile > $dirtobkp.sha1 36 | cat *.md5 *.sha1 37 | ls -alh 38 | 39 | date; 40 | exit; 41 | 42 | time rar \ 43 | a \ 44 | -m5 \ 45 | -md4096 \ 46 | -rr1p \ 47 | -ol \ 48 | -ow \ 49 | -o+ \ 50 | -r \ 51 | -tsm \ 52 | -tsc \ 53 | -s \ 54 | -- \ 55 | $outfile \ 56 | $dirtobkp 57 | -------------------------------------------------------------------------------- /ZFS/rescan-scsi-bus.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # REF: https://support.hpe.com/hpesc/public/docDisplay?docId=emr_na-c03113986 4 | 5 | echo "$(date) - Rescanning scsi bus" 6 | for hba in $(ls -1 /sys/class/scsi_host); do 7 | echo -e -n "$hba \r" 8 | echo "- - -" > /sys/class/scsi_host/${hba}/scan 9 | done 10 | echo '' 11 | -------------------------------------------------------------------------------- /ZFS/samba-show-current-users.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # http://askubuntu.com/questions/102924/list-samba-shares-and-current-users 4 | smbstatus -v 5 | -------------------------------------------------------------------------------- /ZFS/spinup.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # spin up drives faster ? 4 | # http://www.admin-magazine.com/HPC/Articles/GNU-Parallel-Multicore-at-the-Command-Line-with-GNU-Parallel 5 | # http://www.gnu.org/software/parallel/parallel_tutorial.html#Building-the-command-line 6 | 7 | logger "BOOJUM note - spinning up disks $0" 8 | logfile=~/spinup.log 9 | 10 | echo "`date` - boojum spinup called - spinning up disks" >> $logfile 11 | 12 | infile=/run/shm/paratmp.list 13 | > $infile # clearit 14 | 15 | # exec to use 16 | para=/usr/bin/parallel 17 | 18 | # populate list of drives - REF: http://unix.stackexchange.com/questions/132126/which-command-to-force-a-drive-to-spin-up 19 | # TODO random seek - 1-100 RND 20 | # random REF: https://stackoverflow.com/questions/8988824/generating-random-number-between-1-and-10-in-bash-shell-script 21 | for c in /dev/sd?; do 22 | myrand=$(( ( RANDOM % 100 ) + 1 )) 23 | mycmd="echo $c;/bin/dd if=$c of=/dev/null bs=4096 skip=$myrand count=1 iflag=direct" 24 | echo "$mycmd" >> $infile 25 | # `$mycmd &` 26 | done 27 | 28 | #jobs 29 | #limitt=6 30 | limitt=5 31 | 32 | #cat $infile |$para -j $limitt --progress --keep-order --group --linebuffer --results $paradir qpbatch 33 | #cat $infile |$para -j $limitt --progress fdisk -l $1 34 | #|grep Disk 35 | 36 | date1=`date +%s` # seconds 37 | time cat $infile |$para -j $limitt --progress 38 | wait; 39 | date2=`date +%s` # seconds 40 | let date3=$date2-$date1 41 | echo "`date` + spinup took ($date3) seconds" >> $logfile 42 | 43 | #/bin/dd if=$1 of=/dev/null bs=4096 count=1 iflag=direct 44 | 45 | # combine lines of output for brevity 46 | # REF: https://stackoverflow.com/questions/9605232/how-to-merge-every-two-lines-into-one-from-the-command-line 47 | #/root/bin/hd-power-status |awk 'NR%2{printf "%s ",$0;next;}1' 48 | /root/bin/hd-power-status 49 | 50 | #echo 'o DONE: '`date` #>> ~/$outlog 51 | 52 | exit; 53 | 54 | -------------------------------------------------------------------------------- /ZFS/ssh-into-qemu-vm.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # This runs on the QEMU Host 4 | # portfwd to squid on raspberry pi; run-qemu is listening for ssh on 32222 5 | ssh -2 -C -Y -oTCPKeepAlive=yes -g -R 3128:10.1.0.4:3128 -l user localhost -p 32222 6 | -------------------------------------------------------------------------------- /ZFS/vbox-create-n-attach-disks-SAS90.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 2021 Dave Bechtel - for testing ZFS DRAID 2.1.x 4 | # create ZFS data disks and attach them to existing VM 5 | # OLD version - use 96 drives instead 6 | # REF: http://www.allgoodbits.org/articles/view/54 7 | # REF: https://superuser.com/questions/741734/virtualbox-how-can-i-add-mount-a-iso-image-file-from-command-line 8 | 9 | vmname=test-zfs-21-Draid 10 | 11 | 12 | #4,000,797,696 - must be evenly div.by 512 = sector size 13 | nd=24 14 | # root is already on port 0 15 | port=1 16 | function mkdisks () { 17 | for this in $(seq -w 01 $nd); do 18 | echo $PWD/${this} 19 | 20 | # "Actual" 2TB - REF: https://www.virtualbox.org/manual/ch08.html#vboxmanage-createmedium 21 | # time VBoxManage createmedium disk --filename $PWD/zfs$this.vdi --sizebyte 2000398934016 22 | 23 | # "Actual" 4GB - REF: https://www.virtualbox.org/manual/ch08.html#vboxmanage-createmedium 24 | time VBoxManage createmedium disk --filename $PWD/zfs$this.vdi --sizebyte 4000797696 # 400079786802 25 | VBoxManage storageattach "$vmname" --storagectl SATA --port $port --device 0 --type hdd --medium $PWD/zfs$this.vdi 26 | 27 | let port=$port+1 28 | done 29 | } 30 | 31 | mkdisks 32 | 33 | # SAS controller, goin up to 90 34 | pnd=$nd 35 | nd=90 36 | let startd=$pnd+1 # 90-24 = 66 more disks on SAS 37 | echo "startd=$startd - nd=$nd" 38 | port=0 39 | function mkdiskSAS () { 40 | for this in $(seq -w $startd $nd); do 41 | echo $PWD/${this} 42 | 43 | time VBoxManage createmedium disk --filename $PWD/zfs-SAS$this.vdi --sizebyte 4000797696 44 | VBoxManage storageattach "$vmname" --storagectl SAS --port $port --device 0 --type hdd --medium $PWD/zfs-SAS$this.vdi 45 | 46 | let port=$port+1 47 | done 48 | } 49 | 50 | mkdiskSAS 51 | 52 | VBoxManage showvminfo "$vmname" 53 | date 54 | 55 | exit; 56 | -------------------------------------------------------------------------------- /ZFS/zfs-draid-configs.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kneutron/ansitest/ceafcc8d2a7ec1e6b2a9fbe04e5f443515ebc0c2/ZFS/zfs-draid-configs.xlsx -------------------------------------------------------------------------------- /ZFS/zfs-emergency-free-space.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 2024.Feb kneutron 4 | # REF: https://www.reddit.com/r/Proxmox/comments/1auxnpd/io_error_zfs_pool_full_do_i_need_to_buy_new_disks/ 5 | 6 | # When your zpool has filled up and you need emergency temporary free space to start deleting things (like snapshots) 7 | 8 | zfspath=/sys/module/zfs/parameters/spa_slop_shift 9 | 10 | if [ "$1" = "putitback" ]; then 11 | echo 5 > $zfspath 12 | cat $zfspath 13 | zpool list 14 | exit 0; 15 | fi 16 | 17 | # only if it doesnt already exist - REF 18 | [ -e /tmp/zfs-slop-shift-orig.txt ] || cat $zfspath >/tmp/zfs-slop-shift-orig.txt 19 | 20 | zpool list 21 | echo "$0 - Adjusting for temporary free space" 22 | echo 8 > $zfspath 23 | echo "=====" 24 | echo "After adjustment:" 25 | zpool list 26 | 27 | echo "This should have freed up a bunch of bonus free space on your pool 28 | BUT you need to put it back when you're done or reboot!" 29 | 30 | # This should allow you to delete files/snapshots. 31 | 32 | # Be sure to switch spa_slop_shift back to its default of 5 afterwards (this 33 | # tunable prevents you from filling up the zpool completely, which can cause 34 | # it to be come permanently readonly). 35 | -------------------------------------------------------------------------------- /ZFS/zfs-feature-flags-compatible-dual-boot-zpool.ods: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kneutron/ansitest/ceafcc8d2a7ec1e6b2a9fbe04e5f443515ebc0c2/ZFS/zfs-feature-flags-compatible-dual-boot-zpool.ods -------------------------------------------------------------------------------- /ZFS/zfs-fix-smb-conf.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # for suse, may also work on rhel-derived 4 | # Fix missing zfs shares in samba config 5 | # 2023.Nov kneutron 6 | 7 | conf=/etc/samba/smb.conf 8 | cp -v $conf /etc/samba/smb.conf.bak-$(date +%Y%m%d)'@'$(date +%H%M) 9 | 10 | template=" 11 | # boojumfix 12 | [SHARENAME] 13 | path = REPLACEME 14 | writable = yes 15 | guest ok = yes 16 | guest only = no 17 | create mode = 0777 18 | directory mode = 0777 19 | 20 | " 21 | 22 | tmpfile=/tmp/fixsmb.tmp.txt 23 | >$tmpfile 24 | 25 | mods=0 26 | for zd in $(zfs get sharesmb |awk '$3=="on" {print $1}'); do 27 | [ "$zd" = "" ] && break; 28 | 29 | mtpt=$(df |grep "$zd" |awk '{print $6}') 30 | echo "$zd = $mtpt" 31 | 32 | #set -x 33 | # only if not already in smb.conf 34 | if [ $(grep -c $mtpt $conf) -lt 1 ]; then 35 | echo "$template" >$tmpfile 36 | 37 | dasher=$(echo $zd |tr '/' '-') 38 | 39 | sed -i 's|SHARENAME|'$dasher'|g' $tmpfile 40 | sed -i 's|REPLACEME|'$mtpt'|' $tmpfile 41 | cat $tmpfile >> $conf 42 | 43 | let mods=$mods+1 44 | fi 45 | done 46 | 47 | cat $conf 48 | ls -l $conf 49 | echo "Modified $mods shares" 50 | 51 | if [ $mods -gt 0 ]; then 52 | msg="$(date) - $0 - Restarting samba service" 53 | logger $msg 54 | echo "$msg" 55 | systemctl restart smb 56 | fi 57 | 58 | zfs-show-my-shares.sh 59 | -------------------------------------------------------------------------------- /ZFS/zfs-killsnaps.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # REF: https://sysadminman.net/blog/2008/remove-all-zfs-snapshots-50 3 | 4 | # destroy arg snapshots on pool (to free space) and track what got killed 5 | # NOTE does NOT do Recursive and can grep on whatever criteria matches! 6 | # NOTE no logfile rotation 7 | # 2014 Dave Bechtel 8 | 9 | #crit=daily 10 | crit=weekly 11 | #crit=$zp 12 | 13 | [ "$1" = "" ] || crit="$1" 14 | 15 | logfile=/root/zfs-killsnaps.log 16 | 17 | function dokill () { 18 | crit=$1 19 | for snapshot in $(zfs list -H -t snapshot |grep $crit | cut -f 1) 20 | do 21 | echo "$(date) - Killing $snapshot" |tee -a $logfile 22 | time zfs destroy $snapshot 23 | done 24 | } 25 | 26 | dokill $crit 27 | #dokill hourly 28 | #dokill weekly 29 | -------------------------------------------------------------------------------- /ZFS/zfs-list-snaps--boojum.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # REF: https://pthree.org/2012/12/19/zfs-administration-part-xii-snapshots-and-clones/ 4 | zfs list -r -t snapshot -o name,used,refer,mountpoint,creation 5 | -------------------------------------------------------------------------------- /ZFS/zfs-list-used-space-by-snapshots.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | zfs list -r -o name,used,usedsnap |sort -h -k 3 4 | 5 | zfs list -t snapshot -o name,refer,used,written,creation 6 | # REF: https://www.reddit.com/r/zfs/comments/i0lx98/why_isnt_snapshot_used_value_0/ 7 | 8 | exit; 9 | 10 | Note - use -p flag for parsable (exact) numbers (for spreadsheet) - date will be in seconds from epoch 11 | 12 | Fields: 13 | 14 | Used is the amount of space reclaimed by deleting only this snapshot. 15 | 16 | Refer is the size of the tarball that would be created from this snapshots contents (give/take compression). 17 | 18 | Written is the amount of data added or modified in the snapshot between the previous snapshot and this one 19 | in particular written == refer for the first snapshot in the timeline 20 | 21 | NAME USED USEDSNAP 22 | zsgtera4/tmpdel-xattrsa 16.7G 120K 23 | zsam52/notshrcompr-zsam52 680K 200K 24 | zsam52 176G 268K 25 | zsgtera4 1.66T 272K 26 | zsam52/imac513-installed-old 869M 396K 27 | zsam52/shrcompr-zsam52 94.7G 1.31M 28 | zsgtera4/virtbox-virtmachines-linux 47.1G 1.64M 29 | zsgtera4/dvdrips-shr 38.4G 4.35G 30 | zsam52/dvdrips-shr-zsam52 25.6G 6.35G 31 | zsgtera4/virtbox-virtmachines/zfsubuntu2FIXEDClone 33.4G 9.31G 32 | zsam52/tmpdel-zsam52 55.0G 16.2G 33 | zsgtera4/virtbox-virtmachines 429G 23.9G 34 | zsgtera4/notshrcompr-zsgt2B 375G 32.2G 35 | zsgtera4/notshrcompr-zsgt2B/bkp-bookmarks 68.9G 36.3G 36 | zsgtera4/shrcompr-zsgt2B 795G 47.4G 37 | -------------------------------------------------------------------------------- /ZFS/zfs-list-used-space-concise.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | zfs list -o space 4 | 5 | # REF: https://www.youtube.com/watch?v=IWp2eYg-M3k 6 | -------------------------------------------------------------------------------- /ZFS/zfs-newds-zstd.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # cre8 a new ZFS dataset with options 4 | echo "$0 opt1=(1)compression opt1=(1)sharesmb, 0 == OFF zpool dirname" 5 | 6 | # TODO -e /tmp/infile read it and process it 7 | 8 | source ~/bin/failexit.mrg 9 | logfile=/root/boojum-zfs-newds.log 10 | 11 | # TODO editme 12 | #zp=zredpool2; myds=home/vmtmpdir/vmware-virtmachines 13 | zp="$2"; myds="$3" 14 | user=user 15 | 16 | # defaults 17 | compr=zstd-3 18 | shrwin=off 19 | 20 | # opt1=compression, opt2=sharesmb 21 | case "$1" in 22 | "10" ) 23 | # use defaults 24 | shrwin=off 25 | ;; 26 | "11" ) 27 | shrwin="on -o xattr=sa " 28 | ;; 29 | "01" ) 30 | compr=off; shrwin="on -o xattr=sa " 31 | ;; 32 | "00" ) 33 | compr=off; shrwin=off 34 | ;; 35 | "" ) 36 | # no arg passed; print help and exit 37 | failexit 101 "No arg passed!" 38 | ;; 39 | * ) 40 | failexit 201 "Invalid arg passed, +$1+ not recognized" 41 | 42 | ;; 43 | esac 44 | 45 | # trace on 46 | (set -x 47 | zfs create -o \ 48 | atime=off -o compression=$compr -o sharesmb=${shrwin} -o recordsize=1024k \ 49 | $zp/$myds || failexit 99 "! Failed to create ZFS $zp/$myds" 50 | ) 51 | 52 | echo "`date` + $zp/$myds + compr=$compr:shr=$shrwin + owner:$user" >> $logfile 53 | 54 | # NOTE does not take into account alt.mountpoints like /home! 55 | chown -v $user /$zp/$myds; ls -al /$zp/$myds 56 | #df -h /$zp/$myds 57 | df -hT |head -n 1 58 | df -hT |grep $myds 59 | 60 | exit; 61 | 62 | # MAC mods 63 | /var/root/bin/boojum/zfs-newds.sh: line 57: /root/boojum-zfs-newds.log: No such file or directory 64 | chown: /zwdgreentera/dvnotshrcompr: No such file or directory 65 | ls: /zwdgreentera/dvnotshrcompr: No such file or directory 66 | Filesystem Size Used Avail Capacity iused ifree %iused Mounted on 67 | zwdgreentera/dvnotshrcompr 449Gi 324Ki 449Gi 1% 10 942667768 0% /Volumes/zwdgreentera/dvnotshrcompr 68 | 40 root ~ # pwd 69 | /var/root 70 | -------------------------------------------------------------------------------- /ZFS/zfs-newds.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 2014 Dave Bechtel 4 | 5 | # cre8 a new ZFS dataset with options and loggit 6 | echo "$0 opt1=(1)compression opt2=(1)sharesmb, 0 == OFF zpool dirname" 7 | echo "Example: $0 11 zpoolname datasetname" 8 | echo "== create zpoolname/datasetname as Shared Samba dataset with recordsize 1M and set owner" 9 | 10 | # TODO -e /tmp/infile read it and process it 11 | 12 | logfile=~/boojum-zfs-newds.log 13 | 14 | #source ~/bin/failexit.mrg 15 | # failexit.mrg 16 | function failexit () { 17 | echo '! Something failed! Code: '"$1 $2" |tee -a $logfile # code # (and optional description) 18 | exit $1 19 | } 20 | 21 | # xxx TODO editme 22 | #zp=zredpool2; myds=home/vmtmpdir/vmware-virtmachines 23 | zp="$2"; myds="$3" 24 | user=dave 25 | # this is for chown later 26 | 27 | # defaults 28 | dcompr=lz4 29 | #dcompr=zstd-2 ## for zfs 2.0.x 30 | dshrwin=off 31 | 32 | # opt1=compression, opt2=sharesmb 33 | case "$1" in 34 | "10" ) 35 | # use defaults 36 | compr=$dcompr; shrwin=$dshrwin 37 | ;; 38 | "11" ) 39 | compr=$dcompr; shrwin="on -o xattr=sa" 40 | # NOTE xattr=sa may not work in older versions of freebsd 41 | ;; 42 | "01" ) 43 | compr=off; shrwin="on -o xattr=sa" 44 | ;; 45 | "00" ) 46 | compr=off; shrwin=off 47 | ;; 48 | "" ) 49 | # no arg passed; bash NOP ref: https://stackoverflow.com/questions/17583578/what-command-means-do-nothing-in-a-conditional-in-bash 50 | : 51 | ;; 52 | * ) 53 | echo "WNG: Invalid arg passed, +$1+ not recognized" 54 | ;; 55 | esac 56 | 57 | # trace on 58 | (set -x 59 | zfs create -o \ 60 | atime=off -o compression=$compr -o sharesmb=${shrwin} -o recordsize=1024k \ 61 | $zp/$myds || failexit 99 "! Failed to create ZFS $zp/$myds" 62 | ) 63 | 64 | echo "$(date) + $zp/$myds + compr=$compr:shr=${shrwin} + Owner:$user" >> $logfile 65 | 66 | # NOTE does not take into account alt.mountpoints like /home! 67 | chown -v $user /$zp/$myds; ls -al /$zp/$myds 68 | #df -h /$zp/$myds 69 | df -hT |head -n 1 70 | df -hT |grep $myds 71 | 72 | exit; 73 | 74 | This is not intended to be comprehensive, but should provide a good example 75 | -------------------------------------------------------------------------------- /ZFS/zfs-parts-list-60TB-backup-raidz1.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kneutron/ansitest/ceafcc8d2a7ec1e6b2a9fbe04e5f443515ebc0c2/ZFS/zfs-parts-list-60TB-backup-raidz1.xlsx -------------------------------------------------------------------------------- /ZFS/zfs-show-my-shares.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | smbclient -N -L localhost 3 | -------------------------------------------------------------------------------- /ZFS/zfs-test-encryption-speeds--linux--copy-iso.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Linux version 4 | # basic copy ISO test timings after running zfs-test-encryption-speeds to create encrypted datasets of each type 5 | 6 | stime=$(date) 7 | 8 | # TODO editme 9 | zp=zfs3nvme1T # This is where the Test-aes* datasets live 10 | 11 | tmpfile=$HOME/zfstestencrspeeds.txt 12 | outfile=$HOME/zfs-test-encryption-speeds-results.log 13 | 14 | #source ~/bin/failexit.mrg 15 | # failexit.mrg 16 | function failexit () { 17 | echo '! Something failed! Code: '"$1 $2" # code # (and optional description) 18 | exit $1 19 | } 20 | 21 | useramdisk=1 22 | [ $useramdisk -eq 0 ] && isopath=/ztoshtera6macpromir/shrcompr-ztoshtera6/ISO # use if < 6GB RAM installed 23 | # xxx TODO EDITME ^^ 24 | [ "$isopath" = "" ] && isopath=/dev/shm 25 | 26 | [ -e "$isopath" ] || failexit 101 "! Ramdisk or ISO source not detected - run zfs-test-encryption-speeds to create it" 27 | 28 | cd "$isopath" && pwd 29 | 30 | function ttime () { 31 | result=$(date +%s) 32 | # see ' man date ' -- seconds 33 | } 34 | 35 | # clearit 36 | > $tmpfile 37 | 38 | # supported encryption at time of writing: 39 | # encryption=aes-128-ccm,aes-192-ccm,aes-256-ccm,aes-128-gcm,aes-192-gcm,aes-256-gcm 40 | 41 | echo "o $(date) + Copying ISO file(s) to each encrypted dataset" 42 | for d in /$zp/Test-aes*; do 43 | date; ttime; tstart=$result 44 | time cp -vf *.iso $d 45 | time sync 46 | date; ttime; tend=$result 47 | 48 | let csecs=$tend-$tstart 49 | echo "$csecs Seconds to Copy ISO to $d" |tee -a $tmpfile 50 | # countdown 10 51 | echo "Pausing 5 seconds" 52 | sleep 5 53 | done 54 | 55 | ntime=$(date) 56 | 57 | echo "o Start time: $stime -- End time: $ntime" 58 | sort -n $tmpfile > $outfile && rm -f $tmpfile 59 | ls -al $outfile 60 | 61 | exit; 62 | 63 | # 2021.april mod osx version to linux 64 | -------------------------------------------------------------------------------- /ZFS/zfs-watchresilver-boojum.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | 4 | # 2014 Dave Bechtel 5 | # arg1 is poolname 6 | 7 | sdate=$(date) 8 | 9 | #mv ~/scrublog.log ~/scrublog-prev.log 10 | #> ~/scrublog.log 11 | 12 | # do forever 13 | while :; do 14 | clear 15 | 16 | echo "Pool: $1 - NOW: $(date) -- Watchresilver started: $sdate" 17 | 18 | zpool status $1 |grep -A 2 'resilver in progress' || break 2 19 | zpool iostat -v $1 2 3 & 20 | # zpool iostat -T d -v $1 2 3 & # with timestamp 21 | 22 | sleep 9 23 | date 24 | 25 | done 26 | 27 | ndate=$(date) 28 | 29 | zpool status -v $1 |awk 'NF>0' # skip blank lines 30 | echo "o Resilver watch $1 start: $sdate // Completed: $ndate" 31 | 32 | #hd-power-status 33 | 34 | exit; 35 | 36 | pool: tank1 37 | state: ONLINE 38 | scan: scrub in progress since Tue May 1 23:28:07 2012 39 | 146G scanned out of 1.24T at 177M/s, 1h47m to go 40 | 0 repaired, 11.56% done 41 | config: 42 | NAME STATE READ WRITE CKSUM 43 | tank1 ONLINE 0 0 0 44 | raidz1-0 ONLINE 0 0 0 45 | label/zdisk1 ONLINE 0 0 0 46 | label/zdisk2 ONLINE 0 0 0 47 | label/zdisk3 ONLINE 0 0 0 48 | label/zdisk4 ONLINE 0 0 0 49 | errors: No known data errors 50 | -------------------------------------------------------------------------------- /ZFS/ziostatt.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | date 4 | zpool iostat $1 -y -T d -v 5 5 | -------------------------------------------------------------------------------- /ZFS/zpool-create-raidz-for-expansion.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 2025.Jan kneutron 4 | 5 | echo "o NOTE zfs-2.3.0-1 or higher is required!" 6 | zfs -V 7 | 8 | zp=zraidzexpandtest 9 | 10 | # vda=vdp avail; f=6 11 | zpool create -o ashift=12 -o autoexpand=on -o autoreplace=off -O atime=off -O compression=lz4 \ 12 | $zp raidz1 \ 13 | vd{a..f} 14 | 15 | zpool list -v 16 | zpool status -v |awk 'NF>0' 17 | -------------------------------------------------------------------------------- /ZFS/zpool-create-raidz2-for-expansion.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 2025.Jan kneutron 4 | 5 | echo "o NOTE zfs-2.3.0-1 or higher is required!" 6 | zfs -V 7 | 8 | # vdi..p avail for pool2 9 | zp=zraidz2expandtest 10 | 11 | zpool create -o ashift=12 -o autoexpand=on -o autoreplace=off -O atime=off -O compression=lz4 \ 12 | $zp raidz2 \ 13 | vd{i..n} 14 | 15 | zpool list -v 16 | zpool status -v |awk 'NF>0' 17 | -------------------------------------------------------------------------------- /ZFS/zpool-import-ro.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | zpool import -f -o readonly=on "$*" 3 | zpool status -v 4 | -------------------------------------------------------------------------------- /ZFS/zpool-show-last-scrub.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | zpool status -v |egrep 'pool:|scan' #|less 4 | 5 | exit; 6 | 7 | # sample output 8 | pool: zint500 9 | scan: scrub repaired 0B in 00:48:16 with 0 errors on Thu Nov 16 00:49:16 2023 10 | pool: zsam53 11 | scan: scrub repaired 0B in 01:42:37 with 0 errors on Wed Nov 15 01:43:37 2023 12 | pool: ztoshtera6 13 | scan: scrub repaired 0B in 22:32:04 with 0 errors on Fri Nov 17 22:33:05 2023 14 | -------------------------------------------------------------------------------- /ans-reboot-server-copypasta.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # NOTE need bash >3.2.57 on OSX for this 4 | 5 | # Paste a vertical list of servers separated by newline 6 | # ^ pass them as comma-separated server(s) to ansible; reboot and wait up to 10 min 7 | 8 | echo "Paste vertical list of servers / IP addresses; Enter EOF at the end of server list to begin processing" 9 | 10 | buildstr="" 11 | while read inline; do 12 | [ "$inline" = "EOF" ] && break; 13 | 14 | fstchr=${inline:0} 15 | if [[ $fstchr =~ ^[0-9] ]] && [ $(echo $inline |awk '{sum+=gsub(/\./,"")}END{print sum}') -eq 3 ]; then 16 | # 1st char=number and contains 3 dots, more than likely an IPV4 addr 17 | buildstr="$buildstr$inline," 18 | else 19 | hnonly=${inline%%.*} # strip evyting after first dot, dont need FQDN 20 | hnonly=${hnonly,,} # and lowercase it 21 | buildstr="$buildstr$hnonly," 22 | fi 23 | done 24 | buildstr=$(echo ${buildstr%,}) # omit trailing comma 25 | 26 | servers=$buildstr 27 | echo "$buildstr" 28 | ansible-playbook reboot-and-wait.yml --become -e "target=$servers" 29 | -------------------------------------------------------------------------------- /ans-reboot-server.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # pass comma-separated server(s) as arg; reboot and wait up to 10 min 4 | if [ "$1" = "" ]; then 5 | echo "Provide at least one target server as parameter" 6 | exit 404; 7 | else 8 | servers=${@%,} # omit trailing comma 9 | echo "$servers" 10 | ansible-playbook reboot-and-wait.yml --become -e "target=$servers" 11 | fi 12 | 13 | -------------------------------------------------------------------------------- /ans-run-demo-lowercase-sr.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ansible-playbook -i localhost demo-ansible-lowercase-search-replace.yml 3 | 4 | -------------------------------------------------------------------------------- /ans-safe-delete-file-dir.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Safely delete file or directory tree with ansible 4 | # Author takes NO responsibility for accidents or misuse, USE AT YOUR OWN RISK 5 | 6 | # arg1=server(s), comma-separated 7 | # arg2=path/to/file 8 | 9 | # failexit.mrg 10 | function failexit () { 11 | echo '! Something failed! Code: '"$1 $2" # code # (and optional description) 12 | exit $1 13 | } 14 | 15 | # Basic sanity 16 | [ "$1" = "" ] && failexit 404 "Server(s) not specified as arg 1" 17 | [ "$2" = "" ] && failexit 405 "File / Dir not specified as arg 2" 18 | 19 | # "" should catch root 20 | for crit in "" bin boot dev etc home lib media mnt opt proc root root/bin run sbin srv sys tmp usr usr/bin usr/sbin var; 21 | do 22 | if [ "$2" = "/$crit" ] || [ "$2" = "/$crit/" ]; then 23 | failexit 999 "ARE YOU INSANE? NO! ( ︶︿︶)_╭∩╮" 24 | fi 25 | done 26 | 27 | echo "Processing servers: $1" 28 | time ansible $1 -m file -a "dest=$2 state=absent" --become 29 | 30 | exit; 31 | 32 | Example usage - On target server: 33 | 34 | # mkdir -pv /tmp/complexdir 35 | # cd /tmp/complexdir && \ 36 | # for d in {1..50}; do mkdir -pv $d/$d; done 37 | 38 | # $0 targetserver /tmp/complexdir # the whole directory tree should be GONE from /tmp after running this script 39 | -------------------------------------------------------------------------------- /awkinput-printcolumns.txt: -------------------------------------------------------------------------------- 1 | drwxrwxr-x 3 dave-imac5 admin 6B Nov 28 2021 0BR-converted 2 | another input line 3 | Filesystem Type Size Used Avail Use% Mounted-on 4 | /dev/disk1s5s1 apfs 233G 226G 7.4G 97% / 5 | -------------------------------------------------------------------------------- /bkp-davebin.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kneutron/ansitest/ceafcc8d2a7ec1e6b2a9fbe04e5f443515ebc0c2/bkp-davebin.tar.gz -------------------------------------------------------------------------------- /burncda2: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Used with make-a-cdset, to burn "songlisting" as ISO mountable-filesystem 3 | # on track 1. Therefore all music tracks start at track 2. 4 | 5 | usecd='/mnt/cdtemp' 6 | echo $usecd 7 | mount $usecd 8 | cd $usecd/audio 9 | #cd /mnt/driveg/cdtemp/audio/alt-trax 10 | 11 | # Use -dummy to test!! 12 | if [ -n $1 ]; then 13 | addto=$1 14 | fi 15 | 16 | echo $addto 17 | 18 | mkisofs -v -f -l -J -r -o isofiletmp.raw /root/bin/songlisting.txt 19 | 20 | ls 21 | echo Preparing to make dual-mode ISO songlisting and audio -- Pk: 22 | read 23 | 24 | # stupid-ass mkisosize won't do it to std output!! 25 | #function getisosize 26 | #{ 27 | # isosize=$8 28 | # echo $isosize 29 | #} 30 | #mkisofs -R -q -print-size /root/bin/songlisting >/root/bin/tmpfile 31 | #getisosize /proc/sys/vm/drop_caches # free pagecache 15 | 16 | #To free dentries and inodes: 17 | [ "$*" = "2" ] && echo 2 > /proc/sys/vm/drop_caches 18 | 19 | #To free pagecache, dentries and inodes: 20 | [ "$*" = "3" ] && echo 3 > /proc/sys/vm/drop_caches 21 | #echo 3 > /proc/sys/vm/drop_caches 22 | 23 | free 24 | -------------------------------------------------------------------------------- /commasep-num.mrg: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Returns a passed number as comma-separated e.g. pass $1 = 80000000000 and receive 80,000,000,000 4 | # REF: https://unix.stackexchange.com/questions/113795/add-thousands-separator-in-a-number 5 | 6 | function commanum () { 7 | LC_NUMERIC=en_US printf "%'.f" $1 8 | } 9 | 10 | # test for interactive shell / OK to echo text 11 | #[ $(echo $- |grep i |wc -l) -gt 0 ] && 12 | [ ! "$1" = "" ] && commanum $1 13 | 14 | exit; 15 | 16 | # Example usage: 17 | #$ tmpvar=$(./commasep-num.mrg 80000000000) 18 | #$ echo $tmpvar 19 | #80,000,000,000 20 | # Limitation: it doesn't handle fractional numbers x.xx , just integers - anything after the decimal gets dropped 21 | # so don't try to display π (pi) with it ;-) 22 | 23 | # this appears to work somewhat with fractionals but is not bash-internal: 24 | #$ echo 1232323.1415927 | awk '{printf(fmt,$1)}' fmt="%'19.19f\n" 25 | #1,232,323.1415927000343799591 26 | -------------------------------------------------------------------------------- /convert-man-pages-to-postscript-for-printing.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # REF: https://distrowatch.com/weekly.php?issue=current 4 | # REF: https://stackoverflow.com/questions/28357997/running-programs-in-parallel-using-xargs/28358088#28358088 5 | 6 | cd 7 | mkdir -pv Printable-Manual-Pages ; cd Printable-Manual-Pages 8 | pwd 9 | 10 | #time find /usr/share/man/man? -type f -print0 |gxargs -0 -t -I % -n 1 -P $(nproc) manTtoPS.sh % # "man -t "%" > $(basename "%").ps" 11 | 12 | time find /opt/local/man/man? -type f -print0 |gxargs -0 -t -I % -n 1 -P $(nproc) manTtoPS.sh % # "man -t "%" > $(basename "%").ps" 13 | 14 | du -s -h 15 | date 16 | 17 | exit; 18 | 19 | for page in $(find /usr/share/man/man? -type f); do 20 | echo "Processing $page" 21 | man -t "$page" > $(basename "$page").ps 22 | done 23 | -------------------------------------------------------------------------------- /countdown.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 2020 Dave Bechtel 4 | # Display a rotating-prompt countdown with keypress early escape 5 | # REF: https://stackoverflow.com/questions/12498304/using-bash-to-display-a-progress-indicator 6 | 7 | # number 8 | declare -i countto=$1 9 | ctr=0 10 | 11 | # array 12 | declare -a spin 13 | spin[0]="-" 14 | spin[1]='\' 15 | spin[2]="|" 16 | spin[3]="/" 17 | 18 | echo -n "[$countto] ${spin[0]} " #$ctr" 19 | 20 | while [ $countto -ge $ctr ]; do 21 | for i in "${spin[@]}" 22 | do 23 | let cdown=$countto-$ctr 24 | printf "\r$countto $i $cdown " 25 | sleep 1 26 | let ctr=$ctr+1 27 | [ $ctr -ge $countto ] && break 28 | read -n 1 -t .1 && break 2 29 | # ESC if key pressed 30 | done 31 | done 32 | echo '' 33 | -------------------------------------------------------------------------------- /debian-compile-zfs--boojum.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Part 1 of 2 scripts - this part *uninstalls* and unmounts all current zfs for code upgrade! 4 | # stops the Samba and Zed daemons, exports all zpools, and uninstalls existing ZFS packages so you start building with a clean slate 5 | 6 | #source ~/bin/failexit.mrg 7 | # failexit.mrg 8 | function failexit () { 9 | echo '! Something failed! Code: '"$1 $2" # code # (and optional description) 10 | exit $1 11 | } 12 | 13 | firstrun=1 14 | [ $firstrun -gt 0 ] && apt update 15 | 16 | # REF: https://github.com/zfsonlinux/zfs/wiki/Building-ZFS 17 | 18 | [ $firstrun -gt 0 ] && time apt install -y build-essential autoconf libtool gawk alien fakeroot \ 19 | zlib1g-dev uuid-dev libattr1-dev libblkid-dev libselinux-dev libudev-dev \ 20 | parted lsscsi ksh libssl-dev libelf-dev linux-headers-$(uname -r) 21 | 22 | # NOTE - TO AVOID COMPILE ERRORS, RUN AT LEAST ONCE: 23 | 24 | service zed stop 25 | service smbd stop 26 | 27 | # NOTE zfs pools go away temporarily here! 28 | zfs umount -a -f 29 | zpool export -a -f 30 | 31 | 32 | modprobe -r zfs zunicode zavl icp zcommon znvpair spl 33 | df -hT |grep zfs 34 | 35 | [ $(lsmod |grep -c zfs) -gt 0 ] && failexit 101 "! ZFS module still loaded!" 36 | 37 | echo "$(date) - Removing existing ZFS packages" 38 | time apt-get remove --purge -y libzfs2linux zfs-dkms zfsutils-linux spl spl-dkms libnvpair* libuutil* libzpool* 39 | time apt-get remove --purge libnvpair3linux libuutil3linux 40 | 41 | [ "$1" = "nuke" ] && apt-get remove $(dpkg -l |egrep 'zfs|libnvpair|libuutil|libzpool' |awk '{printf $2" "}') 42 | 43 | [ $(dpkg -l |egrep -c 'libzfs.linux|zfs-dkms|zfsutils-linux|spl-dkms|libnvpair|libuutil|libzpool') -gt 0 ] && failexit 199 "! ZFS packages are still installed!" 44 | 45 | # call downloaded script, should be in /root/bin or /usr/local/bin // accessible by PATH 46 | ~/dnld/ubuntu_zfs_build_install.sh 47 | 48 | 49 | exit; 50 | -------------------------------------------------------------------------------- /demo-ansible-lowercase-search-replace.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: Demo lowercase and search/replace in var 3 | hosts: localhost 4 | gather_facts: false 5 | vars: 6 | answers: "no so YES no" 7 | 8 | # mastering ansible 4th ed. 2021, p.202 9 | # REF: https://stackoverflow.com/questions/55927273/how-ansible-assign-values-to-variables 10 | # REF: https://docs.ansible.com/ansible/latest/collections/ansible/builtin/debug_module.html 11 | 12 | # replace all no with yes and lowercase it all 13 | tasks: 14 | - name: do the thing 15 | debug: 16 | msg: 17 | - "Original: {{ answers }}" 18 | - "Expected result: {{ answers | replace('no', 'yes') | lower }}" 19 | 20 | - set_fact: my_result="{{ answers | replace('no', 'yes') | lower }}" 21 | 22 | - name: show result 23 | debug: 24 | msg: "{{ my_result }}" 25 | -------------------------------------------------------------------------------- /dot-jstarrc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kneutron/ansitest/ceafcc8d2a7ec1e6b2a9fbe04e5f443515ebc0c2/dot-jstarrc -------------------------------------------------------------------------------- /dot-screenrc-mon1-combined: -------------------------------------------------------------------------------- 1 | hardstatus alwayslastline 2 | hardstatus string '%{= kG}[ %{G}%H %{g}][%= %{=kw}%?%-Lw%?%{r}(%{W}%n*%f %t%?(%u)%?%{r})%{w}%?%+Lw%?%?%= %{g}][%{B}%Y-%m-%d %{W}%c %{g}]' 3 | # Default screens 4 | # Provides a 4-panel text monitor, should work fine on plain TTY as well as xterm 5 | # REQUIRES: bwm-ng, sysstat, watch 6 | 7 | # REF: https://fordodone.com/2016/02/24/start-screen-session-with-4-way-split-screen/ 8 | split 9 | resize -5 10 | split -v 11 | focus down 12 | split -v 13 | 14 | screen -t BWM 0 /usr/bin/bwm-ng -t 2000 15 | screen -t TOP 1 /usr/bin/top -d 15 16 | screen -t IOSTAT 2 /usr/bin/iostat -k -s -y -z 5 17 | screen -t MON1SHORT 3 /usr/bin/watch -n 61 /usr/local/bin/mon1-df-short 18 | 19 | # switch back to 1st window 20 | #select 0 21 | 22 | # 7 screen -t server 2 sh me@myserver 23 | # 8 screen -t IRC 7 irssi 24 | # 9 screen -t Mail 8 mutt 25 | 26 | focus up 27 | focus left 28 | select 0 29 | focus down 30 | select 1 31 | focus up 32 | focus right 33 | select 2 34 | focus down 35 | select 3 36 | -------------------------------------------------------------------------------- /dot-screenrc-nonroot: -------------------------------------------------------------------------------- 1 | hardstatus alwayslastline 2 | hardstatus string '%{= kG}[ %{G}%H %{g}][%= %{=kw}%?%-Lw%?%{r}(%{W}%n*%f %t%?(%u)%?%{r})%{w}%?%+Lw%?%?%= %{g}][%{c}%Y-%m-%d %{W}%c %{g}]' 3 | # cyan for non-root date = readability xxx 2020.0605 4 | # color ref: https://www.gnu.org/software/screen/manual/screen.html#String-Escapes 5 | # Default screens 6 | # NOTE rename to $HOME/.screenrc 7 | defscrollback 2000 8 | 9 | screen -t shell1 0 /bin/bash 10 | screen -t shell2 1 /bin/bash 11 | screen -t shell3 2 /bin/bash 12 | 13 | # switch back to 1st window 14 | select 0 15 | 16 | # 7 screen -t server 2 sh me@myserver 17 | # 8 screen -t IRC 7 irssi 18 | # 9 screen -t Mail 8 mutt 19 | -------------------------------------------------------------------------------- /dot-screenrc-root: -------------------------------------------------------------------------------- 1 | hardstatus alwayslastline 2 | hardstatus string '%{= kG}[ %{G}%H %{g}][%= %{=kw}%?%-Lw%?%{r}(%{W}%n*%f %t%?(%u)%?%{r})%{w}%?%+Lw%?%?%= %{g}][%{R}%Y-%m-%d %{W}%c %{g}]' 3 | # red for root date = warn/readability xxx 2020.0605 4 | # color ref: https://www.gnu.org/software/screen/manual/screen.html#String-Escapes 5 | # NOTE rename to /root/.screenrc 6 | # Default screens 7 | # bashme/aliases not work :( 8 | defscrollback 2000 9 | 10 | screen -t shell1 0 /bin/bash 11 | screen -t shell2 1 /bin/bash 12 | screen -t shell3 2 /bin/bash 13 | #screen -t shell4 3 /usr/local/bin/bash 14 | # bash5 xxx 2020.0605 15 | 16 | 17 | # switch back to 1st window 18 | select 0 19 | 20 | # 7 screen -t server 2 sh me@myserver 21 | # 8 screen -t IRC 7 irssi 22 | # 9 screen -t Mail 8 mutt 23 | -------------------------------------------------------------------------------- /dot-vimrc: -------------------------------------------------------------------------------- 1 | :highlight ExtraWhiteSpace ctermbg=red guibg=red 2 | :match ExtraWhiteSpace /\s\+$/ 3 | " Useful for YAML - REF: https://www.reddit.com/r/bash/comments/tlst8x/i_am_sick_and_tired_of_python_lovers_always_using/i1yey7b/?context=3 4 | 5 | -------------------------------------------------------------------------------- /failexit.mrg: -------------------------------------------------------------------------------- 1 | # failexit.mrg - bash but might work as /bin/sh - can use as ' source ~/bin/failexit.mrg ' 2 | function failexit () { 3 | echo '! Something failed! Code: '"$1 $2" # code # (and optional description) 4 | exit $1 5 | } 6 | 7 | -------------------------------------------------------------------------------- /ffproxy-config.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kneutron/ansitest/ceafcc8d2a7ec1e6b2a9fbe04e5f443515ebc0c2/ffproxy-config.tgz -------------------------------------------------------------------------------- /fix-console-resolution.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Run from tty1 or similar 4 | # Good for VMs on 1920x1080 monitors 5 | # sets the text console / tty to have more cols/lines 6 | # helpful with topscrn4-10 7 | 8 | # REQUIRES fbset 9 | # REF: https://www.reddit.com/r/linuxadmin/comments/sefh94/cant_change_console_resolution/ 10 | 11 | [ -e /bin/fbset ] || apt-get -y install fbset 12 | 13 | fbset -xres 1440 -yres 900 14 | -------------------------------------------------------------------------------- /fixetchosts.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 2022 Dave Bechtel 4 | # Utility: Prints ONLY the lines that need to be fixed in a malformed /etc/hosts 5 | # Canonical format: IP FQDN shortname(s) 6 | # Fix malformed line(s): IP short FQDN 7 | # Handles a limited number of extra aliases (up to 5) 8 | # Does NOT modify original /etc/hosts and MAY NOT handle IPv6 (not tested) 9 | 10 | infile=/etc/hosts 11 | #infile=/tmp/hosts.test 12 | outfile=/tmp/hosts.fixed 13 | >$outfile #clearit 14 | 15 | declare -i checkfq # integer 16 | 17 | #set -x ## debugg 18 | while read inline; do 19 | [ "$inline" = "" ] && continue # blank line 20 | [ ${inline:0:1} = "#" ] && continue # comment 21 | 22 | fld2=$(echo $inline |awk '{print $2'}) 23 | [ "$fld2" = "localhost" ] && continue # 127.0.0.1 has no longname 24 | 25 | checkfq=$(echo $fld2 |awk 'END{print index($0,".")}') 26 | [ $checkfq -gt 0 ] && continue # dot found, valid line 27 | 28 | outline=$(echo "$inline" |awk '{print $1" "$3" "$2" "$4" "$5" "$6" "$7" "$8}') 29 | echo "$outline" |tee -a $outfile 30 | done <$infile 31 | 32 | echo '' 33 | echo '=====' 34 | ls -alh $outfile 35 | 36 | exit; 37 | 38 | 39 | # REF: https://unix.stackexchange.com/questions/153339/how-to-find-a-position-of-a-character 40 | $ echo $tmp1;echo $tmp2 41 | nodot 42 | hasdot.fq.dn 43 | 44 | $ echo $tmp1 |awk 'END{print index($0,".")}' 45 | 0 46 | $ echo $tmp2 |awk 'END{print index($0,".")}' 47 | 7 48 | 49 | Sample output: 50 | 51 | $ time fixetchosts.sh 52 | 255.255.255.255 broadcasthost 53 | 10.9.28.24 davesimac-2.series.org imacdual imacold oldimacdualcore 54 | 192.168.1.4 cubie.series.org cubietruck-wifi pihole 55 | 10.9.0.4 cubietruck-devuan.series.org cubietruck-devuan 56 | 57 | ===== 58 | -rw-r--r-- 1 dave wheel 241B Mar 2 15:42 /tmp/hosts.fixed 59 | 60 | real 0m0.139s 61 | -------------------------------------------------------------------------------- /fixfont: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # NOTE symlinked to 'ff' 4 | 5 | # ubuntu 10.04 aug 2010 6 | cd /usr/share/consolefonts 7 | #setfont Lat15-Fixed13.psf.gz 8 | #setfont Lat15-Fixed16 9 | setfont Lat15-Terminus20x10 10 | # Useful for 1920x1080 11 | 12 | -------------------------------------------------------------------------------- /flist-reconcile.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash5 2 | 3 | debugg=0 4 | 5 | if [ $debugg -gt 0 ]; then 6 | echo "$(date) Running flist 1st JIC" 7 | time flist 8 | fi 9 | 10 | # failexit.mrg 11 | function failexit () { 12 | echo '! Something failed! Code: '"$1 $2" # code # (and optional description) 13 | exit $1 14 | } 15 | 16 | todel=/tmp/todel-flist.txt 17 | >$todel # clearit 18 | 19 | # if flist with no tar, del 20 | 21 | declare -i fl tr # integer 22 | fl=$(ls flist* |wc -l |awk '{print $1}') 23 | tr=$(ls *tar* |grep -v flist |wc -l |awk '{print $1}') 24 | echo "Flists: $fl -- Tars: $tr" 25 | [[ $fl == $tr ]] && failexit 0 "Flists match tars, evyting OK" 26 | 27 | # regular array 28 | declare -a flists=$(ls flist*) 29 | 30 | for c in ${flists[@]}; do 31 | proc1=$(basename $c .txt) # strip .txt from end 32 | proc2=${proc1:7} # easy strip flist-- 33 | if [ $debugg -gt 0 ]; then 34 | [ -e $proc2.tar* ] && echo "MATCH $c" || echo "NOTMATCH $c" 35 | fi 36 | # [ -e $proc2.tar* ] || echo "NOTMATCH $c" 37 | [ -e $proc2.tar* ] || echo "$c" >> $todel 38 | done 39 | 40 | echo "$(wc -l $todel) - hanging FLIST files to delete - Enter to process NON-INTERACTIVELY or ^C" 41 | read 42 | 43 | while read inline; do 44 | [ "$inline" = "" ] && break 45 | ls -l "$inline" |awk '{print "Size:"$5" Date: "$6" "$7" "$8" "$9}' #|column -t 46 | /bin/rm -v "$inline" 47 | done < $todel 48 | # for some reason RM -i not working :( 49 | 50 | # Cleanup 51 | # /bin/rm $todel 52 | 53 | exit; 54 | 55 | 56 | NOTE MAC OSX wc -l also prints filename, thats why we need 1st field only! 57 | 58 | REF: https://tldp.org/LDP/abs/html/string-manipulation.html 59 | 60 | la|awk '{print "Size:"$5" Date: "$6" "$7" "$8" "$9}' |column -t 61 | 62 | Size:35077 Date: Jan 15 11:12 flist--bkp-home-dave-test-p2300m-deepin-sda6.txt 63 | 64 | basename bkp-home--NORZ--p2300m-ultimate--20200626.tar1.tar .tar1.tar 65 | bkp-home--NORZ--p2300m-ultimate--20200626 66 | 67 | missing tar: flist--bkp-home--fryserverantix19--NORZ--20210303.txt 68 | matches: flist--bkp-home-p2300m-deepin-sda6.txt 69 | 01234567 70 | -------------------------------------------------------------------------------- /freshinstall-void.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/bash 2 | 3 | # void linux 4 | # REF: https://docs.voidlinux.org/xbps/index.html 5 | 6 | logfile=~/freshinstall-void.log 7 | 8 | mv -v $logfile $logfile.old 9 | 10 | # Get latest 11 | xbps-install -u xbps 12 | 13 | function instpkg () { 14 | xbps-install -y $* 15 | } 2>>$logfile 16 | 17 | instpkg joe mc screen tmux vim nano sysstat bwm-ng xclock unzip lzop 18 | 19 | # gpg not found 20 | instpkg wget curl 21 | 22 | instpkg fsarchiver openssh smartmontools netcat 23 | 24 | instpkg linux-headers 25 | 26 | # g++ not found 27 | buildessential="gcc make glibc-devel" 28 | instpkg "$buildessential" 29 | 30 | instpkg mlocate ntp lm_sensors gawk net-tools 31 | 32 | instpkg fuse-sshfs pv buffer ethtool gparted iotop dos2unix 33 | 34 | instpkg p7zip parallel pbzip2 xz xfsprogs 35 | 36 | instpkg lsscsi sdparm sg3_utils 37 | 38 | instpkg lftp gftp ncftp 39 | 40 | # nmap not found 2023.0910 41 | instpkg ethstatus iptraf-ng autossh 42 | 43 | instpkg cdparanoia vlc youtube-dl handbrake handbrake-cli lame mpg123 ffmpeg devedeng 44 | 45 | instpkg udftools dvd+rw-tools zisofs-tools imagewriter isoimagewriter xorriso 46 | 47 | instpkg mplayer mpv arandr wmctrl 48 | 49 | instpkg xterm xfontsel 50 | 51 | instpkg libreoffice 52 | 53 | # Toys 54 | instpkg cmatrix xaos ImageMagick geeqie ristretto jpegoptim tumbler xsnow 55 | 56 | instpkg thunderbird firefox-esr mutt 57 | 58 | instpkg samba smbclient cifs-utils 59 | instpkg zfs 60 | modprobe zfs 61 | dmesg|grep zfs 62 | 63 | instpkg vsftpd 64 | 65 | # NON-VM only 66 | # instpkg virtualbox-ose 67 | 68 | result=$(grep -c toor /etc/passwd) 69 | if [ $result -eq 0 ]; then 70 | useradd -d /root -g 0 -G 0 -M -N -o -r -s `which bash` -u 0 toor # bash root user 71 | echo "+ Added toor bash user" 72 | else 73 | echo "toor user already exists - skipped" 74 | fi 75 | 76 | # updt - requires Y input 77 | xbps-install -Su 78 | 79 | echo "$(date) - Checking if reboot needed" 80 | time xcheckrestart 81 | 82 | zpool import 83 | 84 | date 85 | 86 | exit; 87 | -------------------------------------------------------------------------------- /gig-ether--speedup-linux.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # http://fasterdata.es.net/host-tuning/linux/ 4 | 5 | # increase TCP max buffer size setable using setsockopt() 6 | # 16 MB with a few parallel streams is recommended for most 10G paths 7 | # 32 MB might be needed for some very long end-to-end 10G or 40G paths 8 | sysctl net.core.rmem_max=16777216 9 | sysctl net.core.wmem_max=16777216 10 | # increase Linux autotuning TCP buffer limits 11 | # min, default, and max number of bytes to use 12 | # (only change the 3rd value, and make it 16 MB or more) 13 | sysctl net.ipv4.tcp_rmem="4096 87380 16777216" 14 | sysctl net.ipv4.tcp_wmem="4096 65536 16777216" 15 | # recommended to increase this for 10G NICS 16 | sysctl net.core.netdev_max_backlog=30000 17 | # these should be the default, but just to be sure 18 | sysctl net.ipv4.tcp_timestamps=1 19 | 20 | # 1 to 0 per: 21 | # 22 | sysctl net.ipv4.tcp_sack=0 23 | 24 | 25 | sysctl net.core.wmem_max=8388608 26 | #sysctl net.core.wmem_default=65536 27 | #sysctl net.core.rmem_default=65536 28 | sysctl net.core.wmem_default=131072 29 | sysctl net.core.rmem_default=131072 30 | sysctl net.ipv4.tcp_window_scaling=1 31 | sysctl net.ipv4.tcp_mem='98304 131072 196608' 32 | 33 | # determine interfaces found OTF xxx 2017.0319 34 | #for e in `ifconfig -a |grep flags |awk '{print $1}'`; do 35 | 36 | for e in $(ifconfig -a |grep flags |awk -F: '{print $1}'); do 37 | ifconfig $e txqueuelen 5000 38 | #ifconfig eth1 txqueuelen 5000 39 | done 40 | 41 | ifconfig -a > /root/ifconfig-a.txt 42 | ip a >> /root/ifconfig-a.txt 43 | chmod 500 /root/ifconfig-a.txt 44 | 45 | 46 | #http://datatag.web.cern.ch/datatag/howto/tcp.html 47 | #sysctl sys.net.core.netdev_max_backlog=2000 # unknown 48 | ##sysctl net.ipv4.tcp_sack=0 49 | -------------------------------------------------------------------------------- /gnu-screen-to-tmux-translation.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kneutron/ansitest/ceafcc8d2a7ec1e6b2a9fbe04e5f443515ebc0c2/gnu-screen-to-tmux-translation.docx -------------------------------------------------------------------------------- /hd-power-status: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # query drives for spindown state 3 | #hdparm -C /dev/sd? |awk 'NF>0' 4 | hdparm -C /dev/sd? 2>/dev/null |awk 'NF>0' |paste - - 5 | date 6 | -------------------------------------------------------------------------------- /ipreset: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | iptables -P INPUT ACCEPT 4 | iptables -P OUTPUT ACCEPT 5 | iptables -P FORWARD ACCEPT 6 | 7 | iptables -F 8 | iptables -X 9 | 10 | iptables -t nat -F 11 | iptables -t nat -X 12 | 13 | # Specifically allow ssh 14 | # iptables -A INPUT -p tcp --dport 22 -m conntrack --ctstate NEW,ESTABLISHED -j ACCEPT 15 | # iptables -A OUTPUT -p tcp --sport 22 -m conntrack --ctstate ESTABLISHED -j ACCEPT 16 | 17 | iptables -L -v 18 | echo '==============================' 19 | iptables -L -t nat -v 20 | -------------------------------------------------------------------------------- /logecho.mrg: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Echo something to current console AND log 3 | # Can also handle piped input ( cmd |logecho ) 4 | # Warning: Has trouble echoing '*' even when quoted. 5 | function logecho () { 6 | args=$@ 7 | 8 | if [ -z "$args" ]; then 9 | args='tmp' 10 | 11 | while [ 1 ]; do 12 | read -e -t2 args 13 | 14 | if [ -n "$args" ]; then 15 | echo $args |tee -a $logfile; 16 | else 17 | break; 18 | fi 19 | done 20 | 21 | else 22 | echo $args |tee -a $logfile; 23 | fi 24 | } # END FUNC 25 | -------------------------------------------------------------------------------- /manTtoPS.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | man -t $1 > $(basename $1).ps -------------------------------------------------------------------------------- /mk-index-jpg.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 2022 Dave Bechtel 4 | # Create an index .jpg with thumbnails for images in multiple subdirs, one index jpg per subdir 5 | # REF: https://ostechnix.com/how-to-create-a-montage-from-images-in-linux/ 6 | 7 | # CD to where you need to be b4 running 8 | # cd $HOME/Pictures $ $0 9 | 10 | # REQUIRES: imagemagick , findutils , parallel 11 | 12 | # del existing montage jpg first so we dont do Inception 13 | outfile=0montage.jpg 14 | 15 | set -u # abort on uninit var 16 | echo "Precleaning $outfile in this dir tree" 17 | find . -name "$outfile" -print -delete 18 | set +u 19 | 20 | if [ "$1" = "" ]; then 21 | echo "Single tasking" 22 | time find . -type d -print -exec montage -geometry 192x192\>+1+1 -set label '%f\n%wx%h' {}/\* {}/$outfile \; 23 | else 24 | echo "Using multi-cpu" 25 | time find . -type d -print \ 26 | | parallel -I@ --max-args 1 \ 27 | montage -geometry 192x192\>+1+1 -set label '%f\n%wx%h' @/\* @/$outfile 28 | # WARNING be aware that montage can use MULTIPLE GIGS OF RAM 29 | fi 30 | 31 | # ^ Find directories starting in this dir (and processing current directory 32 | # as well), print what it finds to somewhat track progress, run montage on 33 | # the files in that dir (you need to escape the star to avoid bash 34 | # autocomplete) with resulting output file named 0montage.jpg in the found dir. 35 | # PROTIP Prefacing the filename with 0 should sort it to the top in a file manager 36 | 37 | date 38 | 39 | exit; 40 | 41 | To open all the resulting index files (on OSX): 42 | 43 | for f in $(find . -name 0montage\*); do open $f; done 44 | # ^ Adapt to your Linux filemanager or you can use imagemagick ' display ' 45 | 46 | Use "find * " to only process subdirs, not curdir 47 | 48 | REF: https://opensource.com/article/18/5/gnu-parallel 49 | 50 | $ find . -name "*jpeg" | parallel -I% --max-args 1 convert % %.png 51 | -I% creates a placeholder, called %, to stand in for whatever find hands over to Parallel. 52 | -------------------------------------------------------------------------------- /mon1-df-short: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # called by mon1 or topscrn, show in xterm window or text console without getting too wide - useful with zfs 4 | # Save to /usr/local/bin 5 | 6 | # Hides some fields and sorts on field 3 (free space) 7 | df -T -h |grep -v tmpfs |awk '{$1="";$3=""; print}' |column -t |sort -h -k 3 8 | -------------------------------------------------------------------------------- /mon1-tmux-4pane.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | tmux new-session \; \ 4 | send-keys 'topp' C-m \; \ 5 | split-window -v -p 70 \; \ 6 | send-keys 'bwmm' C-m \; \ 7 | split-window -v \; \ 8 | send-keys 'ziostatt' C-m \; \ 9 | select-pane -t 1 \; \ 10 | split-window -h \; \ 11 | send-keys 'watch -n 61 /home/dave/bin/mon1-df-short' C-m \; 12 | -------------------------------------------------------------------------------- /mount-var-cache-apt-sshfs.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # REF: https://superuser.com/questions/32884/sshfs-mount-without-compression-or-encryption 3 | 4 | # Proof of concept, mount /var/cache/apt to a networked location with more free space so can DL packages for Debian/derived upgrade 5 | # Useful for raspberry pi SDCARD, other systems you should be able to add another disk (virtual) or use USB external disk 6 | # REQUIRES: sshfs, rsync 7 | 8 | # failexit.mrg 9 | function failexit () { 10 | echo '! Something failed! Code: '"$1 $2" # code # (and optional description) 11 | exit $1 12 | } 13 | 14 | [ $(which sshfs |wc -l) -gt 0 ] || (apt-get update; apt-get install -y sshfs rsync) 15 | 16 | /bin/mv -v /var/cache/apt /var/cache/apt-old 17 | mkdir -pv /var/cache/apt 18 | 19 | #sshfs -o sshfs_debug -d -C -o Ciphers=chacha20-poly1305@openssh.com user@imacdual-linux:/zredteraB/shrcompr-zrtB /mnt/imacdual -o nonempty 20 | # xxx TODO EDITME 21 | sshfs -C -o Ciphers=chacha20-poly1305@openssh.com \ 22 | dave@10.9.13.4:/Volumes/sgtera2/var-cache-apt /var/cache/apt -o idmap=user 23 | df -hT 24 | 25 | ls -al /var/cache 26 | [ $(df |grep -c /var/cache/apt) -gt 0 ] || failexit 101 "/var/cache/apt not mounted" 27 | 28 | cd /var/cache/apt-old 29 | pwd 30 | echo "Enter to copy OLD /var/cache/apt files over, or ^C" 31 | read 32 | 33 | #time cp -apRv * /var/cache/apt 34 | time rsync -av --remove-source-files --delete-after --max-delete=1 --prune-empty-dirs --progress \ 35 | /var/cache/apt-old/* /var/cache/apt/ 36 | 37 | ls -alh /var/cache/apt 38 | -------------------------------------------------------------------------------- /multiple-sed-example.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # convert short disk names to long OTF, should also work fine with zpool iostat 4 | 5 | # yes, this works without line continuation :) 6 | 7 | subst='s/sdp/ata-ST4000VN000-1H4168_Z3073Z7/; 8 | s/sdo/ata-ST4000VN000-1H4168_Z3076XV/; 9 | s/sdn/ata-ST4000VN008-2DR166_ZDHB3DR/; 10 | s/sdm/ata-ST4000VN008-2DR166_ZDHB41B/; 11 | s/sdd/ata-ST4000VN008-2DR166_ZDHBCLL/; 12 | s/sdc/ata-ST4000VN008-2DR166_ZDHBDGP/' 13 | 14 | # awk NF omits blank lines 15 | zpool status -v \ 16 | |awk 'NF>0' \ 17 | |sed "$subst" 18 | 19 | exit; 20 | 21 | Given: 22 | 23 | pool: zseatera4 24 | state: ONLINE 25 | config: 26 | NAME STATE READ WRITE CKSUM 27 | zseatera4 ONLINE 0 0 0 28 | raidz2-0 ONLINE 0 0 0 29 | sdc ONLINE 0 0 0 30 | sdd ONLINE 0 0 0 31 | sdp ONLINE 0 0 0 32 | sdo ONLINE 0 0 0 33 | sdn ONLINE 0 0 0 34 | sdm ONLINE 0 0 0 35 | errors: No known data errors 36 | 37 | Outputs: 38 | 39 | pool: zseatera4 40 | state: ONLINE 41 | config: 42 | NAME STATE READ WRITE CKSUM 43 | zseatera4 ONLINE 0 0 0 44 | raidz2-0 ONLINE 0 0 0 45 | ata-ST4000VN008-2DR166_ZDHBDGP ONLINE 0 0 0 46 | ata-ST4000VN008-2DR166_ZDHBCLL ONLINE 0 0 0 47 | ata-ST4000VN000-1H4168_Z3073Z7 ONLINE 0 0 0 48 | ata-ST4000VN000-1H4168_Z3076XV ONLINE 0 0 0 49 | ata-ST4000VN008-2DR166_ZDHB3DR ONLINE 0 0 0 50 | ata-ST4000VN008-2DR166_ZDHB41B ONLINE 0 0 0 51 | errors: No known data errors 52 | -------------------------------------------------------------------------------- /powershell/2023-Apr.csv: -------------------------------------------------------------------------------- 1 | Su,Mo,Tu,We,Th,Fr,Sa,, 2 | ,,,,,,1,, 3 | 2,3,4,5,6,7,8,, 4 | 9,10,11,12,13,14,15,, 5 | 16,17,18,19,20,21,22,, 6 | 23,24,25,26,27,28,29,, 7 | 30,,,,,,,, 8 | -------------------------------------------------------------------------------- /powershell/2023-Aug.csv: -------------------------------------------------------------------------------- 1 | Su,Mo,Tu,We,Th,Fr,Sa,, 2 | ,,1,2,3,4,5,, 3 | 6,7,8,9,10,11,12,, 4 | 13,14,15,16,17,18,19,, 5 | 20,21,22,23,24,25,26,, 6 | 27,28,29,30,31,,,, 7 | ,,,,,,,, 8 | -------------------------------------------------------------------------------- /powershell/2023-Dec.csv: -------------------------------------------------------------------------------- 1 | Su,Mo,Tu,We,Th,Fr,Sa,, 2 | ,,,,,1,2,, 3 | 3,4,5,6,7,8,9,, 4 | 10,11,12,13,14,15,16,, 5 | 17,18,19,20,21,22,23,, 6 | 24,25,26,27,28,29,30,, 7 | 31,,,,,,,, 8 | -------------------------------------------------------------------------------- /powershell/2023-Feb.csv: -------------------------------------------------------------------------------- 1 | Su,Mo,Tu,We,Th,Fr,Sa,, 2 | ,,,1,2,3,4,, 3 | 5,6,7,8,9,10,11,, 4 | 12,13,14,15,16,17,18,, 5 | 19,20,21,22,_2_3,24,25,, 6 | 26,27,28,,,,,, 7 | ,,,,,,,, 8 | -------------------------------------------------------------------------------- /powershell/2023-Jan.csv: -------------------------------------------------------------------------------- 1 | Su,Mo,Tu,We,Th,Fr,Sa,, 2 | 1,2,3,4,5,6,7,, 3 | 8,9,10,11,12,13,14,, 4 | 15,16,17,18,19,20,21,, 5 | 22,23,24,25,26,27,28,, 6 | 29,30,31,,,,,, 7 | ,,,,,,,, 8 | -------------------------------------------------------------------------------- /powershell/2023-Jul.csv: -------------------------------------------------------------------------------- 1 | Su,Mo,Tu,We,Th,Fr,Sa,, 2 | ,,,,,,1,, 3 | 2,3,4,5,6,7,8,, 4 | 9,10,11,12,13,14,15,, 5 | 16,17,18,19,20,21,22,, 6 | 23,24,25,26,27,28,29,, 7 | 30,31,,,,,,, 8 | -------------------------------------------------------------------------------- /powershell/2023-Jun.csv: -------------------------------------------------------------------------------- 1 | Su,Mo,Tu,We,Th,Fr,Sa,, 2 | ,,,,1,2,3,, 3 | 4,5,6,7,8,9,10,, 4 | 11,12,13,14,15,16,17,, 5 | 18,19,20,21,22,23,24,, 6 | 25,26,27,28,29,30,,, 7 | ,,,,,,,, 8 | -------------------------------------------------------------------------------- /powershell/2023-Mar.csv: -------------------------------------------------------------------------------- 1 | Su,Mo,Tu,We,Th,Fr,Sa,, 2 | ,,,1,2,3,4,, 3 | 5,6,7,8,9,10,11,, 4 | 12,13,14,15,16,17,18,, 5 | 19,20,21,22,23,24,25,, 6 | 26,27,28,29,30,31,,, 7 | ,,,,,,,, 8 | -------------------------------------------------------------------------------- /powershell/2023-May.csv: -------------------------------------------------------------------------------- 1 | Su,Mo,Tu,We,Th,Fr,Sa,, 2 | ,1,2,3,4,5,6,, 3 | 7,8,9,10,11,12,13,, 4 | 14,15,16,17,18,19,20,, 5 | 21,22,23,24,25,26,27,, 6 | 28,29,30,31,,,,, 7 | ,,,,,,,, 8 | -------------------------------------------------------------------------------- /powershell/2023-Nov.csv: -------------------------------------------------------------------------------- 1 | Su,Mo,Tu,We,Th,Fr,Sa,, 2 | ,,,1,2,3,4,, 3 | 5,6,7,8,9,10,11,, 4 | 12,13,14,15,16,17,18,, 5 | 19,20,21,22,23,24,25,, 6 | 26,27,28,29,30,,,, 7 | ,,,,,,,, 8 | -------------------------------------------------------------------------------- /powershell/2023-Oct.csv: -------------------------------------------------------------------------------- 1 | Su,Mo,Tu,We,Th,Fr,Sa,, 2 | 1,2,3,4,5,6,7,, 3 | 8,9,10,11,12,13,14,, 4 | 15,16,17,18,19,20,21,, 5 | 22,23,24,25,26,27,28,, 6 | 29,30,31,,,,,, 7 | ,,,,,,,, 8 | -------------------------------------------------------------------------------- /powershell/2023-Sep.csv: -------------------------------------------------------------------------------- 1 | Su,Mo,Tu,We,Th,Fr,Sa,, 2 | ,,,,,1,2,, 3 | 3,4,5,6,7,8,9,, 4 | 10,11,12,13,14,15,16,, 5 | 17,18,19,20,21,22,23,, 6 | 24,25,26,27,28,29,30,, 7 | ,,,,,,,, 8 | -------------------------------------------------------------------------------- /powershell/DVDs.csv: -------------------------------------------------------------------------------- 1 | Peter 2 | Paul 3 | Mary -------------------------------------------------------------------------------- /powershell/cdarg.ps1: -------------------------------------------------------------------------------- 1 | #!/usr/local/bin/pwsh 2 | 3 | <# REF: https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_switch?view=powershell-7.3 #> 4 | 5 | $param1=$args[0] 6 | Write-Output $param1 7 | 8 | # switch -Regex $(param1) 9 | # 'bincloud|binc' {} 10 | 11 | switch ($param1) 12 | { 13 | 1 {cd ~/bin/powershell } 14 | # 2 {cd "c:\users\$env:UserName" } 15 | # 3 {cd "c:\users\$env:UserName\Desktop\Docs-local\bin-cloud" } 16 | shr {cd /Volumes/zhgstera6/shrcompr-zhgst6 } 17 | notshr {cd /Volumes/zhgstera6/notshrcompr-zhgst6 } 18 | dvd {cd /Volumes/zhgstera6/dvdrips-shr/MAKEMKV } 19 | 20 | Default { Write-Output "Fallthru, no match" } 21 | } 22 | 23 | Get-Location # pwd -------------------------------------------------------------------------------- /powershell/hats.csv: -------------------------------------------------------------------------------- 1 | Sam 2 | Mary 3 | Trevor 4 | Ted 5 | -------------------------------------------------------------------------------- /powershell/pants.csv: -------------------------------------------------------------------------------- 1 | Bob 2 | Mary 3 | Jane 4 | Ted 5 | Paul 6 | Peter 7 | -------------------------------------------------------------------------------- /powershell/shirts.csv: -------------------------------------------------------------------------------- 1 | Bob 2 | Mary 3 | Jane 4 | Ted 5 | Peter -------------------------------------------------------------------------------- /powershell/test-progressbar-ls.ps1: -------------------------------------------------------------------------------- 1 | <# REF: https://techgenix.com/adding-a-progress-bar-to-your-powershell-scripts/ #> 2 | 3 | cd /Volumes/zhgstera6/shrcompr-zhgst6 4 | 5 | $List = Get-Childitem 6 | 7 | $TotalItems=$List.Count 8 | $CurrentItem = 0 9 | $PercentComplete = 0 10 | 11 | ForEach($file in $List) 12 | { 13 | Write-Progress -Activity "LS Filenames" ` 14 | -Status "$PercentComplete% Complete: $CurrentItem / $TotalItems" ` 15 | -PercentComplete $PercentComplete 16 | 17 | # do a thing here 18 | #$Name = $VM.Name 19 | #Get-VM -Name $Name 20 | 21 | $CurrentItem++ 22 | $PercentComplete = [int](($CurrentItem / $TotalItems) * 100) 23 | Start-Sleep -Milliseconds 10 24 | } 25 | -------------------------------------------------------------------------------- /powershell/win-show-error-log-common--RUN-AS-ADMIN.ps1: -------------------------------------------------------------------------------- 1 | <# REF: https://www.reddit.com/r/PowerShell/comments/10dbu5o/find_frequent_event_viewer_errors_lookup_their/ 2 | #> 3 | 4 | # Clear the console screen for a fresh start 5 | Clear-Host 6 | 7 | # Function to retrieve and filter events from the System log 8 | function Get-SystemEvents { 9 | # Retrieve events from the "System" event log that have a level of 2 or 3 10 | Get-WinEvent -LogName System -FilterXPath "*[System[Level=2 or Level=3]]" | 11 | 12 | # Create a custom object for each event 13 | ForEach-Object { 14 | [PSCustomObject]@{ 15 | EventID = $_.Id 16 | Message = $_.Message 17 | Count = 1 18 | } 19 | } | 20 | 21 | # Group the objects by the EventID 22 | Group-Object -Property EventID | 23 | 24 | # Sort the groups by the Count in descending order 25 | Sort-Object -Property Count -Descending | 26 | 27 | # Select the first 5 groups 28 | Select-Object @{Name='Count'; Expression={$_.Count}}, 29 | @{Name='Event ID'; Expression={$_.Group[0].EventID}}, 30 | @{Name='Message'; Expression={$_.Group[0].Message}} -First 5 31 | } 32 | 33 | Write-Host "Checking your computer for most frequent errors..." -ForegroundColor Yellow 34 | 35 | # Pause so user can read 36 | Start-Sleep 3 37 | 38 | # Call the function once to display results in console 39 | Get-SystemEvents | 40 | 41 | # Without Out-Host piped, Write-Host will steal the spotlight and hide function output 42 | Out-Host 43 | 44 | # Inform user you will find solutions 45 | Write-Host "Please wait. I will retrieve your solutions..." -ForegroundColor Green 46 | 47 | # Put the events into a variable to iterate through 48 | $Events = Get-SystemEvents 49 | 50 | # Pause so user can read 51 | Start-Sleep 5 52 | 53 | # Iterate through each event 54 | foreach ($Event in $Events) { 55 | # Create a search string by combining the EventID and Message properties 56 | $SearchString = "$($Event.EventID) $($Event.Message)" 57 | # Replace spaces with "+" 58 | $SearchString = $SearchString -replace ' ', '+' 59 | # Open the search results in Microsoft Edge (in case default browser is set to a malware browser) 60 | Start-Process "msedge.exe" -ArgumentList "https://www.bing.com/search?q=$SearchString+site:microsoft.com" 61 | } 62 | -------------------------------------------------------------------------------- /proxmox/BKPDEST.mrg: -------------------------------------------------------------------------------- 1 | # bash - this is defining where backup tars, fsarchive, etc will be stored - can be local, sshfs, CIFS, NFS but must be R/W 2 | # can be overridden b4 sourcing (set bkpdest var before sourcing this and you will still get the mount functionality) 3 | 4 | echo "Thank you for using kneutron scripts. If you appreciate them and wish to send some support, please visit:" 5 | echo " https://ko-fi.com/kingneutron " 6 | 7 | # NOTE this script should be in /root/bin/boojum and be chmod +x 8 | # it is sourced / used by several backup scripts 9 | 10 | # you can have it live elsewhere (like /root) for convenience and soft-symlink to it if needed 11 | # but the scripts are checking for it in /root/bin/boojum 12 | 13 | # e.g. 14 | # mkdir -pv /root/bin/boojum 15 | # ln -sfn /root/BKPDEST.mrg /root/bin/boojum/ 16 | 17 | ## and save BKPDEST in /root 18 | ## thus the bkpdest will be in /root for convenience, but still pointed to by the soft symlink in the usual location 19 | ## that the scripts expect 20 | 21 | # xxx TODO EDITME - this is where your backups will be stored - NEEDS TO BE ON A SEPARATE DISK FROM ROOT! 22 | #[ "$bkpdest" = "" ] && export bkpdest=/mnt/imac5 23 | [ "$bkpdest" = "" ] && export bkpdest=/mnt/seatera4-xfs 24 | 25 | [ $(echo $bkpdest |grep -c "/mnt/") -gt 0 ] && mount $bkpdest # mount if not ZFS - needs to be properly defined in /etc/fstab 26 | [ $(echo $bkpdest |grep -c "/media/") -gt 0 ] && mount $bkpdest # mount if not ZFS 27 | 28 | # from failexit.mrg 29 | function failexit () { 30 | echo '! Something failed! Code: '"$1 $2" # code # (and optional description) 31 | exit $1 32 | } 33 | 34 | 35 | [ -e "$bkpdest/NOTHERE" ] && failexit 99 "$bkpdest NOTHERE detected -- NOT MOUNTED" 36 | # "If" checking for NOTHERE file... 37 | 38 | chkmount=$(df |grep -c $bkpdest) 39 | [ $chkmount -gt 0 ] || failexit 99 "$bkpdest NOT MOUNTED" 40 | 41 | # NOTE code 199 is generally could not cd to dir 42 | 43 | export myhn=$(hostname) 44 | -------------------------------------------------------------------------------- /proxmox/HOWTO-make-a-file-backed-backup-of-proxmox-rpool.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kneutron/ansitest/ceafcc8d2a7ec1e6b2a9fbe04e5f443515ebc0c2/proxmox/HOWTO-make-a-file-backed-backup-of-proxmox-rpool.docx -------------------------------------------------------------------------------- /proxmox/cluster-3-node-with-pi-or-vm-qdevice.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # REF: https://www.youtube.com/watch?v=jAlzBm40onc 4 | # This is when you really only have 2 nodes but need a 3rd vote for quorum 5 | # Can setup debian vm with 512MB RAM OUTSIDE the cluster as long as its on the same LAN 6 | 7 | # NOTE do not mix CPU types on host - all AMD or all Intel are OK 8 | 9 | # do on all nodes in cluster 10 | apt update 11 | apt install -y corosync-qdevice 12 | 13 | # TODO EDITME 14 | pvecm qdevice setup 192.168.1.12 # vm on macpro, static ip 15 | 16 | pvecm status 17 | -------------------------------------------------------------------------------- /proxmox/convert-vdi-disks-to-qcow2.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # to convert existing virtualbox VDI disks to qcow2, for import into proxmox vm environment 4 | # 2024 kneutron 5 | 6 | # xxx TODO EDITME - this is the base dir for virtualbox / disk images 7 | based="/zseatera4-f4m8/virtbox-virtmachines" 8 | cd "$based" || exit 44; 9 | 10 | # xxx TODO EDITME - this is where converted disks .qcow2 will go 11 | dest=/mnt/seatera4-xfs 12 | 13 | for disk in $(find -name *.vdi |sed 's|^./||'); do 14 | dirn=$(dirname "$disk") 15 | cd "$based/$dirn"; echo "HERE is: $PWD" 16 | 17 | diskn=$(basename "$disk") 18 | 19 | #echo "dirn=$dirn" 20 | #echo "disk=$disk" 21 | #echo "diskn=$diskn" 22 | 23 | echo "$(date) - Converting $PWD $diskn" 24 | time qemu-img convert -f vdi -O qcow2 "$PWD/$diskn" "$dest/$diskn.qcow2" 25 | # cd "$based" 26 | done 27 | 28 | ls -alh "$dest" 29 | date 30 | -------------------------------------------------------------------------------- /proxmox/dot-config-htop-htoprc: -------------------------------------------------------------------------------- 1 | # Beware! This file is rewritten by htop when settings are changed in the interface. 2 | # The parser is also very primitive, and not human-friendly. 3 | htop_version=3.2.2 4 | config_reader_min_version=3 5 | fields=0 48 17 18 38 39 40 2 46 47 49 1 6 | hide_kernel_threads=1 7 | hide_userland_threads=0 8 | hide_running_in_container=0 9 | shadow_other_users=0 10 | show_thread_names=0 11 | show_program_path=1 12 | highlight_base_name=0 13 | highlight_deleted_exe=1 14 | shadow_distribution_path_prefix=0 15 | highlight_megabytes=1 16 | highlight_threads=1 17 | highlight_changes=0 18 | highlight_changes_delay_secs=5 19 | find_comm_in_cmdline=1 20 | strip_exe_from_cmdline=1 21 | show_merged_command=0 22 | header_margin=1 23 | screen_tabs=1 24 | detailed_cpu_time=0 25 | cpu_count_from_one=0 26 | show_cpu_usage=1 27 | show_cpu_frequency=0 28 | show_cpu_temperature=0 29 | degree_fahrenheit=0 30 | update_process_names=0 31 | account_guest_in_cpu_meter=0 32 | color_scheme=0 33 | enable_mouse=1 34 | delay=22 35 | hide_function_bar=0 36 | header_layout=two_50_50 37 | column_meters_0=LeftCPUs Memory Swap 38 | column_meter_modes_0=1 1 1 39 | column_meters_1=RightCPUs Tasks LoadAverage Uptime 40 | column_meter_modes_1=1 2 2 2 41 | tree_view=0 42 | sort_key=46 43 | tree_sort_key=0 44 | sort_direction=-1 45 | tree_sort_direction=1 46 | tree_view_always_by_pid=0 47 | all_branches_collapsed=0 48 | screen:Main=PID USER PRIORITY NICE M_VIRT M_RESIDENT M_SHARE STATE PERCENT_CPU PERCENT_MEM TIME Command 49 | .sort_key=PERCENT_CPU 50 | .tree_sort_key=PID 51 | .tree_view=0 52 | .tree_view_always_by_pid=0 53 | .sort_direction=-1 54 | .tree_sort_direction=1 55 | .all_branches_collapsed=0 56 | screen:I/O=PID USER IO_PRIORITY IO_RATE IO_READ_RATE IO_WRITE_RATE PERCENT_SWAP_DELAY PERCENT_IO_DELAY Command 57 | .sort_key=IO_RATE 58 | .tree_sort_key=PID 59 | .tree_view=0 60 | .tree_view_always_by_pid=0 61 | .sort_direction=-1 62 | .tree_sort_direction=1 63 | .all_branches_collapsed=0 64 | -------------------------------------------------------------------------------- /proxmox/get-latest-zfsbootmenu.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # REF: https://docs.zfsbootmenu.org/en/v3.0.x/general/portable.html 4 | 5 | curl -k --output BOOTX64.EFI -LJO https://get.zfsbootmenu.org/efi/recovery 6 | ls -alh 7 | -------------------------------------------------------------------------------- /proxmox/importvm-win10.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Import converted virtualbox VDI disks for proxmox vm 4 | # 2024 kneutron 5 | 6 | # NOTE if destination storage is zfs, vm's disk will be a zvol 7 | 8 | source ~/bin/failexit.mrg 9 | 10 | # xxx TODO EDITME - converted qcows from vbox 11 | cd /mnt/seatera4-xfs 12 | 13 | echo "Usage: \$1=name-of-vm \$2=RAM-in-GB [optional]" 14 | 15 | if [ "$1" = "" ]; then 16 | failexit 101 "1st arg not supplied, must be VMNAME" 17 | else 18 | newname="$1" 19 | fi 20 | 21 | #linux=l26 22 | #oldlinux=l24 23 | 24 | # integer / number 25 | declare -i ram lastid newid 26 | 27 | if [ "$2" = "" ]; then 28 | ram=4096 29 | else 30 | ram=$2 31 | fi 32 | 33 | echo "$(date) - Getting last VM number" 34 | lastid=$(qm list |tail -n 1 |awk '{print $1}') 35 | date 36 | # qm list 37 | # VMID NAME STATUS MEM(MB) BOOTDISK(GB) PID 38 | # 100 lmde stopped 4096 21.00 0 39 | # 101 pxenetboot stopped 4096 21.00 0 40 | # 103 win10-restore-from-vbox-choco stopped 6144 80.00 0 41 | # 104 pfsense-272 running 1500 20.00 813250 42 | 43 | let newid=$lastid+1 44 | echo "Last vmid: $lastid - New id: $newid -- RAM: $ram -- PK" 45 | read -n 1 46 | 47 | # --ostype l26 \ 48 | # --boot order=scsi0 \ 49 | qm create $newid \ 50 | --net0 e1000,bridge=vmbr2,firewall=0,link_down=0 \ 51 | --name "$newname" \ 52 | --scsihw virtio-scsi-single \ 53 | --cores 2 --sockets 1 --cpu cputype=host \ 54 | --bios ovmf \ 55 | --ide2 none,media=cdrom \ 56 | --memory $ram \ 57 | --vga=virtio,memory=128 \ 58 | --balloon 2048 \ 59 | --start 0 \ 60 | --boot order="ide2;sata0" \ 61 | --ostype win11 \ 62 | --sata0 zfs1:0,cache=writeback,import-from=$PWD/win11test-chocolatey-wsl2.vdi.qcow2 \ 63 | --sata1 zfs1:0,cache=writeback,import-from=$PWD/win11test-chocolatey-wsl2-disk1.vdi.qcow2 \ 64 | || failexit 40 "Failed to create VM $newid $newname" 65 | 66 | qm list 67 | 68 | exit; 69 | 70 | L, not One 71 | --ostype 72 | -------------------------------------------------------------------------------- /proxmox/ipreset: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Reset all iptables firewall rules 4 | # Useful for systemrescuecd 5 | 6 | iptables -P INPUT ACCEPT 7 | iptables -P OUTPUT ACCEPT 8 | iptables -P FORWARD ACCEPT 9 | 10 | iptables -F 11 | iptables -X 12 | 13 | iptables -t nat -F 14 | iptables -t nat -X 15 | 16 | # Specifically allow ssh 17 | # iptables -A INPUT -p tcp --dport 22 -m conntrack --ctstate NEW,ESTABLISHED -j ACCEPT 18 | # iptables -A OUTPUT -p tcp --sport 22 -m conntrack --ctstate ESTABLISHED -j ACCEPT 19 | 20 | iptables -L -v 21 | echo '==============================' 22 | iptables -L -t nat -v 23 | -------------------------------------------------------------------------------- /proxmox/lxc-fix-timezone.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | echo "RUN THIS INSIDE LXC DEBIAN" 4 | 5 | ln -sfn /usr/share/zoneinfo/America/Denver /etc/localtime 6 | dpkg-reconfigure tzdata 7 | 8 | date 9 | 10 | # REF: https://search.brave.com/search?q=proxmox+timezone+for+lxc&source=desktop&summary=1&conversation=42624bda795fa20034cd71 11 | -------------------------------------------------------------------------------- /proxmox/mkefi.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 2025.Feb kneutron 4 | # for zfsbootmenu 5 | # run from systemrescuecd environment 6 | 7 | # make new gpt partition and a 512MB EFI partition for zfsbootmenu 8 | # AUTHOR TAKES NO RESPONSIBILITY FOR DATA LOSS - GET THE DISK RIGHT!! 9 | 10 | # TODO EDITME - short devname only 11 | drv=vda 12 | [ "$1" = "" ] || drv=$1 13 | 14 | fdisk -l /dev/$drv 15 | echo "Enter to proceed with making EFI zfsmenu boot partition on /dev/$drv, or ^C" 16 | echo "- SCRIPT AUTHOR TAKES NO RESPONSIBILITY FOR DATA LOSS -" 17 | ecgi "GET THE DISK RIGHT - AND HAVE BACKUPS!!" 18 | read 19 | 20 | parted /dev/$drv mklabel gpt 21 | sync 22 | parted --align optimal /dev/$drv mkpart primary fat16 1MiB 512MiB 23 | sync 24 | parted /dev/$drv set 1 boot on 25 | sync 26 | parted /dev/$drv name 1 zfsbootmenuefi 27 | sync 28 | gdisk -l /dev/$drv 29 | 30 | echo "Enter to proceed with mkdosfs, or ^C" 31 | read -n 1 32 | 33 | mkdosfs -F 16 -n zfsbtmnu -v /dev/${drv}1 34 | mkdir -pv /mnt/tmpefi 35 | mount /dev/${drv}1 /mnt/tmpefi 36 | ls -al /mnt/tmpefi 37 | 38 | df -hT 39 | 40 | echo 'Now you can cd to /mnt/tmpefi and run ~/get-latest-zfsbootmenu.sh' 41 | -------------------------------------------------------------------------------- /proxmox/nvme-check-namespace-relative-performance.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | for d in $(ls -1 /dev/nvme?n1); do 4 | echo $d 5 | nvme id-ns -H $d |grep -i relative 6 | done 7 | -------------------------------------------------------------------------------- /proxmox/proxmox-HIBER-RUNNING-VMS.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 2024.feb kneutron 4 | # REF: https://forum.proxmox.com/threads/shutting-down-all-vm-ct-in-parallel.112519/ 5 | 6 | [ $(which parallel |wc -l) -gt 0 ] || apt-get install -y parallel 7 | 8 | VM_LIST=/dev/shm/vmlist.in 9 | 10 | # 1 2 3 11 | # processor : 7 12 | lastcpu=$(grep processor /proc/cpuinfo |tail -n 1 |awk '{print $3}') 13 | [ $lastcpu -gt 1 ] && let lastcpu=$lastcpu-1 14 | 15 | [ -e "$VM_LIST" ] && rm -f "$VM_LIST" # delete the old file ONLY IF it exists 16 | for vmid in $(qm list |grep running |awk '{print $1}'); do 17 | # echo "qm shutdown $vmid" >>"$VM_LIST" 18 | echo "qm suspend $vmid --todisk" >>"$VM_LIST" 19 | done 20 | 21 | echo "$(date) - HIBER ALL VMS using $lastcpu threads" 22 | time cat "$VM_LIST" |parallel -j $lastcpu --progress 23 | date 24 | 25 | exit; 26 | -------------------------------------------------------------------------------- /proxmox/proxmox-SHUTDOWN-RUNNING-VMS.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 2024.feb kneutron 4 | # This does a HIBERNATE to disk, not shutdown -- in parallel 5 | # Useful if you are switched to UPS power and need to shutdown gracefully in minimum time 6 | # NOTE - Will generate A LOT of disk I/O 7 | 8 | # Use "Bulk actions / Bulk shutdown" in the GUI otherwise 9 | 10 | # REF: https://forum.proxmox.com/threads/shutting-down-all-vm-ct-in-parallel.112519/ 11 | 12 | [ $(which parallel |wc -l) -gt 0 ] || apt-get install -y parallel 13 | 14 | VM_LIST=/dev/shm/vmlist.in 15 | 16 | # 1 2 3 17 | # processor : 7 18 | lastcpu=$(grep processor /proc/cpuinfo |tail -n 1 |awk '{print $3}') 19 | [ $lastcpu -gt 1 ] && let lastcpu=$lastcpu-1 20 | 21 | [ -e "$VM_LIST" ] && rm -f "$VM_LIST" # delete the old file ONLY IF it exists 22 | for vmid in $(qm list |grep running |awk '{print $1}'); do 23 | echo "qm shutdown $vmid" >>"$VM_LIST" 24 | # echo "qm suspend $vmid --todisk" >>"$VM_LIST" 25 | done 26 | 27 | echo "$(date) - HIBER ALL VMS using $lastcpu threads" 28 | time cat "$VM_LIST" |parallel -j $lastcpu --progress 29 | date 30 | 31 | exit; 32 | -------------------------------------------------------------------------------- /proxmox/proxmox-START-VMS-parallel.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 2024.Apr kneutron 4 | # REF: https://forum.proxmox.com/threads/shutting-down-all-vm-ct-in-parallel.112519/ 5 | 6 | [ $(which parallel |wc -l) -gt 0 ] || apt-get install -y parallel 7 | 8 | VM_LIST=~/vmlist.in # put the number of the VMs that you want to parastart in this file 9 | # TODO MAKE SURE you uncheck " Start at boot " in the VM/ctr options, or proxmox startup will interfere with what this script is trying to do! 10 | 11 | tmpout=/dev/shm/vms-parallel-start.in 12 | 13 | # 1 2 3 14 | # processor : 7 15 | lastcpu=$(grep processor /proc/cpuinfo |tail -n 1 |awk '{print $3}') 16 | [ $lastcpu -gt 1 ] && let lastcpu=$lastcpu-1 17 | 18 | # You can manually set a lower limit here 19 | let lastcpu=3 20 | 21 | [ -e "$tmpout" ] && rm -f "$tmpout" # delete the old file ONLY IF it exists 22 | for vmid in $(cat $VM_LIST); do 23 | echo "qm start $vmid" >>"$tmpout" 24 | # echo "qm suspend $vmid --todisk" >>"$VM_LIST" 25 | done 26 | 27 | echo "$(date) - parallel START VMS using $lastcpu threads" 28 | time cat "$tmpout" |parallel -j $lastcpu --progress 29 | date 30 | 31 | exit; 32 | 33 | 34 | Example ~/vmlist.in: 35 | 36 | 104 37 | 108 38 | 109 39 | 111 40 | 112 41 | -------------------------------------------------------------------------------- /proxmox/proxmox-UNCLUSTER-me.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # REF: https://blog.bianxi.com/2022/06/02/convert-proxmox-cluster-node-to-standalone-local-mode/ 4 | 5 | echo "WARNING - THIS WILL REMOVE THIS NODE FROM CLUSTER AND PUT IT BACK IN STANDALONE MODE!" 6 | echo "Press Enter if youre REALLY SURE or ^C" 7 | read 8 | 9 | systemctl stop pve-cluster 10 | systemctl stop corosync 11 | 12 | pmxcfs -l 13 | 14 | rm /etc/pve/corosync.conf 15 | rm -r /etc/corosync/* 16 | 17 | killall pmxcfs 18 | systemctl start pve-cluster 19 | 20 | #pvecm delnode oldnode 21 | 22 | pvecm expected 1 23 | 24 | rm /var/lib/corosync/* 25 | 26 | echo '=====' 27 | echo "TODO Remove /etc/pve/nodes/ from other nodes." 28 | 29 | echo "TODO Remove ssh key from /etc/pve/priv/authorized_keys file." 30 | -------------------------------------------------------------------------------- /proxmox/proxmox-backup-veeam-agent-setup.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Install veeam agent for linux for bare-metal backup/restore of root FS + LVM 4 | # 2024.May kneutron 5 | 6 | # NOTE you will also need to download the "veeam Linux Recovery Media" ISO to be able to Restore! 7 | # https://www.veeam.com/download_add_packs/backup-agent-linux-free/recovery-64 8 | 9 | # HOWTO video: 10 | # REF: https://www.youtube.com/watch?v=g9J-mmoCLTs 11 | 12 | # NOTE - WARNING - veeam only restores rootfs ext4 + LVM structure, does **NOT** restore LVM-thin! 13 | # You still need to backup your VMs! 14 | 15 | # Install veeam agent for linux 16 | apt update 17 | 18 | apt install pve-headers-$(uname -r) squashfs-tools libisoburn1 xorriso 19 | apt-get install linux-headers-$(uname -r) 20 | 21 | # Needs to be already downloaded and in current dir 22 | # https://www.veeam.com/linux-backup-free-download.html?sec=linux-backup-free-download.html&subsec=&part=&item= 23 | dpkg -i veeam-release*deb 24 | 25 | apt update 26 | apt install -y veeam 27 | 28 | # run the backup setup program TUI 29 | veeam 30 | 31 | exit; 32 | 33 | # to start backup job out of schedule: 34 | # veeamconfig job start --name "BackupJob1" 35 | 36 | NOTE veeam does NOT allow restore to a smaller disk - fsarchiver does! 37 | e.g. if you backed up a 256GB boot disk, you cannot restore your root + LVM with veeam to a 128GB disk! 38 | -------------------------------------------------------------------------------- /proxmox/proxmox-bkp-host-to-pbs.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # REF: https://www.reddit.com/r/Proxmox/comments/tfbhp1/newbie_here_what_are_the_benefits_of_proxmox/ 4 | # REF: https://pbs.proxmox.com/docs/backup-client.html 5 | # REF: https://linuxconfig.org/how-to-create-a-backup-with-proxmox-backup-client 6 | 7 | export PBS_REPOSITORY=10.9.1.23:zpbs1 8 | 9 | date 10 | time proxmox-backup-client backup \ 11 | --include-dev /boot/efi \ 12 | --include-dev /etc/pve \ 13 | root-$(hostname).pxar:/ \ 14 | --repository 10.9.1.23:zpbs1 # : 15 | 16 | date 17 | 18 | exit; 19 | 20 | # root.pxar is name of bkp, / is root dir 21 | 22 | # REF: https://pbs.proxmox.com/docs/backup-client.html 23 | 24 | RESTORE: 25 | Live-restore: This feature can allow you to start a VM when the restore job is started, rather than waiting for it to finish. 26 | 27 | ## proxmox-backup-client snapshot list 28 | 29 | # proxmox-backup-client snapshot list --repository 10.9.1.23:zpbs1 30 | 31 | # proxmox-backup-client restore host/elsa/2019-12-03T09:35:01Z root.pxar /target/path/ 32 | # proxmox-backup-client restore --repository 192.168.122.72:datastore0 host/doc-standardpcq35ich92009/2024-01-11T11:01:49Z etc.pxar /etc 33 | -------------------------------------------------------------------------------- /proxmox/proxmox-cluster-delete-all-snapshots-for-vm.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # REF: https://forum.proxmox.com/threads/feature-request-button-to-delete-all-snapshots-at-once.147460/#post-666313 4 | 5 | # Cluster version - delete all snapshots for a vm 6 | # NOTE this also works on unclustered instances of pve 7 | 8 | # Thanks to original author bbgeek17 9 | # enhanced by kneutron 10 | 11 | # USE AT YOUR OWN RISK - I TAKE NO REPSONSIBILITY FOR DATA LOSS! 12 | 13 | # Depends: jq 14 | [ $(which jq |wc -l) -eq 0 ] && apt install -y jq 15 | 16 | # arg1 = vmid 17 | if [[ $# -lt 1 ]];then 18 | echo "You must provide a parameter!" 19 | echo "USAGE: $0 [VMID]" 20 | exit 1 21 | fi 22 | 23 | logf=~/deleted-snapshots-cluster.log 24 | 25 | set -u # abort on undefined var 26 | 27 | echo "$(date) - Gathering information" 28 | echo '==========' 29 | VMID=$1 30 | NODE=$(pvesh get /cluster/resources --type vm --output-format json \ 31 | |jq --argjson myvmid $VMID -r '.[]|select( .vmid == $myvmid )|.node') 32 | 33 | # show vm info 34 | (pvesh get /cluster/resources --type vm --human-readable 1 --noborder 1 |egrep "cgroup|$1") |column -t 35 | 36 | # TODO test for interactive session 37 | echo '==========' 38 | echo "About to removw ALL snapshots from VM $VMID located on node $NODE - ^C to back out or Enter to proceed" 39 | read 40 | 41 | for snap in $(pvesh get /nodes/$NODE/qemu/$VMID/snapshot --output-format json \ 42 | |jq -r 'sort_by(.snaptime)|.[]|select(.snaptime != null)|.name'); do 43 | echo "$(date) - $(id -un) - $VMID on $NODE - $snap" \ 44 | |tee -a $logf 45 | time pvesh delete /nodes/$NODE/qemu/$VMID/snapshot/$snap 46 | done 47 | 48 | date 49 | -------------------------------------------------------------------------------- /proxmox/proxmox-create-additional-lvm-thin.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 2024.Dec kneutron 4 | # NOTE author takes NO responsibility for data loss, run this at your own risk! 5 | 6 | # This creates an ADDITIONAL lvm-thin on another disk/partition besides the one the PVE installer creates 7 | # Avoids resizing and multiple LVM failures in non-RAID systems 8 | 9 | # xxx TODO EDITME 10 | declare -i lvmthins # integer 11 | if [ "$1" = "" ]; then 12 | lvmthins=2 13 | else 14 | lvmthins=$1 15 | fi 16 | # set to 3, etc if you already have more than 1 17 | 18 | # failexit.mrg 19 | # REF: https://sharats.me/posts/shell-script-best-practices/ 20 | function failexit () { 21 | echo '! Something failed! Code: '"$1 $2" >&2 # code (and optional description) 22 | exit $1 23 | } 24 | 25 | if [ "$1" = "0" ] || [ "$1" -lt 2 ]; then 26 | failexit 66 "Nice try - arg1 needs to be an integer number greater than 1" 27 | fi 28 | 29 | # xxx TODO EDITME 30 | #target=/dev/nvme0n1p6 31 | target=/dev/sdb6 32 | 33 | echo '-- YOU NEED TO EDIT THIS SCRIPT BEFORE RUNNING IT --' 34 | echo "About to create lvm-thin number: $lvmthins on $target - Enter to continue or ^C" 35 | read -n 1 36 | 37 | pvcreate $target 38 | echo "$(date) - vgcreate pvethin${lvmthins} on $target" 39 | time vgcreate -A y pvethin${lvmthins} $target 40 | # pvethin2 41 | 42 | #lvcreate -L 100G -n data pve 43 | echo "$(date) - lvcreate lvmthin${lvmthins}data on VG pvethin${lvmthins}" 44 | time lvcreate -A y --readahead auto \ 45 | --name lvmthin${lvmthins}data --extent 99%FREE pvethin${lvmthins} || failexit 99 "Failed to lvcreate lvmthin${lvmthins}data on VG pvethin${lvmthins}" 46 | # lvmthin2 , pvethin2 47 | 48 | echo "$(date) - lvconvert to thin pool: pvethin${lvmthins}/lvmthin${lvmthins}data" 49 | time lvconvert --type thin-pool pvethin${lvmthins}/lvmthin${lvmthins}data || failexit 101 "Failed to convert pvethin${lvmthins}/lvmthin${lvmthins}data to lvm-thin" 50 | # pvethin2 , lvmthin2 51 | 52 | (pvs; vgs; lvs) |tee >/root/lvminfo.txt 53 | 54 | # backup lvm config for DR - see man page 55 | # In a default installation, each VG is backed up into a separate file bearing the name of the VG in the directory /etc/lvm/backup. 56 | # It may also be useful to regularly back up the files in /etc/lvm. 57 | vgcfgbackup 58 | 59 | echo "Define storage in pve GUI as lvm-thin${lvmthins}" 60 | ls -lh /root/lvminfo.txt 61 | -------------------------------------------------------------------------------- /proxmox/proxmox-create-lvm-thin.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # this create an lvm-thin with the same naming scheme the proxmox installer uses 4 | 5 | # xxx TODO EDITME 6 | target=/dev/sda4 7 | 8 | echo '*** YOU NEED TO EDIT THIS SCRIPT BEFORE RUNNING IT ***' 9 | echo '*** AUTHOR IS NOT RESPONSIBLE FOR DATA LOSS!! ***' 10 | echo '' 11 | echo "About to create lvm-thin on $target - Enter to continue or ^C" 12 | read 13 | 14 | pvcreate $target 15 | vgcreate -A y pve $target 16 | 17 | #lvcreate -L 100G -n data pve 18 | lvcreate -A y --readahead auto \ 19 | --name data --extent 99%FREE pve 20 | 21 | lvconvert --type thin-pool pve/data 22 | 23 | (pvs; vgs; lvs) |tee >/root/lvminfo.txt 24 | echo "Define storage in pve GUI as local-lvm" 25 | -------------------------------------------------------------------------------- /proxmox/proxmox-create-zfs-boot-disk-partitions.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # NOTE I TAKE NO RESPONSIBILITY FOR DATA LOSS, EDIT THIS SCRIPT BEFORE RUNNING 4 | # AND MAKE SURE YOU DESIGNATE THE RIGHT DISKS! 5 | 6 | # REF: https://www.reddit.com/r/Proxmox/comments/1cr6wn7/tutorial_howto_migrate_a_pve_zfs_bootroot_mirror/ 7 | 8 | # TODO EDITME 9 | for disk in vdc vdd; do 10 | echo $disk 11 | sgdisk -g \ 12 | -n 1:0:+1M \ 13 | -n 2:0:+1G \ 14 | -n 3:0:0 \ 15 | -t 1:8300 \ 16 | -t 2:EF00 \ 17 | -t 3:BF01 \ 18 | -p /dev/$disk 19 | 20 | gdisk -l /dev/$disk 21 | done 22 | 23 | exit; 24 | 25 | Device Start End Sectors Size Type 26 | /dev/nvme0n1p1 34 2047 2014 1007K BIOS boot 27 | /dev/nvme0n1p2 2048 2099199 2097152 1G EFI System 28 | /dev/nvme0n1p3 2099200 167772160 165672961 119G ZFS 29 | 30 | # REFs: 31 | https://forum.proxmox.com/threads/replace-512gb-ssds-with-500gb-ssds.143077/ 32 | 33 | https://pve.proxmox.com/wiki/ZFS_on_Linux#sysadmin_zfs_change_failed_dev 34 | 35 | https://pve.proxmox.com/wiki/Host_Bootloader#sysboot_proxmox_boot_tool 36 | 37 | https://forum.proxmox.com/threads/fixing-uefi-boot.87719/ 38 | -------------------------------------------------------------------------------- /proxmox/proxmox-del-fleece-datasets.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | set -u 5 | 6 | zfs list |grep fleece 7 | 8 | echo "$(date) - About to destroy the above fleece datasets - ^C to backout or Enter to proceed" 9 | read 10 | 11 | zfs-killsnaps.sh fleece 12 | 13 | for fd in $(zfs list |grep fleece |awk '{print $1}'); do 14 | echo "$fd" 15 | zfs destroy "$fd" 16 | done 17 | 18 | zfs list |grep fleece 19 | exit; 20 | -------------------------------------------------------------------------------- /proxmox/proxmox-deploy-lxc-debian-icewm-thunderbird.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 2024.Dec kneutron 4 | 5 | # This is script 2 of 2 - run the below one 1st to create the LXC 6 | # https://github.com/kneutron/ansitest/blob/master/proxmox/proxmox-create-lxc-xrdp-icewm-thunderbird-debian.sh 7 | 8 | # Goal: Setup Unprivileged LXC with Debian Standard 12, 2xvCPU (you can probably get away with 1), rootfs 10GB, RAM 1GB, 512MB Swap, IP = DHCP or static, DNS as appropriate 9 | 10 | # REF: https://www.reddit.com/r/Proxmox/comments/1hayp1j/comment/m1ilo4n/?context=3 11 | 12 | 13 | # Fire up LXC console after it builds, root login should already be there, no password needed: # 14 | 15 | # Run this script INSIDE the running LXC, you may need to ' chmod +x ' it first 16 | 17 | # (root) Cmds to accomplish everything: 18 | 19 | # xxx TODO editme 20 | myid=dave 21 | 22 | apt update 23 | apt upgrade -y 24 | 25 | # SKIP # apt install fluxbox # rdesktop clicking did nothing, so went with icewm 26 | 27 | apt install -y icewm xterm xfce4-terminal 28 | 29 | apt install -y xrdp 30 | 31 | adduser xrdp ssl-cert 32 | 33 | systemctl restart xrdp 34 | 35 | apt install -y joe mc screen tmux vim 36 | 37 | apt install -y thunderbird 38 | 39 | # Requires input for passwd 40 | adduser $myid 41 | echo '' 42 | 43 | #screen -aAO -h 2000 44 | 45 | # ============= 46 | 47 | echo "Fire up rdesktop client / mstsc, point it to the below IP address, login as $myid" 48 | echo " You should see icewm minimal desktop with 4 virtual screens preconfigured." 49 | echo '' 50 | echo "Right-click the desktop, open Terminal, enter ' thunderbird & '" 51 | echo '(or use the "Start" menu) and setup your email account(s).' 52 | 53 | ip a 54 | 55 | date; 56 | 57 | # NOTE you can install e.g. fluxbox afterward to save RAM, and switching to it from icewm should work 58 | -------------------------------------------------------------------------------- /proxmox/proxmox-destroy-ctr.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # May work even if the ctr storage is no longer defined 4 | # REF: https://forum.proxmox.com/threads/how-to-delete-a-vm-or-container-that-has-no-storage-and-no-or-missing-storage-pool.87483/ 5 | 6 | # Requires 1 arg, number of LXC ctr to destroy 7 | 8 | lxc-ls --fancy 9 | 10 | exit; # comment me if you're serious, I take NO RESPONSIBILITY for data loss! 11 | 12 | 13 | echo "Press Enter to proceed with destroy or ^C to back out!" 14 | read 15 | 16 | set -x 17 | time lxc-destroy -n $1 18 | 19 | lxc-ls --fancy 20 | -------------------------------------------------------------------------------- /proxmox/proxmox-enter-container.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # provide container number as arg to get root 4 | pct enter $1 5 | date 6 | 7 | exit; 8 | -------------------------------------------------------------------------------- /proxmox/proxmox-expand-lvm-thinpool.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | exit; 4 | 5 | #lvresize -L +300G vmdata/thinvol 6 | lvresize -A --verbose -r -L +100% pve/data 7 | 8 | # REF: https://forum.proxmox.com/threads/how-to-extend-lvm-thin-pool.54900/ 9 | -------------------------------------------------------------------------------- /proxmox/proxmox-fix-10gig-driver-compile.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # REF: https://forum.proxmox.com/threads/intel-x553-sfp-ixgbe-no-go-on-pve8.135129/#post-626516 4 | 5 | echo "WARNING THIS DOES NOT CURRENTLY WORK" 6 | exit; 7 | 8 | 9 | apt update 10 | apt-get install proxmox-default-headers build-essential dkms gcc make 11 | 12 | modinfo ixgbe >/tmp/ixgbe-before.txt 13 | 14 | ixver="5.19.9" 15 | 16 | cd /usr/local/src 17 | wget --no-clobber https://sourceforge.net/projects/e1000/files/ixgbe%20stable/$ixver/ixgbe-$ixver.tar.gz 18 | 19 | tar -xzvf ixgbe-*tar.gz -C /usr/src 20 | 21 | echo ' 22 | MAKE="BUILD_KERNEL=${kernelver} make -C src/ KERNELDIR=/lib/modules/${kernelver}/build" 23 | CLEAN="make -C src/ clean" 24 | PACKAGE_NAME="ixgbe-dkms" 25 | PACKAGE_VERSION="5.19.9" 26 | BUILT_MODULE_NAME="ixgbe" 27 | BUILT_MODULE_LOCATION=src/ 28 | DEST_MODULE_LOCATION="/kernel/drivers/net/ethernet/intel/ixgbe/" 29 | AUTOINSTALL="yes" 30 | ' > /usr/src/ixgbe-$ixver/dkms.conf 31 | 32 | dkms add ixgbe/$ixver 33 | dkms build ixgbe/$ixver 34 | dkms install ixgbe/$ixver 35 | 36 | rmmod ixgbe 37 | cd /usr/src/ixgbe-$ixver/src 38 | #insmod ./ixgbe.ko 39 | modprobe ixgbe 40 | 41 | modinfo ixgbe >/tmp/ixgbe-after.txt 42 | -------------------------------------------------------------------------------- /proxmox/proxmox-fix-pbs-storage-down-spamming-logs.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # REF: https://forum.proxmox.com/threads/reduce-log-spamming-when-pbs-is-offline-error-fetching-datastores-500-cant-connect-to.147310/ 4 | 5 | echo "arg1 = 1/0, 1=enable" 6 | echo "arg2 = storagename [optional]" 7 | 8 | # running from cron, we need this 9 | PATH=/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin:/usr/local/games:/usr/games:/root/bin:/root/bin/boojum:/usr/X11R6/bin:/usr/NX/bin: 10 | 11 | if [ "$2" = "" ]; then 12 | storname=pbs-p2300m-laptop 13 | else 14 | storname="$2" 15 | fi 16 | 17 | pvesm status 18 | 19 | if [ "$1" = "1" ]; then 20 | echo "Enabling storage $storname" 21 | pvesm set $storname --disable 0 22 | else 23 | echo "Disabling storage $storname" 24 | pvesm set $storname --disable 1 25 | fi 26 | 27 | pvesm status 28 | 29 | exit; 30 | 31 | $0 0 pbs-vm-on-macpro 32 | -------------------------------------------------------------------------------- /proxmox/proxmox-get-lxc-container-ips.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | pct list 4 | echo '=====' 5 | 6 | for ctr in $(pct list |grep running |awk '{print $1}'); do 7 | echo "VMID $ctr" 8 | lxc-info -i -n $ctr 9 | echo '=====' 10 | done 11 | 12 | exit; 13 | -------------------------------------------------------------------------------- /proxmox/proxmox-grub-rescue-fix.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # REF: https://pve.proxmox.com/wiki/Recover_From_Grub_Failure 4 | 5 | # TODO EDITME before running if disk devices are different (nvme, etc) 6 | vgscan 7 | vgchange -a y 8 | 9 | #Mount all the filesystems that are already there so we can upgrade/install grub. Your paths may vary depending on your drive configuration. 10 | 11 | mkdir /media/RESCUE 12 | mount /dev/pve/root /media/RESCUE/ 13 | 14 | # EDITME 15 | mount /dev/sda1 /media/RESCUE/boot 16 | 17 | mount -t proc proc /media/RESCUE/proc 18 | mount -t sysfs sys /media/RESCUE/sys 19 | mount -o bind /dev /media/RESCUE/dev 20 | mount -o bind /run /media/RESCUE/run 21 | 22 | # Chroot into your proxmox install. 23 | 24 | chroot /media/RESCUE 25 | #Then update grub and install it. 26 | 27 | update-grub 28 | grub-install /dev/sda 29 | # ^ EDITME 30 | -------------------------------------------------------------------------------- /proxmox/proxmox-list-containers.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 2024.Apr kneutron 4 | 5 | declare -a tmpa 6 | tmpa=$(pct list) 7 | # if we dont quote tha var/array, only get 1 line of output 8 | 9 | echo "$tmpa" |egrep 'Status|running' 10 | #VMID Status Lock Name 11 | #105 running gotify 12 | #118 running proxmox-fileserver-ctr 13 | 14 | echo '=====' 15 | echo "$tmpa" |egrep 'Status|stopped' 16 | #VMID Status Lock Name 17 | #110 stopped suseleap-ctr-p 18 | #113 stopped debian-ctr 19 | #114 stopped debianctr-xorgtest 20 | #122 stopped test-phone-tether 21 | #124 stopped debian-qdevice-dellap 22 | 23 | exit; 24 | 25 | # echo "$tmpa" 26 | VMID Status Lock Name 27 | 105 running gotify 28 | 110 stopped suseleap-ctr-p 29 | 113 stopped debian-ctr 30 | 114 stopped debianctr-xorgtest 31 | 118 running proxmox-fileserver-ctr 32 | 122 stopped test-phone-tether 33 | 124 stopped debian-qdevice-dellap 34 | -------------------------------------------------------------------------------- /proxmox/proxmox-lvm-convert-to-thin-pool.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | exit; 4 | 5 | # https://forum.proxmox.com/threads/how-do-you-squeeze-max-performance-with-software-raid-on-nvme-drives.127869/ 6 | 7 | pvcreate /dev/md0 8 | vgcreate SSD-RAID-10 /dev/md0 9 | lvcreate -l 97%FREE -n SSD-RAID-10 SSD-RAID-10 10 | lvconvert --type thin-pool --poolmetadatasize 2048M --chunksize 64 SSD-RAID-10/SSD-RAID-10 11 | -------------------------------------------------------------------------------- /proxmox/proxmox-mkiso-unattended-install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Remaster a proxmox installer ISO with a self-contained answerfile 4 | # 2024.Apr kneutron 5 | # Feature: Now downloads the ISO for you if not exist 6 | 7 | # XXX TODO EDIT the .toml file before running this! 8 | 9 | # XXX TODO EDITME 10 | isopath=/var/lib/vz/template/iso 11 | #isopath=/mnt/seatera4-xfs/template/iso 12 | 13 | useiso=proxmox-ve_8.2-1.iso 14 | 15 | # bash if not 16 | if [ ! -e "$isopath/$useiso" ]; then 17 | (cd $isopath; wget --no-clobber https://enterprise.proxmox.com/iso/$useiso) 18 | fi 19 | 20 | # TODO changeme if needed 21 | answerfile=/root/proxmox-unattended-install.toml 22 | 23 | [ $(dpkg -l |grep -c proxmox-auto-install-assistant) -gt 0 ] || apt install -y proxmox-auto-install-assistant 24 | 25 | echo "$(date) - Preparing $isopath/$useiso using $answerfile" 26 | time proxmox-auto-install-assistant prepare-iso $isopath/$useiso --fetch-from iso --answer-file $answerfile 27 | 28 | date; 29 | 30 | exit; 31 | 32 | # REF: https://pve.proxmox.com/wiki/Automated_Installation 33 | 34 | # Final ISO is available at "/mnt/seatera4-xfs/template/iso/proxmox-ve_8.2-1-auto-from-iso.iso". 35 | 36 | # test vm config for pve install 37 | BEGIN /etc/pve/qemu-server/126.conf 38 | balloon: 2048 39 | bios: ovmf 40 | boot: order=virtio0;ide2 41 | cores: 2 42 | cpu: host,flags=+aes 43 | efidisk0: local-lvm:vm-126-disk-0,efitype=4m,pre-enrolled-keys=1,size=4M 44 | ide2: dir1:iso/proxmox-ve_8.2-1-auto-from-iso.iso,media=cdrom,size=1364160K 45 | machine: q35 46 | memory: 4096 47 | meta: creation-qemu=8.1.5,ctime=1714504207 48 | name: pve-test-unattended-install 49 | net0: virtio=BC:24:11:B5:12:C2,bridge=vmbr0,queues=2 50 | numa: 0 51 | ostype: l26 52 | scsihw: virtio-scsi-single 53 | smbios1: uuid=0fc8815d-9727-480f-818c-0f390b19f8c7 54 | sockets: 1 55 | tablet: 0 56 | vga: virtio 57 | virtio0: tosh10-xfs-multi:126/vm-126-disk-0.qcow2,backup=0,cache=writeback,discard=on,iothread=1,size=256G 58 | -------------------------------------------------------------------------------- /proxmox/proxmox-mount-lxc-ctr-root-on-host.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | pct mount $1 # number of LXC CTR 4 | 5 | exit; 6 | 7 | First, mount the LXC filesystems on the Proxmox host (LXC does not need to 8 | be running, but can be). Use `pct mount xxx` for each LXC. It will tell 9 | you the mount point, but it will be /var/lib/lxc/xxx/rootfs. Now you can 10 | manipulate the files in the LXC from the Proxmox host. This includes all 11 | mount points of the LXC overlaid properly. 12 | 13 | Next, use `rsync` to copy the files from one LXC to another using the full 14 | path to both rootfs`s. 15 | 16 | Finally, recursively chown the files with a uid/gid offset of 100000 (the 17 | offset used by unprivilaged LXCs). Root in the container (uid 0) is uid 18 | 100000 on host. I would just `chown -R 100000:100000` the entire directory 19 | you just copied, so it`s accessible as root in the container, and then go 20 | into the container and fix permissions within the container as container 21 | root (using `chown -R user:group`) 22 | 23 | When you are done, `pct unmount xxx`. 24 | 25 | # REF: https://www.reddit.com/r/Proxmox/comments/1ch6555/most_efficient_way_to_copy_data_from_privileged/ -------------------------------------------------------------------------------- /proxmox/proxmox-mount-vm-lvm-disk-on-host.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # REF: https://forum.proxmox.com/threads/filled-up-disk-and-cannot-boot.148515/ 4 | 5 | exit; 6 | 7 | #First I have to mount disk in loopback: 8 | 9 | losetup --partscan -f /dev/mapper/pve-vm--200--disk--0 10 | 11 | #then i could activate the vg: 12 | 13 | vgchange -ay ubuntu-vg 14 | 15 | #then i could mount the lv: 16 | 17 | mount /dev/mapper/ubuntu--vg-ubuntu--lv /mnt 18 | -------------------------------------------------------------------------------- /proxmox/proxmox-qcow2-actual-disk-in-use-size-report.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # updatedb 4 | for disk in $(locate *.qcow2); do 5 | qemu-img info "$disk" \ 6 | |egrep 'image|format| size|compression' 7 | echo '=====' 8 | done 9 | -------------------------------------------------------------------------------- /proxmox/proxmox-query-vm-agents.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 2024.feb kneutron 4 | # REF: https://youtu.be/wp4kCUM6dik?t=233 5 | 6 | time qm list |column -t 7 | 8 | for vmid in $(qm list |grep running |awk '{print $1}'); do 9 | echo "$(date) - Checking $vmid" 10 | qm agent $vmid ping; rc=$? 11 | if [ $rc -gt 0 ]; then 12 | echo "$vmid guest agent not responding!" 13 | continue; 14 | fi 15 | qm guest cmd $vmid get-host-name |tr -d '{}' |awk 'NF>0' 16 | qm guest cmd 104 network-get-interfaces |grep 'ip-address" :' 17 | # pvesh get /nodes/proxmox/qemu/104/agent/network-get-interfaces -o json-pretty |grep 'ip-address" :' 18 | # qm guest cmd $vmid get-osinfo 19 | done 20 | 21 | exit; 22 | 23 | qm list 24 | VMID NAME STATUS MEM(MB) BOOTDISK(GB) PID 25 | 100 lmde stopped 4096 21.00 0 26 | 104 pfsense-272-dhcp-for-HO running 1500 20.00 222982 27 | 28 | NOTE for lxc containers: 29 | 30 | # lxc-info -i -n 105 31 | IP: 172.16.25.64 32 | IP: 192.168.1.253 33 | IP: 2600:100e:a001:1a9c:be24:11ff:fe96:3df9 34 | IP: 2600:100e:a011:4e4b:be24:11ff:fe96:3df9 35 | -------------------------------------------------------------------------------- /proxmox/proxmox-recover-vm-disks-without-backup.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Scenario - reinstalled pve, no full backup of VMs but the disks are still available on storage 4 | 5 | qm rescan 6 | 7 | exit; 8 | 9 | # REF: https://www.reddit.com/r/Proxmox/comments/1cqr0xj/pve_host_installed_on_new_disk_how_to_import_vms/ 10 | 11 | So I installed PVE host on a new disk and imported the ZFS disk with all my 12 | VMs to this new installation. I can see the disk and VM disks showing under 13 | storage. So far so good. 14 | 15 | Now how do I go about restoring the VM? I dont have whole backup 16 | 17 | ===== 18 | 19 | narrateourale 20 | 21 | Did you back up the VM configs located at /etc/pve/qemu-config? 22 | 23 | If not, then create new VMs, match the VMID to the old one. Dont create 24 | any disk and once the VM (or all) are created, run qm rescan on the shell. 25 | It will search for disk images on the configured storages that match the 26 | VMID. For each found disk image, it will create a new "unusedX" disk entry 27 | in the VM config. 28 | 29 | You can then edit these disks and finish the configuration. Dont forget to 30 | update the boot order in the options of the VM! 31 | 32 | If your VMs have EFI and TPM disks, it can be a bit messy and you might want 33 | to create them from scratch. Otherwise, editing the config files directly 34 | to change them from "unused0" to whatever config key is needed might be 35 | quicker. 36 | -------------------------------------------------------------------------------- /proxmox/proxmox-refresh-ctr-templates.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # running from cron, we need this 4 | PATH=/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin:/usr/local/games:/usr/games:/root/bin:/root/bin/boojum:/usr/X11R6/bin:/usr/NX/bin: 5 | 6 | pveam update 7 | pveam list local # storage name 8 | 9 | # useful if we downloaded a 3rd-party template 10 | -------------------------------------------------------------------------------- /proxmox/proxmox-scan-samba-server-for-shares.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 10gbit net - prompts for password 4 | pvesm scan cifs macpro-10gd --username dave-imac5 --password 5 | -------------------------------------------------------------------------------- /proxmox/proxmox-sync-windows-time-beyond-48hrs.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | vmid="$1" 4 | phase="$2" 5 | vmconf="/etc/pve/qemu-server/$vmid.conf" 6 | 7 | if [[ "$phase" == "post-start" ]]; then 8 | # waiting for vm guest service to start 9 | started="false" 10 | loopstart=$EPOCHSECONDS 11 | while [[ "$started" == "false" ]]; do 12 | qm guest cmd $vmid ping && started="true" 13 | if [[ "$started" == "false" ]]; then 14 | sleep 2 15 | fi 16 | if (( EPOCHSECONDS-loopstart > 60 )); then 17 | echo "timeout for vm guest service start" 18 | break 19 | fi 20 | done 21 | 22 | # sync VM time after resume or start 23 | if [[ "$started" == "true" ]]; then 24 | if grep -q "ostype: win" $vmconf; then 25 | newdate=$(date +"%d-%m-%y") 26 | newtime=$(date +"%H:%M") 27 | echo "resync windows time" 28 | qm guest exec $vmid "cmd" "/c net stop W32Time & date $newdate & time $newtime & net start W32Time & w32tm /resync /nowait" 29 | else 30 | echo "resync linux time" 31 | echo '{"execute":"guest-set-time"}' | socat stdin unix-connect:"/var/run/qemu-server/$vmid".qga 32 | fi 33 | else 34 | echo "vm guest service not running" 35 | exit 1 36 | fi 37 | fi 38 | # REF: https://forum.proxmox.com/threads/windows-vm-time-not-updated-after-hibernate-resume.110517/page-2#post-624212 39 | -------------------------------------------------------------------------------- /proxmox/proxmox-unattended-install.toml: -------------------------------------------------------------------------------- 1 | # This is the answer file for proxmox pve unattended install to VM (for testing) 2 | # ext4 + LVM boot/root 3 | # REF: https://pve.proxmox.com/wiki/Automated_Installation#Overview 4 | # 2024.Apr kneutron 5 | # xxx TODO EDITME before running ' proxmox-mkiso-unattended-install.sh ' 6 | [global] 7 | keyboard = "en-us" 8 | country = "us" 9 | fqdn = "pveauto.testinstall" 10 | mailto = "root@localhost" 11 | timezone = "America/Denver" 12 | root_password = "123456" 13 | 14 | [network] 15 | source = "from-dhcp" 16 | 17 | [disk-setup] 18 | filesystem = "ext4" 19 | lvm.hdsize = 238 20 | # for "256GB" disk - even if disk is bigger than this, pve lvm will only use this much and rest can be used for ZFS 21 | #lvm.hdsize = "119" 22 | # for "128GB" disk - REF: https://platinumdatarecovery.com/hard-drive-capacity-calculator 23 | lvm.swapsize = 2 24 | # ^^ in GB 25 | lvm.maxroot = 40 26 | # GB 27 | lvm.minfree = 2 28 | # Leave 2GB of space for future growth / safety factor 29 | #disk_list = ["sda"] 30 | disk_list = ["vda"] 31 | -------------------------------------------------------------------------------- /proxmox/proxmox-unlock-vm.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | qm unlock $1 # pass VM number as arg 4 | -------------------------------------------------------------------------------- /proxmox/proxmox-vm-assign-cpu-cores.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 2024.feb kneutron 4 | # optional arg1 $1 = vmid if already known 5 | # Assign cores 6,7 to boinc win10 2-core vm 6 | # This should obviously be done on quad-core or better CPU 7 | 8 | psax 9 | 10 | declare -i vmid lastcpu # has to be a number 11 | 12 | if [ "$1" = "" ]; then 13 | read -p "Enter VMID of highest-CPU kvm: " vmid 14 | else 15 | vmid=$1 16 | fi 17 | 18 | [ "$vmid" = "" ] || [ "$vmid" = "0" ] && exit 44; 19 | 20 | lastcpu=$(grep processor /proc/cpuinfo |tail -n 1 |awk '{print $3}') 21 | let penultcpu=$lastcpu-1 22 | 23 | # print only pid / subthreads that are using >0 CPU 24 | pidlist=$(ps -eLf --columns $COLUMNS |grep "kvm -id $vmid" |egrep -v 'grep|bash' |awk '$5>0 {print $4}') 25 | echo $pidlist 26 | 27 | #exit; 28 | 29 | function assigncores () { 30 | 31 | set -x 32 | taskset -p $1 33 | taskset -cp $penultcpu,$lastcpu $1 34 | 35 | taskset -cp $penultcpu $2 36 | taskset -cp $lastcpu $3 37 | } 38 | # assign cpu cores 6,7 to win10 vm for better latency 39 | # REF: https://www.youtube.com/watch?v=-c_451HV6fE 40 | 41 | # psthreads.sh 'kvm -id 112' |awk '$5>0 {print}' # field 4 is pid + subthreads 42 | 43 | assigncores $pidlist 44 | 45 | set +x 46 | echo "Monitor changes with htop" 47 | 48 | exit; 49 | 50 | # Adapt to different multicore systems 51 | 52 | # grep processor /proc/cpuinfo |tail -n 1 53 | processor : 7 54 | # grep processor /proc/cpuinfo |tail -n 1 |awk '{print $3}' 55 | 7 56 | -------------------------------------------------------------------------------- /proxmox/proxmox-win10-vm-sync-time.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # arg1 = vmid 4 | echo "$(date) - syncing time on Win VM $1" 5 | set -x 6 | qm guest exec $1 w32tm /resync 7 | set +x 8 | date 9 | 10 | # REF: https://windowsloop.com/windows-time-sync-command/ 11 | # REF: https://pve.proxmox.com/pve-docs/qm.1.html 12 | -------------------------------------------------------------------------------- /proxmox/proxmox-windows-vm-free-disk-space.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # REF: https://forum.proxmox.com/threads/determining-free-disk-space-on-windows-vms.145730/#post-656958 4 | 5 | [ $(which jq |wc -l) -eq 0 ] && apt install -y jq 6 | 7 | # either one works 8 | #qm agent $1 get-fsinfo \ 9 | # |jq '[.[] | select(.["total-bytes"]) | {total_gb: ((.["total-bytes"] / (1024 * 1024 * 1024)) | round), used_gb: ((.["used-bytes"] / (1024 * 1024 * 1024)) | round), free_gb: (((.["total-bytes"] - .["used-bytes"]) / (1024 * 1024 * 1024)) | round)}]' 10 | 11 | qm guest cmd $1 get-fsinfo \ 12 | |jq '[.[] | select(.["total-bytes"]) | {total_gb: ((.["total-bytes"] / (1024 * 1024 * 1024)) | round), used_gb: ((.["used-bytes"] / (1024 * 1024 * 1024)) | round), free_gb: (((.["total-bytes"] - .["used-bytes"]) / (1024 * 1024 * 1024)) | round)}]' 13 | 14 | date 15 | 16 | exit; 17 | 18 | -------------------------------------------------------------------------------- /proxmox/psax: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # Displays which PROCESSOR a pid is currently running on :) 4 | 5 | /usr/bin/uptime 6 | COLUMNS=80 ps axw -o pid,user,ni,%cpu,psr,%mem,args --sort -%cpu|head -n 22 7 | /usr/bin/free 8 | 9 | -------------------------------------------------------------------------------- /proxmox/real-du.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # show actual at-the-moment disk usage VS what applications see / what they can address in thin-provisioned / compressed storage 4 | 5 | # REF: https://forum.proxmox.com/threads/when-migrating-to-smb-cifs-the-disk-expands.159645/#post-733180 6 | 7 | du -h "$@" # ACTUAL space being taken up on disk at the moment - can grow to the "allocated limit" 8 | # 288G . 9 | 10 | du --apparent-size -h "$@" # What applications see / what they can actually address in a thin-provisioned / growable disk 11 | # 352G . 12 | -------------------------------------------------------------------------------- /proxmox/resize-lvm-thin-pool.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #exit; 4 | meta=127M # increase by 10% of new GB 5 | 6 | cursize=207 # GB # lvs |grep data |awk '{print $4}' 7 | sizeup=127 # GB 8 | let newsize=$cursize+$sizeup 9 | 10 | # Use webmin to add PV, then 11 | lvresize --poolmetadatasize +$meta /dev/mapper/pve-data 12 | 13 | set -x 14 | time lvresize -L${newsize}G pve/data -r -vvv #--type thin-pool 15 | lvs 16 | -------------------------------------------------------------------------------- /proxmox/zpo.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Bring a zfs file-backed mirror file online/offline to refresh/resilver the backup 4 | # 2024.Jun kneutron 5 | 6 | logf=~/rpool-online-offline-mirdisk.log 7 | 8 | # change online/offline state of sshfs mirror disk for STABILITY and resilver updating 9 | mirdisk=$(zpool status -v |grep rpool-mirror-.*zfs-efi.disk |awk '{print $1}') 10 | 11 | if [ "$1" = "1" ]; then 12 | # TODO add if-mounted test here 13 | echo "$(date) - Onlining rpool $mirdisk" |tee -a $logf 14 | (set -x; time zpool online rpool $mirdisk) 15 | zfs-watchresilver-boojum.sh 16 | else 17 | echo "$(date) - Offlining rpool $mirdisk" |tee -a $logf 18 | (set -x; time zpool offline rpool $mirdisk) 19 | fi 20 | 21 | zpool status rpool -v |awk 'NF>0' 22 | -------------------------------------------------------------------------------- /proxmox/zpool-add-to-proxmox-gui.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # this is for when the zfs pool was created / imported commandline and GUI does not detect it 4 | 5 | # xxx TODO EDITME or use $1 / $2 6 | pvesm add zfspool zfs2nvme -pool znvme 7 | 8 | # zfs2nvme = proxmox name you want displayed in gui 9 | # znvme = actual zpool name 10 | 11 | -------------------------------------------------------------------------------- /reboot-and-wait.yml: -------------------------------------------------------------------------------- 1 | --- 2 | 3 | - hosts: '{{target}}' 4 | tasks: 5 | - name: reboot and wait 6 | become: yes 7 | reboot: 8 | reboot_timeout: 600 9 | 10 | - name: check uptime 11 | register: uptimeoutput 12 | command: "uptime" 13 | 14 | - debug: 15 | var: uptimeoutput.stdout_lines 16 | -------------------------------------------------------------------------------- /redhat-alma-rocky/vdo-create-volume.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 2024.mar kneutron 4 | # Works on almalinux 9 5 | 6 | # Target disk 7 | # TODO EDITME - maybe better to use partition instead of whole device 8 | tdisk="pci-0000:06:0b.0-part1" # -> ../../vdb1 9 | 10 | # REF: https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/9/html-single/deduplicating_and_compressing_logical_volumes_on_rhel/index 11 | 12 | # NOTE Starting with RHEL 9, VDO can only be managed using LVM tools 13 | 14 | 15 | #Replace logical-size with the amount of logical storage that the VDO volume should present: 16 | 17 | #For active VMs or container storage, use logical size that is ten times the 18 | #physical size of your block device. For example, if your block device is 19 | # 1TB in size, use 10T here. 20 | 21 | #For object storage, use logical size that is three times the physical size 22 | # of your block device. For example, if your block device is 1TB in size, use 3T here. 23 | 24 | modprobe kvdo 25 | 26 | # TODO EDITME 27 | vdoname=vdotest 28 | 29 | # TODO EDITME physical disk size 128G 30 | let pdisk=128-1 # GB 31 | # NOTE if we dont do -1 get insufficient free extents error 32 | 33 | lsize=$(echo $[$pdisk * 3]) 34 | 35 | set -x -u 36 | # RHEL8 37 | #time vdo create --name=$vdoname \ 38 | # --device=/dev/disk/by-path/pci-0000:06:0b.0-part1 \ 39 | # --vdoLogicalSize=${lsize}G --writePolicy=async 40 | 41 | # RHEL9 42 | vgcreate $vdoname-vg "/dev/disk/by-path/$tdisk" # pci-0000:06:0b.0-part1 43 | 44 | lvcreate --type vdo -n $vdoname-lv -L ${pdisk}G -V ${lsize}G $vdoname-vg/vdo-pool1 45 | 46 | # vdotest--vg-vdotest--lv -> ../dm-4 47 | time mkfs.xfs -K /dev/mapper/$vdoname--vg-$vdoname--lv 48 | 49 | echo "$(date) - waiting for Godot" 50 | time udevadm settle 51 | date 52 | 53 | systemctl enable --now fstrim.timer # auto once a week 54 | 55 | mkdir -pv /mnt/vdo1 56 | mount /dev/mapper/$vdoname--vg-$vdoname--lv /mnt/vdo1 -odefaults,noatime 57 | 58 | set +x 59 | echo '' 60 | df -hT /mnt/vdo1 61 | echo '' 62 | echo "fstab: 63 | /dev/mapper/$vdoname--vg-$vdoname--lv mount-point xfs defaults,noatime 0 0" 64 | echo '' 65 | vdostats --human-readable 66 | -------------------------------------------------------------------------------- /ripcd.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Reads CDRs from SAF 24x 3 | 4 | # NOTE - The DVD burner on p500 is much FASTER for audio ripping. 5 | 6 | usecd="/dev/sr0" 7 | 8 | #mount /mnt/cdtemp2a 9 | #cd /mnt/cdtemp/audio 10 | cd /bigvaiterazfs/dv/compr/audio/cdrips/ 11 | 12 | # if no parm, just rip generic - else mkdir albumname 13 | if [ "$1" != "" ]; then 14 | mkdir $1 && \ 15 | cd $1 16 | fi 17 | 18 | echo 'o Ripping CD to ';pwd 19 | 20 | # Scsi bprec 21 | #cdda2wav -D$CDR_DEVICE -x "-t1+" -Owav -B 22 | 23 | # CDRW 24 | time cdda2wav -D$usecd --no-infofile -x "-t1+" -Owav -B \ 25 | -n 128 -S 32 26 | #-paranoia 27 | 28 | chown -R dave . 29 | ls -alh 30 | pwd 31 | 32 | ##$CDR_DEVICE 33 | # -n 64? 34 | # add " -V -s speed" if nec 35 | 36 | #cdparanoia -d /dev/cdrom2 --batch "1-" 37 | #cdparanoia --batch "1-" 38 | 39 | # Worx faster without forcereadspd 40 | #cdparanoia -S 1 --batch "1-" 41 | 42 | eject $usecd 43 | #cdrom 44 | #sr0 45 | #cdrom 46 | -------------------------------------------------------------------------------- /rootbin.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kneutron/ansitest/ceafcc8d2a7ec1e6b2a9fbe04e5f443515ebc0c2/rootbin.tgz -------------------------------------------------------------------------------- /rpmsortinst.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # for RPM-based distros 4 | # get detailed installed-packages info 5 | 6 | echo "Getting sorted list of installed pkgs..." 7 | date 8 | 9 | time rpm -qa |sort >~/Installedpkgs.list 10 | #echo EOF>>~/Installedpkgs.list 11 | 12 | echo "$(date) - Done with sort" 13 | 14 | # Blank it 15 | outfile=~/RPMInstalled.list.txt 16 | > $outfile 17 | 18 | echo "Querying all installed pkgs for details..." 19 | # Do it 20 | for i in $(cat ~/Installedpkgs.list); do 21 | rpm -qi $i >>$outfile 22 | done 23 | 24 | echo "$(date) - Done" 25 | #less ~/RPMInstalled.list 26 | ls -alh $outfile 27 | 28 | exit; 29 | 30 | # 2021.0408 rewrite simpler 31 | -------------------------------------------------------------------------------- /safe-dd.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # REF: https://distrowatch.com/weekly.php?issue=20230619#tips 4 | # Some mods by kneutron 2023Jun 5 | 6 | # WRAPPER - This script invokes the dd command to copy a file. 7 | # It first checks to make sure the target file (of) is not mounted. 8 | # Warning, this may not work with device names containing a space. 9 | 10 | if [ $# -lt 2 ] 11 | then 12 | echo "Please provide an input file and an output file." 13 | exit 1 14 | fi 15 | 16 | start=$(echo $@ | sed 's/of=/\^/') 17 | end=$(echo $start | cut -f 2 -d '^') 18 | target=$(echo $end | cut -f 1 -d ' ') 19 | 20 | echo "Checking $target" 21 | df | grep $target 22 | if [ $? -eq 0 ] 23 | then 24 | echo "Output file $target is mounted. Refusing to continue." 25 | exit 2 26 | fi 27 | 28 | echo "Executing nice dd $@ status=progress" 29 | time /usr/bin/dd $@ bs=1M status=progress 30 | sync 31 | echo "$(date) - Finished writing and sync." 32 | -------------------------------------------------------------------------------- /saferm.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # safe delete with find and rm, logged 4 | # 2019 Dave Bechtel 5 | # EDIT BEFORE USING!! 6 | 7 | # to stderr only 8 | >&2 echo "NOTE use this script at your own risk, I take NO responsibility for data loss!" 9 | 10 | #source ~/bin/failexit.mrg 11 | # failexit.mrg 12 | function failexit () { 13 | echo '! Something failed! Code: '"$1 $2" # code # (and optional description) 14 | exit $1 15 | } 16 | 17 | set -u # disallow unset vars 18 | 19 | # xxxxx TODO CHANGEME 20 | dest=/mnt/tmp 21 | 22 | logfile=~/safeRM.log 23 | > $logfile # clearit 24 | 25 | cd "$dest" || failexit 99 "! Unable to cd to $dest" 26 | 27 | # xxxx TODO CHANGEME wildcard files 28 | time find -P "$dest"/* -mount -name "*.wav" -type f -exec /bin/rm -v {} >> $logfile \; 29 | 30 | ls -alh $logfile 31 | 32 | exit; 33 | 34 | REF: http://unix.stackexchange.com/questions/167823/find-exec-rm-vs-delete 35 | -------------------------------------------------------------------------------- /setproxy.sh: -------------------------------------------------------------------------------- 1 | # SOURCE me 2 | #ip="192.168.1.250" 3 | ip="192.168.1.251" 4 | 5 | export http_proxy=http://"$ip":3128 6 | export https_proxy=http://"$ip":3128 7 | export ftp_proxy=http://"$ip":3128 8 | export no_proxy=localhost 9 | set|grep proxy= 10 | -------------------------------------------------------------------------------- /simplewebserver.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # Basically serve current dir as browseable over a given port; cd and run 4 | # - needs to run as root in FG (for ports under 1025) and can run unprivileged on e.g. port 8000 if firewall allows 5 | # - need to ^C to kill this 6 | # REF: https://www.perlmonks.org/?node_id=865148 7 | # REF: https://www.w3.org/Daemon/User/Installation/PrivilegedPorts.html#:~:text=Priviliged%20ports,has%20put%20up%20for%20you. 8 | 9 | runport=8080 10 | 11 | ##Check for root priviliges 12 | if [ "$(id -u)" -ne 0 ]; then 13 | runport=80 14 | fi 15 | 16 | echo "$0 running on port $runport" 17 | python -m SimpleHTTPServer $runport > ~/simple-web-server.log 2>&1 18 | date 19 | -------------------------------------------------------------------------------- /ssh-into-qemu-vm.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # portfwd to squid on pi; run-qemu is listening for ssh on 32222 4 | ssh -2 -C -Y -oTCPKeepAlive=yes -g -R 3128:10.1.0.4:3128 -l user localhost -p 32222 5 | -------------------------------------------------------------------------------- /ssh-speed-test-localhost.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Adapted from: https://www.systutorials.com/improving-sshscp-performance-by-choosing-ciphers/ 4 | 5 | # if not exist, create 6 | [ -e $HOME/.ssh/id_rsa.pub ] || ssh-keygen -t rsa -q -N '' 7 | 8 | # Passwordless run 9 | ssh-copy-id $(whoami)@localhost 10 | 11 | echo "$(date) - Running timing tests" 12 | for i in 3des-cbc \ 13 | aes128-cbc aes128-ctr aes128-gcm@openssh.com \ 14 | aes192-cbc aes192-ctr \ 15 | aes256-cbc aes256-ctr aes256-gcm@openssh.com \ 16 | arcfour arcfour128 arcfour256 \ 17 | blowfish-cbc \ 18 | cast128-cbc \ 19 | chacha20-poly1305@openssh.com \ 20 | rijndael-cbc@lysator.liu.se; 21 | do 22 | dd if=/dev/zero bs=1000000 count=1000 2>/dev/null \ 23 | |ssh -c $i localhost "(time -p cat) >/dev/null" 2>&1 \ 24 | |grep real \ 25 | |awk '{print "'$i': "1000 / $2" MB/s" }' 26 | done |column -t 27 | 28 | date 29 | 30 | exit; 31 | 32 | aes128-ctr: 104.822 MB/s 33 | aes128-gcm@openssh.com: 85.1789 MB/s 34 | aes192-ctr: 91.4077 MB/s 35 | aes256-ctr: 79.1766 MB/s 36 | aes256-gcm@openssh.com: 71.8907 MB/s 37 | chacha20-poly1305@openssh.com: 168.35 MB/s 38 | -------------------------------------------------------------------------------- /ssh-wait4.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # "say" requires OSX for speech synth 4 | # Use ssh-copy-id beforehand for PWless login 5 | 6 | # xxx TODO EDITME 7 | #tryip="10.0.4.21" # mx21 8 | tryip="10.9.0.4" # squid 9 | user=dave 10 | 11 | echo "$tryip" 12 | 13 | function countdown () { 14 | # REF: https://stackoverflow.com/questions/12498304/using-bash-to-display-a-progress-indicator 15 | 16 | #pid=$! # Process Id of the previous running command 17 | 18 | # number 19 | declare -i countto=$1 20 | ctr=0 21 | 22 | declare -a spin 23 | spin[0]="-" 24 | spin[1]='\' 25 | spin[2]="|" 26 | spin[3]="/" 27 | 28 | echo -n "[$countto] ${spin[0]} " #$ctr" 29 | #while [ kill -0 $pid ] 30 | while [ $countto -ge $ctr ]; do 31 | for i in "${spin[@]}" 32 | do 33 | # echo -ne "\b$i $ctr" 34 | let cdown=$countto-$ctr 35 | printf "\r$countto $i $cdown " 36 | sleep 1 37 | let ctr=$ctr+1 38 | [ $ctr -ge $countto ] && break 39 | read -n 1 -t .1 && break 2 40 | done 41 | done 42 | echo '' 43 | } 44 | 45 | # do a countdown if waiting for boot 46 | if [ "$1" = "1" ]; then 47 | date 48 | countdown 150 # 250 # 360 49 | which say && say -v Fiona "check monitor" 50 | 51 | # ping -o 10.0.2.34 52 | # do forever 53 | while :; do 54 | for ip in $tryip; do 55 | echo "Trying IP $ip" 56 | ping -c 5 $ip && break 2 57 | done 58 | done 59 | 60 | which say && say -v Fiona "Attempting log in $ip" & 61 | date 62 | ssh -2 -X -Y -c chacha20-poly1305@openssh.com -l $user $ip # 10.0.2.34 63 | # fryserver 64 | else 65 | # NOTE does not need static ip 66 | #autossh -M 32500 -2 -X -Y -l $user p2700quad1404 67 | ssh -2 -X -Y -c chacha20-poly1305@openssh.com -l $user $tryip # 10.0.2.34 68 | # fryserver 69 | fi 70 | -------------------------------------------------------------------------------- /sysadmin-bkp-edit.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Backup critical file before editing (in current dir) 4 | # 2024.Mar kneutron 5 | 6 | cp -v "$1" "$1.bkp.$(date +%Y%m%d@%H%M%S)--edit-by-$(id -un)" 7 | 8 | ls -lh "$1*" 9 | echo "Backed up $1 - OK to edit - Press enter" 10 | read -n 1 11 | 12 | $EDITOR "$1" 13 | -------------------------------------------------------------------------------- /timesync: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | PATH=/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin:/usr/local/games:/usr/games:/root/bin:/root/bin/boojum:/usr/X11R6/bin:/usr/NX/bin: 4 | 5 | date 6 | if [ $(which ntpdate |wc -l) -gt 0 ]; then 7 | ntpdate -s pool.ntp.org 8 | else 9 | chronyc -a 'burst 4/4' #service chronyd restart 10 | fi 11 | 12 | if [ "$1" = "1" ]; then 13 | sleep 10 14 | chronyc -a makestep 15 | fi 16 | 17 | sleep 2 18 | date 19 | 20 | exit; 21 | 22 | 23 | # REF: https://serverfault.com/questions/930747/force-chrony-time-check 24 | 25 | If you want chronyd to also step the clock instead of slewing if there is a 26 | larger offset and chrony.conf doesnt include an unlimited makestep 27 | directive, you will also need to wait until the new measurements are made 28 | and then tell chronyd to make the step: 29 | 30 | #sleep 10 31 | #chronyc -a makestep 32 | 33 | #ntp1.linuxmedialabs.com 34 | # pool.ntp.org 35 | # ntp1.tummy.com - CO 36 | # louie.udel.edu - DElwr 37 | # ntp.shorty.com - GA 38 | 39 | # inetd's timeserver is port 37; use ' rdate p233 ' 40 | -------------------------------------------------------------------------------- /timesync.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # mod for rhel8 / alma 4 | # Quite useful if time/date in your Resumed VM is stuck in the past 5 | # REF: https://access.redhat.com/solutions/4130881 6 | 7 | date 8 | # if exist, use it; should work with .deb-based distros 9 | [ $(type -path ntpdate |wc -l) -gt 0 ] && ntpdate -s pool.ntp.org 10 | 11 | # RHEL8 / alma 12 | 13 | if [ $(systemctl -a |grep chronyd |head -n 1 |wc -l) -gt 0 ]; then 14 | systemctl stop chronyd 15 | chronyd -q 16 | systemctl start chronyd 17 | fi 18 | 19 | date 20 | 21 | #ntp1.linuxmedialabs.com 22 | # pool.ntp.org 23 | # ntp1.tummy.com - CO 24 | # louie.udel.edu - DElwr 25 | # ntp.shorty.com - GA 26 | 27 | # inetd's timeserver is port 37; use ' rdate servername ' 28 | -------------------------------------------------------------------------------- /topscrn4-10.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #ff # fix fontsize 4 | 5 | # Requires: bwm-ng top screen iostat watch openvt/open 6 | # Requires other files: dot-screenrc-mon1-combined ( renamed as .screenrc-mon1-combined in root's home dir ) 7 | # ^^ mon1-df-short in /usr/local/bin or $HOME/bin 8 | 9 | useprog=open 10 | [ -e `which openvt` ] && useprog=openvt 11 | 12 | # turn off screensaver 13 | setterm -blank 0 2>/dev/null 14 | 15 | # open 4-pane screen on vt10 and switch to it 16 | ( TERM=linux $useprog -f -c 10 -s -w -- /usr/bin/screen -S topscrn410 -c /root/.screenrc-mon1-combined ) & 17 | disown -a 18 | -------------------------------------------------------------------------------- /topscrn4-xterm.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # This is useful with Maximized lxterminal, xfce4-terminal, OSX terminal, etc where you can easily resize the font 4 | # NOTE: if using ssh Use: ssh -t hostname $HOME/bin/topscrn4-xterm.sh 5 | 6 | # open 4-pane screen with sys monitoring 7 | 8 | # Requires: bwm-ng top screen iostat watch openvt/open 9 | 10 | # Requires other files: dot-screenrc-mon1-combined ( renamed as .screenrc-mon1-combined in user's home dir ) 11 | # ^^ mon1-df-short in /usr/local/bin 12 | 13 | # if we try to throw it in the BG, get "screen must be connected to a terminal" error - must be FG 14 | TERM=linux screen -R -c $HOME/.screenrc-mon1-combined 15 | -------------------------------------------------------------------------------- /topterm9.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | result=$(ps ax |awk '/tty9/ {print $5}' |grep -c top) 4 | 5 | if [ $result -eq 0 ]; then 6 | # open top on vt9 7 | setterm -blank 0 2>/dev/null 8 | ( TERM=linux openvt -f -c 9 -w -- /usr/bin/top -d 15 ) & 9 | else 10 | echo "WARNING topterm9 already running - skipping" 11 | fi 12 | 13 | -------------------------------------------------------------------------------- /toptmux4-10.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | ff # fix fontsize 4 | 5 | useprog=open 6 | [ -e $(which openvt) ] && useprog=openvt 7 | # open 4-pane screen on vt10 8 | setterm -blank 0 2>/dev/null 9 | 10 | uset=$(which tmux) 11 | 12 | #( TERM=linux $useprog -f -c 10 -s -w -- /usr/bin/tmux -S topscrn410 -c /root/.screenrc-mon1-combined ) & 13 | ( TERM=linux $useprog -f -c 10 -s -w -- $uset -S topTM410 tmux new-session \; \ 14 | send-keys 'top -d15' C-m \; \ 15 | split-window -v \; \ 16 | send-keys 'bwm-ng -t 2000' C-m \; \ 17 | split-window -h \; \ 18 | send-keys 'iostat -k -s -y -z 5' C-m \; 19 | split-window -h \; \ 20 | send-keys 'watch -n 61 /home/dave/bin/mon1-df-short' ) & 21 | -------------------------------------------------------------------------------- /unpass.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Loop through the range of 0 - 99999 to find the 5-number passcode for a 7zip archive 4 | # REF: https://www.reddit.com/r/bash/comments/zey4h8/finding_a_5_digit_code_for_a_locked_zip_file/ 5 | 6 | # https://youtu.be/B-NhD15ocwA?t=71 7 | # :B 8 | 9 | # Starts 2x parallel jobs, one counts up - the other counts down 10 | # NOTE everything including the .7z file is in /dev/shm (ramdisk) for speed 11 | 12 | # TESTs archive ONLY, does not extract it - but should give you the correct code if it finds it 13 | 14 | # REQUIRES: tee, 7z, seq 15 | # killall assumes Linux, other broken implementations may do the wrong thing 16 | 17 | logf=/dev/shm/unpass.log 18 | #archive=yxor.7z # leaving hardcoded for processing speed, only vars we really need are counternum and passcode 19 | date >$logf 20 | 21 | foundit () { 22 | echo "$(date) FOUND IT $i $j" |tee -a $logf 23 | cat /dev/shm/currentcode /dev/shm/currentcode2 24 | ls -l 25 | # exit 0 26 | killall 7z 27 | killall $(basename $0) 28 | } 29 | 30 | # if the password is in the 54000 range, shortcut to speed up testing 31 | #for i in $(seq -w 54000 55000); do 32 | for i in $(seq -w 0 49999); do 33 | echo $i >/dev/shm/currentcode # use ramdisk 34 | 7z t -p$i yxor.7z 2>&1>/dev/null ; [[ $? -eq 0 ]] && foundit # break 35 | done & 36 | 37 | for j in $(seq -w 99999 -1 50000 ); do 38 | echo $j >/dev/shm/currentcode2 # use ramdisk 39 | 7z t -p$j yxor.7z 2>&1>/dev/null ; [[ $? -eq 0 ]] && foundit 40 | done & 41 | 42 | wait; 43 | 44 | echo "$(date) - DID NOT FIND CODE" |tee -a $logf 45 | 46 | exit; 47 | 48 | # 2022.1207 kingneutron 49 | # To monitor the current password code, in another terminal: 50 | # $ while :; do cat /dev/shm/cur*; sleep 9; done # ^C to quit this (do forever) 51 | # 52 | # Doing this does not slow down the processing 53 | -------------------------------------------------------------------------------- /updt-suse.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # mod for SUSE 4 | zypper ref 5 | zypper update 6 | 7 | rpmsortinst & 8 | 9 | # only updt if locatedb >24H old 10 | # REF: https://unix.stackexchange.com/questions/275728/set-ls-l-time-format 11 | #ls -lhk --time-style='+%s' /var/lib/mlocate/mlocate.db 12 | # 1 2 3 4 5 6 13 | #-rw-r--r-- 1 root root 21M 1665244188 /var/lib/mlocate/mlocate.db 14 | # date +%s 15 | #1665249077 16 | 17 | now=$(date +%s) 18 | dbage=$(ls -lhk --time-style='+%s' /var/lib/mlocate/mlocate.db |awk '{print $6}') 19 | let timediff=$now-$dbage 20 | if [ $timediff -ge 86400 ]; then 21 | updatedb & 22 | else 23 | echo "NOTE Skipping updatedb, timediff is only $timediff" 24 | fi 25 | 26 | #squiderr 27 | #efibootmgr 28 | -------------------------------------------------------------------------------- /wav2mp3.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Source files in /mnt/cdtemp2/dv 4 | # Dest is /mnt/cdtemp 5 | 6 | #cd /mnt/cdtemp2/dv 7 | # Curdir instead 8 | 9 | # toolame 10 | for c in *.wav; 11 | do 12 | echo '.'$c'.' 13 | time lame \ 14 | --disptime 2 \ 15 | -q 4 \ 16 | --vbr-new \ 17 | -V 3 \ 18 | -B 196 \ 19 | $c tmpfile.mp3 20 | 21 | mv -v tmpfile.mp3 $c.mp3 22 | #/mnt/cdtemp/audio/$c.mp3 23 | 24 | done 25 | ls -alh 26 | ## --preset BLAH \ 27 | -------------------------------------------------------------------------------- /winstuff/HALT.cmd: -------------------------------------------------------------------------------- 1 | pause 2 | shutdown /s /f /t 1 -------------------------------------------------------------------------------- /winstuff/REBOOT.cmd: -------------------------------------------------------------------------------- 1 | pause 2 | shutdown /r /f /t 1 -------------------------------------------------------------------------------- /winstuff/chocolatey-install.cmd: -------------------------------------------------------------------------------- 1 | @echo RUN AS ADMIN 2 | pause 3 | 4 | @"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "[System.Net.ServicePointManager]::SecurityProtocol = 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin" 5 | pause 6 | -------------------------------------------------------------------------------- /winstuff/fix-powershell-running-scripts-disabled.cmd: -------------------------------------------------------------------------------- 1 | @echo PASTEME IN ADMINPOWERSHELL TERMINAL 2 | Set-ExecutionPolicy -ExecutionPolicy RemoteSigned 3 | 4 | -------------------------------------------------------------------------------- /winstuff/freshinstall-chocolatey-win.cmd: -------------------------------------------------------------------------------- 1 | @echo RUN AS ADMIN 2 | pause 3 | 4 | choco install -y firefox 5 | choco install -y chromium 6 | choco install -y ublockorigin-chrome 7 | rem choco install -y brave 8 | 9 | choco install -y chocolatey-core.extension 10 | choco install -y chocolateygui 11 | 12 | rem Editors 13 | choco install -y notepadplusplus.install 14 | choco install -y vscode 15 | choco install -y vscode-powershell 16 | choco install -y libreoffice-fresh 17 | choco install -y vim 18 | 19 | rem Utils 20 | choco install -y crystaldiskinfo 21 | choco install -y 7zip.install 22 | choco install -y sysinternals 23 | 24 | choco install -y totalcommander 25 | choco install -y doublecmd 26 | 27 | choco install -y powertoys 28 | choco install -y cpu-z.install 29 | 30 | choco install -y imagemagick.app 31 | choco install -y fsviewer 32 | choco install -y irfanview 33 | 34 | rem backup 35 | choco install -y defraggler 36 | choco install -y veeam-agent 37 | choco install -y rclone 38 | choco install -y smartmontools 39 | choco install -y gsmartcontrol 40 | 41 | choco install -y wget 42 | choco install -y curl 43 | choco install -y teracopy 44 | 45 | choco install -y mobaxterm 46 | choco install -y kitty 47 | choco install -y putty.install 48 | choco install -y winscp.install 49 | choco install -y smartftp 50 | 51 | choco install -y microsoft-windows-terminal 52 | choco install -y conemu 53 | choco install -y powershell-core 54 | choco install -y ripgrep 55 | choco install -y wsl2 56 | 57 | choco install -y rufus 58 | choco install -y imgburn 59 | choco install -y poweriso 60 | 61 | choco install -y vlc 62 | choco install -y handbrake.install 63 | choco install -y makemkv 64 | 65 | rem choco install -y adwcleaner 66 | 67 | rem choco install -y virtualbox 68 | rem choco install -y squid 69 | 70 | choco list 71 | mkdir c:\temp 72 | 73 | rem choco export >$HOME\choco-installed.txt 74 | choco export --output-file-path="'c:\temp\chocolatey-packages.config'" --include-version-numbers 75 | 76 | @pause 77 | -------------------------------------------------------------------------------- /winstuff/make-win-use-utc-time.cmd: -------------------------------------------------------------------------------- 1 | reg add "HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\TimeZoneInformation" /v RealTimeIsUniversal /d 1 /t REG_DWORD /f 2 | pause -------------------------------------------------------------------------------- /winstuff/noatime.cmd: -------------------------------------------------------------------------------- 1 | REM run as Administrator - turn off atime on NTFS filesystems 2 | fsutil behavior set disablelastaccess 1 3 | echo Reboot to commit 4 | pause 5 | -------------------------------------------------------------------------------- /winstuff/noscreensaver.bat: -------------------------------------------------------------------------------- 1 | REM @echo off 2 | powercfg.exe -x -monitor-timeout-ac 0 3 | powercfg.exe -x -monitor-timeout-dc 0 4 | powercfg.exe -x -disk-timeout-ac 0 5 | powercfg.exe -x -disk-timeout-dc 0 6 | powercfg.exe -x -standby-timeout-ac 0 7 | powercfg.exe -x -standby-timeout-dc 0 8 | powercfg.exe -x -hibernate-timeout-ac 0 9 | powercfg.exe -x -hibernate-timeout-dc 0 10 | pause 11 | -------------------------------------------------------------------------------- /winstuff/sfc-scannow-dism.cmd: -------------------------------------------------------------------------------- 1 | sfc /scannow 2 | dism /online /cleanup-image /checkhealth 3 | pause 4 | 5 | dism /online /cleanup-image /scanhealth 6 | pause 7 | 8 | dism /online /cleanup-image /restorehealth 9 | 10 | echo mount Win10 ISO on E: 11 | pause 12 | 13 | dism /online /cleanup-image /restorehealth /source:e:\sources\install.esd /limitaccess 14 | REM skip using win updt 15 | -------------------------------------------------------------------------------- /winstuff/ssh-2p5gig-squidvm-portfwd-squid.cmd: -------------------------------------------------------------------------------- 1 | @ssh -2 -C -X -Y -c chacha20-poly1305@openssh.com -o TCPKeepAlive=yes -L 33128:172.16.25.251:3128 dave@172.16.25.251 2 | -------------------------------------------------------------------------------- /winstuff/win10-firewall-allow-ping.cmd: -------------------------------------------------------------------------------- 1 | echo PK to allow ping 2 | echo Run as admin! 3 | pause 4 | 5 | netsh advfirewall firewall add rule name="ICMP Allow incoming V4 echo request" protocol=icmpv4:8,any dir=in action=allow 6 | 7 | rem ipv6 8 | rem netsh advfirewall firewall add rule name="ICMP Allow incoming V6 echo request" protocol=icmpv6:8,any dir=in action=allow 9 | 10 | rem https://www.thewindowsclub.com/how-to-allow-pings-icmp-echo-requests-through-windows-firewall 11 | 12 | rem disable: 13 | rem netsh advfirewall firewall add rule name="ICMP Allow incoming V4 echo request" protocol=icmpv4:8,any dir=in action=block 14 | -------------------------------------------------------------------------------- /winstuff/win10-upgrade-switches.cmd: -------------------------------------------------------------------------------- 1 | @echo off 2 | J:\setup /Auto Upgrade /CompactOS Enable /DynamicUpdate disable /EULA accept /MigNEO disable /ShowOOBE none /Telemetry disable /Tempdrive D /Uninstall disable -------------------------------------------------------------------------------- /winstuff/winupdates-set-proxy-ie.cmd: -------------------------------------------------------------------------------- 1 | 2 | rem to have Win updates use Squid - Win7 3 | Netsh winhttp import proxy source=ie 4 | pause 5 | 6 | @echo off 7 | rem Win8 syntax: 8 | rem netsh winhttp import proxy source=ie 9 | 10 | rem to reset proxy settings: 11 | rem Netsh winhttp reset proxy 12 | rem http://answers.oreilly.com/topic/1391-how-to-configure-windows-update-to-use-a-proxy-server/ 13 | -------------------------------------------------------------------------------- /zombieprocs.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Linux ps 4 | ps ax -o pid,ppid,s,cmd |awk '$3 ~ /Z/' 5 | # ^ Print pid, parent pid, State, commandline and only print if 3rd column matches Z = zombie 6 | 7 | # kill -9 on the PARENT pid, should clear them up 8 | --------------------------------------------------------------------------------