The DU command

Sometimes you need to find the largest sub directory in a directory, for this, the DU command has an argument that can work for you, max-depth

du -h --max-depth=1 backup-final

The above will simply list all sub directories inside the backup-final directory alongside the size of the directory (recursive, including all files in sub directories)

Running the mv command in the background

One of the most annoying things that can happen to you is to disconnect your laptop from the network, then realize that there was a file moving job that was running, the command is going to get disconnected before mv gets the chance to delete the source files, the new copy is a hassle, i personally use rsync to continue such a copy with the delete source files flag

But it does not have to be this way, you can move the mv command to the background, the steps are simple

First, you need to hit CTRL+z to suspend the job, once suspended, you should see a job number in the suspend acknowledgement

Now, the next step is to disown the job, because right now, if you close your terminal window, the job will still be terminated

disown -h %1 (replace one with your own job number which may be 1)

Now to get the job running again but in the background

bg 1

That is it, you can now close (logout) your terminal window

So the summery
ctrl+z
disown -h %1
bg 1
logout

Now mind you, the output to stdout will not display (In most cases), you will need to use process status ps x to see the process.

Quick 10 minute LVM Setup.

Sometimes, you realize you would want to use LVM in a computer but you want a tutorial to take you there fast, So i have put this post together to get you up and running in 10 minutes or less.

First, let us start with the tools, install the following packages in your debian installation, (Debian 10-Buster in this tutorial)

apt-get install lvm2 dmsetup mdadm reiserfsprogs xfsprogs

In this tutorial, I have two 8TB disks i want to combine with LVM to use as one

1- Create partitions of type LVM on the disks

  • Why not use the disk without a partition ? See this post

Start by running parted on every physical disk, and creating a big partition to span the whole disk (Or if you are using empty spaces on old disks, any partition is good enough really)

In my example, where i wish to combine /dev/sdb and /dev/sdc into one logical volume (To be used as one block)

parted /dev/sdb
mklabel gpt
unit mib
mkpart primary ext4 1 100%
set 1 lvm on

Now, repeat the above, but this time for /dev/sdc

1- Prepare the physical volumes to be added to volume groups (those two partitions) (For instructions on how to add disks directly without an underlying partition which is not recommended, see here)

pvcreate /dev/sdb1 /dev/sdc1

Now, you can see what we have with the commands

pvdisplay or pvs

2- Add the PVs to a logical volume

vgcreate LVMGroup /dev/sdb1 /dev/sdc1
   Volume group "LVMGroup" successfully created

this will create a volume group (VG) called LVMGroup, you can see the VGs you have with the commands (vgdisplay, vgscan, and vgs)

vgs -o +lv_size,lv_name

3- Create a logical group on the volume group

lvcreate -l 100%FREE -n bigvol LVMGroup
  Logical volume "bigvol" created.
mkfs.ext4 /dev/LVMGroup/bigvol
or
mkfs.ext4 /dev/mapper/LVMGroup-bigvol

4- Mount, and add to fstab

To mount the volume, My mount point is at /hds/lvm

using rsync

rsync is better than mv to move files because of a few reasons

First, it gives you much more control, for example the following command

rsync -a -v --ignore-existing --remove-source-files /hds/iscsi/all_new /hds/usb

Does not copy the files that are already at destination, meaning if there is a file with the same name in the same directory at the destination, it will not be overwritten, files moved will be deleted, and files that had counterparts and not moved will not be deleted

rsync -a -v --remove-source-files /hds/iscsi/all_new /hds/usb

While the command above will overwrite files, and delete whatever we have moved ! if files exist on the destination, it does not seem to be overwriting them, but it is probably somehow comparing them, then deleting the original

I had to investigate this as a move command resulting in an error did not remove the files, the error was relevant to the file name being too long

How fast is a raspberry PI 3/4 B

The answer is, depending on your needs, but you are not here to hear that now are you, so I did a little experiment, tailored specifically for a certain need that does not apply accross the board, but combined with other experiments online, this might give you an idea

The experiment is annotating an image with image magic plugin for PHP

Both running buster (Debian/Raspbian 10), both on PHP7.3 and everything fresh installed

the PC has 8GB of DDR3 Ram, and the PI 1GB of LPDDR2-900 SDRAM

