Project

General

Profile

Miscellaneous » History » Version 5

Anonymous, 01/20/2022 08:56 PM
adding note

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