Linksys AC Series Router Configuration Tips for OpenWRT: Difference between revisions

Line 2,956: Line 2,956:


====DD====
====DD====
Another program that functions as an effective cloning utility is ''dd'' (noted in an earlier section).  If cloning an entire disk or drive or flash drive, the image should be cloned to a separate device (another flash drive, disk drive, or network storage location).
A program that functions as a cloning utility is DD (noted in an earlier section for a different purpose).  When cloning an entire drive (SSD in the form of an mSATA, M.2 (NVME, NGFF), etc. device) / disk / flash drive* (* the term "drive" used later in this section will apply to whatever storage medium is being cloned), the image file should of couse be cloned to a separate device as with any other cloning software.  DD is capable of cloning an entire drive, etc. or a single partition


Note, the DD command is built into BusyBox, but does not have all options available.  To utilize the full capability of DD, install the full package with this command: opkg install corutils
Note, the DD command is built into BusyBox, but does not have all options available.  To take advantage of all the options DD offers, install the full package with this command: opkg install corutils


Below is an example command to clone a partition;
Below is a generic example command to clone a partition from one drive to another (remember, any data on the destination will be overwritten);


*dd if=/dev/sdXy of=/dev/sdXy bs=64K conv=noerror,sync status=progress
*dd if=/dev/sdXy of=/dev/sdXy bs=64K conv=noerror,sync status=progress
**sdXy = X is the drive (as in sda, sdb, sdc, etc.) and y is the partition (sda1, sdb1, sdb3, sdc2, etc.), In Linux, sd = Storage Device, sda is the first storage device which is more or less equivalent to C: in Windows, see https://en.wikipedia.org/wiki/Device_file#Naming_conventions for more information.
**if = source
**if = source
**of = destination
**of = destination
**conv=noerror,sync = Don't stop for any read errors and make sure any data stored in RAM / Buffers is written to the physical drive
**status = Show progress
**bs=block size, amount of source data to be read and then written, IE read 64K at a time, then write that, and repeat.
**bs=block size, amount of source data to be read and then written, IE read 64K at a time, then write that, and repeat.
**conv = noerror = Don't stop on read errors, sync = If an error occurs use zeros or nuls to pad file, progress=show the progress
**conv = noerror = Don't stop on read errors, sync = If an error occurs use zeros or nuls to pad file, progress=show the progress


Before cloning a partition, to save space, "zero out" all unallocated space.  IE, with every file system there are potentially sections of the drive that have had data written to them at some point in time that has since been erased.  And as we all know, when a file is "erased" from a drive, the actual file itself is left on the drive and the space it occupied is simply marked as available in a file system.  DD has no method of determining alocated or unallocated space.  It copies everything.  And in the below example where everything it copies is put into a compressed TAR file, compressing a bunch of zeros is very easy to make quite small.  IE, "zeroing out" unallocated space on a disk drive really reduces the size of an image file in a compressed file.
===== Tips =====


* dd if=/dev/zero bs=64K conv=noerror,sync status=progress of=/overlay/ZeroByteFile.zero (in this example the partition being copied is mounted as an /overlay (look it up), so adjust if you need to clone a different partition)
====== Prepare a Drive or Partition for Cloning ======
** if = Source
Before cloning a partition, to save space on the image file, "zero out" all unallocated space.
** bs =  
** status = Essentially show a progress meter
** of = destination
* sync
** sync = write any unwritten files stored in RAM to physical media
* rm ZeroByte.File.zero
** rm = delete the Zero Byte File to free up space as it has filled the entire free space on the disk.


To copy a complete partition to a single compressed file;
With every file system there are potentially sections of the drive that have had data written to them at some point in time that has since been erased.  And as we all know, when a file is "erased" from a drive, the actual file itself is left on the drive and the space it occupied is simply marked as available in a file system.  DD has no method of determining alocated or unallocated space.  It copies everything.  And in the below example where everything it copies is put into a compressed TAR file, compressing a bunch of zeros is very easy to make quite small.  IE, "zeroing out" unallocated space on a disk drive really reduces the size of an image file in a compressed file.  Advanced cloning utilities like Acronis True Image, Clonezilla, etc. take care of this automatically.  But since DD is a multifaceted utility that isn't specifically designed for cloning, it does not have this capability built in.


*dd if=/dev/sdXy conv=sync,noerror bs=64K status=progress | gzip -c  > /WhatEverPath/WhatEverFile.img.gz (-c=Do not change files)
====== Examples ======
*Example: dd if=/dev/sdb1 conv=sync,noerror bs=64K status=progress | gzip -c  > /mnt/sdb2/DD/EXT4a-9.20.2020.img.gz
The below example writes 0s / zeros to a file named ZeroByteFile in a directory named overlay (that happens to be located on a USB Flash Drive) in 64 Kilobyte chunks (of all the words like portion, segment, section, piece, etc., chunk is the most commonly used word in this instance with block coming in second)


