Project

General

Profile

Miscellaneous » History » Version 11

Anonymous, 04/27/2023 07:02 PM
updating note

1 1
h1. Miscellaneous
2
3 10
h2. Build Custom Windows ISOs
4
5
* https://uupdump.net/
6 11
* https://forums.mydigitallife.net/threads/kms_vl_all-smart-activation-script.79535/
7 10
8 9
h2. Script to Convert Local manpages to html
9
10
Note use @zcat@ if the manpages are compressed:
11
12
<pre>
13
#!/bin/bash
14
15
mkdir -p html
16
for file in *; do
17
        if [ -f $file ] && [ "${file: -3}" != ".sh" ]; then
18
                echo $file
19
                #echo "${file%.*}"
20
                pandoc --from man --to html < $file > html/${file%.*}.html
21
        fi
22
done
23
</pre>
24
25 6
h2. Display Total rsync Progress
26
27
<pre>
28 7
$ rsync -a --no-i-r --info=progress2 /path/to/src /path/to/dest/
29 6
</pre>
30
31
NOTE: @-v@ does not work with @--info=progress2@
32
33
Source: https://serverfault.com/a/441724/472586
34
35 5
h2. Slice Video File 
36
37
<pre>
38
$ ffmpeg -ss 00:01:00 -to 00:02:00  -i input.mp4 -c copy output.mp4
39
</pre>
40
41
Explanation of the command:
42
43
* -i: This specifies the input file. In that case, it is (input.mp4).
44
* -ss: Used with -i, this seeks in the input file (input.mp4) to position.
45
* 00:01:00: This is the time your trimmed video will start with.
46
* -to: This specifies duration from start (00:01:40) to end (00:02:12).
47
* 00:02:00: This is the time your trimmed video will end with.
48
* -c copy: This is an option to trim via stream copy. (NB: Very fast)
49
50 4
h2. Add new drive SW RAID5
51
52
# Format drive if needed (see below for steps).
53
# Add new drive to SW RAID:
54
<pre>
55
$ sudo mdadm --manage /dev/md0 --add /dev/sdd1
56
</pre>
57
# Grow array:
58
<pre>
59
$ sudo mdadm --grow --raid-devices=4 /dev/md0
60
</pre>
61
62
h2. Replace failed SW RAID drive
63
64
# If drive is brand new be sure to create a partition on it:
65
<pre>
66
sorber@file2:~$ sudo parted /dev/sdg
67
GNU Parted 3.3
68
Using /dev/sdg
69
Welcome to GNU Parted! Type 'help' to view a list of commands.
70
(parted) mklabel gpt
71
(parted) mkpart primary 2048s 100%                                        
72
(parted) print                                                            
73
Model: ATA ST2000DM008-2FR1 (scsi)
74
Disk /dev/sdg: 2000GB
75
Sector size (logical/physical): 512B/4096B
76
Partition Table: gpt
77
Disk Flags: 
78
79
Number  Start   End     Size    File system  Name     Flags
80
 1      1049kB  2000GB  2000GB               primary
81
82
(parted) quit
83
</pre>
84
# If needed, mark bad drive as failed:
85
<pre>
86
$ sudo mdadm --manage /dev/md0 --fail /dev/sdd
87
</pre>
88
# Add new drive to replace failed:
89
<pre>
90
$ sudo mdadm --manage /dev/md0 --add /dev/sdd1 /dev/sdg1
91
</pre>
92
# Improve rebuild speed slightly:
93
<pre>
94
$ sudo bash -c "echo 9999999 > /proc/sys/dev/raid/speed_limit_min"
95
$ sudo bash -c "echo 9999999 > /proc/sys/dev/raid/speed_limit_max"
96
</pre>
97
# Monitor rebuild:
98
<pre>
99
$ watch -n1 cat /proc/mdstat 
100
</pre>
101
102
h2. Get detailed drive information
103
104
<pre>
105
$ udevadm info --query=all --name=/dev/sda
106
</pre>
107
108 1
h2. Split flac with cue
109
110
<pre>
111
$ sudo apt install cuetools shntool
112
113
$ shnsplit -f file.cue -t %n-%t -o flac file.flac
114
</pre>
115
116
h2. Fix Chrome Display Glitches
117
118
Somewhere around Chrome 86 display glitches started happening on wake. Here is how to fix:
119
120 3
Enabling @enable-vulkan@ in @chrome://flags@ then restarting the browser fixed it. If that does not work, you can also try enabling `ignore-gpu-blacklist` as well.
121 1
122
h2. Setup SSH Public Key
123
124
# On host machine generate a key pair. This key can be reused for multiple remote machines so it's not really necessary to change the name unless multiple keys are generated, which is also not really needed.
125
<pre>
126
$ ssh-keygen -t rsa
127
</pre>
128 3
 *NOTE:* for NetBeans to use/recognize the ssh key you must use the old PEM format:
