Project

General

Profile

Miscellaneous » History » Version 10

Anonymous, 04/25/2023 05:33 PM
adding note

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