The PC has a 12 year old “Intel(R) Core(TM)2 Quad CPU Q9450 @ 2.66GHz”

The PC was around 7 fold faster than the raspberry PI 3 (the mean of a trial of 20 runs, with all the files cached in ram by the linux kernel)

The trial was done with a discrete VGA card (AMD RADEON) and with the chipset’s own graphics card, results were identical (The VGA card did not have it’s drivers installed, so we don’t know if it might have an effect or not)

I am now moving into even older PCs to compare performance, and will report the results here again to see what the limiting factors might be

Debricking a TP-MR3220 V2 router using tftp only

Usually, i go with a serial cable, these days, people have found simpler ways

Start by downloading lede-17.01.5-ar71xx-generic-tl-mr3220-v2-squashfs-factory.bin from the openwrt website (Don’t use the original, it needs trimming 😉 and you can install it after using the post after this one

rename the file you downloaded to mr3220v2_tp_recovery.bin and put it in your tftp client folder

Setup your computer’s LAN settings to the IP address 192.168.0.66

Connect the eithernet cable to the yellow LAN port farthest away from the blue wan port (Not the one next to it, only this port works)

start your TFTP client, pick your eithernet LAN and connect the lan cable

Hold the WPS/Reset button, and while holding it, start the router, then wait 4 seconds and release it

On your screen, you should see your TFTP client sending a file (on tftpd32 you see a download progress bar)

Wait for the router to reboot, now you have hte openwrt firmware, go ahead and read the previous post on going back to factory 😉

Have a great day

reverting tp-link tl-mr3220 V2 to stock firmware the easy way

If you are on openwrt and want to revert back to factory firmware, you need to do the following easy steps

Download the file from the tp-link website, this should be straight forward, you go to the website, search for your router by model, on the firmware download page, select the version of your router and download the file

If it is a zip file, extract it, we are looking for a bin file that should be inside the zip file (Make sure it has up_boot in the file name)

Use an application such as putty to connect to the router as root, and an application such as winSCP to connect to the router (Also as root) to upload the file

upload the file to the /tmp folder, this folder is in RAM not on the flash of the router, so it has more space that can accommodate the procedure

Using Putty, execute the following commands

cd /tmp

On this command here, you will need to replace the name of the file with the name of the file you have uploaded to the router
This command (That starts with DD), trims the first 257*512 = 131,584 bytes from the file which are the boot loader
dd if=yourfilename.bin of=flash.bin skip=257 bs=512

Now you would want to remove the old file after we have trimmed it with DD
rm yourfilename.bin

Now, to the final step, which is actually writing the trimmed firmware to the router
mtd -r write /tmp/flash.bin firmware

Now all you need to do is wait for the router to write the firmware, right after it will reboot and you are done

Changing Windows Fax And Scan storage folder

Well, to make a long story short, I make large scans that don’t need to be on my system disk, I would like to have them stored on the spinning disk, So, i searched online, and found that people were suggesting that I create a symlink to the new location in place of the Scanned Documents folder, Something like

mklink /d "C:\Users\yazeed\Documents\Scanned Documents" D:\scanner

The above obviously has downsides, backup software, changed disk IDs, or other unforeseen effects, In my mind, there is no way the developers of Windows Fax And Scan have hard coded this into the application,

Another solution would have been to move the entire Documents folder (Right click it, then change it’s location, windows provides that option), But not everyone wants that, So there is a third more elegant solution (Even though this works like a charm)

The third is to look in the registry (Find) where Windows Fax And Scan stores it’s path (Look for the word scanned for example), and change that, but i Have already gone with the second, the third should be simple

Connecting to Windows KVM with VNC and putty tunnel

KVM, by default only allows people behind the local computer hosting the virtual machines to connect to them, so here are the tips on creating a tunnel to the host computer and connecting to your windows KVM machine, Yes, windows does not support VNC very well, (Most VNC servers don’t run well on windows), but the VNC server here is not windows, it is your host machine

1- Create a tunnel, simply put, save the connection in putty to that host machine, then under tunnels you will need to have something like this

2- VNC should now connect to localhost:9501 for example, to know which ones are enabled on your machine run this command

netstat -tlpn | grep 590