129 1
<pre>
130
$ ssh-keygen -m PEM -t rsa
131
</pre>
132
# Now use `ssh-copy-id` to copy the key to the remote machine (for example):
133
<pre>
134
$ ssh-copy-id -i ~/.ssh/phalanx_rsa.pub dsorber@phalanx
135
</pre>
136
137
h2. Read Windows Product Key from ACPI Firmware
138
139
Boot into Linux and run:
140
141
<pre>
142
$ sudo strings /sys/firmware/acpi/tables/MSDM
143
</pre>
144
145
h2. Windows 10 Install and SysPrep Instructions
146
147
Very good instructions: https://theitbros.com/sysprep-windows-10-machine-guide/
148
149
150
h2. Search and Replace on Binary Files
151
152
A good hex editor can do search and replace on binary files but sometimes that's not practical:
153
154
* BBE - https://sourceforge.net/projects/bbe-/
155
 BBE is a binary editor with SED-like syntax:
156
<pre>
157
$ bbe -e 's/\x0a\x0d\x0a/\x0d\x0a/' infile > outfile
158
</pre>
159
* binwalk - https://github.com/ReFirmLabs/binwalk
160
 binwalk can search for hex strings (and do many other things)
161
<pre>
162
$ binwalk -R "\x0a\x0d\x0a" infile
163
164
WARNING: Signature '0    string    \x0a\x0d\x0a    Raw signature (\x0a\x0d\x0a)' is a self-overlapping signature!
165
166
DECIMAL       HEXADECIMAL     DESCRIPTION
167
--------------------------------------------------------------------------------
168
242           0xF2            Raw signature (\x0a\x0d\x0a)
169
412           0x19C           Raw signature (\x0a\x0d\x0a)
170
580           0x244           Raw signature (\x0a\x0d\x0a)
171
749           0x2ED           Raw signature (\x0a\x0d\x0a)
172
. . .
173
</pre>
174
175
h2. Wake-on-LAN WOL
176
177
Must be enabled on interface; need MAC
178
<pre>
179
$ sudo apt install etherwake
180
$ sudo etherwake <target MAC> -i <outgoing interface>
181
182
$ sudo etherwake b4:2e:99:a5:1e:f0 -i enp30s0
183
</pre>
184
185
h2. Allocator Shim
186
187
From Chromium, this is really interesting
188
* https://chromium.googlesource.com/chromium/src/base/+/master/allocator/README.md
189
190
However it is not clear how to use it outside of Chromium.
191
192
h2. Update Geany
193
194
# Install prereq packages (this obviously only needs to be done once):
195
<pre>
196
$ sudo apt install libgtk-3-dev libgtkspell-dev libgtkspell3-3-dev
197
</pre>
198
# Set compile flags:
199
<pre>
200
$ export CFLAGS="-O3 -march=native" 
201
$ export CXXFLAGS=$CFLAGS
202
</pre>
203
# Build geany and set to install in /opt so it won't collide with the packaged version:
204
<pre>
205
$ tar xf geany-1.30.tar.bz2
206
$ cd geany-1.30/
207
$ ./configure --prefix=/opt/local --enable-gtk3
208
$ make -j20
209
$ sudo make install
210
</pre>
211
# Set PKG_CONFIG_PATH environment variable so we can build the plugins.
212
<pre>
213
$ export PKG_CONFIG_PATH=/opt/local/lib/pkgconfig/
214
</pre>
215
# Build geany-plugins:
216
<pre>
217
$ tar xf geany-plugins-1.30.tar.bz2 
218
$ cd geany-plugins-1.30/
219
$ ./configure --prefix=/opt/local --enable-gtk3
220
$ make -j20
221
$ sudo make install
222
</pre>
223
224
h2. Find and replace across multiple files
225
226
<pre>
227
$ find /home/www -type f -print0 | xargs -0 sed -i 's/subdomainA\.example\.com/subdomainB.example.com/g'
228
</pre>
229
230
h2. Useful IPMI commands
231
232
233
Power measurement on the SuperMicro (probably won't work on Dell chassis as they have some proprietary version of ipmi):
234
235
<pre>
236
sudo ipmitool -U ADMIN -P ADMIN -H 10.17.136.108 dcmi power reading
237
</pre>
238
239
Check power status (i.e. on/off) of chassis:
240
<pre>
241
sudo ipmitool -U ADMIN -P ADMIN -H 10.17.70.45 power status
242
sudo ipmitool -U ADMIN -P ADMIN -H 10.17.70.45 power off
243
</pre>
244
245
Get IPMI IP address (look for "IP Address"):
246
<pre>
247
sudo ipmitool lan print 
248
</pre>
249
250
h2. Full sshfs Connect Command
251
252
<pre>
253
sudo sshfs -o idmap=user -o uid=$(id -u) -o gid=$(id -g) -o allow_other -o follow_symlinks ryftuser@sm-X11DGQ:/home/ryftuser /mnt/sm-X11DGQ/
254
</pre>
255
256
h2. Side-by-side Color Diff
257
258
<pre>
259
$ sudo apt-get install colordiff
260
$ colordiff -y --suppress-common-lines data.txt /ryftone/data.txt
261
</pre>
262
263
h2. x86 ABI
264
265
* https://github.com/hjl-tools/x86-psABI/wiki/X86-psABI
266
267
h2. clang-format and clang-tidy
268
269
* http://www.labri.fr/perso/fleury/posts/programming/using-clang-tidy-and-clang-format.html
270
271
h2. Shared Library and Related Resources
272
273
* http://tldp.org/HOWTO/Program-Library-HOWTO/shared-libraries.html
274
* https://blog.qt.io/blog/2011/10/28/rpath-and-runpath/
275
* http://www.bnikolic.co.uk/blog/linux-ld-debug.html
276
* http://insanecoding.blogspot.com/2012/07/creating-portable-linux-binaries.html
277
* https://stackoverflow.com/questions/4156055/static-linking-only-some-libraries
278
279
h2. Ubuntu: List Grub Entries
280
281
<pre>
282
gawk  'BEGIN {                                                                                                                       
283
  l=0                                                                                                                                
284
  menuindex= 0                                                                                                                       
285
  stack[t=0] = 0                                                                                                                     
286
}                                                                                                                                    
287
288
function push(x) { stack[t++] = x }                                                                                                  
289
290
function pop() { if (t > 0) { return stack[--t] } else { return "" }  }                                                              
291
292
{                                                                                                                                    
293
294
if( $0 ~ /.*menu.*{.*/ )                                                                                                             
295
{                                                                                                                                    
296
  push( $0 )                                                                                                                         
297
  l++;                                                                                                                               
298
299
} else if( $0 ~ /.*{.*/ )                                                                                                            
300
{                                                                                                                                    
301
  push( $0 )                                                                                                                         
302
303
} else if( $0 ~ /.*}.*/ )                                                                                                            
304
{                                                                                                                                    
305
  X = pop()                                                                                                                          
306
  if( X ~ /.*menu.*{.*/ )                                                                                                            
307
  {                                                                                                                                  
308
     l--;                                                                                                                            
309
     match( X, /^[^'\'']*'\''([^'\'']*)'\''.*$/, arr )                                                                               
310
311
     if( l == 0 )                                                                                                                    
312
     {                                                                                                                               
313
       print menuindex ": " arr[1]                                                                                                   
314
       menuindex++                                                                                                                   
315
       submenu=0                                                                                                                     
316
     } else                                                                                                                          
317
     {                                                                                                                               
318
       print "  " (menuindex-1) ">" submenu " " arr[1]                                                                               
319
       submenu++                                                                                                                     
320
     }                                                                                                                               
321
  }                                                                                                                                  
322
}                                                                                                                                    
323
324
}' /boot/grub/grub.cfg
325
</pre>
326
327
* https://askubuntu.com/a/941993/392271
328
329
330
h2.GCC Disable Unused Variable Warnings
331
332
<pre>
333
#pragma GCC diagnostic push
334
#pragma GCC diagnostic ignored "-Wunused-variable"
335
( your problematic library includes )
336
#pragma GCC diagnostic pop
337
</pre>
338
339
See: https://stackoverflow.com/a/22708539/73878
340
341
h2. Fix Steam after NVidia driver update
342
343
Since this has now bitten me twice... Steam requires the 32 bit version of the GL library.
344
345
<pre>
346
$ sudo apt install libnvidia-gl-418:i386
347
</pre>
348
349
h2. Restart Cinnamon from TTY
350
351
# Cinnamon freezes
352
# Switch tty. I usually go to tty6, `Ctrl+Alt+F6`
353
# If you need to login first, do so.
354
# Type `w` (yes, just the letter) and press enter. This commands does a lot of different things, but you need it to figure out the number of the display you are using. The display number is in the column FROM. Mine is `:0` (yes, including the colon).
355
# Assuming that cinnamon is already dead (which you would notice by the windows lacking titles and that you can't move different windows around, and perhaps even not being able to use the keyboard), you type `export DISPLAY=:0; cinnamon &`, and don't forget the colon. I add the ampersand (&) only not to keep that tty busy.
356
357
Sauce: https://askubuntu.com/a/198935/392271
358
359
h2. Ubuntu Set Specific Kernel to Boot
360
361
* Use this command to get a list of available options:
362
<pre>
363
$ grep -Ei 'submenu|menuentry ' /boot/grub/grub.cfg | sed -re "s/(.? )'([^']+)'.*/\1 \2/"
364
menuentry  Ubuntu
365
submenu  Advanced options for Ubuntu
366
    menuentry  Ubuntu, with Linux 4.4.0-34-generic
367
    menuentry  Ubuntu, with Linux 4.4.0-34-generic (upstart)
368
    menuentry  Ubuntu, with Linux 4.4.0-34-generic (recovery mode)
369
menuentry  System setup
370
</pre>
371
* Backup grub configuration, just in case:
372
<pre>
373
$ sudo cp /etc/default/grub /etc/default/grub.bak
374
</pre>
375
* Edit grub configuration and change `GRUB_DEFAULT` to something like this:
376
<pre>
377
$ sudo vim /etc/default/grub
378
379
GRUB_DEFAULT="Advanced options for Ubuntu>Ubuntu, with Linux 3.13.0-53-generic"
380
</pre>
381
* Update grub configuration
382
<pre>
383
$ sudo update-grub
384
</pre>
385
* See also: https://askubuntu.com/questions/216398/set-older-kernel-as-default-grub-entry
386
387
h2. Ubuntu Networking Resources
388
389
* https://blog.ubuntu.com/2017/12/01/ubuntu-bionic-netplan
390
* https://help.ubuntu.com/lts/serverguide/network-configuration.html.en
391
* https://netplan.io/
392
393
h2. Win10 Licensing Info
394
395
* https://www.windowscentral.com/how-change-product-key-windows-10
396
* https://www.tenforums.com/tutorials/49586-determine-if-windows-license-type-oem-retail-volume.html
397
* https://www.tenforums.com/windows-updates-activation/104569-win-10-activation-expiring-volume-license.html
398
399
h2. Python GTK Development Resources
400
401
* https://python-gtk-3-tutorial.readthedocs.io/en/latest/layout.html
402
* https://lazka.github.io/pgi-docs/Gtk-3.0/classes/Box.html#Gtk.Box.pack_start
403
* https://lazka.github.io/pgi-docs/Gtk-3.0/mapping.html
404
405
h2. cpufrequtils Governor Configuration
406
407
These instructions are intended for Ubuntu 16.04 and later (using systemd init).
408
409
* Check the available and currently set governors. Ubuntu has an โ€œondemandโ€ service that sets the governor to ondemand after boot.
410
<pre>
411
$ cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors
412
conservative ondemand userspace powersave performance schedutil
413
$ cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor 
414
ondemand
415
</pre>
416
417
* Configure cpufrequtils to set the governor to performance at boot
418
<pre>
419
$ echo 'GOVERNOR="performance"' | sudo tee /etc/default/cpufrequtils
420
GOVERNOR="performance"
421
</pre>
422
423
* Disable the automatic ondemand service. 
424
<pre>
425
$ sudo systemctl disable ondemand
426
</pre>
427
428
* Reboot.
429
430
* Now check that the governor is set to performance for every CPU:
431
<pre>
432
$ cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
433
performance
434
performance
435
performance
436
performance
437
โ€ฆ
438
performance
439
performance
440
performance
441
</pre>
442
443
* Check current CPU speeds:
444
<pre>
445
$ watch -n 1 bash -c 'cpufreq-info | grep "current CPU frequency"'
446
</pre>
447
448
h2. rsync via ssh example
449
450
<pre>
451
$ rsync --info=progress2 -ahz --compress-level=9 -e "ssh -i ~/ryft-pat-f1.pem" data/ ryftuser@18.205.65.5:/ryftone/regression/pubmed/data/
452
</pre>
453
454
h2. Read Performance using AIO
455
456
Use this fio command (run from temp directory on disk in question) to measure max disk read performance:
457
458
<pre>
459
$ fio --name TEST --eta-newline=5s --filename=fio-tempfile.dat --rw=read --size=10g --io_size=10g --blocksize=512k --ioengine=libaio --fsync=0 --iodepth=32 --direct=1 --numjobs=1 --runtime=300 --group_reporting
460
</pre>
461
462
Note that DIRECT_IO is required when using AIO. (see also: https://askubuntu.com/a/991311/392271)
463
464
h2. Remove Source Files While Creating Tarball
465
466
This is handy as it saves on disk space.
467
<pre>
468
$ tar --remove-files -cf pictures.tar Pictures/
469
</pre>
470
471
h2. Linux Find and Remove Files
472
473
Find and remove files (even with spaces in the path) using case insensitive matching for the wildcard:
474
<pre>
475
$ find . -type f -iname "*.jpg" -print0 | xargs -0 rm
476
</pre>
477
478
h2. Convert ASCII hex to binary
479
This problem seems to come up every so often. There is no need for a one-off solution:
480
481
<pre>
482
$ xxd -r -p input.txt output.bin
483
</pre>
484
485
https://stackoverflow.com/questions/7826526/transform-a-hex-info-to-binary-using-linux-command
486
487
h2. Well Said
488
489
https://developers.slashdot.org/comments.pl?sid=12326098&cid=56908942
490
491
h2. Hex Editor
492
493
I had been using [[https://hexinator.com/|Hexinator]] but I've had some minor issues with it. Today I tried [[https://www.wxhexeditor.org/home.php|wxHexEditor]] and I was pleasantly surprised.
494
495
Download from here: https://github.com/EUA/wxHexEditor
496
497
You'll need the latest version of libwxgtk<version>-dev package.
498
499
I had some minor issues with the build (which seems a somewhat bizarre arrangement...) modify the makefile to set `CC` and `CXX` directly, right about line 90.
500
501
Finally, to get it installed in the right place:
502
<pre>
503
sudo make install DESTDIR=/opt/local BINDIR=bin DATADIR=share
504
</pre>
505
506
h2. Preprocessor Fun
507
508
To invoke the preprocessor directly:
509
<pre>
510
gcc -E -DSOME_DEFINE=SOME_VALUE somefile.c 
511
</pre>
512
513
See also [[https://linux.die.net/man/1/unifdef|unifdef]]: "The unifdef utility acts on #if, #ifdef, #ifndef, #elif, #else, and #endif lines, and it understands only the commonly-used subset of the expression syntax for #if and #elif lines."
514
515
h2. Convert Oversampled .flac to 16 bit 44.1 khz .flac
516
517
<pre>
518
mkdir -p output && find . -type f -name "*.flac" | parallel -j16 "sox {} -b 16 -r 44100 output/{/.}.flac"
519
520
mkdir -p output && find . -type f -name "*.flac" | parallel -j16 "sox -v 0.98 {} -b 16 -r 44100 output/{/.}.flac"
521
</pre>
522
523
h2. Aligned C++ STL Types
524
525
<pre>
526
#include <vector>
527
#include <boost/align/aligned_allocator.hpp>
528
529
template <typename T>
530
using aligned_vector = std::vector<T, boost::alignment::aligned_allocator<T, 4096>>;
531
</pre>
532
533
h2. Command line convert .png to .jpg
534
535
<pre>
536
$ for x in *.png; do convert $x $(basename $x .png).jpg; done
537
</pre>
538
539
You can also add the "`-quality 90`" option if needed.
540
541
h2. Determine CPU Family Name
542
543
<pre>
544
$ gcc -march=native -Q --help=target|grep march
545
</pre>
546
547
h2. Convert .flac to .m4a (AAC)
548
549
Requires `ffmpeg` built with libfdk_aac:
550
551
<pre>
552
$ /opt/bin/ffmpeg -i input.flac -vn -c:a libfdk_aac -vbr 3 output.m4a
553
</pre>
554
555
All together using `find` and `parallel` for magic:
556
<pre>
557
$ find . -type f -name "*.flac" | parallel -j16 "/opt/bin/ffmpeg -i {} -vn -c:a libfdk_aac -vbr 4 {/.}.m4a"
558
</pre>
559
560
h2. PyGObject
561
562
This is the magic needed to have stuff happen quasi asynchronously using PyGObject (GTK+):
563
564
<pre>
565
# Yield to the main loop temporarily
566
while Gtk.events_pending():
567
    Gtk.main_iteration()
568
</pre>
569
570
h2. FUSE Code
571
572
 *https://pastebin.com/wavKntiu
573
574
h2. Use Windoze Schtuffs
575
576
 * https://support.microsoft.com/en-gb/help/17588/fix-problems-that-block-programs-from-being-installed-or-removed (gotta love how this requires a separate program)
577
 * [[http://landinghub.visualstudio.com/visual-cpp-build-tools|MSVC Tools]] - compiler (seems to be the rough equivalent of `build-essential`)
578
 * [[https://docs.microsoft.com/en-us/sysinternals/downloads/procmon|Process Monitor]] - useful debug tool
579
  * https://www.codeproject.com/Articles/560816/Troubleshooting-dependency-resolution-problems-usi - example for using Process Monitor
580
 * http://download.microsoft.com/download/7/2/E/72E0F986-D247-4289-B9DC-C4FB07374894/wdexpress_full.exe - (required by wingtk below)
581
 
582
* https://github.com/wingtk/gvsbuild - haven't tried this yet but looks amazing... 
583
584
h2. Build Handbrake Git Build
585
586
Steps for building Handbrake using AOCC:
587
588
<pre>
589
$ source /home/dsorber/Downloads/aocc/setenv_AOCC.sh
590
$ export CC=clang
591
$ export CXX=clang++
592
$ export CFLAGS="-g -O3 -mtune=native"
593
$ export CXXFLAGS=$CFLAGS
594
$ cd ~/Downloads/HandBrake/
595
$ rm -rf build/
596
$ ./configure --prefix=/opt --enable-x265 --enable-fdk-aac --gcc=/home/dsorber/Downloads/aocc/AOCC-1.1-Compiler/bin/clang
597
$ cd build
598
$ make -j17
599
$ sudo make install
600
</pre>
601
602
----
603
604
Regular build (18.04 and later):
605
<pre>
606
$ rm -rf build/
607
$ ./configure --prefix=/opt/local --enable-x265 --enable-fdk-aac
608
$ cd build
609
$ make -j17
610
$ sudo make install
611
</pre>
612
613
h2. Politically Correct Linux
614
615
* https://entertainment.slashdot.org/comments.pl?sid=11493671&cid=55759997
616
617
h2. This guy gets it
618
619
Regarding software purist ideology vs pragmatism
620
621
* https://linux.slashdot.org/comments.pl?sid=11156367&cid=55256437
622
623
h2. "Rotate" Video Playback via Metadata
624
625
<pre>
626
$ ffmpeg -i input.mp4 -c copy -metadata:s:v:0 rotate=90 output.mp4
627
</pre>
628
629
630
h2. Ubuntu Remove Old Kernels Oneliner
631
632
<pre>
633
$ sudo apt-get purge $(for tag in "linux-image" "linux-headers"; do dpkg-query -W -f'${Package}\n' "$tag-[0-9]*.[0-9]*.[0-9]*" | sort -V | awk 'index($0,c){exit} //' c=$(uname -r | cut -d- -f1,2); done)
634
</pre>
635
636
* [[https://askubuntu.com/questions/2793/how-do-i-remove-old-kernel-versions-to-clean-up-the-boot-menu/571360#571360|Sauce]]
637
638
h2. Remove New Lines (command line)
639
640
For a file:
641
<pre>
642
$ tr -d '\n' < yourfile.txt
643
</pre>
644
645
Or for output of a command (e.g.):
646
<pre>
647
$ find . -type f -name '*.txt' | tr -d '\n'
648
</pre>
649
650
h2. Convert from .mp4 to .mkv Container
651
652
Use `avconv` to convert container without re-encoding:
653
<pre>
654
$ sudo apt-get install libav-tools
655
656
$ avconv -i filme.mp4 -c copy filme.mkv
657
</pre>
658
659
h2. Remove String From Many File Names
660
661
On Ubuntu use Perl rename utility, e.g.:
662
663
<pre>
664
$ rename 's/ \(1920x1080\) \[WaifuKenny\]//' *.mp4
665
</pre>
666
667
h2. Change Default Text Editor
668
669
I always have to Google this...
670
671
<pre>
672
$ sudo update-alternatives --config editor
673
</pre>
674
675
h2. Linux View System RAM Speed
676
677
View RAM speed (actual) on Debian/Ubuntu/Mint:
678
679
<pre>
680
$ sudo lshw -short -C memory
681
H/W path                      Device      Class          Description
682
====================================================================
683
/0/0                                      memory         64KiB BIOS
684
/0/b                                      memory         32GiB System Memory
685
/0/b/0                                    memory         [empty]
686
/0/b/1                                    memory         16GiB DIMM Synchronous 2134 MHz (0.5 ns)
687
/0/b/2                                    memory         [empty]
688
/0/b/3                                    memory         16GiB DIMM Synchronous 2134 MHz (0.5 ns)
689
/0/d                                      memory         768KiB L1 cache
690
/0/e                                      memory         4MiB L2 cache
691
/0/f                                      memory         16MiB L3 cache
692
</pre>
693
694
h2. Linux Memory Schtuff
695
696
* [[https://github.com/jbert/exmap|exmap]]
697
* https://jameshunt.us/writings/smaps.html
698
* https://techtalk.intersec.com/2013/07/memory-part-2-understanding-process-memory/
699
* http://bmaurer.blogspot.com/2006/03/memory-usage-with-smaps.html
700
701
* https://github.com/torvalds/linux/blob/master/Documentation/filesystems/proc.txt
702
703
* From: http://stackoverflow.com/questions/24484481/entry-in-proc-meminfo
704
<pre>
705
  2. Active(file), Inactive(file) has file back-end which means its original file is in disk but to use it faster it was loaded on RAM.
706
</pre>
707
708
709
* From: http://unix.stackexchange.com/questions/56879/tracking-down-missing-memory-usage-in-linux
710
711
  The "memory used by a process" is not a clear cut concept in modern operating systems. What can be measured is the size of the address space of the process (SIZE) and resident set size (RSS, how many of the pages in the address space are currently in memory). Part of RSS is shared (most processes in memory share one copy of glibc, and so for assorted other shared libraries; several processes running the same executable share it, processes forked share read-only data and possibly a chunk of not-yet-modified read-write data with the parent). On the other hand, memory used for the process by the kernel isn't accounted for, like page tables, kernel buffers, and kernel stack. In the overall picture you have to account for the memory reserved for the graphics card, the kernel's use, and assorted "holes" reserved for DOS and other prehistoric systems (that isn't much, anyway).
712
713
  The only way of getting an overall picture is what the kernel reports as such. Adding up numbers with unknown overlaps and unknown left outs is a nice exercise in arithmetic, nothing more.
714
715
 * [[http://virtualthreads.blogspot.com/2006/02/understanding-memory-usage-on-linux.html|Understanding memory usage on Linux]]
716
717
 * https://linux-mm.org/LinuxMM
718
719
h2. Reinstall grub on UEFI System
720
721
Reinstalling grub on a UEFI system is slightly different than on a traditional legacy BIOS system:
722
723
<pre>
724
# Mount the primary drive root partition and the boot EFI partition
725
sudo mount /dev/sda# /mnt            # Mount root (/) partition
726
sudo mount /dev/sda# /mnt/boot       # Mount boot (/boot) partition (if separate from root partition; typically not)
727
728
sudo mkdir -p /mnt/boot/efi          # Create EFI partition mount point
729
sudo mount /dev/sda1 /mnt/boot/efi   # Mount EFI partition
730
731
# Mount your virtual filesystems:
732
for i in /dev /dev/pts /proc /sys /run; do sudo mount -B $i /mnt$i; done
733
734
# Chroot
735
sudo chroot /mnt
736
</pre>
737
738
Now, if you have networking you'll need DNS. If using `resolvconf` (for recent versions of Ubuntu):
739
740
# Edit ` /etc/resolvconf/resolv.conf.d/head` and add the following line (OpenDNS server).  Then save and exit:
741
<pre>
742
add nameserver 208.67.222.222
743
</pre>
744
# Next enable updates and update:
745
<pre>
746
sudo resolvconf --enable-updates
747
sudo resolvconf -u
748
</pre>
749
# Now you should have DNS. Test by pinging something.
750
751
Finally, back to fixing grub. Note that the grub install should run smoothly with no errors or warnings. If you see any something is probably wrong.
752
<pre>
753
apt-get install grub-efi-amd64  # Install grub EFI bootloader (this should be all you need to do)
754
755
756
# manual steps if you need them for some reason
757
grub-install --recheck --no-floppy --force /dev/sda1  # Install grub bootloader in EFI partition
758
759
#####
760
echo "configfile (hd0,gpt#)/boot/grub.cfg" > /boot/efi/ubuntu/grub.cfg # Tell grub to load grub.cfg from /boot
761
762
update-grub                          # Create grub menu list
763
#####
764
765
exit                                 # Exit chroot
766
</pre>
767
768
Reboot and you should be back in business.
769
770
h2. Convert flac to VBR mp3 using ffmpeg/lame
771
772
<pre>
773
for file in *.flac; do name=$(echo $file | sed "s/\.flac//g"); ffmpeg -i "$file" -codec:a libmp3lame -qscale:a 0 "$name".mp3; done
774
</pre>
775
776
h2. Create UEFI/legacy BIOS Bootable ISO
777
778
* http://askubuntu.com/questions/625286/how-to-create-uefi-bootable-iso
779
780
h2. Getting rEFInd to work on Mac OS 10.11
781
782
* http://mattjanik.ca/blog/2015/10/01/refind-on-el-capitan/
783
784
h2. Convert DTS 5.1 to FLAC
785
786
<pre>
787
sudo apt-get install libdca-utils ffmpeg sound-juicer gnome-terminal easytag vlc 
788
789
for file in *.wav; do name=$(echo $file | sed "s/\.wav//g"); dcadec -o wavall "$file" > "$name"_decoded.wav; ffmpeg -i "$name"_decoded.wav "$name".flac; rm -f "$file" "$name"_decoded.wav; done
790
</pre>
791
792
Source: http://ubuntuforums.org/archive/index.php/t-1849260.html
793
794
h2. Windows Utils
795
796
* http://windirstat.info/download.html
797
* https://www.raymond.cc/blog/safely-delete-unused-msi-and-mst-files-from-windows-installer-folder/
798
799
h2. SSH Security
800
801
https://stribika.github.io/2015/01/04/secure-secure-shell.html
802
803
h2. Windows 10
804
805
* http://ultimateoutsider.com/downloads/ - GWX Control Panel to disable GWX (Windows 10 update nagging)
806
* [[https://www.safer-networking.org/spybot-anti-beacon/|Spybot Anti-Beacon]] - Disable Micro$oft "telemetry" data gathering from Windows 10, 8.x, and 7
807
808
<pre>
809
The newest version of the KB3035583 update includes a background process which scans the 
810
system's Windows Registry twice a day to see if the values for the four aforementioned registry 
811
inputs were manually edited to disable the upgrade prompt. If they were, the process will alter 
812
the values, silently re-download the Windows 10 installation files (about 6 GB in total), and 
813
prompt the user to upgrade.
814
</pre>
815
816
817
h2. gpg-agent
818
819
* http://www.infrastructureanywhere.com/documentation/additional/mirrors.html
820
821
These instructions are geared toward reprepro but should be useful in general for setting up `gpg-agent`.
822
823
824
h2. Resolve DNS While VPN Connected
825
826
How to configure dnsmasq for DNS overrides while using a VPN connection: https://chawlasumit.wordpress.com/2014/06/15/linux-mint-openconnect-vpn-dns-issues/
827
828
h2. Pretty Print Python Traceback
829
830
<pre>#!python
831
import traceback
832
833
 ...
834
835
try: 
836
    with open('/dev/null', 'w') as void:
837
        rc = not bool(subprocess.call('modprobe -r {:s}'.format(mod_name), 
838
                                      shell=True, stdout=void, stderr=void))
839
except Exception as e:
840
    print_failure_status()
841
    exc_type, exc_value, exc_traceback = sys.exc_info()
842
    print('\n')
843
    traceback.print_exception(exc_type, exc_value, exc_traceback)
844
    print('\n')
845
</pre>
846
847
h2. Generating Random Data Files for Testing
848
849
One approach is to use /dev/urandom (non-blocking pseudorandom device):
850
<pre>
851
$ dd if=/dev/urandom bs=32M count=32 of=data_1GB.bin
852
</pre>
853
Unfortunately /dev/urandom is a bit slow. However, you can alternatively use openssl to generate pseudorandom numbers a bit faster:
854
<pre>
855
 $ openssl rand 1073741824 > data_1GB.bin
856
 $ for run in {1..30}; do echo $run; openssl rand 1073741824 >> data_30GB.bin; done
857
</pre>
858
859
h2. Cloning HDDs
860 8
861 1
When configuring multiple chassis it is necessary to clone an HDD. There are all sorts of disk imaging tools out there but it's hard to beat the trusty dd command. The pv (pipe viewer) portion isn't strictly necessary but it prints out a very useful textual status bar. The back ticked blockdev command reports the size of the drive in bytes, which pv then uses to determine overall progress. The bs argument to dd should correspond to the cache size of the drive for optimum performance (32MB is a sane default for most drives these days).
862
863
To clone a single drive to another identical drive (assuming sda is the source and sdb is the destination):
864
<pre>
865
 $ sudo dd if=/dev/sda bs=32M | pv -s `sudo blockdev --getsize64 /dev/sda` | sudo dd of=/dev/sdb bs=32M
866
</pre>
867
To clone to multiple drives all at once (assuming sda is the source and sdb, sdc are destinations):
868
<pre>
869
 $ sudo dd if=/dev/sda bs=32M | pv -s `sudo blockdev --getsize64 /dev/sda` | tee >(sudo dd of=/dev/sdb bs=32M) | sudo dd of=/dev/sdc bs=32M
870
</pre>
871
It is entirely possible to clone more drives by adding additional `>(sudo dd of=/dev/sdX bs=32M)` arguments to the tee command. Note that tee outputs to stdout so it is necessary to pipe the output of tee to the final dd command as shown above. If you don't do this then tee will spew the raw contents of the source HDD to your screen, which will make the clone take forever and look especially ugly!
872
873
For some reason RedHat/CentOS do not have the pv command or even a package for it in their repos!!! Therefore, boot from a Debian-based OS in order to clone.
874
875
h2. Generating ISOs
876
877
<pre>
878
 $ genisoimage -R -J -o <output.iso> <some directory>
879
</pre>
880
To deal with long file names:
881
<pre>
882
 $ genisoimage -R -J -l -D -joliet-long -o <output.iso> <some directory>
883
</pre>
884
885 2
h2. BIOS/grub
886 1
887 2
* http://forums.linuxmint.com/viewtopic.php?f=46&t=119832
888
* http://www.gnu.org/software/grub/manual/html_node/BIOS-installation.html
889
* https://wiki.archlinux.org/index.php/GRUB2
890
* http://unix.stackexchange.com/questions/28443/does-grub2-support-putting-boot-on-a-raid5-partition
891 1
892
h3. Creating a BIOS Boot Partition on a GPT system
893
894
<pre>
895
$ sudo parted /dev/sda
896
(parted) mkpart primary 0 1024k
897
(parted) set 2 bios_grub on
898
</pre>
899
900 2
h2. Actiontec Router
901
902
* http://transition.fcc.gov/oet/ea/fccid/
903
* http://opensource.actiontec.com/mi424wref.html
904 1
905
h2. Temp
906
907
https://www.grumpyland.com/blog/183/installing-software-raid-on-centos-567-via-ssh/
908
<pre>
909
# swap is on /dev/md1
910
/dev/md1 none            swap    sw              0       0
911
912
# storage is on /dev/md0
913
/dev/md0        /storage        xfs     noatime,barrier=0 0 0
914
//faramir/production/sw /sw     cifs    username=samba,password=w00tw00t!,file_mode=0666,dir_mode=0777  0       0
915
</pre>
916
917
----
918
[[../|Back home]]