Everything will be cloned, including the UUID of the partition.  If the second flash drive is being used for the sole purpose of backing up settings, as opposed to replacing a bootable flash drive, then to prevent confusion with the source USB Flash Drive or Partition, change the UUID;
*dd if=[[wikipedia:/dev/zero|/dev/zero]] bs=64K conv=noerror,sync status=progress of=/overlay/ZeroByteFile (change the destination to suit your needs)
*sync (this writes any unwritten files stored in RAM / Buffer to the physical media)
*rm ZeroByteFile (this deletes the "Zero Byte File" to free up space as the above DD command made the ZeroByteFile as large as all of the available free space on the drive.)
 
The below example(s) copies a single partition (on a drive that contains multiple partitions) in 64K chunks to a compressed (TAR / GZ (GunZip)) file.
 
*Generic Example: dd if=/dev/sdXy conv=sync,noerror bs=64K status=progress | gzip -c  > /WhatEverPath/WhatEverFile.img.gz (-c=Do not change files)
**Example: dd if=/dev/sdb1 conv=sync,noerror bs=64K status=progress | gzip -c  > /mnt/sdb2/DD/EXT4a-9.20.2020.img.gz (this file is named after the partition it exists on and the date, but can be named anything)
 
When cloning an entire driveverything will be cloned, including the UUID of the partition.  If the second flash drive is being used for the sole purpose of backing up settings, as opposed to replacing a bootable flash drive, then to prevent confusion with the source USB Flash Drive or Partition, change the UUID;


*tune2fs -U random /dev/sdXy*
*tune2fs -U random /dev/sdXy*
Line 3,001: Line 3,006:
To mount a partition (not a complete disk / drive);
To mount a partition (not a complete disk / drive);


* mkdir /tmp/MyMountPoint (this can be any name)
*mkdir /tmp/MyMountPoint (this can be any name)
* mount -o loop -t ext4 /WhatEverPath/WhatEverImage.img /tmp/MyMountPoint
*mount -o loop -t ext4 /WhatEverPath/WhatEverImage.img /tmp/MyMountPoint
** -t = the type of file system (this could be -t vfat, -t ntfs, -t ext2, etc., but it should obviously match the type of the original file system)
**-t = the type of file system (this could be -t vfat, -t ntfs, -t ext2, etc., but it should obviously match the type of the original file system)
** -o = Option (let the mount command know it is a "loop" device)
**-o = Option (let the mount command know it is a "loop" device)


====Good 'ole Fashion, just make a copy====
====Good 'ole Fashion, just make a copy====
Line 3,057: Line 3,062:
The installation script ./install.sh relies on the full BASH shell (OpenWRT includes the [[wikipedia:Almquist_shell|ASH]] shell by default): opkg install bash, then type the command ''bash ./install.sh'' (plain ASH won't work, they even explicitly state the [[wikipedia:Shebang_(Unix)|shebang]] of their file as ''#!/bin/bash'', not #!/bin/sh, and just for the fun of it attempted to run it with ASH, and it errors out) Read here for more information or to change it permanently: https://www.howtogeek.com/669835/how-to-change-your-default-shell-on-linux-with-chsh/
The installation script ./install.sh relies on the full BASH shell (OpenWRT includes the [[wikipedia:Almquist_shell|ASH]] shell by default): opkg install bash, then type the command ''bash ./install.sh'' (plain ASH won't work, they even explicitly state the [[wikipedia:Shebang_(Unix)|shebang]] of their file as ''#!/bin/bash'', not #!/bin/sh, and just for the fun of it attempted to run it with ASH, and it errors out) Read here for more information or to change it permanently: https://www.howtogeek.com/669835/how-to-change-your-default-shell-on-linux-with-chsh/


=== NTP (Network Time Protocol) ===
===NTP (Network Time Protocol)===
By default OpenWRT provides an NTP Client ''and Server'' (suprise, suprise, and a really good thing) within [[wikipedia:BusyBox|BusyBox]].  Since most routers (if any) do not provide a method (IE, battery) of maintaining an internal clock when the router is off a method must exist to set the proper time for the router when it starts up.  This client service is supplied within the BusyBox version of ntpclient.
By default OpenWRT provides an NTP Client ''and Server'' (suprise, suprise, and a really good thing) within [[wikipedia:BusyBox|BusyBox]].  Since most routers (if any) do not provide a method (IE, battery) of maintaining an internal clock when the router is off a method must exist to set the proper time for the router when it starts up.  This client service is supplied within the BusyBox version of ntpclient.