<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.malinux.no/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Roy</id>
	<title>MalinWiKi - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.malinux.no/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Roy"/>
	<link rel="alternate" type="text/html" href="https://wiki.malinux.no/Special:Contributions/Roy"/>
	<updated>2026-04-04T10:14:20Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.39.3</generator>
	<entry>
		<id>https://wiki.malinux.no/index.php?title=Roy%27s_notes&amp;diff=187</id>
		<title>Roy&#039;s notes</title>
		<link rel="alternate" type="text/html" href="https://wiki.malinux.no/index.php?title=Roy%27s_notes&amp;diff=187"/>
		<updated>2020-11-17T18:53:15Z</updated>

		<summary type="html">&lt;p&gt;Roy: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Page move =&lt;br /&gt;
&lt;br /&gt;
After borrowing space on Malin&#039;s wiki for some years, further edits will be done on the [https://wiki.karlsbakk.net/index.php/Roy%27s_notes my new wiki] so that next time the wiki goes down after something strange happened, she won&#039;t get a ton of mesages from me, but I&#039;ll have to fix it myself - oh well ;)&lt;br /&gt;
&lt;br /&gt;
= LVM, md and friends =&lt;br /&gt;
&lt;br /&gt;
== Linux&#039; Logical Volume Manager (LVM) ==&lt;br /&gt;
&lt;br /&gt;
=== LVM in general ===&lt;br /&gt;
&lt;br /&gt;
LVM is designed to be an abstraction layer on top of physical drives or RAID, typically [https://raid.wiki.kernel.org/index.php/RAID_setup mdraid] or [https://help.ubuntu.com/community/FakeRaidHowto fakeraid]. Keep in mind that fakeraid should be avoided unless you really need it, like in conjunction with dual-booting linux and windows on fakeraid. LVM broadly consists of three elements, the &amp;quot;physical&amp;quot; devices (PV), the volume group (VG) and the logical volume (LV). There can be multiple PVs, VGs and LVs, depending on requirement. More about this below. All commands are given as examples, and all of them can be fine-tuned using extra flags in need of so. In my experience, the defaults work well for most usecases.&lt;br /&gt;
&lt;br /&gt;
I&#039;m mentioning filesystem below too. Where I write ext4, the samme applies to ext2 and ext3.&lt;br /&gt;
&lt;br /&gt;
==== Create a PV ====&lt;br /&gt;
&lt;br /&gt;
A PV is the &amp;quot;physical&amp;quot; parts. This does not need to be a physical disk, but can also be another RAID, be it an mdraid, fakeraid, hardware raid, a virtual disk on a SAN or otherwisee or a partition on one of those. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#  These add three PVs, one on a drive (or hardware raid) and another two on mdraids.&lt;br /&gt;
pvcreate /dev/sdb&lt;br /&gt;
pvcreate /dev/md1 /dev/md2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For more information about pvcreate, see [https://linux.die.net/man/8/pvcreate the manual].&lt;br /&gt;
&lt;br /&gt;
==== Create a VG ====&lt;br /&gt;
&lt;br /&gt;
The volume group consists of one or more PVs grouped together on which LVs can be placed. If several PVs are grouped in a VG, it&#039;s generally a good idea to make sure these PVs have some sort of redundancy, as in mdraid/fakeraid or hwraid. Otherwise it will be like using a [https://en.wikipedia.org/wiki/RAID RAID-0] with a single point of failure on each of the independant drives. LVM has [https://unix.stackexchange.com/questions/150644/raiding-with-lvm-vs-mdraid-pros-and-cons  RAID code in it] as well, so you can use that. I haven&#039;t done so myself, as I generally stick to mraid. The reason is mdraid is, in my opinion older and more stable and has more users (meaning bugs are reported and fixed faster whenever they are found). That said, I beleive the actual RAID code used in LVM RAID are the same function calls as for mdraid, so it may not be much of a difference. I still stick with mdraid. To create a VG, run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create volume group my_vg&lt;br /&gt;
vgcreate my_vg /dev/md1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that if vgcreate is run with a PV (as /dev/md1 above) that is not defined as a PV (like above), this is done implicitly, so if you don&#039;t need any special flags to pvcreate, you can simply skip it and let vgcreate do that for you.&lt;br /&gt;
&lt;br /&gt;
==== Create an LV ====&lt;br /&gt;
&lt;br /&gt;
LVs can be compared to partitions, somehow, since they are bounderies of a fraction or all of that of a VG. The difference between them and a partition, however, is that they can be grown or shrunk easily and also moved around between PVs without downtime. This flexibility makes them superiour to partitions as your system can be changed without users noticing it. By default, an LV is alloated &amp;quot;thickly&amp;quot;, meaning all the data given to it, is allocated from the VG and thus the PV. The following makes a 100GB LV named &amp;quot;thicklv&amp;quot;. When making an LV, I usually allocate what&#039;s needed plus some more, but not everything, just to make sure it&#039;s space available for growth on any of the LVs on the VG, or new LVs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a thick provisioned LV named thicklv on the VG my_vg&lt;br /&gt;
lvcreate -n thicklv -L 100G my_vg&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After the LV is created, a filesystem can be placed on it unless it is meant to be used directly. The application for direct use include swap space, VM storage and certain database systems. Most of these will, however, work on filesystems too, although my testing has shown that on swap space, there is a significant performance gain for using dedicated storage without a filesystem. As for filesystems, most Linux users use either ext4 or xfs. Personally, I generally use XFS these days. See my notes below on filesystem choice.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a filesystem on the LV - this could have been mkfs -t ext4 or whatever filesystem you choose&lt;br /&gt;
mkfs -t xfs /dev/my_vg/thicklv&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then just edit /etc/fstab with correct data and run mount -a, and you should be all set.&lt;br /&gt;
&lt;br /&gt;
==== Create LVM cache ====&lt;br /&gt;
LVMcache is LVM&#039;s solution to caching a slowish filesystem on spinning rust with the help of much faster SSDs. For this to work, use a separate SSD or a mirror or two (just in case) an add the new disk/md dev to the same VG. In this case, we use a small mirror, md1. LVM is not able to cache to a disk or partition outside the volume group.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
vgextend data /dev/md1&lt;br /&gt;
  Physical volume &amp;quot;/dev/md1&amp;quot; successfully created.&lt;br /&gt;
  Volume group &amp;quot;data&amp;quot; successfully extended&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Thn create two LVs, one for the data (contents of files) and one for the metadata (filenames, directories, attributes etc). Typically, the metadata part won&#039;t need to be very large. 100M should usually do unless you have ekstremely many small files. I guess there are ways to calculate it, but again, 1GB should do for everyone (or was that 640k?). As for the data cache, I chose to use 40G here for a 15TB RAID. It will only cache what actively use anyway, so no need for overkill.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
lvcreate -L 1G -n _cache_meta data /dev/md1&lt;br /&gt;
lvcreate -L 100G -n _cache data /dev/md1&lt;br /&gt;
&lt;br /&gt;
# Some would want --cachemode writeback, but if paranoid, I wouldn&#039;t recommend it. Metadata or data can be easily corrupted in case of failure. Most filesystems will however recover from this these days since they use journaling. It &#039;&#039;really&#039;&#039; speeds up things.&lt;br /&gt;
lvconvert --type cache-pool --cachemode writethrough --poolmetadata data/_cache_meta data/_cache&lt;br /&gt;
lvconvert --type cache --cachepool data/_cache data/data&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
That should be it. If you benchmarked the disk before this, you should try again and you&#039;ll probably get a nice surprise. If not, well, see below how to turn this off again :)&lt;br /&gt;
&lt;br /&gt;
==== Disabling LVM cache ====&lt;br /&gt;
&lt;br /&gt;
If you want to change the cached LV, such as growing og shrinking or otherwise, you&#039;ll have to disable caching first and then re-enable it. There&#039;s no quick-and-easy fix, but you just do as you did when enabling in the first place. &lt;br /&gt;
&lt;br /&gt;
Forst, disable caching for the LV. This will do it cleanly and remove the LVs earlier created for caching the main device. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
lvconvert --uncache data/data&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, since you now have a VG with an empty PV in it, earlier used for caching, I&#039;d recommend removing this for now to avoid expanding onto that as well. Since they&#039;re in the same VG, this might happen and if you get so far as to extend the lv and the filesystem on it, and this filesystem is XFS or similar filesystems without possibilities of reducing the size, you have a wee problem. &lt;br /&gt;
&lt;br /&gt;
Just remove that PV from the VG&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
vgreduce data /dev/md1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The PV is still there, but pvs should now show it not connected to a VG&lt;br /&gt;
&lt;br /&gt;
==== Growing devices ====&lt;br /&gt;
&lt;br /&gt;
LVM objects can be grown and shrunk. If a PV resides on a RAID where a new drive has been added or otherwise grown, or on a partition or virtual disk that has been extended, the PV must be updated to reflect these changes. The following command will grow the PV to the maximum available on the underlying storage. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Resize the PV /dev/md (not the RAID, only the PV on the RAID) to its full size&lt;br /&gt;
pvresize /dev/md1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If a new PV is added, the VG can be grown to add the space on that in addition to what&#039;s there already. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Extend my_vg to include md2 and its space&lt;br /&gt;
vgextend my_vg /dev/md2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
With more space available in the VG, the LV can now be extended. Let&#039;s add another 50GB to it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Extend thicklv - add 50GB. If you know you won&#039;t need the space anywhere else, you may want to&lt;br /&gt;
# lvresize -l+100%FREE instead. Keep in mind the difference between -l (extents) and -L (bytes)&lt;br /&gt;
lvresize -L +50G my_vg/thicklv&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Growing filesystems ====&lt;br /&gt;
After the LV has grown, run &#039;&#039;xfs_growfs&#039;&#039; (xfs) or &#039;&#039;resize2fs&#039;&#039; (ext4) to make use of the new data. To grow the filesystem to all available space on ext4, run the below command.  To partly grow the filesystem or to shrink it or otherwise, please see the manuals.&lt;br /&gt;
&lt;br /&gt;
The filesystem can be mounted when this is run. If you for some reason get an &#039;&#039;&#039;access denied&#039;&#039;&#039; error when running this as root or with sudo, it&#039;s likely caused by a filesystem error. To fix this, unmount the filesystem first and run &#039;&#039;&#039;fsck -f /dev/my_vg/thicklv&#039;&#039;&#039; and remount it before retrying to extend it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
resize2fs /dev/my_vg/thicklv&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Similarly, with XFS, but note that xfs_growfs doesn&#039;t take the device name, but the filesystem&#039;s mount point. In the case of XFS, also note that the filesystem &#039;&#039;&#039;&#039;&#039;must&#039;&#039;&#039;&#039;&#039; be mounted to be grown. This, in contrast to how it was in the old days when filesystems had to be unmounted to be grown.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
xfs_growfs /my_mountpoint&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Rename system VG ====&lt;br /&gt;
&lt;br /&gt;
Some distros create VG names like those-from-a-sysadmin-with-a-well-developed-paranoia-not-to-hit-a-duplicate. Debian, for instance, uses names like &amp;quot;my-full-hostname-vg&amp;quot;. Personally, I don&#039;t like these, since if I were to move a disk or vdisk around to somewhere else, I&#039;d make sure not to add a disk named &#039;sys&#039; to an existing system. If you do, most distros will refuse to use the VGs with duplicate names, resulting in the OS not booting until either one is specified by its UUID or just one removed. As I&#039;m aware of this, I stick to the super-risky thing of all system VGs named &#039;sys&#039; and so on.&lt;br /&gt;
&lt;br /&gt;
If you do this, keep in mind that it may blow up your computer and take your girl- or boyfriend with it or even make either of them pregnant, allowing Trump to rule your life and generally make things suck. You&#039;re on your own!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Rename the VG&lt;br /&gt;
vgrename my-full-hostname-vg sys&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, in /boot/grub/grub.cfg, change the old lv path from something like &#039;/dev/mapper/debian--stretch--machine--vg-root&#039; to your new and fancy &#039;/dev/sys/root. Likewise, in /etc/fstab, change occurences of &#039;/dev/mapper/debian--stretch--machine--vg-&#039; (or similar) with &#039;/dev/sys/&#039;. Here, this was like this - the old ones commented out.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;fstab&amp;quot;&amp;gt;&lt;br /&gt;
#/dev/mapper/debian--stretch--box--vg-root      /               ext4            errors=remount-ro,discard       0       1&lt;br /&gt;
/dev/sys/root                                   /               ext4            errors=remount-ro,discard       0       1&lt;br /&gt;
# /boot was on /dev/vda1 during installation&lt;br /&gt;
UUID=myverylonguuidwithatonofgoodinfoinit       /boot           ext2            defaults                        0       2&lt;br /&gt;
#/dev/mapper/debian--stretch--box--vg-swap_1    none            swap            sw                              0       0&lt;br /&gt;
/dev/sys/swap_1                                 none            swap            sw                              0       0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Update /etc/initramfs-tools/conf.d/resume with similar data for swap.&lt;br /&gt;
&lt;br /&gt;
You might want to run &#039;update-initramfs -u -k all&#039; after this, but I&#039;m not sure if it&#039;s needed.&lt;br /&gt;
&lt;br /&gt;
Now, pray to the nearest god(s) and give it a reboot and it should (probably) work.&lt;br /&gt;
&lt;br /&gt;
After reboot, run &#039;&#039;&#039;swapoff -a&#039;&#039;&#039;, then &#039;&#039;&#039;mkswap /dev/sys/swap_1&#039;&#039;&#039; (or whatever it&#039;s called on your system) and &#039;&#039;&#039;swapon -a&#039;&#039;&#039; again. You may want to give it another reboot or two for kicks, but it should work well even without that.&lt;br /&gt;
&lt;br /&gt;
=== Migration tools ===&lt;br /&gt;
&lt;br /&gt;
At times, storage regimes change, new storage is added and sometimes it&#039;s not easy to migrate with the current hardware or its support systems. Once I had to migrate a 45TiB fileserver from one storage system to another, preferably without downtime. The server originally had three 15TiB PVs of which two were full and the third half full. I resorted to using [https://linux.die.net/man/8/pvmove pvmove] to just move the data on the PVs in use to a new PV. We started out with creating a new 50TiB PV, sde, and then to pvmove.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Attach /dev/sde to the VG my_vg&lt;br /&gt;
vgextend my_vg /dev/sde&lt;br /&gt;
&lt;br /&gt;
# Move the contents from /dev/sdb over to /dev/sde block by block. If a target is not given in pvmove,&lt;br /&gt;
# the contents of the source (sdb here) will be put somewhere else in the pool.&lt;br /&gt;
pvmove /dev/sdb /dev/sde&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This took a while (as in a week or so) - the pvmove command uses old code and logic (or at least did that when I migrated this in November 2016), but it affected performance on the server very little, so users didn&#039;t notice. After the first PV was migrated, I continued with the other two, one after the other, and after a month or so, it was migrated. We used this on a number of large fileservers, and it worked flawlessly. Before doing the production servers I also tried interrupting pvmove in various ways, including hard resets, and it just kept on after the reboot.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;NOTE:&#039;&#039;&#039;&#039;&#039; &#039;&#039;Even though it worked well for us, &#039;&#039;&#039;always&#039;&#039;&#039; keep a good backup before doing this. Things may go wrong, and without a good backup, you may be looking for a hard-to-find new job the next morning&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
==== mdadm workarounds ====&lt;br /&gt;
&lt;br /&gt;
===== Migrate from a mirror (raid-1) to raid-10 =====&lt;br /&gt;
&lt;br /&gt;
Create a mirror&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sdb /dev/sdc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
LVM (pv/vg/lv) on md0 (see above), put a filesystem on the lv and fill it with some data.&lt;br /&gt;
&lt;br /&gt;
Now, some months later, you want to change this to raid-10 to allow for the same amount of redundancy, but to allow more disks into the system.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mdadm --grow /dev/md0 --level=10&lt;br /&gt;
mdadm: Impossibly level change request for RAID1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So - no - doesn&#039;t work. But - we&#039;re on &lt;br /&gt;
&lt;br /&gt;
Since we&#039;re on lvm already, this&#039;ll be easy. If you&#039;re using filesystems directly on partitions, you can do this the same way, but without the pvmove part, using rsync or whateever you like instead. I&#039;d recommend using lvm for for the new raid, which should be rather obvious from this article. Now plug in a new drive and create a new raid10 on that one. If you two new drives, install both. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# change &amp;quot;missing&amp;quot; to the other device name if you installed two new drives&lt;br /&gt;
mdadm --create /dev/md1 --level=10 --raid-devices=2 /dev/vdd missing&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, as described above, just vgextend the vg, adding the new raid and run pvmove to move the data from the old pv (residing on the old raid1) to the new pv (on raid10). Afte rpvmove is finished (which may take awile, see above), just&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
vgreduce raidtest /dev/md0&lt;br /&gt;
pvremove /dev/md0&lt;br /&gt;
mdadm --stop /dev/md0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
…and your disk is free to be added to the new array. If the new raid is running in degraded mode (if you created it with just one drive), better don&#039;t wait too long, since you don&#039;t have redundancy. Just mdadm --add the devs.&lt;br /&gt;
&lt;br /&gt;
If you now have /dev/mdstat telling you your raid10 is active and have three drives, of which one is a spare, it should look something like this&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5] [raid4] [raid10]&lt;br /&gt;
md1 : active raid10 vdc[3](S) vdb[2] vdd[0]&lt;br /&gt;
      8380416 blocks super 1.2 2 near-copies [2/2] [UU]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Just mdadm --grow --raid-devices=3 /dev/md1&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;RAID section is not complete. I&#039;ll write more on migraing from raid10 to raid6 later. It&#039;s not straight forward, but easier than this one :)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== Thin provisioned LVs ===&lt;br /&gt;
&lt;br /&gt;
Thin provisioning on LVM is a method used for not allocating all the space given to an LV. For instance, if you have a 1TB VG and want to give an LV 500GB, although it currently only uses a fraction of that, a thin lv can be a good alternative. This will allow for adding a limit to how much it can use, but also to let it grow dynamically without manual work by the sysadmin. Thin provisioning adds another layer of abstaction by creating a special LV as a &#039;&#039;thin pool&#039;&#039; from which data is allocated to the &#039;&#039;thin volume(s)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== Create a thin pool ====&lt;br /&gt;
&lt;br /&gt;
Allocate 1TB to the thin pool to be used for thinly provisioned LVs. Keep in mind that the space allocated to the thin pool is in fact thick provisioned. Only the volumes put on &#039;&#039;thinpool&#039;&#039; are thin provisioned. This will create two hidden LVs, one for data and one for metadata. Normally the defaults will do, but check the manual if the data doesn&#039;t match the usual patterns (such as billions of files, resulting in huge amounts of metadata). I &#039;&#039;beleive&#039;&#039; the metadata part should be resizable at a later time if needed, but I have not tested it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a pool for thin LVs. Keep in mind that the pool itself is not thin provisioned, only the volumes residing on it&lt;br /&gt;
lvcreate --size 1T --type thin-pool --thinpool thinpool my_vg&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Create a thin volume ====&lt;br /&gt;
&lt;br /&gt;
You have the thinpool, now put a thin volume on it. It will allocate some space for metadata, but probably not much (a few megs, perhaps).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Now, create a volume with a virtual (-V) size of half a terabyte named thin_pool, but using the thinpool (-T) named thin_pool for storage&lt;br /&gt;
lvcreate -V 500G -T my_vg/thin_pool --name thinvol&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The new volume&#039;s device name will be /dev/thinvol. Now, create a filesystem on it, add to fstab and mount it. The &#039;&#039;&#039;df&#039;&#039;&#039; command will return available space according to the virtual size (-V), while lvs will show how much data is actually used on each of the thinly provisioned volumes.&lt;br /&gt;
&lt;br /&gt;
== Filesystem dilemmas ==&lt;br /&gt;
&lt;br /&gt;
=== XFS or ext4 or something else ===&lt;br /&gt;
The choice of filesystem varies for your use. Distros such as RHEL/CentOS has moved to XFS by default from v7. Debian/Ubuntu still sticks to ext4, like most other. I&#039;ll discuss my thoughts below on ext4 vs XFS and leave the other filesystems for later.&lt;br /&gt;
&lt;br /&gt;
==== ext4 ====&lt;br /&gt;
ext4 is probably the most used filesystem on linux as of writing. It&#039;s rock stable and has been extended by a lot of extensions since the original ext2. It still retains backward compatibility, being able to mount and fsck ext2 and ext3 with the ext4 driver. However, it doesn&#039;t handle large filesystems very well. If a filesystem is created for &amp;lt;16TiB, it cannot be grown to anything larger than 16TiB. This may have changed lately, though. One other issue is handling errors. If a large filesystem (say 10TiB) is damaged, an fsck may take several hours, leading to long downtime. When I refer to ext4 further in this text, the same applies to ext2 and ext3 unless otherwise specified.&lt;br /&gt;
&lt;br /&gt;
==== XFS ====&lt;br /&gt;
XFS, originally developed by SGI some time in the bronze age, but has been worked on heavily after that. RHEL and Centos version 7 and forward, uses XFS as the default filesystem. It is quick, it scales well, but it lacks at least two things ext4 has. It cannot be shrunk (not that you normally need that, but nice if you have a typo or you need to change things). Also, it doesn&#039;t allow for automatic fsck on bootup. If something is messed up on the filesystem, you&#039;ll have to login as root on the console (not ssh), which might be an issue on some systems. The fsck equivalent, xfs_repair, is a *lot* faster than ext4&#039;s fsck, though.&lt;br /&gt;
&lt;br /&gt;
==== ZFS ====&lt;br /&gt;
ZFS is like a combination of RAID, LVM and a filesystem, supporting full checksumming, auto-healing (given sufficient redundancy), compression, encryption, replication, deduplication (if you&#039;re brave and have a &#039;&#039;ton&#039;&#039; of memory) and a lot more. It&#039;s a separate chapter and needs a lot more talk than paragraph here.&lt;br /&gt;
&lt;br /&gt;
==== btrfs ====&lt;br /&gt;
btrfs, pronounced &amp;quot;butterfs&amp;quot; or &amp;quot;betterfs&amp;quot; or just spelled out, is a filesystem that mimics that of ZFS. It has been around for 10 years or so, but hasn&#039;t yet proven to be really stable. Following the progress of it for those years, I&#039;ve found it to be a nice toy with which to play, but not to be used in production. Again, others may say otherwise, but these are just my words.&lt;br /&gt;
&lt;br /&gt;
== Low level disk handling ==&lt;br /&gt;
&lt;br /&gt;
This section is for low-level handling of disks, regardless of storage system elsewhere. These apply to mdraid, lvmraid and zfs and possibly other solutions, with the exception of individual drives on hwraid (and maybe fakeraid), since there, the drives are hidden from Linux (or whatever OS).&lt;br /&gt;
&lt;br /&gt;
=== S.M.A.R.T. and slow drives ===&lt;br /&gt;
Modern (that is, from about 1990 or later) have S.M.A.R.T. (or just smart, since it&#039;s easier to type) monitoring built in, meaning the disk&#039;s controller is monitoring itself. This is handy and will ideally tell you in advance that a drive is flakey or dying. Modern (2010+) smart monitoring is more or less the same. It can be trusted about 50% of the time. Usually, if smart detects an error, it&#039;s a real error. I don&#039;t think I&#039;ve seen it reporting a false positive, but others may know better. &lt;br /&gt;
&lt;br /&gt;
==== smartmontools ====&lt;br /&gt;
First, install smartmontool and run smartclt -H /dev/yourdisk (/dev/sda or something) to get a health report. Then perhaps run smartctl -a /dev/yourdisk and look for &#039;current pending sectors&#039; This should be zero. Also check the temperature, which normally should be much above 50.&lt;br /&gt;
&lt;br /&gt;
==== single, slow drive ====&lt;br /&gt;
What may happen, is smart not seeing anything and life goes on like before, only slower and less prouductive, without telling anyone. If you stubler over this issue, you&#039;ll probably see it during a large rsync/zfs send/receive or a resync/rebuild/resilver of the raid/zpool. During this, it feels like everything is slow and your RAID has turned into a RAIF (redundant array of inexpensive floppies). To check if you have a single drive messing up it all, check with &#039;&#039;&#039;iostat -x 2&#039;&#039;&#039;, having 2 being the delay between each measurement. Interrupt it with ctrl+x. If there&#039;s a rougue drive there, it should stand out like sdg below&lt;br /&gt;
&lt;br /&gt;
 avg-cpu:  %user   %nice %system %iowait  %steal   %idle&lt;br /&gt;
            0.38    0.00    1.75    0.00    0.00   97.87&lt;br /&gt;
&lt;br /&gt;
 Device            r/s     w/s     rkB/s     wkB/s   rrqm/s   wrqm/s  %rrqm  %wrqm r_await w_await aqu-sz rareq-sz wareq-sz  svctm  %util&lt;br /&gt;
 sda              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdb              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdc              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdd              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sde              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdf              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdg              3.50    0.00   2352.00      0.00     0.00     0.00   0.00   0.00 14306.29    0.00  13.85   672.00     0.00 285.71 100.00&lt;br /&gt;
 sdh              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
&lt;br /&gt;
In ZFS land, you should be able to get similar data with &#039;&#039;&#039;zpool iostat -v &amp;lt;pool&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Now you know the bad drive (sdg), pull it from the raid with &#039;&#039;&#039;mdadm --fail /dev/mdX /dev/sdX&#039;&#039;&#039;. Now test the drive&#039;s performance manually, just simply:&lt;br /&gt;
&lt;br /&gt;
 # hdparm -t /dev/sdg&lt;br /&gt;
 &lt;br /&gt;
 /dev/sdg:&lt;br /&gt;
  Timing buffered disk reads:   2 MB in  5.37 seconds = 381.46 kB/sec&lt;br /&gt;
&lt;br /&gt;
Bingo - nothing you&#039;d want to keep. For a good drive, it should be something like 100-200MB/s&lt;br /&gt;
&lt;br /&gt;
PS: Keep in mind that you have a degraded RAID by now in case you had a spare waiting for things to happen.&lt;br /&gt;
&lt;br /&gt;
Try to replace the cable and/or try the disk on another port/controller. If the result from hdparm persists, it&#039;s probably a bad cable&lt;br /&gt;
&lt;br /&gt;
So, then, just psycially locate the drive, pull it out, take out the discs and magnets and recycle the rest.&lt;br /&gt;
&lt;br /&gt;
=== &amp;quot;Unplug&amp;quot; drive from system ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Find the device unit&#039;s number with something like&lt;br /&gt;
find /sys/bus/scsi/devices/*/block/ -name sdd&lt;br /&gt;
# returning /sys/bus/scsi/devices/3:0:0:0/block/sdd here, &lt;br /&gt;
# meaning 3:0:0:0 is the SCSI device we&#039;re looking for.&lt;br /&gt;
&lt;br /&gt;
# Given this is the correct device, and you want to &#039;unplug&#039; it, do so by&lt;br /&gt;
echo 1 &amp;gt; /sys/bus/scsi/devices/3:0:0:0/delete&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Rescan disk controllers ===&lt;br /&gt;
If a drive is added and for some reason doesn&#039;t get detected, or is removed by the command above, it can be rediscovered with a sysfs command to the scsi host to which it is connected. Since there may be quite a few of these, an easy way is to just scan them all and check the output of &#039;&#039;&#039;dmesg -T&#039;&#039;&#039; after running it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Make a list of controllers and send a rescan message to each of them. It won&#039;t do anything &lt;br /&gt;
# for those where nothing has changed, but it will show new drives where they have been added.&lt;br /&gt;
for host_scan in /sys/class/scsi_host/host*/scan&lt;br /&gt;
do&lt;br /&gt;
  echo &#039;- - -&#039; &amp;gt; $host_scan&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Fail injection with debugfs ===&lt;br /&gt;
[https://lxadm.com/Using_fault_injection https://lxadm.com/Using_fault_injection]&lt;br /&gt;
&lt;br /&gt;
== mdadm stuff ==&lt;br /&gt;
=== Resync ===&lt;br /&gt;
To resync a raid, that is, check, run&lt;br /&gt;
&lt;br /&gt;
 echo check &amp;gt; /sys/block/$dev/md/sync_action&lt;br /&gt;
&lt;br /&gt;
where $dev is something like md0. If you have several raids, something like this should work&lt;br /&gt;
&lt;br /&gt;
 for dev in md{0,1}&lt;br /&gt;
 do&lt;br /&gt;
   echo repair &amp;gt; /sys/block/$dev/md/sync_action&lt;br /&gt;
 done&lt;br /&gt;
&lt;br /&gt;
Also useful in a one-liner like&lt;br /&gt;
&lt;br /&gt;
 for dev in md{0,1} ; do echo repair &amp;gt; /sys/block/$dev/md/sync_action ; done&lt;br /&gt;
&lt;br /&gt;
Different raids on different drives will do this in parallel. If the drives are shared somehow with partitions or similar, the check or repair will wait for the other to finish before going on.&lt;br /&gt;
&lt;br /&gt;
As for repair vs check, [https://raid.wiki.kernel.org/index.php/RAID_Administration this article] describes it well. I stick to using repair unless it&#039;s something rare where I don&#039;t want to touch the data.&lt;br /&gt;
&lt;br /&gt;
=== Spare pools ===&lt;br /&gt;
In the old itmes, mdadm supported only a dedicated spare per md device, so if working with a large set of drives (20? 40?), where you&#039;d want to setup more raid sets to increase redundancy, you&#039;d dedicate a spare to each of the raid sets. This has changed (some time ago?), so in these modern, heathen days, you can change mdadm.conf, usually placed under /etc/mdadm, and add &#039;spare-group=somegroup&#039; where &#039;somegroup&#039; is a string identifying the spare group. After doing this, run &#039;&#039;&#039;update-initramfs -u&#039;&#039;&#039; and reboot and add a spare to one of the raid sets in the spare group, and md will use that or those spares for all the raidsets in that group.&lt;br /&gt;
&lt;br /&gt;
As some pointed out on #linux-raid @ irc.freenode.net, this feature is very badly documented, but as far as I can see, it works well.&lt;br /&gt;
&lt;br /&gt;
==== Example config ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create two raidsets&lt;br /&gt;
&lt;br /&gt;
mdadm --create /dev/md1 --level=6 --raid-devices=6 /dev/vd[efghij]&lt;br /&gt;
mdadm --create /dev/md2 --level=6 --raid-devices=6 /dev/vd[klmnop]&lt;br /&gt;
&lt;br /&gt;
# get their UUID etc&lt;br /&gt;
&lt;br /&gt;
mdadm --detail --scan&lt;br /&gt;
ARRAY /dev/md/1 metadata=1.2 name=raidtest:1 UUID=1a8cbdcb:f4092350:348b6b80:c054d74c&lt;br /&gt;
ARRAY /dev/md/2 metadata=1.2 name=raidtest:2 UUID=894b1b7c:cb7eba70:917d6033:ea5afd2b&lt;br /&gt;
&lt;br /&gt;
# Put those lines into /etc/mdadm/mdadm.conf and and add the spare-group&lt;br /&gt;
&lt;br /&gt;
ARRAY /dev/md/1 metadata=1.2 name=raidtest:1 spare-group=raidtest UUID=1a8cbdcb:f4092350:348b6b80:c054d74c&lt;br /&gt;
ARRAY /dev/md/2 metadata=1.2 name=raidtest:2 spare-group=raidtest UUID=894b1b7c:cb7eba70:917d6033:ea5afd2b&lt;br /&gt;
&lt;br /&gt;
# update the initramfs and reboot&lt;br /&gt;
&lt;br /&gt;
update-initramfs -u&lt;br /&gt;
reboot&lt;br /&gt;
&lt;br /&gt;
# add a spare drive to one of the raids&lt;br /&gt;
&lt;br /&gt;
mdadm --add /dev/md1 /dev/vdq&lt;br /&gt;
&lt;br /&gt;
# fail a drive on the other raid&lt;br /&gt;
&lt;br /&gt;
mdadm --fail /dev/md2 /dev/vdn&lt;br /&gt;
&lt;br /&gt;
# check /proc/mdstat to see md2 rebuilding with the spare from md1&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Recovery ===&lt;br /&gt;
&lt;br /&gt;
The other day, I came across a problem a user had on #linux-raid@irc.freenode.net. He had an old Qnap NAS that had died and tried plugging the drives in to his Linux machine and got various errors. The two-drive RAID-1 did not come up as it should, &#039;&#039;&#039;dmesg&#039;&#039;&#039; was full of errors from one of the drives (both connected on USB) and so forth.&lt;br /&gt;
&lt;br /&gt;
We went on and started by taking down the machine and just connecting one of the drives. I had him check what was assembled with&lt;br /&gt;
&lt;br /&gt;
 cat /proc/mdstat&lt;br /&gt;
&lt;br /&gt;
That returned /proc/md127 assembled, but LVM didn&#039;t find anything. So running a manual scan&lt;br /&gt;
&lt;br /&gt;
 pvscan --cache /dev/md127&lt;br /&gt;
&lt;br /&gt;
This made linux find the PV, VG and a couple of LVs, but probably because the mdraid was degraded, the LVs were deactivated, according to &#039;&#039;&#039;lvscan&#039;&#039;&#039;. Activating the one with a filesystem manually&lt;br /&gt;
&lt;br /&gt;
 lvchange -a y /dev/&amp;lt;vg&amp;gt;/&amp;lt;lv&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Substitute &amp;lt;vg&amp;gt; and &amp;lt;lv&amp;gt; with the names listed by vgs and lvs.&lt;br /&gt;
&lt;br /&gt;
This worked, and the filesystem on /dev/&amp;lt;vg&amp;gt;/&amp;lt;lv&amp;gt; could be mounted correctly.&lt;br /&gt;
&lt;br /&gt;
=== Renaming a RAID ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Not finished&#039;&#039;&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
&lt;br /&gt;
Back around 2001, I asked on the linux-raid list for disk tagging, not default back then, but supported, and thought of the possibility of disk #1 getting replaced with disk #1 from another raid because of a messup. After this, the hostname was added to the raid name in the superblock. So when a RAID is created, it is named &amp;quot;hostname:raidname&amp;quot;, where the raidname is either a number (0,1...) or a name. &lt;br /&gt;
&lt;br /&gt;
For instance, running this on my VM named &amp;quot;raidtest&amp;quot;:&lt;br /&gt;
&lt;br /&gt;
 mdadm --create --level=1 --raid-devices=2 /dev/md/stuff /dev/sd[st]&lt;br /&gt;
&lt;br /&gt;
mdadm --detail --scan now shows this&lt;br /&gt;
&lt;br /&gt;
 ARRAY /dev/md/stuff metadata=1.2 name=raidtest:stuff UUID=c4cdf69f:393a28b1:47648ed3:726613de&lt;br /&gt;
&lt;br /&gt;
Now, you might want to change this name for some reason, and it&#039;s not supported under &amp;quot;grow&amp;quot;, so what to do… The name is, after all, local to the disk, since it&#039;s there to avoid messing up a raid (or two) after a disk mixup.&lt;br /&gt;
&lt;br /&gt;
 mdadm --assemble /dev/md/stuff --name &#039;someotherhost:stuff&#039; --update=homehost /dev/sd[st]&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== The badblock list ===&lt;br /&gt;
&#039;&#039;&#039;md&#039;&#039;&#039; has an internal badblock list (BBL), added around 2010, to list the bad blocks on the disk to avoid using those. While this might sound like a good idea, the badblock list is updated in case of a read error, which can be caused by several things. To make things worse, the BBL is replicated to other drives when a drive fails or the array is grown. So if you start out with sda and sdb and sdb suffers some errors, nothing wrong, md will read from sda, but flag those sectors on sdb as bad. So after a while, perhaps sda dies and gets replaced, with the same content, including the BBL. Then, at some point you might to replace sdb and it, too gets the BBL. So it sticks - forever. Also, there&#039;s no real point of keeping a BBL list, since the drive has its own and even if a sector error occurs, the array will have sufficient redundancy to recover from that (unless you use RAID-0 which you shouldn&#039;t). If a drive finds a bad sector, it&#039;ll be reallocated by the drive itself without the user&#039;s/admin&#039;s/system&#039;s knowledge. If a sector can&#039;t be reallocated, it means the drive is bad and should be replaced.&lt;br /&gt;
&lt;br /&gt;
There&#039;s no official way to remove it and although you can assemble it with the no-bbl option, this will only work if there&#039;s an empty BBL. Also, this will require downtime. As far as I can see, the only way to do this currently, is with a wee hack that should work. Just replace the names of mddev/diskdev with your own.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
mddev=&amp;quot;/dev/md0&amp;quot;&lt;br /&gt;
diskdev=&amp;quot;/dev/sda&amp;quot;&lt;br /&gt;
mdadm $mddev --fail $diskdev --remove $diskdev --re-add $diskdev --update=no-bbl&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If there&#039;s a BBL on the drive already, replace the --update part to &#039;force-no-bbl&#039;. This is not documented anywhere as per se, but it works.&lt;br /&gt;
 &lt;br /&gt;
I haven&#039;t found a way to turn this off permanently, but there may be something coming around when the debate on the linux-raid mailing list closes up on this. There&#039;s a bbl=no in mdadm.conf, but that&#039;s only for creation. I will continue extensive testing for this.&lt;br /&gt;
&lt;br /&gt;
== Tuning ==&lt;br /&gt;
&lt;br /&gt;
While trying to compare a 12-disk RAID (8TB disks) to a hwraid, mdraid was slower, so we did a few things to speed things up:&lt;br /&gt;
&lt;br /&gt;
While testing with [https://linux.die.net/man/1/fio fio], monitor /sys/block/md0/md/stripe_cache_active, and see if it&#039;s close to /sys/block/md0/md/stripe_cache_size. If it is, double the size of the latter&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
echo 4096 &amp;gt; /sys/block/md0/md/stripe_cache_size&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Continue until stripe_cache_active stabilises, and then you&#039;ve found the limit you&#039;ll need. You may want to double that for good measure. &lt;br /&gt;
&lt;br /&gt;
(to be continued)&lt;br /&gt;
&lt;br /&gt;
== Links ==&lt;br /&gt;
&lt;br /&gt;
Below are a few links with useful info&lt;br /&gt;
&lt;br /&gt;
* [https://raid.wiki.kernel.org/index.php/Irreversible_mdadm_failure_recovery Irreversible mdadm failure recovery]&lt;br /&gt;
&lt;br /&gt;
= ZFS =&lt;br /&gt;
&lt;br /&gt;
ZFS can do a lot of things most filesystems or volume managers can&#039;t. It checksums all data and metadata and so long that the system uses ECC enabled memory (RAM), it will have complete control over the whole data set, and when (not if) an error occurs, it&#039;ll fix the issue without even throwing a warning. To fix the issue, you&#039;ll obviously need sufficient redundancy (mirrors or RAIDzN). &lt;br /&gt;
&lt;br /&gt;
== ZFS send/receive between machines ==&lt;br /&gt;
&lt;br /&gt;
ZFS has a send/receive mechanism that allows for snapshots to be sent over the wire to a receiving end. This can be a full filesystem, or an incremental change since last send/reveive. In a WAN scenario, you&#039;ll probably want to use VPN for this. On a controlled network, sending in cleartext is also possible. You may as well use ssh, but keep in mind that ssh was never designed to be used as a fullblown vpn solution and is just too slow or the task with large amounts of data. You may, though, use mbuffer, if on a loal LAN.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Allow traffic from the sending IP in whatever firewall interface you&#039;re using (if you&#039;re using a firewall at all, that is)&lt;br /&gt;
ufw allow from x.x.x.x&lt;br /&gt;
# &lt;br /&gt;
# Start the receiver first. This listens on port 9090, has a 1GB buffer,&lt;br /&gt;
    and uses 128kb chunks (same as zfs):&lt;br /&gt;
&lt;br /&gt;
mbuffer -s 128k -m 1G -I 9090 | zfs receive data/filesystem&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To be continued one day… See [https://everycity.co.uk/alasdair/2010/07/using-mbuffer-to-speed-up-slow-zfs-send-zfs-receive/ this] for some more. I&#039;ll get back with details on it.&lt;br /&gt;
&lt;br /&gt;
= General Linux system control =&lt;br /&gt;
&lt;br /&gt;
== Add a new CPU (core) ==&lt;br /&gt;
&lt;br /&gt;
If working with virtual machines, adding a new core can be useful if the VM is slow and the load is multithreaded or multiprocess. To do this, add a new CPU in the hypervisor (be it KVM or VMware or Hyper-V or whatever). Some hypervisors, like VMware, will activate it automatically if open-vm-tools is installed. Please note that open-vm-tools is for VMware only. I don&#039;t know of any such thing for KVM or other hypervisors (although I beleive VirtualBox has its own set of tools, but not as a package). If this doesn&#039;t work, run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
echo 1 &amp;gt; /sys/devices/system/cpu/cpuX/online&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where X is the CPU number you want to add. You can &#039;cat /sys/devices/system/cpu/cpuX/online&#039; to check if it&#039;s online.&lt;br /&gt;
&lt;br /&gt;
= Mount partitions on a disk image =&lt;br /&gt;
&lt;br /&gt;
Sometimes you&#039;ll have a disk image, either from recovering a bad drive after hours (or days or weeks) of ddrescue, and sometimes you just have a disk image from a virtual machine where you want to mount the partitions inside the image. There are three main methods of doing this, which are more or less synonmous, but some easier than the other.&lt;br /&gt;
&lt;br /&gt;
== Basics ==&lt;br /&gt;
&lt;br /&gt;
A disk image is usually like a disk, consisting of either a large filesystem, a PV or a partition table with one or partitions onto which resides a filesystem, a pv, swap or something else. If it&#039;s partitioned, and you want your operating system to mount a filesystem or allow it to see whatever LVM stuff lies on it, you need to isolate the partitions. &lt;br /&gt;
&lt;br /&gt;
== Manual mapping ==&lt;br /&gt;
&lt;br /&gt;
In the oldern days, this was done manually, something like this&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
root@mymachine:~# fdisk -l /dev/vda&lt;br /&gt;
Disk /dev/vda: 25 GiB, 26843545600 bytes, 52428800 sectors&lt;br /&gt;
Units: sectors of 1 * 512 = 512 bytes&lt;br /&gt;
Sector size (logical/physical): 512 bytes / 512 bytes&lt;br /&gt;
I/O size (minimum/optimal): 512 bytes / 512 bytes&lt;br /&gt;
Disklabel type: dos&lt;br /&gt;
Disk identifier: 0xc37b7ea5&lt;br /&gt;
&lt;br /&gt;
Device     Boot    Start      End  Sectors  Size Id Type&lt;br /&gt;
/dev/vda1  *        2048 50333311 50331264   24G 83 Linux&lt;br /&gt;
/dev/vda2       50333312 52426369  2093058 1022M  5 Extended&lt;br /&gt;
/dev/vda5       50333314 52426369  2093056 1022M 82 Linux swap / Solaris&lt;br /&gt;
root@mymachine:~#&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To calculate the start and end of each partition, you just take the start sector and multiply it by the sector size (512 bytes here) and you have the offset in bytes. After this, it&#039;s merely an losetup -o &amp;lt;offset&amp;gt; /dev/loopX &amp;lt;nameofimagefile&amp;gt; and you have the partition mapped to your /dev/loopX (having X being something typically 0-255. After this, just mount it or run pvscan/vgscan/lvscan to probe whatever lvm config is there, and you should be able to mount it like any other filesystem.&lt;br /&gt;
&lt;br /&gt;
== kpartx ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;kpartx&#039;&#039;&#039; does the same as above, more or less, just without so much hassle. Most of it should be automatic and easy to deal with, except it may fail to disconnect the loopback devices sometimes, so you may have to &#039;&#039;&#039;losetup -d&#039;&#039;&#039; them manually. See the manual, &#039;&#039;&#039;kpartx (8)&#039;&#039;&#039;. Please note that &#039;&#039;&#039;partx&#039;&#039;&#039; works similarly and I&#039;d guess the authors of the two tools are arguing a lot of which one&#039;s the best.&lt;br /&gt;
&lt;br /&gt;
== guestmount ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;guestmount&#039;&#039;&#039; is something similar again, but also supports file formats like &#039;&#039;&#039;qcow2&#039;&#039;&#039; and possibly other, proprietary filesystems like &#039;&#039;&#039;vmdk&#039;&#039;&#039; and &#039;&#039;&#039;vdi&#039;&#039;&#039;, but don&#039;t take my word for it - I haven&#039;t tested. Again, see the manual or just read up on the description [http://ask.xmodulo.com/mount-qcow2-disk-image-linux.html?fbclid=IwAR3snTeZvGzp9PLdX11EQhCfOpux6I93CiJ3A2pUomkkRLly9Xo4851mkTY here]. It seems rather trivial.&lt;br /&gt;
&lt;br /&gt;
= Linux on laptops =&lt;br /&gt;
&lt;br /&gt;
== Wifi with HP EliteBook 725/745 on Ubuntu ==&lt;br /&gt;
&lt;br /&gt;
The HP EliteBook 725/745 and similar are equipped with a BCM4352 wifi chip. As with a lot of other stuff from Broadcom, this lacks an open hardware description, so thus no open driver exist. The proper fix, is to replace the NIC with something with an open driver, but again, this isn&#039;t always possible, so a binary driver exists. In ubuntu, run, somehow connect the machine to the internet and run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install bcmwl-kernel-source&lt;br /&gt;
sudo modprobe wl&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you can&#039;t connect the machine to the internet, download the needed packages on another machine and put it on some usb storage. These packages should suffice:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# apt-cache depends bcmwl-kernel-source&lt;br /&gt;
bcmwl-kernel-source&lt;br /&gt;
  Depends: dkms&lt;br /&gt;
  Depends: linux-libc-dev&lt;br /&gt;
  Depends: libc6-dev&lt;br /&gt;
  Conflicts: &amp;lt;bcmwl-modaliases&amp;gt;&lt;br /&gt;
  Replaces: &amp;lt;bcmwl-modaliases&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then install manually with &#039;&#039;&#039;dpkg -i file1.deb file2.deb&#039;&#039;&#039; etc&lt;br /&gt;
&lt;br /&gt;
After this, ip/ifconfig/iwconfig shouldd see the new wifi nic, probably &#039;&#039;&#039;wlan0&#039;&#039;&#039;, but due to a [https://bugs.launchpad.net/ubuntu/+source/broadcom-sta/+bug/1343151 old, ignored bug], you won&#039;t find any wifi networks. This is because the driver from Broadcom apparently does not support interrupt remapping, commonly used on x64 machines. To turn this off, change &#039;&#039;&#039;/etc/default/grub&#039;&#039;&#039; and change the line &#039;&#039;&#039;GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;quiet splash&amp;quot;&#039;&#039;&#039;, adding intremap=off to the end before the quote: &#039;&#039;&#039;GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;quiet splash intremap=off&amp;quot;&#039;&#039;&#039;. Save the file and run &#039;&#039;&#039;sudo update-grub&#039;&#039;&#039; and reboot. After this, wifi should work well.&lt;br /&gt;
&lt;br /&gt;
== Wifi with HP Compaq Presario CQ57 on Ubuntu ==&lt;br /&gt;
&lt;br /&gt;
The HP Compaq Presario CQ57 uses the RT5390 wifi chipset. This has been supported for quite some time now, and I was quite surprised to find it not working on a laptop a friend was having. The driver loaded correctly, but Ubuntu insisted of the laptop being in &#039;&#039;&#039;flight mode&#039;&#039;&#039;. Checking &#039;&#039;&#039;rfkill&#039;&#039;&#039;, it showed me two NICs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# rfkill list all&lt;br /&gt;
0: phy0: Wireless LAN&lt;br /&gt;
	Soft blocked: no&lt;br /&gt;
	Hard blocked: yes&lt;br /&gt;
1: hp-wifi: Wireless LAN&lt;br /&gt;
	Soft blocked: yes&lt;br /&gt;
	Hard blocked: no&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Turning rfkill on and off resulted in nothing much, except some error messages in the kernel log (dmesg)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] ACPI Error: Field [B128] at bit offset/length 128/1024 exceeds size of target Buffer (160 bits) (20170831/dsopcode-235)&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]&lt;br /&gt;
                            Initialized Local Variables for Method [HWCD]:&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Local0: 00000000a34b7928 &amp;lt;Obj&amp;gt;           Integer 0000000000000000&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Local1: 00000000b0aa6865 &amp;lt;Obj&amp;gt;           Buffer(8) 46 41 49 4C 04 00 00 00&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Local5: 00000000a9811efd &amp;lt;Obj&amp;gt;           Integer 0000000000000004&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] Initialized Arguments for Method [HWCD]:  (2 arguments defined for method invocation)&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Arg0:   0000000078957d1b &amp;lt;Obj&amp;gt;           Integer 0000000000000001&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Arg1:   00000000725c9c6e &amp;lt;Obj&amp;gt;           Buffer(20) 53 45 43 55 02 00 00 00&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] ACPI Error: Method parse/execution failed \_SB.WMID.HWCD, AE_AML_BUFFER_LIMIT (20170831/psparse-550)&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] ACPI Error: Method parse/execution failed \_SB.WMID.WMAD, AE_AML_BUFFER_LIMIT (20170831/psparse-550)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After upgrading BIOS and testing different kernels, I was asked to try to unload the &#039;&#039;&#039;hp_wmi&#039;&#039;&#039; driver. I did, and things changed a bit, so I tried blacklisting it, creating the file &#039;&#039;&#039;/etc/modprobe.d/blacklist-hp_wmi.conf&#039;&#039;&#039; with the following content&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Blacklist this - it doesn&#039;t work!&lt;br /&gt;
blacklist hp_wmi&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
I gave the machine a reboot and afte that, the &#039;&#039;&#039;hp-wifi&#039;&#039;&#039; entry was gone in the rfkill output, and things works.&lt;br /&gt;
&lt;br /&gt;
= Raspberry pi =&lt;br /&gt;
&lt;br /&gt;
I couldn&#039;t quite decide if the raspberry pi should be a separate section or part of Linux, but hell, it can run more than Linux, although 99,lots% of people just uses Linux on them. This is a small list of things to know about them; things not on the front page of the manual or perhaps hidden even better.&lt;br /&gt;
&lt;br /&gt;
== Which pi? ==&lt;br /&gt;
&lt;br /&gt;
I just setup three raspberry pi machines and although some are quite different, like v1 to vEverythingelse or the Pi zero versions to the normal ones, not all of us remember how to distinguish between them, and sometimes they&#039;re in a nice 3d printed (or otherwise) chassis or otherwise hidden. So, how to check three different ones:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
root@home-assistant:~ $ cat /proc/device-tree/model ; echo&lt;br /&gt;
Raspberry Pi 2 Model B Rev 1.1&lt;br /&gt;
&lt;br /&gt;
root@green-pi:~ $ cat /proc/device-tree/model ; echo&lt;br /&gt;
Raspberry Pi 3 Model B Rev 1.2&lt;br /&gt;
&lt;br /&gt;
roy@yellow-pi:~ $cat /proc/device-tree/model ; echo&lt;br /&gt;
Raspberry Pi 4 Model B Rev 1.1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
While this works well, for the latter, the pi4, it doesn&#039;t tell how much memory I have. It comes in variants of 1, 2 and 4GB, and this is the latter.&lt;br /&gt;
&lt;br /&gt;
For a more detailed list, the command &#039;&#039;&#039;awk &#039;/^Revision/ {sub(&amp;quot;^1000&amp;quot;, &amp;quot;&amp;quot;, $3); print $3}&#039; /proc/cpuinfo&#039;&#039;&#039; will give you a revision number, detailing the type of pi, who produced it etc. Please see [https://elinux.org/RPi_HardwareHistory https://elinux.org/RPi_HardwareHistory] for a full table.&lt;br /&gt;
&lt;br /&gt;
== Monitoring ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;vcgencmd&#039;&#039;&#039; from &#039;&#039;&#039;/opt/vc/bin&#039;&#039;&#039;, but symlinked to &#039;&#039;&#039;/usr/bin&#039;&#039;&#039; so it&#039;s available in path, is useful for fetching hardware info about the pi. For example, measuring the temperature&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
root@yellow-pi:~# vcgencmd measure_temp&lt;br /&gt;
temp=63.0&#039;C&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The command is generally badly documented and parts of it seems outdated for newer hardware. Here&#039;s the output from a Raspberry pi 4 with 4GB RAM&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
roy@yellow-pi:~ $ vcgencmd get_mem arm&lt;br /&gt;
arm=948M&lt;br /&gt;
roy@yellow-pi:~ $ vcgencmd get_mem gpu&lt;br /&gt;
gpu=76M&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= BIOS upgrade from Linux =&lt;br /&gt;
&lt;br /&gt;
Generally, BIOS upgrades have been moved to the BIOS itself these days. This saves a lot of work and quite possibly lives after those who earier rammed their heads through walls, now can upgrade directly from the internet instead of using obscure operating systems best avoided. Sometimes, however, one must use these nevertheless. This is a quick run-through on your options.&lt;br /&gt;
&lt;br /&gt;
== DOS ==&lt;br /&gt;
&lt;br /&gt;
Most non-automatic BIOS upgrades are installed from DOS. Doing a BIOS upgrade this way, is generally non-problematic. Just install a USB thingie with [https://www.freedos.org/ FreeDOS], copy your file(s) onto the thing and boot on it. The commandline is the same as old MS/DOS, except a wee bit more userfriendly, but not a lot.&lt;br /&gt;
&lt;br /&gt;
== Windows ==&lt;br /&gt;
&lt;br /&gt;
Some macahines, like laptops from &#039;&#039;&#039;HP&#039;&#039;&#039;, may have BIOS upgrades that are made to be installed from Windows and won&#039;t run in FreeDOS or MS/DOS, instead throwing an error, saying &#039;&#039;&#039;This program cannot be run in DOS mode&#039;&#039;&#039;. This means you&#039;ll have to boot on a Windows rescue disc and do the job from there. Googling this, tells you it&#039;s quite easy, you just choose &#039;make rescue disc&#039; from Windows, and it&#039;s all good, except if you don&#039;t run Windows, that is. To remedy this problem, do as follows:&lt;br /&gt;
&lt;br /&gt;
=== Download Windows ===&lt;br /&gt;
&lt;br /&gt;
Since you don&#039;t run Windows and possibly don&#039;t have a spouse or friend around with such unhealthy habits either, you need to get it. It&#039;s quite easy - just google &#039;download windows&#039; and it&#039;ll send you to [https://www.microsoft.com/en-us/software-download/windows10ISO somewhere like this].&lt;br /&gt;
&lt;br /&gt;
=== Burn it! ===&lt;br /&gt;
&lt;br /&gt;
Now it&#039;s time to burn the installer on a DVD ROM. You&#039;ll need a double-layered one, since the OS is &amp;gt; 4.7GiB, but I&#039;m sure you have a ton of those lying around. Now, just place your optical medium in your optical drive and burn, baby, burn!&lt;br /&gt;
&lt;br /&gt;
=== Or make a USB thing? ===&lt;br /&gt;
&lt;br /&gt;
Not a lot of machines have optical drives these days, so you may want to use an USB pen drive or something instead. This is easy, just make the USB bootable with the Windows application Microsoft has made for this. Unfortunately, this only runs on Windows, and unlike stuff like Debian, where the &#039;&#039;&#039;iso&#039;&#039;&#039; file can be dd&#039;ed directly onto a USB drive to make it bootable, the Windows &#039;&#039;&#039;iso&#039;&#039;&#039;s don&#039;t come with this luxury. There are lots of methods to make bootable USB things from iso files out there, but the only thing most of them have in common, is that they generally don&#039;t work.&lt;br /&gt;
&lt;br /&gt;
==== WoeUSB ====&lt;br /&gt;
&lt;br /&gt;
After hours of swearing, it&#039;s nice to come across software like [https://github.com/slacka/WoeUSB WoeUSB]. It may not be perfect, it relies on a bunch of GUI stuff you&#039;ll never need and so on, but it &#039;&#039;&#039;&#039;&#039;works&#039;&#039;&#039;&#039;&#039;, and that&#039;s the important part! Just clone the repo and RTFM and it&#039;s all nice. It&#039;s slow, but hell, getting a windows machine and/or an optical drive might be slower.&lt;br /&gt;
&lt;br /&gt;
WoeUSB does nothing fancy, but it &#039;&#039;&#039;does&#039;&#039;&#039; work. It will create a filesystem, FAT32 or NTFS (better use NTFS, FAT32 has its limits). It creates normal filesystems and so on. Just make sure to copy in the BIOS update file, usually an exe file, to run when Windows is up and running.&lt;br /&gt;
&lt;br /&gt;
==== Install BIOS ====&lt;br /&gt;
&lt;br /&gt;
Boot on the Windows USB thing and choose &#039;repair computer&#039; and then &#039;command prompt&#039;. Find the install file, and if you&#039;re lucky, you&#039;ll find it needs a 32bit OS, just like I did. Since the 64bit version doesn&#039;t include 32bit compatibility in the installer, revert to downloading the 32bit version of windows and start over. Pray to your favourite god(s) not to get across such machines again - it might help.&lt;br /&gt;
&lt;br /&gt;
= 3D printer stuff =&lt;br /&gt;
&lt;br /&gt;
Below are a number of not very ordered paragraphs about 3D printer related stuff, mostly based on my experience. Their content may be interesting or perhaps practical knowledge, but then, that depends on the reader.&lt;br /&gt;
&lt;br /&gt;
== 3D printer related introductions on youtube or elsewhere ==&lt;br /&gt;
&lt;br /&gt;
First off, I&#039;d like to mention some youtube videos that are all (or mostly) a nice start if you&#039;re new to 3D printers.&lt;br /&gt;
&lt;br /&gt;
=== [https://www.youtube.com/watch?v=nb-Bzf4nQdE&amp;amp;list=PLDJMid0lOOYnkcFhz6rfQ6Uj8x7meNJJx Thomas Salanderer&#039;s 10-video series on 3D printing basics] ===&lt;br /&gt;
&lt;br /&gt;
Thomas Salanderer is a an experienced 3D printer user/admin/fixer/etc and he has a lot of interesting videos. Some accuse him for being a [Prusa https://www.prusa3d.com/] fanboy, which he quite obviously is, but that doesn&#039;t stop him from making interesting and somewhat neutral videos. The series walks you thought the first steps of how things work and so on and hopefully opens more doors than anything else I&#039;ve seen.&lt;br /&gt;
&lt;br /&gt;
=== [https://www.youtube.com/watch?v=rp3r921DBGI Teaching Tech&#039;s &amp;quot;3D printer tuning reborn&amp;quot;] ===&lt;br /&gt;
&lt;br /&gt;
Teaching Tech is, like Salanderer or even more, good pedagogically and explains a lot. They (or he) do a bunch of testing and describing pros and cons with different things, just like other youtubers in the sme business. The mentioned video shows how to tune a 3D printer after you have first learned the basics, and leans on a webpage made to help you out without too much manual work.&lt;br /&gt;
&lt;br /&gt;
This was a short list, but I guess it&#039;ll grow over time.&lt;br /&gt;
&lt;br /&gt;
== Hydrophilic filament ==&lt;br /&gt;
&lt;br /&gt;
Most popular filament types, including PLA, PETG, PP or PA (Polyamide, normally known as Nylon) and virtualy any filament type named [https://www.matterhackers.com/news/filament-and-water poly-something] (and thus with an acronym of P-something) are hydrophilic (also (somewhat incorrectly) called hydroscopic), meaning so long they&#039;re dryer than the atmosphere around them, they&#039;ll do their best to suck out the atmosphere&#039;s humidity. This is why most filament are shrink-wrapped with a small bag of silica gel in it. If such filament is exposed for normal humid air for some time, it&#039;ll become very hard to use. Most of my experience is with PLA, which can handle a bit (depending on make), but still not a lot. With PLA, if you end up with prints where the filament seems not to stick, it may help with a higher temperature. Otherwise, the filament must be [https://all3dp.com/2/how-to-dry-filament-pla-abs-and-nylon/ baked]. If you don&#039;t want to use your oven, try something like a [https://www.jula.no/catalog/hjem-og-husholdning/kjokkenmaskiner/mattilberedningsapparater/frukt-sopptorker/frukt-sopptorker-001641/#tab02 fruit and mushroom dryer]. Then get a good, sealble plastic box and add something like half a kilogram of [https://www.ebay.com/sch/sis.html?_nkw=1KG+Orange+Replacement+Desiccant+Indicating+Silica+Gel+Beads+for+Drawers%2C+Camera&amp;amp;_id=131938742628&amp;amp;&amp;amp;_trksid=p2057872.m2749.l2658 silica gel] to an old sock, tie it and put it in the your new dry box.&lt;br /&gt;
&lt;br /&gt;
Please note that ABS is hydrophobic, so you won&#039;t have to worry too much there. Also, remember that PA/Nylon is extremely hydrophilic. Even a couple of days in normal air humidity can ruin it completely and will require baking.&lt;br /&gt;
&lt;br /&gt;
== Upgrading the firmware on an Ender 3 ==&lt;br /&gt;
&lt;br /&gt;
This is about upgrading the firmware, and thus also flashing a bootloader to the Creality Ender 3 3D printer. Most of this is well documented on several place, like o [https://www.youtube.com/watch?v=fIl5X2ffdyo the video from Teaching tech] and elsewhere, but I&#039;ll just summarise some issues I had.&lt;br /&gt;
&lt;br /&gt;
=== Using an arduino Nano as a programmer ===&lt;br /&gt;
&lt;br /&gt;
Quick note before you read on. If you have an Ender 3 controller version 1.1.5 or newer (or perhaps even a bit older), a CR-10S or some other more or less modern printers or controllers, they come with a bootloader installed already, so don&#039;t bother flashing one. The one that&#039;s in there already, should work well. So if you have one of these, just skip this and jump to the [[Roy&#039;s_notes#Flashing_the_printer|next section]].&lt;br /&gt;
&lt;br /&gt;
However, the normal CR-10 (without the S), Ender 3 and a few other printers from Creality come without a bootloader, so you&#039;ll need to flash one before upgrading the firmware. Well, strictly speakning, you don&#039;t need one, you can save those 8kB or so for other stuff and use a programmer to write the whole firmware, but then you&#039;ll need to wire up everything every time you want a new firmware, so in my world, you &#039;&#039;&#039;do&#039;&#039;&#039; need the bootloader, since it&#039;s easier.&lt;br /&gt;
&lt;br /&gt;
To install a bootloader, you&#039;ll need a programmer, and I didn&#039;t have one available. Having some el-cheapo china-copies of Arduinos around, I read I could use one and tried so. Although the docs mostly mention the Uno etc, it&#039;s just as simple with the Nano copy.&lt;br /&gt;
&lt;br /&gt;
So, grab an arduino, plug it to your machine with a USB cable, and, using the Arduino IDE, use the ArduinoISP sketch there (found under Examples) to burn the software needed for the arduino to work as a programmer. When this is done, connect a 10µF capacitor between RST and GND to stop it from resetting when used as a programmer. Connect the MOSI, MISO and SCK pins from the ICSP block (that little isolated 6-pin block on top of the ardu). See [https://www.arduino.cc/en/Tutorial/ArduinoISP here] for a pinout. Then find Vcc and GND either on the ICSP block or elsewhere. Some sites say that on some boards you shouldn&#039;t use the pins on the ICSP block for this. I doubt it matters, though. Then connect another jumper wire from pin 10 on the ardu to work as the reset pin outwards to the chip being programmed (that is, on the printer). The ICSP jumper block pin layout is the same on the printer and on the ardu, and probably elsewhere. Sometimes [https://xkcd.com/927/ standardisation] actually works…&lt;br /&gt;
&lt;br /&gt;
When it&#039;s all wired up, change the setup in the Arduino IDE to use the Sanguino board (which may need to be installed there), the Atmega 1284 16MHz board with the programmer set to     &amp;quot;Arduino as ISP&amp;quot;. Also make sure to choose the right serial port. When all is done, choose Tools | Burn programmer and it should take a few seconds to finish.&lt;br /&gt;
&lt;br /&gt;
[[File:Ardu-nano-as-programmer.jpg|400px]]&lt;br /&gt;
&lt;br /&gt;
== Flashing the printer ==&lt;br /&gt;
&lt;br /&gt;
When the boot loader is in place, possibly after some wierd errors from during the process, the screen on the 3d printer will go blank and it&#039;ll behave like being bricked. This is ok. Now disconnect the wires and connect the USB cable between computer and printer. If you haven&#039;t installed support for the Sanguino board, that is, the variant of the 1284-chip and surrounding electronics that is the core of the, you need to install it first. In the Arduino IDE, choose the Tools / Boards / Boards manager boot option and search for Sanguino. After this, you should find the Sanguino or Sanguino 1284p in the boards menu. After this, you should be able to communicate with the printer&#039;s controller. Download the [https://www.th3dstudio.com/knowledgebase/th3d-unified-firmware-package/ TH3D unified firmware], making sure it&#039;s the last version. Uncompress the zip and with Finder/Explorer/whateversomething&#039;scalledonlinux, browse to &#039;&#039;&#039;TH3DUF_R2/Firmware/TH3DUF_R2.ino&#039;&#039;&#039; and open it. It should open directly in the Android IDE. Keep in mind that the names TH3DUF_R2 and TH3DUF_R2.ino will vary between versions, but you get the point. Now configure it for your particular needs. You&#039;ll find most of this in the Configuration.h tab (that&#039;s really a file). Most of the other files won&#039;t be necessary unless you&#039;re doing some more advanced stuff, like replacing th controller with something non-standard or similar, but then again, that&#039;s another chapter (or book, even). The video mentioned above describes this well. After flashing the new firmware, you&#039;ll probably get some timeouts and errors, since apparently it resets the printer after giving it the new firmware, but without notifying the flashing software of it doing so. If this happens, calm down and reboot the printer and check its tiny monitor - it should work. If it doesn&#039;t work, and if you flashed the bootload yourself, try to flash it again, and if that doesn&#039;t work, try flashing the programmer again yet another time, just for kicks. Again, if you have a newer controller like the v1.1.5, don&#039;t touch the bootloader, as the one already installed, should work well as it is.&lt;br /&gt;
&lt;br /&gt;
PS: I tried enabling &#039;&#039;&#039;MANUAL_MESH_LEVELING&#039;&#039;&#039;, which in the code says that &#039;&#039;If used with a 1284P board the bootscreen will be disabled to save space&#039;&#039;. This effectively disabled the whole printer, and apparently may be making the firmware image a wee bit too large for it to fit the 1284P on the ender. It works well without it, though, and it may be fixed by now, since I tested this back in early 2019.&lt;br /&gt;
&lt;br /&gt;
== And then… ==&lt;br /&gt;
&lt;br /&gt;
With the new firmware in place, the printer should work as before, although with thermal runaway protection to better avoid fires in case the shit hits the fan, and to allow for things like autolevelling. With any luck, [https://www.precisionpiezo.co.uk/ this thing] may be ready for use by the time you read this - it surely looks nice!&lt;br /&gt;
&lt;br /&gt;
= Octoprint/Octopi =&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;This could have been under some other section, but again, I just branch out even though most of it is about sections mentioned elsewhere.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
When setting up a 3d printer for the first time, you usually get an SD card for storage and transfer data to the printer using [https://en.wikipedia.org/wiki/Sneakernet Sneakernet]. Some printers use micro SD cards, while other fullsize SD cards, which imho is better, since they don&#039;t get lost that easily, but otherwise do the same thing. This works, but is somewhat tedious. If you want to control the printer from a PC or phone, there&#039;s a simple trick for that as well - octoprint.&lt;br /&gt;
&lt;br /&gt;
[https://octoprint.org/ Octoprint], written by Gina Häußge, runs on most platforms including linux, windows, BSD*, macos etc. It supports controlling a camera to some extent out of the box and there&#039;s a large number of plugins availablee to do a lot of things you possibly haven&#039;t thought of (and quite often, you&#039;d ever need). The easiest way to install it, is to just grab a Raspberry pi - preferably some of the newer models (will get to that later) and download [https://octoprint.org/download/ octopi] and follow the instructions on that page.&lt;br /&gt;
&lt;br /&gt;
== Performance issues ==&lt;br /&gt;
&lt;br /&gt;
Some report (and I have seen it myself) issues with the pi&#039;s performance with regards to both handling the octoprint processes (which should be as close to realtime as possible) and handling other stuff like I/O, networking etc. The point is that at pi3 or older, has all peripherals connected to an internal USB hub. This might be practical, but performance-wise it&#039;s &#039;&#039;&#039;&#039;&#039;not&#039;&#039;&#039;&#039;&#039;. If you in addition connect a webcam to USB, you&#039;re asking for trouble, since USB will be your bottleneck. With a raspberry pi camera, the ones connected to the pi directly with a ribbon cable, this should not use USB, so it&#039;s better. Still, again, for older pi&#039;s, there might be some shortage in therms of cpu or i/o. The octopi runs something like raspbian which is a fork of debian which is a linux distro, so it all boils down to knowing linux.&lt;br /&gt;
&lt;br /&gt;
Your typical octopi will run octoprint, a streamer, usually &#039;&#039;&#039;mjpg-streamer&#039;&#039;&#039;, a simple, lightweight videostreamer that outputs a stream of jpeg-images (about the same format as cinemas use - that is - not MPEG). This may be a bit tough on the cpu and potentially i/o. Add inn a dash of USB overload and you&#039;re may see trouble.&lt;br /&gt;
&lt;br /&gt;
Still - a pi3 should be able to handle the load, but it might help to prioritise corretly. The octoprint process is the important part here, so we could give that full priority both in CPU and I/O and. Unfortunately, it doesn&#039;t seem like the current octopi has been migrated to using systemd for the startup. We&#039;ll deal with this later. To fix this in the old SysV init style file present there, the following patch should work against the file /etc/init.d/octoprint&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;diff&amp;quot;&amp;gt;&lt;br /&gt;
--- octoprint.old	2020-07-20 18:46:10.166651965 +0200&lt;br /&gt;
+++ octoprint	2020-07-20 18:53:21.724803211 +0200&lt;br /&gt;
@@ -22,6 +22,9 @@&lt;br /&gt;
 PIDFILE=/var/run/$NAME.pid&lt;br /&gt;
 PKGNAME=octoprint&lt;br /&gt;
 SCRIPTNAME=/etc/init.d/$PKGNAME&lt;br /&gt;
+NICELEVEL=-19                        # Top CPU priority&lt;br /&gt;
+IONICE_CLASS=1                       # Realtime I/O class&lt;br /&gt;
+IONICE_PRIORITY=0                    # Realtime I/O priority (probably not needed with class=realtime)&lt;br /&gt;
&lt;br /&gt;
 # Read configuration variable file if it is present&lt;br /&gt;
 [ -r /etc/default/$PKGNAME ] &amp;amp;&amp;amp; . /etc/default/$PKGNAME&lt;br /&gt;
@@ -70,10 +73,11 @@&lt;br /&gt;
&lt;br /&gt;
    is_alive $PIDFILE&lt;br /&gt;
    RETVAL=&amp;quot;$?&amp;quot;&lt;br /&gt;
-&lt;br /&gt;
    if [ $RETVAL != 0 ]; then&lt;br /&gt;
        start-stop-daemon --start --background --quiet --pidfile $PIDFILE --make-pidfile \&lt;br /&gt;
-       --exec $DAEMON --chuid $OCTOPRINT_USER --user $OCTOPRINT_USER --umask $UMASK -- serve $DAEMON_ARGS&lt;br /&gt;
+       --exec $DAEMON --chuid $OCTOPRINT_USER --user $OCTOPRINT_USER --umask $UMASK \&lt;br /&gt;
+       --nicelevel $NICELEVEL --ioched $IONICE_CLASS:$IONICE_PRIORITY \&lt;br /&gt;
+       --serve $DAEMON_ARGS&lt;br /&gt;
        RETVAL=&amp;quot;$?&amp;quot;&lt;br /&gt;
    fi&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This ismply upgrades the process to be allowed to use most of the resources on the pi, regardless of what other processes are whining about.&lt;br /&gt;
&lt;br /&gt;
PS: Code not tested - I don&#039;t have a pi right here. Will test later, but I&#039;m pretty sure it&#039;ll work. After all, it&#039;s just a few new arguments to start-stop-daemon&lt;br /&gt;
&lt;br /&gt;
roy&lt;/div&gt;</summary>
		<author><name>Roy</name></author>
	</entry>
	<entry>
		<id>https://wiki.malinux.no/index.php?title=Roy%27s_notes&amp;diff=186</id>
		<title>Roy&#039;s notes</title>
		<link rel="alternate" type="text/html" href="https://wiki.malinux.no/index.php?title=Roy%27s_notes&amp;diff=186"/>
		<updated>2020-11-14T23:14:37Z</updated>

		<summary type="html">&lt;p&gt;Roy: /* Using an arduino Nano as a programmer */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= LVM, md and friends =&lt;br /&gt;
&lt;br /&gt;
== Linux&#039; Logical Volume Manager (LVM) ==&lt;br /&gt;
&lt;br /&gt;
=== LVM in general ===&lt;br /&gt;
&lt;br /&gt;
LVM is designed to be an abstraction layer on top of physical drives or RAID, typically [https://raid.wiki.kernel.org/index.php/RAID_setup mdraid] or [https://help.ubuntu.com/community/FakeRaidHowto fakeraid]. Keep in mind that fakeraid should be avoided unless you really need it, like in conjunction with dual-booting linux and windows on fakeraid. LVM broadly consists of three elements, the &amp;quot;physical&amp;quot; devices (PV), the volume group (VG) and the logical volume (LV). There can be multiple PVs, VGs and LVs, depending on requirement. More about this below. All commands are given as examples, and all of them can be fine-tuned using extra flags in need of so. In my experience, the defaults work well for most usecases.&lt;br /&gt;
&lt;br /&gt;
I&#039;m mentioning filesystem below too. Where I write ext4, the samme applies to ext2 and ext3.&lt;br /&gt;
&lt;br /&gt;
==== Create a PV ====&lt;br /&gt;
&lt;br /&gt;
A PV is the &amp;quot;physical&amp;quot; parts. This does not need to be a physical disk, but can also be another RAID, be it an mdraid, fakeraid, hardware raid, a virtual disk on a SAN or otherwisee or a partition on one of those. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#  These add three PVs, one on a drive (or hardware raid) and another two on mdraids.&lt;br /&gt;
pvcreate /dev/sdb&lt;br /&gt;
pvcreate /dev/md1 /dev/md2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For more information about pvcreate, see [https://linux.die.net/man/8/pvcreate the manual].&lt;br /&gt;
&lt;br /&gt;
==== Create a VG ====&lt;br /&gt;
&lt;br /&gt;
The volume group consists of one or more PVs grouped together on which LVs can be placed. If several PVs are grouped in a VG, it&#039;s generally a good idea to make sure these PVs have some sort of redundancy, as in mdraid/fakeraid or hwraid. Otherwise it will be like using a [https://en.wikipedia.org/wiki/RAID RAID-0] with a single point of failure on each of the independant drives. LVM has [https://unix.stackexchange.com/questions/150644/raiding-with-lvm-vs-mdraid-pros-and-cons  RAID code in it] as well, so you can use that. I haven&#039;t done so myself, as I generally stick to mraid. The reason is mdraid is, in my opinion older and more stable and has more users (meaning bugs are reported and fixed faster whenever they are found). That said, I beleive the actual RAID code used in LVM RAID are the same function calls as for mdraid, so it may not be much of a difference. I still stick with mdraid. To create a VG, run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create volume group my_vg&lt;br /&gt;
vgcreate my_vg /dev/md1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that if vgcreate is run with a PV (as /dev/md1 above) that is not defined as a PV (like above), this is done implicitly, so if you don&#039;t need any special flags to pvcreate, you can simply skip it and let vgcreate do that for you.&lt;br /&gt;
&lt;br /&gt;
==== Create an LV ====&lt;br /&gt;
&lt;br /&gt;
LVs can be compared to partitions, somehow, since they are bounderies of a fraction or all of that of a VG. The difference between them and a partition, however, is that they can be grown or shrunk easily and also moved around between PVs without downtime. This flexibility makes them superiour to partitions as your system can be changed without users noticing it. By default, an LV is alloated &amp;quot;thickly&amp;quot;, meaning all the data given to it, is allocated from the VG and thus the PV. The following makes a 100GB LV named &amp;quot;thicklv&amp;quot;. When making an LV, I usually allocate what&#039;s needed plus some more, but not everything, just to make sure it&#039;s space available for growth on any of the LVs on the VG, or new LVs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a thick provisioned LV named thicklv on the VG my_vg&lt;br /&gt;
lvcreate -n thicklv -L 100G my_vg&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After the LV is created, a filesystem can be placed on it unless it is meant to be used directly. The application for direct use include swap space, VM storage and certain database systems. Most of these will, however, work on filesystems too, although my testing has shown that on swap space, there is a significant performance gain for using dedicated storage without a filesystem. As for filesystems, most Linux users use either ext4 or xfs. Personally, I generally use XFS these days. See my notes below on filesystem choice.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a filesystem on the LV - this could have been mkfs -t ext4 or whatever filesystem you choose&lt;br /&gt;
mkfs -t xfs /dev/my_vg/thicklv&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then just edit /etc/fstab with correct data and run mount -a, and you should be all set.&lt;br /&gt;
&lt;br /&gt;
==== Create LVM cache ====&lt;br /&gt;
LVMcache is LVM&#039;s solution to caching a slowish filesystem on spinning rust with the help of much faster SSDs. For this to work, use a separate SSD or a mirror or two (just in case) an add the new disk/md dev to the same VG. In this case, we use a small mirror, md1. LVM is not able to cache to a disk or partition outside the volume group.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
vgextend data /dev/md1&lt;br /&gt;
  Physical volume &amp;quot;/dev/md1&amp;quot; successfully created.&lt;br /&gt;
  Volume group &amp;quot;data&amp;quot; successfully extended&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Thn create two LVs, one for the data (contents of files) and one for the metadata (filenames, directories, attributes etc). Typically, the metadata part won&#039;t need to be very large. 100M should usually do unless you have ekstremely many small files. I guess there are ways to calculate it, but again, 1GB should do for everyone (or was that 640k?). As for the data cache, I chose to use 40G here for a 15TB RAID. It will only cache what actively use anyway, so no need for overkill.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
lvcreate -L 1G -n _cache_meta data /dev/md1&lt;br /&gt;
lvcreate -L 100G -n _cache data /dev/md1&lt;br /&gt;
&lt;br /&gt;
# Some would want --cachemode writeback, but if paranoid, I wouldn&#039;t recommend it. Metadata or data can be easily corrupted in case of failure. Most filesystems will however recover from this these days since they use journaling. It &#039;&#039;really&#039;&#039; speeds up things.&lt;br /&gt;
lvconvert --type cache-pool --cachemode writethrough --poolmetadata data/_cache_meta data/_cache&lt;br /&gt;
lvconvert --type cache --cachepool data/_cache data/data&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
That should be it. If you benchmarked the disk before this, you should try again and you&#039;ll probably get a nice surprise. If not, well, see below how to turn this off again :)&lt;br /&gt;
&lt;br /&gt;
==== Disabling LVM cache ====&lt;br /&gt;
&lt;br /&gt;
If you want to change the cached LV, such as growing og shrinking or otherwise, you&#039;ll have to disable caching first and then re-enable it. There&#039;s no quick-and-easy fix, but you just do as you did when enabling in the first place. &lt;br /&gt;
&lt;br /&gt;
Forst, disable caching for the LV. This will do it cleanly and remove the LVs earlier created for caching the main device. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
lvconvert --uncache data/data&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, since you now have a VG with an empty PV in it, earlier used for caching, I&#039;d recommend removing this for now to avoid expanding onto that as well. Since they&#039;re in the same VG, this might happen and if you get so far as to extend the lv and the filesystem on it, and this filesystem is XFS or similar filesystems without possibilities of reducing the size, you have a wee problem. &lt;br /&gt;
&lt;br /&gt;
Just remove that PV from the VG&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
vgreduce data /dev/md1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The PV is still there, but pvs should now show it not connected to a VG&lt;br /&gt;
&lt;br /&gt;
==== Growing devices ====&lt;br /&gt;
&lt;br /&gt;
LVM objects can be grown and shrunk. If a PV resides on a RAID where a new drive has been added or otherwise grown, or on a partition or virtual disk that has been extended, the PV must be updated to reflect these changes. The following command will grow the PV to the maximum available on the underlying storage. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Resize the PV /dev/md (not the RAID, only the PV on the RAID) to its full size&lt;br /&gt;
pvresize /dev/md1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If a new PV is added, the VG can be grown to add the space on that in addition to what&#039;s there already. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Extend my_vg to include md2 and its space&lt;br /&gt;
vgextend my_vg /dev/md2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
With more space available in the VG, the LV can now be extended. Let&#039;s add another 50GB to it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Extend thicklv - add 50GB. If you know you won&#039;t need the space anywhere else, you may want to&lt;br /&gt;
# lvresize -l+100%FREE instead. Keep in mind the difference between -l (extents) and -L (bytes)&lt;br /&gt;
lvresize -L +50G my_vg/thicklv&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Growing filesystems ====&lt;br /&gt;
After the LV has grown, run &#039;&#039;xfs_growfs&#039;&#039; (xfs) or &#039;&#039;resize2fs&#039;&#039; (ext4) to make use of the new data. To grow the filesystem to all available space on ext4, run the below command.  To partly grow the filesystem or to shrink it or otherwise, please see the manuals.&lt;br /&gt;
&lt;br /&gt;
The filesystem can be mounted when this is run. If you for some reason get an &#039;&#039;&#039;access denied&#039;&#039;&#039; error when running this as root or with sudo, it&#039;s likely caused by a filesystem error. To fix this, unmount the filesystem first and run &#039;&#039;&#039;fsck -f /dev/my_vg/thicklv&#039;&#039;&#039; and remount it before retrying to extend it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
resize2fs /dev/my_vg/thicklv&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Similarly, with XFS, but note that xfs_growfs doesn&#039;t take the device name, but the filesystem&#039;s mount point. In the case of XFS, also note that the filesystem &#039;&#039;&#039;&#039;&#039;must&#039;&#039;&#039;&#039;&#039; be mounted to be grown. This, in contrast to how it was in the old days when filesystems had to be unmounted to be grown.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
xfs_growfs /my_mountpoint&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Rename system VG ====&lt;br /&gt;
&lt;br /&gt;
Some distros create VG names like those-from-a-sysadmin-with-a-well-developed-paranoia-not-to-hit-a-duplicate. Debian, for instance, uses names like &amp;quot;my-full-hostname-vg&amp;quot;. Personally, I don&#039;t like these, since if I were to move a disk or vdisk around to somewhere else, I&#039;d make sure not to add a disk named &#039;sys&#039; to an existing system. If you do, most distros will refuse to use the VGs with duplicate names, resulting in the OS not booting until either one is specified by its UUID or just one removed. As I&#039;m aware of this, I stick to the super-risky thing of all system VGs named &#039;sys&#039; and so on.&lt;br /&gt;
&lt;br /&gt;
If you do this, keep in mind that it may blow up your computer and take your girl- or boyfriend with it or even make either of them pregnant, allowing Trump to rule your life and generally make things suck. You&#039;re on your own!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Rename the VG&lt;br /&gt;
vgrename my-full-hostname-vg sys&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, in /boot/grub/grub.cfg, change the old lv path from something like &#039;/dev/mapper/debian--stretch--machine--vg-root&#039; to your new and fancy &#039;/dev/sys/root. Likewise, in /etc/fstab, change occurences of &#039;/dev/mapper/debian--stretch--machine--vg-&#039; (or similar) with &#039;/dev/sys/&#039;. Here, this was like this - the old ones commented out.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;fstab&amp;quot;&amp;gt;&lt;br /&gt;
#/dev/mapper/debian--stretch--box--vg-root      /               ext4            errors=remount-ro,discard       0       1&lt;br /&gt;
/dev/sys/root                                   /               ext4            errors=remount-ro,discard       0       1&lt;br /&gt;
# /boot was on /dev/vda1 during installation&lt;br /&gt;
UUID=myverylonguuidwithatonofgoodinfoinit       /boot           ext2            defaults                        0       2&lt;br /&gt;
#/dev/mapper/debian--stretch--box--vg-swap_1    none            swap            sw                              0       0&lt;br /&gt;
/dev/sys/swap_1                                 none            swap            sw                              0       0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Update /etc/initramfs-tools/conf.d/resume with similar data for swap.&lt;br /&gt;
&lt;br /&gt;
You might want to run &#039;update-initramfs -u -k all&#039; after this, but I&#039;m not sure if it&#039;s needed.&lt;br /&gt;
&lt;br /&gt;
Now, pray to the nearest god(s) and give it a reboot and it should (probably) work.&lt;br /&gt;
&lt;br /&gt;
After reboot, run &#039;&#039;&#039;swapoff -a&#039;&#039;&#039;, then &#039;&#039;&#039;mkswap /dev/sys/swap_1&#039;&#039;&#039; (or whatever it&#039;s called on your system) and &#039;&#039;&#039;swapon -a&#039;&#039;&#039; again. You may want to give it another reboot or two for kicks, but it should work well even without that.&lt;br /&gt;
&lt;br /&gt;
=== Migration tools ===&lt;br /&gt;
&lt;br /&gt;
At times, storage regimes change, new storage is added and sometimes it&#039;s not easy to migrate with the current hardware or its support systems. Once I had to migrate a 45TiB fileserver from one storage system to another, preferably without downtime. The server originally had three 15TiB PVs of which two were full and the third half full. I resorted to using [https://linux.die.net/man/8/pvmove pvmove] to just move the data on the PVs in use to a new PV. We started out with creating a new 50TiB PV, sde, and then to pvmove.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Attach /dev/sde to the VG my_vg&lt;br /&gt;
vgextend my_vg /dev/sde&lt;br /&gt;
&lt;br /&gt;
# Move the contents from /dev/sdb over to /dev/sde block by block. If a target is not given in pvmove,&lt;br /&gt;
# the contents of the source (sdb here) will be put somewhere else in the pool.&lt;br /&gt;
pvmove /dev/sdb /dev/sde&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This took a while (as in a week or so) - the pvmove command uses old code and logic (or at least did that when I migrated this in November 2016), but it affected performance on the server very little, so users didn&#039;t notice. After the first PV was migrated, I continued with the other two, one after the other, and after a month or so, it was migrated. We used this on a number of large fileservers, and it worked flawlessly. Before doing the production servers I also tried interrupting pvmove in various ways, including hard resets, and it just kept on after the reboot.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;NOTE:&#039;&#039;&#039;&#039;&#039; &#039;&#039;Even though it worked well for us, &#039;&#039;&#039;always&#039;&#039;&#039; keep a good backup before doing this. Things may go wrong, and without a good backup, you may be looking for a hard-to-find new job the next morning&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
==== mdadm workarounds ====&lt;br /&gt;
&lt;br /&gt;
===== Migrate from a mirror (raid-1) to raid-10 =====&lt;br /&gt;
&lt;br /&gt;
Create a mirror&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sdb /dev/sdc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
LVM (pv/vg/lv) on md0 (see above), put a filesystem on the lv and fill it with some data.&lt;br /&gt;
&lt;br /&gt;
Now, some months later, you want to change this to raid-10 to allow for the same amount of redundancy, but to allow more disks into the system.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mdadm --grow /dev/md0 --level=10&lt;br /&gt;
mdadm: Impossibly level change request for RAID1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So - no - doesn&#039;t work. But - we&#039;re on &lt;br /&gt;
&lt;br /&gt;
Since we&#039;re on lvm already, this&#039;ll be easy. If you&#039;re using filesystems directly on partitions, you can do this the same way, but without the pvmove part, using rsync or whateever you like instead. I&#039;d recommend using lvm for for the new raid, which should be rather obvious from this article. Now plug in a new drive and create a new raid10 on that one. If you two new drives, install both. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# change &amp;quot;missing&amp;quot; to the other device name if you installed two new drives&lt;br /&gt;
mdadm --create /dev/md1 --level=10 --raid-devices=2 /dev/vdd missing&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, as described above, just vgextend the vg, adding the new raid and run pvmove to move the data from the old pv (residing on the old raid1) to the new pv (on raid10). Afte rpvmove is finished (which may take awile, see above), just&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
vgreduce raidtest /dev/md0&lt;br /&gt;
pvremove /dev/md0&lt;br /&gt;
mdadm --stop /dev/md0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
…and your disk is free to be added to the new array. If the new raid is running in degraded mode (if you created it with just one drive), better don&#039;t wait too long, since you don&#039;t have redundancy. Just mdadm --add the devs.&lt;br /&gt;
&lt;br /&gt;
If you now have /dev/mdstat telling you your raid10 is active and have three drives, of which one is a spare, it should look something like this&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5] [raid4] [raid10]&lt;br /&gt;
md1 : active raid10 vdc[3](S) vdb[2] vdd[0]&lt;br /&gt;
      8380416 blocks super 1.2 2 near-copies [2/2] [UU]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Just mdadm --grow --raid-devices=3 /dev/md1&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;RAID section is not complete. I&#039;ll write more on migraing from raid10 to raid6 later. It&#039;s not straight forward, but easier than this one :)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== Thin provisioned LVs ===&lt;br /&gt;
&lt;br /&gt;
Thin provisioning on LVM is a method used for not allocating all the space given to an LV. For instance, if you have a 1TB VG and want to give an LV 500GB, although it currently only uses a fraction of that, a thin lv can be a good alternative. This will allow for adding a limit to how much it can use, but also to let it grow dynamically without manual work by the sysadmin. Thin provisioning adds another layer of abstaction by creating a special LV as a &#039;&#039;thin pool&#039;&#039; from which data is allocated to the &#039;&#039;thin volume(s)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== Create a thin pool ====&lt;br /&gt;
&lt;br /&gt;
Allocate 1TB to the thin pool to be used for thinly provisioned LVs. Keep in mind that the space allocated to the thin pool is in fact thick provisioned. Only the volumes put on &#039;&#039;thinpool&#039;&#039; are thin provisioned. This will create two hidden LVs, one for data and one for metadata. Normally the defaults will do, but check the manual if the data doesn&#039;t match the usual patterns (such as billions of files, resulting in huge amounts of metadata). I &#039;&#039;beleive&#039;&#039; the metadata part should be resizable at a later time if needed, but I have not tested it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a pool for thin LVs. Keep in mind that the pool itself is not thin provisioned, only the volumes residing on it&lt;br /&gt;
lvcreate --size 1T --type thin-pool --thinpool thinpool my_vg&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Create a thin volume ====&lt;br /&gt;
&lt;br /&gt;
You have the thinpool, now put a thin volume on it. It will allocate some space for metadata, but probably not much (a few megs, perhaps).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Now, create a volume with a virtual (-V) size of half a terabyte named thin_pool, but using the thinpool (-T) named thin_pool for storage&lt;br /&gt;
lvcreate -V 500G -T my_vg/thin_pool --name thinvol&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The new volume&#039;s device name will be /dev/thinvol. Now, create a filesystem on it, add to fstab and mount it. The &#039;&#039;&#039;df&#039;&#039;&#039; command will return available space according to the virtual size (-V), while lvs will show how much data is actually used on each of the thinly provisioned volumes.&lt;br /&gt;
&lt;br /&gt;
== Filesystem dilemmas ==&lt;br /&gt;
&lt;br /&gt;
=== XFS or ext4 or something else ===&lt;br /&gt;
The choice of filesystem varies for your use. Distros such as RHEL/CentOS has moved to XFS by default from v7. Debian/Ubuntu still sticks to ext4, like most other. I&#039;ll discuss my thoughts below on ext4 vs XFS and leave the other filesystems for later.&lt;br /&gt;
&lt;br /&gt;
==== ext4 ====&lt;br /&gt;
ext4 is probably the most used filesystem on linux as of writing. It&#039;s rock stable and has been extended by a lot of extensions since the original ext2. It still retains backward compatibility, being able to mount and fsck ext2 and ext3 with the ext4 driver. However, it doesn&#039;t handle large filesystems very well. If a filesystem is created for &amp;lt;16TiB, it cannot be grown to anything larger than 16TiB. This may have changed lately, though. One other issue is handling errors. If a large filesystem (say 10TiB) is damaged, an fsck may take several hours, leading to long downtime. When I refer to ext4 further in this text, the same applies to ext2 and ext3 unless otherwise specified.&lt;br /&gt;
&lt;br /&gt;
==== XFS ====&lt;br /&gt;
XFS, originally developed by SGI some time in the bronze age, but has been worked on heavily after that. RHEL and Centos version 7 and forward, uses XFS as the default filesystem. It is quick, it scales well, but it lacks at least two things ext4 has. It cannot be shrunk (not that you normally need that, but nice if you have a typo or you need to change things). Also, it doesn&#039;t allow for automatic fsck on bootup. If something is messed up on the filesystem, you&#039;ll have to login as root on the console (not ssh), which might be an issue on some systems. The fsck equivalent, xfs_repair, is a *lot* faster than ext4&#039;s fsck, though.&lt;br /&gt;
&lt;br /&gt;
==== ZFS ====&lt;br /&gt;
ZFS is like a combination of RAID, LVM and a filesystem, supporting full checksumming, auto-healing (given sufficient redundancy), compression, encryption, replication, deduplication (if you&#039;re brave and have a &#039;&#039;ton&#039;&#039; of memory) and a lot more. It&#039;s a separate chapter and needs a lot more talk than paragraph here.&lt;br /&gt;
&lt;br /&gt;
==== btrfs ====&lt;br /&gt;
btrfs, pronounced &amp;quot;butterfs&amp;quot; or &amp;quot;betterfs&amp;quot; or just spelled out, is a filesystem that mimics that of ZFS. It has been around for 10 years or so, but hasn&#039;t yet proven to be really stable. Following the progress of it for those years, I&#039;ve found it to be a nice toy with which to play, but not to be used in production. Again, others may say otherwise, but these are just my words.&lt;br /&gt;
&lt;br /&gt;
== Low level disk handling ==&lt;br /&gt;
&lt;br /&gt;
This section is for low-level handling of disks, regardless of storage system elsewhere. These apply to mdraid, lvmraid and zfs and possibly other solutions, with the exception of individual drives on hwraid (and maybe fakeraid), since there, the drives are hidden from Linux (or whatever OS).&lt;br /&gt;
&lt;br /&gt;
=== S.M.A.R.T. and slow drives ===&lt;br /&gt;
Modern (that is, from about 1990 or later) have S.M.A.R.T. (or just smart, since it&#039;s easier to type) monitoring built in, meaning the disk&#039;s controller is monitoring itself. This is handy and will ideally tell you in advance that a drive is flakey or dying. Modern (2010+) smart monitoring is more or less the same. It can be trusted about 50% of the time. Usually, if smart detects an error, it&#039;s a real error. I don&#039;t think I&#039;ve seen it reporting a false positive, but others may know better. &lt;br /&gt;
&lt;br /&gt;
==== smartmontools ====&lt;br /&gt;
First, install smartmontool and run smartclt -H /dev/yourdisk (/dev/sda or something) to get a health report. Then perhaps run smartctl -a /dev/yourdisk and look for &#039;current pending sectors&#039; This should be zero. Also check the temperature, which normally should be much above 50.&lt;br /&gt;
&lt;br /&gt;
==== single, slow drive ====&lt;br /&gt;
What may happen, is smart not seeing anything and life goes on like before, only slower and less prouductive, without telling anyone. If you stubler over this issue, you&#039;ll probably see it during a large rsync/zfs send/receive or a resync/rebuild/resilver of the raid/zpool. During this, it feels like everything is slow and your RAID has turned into a RAIF (redundant array of inexpensive floppies). To check if you have a single drive messing up it all, check with &#039;&#039;&#039;iostat -x 2&#039;&#039;&#039;, having 2 being the delay between each measurement. Interrupt it with ctrl+x. If there&#039;s a rougue drive there, it should stand out like sdg below&lt;br /&gt;
&lt;br /&gt;
 avg-cpu:  %user   %nice %system %iowait  %steal   %idle&lt;br /&gt;
            0.38    0.00    1.75    0.00    0.00   97.87&lt;br /&gt;
&lt;br /&gt;
 Device            r/s     w/s     rkB/s     wkB/s   rrqm/s   wrqm/s  %rrqm  %wrqm r_await w_await aqu-sz rareq-sz wareq-sz  svctm  %util&lt;br /&gt;
 sda              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdb              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdc              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdd              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sde              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdf              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdg              3.50    0.00   2352.00      0.00     0.00     0.00   0.00   0.00 14306.29    0.00  13.85   672.00     0.00 285.71 100.00&lt;br /&gt;
 sdh              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
&lt;br /&gt;
In ZFS land, you should be able to get similar data with &#039;&#039;&#039;zpool iostat -v &amp;lt;pool&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Now you know the bad drive (sdg), pull it from the raid with &#039;&#039;&#039;mdadm --fail /dev/mdX /dev/sdX&#039;&#039;&#039;. Now test the drive&#039;s performance manually, just simply:&lt;br /&gt;
&lt;br /&gt;
 # hdparm -t /dev/sdg&lt;br /&gt;
 &lt;br /&gt;
 /dev/sdg:&lt;br /&gt;
  Timing buffered disk reads:   2 MB in  5.37 seconds = 381.46 kB/sec&lt;br /&gt;
&lt;br /&gt;
Bingo - nothing you&#039;d want to keep. For a good drive, it should be something like 100-200MB/s&lt;br /&gt;
&lt;br /&gt;
PS: Keep in mind that you have a degraded RAID by now in case you had a spare waiting for things to happen.&lt;br /&gt;
&lt;br /&gt;
Try to replace the cable and/or try the disk on another port/controller. If the result from hdparm persists, it&#039;s probably a bad cable&lt;br /&gt;
&lt;br /&gt;
So, then, just psycially locate the drive, pull it out, take out the discs and magnets and recycle the rest.&lt;br /&gt;
&lt;br /&gt;
=== &amp;quot;Unplug&amp;quot; drive from system ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Find the device unit&#039;s number with something like&lt;br /&gt;
find /sys/bus/scsi/devices/*/block/ -name sdd&lt;br /&gt;
# returning /sys/bus/scsi/devices/3:0:0:0/block/sdd here, &lt;br /&gt;
# meaning 3:0:0:0 is the SCSI device we&#039;re looking for.&lt;br /&gt;
&lt;br /&gt;
# Given this is the correct device, and you want to &#039;unplug&#039; it, do so by&lt;br /&gt;
echo 1 &amp;gt; /sys/bus/scsi/devices/3:0:0:0/delete&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Rescan disk controllers ===&lt;br /&gt;
If a drive is added and for some reason doesn&#039;t get detected, or is removed by the command above, it can be rediscovered with a sysfs command to the scsi host to which it is connected. Since there may be quite a few of these, an easy way is to just scan them all and check the output of &#039;&#039;&#039;dmesg -T&#039;&#039;&#039; after running it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Make a list of controllers and send a rescan message to each of them. It won&#039;t do anything &lt;br /&gt;
# for those where nothing has changed, but it will show new drives where they have been added.&lt;br /&gt;
for host_scan in /sys/class/scsi_host/host*/scan&lt;br /&gt;
do&lt;br /&gt;
  echo &#039;- - -&#039; &amp;gt; $host_scan&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Fail injection with debugfs ===&lt;br /&gt;
[https://lxadm.com/Using_fault_injection https://lxadm.com/Using_fault_injection]&lt;br /&gt;
&lt;br /&gt;
== mdadm stuff ==&lt;br /&gt;
=== Resync ===&lt;br /&gt;
To resync a raid, that is, check, run&lt;br /&gt;
&lt;br /&gt;
 echo check &amp;gt; /sys/block/$dev/md/sync_action&lt;br /&gt;
&lt;br /&gt;
where $dev is something like md0. If you have several raids, something like this should work&lt;br /&gt;
&lt;br /&gt;
 for dev in md{0,1}&lt;br /&gt;
 do&lt;br /&gt;
   echo repair &amp;gt; /sys/block/$dev/md/sync_action&lt;br /&gt;
 done&lt;br /&gt;
&lt;br /&gt;
Also useful in a one-liner like&lt;br /&gt;
&lt;br /&gt;
 for dev in md{0,1} ; do echo repair &amp;gt; /sys/block/$dev/md/sync_action ; done&lt;br /&gt;
&lt;br /&gt;
Different raids on different drives will do this in parallel. If the drives are shared somehow with partitions or similar, the check or repair will wait for the other to finish before going on.&lt;br /&gt;
&lt;br /&gt;
As for repair vs check, [https://raid.wiki.kernel.org/index.php/RAID_Administration this article] describes it well. I stick to using repair unless it&#039;s something rare where I don&#039;t want to touch the data.&lt;br /&gt;
&lt;br /&gt;
=== Spare pools ===&lt;br /&gt;
In the old itmes, mdadm supported only a dedicated spare per md device, so if working with a large set of drives (20? 40?), where you&#039;d want to setup more raid sets to increase redundancy, you&#039;d dedicate a spare to each of the raid sets. This has changed (some time ago?), so in these modern, heathen days, you can change mdadm.conf, usually placed under /etc/mdadm, and add &#039;spare-group=somegroup&#039; where &#039;somegroup&#039; is a string identifying the spare group. After doing this, run &#039;&#039;&#039;update-initramfs -u&#039;&#039;&#039; and reboot and add a spare to one of the raid sets in the spare group, and md will use that or those spares for all the raidsets in that group.&lt;br /&gt;
&lt;br /&gt;
As some pointed out on #linux-raid @ irc.freenode.net, this feature is very badly documented, but as far as I can see, it works well.&lt;br /&gt;
&lt;br /&gt;
==== Example config ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create two raidsets&lt;br /&gt;
&lt;br /&gt;
mdadm --create /dev/md1 --level=6 --raid-devices=6 /dev/vd[efghij]&lt;br /&gt;
mdadm --create /dev/md2 --level=6 --raid-devices=6 /dev/vd[klmnop]&lt;br /&gt;
&lt;br /&gt;
# get their UUID etc&lt;br /&gt;
&lt;br /&gt;
mdadm --detail --scan&lt;br /&gt;
ARRAY /dev/md/1 metadata=1.2 name=raidtest:1 UUID=1a8cbdcb:f4092350:348b6b80:c054d74c&lt;br /&gt;
ARRAY /dev/md/2 metadata=1.2 name=raidtest:2 UUID=894b1b7c:cb7eba70:917d6033:ea5afd2b&lt;br /&gt;
&lt;br /&gt;
# Put those lines into /etc/mdadm/mdadm.conf and and add the spare-group&lt;br /&gt;
&lt;br /&gt;
ARRAY /dev/md/1 metadata=1.2 name=raidtest:1 spare-group=raidtest UUID=1a8cbdcb:f4092350:348b6b80:c054d74c&lt;br /&gt;
ARRAY /dev/md/2 metadata=1.2 name=raidtest:2 spare-group=raidtest UUID=894b1b7c:cb7eba70:917d6033:ea5afd2b&lt;br /&gt;
&lt;br /&gt;
# update the initramfs and reboot&lt;br /&gt;
&lt;br /&gt;
update-initramfs -u&lt;br /&gt;
reboot&lt;br /&gt;
&lt;br /&gt;
# add a spare drive to one of the raids&lt;br /&gt;
&lt;br /&gt;
mdadm --add /dev/md1 /dev/vdq&lt;br /&gt;
&lt;br /&gt;
# fail a drive on the other raid&lt;br /&gt;
&lt;br /&gt;
mdadm --fail /dev/md2 /dev/vdn&lt;br /&gt;
&lt;br /&gt;
# check /proc/mdstat to see md2 rebuilding with the spare from md1&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Recovery ===&lt;br /&gt;
&lt;br /&gt;
The other day, I came across a problem a user had on #linux-raid@irc.freenode.net. He had an old Qnap NAS that had died and tried plugging the drives in to his Linux machine and got various errors. The two-drive RAID-1 did not come up as it should, &#039;&#039;&#039;dmesg&#039;&#039;&#039; was full of errors from one of the drives (both connected on USB) and so forth.&lt;br /&gt;
&lt;br /&gt;
We went on and started by taking down the machine and just connecting one of the drives. I had him check what was assembled with&lt;br /&gt;
&lt;br /&gt;
 cat /proc/mdstat&lt;br /&gt;
&lt;br /&gt;
That returned /proc/md127 assembled, but LVM didn&#039;t find anything. So running a manual scan&lt;br /&gt;
&lt;br /&gt;
 pvscan --cache /dev/md127&lt;br /&gt;
&lt;br /&gt;
This made linux find the PV, VG and a couple of LVs, but probably because the mdraid was degraded, the LVs were deactivated, according to &#039;&#039;&#039;lvscan&#039;&#039;&#039;. Activating the one with a filesystem manually&lt;br /&gt;
&lt;br /&gt;
 lvchange -a y /dev/&amp;lt;vg&amp;gt;/&amp;lt;lv&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Substitute &amp;lt;vg&amp;gt; and &amp;lt;lv&amp;gt; with the names listed by vgs and lvs.&lt;br /&gt;
&lt;br /&gt;
This worked, and the filesystem on /dev/&amp;lt;vg&amp;gt;/&amp;lt;lv&amp;gt; could be mounted correctly.&lt;br /&gt;
&lt;br /&gt;
=== Renaming a RAID ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Not finished&#039;&#039;&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
&lt;br /&gt;
Back around 2001, I asked on the linux-raid list for disk tagging, not default back then, but supported, and thought of the possibility of disk #1 getting replaced with disk #1 from another raid because of a messup. After this, the hostname was added to the raid name in the superblock. So when a RAID is created, it is named &amp;quot;hostname:raidname&amp;quot;, where the raidname is either a number (0,1...) or a name. &lt;br /&gt;
&lt;br /&gt;
For instance, running this on my VM named &amp;quot;raidtest&amp;quot;:&lt;br /&gt;
&lt;br /&gt;
 mdadm --create --level=1 --raid-devices=2 /dev/md/stuff /dev/sd[st]&lt;br /&gt;
&lt;br /&gt;
mdadm --detail --scan now shows this&lt;br /&gt;
&lt;br /&gt;
 ARRAY /dev/md/stuff metadata=1.2 name=raidtest:stuff UUID=c4cdf69f:393a28b1:47648ed3:726613de&lt;br /&gt;
&lt;br /&gt;
Now, you might want to change this name for some reason, and it&#039;s not supported under &amp;quot;grow&amp;quot;, so what to do… The name is, after all, local to the disk, since it&#039;s there to avoid messing up a raid (or two) after a disk mixup.&lt;br /&gt;
&lt;br /&gt;
 mdadm --assemble /dev/md/stuff --name &#039;someotherhost:stuff&#039; --update=homehost /dev/sd[st]&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== The badblock list ===&lt;br /&gt;
&#039;&#039;&#039;md&#039;&#039;&#039; has an internal badblock list (BBL), added around 2010, to list the bad blocks on the disk to avoid using those. While this might sound like a good idea, the badblock list is updated in case of a read error, which can be caused by several things. To make things worse, the BBL is replicated to other drives when a drive fails or the array is grown. So if you start out with sda and sdb and sdb suffers some errors, nothing wrong, md will read from sda, but flag those sectors on sdb as bad. So after a while, perhaps sda dies and gets replaced, with the same content, including the BBL. Then, at some point you might to replace sdb and it, too gets the BBL. So it sticks - forever. Also, there&#039;s no real point of keeping a BBL list, since the drive has its own and even if a sector error occurs, the array will have sufficient redundancy to recover from that (unless you use RAID-0 which you shouldn&#039;t). If a drive finds a bad sector, it&#039;ll be reallocated by the drive itself without the user&#039;s/admin&#039;s/system&#039;s knowledge. If a sector can&#039;t be reallocated, it means the drive is bad and should be replaced.&lt;br /&gt;
&lt;br /&gt;
There&#039;s no official way to remove it and although you can assemble it with the no-bbl option, this will only work if there&#039;s an empty BBL. Also, this will require downtime. As far as I can see, the only way to do this currently, is with a wee hack that should work. Just replace the names of mddev/diskdev with your own.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
mddev=&amp;quot;/dev/md0&amp;quot;&lt;br /&gt;
diskdev=&amp;quot;/dev/sda&amp;quot;&lt;br /&gt;
mdadm $mddev --fail $diskdev --remove $diskdev --re-add $diskdev --update=no-bbl&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If there&#039;s a BBL on the drive already, replace the --update part to &#039;force-no-bbl&#039;. This is not documented anywhere as per se, but it works.&lt;br /&gt;
 &lt;br /&gt;
I haven&#039;t found a way to turn this off permanently, but there may be something coming around when the debate on the linux-raid mailing list closes up on this. There&#039;s a bbl=no in mdadm.conf, but that&#039;s only for creation. I will continue extensive testing for this.&lt;br /&gt;
&lt;br /&gt;
== Tuning ==&lt;br /&gt;
&lt;br /&gt;
While trying to compare a 12-disk RAID (8TB disks) to a hwraid, mdraid was slower, so we did a few things to speed things up:&lt;br /&gt;
&lt;br /&gt;
While testing with [https://linux.die.net/man/1/fio fio], monitor /sys/block/md0/md/stripe_cache_active, and see if it&#039;s close to /sys/block/md0/md/stripe_cache_size. If it is, double the size of the latter&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
echo 4096 &amp;gt; /sys/block/md0/md/stripe_cache_size&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Continue until stripe_cache_active stabilises, and then you&#039;ve found the limit you&#039;ll need. You may want to double that for good measure. &lt;br /&gt;
&lt;br /&gt;
(to be continued)&lt;br /&gt;
&lt;br /&gt;
== Links ==&lt;br /&gt;
&lt;br /&gt;
Below are a few links with useful info&lt;br /&gt;
&lt;br /&gt;
* [https://raid.wiki.kernel.org/index.php/Irreversible_mdadm_failure_recovery Irreversible mdadm failure recovery]&lt;br /&gt;
&lt;br /&gt;
= ZFS =&lt;br /&gt;
&lt;br /&gt;
ZFS can do a lot of things most filesystems or volume managers can&#039;t. It checksums all data and metadata and so long that the system uses ECC enabled memory (RAM), it will have complete control over the whole data set, and when (not if) an error occurs, it&#039;ll fix the issue without even throwing a warning. To fix the issue, you&#039;ll obviously need sufficient redundancy (mirrors or RAIDzN). &lt;br /&gt;
&lt;br /&gt;
== ZFS send/receive between machines ==&lt;br /&gt;
&lt;br /&gt;
ZFS has a send/receive mechanism that allows for snapshots to be sent over the wire to a receiving end. This can be a full filesystem, or an incremental change since last send/reveive. In a WAN scenario, you&#039;ll probably want to use VPN for this. On a controlled network, sending in cleartext is also possible. You may as well use ssh, but keep in mind that ssh was never designed to be used as a fullblown vpn solution and is just too slow or the task with large amounts of data. You may, though, use mbuffer, if on a loal LAN.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Allow traffic from the sending IP in whatever firewall interface you&#039;re using (if you&#039;re using a firewall at all, that is)&lt;br /&gt;
ufw allow from x.x.x.x&lt;br /&gt;
# &lt;br /&gt;
# Start the receiver first. This listens on port 9090, has a 1GB buffer,&lt;br /&gt;
    and uses 128kb chunks (same as zfs):&lt;br /&gt;
&lt;br /&gt;
mbuffer -s 128k -m 1G -I 9090 | zfs receive data/filesystem&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To be continued one day… See [https://everycity.co.uk/alasdair/2010/07/using-mbuffer-to-speed-up-slow-zfs-send-zfs-receive/ this] for some more. I&#039;ll get back with details on it.&lt;br /&gt;
&lt;br /&gt;
= General Linux system control =&lt;br /&gt;
&lt;br /&gt;
== Add a new CPU (core) ==&lt;br /&gt;
&lt;br /&gt;
If working with virtual machines, adding a new core can be useful if the VM is slow and the load is multithreaded or multiprocess. To do this, add a new CPU in the hypervisor (be it KVM or VMware or Hyper-V or whatever). Some hypervisors, like VMware, will activate it automatically if open-vm-tools is installed. Please note that open-vm-tools is for VMware only. I don&#039;t know of any such thing for KVM or other hypervisors (although I beleive VirtualBox has its own set of tools, but not as a package). If this doesn&#039;t work, run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
echo 1 &amp;gt; /sys/devices/system/cpu/cpuX/online&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where X is the CPU number you want to add. You can &#039;cat /sys/devices/system/cpu/cpuX/online&#039; to check if it&#039;s online.&lt;br /&gt;
&lt;br /&gt;
= Mount partitions on a disk image =&lt;br /&gt;
&lt;br /&gt;
Sometimes you&#039;ll have a disk image, either from recovering a bad drive after hours (or days or weeks) of ddrescue, and sometimes you just have a disk image from a virtual machine where you want to mount the partitions inside the image. There are three main methods of doing this, which are more or less synonmous, but some easier than the other.&lt;br /&gt;
&lt;br /&gt;
== Basics ==&lt;br /&gt;
&lt;br /&gt;
A disk image is usually like a disk, consisting of either a large filesystem, a PV or a partition table with one or partitions onto which resides a filesystem, a pv, swap or something else. If it&#039;s partitioned, and you want your operating system to mount a filesystem or allow it to see whatever LVM stuff lies on it, you need to isolate the partitions. &lt;br /&gt;
&lt;br /&gt;
== Manual mapping ==&lt;br /&gt;
&lt;br /&gt;
In the oldern days, this was done manually, something like this&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
root@mymachine:~# fdisk -l /dev/vda&lt;br /&gt;
Disk /dev/vda: 25 GiB, 26843545600 bytes, 52428800 sectors&lt;br /&gt;
Units: sectors of 1 * 512 = 512 bytes&lt;br /&gt;
Sector size (logical/physical): 512 bytes / 512 bytes&lt;br /&gt;
I/O size (minimum/optimal): 512 bytes / 512 bytes&lt;br /&gt;
Disklabel type: dos&lt;br /&gt;
Disk identifier: 0xc37b7ea5&lt;br /&gt;
&lt;br /&gt;
Device     Boot    Start      End  Sectors  Size Id Type&lt;br /&gt;
/dev/vda1  *        2048 50333311 50331264   24G 83 Linux&lt;br /&gt;
/dev/vda2       50333312 52426369  2093058 1022M  5 Extended&lt;br /&gt;
/dev/vda5       50333314 52426369  2093056 1022M 82 Linux swap / Solaris&lt;br /&gt;
root@mymachine:~#&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To calculate the start and end of each partition, you just take the start sector and multiply it by the sector size (512 bytes here) and you have the offset in bytes. After this, it&#039;s merely an losetup -o &amp;lt;offset&amp;gt; /dev/loopX &amp;lt;nameofimagefile&amp;gt; and you have the partition mapped to your /dev/loopX (having X being something typically 0-255. After this, just mount it or run pvscan/vgscan/lvscan to probe whatever lvm config is there, and you should be able to mount it like any other filesystem.&lt;br /&gt;
&lt;br /&gt;
== kpartx ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;kpartx&#039;&#039;&#039; does the same as above, more or less, just without so much hassle. Most of it should be automatic and easy to deal with, except it may fail to disconnect the loopback devices sometimes, so you may have to &#039;&#039;&#039;losetup -d&#039;&#039;&#039; them manually. See the manual, &#039;&#039;&#039;kpartx (8)&#039;&#039;&#039;. Please note that &#039;&#039;&#039;partx&#039;&#039;&#039; works similarly and I&#039;d guess the authors of the two tools are arguing a lot of which one&#039;s the best.&lt;br /&gt;
&lt;br /&gt;
== guestmount ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;guestmount&#039;&#039;&#039; is something similar again, but also supports file formats like &#039;&#039;&#039;qcow2&#039;&#039;&#039; and possibly other, proprietary filesystems like &#039;&#039;&#039;vmdk&#039;&#039;&#039; and &#039;&#039;&#039;vdi&#039;&#039;&#039;, but don&#039;t take my word for it - I haven&#039;t tested. Again, see the manual or just read up on the description [http://ask.xmodulo.com/mount-qcow2-disk-image-linux.html?fbclid=IwAR3snTeZvGzp9PLdX11EQhCfOpux6I93CiJ3A2pUomkkRLly9Xo4851mkTY here]. It seems rather trivial.&lt;br /&gt;
&lt;br /&gt;
= Linux on laptops =&lt;br /&gt;
&lt;br /&gt;
== Wifi with HP EliteBook 725/745 on Ubuntu ==&lt;br /&gt;
&lt;br /&gt;
The HP EliteBook 725/745 and similar are equipped with a BCM4352 wifi chip. As with a lot of other stuff from Broadcom, this lacks an open hardware description, so thus no open driver exist. The proper fix, is to replace the NIC with something with an open driver, but again, this isn&#039;t always possible, so a binary driver exists. In ubuntu, run, somehow connect the machine to the internet and run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install bcmwl-kernel-source&lt;br /&gt;
sudo modprobe wl&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you can&#039;t connect the machine to the internet, download the needed packages on another machine and put it on some usb storage. These packages should suffice:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# apt-cache depends bcmwl-kernel-source&lt;br /&gt;
bcmwl-kernel-source&lt;br /&gt;
  Depends: dkms&lt;br /&gt;
  Depends: linux-libc-dev&lt;br /&gt;
  Depends: libc6-dev&lt;br /&gt;
  Conflicts: &amp;lt;bcmwl-modaliases&amp;gt;&lt;br /&gt;
  Replaces: &amp;lt;bcmwl-modaliases&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then install manually with &#039;&#039;&#039;dpkg -i file1.deb file2.deb&#039;&#039;&#039; etc&lt;br /&gt;
&lt;br /&gt;
After this, ip/ifconfig/iwconfig shouldd see the new wifi nic, probably &#039;&#039;&#039;wlan0&#039;&#039;&#039;, but due to a [https://bugs.launchpad.net/ubuntu/+source/broadcom-sta/+bug/1343151 old, ignored bug], you won&#039;t find any wifi networks. This is because the driver from Broadcom apparently does not support interrupt remapping, commonly used on x64 machines. To turn this off, change &#039;&#039;&#039;/etc/default/grub&#039;&#039;&#039; and change the line &#039;&#039;&#039;GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;quiet splash&amp;quot;&#039;&#039;&#039;, adding intremap=off to the end before the quote: &#039;&#039;&#039;GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;quiet splash intremap=off&amp;quot;&#039;&#039;&#039;. Save the file and run &#039;&#039;&#039;sudo update-grub&#039;&#039;&#039; and reboot. After this, wifi should work well.&lt;br /&gt;
&lt;br /&gt;
== Wifi with HP Compaq Presario CQ57 on Ubuntu ==&lt;br /&gt;
&lt;br /&gt;
The HP Compaq Presario CQ57 uses the RT5390 wifi chipset. This has been supported for quite some time now, and I was quite surprised to find it not working on a laptop a friend was having. The driver loaded correctly, but Ubuntu insisted of the laptop being in &#039;&#039;&#039;flight mode&#039;&#039;&#039;. Checking &#039;&#039;&#039;rfkill&#039;&#039;&#039;, it showed me two NICs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# rfkill list all&lt;br /&gt;
0: phy0: Wireless LAN&lt;br /&gt;
	Soft blocked: no&lt;br /&gt;
	Hard blocked: yes&lt;br /&gt;
1: hp-wifi: Wireless LAN&lt;br /&gt;
	Soft blocked: yes&lt;br /&gt;
	Hard blocked: no&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Turning rfkill on and off resulted in nothing much, except some error messages in the kernel log (dmesg)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] ACPI Error: Field [B128] at bit offset/length 128/1024 exceeds size of target Buffer (160 bits) (20170831/dsopcode-235)&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]&lt;br /&gt;
                            Initialized Local Variables for Method [HWCD]:&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Local0: 00000000a34b7928 &amp;lt;Obj&amp;gt;           Integer 0000000000000000&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Local1: 00000000b0aa6865 &amp;lt;Obj&amp;gt;           Buffer(8) 46 41 49 4C 04 00 00 00&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Local5: 00000000a9811efd &amp;lt;Obj&amp;gt;           Integer 0000000000000004&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] Initialized Arguments for Method [HWCD]:  (2 arguments defined for method invocation)&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Arg0:   0000000078957d1b &amp;lt;Obj&amp;gt;           Integer 0000000000000001&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Arg1:   00000000725c9c6e &amp;lt;Obj&amp;gt;           Buffer(20) 53 45 43 55 02 00 00 00&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] ACPI Error: Method parse/execution failed \_SB.WMID.HWCD, AE_AML_BUFFER_LIMIT (20170831/psparse-550)&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] ACPI Error: Method parse/execution failed \_SB.WMID.WMAD, AE_AML_BUFFER_LIMIT (20170831/psparse-550)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After upgrading BIOS and testing different kernels, I was asked to try to unload the &#039;&#039;&#039;hp_wmi&#039;&#039;&#039; driver. I did, and things changed a bit, so I tried blacklisting it, creating the file &#039;&#039;&#039;/etc/modprobe.d/blacklist-hp_wmi.conf&#039;&#039;&#039; with the following content&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Blacklist this - it doesn&#039;t work!&lt;br /&gt;
blacklist hp_wmi&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
I gave the machine a reboot and afte that, the &#039;&#039;&#039;hp-wifi&#039;&#039;&#039; entry was gone in the rfkill output, and things works.&lt;br /&gt;
&lt;br /&gt;
= Raspberry pi =&lt;br /&gt;
&lt;br /&gt;
I couldn&#039;t quite decide if the raspberry pi should be a separate section or part of Linux, but hell, it can run more than Linux, although 99,lots% of people just uses Linux on them. This is a small list of things to know about them; things not on the front page of the manual or perhaps hidden even better.&lt;br /&gt;
&lt;br /&gt;
== Which pi? ==&lt;br /&gt;
&lt;br /&gt;
I just setup three raspberry pi machines and although some are quite different, like v1 to vEverythingelse or the Pi zero versions to the normal ones, not all of us remember how to distinguish between them, and sometimes they&#039;re in a nice 3d printed (or otherwise) chassis or otherwise hidden. So, how to check three different ones:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
root@home-assistant:~ $ cat /proc/device-tree/model ; echo&lt;br /&gt;
Raspberry Pi 2 Model B Rev 1.1&lt;br /&gt;
&lt;br /&gt;
root@green-pi:~ $ cat /proc/device-tree/model ; echo&lt;br /&gt;
Raspberry Pi 3 Model B Rev 1.2&lt;br /&gt;
&lt;br /&gt;
roy@yellow-pi:~ $cat /proc/device-tree/model ; echo&lt;br /&gt;
Raspberry Pi 4 Model B Rev 1.1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
While this works well, for the latter, the pi4, it doesn&#039;t tell how much memory I have. It comes in variants of 1, 2 and 4GB, and this is the latter.&lt;br /&gt;
&lt;br /&gt;
For a more detailed list, the command &#039;&#039;&#039;awk &#039;/^Revision/ {sub(&amp;quot;^1000&amp;quot;, &amp;quot;&amp;quot;, $3); print $3}&#039; /proc/cpuinfo&#039;&#039;&#039; will give you a revision number, detailing the type of pi, who produced it etc. Please see [https://elinux.org/RPi_HardwareHistory https://elinux.org/RPi_HardwareHistory] for a full table.&lt;br /&gt;
&lt;br /&gt;
== Monitoring ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;vcgencmd&#039;&#039;&#039; from &#039;&#039;&#039;/opt/vc/bin&#039;&#039;&#039;, but symlinked to &#039;&#039;&#039;/usr/bin&#039;&#039;&#039; so it&#039;s available in path, is useful for fetching hardware info about the pi. For example, measuring the temperature&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
root@yellow-pi:~# vcgencmd measure_temp&lt;br /&gt;
temp=63.0&#039;C&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The command is generally badly documented and parts of it seems outdated for newer hardware. Here&#039;s the output from a Raspberry pi 4 with 4GB RAM&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
roy@yellow-pi:~ $ vcgencmd get_mem arm&lt;br /&gt;
arm=948M&lt;br /&gt;
roy@yellow-pi:~ $ vcgencmd get_mem gpu&lt;br /&gt;
gpu=76M&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= BIOS upgrade from Linux =&lt;br /&gt;
&lt;br /&gt;
Generally, BIOS upgrades have been moved to the BIOS itself these days. This saves a lot of work and quite possibly lives after those who earier rammed their heads through walls, now can upgrade directly from the internet instead of using obscure operating systems best avoided. Sometimes, however, one must use these nevertheless. This is a quick run-through on your options.&lt;br /&gt;
&lt;br /&gt;
== DOS ==&lt;br /&gt;
&lt;br /&gt;
Most non-automatic BIOS upgrades are installed from DOS. Doing a BIOS upgrade this way, is generally non-problematic. Just install a USB thingie with [https://www.freedos.org/ FreeDOS], copy your file(s) onto the thing and boot on it. The commandline is the same as old MS/DOS, except a wee bit more userfriendly, but not a lot.&lt;br /&gt;
&lt;br /&gt;
== Windows ==&lt;br /&gt;
&lt;br /&gt;
Some macahines, like laptops from &#039;&#039;&#039;HP&#039;&#039;&#039;, may have BIOS upgrades that are made to be installed from Windows and won&#039;t run in FreeDOS or MS/DOS, instead throwing an error, saying &#039;&#039;&#039;This program cannot be run in DOS mode&#039;&#039;&#039;. This means you&#039;ll have to boot on a Windows rescue disc and do the job from there. Googling this, tells you it&#039;s quite easy, you just choose &#039;make rescue disc&#039; from Windows, and it&#039;s all good, except if you don&#039;t run Windows, that is. To remedy this problem, do as follows:&lt;br /&gt;
&lt;br /&gt;
=== Download Windows ===&lt;br /&gt;
&lt;br /&gt;
Since you don&#039;t run Windows and possibly don&#039;t have a spouse or friend around with such unhealthy habits either, you need to get it. It&#039;s quite easy - just google &#039;download windows&#039; and it&#039;ll send you to [https://www.microsoft.com/en-us/software-download/windows10ISO somewhere like this].&lt;br /&gt;
&lt;br /&gt;
=== Burn it! ===&lt;br /&gt;
&lt;br /&gt;
Now it&#039;s time to burn the installer on a DVD ROM. You&#039;ll need a double-layered one, since the OS is &amp;gt; 4.7GiB, but I&#039;m sure you have a ton of those lying around. Now, just place your optical medium in your optical drive and burn, baby, burn!&lt;br /&gt;
&lt;br /&gt;
=== Or make a USB thing? ===&lt;br /&gt;
&lt;br /&gt;
Not a lot of machines have optical drives these days, so you may want to use an USB pen drive or something instead. This is easy, just make the USB bootable with the Windows application Microsoft has made for this. Unfortunately, this only runs on Windows, and unlike stuff like Debian, where the &#039;&#039;&#039;iso&#039;&#039;&#039; file can be dd&#039;ed directly onto a USB drive to make it bootable, the Windows &#039;&#039;&#039;iso&#039;&#039;&#039;s don&#039;t come with this luxury. There are lots of methods to make bootable USB things from iso files out there, but the only thing most of them have in common, is that they generally don&#039;t work.&lt;br /&gt;
&lt;br /&gt;
==== WoeUSB ====&lt;br /&gt;
&lt;br /&gt;
After hours of swearing, it&#039;s nice to come across software like [https://github.com/slacka/WoeUSB WoeUSB]. It may not be perfect, it relies on a bunch of GUI stuff you&#039;ll never need and so on, but it &#039;&#039;&#039;&#039;&#039;works&#039;&#039;&#039;&#039;&#039;, and that&#039;s the important part! Just clone the repo and RTFM and it&#039;s all nice. It&#039;s slow, but hell, getting a windows machine and/or an optical drive might be slower.&lt;br /&gt;
&lt;br /&gt;
WoeUSB does nothing fancy, but it &#039;&#039;&#039;does&#039;&#039;&#039; work. It will create a filesystem, FAT32 or NTFS (better use NTFS, FAT32 has its limits). It creates normal filesystems and so on. Just make sure to copy in the BIOS update file, usually an exe file, to run when Windows is up and running.&lt;br /&gt;
&lt;br /&gt;
==== Install BIOS ====&lt;br /&gt;
&lt;br /&gt;
Boot on the Windows USB thing and choose &#039;repair computer&#039; and then &#039;command prompt&#039;. Find the install file, and if you&#039;re lucky, you&#039;ll find it needs a 32bit OS, just like I did. Since the 64bit version doesn&#039;t include 32bit compatibility in the installer, revert to downloading the 32bit version of windows and start over. Pray to your favourite god(s) not to get across such machines again - it might help.&lt;br /&gt;
&lt;br /&gt;
= 3D printer stuff =&lt;br /&gt;
&lt;br /&gt;
Below are a number of not very ordered paragraphs about 3D printer related stuff, mostly based on my experience. Their content may be interesting or perhaps practical knowledge, but then, that depends on the reader.&lt;br /&gt;
&lt;br /&gt;
== 3D printer related introductions on youtube or elsewhere ==&lt;br /&gt;
&lt;br /&gt;
First off, I&#039;d like to mention some youtube videos that are all (or mostly) a nice start if you&#039;re new to 3D printers.&lt;br /&gt;
&lt;br /&gt;
=== [https://www.youtube.com/watch?v=nb-Bzf4nQdE&amp;amp;list=PLDJMid0lOOYnkcFhz6rfQ6Uj8x7meNJJx Thomas Salanderer&#039;s 10-video series on 3D printing basics] ===&lt;br /&gt;
&lt;br /&gt;
Thomas Salanderer is a an experienced 3D printer user/admin/fixer/etc and he has a lot of interesting videos. Some accuse him for being a [Prusa https://www.prusa3d.com/] fanboy, which he quite obviously is, but that doesn&#039;t stop him from making interesting and somewhat neutral videos. The series walks you thought the first steps of how things work and so on and hopefully opens more doors than anything else I&#039;ve seen.&lt;br /&gt;
&lt;br /&gt;
=== [https://www.youtube.com/watch?v=rp3r921DBGI Teaching Tech&#039;s &amp;quot;3D printer tuning reborn&amp;quot;] ===&lt;br /&gt;
&lt;br /&gt;
Teaching Tech is, like Salanderer or even more, good pedagogically and explains a lot. They (or he) do a bunch of testing and describing pros and cons with different things, just like other youtubers in the sme business. The mentioned video shows how to tune a 3D printer after you have first learned the basics, and leans on a webpage made to help you out without too much manual work.&lt;br /&gt;
&lt;br /&gt;
This was a short list, but I guess it&#039;ll grow over time.&lt;br /&gt;
&lt;br /&gt;
== Hydrophilic filament ==&lt;br /&gt;
&lt;br /&gt;
Most popular filament types, including PLA, PETG, PP or PA (Polyamide, normally known as Nylon) and virtualy any filament type named [https://www.matterhackers.com/news/filament-and-water poly-something] (and thus with an acronym of P-something) are hydrophilic (also (somewhat incorrectly) called hydroscopic), meaning so long they&#039;re dryer than the atmosphere around them, they&#039;ll do their best to suck out the atmosphere&#039;s humidity. This is why most filament are shrink-wrapped with a small bag of silica gel in it. If such filament is exposed for normal humid air for some time, it&#039;ll become very hard to use. Most of my experience is with PLA, which can handle a bit (depending on make), but still not a lot. With PLA, if you end up with prints where the filament seems not to stick, it may help with a higher temperature. Otherwise, the filament must be [https://all3dp.com/2/how-to-dry-filament-pla-abs-and-nylon/ baked]. If you don&#039;t want to use your oven, try something like a [https://www.jula.no/catalog/hjem-og-husholdning/kjokkenmaskiner/mattilberedningsapparater/frukt-sopptorker/frukt-sopptorker-001641/#tab02 fruit and mushroom dryer]. Then get a good, sealble plastic box and add something like half a kilogram of [https://www.ebay.com/sch/sis.html?_nkw=1KG+Orange+Replacement+Desiccant+Indicating+Silica+Gel+Beads+for+Drawers%2C+Camera&amp;amp;_id=131938742628&amp;amp;&amp;amp;_trksid=p2057872.m2749.l2658 silica gel] to an old sock, tie it and put it in the your new dry box.&lt;br /&gt;
&lt;br /&gt;
Please note that ABS is hydrophobic, so you won&#039;t have to worry too much there. Also, remember that PA/Nylon is extremely hydrophilic. Even a couple of days in normal air humidity can ruin it completely and will require baking.&lt;br /&gt;
&lt;br /&gt;
== Upgrading the firmware on an Ender 3 ==&lt;br /&gt;
&lt;br /&gt;
This is about upgrading the firmware, and thus also flashing a bootloader to the Creality Ender 3 3D printer. Most of this is well documented on several place, like o [https://www.youtube.com/watch?v=fIl5X2ffdyo the video from Teaching tech] and elsewhere, but I&#039;ll just summarise some issues I had.&lt;br /&gt;
&lt;br /&gt;
=== Using an arduino Nano as a programmer ===&lt;br /&gt;
&lt;br /&gt;
Quick note before you read on. If you have an Ender 3 controller version 1.1.5 or newer (or perhaps even a bit older), a CR-10S or some other more or less modern printers or controllers, they come with a bootloader installed already, so don&#039;t bother flashing one. The one that&#039;s in there already, should work well. So if you have one of these, just skip this and jump to the [[Roy&#039;s_notes#Flashing_the_printer|next section]].&lt;br /&gt;
&lt;br /&gt;
However, the normal CR-10 (without the S), Ender 3 and a few other printers from Creality come without a bootloader, so you&#039;ll need to flash one before upgrading the firmware. Well, strictly speakning, you don&#039;t need one, you can save those 8kB or so for other stuff and use a programmer to write the whole firmware, but then you&#039;ll need to wire up everything every time you want a new firmware, so in my world, you &#039;&#039;&#039;do&#039;&#039;&#039; need the bootloader, since it&#039;s easier.&lt;br /&gt;
&lt;br /&gt;
To install a bootloader, you&#039;ll need a programmer, and I didn&#039;t have one available. Having some el-cheapo china-copies of Arduinos around, I read I could use one and tried so. Although the docs mostly mention the Uno etc, it&#039;s just as simple with the Nano copy.&lt;br /&gt;
&lt;br /&gt;
So, grab an arduino, plug it to your machine with a USB cable, and, using the Arduino IDE, use the ArduinoISP sketch there (found under Examples) to burn the software needed for the arduino to work as a programmer. When this is done, connect a 10µF capacitor between RST and GND to stop it from resetting when used as a programmer. Connect the MOSI, MISO and SCK pins from the ICSP block (that little isolated 6-pin block on top of the ardu). See [https://www.arduino.cc/en/Tutorial/ArduinoISP here] for a pinout. Then find Vcc and GND either on the ICSP block or elsewhere. Some sites say that on some boards you shouldn&#039;t use the pins on the ICSP block for this. I doubt it matters, though. Then connect another jumper wire from pin 10 on the ardu to work as the reset pin outwards to the chip being programmed (that is, on the printer). The ICSP jumper block pin layout is the same on the printer and on the ardu, and probably elsewhere. Sometimes [https://xkcd.com/927/ standardisation] actually works…&lt;br /&gt;
&lt;br /&gt;
When it&#039;s all wired up, change the setup in the Arduino IDE to use the Sanguino board (which may need to be installed there), the Atmega 1284 16MHz board with the programmer set to     &amp;quot;Arduino as ISP&amp;quot;. Also make sure to choose the right serial port. When all is done, choose Tools | Burn programmer and it should take a few seconds to finish.&lt;br /&gt;
&lt;br /&gt;
[[File:Ardu-nano-as-programmer.jpg|400px]]&lt;br /&gt;
&lt;br /&gt;
== Flashing the printer ==&lt;br /&gt;
&lt;br /&gt;
When the boot loader is in place, possibly after some wierd errors from during the process, the screen on the 3d printer will go blank and it&#039;ll behave like being bricked. This is ok. Now disconnect the wires and connect the USB cable between computer and printer. If you haven&#039;t installed support for the Sanguino board, that is, the variant of the 1284-chip and surrounding electronics that is the core of the, you need to install it first. In the Arduino IDE, choose the Tools / Boards / Boards manager boot option and search for Sanguino. After this, you should find the Sanguino or Sanguino 1284p in the boards menu. After this, you should be able to communicate with the printer&#039;s controller. Download the [https://www.th3dstudio.com/knowledgebase/th3d-unified-firmware-package/ TH3D unified firmware], making sure it&#039;s the last version. Uncompress the zip and with Finder/Explorer/whateversomething&#039;scalledonlinux, browse to &#039;&#039;&#039;TH3DUF_R2/Firmware/TH3DUF_R2.ino&#039;&#039;&#039; and open it. It should open directly in the Android IDE. Keep in mind that the names TH3DUF_R2 and TH3DUF_R2.ino will vary between versions, but you get the point. Now configure it for your particular needs. You&#039;ll find most of this in the Configuration.h tab (that&#039;s really a file). Most of the other files won&#039;t be necessary unless you&#039;re doing some more advanced stuff, like replacing th controller with something non-standard or similar, but then again, that&#039;s another chapter (or book, even). The video mentioned above describes this well. After flashing the new firmware, you&#039;ll probably get some timeouts and errors, since apparently it resets the printer after giving it the new firmware, but without notifying the flashing software of it doing so. If this happens, calm down and reboot the printer and check its tiny monitor - it should work. If it doesn&#039;t work, and if you flashed the bootload yourself, try to flash it again, and if that doesn&#039;t work, try flashing the programmer again yet another time, just for kicks. Again, if you have a newer controller like the v1.1.5, don&#039;t touch the bootloader, as the one already installed, should work well as it is.&lt;br /&gt;
&lt;br /&gt;
PS: I tried enabling &#039;&#039;&#039;MANUAL_MESH_LEVELING&#039;&#039;&#039;, which in the code says that &#039;&#039;If used with a 1284P board the bootscreen will be disabled to save space&#039;&#039;. This effectively disabled the whole printer, and apparently may be making the firmware image a wee bit too large for it to fit the 1284P on the ender. It works well without it, though, and it may be fixed by now, since I tested this back in early 2019.&lt;br /&gt;
&lt;br /&gt;
== And then… ==&lt;br /&gt;
&lt;br /&gt;
With the new firmware in place, the printer should work as before, although with thermal runaway protection to better avoid fires in case the shit hits the fan, and to allow for things like autolevelling. With any luck, [https://www.precisionpiezo.co.uk/ this thing] may be ready for use by the time you read this - it surely looks nice!&lt;br /&gt;
&lt;br /&gt;
= Octoprint/Octopi =&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;This could have been under some other section, but again, I just branch out even though most of it is about sections mentioned elsewhere.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
When setting up a 3d printer for the first time, you usually get an SD card for storage and transfer data to the printer using [https://en.wikipedia.org/wiki/Sneakernet Sneakernet]. Some printers use micro SD cards, while other fullsize SD cards, which imho is better, since they don&#039;t get lost that easily, but otherwise do the same thing. This works, but is somewhat tedious. If you want to control the printer from a PC or phone, there&#039;s a simple trick for that as well - octoprint.&lt;br /&gt;
&lt;br /&gt;
[https://octoprint.org/ Octoprint], written by Gina Häußge, runs on most platforms including linux, windows, BSD*, macos etc. It supports controlling a camera to some extent out of the box and there&#039;s a large number of plugins availablee to do a lot of things you possibly haven&#039;t thought of (and quite often, you&#039;d ever need). The easiest way to install it, is to just grab a Raspberry pi - preferably some of the newer models (will get to that later) and download [https://octoprint.org/download/ octopi] and follow the instructions on that page.&lt;br /&gt;
&lt;br /&gt;
== Performance issues ==&lt;br /&gt;
&lt;br /&gt;
Some report (and I have seen it myself) issues with the pi&#039;s performance with regards to both handling the octoprint processes (which should be as close to realtime as possible) and handling other stuff like I/O, networking etc. The point is that at pi3 or older, has all peripherals connected to an internal USB hub. This might be practical, but performance-wise it&#039;s &#039;&#039;&#039;&#039;&#039;not&#039;&#039;&#039;&#039;&#039;. If you in addition connect a webcam to USB, you&#039;re asking for trouble, since USB will be your bottleneck. With a raspberry pi camera, the ones connected to the pi directly with a ribbon cable, this should not use USB, so it&#039;s better. Still, again, for older pi&#039;s, there might be some shortage in therms of cpu or i/o. The octopi runs something like raspbian which is a fork of debian which is a linux distro, so it all boils down to knowing linux.&lt;br /&gt;
&lt;br /&gt;
Your typical octopi will run octoprint, a streamer, usually &#039;&#039;&#039;mjpg-streamer&#039;&#039;&#039;, a simple, lightweight videostreamer that outputs a stream of jpeg-images (about the same format as cinemas use - that is - not MPEG). This may be a bit tough on the cpu and potentially i/o. Add inn a dash of USB overload and you&#039;re may see trouble.&lt;br /&gt;
&lt;br /&gt;
Still - a pi3 should be able to handle the load, but it might help to prioritise corretly. The octoprint process is the important part here, so we could give that full priority both in CPU and I/O and. Unfortunately, it doesn&#039;t seem like the current octopi has been migrated to using systemd for the startup. We&#039;ll deal with this later. To fix this in the old SysV init style file present there, the following patch should work against the file /etc/init.d/octoprint&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;diff&amp;quot;&amp;gt;&lt;br /&gt;
--- octoprint.old	2020-07-20 18:46:10.166651965 +0200&lt;br /&gt;
+++ octoprint	2020-07-20 18:53:21.724803211 +0200&lt;br /&gt;
@@ -22,6 +22,9 @@&lt;br /&gt;
 PIDFILE=/var/run/$NAME.pid&lt;br /&gt;
 PKGNAME=octoprint&lt;br /&gt;
 SCRIPTNAME=/etc/init.d/$PKGNAME&lt;br /&gt;
+NICELEVEL=-19                        # Top CPU priority&lt;br /&gt;
+IONICE_CLASS=1                       # Realtime I/O class&lt;br /&gt;
+IONICE_PRIORITY=0                    # Realtime I/O priority (probably not needed with class=realtime)&lt;br /&gt;
&lt;br /&gt;
 # Read configuration variable file if it is present&lt;br /&gt;
 [ -r /etc/default/$PKGNAME ] &amp;amp;&amp;amp; . /etc/default/$PKGNAME&lt;br /&gt;
@@ -70,10 +73,11 @@&lt;br /&gt;
&lt;br /&gt;
    is_alive $PIDFILE&lt;br /&gt;
    RETVAL=&amp;quot;$?&amp;quot;&lt;br /&gt;
-&lt;br /&gt;
    if [ $RETVAL != 0 ]; then&lt;br /&gt;
        start-stop-daemon --start --background --quiet --pidfile $PIDFILE --make-pidfile \&lt;br /&gt;
-       --exec $DAEMON --chuid $OCTOPRINT_USER --user $OCTOPRINT_USER --umask $UMASK -- serve $DAEMON_ARGS&lt;br /&gt;
+       --exec $DAEMON --chuid $OCTOPRINT_USER --user $OCTOPRINT_USER --umask $UMASK \&lt;br /&gt;
+       --nicelevel $NICELEVEL --ioched $IONICE_CLASS:$IONICE_PRIORITY \&lt;br /&gt;
+       --serve $DAEMON_ARGS&lt;br /&gt;
        RETVAL=&amp;quot;$?&amp;quot;&lt;br /&gt;
    fi&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This ismply upgrades the process to be allowed to use most of the resources on the pi, regardless of what other processes are whining about.&lt;br /&gt;
&lt;br /&gt;
PS: Code not tested - I don&#039;t have a pi right here. Will test later, but I&#039;m pretty sure it&#039;ll work. After all, it&#039;s just a few new arguments to start-stop-daemon&lt;br /&gt;
&lt;br /&gt;
roy&lt;/div&gt;</summary>
		<author><name>Roy</name></author>
	</entry>
	<entry>
		<id>https://wiki.malinux.no/index.php?title=Roy%27s_notes&amp;diff=185</id>
		<title>Roy&#039;s notes</title>
		<link rel="alternate" type="text/html" href="https://wiki.malinux.no/index.php?title=Roy%27s_notes&amp;diff=185"/>
		<updated>2020-11-14T23:08:08Z</updated>

		<summary type="html">&lt;p&gt;Roy: /* Using an arduino Nano as a programmer */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= LVM, md and friends =&lt;br /&gt;
&lt;br /&gt;
== Linux&#039; Logical Volume Manager (LVM) ==&lt;br /&gt;
&lt;br /&gt;
=== LVM in general ===&lt;br /&gt;
&lt;br /&gt;
LVM is designed to be an abstraction layer on top of physical drives or RAID, typically [https://raid.wiki.kernel.org/index.php/RAID_setup mdraid] or [https://help.ubuntu.com/community/FakeRaidHowto fakeraid]. Keep in mind that fakeraid should be avoided unless you really need it, like in conjunction with dual-booting linux and windows on fakeraid. LVM broadly consists of three elements, the &amp;quot;physical&amp;quot; devices (PV), the volume group (VG) and the logical volume (LV). There can be multiple PVs, VGs and LVs, depending on requirement. More about this below. All commands are given as examples, and all of them can be fine-tuned using extra flags in need of so. In my experience, the defaults work well for most usecases.&lt;br /&gt;
&lt;br /&gt;
I&#039;m mentioning filesystem below too. Where I write ext4, the samme applies to ext2 and ext3.&lt;br /&gt;
&lt;br /&gt;
==== Create a PV ====&lt;br /&gt;
&lt;br /&gt;
A PV is the &amp;quot;physical&amp;quot; parts. This does not need to be a physical disk, but can also be another RAID, be it an mdraid, fakeraid, hardware raid, a virtual disk on a SAN or otherwisee or a partition on one of those. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#  These add three PVs, one on a drive (or hardware raid) and another two on mdraids.&lt;br /&gt;
pvcreate /dev/sdb&lt;br /&gt;
pvcreate /dev/md1 /dev/md2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For more information about pvcreate, see [https://linux.die.net/man/8/pvcreate the manual].&lt;br /&gt;
&lt;br /&gt;
==== Create a VG ====&lt;br /&gt;
&lt;br /&gt;
The volume group consists of one or more PVs grouped together on which LVs can be placed. If several PVs are grouped in a VG, it&#039;s generally a good idea to make sure these PVs have some sort of redundancy, as in mdraid/fakeraid or hwraid. Otherwise it will be like using a [https://en.wikipedia.org/wiki/RAID RAID-0] with a single point of failure on each of the independant drives. LVM has [https://unix.stackexchange.com/questions/150644/raiding-with-lvm-vs-mdraid-pros-and-cons  RAID code in it] as well, so you can use that. I haven&#039;t done so myself, as I generally stick to mraid. The reason is mdraid is, in my opinion older and more stable and has more users (meaning bugs are reported and fixed faster whenever they are found). That said, I beleive the actual RAID code used in LVM RAID are the same function calls as for mdraid, so it may not be much of a difference. I still stick with mdraid. To create a VG, run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create volume group my_vg&lt;br /&gt;
vgcreate my_vg /dev/md1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that if vgcreate is run with a PV (as /dev/md1 above) that is not defined as a PV (like above), this is done implicitly, so if you don&#039;t need any special flags to pvcreate, you can simply skip it and let vgcreate do that for you.&lt;br /&gt;
&lt;br /&gt;
==== Create an LV ====&lt;br /&gt;
&lt;br /&gt;
LVs can be compared to partitions, somehow, since they are bounderies of a fraction or all of that of a VG. The difference between them and a partition, however, is that they can be grown or shrunk easily and also moved around between PVs without downtime. This flexibility makes them superiour to partitions as your system can be changed without users noticing it. By default, an LV is alloated &amp;quot;thickly&amp;quot;, meaning all the data given to it, is allocated from the VG and thus the PV. The following makes a 100GB LV named &amp;quot;thicklv&amp;quot;. When making an LV, I usually allocate what&#039;s needed plus some more, but not everything, just to make sure it&#039;s space available for growth on any of the LVs on the VG, or new LVs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a thick provisioned LV named thicklv on the VG my_vg&lt;br /&gt;
lvcreate -n thicklv -L 100G my_vg&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After the LV is created, a filesystem can be placed on it unless it is meant to be used directly. The application for direct use include swap space, VM storage and certain database systems. Most of these will, however, work on filesystems too, although my testing has shown that on swap space, there is a significant performance gain for using dedicated storage without a filesystem. As for filesystems, most Linux users use either ext4 or xfs. Personally, I generally use XFS these days. See my notes below on filesystem choice.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a filesystem on the LV - this could have been mkfs -t ext4 or whatever filesystem you choose&lt;br /&gt;
mkfs -t xfs /dev/my_vg/thicklv&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then just edit /etc/fstab with correct data and run mount -a, and you should be all set.&lt;br /&gt;
&lt;br /&gt;
==== Create LVM cache ====&lt;br /&gt;
LVMcache is LVM&#039;s solution to caching a slowish filesystem on spinning rust with the help of much faster SSDs. For this to work, use a separate SSD or a mirror or two (just in case) an add the new disk/md dev to the same VG. In this case, we use a small mirror, md1. LVM is not able to cache to a disk or partition outside the volume group.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
vgextend data /dev/md1&lt;br /&gt;
  Physical volume &amp;quot;/dev/md1&amp;quot; successfully created.&lt;br /&gt;
  Volume group &amp;quot;data&amp;quot; successfully extended&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Thn create two LVs, one for the data (contents of files) and one for the metadata (filenames, directories, attributes etc). Typically, the metadata part won&#039;t need to be very large. 100M should usually do unless you have ekstremely many small files. I guess there are ways to calculate it, but again, 1GB should do for everyone (or was that 640k?). As for the data cache, I chose to use 40G here for a 15TB RAID. It will only cache what actively use anyway, so no need for overkill.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
lvcreate -L 1G -n _cache_meta data /dev/md1&lt;br /&gt;
lvcreate -L 100G -n _cache data /dev/md1&lt;br /&gt;
&lt;br /&gt;
# Some would want --cachemode writeback, but if paranoid, I wouldn&#039;t recommend it. Metadata or data can be easily corrupted in case of failure. Most filesystems will however recover from this these days since they use journaling. It &#039;&#039;really&#039;&#039; speeds up things.&lt;br /&gt;
lvconvert --type cache-pool --cachemode writethrough --poolmetadata data/_cache_meta data/_cache&lt;br /&gt;
lvconvert --type cache --cachepool data/_cache data/data&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
That should be it. If you benchmarked the disk before this, you should try again and you&#039;ll probably get a nice surprise. If not, well, see below how to turn this off again :)&lt;br /&gt;
&lt;br /&gt;
==== Disabling LVM cache ====&lt;br /&gt;
&lt;br /&gt;
If you want to change the cached LV, such as growing og shrinking or otherwise, you&#039;ll have to disable caching first and then re-enable it. There&#039;s no quick-and-easy fix, but you just do as you did when enabling in the first place. &lt;br /&gt;
&lt;br /&gt;
Forst, disable caching for the LV. This will do it cleanly and remove the LVs earlier created for caching the main device. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
lvconvert --uncache data/data&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, since you now have a VG with an empty PV in it, earlier used for caching, I&#039;d recommend removing this for now to avoid expanding onto that as well. Since they&#039;re in the same VG, this might happen and if you get so far as to extend the lv and the filesystem on it, and this filesystem is XFS or similar filesystems without possibilities of reducing the size, you have a wee problem. &lt;br /&gt;
&lt;br /&gt;
Just remove that PV from the VG&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
vgreduce data /dev/md1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The PV is still there, but pvs should now show it not connected to a VG&lt;br /&gt;
&lt;br /&gt;
==== Growing devices ====&lt;br /&gt;
&lt;br /&gt;
LVM objects can be grown and shrunk. If a PV resides on a RAID where a new drive has been added or otherwise grown, or on a partition or virtual disk that has been extended, the PV must be updated to reflect these changes. The following command will grow the PV to the maximum available on the underlying storage. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Resize the PV /dev/md (not the RAID, only the PV on the RAID) to its full size&lt;br /&gt;
pvresize /dev/md1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If a new PV is added, the VG can be grown to add the space on that in addition to what&#039;s there already. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Extend my_vg to include md2 and its space&lt;br /&gt;
vgextend my_vg /dev/md2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
With more space available in the VG, the LV can now be extended. Let&#039;s add another 50GB to it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Extend thicklv - add 50GB. If you know you won&#039;t need the space anywhere else, you may want to&lt;br /&gt;
# lvresize -l+100%FREE instead. Keep in mind the difference between -l (extents) and -L (bytes)&lt;br /&gt;
lvresize -L +50G my_vg/thicklv&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Growing filesystems ====&lt;br /&gt;
After the LV has grown, run &#039;&#039;xfs_growfs&#039;&#039; (xfs) or &#039;&#039;resize2fs&#039;&#039; (ext4) to make use of the new data. To grow the filesystem to all available space on ext4, run the below command.  To partly grow the filesystem or to shrink it or otherwise, please see the manuals.&lt;br /&gt;
&lt;br /&gt;
The filesystem can be mounted when this is run. If you for some reason get an &#039;&#039;&#039;access denied&#039;&#039;&#039; error when running this as root or with sudo, it&#039;s likely caused by a filesystem error. To fix this, unmount the filesystem first and run &#039;&#039;&#039;fsck -f /dev/my_vg/thicklv&#039;&#039;&#039; and remount it before retrying to extend it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
resize2fs /dev/my_vg/thicklv&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Similarly, with XFS, but note that xfs_growfs doesn&#039;t take the device name, but the filesystem&#039;s mount point. In the case of XFS, also note that the filesystem &#039;&#039;&#039;&#039;&#039;must&#039;&#039;&#039;&#039;&#039; be mounted to be grown. This, in contrast to how it was in the old days when filesystems had to be unmounted to be grown.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
xfs_growfs /my_mountpoint&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Rename system VG ====&lt;br /&gt;
&lt;br /&gt;
Some distros create VG names like those-from-a-sysadmin-with-a-well-developed-paranoia-not-to-hit-a-duplicate. Debian, for instance, uses names like &amp;quot;my-full-hostname-vg&amp;quot;. Personally, I don&#039;t like these, since if I were to move a disk or vdisk around to somewhere else, I&#039;d make sure not to add a disk named &#039;sys&#039; to an existing system. If you do, most distros will refuse to use the VGs with duplicate names, resulting in the OS not booting until either one is specified by its UUID or just one removed. As I&#039;m aware of this, I stick to the super-risky thing of all system VGs named &#039;sys&#039; and so on.&lt;br /&gt;
&lt;br /&gt;
If you do this, keep in mind that it may blow up your computer and take your girl- or boyfriend with it or even make either of them pregnant, allowing Trump to rule your life and generally make things suck. You&#039;re on your own!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Rename the VG&lt;br /&gt;
vgrename my-full-hostname-vg sys&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, in /boot/grub/grub.cfg, change the old lv path from something like &#039;/dev/mapper/debian--stretch--machine--vg-root&#039; to your new and fancy &#039;/dev/sys/root. Likewise, in /etc/fstab, change occurences of &#039;/dev/mapper/debian--stretch--machine--vg-&#039; (or similar) with &#039;/dev/sys/&#039;. Here, this was like this - the old ones commented out.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;fstab&amp;quot;&amp;gt;&lt;br /&gt;
#/dev/mapper/debian--stretch--box--vg-root      /               ext4            errors=remount-ro,discard       0       1&lt;br /&gt;
/dev/sys/root                                   /               ext4            errors=remount-ro,discard       0       1&lt;br /&gt;
# /boot was on /dev/vda1 during installation&lt;br /&gt;
UUID=myverylonguuidwithatonofgoodinfoinit       /boot           ext2            defaults                        0       2&lt;br /&gt;
#/dev/mapper/debian--stretch--box--vg-swap_1    none            swap            sw                              0       0&lt;br /&gt;
/dev/sys/swap_1                                 none            swap            sw                              0       0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Update /etc/initramfs-tools/conf.d/resume with similar data for swap.&lt;br /&gt;
&lt;br /&gt;
You might want to run &#039;update-initramfs -u -k all&#039; after this, but I&#039;m not sure if it&#039;s needed.&lt;br /&gt;
&lt;br /&gt;
Now, pray to the nearest god(s) and give it a reboot and it should (probably) work.&lt;br /&gt;
&lt;br /&gt;
After reboot, run &#039;&#039;&#039;swapoff -a&#039;&#039;&#039;, then &#039;&#039;&#039;mkswap /dev/sys/swap_1&#039;&#039;&#039; (or whatever it&#039;s called on your system) and &#039;&#039;&#039;swapon -a&#039;&#039;&#039; again. You may want to give it another reboot or two for kicks, but it should work well even without that.&lt;br /&gt;
&lt;br /&gt;
=== Migration tools ===&lt;br /&gt;
&lt;br /&gt;
At times, storage regimes change, new storage is added and sometimes it&#039;s not easy to migrate with the current hardware or its support systems. Once I had to migrate a 45TiB fileserver from one storage system to another, preferably without downtime. The server originally had three 15TiB PVs of which two were full and the third half full. I resorted to using [https://linux.die.net/man/8/pvmove pvmove] to just move the data on the PVs in use to a new PV. We started out with creating a new 50TiB PV, sde, and then to pvmove.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Attach /dev/sde to the VG my_vg&lt;br /&gt;
vgextend my_vg /dev/sde&lt;br /&gt;
&lt;br /&gt;
# Move the contents from /dev/sdb over to /dev/sde block by block. If a target is not given in pvmove,&lt;br /&gt;
# the contents of the source (sdb here) will be put somewhere else in the pool.&lt;br /&gt;
pvmove /dev/sdb /dev/sde&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This took a while (as in a week or so) - the pvmove command uses old code and logic (or at least did that when I migrated this in November 2016), but it affected performance on the server very little, so users didn&#039;t notice. After the first PV was migrated, I continued with the other two, one after the other, and after a month or so, it was migrated. We used this on a number of large fileservers, and it worked flawlessly. Before doing the production servers I also tried interrupting pvmove in various ways, including hard resets, and it just kept on after the reboot.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;NOTE:&#039;&#039;&#039;&#039;&#039; &#039;&#039;Even though it worked well for us, &#039;&#039;&#039;always&#039;&#039;&#039; keep a good backup before doing this. Things may go wrong, and without a good backup, you may be looking for a hard-to-find new job the next morning&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
==== mdadm workarounds ====&lt;br /&gt;
&lt;br /&gt;
===== Migrate from a mirror (raid-1) to raid-10 =====&lt;br /&gt;
&lt;br /&gt;
Create a mirror&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sdb /dev/sdc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
LVM (pv/vg/lv) on md0 (see above), put a filesystem on the lv and fill it with some data.&lt;br /&gt;
&lt;br /&gt;
Now, some months later, you want to change this to raid-10 to allow for the same amount of redundancy, but to allow more disks into the system.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mdadm --grow /dev/md0 --level=10&lt;br /&gt;
mdadm: Impossibly level change request for RAID1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So - no - doesn&#039;t work. But - we&#039;re on &lt;br /&gt;
&lt;br /&gt;
Since we&#039;re on lvm already, this&#039;ll be easy. If you&#039;re using filesystems directly on partitions, you can do this the same way, but without the pvmove part, using rsync or whateever you like instead. I&#039;d recommend using lvm for for the new raid, which should be rather obvious from this article. Now plug in a new drive and create a new raid10 on that one. If you two new drives, install both. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# change &amp;quot;missing&amp;quot; to the other device name if you installed two new drives&lt;br /&gt;
mdadm --create /dev/md1 --level=10 --raid-devices=2 /dev/vdd missing&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, as described above, just vgextend the vg, adding the new raid and run pvmove to move the data from the old pv (residing on the old raid1) to the new pv (on raid10). Afte rpvmove is finished (which may take awile, see above), just&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
vgreduce raidtest /dev/md0&lt;br /&gt;
pvremove /dev/md0&lt;br /&gt;
mdadm --stop /dev/md0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
…and your disk is free to be added to the new array. If the new raid is running in degraded mode (if you created it with just one drive), better don&#039;t wait too long, since you don&#039;t have redundancy. Just mdadm --add the devs.&lt;br /&gt;
&lt;br /&gt;
If you now have /dev/mdstat telling you your raid10 is active and have three drives, of which one is a spare, it should look something like this&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5] [raid4] [raid10]&lt;br /&gt;
md1 : active raid10 vdc[3](S) vdb[2] vdd[0]&lt;br /&gt;
      8380416 blocks super 1.2 2 near-copies [2/2] [UU]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Just mdadm --grow --raid-devices=3 /dev/md1&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;RAID section is not complete. I&#039;ll write more on migraing from raid10 to raid6 later. It&#039;s not straight forward, but easier than this one :)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== Thin provisioned LVs ===&lt;br /&gt;
&lt;br /&gt;
Thin provisioning on LVM is a method used for not allocating all the space given to an LV. For instance, if you have a 1TB VG and want to give an LV 500GB, although it currently only uses a fraction of that, a thin lv can be a good alternative. This will allow for adding a limit to how much it can use, but also to let it grow dynamically without manual work by the sysadmin. Thin provisioning adds another layer of abstaction by creating a special LV as a &#039;&#039;thin pool&#039;&#039; from which data is allocated to the &#039;&#039;thin volume(s)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== Create a thin pool ====&lt;br /&gt;
&lt;br /&gt;
Allocate 1TB to the thin pool to be used for thinly provisioned LVs. Keep in mind that the space allocated to the thin pool is in fact thick provisioned. Only the volumes put on &#039;&#039;thinpool&#039;&#039; are thin provisioned. This will create two hidden LVs, one for data and one for metadata. Normally the defaults will do, but check the manual if the data doesn&#039;t match the usual patterns (such as billions of files, resulting in huge amounts of metadata). I &#039;&#039;beleive&#039;&#039; the metadata part should be resizable at a later time if needed, but I have not tested it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a pool for thin LVs. Keep in mind that the pool itself is not thin provisioned, only the volumes residing on it&lt;br /&gt;
lvcreate --size 1T --type thin-pool --thinpool thinpool my_vg&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Create a thin volume ====&lt;br /&gt;
&lt;br /&gt;
You have the thinpool, now put a thin volume on it. It will allocate some space for metadata, but probably not much (a few megs, perhaps).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Now, create a volume with a virtual (-V) size of half a terabyte named thin_pool, but using the thinpool (-T) named thin_pool for storage&lt;br /&gt;
lvcreate -V 500G -T my_vg/thin_pool --name thinvol&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The new volume&#039;s device name will be /dev/thinvol. Now, create a filesystem on it, add to fstab and mount it. The &#039;&#039;&#039;df&#039;&#039;&#039; command will return available space according to the virtual size (-V), while lvs will show how much data is actually used on each of the thinly provisioned volumes.&lt;br /&gt;
&lt;br /&gt;
== Filesystem dilemmas ==&lt;br /&gt;
&lt;br /&gt;
=== XFS or ext4 or something else ===&lt;br /&gt;
The choice of filesystem varies for your use. Distros such as RHEL/CentOS has moved to XFS by default from v7. Debian/Ubuntu still sticks to ext4, like most other. I&#039;ll discuss my thoughts below on ext4 vs XFS and leave the other filesystems for later.&lt;br /&gt;
&lt;br /&gt;
==== ext4 ====&lt;br /&gt;
ext4 is probably the most used filesystem on linux as of writing. It&#039;s rock stable and has been extended by a lot of extensions since the original ext2. It still retains backward compatibility, being able to mount and fsck ext2 and ext3 with the ext4 driver. However, it doesn&#039;t handle large filesystems very well. If a filesystem is created for &amp;lt;16TiB, it cannot be grown to anything larger than 16TiB. This may have changed lately, though. One other issue is handling errors. If a large filesystem (say 10TiB) is damaged, an fsck may take several hours, leading to long downtime. When I refer to ext4 further in this text, the same applies to ext2 and ext3 unless otherwise specified.&lt;br /&gt;
&lt;br /&gt;
==== XFS ====&lt;br /&gt;
XFS, originally developed by SGI some time in the bronze age, but has been worked on heavily after that. RHEL and Centos version 7 and forward, uses XFS as the default filesystem. It is quick, it scales well, but it lacks at least two things ext4 has. It cannot be shrunk (not that you normally need that, but nice if you have a typo or you need to change things). Also, it doesn&#039;t allow for automatic fsck on bootup. If something is messed up on the filesystem, you&#039;ll have to login as root on the console (not ssh), which might be an issue on some systems. The fsck equivalent, xfs_repair, is a *lot* faster than ext4&#039;s fsck, though.&lt;br /&gt;
&lt;br /&gt;
==== ZFS ====&lt;br /&gt;
ZFS is like a combination of RAID, LVM and a filesystem, supporting full checksumming, auto-healing (given sufficient redundancy), compression, encryption, replication, deduplication (if you&#039;re brave and have a &#039;&#039;ton&#039;&#039; of memory) and a lot more. It&#039;s a separate chapter and needs a lot more talk than paragraph here.&lt;br /&gt;
&lt;br /&gt;
==== btrfs ====&lt;br /&gt;
btrfs, pronounced &amp;quot;butterfs&amp;quot; or &amp;quot;betterfs&amp;quot; or just spelled out, is a filesystem that mimics that of ZFS. It has been around for 10 years or so, but hasn&#039;t yet proven to be really stable. Following the progress of it for those years, I&#039;ve found it to be a nice toy with which to play, but not to be used in production. Again, others may say otherwise, but these are just my words.&lt;br /&gt;
&lt;br /&gt;
== Low level disk handling ==&lt;br /&gt;
&lt;br /&gt;
This section is for low-level handling of disks, regardless of storage system elsewhere. These apply to mdraid, lvmraid and zfs and possibly other solutions, with the exception of individual drives on hwraid (and maybe fakeraid), since there, the drives are hidden from Linux (or whatever OS).&lt;br /&gt;
&lt;br /&gt;
=== S.M.A.R.T. and slow drives ===&lt;br /&gt;
Modern (that is, from about 1990 or later) have S.M.A.R.T. (or just smart, since it&#039;s easier to type) monitoring built in, meaning the disk&#039;s controller is monitoring itself. This is handy and will ideally tell you in advance that a drive is flakey or dying. Modern (2010+) smart monitoring is more or less the same. It can be trusted about 50% of the time. Usually, if smart detects an error, it&#039;s a real error. I don&#039;t think I&#039;ve seen it reporting a false positive, but others may know better. &lt;br /&gt;
&lt;br /&gt;
==== smartmontools ====&lt;br /&gt;
First, install smartmontool and run smartclt -H /dev/yourdisk (/dev/sda or something) to get a health report. Then perhaps run smartctl -a /dev/yourdisk and look for &#039;current pending sectors&#039; This should be zero. Also check the temperature, which normally should be much above 50.&lt;br /&gt;
&lt;br /&gt;
==== single, slow drive ====&lt;br /&gt;
What may happen, is smart not seeing anything and life goes on like before, only slower and less prouductive, without telling anyone. If you stubler over this issue, you&#039;ll probably see it during a large rsync/zfs send/receive or a resync/rebuild/resilver of the raid/zpool. During this, it feels like everything is slow and your RAID has turned into a RAIF (redundant array of inexpensive floppies). To check if you have a single drive messing up it all, check with &#039;&#039;&#039;iostat -x 2&#039;&#039;&#039;, having 2 being the delay between each measurement. Interrupt it with ctrl+x. If there&#039;s a rougue drive there, it should stand out like sdg below&lt;br /&gt;
&lt;br /&gt;
 avg-cpu:  %user   %nice %system %iowait  %steal   %idle&lt;br /&gt;
            0.38    0.00    1.75    0.00    0.00   97.87&lt;br /&gt;
&lt;br /&gt;
 Device            r/s     w/s     rkB/s     wkB/s   rrqm/s   wrqm/s  %rrqm  %wrqm r_await w_await aqu-sz rareq-sz wareq-sz  svctm  %util&lt;br /&gt;
 sda              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdb              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdc              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdd              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sde              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdf              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdg              3.50    0.00   2352.00      0.00     0.00     0.00   0.00   0.00 14306.29    0.00  13.85   672.00     0.00 285.71 100.00&lt;br /&gt;
 sdh              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
&lt;br /&gt;
In ZFS land, you should be able to get similar data with &#039;&#039;&#039;zpool iostat -v &amp;lt;pool&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Now you know the bad drive (sdg), pull it from the raid with &#039;&#039;&#039;mdadm --fail /dev/mdX /dev/sdX&#039;&#039;&#039;. Now test the drive&#039;s performance manually, just simply:&lt;br /&gt;
&lt;br /&gt;
 # hdparm -t /dev/sdg&lt;br /&gt;
 &lt;br /&gt;
 /dev/sdg:&lt;br /&gt;
  Timing buffered disk reads:   2 MB in  5.37 seconds = 381.46 kB/sec&lt;br /&gt;
&lt;br /&gt;
Bingo - nothing you&#039;d want to keep. For a good drive, it should be something like 100-200MB/s&lt;br /&gt;
&lt;br /&gt;
PS: Keep in mind that you have a degraded RAID by now in case you had a spare waiting for things to happen.&lt;br /&gt;
&lt;br /&gt;
Try to replace the cable and/or try the disk on another port/controller. If the result from hdparm persists, it&#039;s probably a bad cable&lt;br /&gt;
&lt;br /&gt;
So, then, just psycially locate the drive, pull it out, take out the discs and magnets and recycle the rest.&lt;br /&gt;
&lt;br /&gt;
=== &amp;quot;Unplug&amp;quot; drive from system ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Find the device unit&#039;s number with something like&lt;br /&gt;
find /sys/bus/scsi/devices/*/block/ -name sdd&lt;br /&gt;
# returning /sys/bus/scsi/devices/3:0:0:0/block/sdd here, &lt;br /&gt;
# meaning 3:0:0:0 is the SCSI device we&#039;re looking for.&lt;br /&gt;
&lt;br /&gt;
# Given this is the correct device, and you want to &#039;unplug&#039; it, do so by&lt;br /&gt;
echo 1 &amp;gt; /sys/bus/scsi/devices/3:0:0:0/delete&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Rescan disk controllers ===&lt;br /&gt;
If a drive is added and for some reason doesn&#039;t get detected, or is removed by the command above, it can be rediscovered with a sysfs command to the scsi host to which it is connected. Since there may be quite a few of these, an easy way is to just scan them all and check the output of &#039;&#039;&#039;dmesg -T&#039;&#039;&#039; after running it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Make a list of controllers and send a rescan message to each of them. It won&#039;t do anything &lt;br /&gt;
# for those where nothing has changed, but it will show new drives where they have been added.&lt;br /&gt;
for host_scan in /sys/class/scsi_host/host*/scan&lt;br /&gt;
do&lt;br /&gt;
  echo &#039;- - -&#039; &amp;gt; $host_scan&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Fail injection with debugfs ===&lt;br /&gt;
[https://lxadm.com/Using_fault_injection https://lxadm.com/Using_fault_injection]&lt;br /&gt;
&lt;br /&gt;
== mdadm stuff ==&lt;br /&gt;
=== Resync ===&lt;br /&gt;
To resync a raid, that is, check, run&lt;br /&gt;
&lt;br /&gt;
 echo check &amp;gt; /sys/block/$dev/md/sync_action&lt;br /&gt;
&lt;br /&gt;
where $dev is something like md0. If you have several raids, something like this should work&lt;br /&gt;
&lt;br /&gt;
 for dev in md{0,1}&lt;br /&gt;
 do&lt;br /&gt;
   echo repair &amp;gt; /sys/block/$dev/md/sync_action&lt;br /&gt;
 done&lt;br /&gt;
&lt;br /&gt;
Also useful in a one-liner like&lt;br /&gt;
&lt;br /&gt;
 for dev in md{0,1} ; do echo repair &amp;gt; /sys/block/$dev/md/sync_action ; done&lt;br /&gt;
&lt;br /&gt;
Different raids on different drives will do this in parallel. If the drives are shared somehow with partitions or similar, the check or repair will wait for the other to finish before going on.&lt;br /&gt;
&lt;br /&gt;
As for repair vs check, [https://raid.wiki.kernel.org/index.php/RAID_Administration this article] describes it well. I stick to using repair unless it&#039;s something rare where I don&#039;t want to touch the data.&lt;br /&gt;
&lt;br /&gt;
=== Spare pools ===&lt;br /&gt;
In the old itmes, mdadm supported only a dedicated spare per md device, so if working with a large set of drives (20? 40?), where you&#039;d want to setup more raid sets to increase redundancy, you&#039;d dedicate a spare to each of the raid sets. This has changed (some time ago?), so in these modern, heathen days, you can change mdadm.conf, usually placed under /etc/mdadm, and add &#039;spare-group=somegroup&#039; where &#039;somegroup&#039; is a string identifying the spare group. After doing this, run &#039;&#039;&#039;update-initramfs -u&#039;&#039;&#039; and reboot and add a spare to one of the raid sets in the spare group, and md will use that or those spares for all the raidsets in that group.&lt;br /&gt;
&lt;br /&gt;
As some pointed out on #linux-raid @ irc.freenode.net, this feature is very badly documented, but as far as I can see, it works well.&lt;br /&gt;
&lt;br /&gt;
==== Example config ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create two raidsets&lt;br /&gt;
&lt;br /&gt;
mdadm --create /dev/md1 --level=6 --raid-devices=6 /dev/vd[efghij]&lt;br /&gt;
mdadm --create /dev/md2 --level=6 --raid-devices=6 /dev/vd[klmnop]&lt;br /&gt;
&lt;br /&gt;
# get their UUID etc&lt;br /&gt;
&lt;br /&gt;
mdadm --detail --scan&lt;br /&gt;
ARRAY /dev/md/1 metadata=1.2 name=raidtest:1 UUID=1a8cbdcb:f4092350:348b6b80:c054d74c&lt;br /&gt;
ARRAY /dev/md/2 metadata=1.2 name=raidtest:2 UUID=894b1b7c:cb7eba70:917d6033:ea5afd2b&lt;br /&gt;
&lt;br /&gt;
# Put those lines into /etc/mdadm/mdadm.conf and and add the spare-group&lt;br /&gt;
&lt;br /&gt;
ARRAY /dev/md/1 metadata=1.2 name=raidtest:1 spare-group=raidtest UUID=1a8cbdcb:f4092350:348b6b80:c054d74c&lt;br /&gt;
ARRAY /dev/md/2 metadata=1.2 name=raidtest:2 spare-group=raidtest UUID=894b1b7c:cb7eba70:917d6033:ea5afd2b&lt;br /&gt;
&lt;br /&gt;
# update the initramfs and reboot&lt;br /&gt;
&lt;br /&gt;
update-initramfs -u&lt;br /&gt;
reboot&lt;br /&gt;
&lt;br /&gt;
# add a spare drive to one of the raids&lt;br /&gt;
&lt;br /&gt;
mdadm --add /dev/md1 /dev/vdq&lt;br /&gt;
&lt;br /&gt;
# fail a drive on the other raid&lt;br /&gt;
&lt;br /&gt;
mdadm --fail /dev/md2 /dev/vdn&lt;br /&gt;
&lt;br /&gt;
# check /proc/mdstat to see md2 rebuilding with the spare from md1&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Recovery ===&lt;br /&gt;
&lt;br /&gt;
The other day, I came across a problem a user had on #linux-raid@irc.freenode.net. He had an old Qnap NAS that had died and tried plugging the drives in to his Linux machine and got various errors. The two-drive RAID-1 did not come up as it should, &#039;&#039;&#039;dmesg&#039;&#039;&#039; was full of errors from one of the drives (both connected on USB) and so forth.&lt;br /&gt;
&lt;br /&gt;
We went on and started by taking down the machine and just connecting one of the drives. I had him check what was assembled with&lt;br /&gt;
&lt;br /&gt;
 cat /proc/mdstat&lt;br /&gt;
&lt;br /&gt;
That returned /proc/md127 assembled, but LVM didn&#039;t find anything. So running a manual scan&lt;br /&gt;
&lt;br /&gt;
 pvscan --cache /dev/md127&lt;br /&gt;
&lt;br /&gt;
This made linux find the PV, VG and a couple of LVs, but probably because the mdraid was degraded, the LVs were deactivated, according to &#039;&#039;&#039;lvscan&#039;&#039;&#039;. Activating the one with a filesystem manually&lt;br /&gt;
&lt;br /&gt;
 lvchange -a y /dev/&amp;lt;vg&amp;gt;/&amp;lt;lv&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Substitute &amp;lt;vg&amp;gt; and &amp;lt;lv&amp;gt; with the names listed by vgs and lvs.&lt;br /&gt;
&lt;br /&gt;
This worked, and the filesystem on /dev/&amp;lt;vg&amp;gt;/&amp;lt;lv&amp;gt; could be mounted correctly.&lt;br /&gt;
&lt;br /&gt;
=== Renaming a RAID ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Not finished&#039;&#039;&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
&lt;br /&gt;
Back around 2001, I asked on the linux-raid list for disk tagging, not default back then, but supported, and thought of the possibility of disk #1 getting replaced with disk #1 from another raid because of a messup. After this, the hostname was added to the raid name in the superblock. So when a RAID is created, it is named &amp;quot;hostname:raidname&amp;quot;, where the raidname is either a number (0,1...) or a name. &lt;br /&gt;
&lt;br /&gt;
For instance, running this on my VM named &amp;quot;raidtest&amp;quot;:&lt;br /&gt;
&lt;br /&gt;
 mdadm --create --level=1 --raid-devices=2 /dev/md/stuff /dev/sd[st]&lt;br /&gt;
&lt;br /&gt;
mdadm --detail --scan now shows this&lt;br /&gt;
&lt;br /&gt;
 ARRAY /dev/md/stuff metadata=1.2 name=raidtest:stuff UUID=c4cdf69f:393a28b1:47648ed3:726613de&lt;br /&gt;
&lt;br /&gt;
Now, you might want to change this name for some reason, and it&#039;s not supported under &amp;quot;grow&amp;quot;, so what to do… The name is, after all, local to the disk, since it&#039;s there to avoid messing up a raid (or two) after a disk mixup.&lt;br /&gt;
&lt;br /&gt;
 mdadm --assemble /dev/md/stuff --name &#039;someotherhost:stuff&#039; --update=homehost /dev/sd[st]&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== The badblock list ===&lt;br /&gt;
&#039;&#039;&#039;md&#039;&#039;&#039; has an internal badblock list (BBL), added around 2010, to list the bad blocks on the disk to avoid using those. While this might sound like a good idea, the badblock list is updated in case of a read error, which can be caused by several things. To make things worse, the BBL is replicated to other drives when a drive fails or the array is grown. So if you start out with sda and sdb and sdb suffers some errors, nothing wrong, md will read from sda, but flag those sectors on sdb as bad. So after a while, perhaps sda dies and gets replaced, with the same content, including the BBL. Then, at some point you might to replace sdb and it, too gets the BBL. So it sticks - forever. Also, there&#039;s no real point of keeping a BBL list, since the drive has its own and even if a sector error occurs, the array will have sufficient redundancy to recover from that (unless you use RAID-0 which you shouldn&#039;t). If a drive finds a bad sector, it&#039;ll be reallocated by the drive itself without the user&#039;s/admin&#039;s/system&#039;s knowledge. If a sector can&#039;t be reallocated, it means the drive is bad and should be replaced.&lt;br /&gt;
&lt;br /&gt;
There&#039;s no official way to remove it and although you can assemble it with the no-bbl option, this will only work if there&#039;s an empty BBL. Also, this will require downtime. As far as I can see, the only way to do this currently, is with a wee hack that should work. Just replace the names of mddev/diskdev with your own.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
mddev=&amp;quot;/dev/md0&amp;quot;&lt;br /&gt;
diskdev=&amp;quot;/dev/sda&amp;quot;&lt;br /&gt;
mdadm $mddev --fail $diskdev --remove $diskdev --re-add $diskdev --update=no-bbl&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If there&#039;s a BBL on the drive already, replace the --update part to &#039;force-no-bbl&#039;. This is not documented anywhere as per se, but it works.&lt;br /&gt;
 &lt;br /&gt;
I haven&#039;t found a way to turn this off permanently, but there may be something coming around when the debate on the linux-raid mailing list closes up on this. There&#039;s a bbl=no in mdadm.conf, but that&#039;s only for creation. I will continue extensive testing for this.&lt;br /&gt;
&lt;br /&gt;
== Tuning ==&lt;br /&gt;
&lt;br /&gt;
While trying to compare a 12-disk RAID (8TB disks) to a hwraid, mdraid was slower, so we did a few things to speed things up:&lt;br /&gt;
&lt;br /&gt;
While testing with [https://linux.die.net/man/1/fio fio], monitor /sys/block/md0/md/stripe_cache_active, and see if it&#039;s close to /sys/block/md0/md/stripe_cache_size. If it is, double the size of the latter&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
echo 4096 &amp;gt; /sys/block/md0/md/stripe_cache_size&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Continue until stripe_cache_active stabilises, and then you&#039;ve found the limit you&#039;ll need. You may want to double that for good measure. &lt;br /&gt;
&lt;br /&gt;
(to be continued)&lt;br /&gt;
&lt;br /&gt;
== Links ==&lt;br /&gt;
&lt;br /&gt;
Below are a few links with useful info&lt;br /&gt;
&lt;br /&gt;
* [https://raid.wiki.kernel.org/index.php/Irreversible_mdadm_failure_recovery Irreversible mdadm failure recovery]&lt;br /&gt;
&lt;br /&gt;
= ZFS =&lt;br /&gt;
&lt;br /&gt;
ZFS can do a lot of things most filesystems or volume managers can&#039;t. It checksums all data and metadata and so long that the system uses ECC enabled memory (RAM), it will have complete control over the whole data set, and when (not if) an error occurs, it&#039;ll fix the issue without even throwing a warning. To fix the issue, you&#039;ll obviously need sufficient redundancy (mirrors or RAIDzN). &lt;br /&gt;
&lt;br /&gt;
== ZFS send/receive between machines ==&lt;br /&gt;
&lt;br /&gt;
ZFS has a send/receive mechanism that allows for snapshots to be sent over the wire to a receiving end. This can be a full filesystem, or an incremental change since last send/reveive. In a WAN scenario, you&#039;ll probably want to use VPN for this. On a controlled network, sending in cleartext is also possible. You may as well use ssh, but keep in mind that ssh was never designed to be used as a fullblown vpn solution and is just too slow or the task with large amounts of data. You may, though, use mbuffer, if on a loal LAN.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Allow traffic from the sending IP in whatever firewall interface you&#039;re using (if you&#039;re using a firewall at all, that is)&lt;br /&gt;
ufw allow from x.x.x.x&lt;br /&gt;
# &lt;br /&gt;
# Start the receiver first. This listens on port 9090, has a 1GB buffer,&lt;br /&gt;
    and uses 128kb chunks (same as zfs):&lt;br /&gt;
&lt;br /&gt;
mbuffer -s 128k -m 1G -I 9090 | zfs receive data/filesystem&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To be continued one day… See [https://everycity.co.uk/alasdair/2010/07/using-mbuffer-to-speed-up-slow-zfs-send-zfs-receive/ this] for some more. I&#039;ll get back with details on it.&lt;br /&gt;
&lt;br /&gt;
= General Linux system control =&lt;br /&gt;
&lt;br /&gt;
== Add a new CPU (core) ==&lt;br /&gt;
&lt;br /&gt;
If working with virtual machines, adding a new core can be useful if the VM is slow and the load is multithreaded or multiprocess. To do this, add a new CPU in the hypervisor (be it KVM or VMware or Hyper-V or whatever). Some hypervisors, like VMware, will activate it automatically if open-vm-tools is installed. Please note that open-vm-tools is for VMware only. I don&#039;t know of any such thing for KVM or other hypervisors (although I beleive VirtualBox has its own set of tools, but not as a package). If this doesn&#039;t work, run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
echo 1 &amp;gt; /sys/devices/system/cpu/cpuX/online&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where X is the CPU number you want to add. You can &#039;cat /sys/devices/system/cpu/cpuX/online&#039; to check if it&#039;s online.&lt;br /&gt;
&lt;br /&gt;
= Mount partitions on a disk image =&lt;br /&gt;
&lt;br /&gt;
Sometimes you&#039;ll have a disk image, either from recovering a bad drive after hours (or days or weeks) of ddrescue, and sometimes you just have a disk image from a virtual machine where you want to mount the partitions inside the image. There are three main methods of doing this, which are more or less synonmous, but some easier than the other.&lt;br /&gt;
&lt;br /&gt;
== Basics ==&lt;br /&gt;
&lt;br /&gt;
A disk image is usually like a disk, consisting of either a large filesystem, a PV or a partition table with one or partitions onto which resides a filesystem, a pv, swap or something else. If it&#039;s partitioned, and you want your operating system to mount a filesystem or allow it to see whatever LVM stuff lies on it, you need to isolate the partitions. &lt;br /&gt;
&lt;br /&gt;
== Manual mapping ==&lt;br /&gt;
&lt;br /&gt;
In the oldern days, this was done manually, something like this&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
root@mymachine:~# fdisk -l /dev/vda&lt;br /&gt;
Disk /dev/vda: 25 GiB, 26843545600 bytes, 52428800 sectors&lt;br /&gt;
Units: sectors of 1 * 512 = 512 bytes&lt;br /&gt;
Sector size (logical/physical): 512 bytes / 512 bytes&lt;br /&gt;
I/O size (minimum/optimal): 512 bytes / 512 bytes&lt;br /&gt;
Disklabel type: dos&lt;br /&gt;
Disk identifier: 0xc37b7ea5&lt;br /&gt;
&lt;br /&gt;
Device     Boot    Start      End  Sectors  Size Id Type&lt;br /&gt;
/dev/vda1  *        2048 50333311 50331264   24G 83 Linux&lt;br /&gt;
/dev/vda2       50333312 52426369  2093058 1022M  5 Extended&lt;br /&gt;
/dev/vda5       50333314 52426369  2093056 1022M 82 Linux swap / Solaris&lt;br /&gt;
root@mymachine:~#&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To calculate the start and end of each partition, you just take the start sector and multiply it by the sector size (512 bytes here) and you have the offset in bytes. After this, it&#039;s merely an losetup -o &amp;lt;offset&amp;gt; /dev/loopX &amp;lt;nameofimagefile&amp;gt; and you have the partition mapped to your /dev/loopX (having X being something typically 0-255. After this, just mount it or run pvscan/vgscan/lvscan to probe whatever lvm config is there, and you should be able to mount it like any other filesystem.&lt;br /&gt;
&lt;br /&gt;
== kpartx ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;kpartx&#039;&#039;&#039; does the same as above, more or less, just without so much hassle. Most of it should be automatic and easy to deal with, except it may fail to disconnect the loopback devices sometimes, so you may have to &#039;&#039;&#039;losetup -d&#039;&#039;&#039; them manually. See the manual, &#039;&#039;&#039;kpartx (8)&#039;&#039;&#039;. Please note that &#039;&#039;&#039;partx&#039;&#039;&#039; works similarly and I&#039;d guess the authors of the two tools are arguing a lot of which one&#039;s the best.&lt;br /&gt;
&lt;br /&gt;
== guestmount ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;guestmount&#039;&#039;&#039; is something similar again, but also supports file formats like &#039;&#039;&#039;qcow2&#039;&#039;&#039; and possibly other, proprietary filesystems like &#039;&#039;&#039;vmdk&#039;&#039;&#039; and &#039;&#039;&#039;vdi&#039;&#039;&#039;, but don&#039;t take my word for it - I haven&#039;t tested. Again, see the manual or just read up on the description [http://ask.xmodulo.com/mount-qcow2-disk-image-linux.html?fbclid=IwAR3snTeZvGzp9PLdX11EQhCfOpux6I93CiJ3A2pUomkkRLly9Xo4851mkTY here]. It seems rather trivial.&lt;br /&gt;
&lt;br /&gt;
= Linux on laptops =&lt;br /&gt;
&lt;br /&gt;
== Wifi with HP EliteBook 725/745 on Ubuntu ==&lt;br /&gt;
&lt;br /&gt;
The HP EliteBook 725/745 and similar are equipped with a BCM4352 wifi chip. As with a lot of other stuff from Broadcom, this lacks an open hardware description, so thus no open driver exist. The proper fix, is to replace the NIC with something with an open driver, but again, this isn&#039;t always possible, so a binary driver exists. In ubuntu, run, somehow connect the machine to the internet and run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install bcmwl-kernel-source&lt;br /&gt;
sudo modprobe wl&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you can&#039;t connect the machine to the internet, download the needed packages on another machine and put it on some usb storage. These packages should suffice:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# apt-cache depends bcmwl-kernel-source&lt;br /&gt;
bcmwl-kernel-source&lt;br /&gt;
  Depends: dkms&lt;br /&gt;
  Depends: linux-libc-dev&lt;br /&gt;
  Depends: libc6-dev&lt;br /&gt;
  Conflicts: &amp;lt;bcmwl-modaliases&amp;gt;&lt;br /&gt;
  Replaces: &amp;lt;bcmwl-modaliases&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then install manually with &#039;&#039;&#039;dpkg -i file1.deb file2.deb&#039;&#039;&#039; etc&lt;br /&gt;
&lt;br /&gt;
After this, ip/ifconfig/iwconfig shouldd see the new wifi nic, probably &#039;&#039;&#039;wlan0&#039;&#039;&#039;, but due to a [https://bugs.launchpad.net/ubuntu/+source/broadcom-sta/+bug/1343151 old, ignored bug], you won&#039;t find any wifi networks. This is because the driver from Broadcom apparently does not support interrupt remapping, commonly used on x64 machines. To turn this off, change &#039;&#039;&#039;/etc/default/grub&#039;&#039;&#039; and change the line &#039;&#039;&#039;GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;quiet splash&amp;quot;&#039;&#039;&#039;, adding intremap=off to the end before the quote: &#039;&#039;&#039;GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;quiet splash intremap=off&amp;quot;&#039;&#039;&#039;. Save the file and run &#039;&#039;&#039;sudo update-grub&#039;&#039;&#039; and reboot. After this, wifi should work well.&lt;br /&gt;
&lt;br /&gt;
== Wifi with HP Compaq Presario CQ57 on Ubuntu ==&lt;br /&gt;
&lt;br /&gt;
The HP Compaq Presario CQ57 uses the RT5390 wifi chipset. This has been supported for quite some time now, and I was quite surprised to find it not working on a laptop a friend was having. The driver loaded correctly, but Ubuntu insisted of the laptop being in &#039;&#039;&#039;flight mode&#039;&#039;&#039;. Checking &#039;&#039;&#039;rfkill&#039;&#039;&#039;, it showed me two NICs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# rfkill list all&lt;br /&gt;
0: phy0: Wireless LAN&lt;br /&gt;
	Soft blocked: no&lt;br /&gt;
	Hard blocked: yes&lt;br /&gt;
1: hp-wifi: Wireless LAN&lt;br /&gt;
	Soft blocked: yes&lt;br /&gt;
	Hard blocked: no&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Turning rfkill on and off resulted in nothing much, except some error messages in the kernel log (dmesg)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] ACPI Error: Field [B128] at bit offset/length 128/1024 exceeds size of target Buffer (160 bits) (20170831/dsopcode-235)&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]&lt;br /&gt;
                            Initialized Local Variables for Method [HWCD]:&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Local0: 00000000a34b7928 &amp;lt;Obj&amp;gt;           Integer 0000000000000000&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Local1: 00000000b0aa6865 &amp;lt;Obj&amp;gt;           Buffer(8) 46 41 49 4C 04 00 00 00&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Local5: 00000000a9811efd &amp;lt;Obj&amp;gt;           Integer 0000000000000004&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] Initialized Arguments for Method [HWCD]:  (2 arguments defined for method invocation)&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Arg0:   0000000078957d1b &amp;lt;Obj&amp;gt;           Integer 0000000000000001&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Arg1:   00000000725c9c6e &amp;lt;Obj&amp;gt;           Buffer(20) 53 45 43 55 02 00 00 00&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] ACPI Error: Method parse/execution failed \_SB.WMID.HWCD, AE_AML_BUFFER_LIMIT (20170831/psparse-550)&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] ACPI Error: Method parse/execution failed \_SB.WMID.WMAD, AE_AML_BUFFER_LIMIT (20170831/psparse-550)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After upgrading BIOS and testing different kernels, I was asked to try to unload the &#039;&#039;&#039;hp_wmi&#039;&#039;&#039; driver. I did, and things changed a bit, so I tried blacklisting it, creating the file &#039;&#039;&#039;/etc/modprobe.d/blacklist-hp_wmi.conf&#039;&#039;&#039; with the following content&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Blacklist this - it doesn&#039;t work!&lt;br /&gt;
blacklist hp_wmi&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
I gave the machine a reboot and afte that, the &#039;&#039;&#039;hp-wifi&#039;&#039;&#039; entry was gone in the rfkill output, and things works.&lt;br /&gt;
&lt;br /&gt;
= Raspberry pi =&lt;br /&gt;
&lt;br /&gt;
I couldn&#039;t quite decide if the raspberry pi should be a separate section or part of Linux, but hell, it can run more than Linux, although 99,lots% of people just uses Linux on them. This is a small list of things to know about them; things not on the front page of the manual or perhaps hidden even better.&lt;br /&gt;
&lt;br /&gt;
== Which pi? ==&lt;br /&gt;
&lt;br /&gt;
I just setup three raspberry pi machines and although some are quite different, like v1 to vEverythingelse or the Pi zero versions to the normal ones, not all of us remember how to distinguish between them, and sometimes they&#039;re in a nice 3d printed (or otherwise) chassis or otherwise hidden. So, how to check three different ones:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
root@home-assistant:~ $ cat /proc/device-tree/model ; echo&lt;br /&gt;
Raspberry Pi 2 Model B Rev 1.1&lt;br /&gt;
&lt;br /&gt;
root@green-pi:~ $ cat /proc/device-tree/model ; echo&lt;br /&gt;
Raspberry Pi 3 Model B Rev 1.2&lt;br /&gt;
&lt;br /&gt;
roy@yellow-pi:~ $cat /proc/device-tree/model ; echo&lt;br /&gt;
Raspberry Pi 4 Model B Rev 1.1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
While this works well, for the latter, the pi4, it doesn&#039;t tell how much memory I have. It comes in variants of 1, 2 and 4GB, and this is the latter.&lt;br /&gt;
&lt;br /&gt;
For a more detailed list, the command &#039;&#039;&#039;awk &#039;/^Revision/ {sub(&amp;quot;^1000&amp;quot;, &amp;quot;&amp;quot;, $3); print $3}&#039; /proc/cpuinfo&#039;&#039;&#039; will give you a revision number, detailing the type of pi, who produced it etc. Please see [https://elinux.org/RPi_HardwareHistory https://elinux.org/RPi_HardwareHistory] for a full table.&lt;br /&gt;
&lt;br /&gt;
== Monitoring ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;vcgencmd&#039;&#039;&#039; from &#039;&#039;&#039;/opt/vc/bin&#039;&#039;&#039;, but symlinked to &#039;&#039;&#039;/usr/bin&#039;&#039;&#039; so it&#039;s available in path, is useful for fetching hardware info about the pi. For example, measuring the temperature&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
root@yellow-pi:~# vcgencmd measure_temp&lt;br /&gt;
temp=63.0&#039;C&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The command is generally badly documented and parts of it seems outdated for newer hardware. Here&#039;s the output from a Raspberry pi 4 with 4GB RAM&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
roy@yellow-pi:~ $ vcgencmd get_mem arm&lt;br /&gt;
arm=948M&lt;br /&gt;
roy@yellow-pi:~ $ vcgencmd get_mem gpu&lt;br /&gt;
gpu=76M&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= BIOS upgrade from Linux =&lt;br /&gt;
&lt;br /&gt;
Generally, BIOS upgrades have been moved to the BIOS itself these days. This saves a lot of work and quite possibly lives after those who earier rammed their heads through walls, now can upgrade directly from the internet instead of using obscure operating systems best avoided. Sometimes, however, one must use these nevertheless. This is a quick run-through on your options.&lt;br /&gt;
&lt;br /&gt;
== DOS ==&lt;br /&gt;
&lt;br /&gt;
Most non-automatic BIOS upgrades are installed from DOS. Doing a BIOS upgrade this way, is generally non-problematic. Just install a USB thingie with [https://www.freedos.org/ FreeDOS], copy your file(s) onto the thing and boot on it. The commandline is the same as old MS/DOS, except a wee bit more userfriendly, but not a lot.&lt;br /&gt;
&lt;br /&gt;
== Windows ==&lt;br /&gt;
&lt;br /&gt;
Some macahines, like laptops from &#039;&#039;&#039;HP&#039;&#039;&#039;, may have BIOS upgrades that are made to be installed from Windows and won&#039;t run in FreeDOS or MS/DOS, instead throwing an error, saying &#039;&#039;&#039;This program cannot be run in DOS mode&#039;&#039;&#039;. This means you&#039;ll have to boot on a Windows rescue disc and do the job from there. Googling this, tells you it&#039;s quite easy, you just choose &#039;make rescue disc&#039; from Windows, and it&#039;s all good, except if you don&#039;t run Windows, that is. To remedy this problem, do as follows:&lt;br /&gt;
&lt;br /&gt;
=== Download Windows ===&lt;br /&gt;
&lt;br /&gt;
Since you don&#039;t run Windows and possibly don&#039;t have a spouse or friend around with such unhealthy habits either, you need to get it. It&#039;s quite easy - just google &#039;download windows&#039; and it&#039;ll send you to [https://www.microsoft.com/en-us/software-download/windows10ISO somewhere like this].&lt;br /&gt;
&lt;br /&gt;
=== Burn it! ===&lt;br /&gt;
&lt;br /&gt;
Now it&#039;s time to burn the installer on a DVD ROM. You&#039;ll need a double-layered one, since the OS is &amp;gt; 4.7GiB, but I&#039;m sure you have a ton of those lying around. Now, just place your optical medium in your optical drive and burn, baby, burn!&lt;br /&gt;
&lt;br /&gt;
=== Or make a USB thing? ===&lt;br /&gt;
&lt;br /&gt;
Not a lot of machines have optical drives these days, so you may want to use an USB pen drive or something instead. This is easy, just make the USB bootable with the Windows application Microsoft has made for this. Unfortunately, this only runs on Windows, and unlike stuff like Debian, where the &#039;&#039;&#039;iso&#039;&#039;&#039; file can be dd&#039;ed directly onto a USB drive to make it bootable, the Windows &#039;&#039;&#039;iso&#039;&#039;&#039;s don&#039;t come with this luxury. There are lots of methods to make bootable USB things from iso files out there, but the only thing most of them have in common, is that they generally don&#039;t work.&lt;br /&gt;
&lt;br /&gt;
==== WoeUSB ====&lt;br /&gt;
&lt;br /&gt;
After hours of swearing, it&#039;s nice to come across software like [https://github.com/slacka/WoeUSB WoeUSB]. It may not be perfect, it relies on a bunch of GUI stuff you&#039;ll never need and so on, but it &#039;&#039;&#039;&#039;&#039;works&#039;&#039;&#039;&#039;&#039;, and that&#039;s the important part! Just clone the repo and RTFM and it&#039;s all nice. It&#039;s slow, but hell, getting a windows machine and/or an optical drive might be slower.&lt;br /&gt;
&lt;br /&gt;
WoeUSB does nothing fancy, but it &#039;&#039;&#039;does&#039;&#039;&#039; work. It will create a filesystem, FAT32 or NTFS (better use NTFS, FAT32 has its limits). It creates normal filesystems and so on. Just make sure to copy in the BIOS update file, usually an exe file, to run when Windows is up and running.&lt;br /&gt;
&lt;br /&gt;
==== Install BIOS ====&lt;br /&gt;
&lt;br /&gt;
Boot on the Windows USB thing and choose &#039;repair computer&#039; and then &#039;command prompt&#039;. Find the install file, and if you&#039;re lucky, you&#039;ll find it needs a 32bit OS, just like I did. Since the 64bit version doesn&#039;t include 32bit compatibility in the installer, revert to downloading the 32bit version of windows and start over. Pray to your favourite god(s) not to get across such machines again - it might help.&lt;br /&gt;
&lt;br /&gt;
= 3D printer stuff =&lt;br /&gt;
&lt;br /&gt;
Below are a number of not very ordered paragraphs about 3D printer related stuff, mostly based on my experience. Their content may be interesting or perhaps practical knowledge, but then, that depends on the reader.&lt;br /&gt;
&lt;br /&gt;
== 3D printer related introductions on youtube or elsewhere ==&lt;br /&gt;
&lt;br /&gt;
First off, I&#039;d like to mention some youtube videos that are all (or mostly) a nice start if you&#039;re new to 3D printers.&lt;br /&gt;
&lt;br /&gt;
=== [https://www.youtube.com/watch?v=nb-Bzf4nQdE&amp;amp;list=PLDJMid0lOOYnkcFhz6rfQ6Uj8x7meNJJx Thomas Salanderer&#039;s 10-video series on 3D printing basics] ===&lt;br /&gt;
&lt;br /&gt;
Thomas Salanderer is a an experienced 3D printer user/admin/fixer/etc and he has a lot of interesting videos. Some accuse him for being a [Prusa https://www.prusa3d.com/] fanboy, which he quite obviously is, but that doesn&#039;t stop him from making interesting and somewhat neutral videos. The series walks you thought the first steps of how things work and so on and hopefully opens more doors than anything else I&#039;ve seen.&lt;br /&gt;
&lt;br /&gt;
=== [https://www.youtube.com/watch?v=rp3r921DBGI Teaching Tech&#039;s &amp;quot;3D printer tuning reborn&amp;quot;] ===&lt;br /&gt;
&lt;br /&gt;
Teaching Tech is, like Salanderer or even more, good pedagogically and explains a lot. They (or he) do a bunch of testing and describing pros and cons with different things, just like other youtubers in the sme business. The mentioned video shows how to tune a 3D printer after you have first learned the basics, and leans on a webpage made to help you out without too much manual work.&lt;br /&gt;
&lt;br /&gt;
This was a short list, but I guess it&#039;ll grow over time.&lt;br /&gt;
&lt;br /&gt;
== Hydrophilic filament ==&lt;br /&gt;
&lt;br /&gt;
Most popular filament types, including PLA, PETG, PP or PA (Polyamide, normally known as Nylon) and virtualy any filament type named [https://www.matterhackers.com/news/filament-and-water poly-something] (and thus with an acronym of P-something) are hydrophilic (also (somewhat incorrectly) called hydroscopic), meaning so long they&#039;re dryer than the atmosphere around them, they&#039;ll do their best to suck out the atmosphere&#039;s humidity. This is why most filament are shrink-wrapped with a small bag of silica gel in it. If such filament is exposed for normal humid air for some time, it&#039;ll become very hard to use. Most of my experience is with PLA, which can handle a bit (depending on make), but still not a lot. With PLA, if you end up with prints where the filament seems not to stick, it may help with a higher temperature. Otherwise, the filament must be [https://all3dp.com/2/how-to-dry-filament-pla-abs-and-nylon/ baked]. If you don&#039;t want to use your oven, try something like a [https://www.jula.no/catalog/hjem-og-husholdning/kjokkenmaskiner/mattilberedningsapparater/frukt-sopptorker/frukt-sopptorker-001641/#tab02 fruit and mushroom dryer]. Then get a good, sealble plastic box and add something like half a kilogram of [https://www.ebay.com/sch/sis.html?_nkw=1KG+Orange+Replacement+Desiccant+Indicating+Silica+Gel+Beads+for+Drawers%2C+Camera&amp;amp;_id=131938742628&amp;amp;&amp;amp;_trksid=p2057872.m2749.l2658 silica gel] to an old sock, tie it and put it in the your new dry box.&lt;br /&gt;
&lt;br /&gt;
Please note that ABS is hydrophobic, so you won&#039;t have to worry too much there. Also, remember that PA/Nylon is extremely hydrophilic. Even a couple of days in normal air humidity can ruin it completely and will require baking.&lt;br /&gt;
&lt;br /&gt;
== Upgrading the firmware on an Ender 3 ==&lt;br /&gt;
&lt;br /&gt;
This is about upgrading the firmware, and thus also flashing a bootloader to the Creality Ender 3 3D printer. Most of this is well documented on several place, like o [https://www.youtube.com/watch?v=fIl5X2ffdyo the video from Teaching tech] and elsewhere, but I&#039;ll just summarise some issues I had.&lt;br /&gt;
&lt;br /&gt;
=== Using an arduino Nano as a programmer ===&lt;br /&gt;
&lt;br /&gt;
Quick note before you read on. If you have an Ender 3 controller version 1.1.5 or newer (or perhaps even a bit older), a CR-10S or some other more or less modern printers or controllers, they come with a bootloader installed already, so don&#039;t bother flashing one. The one that&#039;s in there already, should work well. So if you have one of these, just skip this and jump to the [[Roy&#039;s_notes#Flashing_the_printer|next section]].&lt;br /&gt;
&lt;br /&gt;
However, the normal CR-10 (without the S), Ender 3 and a few other printers from Creality come without a bootloader, so you&#039;ll need to flash one before upgrading the firmware. Well, strictly speakning, you don&#039;t need one, you can save those 8kB or so for other stuff and use a programmer to write the whole firmware, but then you&#039;ll need to wire up everything every time you want a new firmware, so in my world, you &#039;&#039;&#039;do&#039;&#039;&#039; need the bootloader, since it&#039;s easier.&lt;br /&gt;
&lt;br /&gt;
To install a bootloader, you&#039;ll need a programmer, and I didn&#039;t have one available. Having some el-cheapo china-copies of Arduinos around, I read I could use one and tried so. Although the docs mostly mention the Uno etc, it&#039;s just as simple with the Nano copy.&lt;br /&gt;
&lt;br /&gt;
So, grab an arduino, plug it to your machine with a USB cable, and, using the Arduino IDE, use the ArduinoISP sketch there (found under Examples) to burn the software needed for the arduino to work as a programmer. When this is done, connect a 10µF capacitor between RST and GND to stop it from resetting when used as a programmer. Connect the MOSI, MISO and SCK pins from the ICSP block (that little isolated 6-pin block on top of the ardu). See [https://www.arduino.cc/en/Tutorial/ArduinoISP here] for a pinout. Then find Vcc and GND either on the ICSP block or elsewhere. Some sites say that on some boards you shouldn&#039;t use the pins on the ICSP block for this. I doubt it matters, though. Then connect another jumper wire from pin 10 on the ardu to work as the reset pin outwards to the chip being programmed (that is, on the printer). The ICSP jumper block pin layout is the same on the printer and on the ardu, and probably elsewhere. Sometimes [https://xkcd.com/927/ standardisation] actually works…&lt;br /&gt;
&lt;br /&gt;
[[File:Ardu-nano-as-programmer.jpg|400px]]&lt;br /&gt;
&lt;br /&gt;
== Flashing the printer ==&lt;br /&gt;
&lt;br /&gt;
When the boot loader is in place, possibly after some wierd errors from during the process, the screen on the 3d printer will go blank and it&#039;ll behave like being bricked. This is ok. Now disconnect the wires and connect the USB cable between computer and printer. If you haven&#039;t installed support for the Sanguino board, that is, the variant of the 1284-chip and surrounding electronics that is the core of the, you need to install it first. In the Arduino IDE, choose the Tools / Boards / Boards manager boot option and search for Sanguino. After this, you should find the Sanguino or Sanguino 1284p in the boards menu. After this, you should be able to communicate with the printer&#039;s controller. Download the [https://www.th3dstudio.com/knowledgebase/th3d-unified-firmware-package/ TH3D unified firmware], making sure it&#039;s the last version. Uncompress the zip and with Finder/Explorer/whateversomething&#039;scalledonlinux, browse to &#039;&#039;&#039;TH3DUF_R2/Firmware/TH3DUF_R2.ino&#039;&#039;&#039; and open it. It should open directly in the Android IDE. Keep in mind that the names TH3DUF_R2 and TH3DUF_R2.ino will vary between versions, but you get the point. Now configure it for your particular needs. You&#039;ll find most of this in the Configuration.h tab (that&#039;s really a file). Most of the other files won&#039;t be necessary unless you&#039;re doing some more advanced stuff, like replacing th controller with something non-standard or similar, but then again, that&#039;s another chapter (or book, even). The video mentioned above describes this well. After flashing the new firmware, you&#039;ll probably get some timeouts and errors, since apparently it resets the printer after giving it the new firmware, but without notifying the flashing software of it doing so. If this happens, calm down and reboot the printer and check its tiny monitor - it should work. If it doesn&#039;t work, and if you flashed the bootload yourself, try to flash it again, and if that doesn&#039;t work, try flashing the programmer again yet another time, just for kicks. Again, if you have a newer controller like the v1.1.5, don&#039;t touch the bootloader, as the one already installed, should work well as it is.&lt;br /&gt;
&lt;br /&gt;
PS: I tried enabling &#039;&#039;&#039;MANUAL_MESH_LEVELING&#039;&#039;&#039;, which in the code says that &#039;&#039;If used with a 1284P board the bootscreen will be disabled to save space&#039;&#039;. This effectively disabled the whole printer, and apparently may be making the firmware image a wee bit too large for it to fit the 1284P on the ender. It works well without it, though, and it may be fixed by now, since I tested this back in early 2019.&lt;br /&gt;
&lt;br /&gt;
== And then… ==&lt;br /&gt;
&lt;br /&gt;
With the new firmware in place, the printer should work as before, although with thermal runaway protection to better avoid fires in case the shit hits the fan, and to allow for things like autolevelling. With any luck, [https://www.precisionpiezo.co.uk/ this thing] may be ready for use by the time you read this - it surely looks nice!&lt;br /&gt;
&lt;br /&gt;
= Octoprint/Octopi =&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;This could have been under some other section, but again, I just branch out even though most of it is about sections mentioned elsewhere.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
When setting up a 3d printer for the first time, you usually get an SD card for storage and transfer data to the printer using [https://en.wikipedia.org/wiki/Sneakernet Sneakernet]. Some printers use micro SD cards, while other fullsize SD cards, which imho is better, since they don&#039;t get lost that easily, but otherwise do the same thing. This works, but is somewhat tedious. If you want to control the printer from a PC or phone, there&#039;s a simple trick for that as well - octoprint.&lt;br /&gt;
&lt;br /&gt;
[https://octoprint.org/ Octoprint], written by Gina Häußge, runs on most platforms including linux, windows, BSD*, macos etc. It supports controlling a camera to some extent out of the box and there&#039;s a large number of plugins availablee to do a lot of things you possibly haven&#039;t thought of (and quite often, you&#039;d ever need). The easiest way to install it, is to just grab a Raspberry pi - preferably some of the newer models (will get to that later) and download [https://octoprint.org/download/ octopi] and follow the instructions on that page.&lt;br /&gt;
&lt;br /&gt;
== Performance issues ==&lt;br /&gt;
&lt;br /&gt;
Some report (and I have seen it myself) issues with the pi&#039;s performance with regards to both handling the octoprint processes (which should be as close to realtime as possible) and handling other stuff like I/O, networking etc. The point is that at pi3 or older, has all peripherals connected to an internal USB hub. This might be practical, but performance-wise it&#039;s &#039;&#039;&#039;&#039;&#039;not&#039;&#039;&#039;&#039;&#039;. If you in addition connect a webcam to USB, you&#039;re asking for trouble, since USB will be your bottleneck. With a raspberry pi camera, the ones connected to the pi directly with a ribbon cable, this should not use USB, so it&#039;s better. Still, again, for older pi&#039;s, there might be some shortage in therms of cpu or i/o. The octopi runs something like raspbian which is a fork of debian which is a linux distro, so it all boils down to knowing linux.&lt;br /&gt;
&lt;br /&gt;
Your typical octopi will run octoprint, a streamer, usually &#039;&#039;&#039;mjpg-streamer&#039;&#039;&#039;, a simple, lightweight videostreamer that outputs a stream of jpeg-images (about the same format as cinemas use - that is - not MPEG). This may be a bit tough on the cpu and potentially i/o. Add inn a dash of USB overload and you&#039;re may see trouble.&lt;br /&gt;
&lt;br /&gt;
Still - a pi3 should be able to handle the load, but it might help to prioritise corretly. The octoprint process is the important part here, so we could give that full priority both in CPU and I/O and. Unfortunately, it doesn&#039;t seem like the current octopi has been migrated to using systemd for the startup. We&#039;ll deal with this later. To fix this in the old SysV init style file present there, the following patch should work against the file /etc/init.d/octoprint&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;diff&amp;quot;&amp;gt;&lt;br /&gt;
--- octoprint.old	2020-07-20 18:46:10.166651965 +0200&lt;br /&gt;
+++ octoprint	2020-07-20 18:53:21.724803211 +0200&lt;br /&gt;
@@ -22,6 +22,9 @@&lt;br /&gt;
 PIDFILE=/var/run/$NAME.pid&lt;br /&gt;
 PKGNAME=octoprint&lt;br /&gt;
 SCRIPTNAME=/etc/init.d/$PKGNAME&lt;br /&gt;
+NICELEVEL=-19                        # Top CPU priority&lt;br /&gt;
+IONICE_CLASS=1                       # Realtime I/O class&lt;br /&gt;
+IONICE_PRIORITY=0                    # Realtime I/O priority (probably not needed with class=realtime)&lt;br /&gt;
&lt;br /&gt;
 # Read configuration variable file if it is present&lt;br /&gt;
 [ -r /etc/default/$PKGNAME ] &amp;amp;&amp;amp; . /etc/default/$PKGNAME&lt;br /&gt;
@@ -70,10 +73,11 @@&lt;br /&gt;
&lt;br /&gt;
    is_alive $PIDFILE&lt;br /&gt;
    RETVAL=&amp;quot;$?&amp;quot;&lt;br /&gt;
-&lt;br /&gt;
    if [ $RETVAL != 0 ]; then&lt;br /&gt;
        start-stop-daemon --start --background --quiet --pidfile $PIDFILE --make-pidfile \&lt;br /&gt;
-       --exec $DAEMON --chuid $OCTOPRINT_USER --user $OCTOPRINT_USER --umask $UMASK -- serve $DAEMON_ARGS&lt;br /&gt;
+       --exec $DAEMON --chuid $OCTOPRINT_USER --user $OCTOPRINT_USER --umask $UMASK \&lt;br /&gt;
+       --nicelevel $NICELEVEL --ioched $IONICE_CLASS:$IONICE_PRIORITY \&lt;br /&gt;
+       --serve $DAEMON_ARGS&lt;br /&gt;
        RETVAL=&amp;quot;$?&amp;quot;&lt;br /&gt;
    fi&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This ismply upgrades the process to be allowed to use most of the resources on the pi, regardless of what other processes are whining about.&lt;br /&gt;
&lt;br /&gt;
PS: Code not tested - I don&#039;t have a pi right here. Will test later, but I&#039;m pretty sure it&#039;ll work. After all, it&#039;s just a few new arguments to start-stop-daemon&lt;br /&gt;
&lt;br /&gt;
roy&lt;/div&gt;</summary>
		<author><name>Roy</name></author>
	</entry>
	<entry>
		<id>https://wiki.malinux.no/index.php?title=Roy%27s_notes&amp;diff=184</id>
		<title>Roy&#039;s notes</title>
		<link rel="alternate" type="text/html" href="https://wiki.malinux.no/index.php?title=Roy%27s_notes&amp;diff=184"/>
		<updated>2020-11-14T22:45:29Z</updated>

		<summary type="html">&lt;p&gt;Roy: /* Using an arduino Nano as a programmer */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= LVM, md and friends =&lt;br /&gt;
&lt;br /&gt;
== Linux&#039; Logical Volume Manager (LVM) ==&lt;br /&gt;
&lt;br /&gt;
=== LVM in general ===&lt;br /&gt;
&lt;br /&gt;
LVM is designed to be an abstraction layer on top of physical drives or RAID, typically [https://raid.wiki.kernel.org/index.php/RAID_setup mdraid] or [https://help.ubuntu.com/community/FakeRaidHowto fakeraid]. Keep in mind that fakeraid should be avoided unless you really need it, like in conjunction with dual-booting linux and windows on fakeraid. LVM broadly consists of three elements, the &amp;quot;physical&amp;quot; devices (PV), the volume group (VG) and the logical volume (LV). There can be multiple PVs, VGs and LVs, depending on requirement. More about this below. All commands are given as examples, and all of them can be fine-tuned using extra flags in need of so. In my experience, the defaults work well for most usecases.&lt;br /&gt;
&lt;br /&gt;
I&#039;m mentioning filesystem below too. Where I write ext4, the samme applies to ext2 and ext3.&lt;br /&gt;
&lt;br /&gt;
==== Create a PV ====&lt;br /&gt;
&lt;br /&gt;
A PV is the &amp;quot;physical&amp;quot; parts. This does not need to be a physical disk, but can also be another RAID, be it an mdraid, fakeraid, hardware raid, a virtual disk on a SAN or otherwisee or a partition on one of those. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#  These add three PVs, one on a drive (or hardware raid) and another two on mdraids.&lt;br /&gt;
pvcreate /dev/sdb&lt;br /&gt;
pvcreate /dev/md1 /dev/md2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For more information about pvcreate, see [https://linux.die.net/man/8/pvcreate the manual].&lt;br /&gt;
&lt;br /&gt;
==== Create a VG ====&lt;br /&gt;
&lt;br /&gt;
The volume group consists of one or more PVs grouped together on which LVs can be placed. If several PVs are grouped in a VG, it&#039;s generally a good idea to make sure these PVs have some sort of redundancy, as in mdraid/fakeraid or hwraid. Otherwise it will be like using a [https://en.wikipedia.org/wiki/RAID RAID-0] with a single point of failure on each of the independant drives. LVM has [https://unix.stackexchange.com/questions/150644/raiding-with-lvm-vs-mdraid-pros-and-cons  RAID code in it] as well, so you can use that. I haven&#039;t done so myself, as I generally stick to mraid. The reason is mdraid is, in my opinion older and more stable and has more users (meaning bugs are reported and fixed faster whenever they are found). That said, I beleive the actual RAID code used in LVM RAID are the same function calls as for mdraid, so it may not be much of a difference. I still stick with mdraid. To create a VG, run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create volume group my_vg&lt;br /&gt;
vgcreate my_vg /dev/md1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that if vgcreate is run with a PV (as /dev/md1 above) that is not defined as a PV (like above), this is done implicitly, so if you don&#039;t need any special flags to pvcreate, you can simply skip it and let vgcreate do that for you.&lt;br /&gt;
&lt;br /&gt;
==== Create an LV ====&lt;br /&gt;
&lt;br /&gt;
LVs can be compared to partitions, somehow, since they are bounderies of a fraction or all of that of a VG. The difference between them and a partition, however, is that they can be grown or shrunk easily and also moved around between PVs without downtime. This flexibility makes them superiour to partitions as your system can be changed without users noticing it. By default, an LV is alloated &amp;quot;thickly&amp;quot;, meaning all the data given to it, is allocated from the VG and thus the PV. The following makes a 100GB LV named &amp;quot;thicklv&amp;quot;. When making an LV, I usually allocate what&#039;s needed plus some more, but not everything, just to make sure it&#039;s space available for growth on any of the LVs on the VG, or new LVs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a thick provisioned LV named thicklv on the VG my_vg&lt;br /&gt;
lvcreate -n thicklv -L 100G my_vg&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After the LV is created, a filesystem can be placed on it unless it is meant to be used directly. The application for direct use include swap space, VM storage and certain database systems. Most of these will, however, work on filesystems too, although my testing has shown that on swap space, there is a significant performance gain for using dedicated storage without a filesystem. As for filesystems, most Linux users use either ext4 or xfs. Personally, I generally use XFS these days. See my notes below on filesystem choice.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a filesystem on the LV - this could have been mkfs -t ext4 or whatever filesystem you choose&lt;br /&gt;
mkfs -t xfs /dev/my_vg/thicklv&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then just edit /etc/fstab with correct data and run mount -a, and you should be all set.&lt;br /&gt;
&lt;br /&gt;
==== Create LVM cache ====&lt;br /&gt;
LVMcache is LVM&#039;s solution to caching a slowish filesystem on spinning rust with the help of much faster SSDs. For this to work, use a separate SSD or a mirror or two (just in case) an add the new disk/md dev to the same VG. In this case, we use a small mirror, md1. LVM is not able to cache to a disk or partition outside the volume group.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
vgextend data /dev/md1&lt;br /&gt;
  Physical volume &amp;quot;/dev/md1&amp;quot; successfully created.&lt;br /&gt;
  Volume group &amp;quot;data&amp;quot; successfully extended&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Thn create two LVs, one for the data (contents of files) and one for the metadata (filenames, directories, attributes etc). Typically, the metadata part won&#039;t need to be very large. 100M should usually do unless you have ekstremely many small files. I guess there are ways to calculate it, but again, 1GB should do for everyone (or was that 640k?). As for the data cache, I chose to use 40G here for a 15TB RAID. It will only cache what actively use anyway, so no need for overkill.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
lvcreate -L 1G -n _cache_meta data /dev/md1&lt;br /&gt;
lvcreate -L 100G -n _cache data /dev/md1&lt;br /&gt;
&lt;br /&gt;
# Some would want --cachemode writeback, but if paranoid, I wouldn&#039;t recommend it. Metadata or data can be easily corrupted in case of failure. Most filesystems will however recover from this these days since they use journaling. It &#039;&#039;really&#039;&#039; speeds up things.&lt;br /&gt;
lvconvert --type cache-pool --cachemode writethrough --poolmetadata data/_cache_meta data/_cache&lt;br /&gt;
lvconvert --type cache --cachepool data/_cache data/data&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
That should be it. If you benchmarked the disk before this, you should try again and you&#039;ll probably get a nice surprise. If not, well, see below how to turn this off again :)&lt;br /&gt;
&lt;br /&gt;
==== Disabling LVM cache ====&lt;br /&gt;
&lt;br /&gt;
If you want to change the cached LV, such as growing og shrinking or otherwise, you&#039;ll have to disable caching first and then re-enable it. There&#039;s no quick-and-easy fix, but you just do as you did when enabling in the first place. &lt;br /&gt;
&lt;br /&gt;
Forst, disable caching for the LV. This will do it cleanly and remove the LVs earlier created for caching the main device. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
lvconvert --uncache data/data&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, since you now have a VG with an empty PV in it, earlier used for caching, I&#039;d recommend removing this for now to avoid expanding onto that as well. Since they&#039;re in the same VG, this might happen and if you get so far as to extend the lv and the filesystem on it, and this filesystem is XFS or similar filesystems without possibilities of reducing the size, you have a wee problem. &lt;br /&gt;
&lt;br /&gt;
Just remove that PV from the VG&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
vgreduce data /dev/md1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The PV is still there, but pvs should now show it not connected to a VG&lt;br /&gt;
&lt;br /&gt;
==== Growing devices ====&lt;br /&gt;
&lt;br /&gt;
LVM objects can be grown and shrunk. If a PV resides on a RAID where a new drive has been added or otherwise grown, or on a partition or virtual disk that has been extended, the PV must be updated to reflect these changes. The following command will grow the PV to the maximum available on the underlying storage. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Resize the PV /dev/md (not the RAID, only the PV on the RAID) to its full size&lt;br /&gt;
pvresize /dev/md1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If a new PV is added, the VG can be grown to add the space on that in addition to what&#039;s there already. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Extend my_vg to include md2 and its space&lt;br /&gt;
vgextend my_vg /dev/md2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
With more space available in the VG, the LV can now be extended. Let&#039;s add another 50GB to it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Extend thicklv - add 50GB. If you know you won&#039;t need the space anywhere else, you may want to&lt;br /&gt;
# lvresize -l+100%FREE instead. Keep in mind the difference between -l (extents) and -L (bytes)&lt;br /&gt;
lvresize -L +50G my_vg/thicklv&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Growing filesystems ====&lt;br /&gt;
After the LV has grown, run &#039;&#039;xfs_growfs&#039;&#039; (xfs) or &#039;&#039;resize2fs&#039;&#039; (ext4) to make use of the new data. To grow the filesystem to all available space on ext4, run the below command.  To partly grow the filesystem or to shrink it or otherwise, please see the manuals.&lt;br /&gt;
&lt;br /&gt;
The filesystem can be mounted when this is run. If you for some reason get an &#039;&#039;&#039;access denied&#039;&#039;&#039; error when running this as root or with sudo, it&#039;s likely caused by a filesystem error. To fix this, unmount the filesystem first and run &#039;&#039;&#039;fsck -f /dev/my_vg/thicklv&#039;&#039;&#039; and remount it before retrying to extend it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
resize2fs /dev/my_vg/thicklv&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Similarly, with XFS, but note that xfs_growfs doesn&#039;t take the device name, but the filesystem&#039;s mount point. In the case of XFS, also note that the filesystem &#039;&#039;&#039;&#039;&#039;must&#039;&#039;&#039;&#039;&#039; be mounted to be grown. This, in contrast to how it was in the old days when filesystems had to be unmounted to be grown.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
xfs_growfs /my_mountpoint&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Rename system VG ====&lt;br /&gt;
&lt;br /&gt;
Some distros create VG names like those-from-a-sysadmin-with-a-well-developed-paranoia-not-to-hit-a-duplicate. Debian, for instance, uses names like &amp;quot;my-full-hostname-vg&amp;quot;. Personally, I don&#039;t like these, since if I were to move a disk or vdisk around to somewhere else, I&#039;d make sure not to add a disk named &#039;sys&#039; to an existing system. If you do, most distros will refuse to use the VGs with duplicate names, resulting in the OS not booting until either one is specified by its UUID or just one removed. As I&#039;m aware of this, I stick to the super-risky thing of all system VGs named &#039;sys&#039; and so on.&lt;br /&gt;
&lt;br /&gt;
If you do this, keep in mind that it may blow up your computer and take your girl- or boyfriend with it or even make either of them pregnant, allowing Trump to rule your life and generally make things suck. You&#039;re on your own!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Rename the VG&lt;br /&gt;
vgrename my-full-hostname-vg sys&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, in /boot/grub/grub.cfg, change the old lv path from something like &#039;/dev/mapper/debian--stretch--machine--vg-root&#039; to your new and fancy &#039;/dev/sys/root. Likewise, in /etc/fstab, change occurences of &#039;/dev/mapper/debian--stretch--machine--vg-&#039; (or similar) with &#039;/dev/sys/&#039;. Here, this was like this - the old ones commented out.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;fstab&amp;quot;&amp;gt;&lt;br /&gt;
#/dev/mapper/debian--stretch--box--vg-root      /               ext4            errors=remount-ro,discard       0       1&lt;br /&gt;
/dev/sys/root                                   /               ext4            errors=remount-ro,discard       0       1&lt;br /&gt;
# /boot was on /dev/vda1 during installation&lt;br /&gt;
UUID=myverylonguuidwithatonofgoodinfoinit       /boot           ext2            defaults                        0       2&lt;br /&gt;
#/dev/mapper/debian--stretch--box--vg-swap_1    none            swap            sw                              0       0&lt;br /&gt;
/dev/sys/swap_1                                 none            swap            sw                              0       0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Update /etc/initramfs-tools/conf.d/resume with similar data for swap.&lt;br /&gt;
&lt;br /&gt;
You might want to run &#039;update-initramfs -u -k all&#039; after this, but I&#039;m not sure if it&#039;s needed.&lt;br /&gt;
&lt;br /&gt;
Now, pray to the nearest god(s) and give it a reboot and it should (probably) work.&lt;br /&gt;
&lt;br /&gt;
After reboot, run &#039;&#039;&#039;swapoff -a&#039;&#039;&#039;, then &#039;&#039;&#039;mkswap /dev/sys/swap_1&#039;&#039;&#039; (or whatever it&#039;s called on your system) and &#039;&#039;&#039;swapon -a&#039;&#039;&#039; again. You may want to give it another reboot or two for kicks, but it should work well even without that.&lt;br /&gt;
&lt;br /&gt;
=== Migration tools ===&lt;br /&gt;
&lt;br /&gt;
At times, storage regimes change, new storage is added and sometimes it&#039;s not easy to migrate with the current hardware or its support systems. Once I had to migrate a 45TiB fileserver from one storage system to another, preferably without downtime. The server originally had three 15TiB PVs of which two were full and the third half full. I resorted to using [https://linux.die.net/man/8/pvmove pvmove] to just move the data on the PVs in use to a new PV. We started out with creating a new 50TiB PV, sde, and then to pvmove.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Attach /dev/sde to the VG my_vg&lt;br /&gt;
vgextend my_vg /dev/sde&lt;br /&gt;
&lt;br /&gt;
# Move the contents from /dev/sdb over to /dev/sde block by block. If a target is not given in pvmove,&lt;br /&gt;
# the contents of the source (sdb here) will be put somewhere else in the pool.&lt;br /&gt;
pvmove /dev/sdb /dev/sde&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This took a while (as in a week or so) - the pvmove command uses old code and logic (or at least did that when I migrated this in November 2016), but it affected performance on the server very little, so users didn&#039;t notice. After the first PV was migrated, I continued with the other two, one after the other, and after a month or so, it was migrated. We used this on a number of large fileservers, and it worked flawlessly. Before doing the production servers I also tried interrupting pvmove in various ways, including hard resets, and it just kept on after the reboot.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;NOTE:&#039;&#039;&#039;&#039;&#039; &#039;&#039;Even though it worked well for us, &#039;&#039;&#039;always&#039;&#039;&#039; keep a good backup before doing this. Things may go wrong, and without a good backup, you may be looking for a hard-to-find new job the next morning&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
==== mdadm workarounds ====&lt;br /&gt;
&lt;br /&gt;
===== Migrate from a mirror (raid-1) to raid-10 =====&lt;br /&gt;
&lt;br /&gt;
Create a mirror&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sdb /dev/sdc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
LVM (pv/vg/lv) on md0 (see above), put a filesystem on the lv and fill it with some data.&lt;br /&gt;
&lt;br /&gt;
Now, some months later, you want to change this to raid-10 to allow for the same amount of redundancy, but to allow more disks into the system.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mdadm --grow /dev/md0 --level=10&lt;br /&gt;
mdadm: Impossibly level change request for RAID1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So - no - doesn&#039;t work. But - we&#039;re on &lt;br /&gt;
&lt;br /&gt;
Since we&#039;re on lvm already, this&#039;ll be easy. If you&#039;re using filesystems directly on partitions, you can do this the same way, but without the pvmove part, using rsync or whateever you like instead. I&#039;d recommend using lvm for for the new raid, which should be rather obvious from this article. Now plug in a new drive and create a new raid10 on that one. If you two new drives, install both. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# change &amp;quot;missing&amp;quot; to the other device name if you installed two new drives&lt;br /&gt;
mdadm --create /dev/md1 --level=10 --raid-devices=2 /dev/vdd missing&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, as described above, just vgextend the vg, adding the new raid and run pvmove to move the data from the old pv (residing on the old raid1) to the new pv (on raid10). Afte rpvmove is finished (which may take awile, see above), just&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
vgreduce raidtest /dev/md0&lt;br /&gt;
pvremove /dev/md0&lt;br /&gt;
mdadm --stop /dev/md0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
…and your disk is free to be added to the new array. If the new raid is running in degraded mode (if you created it with just one drive), better don&#039;t wait too long, since you don&#039;t have redundancy. Just mdadm --add the devs.&lt;br /&gt;
&lt;br /&gt;
If you now have /dev/mdstat telling you your raid10 is active and have three drives, of which one is a spare, it should look something like this&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5] [raid4] [raid10]&lt;br /&gt;
md1 : active raid10 vdc[3](S) vdb[2] vdd[0]&lt;br /&gt;
      8380416 blocks super 1.2 2 near-copies [2/2] [UU]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Just mdadm --grow --raid-devices=3 /dev/md1&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;RAID section is not complete. I&#039;ll write more on migraing from raid10 to raid6 later. It&#039;s not straight forward, but easier than this one :)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== Thin provisioned LVs ===&lt;br /&gt;
&lt;br /&gt;
Thin provisioning on LVM is a method used for not allocating all the space given to an LV. For instance, if you have a 1TB VG and want to give an LV 500GB, although it currently only uses a fraction of that, a thin lv can be a good alternative. This will allow for adding a limit to how much it can use, but also to let it grow dynamically without manual work by the sysadmin. Thin provisioning adds another layer of abstaction by creating a special LV as a &#039;&#039;thin pool&#039;&#039; from which data is allocated to the &#039;&#039;thin volume(s)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== Create a thin pool ====&lt;br /&gt;
&lt;br /&gt;
Allocate 1TB to the thin pool to be used for thinly provisioned LVs. Keep in mind that the space allocated to the thin pool is in fact thick provisioned. Only the volumes put on &#039;&#039;thinpool&#039;&#039; are thin provisioned. This will create two hidden LVs, one for data and one for metadata. Normally the defaults will do, but check the manual if the data doesn&#039;t match the usual patterns (such as billions of files, resulting in huge amounts of metadata). I &#039;&#039;beleive&#039;&#039; the metadata part should be resizable at a later time if needed, but I have not tested it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a pool for thin LVs. Keep in mind that the pool itself is not thin provisioned, only the volumes residing on it&lt;br /&gt;
lvcreate --size 1T --type thin-pool --thinpool thinpool my_vg&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Create a thin volume ====&lt;br /&gt;
&lt;br /&gt;
You have the thinpool, now put a thin volume on it. It will allocate some space for metadata, but probably not much (a few megs, perhaps).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Now, create a volume with a virtual (-V) size of half a terabyte named thin_pool, but using the thinpool (-T) named thin_pool for storage&lt;br /&gt;
lvcreate -V 500G -T my_vg/thin_pool --name thinvol&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The new volume&#039;s device name will be /dev/thinvol. Now, create a filesystem on it, add to fstab and mount it. The &#039;&#039;&#039;df&#039;&#039;&#039; command will return available space according to the virtual size (-V), while lvs will show how much data is actually used on each of the thinly provisioned volumes.&lt;br /&gt;
&lt;br /&gt;
== Filesystem dilemmas ==&lt;br /&gt;
&lt;br /&gt;
=== XFS or ext4 or something else ===&lt;br /&gt;
The choice of filesystem varies for your use. Distros such as RHEL/CentOS has moved to XFS by default from v7. Debian/Ubuntu still sticks to ext4, like most other. I&#039;ll discuss my thoughts below on ext4 vs XFS and leave the other filesystems for later.&lt;br /&gt;
&lt;br /&gt;
==== ext4 ====&lt;br /&gt;
ext4 is probably the most used filesystem on linux as of writing. It&#039;s rock stable and has been extended by a lot of extensions since the original ext2. It still retains backward compatibility, being able to mount and fsck ext2 and ext3 with the ext4 driver. However, it doesn&#039;t handle large filesystems very well. If a filesystem is created for &amp;lt;16TiB, it cannot be grown to anything larger than 16TiB. This may have changed lately, though. One other issue is handling errors. If a large filesystem (say 10TiB) is damaged, an fsck may take several hours, leading to long downtime. When I refer to ext4 further in this text, the same applies to ext2 and ext3 unless otherwise specified.&lt;br /&gt;
&lt;br /&gt;
==== XFS ====&lt;br /&gt;
XFS, originally developed by SGI some time in the bronze age, but has been worked on heavily after that. RHEL and Centos version 7 and forward, uses XFS as the default filesystem. It is quick, it scales well, but it lacks at least two things ext4 has. It cannot be shrunk (not that you normally need that, but nice if you have a typo or you need to change things). Also, it doesn&#039;t allow for automatic fsck on bootup. If something is messed up on the filesystem, you&#039;ll have to login as root on the console (not ssh), which might be an issue on some systems. The fsck equivalent, xfs_repair, is a *lot* faster than ext4&#039;s fsck, though.&lt;br /&gt;
&lt;br /&gt;
==== ZFS ====&lt;br /&gt;
ZFS is like a combination of RAID, LVM and a filesystem, supporting full checksumming, auto-healing (given sufficient redundancy), compression, encryption, replication, deduplication (if you&#039;re brave and have a &#039;&#039;ton&#039;&#039; of memory) and a lot more. It&#039;s a separate chapter and needs a lot more talk than paragraph here.&lt;br /&gt;
&lt;br /&gt;
==== btrfs ====&lt;br /&gt;
btrfs, pronounced &amp;quot;butterfs&amp;quot; or &amp;quot;betterfs&amp;quot; or just spelled out, is a filesystem that mimics that of ZFS. It has been around for 10 years or so, but hasn&#039;t yet proven to be really stable. Following the progress of it for those years, I&#039;ve found it to be a nice toy with which to play, but not to be used in production. Again, others may say otherwise, but these are just my words.&lt;br /&gt;
&lt;br /&gt;
== Low level disk handling ==&lt;br /&gt;
&lt;br /&gt;
This section is for low-level handling of disks, regardless of storage system elsewhere. These apply to mdraid, lvmraid and zfs and possibly other solutions, with the exception of individual drives on hwraid (and maybe fakeraid), since there, the drives are hidden from Linux (or whatever OS).&lt;br /&gt;
&lt;br /&gt;
=== S.M.A.R.T. and slow drives ===&lt;br /&gt;
Modern (that is, from about 1990 or later) have S.M.A.R.T. (or just smart, since it&#039;s easier to type) monitoring built in, meaning the disk&#039;s controller is monitoring itself. This is handy and will ideally tell you in advance that a drive is flakey or dying. Modern (2010+) smart monitoring is more or less the same. It can be trusted about 50% of the time. Usually, if smart detects an error, it&#039;s a real error. I don&#039;t think I&#039;ve seen it reporting a false positive, but others may know better. &lt;br /&gt;
&lt;br /&gt;
==== smartmontools ====&lt;br /&gt;
First, install smartmontool and run smartclt -H /dev/yourdisk (/dev/sda or something) to get a health report. Then perhaps run smartctl -a /dev/yourdisk and look for &#039;current pending sectors&#039; This should be zero. Also check the temperature, which normally should be much above 50.&lt;br /&gt;
&lt;br /&gt;
==== single, slow drive ====&lt;br /&gt;
What may happen, is smart not seeing anything and life goes on like before, only slower and less prouductive, without telling anyone. If you stubler over this issue, you&#039;ll probably see it during a large rsync/zfs send/receive or a resync/rebuild/resilver of the raid/zpool. During this, it feels like everything is slow and your RAID has turned into a RAIF (redundant array of inexpensive floppies). To check if you have a single drive messing up it all, check with &#039;&#039;&#039;iostat -x 2&#039;&#039;&#039;, having 2 being the delay between each measurement. Interrupt it with ctrl+x. If there&#039;s a rougue drive there, it should stand out like sdg below&lt;br /&gt;
&lt;br /&gt;
 avg-cpu:  %user   %nice %system %iowait  %steal   %idle&lt;br /&gt;
            0.38    0.00    1.75    0.00    0.00   97.87&lt;br /&gt;
&lt;br /&gt;
 Device            r/s     w/s     rkB/s     wkB/s   rrqm/s   wrqm/s  %rrqm  %wrqm r_await w_await aqu-sz rareq-sz wareq-sz  svctm  %util&lt;br /&gt;
 sda              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdb              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdc              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdd              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sde              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdf              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdg              3.50    0.00   2352.00      0.00     0.00     0.00   0.00   0.00 14306.29    0.00  13.85   672.00     0.00 285.71 100.00&lt;br /&gt;
 sdh              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
&lt;br /&gt;
In ZFS land, you should be able to get similar data with &#039;&#039;&#039;zpool iostat -v &amp;lt;pool&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Now you know the bad drive (sdg), pull it from the raid with &#039;&#039;&#039;mdadm --fail /dev/mdX /dev/sdX&#039;&#039;&#039;. Now test the drive&#039;s performance manually, just simply:&lt;br /&gt;
&lt;br /&gt;
 # hdparm -t /dev/sdg&lt;br /&gt;
 &lt;br /&gt;
 /dev/sdg:&lt;br /&gt;
  Timing buffered disk reads:   2 MB in  5.37 seconds = 381.46 kB/sec&lt;br /&gt;
&lt;br /&gt;
Bingo - nothing you&#039;d want to keep. For a good drive, it should be something like 100-200MB/s&lt;br /&gt;
&lt;br /&gt;
PS: Keep in mind that you have a degraded RAID by now in case you had a spare waiting for things to happen.&lt;br /&gt;
&lt;br /&gt;
Try to replace the cable and/or try the disk on another port/controller. If the result from hdparm persists, it&#039;s probably a bad cable&lt;br /&gt;
&lt;br /&gt;
So, then, just psycially locate the drive, pull it out, take out the discs and magnets and recycle the rest.&lt;br /&gt;
&lt;br /&gt;
=== &amp;quot;Unplug&amp;quot; drive from system ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Find the device unit&#039;s number with something like&lt;br /&gt;
find /sys/bus/scsi/devices/*/block/ -name sdd&lt;br /&gt;
# returning /sys/bus/scsi/devices/3:0:0:0/block/sdd here, &lt;br /&gt;
# meaning 3:0:0:0 is the SCSI device we&#039;re looking for.&lt;br /&gt;
&lt;br /&gt;
# Given this is the correct device, and you want to &#039;unplug&#039; it, do so by&lt;br /&gt;
echo 1 &amp;gt; /sys/bus/scsi/devices/3:0:0:0/delete&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Rescan disk controllers ===&lt;br /&gt;
If a drive is added and for some reason doesn&#039;t get detected, or is removed by the command above, it can be rediscovered with a sysfs command to the scsi host to which it is connected. Since there may be quite a few of these, an easy way is to just scan them all and check the output of &#039;&#039;&#039;dmesg -T&#039;&#039;&#039; after running it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Make a list of controllers and send a rescan message to each of them. It won&#039;t do anything &lt;br /&gt;
# for those where nothing has changed, but it will show new drives where they have been added.&lt;br /&gt;
for host_scan in /sys/class/scsi_host/host*/scan&lt;br /&gt;
do&lt;br /&gt;
  echo &#039;- - -&#039; &amp;gt; $host_scan&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Fail injection with debugfs ===&lt;br /&gt;
[https://lxadm.com/Using_fault_injection https://lxadm.com/Using_fault_injection]&lt;br /&gt;
&lt;br /&gt;
== mdadm stuff ==&lt;br /&gt;
=== Resync ===&lt;br /&gt;
To resync a raid, that is, check, run&lt;br /&gt;
&lt;br /&gt;
 echo check &amp;gt; /sys/block/$dev/md/sync_action&lt;br /&gt;
&lt;br /&gt;
where $dev is something like md0. If you have several raids, something like this should work&lt;br /&gt;
&lt;br /&gt;
 for dev in md{0,1}&lt;br /&gt;
 do&lt;br /&gt;
   echo repair &amp;gt; /sys/block/$dev/md/sync_action&lt;br /&gt;
 done&lt;br /&gt;
&lt;br /&gt;
Also useful in a one-liner like&lt;br /&gt;
&lt;br /&gt;
 for dev in md{0,1} ; do echo repair &amp;gt; /sys/block/$dev/md/sync_action ; done&lt;br /&gt;
&lt;br /&gt;
Different raids on different drives will do this in parallel. If the drives are shared somehow with partitions or similar, the check or repair will wait for the other to finish before going on.&lt;br /&gt;
&lt;br /&gt;
As for repair vs check, [https://raid.wiki.kernel.org/index.php/RAID_Administration this article] describes it well. I stick to using repair unless it&#039;s something rare where I don&#039;t want to touch the data.&lt;br /&gt;
&lt;br /&gt;
=== Spare pools ===&lt;br /&gt;
In the old itmes, mdadm supported only a dedicated spare per md device, so if working with a large set of drives (20? 40?), where you&#039;d want to setup more raid sets to increase redundancy, you&#039;d dedicate a spare to each of the raid sets. This has changed (some time ago?), so in these modern, heathen days, you can change mdadm.conf, usually placed under /etc/mdadm, and add &#039;spare-group=somegroup&#039; where &#039;somegroup&#039; is a string identifying the spare group. After doing this, run &#039;&#039;&#039;update-initramfs -u&#039;&#039;&#039; and reboot and add a spare to one of the raid sets in the spare group, and md will use that or those spares for all the raidsets in that group.&lt;br /&gt;
&lt;br /&gt;
As some pointed out on #linux-raid @ irc.freenode.net, this feature is very badly documented, but as far as I can see, it works well.&lt;br /&gt;
&lt;br /&gt;
==== Example config ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create two raidsets&lt;br /&gt;
&lt;br /&gt;
mdadm --create /dev/md1 --level=6 --raid-devices=6 /dev/vd[efghij]&lt;br /&gt;
mdadm --create /dev/md2 --level=6 --raid-devices=6 /dev/vd[klmnop]&lt;br /&gt;
&lt;br /&gt;
# get their UUID etc&lt;br /&gt;
&lt;br /&gt;
mdadm --detail --scan&lt;br /&gt;
ARRAY /dev/md/1 metadata=1.2 name=raidtest:1 UUID=1a8cbdcb:f4092350:348b6b80:c054d74c&lt;br /&gt;
ARRAY /dev/md/2 metadata=1.2 name=raidtest:2 UUID=894b1b7c:cb7eba70:917d6033:ea5afd2b&lt;br /&gt;
&lt;br /&gt;
# Put those lines into /etc/mdadm/mdadm.conf and and add the spare-group&lt;br /&gt;
&lt;br /&gt;
ARRAY /dev/md/1 metadata=1.2 name=raidtest:1 spare-group=raidtest UUID=1a8cbdcb:f4092350:348b6b80:c054d74c&lt;br /&gt;
ARRAY /dev/md/2 metadata=1.2 name=raidtest:2 spare-group=raidtest UUID=894b1b7c:cb7eba70:917d6033:ea5afd2b&lt;br /&gt;
&lt;br /&gt;
# update the initramfs and reboot&lt;br /&gt;
&lt;br /&gt;
update-initramfs -u&lt;br /&gt;
reboot&lt;br /&gt;
&lt;br /&gt;
# add a spare drive to one of the raids&lt;br /&gt;
&lt;br /&gt;
mdadm --add /dev/md1 /dev/vdq&lt;br /&gt;
&lt;br /&gt;
# fail a drive on the other raid&lt;br /&gt;
&lt;br /&gt;
mdadm --fail /dev/md2 /dev/vdn&lt;br /&gt;
&lt;br /&gt;
# check /proc/mdstat to see md2 rebuilding with the spare from md1&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Recovery ===&lt;br /&gt;
&lt;br /&gt;
The other day, I came across a problem a user had on #linux-raid@irc.freenode.net. He had an old Qnap NAS that had died and tried plugging the drives in to his Linux machine and got various errors. The two-drive RAID-1 did not come up as it should, &#039;&#039;&#039;dmesg&#039;&#039;&#039; was full of errors from one of the drives (both connected on USB) and so forth.&lt;br /&gt;
&lt;br /&gt;
We went on and started by taking down the machine and just connecting one of the drives. I had him check what was assembled with&lt;br /&gt;
&lt;br /&gt;
 cat /proc/mdstat&lt;br /&gt;
&lt;br /&gt;
That returned /proc/md127 assembled, but LVM didn&#039;t find anything. So running a manual scan&lt;br /&gt;
&lt;br /&gt;
 pvscan --cache /dev/md127&lt;br /&gt;
&lt;br /&gt;
This made linux find the PV, VG and a couple of LVs, but probably because the mdraid was degraded, the LVs were deactivated, according to &#039;&#039;&#039;lvscan&#039;&#039;&#039;. Activating the one with a filesystem manually&lt;br /&gt;
&lt;br /&gt;
 lvchange -a y /dev/&amp;lt;vg&amp;gt;/&amp;lt;lv&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Substitute &amp;lt;vg&amp;gt; and &amp;lt;lv&amp;gt; with the names listed by vgs and lvs.&lt;br /&gt;
&lt;br /&gt;
This worked, and the filesystem on /dev/&amp;lt;vg&amp;gt;/&amp;lt;lv&amp;gt; could be mounted correctly.&lt;br /&gt;
&lt;br /&gt;
=== Renaming a RAID ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Not finished&#039;&#039;&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
&lt;br /&gt;
Back around 2001, I asked on the linux-raid list for disk tagging, not default back then, but supported, and thought of the possibility of disk #1 getting replaced with disk #1 from another raid because of a messup. After this, the hostname was added to the raid name in the superblock. So when a RAID is created, it is named &amp;quot;hostname:raidname&amp;quot;, where the raidname is either a number (0,1...) or a name. &lt;br /&gt;
&lt;br /&gt;
For instance, running this on my VM named &amp;quot;raidtest&amp;quot;:&lt;br /&gt;
&lt;br /&gt;
 mdadm --create --level=1 --raid-devices=2 /dev/md/stuff /dev/sd[st]&lt;br /&gt;
&lt;br /&gt;
mdadm --detail --scan now shows this&lt;br /&gt;
&lt;br /&gt;
 ARRAY /dev/md/stuff metadata=1.2 name=raidtest:stuff UUID=c4cdf69f:393a28b1:47648ed3:726613de&lt;br /&gt;
&lt;br /&gt;
Now, you might want to change this name for some reason, and it&#039;s not supported under &amp;quot;grow&amp;quot;, so what to do… The name is, after all, local to the disk, since it&#039;s there to avoid messing up a raid (or two) after a disk mixup.&lt;br /&gt;
&lt;br /&gt;
 mdadm --assemble /dev/md/stuff --name &#039;someotherhost:stuff&#039; --update=homehost /dev/sd[st]&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== The badblock list ===&lt;br /&gt;
&#039;&#039;&#039;md&#039;&#039;&#039; has an internal badblock list (BBL), added around 2010, to list the bad blocks on the disk to avoid using those. While this might sound like a good idea, the badblock list is updated in case of a read error, which can be caused by several things. To make things worse, the BBL is replicated to other drives when a drive fails or the array is grown. So if you start out with sda and sdb and sdb suffers some errors, nothing wrong, md will read from sda, but flag those sectors on sdb as bad. So after a while, perhaps sda dies and gets replaced, with the same content, including the BBL. Then, at some point you might to replace sdb and it, too gets the BBL. So it sticks - forever. Also, there&#039;s no real point of keeping a BBL list, since the drive has its own and even if a sector error occurs, the array will have sufficient redundancy to recover from that (unless you use RAID-0 which you shouldn&#039;t). If a drive finds a bad sector, it&#039;ll be reallocated by the drive itself without the user&#039;s/admin&#039;s/system&#039;s knowledge. If a sector can&#039;t be reallocated, it means the drive is bad and should be replaced.&lt;br /&gt;
&lt;br /&gt;
There&#039;s no official way to remove it and although you can assemble it with the no-bbl option, this will only work if there&#039;s an empty BBL. Also, this will require downtime. As far as I can see, the only way to do this currently, is with a wee hack that should work. Just replace the names of mddev/diskdev with your own.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
mddev=&amp;quot;/dev/md0&amp;quot;&lt;br /&gt;
diskdev=&amp;quot;/dev/sda&amp;quot;&lt;br /&gt;
mdadm $mddev --fail $diskdev --remove $diskdev --re-add $diskdev --update=no-bbl&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If there&#039;s a BBL on the drive already, replace the --update part to &#039;force-no-bbl&#039;. This is not documented anywhere as per se, but it works.&lt;br /&gt;
 &lt;br /&gt;
I haven&#039;t found a way to turn this off permanently, but there may be something coming around when the debate on the linux-raid mailing list closes up on this. There&#039;s a bbl=no in mdadm.conf, but that&#039;s only for creation. I will continue extensive testing for this.&lt;br /&gt;
&lt;br /&gt;
== Tuning ==&lt;br /&gt;
&lt;br /&gt;
While trying to compare a 12-disk RAID (8TB disks) to a hwraid, mdraid was slower, so we did a few things to speed things up:&lt;br /&gt;
&lt;br /&gt;
While testing with [https://linux.die.net/man/1/fio fio], monitor /sys/block/md0/md/stripe_cache_active, and see if it&#039;s close to /sys/block/md0/md/stripe_cache_size. If it is, double the size of the latter&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
echo 4096 &amp;gt; /sys/block/md0/md/stripe_cache_size&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Continue until stripe_cache_active stabilises, and then you&#039;ve found the limit you&#039;ll need. You may want to double that for good measure. &lt;br /&gt;
&lt;br /&gt;
(to be continued)&lt;br /&gt;
&lt;br /&gt;
== Links ==&lt;br /&gt;
&lt;br /&gt;
Below are a few links with useful info&lt;br /&gt;
&lt;br /&gt;
* [https://raid.wiki.kernel.org/index.php/Irreversible_mdadm_failure_recovery Irreversible mdadm failure recovery]&lt;br /&gt;
&lt;br /&gt;
= ZFS =&lt;br /&gt;
&lt;br /&gt;
ZFS can do a lot of things most filesystems or volume managers can&#039;t. It checksums all data and metadata and so long that the system uses ECC enabled memory (RAM), it will have complete control over the whole data set, and when (not if) an error occurs, it&#039;ll fix the issue without even throwing a warning. To fix the issue, you&#039;ll obviously need sufficient redundancy (mirrors or RAIDzN). &lt;br /&gt;
&lt;br /&gt;
== ZFS send/receive between machines ==&lt;br /&gt;
&lt;br /&gt;
ZFS has a send/receive mechanism that allows for snapshots to be sent over the wire to a receiving end. This can be a full filesystem, or an incremental change since last send/reveive. In a WAN scenario, you&#039;ll probably want to use VPN for this. On a controlled network, sending in cleartext is also possible. You may as well use ssh, but keep in mind that ssh was never designed to be used as a fullblown vpn solution and is just too slow or the task with large amounts of data. You may, though, use mbuffer, if on a loal LAN.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Allow traffic from the sending IP in whatever firewall interface you&#039;re using (if you&#039;re using a firewall at all, that is)&lt;br /&gt;
ufw allow from x.x.x.x&lt;br /&gt;
# &lt;br /&gt;
# Start the receiver first. This listens on port 9090, has a 1GB buffer,&lt;br /&gt;
    and uses 128kb chunks (same as zfs):&lt;br /&gt;
&lt;br /&gt;
mbuffer -s 128k -m 1G -I 9090 | zfs receive data/filesystem&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To be continued one day… See [https://everycity.co.uk/alasdair/2010/07/using-mbuffer-to-speed-up-slow-zfs-send-zfs-receive/ this] for some more. I&#039;ll get back with details on it.&lt;br /&gt;
&lt;br /&gt;
= General Linux system control =&lt;br /&gt;
&lt;br /&gt;
== Add a new CPU (core) ==&lt;br /&gt;
&lt;br /&gt;
If working with virtual machines, adding a new core can be useful if the VM is slow and the load is multithreaded or multiprocess. To do this, add a new CPU in the hypervisor (be it KVM or VMware or Hyper-V or whatever). Some hypervisors, like VMware, will activate it automatically if open-vm-tools is installed. Please note that open-vm-tools is for VMware only. I don&#039;t know of any such thing for KVM or other hypervisors (although I beleive VirtualBox has its own set of tools, but not as a package). If this doesn&#039;t work, run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
echo 1 &amp;gt; /sys/devices/system/cpu/cpuX/online&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where X is the CPU number you want to add. You can &#039;cat /sys/devices/system/cpu/cpuX/online&#039; to check if it&#039;s online.&lt;br /&gt;
&lt;br /&gt;
= Mount partitions on a disk image =&lt;br /&gt;
&lt;br /&gt;
Sometimes you&#039;ll have a disk image, either from recovering a bad drive after hours (or days or weeks) of ddrescue, and sometimes you just have a disk image from a virtual machine where you want to mount the partitions inside the image. There are three main methods of doing this, which are more or less synonmous, but some easier than the other.&lt;br /&gt;
&lt;br /&gt;
== Basics ==&lt;br /&gt;
&lt;br /&gt;
A disk image is usually like a disk, consisting of either a large filesystem, a PV or a partition table with one or partitions onto which resides a filesystem, a pv, swap or something else. If it&#039;s partitioned, and you want your operating system to mount a filesystem or allow it to see whatever LVM stuff lies on it, you need to isolate the partitions. &lt;br /&gt;
&lt;br /&gt;
== Manual mapping ==&lt;br /&gt;
&lt;br /&gt;
In the oldern days, this was done manually, something like this&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
root@mymachine:~# fdisk -l /dev/vda&lt;br /&gt;
Disk /dev/vda: 25 GiB, 26843545600 bytes, 52428800 sectors&lt;br /&gt;
Units: sectors of 1 * 512 = 512 bytes&lt;br /&gt;
Sector size (logical/physical): 512 bytes / 512 bytes&lt;br /&gt;
I/O size (minimum/optimal): 512 bytes / 512 bytes&lt;br /&gt;
Disklabel type: dos&lt;br /&gt;
Disk identifier: 0xc37b7ea5&lt;br /&gt;
&lt;br /&gt;
Device     Boot    Start      End  Sectors  Size Id Type&lt;br /&gt;
/dev/vda1  *        2048 50333311 50331264   24G 83 Linux&lt;br /&gt;
/dev/vda2       50333312 52426369  2093058 1022M  5 Extended&lt;br /&gt;
/dev/vda5       50333314 52426369  2093056 1022M 82 Linux swap / Solaris&lt;br /&gt;
root@mymachine:~#&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To calculate the start and end of each partition, you just take the start sector and multiply it by the sector size (512 bytes here) and you have the offset in bytes. After this, it&#039;s merely an losetup -o &amp;lt;offset&amp;gt; /dev/loopX &amp;lt;nameofimagefile&amp;gt; and you have the partition mapped to your /dev/loopX (having X being something typically 0-255. After this, just mount it or run pvscan/vgscan/lvscan to probe whatever lvm config is there, and you should be able to mount it like any other filesystem.&lt;br /&gt;
&lt;br /&gt;
== kpartx ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;kpartx&#039;&#039;&#039; does the same as above, more or less, just without so much hassle. Most of it should be automatic and easy to deal with, except it may fail to disconnect the loopback devices sometimes, so you may have to &#039;&#039;&#039;losetup -d&#039;&#039;&#039; them manually. See the manual, &#039;&#039;&#039;kpartx (8)&#039;&#039;&#039;. Please note that &#039;&#039;&#039;partx&#039;&#039;&#039; works similarly and I&#039;d guess the authors of the two tools are arguing a lot of which one&#039;s the best.&lt;br /&gt;
&lt;br /&gt;
== guestmount ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;guestmount&#039;&#039;&#039; is something similar again, but also supports file formats like &#039;&#039;&#039;qcow2&#039;&#039;&#039; and possibly other, proprietary filesystems like &#039;&#039;&#039;vmdk&#039;&#039;&#039; and &#039;&#039;&#039;vdi&#039;&#039;&#039;, but don&#039;t take my word for it - I haven&#039;t tested. Again, see the manual or just read up on the description [http://ask.xmodulo.com/mount-qcow2-disk-image-linux.html?fbclid=IwAR3snTeZvGzp9PLdX11EQhCfOpux6I93CiJ3A2pUomkkRLly9Xo4851mkTY here]. It seems rather trivial.&lt;br /&gt;
&lt;br /&gt;
= Linux on laptops =&lt;br /&gt;
&lt;br /&gt;
== Wifi with HP EliteBook 725/745 on Ubuntu ==&lt;br /&gt;
&lt;br /&gt;
The HP EliteBook 725/745 and similar are equipped with a BCM4352 wifi chip. As with a lot of other stuff from Broadcom, this lacks an open hardware description, so thus no open driver exist. The proper fix, is to replace the NIC with something with an open driver, but again, this isn&#039;t always possible, so a binary driver exists. In ubuntu, run, somehow connect the machine to the internet and run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install bcmwl-kernel-source&lt;br /&gt;
sudo modprobe wl&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you can&#039;t connect the machine to the internet, download the needed packages on another machine and put it on some usb storage. These packages should suffice:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# apt-cache depends bcmwl-kernel-source&lt;br /&gt;
bcmwl-kernel-source&lt;br /&gt;
  Depends: dkms&lt;br /&gt;
  Depends: linux-libc-dev&lt;br /&gt;
  Depends: libc6-dev&lt;br /&gt;
  Conflicts: &amp;lt;bcmwl-modaliases&amp;gt;&lt;br /&gt;
  Replaces: &amp;lt;bcmwl-modaliases&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then install manually with &#039;&#039;&#039;dpkg -i file1.deb file2.deb&#039;&#039;&#039; etc&lt;br /&gt;
&lt;br /&gt;
After this, ip/ifconfig/iwconfig shouldd see the new wifi nic, probably &#039;&#039;&#039;wlan0&#039;&#039;&#039;, but due to a [https://bugs.launchpad.net/ubuntu/+source/broadcom-sta/+bug/1343151 old, ignored bug], you won&#039;t find any wifi networks. This is because the driver from Broadcom apparently does not support interrupt remapping, commonly used on x64 machines. To turn this off, change &#039;&#039;&#039;/etc/default/grub&#039;&#039;&#039; and change the line &#039;&#039;&#039;GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;quiet splash&amp;quot;&#039;&#039;&#039;, adding intremap=off to the end before the quote: &#039;&#039;&#039;GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;quiet splash intremap=off&amp;quot;&#039;&#039;&#039;. Save the file and run &#039;&#039;&#039;sudo update-grub&#039;&#039;&#039; and reboot. After this, wifi should work well.&lt;br /&gt;
&lt;br /&gt;
== Wifi with HP Compaq Presario CQ57 on Ubuntu ==&lt;br /&gt;
&lt;br /&gt;
The HP Compaq Presario CQ57 uses the RT5390 wifi chipset. This has been supported for quite some time now, and I was quite surprised to find it not working on a laptop a friend was having. The driver loaded correctly, but Ubuntu insisted of the laptop being in &#039;&#039;&#039;flight mode&#039;&#039;&#039;. Checking &#039;&#039;&#039;rfkill&#039;&#039;&#039;, it showed me two NICs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# rfkill list all&lt;br /&gt;
0: phy0: Wireless LAN&lt;br /&gt;
	Soft blocked: no&lt;br /&gt;
	Hard blocked: yes&lt;br /&gt;
1: hp-wifi: Wireless LAN&lt;br /&gt;
	Soft blocked: yes&lt;br /&gt;
	Hard blocked: no&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Turning rfkill on and off resulted in nothing much, except some error messages in the kernel log (dmesg)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] ACPI Error: Field [B128] at bit offset/length 128/1024 exceeds size of target Buffer (160 bits) (20170831/dsopcode-235)&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]&lt;br /&gt;
                            Initialized Local Variables for Method [HWCD]:&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Local0: 00000000a34b7928 &amp;lt;Obj&amp;gt;           Integer 0000000000000000&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Local1: 00000000b0aa6865 &amp;lt;Obj&amp;gt;           Buffer(8) 46 41 49 4C 04 00 00 00&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Local5: 00000000a9811efd &amp;lt;Obj&amp;gt;           Integer 0000000000000004&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] Initialized Arguments for Method [HWCD]:  (2 arguments defined for method invocation)&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Arg0:   0000000078957d1b &amp;lt;Obj&amp;gt;           Integer 0000000000000001&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Arg1:   00000000725c9c6e &amp;lt;Obj&amp;gt;           Buffer(20) 53 45 43 55 02 00 00 00&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] ACPI Error: Method parse/execution failed \_SB.WMID.HWCD, AE_AML_BUFFER_LIMIT (20170831/psparse-550)&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] ACPI Error: Method parse/execution failed \_SB.WMID.WMAD, AE_AML_BUFFER_LIMIT (20170831/psparse-550)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After upgrading BIOS and testing different kernels, I was asked to try to unload the &#039;&#039;&#039;hp_wmi&#039;&#039;&#039; driver. I did, and things changed a bit, so I tried blacklisting it, creating the file &#039;&#039;&#039;/etc/modprobe.d/blacklist-hp_wmi.conf&#039;&#039;&#039; with the following content&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Blacklist this - it doesn&#039;t work!&lt;br /&gt;
blacklist hp_wmi&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
I gave the machine a reboot and afte that, the &#039;&#039;&#039;hp-wifi&#039;&#039;&#039; entry was gone in the rfkill output, and things works.&lt;br /&gt;
&lt;br /&gt;
= Raspberry pi =&lt;br /&gt;
&lt;br /&gt;
I couldn&#039;t quite decide if the raspberry pi should be a separate section or part of Linux, but hell, it can run more than Linux, although 99,lots% of people just uses Linux on them. This is a small list of things to know about them; things not on the front page of the manual or perhaps hidden even better.&lt;br /&gt;
&lt;br /&gt;
== Which pi? ==&lt;br /&gt;
&lt;br /&gt;
I just setup three raspberry pi machines and although some are quite different, like v1 to vEverythingelse or the Pi zero versions to the normal ones, not all of us remember how to distinguish between them, and sometimes they&#039;re in a nice 3d printed (or otherwise) chassis or otherwise hidden. So, how to check three different ones:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
root@home-assistant:~ $ cat /proc/device-tree/model ; echo&lt;br /&gt;
Raspberry Pi 2 Model B Rev 1.1&lt;br /&gt;
&lt;br /&gt;
root@green-pi:~ $ cat /proc/device-tree/model ; echo&lt;br /&gt;
Raspberry Pi 3 Model B Rev 1.2&lt;br /&gt;
&lt;br /&gt;
roy@yellow-pi:~ $cat /proc/device-tree/model ; echo&lt;br /&gt;
Raspberry Pi 4 Model B Rev 1.1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
While this works well, for the latter, the pi4, it doesn&#039;t tell how much memory I have. It comes in variants of 1, 2 and 4GB, and this is the latter.&lt;br /&gt;
&lt;br /&gt;
For a more detailed list, the command &#039;&#039;&#039;awk &#039;/^Revision/ {sub(&amp;quot;^1000&amp;quot;, &amp;quot;&amp;quot;, $3); print $3}&#039; /proc/cpuinfo&#039;&#039;&#039; will give you a revision number, detailing the type of pi, who produced it etc. Please see [https://elinux.org/RPi_HardwareHistory https://elinux.org/RPi_HardwareHistory] for a full table.&lt;br /&gt;
&lt;br /&gt;
== Monitoring ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;vcgencmd&#039;&#039;&#039; from &#039;&#039;&#039;/opt/vc/bin&#039;&#039;&#039;, but symlinked to &#039;&#039;&#039;/usr/bin&#039;&#039;&#039; so it&#039;s available in path, is useful for fetching hardware info about the pi. For example, measuring the temperature&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
root@yellow-pi:~# vcgencmd measure_temp&lt;br /&gt;
temp=63.0&#039;C&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The command is generally badly documented and parts of it seems outdated for newer hardware. Here&#039;s the output from a Raspberry pi 4 with 4GB RAM&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
roy@yellow-pi:~ $ vcgencmd get_mem arm&lt;br /&gt;
arm=948M&lt;br /&gt;
roy@yellow-pi:~ $ vcgencmd get_mem gpu&lt;br /&gt;
gpu=76M&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= BIOS upgrade from Linux =&lt;br /&gt;
&lt;br /&gt;
Generally, BIOS upgrades have been moved to the BIOS itself these days. This saves a lot of work and quite possibly lives after those who earier rammed their heads through walls, now can upgrade directly from the internet instead of using obscure operating systems best avoided. Sometimes, however, one must use these nevertheless. This is a quick run-through on your options.&lt;br /&gt;
&lt;br /&gt;
== DOS ==&lt;br /&gt;
&lt;br /&gt;
Most non-automatic BIOS upgrades are installed from DOS. Doing a BIOS upgrade this way, is generally non-problematic. Just install a USB thingie with [https://www.freedos.org/ FreeDOS], copy your file(s) onto the thing and boot on it. The commandline is the same as old MS/DOS, except a wee bit more userfriendly, but not a lot.&lt;br /&gt;
&lt;br /&gt;
== Windows ==&lt;br /&gt;
&lt;br /&gt;
Some macahines, like laptops from &#039;&#039;&#039;HP&#039;&#039;&#039;, may have BIOS upgrades that are made to be installed from Windows and won&#039;t run in FreeDOS or MS/DOS, instead throwing an error, saying &#039;&#039;&#039;This program cannot be run in DOS mode&#039;&#039;&#039;. This means you&#039;ll have to boot on a Windows rescue disc and do the job from there. Googling this, tells you it&#039;s quite easy, you just choose &#039;make rescue disc&#039; from Windows, and it&#039;s all good, except if you don&#039;t run Windows, that is. To remedy this problem, do as follows:&lt;br /&gt;
&lt;br /&gt;
=== Download Windows ===&lt;br /&gt;
&lt;br /&gt;
Since you don&#039;t run Windows and possibly don&#039;t have a spouse or friend around with such unhealthy habits either, you need to get it. It&#039;s quite easy - just google &#039;download windows&#039; and it&#039;ll send you to [https://www.microsoft.com/en-us/software-download/windows10ISO somewhere like this].&lt;br /&gt;
&lt;br /&gt;
=== Burn it! ===&lt;br /&gt;
&lt;br /&gt;
Now it&#039;s time to burn the installer on a DVD ROM. You&#039;ll need a double-layered one, since the OS is &amp;gt; 4.7GiB, but I&#039;m sure you have a ton of those lying around. Now, just place your optical medium in your optical drive and burn, baby, burn!&lt;br /&gt;
&lt;br /&gt;
=== Or make a USB thing? ===&lt;br /&gt;
&lt;br /&gt;
Not a lot of machines have optical drives these days, so you may want to use an USB pen drive or something instead. This is easy, just make the USB bootable with the Windows application Microsoft has made for this. Unfortunately, this only runs on Windows, and unlike stuff like Debian, where the &#039;&#039;&#039;iso&#039;&#039;&#039; file can be dd&#039;ed directly onto a USB drive to make it bootable, the Windows &#039;&#039;&#039;iso&#039;&#039;&#039;s don&#039;t come with this luxury. There are lots of methods to make bootable USB things from iso files out there, but the only thing most of them have in common, is that they generally don&#039;t work.&lt;br /&gt;
&lt;br /&gt;
==== WoeUSB ====&lt;br /&gt;
&lt;br /&gt;
After hours of swearing, it&#039;s nice to come across software like [https://github.com/slacka/WoeUSB WoeUSB]. It may not be perfect, it relies on a bunch of GUI stuff you&#039;ll never need and so on, but it &#039;&#039;&#039;&#039;&#039;works&#039;&#039;&#039;&#039;&#039;, and that&#039;s the important part! Just clone the repo and RTFM and it&#039;s all nice. It&#039;s slow, but hell, getting a windows machine and/or an optical drive might be slower.&lt;br /&gt;
&lt;br /&gt;
WoeUSB does nothing fancy, but it &#039;&#039;&#039;does&#039;&#039;&#039; work. It will create a filesystem, FAT32 or NTFS (better use NTFS, FAT32 has its limits). It creates normal filesystems and so on. Just make sure to copy in the BIOS update file, usually an exe file, to run when Windows is up and running.&lt;br /&gt;
&lt;br /&gt;
==== Install BIOS ====&lt;br /&gt;
&lt;br /&gt;
Boot on the Windows USB thing and choose &#039;repair computer&#039; and then &#039;command prompt&#039;. Find the install file, and if you&#039;re lucky, you&#039;ll find it needs a 32bit OS, just like I did. Since the 64bit version doesn&#039;t include 32bit compatibility in the installer, revert to downloading the 32bit version of windows and start over. Pray to your favourite god(s) not to get across such machines again - it might help.&lt;br /&gt;
&lt;br /&gt;
= 3D printer stuff =&lt;br /&gt;
&lt;br /&gt;
Below are a number of not very ordered paragraphs about 3D printer related stuff, mostly based on my experience. Their content may be interesting or perhaps practical knowledge, but then, that depends on the reader.&lt;br /&gt;
&lt;br /&gt;
== 3D printer related introductions on youtube or elsewhere ==&lt;br /&gt;
&lt;br /&gt;
First off, I&#039;d like to mention some youtube videos that are all (or mostly) a nice start if you&#039;re new to 3D printers.&lt;br /&gt;
&lt;br /&gt;
=== [https://www.youtube.com/watch?v=nb-Bzf4nQdE&amp;amp;list=PLDJMid0lOOYnkcFhz6rfQ6Uj8x7meNJJx Thomas Salanderer&#039;s 10-video series on 3D printing basics] ===&lt;br /&gt;
&lt;br /&gt;
Thomas Salanderer is a an experienced 3D printer user/admin/fixer/etc and he has a lot of interesting videos. Some accuse him for being a [Prusa https://www.prusa3d.com/] fanboy, which he quite obviously is, but that doesn&#039;t stop him from making interesting and somewhat neutral videos. The series walks you thought the first steps of how things work and so on and hopefully opens more doors than anything else I&#039;ve seen.&lt;br /&gt;
&lt;br /&gt;
=== [https://www.youtube.com/watch?v=rp3r921DBGI Teaching Tech&#039;s &amp;quot;3D printer tuning reborn&amp;quot;] ===&lt;br /&gt;
&lt;br /&gt;
Teaching Tech is, like Salanderer or even more, good pedagogically and explains a lot. They (or he) do a bunch of testing and describing pros and cons with different things, just like other youtubers in the sme business. The mentioned video shows how to tune a 3D printer after you have first learned the basics, and leans on a webpage made to help you out without too much manual work.&lt;br /&gt;
&lt;br /&gt;
This was a short list, but I guess it&#039;ll grow over time.&lt;br /&gt;
&lt;br /&gt;
== Hydrophilic filament ==&lt;br /&gt;
&lt;br /&gt;
Most popular filament types, including PLA, PETG, PP or PA (Polyamide, normally known as Nylon) and virtualy any filament type named [https://www.matterhackers.com/news/filament-and-water poly-something] (and thus with an acronym of P-something) are hydrophilic (also (somewhat incorrectly) called hydroscopic), meaning so long they&#039;re dryer than the atmosphere around them, they&#039;ll do their best to suck out the atmosphere&#039;s humidity. This is why most filament are shrink-wrapped with a small bag of silica gel in it. If such filament is exposed for normal humid air for some time, it&#039;ll become very hard to use. Most of my experience is with PLA, which can handle a bit (depending on make), but still not a lot. With PLA, if you end up with prints where the filament seems not to stick, it may help with a higher temperature. Otherwise, the filament must be [https://all3dp.com/2/how-to-dry-filament-pla-abs-and-nylon/ baked]. If you don&#039;t want to use your oven, try something like a [https://www.jula.no/catalog/hjem-og-husholdning/kjokkenmaskiner/mattilberedningsapparater/frukt-sopptorker/frukt-sopptorker-001641/#tab02 fruit and mushroom dryer]. Then get a good, sealble plastic box and add something like half a kilogram of [https://www.ebay.com/sch/sis.html?_nkw=1KG+Orange+Replacement+Desiccant+Indicating+Silica+Gel+Beads+for+Drawers%2C+Camera&amp;amp;_id=131938742628&amp;amp;&amp;amp;_trksid=p2057872.m2749.l2658 silica gel] to an old sock, tie it and put it in the your new dry box.&lt;br /&gt;
&lt;br /&gt;
Please note that ABS is hydrophobic, so you won&#039;t have to worry too much there. Also, remember that PA/Nylon is extremely hydrophilic. Even a couple of days in normal air humidity can ruin it completely and will require baking.&lt;br /&gt;
&lt;br /&gt;
== Upgrading the firmware on an Ender 3 ==&lt;br /&gt;
&lt;br /&gt;
This is about upgrading the firmware, and thus also flashing a bootloader to the Creality Ender 3 3D printer. Most of this is well documented on several place, like o [https://www.youtube.com/watch?v=fIl5X2ffdyo the video from Teaching tech] and elsewhere, but I&#039;ll just summarise some issues I had.&lt;br /&gt;
&lt;br /&gt;
=== Using an arduino Nano as a programmer ===&lt;br /&gt;
&lt;br /&gt;
Quick note before you read on. If you have an Ender 3 controller version 1.1.5 or newer (or perhaps even a bit older), a CR-10S or some other more or less modern printers or controllers, they come with a bootloader installed already, so don&#039;t bother flashing one. The one that&#039;s in there already, should work well. So if you have one of these, just skip this and jump to the [[Roy&#039;s_notes#Flashing_the_printer|next section]].&lt;br /&gt;
&lt;br /&gt;
However, the normal CR-10 (without the S), Ender 3 and a few other printers from Creality come without a bootloader, so you&#039;ll need to flash one before upgrading the firmware. Well, strictly speakning, you don&#039;t need one, you can save those 8kB or so for other stuff and use a programmer to write the whole firmware, but then you&#039;ll need to wire up everything every time you want a new firmware, so in my world, you &#039;&#039;&#039;do&#039;&#039;&#039; need the bootloader, since it&#039;s easier.&lt;br /&gt;
&lt;br /&gt;
To install a bootloader, you&#039;ll need a programmer, and I didn&#039;t have one available. Having some el-cheapo china-copies of Arduinos around, I read I could use one and tried so. Although the docs mostly mention the Uno etc, it&#039;s just as simple with the Nano copy.&lt;br /&gt;
&lt;br /&gt;
So, grab an arduino, plug it to your machine with a USB cable, and, using the Arduino IDE, use the ArduinoISP sketch there (found under Examples) to burn the software needed for the arduino to work as a programmer. When this is done, connect a 10µF capacitor between RST and GND to stop it from resetting when used as a programmer. Connect the MOSI, MISO and SCK pins from the ICSP block (that little isolated 6-pin block on top of the ardu). See [https://www.arduino.cc/en/Tutorial/ArduinoISP here] for a pinout. Then find Vcc and GND either on the ICSP block or elsewhere. Some sites say that on some boards you shouldn&#039;t use the pins on the ICSP block for this. I doubt it matters, though. Then connect another jumper wire from pin 10 on the ardu to work as the reset pin outwards to the chip being programmed (that is, on the printer). The ICSP jumper block pin layout is the same on the printer and on the ardu, and probably elsewhere. Sometimes [https://xkcd.com/927/ standardisation] actually works…&lt;br /&gt;
&lt;br /&gt;
[[File:Ardu-nano-as-programmer.jpg|500px]]&lt;br /&gt;
&lt;br /&gt;
== Flashing the printer ==&lt;br /&gt;
&lt;br /&gt;
When the boot loader is in place, possibly after some wierd errors from during the process, the screen on the 3d printer will go blank and it&#039;ll behave like being bricked. This is ok. Now disconnect the wires and connect the USB cable between computer and printer. If you haven&#039;t installed support for the Sanguino board, that is, the variant of the 1284-chip and surrounding electronics that is the core of the, you need to install it first. In the Arduino IDE, choose the Tools / Boards / Boards manager boot option and search for Sanguino. After this, you should find the Sanguino or Sanguino 1284p in the boards menu. After this, you should be able to communicate with the printer&#039;s controller. Download the [https://www.th3dstudio.com/knowledgebase/th3d-unified-firmware-package/ TH3D unified firmware], making sure it&#039;s the last version. Uncompress the zip and with Finder/Explorer/whateversomething&#039;scalledonlinux, browse to &#039;&#039;&#039;TH3DUF_R2/Firmware/TH3DUF_R2.ino&#039;&#039;&#039; and open it. It should open directly in the Android IDE. Keep in mind that the names TH3DUF_R2 and TH3DUF_R2.ino will vary between versions, but you get the point. Now configure it for your particular needs. You&#039;ll find most of this in the Configuration.h tab (that&#039;s really a file). Most of the other files won&#039;t be necessary unless you&#039;re doing some more advanced stuff, like replacing th controller with something non-standard or similar, but then again, that&#039;s another chapter (or book, even). The video mentioned above describes this well. After flashing the new firmware, you&#039;ll probably get some timeouts and errors, since apparently it resets the printer after giving it the new firmware, but without notifying the flashing software of it doing so. If this happens, calm down and reboot the printer and check its tiny monitor - it should work. If it doesn&#039;t work, and if you flashed the bootload yourself, try to flash it again, and if that doesn&#039;t work, try flashing the programmer again yet another time, just for kicks. Again, if you have a newer controller like the v1.1.5, don&#039;t touch the bootloader, as the one already installed, should work well as it is.&lt;br /&gt;
&lt;br /&gt;
PS: I tried enabling &#039;&#039;&#039;MANUAL_MESH_LEVELING&#039;&#039;&#039;, which in the code says that &#039;&#039;If used with a 1284P board the bootscreen will be disabled to save space&#039;&#039;. This effectively disabled the whole printer, and apparently may be making the firmware image a wee bit too large for it to fit the 1284P on the ender. It works well without it, though, and it may be fixed by now, since I tested this back in early 2019.&lt;br /&gt;
&lt;br /&gt;
== And then… ==&lt;br /&gt;
&lt;br /&gt;
With the new firmware in place, the printer should work as before, although with thermal runaway protection to better avoid fires in case the shit hits the fan, and to allow for things like autolevelling. With any luck, [https://www.precisionpiezo.co.uk/ this thing] may be ready for use by the time you read this - it surely looks nice!&lt;br /&gt;
&lt;br /&gt;
= Octoprint/Octopi =&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;This could have been under some other section, but again, I just branch out even though most of it is about sections mentioned elsewhere.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
When setting up a 3d printer for the first time, you usually get an SD card for storage and transfer data to the printer using [https://en.wikipedia.org/wiki/Sneakernet Sneakernet]. Some printers use micro SD cards, while other fullsize SD cards, which imho is better, since they don&#039;t get lost that easily, but otherwise do the same thing. This works, but is somewhat tedious. If you want to control the printer from a PC or phone, there&#039;s a simple trick for that as well - octoprint.&lt;br /&gt;
&lt;br /&gt;
[https://octoprint.org/ Octoprint], written by Gina Häußge, runs on most platforms including linux, windows, BSD*, macos etc. It supports controlling a camera to some extent out of the box and there&#039;s a large number of plugins availablee to do a lot of things you possibly haven&#039;t thought of (and quite often, you&#039;d ever need). The easiest way to install it, is to just grab a Raspberry pi - preferably some of the newer models (will get to that later) and download [https://octoprint.org/download/ octopi] and follow the instructions on that page.&lt;br /&gt;
&lt;br /&gt;
== Performance issues ==&lt;br /&gt;
&lt;br /&gt;
Some report (and I have seen it myself) issues with the pi&#039;s performance with regards to both handling the octoprint processes (which should be as close to realtime as possible) and handling other stuff like I/O, networking etc. The point is that at pi3 or older, has all peripherals connected to an internal USB hub. This might be practical, but performance-wise it&#039;s &#039;&#039;&#039;&#039;&#039;not&#039;&#039;&#039;&#039;&#039;. If you in addition connect a webcam to USB, you&#039;re asking for trouble, since USB will be your bottleneck. With a raspberry pi camera, the ones connected to the pi directly with a ribbon cable, this should not use USB, so it&#039;s better. Still, again, for older pi&#039;s, there might be some shortage in therms of cpu or i/o. The octopi runs something like raspbian which is a fork of debian which is a linux distro, so it all boils down to knowing linux.&lt;br /&gt;
&lt;br /&gt;
Your typical octopi will run octoprint, a streamer, usually &#039;&#039;&#039;mjpg-streamer&#039;&#039;&#039;, a simple, lightweight videostreamer that outputs a stream of jpeg-images (about the same format as cinemas use - that is - not MPEG). This may be a bit tough on the cpu and potentially i/o. Add inn a dash of USB overload and you&#039;re may see trouble.&lt;br /&gt;
&lt;br /&gt;
Still - a pi3 should be able to handle the load, but it might help to prioritise corretly. The octoprint process is the important part here, so we could give that full priority both in CPU and I/O and. Unfortunately, it doesn&#039;t seem like the current octopi has been migrated to using systemd for the startup. We&#039;ll deal with this later. To fix this in the old SysV init style file present there, the following patch should work against the file /etc/init.d/octoprint&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;diff&amp;quot;&amp;gt;&lt;br /&gt;
--- octoprint.old	2020-07-20 18:46:10.166651965 +0200&lt;br /&gt;
+++ octoprint	2020-07-20 18:53:21.724803211 +0200&lt;br /&gt;
@@ -22,6 +22,9 @@&lt;br /&gt;
 PIDFILE=/var/run/$NAME.pid&lt;br /&gt;
 PKGNAME=octoprint&lt;br /&gt;
 SCRIPTNAME=/etc/init.d/$PKGNAME&lt;br /&gt;
+NICELEVEL=-19                        # Top CPU priority&lt;br /&gt;
+IONICE_CLASS=1                       # Realtime I/O class&lt;br /&gt;
+IONICE_PRIORITY=0                    # Realtime I/O priority (probably not needed with class=realtime)&lt;br /&gt;
&lt;br /&gt;
 # Read configuration variable file if it is present&lt;br /&gt;
 [ -r /etc/default/$PKGNAME ] &amp;amp;&amp;amp; . /etc/default/$PKGNAME&lt;br /&gt;
@@ -70,10 +73,11 @@&lt;br /&gt;
&lt;br /&gt;
    is_alive $PIDFILE&lt;br /&gt;
    RETVAL=&amp;quot;$?&amp;quot;&lt;br /&gt;
-&lt;br /&gt;
    if [ $RETVAL != 0 ]; then&lt;br /&gt;
        start-stop-daemon --start --background --quiet --pidfile $PIDFILE --make-pidfile \&lt;br /&gt;
-       --exec $DAEMON --chuid $OCTOPRINT_USER --user $OCTOPRINT_USER --umask $UMASK -- serve $DAEMON_ARGS&lt;br /&gt;
+       --exec $DAEMON --chuid $OCTOPRINT_USER --user $OCTOPRINT_USER --umask $UMASK \&lt;br /&gt;
+       --nicelevel $NICELEVEL --ioched $IONICE_CLASS:$IONICE_PRIORITY \&lt;br /&gt;
+       --serve $DAEMON_ARGS&lt;br /&gt;
        RETVAL=&amp;quot;$?&amp;quot;&lt;br /&gt;
    fi&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This ismply upgrades the process to be allowed to use most of the resources on the pi, regardless of what other processes are whining about.&lt;br /&gt;
&lt;br /&gt;
PS: Code not tested - I don&#039;t have a pi right here. Will test later, but I&#039;m pretty sure it&#039;ll work. After all, it&#039;s just a few new arguments to start-stop-daemon&lt;br /&gt;
&lt;br /&gt;
roy&lt;/div&gt;</summary>
		<author><name>Roy</name></author>
	</entry>
	<entry>
		<id>https://wiki.malinux.no/index.php?title=File:Ardu-nano-as-programmer.jpg&amp;diff=183</id>
		<title>File:Ardu-nano-as-programmer.jpg</title>
		<link rel="alternate" type="text/html" href="https://wiki.malinux.no/index.php?title=File:Ardu-nano-as-programmer.jpg&amp;diff=183"/>
		<updated>2020-11-14T22:40:46Z</updated>

		<summary type="html">&lt;p&gt;Roy: Arduino Nano used as programmer&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Summary ==&lt;br /&gt;
Arduino Nano used as programmer&lt;/div&gt;</summary>
		<author><name>Roy</name></author>
	</entry>
	<entry>
		<id>https://wiki.malinux.no/index.php?title=Mdadm-badblocks&amp;diff=182</id>
		<title>Mdadm-badblocks</title>
		<link rel="alternate" type="text/html" href="https://wiki.malinux.no/index.php?title=Mdadm-badblocks&amp;diff=182"/>
		<updated>2020-11-12T17:11:47Z</updated>

		<summary type="html">&lt;p&gt;Roy: /* Test 1 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= mdadm badblocks testing =&lt;br /&gt;
&lt;br /&gt;
This article is about mdadm (not Mdadm, but hell, mediawiki) badblocks testing, an attempt to prove that the badblocks implementation in &#039;&#039;&#039;md&#039;&#039;&#039; is full of shite. This has been addressed before &amp;lt;ref&amp;gt;https://raid.wiki.kernel.org/index.php/The_Badblocks_controversy&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Setup ==&lt;br /&gt;
The test will be setup on a virtual machine (VM) running Debian Bullseye with the latest stable kernel from kernel.org. This way, I get updated versions of most stuff without building it all manually. If other versions than those in the distro are used, this will be pointed out in the text. All version numbers used will nevertheless be listed along with their origins.&lt;br /&gt;
&lt;br /&gt;
All tests are done with the virtio scsi driver. The host machine runs Debian Buster and the VM runs from within KVM, giving it a close to total isolation from its host. &lt;br /&gt;
&lt;br /&gt;
== Test 1 ==&lt;br /&gt;
The machine&#039;s is given two virtual disks, &#039;&#039;&#039;sdg&#039;&#039;&#039; and &#039;&#039;&#039;sdh&#039;&#039;&#039;, 16GB each, used without a partition table. On these, &#039;&#039;&#039;dm-dust&#039;&#039;&#039;&amp;lt;ref&amp;gt;https://01.org/linuxgraphics/gfx-docs/drm/admin-guide/device-mapper/dm-dust.html&amp;lt;/ref&amp;gt; is used to create flakey devices, imposing errors like a drive would. On top of these, an mdadm mirror (RAID-1), is placed. On top of this, LVM is used, and then ext4. The software used is mdadm v4.1 (2018-10-01) from &#039;&#039;&#039;Debian Bullseye&#039;&#039;&#039; and the official &#039;&#039;&#039;Linux kernel 5.9.8&#039;&#039;&#039;&amp;lt;ref&amp;gt;https://www.kernel.org/&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Roy</name></author>
	</entry>
	<entry>
		<id>https://wiki.malinux.no/index.php?title=Mdadm-badblocks&amp;diff=181</id>
		<title>Mdadm-badblocks</title>
		<link rel="alternate" type="text/html" href="https://wiki.malinux.no/index.php?title=Mdadm-badblocks&amp;diff=181"/>
		<updated>2020-11-12T17:08:28Z</updated>

		<summary type="html">&lt;p&gt;Roy: /* mdadm badblocks testing */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= mdadm badblocks testing =&lt;br /&gt;
&lt;br /&gt;
This article is about mdadm (not Mdadm, but hell, mediawiki) badblocks testing, an attempt to prove that the badblocks implementation in &#039;&#039;&#039;md&#039;&#039;&#039; is full of shite. This has been addressed before &amp;lt;ref&amp;gt;https://raid.wiki.kernel.org/index.php/The_Badblocks_controversy&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Setup ==&lt;br /&gt;
The test will be setup on a virtual machine (VM) running Debian Bullseye with the latest stable kernel from kernel.org. This way, I get updated versions of most stuff without building it all manually. If other versions than those in the distro are used, this will be pointed out in the text. All version numbers used will nevertheless be listed along with their origins.&lt;br /&gt;
&lt;br /&gt;
All tests are done with the virtio scsi driver. The host machine runs Debian Buster and the VM runs from within KVM, giving it a close to total isolation from its host. &lt;br /&gt;
&lt;br /&gt;
== Test 1 ==&lt;br /&gt;
The machine&#039;s is given two virtual disks, &#039;&#039;&#039;sdg&#039;&#039;&#039; and &#039;&#039;&#039;sdh&#039;&#039;&#039;, 16GB each, used without a partition table. On these, &#039;&#039;&#039;dm-dust&#039;&#039;&#039;&amp;lt;ref&amp;gt;https://01.org/linuxgraphics/gfx-docs/drm/admin-guide/device-mapper/dm-dust.html&amp;lt;/ref&amp;gt; is used to create flakey devices, imposing errors like a drive would. On top of these, an mdadm mirror (RAID-1), is placed. On top of this, LVM is used, and then ext4. The software used is mdadm v4.1 (2018-10-01) and the Linux kernel 5.9.8 from kernel.org.&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Roy</name></author>
	</entry>
	<entry>
		<id>https://wiki.malinux.no/index.php?title=Mdadm-badblocks&amp;diff=180</id>
		<title>Mdadm-badblocks</title>
		<link rel="alternate" type="text/html" href="https://wiki.malinux.no/index.php?title=Mdadm-badblocks&amp;diff=180"/>
		<updated>2020-11-12T16:59:24Z</updated>

		<summary type="html">&lt;p&gt;Roy: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= mdadm badblocks testing =&lt;br /&gt;
&lt;br /&gt;
This article is about mdadm (not Mdadm, but hell, mediawiki) badblocks testing, an attempt to prove that the badblocks implementation in &#039;&#039;&#039;md&#039;&#039;&#039; is full of shite.&lt;br /&gt;
&lt;br /&gt;
Testing starts out at 2020-11-12 17:30, using &#039;&#039;&#039;dm-dust&#039;&#039;&#039; to &lt;br /&gt;
&lt;br /&gt;
== Setup ==&lt;br /&gt;
The test will be setup on a virtual machine (VM) running Debian Bullseye with the latest stable kernel from kernel.org. This way, I get updated versions of most stuff without building it all manually. If other versions than those in the distro are used, this will be pointed out in the text. All version numbers used will nevertheless be listed along with their origins.&lt;br /&gt;
&lt;br /&gt;
All tests are done with the virtio scsi driver. The host machine runs Debian Buster and the VM runs from within KVM, giving it a close to total isolation from its host. &lt;br /&gt;
&lt;br /&gt;
== Test 1 ==&lt;br /&gt;
The machine&#039;s is given two virtual disks, &#039;&#039;&#039;sdg&#039;&#039;&#039; and &#039;&#039;&#039;sdh&#039;&#039;&#039;, 16GB each, used without a partition table. On these, &#039;&#039;&#039;dm-dust&#039;&#039;&#039; (see below) is used to create flakey devices, imposing errors like a drive would. On top of these, an mdadm mirror (RAID-1), is placed. On top of this, LVM is used, and then ext4. The software used is mdadm v4.1 (2018-10-01) and the Linux kernel 5.9.8 from kernel.org.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
* [https://raid.wiki.kernel.org/index.php/The_Badblocks_controversy The Badblocks controversy]&lt;br /&gt;
* [https://01.org/linuxgraphics/gfx-docs/drm/admin-guide/device-mapper/dm-dust.html dm-dust]&lt;/div&gt;</summary>
		<author><name>Roy</name></author>
	</entry>
	<entry>
		<id>https://wiki.malinux.no/index.php?title=Mdadm-badblocks&amp;diff=179</id>
		<title>Mdadm-badblocks</title>
		<link rel="alternate" type="text/html" href="https://wiki.malinux.no/index.php?title=Mdadm-badblocks&amp;diff=179"/>
		<updated>2020-11-12T16:34:45Z</updated>

		<summary type="html">&lt;p&gt;Roy: Created page with &amp;quot;= mdadm badblocks testing =  This article is about mdadm (not Mdadm, but hell, mediawiki) badblocks testing, an attempt to prove that the badblocks implementation in &amp;#039;&amp;#039;&amp;#039;md&amp;#039;&amp;#039;&amp;#039;...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= mdadm badblocks testing =&lt;br /&gt;
&lt;br /&gt;
This article is about mdadm (not Mdadm, but hell, mediawiki) badblocks testing, an attempt to prove that the badblocks implementation in &#039;&#039;&#039;md&#039;&#039;&#039; is full of shite.&lt;br /&gt;
&lt;br /&gt;
Testing starts out at 2020-11-12 17:30, using &#039;&#039;&#039;dm-dust&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
* [https://raid.wiki.kernel.org/index.php/The_Badblocks_controversy The Badblocks controversy]&lt;br /&gt;
* [https://01.org/linuxgraphics/gfx-docs/drm/admin-guide/device-mapper/dm-dust.html dm-dust]&lt;/div&gt;</summary>
		<author><name>Roy</name></author>
	</entry>
	<entry>
		<id>https://wiki.malinux.no/index.php?title=Roy%27s_notes&amp;diff=178</id>
		<title>Roy&#039;s notes</title>
		<link rel="alternate" type="text/html" href="https://wiki.malinux.no/index.php?title=Roy%27s_notes&amp;diff=178"/>
		<updated>2020-11-12T13:00:09Z</updated>

		<summary type="html">&lt;p&gt;Roy: /* Recovery */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= LVM, md and friends =&lt;br /&gt;
&lt;br /&gt;
== Linux&#039; Logical Volume Manager (LVM) ==&lt;br /&gt;
&lt;br /&gt;
=== LVM in general ===&lt;br /&gt;
&lt;br /&gt;
LVM is designed to be an abstraction layer on top of physical drives or RAID, typically [https://raid.wiki.kernel.org/index.php/RAID_setup mdraid] or [https://help.ubuntu.com/community/FakeRaidHowto fakeraid]. Keep in mind that fakeraid should be avoided unless you really need it, like in conjunction with dual-booting linux and windows on fakeraid. LVM broadly consists of three elements, the &amp;quot;physical&amp;quot; devices (PV), the volume group (VG) and the logical volume (LV). There can be multiple PVs, VGs and LVs, depending on requirement. More about this below. All commands are given as examples, and all of them can be fine-tuned using extra flags in need of so. In my experience, the defaults work well for most usecases.&lt;br /&gt;
&lt;br /&gt;
I&#039;m mentioning filesystem below too. Where I write ext4, the samme applies to ext2 and ext3.&lt;br /&gt;
&lt;br /&gt;
==== Create a PV ====&lt;br /&gt;
&lt;br /&gt;
A PV is the &amp;quot;physical&amp;quot; parts. This does not need to be a physical disk, but can also be another RAID, be it an mdraid, fakeraid, hardware raid, a virtual disk on a SAN or otherwisee or a partition on one of those. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#  These add three PVs, one on a drive (or hardware raid) and another two on mdraids.&lt;br /&gt;
pvcreate /dev/sdb&lt;br /&gt;
pvcreate /dev/md1 /dev/md2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For more information about pvcreate, see [https://linux.die.net/man/8/pvcreate the manual].&lt;br /&gt;
&lt;br /&gt;
==== Create a VG ====&lt;br /&gt;
&lt;br /&gt;
The volume group consists of one or more PVs grouped together on which LVs can be placed. If several PVs are grouped in a VG, it&#039;s generally a good idea to make sure these PVs have some sort of redundancy, as in mdraid/fakeraid or hwraid. Otherwise it will be like using a [https://en.wikipedia.org/wiki/RAID RAID-0] with a single point of failure on each of the independant drives. LVM has [https://unix.stackexchange.com/questions/150644/raiding-with-lvm-vs-mdraid-pros-and-cons  RAID code in it] as well, so you can use that. I haven&#039;t done so myself, as I generally stick to mraid. The reason is mdraid is, in my opinion older and more stable and has more users (meaning bugs are reported and fixed faster whenever they are found). That said, I beleive the actual RAID code used in LVM RAID are the same function calls as for mdraid, so it may not be much of a difference. I still stick with mdraid. To create a VG, run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create volume group my_vg&lt;br /&gt;
vgcreate my_vg /dev/md1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that if vgcreate is run with a PV (as /dev/md1 above) that is not defined as a PV (like above), this is done implicitly, so if you don&#039;t need any special flags to pvcreate, you can simply skip it and let vgcreate do that for you.&lt;br /&gt;
&lt;br /&gt;
==== Create an LV ====&lt;br /&gt;
&lt;br /&gt;
LVs can be compared to partitions, somehow, since they are bounderies of a fraction or all of that of a VG. The difference between them and a partition, however, is that they can be grown or shrunk easily and also moved around between PVs without downtime. This flexibility makes them superiour to partitions as your system can be changed without users noticing it. By default, an LV is alloated &amp;quot;thickly&amp;quot;, meaning all the data given to it, is allocated from the VG and thus the PV. The following makes a 100GB LV named &amp;quot;thicklv&amp;quot;. When making an LV, I usually allocate what&#039;s needed plus some more, but not everything, just to make sure it&#039;s space available for growth on any of the LVs on the VG, or new LVs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a thick provisioned LV named thicklv on the VG my_vg&lt;br /&gt;
lvcreate -n thicklv -L 100G my_vg&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After the LV is created, a filesystem can be placed on it unless it is meant to be used directly. The application for direct use include swap space, VM storage and certain database systems. Most of these will, however, work on filesystems too, although my testing has shown that on swap space, there is a significant performance gain for using dedicated storage without a filesystem. As for filesystems, most Linux users use either ext4 or xfs. Personally, I generally use XFS these days. See my notes below on filesystem choice.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a filesystem on the LV - this could have been mkfs -t ext4 or whatever filesystem you choose&lt;br /&gt;
mkfs -t xfs /dev/my_vg/thicklv&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then just edit /etc/fstab with correct data and run mount -a, and you should be all set.&lt;br /&gt;
&lt;br /&gt;
==== Create LVM cache ====&lt;br /&gt;
LVMcache is LVM&#039;s solution to caching a slowish filesystem on spinning rust with the help of much faster SSDs. For this to work, use a separate SSD or a mirror or two (just in case) an add the new disk/md dev to the same VG. In this case, we use a small mirror, md1. LVM is not able to cache to a disk or partition outside the volume group.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
vgextend data /dev/md1&lt;br /&gt;
  Physical volume &amp;quot;/dev/md1&amp;quot; successfully created.&lt;br /&gt;
  Volume group &amp;quot;data&amp;quot; successfully extended&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Thn create two LVs, one for the data (contents of files) and one for the metadata (filenames, directories, attributes etc). Typically, the metadata part won&#039;t need to be very large. 100M should usually do unless you have ekstremely many small files. I guess there are ways to calculate it, but again, 1GB should do for everyone (or was that 640k?). As for the data cache, I chose to use 40G here for a 15TB RAID. It will only cache what actively use anyway, so no need for overkill.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
lvcreate -L 1G -n _cache_meta data /dev/md1&lt;br /&gt;
lvcreate -L 100G -n _cache data /dev/md1&lt;br /&gt;
&lt;br /&gt;
# Some would want --cachemode writeback, but if paranoid, I wouldn&#039;t recommend it. Metadata or data can be easily corrupted in case of failure. Most filesystems will however recover from this these days since they use journaling. It &#039;&#039;really&#039;&#039; speeds up things.&lt;br /&gt;
lvconvert --type cache-pool --cachemode writethrough --poolmetadata data/_cache_meta data/_cache&lt;br /&gt;
lvconvert --type cache --cachepool data/_cache data/data&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
That should be it. If you benchmarked the disk before this, you should try again and you&#039;ll probably get a nice surprise. If not, well, see below how to turn this off again :)&lt;br /&gt;
&lt;br /&gt;
==== Disabling LVM cache ====&lt;br /&gt;
&lt;br /&gt;
If you want to change the cached LV, such as growing og shrinking or otherwise, you&#039;ll have to disable caching first and then re-enable it. There&#039;s no quick-and-easy fix, but you just do as you did when enabling in the first place. &lt;br /&gt;
&lt;br /&gt;
Forst, disable caching for the LV. This will do it cleanly and remove the LVs earlier created for caching the main device. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
lvconvert --uncache data/data&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, since you now have a VG with an empty PV in it, earlier used for caching, I&#039;d recommend removing this for now to avoid expanding onto that as well. Since they&#039;re in the same VG, this might happen and if you get so far as to extend the lv and the filesystem on it, and this filesystem is XFS or similar filesystems without possibilities of reducing the size, you have a wee problem. &lt;br /&gt;
&lt;br /&gt;
Just remove that PV from the VG&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
vgreduce data /dev/md1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The PV is still there, but pvs should now show it not connected to a VG&lt;br /&gt;
&lt;br /&gt;
==== Growing devices ====&lt;br /&gt;
&lt;br /&gt;
LVM objects can be grown and shrunk. If a PV resides on a RAID where a new drive has been added or otherwise grown, or on a partition or virtual disk that has been extended, the PV must be updated to reflect these changes. The following command will grow the PV to the maximum available on the underlying storage. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Resize the PV /dev/md (not the RAID, only the PV on the RAID) to its full size&lt;br /&gt;
pvresize /dev/md1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If a new PV is added, the VG can be grown to add the space on that in addition to what&#039;s there already. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Extend my_vg to include md2 and its space&lt;br /&gt;
vgextend my_vg /dev/md2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
With more space available in the VG, the LV can now be extended. Let&#039;s add another 50GB to it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Extend thicklv - add 50GB. If you know you won&#039;t need the space anywhere else, you may want to&lt;br /&gt;
# lvresize -l+100%FREE instead. Keep in mind the difference between -l (extents) and -L (bytes)&lt;br /&gt;
lvresize -L +50G my_vg/thicklv&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Growing filesystems ====&lt;br /&gt;
After the LV has grown, run &#039;&#039;xfs_growfs&#039;&#039; (xfs) or &#039;&#039;resize2fs&#039;&#039; (ext4) to make use of the new data. To grow the filesystem to all available space on ext4, run the below command.  To partly grow the filesystem or to shrink it or otherwise, please see the manuals.&lt;br /&gt;
&lt;br /&gt;
The filesystem can be mounted when this is run. If you for some reason get an &#039;&#039;&#039;access denied&#039;&#039;&#039; error when running this as root or with sudo, it&#039;s likely caused by a filesystem error. To fix this, unmount the filesystem first and run &#039;&#039;&#039;fsck -f /dev/my_vg/thicklv&#039;&#039;&#039; and remount it before retrying to extend it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
resize2fs /dev/my_vg/thicklv&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Similarly, with XFS, but note that xfs_growfs doesn&#039;t take the device name, but the filesystem&#039;s mount point. In the case of XFS, also note that the filesystem &#039;&#039;&#039;&#039;&#039;must&#039;&#039;&#039;&#039;&#039; be mounted to be grown. This, in contrast to how it was in the old days when filesystems had to be unmounted to be grown.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
xfs_growfs /my_mountpoint&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Rename system VG ====&lt;br /&gt;
&lt;br /&gt;
Some distros create VG names like those-from-a-sysadmin-with-a-well-developed-paranoia-not-to-hit-a-duplicate. Debian, for instance, uses names like &amp;quot;my-full-hostname-vg&amp;quot;. Personally, I don&#039;t like these, since if I were to move a disk or vdisk around to somewhere else, I&#039;d make sure not to add a disk named &#039;sys&#039; to an existing system. If you do, most distros will refuse to use the VGs with duplicate names, resulting in the OS not booting until either one is specified by its UUID or just one removed. As I&#039;m aware of this, I stick to the super-risky thing of all system VGs named &#039;sys&#039; and so on.&lt;br /&gt;
&lt;br /&gt;
If you do this, keep in mind that it may blow up your computer and take your girl- or boyfriend with it or even make either of them pregnant, allowing Trump to rule your life and generally make things suck. You&#039;re on your own!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Rename the VG&lt;br /&gt;
vgrename my-full-hostname-vg sys&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, in /boot/grub/grub.cfg, change the old lv path from something like &#039;/dev/mapper/debian--stretch--machine--vg-root&#039; to your new and fancy &#039;/dev/sys/root. Likewise, in /etc/fstab, change occurences of &#039;/dev/mapper/debian--stretch--machine--vg-&#039; (or similar) with &#039;/dev/sys/&#039;. Here, this was like this - the old ones commented out.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;fstab&amp;quot;&amp;gt;&lt;br /&gt;
#/dev/mapper/debian--stretch--box--vg-root      /               ext4            errors=remount-ro,discard       0       1&lt;br /&gt;
/dev/sys/root                                   /               ext4            errors=remount-ro,discard       0       1&lt;br /&gt;
# /boot was on /dev/vda1 during installation&lt;br /&gt;
UUID=myverylonguuidwithatonofgoodinfoinit       /boot           ext2            defaults                        0       2&lt;br /&gt;
#/dev/mapper/debian--stretch--box--vg-swap_1    none            swap            sw                              0       0&lt;br /&gt;
/dev/sys/swap_1                                 none            swap            sw                              0       0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Update /etc/initramfs-tools/conf.d/resume with similar data for swap.&lt;br /&gt;
&lt;br /&gt;
You might want to run &#039;update-initramfs -u -k all&#039; after this, but I&#039;m not sure if it&#039;s needed.&lt;br /&gt;
&lt;br /&gt;
Now, pray to the nearest god(s) and give it a reboot and it should (probably) work.&lt;br /&gt;
&lt;br /&gt;
After reboot, run &#039;&#039;&#039;swapoff -a&#039;&#039;&#039;, then &#039;&#039;&#039;mkswap /dev/sys/swap_1&#039;&#039;&#039; (or whatever it&#039;s called on your system) and &#039;&#039;&#039;swapon -a&#039;&#039;&#039; again. You may want to give it another reboot or two for kicks, but it should work well even without that.&lt;br /&gt;
&lt;br /&gt;
=== Migration tools ===&lt;br /&gt;
&lt;br /&gt;
At times, storage regimes change, new storage is added and sometimes it&#039;s not easy to migrate with the current hardware or its support systems. Once I had to migrate a 45TiB fileserver from one storage system to another, preferably without downtime. The server originally had three 15TiB PVs of which two were full and the third half full. I resorted to using [https://linux.die.net/man/8/pvmove pvmove] to just move the data on the PVs in use to a new PV. We started out with creating a new 50TiB PV, sde, and then to pvmove.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Attach /dev/sde to the VG my_vg&lt;br /&gt;
vgextend my_vg /dev/sde&lt;br /&gt;
&lt;br /&gt;
# Move the contents from /dev/sdb over to /dev/sde block by block. If a target is not given in pvmove,&lt;br /&gt;
# the contents of the source (sdb here) will be put somewhere else in the pool.&lt;br /&gt;
pvmove /dev/sdb /dev/sde&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This took a while (as in a week or so) - the pvmove command uses old code and logic (or at least did that when I migrated this in November 2016), but it affected performance on the server very little, so users didn&#039;t notice. After the first PV was migrated, I continued with the other two, one after the other, and after a month or so, it was migrated. We used this on a number of large fileservers, and it worked flawlessly. Before doing the production servers I also tried interrupting pvmove in various ways, including hard resets, and it just kept on after the reboot.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;NOTE:&#039;&#039;&#039;&#039;&#039; &#039;&#039;Even though it worked well for us, &#039;&#039;&#039;always&#039;&#039;&#039; keep a good backup before doing this. Things may go wrong, and without a good backup, you may be looking for a hard-to-find new job the next morning&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
==== mdadm workarounds ====&lt;br /&gt;
&lt;br /&gt;
===== Migrate from a mirror (raid-1) to raid-10 =====&lt;br /&gt;
&lt;br /&gt;
Create a mirror&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sdb /dev/sdc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
LVM (pv/vg/lv) on md0 (see above), put a filesystem on the lv and fill it with some data.&lt;br /&gt;
&lt;br /&gt;
Now, some months later, you want to change this to raid-10 to allow for the same amount of redundancy, but to allow more disks into the system.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mdadm --grow /dev/md0 --level=10&lt;br /&gt;
mdadm: Impossibly level change request for RAID1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So - no - doesn&#039;t work. But - we&#039;re on &lt;br /&gt;
&lt;br /&gt;
Since we&#039;re on lvm already, this&#039;ll be easy. If you&#039;re using filesystems directly on partitions, you can do this the same way, but without the pvmove part, using rsync or whateever you like instead. I&#039;d recommend using lvm for for the new raid, which should be rather obvious from this article. Now plug in a new drive and create a new raid10 on that one. If you two new drives, install both. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# change &amp;quot;missing&amp;quot; to the other device name if you installed two new drives&lt;br /&gt;
mdadm --create /dev/md1 --level=10 --raid-devices=2 /dev/vdd missing&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, as described above, just vgextend the vg, adding the new raid and run pvmove to move the data from the old pv (residing on the old raid1) to the new pv (on raid10). Afte rpvmove is finished (which may take awile, see above), just&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
vgreduce raidtest /dev/md0&lt;br /&gt;
pvremove /dev/md0&lt;br /&gt;
mdadm --stop /dev/md0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
…and your disk is free to be added to the new array. If the new raid is running in degraded mode (if you created it with just one drive), better don&#039;t wait too long, since you don&#039;t have redundancy. Just mdadm --add the devs.&lt;br /&gt;
&lt;br /&gt;
If you now have /dev/mdstat telling you your raid10 is active and have three drives, of which one is a spare, it should look something like this&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5] [raid4] [raid10]&lt;br /&gt;
md1 : active raid10 vdc[3](S) vdb[2] vdd[0]&lt;br /&gt;
      8380416 blocks super 1.2 2 near-copies [2/2] [UU]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Just mdadm --grow --raid-devices=3 /dev/md1&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;RAID section is not complete. I&#039;ll write more on migraing from raid10 to raid6 later. It&#039;s not straight forward, but easier than this one :)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== Thin provisioned LVs ===&lt;br /&gt;
&lt;br /&gt;
Thin provisioning on LVM is a method used for not allocating all the space given to an LV. For instance, if you have a 1TB VG and want to give an LV 500GB, although it currently only uses a fraction of that, a thin lv can be a good alternative. This will allow for adding a limit to how much it can use, but also to let it grow dynamically without manual work by the sysadmin. Thin provisioning adds another layer of abstaction by creating a special LV as a &#039;&#039;thin pool&#039;&#039; from which data is allocated to the &#039;&#039;thin volume(s)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== Create a thin pool ====&lt;br /&gt;
&lt;br /&gt;
Allocate 1TB to the thin pool to be used for thinly provisioned LVs. Keep in mind that the space allocated to the thin pool is in fact thick provisioned. Only the volumes put on &#039;&#039;thinpool&#039;&#039; are thin provisioned. This will create two hidden LVs, one for data and one for metadata. Normally the defaults will do, but check the manual if the data doesn&#039;t match the usual patterns (such as billions of files, resulting in huge amounts of metadata). I &#039;&#039;beleive&#039;&#039; the metadata part should be resizable at a later time if needed, but I have not tested it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a pool for thin LVs. Keep in mind that the pool itself is not thin provisioned, only the volumes residing on it&lt;br /&gt;
lvcreate --size 1T --type thin-pool --thinpool thinpool my_vg&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Create a thin volume ====&lt;br /&gt;
&lt;br /&gt;
You have the thinpool, now put a thin volume on it. It will allocate some space for metadata, but probably not much (a few megs, perhaps).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Now, create a volume with a virtual (-V) size of half a terabyte named thin_pool, but using the thinpool (-T) named thin_pool for storage&lt;br /&gt;
lvcreate -V 500G -T my_vg/thin_pool --name thinvol&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The new volume&#039;s device name will be /dev/thinvol. Now, create a filesystem on it, add to fstab and mount it. The &#039;&#039;&#039;df&#039;&#039;&#039; command will return available space according to the virtual size (-V), while lvs will show how much data is actually used on each of the thinly provisioned volumes.&lt;br /&gt;
&lt;br /&gt;
== Filesystem dilemmas ==&lt;br /&gt;
&lt;br /&gt;
=== XFS or ext4 or something else ===&lt;br /&gt;
The choice of filesystem varies for your use. Distros such as RHEL/CentOS has moved to XFS by default from v7. Debian/Ubuntu still sticks to ext4, like most other. I&#039;ll discuss my thoughts below on ext4 vs XFS and leave the other filesystems for later.&lt;br /&gt;
&lt;br /&gt;
==== ext4 ====&lt;br /&gt;
ext4 is probably the most used filesystem on linux as of writing. It&#039;s rock stable and has been extended by a lot of extensions since the original ext2. It still retains backward compatibility, being able to mount and fsck ext2 and ext3 with the ext4 driver. However, it doesn&#039;t handle large filesystems very well. If a filesystem is created for &amp;lt;16TiB, it cannot be grown to anything larger than 16TiB. This may have changed lately, though. One other issue is handling errors. If a large filesystem (say 10TiB) is damaged, an fsck may take several hours, leading to long downtime. When I refer to ext4 further in this text, the same applies to ext2 and ext3 unless otherwise specified.&lt;br /&gt;
&lt;br /&gt;
==== XFS ====&lt;br /&gt;
XFS, originally developed by SGI some time in the bronze age, but has been worked on heavily after that. RHEL and Centos version 7 and forward, uses XFS as the default filesystem. It is quick, it scales well, but it lacks at least two things ext4 has. It cannot be shrunk (not that you normally need that, but nice if you have a typo or you need to change things). Also, it doesn&#039;t allow for automatic fsck on bootup. If something is messed up on the filesystem, you&#039;ll have to login as root on the console (not ssh), which might be an issue on some systems. The fsck equivalent, xfs_repair, is a *lot* faster than ext4&#039;s fsck, though.&lt;br /&gt;
&lt;br /&gt;
==== ZFS ====&lt;br /&gt;
ZFS is like a combination of RAID, LVM and a filesystem, supporting full checksumming, auto-healing (given sufficient redundancy), compression, encryption, replication, deduplication (if you&#039;re brave and have a &#039;&#039;ton&#039;&#039; of memory) and a lot more. It&#039;s a separate chapter and needs a lot more talk than paragraph here.&lt;br /&gt;
&lt;br /&gt;
==== btrfs ====&lt;br /&gt;
btrfs, pronounced &amp;quot;butterfs&amp;quot; or &amp;quot;betterfs&amp;quot; or just spelled out, is a filesystem that mimics that of ZFS. It has been around for 10 years or so, but hasn&#039;t yet proven to be really stable. Following the progress of it for those years, I&#039;ve found it to be a nice toy with which to play, but not to be used in production. Again, others may say otherwise, but these are just my words.&lt;br /&gt;
&lt;br /&gt;
== Low level disk handling ==&lt;br /&gt;
&lt;br /&gt;
This section is for low-level handling of disks, regardless of storage system elsewhere. These apply to mdraid, lvmraid and zfs and possibly other solutions, with the exception of individual drives on hwraid (and maybe fakeraid), since there, the drives are hidden from Linux (or whatever OS).&lt;br /&gt;
&lt;br /&gt;
=== S.M.A.R.T. and slow drives ===&lt;br /&gt;
Modern (that is, from about 1990 or later) have S.M.A.R.T. (or just smart, since it&#039;s easier to type) monitoring built in, meaning the disk&#039;s controller is monitoring itself. This is handy and will ideally tell you in advance that a drive is flakey or dying. Modern (2010+) smart monitoring is more or less the same. It can be trusted about 50% of the time. Usually, if smart detects an error, it&#039;s a real error. I don&#039;t think I&#039;ve seen it reporting a false positive, but others may know better. &lt;br /&gt;
&lt;br /&gt;
==== smartmontools ====&lt;br /&gt;
First, install smartmontool and run smartclt -H /dev/yourdisk (/dev/sda or something) to get a health report. Then perhaps run smartctl -a /dev/yourdisk and look for &#039;current pending sectors&#039; This should be zero. Also check the temperature, which normally should be much above 50.&lt;br /&gt;
&lt;br /&gt;
==== single, slow drive ====&lt;br /&gt;
What may happen, is smart not seeing anything and life goes on like before, only slower and less prouductive, without telling anyone. If you stubler over this issue, you&#039;ll probably see it during a large rsync/zfs send/receive or a resync/rebuild/resilver of the raid/zpool. During this, it feels like everything is slow and your RAID has turned into a RAIF (redundant array of inexpensive floppies). To check if you have a single drive messing up it all, check with &#039;&#039;&#039;iostat -x 2&#039;&#039;&#039;, having 2 being the delay between each measurement. Interrupt it with ctrl+x. If there&#039;s a rougue drive there, it should stand out like sdg below&lt;br /&gt;
&lt;br /&gt;
 avg-cpu:  %user   %nice %system %iowait  %steal   %idle&lt;br /&gt;
            0.38    0.00    1.75    0.00    0.00   97.87&lt;br /&gt;
&lt;br /&gt;
 Device            r/s     w/s     rkB/s     wkB/s   rrqm/s   wrqm/s  %rrqm  %wrqm r_await w_await aqu-sz rareq-sz wareq-sz  svctm  %util&lt;br /&gt;
 sda              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdb              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdc              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdd              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sde              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdf              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdg              3.50    0.00   2352.00      0.00     0.00     0.00   0.00   0.00 14306.29    0.00  13.85   672.00     0.00 285.71 100.00&lt;br /&gt;
 sdh              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
&lt;br /&gt;
In ZFS land, you should be able to get similar data with &#039;&#039;&#039;zpool iostat -v &amp;lt;pool&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Now you know the bad drive (sdg), pull it from the raid with &#039;&#039;&#039;mdadm --fail /dev/mdX /dev/sdX&#039;&#039;&#039;. Now test the drive&#039;s performance manually, just simply:&lt;br /&gt;
&lt;br /&gt;
 # hdparm -t /dev/sdg&lt;br /&gt;
 &lt;br /&gt;
 /dev/sdg:&lt;br /&gt;
  Timing buffered disk reads:   2 MB in  5.37 seconds = 381.46 kB/sec&lt;br /&gt;
&lt;br /&gt;
Bingo - nothing you&#039;d want to keep. For a good drive, it should be something like 100-200MB/s&lt;br /&gt;
&lt;br /&gt;
PS: Keep in mind that you have a degraded RAID by now in case you had a spare waiting for things to happen.&lt;br /&gt;
&lt;br /&gt;
Try to replace the cable and/or try the disk on another port/controller. If the result from hdparm persists, it&#039;s probably a bad cable&lt;br /&gt;
&lt;br /&gt;
So, then, just psycially locate the drive, pull it out, take out the discs and magnets and recycle the rest.&lt;br /&gt;
&lt;br /&gt;
=== &amp;quot;Unplug&amp;quot; drive from system ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Find the device unit&#039;s number with something like&lt;br /&gt;
find /sys/bus/scsi/devices/*/block/ -name sdd&lt;br /&gt;
# returning /sys/bus/scsi/devices/3:0:0:0/block/sdd here, &lt;br /&gt;
# meaning 3:0:0:0 is the SCSI device we&#039;re looking for.&lt;br /&gt;
&lt;br /&gt;
# Given this is the correct device, and you want to &#039;unplug&#039; it, do so by&lt;br /&gt;
echo 1 &amp;gt; /sys/bus/scsi/devices/3:0:0:0/delete&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Rescan disk controllers ===&lt;br /&gt;
If a drive is added and for some reason doesn&#039;t get detected, or is removed by the command above, it can be rediscovered with a sysfs command to the scsi host to which it is connected. Since there may be quite a few of these, an easy way is to just scan them all and check the output of &#039;&#039;&#039;dmesg -T&#039;&#039;&#039; after running it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Make a list of controllers and send a rescan message to each of them. It won&#039;t do anything &lt;br /&gt;
# for those where nothing has changed, but it will show new drives where they have been added.&lt;br /&gt;
for host_scan in /sys/class/scsi_host/host*/scan&lt;br /&gt;
do&lt;br /&gt;
  echo &#039;- - -&#039; &amp;gt; $host_scan&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Fail injection with debugfs ===&lt;br /&gt;
[https://lxadm.com/Using_fault_injection https://lxadm.com/Using_fault_injection]&lt;br /&gt;
&lt;br /&gt;
== mdadm stuff ==&lt;br /&gt;
=== Resync ===&lt;br /&gt;
To resync a raid, that is, check, run&lt;br /&gt;
&lt;br /&gt;
 echo check &amp;gt; /sys/block/$dev/md/sync_action&lt;br /&gt;
&lt;br /&gt;
where $dev is something like md0. If you have several raids, something like this should work&lt;br /&gt;
&lt;br /&gt;
 for dev in md{0,1}&lt;br /&gt;
 do&lt;br /&gt;
   echo repair &amp;gt; /sys/block/$dev/md/sync_action&lt;br /&gt;
 done&lt;br /&gt;
&lt;br /&gt;
Also useful in a one-liner like&lt;br /&gt;
&lt;br /&gt;
 for dev in md{0,1} ; do echo repair &amp;gt; /sys/block/$dev/md/sync_action ; done&lt;br /&gt;
&lt;br /&gt;
Different raids on different drives will do this in parallel. If the drives are shared somehow with partitions or similar, the check or repair will wait for the other to finish before going on.&lt;br /&gt;
&lt;br /&gt;
As for repair vs check, [https://raid.wiki.kernel.org/index.php/RAID_Administration this article] describes it well. I stick to using repair unless it&#039;s something rare where I don&#039;t want to touch the data.&lt;br /&gt;
&lt;br /&gt;
=== Spare pools ===&lt;br /&gt;
In the old itmes, mdadm supported only a dedicated spare per md device, so if working with a large set of drives (20? 40?), where you&#039;d want to setup more raid sets to increase redundancy, you&#039;d dedicate a spare to each of the raid sets. This has changed (some time ago?), so in these modern, heathen days, you can change mdadm.conf, usually placed under /etc/mdadm, and add &#039;spare-group=somegroup&#039; where &#039;somegroup&#039; is a string identifying the spare group. After doing this, run &#039;&#039;&#039;update-initramfs -u&#039;&#039;&#039; and reboot and add a spare to one of the raid sets in the spare group, and md will use that or those spares for all the raidsets in that group.&lt;br /&gt;
&lt;br /&gt;
As some pointed out on #linux-raid @ irc.freenode.net, this feature is very badly documented, but as far as I can see, it works well.&lt;br /&gt;
&lt;br /&gt;
==== Example config ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create two raidsets&lt;br /&gt;
&lt;br /&gt;
mdadm --create /dev/md1 --level=6 --raid-devices=6 /dev/vd[efghij]&lt;br /&gt;
mdadm --create /dev/md2 --level=6 --raid-devices=6 /dev/vd[klmnop]&lt;br /&gt;
&lt;br /&gt;
# get their UUID etc&lt;br /&gt;
&lt;br /&gt;
mdadm --detail --scan&lt;br /&gt;
ARRAY /dev/md/1 metadata=1.2 name=raidtest:1 UUID=1a8cbdcb:f4092350:348b6b80:c054d74c&lt;br /&gt;
ARRAY /dev/md/2 metadata=1.2 name=raidtest:2 UUID=894b1b7c:cb7eba70:917d6033:ea5afd2b&lt;br /&gt;
&lt;br /&gt;
# Put those lines into /etc/mdadm/mdadm.conf and and add the spare-group&lt;br /&gt;
&lt;br /&gt;
ARRAY /dev/md/1 metadata=1.2 name=raidtest:1 spare-group=raidtest UUID=1a8cbdcb:f4092350:348b6b80:c054d74c&lt;br /&gt;
ARRAY /dev/md/2 metadata=1.2 name=raidtest:2 spare-group=raidtest UUID=894b1b7c:cb7eba70:917d6033:ea5afd2b&lt;br /&gt;
&lt;br /&gt;
# update the initramfs and reboot&lt;br /&gt;
&lt;br /&gt;
update-initramfs -u&lt;br /&gt;
reboot&lt;br /&gt;
&lt;br /&gt;
# add a spare drive to one of the raids&lt;br /&gt;
&lt;br /&gt;
mdadm --add /dev/md1 /dev/vdq&lt;br /&gt;
&lt;br /&gt;
# fail a drive on the other raid&lt;br /&gt;
&lt;br /&gt;
mdadm --fail /dev/md2 /dev/vdn&lt;br /&gt;
&lt;br /&gt;
# check /proc/mdstat to see md2 rebuilding with the spare from md1&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Recovery ===&lt;br /&gt;
&lt;br /&gt;
The other day, I came across a problem a user had on #linux-raid@irc.freenode.net. He had an old Qnap NAS that had died and tried plugging the drives in to his Linux machine and got various errors. The two-drive RAID-1 did not come up as it should, &#039;&#039;&#039;dmesg&#039;&#039;&#039; was full of errors from one of the drives (both connected on USB) and so forth.&lt;br /&gt;
&lt;br /&gt;
We went on and started by taking down the machine and just connecting one of the drives. I had him check what was assembled with&lt;br /&gt;
&lt;br /&gt;
 cat /proc/mdstat&lt;br /&gt;
&lt;br /&gt;
That returned /proc/md127 assembled, but LVM didn&#039;t find anything. So running a manual scan&lt;br /&gt;
&lt;br /&gt;
 pvscan --cache /dev/md127&lt;br /&gt;
&lt;br /&gt;
This made linux find the PV, VG and a couple of LVs, but probably because the mdraid was degraded, the LVs were deactivated, according to &#039;&#039;&#039;lvscan&#039;&#039;&#039;. Activating the one with a filesystem manually&lt;br /&gt;
&lt;br /&gt;
 lvchange -a y /dev/&amp;lt;vg&amp;gt;/&amp;lt;lv&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Substitute &amp;lt;vg&amp;gt; and &amp;lt;lv&amp;gt; with the names listed by vgs and lvs.&lt;br /&gt;
&lt;br /&gt;
This worked, and the filesystem on /dev/&amp;lt;vg&amp;gt;/&amp;lt;lv&amp;gt; could be mounted correctly.&lt;br /&gt;
&lt;br /&gt;
=== Renaming a RAID ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Not finished&#039;&#039;&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
&lt;br /&gt;
Back around 2001, I asked on the linux-raid list for disk tagging, not default back then, but supported, and thought of the possibility of disk #1 getting replaced with disk #1 from another raid because of a messup. After this, the hostname was added to the raid name in the superblock. So when a RAID is created, it is named &amp;quot;hostname:raidname&amp;quot;, where the raidname is either a number (0,1...) or a name. &lt;br /&gt;
&lt;br /&gt;
For instance, running this on my VM named &amp;quot;raidtest&amp;quot;:&lt;br /&gt;
&lt;br /&gt;
 mdadm --create --level=1 --raid-devices=2 /dev/md/stuff /dev/sd[st]&lt;br /&gt;
&lt;br /&gt;
mdadm --detail --scan now shows this&lt;br /&gt;
&lt;br /&gt;
 ARRAY /dev/md/stuff metadata=1.2 name=raidtest:stuff UUID=c4cdf69f:393a28b1:47648ed3:726613de&lt;br /&gt;
&lt;br /&gt;
Now, you might want to change this name for some reason, and it&#039;s not supported under &amp;quot;grow&amp;quot;, so what to do… The name is, after all, local to the disk, since it&#039;s there to avoid messing up a raid (or two) after a disk mixup.&lt;br /&gt;
&lt;br /&gt;
 mdadm --assemble /dev/md/stuff --name &#039;someotherhost:stuff&#039; --update=homehost /dev/sd[st]&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== The badblock list ===&lt;br /&gt;
&#039;&#039;&#039;md&#039;&#039;&#039; has an internal badblock list (BBL), added around 2010, to list the bad blocks on the disk to avoid using those. While this might sound like a good idea, the badblock list is updated in case of a read error, which can be caused by several things. To make things worse, the BBL is replicated to other drives when a drive fails or the array is grown. So if you start out with sda and sdb and sdb suffers some errors, nothing wrong, md will read from sda, but flag those sectors on sdb as bad. So after a while, perhaps sda dies and gets replaced, with the same content, including the BBL. Then, at some point you might to replace sdb and it, too gets the BBL. So it sticks - forever. Also, there&#039;s no real point of keeping a BBL list, since the drive has its own and even if a sector error occurs, the array will have sufficient redundancy to recover from that (unless you use RAID-0 which you shouldn&#039;t). If a drive finds a bad sector, it&#039;ll be reallocated by the drive itself without the user&#039;s/admin&#039;s/system&#039;s knowledge. If a sector can&#039;t be reallocated, it means the drive is bad and should be replaced.&lt;br /&gt;
&lt;br /&gt;
There&#039;s no official way to remove it and although you can assemble it with the no-bbl option, this will only work if there&#039;s an empty BBL. Also, this will require downtime. As far as I can see, the only way to do this currently, is with a wee hack that should work. Just replace the names of mddev/diskdev with your own.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
mddev=&amp;quot;/dev/md0&amp;quot;&lt;br /&gt;
diskdev=&amp;quot;/dev/sda&amp;quot;&lt;br /&gt;
mdadm $mddev --fail $diskdev --remove $diskdev --re-add $diskdev --update=no-bbl&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If there&#039;s a BBL on the drive already, replace the --update part to &#039;force-no-bbl&#039;. This is not documented anywhere as per se, but it works.&lt;br /&gt;
 &lt;br /&gt;
I haven&#039;t found a way to turn this off permanently, but there may be something coming around when the debate on the linux-raid mailing list closes up on this. There&#039;s a bbl=no in mdadm.conf, but that&#039;s only for creation. I will continue extensive testing for this.&lt;br /&gt;
&lt;br /&gt;
== Tuning ==&lt;br /&gt;
&lt;br /&gt;
While trying to compare a 12-disk RAID (8TB disks) to a hwraid, mdraid was slower, so we did a few things to speed things up:&lt;br /&gt;
&lt;br /&gt;
While testing with [https://linux.die.net/man/1/fio fio], monitor /sys/block/md0/md/stripe_cache_active, and see if it&#039;s close to /sys/block/md0/md/stripe_cache_size. If it is, double the size of the latter&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
echo 4096 &amp;gt; /sys/block/md0/md/stripe_cache_size&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Continue until stripe_cache_active stabilises, and then you&#039;ve found the limit you&#039;ll need. You may want to double that for good measure. &lt;br /&gt;
&lt;br /&gt;
(to be continued)&lt;br /&gt;
&lt;br /&gt;
== Links ==&lt;br /&gt;
&lt;br /&gt;
Below are a few links with useful info&lt;br /&gt;
&lt;br /&gt;
* [https://raid.wiki.kernel.org/index.php/Irreversible_mdadm_failure_recovery Irreversible mdadm failure recovery]&lt;br /&gt;
&lt;br /&gt;
= ZFS =&lt;br /&gt;
&lt;br /&gt;
ZFS can do a lot of things most filesystems or volume managers can&#039;t. It checksums all data and metadata and so long that the system uses ECC enabled memory (RAM), it will have complete control over the whole data set, and when (not if) an error occurs, it&#039;ll fix the issue without even throwing a warning. To fix the issue, you&#039;ll obviously need sufficient redundancy (mirrors or RAIDzN). &lt;br /&gt;
&lt;br /&gt;
== ZFS send/receive between machines ==&lt;br /&gt;
&lt;br /&gt;
ZFS has a send/receive mechanism that allows for snapshots to be sent over the wire to a receiving end. This can be a full filesystem, or an incremental change since last send/reveive. In a WAN scenario, you&#039;ll probably want to use VPN for this. On a controlled network, sending in cleartext is also possible. You may as well use ssh, but keep in mind that ssh was never designed to be used as a fullblown vpn solution and is just too slow or the task with large amounts of data. You may, though, use mbuffer, if on a loal LAN.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Allow traffic from the sending IP in whatever firewall interface you&#039;re using (if you&#039;re using a firewall at all, that is)&lt;br /&gt;
ufw allow from x.x.x.x&lt;br /&gt;
# &lt;br /&gt;
# Start the receiver first. This listens on port 9090, has a 1GB buffer,&lt;br /&gt;
    and uses 128kb chunks (same as zfs):&lt;br /&gt;
&lt;br /&gt;
mbuffer -s 128k -m 1G -I 9090 | zfs receive data/filesystem&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To be continued one day… See [https://everycity.co.uk/alasdair/2010/07/using-mbuffer-to-speed-up-slow-zfs-send-zfs-receive/ this] for some more. I&#039;ll get back with details on it.&lt;br /&gt;
&lt;br /&gt;
= General Linux system control =&lt;br /&gt;
&lt;br /&gt;
== Add a new CPU (core) ==&lt;br /&gt;
&lt;br /&gt;
If working with virtual machines, adding a new core can be useful if the VM is slow and the load is multithreaded or multiprocess. To do this, add a new CPU in the hypervisor (be it KVM or VMware or Hyper-V or whatever). Some hypervisors, like VMware, will activate it automatically if open-vm-tools is installed. Please note that open-vm-tools is for VMware only. I don&#039;t know of any such thing for KVM or other hypervisors (although I beleive VirtualBox has its own set of tools, but not as a package). If this doesn&#039;t work, run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
echo 1 &amp;gt; /sys/devices/system/cpu/cpuX/online&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where X is the CPU number you want to add. You can &#039;cat /sys/devices/system/cpu/cpuX/online&#039; to check if it&#039;s online.&lt;br /&gt;
&lt;br /&gt;
= Mount partitions on a disk image =&lt;br /&gt;
&lt;br /&gt;
Sometimes you&#039;ll have a disk image, either from recovering a bad drive after hours (or days or weeks) of ddrescue, and sometimes you just have a disk image from a virtual machine where you want to mount the partitions inside the image. There are three main methods of doing this, which are more or less synonmous, but some easier than the other.&lt;br /&gt;
&lt;br /&gt;
== Basics ==&lt;br /&gt;
&lt;br /&gt;
A disk image is usually like a disk, consisting of either a large filesystem, a PV or a partition table with one or partitions onto which resides a filesystem, a pv, swap or something else. If it&#039;s partitioned, and you want your operating system to mount a filesystem or allow it to see whatever LVM stuff lies on it, you need to isolate the partitions. &lt;br /&gt;
&lt;br /&gt;
== Manual mapping ==&lt;br /&gt;
&lt;br /&gt;
In the oldern days, this was done manually, something like this&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
root@mymachine:~# fdisk -l /dev/vda&lt;br /&gt;
Disk /dev/vda: 25 GiB, 26843545600 bytes, 52428800 sectors&lt;br /&gt;
Units: sectors of 1 * 512 = 512 bytes&lt;br /&gt;
Sector size (logical/physical): 512 bytes / 512 bytes&lt;br /&gt;
I/O size (minimum/optimal): 512 bytes / 512 bytes&lt;br /&gt;
Disklabel type: dos&lt;br /&gt;
Disk identifier: 0xc37b7ea5&lt;br /&gt;
&lt;br /&gt;
Device     Boot    Start      End  Sectors  Size Id Type&lt;br /&gt;
/dev/vda1  *        2048 50333311 50331264   24G 83 Linux&lt;br /&gt;
/dev/vda2       50333312 52426369  2093058 1022M  5 Extended&lt;br /&gt;
/dev/vda5       50333314 52426369  2093056 1022M 82 Linux swap / Solaris&lt;br /&gt;
root@mymachine:~#&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To calculate the start and end of each partition, you just take the start sector and multiply it by the sector size (512 bytes here) and you have the offset in bytes. After this, it&#039;s merely an losetup -o &amp;lt;offset&amp;gt; /dev/loopX &amp;lt;nameofimagefile&amp;gt; and you have the partition mapped to your /dev/loopX (having X being something typically 0-255. After this, just mount it or run pvscan/vgscan/lvscan to probe whatever lvm config is there, and you should be able to mount it like any other filesystem.&lt;br /&gt;
&lt;br /&gt;
== kpartx ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;kpartx&#039;&#039;&#039; does the same as above, more or less, just without so much hassle. Most of it should be automatic and easy to deal with, except it may fail to disconnect the loopback devices sometimes, so you may have to &#039;&#039;&#039;losetup -d&#039;&#039;&#039; them manually. See the manual, &#039;&#039;&#039;kpartx (8)&#039;&#039;&#039;. Please note that &#039;&#039;&#039;partx&#039;&#039;&#039; works similarly and I&#039;d guess the authors of the two tools are arguing a lot of which one&#039;s the best.&lt;br /&gt;
&lt;br /&gt;
== guestmount ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;guestmount&#039;&#039;&#039; is something similar again, but also supports file formats like &#039;&#039;&#039;qcow2&#039;&#039;&#039; and possibly other, proprietary filesystems like &#039;&#039;&#039;vmdk&#039;&#039;&#039; and &#039;&#039;&#039;vdi&#039;&#039;&#039;, but don&#039;t take my word for it - I haven&#039;t tested. Again, see the manual or just read up on the description [http://ask.xmodulo.com/mount-qcow2-disk-image-linux.html?fbclid=IwAR3snTeZvGzp9PLdX11EQhCfOpux6I93CiJ3A2pUomkkRLly9Xo4851mkTY here]. It seems rather trivial.&lt;br /&gt;
&lt;br /&gt;
= Linux on laptops =&lt;br /&gt;
&lt;br /&gt;
== Wifi with HP EliteBook 725/745 on Ubuntu ==&lt;br /&gt;
&lt;br /&gt;
The HP EliteBook 725/745 and similar are equipped with a BCM4352 wifi chip. As with a lot of other stuff from Broadcom, this lacks an open hardware description, so thus no open driver exist. The proper fix, is to replace the NIC with something with an open driver, but again, this isn&#039;t always possible, so a binary driver exists. In ubuntu, run, somehow connect the machine to the internet and run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install bcmwl-kernel-source&lt;br /&gt;
sudo modprobe wl&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you can&#039;t connect the machine to the internet, download the needed packages on another machine and put it on some usb storage. These packages should suffice:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# apt-cache depends bcmwl-kernel-source&lt;br /&gt;
bcmwl-kernel-source&lt;br /&gt;
  Depends: dkms&lt;br /&gt;
  Depends: linux-libc-dev&lt;br /&gt;
  Depends: libc6-dev&lt;br /&gt;
  Conflicts: &amp;lt;bcmwl-modaliases&amp;gt;&lt;br /&gt;
  Replaces: &amp;lt;bcmwl-modaliases&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then install manually with &#039;&#039;&#039;dpkg -i file1.deb file2.deb&#039;&#039;&#039; etc&lt;br /&gt;
&lt;br /&gt;
After this, ip/ifconfig/iwconfig shouldd see the new wifi nic, probably &#039;&#039;&#039;wlan0&#039;&#039;&#039;, but due to a [https://bugs.launchpad.net/ubuntu/+source/broadcom-sta/+bug/1343151 old, ignored bug], you won&#039;t find any wifi networks. This is because the driver from Broadcom apparently does not support interrupt remapping, commonly used on x64 machines. To turn this off, change &#039;&#039;&#039;/etc/default/grub&#039;&#039;&#039; and change the line &#039;&#039;&#039;GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;quiet splash&amp;quot;&#039;&#039;&#039;, adding intremap=off to the end before the quote: &#039;&#039;&#039;GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;quiet splash intremap=off&amp;quot;&#039;&#039;&#039;. Save the file and run &#039;&#039;&#039;sudo update-grub&#039;&#039;&#039; and reboot. After this, wifi should work well.&lt;br /&gt;
&lt;br /&gt;
== Wifi with HP Compaq Presario CQ57 on Ubuntu ==&lt;br /&gt;
&lt;br /&gt;
The HP Compaq Presario CQ57 uses the RT5390 wifi chipset. This has been supported for quite some time now, and I was quite surprised to find it not working on a laptop a friend was having. The driver loaded correctly, but Ubuntu insisted of the laptop being in &#039;&#039;&#039;flight mode&#039;&#039;&#039;. Checking &#039;&#039;&#039;rfkill&#039;&#039;&#039;, it showed me two NICs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# rfkill list all&lt;br /&gt;
0: phy0: Wireless LAN&lt;br /&gt;
	Soft blocked: no&lt;br /&gt;
	Hard blocked: yes&lt;br /&gt;
1: hp-wifi: Wireless LAN&lt;br /&gt;
	Soft blocked: yes&lt;br /&gt;
	Hard blocked: no&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Turning rfkill on and off resulted in nothing much, except some error messages in the kernel log (dmesg)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] ACPI Error: Field [B128] at bit offset/length 128/1024 exceeds size of target Buffer (160 bits) (20170831/dsopcode-235)&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]&lt;br /&gt;
                            Initialized Local Variables for Method [HWCD]:&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Local0: 00000000a34b7928 &amp;lt;Obj&amp;gt;           Integer 0000000000000000&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Local1: 00000000b0aa6865 &amp;lt;Obj&amp;gt;           Buffer(8) 46 41 49 4C 04 00 00 00&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Local5: 00000000a9811efd &amp;lt;Obj&amp;gt;           Integer 0000000000000004&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] Initialized Arguments for Method [HWCD]:  (2 arguments defined for method invocation)&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Arg0:   0000000078957d1b &amp;lt;Obj&amp;gt;           Integer 0000000000000001&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Arg1:   00000000725c9c6e &amp;lt;Obj&amp;gt;           Buffer(20) 53 45 43 55 02 00 00 00&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] ACPI Error: Method parse/execution failed \_SB.WMID.HWCD, AE_AML_BUFFER_LIMIT (20170831/psparse-550)&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] ACPI Error: Method parse/execution failed \_SB.WMID.WMAD, AE_AML_BUFFER_LIMIT (20170831/psparse-550)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After upgrading BIOS and testing different kernels, I was asked to try to unload the &#039;&#039;&#039;hp_wmi&#039;&#039;&#039; driver. I did, and things changed a bit, so I tried blacklisting it, creating the file &#039;&#039;&#039;/etc/modprobe.d/blacklist-hp_wmi.conf&#039;&#039;&#039; with the following content&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Blacklist this - it doesn&#039;t work!&lt;br /&gt;
blacklist hp_wmi&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
I gave the machine a reboot and afte that, the &#039;&#039;&#039;hp-wifi&#039;&#039;&#039; entry was gone in the rfkill output, and things works.&lt;br /&gt;
&lt;br /&gt;
= Raspberry pi =&lt;br /&gt;
&lt;br /&gt;
I couldn&#039;t quite decide if the raspberry pi should be a separate section or part of Linux, but hell, it can run more than Linux, although 99,lots% of people just uses Linux on them. This is a small list of things to know about them; things not on the front page of the manual or perhaps hidden even better.&lt;br /&gt;
&lt;br /&gt;
== Which pi? ==&lt;br /&gt;
&lt;br /&gt;
I just setup three raspberry pi machines and although some are quite different, like v1 to vEverythingelse or the Pi zero versions to the normal ones, not all of us remember how to distinguish between them, and sometimes they&#039;re in a nice 3d printed (or otherwise) chassis or otherwise hidden. So, how to check three different ones:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
root@home-assistant:~ $ cat /proc/device-tree/model ; echo&lt;br /&gt;
Raspberry Pi 2 Model B Rev 1.1&lt;br /&gt;
&lt;br /&gt;
root@green-pi:~ $ cat /proc/device-tree/model ; echo&lt;br /&gt;
Raspberry Pi 3 Model B Rev 1.2&lt;br /&gt;
&lt;br /&gt;
roy@yellow-pi:~ $cat /proc/device-tree/model ; echo&lt;br /&gt;
Raspberry Pi 4 Model B Rev 1.1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
While this works well, for the latter, the pi4, it doesn&#039;t tell how much memory I have. It comes in variants of 1, 2 and 4GB, and this is the latter.&lt;br /&gt;
&lt;br /&gt;
For a more detailed list, the command &#039;&#039;&#039;awk &#039;/^Revision/ {sub(&amp;quot;^1000&amp;quot;, &amp;quot;&amp;quot;, $3); print $3}&#039; /proc/cpuinfo&#039;&#039;&#039; will give you a revision number, detailing the type of pi, who produced it etc. Please see [https://elinux.org/RPi_HardwareHistory https://elinux.org/RPi_HardwareHistory] for a full table.&lt;br /&gt;
&lt;br /&gt;
== Monitoring ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;vcgencmd&#039;&#039;&#039; from &#039;&#039;&#039;/opt/vc/bin&#039;&#039;&#039;, but symlinked to &#039;&#039;&#039;/usr/bin&#039;&#039;&#039; so it&#039;s available in path, is useful for fetching hardware info about the pi. For example, measuring the temperature&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
root@yellow-pi:~# vcgencmd measure_temp&lt;br /&gt;
temp=63.0&#039;C&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The command is generally badly documented and parts of it seems outdated for newer hardware. Here&#039;s the output from a Raspberry pi 4 with 4GB RAM&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
roy@yellow-pi:~ $ vcgencmd get_mem arm&lt;br /&gt;
arm=948M&lt;br /&gt;
roy@yellow-pi:~ $ vcgencmd get_mem gpu&lt;br /&gt;
gpu=76M&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= BIOS upgrade from Linux =&lt;br /&gt;
&lt;br /&gt;
Generally, BIOS upgrades have been moved to the BIOS itself these days. This saves a lot of work and quite possibly lives after those who earier rammed their heads through walls, now can upgrade directly from the internet instead of using obscure operating systems best avoided. Sometimes, however, one must use these nevertheless. This is a quick run-through on your options.&lt;br /&gt;
&lt;br /&gt;
== DOS ==&lt;br /&gt;
&lt;br /&gt;
Most non-automatic BIOS upgrades are installed from DOS. Doing a BIOS upgrade this way, is generally non-problematic. Just install a USB thingie with [https://www.freedos.org/ FreeDOS], copy your file(s) onto the thing and boot on it. The commandline is the same as old MS/DOS, except a wee bit more userfriendly, but not a lot.&lt;br /&gt;
&lt;br /&gt;
== Windows ==&lt;br /&gt;
&lt;br /&gt;
Some macahines, like laptops from &#039;&#039;&#039;HP&#039;&#039;&#039;, may have BIOS upgrades that are made to be installed from Windows and won&#039;t run in FreeDOS or MS/DOS, instead throwing an error, saying &#039;&#039;&#039;This program cannot be run in DOS mode&#039;&#039;&#039;. This means you&#039;ll have to boot on a Windows rescue disc and do the job from there. Googling this, tells you it&#039;s quite easy, you just choose &#039;make rescue disc&#039; from Windows, and it&#039;s all good, except if you don&#039;t run Windows, that is. To remedy this problem, do as follows:&lt;br /&gt;
&lt;br /&gt;
=== Download Windows ===&lt;br /&gt;
&lt;br /&gt;
Since you don&#039;t run Windows and possibly don&#039;t have a spouse or friend around with such unhealthy habits either, you need to get it. It&#039;s quite easy - just google &#039;download windows&#039; and it&#039;ll send you to [https://www.microsoft.com/en-us/software-download/windows10ISO somewhere like this].&lt;br /&gt;
&lt;br /&gt;
=== Burn it! ===&lt;br /&gt;
&lt;br /&gt;
Now it&#039;s time to burn the installer on a DVD ROM. You&#039;ll need a double-layered one, since the OS is &amp;gt; 4.7GiB, but I&#039;m sure you have a ton of those lying around. Now, just place your optical medium in your optical drive and burn, baby, burn!&lt;br /&gt;
&lt;br /&gt;
=== Or make a USB thing? ===&lt;br /&gt;
&lt;br /&gt;
Not a lot of machines have optical drives these days, so you may want to use an USB pen drive or something instead. This is easy, just make the USB bootable with the Windows application Microsoft has made for this. Unfortunately, this only runs on Windows, and unlike stuff like Debian, where the &#039;&#039;&#039;iso&#039;&#039;&#039; file can be dd&#039;ed directly onto a USB drive to make it bootable, the Windows &#039;&#039;&#039;iso&#039;&#039;&#039;s don&#039;t come with this luxury. There are lots of methods to make bootable USB things from iso files out there, but the only thing most of them have in common, is that they generally don&#039;t work.&lt;br /&gt;
&lt;br /&gt;
==== WoeUSB ====&lt;br /&gt;
&lt;br /&gt;
After hours of swearing, it&#039;s nice to come across software like [https://github.com/slacka/WoeUSB WoeUSB]. It may not be perfect, it relies on a bunch of GUI stuff you&#039;ll never need and so on, but it &#039;&#039;&#039;&#039;&#039;works&#039;&#039;&#039;&#039;&#039;, and that&#039;s the important part! Just clone the repo and RTFM and it&#039;s all nice. It&#039;s slow, but hell, getting a windows machine and/or an optical drive might be slower.&lt;br /&gt;
&lt;br /&gt;
WoeUSB does nothing fancy, but it &#039;&#039;&#039;does&#039;&#039;&#039; work. It will create a filesystem, FAT32 or NTFS (better use NTFS, FAT32 has its limits). It creates normal filesystems and so on. Just make sure to copy in the BIOS update file, usually an exe file, to run when Windows is up and running.&lt;br /&gt;
&lt;br /&gt;
==== Install BIOS ====&lt;br /&gt;
&lt;br /&gt;
Boot on the Windows USB thing and choose &#039;repair computer&#039; and then &#039;command prompt&#039;. Find the install file, and if you&#039;re lucky, you&#039;ll find it needs a 32bit OS, just like I did. Since the 64bit version doesn&#039;t include 32bit compatibility in the installer, revert to downloading the 32bit version of windows and start over. Pray to your favourite god(s) not to get across such machines again - it might help.&lt;br /&gt;
&lt;br /&gt;
= 3D printer stuff =&lt;br /&gt;
&lt;br /&gt;
Below are a number of not very ordered paragraphs about 3D printer related stuff, mostly based on my experience. Their content may be interesting or perhaps practical knowledge, but then, that depends on the reader.&lt;br /&gt;
&lt;br /&gt;
== 3D printer related introductions on youtube or elsewhere ==&lt;br /&gt;
&lt;br /&gt;
First off, I&#039;d like to mention some youtube videos that are all (or mostly) a nice start if you&#039;re new to 3D printers.&lt;br /&gt;
&lt;br /&gt;
=== [https://www.youtube.com/watch?v=nb-Bzf4nQdE&amp;amp;list=PLDJMid0lOOYnkcFhz6rfQ6Uj8x7meNJJx Thomas Salanderer&#039;s 10-video series on 3D printing basics] ===&lt;br /&gt;
&lt;br /&gt;
Thomas Salanderer is a an experienced 3D printer user/admin/fixer/etc and he has a lot of interesting videos. Some accuse him for being a [Prusa https://www.prusa3d.com/] fanboy, which he quite obviously is, but that doesn&#039;t stop him from making interesting and somewhat neutral videos. The series walks you thought the first steps of how things work and so on and hopefully opens more doors than anything else I&#039;ve seen.&lt;br /&gt;
&lt;br /&gt;
=== [https://www.youtube.com/watch?v=rp3r921DBGI Teaching Tech&#039;s &amp;quot;3D printer tuning reborn&amp;quot;] ===&lt;br /&gt;
&lt;br /&gt;
Teaching Tech is, like Salanderer or even more, good pedagogically and explains a lot. They (or he) do a bunch of testing and describing pros and cons with different things, just like other youtubers in the sme business. The mentioned video shows how to tune a 3D printer after you have first learned the basics, and leans on a webpage made to help you out without too much manual work.&lt;br /&gt;
&lt;br /&gt;
This was a short list, but I guess it&#039;ll grow over time.&lt;br /&gt;
&lt;br /&gt;
== Hydrophilic filament ==&lt;br /&gt;
&lt;br /&gt;
Most popular filament types, including PLA, PETG, PP or PA (Polyamide, normally known as Nylon) and virtualy any filament type named [https://www.matterhackers.com/news/filament-and-water poly-something] (and thus with an acronym of P-something) are hydrophilic (also (somewhat incorrectly) called hydroscopic), meaning so long they&#039;re dryer than the atmosphere around them, they&#039;ll do their best to suck out the atmosphere&#039;s humidity. This is why most filament are shrink-wrapped with a small bag of silica gel in it. If such filament is exposed for normal humid air for some time, it&#039;ll become very hard to use. Most of my experience is with PLA, which can handle a bit (depending on make), but still not a lot. With PLA, if you end up with prints where the filament seems not to stick, it may help with a higher temperature. Otherwise, the filament must be [https://all3dp.com/2/how-to-dry-filament-pla-abs-and-nylon/ baked]. If you don&#039;t want to use your oven, try something like a [https://www.jula.no/catalog/hjem-og-husholdning/kjokkenmaskiner/mattilberedningsapparater/frukt-sopptorker/frukt-sopptorker-001641/#tab02 fruit and mushroom dryer]. Then get a good, sealble plastic box and add something like half a kilogram of [https://www.ebay.com/sch/sis.html?_nkw=1KG+Orange+Replacement+Desiccant+Indicating+Silica+Gel+Beads+for+Drawers%2C+Camera&amp;amp;_id=131938742628&amp;amp;&amp;amp;_trksid=p2057872.m2749.l2658 silica gel] to an old sock, tie it and put it in the your new dry box.&lt;br /&gt;
&lt;br /&gt;
Please note that ABS is hydrophobic, so you won&#039;t have to worry too much there. Also, remember that PA/Nylon is extremely hydrophilic. Even a couple of days in normal air humidity can ruin it completely and will require baking.&lt;br /&gt;
&lt;br /&gt;
== Upgrading the firmware on an Ender 3 ==&lt;br /&gt;
&lt;br /&gt;
This is about upgrading the firmware, and thus also flashing a bootloader to the Creality Ender 3 3D printer. Most of this is well documented on several place, like o [https://www.youtube.com/watch?v=fIl5X2ffdyo the video from Teaching tech] and elsewhere, but I&#039;ll just summarise some issues I had.&lt;br /&gt;
&lt;br /&gt;
=== Using an arduino Nano as a programmer ===&lt;br /&gt;
&lt;br /&gt;
Quick note before you read on. If you have an Ender 3 controller version 1.1.5 or newer (or perhaps even a bit older), a CR-10S or some other more or less modern printers or controllers, they come with a bootloader installed already, so don&#039;t bother flashing one. The one that&#039;s in there already, should work well. So if you have one of these, just skip this and jump to the [[Roy&#039;s_notes#Flashing_the_printer|next section]].&lt;br /&gt;
&lt;br /&gt;
However, the normal CR-10 (without the S), Ender 3 and a few other printers from Creality come without a bootloader, so you&#039;ll need to flash one before upgrading the firmware. Well, strictly speakning, you don&#039;t need one, you can save those 8kB or so for other stuff and use a programmer to write the whole firmware, but then you&#039;ll need to wire up everything every time you want a new firmware, so in my world, you &#039;&#039;&#039;do&#039;&#039;&#039; need the bootloader, since it&#039;s easier.&lt;br /&gt;
&lt;br /&gt;
To install a bootloader, you&#039;ll need a programmer, and I didn&#039;t have one available. Having some el-cheapo china-copies of Arduinos around, I read I could use one and tried so. Although the docs mostly mention the Uno etc, it&#039;s just as simple with the Nano copy.&lt;br /&gt;
&lt;br /&gt;
So, grab an arduino, plug it to your machine with a USB cable, and, using the Arduino IDE, use the ArduinoISP sketch there (found under Examples) to burn the software needed for the arduino to work as a programmer. When this is done, connect a 10µF capacitor between RST and GND to stop it from resetting when used as a programmer. Connect the MOSI, MISO and SCK pins from the ICSP block (that little isolated 6-pin block on top of the ardu). See [https://www.arduino.cc/en/Tutorial/ArduinoISP here] for a pinout. Then find Vcc and GND either on the ICSP block or elsewhere. Some sites say that on some boards you shouldn&#039;t use the pins on the ICSP block for this. I doubt it matters, though. Then connect another jumper wire from pin 10 on the ardu to work as the reset pin outwards to the chip being programmed (that is, on the printer). The ICSP jumper block pin layout is the same on the printer and on the ardu, and probably elsewhere. Sometimes [https://xkcd.com/927/ standardisation] actually works…&lt;br /&gt;
&lt;br /&gt;
See https://cloud.karlsbakk.net/index.php/s/zw48YJjzaf8Rc2F for a pic with the ardu (this wiki is broken atm, will fix it later)&lt;br /&gt;
&lt;br /&gt;
== Flashing the printer ==&lt;br /&gt;
&lt;br /&gt;
When the boot loader is in place, possibly after some wierd errors from during the process, the screen on the 3d printer will go blank and it&#039;ll behave like being bricked. This is ok. Now disconnect the wires and connect the USB cable between computer and printer. If you haven&#039;t installed support for the Sanguino board, that is, the variant of the 1284-chip and surrounding electronics that is the core of the, you need to install it first. In the Arduino IDE, choose the Tools / Boards / Boards manager boot option and search for Sanguino. After this, you should find the Sanguino or Sanguino 1284p in the boards menu. After this, you should be able to communicate with the printer&#039;s controller. Download the [https://www.th3dstudio.com/knowledgebase/th3d-unified-firmware-package/ TH3D unified firmware], making sure it&#039;s the last version. Uncompress the zip and with Finder/Explorer/whateversomething&#039;scalledonlinux, browse to &#039;&#039;&#039;TH3DUF_R2/Firmware/TH3DUF_R2.ino&#039;&#039;&#039; and open it. It should open directly in the Android IDE. Keep in mind that the names TH3DUF_R2 and TH3DUF_R2.ino will vary between versions, but you get the point. Now configure it for your particular needs. You&#039;ll find most of this in the Configuration.h tab (that&#039;s really a file). Most of the other files won&#039;t be necessary unless you&#039;re doing some more advanced stuff, like replacing th controller with something non-standard or similar, but then again, that&#039;s another chapter (or book, even). The video mentioned above describes this well. After flashing the new firmware, you&#039;ll probably get some timeouts and errors, since apparently it resets the printer after giving it the new firmware, but without notifying the flashing software of it doing so. If this happens, calm down and reboot the printer and check its tiny monitor - it should work. If it doesn&#039;t work, and if you flashed the bootload yourself, try to flash it again, and if that doesn&#039;t work, try flashing the programmer again yet another time, just for kicks. Again, if you have a newer controller like the v1.1.5, don&#039;t touch the bootloader, as the one already installed, should work well as it is.&lt;br /&gt;
&lt;br /&gt;
PS: I tried enabling &#039;&#039;&#039;MANUAL_MESH_LEVELING&#039;&#039;&#039;, which in the code says that &#039;&#039;If used with a 1284P board the bootscreen will be disabled to save space&#039;&#039;. This effectively disabled the whole printer, and apparently may be making the firmware image a wee bit too large for it to fit the 1284P on the ender. It works well without it, though, and it may be fixed by now, since I tested this back in early 2019.&lt;br /&gt;
&lt;br /&gt;
== And then… ==&lt;br /&gt;
&lt;br /&gt;
With the new firmware in place, the printer should work as before, although with thermal runaway protection to better avoid fires in case the shit hits the fan, and to allow for things like autolevelling. With any luck, [https://www.precisionpiezo.co.uk/ this thing] may be ready for use by the time you read this - it surely looks nice!&lt;br /&gt;
&lt;br /&gt;
= Octoprint/Octopi =&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;This could have been under some other section, but again, I just branch out even though most of it is about sections mentioned elsewhere.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
When setting up a 3d printer for the first time, you usually get an SD card for storage and transfer data to the printer using [https://en.wikipedia.org/wiki/Sneakernet Sneakernet]. Some printers use micro SD cards, while other fullsize SD cards, which imho is better, since they don&#039;t get lost that easily, but otherwise do the same thing. This works, but is somewhat tedious. If you want to control the printer from a PC or phone, there&#039;s a simple trick for that as well - octoprint.&lt;br /&gt;
&lt;br /&gt;
[https://octoprint.org/ Octoprint], written by Gina Häußge, runs on most platforms including linux, windows, BSD*, macos etc. It supports controlling a camera to some extent out of the box and there&#039;s a large number of plugins availablee to do a lot of things you possibly haven&#039;t thought of (and quite often, you&#039;d ever need). The easiest way to install it, is to just grab a Raspberry pi - preferably some of the newer models (will get to that later) and download [https://octoprint.org/download/ octopi] and follow the instructions on that page.&lt;br /&gt;
&lt;br /&gt;
== Performance issues ==&lt;br /&gt;
&lt;br /&gt;
Some report (and I have seen it myself) issues with the pi&#039;s performance with regards to both handling the octoprint processes (which should be as close to realtime as possible) and handling other stuff like I/O, networking etc. The point is that at pi3 or older, has all peripherals connected to an internal USB hub. This might be practical, but performance-wise it&#039;s &#039;&#039;&#039;&#039;&#039;not&#039;&#039;&#039;&#039;&#039;. If you in addition connect a webcam to USB, you&#039;re asking for trouble, since USB will be your bottleneck. With a raspberry pi camera, the ones connected to the pi directly with a ribbon cable, this should not use USB, so it&#039;s better. Still, again, for older pi&#039;s, there might be some shortage in therms of cpu or i/o. The octopi runs something like raspbian which is a fork of debian which is a linux distro, so it all boils down to knowing linux.&lt;br /&gt;
&lt;br /&gt;
Your typical octopi will run octoprint, a streamer, usually &#039;&#039;&#039;mjpg-streamer&#039;&#039;&#039;, a simple, lightweight videostreamer that outputs a stream of jpeg-images (about the same format as cinemas use - that is - not MPEG). This may be a bit tough on the cpu and potentially i/o. Add inn a dash of USB overload and you&#039;re may see trouble.&lt;br /&gt;
&lt;br /&gt;
Still - a pi3 should be able to handle the load, but it might help to prioritise corretly. The octoprint process is the important part here, so we could give that full priority both in CPU and I/O and. Unfortunately, it doesn&#039;t seem like the current octopi has been migrated to using systemd for the startup. We&#039;ll deal with this later. To fix this in the old SysV init style file present there, the following patch should work against the file /etc/init.d/octoprint&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;diff&amp;quot;&amp;gt;&lt;br /&gt;
--- octoprint.old	2020-07-20 18:46:10.166651965 +0200&lt;br /&gt;
+++ octoprint	2020-07-20 18:53:21.724803211 +0200&lt;br /&gt;
@@ -22,6 +22,9 @@&lt;br /&gt;
 PIDFILE=/var/run/$NAME.pid&lt;br /&gt;
 PKGNAME=octoprint&lt;br /&gt;
 SCRIPTNAME=/etc/init.d/$PKGNAME&lt;br /&gt;
+NICELEVEL=-19                        # Top CPU priority&lt;br /&gt;
+IONICE_CLASS=1                       # Realtime I/O class&lt;br /&gt;
+IONICE_PRIORITY=0                    # Realtime I/O priority (probably not needed with class=realtime)&lt;br /&gt;
&lt;br /&gt;
 # Read configuration variable file if it is present&lt;br /&gt;
 [ -r /etc/default/$PKGNAME ] &amp;amp;&amp;amp; . /etc/default/$PKGNAME&lt;br /&gt;
@@ -70,10 +73,11 @@&lt;br /&gt;
&lt;br /&gt;
    is_alive $PIDFILE&lt;br /&gt;
    RETVAL=&amp;quot;$?&amp;quot;&lt;br /&gt;
-&lt;br /&gt;
    if [ $RETVAL != 0 ]; then&lt;br /&gt;
        start-stop-daemon --start --background --quiet --pidfile $PIDFILE --make-pidfile \&lt;br /&gt;
-       --exec $DAEMON --chuid $OCTOPRINT_USER --user $OCTOPRINT_USER --umask $UMASK -- serve $DAEMON_ARGS&lt;br /&gt;
+       --exec $DAEMON --chuid $OCTOPRINT_USER --user $OCTOPRINT_USER --umask $UMASK \&lt;br /&gt;
+       --nicelevel $NICELEVEL --ioched $IONICE_CLASS:$IONICE_PRIORITY \&lt;br /&gt;
+       --serve $DAEMON_ARGS&lt;br /&gt;
        RETVAL=&amp;quot;$?&amp;quot;&lt;br /&gt;
    fi&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This ismply upgrades the process to be allowed to use most of the resources on the pi, regardless of what other processes are whining about.&lt;br /&gt;
&lt;br /&gt;
PS: Code not tested - I don&#039;t have a pi right here. Will test later, but I&#039;m pretty sure it&#039;ll work. After all, it&#039;s just a few new arguments to start-stop-daemon&lt;br /&gt;
&lt;br /&gt;
roy&lt;/div&gt;</summary>
		<author><name>Roy</name></author>
	</entry>
	<entry>
		<id>https://wiki.malinux.no/index.php?title=Roy%27s_notes&amp;diff=177</id>
		<title>Roy&#039;s notes</title>
		<link rel="alternate" type="text/html" href="https://wiki.malinux.no/index.php?title=Roy%27s_notes&amp;diff=177"/>
		<updated>2020-11-05T17:12:41Z</updated>

		<summary type="html">&lt;p&gt;Roy: /* Which pi? */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= LVM, md and friends =&lt;br /&gt;
&lt;br /&gt;
== Linux&#039; Logical Volume Manager (LVM) ==&lt;br /&gt;
&lt;br /&gt;
=== LVM in general ===&lt;br /&gt;
&lt;br /&gt;
LVM is designed to be an abstraction layer on top of physical drives or RAID, typically [https://raid.wiki.kernel.org/index.php/RAID_setup mdraid] or [https://help.ubuntu.com/community/FakeRaidHowto fakeraid]. Keep in mind that fakeraid should be avoided unless you really need it, like in conjunction with dual-booting linux and windows on fakeraid. LVM broadly consists of three elements, the &amp;quot;physical&amp;quot; devices (PV), the volume group (VG) and the logical volume (LV). There can be multiple PVs, VGs and LVs, depending on requirement. More about this below. All commands are given as examples, and all of them can be fine-tuned using extra flags in need of so. In my experience, the defaults work well for most usecases.&lt;br /&gt;
&lt;br /&gt;
I&#039;m mentioning filesystem below too. Where I write ext4, the samme applies to ext2 and ext3.&lt;br /&gt;
&lt;br /&gt;
==== Create a PV ====&lt;br /&gt;
&lt;br /&gt;
A PV is the &amp;quot;physical&amp;quot; parts. This does not need to be a physical disk, but can also be another RAID, be it an mdraid, fakeraid, hardware raid, a virtual disk on a SAN or otherwisee or a partition on one of those. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#  These add three PVs, one on a drive (or hardware raid) and another two on mdraids.&lt;br /&gt;
pvcreate /dev/sdb&lt;br /&gt;
pvcreate /dev/md1 /dev/md2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For more information about pvcreate, see [https://linux.die.net/man/8/pvcreate the manual].&lt;br /&gt;
&lt;br /&gt;
==== Create a VG ====&lt;br /&gt;
&lt;br /&gt;
The volume group consists of one or more PVs grouped together on which LVs can be placed. If several PVs are grouped in a VG, it&#039;s generally a good idea to make sure these PVs have some sort of redundancy, as in mdraid/fakeraid or hwraid. Otherwise it will be like using a [https://en.wikipedia.org/wiki/RAID RAID-0] with a single point of failure on each of the independant drives. LVM has [https://unix.stackexchange.com/questions/150644/raiding-with-lvm-vs-mdraid-pros-and-cons  RAID code in it] as well, so you can use that. I haven&#039;t done so myself, as I generally stick to mraid. The reason is mdraid is, in my opinion older and more stable and has more users (meaning bugs are reported and fixed faster whenever they are found). That said, I beleive the actual RAID code used in LVM RAID are the same function calls as for mdraid, so it may not be much of a difference. I still stick with mdraid. To create a VG, run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create volume group my_vg&lt;br /&gt;
vgcreate my_vg /dev/md1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that if vgcreate is run with a PV (as /dev/md1 above) that is not defined as a PV (like above), this is done implicitly, so if you don&#039;t need any special flags to pvcreate, you can simply skip it and let vgcreate do that for you.&lt;br /&gt;
&lt;br /&gt;
==== Create an LV ====&lt;br /&gt;
&lt;br /&gt;
LVs can be compared to partitions, somehow, since they are bounderies of a fraction or all of that of a VG. The difference between them and a partition, however, is that they can be grown or shrunk easily and also moved around between PVs without downtime. This flexibility makes them superiour to partitions as your system can be changed without users noticing it. By default, an LV is alloated &amp;quot;thickly&amp;quot;, meaning all the data given to it, is allocated from the VG and thus the PV. The following makes a 100GB LV named &amp;quot;thicklv&amp;quot;. When making an LV, I usually allocate what&#039;s needed plus some more, but not everything, just to make sure it&#039;s space available for growth on any of the LVs on the VG, or new LVs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a thick provisioned LV named thicklv on the VG my_vg&lt;br /&gt;
lvcreate -n thicklv -L 100G my_vg&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After the LV is created, a filesystem can be placed on it unless it is meant to be used directly. The application for direct use include swap space, VM storage and certain database systems. Most of these will, however, work on filesystems too, although my testing has shown that on swap space, there is a significant performance gain for using dedicated storage without a filesystem. As for filesystems, most Linux users use either ext4 or xfs. Personally, I generally use XFS these days. See my notes below on filesystem choice.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a filesystem on the LV - this could have been mkfs -t ext4 or whatever filesystem you choose&lt;br /&gt;
mkfs -t xfs /dev/my_vg/thicklv&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then just edit /etc/fstab with correct data and run mount -a, and you should be all set.&lt;br /&gt;
&lt;br /&gt;
==== Create LVM cache ====&lt;br /&gt;
LVMcache is LVM&#039;s solution to caching a slowish filesystem on spinning rust with the help of much faster SSDs. For this to work, use a separate SSD or a mirror or two (just in case) an add the new disk/md dev to the same VG. In this case, we use a small mirror, md1. LVM is not able to cache to a disk or partition outside the volume group.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
vgextend data /dev/md1&lt;br /&gt;
  Physical volume &amp;quot;/dev/md1&amp;quot; successfully created.&lt;br /&gt;
  Volume group &amp;quot;data&amp;quot; successfully extended&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Thn create two LVs, one for the data (contents of files) and one for the metadata (filenames, directories, attributes etc). Typically, the metadata part won&#039;t need to be very large. 100M should usually do unless you have ekstremely many small files. I guess there are ways to calculate it, but again, 1GB should do for everyone (or was that 640k?). As for the data cache, I chose to use 40G here for a 15TB RAID. It will only cache what actively use anyway, so no need for overkill.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
lvcreate -L 1G -n _cache_meta data /dev/md1&lt;br /&gt;
lvcreate -L 100G -n _cache data /dev/md1&lt;br /&gt;
&lt;br /&gt;
# Some would want --cachemode writeback, but if paranoid, I wouldn&#039;t recommend it. Metadata or data can be easily corrupted in case of failure. Most filesystems will however recover from this these days since they use journaling. It &#039;&#039;really&#039;&#039; speeds up things.&lt;br /&gt;
lvconvert --type cache-pool --cachemode writethrough --poolmetadata data/_cache_meta data/_cache&lt;br /&gt;
lvconvert --type cache --cachepool data/_cache data/data&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
That should be it. If you benchmarked the disk before this, you should try again and you&#039;ll probably get a nice surprise. If not, well, see below how to turn this off again :)&lt;br /&gt;
&lt;br /&gt;
==== Disabling LVM cache ====&lt;br /&gt;
&lt;br /&gt;
If you want to change the cached LV, such as growing og shrinking or otherwise, you&#039;ll have to disable caching first and then re-enable it. There&#039;s no quick-and-easy fix, but you just do as you did when enabling in the first place. &lt;br /&gt;
&lt;br /&gt;
Forst, disable caching for the LV. This will do it cleanly and remove the LVs earlier created for caching the main device. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
lvconvert --uncache data/data&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, since you now have a VG with an empty PV in it, earlier used for caching, I&#039;d recommend removing this for now to avoid expanding onto that as well. Since they&#039;re in the same VG, this might happen and if you get so far as to extend the lv and the filesystem on it, and this filesystem is XFS or similar filesystems without possibilities of reducing the size, you have a wee problem. &lt;br /&gt;
&lt;br /&gt;
Just remove that PV from the VG&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
vgreduce data /dev/md1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The PV is still there, but pvs should now show it not connected to a VG&lt;br /&gt;
&lt;br /&gt;
==== Growing devices ====&lt;br /&gt;
&lt;br /&gt;
LVM objects can be grown and shrunk. If a PV resides on a RAID where a new drive has been added or otherwise grown, or on a partition or virtual disk that has been extended, the PV must be updated to reflect these changes. The following command will grow the PV to the maximum available on the underlying storage. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Resize the PV /dev/md (not the RAID, only the PV on the RAID) to its full size&lt;br /&gt;
pvresize /dev/md1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If a new PV is added, the VG can be grown to add the space on that in addition to what&#039;s there already. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Extend my_vg to include md2 and its space&lt;br /&gt;
vgextend my_vg /dev/md2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
With more space available in the VG, the LV can now be extended. Let&#039;s add another 50GB to it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Extend thicklv - add 50GB. If you know you won&#039;t need the space anywhere else, you may want to&lt;br /&gt;
# lvresize -l+100%FREE instead. Keep in mind the difference between -l (extents) and -L (bytes)&lt;br /&gt;
lvresize -L +50G my_vg/thicklv&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Growing filesystems ====&lt;br /&gt;
After the LV has grown, run &#039;&#039;xfs_growfs&#039;&#039; (xfs) or &#039;&#039;resize2fs&#039;&#039; (ext4) to make use of the new data. To grow the filesystem to all available space on ext4, run the below command.  To partly grow the filesystem or to shrink it or otherwise, please see the manuals.&lt;br /&gt;
&lt;br /&gt;
The filesystem can be mounted when this is run. If you for some reason get an &#039;&#039;&#039;access denied&#039;&#039;&#039; error when running this as root or with sudo, it&#039;s likely caused by a filesystem error. To fix this, unmount the filesystem first and run &#039;&#039;&#039;fsck -f /dev/my_vg/thicklv&#039;&#039;&#039; and remount it before retrying to extend it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
resize2fs /dev/my_vg/thicklv&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Similarly, with XFS, but note that xfs_growfs doesn&#039;t take the device name, but the filesystem&#039;s mount point. In the case of XFS, also note that the filesystem &#039;&#039;&#039;&#039;&#039;must&#039;&#039;&#039;&#039;&#039; be mounted to be grown. This, in contrast to how it was in the old days when filesystems had to be unmounted to be grown.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
xfs_growfs /my_mountpoint&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Rename system VG ====&lt;br /&gt;
&lt;br /&gt;
Some distros create VG names like those-from-a-sysadmin-with-a-well-developed-paranoia-not-to-hit-a-duplicate. Debian, for instance, uses names like &amp;quot;my-full-hostname-vg&amp;quot;. Personally, I don&#039;t like these, since if I were to move a disk or vdisk around to somewhere else, I&#039;d make sure not to add a disk named &#039;sys&#039; to an existing system. If you do, most distros will refuse to use the VGs with duplicate names, resulting in the OS not booting until either one is specified by its UUID or just one removed. As I&#039;m aware of this, I stick to the super-risky thing of all system VGs named &#039;sys&#039; and so on.&lt;br /&gt;
&lt;br /&gt;
If you do this, keep in mind that it may blow up your computer and take your girl- or boyfriend with it or even make either of them pregnant, allowing Trump to rule your life and generally make things suck. You&#039;re on your own!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Rename the VG&lt;br /&gt;
vgrename my-full-hostname-vg sys&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, in /boot/grub/grub.cfg, change the old lv path from something like &#039;/dev/mapper/debian--stretch--machine--vg-root&#039; to your new and fancy &#039;/dev/sys/root. Likewise, in /etc/fstab, change occurences of &#039;/dev/mapper/debian--stretch--machine--vg-&#039; (or similar) with &#039;/dev/sys/&#039;. Here, this was like this - the old ones commented out.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;fstab&amp;quot;&amp;gt;&lt;br /&gt;
#/dev/mapper/debian--stretch--box--vg-root      /               ext4            errors=remount-ro,discard       0       1&lt;br /&gt;
/dev/sys/root                                   /               ext4            errors=remount-ro,discard       0       1&lt;br /&gt;
# /boot was on /dev/vda1 during installation&lt;br /&gt;
UUID=myverylonguuidwithatonofgoodinfoinit       /boot           ext2            defaults                        0       2&lt;br /&gt;
#/dev/mapper/debian--stretch--box--vg-swap_1    none            swap            sw                              0       0&lt;br /&gt;
/dev/sys/swap_1                                 none            swap            sw                              0       0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Update /etc/initramfs-tools/conf.d/resume with similar data for swap.&lt;br /&gt;
&lt;br /&gt;
You might want to run &#039;update-initramfs -u -k all&#039; after this, but I&#039;m not sure if it&#039;s needed.&lt;br /&gt;
&lt;br /&gt;
Now, pray to the nearest god(s) and give it a reboot and it should (probably) work.&lt;br /&gt;
&lt;br /&gt;
After reboot, run &#039;&#039;&#039;swapoff -a&#039;&#039;&#039;, then &#039;&#039;&#039;mkswap /dev/sys/swap_1&#039;&#039;&#039; (or whatever it&#039;s called on your system) and &#039;&#039;&#039;swapon -a&#039;&#039;&#039; again. You may want to give it another reboot or two for kicks, but it should work well even without that.&lt;br /&gt;
&lt;br /&gt;
=== Migration tools ===&lt;br /&gt;
&lt;br /&gt;
At times, storage regimes change, new storage is added and sometimes it&#039;s not easy to migrate with the current hardware or its support systems. Once I had to migrate a 45TiB fileserver from one storage system to another, preferably without downtime. The server originally had three 15TiB PVs of which two were full and the third half full. I resorted to using [https://linux.die.net/man/8/pvmove pvmove] to just move the data on the PVs in use to a new PV. We started out with creating a new 50TiB PV, sde, and then to pvmove.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Attach /dev/sde to the VG my_vg&lt;br /&gt;
vgextend my_vg /dev/sde&lt;br /&gt;
&lt;br /&gt;
# Move the contents from /dev/sdb over to /dev/sde block by block. If a target is not given in pvmove,&lt;br /&gt;
# the contents of the source (sdb here) will be put somewhere else in the pool.&lt;br /&gt;
pvmove /dev/sdb /dev/sde&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This took a while (as in a week or so) - the pvmove command uses old code and logic (or at least did that when I migrated this in November 2016), but it affected performance on the server very little, so users didn&#039;t notice. After the first PV was migrated, I continued with the other two, one after the other, and after a month or so, it was migrated. We used this on a number of large fileservers, and it worked flawlessly. Before doing the production servers I also tried interrupting pvmove in various ways, including hard resets, and it just kept on after the reboot.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;NOTE:&#039;&#039;&#039;&#039;&#039; &#039;&#039;Even though it worked well for us, &#039;&#039;&#039;always&#039;&#039;&#039; keep a good backup before doing this. Things may go wrong, and without a good backup, you may be looking for a hard-to-find new job the next morning&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
==== mdadm workarounds ====&lt;br /&gt;
&lt;br /&gt;
===== Migrate from a mirror (raid-1) to raid-10 =====&lt;br /&gt;
&lt;br /&gt;
Create a mirror&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sdb /dev/sdc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
LVM (pv/vg/lv) on md0 (see above), put a filesystem on the lv and fill it with some data.&lt;br /&gt;
&lt;br /&gt;
Now, some months later, you want to change this to raid-10 to allow for the same amount of redundancy, but to allow more disks into the system.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mdadm --grow /dev/md0 --level=10&lt;br /&gt;
mdadm: Impossibly level change request for RAID1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So - no - doesn&#039;t work. But - we&#039;re on &lt;br /&gt;
&lt;br /&gt;
Since we&#039;re on lvm already, this&#039;ll be easy. If you&#039;re using filesystems directly on partitions, you can do this the same way, but without the pvmove part, using rsync or whateever you like instead. I&#039;d recommend using lvm for for the new raid, which should be rather obvious from this article. Now plug in a new drive and create a new raid10 on that one. If you two new drives, install both. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# change &amp;quot;missing&amp;quot; to the other device name if you installed two new drives&lt;br /&gt;
mdadm --create /dev/md1 --level=10 --raid-devices=2 /dev/vdd missing&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, as described above, just vgextend the vg, adding the new raid and run pvmove to move the data from the old pv (residing on the old raid1) to the new pv (on raid10). Afte rpvmove is finished (which may take awile, see above), just&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
vgreduce raidtest /dev/md0&lt;br /&gt;
pvremove /dev/md0&lt;br /&gt;
mdadm --stop /dev/md0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
…and your disk is free to be added to the new array. If the new raid is running in degraded mode (if you created it with just one drive), better don&#039;t wait too long, since you don&#039;t have redundancy. Just mdadm --add the devs.&lt;br /&gt;
&lt;br /&gt;
If you now have /dev/mdstat telling you your raid10 is active and have three drives, of which one is a spare, it should look something like this&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5] [raid4] [raid10]&lt;br /&gt;
md1 : active raid10 vdc[3](S) vdb[2] vdd[0]&lt;br /&gt;
      8380416 blocks super 1.2 2 near-copies [2/2] [UU]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Just mdadm --grow --raid-devices=3 /dev/md1&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;RAID section is not complete. I&#039;ll write more on migraing from raid10 to raid6 later. It&#039;s not straight forward, but easier than this one :)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== Thin provisioned LVs ===&lt;br /&gt;
&lt;br /&gt;
Thin provisioning on LVM is a method used for not allocating all the space given to an LV. For instance, if you have a 1TB VG and want to give an LV 500GB, although it currently only uses a fraction of that, a thin lv can be a good alternative. This will allow for adding a limit to how much it can use, but also to let it grow dynamically without manual work by the sysadmin. Thin provisioning adds another layer of abstaction by creating a special LV as a &#039;&#039;thin pool&#039;&#039; from which data is allocated to the &#039;&#039;thin volume(s)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== Create a thin pool ====&lt;br /&gt;
&lt;br /&gt;
Allocate 1TB to the thin pool to be used for thinly provisioned LVs. Keep in mind that the space allocated to the thin pool is in fact thick provisioned. Only the volumes put on &#039;&#039;thinpool&#039;&#039; are thin provisioned. This will create two hidden LVs, one for data and one for metadata. Normally the defaults will do, but check the manual if the data doesn&#039;t match the usual patterns (such as billions of files, resulting in huge amounts of metadata). I &#039;&#039;beleive&#039;&#039; the metadata part should be resizable at a later time if needed, but I have not tested it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a pool for thin LVs. Keep in mind that the pool itself is not thin provisioned, only the volumes residing on it&lt;br /&gt;
lvcreate --size 1T --type thin-pool --thinpool thinpool my_vg&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Create a thin volume ====&lt;br /&gt;
&lt;br /&gt;
You have the thinpool, now put a thin volume on it. It will allocate some space for metadata, but probably not much (a few megs, perhaps).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Now, create a volume with a virtual (-V) size of half a terabyte named thin_pool, but using the thinpool (-T) named thin_pool for storage&lt;br /&gt;
lvcreate -V 500G -T my_vg/thin_pool --name thinvol&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The new volume&#039;s device name will be /dev/thinvol. Now, create a filesystem on it, add to fstab and mount it. The &#039;&#039;&#039;df&#039;&#039;&#039; command will return available space according to the virtual size (-V), while lvs will show how much data is actually used on each of the thinly provisioned volumes.&lt;br /&gt;
&lt;br /&gt;
== Filesystem dilemmas ==&lt;br /&gt;
&lt;br /&gt;
=== XFS or ext4 or something else ===&lt;br /&gt;
The choice of filesystem varies for your use. Distros such as RHEL/CentOS has moved to XFS by default from v7. Debian/Ubuntu still sticks to ext4, like most other. I&#039;ll discuss my thoughts below on ext4 vs XFS and leave the other filesystems for later.&lt;br /&gt;
&lt;br /&gt;
==== ext4 ====&lt;br /&gt;
ext4 is probably the most used filesystem on linux as of writing. It&#039;s rock stable and has been extended by a lot of extensions since the original ext2. It still retains backward compatibility, being able to mount and fsck ext2 and ext3 with the ext4 driver. However, it doesn&#039;t handle large filesystems very well. If a filesystem is created for &amp;lt;16TiB, it cannot be grown to anything larger than 16TiB. This may have changed lately, though. One other issue is handling errors. If a large filesystem (say 10TiB) is damaged, an fsck may take several hours, leading to long downtime. When I refer to ext4 further in this text, the same applies to ext2 and ext3 unless otherwise specified.&lt;br /&gt;
&lt;br /&gt;
==== XFS ====&lt;br /&gt;
XFS, originally developed by SGI some time in the bronze age, but has been worked on heavily after that. RHEL and Centos version 7 and forward, uses XFS as the default filesystem. It is quick, it scales well, but it lacks at least two things ext4 has. It cannot be shrunk (not that you normally need that, but nice if you have a typo or you need to change things). Also, it doesn&#039;t allow for automatic fsck on bootup. If something is messed up on the filesystem, you&#039;ll have to login as root on the console (not ssh), which might be an issue on some systems. The fsck equivalent, xfs_repair, is a *lot* faster than ext4&#039;s fsck, though.&lt;br /&gt;
&lt;br /&gt;
==== ZFS ====&lt;br /&gt;
ZFS is like a combination of RAID, LVM and a filesystem, supporting full checksumming, auto-healing (given sufficient redundancy), compression, encryption, replication, deduplication (if you&#039;re brave and have a &#039;&#039;ton&#039;&#039; of memory) and a lot more. It&#039;s a separate chapter and needs a lot more talk than paragraph here.&lt;br /&gt;
&lt;br /&gt;
==== btrfs ====&lt;br /&gt;
btrfs, pronounced &amp;quot;butterfs&amp;quot; or &amp;quot;betterfs&amp;quot; or just spelled out, is a filesystem that mimics that of ZFS. It has been around for 10 years or so, but hasn&#039;t yet proven to be really stable. Following the progress of it for those years, I&#039;ve found it to be a nice toy with which to play, but not to be used in production. Again, others may say otherwise, but these are just my words.&lt;br /&gt;
&lt;br /&gt;
== Low level disk handling ==&lt;br /&gt;
&lt;br /&gt;
This section is for low-level handling of disks, regardless of storage system elsewhere. These apply to mdraid, lvmraid and zfs and possibly other solutions, with the exception of individual drives on hwraid (and maybe fakeraid), since there, the drives are hidden from Linux (or whatever OS).&lt;br /&gt;
&lt;br /&gt;
=== S.M.A.R.T. and slow drives ===&lt;br /&gt;
Modern (that is, from about 1990 or later) have S.M.A.R.T. (or just smart, since it&#039;s easier to type) monitoring built in, meaning the disk&#039;s controller is monitoring itself. This is handy and will ideally tell you in advance that a drive is flakey or dying. Modern (2010+) smart monitoring is more or less the same. It can be trusted about 50% of the time. Usually, if smart detects an error, it&#039;s a real error. I don&#039;t think I&#039;ve seen it reporting a false positive, but others may know better. &lt;br /&gt;
&lt;br /&gt;
==== smartmontools ====&lt;br /&gt;
First, install smartmontool and run smartclt -H /dev/yourdisk (/dev/sda or something) to get a health report. Then perhaps run smartctl -a /dev/yourdisk and look for &#039;current pending sectors&#039; This should be zero. Also check the temperature, which normally should be much above 50.&lt;br /&gt;
&lt;br /&gt;
==== single, slow drive ====&lt;br /&gt;
What may happen, is smart not seeing anything and life goes on like before, only slower and less prouductive, without telling anyone. If you stubler over this issue, you&#039;ll probably see it during a large rsync/zfs send/receive or a resync/rebuild/resilver of the raid/zpool. During this, it feels like everything is slow and your RAID has turned into a RAIF (redundant array of inexpensive floppies). To check if you have a single drive messing up it all, check with &#039;&#039;&#039;iostat -x 2&#039;&#039;&#039;, having 2 being the delay between each measurement. Interrupt it with ctrl+x. If there&#039;s a rougue drive there, it should stand out like sdg below&lt;br /&gt;
&lt;br /&gt;
 avg-cpu:  %user   %nice %system %iowait  %steal   %idle&lt;br /&gt;
            0.38    0.00    1.75    0.00    0.00   97.87&lt;br /&gt;
&lt;br /&gt;
 Device            r/s     w/s     rkB/s     wkB/s   rrqm/s   wrqm/s  %rrqm  %wrqm r_await w_await aqu-sz rareq-sz wareq-sz  svctm  %util&lt;br /&gt;
 sda              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdb              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdc              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdd              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sde              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdf              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdg              3.50    0.00   2352.00      0.00     0.00     0.00   0.00   0.00 14306.29    0.00  13.85   672.00     0.00 285.71 100.00&lt;br /&gt;
 sdh              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
&lt;br /&gt;
In ZFS land, you should be able to get similar data with &#039;&#039;&#039;zpool iostat -v &amp;lt;pool&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Now you know the bad drive (sdg), pull it from the raid with &#039;&#039;&#039;mdadm --fail /dev/mdX /dev/sdX&#039;&#039;&#039;. Now test the drive&#039;s performance manually, just simply:&lt;br /&gt;
&lt;br /&gt;
 # hdparm -t /dev/sdg&lt;br /&gt;
 &lt;br /&gt;
 /dev/sdg:&lt;br /&gt;
  Timing buffered disk reads:   2 MB in  5.37 seconds = 381.46 kB/sec&lt;br /&gt;
&lt;br /&gt;
Bingo - nothing you&#039;d want to keep. For a good drive, it should be something like 100-200MB/s&lt;br /&gt;
&lt;br /&gt;
PS: Keep in mind that you have a degraded RAID by now in case you had a spare waiting for things to happen.&lt;br /&gt;
&lt;br /&gt;
Try to replace the cable and/or try the disk on another port/controller. If the result from hdparm persists, it&#039;s probably a bad cable&lt;br /&gt;
&lt;br /&gt;
So, then, just psycially locate the drive, pull it out, take out the discs and magnets and recycle the rest.&lt;br /&gt;
&lt;br /&gt;
=== &amp;quot;Unplug&amp;quot; drive from system ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Find the device unit&#039;s number with something like&lt;br /&gt;
find /sys/bus/scsi/devices/*/block/ -name sdd&lt;br /&gt;
# returning /sys/bus/scsi/devices/3:0:0:0/block/sdd here, &lt;br /&gt;
# meaning 3:0:0:0 is the SCSI device we&#039;re looking for.&lt;br /&gt;
&lt;br /&gt;
# Given this is the correct device, and you want to &#039;unplug&#039; it, do so by&lt;br /&gt;
echo 1 &amp;gt; /sys/bus/scsi/devices/3:0:0:0/delete&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Rescan disk controllers ===&lt;br /&gt;
If a drive is added and for some reason doesn&#039;t get detected, or is removed by the command above, it can be rediscovered with a sysfs command to the scsi host to which it is connected. Since there may be quite a few of these, an easy way is to just scan them all and check the output of &#039;&#039;&#039;dmesg -T&#039;&#039;&#039; after running it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Make a list of controllers and send a rescan message to each of them. It won&#039;t do anything &lt;br /&gt;
# for those where nothing has changed, but it will show new drives where they have been added.&lt;br /&gt;
for host_scan in /sys/class/scsi_host/host*/scan&lt;br /&gt;
do&lt;br /&gt;
  echo &#039;- - -&#039; &amp;gt; $host_scan&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Fail injection with debugfs ===&lt;br /&gt;
[https://lxadm.com/Using_fault_injection https://lxadm.com/Using_fault_injection]&lt;br /&gt;
&lt;br /&gt;
== mdadm stuff ==&lt;br /&gt;
=== Resync ===&lt;br /&gt;
To resync a raid, that is, check, run&lt;br /&gt;
&lt;br /&gt;
 echo check &amp;gt; /sys/block/$dev/md/sync_action&lt;br /&gt;
&lt;br /&gt;
where $dev is something like md0. If you have several raids, something like this should work&lt;br /&gt;
&lt;br /&gt;
 for dev in md{0,1}&lt;br /&gt;
 do&lt;br /&gt;
   echo repair &amp;gt; /sys/block/$dev/md/sync_action&lt;br /&gt;
 done&lt;br /&gt;
&lt;br /&gt;
Also useful in a one-liner like&lt;br /&gt;
&lt;br /&gt;
 for dev in md{0,1} ; do echo repair &amp;gt; /sys/block/$dev/md/sync_action ; done&lt;br /&gt;
&lt;br /&gt;
Different raids on different drives will do this in parallel. If the drives are shared somehow with partitions or similar, the check or repair will wait for the other to finish before going on.&lt;br /&gt;
&lt;br /&gt;
As for repair vs check, [https://raid.wiki.kernel.org/index.php/RAID_Administration this article] describes it well. I stick to using repair unless it&#039;s something rare where I don&#039;t want to touch the data.&lt;br /&gt;
&lt;br /&gt;
=== Spare pools ===&lt;br /&gt;
In the old itmes, mdadm supported only a dedicated spare per md device, so if working with a large set of drives (20? 40?), where you&#039;d want to setup more raid sets to increase redundancy, you&#039;d dedicate a spare to each of the raid sets. This has changed (some time ago?), so in these modern, heathen days, you can change mdadm.conf, usually placed under /etc/mdadm, and add &#039;spare-group=somegroup&#039; where &#039;somegroup&#039; is a string identifying the spare group. After doing this, run &#039;&#039;&#039;update-initramfs -u&#039;&#039;&#039; and reboot and add a spare to one of the raid sets in the spare group, and md will use that or those spares for all the raidsets in that group.&lt;br /&gt;
&lt;br /&gt;
As some pointed out on #linux-raid @ irc.freenode.net, this feature is very badly documented, but as far as I can see, it works well.&lt;br /&gt;
&lt;br /&gt;
==== Example config ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create two raidsets&lt;br /&gt;
&lt;br /&gt;
mdadm --create /dev/md1 --level=6 --raid-devices=6 /dev/vd[efghij]&lt;br /&gt;
mdadm --create /dev/md2 --level=6 --raid-devices=6 /dev/vd[klmnop]&lt;br /&gt;
&lt;br /&gt;
# get their UUID etc&lt;br /&gt;
&lt;br /&gt;
mdadm --detail --scan&lt;br /&gt;
ARRAY /dev/md/1 metadata=1.2 name=raidtest:1 UUID=1a8cbdcb:f4092350:348b6b80:c054d74c&lt;br /&gt;
ARRAY /dev/md/2 metadata=1.2 name=raidtest:2 UUID=894b1b7c:cb7eba70:917d6033:ea5afd2b&lt;br /&gt;
&lt;br /&gt;
# Put those lines into /etc/mdadm/mdadm.conf and and add the spare-group&lt;br /&gt;
&lt;br /&gt;
ARRAY /dev/md/1 metadata=1.2 name=raidtest:1 spare-group=raidtest UUID=1a8cbdcb:f4092350:348b6b80:c054d74c&lt;br /&gt;
ARRAY /dev/md/2 metadata=1.2 name=raidtest:2 spare-group=raidtest UUID=894b1b7c:cb7eba70:917d6033:ea5afd2b&lt;br /&gt;
&lt;br /&gt;
# update the initramfs and reboot&lt;br /&gt;
&lt;br /&gt;
update-initramfs -u&lt;br /&gt;
reboot&lt;br /&gt;
&lt;br /&gt;
# add a spare drive to one of the raids&lt;br /&gt;
&lt;br /&gt;
mdadm --add /dev/md1 /dev/vdq&lt;br /&gt;
&lt;br /&gt;
# fail a drive on the other raid&lt;br /&gt;
&lt;br /&gt;
mdadm --fail /dev/md2 /dev/vdn&lt;br /&gt;
&lt;br /&gt;
# check /proc/mdstat to see md2 rebuilding with the spare from md1&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Recovery ===&lt;br /&gt;
&lt;br /&gt;
The other day, I came across a problem a user had on #linux-raid@irc.freenode.net. He had an old Qnap NAS that had died and tried plugging the drives in to his Linux machine and got various errors. The two-drive RAID-1 did not come up as it should, &#039;&#039;&#039;dmesg&#039;&#039;&#039; was full of errors from one of the drives (both connected on USB) and so forth.&lt;br /&gt;
&lt;br /&gt;
We went on and started by taking down the machine and just connecting one of the drives. I had him check what was assembled with&lt;br /&gt;
&lt;br /&gt;
 cat /proc/mdstat&lt;br /&gt;
&lt;br /&gt;
That returned /proc/md127 assembled, but LVM didn&#039;t find anything. So running a manual scan&lt;br /&gt;
&lt;br /&gt;
 pvscan --cache /dev/md127&lt;br /&gt;
&lt;br /&gt;
This made linux find the PV, VG and a couple of LVs, but probably because the mdraid was degraded, the LVs were deactivated, according to &#039;&#039;&#039;lvscan&#039;&#039;&#039;. Activating the one with a filesystem manually&lt;br /&gt;
&lt;br /&gt;
 lvchange -a y /dev/&amp;lt;vg&amp;gt;/&amp;lt;lv&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Substitute &amp;lt;vg&amp;gt; and &amp;lt;lv&amp;gt; with the names listed by vgs and lvs.&lt;br /&gt;
&lt;br /&gt;
This worked, and the filesystem on /dev/&amp;lt;vg&amp;gt;/&amp;lt;lv&amp;gt; could be mounted correctly.&lt;br /&gt;
&lt;br /&gt;
=== The badblock list ===&lt;br /&gt;
&#039;&#039;&#039;md&#039;&#039;&#039; has an internal badblock list (BBL), added around 2010, to list the bad blocks on the disk to avoid using those. While this might sound like a good idea, the badblock list is updated in case of a read error, which can be caused by several things. To make things worse, the BBL is replicated to other drives when a drive fails or the array is grown. So if you start out with sda and sdb and sdb suffers some errors, nothing wrong, md will read from sda, but flag those sectors on sdb as bad. So after a while, perhaps sda dies and gets replaced, with the same content, including the BBL. Then, at some point you might to replace sdb and it, too gets the BBL. So it sticks - forever. Also, there&#039;s no real point of keeping a BBL list, since the drive has its own and even if a sector error occurs, the array will have sufficient redundancy to recover from that (unless you use RAID-0 which you shouldn&#039;t). If a drive finds a bad sector, it&#039;ll be reallocated by the drive itself without the user&#039;s/admin&#039;s/system&#039;s knowledge. If a sector can&#039;t be reallocated, it means the drive is bad and should be replaced.&lt;br /&gt;
&lt;br /&gt;
There&#039;s no official way to remove it and although you can assemble it with the no-bbl option, this will only work if there&#039;s an empty BBL. Also, this will require downtime. As far as I can see, the only way to do this currently, is with a wee hack that should work. Just replace the names of mddev/diskdev with your own.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
mddev=&amp;quot;/dev/md0&amp;quot;&lt;br /&gt;
diskdev=&amp;quot;/dev/sda&amp;quot;&lt;br /&gt;
mdadm $mddev --fail $diskdev --remove $diskdev --re-add $diskdev --update=no-bbl&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If there&#039;s a BBL on the drive already, replace the --update part to &#039;force-no-bbl&#039;. This is not documented anywhere as per se, but it works.&lt;br /&gt;
 &lt;br /&gt;
I haven&#039;t found a way to turn this off permanently, but there may be something coming around when the debate on the linux-raid mailing list closes up on this. There&#039;s a bbl=no in mdadm.conf, but that&#039;s only for creation. I will continue extensive testing for this.&lt;br /&gt;
&lt;br /&gt;
== Tuning ==&lt;br /&gt;
&lt;br /&gt;
While trying to compare a 12-disk RAID (8TB disks) to a hwraid, mdraid was slower, so we did a few things to speed things up:&lt;br /&gt;
&lt;br /&gt;
While testing with [https://linux.die.net/man/1/fio fio], monitor /sys/block/md0/md/stripe_cache_active, and see if it&#039;s close to /sys/block/md0/md/stripe_cache_size. If it is, double the size of the latter&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
echo 4096 &amp;gt; /sys/block/md0/md/stripe_cache_size&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Continue until stripe_cache_active stabilises, and then you&#039;ve found the limit you&#039;ll need. You may want to double that for good measure. &lt;br /&gt;
&lt;br /&gt;
(to be continued)&lt;br /&gt;
&lt;br /&gt;
== Links ==&lt;br /&gt;
&lt;br /&gt;
Below are a few links with useful info&lt;br /&gt;
&lt;br /&gt;
* [https://raid.wiki.kernel.org/index.php/Irreversible_mdadm_failure_recovery Irreversible mdadm failure recovery]&lt;br /&gt;
&lt;br /&gt;
= ZFS =&lt;br /&gt;
&lt;br /&gt;
ZFS can do a lot of things most filesystems or volume managers can&#039;t. It checksums all data and metadata and so long that the system uses ECC enabled memory (RAM), it will have complete control over the whole data set, and when (not if) an error occurs, it&#039;ll fix the issue without even throwing a warning. To fix the issue, you&#039;ll obviously need sufficient redundancy (mirrors or RAIDzN). &lt;br /&gt;
&lt;br /&gt;
== ZFS send/receive between machines ==&lt;br /&gt;
&lt;br /&gt;
ZFS has a send/receive mechanism that allows for snapshots to be sent over the wire to a receiving end. This can be a full filesystem, or an incremental change since last send/reveive. In a WAN scenario, you&#039;ll probably want to use VPN for this. On a controlled network, sending in cleartext is also possible. You may as well use ssh, but keep in mind that ssh was never designed to be used as a fullblown vpn solution and is just too slow or the task with large amounts of data. You may, though, use mbuffer, if on a loal LAN.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Allow traffic from the sending IP in whatever firewall interface you&#039;re using (if you&#039;re using a firewall at all, that is)&lt;br /&gt;
ufw allow from x.x.x.x&lt;br /&gt;
# &lt;br /&gt;
# Start the receiver first. This listens on port 9090, has a 1GB buffer,&lt;br /&gt;
    and uses 128kb chunks (same as zfs):&lt;br /&gt;
&lt;br /&gt;
mbuffer -s 128k -m 1G -I 9090 | zfs receive data/filesystem&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To be continued one day… See [https://everycity.co.uk/alasdair/2010/07/using-mbuffer-to-speed-up-slow-zfs-send-zfs-receive/ this] for some more. I&#039;ll get back with details on it.&lt;br /&gt;
&lt;br /&gt;
= General Linux system control =&lt;br /&gt;
&lt;br /&gt;
== Add a new CPU (core) ==&lt;br /&gt;
&lt;br /&gt;
If working with virtual machines, adding a new core can be useful if the VM is slow and the load is multithreaded or multiprocess. To do this, add a new CPU in the hypervisor (be it KVM or VMware or Hyper-V or whatever). Some hypervisors, like VMware, will activate it automatically if open-vm-tools is installed. Please note that open-vm-tools is for VMware only. I don&#039;t know of any such thing for KVM or other hypervisors (although I beleive VirtualBox has its own set of tools, but not as a package). If this doesn&#039;t work, run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
echo 1 &amp;gt; /sys/devices/system/cpu/cpuX/online&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where X is the CPU number you want to add. You can &#039;cat /sys/devices/system/cpu/cpuX/online&#039; to check if it&#039;s online.&lt;br /&gt;
&lt;br /&gt;
= Mount partitions on a disk image =&lt;br /&gt;
&lt;br /&gt;
Sometimes you&#039;ll have a disk image, either from recovering a bad drive after hours (or days or weeks) of ddrescue, and sometimes you just have a disk image from a virtual machine where you want to mount the partitions inside the image. There are three main methods of doing this, which are more or less synonmous, but some easier than the other.&lt;br /&gt;
&lt;br /&gt;
== Basics ==&lt;br /&gt;
&lt;br /&gt;
A disk image is usually like a disk, consisting of either a large filesystem, a PV or a partition table with one or partitions onto which resides a filesystem, a pv, swap or something else. If it&#039;s partitioned, and you want your operating system to mount a filesystem or allow it to see whatever LVM stuff lies on it, you need to isolate the partitions. &lt;br /&gt;
&lt;br /&gt;
== Manual mapping ==&lt;br /&gt;
&lt;br /&gt;
In the oldern days, this was done manually, something like this&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
root@mymachine:~# fdisk -l /dev/vda&lt;br /&gt;
Disk /dev/vda: 25 GiB, 26843545600 bytes, 52428800 sectors&lt;br /&gt;
Units: sectors of 1 * 512 = 512 bytes&lt;br /&gt;
Sector size (logical/physical): 512 bytes / 512 bytes&lt;br /&gt;
I/O size (minimum/optimal): 512 bytes / 512 bytes&lt;br /&gt;
Disklabel type: dos&lt;br /&gt;
Disk identifier: 0xc37b7ea5&lt;br /&gt;
&lt;br /&gt;
Device     Boot    Start      End  Sectors  Size Id Type&lt;br /&gt;
/dev/vda1  *        2048 50333311 50331264   24G 83 Linux&lt;br /&gt;
/dev/vda2       50333312 52426369  2093058 1022M  5 Extended&lt;br /&gt;
/dev/vda5       50333314 52426369  2093056 1022M 82 Linux swap / Solaris&lt;br /&gt;
root@mymachine:~#&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To calculate the start and end of each partition, you just take the start sector and multiply it by the sector size (512 bytes here) and you have the offset in bytes. After this, it&#039;s merely an losetup -o &amp;lt;offset&amp;gt; /dev/loopX &amp;lt;nameofimagefile&amp;gt; and you have the partition mapped to your /dev/loopX (having X being something typically 0-255. After this, just mount it or run pvscan/vgscan/lvscan to probe whatever lvm config is there, and you should be able to mount it like any other filesystem.&lt;br /&gt;
&lt;br /&gt;
== kpartx ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;kpartx&#039;&#039;&#039; does the same as above, more or less, just without so much hassle. Most of it should be automatic and easy to deal with, except it may fail to disconnect the loopback devices sometimes, so you may have to &#039;&#039;&#039;losetup -d&#039;&#039;&#039; them manually. See the manual, &#039;&#039;&#039;kpartx (8)&#039;&#039;&#039;. Please note that &#039;&#039;&#039;partx&#039;&#039;&#039; works similarly and I&#039;d guess the authors of the two tools are arguing a lot of which one&#039;s the best.&lt;br /&gt;
&lt;br /&gt;
== guestmount ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;guestmount&#039;&#039;&#039; is something similar again, but also supports file formats like &#039;&#039;&#039;qcow2&#039;&#039;&#039; and possibly other, proprietary filesystems like &#039;&#039;&#039;vmdk&#039;&#039;&#039; and &#039;&#039;&#039;vdi&#039;&#039;&#039;, but don&#039;t take my word for it - I haven&#039;t tested. Again, see the manual or just read up on the description [http://ask.xmodulo.com/mount-qcow2-disk-image-linux.html?fbclid=IwAR3snTeZvGzp9PLdX11EQhCfOpux6I93CiJ3A2pUomkkRLly9Xo4851mkTY here]. It seems rather trivial.&lt;br /&gt;
&lt;br /&gt;
= Linux on laptops =&lt;br /&gt;
&lt;br /&gt;
== Wifi with HP EliteBook 725/745 on Ubuntu ==&lt;br /&gt;
&lt;br /&gt;
The HP EliteBook 725/745 and similar are equipped with a BCM4352 wifi chip. As with a lot of other stuff from Broadcom, this lacks an open hardware description, so thus no open driver exist. The proper fix, is to replace the NIC with something with an open driver, but again, this isn&#039;t always possible, so a binary driver exists. In ubuntu, run, somehow connect the machine to the internet and run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install bcmwl-kernel-source&lt;br /&gt;
sudo modprobe wl&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you can&#039;t connect the machine to the internet, download the needed packages on another machine and put it on some usb storage. These packages should suffice:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# apt-cache depends bcmwl-kernel-source&lt;br /&gt;
bcmwl-kernel-source&lt;br /&gt;
  Depends: dkms&lt;br /&gt;
  Depends: linux-libc-dev&lt;br /&gt;
  Depends: libc6-dev&lt;br /&gt;
  Conflicts: &amp;lt;bcmwl-modaliases&amp;gt;&lt;br /&gt;
  Replaces: &amp;lt;bcmwl-modaliases&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then install manually with &#039;&#039;&#039;dpkg -i file1.deb file2.deb&#039;&#039;&#039; etc&lt;br /&gt;
&lt;br /&gt;
After this, ip/ifconfig/iwconfig shouldd see the new wifi nic, probably &#039;&#039;&#039;wlan0&#039;&#039;&#039;, but due to a [https://bugs.launchpad.net/ubuntu/+source/broadcom-sta/+bug/1343151 old, ignored bug], you won&#039;t find any wifi networks. This is because the driver from Broadcom apparently does not support interrupt remapping, commonly used on x64 machines. To turn this off, change &#039;&#039;&#039;/etc/default/grub&#039;&#039;&#039; and change the line &#039;&#039;&#039;GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;quiet splash&amp;quot;&#039;&#039;&#039;, adding intremap=off to the end before the quote: &#039;&#039;&#039;GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;quiet splash intremap=off&amp;quot;&#039;&#039;&#039;. Save the file and run &#039;&#039;&#039;sudo update-grub&#039;&#039;&#039; and reboot. After this, wifi should work well.&lt;br /&gt;
&lt;br /&gt;
== Wifi with HP Compaq Presario CQ57 on Ubuntu ==&lt;br /&gt;
&lt;br /&gt;
The HP Compaq Presario CQ57 uses the RT5390 wifi chipset. This has been supported for quite some time now, and I was quite surprised to find it not working on a laptop a friend was having. The driver loaded correctly, but Ubuntu insisted of the laptop being in &#039;&#039;&#039;flight mode&#039;&#039;&#039;. Checking &#039;&#039;&#039;rfkill&#039;&#039;&#039;, it showed me two NICs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# rfkill list all&lt;br /&gt;
0: phy0: Wireless LAN&lt;br /&gt;
	Soft blocked: no&lt;br /&gt;
	Hard blocked: yes&lt;br /&gt;
1: hp-wifi: Wireless LAN&lt;br /&gt;
	Soft blocked: yes&lt;br /&gt;
	Hard blocked: no&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Turning rfkill on and off resulted in nothing much, except some error messages in the kernel log (dmesg)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] ACPI Error: Field [B128] at bit offset/length 128/1024 exceeds size of target Buffer (160 bits) (20170831/dsopcode-235)&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]&lt;br /&gt;
                            Initialized Local Variables for Method [HWCD]:&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Local0: 00000000a34b7928 &amp;lt;Obj&amp;gt;           Integer 0000000000000000&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Local1: 00000000b0aa6865 &amp;lt;Obj&amp;gt;           Buffer(8) 46 41 49 4C 04 00 00 00&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Local5: 00000000a9811efd &amp;lt;Obj&amp;gt;           Integer 0000000000000004&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] Initialized Arguments for Method [HWCD]:  (2 arguments defined for method invocation)&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Arg0:   0000000078957d1b &amp;lt;Obj&amp;gt;           Integer 0000000000000001&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Arg1:   00000000725c9c6e &amp;lt;Obj&amp;gt;           Buffer(20) 53 45 43 55 02 00 00 00&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] ACPI Error: Method parse/execution failed \_SB.WMID.HWCD, AE_AML_BUFFER_LIMIT (20170831/psparse-550)&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] ACPI Error: Method parse/execution failed \_SB.WMID.WMAD, AE_AML_BUFFER_LIMIT (20170831/psparse-550)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After upgrading BIOS and testing different kernels, I was asked to try to unload the &#039;&#039;&#039;hp_wmi&#039;&#039;&#039; driver. I did, and things changed a bit, so I tried blacklisting it, creating the file &#039;&#039;&#039;/etc/modprobe.d/blacklist-hp_wmi.conf&#039;&#039;&#039; with the following content&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Blacklist this - it doesn&#039;t work!&lt;br /&gt;
blacklist hp_wmi&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
I gave the machine a reboot and afte that, the &#039;&#039;&#039;hp-wifi&#039;&#039;&#039; entry was gone in the rfkill output, and things works.&lt;br /&gt;
&lt;br /&gt;
= Raspberry pi =&lt;br /&gt;
&lt;br /&gt;
I couldn&#039;t quite decide if the raspberry pi should be a separate section or part of Linux, but hell, it can run more than Linux, although 99,lots% of people just uses Linux on them. This is a small list of things to know about them; things not on the front page of the manual or perhaps hidden even better.&lt;br /&gt;
&lt;br /&gt;
== Which pi? ==&lt;br /&gt;
&lt;br /&gt;
I just setup three raspberry pi machines and although some are quite different, like v1 to vEverythingelse or the Pi zero versions to the normal ones, not all of us remember how to distinguish between them, and sometimes they&#039;re in a nice 3d printed (or otherwise) chassis or otherwise hidden. So, how to check three different ones:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
root@home-assistant:~ $ cat /proc/device-tree/model ; echo&lt;br /&gt;
Raspberry Pi 2 Model B Rev 1.1&lt;br /&gt;
&lt;br /&gt;
root@green-pi:~ $ cat /proc/device-tree/model ; echo&lt;br /&gt;
Raspberry Pi 3 Model B Rev 1.2&lt;br /&gt;
&lt;br /&gt;
roy@yellow-pi:~ $cat /proc/device-tree/model ; echo&lt;br /&gt;
Raspberry Pi 4 Model B Rev 1.1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
While this works well, for the latter, the pi4, it doesn&#039;t tell how much memory I have. It comes in variants of 1, 2 and 4GB, and this is the latter.&lt;br /&gt;
&lt;br /&gt;
For a more detailed list, the command &#039;&#039;&#039;awk &#039;/^Revision/ {sub(&amp;quot;^1000&amp;quot;, &amp;quot;&amp;quot;, $3); print $3}&#039; /proc/cpuinfo&#039;&#039;&#039; will give you a revision number, detailing the type of pi, who produced it etc. Please see [https://elinux.org/RPi_HardwareHistory https://elinux.org/RPi_HardwareHistory] for a full table.&lt;br /&gt;
&lt;br /&gt;
== Monitoring ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;vcgencmd&#039;&#039;&#039; from &#039;&#039;&#039;/opt/vc/bin&#039;&#039;&#039;, but symlinked to &#039;&#039;&#039;/usr/bin&#039;&#039;&#039; so it&#039;s available in path, is useful for fetching hardware info about the pi. For example, measuring the temperature&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
root@yellow-pi:~# vcgencmd measure_temp&lt;br /&gt;
temp=63.0&#039;C&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The command is generally badly documented and parts of it seems outdated for newer hardware. Here&#039;s the output from a Raspberry pi 4 with 4GB RAM&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
roy@yellow-pi:~ $ vcgencmd get_mem arm&lt;br /&gt;
arm=948M&lt;br /&gt;
roy@yellow-pi:~ $ vcgencmd get_mem gpu&lt;br /&gt;
gpu=76M&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= BIOS upgrade from Linux =&lt;br /&gt;
&lt;br /&gt;
Generally, BIOS upgrades have been moved to the BIOS itself these days. This saves a lot of work and quite possibly lives after those who earier rammed their heads through walls, now can upgrade directly from the internet instead of using obscure operating systems best avoided. Sometimes, however, one must use these nevertheless. This is a quick run-through on your options.&lt;br /&gt;
&lt;br /&gt;
== DOS ==&lt;br /&gt;
&lt;br /&gt;
Most non-automatic BIOS upgrades are installed from DOS. Doing a BIOS upgrade this way, is generally non-problematic. Just install a USB thingie with [https://www.freedos.org/ FreeDOS], copy your file(s) onto the thing and boot on it. The commandline is the same as old MS/DOS, except a wee bit more userfriendly, but not a lot.&lt;br /&gt;
&lt;br /&gt;
== Windows ==&lt;br /&gt;
&lt;br /&gt;
Some macahines, like laptops from &#039;&#039;&#039;HP&#039;&#039;&#039;, may have BIOS upgrades that are made to be installed from Windows and won&#039;t run in FreeDOS or MS/DOS, instead throwing an error, saying &#039;&#039;&#039;This program cannot be run in DOS mode&#039;&#039;&#039;. This means you&#039;ll have to boot on a Windows rescue disc and do the job from there. Googling this, tells you it&#039;s quite easy, you just choose &#039;make rescue disc&#039; from Windows, and it&#039;s all good, except if you don&#039;t run Windows, that is. To remedy this problem, do as follows:&lt;br /&gt;
&lt;br /&gt;
=== Download Windows ===&lt;br /&gt;
&lt;br /&gt;
Since you don&#039;t run Windows and possibly don&#039;t have a spouse or friend around with such unhealthy habits either, you need to get it. It&#039;s quite easy - just google &#039;download windows&#039; and it&#039;ll send you to [https://www.microsoft.com/en-us/software-download/windows10ISO somewhere like this].&lt;br /&gt;
&lt;br /&gt;
=== Burn it! ===&lt;br /&gt;
&lt;br /&gt;
Now it&#039;s time to burn the installer on a DVD ROM. You&#039;ll need a double-layered one, since the OS is &amp;gt; 4.7GiB, but I&#039;m sure you have a ton of those lying around. Now, just place your optical medium in your optical drive and burn, baby, burn!&lt;br /&gt;
&lt;br /&gt;
=== Or make a USB thing? ===&lt;br /&gt;
&lt;br /&gt;
Not a lot of machines have optical drives these days, so you may want to use an USB pen drive or something instead. This is easy, just make the USB bootable with the Windows application Microsoft has made for this. Unfortunately, this only runs on Windows, and unlike stuff like Debian, where the &#039;&#039;&#039;iso&#039;&#039;&#039; file can be dd&#039;ed directly onto a USB drive to make it bootable, the Windows &#039;&#039;&#039;iso&#039;&#039;&#039;s don&#039;t come with this luxury. There are lots of methods to make bootable USB things from iso files out there, but the only thing most of them have in common, is that they generally don&#039;t work.&lt;br /&gt;
&lt;br /&gt;
==== WoeUSB ====&lt;br /&gt;
&lt;br /&gt;
After hours of swearing, it&#039;s nice to come across software like [https://github.com/slacka/WoeUSB WoeUSB]. It may not be perfect, it relies on a bunch of GUI stuff you&#039;ll never need and so on, but it &#039;&#039;&#039;&#039;&#039;works&#039;&#039;&#039;&#039;&#039;, and that&#039;s the important part! Just clone the repo and RTFM and it&#039;s all nice. It&#039;s slow, but hell, getting a windows machine and/or an optical drive might be slower.&lt;br /&gt;
&lt;br /&gt;
WoeUSB does nothing fancy, but it &#039;&#039;&#039;does&#039;&#039;&#039; work. It will create a filesystem, FAT32 or NTFS (better use NTFS, FAT32 has its limits). It creates normal filesystems and so on. Just make sure to copy in the BIOS update file, usually an exe file, to run when Windows is up and running.&lt;br /&gt;
&lt;br /&gt;
==== Install BIOS ====&lt;br /&gt;
&lt;br /&gt;
Boot on the Windows USB thing and choose &#039;repair computer&#039; and then &#039;command prompt&#039;. Find the install file, and if you&#039;re lucky, you&#039;ll find it needs a 32bit OS, just like I did. Since the 64bit version doesn&#039;t include 32bit compatibility in the installer, revert to downloading the 32bit version of windows and start over. Pray to your favourite god(s) not to get across such machines again - it might help.&lt;br /&gt;
&lt;br /&gt;
= 3D printer stuff =&lt;br /&gt;
&lt;br /&gt;
Below are a number of not very ordered paragraphs about 3D printer related stuff, mostly based on my experience. Their content may be interesting or perhaps practical knowledge, but then, that depends on the reader.&lt;br /&gt;
&lt;br /&gt;
== 3D printer related introductions on youtube or elsewhere ==&lt;br /&gt;
&lt;br /&gt;
First off, I&#039;d like to mention some youtube videos that are all (or mostly) a nice start if you&#039;re new to 3D printers.&lt;br /&gt;
&lt;br /&gt;
=== [https://www.youtube.com/watch?v=nb-Bzf4nQdE&amp;amp;list=PLDJMid0lOOYnkcFhz6rfQ6Uj8x7meNJJx Thomas Salanderer&#039;s 10-video series on 3D printing basics] ===&lt;br /&gt;
&lt;br /&gt;
Thomas Salanderer is a an experienced 3D printer user/admin/fixer/etc and he has a lot of interesting videos. Some accuse him for being a [Prusa https://www.prusa3d.com/] fanboy, which he quite obviously is, but that doesn&#039;t stop him from making interesting and somewhat neutral videos. The series walks you thought the first steps of how things work and so on and hopefully opens more doors than anything else I&#039;ve seen.&lt;br /&gt;
&lt;br /&gt;
=== [https://www.youtube.com/watch?v=rp3r921DBGI Teaching Tech&#039;s &amp;quot;3D printer tuning reborn&amp;quot;] ===&lt;br /&gt;
&lt;br /&gt;
Teaching Tech is, like Salanderer or even more, good pedagogically and explains a lot. They (or he) do a bunch of testing and describing pros and cons with different things, just like other youtubers in the sme business. The mentioned video shows how to tune a 3D printer after you have first learned the basics, and leans on a webpage made to help you out without too much manual work.&lt;br /&gt;
&lt;br /&gt;
This was a short list, but I guess it&#039;ll grow over time.&lt;br /&gt;
&lt;br /&gt;
== Hydrophilic filament ==&lt;br /&gt;
&lt;br /&gt;
Most popular filament types, including PLA, PETG, PP or PA (Polyamide, normally known as Nylon) and virtualy any filament type named [https://www.matterhackers.com/news/filament-and-water poly-something] (and thus with an acronym of P-something) are hydrophilic (also (somewhat incorrectly) called hydroscopic), meaning so long they&#039;re dryer than the atmosphere around them, they&#039;ll do their best to suck out the atmosphere&#039;s humidity. This is why most filament are shrink-wrapped with a small bag of silica gel in it. If such filament is exposed for normal humid air for some time, it&#039;ll become very hard to use. Most of my experience is with PLA, which can handle a bit (depending on make), but still not a lot. With PLA, if you end up with prints where the filament seems not to stick, it may help with a higher temperature. Otherwise, the filament must be [https://all3dp.com/2/how-to-dry-filament-pla-abs-and-nylon/ baked]. If you don&#039;t want to use your oven, try something like a [https://www.jula.no/catalog/hjem-og-husholdning/kjokkenmaskiner/mattilberedningsapparater/frukt-sopptorker/frukt-sopptorker-001641/#tab02 fruit and mushroom dryer]. Then get a good, sealble plastic box and add something like half a kilogram of [https://www.ebay.com/sch/sis.html?_nkw=1KG+Orange+Replacement+Desiccant+Indicating+Silica+Gel+Beads+for+Drawers%2C+Camera&amp;amp;_id=131938742628&amp;amp;&amp;amp;_trksid=p2057872.m2749.l2658 silica gel] to an old sock, tie it and put it in the your new dry box.&lt;br /&gt;
&lt;br /&gt;
Please note that ABS is hydrophobic, so you won&#039;t have to worry too much there. Also, remember that PA/Nylon is extremely hydrophilic. Even a couple of days in normal air humidity can ruin it completely and will require baking.&lt;br /&gt;
&lt;br /&gt;
== Upgrading the firmware on an Ender 3 ==&lt;br /&gt;
&lt;br /&gt;
This is about upgrading the firmware, and thus also flashing a bootloader to the Creality Ender 3 3D printer. Most of this is well documented on several place, like o [https://www.youtube.com/watch?v=fIl5X2ffdyo the video from Teaching tech] and elsewhere, but I&#039;ll just summarise some issues I had.&lt;br /&gt;
&lt;br /&gt;
=== Using an arduino Nano as a programmer ===&lt;br /&gt;
&lt;br /&gt;
Quick note before you read on. If you have an Ender 3 controller version 1.1.5 or newer (or perhaps even a bit older), a CR-10S or some other more or less modern printers or controllers, they come with a bootloader installed already, so don&#039;t bother flashing one. The one that&#039;s in there already, should work well. So if you have one of these, just skip this and jump to the [[Roy&#039;s_notes#Flashing_the_printer|next section]].&lt;br /&gt;
&lt;br /&gt;
However, the normal CR-10 (without the S), Ender 3 and a few other printers from Creality come without a bootloader, so you&#039;ll need to flash one before upgrading the firmware. Well, strictly speakning, you don&#039;t need one, you can save those 8kB or so for other stuff and use a programmer to write the whole firmware, but then you&#039;ll need to wire up everything every time you want a new firmware, so in my world, you &#039;&#039;&#039;do&#039;&#039;&#039; need the bootloader, since it&#039;s easier.&lt;br /&gt;
&lt;br /&gt;
To install a bootloader, you&#039;ll need a programmer, and I didn&#039;t have one available. Having some el-cheapo china-copies of Arduinos around, I read I could use one and tried so. Although the docs mostly mention the Uno etc, it&#039;s just as simple with the Nano copy.&lt;br /&gt;
&lt;br /&gt;
So, grab an arduino, plug it to your machine with a USB cable, and, using the Arduino IDE, use the ArduinoISP sketch there (found under Examples) to burn the software needed for the arduino to work as a programmer. When this is done, connect a 10µF capacitor between RST and GND to stop it from resetting when used as a programmer. Connect the MOSI, MISO and SCK pins from the ICSP block (that little isolated 6-pin block on top of the ardu). See [https://www.arduino.cc/en/Tutorial/ArduinoISP here] for a pinout. Then find Vcc and GND either on the ICSP block or elsewhere. Some sites say that on some boards you shouldn&#039;t use the pins on the ICSP block for this. I doubt it matters, though. Then connect another jumper wire from pin 10 on the ardu to work as the reset pin outwards to the chip being programmed (that is, on the printer). The ICSP jumper block pin layout is the same on the printer and on the ardu, and probably elsewhere. Sometimes [https://xkcd.com/927/ standardisation] actually works…&lt;br /&gt;
&lt;br /&gt;
See https://cloud.karlsbakk.net/index.php/s/zw48YJjzaf8Rc2F for a pic with the ardu (this wiki is broken atm, will fix it later)&lt;br /&gt;
&lt;br /&gt;
== Flashing the printer ==&lt;br /&gt;
&lt;br /&gt;
When the boot loader is in place, possibly after some wierd errors from during the process, the screen on the 3d printer will go blank and it&#039;ll behave like being bricked. This is ok. Now disconnect the wires and connect the USB cable between computer and printer. If you haven&#039;t installed support for the Sanguino board, that is, the variant of the 1284-chip and surrounding electronics that is the core of the, you need to install it first. In the Arduino IDE, choose the Tools / Boards / Boards manager boot option and search for Sanguino. After this, you should find the Sanguino or Sanguino 1284p in the boards menu. After this, you should be able to communicate with the printer&#039;s controller. Download the [https://www.th3dstudio.com/knowledgebase/th3d-unified-firmware-package/ TH3D unified firmware], making sure it&#039;s the last version. Uncompress the zip and with Finder/Explorer/whateversomething&#039;scalledonlinux, browse to &#039;&#039;&#039;TH3DUF_R2/Firmware/TH3DUF_R2.ino&#039;&#039;&#039; and open it. It should open directly in the Android IDE. Keep in mind that the names TH3DUF_R2 and TH3DUF_R2.ino will vary between versions, but you get the point. Now configure it for your particular needs. You&#039;ll find most of this in the Configuration.h tab (that&#039;s really a file). Most of the other files won&#039;t be necessary unless you&#039;re doing some more advanced stuff, like replacing th controller with something non-standard or similar, but then again, that&#039;s another chapter (or book, even). The video mentioned above describes this well. After flashing the new firmware, you&#039;ll probably get some timeouts and errors, since apparently it resets the printer after giving it the new firmware, but without notifying the flashing software of it doing so. If this happens, calm down and reboot the printer and check its tiny monitor - it should work. If it doesn&#039;t work, and if you flashed the bootload yourself, try to flash it again, and if that doesn&#039;t work, try flashing the programmer again yet another time, just for kicks. Again, if you have a newer controller like the v1.1.5, don&#039;t touch the bootloader, as the one already installed, should work well as it is.&lt;br /&gt;
&lt;br /&gt;
PS: I tried enabling &#039;&#039;&#039;MANUAL_MESH_LEVELING&#039;&#039;&#039;, which in the code says that &#039;&#039;If used with a 1284P board the bootscreen will be disabled to save space&#039;&#039;. This effectively disabled the whole printer, and apparently may be making the firmware image a wee bit too large for it to fit the 1284P on the ender. It works well without it, though, and it may be fixed by now, since I tested this back in early 2019.&lt;br /&gt;
&lt;br /&gt;
== And then… ==&lt;br /&gt;
&lt;br /&gt;
With the new firmware in place, the printer should work as before, although with thermal runaway protection to better avoid fires in case the shit hits the fan, and to allow for things like autolevelling. With any luck, [https://www.precisionpiezo.co.uk/ this thing] may be ready for use by the time you read this - it surely looks nice!&lt;br /&gt;
&lt;br /&gt;
= Octoprint/Octopi =&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;This could have been under some other section, but again, I just branch out even though most of it is about sections mentioned elsewhere.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
When setting up a 3d printer for the first time, you usually get an SD card for storage and transfer data to the printer using [https://en.wikipedia.org/wiki/Sneakernet Sneakernet]. Some printers use micro SD cards, while other fullsize SD cards, which imho is better, since they don&#039;t get lost that easily, but otherwise do the same thing. This works, but is somewhat tedious. If you want to control the printer from a PC or phone, there&#039;s a simple trick for that as well - octoprint.&lt;br /&gt;
&lt;br /&gt;
[https://octoprint.org/ Octoprint], written by Gina Häußge, runs on most platforms including linux, windows, BSD*, macos etc. It supports controlling a camera to some extent out of the box and there&#039;s a large number of plugins availablee to do a lot of things you possibly haven&#039;t thought of (and quite often, you&#039;d ever need). The easiest way to install it, is to just grab a Raspberry pi - preferably some of the newer models (will get to that later) and download [https://octoprint.org/download/ octopi] and follow the instructions on that page.&lt;br /&gt;
&lt;br /&gt;
== Performance issues ==&lt;br /&gt;
&lt;br /&gt;
Some report (and I have seen it myself) issues with the pi&#039;s performance with regards to both handling the octoprint processes (which should be as close to realtime as possible) and handling other stuff like I/O, networking etc. The point is that at pi3 or older, has all peripherals connected to an internal USB hub. This might be practical, but performance-wise it&#039;s &#039;&#039;&#039;&#039;&#039;not&#039;&#039;&#039;&#039;&#039;. If you in addition connect a webcam to USB, you&#039;re asking for trouble, since USB will be your bottleneck. With a raspberry pi camera, the ones connected to the pi directly with a ribbon cable, this should not use USB, so it&#039;s better. Still, again, for older pi&#039;s, there might be some shortage in therms of cpu or i/o. The octopi runs something like raspbian which is a fork of debian which is a linux distro, so it all boils down to knowing linux.&lt;br /&gt;
&lt;br /&gt;
Your typical octopi will run octoprint, a streamer, usually &#039;&#039;&#039;mjpg-streamer&#039;&#039;&#039;, a simple, lightweight videostreamer that outputs a stream of jpeg-images (about the same format as cinemas use - that is - not MPEG). This may be a bit tough on the cpu and potentially i/o. Add inn a dash of USB overload and you&#039;re may see trouble.&lt;br /&gt;
&lt;br /&gt;
Still - a pi3 should be able to handle the load, but it might help to prioritise corretly. The octoprint process is the important part here, so we could give that full priority both in CPU and I/O and. Unfortunately, it doesn&#039;t seem like the current octopi has been migrated to using systemd for the startup. We&#039;ll deal with this later. To fix this in the old SysV init style file present there, the following patch should work against the file /etc/init.d/octoprint&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;diff&amp;quot;&amp;gt;&lt;br /&gt;
--- octoprint.old	2020-07-20 18:46:10.166651965 +0200&lt;br /&gt;
+++ octoprint	2020-07-20 18:53:21.724803211 +0200&lt;br /&gt;
@@ -22,6 +22,9 @@&lt;br /&gt;
 PIDFILE=/var/run/$NAME.pid&lt;br /&gt;
 PKGNAME=octoprint&lt;br /&gt;
 SCRIPTNAME=/etc/init.d/$PKGNAME&lt;br /&gt;
+NICELEVEL=-19                        # Top CPU priority&lt;br /&gt;
+IONICE_CLASS=1                       # Realtime I/O class&lt;br /&gt;
+IONICE_PRIORITY=0                    # Realtime I/O priority (probably not needed with class=realtime)&lt;br /&gt;
&lt;br /&gt;
 # Read configuration variable file if it is present&lt;br /&gt;
 [ -r /etc/default/$PKGNAME ] &amp;amp;&amp;amp; . /etc/default/$PKGNAME&lt;br /&gt;
@@ -70,10 +73,11 @@&lt;br /&gt;
&lt;br /&gt;
    is_alive $PIDFILE&lt;br /&gt;
    RETVAL=&amp;quot;$?&amp;quot;&lt;br /&gt;
-&lt;br /&gt;
    if [ $RETVAL != 0 ]; then&lt;br /&gt;
        start-stop-daemon --start --background --quiet --pidfile $PIDFILE --make-pidfile \&lt;br /&gt;
-       --exec $DAEMON --chuid $OCTOPRINT_USER --user $OCTOPRINT_USER --umask $UMASK -- serve $DAEMON_ARGS&lt;br /&gt;
+       --exec $DAEMON --chuid $OCTOPRINT_USER --user $OCTOPRINT_USER --umask $UMASK \&lt;br /&gt;
+       --nicelevel $NICELEVEL --ioched $IONICE_CLASS:$IONICE_PRIORITY \&lt;br /&gt;
+       --serve $DAEMON_ARGS&lt;br /&gt;
        RETVAL=&amp;quot;$?&amp;quot;&lt;br /&gt;
    fi&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This ismply upgrades the process to be allowed to use most of the resources on the pi, regardless of what other processes are whining about.&lt;br /&gt;
&lt;br /&gt;
PS: Code not tested - I don&#039;t have a pi right here. Will test later, but I&#039;m pretty sure it&#039;ll work. After all, it&#039;s just a few new arguments to start-stop-daemon&lt;br /&gt;
&lt;br /&gt;
roy&lt;/div&gt;</summary>
		<author><name>Roy</name></author>
	</entry>
	<entry>
		<id>https://wiki.malinux.no/index.php?title=Roy%27s_notes&amp;diff=176</id>
		<title>Roy&#039;s notes</title>
		<link rel="alternate" type="text/html" href="https://wiki.malinux.no/index.php?title=Roy%27s_notes&amp;diff=176"/>
		<updated>2020-11-05T17:12:01Z</updated>

		<summary type="html">&lt;p&gt;Roy: /* Which pi? */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= LVM, md and friends =&lt;br /&gt;
&lt;br /&gt;
== Linux&#039; Logical Volume Manager (LVM) ==&lt;br /&gt;
&lt;br /&gt;
=== LVM in general ===&lt;br /&gt;
&lt;br /&gt;
LVM is designed to be an abstraction layer on top of physical drives or RAID, typically [https://raid.wiki.kernel.org/index.php/RAID_setup mdraid] or [https://help.ubuntu.com/community/FakeRaidHowto fakeraid]. Keep in mind that fakeraid should be avoided unless you really need it, like in conjunction with dual-booting linux and windows on fakeraid. LVM broadly consists of three elements, the &amp;quot;physical&amp;quot; devices (PV), the volume group (VG) and the logical volume (LV). There can be multiple PVs, VGs and LVs, depending on requirement. More about this below. All commands are given as examples, and all of them can be fine-tuned using extra flags in need of so. In my experience, the defaults work well for most usecases.&lt;br /&gt;
&lt;br /&gt;
I&#039;m mentioning filesystem below too. Where I write ext4, the samme applies to ext2 and ext3.&lt;br /&gt;
&lt;br /&gt;
==== Create a PV ====&lt;br /&gt;
&lt;br /&gt;
A PV is the &amp;quot;physical&amp;quot; parts. This does not need to be a physical disk, but can also be another RAID, be it an mdraid, fakeraid, hardware raid, a virtual disk on a SAN or otherwisee or a partition on one of those. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#  These add three PVs, one on a drive (or hardware raid) and another two on mdraids.&lt;br /&gt;
pvcreate /dev/sdb&lt;br /&gt;
pvcreate /dev/md1 /dev/md2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For more information about pvcreate, see [https://linux.die.net/man/8/pvcreate the manual].&lt;br /&gt;
&lt;br /&gt;
==== Create a VG ====&lt;br /&gt;
&lt;br /&gt;
The volume group consists of one or more PVs grouped together on which LVs can be placed. If several PVs are grouped in a VG, it&#039;s generally a good idea to make sure these PVs have some sort of redundancy, as in mdraid/fakeraid or hwraid. Otherwise it will be like using a [https://en.wikipedia.org/wiki/RAID RAID-0] with a single point of failure on each of the independant drives. LVM has [https://unix.stackexchange.com/questions/150644/raiding-with-lvm-vs-mdraid-pros-and-cons  RAID code in it] as well, so you can use that. I haven&#039;t done so myself, as I generally stick to mraid. The reason is mdraid is, in my opinion older and more stable and has more users (meaning bugs are reported and fixed faster whenever they are found). That said, I beleive the actual RAID code used in LVM RAID are the same function calls as for mdraid, so it may not be much of a difference. I still stick with mdraid. To create a VG, run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create volume group my_vg&lt;br /&gt;
vgcreate my_vg /dev/md1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that if vgcreate is run with a PV (as /dev/md1 above) that is not defined as a PV (like above), this is done implicitly, so if you don&#039;t need any special flags to pvcreate, you can simply skip it and let vgcreate do that for you.&lt;br /&gt;
&lt;br /&gt;
==== Create an LV ====&lt;br /&gt;
&lt;br /&gt;
LVs can be compared to partitions, somehow, since they are bounderies of a fraction or all of that of a VG. The difference between them and a partition, however, is that they can be grown or shrunk easily and also moved around between PVs without downtime. This flexibility makes them superiour to partitions as your system can be changed without users noticing it. By default, an LV is alloated &amp;quot;thickly&amp;quot;, meaning all the data given to it, is allocated from the VG and thus the PV. The following makes a 100GB LV named &amp;quot;thicklv&amp;quot;. When making an LV, I usually allocate what&#039;s needed plus some more, but not everything, just to make sure it&#039;s space available for growth on any of the LVs on the VG, or new LVs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a thick provisioned LV named thicklv on the VG my_vg&lt;br /&gt;
lvcreate -n thicklv -L 100G my_vg&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After the LV is created, a filesystem can be placed on it unless it is meant to be used directly. The application for direct use include swap space, VM storage and certain database systems. Most of these will, however, work on filesystems too, although my testing has shown that on swap space, there is a significant performance gain for using dedicated storage without a filesystem. As for filesystems, most Linux users use either ext4 or xfs. Personally, I generally use XFS these days. See my notes below on filesystem choice.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a filesystem on the LV - this could have been mkfs -t ext4 or whatever filesystem you choose&lt;br /&gt;
mkfs -t xfs /dev/my_vg/thicklv&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then just edit /etc/fstab with correct data and run mount -a, and you should be all set.&lt;br /&gt;
&lt;br /&gt;
==== Create LVM cache ====&lt;br /&gt;
LVMcache is LVM&#039;s solution to caching a slowish filesystem on spinning rust with the help of much faster SSDs. For this to work, use a separate SSD or a mirror or two (just in case) an add the new disk/md dev to the same VG. In this case, we use a small mirror, md1. LVM is not able to cache to a disk or partition outside the volume group.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
vgextend data /dev/md1&lt;br /&gt;
  Physical volume &amp;quot;/dev/md1&amp;quot; successfully created.&lt;br /&gt;
  Volume group &amp;quot;data&amp;quot; successfully extended&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Thn create two LVs, one for the data (contents of files) and one for the metadata (filenames, directories, attributes etc). Typically, the metadata part won&#039;t need to be very large. 100M should usually do unless you have ekstremely many small files. I guess there are ways to calculate it, but again, 1GB should do for everyone (or was that 640k?). As for the data cache, I chose to use 40G here for a 15TB RAID. It will only cache what actively use anyway, so no need for overkill.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
lvcreate -L 1G -n _cache_meta data /dev/md1&lt;br /&gt;
lvcreate -L 100G -n _cache data /dev/md1&lt;br /&gt;
&lt;br /&gt;
# Some would want --cachemode writeback, but if paranoid, I wouldn&#039;t recommend it. Metadata or data can be easily corrupted in case of failure. Most filesystems will however recover from this these days since they use journaling. It &#039;&#039;really&#039;&#039; speeds up things.&lt;br /&gt;
lvconvert --type cache-pool --cachemode writethrough --poolmetadata data/_cache_meta data/_cache&lt;br /&gt;
lvconvert --type cache --cachepool data/_cache data/data&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
That should be it. If you benchmarked the disk before this, you should try again and you&#039;ll probably get a nice surprise. If not, well, see below how to turn this off again :)&lt;br /&gt;
&lt;br /&gt;
==== Disabling LVM cache ====&lt;br /&gt;
&lt;br /&gt;
If you want to change the cached LV, such as growing og shrinking or otherwise, you&#039;ll have to disable caching first and then re-enable it. There&#039;s no quick-and-easy fix, but you just do as you did when enabling in the first place. &lt;br /&gt;
&lt;br /&gt;
Forst, disable caching for the LV. This will do it cleanly and remove the LVs earlier created for caching the main device. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
lvconvert --uncache data/data&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, since you now have a VG with an empty PV in it, earlier used for caching, I&#039;d recommend removing this for now to avoid expanding onto that as well. Since they&#039;re in the same VG, this might happen and if you get so far as to extend the lv and the filesystem on it, and this filesystem is XFS or similar filesystems without possibilities of reducing the size, you have a wee problem. &lt;br /&gt;
&lt;br /&gt;
Just remove that PV from the VG&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
vgreduce data /dev/md1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The PV is still there, but pvs should now show it not connected to a VG&lt;br /&gt;
&lt;br /&gt;
==== Growing devices ====&lt;br /&gt;
&lt;br /&gt;
LVM objects can be grown and shrunk. If a PV resides on a RAID where a new drive has been added or otherwise grown, or on a partition or virtual disk that has been extended, the PV must be updated to reflect these changes. The following command will grow the PV to the maximum available on the underlying storage. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Resize the PV /dev/md (not the RAID, only the PV on the RAID) to its full size&lt;br /&gt;
pvresize /dev/md1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If a new PV is added, the VG can be grown to add the space on that in addition to what&#039;s there already. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Extend my_vg to include md2 and its space&lt;br /&gt;
vgextend my_vg /dev/md2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
With more space available in the VG, the LV can now be extended. Let&#039;s add another 50GB to it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Extend thicklv - add 50GB. If you know you won&#039;t need the space anywhere else, you may want to&lt;br /&gt;
# lvresize -l+100%FREE instead. Keep in mind the difference between -l (extents) and -L (bytes)&lt;br /&gt;
lvresize -L +50G my_vg/thicklv&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Growing filesystems ====&lt;br /&gt;
After the LV has grown, run &#039;&#039;xfs_growfs&#039;&#039; (xfs) or &#039;&#039;resize2fs&#039;&#039; (ext4) to make use of the new data. To grow the filesystem to all available space on ext4, run the below command.  To partly grow the filesystem or to shrink it or otherwise, please see the manuals.&lt;br /&gt;
&lt;br /&gt;
The filesystem can be mounted when this is run. If you for some reason get an &#039;&#039;&#039;access denied&#039;&#039;&#039; error when running this as root or with sudo, it&#039;s likely caused by a filesystem error. To fix this, unmount the filesystem first and run &#039;&#039;&#039;fsck -f /dev/my_vg/thicklv&#039;&#039;&#039; and remount it before retrying to extend it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
resize2fs /dev/my_vg/thicklv&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Similarly, with XFS, but note that xfs_growfs doesn&#039;t take the device name, but the filesystem&#039;s mount point. In the case of XFS, also note that the filesystem &#039;&#039;&#039;&#039;&#039;must&#039;&#039;&#039;&#039;&#039; be mounted to be grown. This, in contrast to how it was in the old days when filesystems had to be unmounted to be grown.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
xfs_growfs /my_mountpoint&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Rename system VG ====&lt;br /&gt;
&lt;br /&gt;
Some distros create VG names like those-from-a-sysadmin-with-a-well-developed-paranoia-not-to-hit-a-duplicate. Debian, for instance, uses names like &amp;quot;my-full-hostname-vg&amp;quot;. Personally, I don&#039;t like these, since if I were to move a disk or vdisk around to somewhere else, I&#039;d make sure not to add a disk named &#039;sys&#039; to an existing system. If you do, most distros will refuse to use the VGs with duplicate names, resulting in the OS not booting until either one is specified by its UUID or just one removed. As I&#039;m aware of this, I stick to the super-risky thing of all system VGs named &#039;sys&#039; and so on.&lt;br /&gt;
&lt;br /&gt;
If you do this, keep in mind that it may blow up your computer and take your girl- or boyfriend with it or even make either of them pregnant, allowing Trump to rule your life and generally make things suck. You&#039;re on your own!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Rename the VG&lt;br /&gt;
vgrename my-full-hostname-vg sys&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, in /boot/grub/grub.cfg, change the old lv path from something like &#039;/dev/mapper/debian--stretch--machine--vg-root&#039; to your new and fancy &#039;/dev/sys/root. Likewise, in /etc/fstab, change occurences of &#039;/dev/mapper/debian--stretch--machine--vg-&#039; (or similar) with &#039;/dev/sys/&#039;. Here, this was like this - the old ones commented out.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;fstab&amp;quot;&amp;gt;&lt;br /&gt;
#/dev/mapper/debian--stretch--box--vg-root      /               ext4            errors=remount-ro,discard       0       1&lt;br /&gt;
/dev/sys/root                                   /               ext4            errors=remount-ro,discard       0       1&lt;br /&gt;
# /boot was on /dev/vda1 during installation&lt;br /&gt;
UUID=myverylonguuidwithatonofgoodinfoinit       /boot           ext2            defaults                        0       2&lt;br /&gt;
#/dev/mapper/debian--stretch--box--vg-swap_1    none            swap            sw                              0       0&lt;br /&gt;
/dev/sys/swap_1                                 none            swap            sw                              0       0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Update /etc/initramfs-tools/conf.d/resume with similar data for swap.&lt;br /&gt;
&lt;br /&gt;
You might want to run &#039;update-initramfs -u -k all&#039; after this, but I&#039;m not sure if it&#039;s needed.&lt;br /&gt;
&lt;br /&gt;
Now, pray to the nearest god(s) and give it a reboot and it should (probably) work.&lt;br /&gt;
&lt;br /&gt;
After reboot, run &#039;&#039;&#039;swapoff -a&#039;&#039;&#039;, then &#039;&#039;&#039;mkswap /dev/sys/swap_1&#039;&#039;&#039; (or whatever it&#039;s called on your system) and &#039;&#039;&#039;swapon -a&#039;&#039;&#039; again. You may want to give it another reboot or two for kicks, but it should work well even without that.&lt;br /&gt;
&lt;br /&gt;
=== Migration tools ===&lt;br /&gt;
&lt;br /&gt;
At times, storage regimes change, new storage is added and sometimes it&#039;s not easy to migrate with the current hardware or its support systems. Once I had to migrate a 45TiB fileserver from one storage system to another, preferably without downtime. The server originally had three 15TiB PVs of which two were full and the third half full. I resorted to using [https://linux.die.net/man/8/pvmove pvmove] to just move the data on the PVs in use to a new PV. We started out with creating a new 50TiB PV, sde, and then to pvmove.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Attach /dev/sde to the VG my_vg&lt;br /&gt;
vgextend my_vg /dev/sde&lt;br /&gt;
&lt;br /&gt;
# Move the contents from /dev/sdb over to /dev/sde block by block. If a target is not given in pvmove,&lt;br /&gt;
# the contents of the source (sdb here) will be put somewhere else in the pool.&lt;br /&gt;
pvmove /dev/sdb /dev/sde&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This took a while (as in a week or so) - the pvmove command uses old code and logic (or at least did that when I migrated this in November 2016), but it affected performance on the server very little, so users didn&#039;t notice. After the first PV was migrated, I continued with the other two, one after the other, and after a month or so, it was migrated. We used this on a number of large fileservers, and it worked flawlessly. Before doing the production servers I also tried interrupting pvmove in various ways, including hard resets, and it just kept on after the reboot.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;NOTE:&#039;&#039;&#039;&#039;&#039; &#039;&#039;Even though it worked well for us, &#039;&#039;&#039;always&#039;&#039;&#039; keep a good backup before doing this. Things may go wrong, and without a good backup, you may be looking for a hard-to-find new job the next morning&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
==== mdadm workarounds ====&lt;br /&gt;
&lt;br /&gt;
===== Migrate from a mirror (raid-1) to raid-10 =====&lt;br /&gt;
&lt;br /&gt;
Create a mirror&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sdb /dev/sdc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
LVM (pv/vg/lv) on md0 (see above), put a filesystem on the lv and fill it with some data.&lt;br /&gt;
&lt;br /&gt;
Now, some months later, you want to change this to raid-10 to allow for the same amount of redundancy, but to allow more disks into the system.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mdadm --grow /dev/md0 --level=10&lt;br /&gt;
mdadm: Impossibly level change request for RAID1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So - no - doesn&#039;t work. But - we&#039;re on &lt;br /&gt;
&lt;br /&gt;
Since we&#039;re on lvm already, this&#039;ll be easy. If you&#039;re using filesystems directly on partitions, you can do this the same way, but without the pvmove part, using rsync or whateever you like instead. I&#039;d recommend using lvm for for the new raid, which should be rather obvious from this article. Now plug in a new drive and create a new raid10 on that one. If you two new drives, install both. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# change &amp;quot;missing&amp;quot; to the other device name if you installed two new drives&lt;br /&gt;
mdadm --create /dev/md1 --level=10 --raid-devices=2 /dev/vdd missing&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, as described above, just vgextend the vg, adding the new raid and run pvmove to move the data from the old pv (residing on the old raid1) to the new pv (on raid10). Afte rpvmove is finished (which may take awile, see above), just&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
vgreduce raidtest /dev/md0&lt;br /&gt;
pvremove /dev/md0&lt;br /&gt;
mdadm --stop /dev/md0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
…and your disk is free to be added to the new array. If the new raid is running in degraded mode (if you created it with just one drive), better don&#039;t wait too long, since you don&#039;t have redundancy. Just mdadm --add the devs.&lt;br /&gt;
&lt;br /&gt;
If you now have /dev/mdstat telling you your raid10 is active and have three drives, of which one is a spare, it should look something like this&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5] [raid4] [raid10]&lt;br /&gt;
md1 : active raid10 vdc[3](S) vdb[2] vdd[0]&lt;br /&gt;
      8380416 blocks super 1.2 2 near-copies [2/2] [UU]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Just mdadm --grow --raid-devices=3 /dev/md1&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;RAID section is not complete. I&#039;ll write more on migraing from raid10 to raid6 later. It&#039;s not straight forward, but easier than this one :)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== Thin provisioned LVs ===&lt;br /&gt;
&lt;br /&gt;
Thin provisioning on LVM is a method used for not allocating all the space given to an LV. For instance, if you have a 1TB VG and want to give an LV 500GB, although it currently only uses a fraction of that, a thin lv can be a good alternative. This will allow for adding a limit to how much it can use, but also to let it grow dynamically without manual work by the sysadmin. Thin provisioning adds another layer of abstaction by creating a special LV as a &#039;&#039;thin pool&#039;&#039; from which data is allocated to the &#039;&#039;thin volume(s)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== Create a thin pool ====&lt;br /&gt;
&lt;br /&gt;
Allocate 1TB to the thin pool to be used for thinly provisioned LVs. Keep in mind that the space allocated to the thin pool is in fact thick provisioned. Only the volumes put on &#039;&#039;thinpool&#039;&#039; are thin provisioned. This will create two hidden LVs, one for data and one for metadata. Normally the defaults will do, but check the manual if the data doesn&#039;t match the usual patterns (such as billions of files, resulting in huge amounts of metadata). I &#039;&#039;beleive&#039;&#039; the metadata part should be resizable at a later time if needed, but I have not tested it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a pool for thin LVs. Keep in mind that the pool itself is not thin provisioned, only the volumes residing on it&lt;br /&gt;
lvcreate --size 1T --type thin-pool --thinpool thinpool my_vg&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Create a thin volume ====&lt;br /&gt;
&lt;br /&gt;
You have the thinpool, now put a thin volume on it. It will allocate some space for metadata, but probably not much (a few megs, perhaps).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Now, create a volume with a virtual (-V) size of half a terabyte named thin_pool, but using the thinpool (-T) named thin_pool for storage&lt;br /&gt;
lvcreate -V 500G -T my_vg/thin_pool --name thinvol&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The new volume&#039;s device name will be /dev/thinvol. Now, create a filesystem on it, add to fstab and mount it. The &#039;&#039;&#039;df&#039;&#039;&#039; command will return available space according to the virtual size (-V), while lvs will show how much data is actually used on each of the thinly provisioned volumes.&lt;br /&gt;
&lt;br /&gt;
== Filesystem dilemmas ==&lt;br /&gt;
&lt;br /&gt;
=== XFS or ext4 or something else ===&lt;br /&gt;
The choice of filesystem varies for your use. Distros such as RHEL/CentOS has moved to XFS by default from v7. Debian/Ubuntu still sticks to ext4, like most other. I&#039;ll discuss my thoughts below on ext4 vs XFS and leave the other filesystems for later.&lt;br /&gt;
&lt;br /&gt;
==== ext4 ====&lt;br /&gt;
ext4 is probably the most used filesystem on linux as of writing. It&#039;s rock stable and has been extended by a lot of extensions since the original ext2. It still retains backward compatibility, being able to mount and fsck ext2 and ext3 with the ext4 driver. However, it doesn&#039;t handle large filesystems very well. If a filesystem is created for &amp;lt;16TiB, it cannot be grown to anything larger than 16TiB. This may have changed lately, though. One other issue is handling errors. If a large filesystem (say 10TiB) is damaged, an fsck may take several hours, leading to long downtime. When I refer to ext4 further in this text, the same applies to ext2 and ext3 unless otherwise specified.&lt;br /&gt;
&lt;br /&gt;
==== XFS ====&lt;br /&gt;
XFS, originally developed by SGI some time in the bronze age, but has been worked on heavily after that. RHEL and Centos version 7 and forward, uses XFS as the default filesystem. It is quick, it scales well, but it lacks at least two things ext4 has. It cannot be shrunk (not that you normally need that, but nice if you have a typo or you need to change things). Also, it doesn&#039;t allow for automatic fsck on bootup. If something is messed up on the filesystem, you&#039;ll have to login as root on the console (not ssh), which might be an issue on some systems. The fsck equivalent, xfs_repair, is a *lot* faster than ext4&#039;s fsck, though.&lt;br /&gt;
&lt;br /&gt;
==== ZFS ====&lt;br /&gt;
ZFS is like a combination of RAID, LVM and a filesystem, supporting full checksumming, auto-healing (given sufficient redundancy), compression, encryption, replication, deduplication (if you&#039;re brave and have a &#039;&#039;ton&#039;&#039; of memory) and a lot more. It&#039;s a separate chapter and needs a lot more talk than paragraph here.&lt;br /&gt;
&lt;br /&gt;
==== btrfs ====&lt;br /&gt;
btrfs, pronounced &amp;quot;butterfs&amp;quot; or &amp;quot;betterfs&amp;quot; or just spelled out, is a filesystem that mimics that of ZFS. It has been around for 10 years or so, but hasn&#039;t yet proven to be really stable. Following the progress of it for those years, I&#039;ve found it to be a nice toy with which to play, but not to be used in production. Again, others may say otherwise, but these are just my words.&lt;br /&gt;
&lt;br /&gt;
== Low level disk handling ==&lt;br /&gt;
&lt;br /&gt;
This section is for low-level handling of disks, regardless of storage system elsewhere. These apply to mdraid, lvmraid and zfs and possibly other solutions, with the exception of individual drives on hwraid (and maybe fakeraid), since there, the drives are hidden from Linux (or whatever OS).&lt;br /&gt;
&lt;br /&gt;
=== S.M.A.R.T. and slow drives ===&lt;br /&gt;
Modern (that is, from about 1990 or later) have S.M.A.R.T. (or just smart, since it&#039;s easier to type) monitoring built in, meaning the disk&#039;s controller is monitoring itself. This is handy and will ideally tell you in advance that a drive is flakey or dying. Modern (2010+) smart monitoring is more or less the same. It can be trusted about 50% of the time. Usually, if smart detects an error, it&#039;s a real error. I don&#039;t think I&#039;ve seen it reporting a false positive, but others may know better. &lt;br /&gt;
&lt;br /&gt;
==== smartmontools ====&lt;br /&gt;
First, install smartmontool and run smartclt -H /dev/yourdisk (/dev/sda or something) to get a health report. Then perhaps run smartctl -a /dev/yourdisk and look for &#039;current pending sectors&#039; This should be zero. Also check the temperature, which normally should be much above 50.&lt;br /&gt;
&lt;br /&gt;
==== single, slow drive ====&lt;br /&gt;
What may happen, is smart not seeing anything and life goes on like before, only slower and less prouductive, without telling anyone. If you stubler over this issue, you&#039;ll probably see it during a large rsync/zfs send/receive or a resync/rebuild/resilver of the raid/zpool. During this, it feels like everything is slow and your RAID has turned into a RAIF (redundant array of inexpensive floppies). To check if you have a single drive messing up it all, check with &#039;&#039;&#039;iostat -x 2&#039;&#039;&#039;, having 2 being the delay between each measurement. Interrupt it with ctrl+x. If there&#039;s a rougue drive there, it should stand out like sdg below&lt;br /&gt;
&lt;br /&gt;
 avg-cpu:  %user   %nice %system %iowait  %steal   %idle&lt;br /&gt;
            0.38    0.00    1.75    0.00    0.00   97.87&lt;br /&gt;
&lt;br /&gt;
 Device            r/s     w/s     rkB/s     wkB/s   rrqm/s   wrqm/s  %rrqm  %wrqm r_await w_await aqu-sz rareq-sz wareq-sz  svctm  %util&lt;br /&gt;
 sda              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdb              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdc              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdd              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sde              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdf              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdg              3.50    0.00   2352.00      0.00     0.00     0.00   0.00   0.00 14306.29    0.00  13.85   672.00     0.00 285.71 100.00&lt;br /&gt;
 sdh              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
&lt;br /&gt;
In ZFS land, you should be able to get similar data with &#039;&#039;&#039;zpool iostat -v &amp;lt;pool&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Now you know the bad drive (sdg), pull it from the raid with &#039;&#039;&#039;mdadm --fail /dev/mdX /dev/sdX&#039;&#039;&#039;. Now test the drive&#039;s performance manually, just simply:&lt;br /&gt;
&lt;br /&gt;
 # hdparm -t /dev/sdg&lt;br /&gt;
 &lt;br /&gt;
 /dev/sdg:&lt;br /&gt;
  Timing buffered disk reads:   2 MB in  5.37 seconds = 381.46 kB/sec&lt;br /&gt;
&lt;br /&gt;
Bingo - nothing you&#039;d want to keep. For a good drive, it should be something like 100-200MB/s&lt;br /&gt;
&lt;br /&gt;
PS: Keep in mind that you have a degraded RAID by now in case you had a spare waiting for things to happen.&lt;br /&gt;
&lt;br /&gt;
Try to replace the cable and/or try the disk on another port/controller. If the result from hdparm persists, it&#039;s probably a bad cable&lt;br /&gt;
&lt;br /&gt;
So, then, just psycially locate the drive, pull it out, take out the discs and magnets and recycle the rest.&lt;br /&gt;
&lt;br /&gt;
=== &amp;quot;Unplug&amp;quot; drive from system ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Find the device unit&#039;s number with something like&lt;br /&gt;
find /sys/bus/scsi/devices/*/block/ -name sdd&lt;br /&gt;
# returning /sys/bus/scsi/devices/3:0:0:0/block/sdd here, &lt;br /&gt;
# meaning 3:0:0:0 is the SCSI device we&#039;re looking for.&lt;br /&gt;
&lt;br /&gt;
# Given this is the correct device, and you want to &#039;unplug&#039; it, do so by&lt;br /&gt;
echo 1 &amp;gt; /sys/bus/scsi/devices/3:0:0:0/delete&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Rescan disk controllers ===&lt;br /&gt;
If a drive is added and for some reason doesn&#039;t get detected, or is removed by the command above, it can be rediscovered with a sysfs command to the scsi host to which it is connected. Since there may be quite a few of these, an easy way is to just scan them all and check the output of &#039;&#039;&#039;dmesg -T&#039;&#039;&#039; after running it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Make a list of controllers and send a rescan message to each of them. It won&#039;t do anything &lt;br /&gt;
# for those where nothing has changed, but it will show new drives where they have been added.&lt;br /&gt;
for host_scan in /sys/class/scsi_host/host*/scan&lt;br /&gt;
do&lt;br /&gt;
  echo &#039;- - -&#039; &amp;gt; $host_scan&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Fail injection with debugfs ===&lt;br /&gt;
[https://lxadm.com/Using_fault_injection https://lxadm.com/Using_fault_injection]&lt;br /&gt;
&lt;br /&gt;
== mdadm stuff ==&lt;br /&gt;
=== Resync ===&lt;br /&gt;
To resync a raid, that is, check, run&lt;br /&gt;
&lt;br /&gt;
 echo check &amp;gt; /sys/block/$dev/md/sync_action&lt;br /&gt;
&lt;br /&gt;
where $dev is something like md0. If you have several raids, something like this should work&lt;br /&gt;
&lt;br /&gt;
 for dev in md{0,1}&lt;br /&gt;
 do&lt;br /&gt;
   echo repair &amp;gt; /sys/block/$dev/md/sync_action&lt;br /&gt;
 done&lt;br /&gt;
&lt;br /&gt;
Also useful in a one-liner like&lt;br /&gt;
&lt;br /&gt;
 for dev in md{0,1} ; do echo repair &amp;gt; /sys/block/$dev/md/sync_action ; done&lt;br /&gt;
&lt;br /&gt;
Different raids on different drives will do this in parallel. If the drives are shared somehow with partitions or similar, the check or repair will wait for the other to finish before going on.&lt;br /&gt;
&lt;br /&gt;
As for repair vs check, [https://raid.wiki.kernel.org/index.php/RAID_Administration this article] describes it well. I stick to using repair unless it&#039;s something rare where I don&#039;t want to touch the data.&lt;br /&gt;
&lt;br /&gt;
=== Spare pools ===&lt;br /&gt;
In the old itmes, mdadm supported only a dedicated spare per md device, so if working with a large set of drives (20? 40?), where you&#039;d want to setup more raid sets to increase redundancy, you&#039;d dedicate a spare to each of the raid sets. This has changed (some time ago?), so in these modern, heathen days, you can change mdadm.conf, usually placed under /etc/mdadm, and add &#039;spare-group=somegroup&#039; where &#039;somegroup&#039; is a string identifying the spare group. After doing this, run &#039;&#039;&#039;update-initramfs -u&#039;&#039;&#039; and reboot and add a spare to one of the raid sets in the spare group, and md will use that or those spares for all the raidsets in that group.&lt;br /&gt;
&lt;br /&gt;
As some pointed out on #linux-raid @ irc.freenode.net, this feature is very badly documented, but as far as I can see, it works well.&lt;br /&gt;
&lt;br /&gt;
==== Example config ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create two raidsets&lt;br /&gt;
&lt;br /&gt;
mdadm --create /dev/md1 --level=6 --raid-devices=6 /dev/vd[efghij]&lt;br /&gt;
mdadm --create /dev/md2 --level=6 --raid-devices=6 /dev/vd[klmnop]&lt;br /&gt;
&lt;br /&gt;
# get their UUID etc&lt;br /&gt;
&lt;br /&gt;
mdadm --detail --scan&lt;br /&gt;
ARRAY /dev/md/1 metadata=1.2 name=raidtest:1 UUID=1a8cbdcb:f4092350:348b6b80:c054d74c&lt;br /&gt;
ARRAY /dev/md/2 metadata=1.2 name=raidtest:2 UUID=894b1b7c:cb7eba70:917d6033:ea5afd2b&lt;br /&gt;
&lt;br /&gt;
# Put those lines into /etc/mdadm/mdadm.conf and and add the spare-group&lt;br /&gt;
&lt;br /&gt;
ARRAY /dev/md/1 metadata=1.2 name=raidtest:1 spare-group=raidtest UUID=1a8cbdcb:f4092350:348b6b80:c054d74c&lt;br /&gt;
ARRAY /dev/md/2 metadata=1.2 name=raidtest:2 spare-group=raidtest UUID=894b1b7c:cb7eba70:917d6033:ea5afd2b&lt;br /&gt;
&lt;br /&gt;
# update the initramfs and reboot&lt;br /&gt;
&lt;br /&gt;
update-initramfs -u&lt;br /&gt;
reboot&lt;br /&gt;
&lt;br /&gt;
# add a spare drive to one of the raids&lt;br /&gt;
&lt;br /&gt;
mdadm --add /dev/md1 /dev/vdq&lt;br /&gt;
&lt;br /&gt;
# fail a drive on the other raid&lt;br /&gt;
&lt;br /&gt;
mdadm --fail /dev/md2 /dev/vdn&lt;br /&gt;
&lt;br /&gt;
# check /proc/mdstat to see md2 rebuilding with the spare from md1&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Recovery ===&lt;br /&gt;
&lt;br /&gt;
The other day, I came across a problem a user had on #linux-raid@irc.freenode.net. He had an old Qnap NAS that had died and tried plugging the drives in to his Linux machine and got various errors. The two-drive RAID-1 did not come up as it should, &#039;&#039;&#039;dmesg&#039;&#039;&#039; was full of errors from one of the drives (both connected on USB) and so forth.&lt;br /&gt;
&lt;br /&gt;
We went on and started by taking down the machine and just connecting one of the drives. I had him check what was assembled with&lt;br /&gt;
&lt;br /&gt;
 cat /proc/mdstat&lt;br /&gt;
&lt;br /&gt;
That returned /proc/md127 assembled, but LVM didn&#039;t find anything. So running a manual scan&lt;br /&gt;
&lt;br /&gt;
 pvscan --cache /dev/md127&lt;br /&gt;
&lt;br /&gt;
This made linux find the PV, VG and a couple of LVs, but probably because the mdraid was degraded, the LVs were deactivated, according to &#039;&#039;&#039;lvscan&#039;&#039;&#039;. Activating the one with a filesystem manually&lt;br /&gt;
&lt;br /&gt;
 lvchange -a y /dev/&amp;lt;vg&amp;gt;/&amp;lt;lv&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Substitute &amp;lt;vg&amp;gt; and &amp;lt;lv&amp;gt; with the names listed by vgs and lvs.&lt;br /&gt;
&lt;br /&gt;
This worked, and the filesystem on /dev/&amp;lt;vg&amp;gt;/&amp;lt;lv&amp;gt; could be mounted correctly.&lt;br /&gt;
&lt;br /&gt;
=== The badblock list ===&lt;br /&gt;
&#039;&#039;&#039;md&#039;&#039;&#039; has an internal badblock list (BBL), added around 2010, to list the bad blocks on the disk to avoid using those. While this might sound like a good idea, the badblock list is updated in case of a read error, which can be caused by several things. To make things worse, the BBL is replicated to other drives when a drive fails or the array is grown. So if you start out with sda and sdb and sdb suffers some errors, nothing wrong, md will read from sda, but flag those sectors on sdb as bad. So after a while, perhaps sda dies and gets replaced, with the same content, including the BBL. Then, at some point you might to replace sdb and it, too gets the BBL. So it sticks - forever. Also, there&#039;s no real point of keeping a BBL list, since the drive has its own and even if a sector error occurs, the array will have sufficient redundancy to recover from that (unless you use RAID-0 which you shouldn&#039;t). If a drive finds a bad sector, it&#039;ll be reallocated by the drive itself without the user&#039;s/admin&#039;s/system&#039;s knowledge. If a sector can&#039;t be reallocated, it means the drive is bad and should be replaced.&lt;br /&gt;
&lt;br /&gt;
There&#039;s no official way to remove it and although you can assemble it with the no-bbl option, this will only work if there&#039;s an empty BBL. Also, this will require downtime. As far as I can see, the only way to do this currently, is with a wee hack that should work. Just replace the names of mddev/diskdev with your own.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
mddev=&amp;quot;/dev/md0&amp;quot;&lt;br /&gt;
diskdev=&amp;quot;/dev/sda&amp;quot;&lt;br /&gt;
mdadm $mddev --fail $diskdev --remove $diskdev --re-add $diskdev --update=no-bbl&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If there&#039;s a BBL on the drive already, replace the --update part to &#039;force-no-bbl&#039;. This is not documented anywhere as per se, but it works.&lt;br /&gt;
 &lt;br /&gt;
I haven&#039;t found a way to turn this off permanently, but there may be something coming around when the debate on the linux-raid mailing list closes up on this. There&#039;s a bbl=no in mdadm.conf, but that&#039;s only for creation. I will continue extensive testing for this.&lt;br /&gt;
&lt;br /&gt;
== Tuning ==&lt;br /&gt;
&lt;br /&gt;
While trying to compare a 12-disk RAID (8TB disks) to a hwraid, mdraid was slower, so we did a few things to speed things up:&lt;br /&gt;
&lt;br /&gt;
While testing with [https://linux.die.net/man/1/fio fio], monitor /sys/block/md0/md/stripe_cache_active, and see if it&#039;s close to /sys/block/md0/md/stripe_cache_size. If it is, double the size of the latter&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
echo 4096 &amp;gt; /sys/block/md0/md/stripe_cache_size&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Continue until stripe_cache_active stabilises, and then you&#039;ve found the limit you&#039;ll need. You may want to double that for good measure. &lt;br /&gt;
&lt;br /&gt;
(to be continued)&lt;br /&gt;
&lt;br /&gt;
== Links ==&lt;br /&gt;
&lt;br /&gt;
Below are a few links with useful info&lt;br /&gt;
&lt;br /&gt;
* [https://raid.wiki.kernel.org/index.php/Irreversible_mdadm_failure_recovery Irreversible mdadm failure recovery]&lt;br /&gt;
&lt;br /&gt;
= ZFS =&lt;br /&gt;
&lt;br /&gt;
ZFS can do a lot of things most filesystems or volume managers can&#039;t. It checksums all data and metadata and so long that the system uses ECC enabled memory (RAM), it will have complete control over the whole data set, and when (not if) an error occurs, it&#039;ll fix the issue without even throwing a warning. To fix the issue, you&#039;ll obviously need sufficient redundancy (mirrors or RAIDzN). &lt;br /&gt;
&lt;br /&gt;
== ZFS send/receive between machines ==&lt;br /&gt;
&lt;br /&gt;
ZFS has a send/receive mechanism that allows for snapshots to be sent over the wire to a receiving end. This can be a full filesystem, or an incremental change since last send/reveive. In a WAN scenario, you&#039;ll probably want to use VPN for this. On a controlled network, sending in cleartext is also possible. You may as well use ssh, but keep in mind that ssh was never designed to be used as a fullblown vpn solution and is just too slow or the task with large amounts of data. You may, though, use mbuffer, if on a loal LAN.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Allow traffic from the sending IP in whatever firewall interface you&#039;re using (if you&#039;re using a firewall at all, that is)&lt;br /&gt;
ufw allow from x.x.x.x&lt;br /&gt;
# &lt;br /&gt;
# Start the receiver first. This listens on port 9090, has a 1GB buffer,&lt;br /&gt;
    and uses 128kb chunks (same as zfs):&lt;br /&gt;
&lt;br /&gt;
mbuffer -s 128k -m 1G -I 9090 | zfs receive data/filesystem&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To be continued one day… See [https://everycity.co.uk/alasdair/2010/07/using-mbuffer-to-speed-up-slow-zfs-send-zfs-receive/ this] for some more. I&#039;ll get back with details on it.&lt;br /&gt;
&lt;br /&gt;
= General Linux system control =&lt;br /&gt;
&lt;br /&gt;
== Add a new CPU (core) ==&lt;br /&gt;
&lt;br /&gt;
If working with virtual machines, adding a new core can be useful if the VM is slow and the load is multithreaded or multiprocess. To do this, add a new CPU in the hypervisor (be it KVM or VMware or Hyper-V or whatever). Some hypervisors, like VMware, will activate it automatically if open-vm-tools is installed. Please note that open-vm-tools is for VMware only. I don&#039;t know of any such thing for KVM or other hypervisors (although I beleive VirtualBox has its own set of tools, but not as a package). If this doesn&#039;t work, run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
echo 1 &amp;gt; /sys/devices/system/cpu/cpuX/online&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where X is the CPU number you want to add. You can &#039;cat /sys/devices/system/cpu/cpuX/online&#039; to check if it&#039;s online.&lt;br /&gt;
&lt;br /&gt;
= Mount partitions on a disk image =&lt;br /&gt;
&lt;br /&gt;
Sometimes you&#039;ll have a disk image, either from recovering a bad drive after hours (or days or weeks) of ddrescue, and sometimes you just have a disk image from a virtual machine where you want to mount the partitions inside the image. There are three main methods of doing this, which are more or less synonmous, but some easier than the other.&lt;br /&gt;
&lt;br /&gt;
== Basics ==&lt;br /&gt;
&lt;br /&gt;
A disk image is usually like a disk, consisting of either a large filesystem, a PV or a partition table with one or partitions onto which resides a filesystem, a pv, swap or something else. If it&#039;s partitioned, and you want your operating system to mount a filesystem or allow it to see whatever LVM stuff lies on it, you need to isolate the partitions. &lt;br /&gt;
&lt;br /&gt;
== Manual mapping ==&lt;br /&gt;
&lt;br /&gt;
In the oldern days, this was done manually, something like this&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
root@mymachine:~# fdisk -l /dev/vda&lt;br /&gt;
Disk /dev/vda: 25 GiB, 26843545600 bytes, 52428800 sectors&lt;br /&gt;
Units: sectors of 1 * 512 = 512 bytes&lt;br /&gt;
Sector size (logical/physical): 512 bytes / 512 bytes&lt;br /&gt;
I/O size (minimum/optimal): 512 bytes / 512 bytes&lt;br /&gt;
Disklabel type: dos&lt;br /&gt;
Disk identifier: 0xc37b7ea5&lt;br /&gt;
&lt;br /&gt;
Device     Boot    Start      End  Sectors  Size Id Type&lt;br /&gt;
/dev/vda1  *        2048 50333311 50331264   24G 83 Linux&lt;br /&gt;
/dev/vda2       50333312 52426369  2093058 1022M  5 Extended&lt;br /&gt;
/dev/vda5       50333314 52426369  2093056 1022M 82 Linux swap / Solaris&lt;br /&gt;
root@mymachine:~#&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To calculate the start and end of each partition, you just take the start sector and multiply it by the sector size (512 bytes here) and you have the offset in bytes. After this, it&#039;s merely an losetup -o &amp;lt;offset&amp;gt; /dev/loopX &amp;lt;nameofimagefile&amp;gt; and you have the partition mapped to your /dev/loopX (having X being something typically 0-255. After this, just mount it or run pvscan/vgscan/lvscan to probe whatever lvm config is there, and you should be able to mount it like any other filesystem.&lt;br /&gt;
&lt;br /&gt;
== kpartx ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;kpartx&#039;&#039;&#039; does the same as above, more or less, just without so much hassle. Most of it should be automatic and easy to deal with, except it may fail to disconnect the loopback devices sometimes, so you may have to &#039;&#039;&#039;losetup -d&#039;&#039;&#039; them manually. See the manual, &#039;&#039;&#039;kpartx (8)&#039;&#039;&#039;. Please note that &#039;&#039;&#039;partx&#039;&#039;&#039; works similarly and I&#039;d guess the authors of the two tools are arguing a lot of which one&#039;s the best.&lt;br /&gt;
&lt;br /&gt;
== guestmount ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;guestmount&#039;&#039;&#039; is something similar again, but also supports file formats like &#039;&#039;&#039;qcow2&#039;&#039;&#039; and possibly other, proprietary filesystems like &#039;&#039;&#039;vmdk&#039;&#039;&#039; and &#039;&#039;&#039;vdi&#039;&#039;&#039;, but don&#039;t take my word for it - I haven&#039;t tested. Again, see the manual or just read up on the description [http://ask.xmodulo.com/mount-qcow2-disk-image-linux.html?fbclid=IwAR3snTeZvGzp9PLdX11EQhCfOpux6I93CiJ3A2pUomkkRLly9Xo4851mkTY here]. It seems rather trivial.&lt;br /&gt;
&lt;br /&gt;
= Linux on laptops =&lt;br /&gt;
&lt;br /&gt;
== Wifi with HP EliteBook 725/745 on Ubuntu ==&lt;br /&gt;
&lt;br /&gt;
The HP EliteBook 725/745 and similar are equipped with a BCM4352 wifi chip. As with a lot of other stuff from Broadcom, this lacks an open hardware description, so thus no open driver exist. The proper fix, is to replace the NIC with something with an open driver, but again, this isn&#039;t always possible, so a binary driver exists. In ubuntu, run, somehow connect the machine to the internet and run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install bcmwl-kernel-source&lt;br /&gt;
sudo modprobe wl&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you can&#039;t connect the machine to the internet, download the needed packages on another machine and put it on some usb storage. These packages should suffice:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# apt-cache depends bcmwl-kernel-source&lt;br /&gt;
bcmwl-kernel-source&lt;br /&gt;
  Depends: dkms&lt;br /&gt;
  Depends: linux-libc-dev&lt;br /&gt;
  Depends: libc6-dev&lt;br /&gt;
  Conflicts: &amp;lt;bcmwl-modaliases&amp;gt;&lt;br /&gt;
  Replaces: &amp;lt;bcmwl-modaliases&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then install manually with &#039;&#039;&#039;dpkg -i file1.deb file2.deb&#039;&#039;&#039; etc&lt;br /&gt;
&lt;br /&gt;
After this, ip/ifconfig/iwconfig shouldd see the new wifi nic, probably &#039;&#039;&#039;wlan0&#039;&#039;&#039;, but due to a [https://bugs.launchpad.net/ubuntu/+source/broadcom-sta/+bug/1343151 old, ignored bug], you won&#039;t find any wifi networks. This is because the driver from Broadcom apparently does not support interrupt remapping, commonly used on x64 machines. To turn this off, change &#039;&#039;&#039;/etc/default/grub&#039;&#039;&#039; and change the line &#039;&#039;&#039;GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;quiet splash&amp;quot;&#039;&#039;&#039;, adding intremap=off to the end before the quote: &#039;&#039;&#039;GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;quiet splash intremap=off&amp;quot;&#039;&#039;&#039;. Save the file and run &#039;&#039;&#039;sudo update-grub&#039;&#039;&#039; and reboot. After this, wifi should work well.&lt;br /&gt;
&lt;br /&gt;
== Wifi with HP Compaq Presario CQ57 on Ubuntu ==&lt;br /&gt;
&lt;br /&gt;
The HP Compaq Presario CQ57 uses the RT5390 wifi chipset. This has been supported for quite some time now, and I was quite surprised to find it not working on a laptop a friend was having. The driver loaded correctly, but Ubuntu insisted of the laptop being in &#039;&#039;&#039;flight mode&#039;&#039;&#039;. Checking &#039;&#039;&#039;rfkill&#039;&#039;&#039;, it showed me two NICs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# rfkill list all&lt;br /&gt;
0: phy0: Wireless LAN&lt;br /&gt;
	Soft blocked: no&lt;br /&gt;
	Hard blocked: yes&lt;br /&gt;
1: hp-wifi: Wireless LAN&lt;br /&gt;
	Soft blocked: yes&lt;br /&gt;
	Hard blocked: no&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Turning rfkill on and off resulted in nothing much, except some error messages in the kernel log (dmesg)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] ACPI Error: Field [B128] at bit offset/length 128/1024 exceeds size of target Buffer (160 bits) (20170831/dsopcode-235)&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]&lt;br /&gt;
                            Initialized Local Variables for Method [HWCD]:&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Local0: 00000000a34b7928 &amp;lt;Obj&amp;gt;           Integer 0000000000000000&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Local1: 00000000b0aa6865 &amp;lt;Obj&amp;gt;           Buffer(8) 46 41 49 4C 04 00 00 00&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Local5: 00000000a9811efd &amp;lt;Obj&amp;gt;           Integer 0000000000000004&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] Initialized Arguments for Method [HWCD]:  (2 arguments defined for method invocation)&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Arg0:   0000000078957d1b &amp;lt;Obj&amp;gt;           Integer 0000000000000001&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Arg1:   00000000725c9c6e &amp;lt;Obj&amp;gt;           Buffer(20) 53 45 43 55 02 00 00 00&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] ACPI Error: Method parse/execution failed \_SB.WMID.HWCD, AE_AML_BUFFER_LIMIT (20170831/psparse-550)&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] ACPI Error: Method parse/execution failed \_SB.WMID.WMAD, AE_AML_BUFFER_LIMIT (20170831/psparse-550)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After upgrading BIOS and testing different kernels, I was asked to try to unload the &#039;&#039;&#039;hp_wmi&#039;&#039;&#039; driver. I did, and things changed a bit, so I tried blacklisting it, creating the file &#039;&#039;&#039;/etc/modprobe.d/blacklist-hp_wmi.conf&#039;&#039;&#039; with the following content&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Blacklist this - it doesn&#039;t work!&lt;br /&gt;
blacklist hp_wmi&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
I gave the machine a reboot and afte that, the &#039;&#039;&#039;hp-wifi&#039;&#039;&#039; entry was gone in the rfkill output, and things works.&lt;br /&gt;
&lt;br /&gt;
= Raspberry pi =&lt;br /&gt;
&lt;br /&gt;
I couldn&#039;t quite decide if the raspberry pi should be a separate section or part of Linux, but hell, it can run more than Linux, although 99,lots% of people just uses Linux on them. This is a small list of things to know about them; things not on the front page of the manual or perhaps hidden even better.&lt;br /&gt;
&lt;br /&gt;
== Which pi? ==&lt;br /&gt;
&lt;br /&gt;
I just setup three raspberry pi machines and although some are quite different, like v1 to vEverythingelse or the Pi zero versions to the normal ones, not all of us remember how to distinguish between them, and sometimes they&#039;re in a nice 3d printed (or otherwise) chassis or otherwise hidden. So, how to check three different ones:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
root@home-assistant:~ $ cat /proc/device-tree/model ; echo&lt;br /&gt;
Raspberry Pi 2 Model B Rev 1.1&lt;br /&gt;
&lt;br /&gt;
root@green-pi:~ $ cat /proc/device-tree/model ; echo&lt;br /&gt;
Raspberry Pi 3 Model B Rev 1.2&lt;br /&gt;
&lt;br /&gt;
roy@yellow-pi:~ $cat /proc/device-tree/model ; echo&lt;br /&gt;
Raspberry Pi 4 Model B Rev 1.1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
While this works well, for the latter, the pi4, it doesn&#039;t tell how much memory I have. It comes in variants of 1, 2 and 4GB, and this is the latter.&lt;br /&gt;
&lt;br /&gt;
For a more detailed list, the command &#039;&#039;&#039;awk &#039;/^Revision/ {sub(&amp;quot;^1000&amp;quot;, &amp;quot;&amp;quot;, $3); print $3}&#039; /proc/cpuinfo&#039;&#039;&#039; will give you a revision number, detailing the type of pi, who produced it etc. Please see [https://elinux.org/RPi_HardwareHistory] for a full table.&lt;br /&gt;
&lt;br /&gt;
== Monitoring ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;vcgencmd&#039;&#039;&#039; from &#039;&#039;&#039;/opt/vc/bin&#039;&#039;&#039;, but symlinked to &#039;&#039;&#039;/usr/bin&#039;&#039;&#039; so it&#039;s available in path, is useful for fetching hardware info about the pi. For example, measuring the temperature&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
root@yellow-pi:~# vcgencmd measure_temp&lt;br /&gt;
temp=63.0&#039;C&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The command is generally badly documented and parts of it seems outdated for newer hardware. Here&#039;s the output from a Raspberry pi 4 with 4GB RAM&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
roy@yellow-pi:~ $ vcgencmd get_mem arm&lt;br /&gt;
arm=948M&lt;br /&gt;
roy@yellow-pi:~ $ vcgencmd get_mem gpu&lt;br /&gt;
gpu=76M&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= BIOS upgrade from Linux =&lt;br /&gt;
&lt;br /&gt;
Generally, BIOS upgrades have been moved to the BIOS itself these days. This saves a lot of work and quite possibly lives after those who earier rammed their heads through walls, now can upgrade directly from the internet instead of using obscure operating systems best avoided. Sometimes, however, one must use these nevertheless. This is a quick run-through on your options.&lt;br /&gt;
&lt;br /&gt;
== DOS ==&lt;br /&gt;
&lt;br /&gt;
Most non-automatic BIOS upgrades are installed from DOS. Doing a BIOS upgrade this way, is generally non-problematic. Just install a USB thingie with [https://www.freedos.org/ FreeDOS], copy your file(s) onto the thing and boot on it. The commandline is the same as old MS/DOS, except a wee bit more userfriendly, but not a lot.&lt;br /&gt;
&lt;br /&gt;
== Windows ==&lt;br /&gt;
&lt;br /&gt;
Some macahines, like laptops from &#039;&#039;&#039;HP&#039;&#039;&#039;, may have BIOS upgrades that are made to be installed from Windows and won&#039;t run in FreeDOS or MS/DOS, instead throwing an error, saying &#039;&#039;&#039;This program cannot be run in DOS mode&#039;&#039;&#039;. This means you&#039;ll have to boot on a Windows rescue disc and do the job from there. Googling this, tells you it&#039;s quite easy, you just choose &#039;make rescue disc&#039; from Windows, and it&#039;s all good, except if you don&#039;t run Windows, that is. To remedy this problem, do as follows:&lt;br /&gt;
&lt;br /&gt;
=== Download Windows ===&lt;br /&gt;
&lt;br /&gt;
Since you don&#039;t run Windows and possibly don&#039;t have a spouse or friend around with such unhealthy habits either, you need to get it. It&#039;s quite easy - just google &#039;download windows&#039; and it&#039;ll send you to [https://www.microsoft.com/en-us/software-download/windows10ISO somewhere like this].&lt;br /&gt;
&lt;br /&gt;
=== Burn it! ===&lt;br /&gt;
&lt;br /&gt;
Now it&#039;s time to burn the installer on a DVD ROM. You&#039;ll need a double-layered one, since the OS is &amp;gt; 4.7GiB, but I&#039;m sure you have a ton of those lying around. Now, just place your optical medium in your optical drive and burn, baby, burn!&lt;br /&gt;
&lt;br /&gt;
=== Or make a USB thing? ===&lt;br /&gt;
&lt;br /&gt;
Not a lot of machines have optical drives these days, so you may want to use an USB pen drive or something instead. This is easy, just make the USB bootable with the Windows application Microsoft has made for this. Unfortunately, this only runs on Windows, and unlike stuff like Debian, where the &#039;&#039;&#039;iso&#039;&#039;&#039; file can be dd&#039;ed directly onto a USB drive to make it bootable, the Windows &#039;&#039;&#039;iso&#039;&#039;&#039;s don&#039;t come with this luxury. There are lots of methods to make bootable USB things from iso files out there, but the only thing most of them have in common, is that they generally don&#039;t work.&lt;br /&gt;
&lt;br /&gt;
==== WoeUSB ====&lt;br /&gt;
&lt;br /&gt;
After hours of swearing, it&#039;s nice to come across software like [https://github.com/slacka/WoeUSB WoeUSB]. It may not be perfect, it relies on a bunch of GUI stuff you&#039;ll never need and so on, but it &#039;&#039;&#039;&#039;&#039;works&#039;&#039;&#039;&#039;&#039;, and that&#039;s the important part! Just clone the repo and RTFM and it&#039;s all nice. It&#039;s slow, but hell, getting a windows machine and/or an optical drive might be slower.&lt;br /&gt;
&lt;br /&gt;
WoeUSB does nothing fancy, but it &#039;&#039;&#039;does&#039;&#039;&#039; work. It will create a filesystem, FAT32 or NTFS (better use NTFS, FAT32 has its limits). It creates normal filesystems and so on. Just make sure to copy in the BIOS update file, usually an exe file, to run when Windows is up and running.&lt;br /&gt;
&lt;br /&gt;
==== Install BIOS ====&lt;br /&gt;
&lt;br /&gt;
Boot on the Windows USB thing and choose &#039;repair computer&#039; and then &#039;command prompt&#039;. Find the install file, and if you&#039;re lucky, you&#039;ll find it needs a 32bit OS, just like I did. Since the 64bit version doesn&#039;t include 32bit compatibility in the installer, revert to downloading the 32bit version of windows and start over. Pray to your favourite god(s) not to get across such machines again - it might help.&lt;br /&gt;
&lt;br /&gt;
= 3D printer stuff =&lt;br /&gt;
&lt;br /&gt;
Below are a number of not very ordered paragraphs about 3D printer related stuff, mostly based on my experience. Their content may be interesting or perhaps practical knowledge, but then, that depends on the reader.&lt;br /&gt;
&lt;br /&gt;
== 3D printer related introductions on youtube or elsewhere ==&lt;br /&gt;
&lt;br /&gt;
First off, I&#039;d like to mention some youtube videos that are all (or mostly) a nice start if you&#039;re new to 3D printers.&lt;br /&gt;
&lt;br /&gt;
=== [https://www.youtube.com/watch?v=nb-Bzf4nQdE&amp;amp;list=PLDJMid0lOOYnkcFhz6rfQ6Uj8x7meNJJx Thomas Salanderer&#039;s 10-video series on 3D printing basics] ===&lt;br /&gt;
&lt;br /&gt;
Thomas Salanderer is a an experienced 3D printer user/admin/fixer/etc and he has a lot of interesting videos. Some accuse him for being a [Prusa https://www.prusa3d.com/] fanboy, which he quite obviously is, but that doesn&#039;t stop him from making interesting and somewhat neutral videos. The series walks you thought the first steps of how things work and so on and hopefully opens more doors than anything else I&#039;ve seen.&lt;br /&gt;
&lt;br /&gt;
=== [https://www.youtube.com/watch?v=rp3r921DBGI Teaching Tech&#039;s &amp;quot;3D printer tuning reborn&amp;quot;] ===&lt;br /&gt;
&lt;br /&gt;
Teaching Tech is, like Salanderer or even more, good pedagogically and explains a lot. They (or he) do a bunch of testing and describing pros and cons with different things, just like other youtubers in the sme business. The mentioned video shows how to tune a 3D printer after you have first learned the basics, and leans on a webpage made to help you out without too much manual work.&lt;br /&gt;
&lt;br /&gt;
This was a short list, but I guess it&#039;ll grow over time.&lt;br /&gt;
&lt;br /&gt;
== Hydrophilic filament ==&lt;br /&gt;
&lt;br /&gt;
Most popular filament types, including PLA, PETG, PP or PA (Polyamide, normally known as Nylon) and virtualy any filament type named [https://www.matterhackers.com/news/filament-and-water poly-something] (and thus with an acronym of P-something) are hydrophilic (also (somewhat incorrectly) called hydroscopic), meaning so long they&#039;re dryer than the atmosphere around them, they&#039;ll do their best to suck out the atmosphere&#039;s humidity. This is why most filament are shrink-wrapped with a small bag of silica gel in it. If such filament is exposed for normal humid air for some time, it&#039;ll become very hard to use. Most of my experience is with PLA, which can handle a bit (depending on make), but still not a lot. With PLA, if you end up with prints where the filament seems not to stick, it may help with a higher temperature. Otherwise, the filament must be [https://all3dp.com/2/how-to-dry-filament-pla-abs-and-nylon/ baked]. If you don&#039;t want to use your oven, try something like a [https://www.jula.no/catalog/hjem-og-husholdning/kjokkenmaskiner/mattilberedningsapparater/frukt-sopptorker/frukt-sopptorker-001641/#tab02 fruit and mushroom dryer]. Then get a good, sealble plastic box and add something like half a kilogram of [https://www.ebay.com/sch/sis.html?_nkw=1KG+Orange+Replacement+Desiccant+Indicating+Silica+Gel+Beads+for+Drawers%2C+Camera&amp;amp;_id=131938742628&amp;amp;&amp;amp;_trksid=p2057872.m2749.l2658 silica gel] to an old sock, tie it and put it in the your new dry box.&lt;br /&gt;
&lt;br /&gt;
Please note that ABS is hydrophobic, so you won&#039;t have to worry too much there. Also, remember that PA/Nylon is extremely hydrophilic. Even a couple of days in normal air humidity can ruin it completely and will require baking.&lt;br /&gt;
&lt;br /&gt;
== Upgrading the firmware on an Ender 3 ==&lt;br /&gt;
&lt;br /&gt;
This is about upgrading the firmware, and thus also flashing a bootloader to the Creality Ender 3 3D printer. Most of this is well documented on several place, like o [https://www.youtube.com/watch?v=fIl5X2ffdyo the video from Teaching tech] and elsewhere, but I&#039;ll just summarise some issues I had.&lt;br /&gt;
&lt;br /&gt;
=== Using an arduino Nano as a programmer ===&lt;br /&gt;
&lt;br /&gt;
Quick note before you read on. If you have an Ender 3 controller version 1.1.5 or newer (or perhaps even a bit older), a CR-10S or some other more or less modern printers or controllers, they come with a bootloader installed already, so don&#039;t bother flashing one. The one that&#039;s in there already, should work well. So if you have one of these, just skip this and jump to the [[Roy&#039;s_notes#Flashing_the_printer|next section]].&lt;br /&gt;
&lt;br /&gt;
However, the normal CR-10 (without the S), Ender 3 and a few other printers from Creality come without a bootloader, so you&#039;ll need to flash one before upgrading the firmware. Well, strictly speakning, you don&#039;t need one, you can save those 8kB or so for other stuff and use a programmer to write the whole firmware, but then you&#039;ll need to wire up everything every time you want a new firmware, so in my world, you &#039;&#039;&#039;do&#039;&#039;&#039; need the bootloader, since it&#039;s easier.&lt;br /&gt;
&lt;br /&gt;
To install a bootloader, you&#039;ll need a programmer, and I didn&#039;t have one available. Having some el-cheapo china-copies of Arduinos around, I read I could use one and tried so. Although the docs mostly mention the Uno etc, it&#039;s just as simple with the Nano copy.&lt;br /&gt;
&lt;br /&gt;
So, grab an arduino, plug it to your machine with a USB cable, and, using the Arduino IDE, use the ArduinoISP sketch there (found under Examples) to burn the software needed for the arduino to work as a programmer. When this is done, connect a 10µF capacitor between RST and GND to stop it from resetting when used as a programmer. Connect the MOSI, MISO and SCK pins from the ICSP block (that little isolated 6-pin block on top of the ardu). See [https://www.arduino.cc/en/Tutorial/ArduinoISP here] for a pinout. Then find Vcc and GND either on the ICSP block or elsewhere. Some sites say that on some boards you shouldn&#039;t use the pins on the ICSP block for this. I doubt it matters, though. Then connect another jumper wire from pin 10 on the ardu to work as the reset pin outwards to the chip being programmed (that is, on the printer). The ICSP jumper block pin layout is the same on the printer and on the ardu, and probably elsewhere. Sometimes [https://xkcd.com/927/ standardisation] actually works…&lt;br /&gt;
&lt;br /&gt;
See https://cloud.karlsbakk.net/index.php/s/zw48YJjzaf8Rc2F for a pic with the ardu (this wiki is broken atm, will fix it later)&lt;br /&gt;
&lt;br /&gt;
== Flashing the printer ==&lt;br /&gt;
&lt;br /&gt;
When the boot loader is in place, possibly after some wierd errors from during the process, the screen on the 3d printer will go blank and it&#039;ll behave like being bricked. This is ok. Now disconnect the wires and connect the USB cable between computer and printer. If you haven&#039;t installed support for the Sanguino board, that is, the variant of the 1284-chip and surrounding electronics that is the core of the, you need to install it first. In the Arduino IDE, choose the Tools / Boards / Boards manager boot option and search for Sanguino. After this, you should find the Sanguino or Sanguino 1284p in the boards menu. After this, you should be able to communicate with the printer&#039;s controller. Download the [https://www.th3dstudio.com/knowledgebase/th3d-unified-firmware-package/ TH3D unified firmware], making sure it&#039;s the last version. Uncompress the zip and with Finder/Explorer/whateversomething&#039;scalledonlinux, browse to &#039;&#039;&#039;TH3DUF_R2/Firmware/TH3DUF_R2.ino&#039;&#039;&#039; and open it. It should open directly in the Android IDE. Keep in mind that the names TH3DUF_R2 and TH3DUF_R2.ino will vary between versions, but you get the point. Now configure it for your particular needs. You&#039;ll find most of this in the Configuration.h tab (that&#039;s really a file). Most of the other files won&#039;t be necessary unless you&#039;re doing some more advanced stuff, like replacing th controller with something non-standard or similar, but then again, that&#039;s another chapter (or book, even). The video mentioned above describes this well. After flashing the new firmware, you&#039;ll probably get some timeouts and errors, since apparently it resets the printer after giving it the new firmware, but without notifying the flashing software of it doing so. If this happens, calm down and reboot the printer and check its tiny monitor - it should work. If it doesn&#039;t work, and if you flashed the bootload yourself, try to flash it again, and if that doesn&#039;t work, try flashing the programmer again yet another time, just for kicks. Again, if you have a newer controller like the v1.1.5, don&#039;t touch the bootloader, as the one already installed, should work well as it is.&lt;br /&gt;
&lt;br /&gt;
PS: I tried enabling &#039;&#039;&#039;MANUAL_MESH_LEVELING&#039;&#039;&#039;, which in the code says that &#039;&#039;If used with a 1284P board the bootscreen will be disabled to save space&#039;&#039;. This effectively disabled the whole printer, and apparently may be making the firmware image a wee bit too large for it to fit the 1284P on the ender. It works well without it, though, and it may be fixed by now, since I tested this back in early 2019.&lt;br /&gt;
&lt;br /&gt;
== And then… ==&lt;br /&gt;
&lt;br /&gt;
With the new firmware in place, the printer should work as before, although with thermal runaway protection to better avoid fires in case the shit hits the fan, and to allow for things like autolevelling. With any luck, [https://www.precisionpiezo.co.uk/ this thing] may be ready for use by the time you read this - it surely looks nice!&lt;br /&gt;
&lt;br /&gt;
= Octoprint/Octopi =&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;This could have been under some other section, but again, I just branch out even though most of it is about sections mentioned elsewhere.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
When setting up a 3d printer for the first time, you usually get an SD card for storage and transfer data to the printer using [https://en.wikipedia.org/wiki/Sneakernet Sneakernet]. Some printers use micro SD cards, while other fullsize SD cards, which imho is better, since they don&#039;t get lost that easily, but otherwise do the same thing. This works, but is somewhat tedious. If you want to control the printer from a PC or phone, there&#039;s a simple trick for that as well - octoprint.&lt;br /&gt;
&lt;br /&gt;
[https://octoprint.org/ Octoprint], written by Gina Häußge, runs on most platforms including linux, windows, BSD*, macos etc. It supports controlling a camera to some extent out of the box and there&#039;s a large number of plugins availablee to do a lot of things you possibly haven&#039;t thought of (and quite often, you&#039;d ever need). The easiest way to install it, is to just grab a Raspberry pi - preferably some of the newer models (will get to that later) and download [https://octoprint.org/download/ octopi] and follow the instructions on that page.&lt;br /&gt;
&lt;br /&gt;
== Performance issues ==&lt;br /&gt;
&lt;br /&gt;
Some report (and I have seen it myself) issues with the pi&#039;s performance with regards to both handling the octoprint processes (which should be as close to realtime as possible) and handling other stuff like I/O, networking etc. The point is that at pi3 or older, has all peripherals connected to an internal USB hub. This might be practical, but performance-wise it&#039;s &#039;&#039;&#039;&#039;&#039;not&#039;&#039;&#039;&#039;&#039;. If you in addition connect a webcam to USB, you&#039;re asking for trouble, since USB will be your bottleneck. With a raspberry pi camera, the ones connected to the pi directly with a ribbon cable, this should not use USB, so it&#039;s better. Still, again, for older pi&#039;s, there might be some shortage in therms of cpu or i/o. The octopi runs something like raspbian which is a fork of debian which is a linux distro, so it all boils down to knowing linux.&lt;br /&gt;
&lt;br /&gt;
Your typical octopi will run octoprint, a streamer, usually &#039;&#039;&#039;mjpg-streamer&#039;&#039;&#039;, a simple, lightweight videostreamer that outputs a stream of jpeg-images (about the same format as cinemas use - that is - not MPEG). This may be a bit tough on the cpu and potentially i/o. Add inn a dash of USB overload and you&#039;re may see trouble.&lt;br /&gt;
&lt;br /&gt;
Still - a pi3 should be able to handle the load, but it might help to prioritise corretly. The octoprint process is the important part here, so we could give that full priority both in CPU and I/O and. Unfortunately, it doesn&#039;t seem like the current octopi has been migrated to using systemd for the startup. We&#039;ll deal with this later. To fix this in the old SysV init style file present there, the following patch should work against the file /etc/init.d/octoprint&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;diff&amp;quot;&amp;gt;&lt;br /&gt;
--- octoprint.old	2020-07-20 18:46:10.166651965 +0200&lt;br /&gt;
+++ octoprint	2020-07-20 18:53:21.724803211 +0200&lt;br /&gt;
@@ -22,6 +22,9 @@&lt;br /&gt;
 PIDFILE=/var/run/$NAME.pid&lt;br /&gt;
 PKGNAME=octoprint&lt;br /&gt;
 SCRIPTNAME=/etc/init.d/$PKGNAME&lt;br /&gt;
+NICELEVEL=-19                        # Top CPU priority&lt;br /&gt;
+IONICE_CLASS=1                       # Realtime I/O class&lt;br /&gt;
+IONICE_PRIORITY=0                    # Realtime I/O priority (probably not needed with class=realtime)&lt;br /&gt;
&lt;br /&gt;
 # Read configuration variable file if it is present&lt;br /&gt;
 [ -r /etc/default/$PKGNAME ] &amp;amp;&amp;amp; . /etc/default/$PKGNAME&lt;br /&gt;
@@ -70,10 +73,11 @@&lt;br /&gt;
&lt;br /&gt;
    is_alive $PIDFILE&lt;br /&gt;
    RETVAL=&amp;quot;$?&amp;quot;&lt;br /&gt;
-&lt;br /&gt;
    if [ $RETVAL != 0 ]; then&lt;br /&gt;
        start-stop-daemon --start --background --quiet --pidfile $PIDFILE --make-pidfile \&lt;br /&gt;
-       --exec $DAEMON --chuid $OCTOPRINT_USER --user $OCTOPRINT_USER --umask $UMASK -- serve $DAEMON_ARGS&lt;br /&gt;
+       --exec $DAEMON --chuid $OCTOPRINT_USER --user $OCTOPRINT_USER --umask $UMASK \&lt;br /&gt;
+       --nicelevel $NICELEVEL --ioched $IONICE_CLASS:$IONICE_PRIORITY \&lt;br /&gt;
+       --serve $DAEMON_ARGS&lt;br /&gt;
        RETVAL=&amp;quot;$?&amp;quot;&lt;br /&gt;
    fi&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This ismply upgrades the process to be allowed to use most of the resources on the pi, regardless of what other processes are whining about.&lt;br /&gt;
&lt;br /&gt;
PS: Code not tested - I don&#039;t have a pi right here. Will test later, but I&#039;m pretty sure it&#039;ll work. After all, it&#039;s just a few new arguments to start-stop-daemon&lt;br /&gt;
&lt;br /&gt;
roy&lt;/div&gt;</summary>
		<author><name>Roy</name></author>
	</entry>
	<entry>
		<id>https://wiki.malinux.no/index.php?title=Roy%27s_notes&amp;diff=175</id>
		<title>Roy&#039;s notes</title>
		<link rel="alternate" type="text/html" href="https://wiki.malinux.no/index.php?title=Roy%27s_notes&amp;diff=175"/>
		<updated>2020-09-18T19:40:11Z</updated>

		<summary type="html">&lt;p&gt;Roy: /* The badblock list */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= LVM, md and friends =&lt;br /&gt;
&lt;br /&gt;
== Linux&#039; Logical Volume Manager (LVM) ==&lt;br /&gt;
&lt;br /&gt;
=== LVM in general ===&lt;br /&gt;
&lt;br /&gt;
LVM is designed to be an abstraction layer on top of physical drives or RAID, typically [https://raid.wiki.kernel.org/index.php/RAID_setup mdraid] or [https://help.ubuntu.com/community/FakeRaidHowto fakeraid]. Keep in mind that fakeraid should be avoided unless you really need it, like in conjunction with dual-booting linux and windows on fakeraid. LVM broadly consists of three elements, the &amp;quot;physical&amp;quot; devices (PV), the volume group (VG) and the logical volume (LV). There can be multiple PVs, VGs and LVs, depending on requirement. More about this below. All commands are given as examples, and all of them can be fine-tuned using extra flags in need of so. In my experience, the defaults work well for most usecases.&lt;br /&gt;
&lt;br /&gt;
I&#039;m mentioning filesystem below too. Where I write ext4, the samme applies to ext2 and ext3.&lt;br /&gt;
&lt;br /&gt;
==== Create a PV ====&lt;br /&gt;
&lt;br /&gt;
A PV is the &amp;quot;physical&amp;quot; parts. This does not need to be a physical disk, but can also be another RAID, be it an mdraid, fakeraid, hardware raid, a virtual disk on a SAN or otherwisee or a partition on one of those. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#  These add three PVs, one on a drive (or hardware raid) and another two on mdraids.&lt;br /&gt;
pvcreate /dev/sdb&lt;br /&gt;
pvcreate /dev/md1 /dev/md2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For more information about pvcreate, see [https://linux.die.net/man/8/pvcreate the manual].&lt;br /&gt;
&lt;br /&gt;
==== Create a VG ====&lt;br /&gt;
&lt;br /&gt;
The volume group consists of one or more PVs grouped together on which LVs can be placed. If several PVs are grouped in a VG, it&#039;s generally a good idea to make sure these PVs have some sort of redundancy, as in mdraid/fakeraid or hwraid. Otherwise it will be like using a [https://en.wikipedia.org/wiki/RAID RAID-0] with a single point of failure on each of the independant drives. LVM has [https://unix.stackexchange.com/questions/150644/raiding-with-lvm-vs-mdraid-pros-and-cons  RAID code in it] as well, so you can use that. I haven&#039;t done so myself, as I generally stick to mraid. The reason is mdraid is, in my opinion older and more stable and has more users (meaning bugs are reported and fixed faster whenever they are found). That said, I beleive the actual RAID code used in LVM RAID are the same function calls as for mdraid, so it may not be much of a difference. I still stick with mdraid. To create a VG, run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create volume group my_vg&lt;br /&gt;
vgcreate my_vg /dev/md1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that if vgcreate is run with a PV (as /dev/md1 above) that is not defined as a PV (like above), this is done implicitly, so if you don&#039;t need any special flags to pvcreate, you can simply skip it and let vgcreate do that for you.&lt;br /&gt;
&lt;br /&gt;
==== Create an LV ====&lt;br /&gt;
&lt;br /&gt;
LVs can be compared to partitions, somehow, since they are bounderies of a fraction or all of that of a VG. The difference between them and a partition, however, is that they can be grown or shrunk easily and also moved around between PVs without downtime. This flexibility makes them superiour to partitions as your system can be changed without users noticing it. By default, an LV is alloated &amp;quot;thickly&amp;quot;, meaning all the data given to it, is allocated from the VG and thus the PV. The following makes a 100GB LV named &amp;quot;thicklv&amp;quot;. When making an LV, I usually allocate what&#039;s needed plus some more, but not everything, just to make sure it&#039;s space available for growth on any of the LVs on the VG, or new LVs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a thick provisioned LV named thicklv on the VG my_vg&lt;br /&gt;
lvcreate -n thicklv -L 100G my_vg&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After the LV is created, a filesystem can be placed on it unless it is meant to be used directly. The application for direct use include swap space, VM storage and certain database systems. Most of these will, however, work on filesystems too, although my testing has shown that on swap space, there is a significant performance gain for using dedicated storage without a filesystem. As for filesystems, most Linux users use either ext4 or xfs. Personally, I generally use XFS these days. See my notes below on filesystem choice.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a filesystem on the LV - this could have been mkfs -t ext4 or whatever filesystem you choose&lt;br /&gt;
mkfs -t xfs /dev/my_vg/thicklv&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then just edit /etc/fstab with correct data and run mount -a, and you should be all set.&lt;br /&gt;
&lt;br /&gt;
==== Create LVM cache ====&lt;br /&gt;
LVMcache is LVM&#039;s solution to caching a slowish filesystem on spinning rust with the help of much faster SSDs. For this to work, use a separate SSD or a mirror or two (just in case) an add the new disk/md dev to the same VG. In this case, we use a small mirror, md1. LVM is not able to cache to a disk or partition outside the volume group.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
vgextend data /dev/md1&lt;br /&gt;
  Physical volume &amp;quot;/dev/md1&amp;quot; successfully created.&lt;br /&gt;
  Volume group &amp;quot;data&amp;quot; successfully extended&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Thn create two LVs, one for the data (contents of files) and one for the metadata (filenames, directories, attributes etc). Typically, the metadata part won&#039;t need to be very large. 100M should usually do unless you have ekstremely many small files. I guess there are ways to calculate it, but again, 1GB should do for everyone (or was that 640k?). As for the data cache, I chose to use 40G here for a 15TB RAID. It will only cache what actively use anyway, so no need for overkill.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
lvcreate -L 1G -n _cache_meta data /dev/md1&lt;br /&gt;
lvcreate -L 100G -n _cache data /dev/md1&lt;br /&gt;
&lt;br /&gt;
# Some would want --cachemode writeback, but if paranoid, I wouldn&#039;t recommend it. Metadata or data can be easily corrupted in case of failure. Most filesystems will however recover from this these days since they use journaling. It &#039;&#039;really&#039;&#039; speeds up things.&lt;br /&gt;
lvconvert --type cache-pool --cachemode writethrough --poolmetadata data/_cache_meta data/_cache&lt;br /&gt;
lvconvert --type cache --cachepool data/_cache data/data&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
That should be it. If you benchmarked the disk before this, you should try again and you&#039;ll probably get a nice surprise. If not, well, see below how to turn this off again :)&lt;br /&gt;
&lt;br /&gt;
==== Disabling LVM cache ====&lt;br /&gt;
&lt;br /&gt;
If you want to change the cached LV, such as growing og shrinking or otherwise, you&#039;ll have to disable caching first and then re-enable it. There&#039;s no quick-and-easy fix, but you just do as you did when enabling in the first place. &lt;br /&gt;
&lt;br /&gt;
Forst, disable caching for the LV. This will do it cleanly and remove the LVs earlier created for caching the main device. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
lvconvert --uncache data/data&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, since you now have a VG with an empty PV in it, earlier used for caching, I&#039;d recommend removing this for now to avoid expanding onto that as well. Since they&#039;re in the same VG, this might happen and if you get so far as to extend the lv and the filesystem on it, and this filesystem is XFS or similar filesystems without possibilities of reducing the size, you have a wee problem. &lt;br /&gt;
&lt;br /&gt;
Just remove that PV from the VG&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
vgreduce data /dev/md1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The PV is still there, but pvs should now show it not connected to a VG&lt;br /&gt;
&lt;br /&gt;
==== Growing devices ====&lt;br /&gt;
&lt;br /&gt;
LVM objects can be grown and shrunk. If a PV resides on a RAID where a new drive has been added or otherwise grown, or on a partition or virtual disk that has been extended, the PV must be updated to reflect these changes. The following command will grow the PV to the maximum available on the underlying storage. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Resize the PV /dev/md (not the RAID, only the PV on the RAID) to its full size&lt;br /&gt;
pvresize /dev/md1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If a new PV is added, the VG can be grown to add the space on that in addition to what&#039;s there already. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Extend my_vg to include md2 and its space&lt;br /&gt;
vgextend my_vg /dev/md2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
With more space available in the VG, the LV can now be extended. Let&#039;s add another 50GB to it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Extend thicklv - add 50GB. If you know you won&#039;t need the space anywhere else, you may want to&lt;br /&gt;
# lvresize -l+100%FREE instead. Keep in mind the difference between -l (extents) and -L (bytes)&lt;br /&gt;
lvresize -L +50G my_vg/thicklv&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Growing filesystems ====&lt;br /&gt;
After the LV has grown, run &#039;&#039;xfs_growfs&#039;&#039; (xfs) or &#039;&#039;resize2fs&#039;&#039; (ext4) to make use of the new data. To grow the filesystem to all available space on ext4, run the below command.  To partly grow the filesystem or to shrink it or otherwise, please see the manuals.&lt;br /&gt;
&lt;br /&gt;
The filesystem can be mounted when this is run. If you for some reason get an &#039;&#039;&#039;access denied&#039;&#039;&#039; error when running this as root or with sudo, it&#039;s likely caused by a filesystem error. To fix this, unmount the filesystem first and run &#039;&#039;&#039;fsck -f /dev/my_vg/thicklv&#039;&#039;&#039; and remount it before retrying to extend it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
resize2fs /dev/my_vg/thicklv&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Similarly, with XFS, but note that xfs_growfs doesn&#039;t take the device name, but the filesystem&#039;s mount point. In the case of XFS, also note that the filesystem &#039;&#039;&#039;&#039;&#039;must&#039;&#039;&#039;&#039;&#039; be mounted to be grown. This, in contrast to how it was in the old days when filesystems had to be unmounted to be grown.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
xfs_growfs /my_mountpoint&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Rename system VG ====&lt;br /&gt;
&lt;br /&gt;
Some distros create VG names like those-from-a-sysadmin-with-a-well-developed-paranoia-not-to-hit-a-duplicate. Debian, for instance, uses names like &amp;quot;my-full-hostname-vg&amp;quot;. Personally, I don&#039;t like these, since if I were to move a disk or vdisk around to somewhere else, I&#039;d make sure not to add a disk named &#039;sys&#039; to an existing system. If you do, most distros will refuse to use the VGs with duplicate names, resulting in the OS not booting until either one is specified by its UUID or just one removed. As I&#039;m aware of this, I stick to the super-risky thing of all system VGs named &#039;sys&#039; and so on.&lt;br /&gt;
&lt;br /&gt;
If you do this, keep in mind that it may blow up your computer and take your girl- or boyfriend with it or even make either of them pregnant, allowing Trump to rule your life and generally make things suck. You&#039;re on your own!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Rename the VG&lt;br /&gt;
vgrename my-full-hostname-vg sys&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, in /boot/grub/grub.cfg, change the old lv path from something like &#039;/dev/mapper/debian--stretch--machine--vg-root&#039; to your new and fancy &#039;/dev/sys/root. Likewise, in /etc/fstab, change occurences of &#039;/dev/mapper/debian--stretch--machine--vg-&#039; (or similar) with &#039;/dev/sys/&#039;. Here, this was like this - the old ones commented out.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;fstab&amp;quot;&amp;gt;&lt;br /&gt;
#/dev/mapper/debian--stretch--box--vg-root      /               ext4            errors=remount-ro,discard       0       1&lt;br /&gt;
/dev/sys/root                                   /               ext4            errors=remount-ro,discard       0       1&lt;br /&gt;
# /boot was on /dev/vda1 during installation&lt;br /&gt;
UUID=myverylonguuidwithatonofgoodinfoinit       /boot           ext2            defaults                        0       2&lt;br /&gt;
#/dev/mapper/debian--stretch--box--vg-swap_1    none            swap            sw                              0       0&lt;br /&gt;
/dev/sys/swap_1                                 none            swap            sw                              0       0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Update /etc/initramfs-tools/conf.d/resume with similar data for swap.&lt;br /&gt;
&lt;br /&gt;
You might want to run &#039;update-initramfs -u -k all&#039; after this, but I&#039;m not sure if it&#039;s needed.&lt;br /&gt;
&lt;br /&gt;
Now, pray to the nearest god(s) and give it a reboot and it should (probably) work.&lt;br /&gt;
&lt;br /&gt;
After reboot, run &#039;&#039;&#039;swapoff -a&#039;&#039;&#039;, then &#039;&#039;&#039;mkswap /dev/sys/swap_1&#039;&#039;&#039; (or whatever it&#039;s called on your system) and &#039;&#039;&#039;swapon -a&#039;&#039;&#039; again. You may want to give it another reboot or two for kicks, but it should work well even without that.&lt;br /&gt;
&lt;br /&gt;
=== Migration tools ===&lt;br /&gt;
&lt;br /&gt;
At times, storage regimes change, new storage is added and sometimes it&#039;s not easy to migrate with the current hardware or its support systems. Once I had to migrate a 45TiB fileserver from one storage system to another, preferably without downtime. The server originally had three 15TiB PVs of which two were full and the third half full. I resorted to using [https://linux.die.net/man/8/pvmove pvmove] to just move the data on the PVs in use to a new PV. We started out with creating a new 50TiB PV, sde, and then to pvmove.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Attach /dev/sde to the VG my_vg&lt;br /&gt;
vgextend my_vg /dev/sde&lt;br /&gt;
&lt;br /&gt;
# Move the contents from /dev/sdb over to /dev/sde block by block. If a target is not given in pvmove,&lt;br /&gt;
# the contents of the source (sdb here) will be put somewhere else in the pool.&lt;br /&gt;
pvmove /dev/sdb /dev/sde&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This took a while (as in a week or so) - the pvmove command uses old code and logic (or at least did that when I migrated this in November 2016), but it affected performance on the server very little, so users didn&#039;t notice. After the first PV was migrated, I continued with the other two, one after the other, and after a month or so, it was migrated. We used this on a number of large fileservers, and it worked flawlessly. Before doing the production servers I also tried interrupting pvmove in various ways, including hard resets, and it just kept on after the reboot.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;NOTE:&#039;&#039;&#039;&#039;&#039; &#039;&#039;Even though it worked well for us, &#039;&#039;&#039;always&#039;&#039;&#039; keep a good backup before doing this. Things may go wrong, and without a good backup, you may be looking for a hard-to-find new job the next morning&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
==== mdadm workarounds ====&lt;br /&gt;
&lt;br /&gt;
===== Migrate from a mirror (raid-1) to raid-10 =====&lt;br /&gt;
&lt;br /&gt;
Create a mirror&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sdb /dev/sdc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
LVM (pv/vg/lv) on md0 (see above), put a filesystem on the lv and fill it with some data.&lt;br /&gt;
&lt;br /&gt;
Now, some months later, you want to change this to raid-10 to allow for the same amount of redundancy, but to allow more disks into the system.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mdadm --grow /dev/md0 --level=10&lt;br /&gt;
mdadm: Impossibly level change request for RAID1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So - no - doesn&#039;t work. But - we&#039;re on &lt;br /&gt;
&lt;br /&gt;
Since we&#039;re on lvm already, this&#039;ll be easy. If you&#039;re using filesystems directly on partitions, you can do this the same way, but without the pvmove part, using rsync or whateever you like instead. I&#039;d recommend using lvm for for the new raid, which should be rather obvious from this article. Now plug in a new drive and create a new raid10 on that one. If you two new drives, install both. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# change &amp;quot;missing&amp;quot; to the other device name if you installed two new drives&lt;br /&gt;
mdadm --create /dev/md1 --level=10 --raid-devices=2 /dev/vdd missing&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, as described above, just vgextend the vg, adding the new raid and run pvmove to move the data from the old pv (residing on the old raid1) to the new pv (on raid10). Afte rpvmove is finished (which may take awile, see above), just&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
vgreduce raidtest /dev/md0&lt;br /&gt;
pvremove /dev/md0&lt;br /&gt;
mdadm --stop /dev/md0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
…and your disk is free to be added to the new array. If the new raid is running in degraded mode (if you created it with just one drive), better don&#039;t wait too long, since you don&#039;t have redundancy. Just mdadm --add the devs.&lt;br /&gt;
&lt;br /&gt;
If you now have /dev/mdstat telling you your raid10 is active and have three drives, of which one is a spare, it should look something like this&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5] [raid4] [raid10]&lt;br /&gt;
md1 : active raid10 vdc[3](S) vdb[2] vdd[0]&lt;br /&gt;
      8380416 blocks super 1.2 2 near-copies [2/2] [UU]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Just mdadm --grow --raid-devices=3 /dev/md1&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;RAID section is not complete. I&#039;ll write more on migraing from raid10 to raid6 later. It&#039;s not straight forward, but easier than this one :)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== Thin provisioned LVs ===&lt;br /&gt;
&lt;br /&gt;
Thin provisioning on LVM is a method used for not allocating all the space given to an LV. For instance, if you have a 1TB VG and want to give an LV 500GB, although it currently only uses a fraction of that, a thin lv can be a good alternative. This will allow for adding a limit to how much it can use, but also to let it grow dynamically without manual work by the sysadmin. Thin provisioning adds another layer of abstaction by creating a special LV as a &#039;&#039;thin pool&#039;&#039; from which data is allocated to the &#039;&#039;thin volume(s)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== Create a thin pool ====&lt;br /&gt;
&lt;br /&gt;
Allocate 1TB to the thin pool to be used for thinly provisioned LVs. Keep in mind that the space allocated to the thin pool is in fact thick provisioned. Only the volumes put on &#039;&#039;thinpool&#039;&#039; are thin provisioned. This will create two hidden LVs, one for data and one for metadata. Normally the defaults will do, but check the manual if the data doesn&#039;t match the usual patterns (such as billions of files, resulting in huge amounts of metadata). I &#039;&#039;beleive&#039;&#039; the metadata part should be resizable at a later time if needed, but I have not tested it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a pool for thin LVs. Keep in mind that the pool itself is not thin provisioned, only the volumes residing on it&lt;br /&gt;
lvcreate --size 1T --type thin-pool --thinpool thinpool my_vg&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Create a thin volume ====&lt;br /&gt;
&lt;br /&gt;
You have the thinpool, now put a thin volume on it. It will allocate some space for metadata, but probably not much (a few megs, perhaps).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Now, create a volume with a virtual (-V) size of half a terabyte named thin_pool, but using the thinpool (-T) named thin_pool for storage&lt;br /&gt;
lvcreate -V 500G -T my_vg/thin_pool --name thinvol&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The new volume&#039;s device name will be /dev/thinvol. Now, create a filesystem on it, add to fstab and mount it. The &#039;&#039;&#039;df&#039;&#039;&#039; command will return available space according to the virtual size (-V), while lvs will show how much data is actually used on each of the thinly provisioned volumes.&lt;br /&gt;
&lt;br /&gt;
== Filesystem dilemmas ==&lt;br /&gt;
&lt;br /&gt;
=== XFS or ext4 or something else ===&lt;br /&gt;
The choice of filesystem varies for your use. Distros such as RHEL/CentOS has moved to XFS by default from v7. Debian/Ubuntu still sticks to ext4, like most other. I&#039;ll discuss my thoughts below on ext4 vs XFS and leave the other filesystems for later.&lt;br /&gt;
&lt;br /&gt;
==== ext4 ====&lt;br /&gt;
ext4 is probably the most used filesystem on linux as of writing. It&#039;s rock stable and has been extended by a lot of extensions since the original ext2. It still retains backward compatibility, being able to mount and fsck ext2 and ext3 with the ext4 driver. However, it doesn&#039;t handle large filesystems very well. If a filesystem is created for &amp;lt;16TiB, it cannot be grown to anything larger than 16TiB. This may have changed lately, though. One other issue is handling errors. If a large filesystem (say 10TiB) is damaged, an fsck may take several hours, leading to long downtime. When I refer to ext4 further in this text, the same applies to ext2 and ext3 unless otherwise specified.&lt;br /&gt;
&lt;br /&gt;
==== XFS ====&lt;br /&gt;
XFS, originally developed by SGI some time in the bronze age, but has been worked on heavily after that. RHEL and Centos version 7 and forward, uses XFS as the default filesystem. It is quick, it scales well, but it lacks at least two things ext4 has. It cannot be shrunk (not that you normally need that, but nice if you have a typo or you need to change things). Also, it doesn&#039;t allow for automatic fsck on bootup. If something is messed up on the filesystem, you&#039;ll have to login as root on the console (not ssh), which might be an issue on some systems. The fsck equivalent, xfs_repair, is a *lot* faster than ext4&#039;s fsck, though.&lt;br /&gt;
&lt;br /&gt;
==== ZFS ====&lt;br /&gt;
ZFS is like a combination of RAID, LVM and a filesystem, supporting full checksumming, auto-healing (given sufficient redundancy), compression, encryption, replication, deduplication (if you&#039;re brave and have a &#039;&#039;ton&#039;&#039; of memory) and a lot more. It&#039;s a separate chapter and needs a lot more talk than paragraph here.&lt;br /&gt;
&lt;br /&gt;
==== btrfs ====&lt;br /&gt;
btrfs, pronounced &amp;quot;butterfs&amp;quot; or &amp;quot;betterfs&amp;quot; or just spelled out, is a filesystem that mimics that of ZFS. It has been around for 10 years or so, but hasn&#039;t yet proven to be really stable. Following the progress of it for those years, I&#039;ve found it to be a nice toy with which to play, but not to be used in production. Again, others may say otherwise, but these are just my words.&lt;br /&gt;
&lt;br /&gt;
== Low level disk handling ==&lt;br /&gt;
&lt;br /&gt;
This section is for low-level handling of disks, regardless of storage system elsewhere. These apply to mdraid, lvmraid and zfs and possibly other solutions, with the exception of individual drives on hwraid (and maybe fakeraid), since there, the drives are hidden from Linux (or whatever OS).&lt;br /&gt;
&lt;br /&gt;
=== S.M.A.R.T. and slow drives ===&lt;br /&gt;
Modern (that is, from about 1990 or later) have S.M.A.R.T. (or just smart, since it&#039;s easier to type) monitoring built in, meaning the disk&#039;s controller is monitoring itself. This is handy and will ideally tell you in advance that a drive is flakey or dying. Modern (2010+) smart monitoring is more or less the same. It can be trusted about 50% of the time. Usually, if smart detects an error, it&#039;s a real error. I don&#039;t think I&#039;ve seen it reporting a false positive, but others may know better. &lt;br /&gt;
&lt;br /&gt;
==== smartmontools ====&lt;br /&gt;
First, install smartmontool and run smartclt -H /dev/yourdisk (/dev/sda or something) to get a health report. Then perhaps run smartctl -a /dev/yourdisk and look for &#039;current pending sectors&#039; This should be zero. Also check the temperature, which normally should be much above 50.&lt;br /&gt;
&lt;br /&gt;
==== single, slow drive ====&lt;br /&gt;
What may happen, is smart not seeing anything and life goes on like before, only slower and less prouductive, without telling anyone. If you stubler over this issue, you&#039;ll probably see it during a large rsync/zfs send/receive or a resync/rebuild/resilver of the raid/zpool. During this, it feels like everything is slow and your RAID has turned into a RAIF (redundant array of inexpensive floppies). To check if you have a single drive messing up it all, check with &#039;&#039;&#039;iostat -x 2&#039;&#039;&#039;, having 2 being the delay between each measurement. Interrupt it with ctrl+x. If there&#039;s a rougue drive there, it should stand out like sdg below&lt;br /&gt;
&lt;br /&gt;
 avg-cpu:  %user   %nice %system %iowait  %steal   %idle&lt;br /&gt;
            0.38    0.00    1.75    0.00    0.00   97.87&lt;br /&gt;
&lt;br /&gt;
 Device            r/s     w/s     rkB/s     wkB/s   rrqm/s   wrqm/s  %rrqm  %wrqm r_await w_await aqu-sz rareq-sz wareq-sz  svctm  %util&lt;br /&gt;
 sda              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdb              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdc              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdd              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sde              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdf              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdg              3.50    0.00   2352.00      0.00     0.00     0.00   0.00   0.00 14306.29    0.00  13.85   672.00     0.00 285.71 100.00&lt;br /&gt;
 sdh              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
&lt;br /&gt;
In ZFS land, you should be able to get similar data with &#039;&#039;&#039;zpool iostat -v &amp;lt;pool&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Now you know the bad drive (sdg), pull it from the raid with &#039;&#039;&#039;mdadm --fail /dev/mdX /dev/sdX&#039;&#039;&#039;. Now test the drive&#039;s performance manually, just simply:&lt;br /&gt;
&lt;br /&gt;
 # hdparm -t /dev/sdg&lt;br /&gt;
 &lt;br /&gt;
 /dev/sdg:&lt;br /&gt;
  Timing buffered disk reads:   2 MB in  5.37 seconds = 381.46 kB/sec&lt;br /&gt;
&lt;br /&gt;
Bingo - nothing you&#039;d want to keep. For a good drive, it should be something like 100-200MB/s&lt;br /&gt;
&lt;br /&gt;
PS: Keep in mind that you have a degraded RAID by now in case you had a spare waiting for things to happen.&lt;br /&gt;
&lt;br /&gt;
Try to replace the cable and/or try the disk on another port/controller. If the result from hdparm persists, it&#039;s probably a bad cable&lt;br /&gt;
&lt;br /&gt;
So, then, just psycially locate the drive, pull it out, take out the discs and magnets and recycle the rest.&lt;br /&gt;
&lt;br /&gt;
=== &amp;quot;Unplug&amp;quot; drive from system ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Find the device unit&#039;s number with something like&lt;br /&gt;
find /sys/bus/scsi/devices/*/block/ -name sdd&lt;br /&gt;
# returning /sys/bus/scsi/devices/3:0:0:0/block/sdd here, &lt;br /&gt;
# meaning 3:0:0:0 is the SCSI device we&#039;re looking for.&lt;br /&gt;
&lt;br /&gt;
# Given this is the correct device, and you want to &#039;unplug&#039; it, do so by&lt;br /&gt;
echo 1 &amp;gt; /sys/bus/scsi/devices/3:0:0:0/delete&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Rescan disk controllers ===&lt;br /&gt;
If a drive is added and for some reason doesn&#039;t get detected, or is removed by the command above, it can be rediscovered with a sysfs command to the scsi host to which it is connected. Since there may be quite a few of these, an easy way is to just scan them all and check the output of &#039;&#039;&#039;dmesg -T&#039;&#039;&#039; after running it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Make a list of controllers and send a rescan message to each of them. It won&#039;t do anything &lt;br /&gt;
# for those where nothing has changed, but it will show new drives where they have been added.&lt;br /&gt;
for host_scan in /sys/class/scsi_host/host*/scan&lt;br /&gt;
do&lt;br /&gt;
  echo &#039;- - -&#039; &amp;gt; $host_scan&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Fail injection with debugfs ===&lt;br /&gt;
[https://lxadm.com/Using_fault_injection https://lxadm.com/Using_fault_injection]&lt;br /&gt;
&lt;br /&gt;
== mdadm stuff ==&lt;br /&gt;
=== Resync ===&lt;br /&gt;
To resync a raid, that is, check, run&lt;br /&gt;
&lt;br /&gt;
 echo check &amp;gt; /sys/block/$dev/md/sync_action&lt;br /&gt;
&lt;br /&gt;
where $dev is something like md0. If you have several raids, something like this should work&lt;br /&gt;
&lt;br /&gt;
 for dev in md{0,1}&lt;br /&gt;
 do&lt;br /&gt;
   echo repair &amp;gt; /sys/block/$dev/md/sync_action&lt;br /&gt;
 done&lt;br /&gt;
&lt;br /&gt;
Also useful in a one-liner like&lt;br /&gt;
&lt;br /&gt;
 for dev in md{0,1} ; do echo repair &amp;gt; /sys/block/$dev/md/sync_action ; done&lt;br /&gt;
&lt;br /&gt;
Different raids on different drives will do this in parallel. If the drives are shared somehow with partitions or similar, the check or repair will wait for the other to finish before going on.&lt;br /&gt;
&lt;br /&gt;
As for repair vs check, [https://raid.wiki.kernel.org/index.php/RAID_Administration this article] describes it well. I stick to using repair unless it&#039;s something rare where I don&#039;t want to touch the data.&lt;br /&gt;
&lt;br /&gt;
=== Spare pools ===&lt;br /&gt;
In the old itmes, mdadm supported only a dedicated spare per md device, so if working with a large set of drives (20? 40?), where you&#039;d want to setup more raid sets to increase redundancy, you&#039;d dedicate a spare to each of the raid sets. This has changed (some time ago?), so in these modern, heathen days, you can change mdadm.conf, usually placed under /etc/mdadm, and add &#039;spare-group=somegroup&#039; where &#039;somegroup&#039; is a string identifying the spare group. After doing this, run &#039;&#039;&#039;update-initramfs -u&#039;&#039;&#039; and reboot and add a spare to one of the raid sets in the spare group, and md will use that or those spares for all the raidsets in that group.&lt;br /&gt;
&lt;br /&gt;
As some pointed out on #linux-raid @ irc.freenode.net, this feature is very badly documented, but as far as I can see, it works well.&lt;br /&gt;
&lt;br /&gt;
==== Example config ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create two raidsets&lt;br /&gt;
&lt;br /&gt;
mdadm --create /dev/md1 --level=6 --raid-devices=6 /dev/vd[efghij]&lt;br /&gt;
mdadm --create /dev/md2 --level=6 --raid-devices=6 /dev/vd[klmnop]&lt;br /&gt;
&lt;br /&gt;
# get their UUID etc&lt;br /&gt;
&lt;br /&gt;
mdadm --detail --scan&lt;br /&gt;
ARRAY /dev/md/1 metadata=1.2 name=raidtest:1 UUID=1a8cbdcb:f4092350:348b6b80:c054d74c&lt;br /&gt;
ARRAY /dev/md/2 metadata=1.2 name=raidtest:2 UUID=894b1b7c:cb7eba70:917d6033:ea5afd2b&lt;br /&gt;
&lt;br /&gt;
# Put those lines into /etc/mdadm/mdadm.conf and and add the spare-group&lt;br /&gt;
&lt;br /&gt;
ARRAY /dev/md/1 metadata=1.2 name=raidtest:1 spare-group=raidtest UUID=1a8cbdcb:f4092350:348b6b80:c054d74c&lt;br /&gt;
ARRAY /dev/md/2 metadata=1.2 name=raidtest:2 spare-group=raidtest UUID=894b1b7c:cb7eba70:917d6033:ea5afd2b&lt;br /&gt;
&lt;br /&gt;
# update the initramfs and reboot&lt;br /&gt;
&lt;br /&gt;
update-initramfs -u&lt;br /&gt;
reboot&lt;br /&gt;
&lt;br /&gt;
# add a spare drive to one of the raids&lt;br /&gt;
&lt;br /&gt;
mdadm --add /dev/md1 /dev/vdq&lt;br /&gt;
&lt;br /&gt;
# fail a drive on the other raid&lt;br /&gt;
&lt;br /&gt;
mdadm --fail /dev/md2 /dev/vdn&lt;br /&gt;
&lt;br /&gt;
# check /proc/mdstat to see md2 rebuilding with the spare from md1&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Recovery ===&lt;br /&gt;
&lt;br /&gt;
The other day, I came across a problem a user had on #linux-raid@irc.freenode.net. He had an old Qnap NAS that had died and tried plugging the drives in to his Linux machine and got various errors. The two-drive RAID-1 did not come up as it should, &#039;&#039;&#039;dmesg&#039;&#039;&#039; was full of errors from one of the drives (both connected on USB) and so forth.&lt;br /&gt;
&lt;br /&gt;
We went on and started by taking down the machine and just connecting one of the drives. I had him check what was assembled with&lt;br /&gt;
&lt;br /&gt;
 cat /proc/mdstat&lt;br /&gt;
&lt;br /&gt;
That returned /proc/md127 assembled, but LVM didn&#039;t find anything. So running a manual scan&lt;br /&gt;
&lt;br /&gt;
 pvscan --cache /dev/md127&lt;br /&gt;
&lt;br /&gt;
This made linux find the PV, VG and a couple of LVs, but probably because the mdraid was degraded, the LVs were deactivated, according to &#039;&#039;&#039;lvscan&#039;&#039;&#039;. Activating the one with a filesystem manually&lt;br /&gt;
&lt;br /&gt;
 lvchange -a y /dev/&amp;lt;vg&amp;gt;/&amp;lt;lv&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Substitute &amp;lt;vg&amp;gt; and &amp;lt;lv&amp;gt; with the names listed by vgs and lvs.&lt;br /&gt;
&lt;br /&gt;
This worked, and the filesystem on /dev/&amp;lt;vg&amp;gt;/&amp;lt;lv&amp;gt; could be mounted correctly.&lt;br /&gt;
&lt;br /&gt;
=== The badblock list ===&lt;br /&gt;
&#039;&#039;&#039;md&#039;&#039;&#039; has an internal badblock list (BBL), added around 2010, to list the bad blocks on the disk to avoid using those. While this might sound like a good idea, the badblock list is updated in case of a read error, which can be caused by several things. To make things worse, the BBL is replicated to other drives when a drive fails or the array is grown. So if you start out with sda and sdb and sdb suffers some errors, nothing wrong, md will read from sda, but flag those sectors on sdb as bad. So after a while, perhaps sda dies and gets replaced, with the same content, including the BBL. Then, at some point you might to replace sdb and it, too gets the BBL. So it sticks - forever. Also, there&#039;s no real point of keeping a BBL list, since the drive has its own and even if a sector error occurs, the array will have sufficient redundancy to recover from that (unless you use RAID-0 which you shouldn&#039;t). If a drive finds a bad sector, it&#039;ll be reallocated by the drive itself without the user&#039;s/admin&#039;s/system&#039;s knowledge. If a sector can&#039;t be reallocated, it means the drive is bad and should be replaced.&lt;br /&gt;
&lt;br /&gt;
There&#039;s no official way to remove it and although you can assemble it with the no-bbl option, this will only work if there&#039;s an empty BBL. Also, this will require downtime. As far as I can see, the only way to do this currently, is with a wee hack that should work. Just replace the names of mddev/diskdev with your own.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
mddev=&amp;quot;/dev/md0&amp;quot;&lt;br /&gt;
diskdev=&amp;quot;/dev/sda&amp;quot;&lt;br /&gt;
mdadm $mddev --fail $diskdev --remove $diskdev --re-add $diskdev --update=no-bbl&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If there&#039;s a BBL on the drive already, replace the --update part to &#039;force-no-bbl&#039;. This is not documented anywhere as per se, but it works.&lt;br /&gt;
 &lt;br /&gt;
I haven&#039;t found a way to turn this off permanently, but there may be something coming around when the debate on the linux-raid mailing list closes up on this. There&#039;s a bbl=no in mdadm.conf, but that&#039;s only for creation. I will continue extensive testing for this.&lt;br /&gt;
&lt;br /&gt;
== Tuning ==&lt;br /&gt;
&lt;br /&gt;
While trying to compare a 12-disk RAID (8TB disks) to a hwraid, mdraid was slower, so we did a few things to speed things up:&lt;br /&gt;
&lt;br /&gt;
While testing with [https://linux.die.net/man/1/fio fio], monitor /sys/block/md0/md/stripe_cache_active, and see if it&#039;s close to /sys/block/md0/md/stripe_cache_size. If it is, double the size of the latter&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
echo 4096 &amp;gt; /sys/block/md0/md/stripe_cache_size&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Continue until stripe_cache_active stabilises, and then you&#039;ve found the limit you&#039;ll need. You may want to double that for good measure. &lt;br /&gt;
&lt;br /&gt;
(to be continued)&lt;br /&gt;
&lt;br /&gt;
== Links ==&lt;br /&gt;
&lt;br /&gt;
Below are a few links with useful info&lt;br /&gt;
&lt;br /&gt;
* [https://raid.wiki.kernel.org/index.php/Irreversible_mdadm_failure_recovery Irreversible mdadm failure recovery]&lt;br /&gt;
&lt;br /&gt;
= ZFS =&lt;br /&gt;
&lt;br /&gt;
ZFS can do a lot of things most filesystems or volume managers can&#039;t. It checksums all data and metadata and so long that the system uses ECC enabled memory (RAM), it will have complete control over the whole data set, and when (not if) an error occurs, it&#039;ll fix the issue without even throwing a warning. To fix the issue, you&#039;ll obviously need sufficient redundancy (mirrors or RAIDzN). &lt;br /&gt;
&lt;br /&gt;
== ZFS send/receive between machines ==&lt;br /&gt;
&lt;br /&gt;
ZFS has a send/receive mechanism that allows for snapshots to be sent over the wire to a receiving end. This can be a full filesystem, or an incremental change since last send/reveive. In a WAN scenario, you&#039;ll probably want to use VPN for this. On a controlled network, sending in cleartext is also possible. You may as well use ssh, but keep in mind that ssh was never designed to be used as a fullblown vpn solution and is just too slow or the task with large amounts of data. You may, though, use mbuffer, if on a loal LAN.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Allow traffic from the sending IP in whatever firewall interface you&#039;re using (if you&#039;re using a firewall at all, that is)&lt;br /&gt;
ufw allow from x.x.x.x&lt;br /&gt;
# &lt;br /&gt;
# Start the receiver first. This listens on port 9090, has a 1GB buffer,&lt;br /&gt;
    and uses 128kb chunks (same as zfs):&lt;br /&gt;
&lt;br /&gt;
mbuffer -s 128k -m 1G -I 9090 | zfs receive data/filesystem&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To be continued one day… See [https://everycity.co.uk/alasdair/2010/07/using-mbuffer-to-speed-up-slow-zfs-send-zfs-receive/ this] for some more. I&#039;ll get back with details on it.&lt;br /&gt;
&lt;br /&gt;
= General Linux system control =&lt;br /&gt;
&lt;br /&gt;
== Add a new CPU (core) ==&lt;br /&gt;
&lt;br /&gt;
If working with virtual machines, adding a new core can be useful if the VM is slow and the load is multithreaded or multiprocess. To do this, add a new CPU in the hypervisor (be it KVM or VMware or Hyper-V or whatever). Some hypervisors, like VMware, will activate it automatically if open-vm-tools is installed. Please note that open-vm-tools is for VMware only. I don&#039;t know of any such thing for KVM or other hypervisors (although I beleive VirtualBox has its own set of tools, but not as a package). If this doesn&#039;t work, run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
echo 1 &amp;gt; /sys/devices/system/cpu/cpuX/online&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where X is the CPU number you want to add. You can &#039;cat /sys/devices/system/cpu/cpuX/online&#039; to check if it&#039;s online.&lt;br /&gt;
&lt;br /&gt;
= Mount partitions on a disk image =&lt;br /&gt;
&lt;br /&gt;
Sometimes you&#039;ll have a disk image, either from recovering a bad drive after hours (or days or weeks) of ddrescue, and sometimes you just have a disk image from a virtual machine where you want to mount the partitions inside the image. There are three main methods of doing this, which are more or less synonmous, but some easier than the other.&lt;br /&gt;
&lt;br /&gt;
== Basics ==&lt;br /&gt;
&lt;br /&gt;
A disk image is usually like a disk, consisting of either a large filesystem, a PV or a partition table with one or partitions onto which resides a filesystem, a pv, swap or something else. If it&#039;s partitioned, and you want your operating system to mount a filesystem or allow it to see whatever LVM stuff lies on it, you need to isolate the partitions. &lt;br /&gt;
&lt;br /&gt;
== Manual mapping ==&lt;br /&gt;
&lt;br /&gt;
In the oldern days, this was done manually, something like this&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
root@mymachine:~# fdisk -l /dev/vda&lt;br /&gt;
Disk /dev/vda: 25 GiB, 26843545600 bytes, 52428800 sectors&lt;br /&gt;
Units: sectors of 1 * 512 = 512 bytes&lt;br /&gt;
Sector size (logical/physical): 512 bytes / 512 bytes&lt;br /&gt;
I/O size (minimum/optimal): 512 bytes / 512 bytes&lt;br /&gt;
Disklabel type: dos&lt;br /&gt;
Disk identifier: 0xc37b7ea5&lt;br /&gt;
&lt;br /&gt;
Device     Boot    Start      End  Sectors  Size Id Type&lt;br /&gt;
/dev/vda1  *        2048 50333311 50331264   24G 83 Linux&lt;br /&gt;
/dev/vda2       50333312 52426369  2093058 1022M  5 Extended&lt;br /&gt;
/dev/vda5       50333314 52426369  2093056 1022M 82 Linux swap / Solaris&lt;br /&gt;
root@mymachine:~#&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To calculate the start and end of each partition, you just take the start sector and multiply it by the sector size (512 bytes here) and you have the offset in bytes. After this, it&#039;s merely an losetup -o &amp;lt;offset&amp;gt; /dev/loopX &amp;lt;nameofimagefile&amp;gt; and you have the partition mapped to your /dev/loopX (having X being something typically 0-255. After this, just mount it or run pvscan/vgscan/lvscan to probe whatever lvm config is there, and you should be able to mount it like any other filesystem.&lt;br /&gt;
&lt;br /&gt;
== kpartx ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;kpartx&#039;&#039;&#039; does the same as above, more or less, just without so much hassle. Most of it should be automatic and easy to deal with, except it may fail to disconnect the loopback devices sometimes, so you may have to &#039;&#039;&#039;losetup -d&#039;&#039;&#039; them manually. See the manual, &#039;&#039;&#039;kpartx (8)&#039;&#039;&#039;. Please note that &#039;&#039;&#039;partx&#039;&#039;&#039; works similarly and I&#039;d guess the authors of the two tools are arguing a lot of which one&#039;s the best.&lt;br /&gt;
&lt;br /&gt;
== guestmount ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;guestmount&#039;&#039;&#039; is something similar again, but also supports file formats like &#039;&#039;&#039;qcow2&#039;&#039;&#039; and possibly other, proprietary filesystems like &#039;&#039;&#039;vmdk&#039;&#039;&#039; and &#039;&#039;&#039;vdi&#039;&#039;&#039;, but don&#039;t take my word for it - I haven&#039;t tested. Again, see the manual or just read up on the description [http://ask.xmodulo.com/mount-qcow2-disk-image-linux.html?fbclid=IwAR3snTeZvGzp9PLdX11EQhCfOpux6I93CiJ3A2pUomkkRLly9Xo4851mkTY here]. It seems rather trivial.&lt;br /&gt;
&lt;br /&gt;
= Linux on laptops =&lt;br /&gt;
&lt;br /&gt;
== Wifi with HP EliteBook 725/745 on Ubuntu ==&lt;br /&gt;
&lt;br /&gt;
The HP EliteBook 725/745 and similar are equipped with a BCM4352 wifi chip. As with a lot of other stuff from Broadcom, this lacks an open hardware description, so thus no open driver exist. The proper fix, is to replace the NIC with something with an open driver, but again, this isn&#039;t always possible, so a binary driver exists. In ubuntu, run, somehow connect the machine to the internet and run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install bcmwl-kernel-source&lt;br /&gt;
sudo modprobe wl&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you can&#039;t connect the machine to the internet, download the needed packages on another machine and put it on some usb storage. These packages should suffice:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# apt-cache depends bcmwl-kernel-source&lt;br /&gt;
bcmwl-kernel-source&lt;br /&gt;
  Depends: dkms&lt;br /&gt;
  Depends: linux-libc-dev&lt;br /&gt;
  Depends: libc6-dev&lt;br /&gt;
  Conflicts: &amp;lt;bcmwl-modaliases&amp;gt;&lt;br /&gt;
  Replaces: &amp;lt;bcmwl-modaliases&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then install manually with &#039;&#039;&#039;dpkg -i file1.deb file2.deb&#039;&#039;&#039; etc&lt;br /&gt;
&lt;br /&gt;
After this, ip/ifconfig/iwconfig shouldd see the new wifi nic, probably &#039;&#039;&#039;wlan0&#039;&#039;&#039;, but due to a [https://bugs.launchpad.net/ubuntu/+source/broadcom-sta/+bug/1343151 old, ignored bug], you won&#039;t find any wifi networks. This is because the driver from Broadcom apparently does not support interrupt remapping, commonly used on x64 machines. To turn this off, change &#039;&#039;&#039;/etc/default/grub&#039;&#039;&#039; and change the line &#039;&#039;&#039;GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;quiet splash&amp;quot;&#039;&#039;&#039;, adding intremap=off to the end before the quote: &#039;&#039;&#039;GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;quiet splash intremap=off&amp;quot;&#039;&#039;&#039;. Save the file and run &#039;&#039;&#039;sudo update-grub&#039;&#039;&#039; and reboot. After this, wifi should work well.&lt;br /&gt;
&lt;br /&gt;
== Wifi with HP Compaq Presario CQ57 on Ubuntu ==&lt;br /&gt;
&lt;br /&gt;
The HP Compaq Presario CQ57 uses the RT5390 wifi chipset. This has been supported for quite some time now, and I was quite surprised to find it not working on a laptop a friend was having. The driver loaded correctly, but Ubuntu insisted of the laptop being in &#039;&#039;&#039;flight mode&#039;&#039;&#039;. Checking &#039;&#039;&#039;rfkill&#039;&#039;&#039;, it showed me two NICs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# rfkill list all&lt;br /&gt;
0: phy0: Wireless LAN&lt;br /&gt;
	Soft blocked: no&lt;br /&gt;
	Hard blocked: yes&lt;br /&gt;
1: hp-wifi: Wireless LAN&lt;br /&gt;
	Soft blocked: yes&lt;br /&gt;
	Hard blocked: no&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Turning rfkill on and off resulted in nothing much, except some error messages in the kernel log (dmesg)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] ACPI Error: Field [B128] at bit offset/length 128/1024 exceeds size of target Buffer (160 bits) (20170831/dsopcode-235)&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]&lt;br /&gt;
                            Initialized Local Variables for Method [HWCD]:&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Local0: 00000000a34b7928 &amp;lt;Obj&amp;gt;           Integer 0000000000000000&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Local1: 00000000b0aa6865 &amp;lt;Obj&amp;gt;           Buffer(8) 46 41 49 4C 04 00 00 00&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Local5: 00000000a9811efd &amp;lt;Obj&amp;gt;           Integer 0000000000000004&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] Initialized Arguments for Method [HWCD]:  (2 arguments defined for method invocation)&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Arg0:   0000000078957d1b &amp;lt;Obj&amp;gt;           Integer 0000000000000001&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Arg1:   00000000725c9c6e &amp;lt;Obj&amp;gt;           Buffer(20) 53 45 43 55 02 00 00 00&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] ACPI Error: Method parse/execution failed \_SB.WMID.HWCD, AE_AML_BUFFER_LIMIT (20170831/psparse-550)&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] ACPI Error: Method parse/execution failed \_SB.WMID.WMAD, AE_AML_BUFFER_LIMIT (20170831/psparse-550)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After upgrading BIOS and testing different kernels, I was asked to try to unload the &#039;&#039;&#039;hp_wmi&#039;&#039;&#039; driver. I did, and things changed a bit, so I tried blacklisting it, creating the file &#039;&#039;&#039;/etc/modprobe.d/blacklist-hp_wmi.conf&#039;&#039;&#039; with the following content&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Blacklist this - it doesn&#039;t work!&lt;br /&gt;
blacklist hp_wmi&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
I gave the machine a reboot and afte that, the &#039;&#039;&#039;hp-wifi&#039;&#039;&#039; entry was gone in the rfkill output, and things works.&lt;br /&gt;
&lt;br /&gt;
= Raspberry pi =&lt;br /&gt;
&lt;br /&gt;
I couldn&#039;t quite decide if the raspberry pi should be a separate section or part of Linux, but hell, it can run more than Linux, although 99,lots% of people just uses Linux on them. This is a small list of things to know about them; things not on the front page of the manual or perhaps hidden even better.&lt;br /&gt;
&lt;br /&gt;
== Which pi? ==&lt;br /&gt;
&lt;br /&gt;
I just setup three raspberry pi machines and although some are quite different, like v1 to vEverythingelse or the Pi zero versions to the normal ones, not all of us remember how to distinguish between them, and sometimes they&#039;re in a nice 3d printed (or otherwise) chassis or otherwise hidden. So, how to check three different ones:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
root@home-assistant:~ $ cat /proc/device-tree/model ; echo&lt;br /&gt;
Raspberry Pi 2 Model B Rev 1.1&lt;br /&gt;
&lt;br /&gt;
root@green-pi:~ $ cat /proc/device-tree/model ; echo&lt;br /&gt;
Raspberry Pi 3 Model B Rev 1.2&lt;br /&gt;
&lt;br /&gt;
roy@yellow-pi:~ $cat /proc/device-tree/model ; echo&lt;br /&gt;
Raspberry Pi 4 Model B Rev 1.1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
While this works well, for the latter, the pi4, it doesn&#039;t tell how much memory I have. It comes in variants of 1, 2 and 4GB, and this is the latter.&lt;br /&gt;
&lt;br /&gt;
== Monitoring ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;vcgencmd&#039;&#039;&#039; from &#039;&#039;&#039;/opt/vc/bin&#039;&#039;&#039;, but symlinked to &#039;&#039;&#039;/usr/bin&#039;&#039;&#039; so it&#039;s available in path, is useful for fetching hardware info about the pi. For example, measuring the temperature&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
root@yellow-pi:~# vcgencmd measure_temp&lt;br /&gt;
temp=63.0&#039;C&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The command is generally badly documented and parts of it seems outdated for newer hardware. Here&#039;s the output from a Raspberry pi 4 with 4GB RAM&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
roy@yellow-pi:~ $ vcgencmd get_mem arm&lt;br /&gt;
arm=948M&lt;br /&gt;
roy@yellow-pi:~ $ vcgencmd get_mem gpu&lt;br /&gt;
gpu=76M&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= BIOS upgrade from Linux =&lt;br /&gt;
&lt;br /&gt;
Generally, BIOS upgrades have been moved to the BIOS itself these days. This saves a lot of work and quite possibly lives after those who earier rammed their heads through walls, now can upgrade directly from the internet instead of using obscure operating systems best avoided. Sometimes, however, one must use these nevertheless. This is a quick run-through on your options.&lt;br /&gt;
&lt;br /&gt;
== DOS ==&lt;br /&gt;
&lt;br /&gt;
Most non-automatic BIOS upgrades are installed from DOS. Doing a BIOS upgrade this way, is generally non-problematic. Just install a USB thingie with [https://www.freedos.org/ FreeDOS], copy your file(s) onto the thing and boot on it. The commandline is the same as old MS/DOS, except a wee bit more userfriendly, but not a lot.&lt;br /&gt;
&lt;br /&gt;
== Windows ==&lt;br /&gt;
&lt;br /&gt;
Some macahines, like laptops from &#039;&#039;&#039;HP&#039;&#039;&#039;, may have BIOS upgrades that are made to be installed from Windows and won&#039;t run in FreeDOS or MS/DOS, instead throwing an error, saying &#039;&#039;&#039;This program cannot be run in DOS mode&#039;&#039;&#039;. This means you&#039;ll have to boot on a Windows rescue disc and do the job from there. Googling this, tells you it&#039;s quite easy, you just choose &#039;make rescue disc&#039; from Windows, and it&#039;s all good, except if you don&#039;t run Windows, that is. To remedy this problem, do as follows:&lt;br /&gt;
&lt;br /&gt;
=== Download Windows ===&lt;br /&gt;
&lt;br /&gt;
Since you don&#039;t run Windows and possibly don&#039;t have a spouse or friend around with such unhealthy habits either, you need to get it. It&#039;s quite easy - just google &#039;download windows&#039; and it&#039;ll send you to [https://www.microsoft.com/en-us/software-download/windows10ISO somewhere like this].&lt;br /&gt;
&lt;br /&gt;
=== Burn it! ===&lt;br /&gt;
&lt;br /&gt;
Now it&#039;s time to burn the installer on a DVD ROM. You&#039;ll need a double-layered one, since the OS is &amp;gt; 4.7GiB, but I&#039;m sure you have a ton of those lying around. Now, just place your optical medium in your optical drive and burn, baby, burn!&lt;br /&gt;
&lt;br /&gt;
=== Or make a USB thing? ===&lt;br /&gt;
&lt;br /&gt;
Not a lot of machines have optical drives these days, so you may want to use an USB pen drive or something instead. This is easy, just make the USB bootable with the Windows application Microsoft has made for this. Unfortunately, this only runs on Windows, and unlike stuff like Debian, where the &#039;&#039;&#039;iso&#039;&#039;&#039; file can be dd&#039;ed directly onto a USB drive to make it bootable, the Windows &#039;&#039;&#039;iso&#039;&#039;&#039;s don&#039;t come with this luxury. There are lots of methods to make bootable USB things from iso files out there, but the only thing most of them have in common, is that they generally don&#039;t work.&lt;br /&gt;
&lt;br /&gt;
==== WoeUSB ====&lt;br /&gt;
&lt;br /&gt;
After hours of swearing, it&#039;s nice to come across software like [https://github.com/slacka/WoeUSB WoeUSB]. It may not be perfect, it relies on a bunch of GUI stuff you&#039;ll never need and so on, but it &#039;&#039;&#039;&#039;&#039;works&#039;&#039;&#039;&#039;&#039;, and that&#039;s the important part! Just clone the repo and RTFM and it&#039;s all nice. It&#039;s slow, but hell, getting a windows machine and/or an optical drive might be slower.&lt;br /&gt;
&lt;br /&gt;
WoeUSB does nothing fancy, but it &#039;&#039;&#039;does&#039;&#039;&#039; work. It will create a filesystem, FAT32 or NTFS (better use NTFS, FAT32 has its limits). It creates normal filesystems and so on. Just make sure to copy in the BIOS update file, usually an exe file, to run when Windows is up and running.&lt;br /&gt;
&lt;br /&gt;
==== Install BIOS ====&lt;br /&gt;
&lt;br /&gt;
Boot on the Windows USB thing and choose &#039;repair computer&#039; and then &#039;command prompt&#039;. Find the install file, and if you&#039;re lucky, you&#039;ll find it needs a 32bit OS, just like I did. Since the 64bit version doesn&#039;t include 32bit compatibility in the installer, revert to downloading the 32bit version of windows and start over. Pray to your favourite god(s) not to get across such machines again - it might help.&lt;br /&gt;
&lt;br /&gt;
= 3D printer stuff =&lt;br /&gt;
&lt;br /&gt;
Below are a number of not very ordered paragraphs about 3D printer related stuff, mostly based on my experience. Their content may be interesting or perhaps practical knowledge, but then, that depends on the reader.&lt;br /&gt;
&lt;br /&gt;
== 3D printer related introductions on youtube or elsewhere ==&lt;br /&gt;
&lt;br /&gt;
First off, I&#039;d like to mention some youtube videos that are all (or mostly) a nice start if you&#039;re new to 3D printers.&lt;br /&gt;
&lt;br /&gt;
=== [https://www.youtube.com/watch?v=nb-Bzf4nQdE&amp;amp;list=PLDJMid0lOOYnkcFhz6rfQ6Uj8x7meNJJx Thomas Salanderer&#039;s 10-video series on 3D printing basics] ===&lt;br /&gt;
&lt;br /&gt;
Thomas Salanderer is a an experienced 3D printer user/admin/fixer/etc and he has a lot of interesting videos. Some accuse him for being a [Prusa https://www.prusa3d.com/] fanboy, which he quite obviously is, but that doesn&#039;t stop him from making interesting and somewhat neutral videos. The series walks you thought the first steps of how things work and so on and hopefully opens more doors than anything else I&#039;ve seen.&lt;br /&gt;
&lt;br /&gt;
=== [https://www.youtube.com/watch?v=rp3r921DBGI Teaching Tech&#039;s &amp;quot;3D printer tuning reborn&amp;quot;] ===&lt;br /&gt;
&lt;br /&gt;
Teaching Tech is, like Salanderer or even more, good pedagogically and explains a lot. They (or he) do a bunch of testing and describing pros and cons with different things, just like other youtubers in the sme business. The mentioned video shows how to tune a 3D printer after you have first learned the basics, and leans on a webpage made to help you out without too much manual work.&lt;br /&gt;
&lt;br /&gt;
This was a short list, but I guess it&#039;ll grow over time.&lt;br /&gt;
&lt;br /&gt;
== Hydrophilic filament ==&lt;br /&gt;
&lt;br /&gt;
Most popular filament types, including PLA, PETG, PP or PA (Polyamide, normally known as Nylon) and virtualy any filament type named [https://www.matterhackers.com/news/filament-and-water poly-something] (and thus with an acronym of P-something) are hydrophilic (also (somewhat incorrectly) called hydroscopic), meaning so long they&#039;re dryer than the atmosphere around them, they&#039;ll do their best to suck out the atmosphere&#039;s humidity. This is why most filament are shrink-wrapped with a small bag of silica gel in it. If such filament is exposed for normal humid air for some time, it&#039;ll become very hard to use. Most of my experience is with PLA, which can handle a bit (depending on make), but still not a lot. With PLA, if you end up with prints where the filament seems not to stick, it may help with a higher temperature. Otherwise, the filament must be [https://all3dp.com/2/how-to-dry-filament-pla-abs-and-nylon/ baked]. If you don&#039;t want to use your oven, try something like a [https://www.jula.no/catalog/hjem-og-husholdning/kjokkenmaskiner/mattilberedningsapparater/frukt-sopptorker/frukt-sopptorker-001641/#tab02 fruit and mushroom dryer]. Then get a good, sealble plastic box and add something like half a kilogram of [https://www.ebay.com/sch/sis.html?_nkw=1KG+Orange+Replacement+Desiccant+Indicating+Silica+Gel+Beads+for+Drawers%2C+Camera&amp;amp;_id=131938742628&amp;amp;&amp;amp;_trksid=p2057872.m2749.l2658 silica gel] to an old sock, tie it and put it in the your new dry box.&lt;br /&gt;
&lt;br /&gt;
Please note that ABS is hydrophobic, so you won&#039;t have to worry too much there. Also, remember that PA/Nylon is extremely hydrophilic. Even a couple of days in normal air humidity can ruin it completely and will require baking.&lt;br /&gt;
&lt;br /&gt;
== Upgrading the firmware on an Ender 3 ==&lt;br /&gt;
&lt;br /&gt;
This is about upgrading the firmware, and thus also flashing a bootloader to the Creality Ender 3 3D printer. Most of this is well documented on several place, like o [https://www.youtube.com/watch?v=fIl5X2ffdyo the video from Teaching tech] and elsewhere, but I&#039;ll just summarise some issues I had.&lt;br /&gt;
&lt;br /&gt;
=== Using an arduino Nano as a programmer ===&lt;br /&gt;
&lt;br /&gt;
Quick note before you read on. If you have an Ender 3 controller version 1.1.5 or newer (or perhaps even a bit older), a CR-10S or some other more or less modern printers or controllers, they come with a bootloader installed already, so don&#039;t bother flashing one. The one that&#039;s in there already, should work well. So if you have one of these, just skip this and jump to the [[Roy&#039;s_notes#Flashing_the_printer|next section]].&lt;br /&gt;
&lt;br /&gt;
However, the normal CR-10 (without the S), Ender 3 and a few other printers from Creality come without a bootloader, so you&#039;ll need to flash one before upgrading the firmware. Well, strictly speakning, you don&#039;t need one, you can save those 8kB or so for other stuff and use a programmer to write the whole firmware, but then you&#039;ll need to wire up everything every time you want a new firmware, so in my world, you &#039;&#039;&#039;do&#039;&#039;&#039; need the bootloader, since it&#039;s easier.&lt;br /&gt;
&lt;br /&gt;
To install a bootloader, you&#039;ll need a programmer, and I didn&#039;t have one available. Having some el-cheapo china-copies of Arduinos around, I read I could use one and tried so. Although the docs mostly mention the Uno etc, it&#039;s just as simple with the Nano copy.&lt;br /&gt;
&lt;br /&gt;
So, grab an arduino, plug it to your machine with a USB cable, and, using the Arduino IDE, use the ArduinoISP sketch there (found under Examples) to burn the software needed for the arduino to work as a programmer. When this is done, connect a 10µF capacitor between RST and GND to stop it from resetting when used as a programmer. Connect the MOSI, MISO and SCK pins from the ICSP block (that little isolated 6-pin block on top of the ardu). See [https://www.arduino.cc/en/Tutorial/ArduinoISP here] for a pinout. Then find Vcc and GND either on the ICSP block or elsewhere. Some sites say that on some boards you shouldn&#039;t use the pins on the ICSP block for this. I doubt it matters, though. Then connect another jumper wire from pin 10 on the ardu to work as the reset pin outwards to the chip being programmed (that is, on the printer). The ICSP jumper block pin layout is the same on the printer and on the ardu, and probably elsewhere. Sometimes [https://xkcd.com/927/ standardisation] actually works…&lt;br /&gt;
&lt;br /&gt;
See https://cloud.karlsbakk.net/index.php/s/zw48YJjzaf8Rc2F for a pic with the ardu (this wiki is broken atm, will fix it later)&lt;br /&gt;
&lt;br /&gt;
== Flashing the printer ==&lt;br /&gt;
&lt;br /&gt;
When the boot loader is in place, possibly after some wierd errors from during the process, the screen on the 3d printer will go blank and it&#039;ll behave like being bricked. This is ok. Now disconnect the wires and connect the USB cable between computer and printer. If you haven&#039;t installed support for the Sanguino board, that is, the variant of the 1284-chip and surrounding electronics that is the core of the, you need to install it first. In the Arduino IDE, choose the Tools / Boards / Boards manager boot option and search for Sanguino. After this, you should find the Sanguino or Sanguino 1284p in the boards menu. After this, you should be able to communicate with the printer&#039;s controller. Download the [https://www.th3dstudio.com/knowledgebase/th3d-unified-firmware-package/ TH3D unified firmware], making sure it&#039;s the last version. Uncompress the zip and with Finder/Explorer/whateversomething&#039;scalledonlinux, browse to &#039;&#039;&#039;TH3DUF_R2/Firmware/TH3DUF_R2.ino&#039;&#039;&#039; and open it. It should open directly in the Android IDE. Keep in mind that the names TH3DUF_R2 and TH3DUF_R2.ino will vary between versions, but you get the point. Now configure it for your particular needs. You&#039;ll find most of this in the Configuration.h tab (that&#039;s really a file). Most of the other files won&#039;t be necessary unless you&#039;re doing some more advanced stuff, like replacing th controller with something non-standard or similar, but then again, that&#039;s another chapter (or book, even). The video mentioned above describes this well. After flashing the new firmware, you&#039;ll probably get some timeouts and errors, since apparently it resets the printer after giving it the new firmware, but without notifying the flashing software of it doing so. If this happens, calm down and reboot the printer and check its tiny monitor - it should work. If it doesn&#039;t work, and if you flashed the bootload yourself, try to flash it again, and if that doesn&#039;t work, try flashing the programmer again yet another time, just for kicks. Again, if you have a newer controller like the v1.1.5, don&#039;t touch the bootloader, as the one already installed, should work well as it is.&lt;br /&gt;
&lt;br /&gt;
PS: I tried enabling &#039;&#039;&#039;MANUAL_MESH_LEVELING&#039;&#039;&#039;, which in the code says that &#039;&#039;If used with a 1284P board the bootscreen will be disabled to save space&#039;&#039;. This effectively disabled the whole printer, and apparently may be making the firmware image a wee bit too large for it to fit the 1284P on the ender. It works well without it, though, and it may be fixed by now, since I tested this back in early 2019.&lt;br /&gt;
&lt;br /&gt;
== And then… ==&lt;br /&gt;
&lt;br /&gt;
With the new firmware in place, the printer should work as before, although with thermal runaway protection to better avoid fires in case the shit hits the fan, and to allow for things like autolevelling. With any luck, [https://www.precisionpiezo.co.uk/ this thing] may be ready for use by the time you read this - it surely looks nice!&lt;br /&gt;
&lt;br /&gt;
= Octoprint/Octopi =&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;This could have been under some other section, but again, I just branch out even though most of it is about sections mentioned elsewhere.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
When setting up a 3d printer for the first time, you usually get an SD card for storage and transfer data to the printer using [https://en.wikipedia.org/wiki/Sneakernet Sneakernet]. Some printers use micro SD cards, while other fullsize SD cards, which imho is better, since they don&#039;t get lost that easily, but otherwise do the same thing. This works, but is somewhat tedious. If you want to control the printer from a PC or phone, there&#039;s a simple trick for that as well - octoprint.&lt;br /&gt;
&lt;br /&gt;
[https://octoprint.org/ Octoprint], written by Gina Häußge, runs on most platforms including linux, windows, BSD*, macos etc. It supports controlling a camera to some extent out of the box and there&#039;s a large number of plugins availablee to do a lot of things you possibly haven&#039;t thought of (and quite often, you&#039;d ever need). The easiest way to install it, is to just grab a Raspberry pi - preferably some of the newer models (will get to that later) and download [https://octoprint.org/download/ octopi] and follow the instructions on that page.&lt;br /&gt;
&lt;br /&gt;
== Performance issues ==&lt;br /&gt;
&lt;br /&gt;
Some report (and I have seen it myself) issues with the pi&#039;s performance with regards to both handling the octoprint processes (which should be as close to realtime as possible) and handling other stuff like I/O, networking etc. The point is that at pi3 or older, has all peripherals connected to an internal USB hub. This might be practical, but performance-wise it&#039;s &#039;&#039;&#039;&#039;&#039;not&#039;&#039;&#039;&#039;&#039;. If you in addition connect a webcam to USB, you&#039;re asking for trouble, since USB will be your bottleneck. With a raspberry pi camera, the ones connected to the pi directly with a ribbon cable, this should not use USB, so it&#039;s better. Still, again, for older pi&#039;s, there might be some shortage in therms of cpu or i/o. The octopi runs something like raspbian which is a fork of debian which is a linux distro, so it all boils down to knowing linux.&lt;br /&gt;
&lt;br /&gt;
Your typical octopi will run octoprint, a streamer, usually &#039;&#039;&#039;mjpg-streamer&#039;&#039;&#039;, a simple, lightweight videostreamer that outputs a stream of jpeg-images (about the same format as cinemas use - that is - not MPEG). This may be a bit tough on the cpu and potentially i/o. Add inn a dash of USB overload and you&#039;re may see trouble.&lt;br /&gt;
&lt;br /&gt;
Still - a pi3 should be able to handle the load, but it might help to prioritise corretly. The octoprint process is the important part here, so we could give that full priority both in CPU and I/O and. Unfortunately, it doesn&#039;t seem like the current octopi has been migrated to using systemd for the startup. We&#039;ll deal with this later. To fix this in the old SysV init style file present there, the following patch should work against the file /etc/init.d/octoprint&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;diff&amp;quot;&amp;gt;&lt;br /&gt;
--- octoprint.old	2020-07-20 18:46:10.166651965 +0200&lt;br /&gt;
+++ octoprint	2020-07-20 18:53:21.724803211 +0200&lt;br /&gt;
@@ -22,6 +22,9 @@&lt;br /&gt;
 PIDFILE=/var/run/$NAME.pid&lt;br /&gt;
 PKGNAME=octoprint&lt;br /&gt;
 SCRIPTNAME=/etc/init.d/$PKGNAME&lt;br /&gt;
+NICELEVEL=-19                        # Top CPU priority&lt;br /&gt;
+IONICE_CLASS=1                       # Realtime I/O class&lt;br /&gt;
+IONICE_PRIORITY=0                    # Realtime I/O priority (probably not needed with class=realtime)&lt;br /&gt;
&lt;br /&gt;
 # Read configuration variable file if it is present&lt;br /&gt;
 [ -r /etc/default/$PKGNAME ] &amp;amp;&amp;amp; . /etc/default/$PKGNAME&lt;br /&gt;
@@ -70,10 +73,11 @@&lt;br /&gt;
&lt;br /&gt;
    is_alive $PIDFILE&lt;br /&gt;
    RETVAL=&amp;quot;$?&amp;quot;&lt;br /&gt;
-&lt;br /&gt;
    if [ $RETVAL != 0 ]; then&lt;br /&gt;
        start-stop-daemon --start --background --quiet --pidfile $PIDFILE --make-pidfile \&lt;br /&gt;
-       --exec $DAEMON --chuid $OCTOPRINT_USER --user $OCTOPRINT_USER --umask $UMASK -- serve $DAEMON_ARGS&lt;br /&gt;
+       --exec $DAEMON --chuid $OCTOPRINT_USER --user $OCTOPRINT_USER --umask $UMASK \&lt;br /&gt;
+       --nicelevel $NICELEVEL --ioched $IONICE_CLASS:$IONICE_PRIORITY \&lt;br /&gt;
+       --serve $DAEMON_ARGS&lt;br /&gt;
        RETVAL=&amp;quot;$?&amp;quot;&lt;br /&gt;
    fi&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This ismply upgrades the process to be allowed to use most of the resources on the pi, regardless of what other processes are whining about.&lt;br /&gt;
&lt;br /&gt;
PS: Code not tested - I don&#039;t have a pi right here. Will test later, but I&#039;m pretty sure it&#039;ll work. After all, it&#039;s just a few new arguments to start-stop-daemon&lt;br /&gt;
&lt;br /&gt;
roy&lt;/div&gt;</summary>
		<author><name>Roy</name></author>
	</entry>
	<entry>
		<id>https://wiki.malinux.no/index.php?title=Roy%27s_notes&amp;diff=174</id>
		<title>Roy&#039;s notes</title>
		<link rel="alternate" type="text/html" href="https://wiki.malinux.no/index.php?title=Roy%27s_notes&amp;diff=174"/>
		<updated>2020-09-18T19:22:02Z</updated>

		<summary type="html">&lt;p&gt;Roy: /* mdadm stuff */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= LVM, md and friends =&lt;br /&gt;
&lt;br /&gt;
== Linux&#039; Logical Volume Manager (LVM) ==&lt;br /&gt;
&lt;br /&gt;
=== LVM in general ===&lt;br /&gt;
&lt;br /&gt;
LVM is designed to be an abstraction layer on top of physical drives or RAID, typically [https://raid.wiki.kernel.org/index.php/RAID_setup mdraid] or [https://help.ubuntu.com/community/FakeRaidHowto fakeraid]. Keep in mind that fakeraid should be avoided unless you really need it, like in conjunction with dual-booting linux and windows on fakeraid. LVM broadly consists of three elements, the &amp;quot;physical&amp;quot; devices (PV), the volume group (VG) and the logical volume (LV). There can be multiple PVs, VGs and LVs, depending on requirement. More about this below. All commands are given as examples, and all of them can be fine-tuned using extra flags in need of so. In my experience, the defaults work well for most usecases.&lt;br /&gt;
&lt;br /&gt;
I&#039;m mentioning filesystem below too. Where I write ext4, the samme applies to ext2 and ext3.&lt;br /&gt;
&lt;br /&gt;
==== Create a PV ====&lt;br /&gt;
&lt;br /&gt;
A PV is the &amp;quot;physical&amp;quot; parts. This does not need to be a physical disk, but can also be another RAID, be it an mdraid, fakeraid, hardware raid, a virtual disk on a SAN or otherwisee or a partition on one of those. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#  These add three PVs, one on a drive (or hardware raid) and another two on mdraids.&lt;br /&gt;
pvcreate /dev/sdb&lt;br /&gt;
pvcreate /dev/md1 /dev/md2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For more information about pvcreate, see [https://linux.die.net/man/8/pvcreate the manual].&lt;br /&gt;
&lt;br /&gt;
==== Create a VG ====&lt;br /&gt;
&lt;br /&gt;
The volume group consists of one or more PVs grouped together on which LVs can be placed. If several PVs are grouped in a VG, it&#039;s generally a good idea to make sure these PVs have some sort of redundancy, as in mdraid/fakeraid or hwraid. Otherwise it will be like using a [https://en.wikipedia.org/wiki/RAID RAID-0] with a single point of failure on each of the independant drives. LVM has [https://unix.stackexchange.com/questions/150644/raiding-with-lvm-vs-mdraid-pros-and-cons  RAID code in it] as well, so you can use that. I haven&#039;t done so myself, as I generally stick to mraid. The reason is mdraid is, in my opinion older and more stable and has more users (meaning bugs are reported and fixed faster whenever they are found). That said, I beleive the actual RAID code used in LVM RAID are the same function calls as for mdraid, so it may not be much of a difference. I still stick with mdraid. To create a VG, run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create volume group my_vg&lt;br /&gt;
vgcreate my_vg /dev/md1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that if vgcreate is run with a PV (as /dev/md1 above) that is not defined as a PV (like above), this is done implicitly, so if you don&#039;t need any special flags to pvcreate, you can simply skip it and let vgcreate do that for you.&lt;br /&gt;
&lt;br /&gt;
==== Create an LV ====&lt;br /&gt;
&lt;br /&gt;
LVs can be compared to partitions, somehow, since they are bounderies of a fraction or all of that of a VG. The difference between them and a partition, however, is that they can be grown or shrunk easily and also moved around between PVs without downtime. This flexibility makes them superiour to partitions as your system can be changed without users noticing it. By default, an LV is alloated &amp;quot;thickly&amp;quot;, meaning all the data given to it, is allocated from the VG and thus the PV. The following makes a 100GB LV named &amp;quot;thicklv&amp;quot;. When making an LV, I usually allocate what&#039;s needed plus some more, but not everything, just to make sure it&#039;s space available for growth on any of the LVs on the VG, or new LVs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a thick provisioned LV named thicklv on the VG my_vg&lt;br /&gt;
lvcreate -n thicklv -L 100G my_vg&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After the LV is created, a filesystem can be placed on it unless it is meant to be used directly. The application for direct use include swap space, VM storage and certain database systems. Most of these will, however, work on filesystems too, although my testing has shown that on swap space, there is a significant performance gain for using dedicated storage without a filesystem. As for filesystems, most Linux users use either ext4 or xfs. Personally, I generally use XFS these days. See my notes below on filesystem choice.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a filesystem on the LV - this could have been mkfs -t ext4 or whatever filesystem you choose&lt;br /&gt;
mkfs -t xfs /dev/my_vg/thicklv&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then just edit /etc/fstab with correct data and run mount -a, and you should be all set.&lt;br /&gt;
&lt;br /&gt;
==== Create LVM cache ====&lt;br /&gt;
LVMcache is LVM&#039;s solution to caching a slowish filesystem on spinning rust with the help of much faster SSDs. For this to work, use a separate SSD or a mirror or two (just in case) an add the new disk/md dev to the same VG. In this case, we use a small mirror, md1. LVM is not able to cache to a disk or partition outside the volume group.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
vgextend data /dev/md1&lt;br /&gt;
  Physical volume &amp;quot;/dev/md1&amp;quot; successfully created.&lt;br /&gt;
  Volume group &amp;quot;data&amp;quot; successfully extended&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Thn create two LVs, one for the data (contents of files) and one for the metadata (filenames, directories, attributes etc). Typically, the metadata part won&#039;t need to be very large. 100M should usually do unless you have ekstremely many small files. I guess there are ways to calculate it, but again, 1GB should do for everyone (or was that 640k?). As for the data cache, I chose to use 40G here for a 15TB RAID. It will only cache what actively use anyway, so no need for overkill.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
lvcreate -L 1G -n _cache_meta data /dev/md1&lt;br /&gt;
lvcreate -L 100G -n _cache data /dev/md1&lt;br /&gt;
&lt;br /&gt;
# Some would want --cachemode writeback, but if paranoid, I wouldn&#039;t recommend it. Metadata or data can be easily corrupted in case of failure. Most filesystems will however recover from this these days since they use journaling. It &#039;&#039;really&#039;&#039; speeds up things.&lt;br /&gt;
lvconvert --type cache-pool --cachemode writethrough --poolmetadata data/_cache_meta data/_cache&lt;br /&gt;
lvconvert --type cache --cachepool data/_cache data/data&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
That should be it. If you benchmarked the disk before this, you should try again and you&#039;ll probably get a nice surprise. If not, well, see below how to turn this off again :)&lt;br /&gt;
&lt;br /&gt;
==== Disabling LVM cache ====&lt;br /&gt;
&lt;br /&gt;
If you want to change the cached LV, such as growing og shrinking or otherwise, you&#039;ll have to disable caching first and then re-enable it. There&#039;s no quick-and-easy fix, but you just do as you did when enabling in the first place. &lt;br /&gt;
&lt;br /&gt;
Forst, disable caching for the LV. This will do it cleanly and remove the LVs earlier created for caching the main device. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
lvconvert --uncache data/data&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, since you now have a VG with an empty PV in it, earlier used for caching, I&#039;d recommend removing this for now to avoid expanding onto that as well. Since they&#039;re in the same VG, this might happen and if you get so far as to extend the lv and the filesystem on it, and this filesystem is XFS or similar filesystems without possibilities of reducing the size, you have a wee problem. &lt;br /&gt;
&lt;br /&gt;
Just remove that PV from the VG&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
vgreduce data /dev/md1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The PV is still there, but pvs should now show it not connected to a VG&lt;br /&gt;
&lt;br /&gt;
==== Growing devices ====&lt;br /&gt;
&lt;br /&gt;
LVM objects can be grown and shrunk. If a PV resides on a RAID where a new drive has been added or otherwise grown, or on a partition or virtual disk that has been extended, the PV must be updated to reflect these changes. The following command will grow the PV to the maximum available on the underlying storage. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Resize the PV /dev/md (not the RAID, only the PV on the RAID) to its full size&lt;br /&gt;
pvresize /dev/md1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If a new PV is added, the VG can be grown to add the space on that in addition to what&#039;s there already. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Extend my_vg to include md2 and its space&lt;br /&gt;
vgextend my_vg /dev/md2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
With more space available in the VG, the LV can now be extended. Let&#039;s add another 50GB to it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Extend thicklv - add 50GB. If you know you won&#039;t need the space anywhere else, you may want to&lt;br /&gt;
# lvresize -l+100%FREE instead. Keep in mind the difference between -l (extents) and -L (bytes)&lt;br /&gt;
lvresize -L +50G my_vg/thicklv&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Growing filesystems ====&lt;br /&gt;
After the LV has grown, run &#039;&#039;xfs_growfs&#039;&#039; (xfs) or &#039;&#039;resize2fs&#039;&#039; (ext4) to make use of the new data. To grow the filesystem to all available space on ext4, run the below command.  To partly grow the filesystem or to shrink it or otherwise, please see the manuals.&lt;br /&gt;
&lt;br /&gt;
The filesystem can be mounted when this is run. If you for some reason get an &#039;&#039;&#039;access denied&#039;&#039;&#039; error when running this as root or with sudo, it&#039;s likely caused by a filesystem error. To fix this, unmount the filesystem first and run &#039;&#039;&#039;fsck -f /dev/my_vg/thicklv&#039;&#039;&#039; and remount it before retrying to extend it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
resize2fs /dev/my_vg/thicklv&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Similarly, with XFS, but note that xfs_growfs doesn&#039;t take the device name, but the filesystem&#039;s mount point. In the case of XFS, also note that the filesystem &#039;&#039;&#039;&#039;&#039;must&#039;&#039;&#039;&#039;&#039; be mounted to be grown. This, in contrast to how it was in the old days when filesystems had to be unmounted to be grown.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
xfs_growfs /my_mountpoint&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Rename system VG ====&lt;br /&gt;
&lt;br /&gt;
Some distros create VG names like those-from-a-sysadmin-with-a-well-developed-paranoia-not-to-hit-a-duplicate. Debian, for instance, uses names like &amp;quot;my-full-hostname-vg&amp;quot;. Personally, I don&#039;t like these, since if I were to move a disk or vdisk around to somewhere else, I&#039;d make sure not to add a disk named &#039;sys&#039; to an existing system. If you do, most distros will refuse to use the VGs with duplicate names, resulting in the OS not booting until either one is specified by its UUID or just one removed. As I&#039;m aware of this, I stick to the super-risky thing of all system VGs named &#039;sys&#039; and so on.&lt;br /&gt;
&lt;br /&gt;
If you do this, keep in mind that it may blow up your computer and take your girl- or boyfriend with it or even make either of them pregnant, allowing Trump to rule your life and generally make things suck. You&#039;re on your own!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Rename the VG&lt;br /&gt;
vgrename my-full-hostname-vg sys&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, in /boot/grub/grub.cfg, change the old lv path from something like &#039;/dev/mapper/debian--stretch--machine--vg-root&#039; to your new and fancy &#039;/dev/sys/root. Likewise, in /etc/fstab, change occurences of &#039;/dev/mapper/debian--stretch--machine--vg-&#039; (or similar) with &#039;/dev/sys/&#039;. Here, this was like this - the old ones commented out.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;fstab&amp;quot;&amp;gt;&lt;br /&gt;
#/dev/mapper/debian--stretch--box--vg-root      /               ext4            errors=remount-ro,discard       0       1&lt;br /&gt;
/dev/sys/root                                   /               ext4            errors=remount-ro,discard       0       1&lt;br /&gt;
# /boot was on /dev/vda1 during installation&lt;br /&gt;
UUID=myverylonguuidwithatonofgoodinfoinit       /boot           ext2            defaults                        0       2&lt;br /&gt;
#/dev/mapper/debian--stretch--box--vg-swap_1    none            swap            sw                              0       0&lt;br /&gt;
/dev/sys/swap_1                                 none            swap            sw                              0       0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Update /etc/initramfs-tools/conf.d/resume with similar data for swap.&lt;br /&gt;
&lt;br /&gt;
You might want to run &#039;update-initramfs -u -k all&#039; after this, but I&#039;m not sure if it&#039;s needed.&lt;br /&gt;
&lt;br /&gt;
Now, pray to the nearest god(s) and give it a reboot and it should (probably) work.&lt;br /&gt;
&lt;br /&gt;
After reboot, run &#039;&#039;&#039;swapoff -a&#039;&#039;&#039;, then &#039;&#039;&#039;mkswap /dev/sys/swap_1&#039;&#039;&#039; (or whatever it&#039;s called on your system) and &#039;&#039;&#039;swapon -a&#039;&#039;&#039; again. You may want to give it another reboot or two for kicks, but it should work well even without that.&lt;br /&gt;
&lt;br /&gt;
=== Migration tools ===&lt;br /&gt;
&lt;br /&gt;
At times, storage regimes change, new storage is added and sometimes it&#039;s not easy to migrate with the current hardware or its support systems. Once I had to migrate a 45TiB fileserver from one storage system to another, preferably without downtime. The server originally had three 15TiB PVs of which two were full and the third half full. I resorted to using [https://linux.die.net/man/8/pvmove pvmove] to just move the data on the PVs in use to a new PV. We started out with creating a new 50TiB PV, sde, and then to pvmove.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Attach /dev/sde to the VG my_vg&lt;br /&gt;
vgextend my_vg /dev/sde&lt;br /&gt;
&lt;br /&gt;
# Move the contents from /dev/sdb over to /dev/sde block by block. If a target is not given in pvmove,&lt;br /&gt;
# the contents of the source (sdb here) will be put somewhere else in the pool.&lt;br /&gt;
pvmove /dev/sdb /dev/sde&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This took a while (as in a week or so) - the pvmove command uses old code and logic (or at least did that when I migrated this in November 2016), but it affected performance on the server very little, so users didn&#039;t notice. After the first PV was migrated, I continued with the other two, one after the other, and after a month or so, it was migrated. We used this on a number of large fileservers, and it worked flawlessly. Before doing the production servers I also tried interrupting pvmove in various ways, including hard resets, and it just kept on after the reboot.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;NOTE:&#039;&#039;&#039;&#039;&#039; &#039;&#039;Even though it worked well for us, &#039;&#039;&#039;always&#039;&#039;&#039; keep a good backup before doing this. Things may go wrong, and without a good backup, you may be looking for a hard-to-find new job the next morning&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
==== mdadm workarounds ====&lt;br /&gt;
&lt;br /&gt;
===== Migrate from a mirror (raid-1) to raid-10 =====&lt;br /&gt;
&lt;br /&gt;
Create a mirror&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sdb /dev/sdc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
LVM (pv/vg/lv) on md0 (see above), put a filesystem on the lv and fill it with some data.&lt;br /&gt;
&lt;br /&gt;
Now, some months later, you want to change this to raid-10 to allow for the same amount of redundancy, but to allow more disks into the system.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mdadm --grow /dev/md0 --level=10&lt;br /&gt;
mdadm: Impossibly level change request for RAID1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So - no - doesn&#039;t work. But - we&#039;re on &lt;br /&gt;
&lt;br /&gt;
Since we&#039;re on lvm already, this&#039;ll be easy. If you&#039;re using filesystems directly on partitions, you can do this the same way, but without the pvmove part, using rsync or whateever you like instead. I&#039;d recommend using lvm for for the new raid, which should be rather obvious from this article. Now plug in a new drive and create a new raid10 on that one. If you two new drives, install both. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# change &amp;quot;missing&amp;quot; to the other device name if you installed two new drives&lt;br /&gt;
mdadm --create /dev/md1 --level=10 --raid-devices=2 /dev/vdd missing&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, as described above, just vgextend the vg, adding the new raid and run pvmove to move the data from the old pv (residing on the old raid1) to the new pv (on raid10). Afte rpvmove is finished (which may take awile, see above), just&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
vgreduce raidtest /dev/md0&lt;br /&gt;
pvremove /dev/md0&lt;br /&gt;
mdadm --stop /dev/md0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
…and your disk is free to be added to the new array. If the new raid is running in degraded mode (if you created it with just one drive), better don&#039;t wait too long, since you don&#039;t have redundancy. Just mdadm --add the devs.&lt;br /&gt;
&lt;br /&gt;
If you now have /dev/mdstat telling you your raid10 is active and have three drives, of which one is a spare, it should look something like this&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5] [raid4] [raid10]&lt;br /&gt;
md1 : active raid10 vdc[3](S) vdb[2] vdd[0]&lt;br /&gt;
      8380416 blocks super 1.2 2 near-copies [2/2] [UU]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Just mdadm --grow --raid-devices=3 /dev/md1&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;RAID section is not complete. I&#039;ll write more on migraing from raid10 to raid6 later. It&#039;s not straight forward, but easier than this one :)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== Thin provisioned LVs ===&lt;br /&gt;
&lt;br /&gt;
Thin provisioning on LVM is a method used for not allocating all the space given to an LV. For instance, if you have a 1TB VG and want to give an LV 500GB, although it currently only uses a fraction of that, a thin lv can be a good alternative. This will allow for adding a limit to how much it can use, but also to let it grow dynamically without manual work by the sysadmin. Thin provisioning adds another layer of abstaction by creating a special LV as a &#039;&#039;thin pool&#039;&#039; from which data is allocated to the &#039;&#039;thin volume(s)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== Create a thin pool ====&lt;br /&gt;
&lt;br /&gt;
Allocate 1TB to the thin pool to be used for thinly provisioned LVs. Keep in mind that the space allocated to the thin pool is in fact thick provisioned. Only the volumes put on &#039;&#039;thinpool&#039;&#039; are thin provisioned. This will create two hidden LVs, one for data and one for metadata. Normally the defaults will do, but check the manual if the data doesn&#039;t match the usual patterns (such as billions of files, resulting in huge amounts of metadata). I &#039;&#039;beleive&#039;&#039; the metadata part should be resizable at a later time if needed, but I have not tested it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a pool for thin LVs. Keep in mind that the pool itself is not thin provisioned, only the volumes residing on it&lt;br /&gt;
lvcreate --size 1T --type thin-pool --thinpool thinpool my_vg&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Create a thin volume ====&lt;br /&gt;
&lt;br /&gt;
You have the thinpool, now put a thin volume on it. It will allocate some space for metadata, but probably not much (a few megs, perhaps).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Now, create a volume with a virtual (-V) size of half a terabyte named thin_pool, but using the thinpool (-T) named thin_pool for storage&lt;br /&gt;
lvcreate -V 500G -T my_vg/thin_pool --name thinvol&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The new volume&#039;s device name will be /dev/thinvol. Now, create a filesystem on it, add to fstab and mount it. The &#039;&#039;&#039;df&#039;&#039;&#039; command will return available space according to the virtual size (-V), while lvs will show how much data is actually used on each of the thinly provisioned volumes.&lt;br /&gt;
&lt;br /&gt;
== Filesystem dilemmas ==&lt;br /&gt;
&lt;br /&gt;
=== XFS or ext4 or something else ===&lt;br /&gt;
The choice of filesystem varies for your use. Distros such as RHEL/CentOS has moved to XFS by default from v7. Debian/Ubuntu still sticks to ext4, like most other. I&#039;ll discuss my thoughts below on ext4 vs XFS and leave the other filesystems for later.&lt;br /&gt;
&lt;br /&gt;
==== ext4 ====&lt;br /&gt;
ext4 is probably the most used filesystem on linux as of writing. It&#039;s rock stable and has been extended by a lot of extensions since the original ext2. It still retains backward compatibility, being able to mount and fsck ext2 and ext3 with the ext4 driver. However, it doesn&#039;t handle large filesystems very well. If a filesystem is created for &amp;lt;16TiB, it cannot be grown to anything larger than 16TiB. This may have changed lately, though. One other issue is handling errors. If a large filesystem (say 10TiB) is damaged, an fsck may take several hours, leading to long downtime. When I refer to ext4 further in this text, the same applies to ext2 and ext3 unless otherwise specified.&lt;br /&gt;
&lt;br /&gt;
==== XFS ====&lt;br /&gt;
XFS, originally developed by SGI some time in the bronze age, but has been worked on heavily after that. RHEL and Centos version 7 and forward, uses XFS as the default filesystem. It is quick, it scales well, but it lacks at least two things ext4 has. It cannot be shrunk (not that you normally need that, but nice if you have a typo or you need to change things). Also, it doesn&#039;t allow for automatic fsck on bootup. If something is messed up on the filesystem, you&#039;ll have to login as root on the console (not ssh), which might be an issue on some systems. The fsck equivalent, xfs_repair, is a *lot* faster than ext4&#039;s fsck, though.&lt;br /&gt;
&lt;br /&gt;
==== ZFS ====&lt;br /&gt;
ZFS is like a combination of RAID, LVM and a filesystem, supporting full checksumming, auto-healing (given sufficient redundancy), compression, encryption, replication, deduplication (if you&#039;re brave and have a &#039;&#039;ton&#039;&#039; of memory) and a lot more. It&#039;s a separate chapter and needs a lot more talk than paragraph here.&lt;br /&gt;
&lt;br /&gt;
==== btrfs ====&lt;br /&gt;
btrfs, pronounced &amp;quot;butterfs&amp;quot; or &amp;quot;betterfs&amp;quot; or just spelled out, is a filesystem that mimics that of ZFS. It has been around for 10 years or so, but hasn&#039;t yet proven to be really stable. Following the progress of it for those years, I&#039;ve found it to be a nice toy with which to play, but not to be used in production. Again, others may say otherwise, but these are just my words.&lt;br /&gt;
&lt;br /&gt;
== Low level disk handling ==&lt;br /&gt;
&lt;br /&gt;
This section is for low-level handling of disks, regardless of storage system elsewhere. These apply to mdraid, lvmraid and zfs and possibly other solutions, with the exception of individual drives on hwraid (and maybe fakeraid), since there, the drives are hidden from Linux (or whatever OS).&lt;br /&gt;
&lt;br /&gt;
=== S.M.A.R.T. and slow drives ===&lt;br /&gt;
Modern (that is, from about 1990 or later) have S.M.A.R.T. (or just smart, since it&#039;s easier to type) monitoring built in, meaning the disk&#039;s controller is monitoring itself. This is handy and will ideally tell you in advance that a drive is flakey or dying. Modern (2010+) smart monitoring is more or less the same. It can be trusted about 50% of the time. Usually, if smart detects an error, it&#039;s a real error. I don&#039;t think I&#039;ve seen it reporting a false positive, but others may know better. &lt;br /&gt;
&lt;br /&gt;
==== smartmontools ====&lt;br /&gt;
First, install smartmontool and run smartclt -H /dev/yourdisk (/dev/sda or something) to get a health report. Then perhaps run smartctl -a /dev/yourdisk and look for &#039;current pending sectors&#039; This should be zero. Also check the temperature, which normally should be much above 50.&lt;br /&gt;
&lt;br /&gt;
==== single, slow drive ====&lt;br /&gt;
What may happen, is smart not seeing anything and life goes on like before, only slower and less prouductive, without telling anyone. If you stubler over this issue, you&#039;ll probably see it during a large rsync/zfs send/receive or a resync/rebuild/resilver of the raid/zpool. During this, it feels like everything is slow and your RAID has turned into a RAIF (redundant array of inexpensive floppies). To check if you have a single drive messing up it all, check with &#039;&#039;&#039;iostat -x 2&#039;&#039;&#039;, having 2 being the delay between each measurement. Interrupt it with ctrl+x. If there&#039;s a rougue drive there, it should stand out like sdg below&lt;br /&gt;
&lt;br /&gt;
 avg-cpu:  %user   %nice %system %iowait  %steal   %idle&lt;br /&gt;
            0.38    0.00    1.75    0.00    0.00   97.87&lt;br /&gt;
&lt;br /&gt;
 Device            r/s     w/s     rkB/s     wkB/s   rrqm/s   wrqm/s  %rrqm  %wrqm r_await w_await aqu-sz rareq-sz wareq-sz  svctm  %util&lt;br /&gt;
 sda              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdb              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdc              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdd              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sde              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdf              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdg              3.50    0.00   2352.00      0.00     0.00     0.00   0.00   0.00 14306.29    0.00  13.85   672.00     0.00 285.71 100.00&lt;br /&gt;
 sdh              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
&lt;br /&gt;
In ZFS land, you should be able to get similar data with &#039;&#039;&#039;zpool iostat -v &amp;lt;pool&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Now you know the bad drive (sdg), pull it from the raid with &#039;&#039;&#039;mdadm --fail /dev/mdX /dev/sdX&#039;&#039;&#039;. Now test the drive&#039;s performance manually, just simply:&lt;br /&gt;
&lt;br /&gt;
 # hdparm -t /dev/sdg&lt;br /&gt;
 &lt;br /&gt;
 /dev/sdg:&lt;br /&gt;
  Timing buffered disk reads:   2 MB in  5.37 seconds = 381.46 kB/sec&lt;br /&gt;
&lt;br /&gt;
Bingo - nothing you&#039;d want to keep. For a good drive, it should be something like 100-200MB/s&lt;br /&gt;
&lt;br /&gt;
PS: Keep in mind that you have a degraded RAID by now in case you had a spare waiting for things to happen.&lt;br /&gt;
&lt;br /&gt;
Try to replace the cable and/or try the disk on another port/controller. If the result from hdparm persists, it&#039;s probably a bad cable&lt;br /&gt;
&lt;br /&gt;
So, then, just psycially locate the drive, pull it out, take out the discs and magnets and recycle the rest.&lt;br /&gt;
&lt;br /&gt;
=== &amp;quot;Unplug&amp;quot; drive from system ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Find the device unit&#039;s number with something like&lt;br /&gt;
find /sys/bus/scsi/devices/*/block/ -name sdd&lt;br /&gt;
# returning /sys/bus/scsi/devices/3:0:0:0/block/sdd here, &lt;br /&gt;
# meaning 3:0:0:0 is the SCSI device we&#039;re looking for.&lt;br /&gt;
&lt;br /&gt;
# Given this is the correct device, and you want to &#039;unplug&#039; it, do so by&lt;br /&gt;
echo 1 &amp;gt; /sys/bus/scsi/devices/3:0:0:0/delete&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Rescan disk controllers ===&lt;br /&gt;
If a drive is added and for some reason doesn&#039;t get detected, or is removed by the command above, it can be rediscovered with a sysfs command to the scsi host to which it is connected. Since there may be quite a few of these, an easy way is to just scan them all and check the output of &#039;&#039;&#039;dmesg -T&#039;&#039;&#039; after running it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Make a list of controllers and send a rescan message to each of them. It won&#039;t do anything &lt;br /&gt;
# for those where nothing has changed, but it will show new drives where they have been added.&lt;br /&gt;
for host_scan in /sys/class/scsi_host/host*/scan&lt;br /&gt;
do&lt;br /&gt;
  echo &#039;- - -&#039; &amp;gt; $host_scan&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Fail injection with debugfs ===&lt;br /&gt;
[https://lxadm.com/Using_fault_injection https://lxadm.com/Using_fault_injection]&lt;br /&gt;
&lt;br /&gt;
== mdadm stuff ==&lt;br /&gt;
=== Resync ===&lt;br /&gt;
To resync a raid, that is, check, run&lt;br /&gt;
&lt;br /&gt;
 echo check &amp;gt; /sys/block/$dev/md/sync_action&lt;br /&gt;
&lt;br /&gt;
where $dev is something like md0. If you have several raids, something like this should work&lt;br /&gt;
&lt;br /&gt;
 for dev in md{0,1}&lt;br /&gt;
 do&lt;br /&gt;
   echo repair &amp;gt; /sys/block/$dev/md/sync_action&lt;br /&gt;
 done&lt;br /&gt;
&lt;br /&gt;
Also useful in a one-liner like&lt;br /&gt;
&lt;br /&gt;
 for dev in md{0,1} ; do echo repair &amp;gt; /sys/block/$dev/md/sync_action ; done&lt;br /&gt;
&lt;br /&gt;
Different raids on different drives will do this in parallel. If the drives are shared somehow with partitions or similar, the check or repair will wait for the other to finish before going on.&lt;br /&gt;
&lt;br /&gt;
As for repair vs check, [https://raid.wiki.kernel.org/index.php/RAID_Administration this article] describes it well. I stick to using repair unless it&#039;s something rare where I don&#039;t want to touch the data.&lt;br /&gt;
&lt;br /&gt;
=== Spare pools ===&lt;br /&gt;
In the old itmes, mdadm supported only a dedicated spare per md device, so if working with a large set of drives (20? 40?), where you&#039;d want to setup more raid sets to increase redundancy, you&#039;d dedicate a spare to each of the raid sets. This has changed (some time ago?), so in these modern, heathen days, you can change mdadm.conf, usually placed under /etc/mdadm, and add &#039;spare-group=somegroup&#039; where &#039;somegroup&#039; is a string identifying the spare group. After doing this, run &#039;&#039;&#039;update-initramfs -u&#039;&#039;&#039; and reboot and add a spare to one of the raid sets in the spare group, and md will use that or those spares for all the raidsets in that group.&lt;br /&gt;
&lt;br /&gt;
As some pointed out on #linux-raid @ irc.freenode.net, this feature is very badly documented, but as far as I can see, it works well.&lt;br /&gt;
&lt;br /&gt;
==== Example config ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create two raidsets&lt;br /&gt;
&lt;br /&gt;
mdadm --create /dev/md1 --level=6 --raid-devices=6 /dev/vd[efghij]&lt;br /&gt;
mdadm --create /dev/md2 --level=6 --raid-devices=6 /dev/vd[klmnop]&lt;br /&gt;
&lt;br /&gt;
# get their UUID etc&lt;br /&gt;
&lt;br /&gt;
mdadm --detail --scan&lt;br /&gt;
ARRAY /dev/md/1 metadata=1.2 name=raidtest:1 UUID=1a8cbdcb:f4092350:348b6b80:c054d74c&lt;br /&gt;
ARRAY /dev/md/2 metadata=1.2 name=raidtest:2 UUID=894b1b7c:cb7eba70:917d6033:ea5afd2b&lt;br /&gt;
&lt;br /&gt;
# Put those lines into /etc/mdadm/mdadm.conf and and add the spare-group&lt;br /&gt;
&lt;br /&gt;
ARRAY /dev/md/1 metadata=1.2 name=raidtest:1 spare-group=raidtest UUID=1a8cbdcb:f4092350:348b6b80:c054d74c&lt;br /&gt;
ARRAY /dev/md/2 metadata=1.2 name=raidtest:2 spare-group=raidtest UUID=894b1b7c:cb7eba70:917d6033:ea5afd2b&lt;br /&gt;
&lt;br /&gt;
# update the initramfs and reboot&lt;br /&gt;
&lt;br /&gt;
update-initramfs -u&lt;br /&gt;
reboot&lt;br /&gt;
&lt;br /&gt;
# add a spare drive to one of the raids&lt;br /&gt;
&lt;br /&gt;
mdadm --add /dev/md1 /dev/vdq&lt;br /&gt;
&lt;br /&gt;
# fail a drive on the other raid&lt;br /&gt;
&lt;br /&gt;
mdadm --fail /dev/md2 /dev/vdn&lt;br /&gt;
&lt;br /&gt;
# check /proc/mdstat to see md2 rebuilding with the spare from md1&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Recovery ===&lt;br /&gt;
&lt;br /&gt;
The other day, I came across a problem a user had on #linux-raid@irc.freenode.net. He had an old Qnap NAS that had died and tried plugging the drives in to his Linux machine and got various errors. The two-drive RAID-1 did not come up as it should, &#039;&#039;&#039;dmesg&#039;&#039;&#039; was full of errors from one of the drives (both connected on USB) and so forth.&lt;br /&gt;
&lt;br /&gt;
We went on and started by taking down the machine and just connecting one of the drives. I had him check what was assembled with&lt;br /&gt;
&lt;br /&gt;
 cat /proc/mdstat&lt;br /&gt;
&lt;br /&gt;
That returned /proc/md127 assembled, but LVM didn&#039;t find anything. So running a manual scan&lt;br /&gt;
&lt;br /&gt;
 pvscan --cache /dev/md127&lt;br /&gt;
&lt;br /&gt;
This made linux find the PV, VG and a couple of LVs, but probably because the mdraid was degraded, the LVs were deactivated, according to &#039;&#039;&#039;lvscan&#039;&#039;&#039;. Activating the one with a filesystem manually&lt;br /&gt;
&lt;br /&gt;
 lvchange -a y /dev/&amp;lt;vg&amp;gt;/&amp;lt;lv&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Substitute &amp;lt;vg&amp;gt; and &amp;lt;lv&amp;gt; with the names listed by vgs and lvs.&lt;br /&gt;
&lt;br /&gt;
This worked, and the filesystem on /dev/&amp;lt;vg&amp;gt;/&amp;lt;lv&amp;gt; could be mounted correctly.&lt;br /&gt;
&lt;br /&gt;
=== The badblock list ===&lt;br /&gt;
&#039;&#039;&#039;md&#039;&#039;&#039; has an internal badblock list (BBL), added around 2010, to list the bad blocks on the disk to avoid using those. While this might sound like a good idea, the badblock list is updated in case of a read error, which can be caused by several things. To make things worse, the BBL is replicated to other drives when a drive fails or the array is grown. So if you start out with sda and sdb and sdb suffers some errors, nothing wrong, md will read from sda, but flag those sectors on sdb as bad. So after a while, perhaps sda dies and gets replaced, with the same content, including the BBL. Then, at some point you might to replace sdb and it, too gets the BBL. So it sticks - forever. Also, there&#039;s no real point of keeping a BBL list, since the drive has its own and even if a sector error occurs, the array will have sufficient redundancy to recover from that (unless you use RAID-0 which you shouldn&#039;t). If a drive finds a bad sector, it&#039;ll be reallocated by the drive itself without the user&#039;s/admin&#039;s/system&#039;s knowledge. If a sector can&#039;t be reallocated, it means the drive is bad and should be replaced.&lt;br /&gt;
&lt;br /&gt;
There&#039;s no official way to remove it and although you can assemble it with the no-bbl option, this will only work if there&#039;s an empty BBL. Also, this will require downtime. As far as I can see, the only way to do this currently, is with a wee hack that should work. Just replace the names of mddev/diskdev with your own.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
mddev=&amp;quot;/dev/md0&amp;quot;&lt;br /&gt;
diskdev=&amp;quot;/dev/sda&amp;quot;&lt;br /&gt;
mdadm $mddev --fail $diskdev --remove $diskdev --re-add $diskdev --update=no-bbl&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
I haven&#039;t found a way to turn this off permanently, but there may be something coming around when the debate on the linux-raid mailing list closes up on this. There&#039;s a bbl=no in mdadm.conf, but that&#039;s only for creation. I will continue extensive testing for this.&lt;br /&gt;
&lt;br /&gt;
== Tuning ==&lt;br /&gt;
&lt;br /&gt;
While trying to compare a 12-disk RAID (8TB disks) to a hwraid, mdraid was slower, so we did a few things to speed things up:&lt;br /&gt;
&lt;br /&gt;
While testing with [https://linux.die.net/man/1/fio fio], monitor /sys/block/md0/md/stripe_cache_active, and see if it&#039;s close to /sys/block/md0/md/stripe_cache_size. If it is, double the size of the latter&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
echo 4096 &amp;gt; /sys/block/md0/md/stripe_cache_size&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Continue until stripe_cache_active stabilises, and then you&#039;ve found the limit you&#039;ll need. You may want to double that for good measure. &lt;br /&gt;
&lt;br /&gt;
(to be continued)&lt;br /&gt;
&lt;br /&gt;
== Links ==&lt;br /&gt;
&lt;br /&gt;
Below are a few links with useful info&lt;br /&gt;
&lt;br /&gt;
* [https://raid.wiki.kernel.org/index.php/Irreversible_mdadm_failure_recovery Irreversible mdadm failure recovery]&lt;br /&gt;
&lt;br /&gt;
= ZFS =&lt;br /&gt;
&lt;br /&gt;
ZFS can do a lot of things most filesystems or volume managers can&#039;t. It checksums all data and metadata and so long that the system uses ECC enabled memory (RAM), it will have complete control over the whole data set, and when (not if) an error occurs, it&#039;ll fix the issue without even throwing a warning. To fix the issue, you&#039;ll obviously need sufficient redundancy (mirrors or RAIDzN). &lt;br /&gt;
&lt;br /&gt;
== ZFS send/receive between machines ==&lt;br /&gt;
&lt;br /&gt;
ZFS has a send/receive mechanism that allows for snapshots to be sent over the wire to a receiving end. This can be a full filesystem, or an incremental change since last send/reveive. In a WAN scenario, you&#039;ll probably want to use VPN for this. On a controlled network, sending in cleartext is also possible. You may as well use ssh, but keep in mind that ssh was never designed to be used as a fullblown vpn solution and is just too slow or the task with large amounts of data. You may, though, use mbuffer, if on a loal LAN.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Allow traffic from the sending IP in whatever firewall interface you&#039;re using (if you&#039;re using a firewall at all, that is)&lt;br /&gt;
ufw allow from x.x.x.x&lt;br /&gt;
# &lt;br /&gt;
# Start the receiver first. This listens on port 9090, has a 1GB buffer,&lt;br /&gt;
    and uses 128kb chunks (same as zfs):&lt;br /&gt;
&lt;br /&gt;
mbuffer -s 128k -m 1G -I 9090 | zfs receive data/filesystem&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To be continued one day… See [https://everycity.co.uk/alasdair/2010/07/using-mbuffer-to-speed-up-slow-zfs-send-zfs-receive/ this] for some more. I&#039;ll get back with details on it.&lt;br /&gt;
&lt;br /&gt;
= General Linux system control =&lt;br /&gt;
&lt;br /&gt;
== Add a new CPU (core) ==&lt;br /&gt;
&lt;br /&gt;
If working with virtual machines, adding a new core can be useful if the VM is slow and the load is multithreaded or multiprocess. To do this, add a new CPU in the hypervisor (be it KVM or VMware or Hyper-V or whatever). Some hypervisors, like VMware, will activate it automatically if open-vm-tools is installed. Please note that open-vm-tools is for VMware only. I don&#039;t know of any such thing for KVM or other hypervisors (although I beleive VirtualBox has its own set of tools, but not as a package). If this doesn&#039;t work, run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
echo 1 &amp;gt; /sys/devices/system/cpu/cpuX/online&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where X is the CPU number you want to add. You can &#039;cat /sys/devices/system/cpu/cpuX/online&#039; to check if it&#039;s online.&lt;br /&gt;
&lt;br /&gt;
= Mount partitions on a disk image =&lt;br /&gt;
&lt;br /&gt;
Sometimes you&#039;ll have a disk image, either from recovering a bad drive after hours (or days or weeks) of ddrescue, and sometimes you just have a disk image from a virtual machine where you want to mount the partitions inside the image. There are three main methods of doing this, which are more or less synonmous, but some easier than the other.&lt;br /&gt;
&lt;br /&gt;
== Basics ==&lt;br /&gt;
&lt;br /&gt;
A disk image is usually like a disk, consisting of either a large filesystem, a PV or a partition table with one or partitions onto which resides a filesystem, a pv, swap or something else. If it&#039;s partitioned, and you want your operating system to mount a filesystem or allow it to see whatever LVM stuff lies on it, you need to isolate the partitions. &lt;br /&gt;
&lt;br /&gt;
== Manual mapping ==&lt;br /&gt;
&lt;br /&gt;
In the oldern days, this was done manually, something like this&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
root@mymachine:~# fdisk -l /dev/vda&lt;br /&gt;
Disk /dev/vda: 25 GiB, 26843545600 bytes, 52428800 sectors&lt;br /&gt;
Units: sectors of 1 * 512 = 512 bytes&lt;br /&gt;
Sector size (logical/physical): 512 bytes / 512 bytes&lt;br /&gt;
I/O size (minimum/optimal): 512 bytes / 512 bytes&lt;br /&gt;
Disklabel type: dos&lt;br /&gt;
Disk identifier: 0xc37b7ea5&lt;br /&gt;
&lt;br /&gt;
Device     Boot    Start      End  Sectors  Size Id Type&lt;br /&gt;
/dev/vda1  *        2048 50333311 50331264   24G 83 Linux&lt;br /&gt;
/dev/vda2       50333312 52426369  2093058 1022M  5 Extended&lt;br /&gt;
/dev/vda5       50333314 52426369  2093056 1022M 82 Linux swap / Solaris&lt;br /&gt;
root@mymachine:~#&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To calculate the start and end of each partition, you just take the start sector and multiply it by the sector size (512 bytes here) and you have the offset in bytes. After this, it&#039;s merely an losetup -o &amp;lt;offset&amp;gt; /dev/loopX &amp;lt;nameofimagefile&amp;gt; and you have the partition mapped to your /dev/loopX (having X being something typically 0-255. After this, just mount it or run pvscan/vgscan/lvscan to probe whatever lvm config is there, and you should be able to mount it like any other filesystem.&lt;br /&gt;
&lt;br /&gt;
== kpartx ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;kpartx&#039;&#039;&#039; does the same as above, more or less, just without so much hassle. Most of it should be automatic and easy to deal with, except it may fail to disconnect the loopback devices sometimes, so you may have to &#039;&#039;&#039;losetup -d&#039;&#039;&#039; them manually. See the manual, &#039;&#039;&#039;kpartx (8)&#039;&#039;&#039;. Please note that &#039;&#039;&#039;partx&#039;&#039;&#039; works similarly and I&#039;d guess the authors of the two tools are arguing a lot of which one&#039;s the best.&lt;br /&gt;
&lt;br /&gt;
== guestmount ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;guestmount&#039;&#039;&#039; is something similar again, but also supports file formats like &#039;&#039;&#039;qcow2&#039;&#039;&#039; and possibly other, proprietary filesystems like &#039;&#039;&#039;vmdk&#039;&#039;&#039; and &#039;&#039;&#039;vdi&#039;&#039;&#039;, but don&#039;t take my word for it - I haven&#039;t tested. Again, see the manual or just read up on the description [http://ask.xmodulo.com/mount-qcow2-disk-image-linux.html?fbclid=IwAR3snTeZvGzp9PLdX11EQhCfOpux6I93CiJ3A2pUomkkRLly9Xo4851mkTY here]. It seems rather trivial.&lt;br /&gt;
&lt;br /&gt;
= Linux on laptops =&lt;br /&gt;
&lt;br /&gt;
== Wifi with HP EliteBook 725/745 on Ubuntu ==&lt;br /&gt;
&lt;br /&gt;
The HP EliteBook 725/745 and similar are equipped with a BCM4352 wifi chip. As with a lot of other stuff from Broadcom, this lacks an open hardware description, so thus no open driver exist. The proper fix, is to replace the NIC with something with an open driver, but again, this isn&#039;t always possible, so a binary driver exists. In ubuntu, run, somehow connect the machine to the internet and run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install bcmwl-kernel-source&lt;br /&gt;
sudo modprobe wl&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you can&#039;t connect the machine to the internet, download the needed packages on another machine and put it on some usb storage. These packages should suffice:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# apt-cache depends bcmwl-kernel-source&lt;br /&gt;
bcmwl-kernel-source&lt;br /&gt;
  Depends: dkms&lt;br /&gt;
  Depends: linux-libc-dev&lt;br /&gt;
  Depends: libc6-dev&lt;br /&gt;
  Conflicts: &amp;lt;bcmwl-modaliases&amp;gt;&lt;br /&gt;
  Replaces: &amp;lt;bcmwl-modaliases&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then install manually with &#039;&#039;&#039;dpkg -i file1.deb file2.deb&#039;&#039;&#039; etc&lt;br /&gt;
&lt;br /&gt;
After this, ip/ifconfig/iwconfig shouldd see the new wifi nic, probably &#039;&#039;&#039;wlan0&#039;&#039;&#039;, but due to a [https://bugs.launchpad.net/ubuntu/+source/broadcom-sta/+bug/1343151 old, ignored bug], you won&#039;t find any wifi networks. This is because the driver from Broadcom apparently does not support interrupt remapping, commonly used on x64 machines. To turn this off, change &#039;&#039;&#039;/etc/default/grub&#039;&#039;&#039; and change the line &#039;&#039;&#039;GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;quiet splash&amp;quot;&#039;&#039;&#039;, adding intremap=off to the end before the quote: &#039;&#039;&#039;GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;quiet splash intremap=off&amp;quot;&#039;&#039;&#039;. Save the file and run &#039;&#039;&#039;sudo update-grub&#039;&#039;&#039; and reboot. After this, wifi should work well.&lt;br /&gt;
&lt;br /&gt;
== Wifi with HP Compaq Presario CQ57 on Ubuntu ==&lt;br /&gt;
&lt;br /&gt;
The HP Compaq Presario CQ57 uses the RT5390 wifi chipset. This has been supported for quite some time now, and I was quite surprised to find it not working on a laptop a friend was having. The driver loaded correctly, but Ubuntu insisted of the laptop being in &#039;&#039;&#039;flight mode&#039;&#039;&#039;. Checking &#039;&#039;&#039;rfkill&#039;&#039;&#039;, it showed me two NICs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# rfkill list all&lt;br /&gt;
0: phy0: Wireless LAN&lt;br /&gt;
	Soft blocked: no&lt;br /&gt;
	Hard blocked: yes&lt;br /&gt;
1: hp-wifi: Wireless LAN&lt;br /&gt;
	Soft blocked: yes&lt;br /&gt;
	Hard blocked: no&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Turning rfkill on and off resulted in nothing much, except some error messages in the kernel log (dmesg)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] ACPI Error: Field [B128] at bit offset/length 128/1024 exceeds size of target Buffer (160 bits) (20170831/dsopcode-235)&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]&lt;br /&gt;
                            Initialized Local Variables for Method [HWCD]:&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Local0: 00000000a34b7928 &amp;lt;Obj&amp;gt;           Integer 0000000000000000&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Local1: 00000000b0aa6865 &amp;lt;Obj&amp;gt;           Buffer(8) 46 41 49 4C 04 00 00 00&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Local5: 00000000a9811efd &amp;lt;Obj&amp;gt;           Integer 0000000000000004&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] Initialized Arguments for Method [HWCD]:  (2 arguments defined for method invocation)&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Arg0:   0000000078957d1b &amp;lt;Obj&amp;gt;           Integer 0000000000000001&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Arg1:   00000000725c9c6e &amp;lt;Obj&amp;gt;           Buffer(20) 53 45 43 55 02 00 00 00&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] ACPI Error: Method parse/execution failed \_SB.WMID.HWCD, AE_AML_BUFFER_LIMIT (20170831/psparse-550)&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] ACPI Error: Method parse/execution failed \_SB.WMID.WMAD, AE_AML_BUFFER_LIMIT (20170831/psparse-550)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After upgrading BIOS and testing different kernels, I was asked to try to unload the &#039;&#039;&#039;hp_wmi&#039;&#039;&#039; driver. I did, and things changed a bit, so I tried blacklisting it, creating the file &#039;&#039;&#039;/etc/modprobe.d/blacklist-hp_wmi.conf&#039;&#039;&#039; with the following content&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Blacklist this - it doesn&#039;t work!&lt;br /&gt;
blacklist hp_wmi&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
I gave the machine a reboot and afte that, the &#039;&#039;&#039;hp-wifi&#039;&#039;&#039; entry was gone in the rfkill output, and things works.&lt;br /&gt;
&lt;br /&gt;
= Raspberry pi =&lt;br /&gt;
&lt;br /&gt;
I couldn&#039;t quite decide if the raspberry pi should be a separate section or part of Linux, but hell, it can run more than Linux, although 99,lots% of people just uses Linux on them. This is a small list of things to know about them; things not on the front page of the manual or perhaps hidden even better.&lt;br /&gt;
&lt;br /&gt;
== Which pi? ==&lt;br /&gt;
&lt;br /&gt;
I just setup three raspberry pi machines and although some are quite different, like v1 to vEverythingelse or the Pi zero versions to the normal ones, not all of us remember how to distinguish between them, and sometimes they&#039;re in a nice 3d printed (or otherwise) chassis or otherwise hidden. So, how to check three different ones:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
root@home-assistant:~ $ cat /proc/device-tree/model ; echo&lt;br /&gt;
Raspberry Pi 2 Model B Rev 1.1&lt;br /&gt;
&lt;br /&gt;
root@green-pi:~ $ cat /proc/device-tree/model ; echo&lt;br /&gt;
Raspberry Pi 3 Model B Rev 1.2&lt;br /&gt;
&lt;br /&gt;
roy@yellow-pi:~ $cat /proc/device-tree/model ; echo&lt;br /&gt;
Raspberry Pi 4 Model B Rev 1.1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
While this works well, for the latter, the pi4, it doesn&#039;t tell how much memory I have. It comes in variants of 1, 2 and 4GB, and this is the latter.&lt;br /&gt;
&lt;br /&gt;
== Monitoring ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;vcgencmd&#039;&#039;&#039; from &#039;&#039;&#039;/opt/vc/bin&#039;&#039;&#039;, but symlinked to &#039;&#039;&#039;/usr/bin&#039;&#039;&#039; so it&#039;s available in path, is useful for fetching hardware info about the pi. For example, measuring the temperature&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
root@yellow-pi:~# vcgencmd measure_temp&lt;br /&gt;
temp=63.0&#039;C&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The command is generally badly documented and parts of it seems outdated for newer hardware. Here&#039;s the output from a Raspberry pi 4 with 4GB RAM&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
roy@yellow-pi:~ $ vcgencmd get_mem arm&lt;br /&gt;
arm=948M&lt;br /&gt;
roy@yellow-pi:~ $ vcgencmd get_mem gpu&lt;br /&gt;
gpu=76M&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= BIOS upgrade from Linux =&lt;br /&gt;
&lt;br /&gt;
Generally, BIOS upgrades have been moved to the BIOS itself these days. This saves a lot of work and quite possibly lives after those who earier rammed their heads through walls, now can upgrade directly from the internet instead of using obscure operating systems best avoided. Sometimes, however, one must use these nevertheless. This is a quick run-through on your options.&lt;br /&gt;
&lt;br /&gt;
== DOS ==&lt;br /&gt;
&lt;br /&gt;
Most non-automatic BIOS upgrades are installed from DOS. Doing a BIOS upgrade this way, is generally non-problematic. Just install a USB thingie with [https://www.freedos.org/ FreeDOS], copy your file(s) onto the thing and boot on it. The commandline is the same as old MS/DOS, except a wee bit more userfriendly, but not a lot.&lt;br /&gt;
&lt;br /&gt;
== Windows ==&lt;br /&gt;
&lt;br /&gt;
Some macahines, like laptops from &#039;&#039;&#039;HP&#039;&#039;&#039;, may have BIOS upgrades that are made to be installed from Windows and won&#039;t run in FreeDOS or MS/DOS, instead throwing an error, saying &#039;&#039;&#039;This program cannot be run in DOS mode&#039;&#039;&#039;. This means you&#039;ll have to boot on a Windows rescue disc and do the job from there. Googling this, tells you it&#039;s quite easy, you just choose &#039;make rescue disc&#039; from Windows, and it&#039;s all good, except if you don&#039;t run Windows, that is. To remedy this problem, do as follows:&lt;br /&gt;
&lt;br /&gt;
=== Download Windows ===&lt;br /&gt;
&lt;br /&gt;
Since you don&#039;t run Windows and possibly don&#039;t have a spouse or friend around with such unhealthy habits either, you need to get it. It&#039;s quite easy - just google &#039;download windows&#039; and it&#039;ll send you to [https://www.microsoft.com/en-us/software-download/windows10ISO somewhere like this].&lt;br /&gt;
&lt;br /&gt;
=== Burn it! ===&lt;br /&gt;
&lt;br /&gt;
Now it&#039;s time to burn the installer on a DVD ROM. You&#039;ll need a double-layered one, since the OS is &amp;gt; 4.7GiB, but I&#039;m sure you have a ton of those lying around. Now, just place your optical medium in your optical drive and burn, baby, burn!&lt;br /&gt;
&lt;br /&gt;
=== Or make a USB thing? ===&lt;br /&gt;
&lt;br /&gt;
Not a lot of machines have optical drives these days, so you may want to use an USB pen drive or something instead. This is easy, just make the USB bootable with the Windows application Microsoft has made for this. Unfortunately, this only runs on Windows, and unlike stuff like Debian, where the &#039;&#039;&#039;iso&#039;&#039;&#039; file can be dd&#039;ed directly onto a USB drive to make it bootable, the Windows &#039;&#039;&#039;iso&#039;&#039;&#039;s don&#039;t come with this luxury. There are lots of methods to make bootable USB things from iso files out there, but the only thing most of them have in common, is that they generally don&#039;t work.&lt;br /&gt;
&lt;br /&gt;
==== WoeUSB ====&lt;br /&gt;
&lt;br /&gt;
After hours of swearing, it&#039;s nice to come across software like [https://github.com/slacka/WoeUSB WoeUSB]. It may not be perfect, it relies on a bunch of GUI stuff you&#039;ll never need and so on, but it &#039;&#039;&#039;&#039;&#039;works&#039;&#039;&#039;&#039;&#039;, and that&#039;s the important part! Just clone the repo and RTFM and it&#039;s all nice. It&#039;s slow, but hell, getting a windows machine and/or an optical drive might be slower.&lt;br /&gt;
&lt;br /&gt;
WoeUSB does nothing fancy, but it &#039;&#039;&#039;does&#039;&#039;&#039; work. It will create a filesystem, FAT32 or NTFS (better use NTFS, FAT32 has its limits). It creates normal filesystems and so on. Just make sure to copy in the BIOS update file, usually an exe file, to run when Windows is up and running.&lt;br /&gt;
&lt;br /&gt;
==== Install BIOS ====&lt;br /&gt;
&lt;br /&gt;
Boot on the Windows USB thing and choose &#039;repair computer&#039; and then &#039;command prompt&#039;. Find the install file, and if you&#039;re lucky, you&#039;ll find it needs a 32bit OS, just like I did. Since the 64bit version doesn&#039;t include 32bit compatibility in the installer, revert to downloading the 32bit version of windows and start over. Pray to your favourite god(s) not to get across such machines again - it might help.&lt;br /&gt;
&lt;br /&gt;
= 3D printer stuff =&lt;br /&gt;
&lt;br /&gt;
Below are a number of not very ordered paragraphs about 3D printer related stuff, mostly based on my experience. Their content may be interesting or perhaps practical knowledge, but then, that depends on the reader.&lt;br /&gt;
&lt;br /&gt;
== 3D printer related introductions on youtube or elsewhere ==&lt;br /&gt;
&lt;br /&gt;
First off, I&#039;d like to mention some youtube videos that are all (or mostly) a nice start if you&#039;re new to 3D printers.&lt;br /&gt;
&lt;br /&gt;
=== [https://www.youtube.com/watch?v=nb-Bzf4nQdE&amp;amp;list=PLDJMid0lOOYnkcFhz6rfQ6Uj8x7meNJJx Thomas Salanderer&#039;s 10-video series on 3D printing basics] ===&lt;br /&gt;
&lt;br /&gt;
Thomas Salanderer is a an experienced 3D printer user/admin/fixer/etc and he has a lot of interesting videos. Some accuse him for being a [Prusa https://www.prusa3d.com/] fanboy, which he quite obviously is, but that doesn&#039;t stop him from making interesting and somewhat neutral videos. The series walks you thought the first steps of how things work and so on and hopefully opens more doors than anything else I&#039;ve seen.&lt;br /&gt;
&lt;br /&gt;
=== [https://www.youtube.com/watch?v=rp3r921DBGI Teaching Tech&#039;s &amp;quot;3D printer tuning reborn&amp;quot;] ===&lt;br /&gt;
&lt;br /&gt;
Teaching Tech is, like Salanderer or even more, good pedagogically and explains a lot. They (or he) do a bunch of testing and describing pros and cons with different things, just like other youtubers in the sme business. The mentioned video shows how to tune a 3D printer after you have first learned the basics, and leans on a webpage made to help you out without too much manual work.&lt;br /&gt;
&lt;br /&gt;
This was a short list, but I guess it&#039;ll grow over time.&lt;br /&gt;
&lt;br /&gt;
== Hydrophilic filament ==&lt;br /&gt;
&lt;br /&gt;
Most popular filament types, including PLA, PETG, PP or PA (Polyamide, normally known as Nylon) and virtualy any filament type named [https://www.matterhackers.com/news/filament-and-water poly-something] (and thus with an acronym of P-something) are hydrophilic (also (somewhat incorrectly) called hydroscopic), meaning so long they&#039;re dryer than the atmosphere around them, they&#039;ll do their best to suck out the atmosphere&#039;s humidity. This is why most filament are shrink-wrapped with a small bag of silica gel in it. If such filament is exposed for normal humid air for some time, it&#039;ll become very hard to use. Most of my experience is with PLA, which can handle a bit (depending on make), but still not a lot. With PLA, if you end up with prints where the filament seems not to stick, it may help with a higher temperature. Otherwise, the filament must be [https://all3dp.com/2/how-to-dry-filament-pla-abs-and-nylon/ baked]. If you don&#039;t want to use your oven, try something like a [https://www.jula.no/catalog/hjem-og-husholdning/kjokkenmaskiner/mattilberedningsapparater/frukt-sopptorker/frukt-sopptorker-001641/#tab02 fruit and mushroom dryer]. Then get a good, sealble plastic box and add something like half a kilogram of [https://www.ebay.com/sch/sis.html?_nkw=1KG+Orange+Replacement+Desiccant+Indicating+Silica+Gel+Beads+for+Drawers%2C+Camera&amp;amp;_id=131938742628&amp;amp;&amp;amp;_trksid=p2057872.m2749.l2658 silica gel] to an old sock, tie it and put it in the your new dry box.&lt;br /&gt;
&lt;br /&gt;
Please note that ABS is hydrophobic, so you won&#039;t have to worry too much there. Also, remember that PA/Nylon is extremely hydrophilic. Even a couple of days in normal air humidity can ruin it completely and will require baking.&lt;br /&gt;
&lt;br /&gt;
== Upgrading the firmware on an Ender 3 ==&lt;br /&gt;
&lt;br /&gt;
This is about upgrading the firmware, and thus also flashing a bootloader to the Creality Ender 3 3D printer. Most of this is well documented on several place, like o [https://www.youtube.com/watch?v=fIl5X2ffdyo the video from Teaching tech] and elsewhere, but I&#039;ll just summarise some issues I had.&lt;br /&gt;
&lt;br /&gt;
=== Using an arduino Nano as a programmer ===&lt;br /&gt;
&lt;br /&gt;
Quick note before you read on. If you have an Ender 3 controller version 1.1.5 or newer (or perhaps even a bit older), a CR-10S or some other more or less modern printers or controllers, they come with a bootloader installed already, so don&#039;t bother flashing one. The one that&#039;s in there already, should work well. So if you have one of these, just skip this and jump to the [[Roy&#039;s_notes#Flashing_the_printer|next section]].&lt;br /&gt;
&lt;br /&gt;
However, the normal CR-10 (without the S), Ender 3 and a few other printers from Creality come without a bootloader, so you&#039;ll need to flash one before upgrading the firmware. Well, strictly speakning, you don&#039;t need one, you can save those 8kB or so for other stuff and use a programmer to write the whole firmware, but then you&#039;ll need to wire up everything every time you want a new firmware, so in my world, you &#039;&#039;&#039;do&#039;&#039;&#039; need the bootloader, since it&#039;s easier.&lt;br /&gt;
&lt;br /&gt;
To install a bootloader, you&#039;ll need a programmer, and I didn&#039;t have one available. Having some el-cheapo china-copies of Arduinos around, I read I could use one and tried so. Although the docs mostly mention the Uno etc, it&#039;s just as simple with the Nano copy.&lt;br /&gt;
&lt;br /&gt;
So, grab an arduino, plug it to your machine with a USB cable, and, using the Arduino IDE, use the ArduinoISP sketch there (found under Examples) to burn the software needed for the arduino to work as a programmer. When this is done, connect a 10µF capacitor between RST and GND to stop it from resetting when used as a programmer. Connect the MOSI, MISO and SCK pins from the ICSP block (that little isolated 6-pin block on top of the ardu). See [https://www.arduino.cc/en/Tutorial/ArduinoISP here] for a pinout. Then find Vcc and GND either on the ICSP block or elsewhere. Some sites say that on some boards you shouldn&#039;t use the pins on the ICSP block for this. I doubt it matters, though. Then connect another jumper wire from pin 10 on the ardu to work as the reset pin outwards to the chip being programmed (that is, on the printer). The ICSP jumper block pin layout is the same on the printer and on the ardu, and probably elsewhere. Sometimes [https://xkcd.com/927/ standardisation] actually works…&lt;br /&gt;
&lt;br /&gt;
See https://cloud.karlsbakk.net/index.php/s/zw48YJjzaf8Rc2F for a pic with the ardu (this wiki is broken atm, will fix it later)&lt;br /&gt;
&lt;br /&gt;
== Flashing the printer ==&lt;br /&gt;
&lt;br /&gt;
When the boot loader is in place, possibly after some wierd errors from during the process, the screen on the 3d printer will go blank and it&#039;ll behave like being bricked. This is ok. Now disconnect the wires and connect the USB cable between computer and printer. If you haven&#039;t installed support for the Sanguino board, that is, the variant of the 1284-chip and surrounding electronics that is the core of the, you need to install it first. In the Arduino IDE, choose the Tools / Boards / Boards manager boot option and search for Sanguino. After this, you should find the Sanguino or Sanguino 1284p in the boards menu. After this, you should be able to communicate with the printer&#039;s controller. Download the [https://www.th3dstudio.com/knowledgebase/th3d-unified-firmware-package/ TH3D unified firmware], making sure it&#039;s the last version. Uncompress the zip and with Finder/Explorer/whateversomething&#039;scalledonlinux, browse to &#039;&#039;&#039;TH3DUF_R2/Firmware/TH3DUF_R2.ino&#039;&#039;&#039; and open it. It should open directly in the Android IDE. Keep in mind that the names TH3DUF_R2 and TH3DUF_R2.ino will vary between versions, but you get the point. Now configure it for your particular needs. You&#039;ll find most of this in the Configuration.h tab (that&#039;s really a file). Most of the other files won&#039;t be necessary unless you&#039;re doing some more advanced stuff, like replacing th controller with something non-standard or similar, but then again, that&#039;s another chapter (or book, even). The video mentioned above describes this well. After flashing the new firmware, you&#039;ll probably get some timeouts and errors, since apparently it resets the printer after giving it the new firmware, but without notifying the flashing software of it doing so. If this happens, calm down and reboot the printer and check its tiny monitor - it should work. If it doesn&#039;t work, and if you flashed the bootload yourself, try to flash it again, and if that doesn&#039;t work, try flashing the programmer again yet another time, just for kicks. Again, if you have a newer controller like the v1.1.5, don&#039;t touch the bootloader, as the one already installed, should work well as it is.&lt;br /&gt;
&lt;br /&gt;
PS: I tried enabling &#039;&#039;&#039;MANUAL_MESH_LEVELING&#039;&#039;&#039;, which in the code says that &#039;&#039;If used with a 1284P board the bootscreen will be disabled to save space&#039;&#039;. This effectively disabled the whole printer, and apparently may be making the firmware image a wee bit too large for it to fit the 1284P on the ender. It works well without it, though, and it may be fixed by now, since I tested this back in early 2019.&lt;br /&gt;
&lt;br /&gt;
== And then… ==&lt;br /&gt;
&lt;br /&gt;
With the new firmware in place, the printer should work as before, although with thermal runaway protection to better avoid fires in case the shit hits the fan, and to allow for things like autolevelling. With any luck, [https://www.precisionpiezo.co.uk/ this thing] may be ready for use by the time you read this - it surely looks nice!&lt;br /&gt;
&lt;br /&gt;
= Octoprint/Octopi =&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;This could have been under some other section, but again, I just branch out even though most of it is about sections mentioned elsewhere.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
When setting up a 3d printer for the first time, you usually get an SD card for storage and transfer data to the printer using [https://en.wikipedia.org/wiki/Sneakernet Sneakernet]. Some printers use micro SD cards, while other fullsize SD cards, which imho is better, since they don&#039;t get lost that easily, but otherwise do the same thing. This works, but is somewhat tedious. If you want to control the printer from a PC or phone, there&#039;s a simple trick for that as well - octoprint.&lt;br /&gt;
&lt;br /&gt;
[https://octoprint.org/ Octoprint], written by Gina Häußge, runs on most platforms including linux, windows, BSD*, macos etc. It supports controlling a camera to some extent out of the box and there&#039;s a large number of plugins availablee to do a lot of things you possibly haven&#039;t thought of (and quite often, you&#039;d ever need). The easiest way to install it, is to just grab a Raspberry pi - preferably some of the newer models (will get to that later) and download [https://octoprint.org/download/ octopi] and follow the instructions on that page.&lt;br /&gt;
&lt;br /&gt;
== Performance issues ==&lt;br /&gt;
&lt;br /&gt;
Some report (and I have seen it myself) issues with the pi&#039;s performance with regards to both handling the octoprint processes (which should be as close to realtime as possible) and handling other stuff like I/O, networking etc. The point is that at pi3 or older, has all peripherals connected to an internal USB hub. This might be practical, but performance-wise it&#039;s &#039;&#039;&#039;&#039;&#039;not&#039;&#039;&#039;&#039;&#039;. If you in addition connect a webcam to USB, you&#039;re asking for trouble, since USB will be your bottleneck. With a raspberry pi camera, the ones connected to the pi directly with a ribbon cable, this should not use USB, so it&#039;s better. Still, again, for older pi&#039;s, there might be some shortage in therms of cpu or i/o. The octopi runs something like raspbian which is a fork of debian which is a linux distro, so it all boils down to knowing linux.&lt;br /&gt;
&lt;br /&gt;
Your typical octopi will run octoprint, a streamer, usually &#039;&#039;&#039;mjpg-streamer&#039;&#039;&#039;, a simple, lightweight videostreamer that outputs a stream of jpeg-images (about the same format as cinemas use - that is - not MPEG). This may be a bit tough on the cpu and potentially i/o. Add inn a dash of USB overload and you&#039;re may see trouble.&lt;br /&gt;
&lt;br /&gt;
Still - a pi3 should be able to handle the load, but it might help to prioritise corretly. The octoprint process is the important part here, so we could give that full priority both in CPU and I/O and. Unfortunately, it doesn&#039;t seem like the current octopi has been migrated to using systemd for the startup. We&#039;ll deal with this later. To fix this in the old SysV init style file present there, the following patch should work against the file /etc/init.d/octoprint&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;diff&amp;quot;&amp;gt;&lt;br /&gt;
--- octoprint.old	2020-07-20 18:46:10.166651965 +0200&lt;br /&gt;
+++ octoprint	2020-07-20 18:53:21.724803211 +0200&lt;br /&gt;
@@ -22,6 +22,9 @@&lt;br /&gt;
 PIDFILE=/var/run/$NAME.pid&lt;br /&gt;
 PKGNAME=octoprint&lt;br /&gt;
 SCRIPTNAME=/etc/init.d/$PKGNAME&lt;br /&gt;
+NICELEVEL=-19                        # Top CPU priority&lt;br /&gt;
+IONICE_CLASS=1                       # Realtime I/O class&lt;br /&gt;
+IONICE_PRIORITY=0                    # Realtime I/O priority (probably not needed with class=realtime)&lt;br /&gt;
&lt;br /&gt;
 # Read configuration variable file if it is present&lt;br /&gt;
 [ -r /etc/default/$PKGNAME ] &amp;amp;&amp;amp; . /etc/default/$PKGNAME&lt;br /&gt;
@@ -70,10 +73,11 @@&lt;br /&gt;
&lt;br /&gt;
    is_alive $PIDFILE&lt;br /&gt;
    RETVAL=&amp;quot;$?&amp;quot;&lt;br /&gt;
-&lt;br /&gt;
    if [ $RETVAL != 0 ]; then&lt;br /&gt;
        start-stop-daemon --start --background --quiet --pidfile $PIDFILE --make-pidfile \&lt;br /&gt;
-       --exec $DAEMON --chuid $OCTOPRINT_USER --user $OCTOPRINT_USER --umask $UMASK -- serve $DAEMON_ARGS&lt;br /&gt;
+       --exec $DAEMON --chuid $OCTOPRINT_USER --user $OCTOPRINT_USER --umask $UMASK \&lt;br /&gt;
+       --nicelevel $NICELEVEL --ioched $IONICE_CLASS:$IONICE_PRIORITY \&lt;br /&gt;
+       --serve $DAEMON_ARGS&lt;br /&gt;
        RETVAL=&amp;quot;$?&amp;quot;&lt;br /&gt;
    fi&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This ismply upgrades the process to be allowed to use most of the resources on the pi, regardless of what other processes are whining about.&lt;br /&gt;
&lt;br /&gt;
PS: Code not tested - I don&#039;t have a pi right here. Will test later, but I&#039;m pretty sure it&#039;ll work. After all, it&#039;s just a few new arguments to start-stop-daemon&lt;br /&gt;
&lt;br /&gt;
roy&lt;/div&gt;</summary>
		<author><name>Roy</name></author>
	</entry>
	<entry>
		<id>https://wiki.malinux.no/index.php?title=Roy%27s_notes&amp;diff=173</id>
		<title>Roy&#039;s notes</title>
		<link rel="alternate" type="text/html" href="https://wiki.malinux.no/index.php?title=Roy%27s_notes&amp;diff=173"/>
		<updated>2020-09-02T09:18:35Z</updated>

		<summary type="html">&lt;p&gt;Roy: /* Disabling LVM cache */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= LVM, md and friends =&lt;br /&gt;
&lt;br /&gt;
== Linux&#039; Logical Volume Manager (LVM) ==&lt;br /&gt;
&lt;br /&gt;
=== LVM in general ===&lt;br /&gt;
&lt;br /&gt;
LVM is designed to be an abstraction layer on top of physical drives or RAID, typically [https://raid.wiki.kernel.org/index.php/RAID_setup mdraid] or [https://help.ubuntu.com/community/FakeRaidHowto fakeraid]. Keep in mind that fakeraid should be avoided unless you really need it, like in conjunction with dual-booting linux and windows on fakeraid. LVM broadly consists of three elements, the &amp;quot;physical&amp;quot; devices (PV), the volume group (VG) and the logical volume (LV). There can be multiple PVs, VGs and LVs, depending on requirement. More about this below. All commands are given as examples, and all of them can be fine-tuned using extra flags in need of so. In my experience, the defaults work well for most usecases.&lt;br /&gt;
&lt;br /&gt;
I&#039;m mentioning filesystem below too. Where I write ext4, the samme applies to ext2 and ext3.&lt;br /&gt;
&lt;br /&gt;
==== Create a PV ====&lt;br /&gt;
&lt;br /&gt;
A PV is the &amp;quot;physical&amp;quot; parts. This does not need to be a physical disk, but can also be another RAID, be it an mdraid, fakeraid, hardware raid, a virtual disk on a SAN or otherwisee or a partition on one of those. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#  These add three PVs, one on a drive (or hardware raid) and another two on mdraids.&lt;br /&gt;
pvcreate /dev/sdb&lt;br /&gt;
pvcreate /dev/md1 /dev/md2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For more information about pvcreate, see [https://linux.die.net/man/8/pvcreate the manual].&lt;br /&gt;
&lt;br /&gt;
==== Create a VG ====&lt;br /&gt;
&lt;br /&gt;
The volume group consists of one or more PVs grouped together on which LVs can be placed. If several PVs are grouped in a VG, it&#039;s generally a good idea to make sure these PVs have some sort of redundancy, as in mdraid/fakeraid or hwraid. Otherwise it will be like using a [https://en.wikipedia.org/wiki/RAID RAID-0] with a single point of failure on each of the independant drives. LVM has [https://unix.stackexchange.com/questions/150644/raiding-with-lvm-vs-mdraid-pros-and-cons  RAID code in it] as well, so you can use that. I haven&#039;t done so myself, as I generally stick to mraid. The reason is mdraid is, in my opinion older and more stable and has more users (meaning bugs are reported and fixed faster whenever they are found). That said, I beleive the actual RAID code used in LVM RAID are the same function calls as for mdraid, so it may not be much of a difference. I still stick with mdraid. To create a VG, run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create volume group my_vg&lt;br /&gt;
vgcreate my_vg /dev/md1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that if vgcreate is run with a PV (as /dev/md1 above) that is not defined as a PV (like above), this is done implicitly, so if you don&#039;t need any special flags to pvcreate, you can simply skip it and let vgcreate do that for you.&lt;br /&gt;
&lt;br /&gt;
==== Create an LV ====&lt;br /&gt;
&lt;br /&gt;
LVs can be compared to partitions, somehow, since they are bounderies of a fraction or all of that of a VG. The difference between them and a partition, however, is that they can be grown or shrunk easily and also moved around between PVs without downtime. This flexibility makes them superiour to partitions as your system can be changed without users noticing it. By default, an LV is alloated &amp;quot;thickly&amp;quot;, meaning all the data given to it, is allocated from the VG and thus the PV. The following makes a 100GB LV named &amp;quot;thicklv&amp;quot;. When making an LV, I usually allocate what&#039;s needed plus some more, but not everything, just to make sure it&#039;s space available for growth on any of the LVs on the VG, or new LVs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a thick provisioned LV named thicklv on the VG my_vg&lt;br /&gt;
lvcreate -n thicklv -L 100G my_vg&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After the LV is created, a filesystem can be placed on it unless it is meant to be used directly. The application for direct use include swap space, VM storage and certain database systems. Most of these will, however, work on filesystems too, although my testing has shown that on swap space, there is a significant performance gain for using dedicated storage without a filesystem. As for filesystems, most Linux users use either ext4 or xfs. Personally, I generally use XFS these days. See my notes below on filesystem choice.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a filesystem on the LV - this could have been mkfs -t ext4 or whatever filesystem you choose&lt;br /&gt;
mkfs -t xfs /dev/my_vg/thicklv&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then just edit /etc/fstab with correct data and run mount -a, and you should be all set.&lt;br /&gt;
&lt;br /&gt;
==== Create LVM cache ====&lt;br /&gt;
LVMcache is LVM&#039;s solution to caching a slowish filesystem on spinning rust with the help of much faster SSDs. For this to work, use a separate SSD or a mirror or two (just in case) an add the new disk/md dev to the same VG. In this case, we use a small mirror, md1. LVM is not able to cache to a disk or partition outside the volume group.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
vgextend data /dev/md1&lt;br /&gt;
  Physical volume &amp;quot;/dev/md1&amp;quot; successfully created.&lt;br /&gt;
  Volume group &amp;quot;data&amp;quot; successfully extended&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Thn create two LVs, one for the data (contents of files) and one for the metadata (filenames, directories, attributes etc). Typically, the metadata part won&#039;t need to be very large. 100M should usually do unless you have ekstremely many small files. I guess there are ways to calculate it, but again, 1GB should do for everyone (or was that 640k?). As for the data cache, I chose to use 40G here for a 15TB RAID. It will only cache what actively use anyway, so no need for overkill.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
lvcreate -L 1G -n _cache_meta data /dev/md1&lt;br /&gt;
lvcreate -L 100G -n _cache data /dev/md1&lt;br /&gt;
&lt;br /&gt;
# Some would want --cachemode writeback, but if paranoid, I wouldn&#039;t recommend it. Metadata or data can be easily corrupted in case of failure. Most filesystems will however recover from this these days since they use journaling. It &#039;&#039;really&#039;&#039; speeds up things.&lt;br /&gt;
lvconvert --type cache-pool --cachemode writethrough --poolmetadata data/_cache_meta data/_cache&lt;br /&gt;
lvconvert --type cache --cachepool data/_cache data/data&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
That should be it. If you benchmarked the disk before this, you should try again and you&#039;ll probably get a nice surprise. If not, well, see below how to turn this off again :)&lt;br /&gt;
&lt;br /&gt;
==== Disabling LVM cache ====&lt;br /&gt;
&lt;br /&gt;
If you want to change the cached LV, such as growing og shrinking or otherwise, you&#039;ll have to disable caching first and then re-enable it. There&#039;s no quick-and-easy fix, but you just do as you did when enabling in the first place. &lt;br /&gt;
&lt;br /&gt;
Forst, disable caching for the LV. This will do it cleanly and remove the LVs earlier created for caching the main device. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
lvconvert --uncache data/data&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, since you now have a VG with an empty PV in it, earlier used for caching, I&#039;d recommend removing this for now to avoid expanding onto that as well. Since they&#039;re in the same VG, this might happen and if you get so far as to extend the lv and the filesystem on it, and this filesystem is XFS or similar filesystems without possibilities of reducing the size, you have a wee problem. &lt;br /&gt;
&lt;br /&gt;
Just remove that PV from the VG&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
vgreduce data /dev/md1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The PV is still there, but pvs should now show it not connected to a VG&lt;br /&gt;
&lt;br /&gt;
==== Growing devices ====&lt;br /&gt;
&lt;br /&gt;
LVM objects can be grown and shrunk. If a PV resides on a RAID where a new drive has been added or otherwise grown, or on a partition or virtual disk that has been extended, the PV must be updated to reflect these changes. The following command will grow the PV to the maximum available on the underlying storage. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Resize the PV /dev/md (not the RAID, only the PV on the RAID) to its full size&lt;br /&gt;
pvresize /dev/md1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If a new PV is added, the VG can be grown to add the space on that in addition to what&#039;s there already. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Extend my_vg to include md2 and its space&lt;br /&gt;
vgextend my_vg /dev/md2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
With more space available in the VG, the LV can now be extended. Let&#039;s add another 50GB to it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Extend thicklv - add 50GB. If you know you won&#039;t need the space anywhere else, you may want to&lt;br /&gt;
# lvresize -l+100%FREE instead. Keep in mind the difference between -l (extents) and -L (bytes)&lt;br /&gt;
lvresize -L +50G my_vg/thicklv&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Growing filesystems ====&lt;br /&gt;
After the LV has grown, run &#039;&#039;xfs_growfs&#039;&#039; (xfs) or &#039;&#039;resize2fs&#039;&#039; (ext4) to make use of the new data. To grow the filesystem to all available space on ext4, run the below command.  To partly grow the filesystem or to shrink it or otherwise, please see the manuals.&lt;br /&gt;
&lt;br /&gt;
The filesystem can be mounted when this is run. If you for some reason get an &#039;&#039;&#039;access denied&#039;&#039;&#039; error when running this as root or with sudo, it&#039;s likely caused by a filesystem error. To fix this, unmount the filesystem first and run &#039;&#039;&#039;fsck -f /dev/my_vg/thicklv&#039;&#039;&#039; and remount it before retrying to extend it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
resize2fs /dev/my_vg/thicklv&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Similarly, with XFS, but note that xfs_growfs doesn&#039;t take the device name, but the filesystem&#039;s mount point. In the case of XFS, also note that the filesystem &#039;&#039;&#039;&#039;&#039;must&#039;&#039;&#039;&#039;&#039; be mounted to be grown. This, in contrast to how it was in the old days when filesystems had to be unmounted to be grown.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
xfs_growfs /my_mountpoint&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Rename system VG ====&lt;br /&gt;
&lt;br /&gt;
Some distros create VG names like those-from-a-sysadmin-with-a-well-developed-paranoia-not-to-hit-a-duplicate. Debian, for instance, uses names like &amp;quot;my-full-hostname-vg&amp;quot;. Personally, I don&#039;t like these, since if I were to move a disk or vdisk around to somewhere else, I&#039;d make sure not to add a disk named &#039;sys&#039; to an existing system. If you do, most distros will refuse to use the VGs with duplicate names, resulting in the OS not booting until either one is specified by its UUID or just one removed. As I&#039;m aware of this, I stick to the super-risky thing of all system VGs named &#039;sys&#039; and so on.&lt;br /&gt;
&lt;br /&gt;
If you do this, keep in mind that it may blow up your computer and take your girl- or boyfriend with it or even make either of them pregnant, allowing Trump to rule your life and generally make things suck. You&#039;re on your own!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Rename the VG&lt;br /&gt;
vgrename my-full-hostname-vg sys&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, in /boot/grub/grub.cfg, change the old lv path from something like &#039;/dev/mapper/debian--stretch--machine--vg-root&#039; to your new and fancy &#039;/dev/sys/root. Likewise, in /etc/fstab, change occurences of &#039;/dev/mapper/debian--stretch--machine--vg-&#039; (or similar) with &#039;/dev/sys/&#039;. Here, this was like this - the old ones commented out.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;fstab&amp;quot;&amp;gt;&lt;br /&gt;
#/dev/mapper/debian--stretch--box--vg-root      /               ext4            errors=remount-ro,discard       0       1&lt;br /&gt;
/dev/sys/root                                   /               ext4            errors=remount-ro,discard       0       1&lt;br /&gt;
# /boot was on /dev/vda1 during installation&lt;br /&gt;
UUID=myverylonguuidwithatonofgoodinfoinit       /boot           ext2            defaults                        0       2&lt;br /&gt;
#/dev/mapper/debian--stretch--box--vg-swap_1    none            swap            sw                              0       0&lt;br /&gt;
/dev/sys/swap_1                                 none            swap            sw                              0       0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Update /etc/initramfs-tools/conf.d/resume with similar data for swap.&lt;br /&gt;
&lt;br /&gt;
You might want to run &#039;update-initramfs -u -k all&#039; after this, but I&#039;m not sure if it&#039;s needed.&lt;br /&gt;
&lt;br /&gt;
Now, pray to the nearest god(s) and give it a reboot and it should (probably) work.&lt;br /&gt;
&lt;br /&gt;
After reboot, run &#039;&#039;&#039;swapoff -a&#039;&#039;&#039;, then &#039;&#039;&#039;mkswap /dev/sys/swap_1&#039;&#039;&#039; (or whatever it&#039;s called on your system) and &#039;&#039;&#039;swapon -a&#039;&#039;&#039; again. You may want to give it another reboot or two for kicks, but it should work well even without that.&lt;br /&gt;
&lt;br /&gt;
=== Migration tools ===&lt;br /&gt;
&lt;br /&gt;
At times, storage regimes change, new storage is added and sometimes it&#039;s not easy to migrate with the current hardware or its support systems. Once I had to migrate a 45TiB fileserver from one storage system to another, preferably without downtime. The server originally had three 15TiB PVs of which two were full and the third half full. I resorted to using [https://linux.die.net/man/8/pvmove pvmove] to just move the data on the PVs in use to a new PV. We started out with creating a new 50TiB PV, sde, and then to pvmove.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Attach /dev/sde to the VG my_vg&lt;br /&gt;
vgextend my_vg /dev/sde&lt;br /&gt;
&lt;br /&gt;
# Move the contents from /dev/sdb over to /dev/sde block by block. If a target is not given in pvmove,&lt;br /&gt;
# the contents of the source (sdb here) will be put somewhere else in the pool.&lt;br /&gt;
pvmove /dev/sdb /dev/sde&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This took a while (as in a week or so) - the pvmove command uses old code and logic (or at least did that when I migrated this in November 2016), but it affected performance on the server very little, so users didn&#039;t notice. After the first PV was migrated, I continued with the other two, one after the other, and after a month or so, it was migrated. We used this on a number of large fileservers, and it worked flawlessly. Before doing the production servers I also tried interrupting pvmove in various ways, including hard resets, and it just kept on after the reboot.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;NOTE:&#039;&#039;&#039;&#039;&#039; &#039;&#039;Even though it worked well for us, &#039;&#039;&#039;always&#039;&#039;&#039; keep a good backup before doing this. Things may go wrong, and without a good backup, you may be looking for a hard-to-find new job the next morning&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
==== mdadm workarounds ====&lt;br /&gt;
&lt;br /&gt;
===== Migrate from a mirror (raid-1) to raid-10 =====&lt;br /&gt;
&lt;br /&gt;
Create a mirror&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sdb /dev/sdc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
LVM (pv/vg/lv) on md0 (see above), put a filesystem on the lv and fill it with some data.&lt;br /&gt;
&lt;br /&gt;
Now, some months later, you want to change this to raid-10 to allow for the same amount of redundancy, but to allow more disks into the system.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mdadm --grow /dev/md0 --level=10&lt;br /&gt;
mdadm: Impossibly level change request for RAID1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So - no - doesn&#039;t work. But - we&#039;re on &lt;br /&gt;
&lt;br /&gt;
Since we&#039;re on lvm already, this&#039;ll be easy. If you&#039;re using filesystems directly on partitions, you can do this the same way, but without the pvmove part, using rsync or whateever you like instead. I&#039;d recommend using lvm for for the new raid, which should be rather obvious from this article. Now plug in a new drive and create a new raid10 on that one. If you two new drives, install both. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# change &amp;quot;missing&amp;quot; to the other device name if you installed two new drives&lt;br /&gt;
mdadm --create /dev/md1 --level=10 --raid-devices=2 /dev/vdd missing&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, as described above, just vgextend the vg, adding the new raid and run pvmove to move the data from the old pv (residing on the old raid1) to the new pv (on raid10). Afte rpvmove is finished (which may take awile, see above), just&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
vgreduce raidtest /dev/md0&lt;br /&gt;
pvremove /dev/md0&lt;br /&gt;
mdadm --stop /dev/md0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
…and your disk is free to be added to the new array. If the new raid is running in degraded mode (if you created it with just one drive), better don&#039;t wait too long, since you don&#039;t have redundancy. Just mdadm --add the devs.&lt;br /&gt;
&lt;br /&gt;
If you now have /dev/mdstat telling you your raid10 is active and have three drives, of which one is a spare, it should look something like this&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5] [raid4] [raid10]&lt;br /&gt;
md1 : active raid10 vdc[3](S) vdb[2] vdd[0]&lt;br /&gt;
      8380416 blocks super 1.2 2 near-copies [2/2] [UU]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Just mdadm --grow --raid-devices=3 /dev/md1&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;RAID section is not complete. I&#039;ll write more on migraing from raid10 to raid6 later. It&#039;s not straight forward, but easier than this one :)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== Thin provisioned LVs ===&lt;br /&gt;
&lt;br /&gt;
Thin provisioning on LVM is a method used for not allocating all the space given to an LV. For instance, if you have a 1TB VG and want to give an LV 500GB, although it currently only uses a fraction of that, a thin lv can be a good alternative. This will allow for adding a limit to how much it can use, but also to let it grow dynamically without manual work by the sysadmin. Thin provisioning adds another layer of abstaction by creating a special LV as a &#039;&#039;thin pool&#039;&#039; from which data is allocated to the &#039;&#039;thin volume(s)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== Create a thin pool ====&lt;br /&gt;
&lt;br /&gt;
Allocate 1TB to the thin pool to be used for thinly provisioned LVs. Keep in mind that the space allocated to the thin pool is in fact thick provisioned. Only the volumes put on &#039;&#039;thinpool&#039;&#039; are thin provisioned. This will create two hidden LVs, one for data and one for metadata. Normally the defaults will do, but check the manual if the data doesn&#039;t match the usual patterns (such as billions of files, resulting in huge amounts of metadata). I &#039;&#039;beleive&#039;&#039; the metadata part should be resizable at a later time if needed, but I have not tested it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a pool for thin LVs. Keep in mind that the pool itself is not thin provisioned, only the volumes residing on it&lt;br /&gt;
lvcreate --size 1T --type thin-pool --thinpool thinpool my_vg&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Create a thin volume ====&lt;br /&gt;
&lt;br /&gt;
You have the thinpool, now put a thin volume on it. It will allocate some space for metadata, but probably not much (a few megs, perhaps).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Now, create a volume with a virtual (-V) size of half a terabyte named thin_pool, but using the thinpool (-T) named thin_pool for storage&lt;br /&gt;
lvcreate -V 500G -T my_vg/thin_pool --name thinvol&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The new volume&#039;s device name will be /dev/thinvol. Now, create a filesystem on it, add to fstab and mount it. The &#039;&#039;&#039;df&#039;&#039;&#039; command will return available space according to the virtual size (-V), while lvs will show how much data is actually used on each of the thinly provisioned volumes.&lt;br /&gt;
&lt;br /&gt;
== Filesystem dilemmas ==&lt;br /&gt;
&lt;br /&gt;
=== XFS or ext4 or something else ===&lt;br /&gt;
The choice of filesystem varies for your use. Distros such as RHEL/CentOS has moved to XFS by default from v7. Debian/Ubuntu still sticks to ext4, like most other. I&#039;ll discuss my thoughts below on ext4 vs XFS and leave the other filesystems for later.&lt;br /&gt;
&lt;br /&gt;
==== ext4 ====&lt;br /&gt;
ext4 is probably the most used filesystem on linux as of writing. It&#039;s rock stable and has been extended by a lot of extensions since the original ext2. It still retains backward compatibility, being able to mount and fsck ext2 and ext3 with the ext4 driver. However, it doesn&#039;t handle large filesystems very well. If a filesystem is created for &amp;lt;16TiB, it cannot be grown to anything larger than 16TiB. This may have changed lately, though. One other issue is handling errors. If a large filesystem (say 10TiB) is damaged, an fsck may take several hours, leading to long downtime. When I refer to ext4 further in this text, the same applies to ext2 and ext3 unless otherwise specified.&lt;br /&gt;
&lt;br /&gt;
==== XFS ====&lt;br /&gt;
XFS, originally developed by SGI some time in the bronze age, but has been worked on heavily after that. RHEL and Centos version 7 and forward, uses XFS as the default filesystem. It is quick, it scales well, but it lacks at least two things ext4 has. It cannot be shrunk (not that you normally need that, but nice if you have a typo or you need to change things). Also, it doesn&#039;t allow for automatic fsck on bootup. If something is messed up on the filesystem, you&#039;ll have to login as root on the console (not ssh), which might be an issue on some systems. The fsck equivalent, xfs_repair, is a *lot* faster than ext4&#039;s fsck, though.&lt;br /&gt;
&lt;br /&gt;
==== ZFS ====&lt;br /&gt;
ZFS is like a combination of RAID, LVM and a filesystem, supporting full checksumming, auto-healing (given sufficient redundancy), compression, encryption, replication, deduplication (if you&#039;re brave and have a &#039;&#039;ton&#039;&#039; of memory) and a lot more. It&#039;s a separate chapter and needs a lot more talk than paragraph here.&lt;br /&gt;
&lt;br /&gt;
==== btrfs ====&lt;br /&gt;
btrfs, pronounced &amp;quot;butterfs&amp;quot; or &amp;quot;betterfs&amp;quot; or just spelled out, is a filesystem that mimics that of ZFS. It has been around for 10 years or so, but hasn&#039;t yet proven to be really stable. Following the progress of it for those years, I&#039;ve found it to be a nice toy with which to play, but not to be used in production. Again, others may say otherwise, but these are just my words.&lt;br /&gt;
&lt;br /&gt;
== Low level disk handling ==&lt;br /&gt;
&lt;br /&gt;
This section is for low-level handling of disks, regardless of storage system elsewhere. These apply to mdraid, lvmraid and zfs and possibly other solutions, with the exception of individual drives on hwraid (and maybe fakeraid), since there, the drives are hidden from Linux (or whatever OS).&lt;br /&gt;
&lt;br /&gt;
=== S.M.A.R.T. and slow drives ===&lt;br /&gt;
Modern (that is, from about 1990 or later) have S.M.A.R.T. (or just smart, since it&#039;s easier to type) monitoring built in, meaning the disk&#039;s controller is monitoring itself. This is handy and will ideally tell you in advance that a drive is flakey or dying. Modern (2010+) smart monitoring is more or less the same. It can be trusted about 50% of the time. Usually, if smart detects an error, it&#039;s a real error. I don&#039;t think I&#039;ve seen it reporting a false positive, but others may know better. &lt;br /&gt;
&lt;br /&gt;
==== smartmontools ====&lt;br /&gt;
First, install smartmontool and run smartclt -H /dev/yourdisk (/dev/sda or something) to get a health report. Then perhaps run smartctl -a /dev/yourdisk and look for &#039;current pending sectors&#039; This should be zero. Also check the temperature, which normally should be much above 50.&lt;br /&gt;
&lt;br /&gt;
==== single, slow drive ====&lt;br /&gt;
What may happen, is smart not seeing anything and life goes on like before, only slower and less prouductive, without telling anyone. If you stubler over this issue, you&#039;ll probably see it during a large rsync/zfs send/receive or a resync/rebuild/resilver of the raid/zpool. During this, it feels like everything is slow and your RAID has turned into a RAIF (redundant array of inexpensive floppies). To check if you have a single drive messing up it all, check with &#039;&#039;&#039;iostat -x 2&#039;&#039;&#039;, having 2 being the delay between each measurement. Interrupt it with ctrl+x. If there&#039;s a rougue drive there, it should stand out like sdg below&lt;br /&gt;
&lt;br /&gt;
 avg-cpu:  %user   %nice %system %iowait  %steal   %idle&lt;br /&gt;
            0.38    0.00    1.75    0.00    0.00   97.87&lt;br /&gt;
&lt;br /&gt;
 Device            r/s     w/s     rkB/s     wkB/s   rrqm/s   wrqm/s  %rrqm  %wrqm r_await w_await aqu-sz rareq-sz wareq-sz  svctm  %util&lt;br /&gt;
 sda              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdb              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdc              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdd              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sde              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdf              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdg              3.50    0.00   2352.00      0.00     0.00     0.00   0.00   0.00 14306.29    0.00  13.85   672.00     0.00 285.71 100.00&lt;br /&gt;
 sdh              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
&lt;br /&gt;
In ZFS land, you should be able to get similar data with &#039;&#039;&#039;zpool iostat -v &amp;lt;pool&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Now you know the bad drive (sdg), pull it from the raid with &#039;&#039;&#039;mdadm --fail /dev/mdX /dev/sdX&#039;&#039;&#039;. Now test the drive&#039;s performance manually, just simply:&lt;br /&gt;
&lt;br /&gt;
 # hdparm -t /dev/sdg&lt;br /&gt;
 &lt;br /&gt;
 /dev/sdg:&lt;br /&gt;
  Timing buffered disk reads:   2 MB in  5.37 seconds = 381.46 kB/sec&lt;br /&gt;
&lt;br /&gt;
Bingo - nothing you&#039;d want to keep. For a good drive, it should be something like 100-200MB/s&lt;br /&gt;
&lt;br /&gt;
PS: Keep in mind that you have a degraded RAID by now in case you had a spare waiting for things to happen.&lt;br /&gt;
&lt;br /&gt;
Try to replace the cable and/or try the disk on another port/controller. If the result from hdparm persists, it&#039;s probably a bad cable&lt;br /&gt;
&lt;br /&gt;
So, then, just psycially locate the drive, pull it out, take out the discs and magnets and recycle the rest.&lt;br /&gt;
&lt;br /&gt;
=== &amp;quot;Unplug&amp;quot; drive from system ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Find the device unit&#039;s number with something like&lt;br /&gt;
find /sys/bus/scsi/devices/*/block/ -name sdd&lt;br /&gt;
# returning /sys/bus/scsi/devices/3:0:0:0/block/sdd here, &lt;br /&gt;
# meaning 3:0:0:0 is the SCSI device we&#039;re looking for.&lt;br /&gt;
&lt;br /&gt;
# Given this is the correct device, and you want to &#039;unplug&#039; it, do so by&lt;br /&gt;
echo 1 &amp;gt; /sys/bus/scsi/devices/3:0:0:0/delete&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Rescan disk controllers ===&lt;br /&gt;
If a drive is added and for some reason doesn&#039;t get detected, or is removed by the command above, it can be rediscovered with a sysfs command to the scsi host to which it is connected. Since there may be quite a few of these, an easy way is to just scan them all and check the output of &#039;&#039;&#039;dmesg -T&#039;&#039;&#039; after running it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Make a list of controllers and send a rescan message to each of them. It won&#039;t do anything &lt;br /&gt;
# for those where nothing has changed, but it will show new drives where they have been added.&lt;br /&gt;
for host_scan in /sys/class/scsi_host/host*/scan&lt;br /&gt;
do&lt;br /&gt;
  echo &#039;- - -&#039; &amp;gt; $host_scan&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Fail injection with debugfs ===&lt;br /&gt;
[https://lxadm.com/Using_fault_injection https://lxadm.com/Using_fault_injection]&lt;br /&gt;
&lt;br /&gt;
== mdadm stuff ==&lt;br /&gt;
=== Resync ===&lt;br /&gt;
To resync a raid, that is, check, run&lt;br /&gt;
&lt;br /&gt;
 echo check &amp;gt; /sys/block/$dev/md/sync_action&lt;br /&gt;
&lt;br /&gt;
where $dev is something like md0. If you have several raids, something like this should work&lt;br /&gt;
&lt;br /&gt;
 for dev in md{0,1}&lt;br /&gt;
 do&lt;br /&gt;
   echo repair &amp;gt; /sys/block/$dev/md/sync_action&lt;br /&gt;
 done&lt;br /&gt;
&lt;br /&gt;
Also useful in a one-liner like&lt;br /&gt;
&lt;br /&gt;
 for dev in md{0,1} ; do echo repair &amp;gt; /sys/block/$dev/md/sync_action ; done&lt;br /&gt;
&lt;br /&gt;
Different raids on different drives will do this in parallel. If the drives are shared somehow with partitions or similar, the check or repair will wait for the other to finish before going on.&lt;br /&gt;
&lt;br /&gt;
As for repair vs check, [https://raid.wiki.kernel.org/index.php/RAID_Administration this article] describes it well. I stick to using repair unless it&#039;s something rare where I don&#039;t want to touch the data.&lt;br /&gt;
&lt;br /&gt;
=== Spare pools ===&lt;br /&gt;
In the old itmes, mdadm supported only a dedicated spare per md device, so if working with a large set of drives (20? 40?), where you&#039;d want to setup more raid sets to increase redundancy, you&#039;d dedicate a spare to each of the raid sets. This has changed (some time ago?), so in these modern, heathen days, you can change mdadm.conf, usually placed under /etc/mdadm, and add &#039;spare-group=somegroup&#039; where &#039;somegroup&#039; is a string identifying the spare group. After doing this, run &#039;&#039;&#039;update-initramfs -u&#039;&#039;&#039; and reboot and add a spare to one of the raid sets in the spare group, and md will use that or those spares for all the raidsets in that group.&lt;br /&gt;
&lt;br /&gt;
As some pointed out on #linux-raid @ irc.freenode.net, this feature is very badly documented, but as far as I can see, it works well.&lt;br /&gt;
&lt;br /&gt;
==== Example config ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create two raidsets&lt;br /&gt;
&lt;br /&gt;
mdadm --create /dev/md1 --level=6 --raid-devices=6 /dev/vd[efghij]&lt;br /&gt;
mdadm --create /dev/md2 --level=6 --raid-devices=6 /dev/vd[klmnop]&lt;br /&gt;
&lt;br /&gt;
# get their UUID etc&lt;br /&gt;
&lt;br /&gt;
mdadm --detail --scan&lt;br /&gt;
ARRAY /dev/md/1 metadata=1.2 name=raidtest:1 UUID=1a8cbdcb:f4092350:348b6b80:c054d74c&lt;br /&gt;
ARRAY /dev/md/2 metadata=1.2 name=raidtest:2 UUID=894b1b7c:cb7eba70:917d6033:ea5afd2b&lt;br /&gt;
&lt;br /&gt;
# Put those lines into /etc/mdadm/mdadm.conf and and add the spare-group&lt;br /&gt;
&lt;br /&gt;
ARRAY /dev/md/1 metadata=1.2 name=raidtest:1 spare-group=raidtest UUID=1a8cbdcb:f4092350:348b6b80:c054d74c&lt;br /&gt;
ARRAY /dev/md/2 metadata=1.2 name=raidtest:2 spare-group=raidtest UUID=894b1b7c:cb7eba70:917d6033:ea5afd2b&lt;br /&gt;
&lt;br /&gt;
# update the initramfs and reboot&lt;br /&gt;
&lt;br /&gt;
update-initramfs -u&lt;br /&gt;
reboot&lt;br /&gt;
&lt;br /&gt;
# add a spare drive to one of the raids&lt;br /&gt;
&lt;br /&gt;
mdadm --add /dev/md1 /dev/vdq&lt;br /&gt;
&lt;br /&gt;
# fail a drive on the other raid&lt;br /&gt;
&lt;br /&gt;
mdadm --fail /dev/md2 /dev/vdn&lt;br /&gt;
&lt;br /&gt;
# check /proc/mdstat to see md2 rebuilding with the spare from md1&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Recovery ===&lt;br /&gt;
&lt;br /&gt;
The other day, I came across a problem a user had on #linux-raid@irc.freenode.net. He had an old Qnap NAS that had died and tried plugging the drives in to his Linux machine and got various errors. The two-drive RAID-1 did not come up as it should, &#039;&#039;&#039;dmesg&#039;&#039;&#039; was full of errors from one of the drives (both connected on USB) and so forth.&lt;br /&gt;
&lt;br /&gt;
We went on and started by taking down the machine and just connecting one of the drives. I had him check what was assembled with&lt;br /&gt;
&lt;br /&gt;
 cat /proc/mdstat&lt;br /&gt;
&lt;br /&gt;
That returned /proc/md127 assembled, but LVM didn&#039;t find anything. So running a manual scan&lt;br /&gt;
&lt;br /&gt;
 pvscan --cache /dev/md127&lt;br /&gt;
&lt;br /&gt;
This made linux find the PV, VG and a couple of LVs, but probably because the mdraid was degraded, the LVs were deactivated, according to &#039;&#039;&#039;lvscan&#039;&#039;&#039;. Activating the one with a filesystem manually&lt;br /&gt;
&lt;br /&gt;
 lvchange -a y /dev/&amp;lt;vg&amp;gt;/&amp;lt;lv&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Substitute &amp;lt;vg&amp;gt; and &amp;lt;lv&amp;gt; with the names listed by vgs and lvs.&lt;br /&gt;
&lt;br /&gt;
This worked, and the filesystem on /dev/&amp;lt;vg&amp;gt;/&amp;lt;lv&amp;gt; could be mounted correctly.&lt;br /&gt;
&lt;br /&gt;
== Tuning ==&lt;br /&gt;
&lt;br /&gt;
While trying to compare a 12-disk RAID (8TB disks) to a hwraid, mdraid was slower, so we did a few things to speed things up:&lt;br /&gt;
&lt;br /&gt;
While testing with [https://linux.die.net/man/1/fio fio], monitor /sys/block/md0/md/stripe_cache_active, and see if it&#039;s close to /sys/block/md0/md/stripe_cache_size. If it is, double the size of the latter&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
echo 4096 &amp;gt; /sys/block/md0/md/stripe_cache_size&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Continue until stripe_cache_active stabilises, and then you&#039;ve found the limit you&#039;ll need. You may want to double that for good measure. &lt;br /&gt;
&lt;br /&gt;
(to be continued)&lt;br /&gt;
&lt;br /&gt;
== Links ==&lt;br /&gt;
&lt;br /&gt;
Below are a few links with useful info&lt;br /&gt;
&lt;br /&gt;
* [https://raid.wiki.kernel.org/index.php/Irreversible_mdadm_failure_recovery Irreversible mdadm failure recovery]&lt;br /&gt;
&lt;br /&gt;
= ZFS =&lt;br /&gt;
&lt;br /&gt;
ZFS can do a lot of things most filesystems or volume managers can&#039;t. It checksums all data and metadata and so long that the system uses ECC enabled memory (RAM), it will have complete control over the whole data set, and when (not if) an error occurs, it&#039;ll fix the issue without even throwing a warning. To fix the issue, you&#039;ll obviously need sufficient redundancy (mirrors or RAIDzN). &lt;br /&gt;
&lt;br /&gt;
== ZFS send/receive between machines ==&lt;br /&gt;
&lt;br /&gt;
ZFS has a send/receive mechanism that allows for snapshots to be sent over the wire to a receiving end. This can be a full filesystem, or an incremental change since last send/reveive. In a WAN scenario, you&#039;ll probably want to use VPN for this. On a controlled network, sending in cleartext is also possible. You may as well use ssh, but keep in mind that ssh was never designed to be used as a fullblown vpn solution and is just too slow or the task with large amounts of data. You may, though, use mbuffer, if on a loal LAN.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Allow traffic from the sending IP in whatever firewall interface you&#039;re using (if you&#039;re using a firewall at all, that is)&lt;br /&gt;
ufw allow from x.x.x.x&lt;br /&gt;
# &lt;br /&gt;
# Start the receiver first. This listens on port 9090, has a 1GB buffer,&lt;br /&gt;
    and uses 128kb chunks (same as zfs):&lt;br /&gt;
&lt;br /&gt;
mbuffer -s 128k -m 1G -I 9090 | zfs receive data/filesystem&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To be continued one day… See [https://everycity.co.uk/alasdair/2010/07/using-mbuffer-to-speed-up-slow-zfs-send-zfs-receive/ this] for some more. I&#039;ll get back with details on it.&lt;br /&gt;
&lt;br /&gt;
= General Linux system control =&lt;br /&gt;
&lt;br /&gt;
== Add a new CPU (core) ==&lt;br /&gt;
&lt;br /&gt;
If working with virtual machines, adding a new core can be useful if the VM is slow and the load is multithreaded or multiprocess. To do this, add a new CPU in the hypervisor (be it KVM or VMware or Hyper-V or whatever). Some hypervisors, like VMware, will activate it automatically if open-vm-tools is installed. Please note that open-vm-tools is for VMware only. I don&#039;t know of any such thing for KVM or other hypervisors (although I beleive VirtualBox has its own set of tools, but not as a package). If this doesn&#039;t work, run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
echo 1 &amp;gt; /sys/devices/system/cpu/cpuX/online&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where X is the CPU number you want to add. You can &#039;cat /sys/devices/system/cpu/cpuX/online&#039; to check if it&#039;s online.&lt;br /&gt;
&lt;br /&gt;
= Mount partitions on a disk image =&lt;br /&gt;
&lt;br /&gt;
Sometimes you&#039;ll have a disk image, either from recovering a bad drive after hours (or days or weeks) of ddrescue, and sometimes you just have a disk image from a virtual machine where you want to mount the partitions inside the image. There are three main methods of doing this, which are more or less synonmous, but some easier than the other.&lt;br /&gt;
&lt;br /&gt;
== Basics ==&lt;br /&gt;
&lt;br /&gt;
A disk image is usually like a disk, consisting of either a large filesystem, a PV or a partition table with one or partitions onto which resides a filesystem, a pv, swap or something else. If it&#039;s partitioned, and you want your operating system to mount a filesystem or allow it to see whatever LVM stuff lies on it, you need to isolate the partitions. &lt;br /&gt;
&lt;br /&gt;
== Manual mapping ==&lt;br /&gt;
&lt;br /&gt;
In the oldern days, this was done manually, something like this&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
root@mymachine:~# fdisk -l /dev/vda&lt;br /&gt;
Disk /dev/vda: 25 GiB, 26843545600 bytes, 52428800 sectors&lt;br /&gt;
Units: sectors of 1 * 512 = 512 bytes&lt;br /&gt;
Sector size (logical/physical): 512 bytes / 512 bytes&lt;br /&gt;
I/O size (minimum/optimal): 512 bytes / 512 bytes&lt;br /&gt;
Disklabel type: dos&lt;br /&gt;
Disk identifier: 0xc37b7ea5&lt;br /&gt;
&lt;br /&gt;
Device     Boot    Start      End  Sectors  Size Id Type&lt;br /&gt;
/dev/vda1  *        2048 50333311 50331264   24G 83 Linux&lt;br /&gt;
/dev/vda2       50333312 52426369  2093058 1022M  5 Extended&lt;br /&gt;
/dev/vda5       50333314 52426369  2093056 1022M 82 Linux swap / Solaris&lt;br /&gt;
root@mymachine:~#&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To calculate the start and end of each partition, you just take the start sector and multiply it by the sector size (512 bytes here) and you have the offset in bytes. After this, it&#039;s merely an losetup -o &amp;lt;offset&amp;gt; /dev/loopX &amp;lt;nameofimagefile&amp;gt; and you have the partition mapped to your /dev/loopX (having X being something typically 0-255. After this, just mount it or run pvscan/vgscan/lvscan to probe whatever lvm config is there, and you should be able to mount it like any other filesystem.&lt;br /&gt;
&lt;br /&gt;
== kpartx ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;kpartx&#039;&#039;&#039; does the same as above, more or less, just without so much hassle. Most of it should be automatic and easy to deal with, except it may fail to disconnect the loopback devices sometimes, so you may have to &#039;&#039;&#039;losetup -d&#039;&#039;&#039; them manually. See the manual, &#039;&#039;&#039;kpartx (8)&#039;&#039;&#039;. Please note that &#039;&#039;&#039;partx&#039;&#039;&#039; works similarly and I&#039;d guess the authors of the two tools are arguing a lot of which one&#039;s the best.&lt;br /&gt;
&lt;br /&gt;
== guestmount ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;guestmount&#039;&#039;&#039; is something similar again, but also supports file formats like &#039;&#039;&#039;qcow2&#039;&#039;&#039; and possibly other, proprietary filesystems like &#039;&#039;&#039;vmdk&#039;&#039;&#039; and &#039;&#039;&#039;vdi&#039;&#039;&#039;, but don&#039;t take my word for it - I haven&#039;t tested. Again, see the manual or just read up on the description [http://ask.xmodulo.com/mount-qcow2-disk-image-linux.html?fbclid=IwAR3snTeZvGzp9PLdX11EQhCfOpux6I93CiJ3A2pUomkkRLly9Xo4851mkTY here]. It seems rather trivial.&lt;br /&gt;
&lt;br /&gt;
= Linux on laptops =&lt;br /&gt;
&lt;br /&gt;
== Wifi with HP EliteBook 725/745 on Ubuntu ==&lt;br /&gt;
&lt;br /&gt;
The HP EliteBook 725/745 and similar are equipped with a BCM4352 wifi chip. As with a lot of other stuff from Broadcom, this lacks an open hardware description, so thus no open driver exist. The proper fix, is to replace the NIC with something with an open driver, but again, this isn&#039;t always possible, so a binary driver exists. In ubuntu, run, somehow connect the machine to the internet and run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install bcmwl-kernel-source&lt;br /&gt;
sudo modprobe wl&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you can&#039;t connect the machine to the internet, download the needed packages on another machine and put it on some usb storage. These packages should suffice:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# apt-cache depends bcmwl-kernel-source&lt;br /&gt;
bcmwl-kernel-source&lt;br /&gt;
  Depends: dkms&lt;br /&gt;
  Depends: linux-libc-dev&lt;br /&gt;
  Depends: libc6-dev&lt;br /&gt;
  Conflicts: &amp;lt;bcmwl-modaliases&amp;gt;&lt;br /&gt;
  Replaces: &amp;lt;bcmwl-modaliases&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then install manually with &#039;&#039;&#039;dpkg -i file1.deb file2.deb&#039;&#039;&#039; etc&lt;br /&gt;
&lt;br /&gt;
After this, ip/ifconfig/iwconfig shouldd see the new wifi nic, probably &#039;&#039;&#039;wlan0&#039;&#039;&#039;, but due to a [https://bugs.launchpad.net/ubuntu/+source/broadcom-sta/+bug/1343151 old, ignored bug], you won&#039;t find any wifi networks. This is because the driver from Broadcom apparently does not support interrupt remapping, commonly used on x64 machines. To turn this off, change &#039;&#039;&#039;/etc/default/grub&#039;&#039;&#039; and change the line &#039;&#039;&#039;GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;quiet splash&amp;quot;&#039;&#039;&#039;, adding intremap=off to the end before the quote: &#039;&#039;&#039;GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;quiet splash intremap=off&amp;quot;&#039;&#039;&#039;. Save the file and run &#039;&#039;&#039;sudo update-grub&#039;&#039;&#039; and reboot. After this, wifi should work well.&lt;br /&gt;
&lt;br /&gt;
== Wifi with HP Compaq Presario CQ57 on Ubuntu ==&lt;br /&gt;
&lt;br /&gt;
The HP Compaq Presario CQ57 uses the RT5390 wifi chipset. This has been supported for quite some time now, and I was quite surprised to find it not working on a laptop a friend was having. The driver loaded correctly, but Ubuntu insisted of the laptop being in &#039;&#039;&#039;flight mode&#039;&#039;&#039;. Checking &#039;&#039;&#039;rfkill&#039;&#039;&#039;, it showed me two NICs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# rfkill list all&lt;br /&gt;
0: phy0: Wireless LAN&lt;br /&gt;
	Soft blocked: no&lt;br /&gt;
	Hard blocked: yes&lt;br /&gt;
1: hp-wifi: Wireless LAN&lt;br /&gt;
	Soft blocked: yes&lt;br /&gt;
	Hard blocked: no&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Turning rfkill on and off resulted in nothing much, except some error messages in the kernel log (dmesg)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] ACPI Error: Field [B128] at bit offset/length 128/1024 exceeds size of target Buffer (160 bits) (20170831/dsopcode-235)&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]&lt;br /&gt;
                            Initialized Local Variables for Method [HWCD]:&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Local0: 00000000a34b7928 &amp;lt;Obj&amp;gt;           Integer 0000000000000000&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Local1: 00000000b0aa6865 &amp;lt;Obj&amp;gt;           Buffer(8) 46 41 49 4C 04 00 00 00&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Local5: 00000000a9811efd &amp;lt;Obj&amp;gt;           Integer 0000000000000004&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] Initialized Arguments for Method [HWCD]:  (2 arguments defined for method invocation)&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Arg0:   0000000078957d1b &amp;lt;Obj&amp;gt;           Integer 0000000000000001&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Arg1:   00000000725c9c6e &amp;lt;Obj&amp;gt;           Buffer(20) 53 45 43 55 02 00 00 00&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] ACPI Error: Method parse/execution failed \_SB.WMID.HWCD, AE_AML_BUFFER_LIMIT (20170831/psparse-550)&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] ACPI Error: Method parse/execution failed \_SB.WMID.WMAD, AE_AML_BUFFER_LIMIT (20170831/psparse-550)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After upgrading BIOS and testing different kernels, I was asked to try to unload the &#039;&#039;&#039;hp_wmi&#039;&#039;&#039; driver. I did, and things changed a bit, so I tried blacklisting it, creating the file &#039;&#039;&#039;/etc/modprobe.d/blacklist-hp_wmi.conf&#039;&#039;&#039; with the following content&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Blacklist this - it doesn&#039;t work!&lt;br /&gt;
blacklist hp_wmi&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
I gave the machine a reboot and afte that, the &#039;&#039;&#039;hp-wifi&#039;&#039;&#039; entry was gone in the rfkill output, and things works.&lt;br /&gt;
&lt;br /&gt;
= Raspberry pi =&lt;br /&gt;
&lt;br /&gt;
I couldn&#039;t quite decide if the raspberry pi should be a separate section or part of Linux, but hell, it can run more than Linux, although 99,lots% of people just uses Linux on them. This is a small list of things to know about them; things not on the front page of the manual or perhaps hidden even better.&lt;br /&gt;
&lt;br /&gt;
== Which pi? ==&lt;br /&gt;
&lt;br /&gt;
I just setup three raspberry pi machines and although some are quite different, like v1 to vEverythingelse or the Pi zero versions to the normal ones, not all of us remember how to distinguish between them, and sometimes they&#039;re in a nice 3d printed (or otherwise) chassis or otherwise hidden. So, how to check three different ones:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
root@home-assistant:~ $ cat /proc/device-tree/model ; echo&lt;br /&gt;
Raspberry Pi 2 Model B Rev 1.1&lt;br /&gt;
&lt;br /&gt;
root@green-pi:~ $ cat /proc/device-tree/model ; echo&lt;br /&gt;
Raspberry Pi 3 Model B Rev 1.2&lt;br /&gt;
&lt;br /&gt;
roy@yellow-pi:~ $cat /proc/device-tree/model ; echo&lt;br /&gt;
Raspberry Pi 4 Model B Rev 1.1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
While this works well, for the latter, the pi4, it doesn&#039;t tell how much memory I have. It comes in variants of 1, 2 and 4GB, and this is the latter.&lt;br /&gt;
&lt;br /&gt;
== Monitoring ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;vcgencmd&#039;&#039;&#039; from &#039;&#039;&#039;/opt/vc/bin&#039;&#039;&#039;, but symlinked to &#039;&#039;&#039;/usr/bin&#039;&#039;&#039; so it&#039;s available in path, is useful for fetching hardware info about the pi. For example, measuring the temperature&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
root@yellow-pi:~# vcgencmd measure_temp&lt;br /&gt;
temp=63.0&#039;C&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The command is generally badly documented and parts of it seems outdated for newer hardware. Here&#039;s the output from a Raspberry pi 4 with 4GB RAM&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
roy@yellow-pi:~ $ vcgencmd get_mem arm&lt;br /&gt;
arm=948M&lt;br /&gt;
roy@yellow-pi:~ $ vcgencmd get_mem gpu&lt;br /&gt;
gpu=76M&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= BIOS upgrade from Linux =&lt;br /&gt;
&lt;br /&gt;
Generally, BIOS upgrades have been moved to the BIOS itself these days. This saves a lot of work and quite possibly lives after those who earier rammed their heads through walls, now can upgrade directly from the internet instead of using obscure operating systems best avoided. Sometimes, however, one must use these nevertheless. This is a quick run-through on your options.&lt;br /&gt;
&lt;br /&gt;
== DOS ==&lt;br /&gt;
&lt;br /&gt;
Most non-automatic BIOS upgrades are installed from DOS. Doing a BIOS upgrade this way, is generally non-problematic. Just install a USB thingie with [https://www.freedos.org/ FreeDOS], copy your file(s) onto the thing and boot on it. The commandline is the same as old MS/DOS, except a wee bit more userfriendly, but not a lot.&lt;br /&gt;
&lt;br /&gt;
== Windows ==&lt;br /&gt;
&lt;br /&gt;
Some macahines, like laptops from &#039;&#039;&#039;HP&#039;&#039;&#039;, may have BIOS upgrades that are made to be installed from Windows and won&#039;t run in FreeDOS or MS/DOS, instead throwing an error, saying &#039;&#039;&#039;This program cannot be run in DOS mode&#039;&#039;&#039;. This means you&#039;ll have to boot on a Windows rescue disc and do the job from there. Googling this, tells you it&#039;s quite easy, you just choose &#039;make rescue disc&#039; from Windows, and it&#039;s all good, except if you don&#039;t run Windows, that is. To remedy this problem, do as follows:&lt;br /&gt;
&lt;br /&gt;
=== Download Windows ===&lt;br /&gt;
&lt;br /&gt;
Since you don&#039;t run Windows and possibly don&#039;t have a spouse or friend around with such unhealthy habits either, you need to get it. It&#039;s quite easy - just google &#039;download windows&#039; and it&#039;ll send you to [https://www.microsoft.com/en-us/software-download/windows10ISO somewhere like this].&lt;br /&gt;
&lt;br /&gt;
=== Burn it! ===&lt;br /&gt;
&lt;br /&gt;
Now it&#039;s time to burn the installer on a DVD ROM. You&#039;ll need a double-layered one, since the OS is &amp;gt; 4.7GiB, but I&#039;m sure you have a ton of those lying around. Now, just place your optical medium in your optical drive and burn, baby, burn!&lt;br /&gt;
&lt;br /&gt;
=== Or make a USB thing? ===&lt;br /&gt;
&lt;br /&gt;
Not a lot of machines have optical drives these days, so you may want to use an USB pen drive or something instead. This is easy, just make the USB bootable with the Windows application Microsoft has made for this. Unfortunately, this only runs on Windows, and unlike stuff like Debian, where the &#039;&#039;&#039;iso&#039;&#039;&#039; file can be dd&#039;ed directly onto a USB drive to make it bootable, the Windows &#039;&#039;&#039;iso&#039;&#039;&#039;s don&#039;t come with this luxury. There are lots of methods to make bootable USB things from iso files out there, but the only thing most of them have in common, is that they generally don&#039;t work.&lt;br /&gt;
&lt;br /&gt;
==== WoeUSB ====&lt;br /&gt;
&lt;br /&gt;
After hours of swearing, it&#039;s nice to come across software like [https://github.com/slacka/WoeUSB WoeUSB]. It may not be perfect, it relies on a bunch of GUI stuff you&#039;ll never need and so on, but it &#039;&#039;&#039;&#039;&#039;works&#039;&#039;&#039;&#039;&#039;, and that&#039;s the important part! Just clone the repo and RTFM and it&#039;s all nice. It&#039;s slow, but hell, getting a windows machine and/or an optical drive might be slower.&lt;br /&gt;
&lt;br /&gt;
WoeUSB does nothing fancy, but it &#039;&#039;&#039;does&#039;&#039;&#039; work. It will create a filesystem, FAT32 or NTFS (better use NTFS, FAT32 has its limits). It creates normal filesystems and so on. Just make sure to copy in the BIOS update file, usually an exe file, to run when Windows is up and running.&lt;br /&gt;
&lt;br /&gt;
==== Install BIOS ====&lt;br /&gt;
&lt;br /&gt;
Boot on the Windows USB thing and choose &#039;repair computer&#039; and then &#039;command prompt&#039;. Find the install file, and if you&#039;re lucky, you&#039;ll find it needs a 32bit OS, just like I did. Since the 64bit version doesn&#039;t include 32bit compatibility in the installer, revert to downloading the 32bit version of windows and start over. Pray to your favourite god(s) not to get across such machines again - it might help.&lt;br /&gt;
&lt;br /&gt;
= 3D printer stuff =&lt;br /&gt;
&lt;br /&gt;
Below are a number of not very ordered paragraphs about 3D printer related stuff, mostly based on my experience. Their content may be interesting or perhaps practical knowledge, but then, that depends on the reader.&lt;br /&gt;
&lt;br /&gt;
== 3D printer related introductions on youtube or elsewhere ==&lt;br /&gt;
&lt;br /&gt;
First off, I&#039;d like to mention some youtube videos that are all (or mostly) a nice start if you&#039;re new to 3D printers.&lt;br /&gt;
&lt;br /&gt;
=== [https://www.youtube.com/watch?v=nb-Bzf4nQdE&amp;amp;list=PLDJMid0lOOYnkcFhz6rfQ6Uj8x7meNJJx Thomas Salanderer&#039;s 10-video series on 3D printing basics] ===&lt;br /&gt;
&lt;br /&gt;
Thomas Salanderer is a an experienced 3D printer user/admin/fixer/etc and he has a lot of interesting videos. Some accuse him for being a [Prusa https://www.prusa3d.com/] fanboy, which he quite obviously is, but that doesn&#039;t stop him from making interesting and somewhat neutral videos. The series walks you thought the first steps of how things work and so on and hopefully opens more doors than anything else I&#039;ve seen.&lt;br /&gt;
&lt;br /&gt;
=== [https://www.youtube.com/watch?v=rp3r921DBGI Teaching Tech&#039;s &amp;quot;3D printer tuning reborn&amp;quot;] ===&lt;br /&gt;
&lt;br /&gt;
Teaching Tech is, like Salanderer or even more, good pedagogically and explains a lot. They (or he) do a bunch of testing and describing pros and cons with different things, just like other youtubers in the sme business. The mentioned video shows how to tune a 3D printer after you have first learned the basics, and leans on a webpage made to help you out without too much manual work.&lt;br /&gt;
&lt;br /&gt;
This was a short list, but I guess it&#039;ll grow over time.&lt;br /&gt;
&lt;br /&gt;
== Hydrophilic filament ==&lt;br /&gt;
&lt;br /&gt;
Most popular filament types, including PLA, PETG, PP or PA (Polyamide, normally known as Nylon) and virtualy any filament type named [https://www.matterhackers.com/news/filament-and-water poly-something] (and thus with an acronym of P-something) are hydrophilic (also (somewhat incorrectly) called hydroscopic), meaning so long they&#039;re dryer than the atmosphere around them, they&#039;ll do their best to suck out the atmosphere&#039;s humidity. This is why most filament are shrink-wrapped with a small bag of silica gel in it. If such filament is exposed for normal humid air for some time, it&#039;ll become very hard to use. Most of my experience is with PLA, which can handle a bit (depending on make), but still not a lot. With PLA, if you end up with prints where the filament seems not to stick, it may help with a higher temperature. Otherwise, the filament must be [https://all3dp.com/2/how-to-dry-filament-pla-abs-and-nylon/ baked]. If you don&#039;t want to use your oven, try something like a [https://www.jula.no/catalog/hjem-og-husholdning/kjokkenmaskiner/mattilberedningsapparater/frukt-sopptorker/frukt-sopptorker-001641/#tab02 fruit and mushroom dryer]. Then get a good, sealble plastic box and add something like half a kilogram of [https://www.ebay.com/sch/sis.html?_nkw=1KG+Orange+Replacement+Desiccant+Indicating+Silica+Gel+Beads+for+Drawers%2C+Camera&amp;amp;_id=131938742628&amp;amp;&amp;amp;_trksid=p2057872.m2749.l2658 silica gel] to an old sock, tie it and put it in the your new dry box.&lt;br /&gt;
&lt;br /&gt;
Please note that ABS is hydrophobic, so you won&#039;t have to worry too much there. Also, remember that PA/Nylon is extremely hydrophilic. Even a couple of days in normal air humidity can ruin it completely and will require baking.&lt;br /&gt;
&lt;br /&gt;
== Upgrading the firmware on an Ender 3 ==&lt;br /&gt;
&lt;br /&gt;
This is about upgrading the firmware, and thus also flashing a bootloader to the Creality Ender 3 3D printer. Most of this is well documented on several place, like o [https://www.youtube.com/watch?v=fIl5X2ffdyo the video from Teaching tech] and elsewhere, but I&#039;ll just summarise some issues I had.&lt;br /&gt;
&lt;br /&gt;
=== Using an arduino Nano as a programmer ===&lt;br /&gt;
&lt;br /&gt;
Quick note before you read on. If you have an Ender 3 controller version 1.1.5 or newer (or perhaps even a bit older), a CR-10S or some other more or less modern printers or controllers, they come with a bootloader installed already, so don&#039;t bother flashing one. The one that&#039;s in there already, should work well. So if you have one of these, just skip this and jump to the [[Roy&#039;s_notes#Flashing_the_printer|next section]].&lt;br /&gt;
&lt;br /&gt;
However, the normal CR-10 (without the S), Ender 3 and a few other printers from Creality come without a bootloader, so you&#039;ll need to flash one before upgrading the firmware. Well, strictly speakning, you don&#039;t need one, you can save those 8kB or so for other stuff and use a programmer to write the whole firmware, but then you&#039;ll need to wire up everything every time you want a new firmware, so in my world, you &#039;&#039;&#039;do&#039;&#039;&#039; need the bootloader, since it&#039;s easier.&lt;br /&gt;
&lt;br /&gt;
To install a bootloader, you&#039;ll need a programmer, and I didn&#039;t have one available. Having some el-cheapo china-copies of Arduinos around, I read I could use one and tried so. Although the docs mostly mention the Uno etc, it&#039;s just as simple with the Nano copy.&lt;br /&gt;
&lt;br /&gt;
So, grab an arduino, plug it to your machine with a USB cable, and, using the Arduino IDE, use the ArduinoISP sketch there (found under Examples) to burn the software needed for the arduino to work as a programmer. When this is done, connect a 10µF capacitor between RST and GND to stop it from resetting when used as a programmer. Connect the MOSI, MISO and SCK pins from the ICSP block (that little isolated 6-pin block on top of the ardu). See [https://www.arduino.cc/en/Tutorial/ArduinoISP here] for a pinout. Then find Vcc and GND either on the ICSP block or elsewhere. Some sites say that on some boards you shouldn&#039;t use the pins on the ICSP block for this. I doubt it matters, though. Then connect another jumper wire from pin 10 on the ardu to work as the reset pin outwards to the chip being programmed (that is, on the printer). The ICSP jumper block pin layout is the same on the printer and on the ardu, and probably elsewhere. Sometimes [https://xkcd.com/927/ standardisation] actually works…&lt;br /&gt;
&lt;br /&gt;
See https://cloud.karlsbakk.net/index.php/s/zw48YJjzaf8Rc2F for a pic with the ardu (this wiki is broken atm, will fix it later)&lt;br /&gt;
&lt;br /&gt;
== Flashing the printer ==&lt;br /&gt;
&lt;br /&gt;
When the boot loader is in place, possibly after some wierd errors from during the process, the screen on the 3d printer will go blank and it&#039;ll behave like being bricked. This is ok. Now disconnect the wires and connect the USB cable between computer and printer. If you haven&#039;t installed support for the Sanguino board, that is, the variant of the 1284-chip and surrounding electronics that is the core of the, you need to install it first. In the Arduino IDE, choose the Tools / Boards / Boards manager boot option and search for Sanguino. After this, you should find the Sanguino or Sanguino 1284p in the boards menu. After this, you should be able to communicate with the printer&#039;s controller. Download the [https://www.th3dstudio.com/knowledgebase/th3d-unified-firmware-package/ TH3D unified firmware], making sure it&#039;s the last version. Uncompress the zip and with Finder/Explorer/whateversomething&#039;scalledonlinux, browse to &#039;&#039;&#039;TH3DUF_R2/Firmware/TH3DUF_R2.ino&#039;&#039;&#039; and open it. It should open directly in the Android IDE. Keep in mind that the names TH3DUF_R2 and TH3DUF_R2.ino will vary between versions, but you get the point. Now configure it for your particular needs. You&#039;ll find most of this in the Configuration.h tab (that&#039;s really a file). Most of the other files won&#039;t be necessary unless you&#039;re doing some more advanced stuff, like replacing th controller with something non-standard or similar, but then again, that&#039;s another chapter (or book, even). The video mentioned above describes this well. After flashing the new firmware, you&#039;ll probably get some timeouts and errors, since apparently it resets the printer after giving it the new firmware, but without notifying the flashing software of it doing so. If this happens, calm down and reboot the printer and check its tiny monitor - it should work. If it doesn&#039;t work, and if you flashed the bootload yourself, try to flash it again, and if that doesn&#039;t work, try flashing the programmer again yet another time, just for kicks. Again, if you have a newer controller like the v1.1.5, don&#039;t touch the bootloader, as the one already installed, should work well as it is.&lt;br /&gt;
&lt;br /&gt;
PS: I tried enabling &#039;&#039;&#039;MANUAL_MESH_LEVELING&#039;&#039;&#039;, which in the code says that &#039;&#039;If used with a 1284P board the bootscreen will be disabled to save space&#039;&#039;. This effectively disabled the whole printer, and apparently may be making the firmware image a wee bit too large for it to fit the 1284P on the ender. It works well without it, though, and it may be fixed by now, since I tested this back in early 2019.&lt;br /&gt;
&lt;br /&gt;
== And then… ==&lt;br /&gt;
&lt;br /&gt;
With the new firmware in place, the printer should work as before, although with thermal runaway protection to better avoid fires in case the shit hits the fan, and to allow for things like autolevelling. With any luck, [https://www.precisionpiezo.co.uk/ this thing] may be ready for use by the time you read this - it surely looks nice!&lt;br /&gt;
&lt;br /&gt;
= Octoprint/Octopi =&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;This could have been under some other section, but again, I just branch out even though most of it is about sections mentioned elsewhere.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
When setting up a 3d printer for the first time, you usually get an SD card for storage and transfer data to the printer using [https://en.wikipedia.org/wiki/Sneakernet Sneakernet]. Some printers use micro SD cards, while other fullsize SD cards, which imho is better, since they don&#039;t get lost that easily, but otherwise do the same thing. This works, but is somewhat tedious. If you want to control the printer from a PC or phone, there&#039;s a simple trick for that as well - octoprint.&lt;br /&gt;
&lt;br /&gt;
[https://octoprint.org/ Octoprint], written by Gina Häußge, runs on most platforms including linux, windows, BSD*, macos etc. It supports controlling a camera to some extent out of the box and there&#039;s a large number of plugins availablee to do a lot of things you possibly haven&#039;t thought of (and quite often, you&#039;d ever need). The easiest way to install it, is to just grab a Raspberry pi - preferably some of the newer models (will get to that later) and download [https://octoprint.org/download/ octopi] and follow the instructions on that page.&lt;br /&gt;
&lt;br /&gt;
== Performance issues ==&lt;br /&gt;
&lt;br /&gt;
Some report (and I have seen it myself) issues with the pi&#039;s performance with regards to both handling the octoprint processes (which should be as close to realtime as possible) and handling other stuff like I/O, networking etc. The point is that at pi3 or older, has all peripherals connected to an internal USB hub. This might be practical, but performance-wise it&#039;s &#039;&#039;&#039;&#039;&#039;not&#039;&#039;&#039;&#039;&#039;. If you in addition connect a webcam to USB, you&#039;re asking for trouble, since USB will be your bottleneck. With a raspberry pi camera, the ones connected to the pi directly with a ribbon cable, this should not use USB, so it&#039;s better. Still, again, for older pi&#039;s, there might be some shortage in therms of cpu or i/o. The octopi runs something like raspbian which is a fork of debian which is a linux distro, so it all boils down to knowing linux.&lt;br /&gt;
&lt;br /&gt;
Your typical octopi will run octoprint, a streamer, usually &#039;&#039;&#039;mjpg-streamer&#039;&#039;&#039;, a simple, lightweight videostreamer that outputs a stream of jpeg-images (about the same format as cinemas use - that is - not MPEG). This may be a bit tough on the cpu and potentially i/o. Add inn a dash of USB overload and you&#039;re may see trouble.&lt;br /&gt;
&lt;br /&gt;
Still - a pi3 should be able to handle the load, but it might help to prioritise corretly. The octoprint process is the important part here, so we could give that full priority both in CPU and I/O and. Unfortunately, it doesn&#039;t seem like the current octopi has been migrated to using systemd for the startup. We&#039;ll deal with this later. To fix this in the old SysV init style file present there, the following patch should work against the file /etc/init.d/octoprint&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;diff&amp;quot;&amp;gt;&lt;br /&gt;
--- octoprint.old	2020-07-20 18:46:10.166651965 +0200&lt;br /&gt;
+++ octoprint	2020-07-20 18:53:21.724803211 +0200&lt;br /&gt;
@@ -22,6 +22,9 @@&lt;br /&gt;
 PIDFILE=/var/run/$NAME.pid&lt;br /&gt;
 PKGNAME=octoprint&lt;br /&gt;
 SCRIPTNAME=/etc/init.d/$PKGNAME&lt;br /&gt;
+NICELEVEL=-19                        # Top CPU priority&lt;br /&gt;
+IONICE_CLASS=1                       # Realtime I/O class&lt;br /&gt;
+IONICE_PRIORITY=0                    # Realtime I/O priority (probably not needed with class=realtime)&lt;br /&gt;
&lt;br /&gt;
 # Read configuration variable file if it is present&lt;br /&gt;
 [ -r /etc/default/$PKGNAME ] &amp;amp;&amp;amp; . /etc/default/$PKGNAME&lt;br /&gt;
@@ -70,10 +73,11 @@&lt;br /&gt;
&lt;br /&gt;
    is_alive $PIDFILE&lt;br /&gt;
    RETVAL=&amp;quot;$?&amp;quot;&lt;br /&gt;
-&lt;br /&gt;
    if [ $RETVAL != 0 ]; then&lt;br /&gt;
        start-stop-daemon --start --background --quiet --pidfile $PIDFILE --make-pidfile \&lt;br /&gt;
-       --exec $DAEMON --chuid $OCTOPRINT_USER --user $OCTOPRINT_USER --umask $UMASK -- serve $DAEMON_ARGS&lt;br /&gt;
+       --exec $DAEMON --chuid $OCTOPRINT_USER --user $OCTOPRINT_USER --umask $UMASK \&lt;br /&gt;
+       --nicelevel $NICELEVEL --ioched $IONICE_CLASS:$IONICE_PRIORITY \&lt;br /&gt;
+       --serve $DAEMON_ARGS&lt;br /&gt;
        RETVAL=&amp;quot;$?&amp;quot;&lt;br /&gt;
    fi&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This ismply upgrades the process to be allowed to use most of the resources on the pi, regardless of what other processes are whining about.&lt;br /&gt;
&lt;br /&gt;
PS: Code not tested - I don&#039;t have a pi right here. Will test later, but I&#039;m pretty sure it&#039;ll work. After all, it&#039;s just a few new arguments to start-stop-daemon&lt;br /&gt;
&lt;br /&gt;
roy&lt;/div&gt;</summary>
		<author><name>Roy</name></author>
	</entry>
	<entry>
		<id>https://wiki.malinux.no/index.php?title=Roy%27s_notes&amp;diff=172</id>
		<title>Roy&#039;s notes</title>
		<link rel="alternate" type="text/html" href="https://wiki.malinux.no/index.php?title=Roy%27s_notes&amp;diff=172"/>
		<updated>2020-09-01T10:14:15Z</updated>

		<summary type="html">&lt;p&gt;Roy: /* Create LVM cache */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= LVM, md and friends =&lt;br /&gt;
&lt;br /&gt;
== Linux&#039; Logical Volume Manager (LVM) ==&lt;br /&gt;
&lt;br /&gt;
=== LVM in general ===&lt;br /&gt;
&lt;br /&gt;
LVM is designed to be an abstraction layer on top of physical drives or RAID, typically [https://raid.wiki.kernel.org/index.php/RAID_setup mdraid] or [https://help.ubuntu.com/community/FakeRaidHowto fakeraid]. Keep in mind that fakeraid should be avoided unless you really need it, like in conjunction with dual-booting linux and windows on fakeraid. LVM broadly consists of three elements, the &amp;quot;physical&amp;quot; devices (PV), the volume group (VG) and the logical volume (LV). There can be multiple PVs, VGs and LVs, depending on requirement. More about this below. All commands are given as examples, and all of them can be fine-tuned using extra flags in need of so. In my experience, the defaults work well for most usecases.&lt;br /&gt;
&lt;br /&gt;
I&#039;m mentioning filesystem below too. Where I write ext4, the samme applies to ext2 and ext3.&lt;br /&gt;
&lt;br /&gt;
==== Create a PV ====&lt;br /&gt;
&lt;br /&gt;
A PV is the &amp;quot;physical&amp;quot; parts. This does not need to be a physical disk, but can also be another RAID, be it an mdraid, fakeraid, hardware raid, a virtual disk on a SAN or otherwisee or a partition on one of those. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#  These add three PVs, one on a drive (or hardware raid) and another two on mdraids.&lt;br /&gt;
pvcreate /dev/sdb&lt;br /&gt;
pvcreate /dev/md1 /dev/md2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For more information about pvcreate, see [https://linux.die.net/man/8/pvcreate the manual].&lt;br /&gt;
&lt;br /&gt;
==== Create a VG ====&lt;br /&gt;
&lt;br /&gt;
The volume group consists of one or more PVs grouped together on which LVs can be placed. If several PVs are grouped in a VG, it&#039;s generally a good idea to make sure these PVs have some sort of redundancy, as in mdraid/fakeraid or hwraid. Otherwise it will be like using a [https://en.wikipedia.org/wiki/RAID RAID-0] with a single point of failure on each of the independant drives. LVM has [https://unix.stackexchange.com/questions/150644/raiding-with-lvm-vs-mdraid-pros-and-cons  RAID code in it] as well, so you can use that. I haven&#039;t done so myself, as I generally stick to mraid. The reason is mdraid is, in my opinion older and more stable and has more users (meaning bugs are reported and fixed faster whenever they are found). That said, I beleive the actual RAID code used in LVM RAID are the same function calls as for mdraid, so it may not be much of a difference. I still stick with mdraid. To create a VG, run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create volume group my_vg&lt;br /&gt;
vgcreate my_vg /dev/md1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that if vgcreate is run with a PV (as /dev/md1 above) that is not defined as a PV (like above), this is done implicitly, so if you don&#039;t need any special flags to pvcreate, you can simply skip it and let vgcreate do that for you.&lt;br /&gt;
&lt;br /&gt;
==== Create an LV ====&lt;br /&gt;
&lt;br /&gt;
LVs can be compared to partitions, somehow, since they are bounderies of a fraction or all of that of a VG. The difference between them and a partition, however, is that they can be grown or shrunk easily and also moved around between PVs without downtime. This flexibility makes them superiour to partitions as your system can be changed without users noticing it. By default, an LV is alloated &amp;quot;thickly&amp;quot;, meaning all the data given to it, is allocated from the VG and thus the PV. The following makes a 100GB LV named &amp;quot;thicklv&amp;quot;. When making an LV, I usually allocate what&#039;s needed plus some more, but not everything, just to make sure it&#039;s space available for growth on any of the LVs on the VG, or new LVs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a thick provisioned LV named thicklv on the VG my_vg&lt;br /&gt;
lvcreate -n thicklv -L 100G my_vg&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After the LV is created, a filesystem can be placed on it unless it is meant to be used directly. The application for direct use include swap space, VM storage and certain database systems. Most of these will, however, work on filesystems too, although my testing has shown that on swap space, there is a significant performance gain for using dedicated storage without a filesystem. As for filesystems, most Linux users use either ext4 or xfs. Personally, I generally use XFS these days. See my notes below on filesystem choice.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a filesystem on the LV - this could have been mkfs -t ext4 or whatever filesystem you choose&lt;br /&gt;
mkfs -t xfs /dev/my_vg/thicklv&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then just edit /etc/fstab with correct data and run mount -a, and you should be all set.&lt;br /&gt;
&lt;br /&gt;
==== Create LVM cache ====&lt;br /&gt;
LVMcache is LVM&#039;s solution to caching a slowish filesystem on spinning rust with the help of much faster SSDs. For this to work, use a separate SSD or a mirror or two (just in case) an add the new disk/md dev to the same VG. In this case, we use a small mirror, md1. LVM is not able to cache to a disk or partition outside the volume group.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
vgextend data /dev/md1&lt;br /&gt;
  Physical volume &amp;quot;/dev/md1&amp;quot; successfully created.&lt;br /&gt;
  Volume group &amp;quot;data&amp;quot; successfully extended&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Thn create two LVs, one for the data (contents of files) and one for the metadata (filenames, directories, attributes etc). Typically, the metadata part won&#039;t need to be very large. 100M should usually do unless you have ekstremely many small files. I guess there are ways to calculate it, but again, 1GB should do for everyone (or was that 640k?). As for the data cache, I chose to use 40G here for a 15TB RAID. It will only cache what actively use anyway, so no need for overkill.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
lvcreate -L 1G -n _cache_meta data /dev/md1&lt;br /&gt;
lvcreate -L 100G -n _cache data /dev/md1&lt;br /&gt;
&lt;br /&gt;
# Some would want --cachemode writeback, but if paranoid, I wouldn&#039;t recommend it. Metadata or data can be easily corrupted in case of failure. Most filesystems will however recover from this these days since they use journaling. It &#039;&#039;really&#039;&#039; speeds up things.&lt;br /&gt;
lvconvert --type cache-pool --cachemode writethrough --poolmetadata data/_cache_meta data/_cache&lt;br /&gt;
lvconvert --type cache --cachepool data/_cache data/data&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
That should be it. If you benchmarked the disk before this, you should try again and you&#039;ll probably get a nice surprise. If not, well, see below how to turn this off again :)&lt;br /&gt;
&lt;br /&gt;
==== Disabling LVM cache ====&lt;br /&gt;
&lt;br /&gt;
If you for some reason want to disable caching, this will do it cleanly and remove the LVs earlier created for caching the main device.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
lvconvert --uncache data/data&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Growing devices ====&lt;br /&gt;
&lt;br /&gt;
LVM objects can be grown and shrunk. If a PV resides on a RAID where a new drive has been added or otherwise grown, or on a partition or virtual disk that has been extended, the PV must be updated to reflect these changes. The following command will grow the PV to the maximum available on the underlying storage. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Resize the PV /dev/md (not the RAID, only the PV on the RAID) to its full size&lt;br /&gt;
pvresize /dev/md1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If a new PV is added, the VG can be grown to add the space on that in addition to what&#039;s there already. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Extend my_vg to include md2 and its space&lt;br /&gt;
vgextend my_vg /dev/md2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
With more space available in the VG, the LV can now be extended. Let&#039;s add another 50GB to it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Extend thicklv - add 50GB. If you know you won&#039;t need the space anywhere else, you may want to&lt;br /&gt;
# lvresize -l+100%FREE instead. Keep in mind the difference between -l (extents) and -L (bytes)&lt;br /&gt;
lvresize -L +50G my_vg/thicklv&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Growing filesystems ====&lt;br /&gt;
After the LV has grown, run &#039;&#039;xfs_growfs&#039;&#039; (xfs) or &#039;&#039;resize2fs&#039;&#039; (ext4) to make use of the new data. To grow the filesystem to all available space on ext4, run the below command.  To partly grow the filesystem or to shrink it or otherwise, please see the manuals.&lt;br /&gt;
&lt;br /&gt;
The filesystem can be mounted when this is run. If you for some reason get an &#039;&#039;&#039;access denied&#039;&#039;&#039; error when running this as root or with sudo, it&#039;s likely caused by a filesystem error. To fix this, unmount the filesystem first and run &#039;&#039;&#039;fsck -f /dev/my_vg/thicklv&#039;&#039;&#039; and remount it before retrying to extend it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
resize2fs /dev/my_vg/thicklv&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Similarly, with XFS, but note that xfs_growfs doesn&#039;t take the device name, but the filesystem&#039;s mount point. In the case of XFS, also note that the filesystem &#039;&#039;&#039;&#039;&#039;must&#039;&#039;&#039;&#039;&#039; be mounted to be grown. This, in contrast to how it was in the old days when filesystems had to be unmounted to be grown.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
xfs_growfs /my_mountpoint&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Rename system VG ====&lt;br /&gt;
&lt;br /&gt;
Some distros create VG names like those-from-a-sysadmin-with-a-well-developed-paranoia-not-to-hit-a-duplicate. Debian, for instance, uses names like &amp;quot;my-full-hostname-vg&amp;quot;. Personally, I don&#039;t like these, since if I were to move a disk or vdisk around to somewhere else, I&#039;d make sure not to add a disk named &#039;sys&#039; to an existing system. If you do, most distros will refuse to use the VGs with duplicate names, resulting in the OS not booting until either one is specified by its UUID or just one removed. As I&#039;m aware of this, I stick to the super-risky thing of all system VGs named &#039;sys&#039; and so on.&lt;br /&gt;
&lt;br /&gt;
If you do this, keep in mind that it may blow up your computer and take your girl- or boyfriend with it or even make either of them pregnant, allowing Trump to rule your life and generally make things suck. You&#039;re on your own!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Rename the VG&lt;br /&gt;
vgrename my-full-hostname-vg sys&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, in /boot/grub/grub.cfg, change the old lv path from something like &#039;/dev/mapper/debian--stretch--machine--vg-root&#039; to your new and fancy &#039;/dev/sys/root. Likewise, in /etc/fstab, change occurences of &#039;/dev/mapper/debian--stretch--machine--vg-&#039; (or similar) with &#039;/dev/sys/&#039;. Here, this was like this - the old ones commented out.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;fstab&amp;quot;&amp;gt;&lt;br /&gt;
#/dev/mapper/debian--stretch--box--vg-root      /               ext4            errors=remount-ro,discard       0       1&lt;br /&gt;
/dev/sys/root                                   /               ext4            errors=remount-ro,discard       0       1&lt;br /&gt;
# /boot was on /dev/vda1 during installation&lt;br /&gt;
UUID=myverylonguuidwithatonofgoodinfoinit       /boot           ext2            defaults                        0       2&lt;br /&gt;
#/dev/mapper/debian--stretch--box--vg-swap_1    none            swap            sw                              0       0&lt;br /&gt;
/dev/sys/swap_1                                 none            swap            sw                              0       0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Update /etc/initramfs-tools/conf.d/resume with similar data for swap.&lt;br /&gt;
&lt;br /&gt;
You might want to run &#039;update-initramfs -u -k all&#039; after this, but I&#039;m not sure if it&#039;s needed.&lt;br /&gt;
&lt;br /&gt;
Now, pray to the nearest god(s) and give it a reboot and it should (probably) work.&lt;br /&gt;
&lt;br /&gt;
After reboot, run &#039;&#039;&#039;swapoff -a&#039;&#039;&#039;, then &#039;&#039;&#039;mkswap /dev/sys/swap_1&#039;&#039;&#039; (or whatever it&#039;s called on your system) and &#039;&#039;&#039;swapon -a&#039;&#039;&#039; again. You may want to give it another reboot or two for kicks, but it should work well even without that.&lt;br /&gt;
&lt;br /&gt;
=== Migration tools ===&lt;br /&gt;
&lt;br /&gt;
At times, storage regimes change, new storage is added and sometimes it&#039;s not easy to migrate with the current hardware or its support systems. Once I had to migrate a 45TiB fileserver from one storage system to another, preferably without downtime. The server originally had three 15TiB PVs of which two were full and the third half full. I resorted to using [https://linux.die.net/man/8/pvmove pvmove] to just move the data on the PVs in use to a new PV. We started out with creating a new 50TiB PV, sde, and then to pvmove.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Attach /dev/sde to the VG my_vg&lt;br /&gt;
vgextend my_vg /dev/sde&lt;br /&gt;
&lt;br /&gt;
# Move the contents from /dev/sdb over to /dev/sde block by block. If a target is not given in pvmove,&lt;br /&gt;
# the contents of the source (sdb here) will be put somewhere else in the pool.&lt;br /&gt;
pvmove /dev/sdb /dev/sde&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This took a while (as in a week or so) - the pvmove command uses old code and logic (or at least did that when I migrated this in November 2016), but it affected performance on the server very little, so users didn&#039;t notice. After the first PV was migrated, I continued with the other two, one after the other, and after a month or so, it was migrated. We used this on a number of large fileservers, and it worked flawlessly. Before doing the production servers I also tried interrupting pvmove in various ways, including hard resets, and it just kept on after the reboot.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;NOTE:&#039;&#039;&#039;&#039;&#039; &#039;&#039;Even though it worked well for us, &#039;&#039;&#039;always&#039;&#039;&#039; keep a good backup before doing this. Things may go wrong, and without a good backup, you may be looking for a hard-to-find new job the next morning&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
==== mdadm workarounds ====&lt;br /&gt;
&lt;br /&gt;
===== Migrate from a mirror (raid-1) to raid-10 =====&lt;br /&gt;
&lt;br /&gt;
Create a mirror&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sdb /dev/sdc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
LVM (pv/vg/lv) on md0 (see above), put a filesystem on the lv and fill it with some data.&lt;br /&gt;
&lt;br /&gt;
Now, some months later, you want to change this to raid-10 to allow for the same amount of redundancy, but to allow more disks into the system.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mdadm --grow /dev/md0 --level=10&lt;br /&gt;
mdadm: Impossibly level change request for RAID1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So - no - doesn&#039;t work. But - we&#039;re on &lt;br /&gt;
&lt;br /&gt;
Since we&#039;re on lvm already, this&#039;ll be easy. If you&#039;re using filesystems directly on partitions, you can do this the same way, but without the pvmove part, using rsync or whateever you like instead. I&#039;d recommend using lvm for for the new raid, which should be rather obvious from this article. Now plug in a new drive and create a new raid10 on that one. If you two new drives, install both. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# change &amp;quot;missing&amp;quot; to the other device name if you installed two new drives&lt;br /&gt;
mdadm --create /dev/md1 --level=10 --raid-devices=2 /dev/vdd missing&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, as described above, just vgextend the vg, adding the new raid and run pvmove to move the data from the old pv (residing on the old raid1) to the new pv (on raid10). Afte rpvmove is finished (which may take awile, see above), just&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
vgreduce raidtest /dev/md0&lt;br /&gt;
pvremove /dev/md0&lt;br /&gt;
mdadm --stop /dev/md0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
…and your disk is free to be added to the new array. If the new raid is running in degraded mode (if you created it with just one drive), better don&#039;t wait too long, since you don&#039;t have redundancy. Just mdadm --add the devs.&lt;br /&gt;
&lt;br /&gt;
If you now have /dev/mdstat telling you your raid10 is active and have three drives, of which one is a spare, it should look something like this&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5] [raid4] [raid10]&lt;br /&gt;
md1 : active raid10 vdc[3](S) vdb[2] vdd[0]&lt;br /&gt;
      8380416 blocks super 1.2 2 near-copies [2/2] [UU]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Just mdadm --grow --raid-devices=3 /dev/md1&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;RAID section is not complete. I&#039;ll write more on migraing from raid10 to raid6 later. It&#039;s not straight forward, but easier than this one :)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== Thin provisioned LVs ===&lt;br /&gt;
&lt;br /&gt;
Thin provisioning on LVM is a method used for not allocating all the space given to an LV. For instance, if you have a 1TB VG and want to give an LV 500GB, although it currently only uses a fraction of that, a thin lv can be a good alternative. This will allow for adding a limit to how much it can use, but also to let it grow dynamically without manual work by the sysadmin. Thin provisioning adds another layer of abstaction by creating a special LV as a &#039;&#039;thin pool&#039;&#039; from which data is allocated to the &#039;&#039;thin volume(s)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== Create a thin pool ====&lt;br /&gt;
&lt;br /&gt;
Allocate 1TB to the thin pool to be used for thinly provisioned LVs. Keep in mind that the space allocated to the thin pool is in fact thick provisioned. Only the volumes put on &#039;&#039;thinpool&#039;&#039; are thin provisioned. This will create two hidden LVs, one for data and one for metadata. Normally the defaults will do, but check the manual if the data doesn&#039;t match the usual patterns (such as billions of files, resulting in huge amounts of metadata). I &#039;&#039;beleive&#039;&#039; the metadata part should be resizable at a later time if needed, but I have not tested it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a pool for thin LVs. Keep in mind that the pool itself is not thin provisioned, only the volumes residing on it&lt;br /&gt;
lvcreate --size 1T --type thin-pool --thinpool thinpool my_vg&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Create a thin volume ====&lt;br /&gt;
&lt;br /&gt;
You have the thinpool, now put a thin volume on it. It will allocate some space for metadata, but probably not much (a few megs, perhaps).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Now, create a volume with a virtual (-V) size of half a terabyte named thin_pool, but using the thinpool (-T) named thin_pool for storage&lt;br /&gt;
lvcreate -V 500G -T my_vg/thin_pool --name thinvol&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The new volume&#039;s device name will be /dev/thinvol. Now, create a filesystem on it, add to fstab and mount it. The &#039;&#039;&#039;df&#039;&#039;&#039; command will return available space according to the virtual size (-V), while lvs will show how much data is actually used on each of the thinly provisioned volumes.&lt;br /&gt;
&lt;br /&gt;
== Filesystem dilemmas ==&lt;br /&gt;
&lt;br /&gt;
=== XFS or ext4 or something else ===&lt;br /&gt;
The choice of filesystem varies for your use. Distros such as RHEL/CentOS has moved to XFS by default from v7. Debian/Ubuntu still sticks to ext4, like most other. I&#039;ll discuss my thoughts below on ext4 vs XFS and leave the other filesystems for later.&lt;br /&gt;
&lt;br /&gt;
==== ext4 ====&lt;br /&gt;
ext4 is probably the most used filesystem on linux as of writing. It&#039;s rock stable and has been extended by a lot of extensions since the original ext2. It still retains backward compatibility, being able to mount and fsck ext2 and ext3 with the ext4 driver. However, it doesn&#039;t handle large filesystems very well. If a filesystem is created for &amp;lt;16TiB, it cannot be grown to anything larger than 16TiB. This may have changed lately, though. One other issue is handling errors. If a large filesystem (say 10TiB) is damaged, an fsck may take several hours, leading to long downtime. When I refer to ext4 further in this text, the same applies to ext2 and ext3 unless otherwise specified.&lt;br /&gt;
&lt;br /&gt;
==== XFS ====&lt;br /&gt;
XFS, originally developed by SGI some time in the bronze age, but has been worked on heavily after that. RHEL and Centos version 7 and forward, uses XFS as the default filesystem. It is quick, it scales well, but it lacks at least two things ext4 has. It cannot be shrunk (not that you normally need that, but nice if you have a typo or you need to change things). Also, it doesn&#039;t allow for automatic fsck on bootup. If something is messed up on the filesystem, you&#039;ll have to login as root on the console (not ssh), which might be an issue on some systems. The fsck equivalent, xfs_repair, is a *lot* faster than ext4&#039;s fsck, though.&lt;br /&gt;
&lt;br /&gt;
==== ZFS ====&lt;br /&gt;
ZFS is like a combination of RAID, LVM and a filesystem, supporting full checksumming, auto-healing (given sufficient redundancy), compression, encryption, replication, deduplication (if you&#039;re brave and have a &#039;&#039;ton&#039;&#039; of memory) and a lot more. It&#039;s a separate chapter and needs a lot more talk than paragraph here.&lt;br /&gt;
&lt;br /&gt;
==== btrfs ====&lt;br /&gt;
btrfs, pronounced &amp;quot;butterfs&amp;quot; or &amp;quot;betterfs&amp;quot; or just spelled out, is a filesystem that mimics that of ZFS. It has been around for 10 years or so, but hasn&#039;t yet proven to be really stable. Following the progress of it for those years, I&#039;ve found it to be a nice toy with which to play, but not to be used in production. Again, others may say otherwise, but these are just my words.&lt;br /&gt;
&lt;br /&gt;
== Low level disk handling ==&lt;br /&gt;
&lt;br /&gt;
This section is for low-level handling of disks, regardless of storage system elsewhere. These apply to mdraid, lvmraid and zfs and possibly other solutions, with the exception of individual drives on hwraid (and maybe fakeraid), since there, the drives are hidden from Linux (or whatever OS).&lt;br /&gt;
&lt;br /&gt;
=== S.M.A.R.T. and slow drives ===&lt;br /&gt;
Modern (that is, from about 1990 or later) have S.M.A.R.T. (or just smart, since it&#039;s easier to type) monitoring built in, meaning the disk&#039;s controller is monitoring itself. This is handy and will ideally tell you in advance that a drive is flakey or dying. Modern (2010+) smart monitoring is more or less the same. It can be trusted about 50% of the time. Usually, if smart detects an error, it&#039;s a real error. I don&#039;t think I&#039;ve seen it reporting a false positive, but others may know better. &lt;br /&gt;
&lt;br /&gt;
==== smartmontools ====&lt;br /&gt;
First, install smartmontool and run smartclt -H /dev/yourdisk (/dev/sda or something) to get a health report. Then perhaps run smartctl -a /dev/yourdisk and look for &#039;current pending sectors&#039; This should be zero. Also check the temperature, which normally should be much above 50.&lt;br /&gt;
&lt;br /&gt;
==== single, slow drive ====&lt;br /&gt;
What may happen, is smart not seeing anything and life goes on like before, only slower and less prouductive, without telling anyone. If you stubler over this issue, you&#039;ll probably see it during a large rsync/zfs send/receive or a resync/rebuild/resilver of the raid/zpool. During this, it feels like everything is slow and your RAID has turned into a RAIF (redundant array of inexpensive floppies). To check if you have a single drive messing up it all, check with &#039;&#039;&#039;iostat -x 2&#039;&#039;&#039;, having 2 being the delay between each measurement. Interrupt it with ctrl+x. If there&#039;s a rougue drive there, it should stand out like sdg below&lt;br /&gt;
&lt;br /&gt;
 avg-cpu:  %user   %nice %system %iowait  %steal   %idle&lt;br /&gt;
            0.38    0.00    1.75    0.00    0.00   97.87&lt;br /&gt;
&lt;br /&gt;
 Device            r/s     w/s     rkB/s     wkB/s   rrqm/s   wrqm/s  %rrqm  %wrqm r_await w_await aqu-sz rareq-sz wareq-sz  svctm  %util&lt;br /&gt;
 sda              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdb              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdc              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdd              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sde              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdf              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdg              3.50    0.00   2352.00      0.00     0.00     0.00   0.00   0.00 14306.29    0.00  13.85   672.00     0.00 285.71 100.00&lt;br /&gt;
 sdh              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
&lt;br /&gt;
In ZFS land, you should be able to get similar data with &#039;&#039;&#039;zpool iostat -v &amp;lt;pool&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Now you know the bad drive (sdg), pull it from the raid with &#039;&#039;&#039;mdadm --fail /dev/mdX /dev/sdX&#039;&#039;&#039;. Now test the drive&#039;s performance manually, just simply:&lt;br /&gt;
&lt;br /&gt;
 # hdparm -t /dev/sdg&lt;br /&gt;
 &lt;br /&gt;
 /dev/sdg:&lt;br /&gt;
  Timing buffered disk reads:   2 MB in  5.37 seconds = 381.46 kB/sec&lt;br /&gt;
&lt;br /&gt;
Bingo - nothing you&#039;d want to keep. For a good drive, it should be something like 100-200MB/s&lt;br /&gt;
&lt;br /&gt;
PS: Keep in mind that you have a degraded RAID by now in case you had a spare waiting for things to happen.&lt;br /&gt;
&lt;br /&gt;
Try to replace the cable and/or try the disk on another port/controller. If the result from hdparm persists, it&#039;s probably a bad cable&lt;br /&gt;
&lt;br /&gt;
So, then, just psycially locate the drive, pull it out, take out the discs and magnets and recycle the rest.&lt;br /&gt;
&lt;br /&gt;
=== &amp;quot;Unplug&amp;quot; drive from system ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Find the device unit&#039;s number with something like&lt;br /&gt;
find /sys/bus/scsi/devices/*/block/ -name sdd&lt;br /&gt;
# returning /sys/bus/scsi/devices/3:0:0:0/block/sdd here, &lt;br /&gt;
# meaning 3:0:0:0 is the SCSI device we&#039;re looking for.&lt;br /&gt;
&lt;br /&gt;
# Given this is the correct device, and you want to &#039;unplug&#039; it, do so by&lt;br /&gt;
echo 1 &amp;gt; /sys/bus/scsi/devices/3:0:0:0/delete&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Rescan disk controllers ===&lt;br /&gt;
If a drive is added and for some reason doesn&#039;t get detected, or is removed by the command above, it can be rediscovered with a sysfs command to the scsi host to which it is connected. Since there may be quite a few of these, an easy way is to just scan them all and check the output of &#039;&#039;&#039;dmesg -T&#039;&#039;&#039; after running it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Make a list of controllers and send a rescan message to each of them. It won&#039;t do anything &lt;br /&gt;
# for those where nothing has changed, but it will show new drives where they have been added.&lt;br /&gt;
for host_scan in /sys/class/scsi_host/host*/scan&lt;br /&gt;
do&lt;br /&gt;
  echo &#039;- - -&#039; &amp;gt; $host_scan&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Fail injection with debugfs ===&lt;br /&gt;
[https://lxadm.com/Using_fault_injection https://lxadm.com/Using_fault_injection]&lt;br /&gt;
&lt;br /&gt;
== mdadm stuff ==&lt;br /&gt;
=== Resync ===&lt;br /&gt;
To resync a raid, that is, check, run&lt;br /&gt;
&lt;br /&gt;
 echo check &amp;gt; /sys/block/$dev/md/sync_action&lt;br /&gt;
&lt;br /&gt;
where $dev is something like md0. If you have several raids, something like this should work&lt;br /&gt;
&lt;br /&gt;
 for dev in md{0,1}&lt;br /&gt;
 do&lt;br /&gt;
   echo repair &amp;gt; /sys/block/$dev/md/sync_action&lt;br /&gt;
 done&lt;br /&gt;
&lt;br /&gt;
Also useful in a one-liner like&lt;br /&gt;
&lt;br /&gt;
 for dev in md{0,1} ; do echo repair &amp;gt; /sys/block/$dev/md/sync_action ; done&lt;br /&gt;
&lt;br /&gt;
Different raids on different drives will do this in parallel. If the drives are shared somehow with partitions or similar, the check or repair will wait for the other to finish before going on.&lt;br /&gt;
&lt;br /&gt;
As for repair vs check, [https://raid.wiki.kernel.org/index.php/RAID_Administration this article] describes it well. I stick to using repair unless it&#039;s something rare where I don&#039;t want to touch the data.&lt;br /&gt;
&lt;br /&gt;
=== Spare pools ===&lt;br /&gt;
In the old itmes, mdadm supported only a dedicated spare per md device, so if working with a large set of drives (20? 40?), where you&#039;d want to setup more raid sets to increase redundancy, you&#039;d dedicate a spare to each of the raid sets. This has changed (some time ago?), so in these modern, heathen days, you can change mdadm.conf, usually placed under /etc/mdadm, and add &#039;spare-group=somegroup&#039; where &#039;somegroup&#039; is a string identifying the spare group. After doing this, run &#039;&#039;&#039;update-initramfs -u&#039;&#039;&#039; and reboot and add a spare to one of the raid sets in the spare group, and md will use that or those spares for all the raidsets in that group.&lt;br /&gt;
&lt;br /&gt;
As some pointed out on #linux-raid @ irc.freenode.net, this feature is very badly documented, but as far as I can see, it works well.&lt;br /&gt;
&lt;br /&gt;
==== Example config ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create two raidsets&lt;br /&gt;
&lt;br /&gt;
mdadm --create /dev/md1 --level=6 --raid-devices=6 /dev/vd[efghij]&lt;br /&gt;
mdadm --create /dev/md2 --level=6 --raid-devices=6 /dev/vd[klmnop]&lt;br /&gt;
&lt;br /&gt;
# get their UUID etc&lt;br /&gt;
&lt;br /&gt;
mdadm --detail --scan&lt;br /&gt;
ARRAY /dev/md/1 metadata=1.2 name=raidtest:1 UUID=1a8cbdcb:f4092350:348b6b80:c054d74c&lt;br /&gt;
ARRAY /dev/md/2 metadata=1.2 name=raidtest:2 UUID=894b1b7c:cb7eba70:917d6033:ea5afd2b&lt;br /&gt;
&lt;br /&gt;
# Put those lines into /etc/mdadm/mdadm.conf and and add the spare-group&lt;br /&gt;
&lt;br /&gt;
ARRAY /dev/md/1 metadata=1.2 name=raidtest:1 spare-group=raidtest UUID=1a8cbdcb:f4092350:348b6b80:c054d74c&lt;br /&gt;
ARRAY /dev/md/2 metadata=1.2 name=raidtest:2 spare-group=raidtest UUID=894b1b7c:cb7eba70:917d6033:ea5afd2b&lt;br /&gt;
&lt;br /&gt;
# update the initramfs and reboot&lt;br /&gt;
&lt;br /&gt;
update-initramfs -u&lt;br /&gt;
reboot&lt;br /&gt;
&lt;br /&gt;
# add a spare drive to one of the raids&lt;br /&gt;
&lt;br /&gt;
mdadm --add /dev/md1 /dev/vdq&lt;br /&gt;
&lt;br /&gt;
# fail a drive on the other raid&lt;br /&gt;
&lt;br /&gt;
mdadm --fail /dev/md2 /dev/vdn&lt;br /&gt;
&lt;br /&gt;
# check /proc/mdstat to see md2 rebuilding with the spare from md1&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Recovery ===&lt;br /&gt;
&lt;br /&gt;
The other day, I came across a problem a user had on #linux-raid@irc.freenode.net. He had an old Qnap NAS that had died and tried plugging the drives in to his Linux machine and got various errors. The two-drive RAID-1 did not come up as it should, &#039;&#039;&#039;dmesg&#039;&#039;&#039; was full of errors from one of the drives (both connected on USB) and so forth.&lt;br /&gt;
&lt;br /&gt;
We went on and started by taking down the machine and just connecting one of the drives. I had him check what was assembled with&lt;br /&gt;
&lt;br /&gt;
 cat /proc/mdstat&lt;br /&gt;
&lt;br /&gt;
That returned /proc/md127 assembled, but LVM didn&#039;t find anything. So running a manual scan&lt;br /&gt;
&lt;br /&gt;
 pvscan --cache /dev/md127&lt;br /&gt;
&lt;br /&gt;
This made linux find the PV, VG and a couple of LVs, but probably because the mdraid was degraded, the LVs were deactivated, according to &#039;&#039;&#039;lvscan&#039;&#039;&#039;. Activating the one with a filesystem manually&lt;br /&gt;
&lt;br /&gt;
 lvchange -a y /dev/&amp;lt;vg&amp;gt;/&amp;lt;lv&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Substitute &amp;lt;vg&amp;gt; and &amp;lt;lv&amp;gt; with the names listed by vgs and lvs.&lt;br /&gt;
&lt;br /&gt;
This worked, and the filesystem on /dev/&amp;lt;vg&amp;gt;/&amp;lt;lv&amp;gt; could be mounted correctly.&lt;br /&gt;
&lt;br /&gt;
== Tuning ==&lt;br /&gt;
&lt;br /&gt;
While trying to compare a 12-disk RAID (8TB disks) to a hwraid, mdraid was slower, so we did a few things to speed things up:&lt;br /&gt;
&lt;br /&gt;
While testing with [https://linux.die.net/man/1/fio fio], monitor /sys/block/md0/md/stripe_cache_active, and see if it&#039;s close to /sys/block/md0/md/stripe_cache_size. If it is, double the size of the latter&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
echo 4096 &amp;gt; /sys/block/md0/md/stripe_cache_size&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Continue until stripe_cache_active stabilises, and then you&#039;ve found the limit you&#039;ll need. You may want to double that for good measure. &lt;br /&gt;
&lt;br /&gt;
(to be continued)&lt;br /&gt;
&lt;br /&gt;
== Links ==&lt;br /&gt;
&lt;br /&gt;
Below are a few links with useful info&lt;br /&gt;
&lt;br /&gt;
* [https://raid.wiki.kernel.org/index.php/Irreversible_mdadm_failure_recovery Irreversible mdadm failure recovery]&lt;br /&gt;
&lt;br /&gt;
= ZFS =&lt;br /&gt;
&lt;br /&gt;
ZFS can do a lot of things most filesystems or volume managers can&#039;t. It checksums all data and metadata and so long that the system uses ECC enabled memory (RAM), it will have complete control over the whole data set, and when (not if) an error occurs, it&#039;ll fix the issue without even throwing a warning. To fix the issue, you&#039;ll obviously need sufficient redundancy (mirrors or RAIDzN). &lt;br /&gt;
&lt;br /&gt;
== ZFS send/receive between machines ==&lt;br /&gt;
&lt;br /&gt;
ZFS has a send/receive mechanism that allows for snapshots to be sent over the wire to a receiving end. This can be a full filesystem, or an incremental change since last send/reveive. In a WAN scenario, you&#039;ll probably want to use VPN for this. On a controlled network, sending in cleartext is also possible. You may as well use ssh, but keep in mind that ssh was never designed to be used as a fullblown vpn solution and is just too slow or the task with large amounts of data. You may, though, use mbuffer, if on a loal LAN.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Allow traffic from the sending IP in whatever firewall interface you&#039;re using (if you&#039;re using a firewall at all, that is)&lt;br /&gt;
ufw allow from x.x.x.x&lt;br /&gt;
# &lt;br /&gt;
# Start the receiver first. This listens on port 9090, has a 1GB buffer,&lt;br /&gt;
    and uses 128kb chunks (same as zfs):&lt;br /&gt;
&lt;br /&gt;
mbuffer -s 128k -m 1G -I 9090 | zfs receive data/filesystem&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To be continued one day… See [https://everycity.co.uk/alasdair/2010/07/using-mbuffer-to-speed-up-slow-zfs-send-zfs-receive/ this] for some more. I&#039;ll get back with details on it.&lt;br /&gt;
&lt;br /&gt;
= General Linux system control =&lt;br /&gt;
&lt;br /&gt;
== Add a new CPU (core) ==&lt;br /&gt;
&lt;br /&gt;
If working with virtual machines, adding a new core can be useful if the VM is slow and the load is multithreaded or multiprocess. To do this, add a new CPU in the hypervisor (be it KVM or VMware or Hyper-V or whatever). Some hypervisors, like VMware, will activate it automatically if open-vm-tools is installed. Please note that open-vm-tools is for VMware only. I don&#039;t know of any such thing for KVM or other hypervisors (although I beleive VirtualBox has its own set of tools, but not as a package). If this doesn&#039;t work, run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
echo 1 &amp;gt; /sys/devices/system/cpu/cpuX/online&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where X is the CPU number you want to add. You can &#039;cat /sys/devices/system/cpu/cpuX/online&#039; to check if it&#039;s online.&lt;br /&gt;
&lt;br /&gt;
= Mount partitions on a disk image =&lt;br /&gt;
&lt;br /&gt;
Sometimes you&#039;ll have a disk image, either from recovering a bad drive after hours (or days or weeks) of ddrescue, and sometimes you just have a disk image from a virtual machine where you want to mount the partitions inside the image. There are three main methods of doing this, which are more or less synonmous, but some easier than the other.&lt;br /&gt;
&lt;br /&gt;
== Basics ==&lt;br /&gt;
&lt;br /&gt;
A disk image is usually like a disk, consisting of either a large filesystem, a PV or a partition table with one or partitions onto which resides a filesystem, a pv, swap or something else. If it&#039;s partitioned, and you want your operating system to mount a filesystem or allow it to see whatever LVM stuff lies on it, you need to isolate the partitions. &lt;br /&gt;
&lt;br /&gt;
== Manual mapping ==&lt;br /&gt;
&lt;br /&gt;
In the oldern days, this was done manually, something like this&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
root@mymachine:~# fdisk -l /dev/vda&lt;br /&gt;
Disk /dev/vda: 25 GiB, 26843545600 bytes, 52428800 sectors&lt;br /&gt;
Units: sectors of 1 * 512 = 512 bytes&lt;br /&gt;
Sector size (logical/physical): 512 bytes / 512 bytes&lt;br /&gt;
I/O size (minimum/optimal): 512 bytes / 512 bytes&lt;br /&gt;
Disklabel type: dos&lt;br /&gt;
Disk identifier: 0xc37b7ea5&lt;br /&gt;
&lt;br /&gt;
Device     Boot    Start      End  Sectors  Size Id Type&lt;br /&gt;
/dev/vda1  *        2048 50333311 50331264   24G 83 Linux&lt;br /&gt;
/dev/vda2       50333312 52426369  2093058 1022M  5 Extended&lt;br /&gt;
/dev/vda5       50333314 52426369  2093056 1022M 82 Linux swap / Solaris&lt;br /&gt;
root@mymachine:~#&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To calculate the start and end of each partition, you just take the start sector and multiply it by the sector size (512 bytes here) and you have the offset in bytes. After this, it&#039;s merely an losetup -o &amp;lt;offset&amp;gt; /dev/loopX &amp;lt;nameofimagefile&amp;gt; and you have the partition mapped to your /dev/loopX (having X being something typically 0-255. After this, just mount it or run pvscan/vgscan/lvscan to probe whatever lvm config is there, and you should be able to mount it like any other filesystem.&lt;br /&gt;
&lt;br /&gt;
== kpartx ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;kpartx&#039;&#039;&#039; does the same as above, more or less, just without so much hassle. Most of it should be automatic and easy to deal with, except it may fail to disconnect the loopback devices sometimes, so you may have to &#039;&#039;&#039;losetup -d&#039;&#039;&#039; them manually. See the manual, &#039;&#039;&#039;kpartx (8)&#039;&#039;&#039;. Please note that &#039;&#039;&#039;partx&#039;&#039;&#039; works similarly and I&#039;d guess the authors of the two tools are arguing a lot of which one&#039;s the best.&lt;br /&gt;
&lt;br /&gt;
== guestmount ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;guestmount&#039;&#039;&#039; is something similar again, but also supports file formats like &#039;&#039;&#039;qcow2&#039;&#039;&#039; and possibly other, proprietary filesystems like &#039;&#039;&#039;vmdk&#039;&#039;&#039; and &#039;&#039;&#039;vdi&#039;&#039;&#039;, but don&#039;t take my word for it - I haven&#039;t tested. Again, see the manual or just read up on the description [http://ask.xmodulo.com/mount-qcow2-disk-image-linux.html?fbclid=IwAR3snTeZvGzp9PLdX11EQhCfOpux6I93CiJ3A2pUomkkRLly9Xo4851mkTY here]. It seems rather trivial.&lt;br /&gt;
&lt;br /&gt;
= Linux on laptops =&lt;br /&gt;
&lt;br /&gt;
== Wifi with HP EliteBook 725/745 on Ubuntu ==&lt;br /&gt;
&lt;br /&gt;
The HP EliteBook 725/745 and similar are equipped with a BCM4352 wifi chip. As with a lot of other stuff from Broadcom, this lacks an open hardware description, so thus no open driver exist. The proper fix, is to replace the NIC with something with an open driver, but again, this isn&#039;t always possible, so a binary driver exists. In ubuntu, run, somehow connect the machine to the internet and run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install bcmwl-kernel-source&lt;br /&gt;
sudo modprobe wl&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you can&#039;t connect the machine to the internet, download the needed packages on another machine and put it on some usb storage. These packages should suffice:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# apt-cache depends bcmwl-kernel-source&lt;br /&gt;
bcmwl-kernel-source&lt;br /&gt;
  Depends: dkms&lt;br /&gt;
  Depends: linux-libc-dev&lt;br /&gt;
  Depends: libc6-dev&lt;br /&gt;
  Conflicts: &amp;lt;bcmwl-modaliases&amp;gt;&lt;br /&gt;
  Replaces: &amp;lt;bcmwl-modaliases&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then install manually with &#039;&#039;&#039;dpkg -i file1.deb file2.deb&#039;&#039;&#039; etc&lt;br /&gt;
&lt;br /&gt;
After this, ip/ifconfig/iwconfig shouldd see the new wifi nic, probably &#039;&#039;&#039;wlan0&#039;&#039;&#039;, but due to a [https://bugs.launchpad.net/ubuntu/+source/broadcom-sta/+bug/1343151 old, ignored bug], you won&#039;t find any wifi networks. This is because the driver from Broadcom apparently does not support interrupt remapping, commonly used on x64 machines. To turn this off, change &#039;&#039;&#039;/etc/default/grub&#039;&#039;&#039; and change the line &#039;&#039;&#039;GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;quiet splash&amp;quot;&#039;&#039;&#039;, adding intremap=off to the end before the quote: &#039;&#039;&#039;GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;quiet splash intremap=off&amp;quot;&#039;&#039;&#039;. Save the file and run &#039;&#039;&#039;sudo update-grub&#039;&#039;&#039; and reboot. After this, wifi should work well.&lt;br /&gt;
&lt;br /&gt;
== Wifi with HP Compaq Presario CQ57 on Ubuntu ==&lt;br /&gt;
&lt;br /&gt;
The HP Compaq Presario CQ57 uses the RT5390 wifi chipset. This has been supported for quite some time now, and I was quite surprised to find it not working on a laptop a friend was having. The driver loaded correctly, but Ubuntu insisted of the laptop being in &#039;&#039;&#039;flight mode&#039;&#039;&#039;. Checking &#039;&#039;&#039;rfkill&#039;&#039;&#039;, it showed me two NICs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# rfkill list all&lt;br /&gt;
0: phy0: Wireless LAN&lt;br /&gt;
	Soft blocked: no&lt;br /&gt;
	Hard blocked: yes&lt;br /&gt;
1: hp-wifi: Wireless LAN&lt;br /&gt;
	Soft blocked: yes&lt;br /&gt;
	Hard blocked: no&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Turning rfkill on and off resulted in nothing much, except some error messages in the kernel log (dmesg)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] ACPI Error: Field [B128] at bit offset/length 128/1024 exceeds size of target Buffer (160 bits) (20170831/dsopcode-235)&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]&lt;br /&gt;
                            Initialized Local Variables for Method [HWCD]:&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Local0: 00000000a34b7928 &amp;lt;Obj&amp;gt;           Integer 0000000000000000&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Local1: 00000000b0aa6865 &amp;lt;Obj&amp;gt;           Buffer(8) 46 41 49 4C 04 00 00 00&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Local5: 00000000a9811efd &amp;lt;Obj&amp;gt;           Integer 0000000000000004&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] Initialized Arguments for Method [HWCD]:  (2 arguments defined for method invocation)&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Arg0:   0000000078957d1b &amp;lt;Obj&amp;gt;           Integer 0000000000000001&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Arg1:   00000000725c9c6e &amp;lt;Obj&amp;gt;           Buffer(20) 53 45 43 55 02 00 00 00&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] ACPI Error: Method parse/execution failed \_SB.WMID.HWCD, AE_AML_BUFFER_LIMIT (20170831/psparse-550)&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] ACPI Error: Method parse/execution failed \_SB.WMID.WMAD, AE_AML_BUFFER_LIMIT (20170831/psparse-550)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After upgrading BIOS and testing different kernels, I was asked to try to unload the &#039;&#039;&#039;hp_wmi&#039;&#039;&#039; driver. I did, and things changed a bit, so I tried blacklisting it, creating the file &#039;&#039;&#039;/etc/modprobe.d/blacklist-hp_wmi.conf&#039;&#039;&#039; with the following content&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Blacklist this - it doesn&#039;t work!&lt;br /&gt;
blacklist hp_wmi&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
I gave the machine a reboot and afte that, the &#039;&#039;&#039;hp-wifi&#039;&#039;&#039; entry was gone in the rfkill output, and things works.&lt;br /&gt;
&lt;br /&gt;
= Raspberry pi =&lt;br /&gt;
&lt;br /&gt;
I couldn&#039;t quite decide if the raspberry pi should be a separate section or part of Linux, but hell, it can run more than Linux, although 99,lots% of people just uses Linux on them. This is a small list of things to know about them; things not on the front page of the manual or perhaps hidden even better.&lt;br /&gt;
&lt;br /&gt;
== Which pi? ==&lt;br /&gt;
&lt;br /&gt;
I just setup three raspberry pi machines and although some are quite different, like v1 to vEverythingelse or the Pi zero versions to the normal ones, not all of us remember how to distinguish between them, and sometimes they&#039;re in a nice 3d printed (or otherwise) chassis or otherwise hidden. So, how to check three different ones:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
root@home-assistant:~ $ cat /proc/device-tree/model ; echo&lt;br /&gt;
Raspberry Pi 2 Model B Rev 1.1&lt;br /&gt;
&lt;br /&gt;
root@green-pi:~ $ cat /proc/device-tree/model ; echo&lt;br /&gt;
Raspberry Pi 3 Model B Rev 1.2&lt;br /&gt;
&lt;br /&gt;
roy@yellow-pi:~ $cat /proc/device-tree/model ; echo&lt;br /&gt;
Raspberry Pi 4 Model B Rev 1.1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
While this works well, for the latter, the pi4, it doesn&#039;t tell how much memory I have. It comes in variants of 1, 2 and 4GB, and this is the latter.&lt;br /&gt;
&lt;br /&gt;
== Monitoring ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;vcgencmd&#039;&#039;&#039; from &#039;&#039;&#039;/opt/vc/bin&#039;&#039;&#039;, but symlinked to &#039;&#039;&#039;/usr/bin&#039;&#039;&#039; so it&#039;s available in path, is useful for fetching hardware info about the pi. For example, measuring the temperature&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
root@yellow-pi:~# vcgencmd measure_temp&lt;br /&gt;
temp=63.0&#039;C&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The command is generally badly documented and parts of it seems outdated for newer hardware. Here&#039;s the output from a Raspberry pi 4 with 4GB RAM&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
roy@yellow-pi:~ $ vcgencmd get_mem arm&lt;br /&gt;
arm=948M&lt;br /&gt;
roy@yellow-pi:~ $ vcgencmd get_mem gpu&lt;br /&gt;
gpu=76M&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= BIOS upgrade from Linux =&lt;br /&gt;
&lt;br /&gt;
Generally, BIOS upgrades have been moved to the BIOS itself these days. This saves a lot of work and quite possibly lives after those who earier rammed their heads through walls, now can upgrade directly from the internet instead of using obscure operating systems best avoided. Sometimes, however, one must use these nevertheless. This is a quick run-through on your options.&lt;br /&gt;
&lt;br /&gt;
== DOS ==&lt;br /&gt;
&lt;br /&gt;
Most non-automatic BIOS upgrades are installed from DOS. Doing a BIOS upgrade this way, is generally non-problematic. Just install a USB thingie with [https://www.freedos.org/ FreeDOS], copy your file(s) onto the thing and boot on it. The commandline is the same as old MS/DOS, except a wee bit more userfriendly, but not a lot.&lt;br /&gt;
&lt;br /&gt;
== Windows ==&lt;br /&gt;
&lt;br /&gt;
Some macahines, like laptops from &#039;&#039;&#039;HP&#039;&#039;&#039;, may have BIOS upgrades that are made to be installed from Windows and won&#039;t run in FreeDOS or MS/DOS, instead throwing an error, saying &#039;&#039;&#039;This program cannot be run in DOS mode&#039;&#039;&#039;. This means you&#039;ll have to boot on a Windows rescue disc and do the job from there. Googling this, tells you it&#039;s quite easy, you just choose &#039;make rescue disc&#039; from Windows, and it&#039;s all good, except if you don&#039;t run Windows, that is. To remedy this problem, do as follows:&lt;br /&gt;
&lt;br /&gt;
=== Download Windows ===&lt;br /&gt;
&lt;br /&gt;
Since you don&#039;t run Windows and possibly don&#039;t have a spouse or friend around with such unhealthy habits either, you need to get it. It&#039;s quite easy - just google &#039;download windows&#039; and it&#039;ll send you to [https://www.microsoft.com/en-us/software-download/windows10ISO somewhere like this].&lt;br /&gt;
&lt;br /&gt;
=== Burn it! ===&lt;br /&gt;
&lt;br /&gt;
Now it&#039;s time to burn the installer on a DVD ROM. You&#039;ll need a double-layered one, since the OS is &amp;gt; 4.7GiB, but I&#039;m sure you have a ton of those lying around. Now, just place your optical medium in your optical drive and burn, baby, burn!&lt;br /&gt;
&lt;br /&gt;
=== Or make a USB thing? ===&lt;br /&gt;
&lt;br /&gt;
Not a lot of machines have optical drives these days, so you may want to use an USB pen drive or something instead. This is easy, just make the USB bootable with the Windows application Microsoft has made for this. Unfortunately, this only runs on Windows, and unlike stuff like Debian, where the &#039;&#039;&#039;iso&#039;&#039;&#039; file can be dd&#039;ed directly onto a USB drive to make it bootable, the Windows &#039;&#039;&#039;iso&#039;&#039;&#039;s don&#039;t come with this luxury. There are lots of methods to make bootable USB things from iso files out there, but the only thing most of them have in common, is that they generally don&#039;t work.&lt;br /&gt;
&lt;br /&gt;
==== WoeUSB ====&lt;br /&gt;
&lt;br /&gt;
After hours of swearing, it&#039;s nice to come across software like [https://github.com/slacka/WoeUSB WoeUSB]. It may not be perfect, it relies on a bunch of GUI stuff you&#039;ll never need and so on, but it &#039;&#039;&#039;&#039;&#039;works&#039;&#039;&#039;&#039;&#039;, and that&#039;s the important part! Just clone the repo and RTFM and it&#039;s all nice. It&#039;s slow, but hell, getting a windows machine and/or an optical drive might be slower.&lt;br /&gt;
&lt;br /&gt;
WoeUSB does nothing fancy, but it &#039;&#039;&#039;does&#039;&#039;&#039; work. It will create a filesystem, FAT32 or NTFS (better use NTFS, FAT32 has its limits). It creates normal filesystems and so on. Just make sure to copy in the BIOS update file, usually an exe file, to run when Windows is up and running.&lt;br /&gt;
&lt;br /&gt;
==== Install BIOS ====&lt;br /&gt;
&lt;br /&gt;
Boot on the Windows USB thing and choose &#039;repair computer&#039; and then &#039;command prompt&#039;. Find the install file, and if you&#039;re lucky, you&#039;ll find it needs a 32bit OS, just like I did. Since the 64bit version doesn&#039;t include 32bit compatibility in the installer, revert to downloading the 32bit version of windows and start over. Pray to your favourite god(s) not to get across such machines again - it might help.&lt;br /&gt;
&lt;br /&gt;
= 3D printer stuff =&lt;br /&gt;
&lt;br /&gt;
Below are a number of not very ordered paragraphs about 3D printer related stuff, mostly based on my experience. Their content may be interesting or perhaps practical knowledge, but then, that depends on the reader.&lt;br /&gt;
&lt;br /&gt;
== 3D printer related introductions on youtube or elsewhere ==&lt;br /&gt;
&lt;br /&gt;
First off, I&#039;d like to mention some youtube videos that are all (or mostly) a nice start if you&#039;re new to 3D printers.&lt;br /&gt;
&lt;br /&gt;
=== [https://www.youtube.com/watch?v=nb-Bzf4nQdE&amp;amp;list=PLDJMid0lOOYnkcFhz6rfQ6Uj8x7meNJJx Thomas Salanderer&#039;s 10-video series on 3D printing basics] ===&lt;br /&gt;
&lt;br /&gt;
Thomas Salanderer is a an experienced 3D printer user/admin/fixer/etc and he has a lot of interesting videos. Some accuse him for being a [Prusa https://www.prusa3d.com/] fanboy, which he quite obviously is, but that doesn&#039;t stop him from making interesting and somewhat neutral videos. The series walks you thought the first steps of how things work and so on and hopefully opens more doors than anything else I&#039;ve seen.&lt;br /&gt;
&lt;br /&gt;
=== [https://www.youtube.com/watch?v=rp3r921DBGI Teaching Tech&#039;s &amp;quot;3D printer tuning reborn&amp;quot;] ===&lt;br /&gt;
&lt;br /&gt;
Teaching Tech is, like Salanderer or even more, good pedagogically and explains a lot. They (or he) do a bunch of testing and describing pros and cons with different things, just like other youtubers in the sme business. The mentioned video shows how to tune a 3D printer after you have first learned the basics, and leans on a webpage made to help you out without too much manual work.&lt;br /&gt;
&lt;br /&gt;
This was a short list, but I guess it&#039;ll grow over time.&lt;br /&gt;
&lt;br /&gt;
== Hydrophilic filament ==&lt;br /&gt;
&lt;br /&gt;
Most popular filament types, including PLA, PETG, PP or PA (Polyamide, normally known as Nylon) and virtualy any filament type named [https://www.matterhackers.com/news/filament-and-water poly-something] (and thus with an acronym of P-something) are hydrophilic (also (somewhat incorrectly) called hydroscopic), meaning so long they&#039;re dryer than the atmosphere around them, they&#039;ll do their best to suck out the atmosphere&#039;s humidity. This is why most filament are shrink-wrapped with a small bag of silica gel in it. If such filament is exposed for normal humid air for some time, it&#039;ll become very hard to use. Most of my experience is with PLA, which can handle a bit (depending on make), but still not a lot. With PLA, if you end up with prints where the filament seems not to stick, it may help with a higher temperature. Otherwise, the filament must be [https://all3dp.com/2/how-to-dry-filament-pla-abs-and-nylon/ baked]. If you don&#039;t want to use your oven, try something like a [https://www.jula.no/catalog/hjem-og-husholdning/kjokkenmaskiner/mattilberedningsapparater/frukt-sopptorker/frukt-sopptorker-001641/#tab02 fruit and mushroom dryer]. Then get a good, sealble plastic box and add something like half a kilogram of [https://www.ebay.com/sch/sis.html?_nkw=1KG+Orange+Replacement+Desiccant+Indicating+Silica+Gel+Beads+for+Drawers%2C+Camera&amp;amp;_id=131938742628&amp;amp;&amp;amp;_trksid=p2057872.m2749.l2658 silica gel] to an old sock, tie it and put it in the your new dry box.&lt;br /&gt;
&lt;br /&gt;
Please note that ABS is hydrophobic, so you won&#039;t have to worry too much there. Also, remember that PA/Nylon is extremely hydrophilic. Even a couple of days in normal air humidity can ruin it completely and will require baking.&lt;br /&gt;
&lt;br /&gt;
== Upgrading the firmware on an Ender 3 ==&lt;br /&gt;
&lt;br /&gt;
This is about upgrading the firmware, and thus also flashing a bootloader to the Creality Ender 3 3D printer. Most of this is well documented on several place, like o [https://www.youtube.com/watch?v=fIl5X2ffdyo the video from Teaching tech] and elsewhere, but I&#039;ll just summarise some issues I had.&lt;br /&gt;
&lt;br /&gt;
=== Using an arduino Nano as a programmer ===&lt;br /&gt;
&lt;br /&gt;
Quick note before you read on. If you have an Ender 3 controller version 1.1.5 or newer (or perhaps even a bit older), a CR-10S or some other more or less modern printers or controllers, they come with a bootloader installed already, so don&#039;t bother flashing one. The one that&#039;s in there already, should work well. So if you have one of these, just skip this and jump to the [[Roy&#039;s_notes#Flashing_the_printer|next section]].&lt;br /&gt;
&lt;br /&gt;
However, the normal CR-10 (without the S), Ender 3 and a few other printers from Creality come without a bootloader, so you&#039;ll need to flash one before upgrading the firmware. Well, strictly speakning, you don&#039;t need one, you can save those 8kB or so for other stuff and use a programmer to write the whole firmware, but then you&#039;ll need to wire up everything every time you want a new firmware, so in my world, you &#039;&#039;&#039;do&#039;&#039;&#039; need the bootloader, since it&#039;s easier.&lt;br /&gt;
&lt;br /&gt;
To install a bootloader, you&#039;ll need a programmer, and I didn&#039;t have one available. Having some el-cheapo china-copies of Arduinos around, I read I could use one and tried so. Although the docs mostly mention the Uno etc, it&#039;s just as simple with the Nano copy.&lt;br /&gt;
&lt;br /&gt;
So, grab an arduino, plug it to your machine with a USB cable, and, using the Arduino IDE, use the ArduinoISP sketch there (found under Examples) to burn the software needed for the arduino to work as a programmer. When this is done, connect a 10µF capacitor between RST and GND to stop it from resetting when used as a programmer. Connect the MOSI, MISO and SCK pins from the ICSP block (that little isolated 6-pin block on top of the ardu). See [https://www.arduino.cc/en/Tutorial/ArduinoISP here] for a pinout. Then find Vcc and GND either on the ICSP block or elsewhere. Some sites say that on some boards you shouldn&#039;t use the pins on the ICSP block for this. I doubt it matters, though. Then connect another jumper wire from pin 10 on the ardu to work as the reset pin outwards to the chip being programmed (that is, on the printer). The ICSP jumper block pin layout is the same on the printer and on the ardu, and probably elsewhere. Sometimes [https://xkcd.com/927/ standardisation] actually works…&lt;br /&gt;
&lt;br /&gt;
See https://cloud.karlsbakk.net/index.php/s/zw48YJjzaf8Rc2F for a pic with the ardu (this wiki is broken atm, will fix it later)&lt;br /&gt;
&lt;br /&gt;
== Flashing the printer ==&lt;br /&gt;
&lt;br /&gt;
When the boot loader is in place, possibly after some wierd errors from during the process, the screen on the 3d printer will go blank and it&#039;ll behave like being bricked. This is ok. Now disconnect the wires and connect the USB cable between computer and printer. If you haven&#039;t installed support for the Sanguino board, that is, the variant of the 1284-chip and surrounding electronics that is the core of the, you need to install it first. In the Arduino IDE, choose the Tools / Boards / Boards manager boot option and search for Sanguino. After this, you should find the Sanguino or Sanguino 1284p in the boards menu. After this, you should be able to communicate with the printer&#039;s controller. Download the [https://www.th3dstudio.com/knowledgebase/th3d-unified-firmware-package/ TH3D unified firmware], making sure it&#039;s the last version. Uncompress the zip and with Finder/Explorer/whateversomething&#039;scalledonlinux, browse to &#039;&#039;&#039;TH3DUF_R2/Firmware/TH3DUF_R2.ino&#039;&#039;&#039; and open it. It should open directly in the Android IDE. Keep in mind that the names TH3DUF_R2 and TH3DUF_R2.ino will vary between versions, but you get the point. Now configure it for your particular needs. You&#039;ll find most of this in the Configuration.h tab (that&#039;s really a file). Most of the other files won&#039;t be necessary unless you&#039;re doing some more advanced stuff, like replacing th controller with something non-standard or similar, but then again, that&#039;s another chapter (or book, even). The video mentioned above describes this well. After flashing the new firmware, you&#039;ll probably get some timeouts and errors, since apparently it resets the printer after giving it the new firmware, but without notifying the flashing software of it doing so. If this happens, calm down and reboot the printer and check its tiny monitor - it should work. If it doesn&#039;t work, and if you flashed the bootload yourself, try to flash it again, and if that doesn&#039;t work, try flashing the programmer again yet another time, just for kicks. Again, if you have a newer controller like the v1.1.5, don&#039;t touch the bootloader, as the one already installed, should work well as it is.&lt;br /&gt;
&lt;br /&gt;
PS: I tried enabling &#039;&#039;&#039;MANUAL_MESH_LEVELING&#039;&#039;&#039;, which in the code says that &#039;&#039;If used with a 1284P board the bootscreen will be disabled to save space&#039;&#039;. This effectively disabled the whole printer, and apparently may be making the firmware image a wee bit too large for it to fit the 1284P on the ender. It works well without it, though, and it may be fixed by now, since I tested this back in early 2019.&lt;br /&gt;
&lt;br /&gt;
== And then… ==&lt;br /&gt;
&lt;br /&gt;
With the new firmware in place, the printer should work as before, although with thermal runaway protection to better avoid fires in case the shit hits the fan, and to allow for things like autolevelling. With any luck, [https://www.precisionpiezo.co.uk/ this thing] may be ready for use by the time you read this - it surely looks nice!&lt;br /&gt;
&lt;br /&gt;
= Octoprint/Octopi =&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;This could have been under some other section, but again, I just branch out even though most of it is about sections mentioned elsewhere.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
When setting up a 3d printer for the first time, you usually get an SD card for storage and transfer data to the printer using [https://en.wikipedia.org/wiki/Sneakernet Sneakernet]. Some printers use micro SD cards, while other fullsize SD cards, which imho is better, since they don&#039;t get lost that easily, but otherwise do the same thing. This works, but is somewhat tedious. If you want to control the printer from a PC or phone, there&#039;s a simple trick for that as well - octoprint.&lt;br /&gt;
&lt;br /&gt;
[https://octoprint.org/ Octoprint], written by Gina Häußge, runs on most platforms including linux, windows, BSD*, macos etc. It supports controlling a camera to some extent out of the box and there&#039;s a large number of plugins availablee to do a lot of things you possibly haven&#039;t thought of (and quite often, you&#039;d ever need). The easiest way to install it, is to just grab a Raspberry pi - preferably some of the newer models (will get to that later) and download [https://octoprint.org/download/ octopi] and follow the instructions on that page.&lt;br /&gt;
&lt;br /&gt;
== Performance issues ==&lt;br /&gt;
&lt;br /&gt;
Some report (and I have seen it myself) issues with the pi&#039;s performance with regards to both handling the octoprint processes (which should be as close to realtime as possible) and handling other stuff like I/O, networking etc. The point is that at pi3 or older, has all peripherals connected to an internal USB hub. This might be practical, but performance-wise it&#039;s &#039;&#039;&#039;&#039;&#039;not&#039;&#039;&#039;&#039;&#039;. If you in addition connect a webcam to USB, you&#039;re asking for trouble, since USB will be your bottleneck. With a raspberry pi camera, the ones connected to the pi directly with a ribbon cable, this should not use USB, so it&#039;s better. Still, again, for older pi&#039;s, there might be some shortage in therms of cpu or i/o. The octopi runs something like raspbian which is a fork of debian which is a linux distro, so it all boils down to knowing linux.&lt;br /&gt;
&lt;br /&gt;
Your typical octopi will run octoprint, a streamer, usually &#039;&#039;&#039;mjpg-streamer&#039;&#039;&#039;, a simple, lightweight videostreamer that outputs a stream of jpeg-images (about the same format as cinemas use - that is - not MPEG). This may be a bit tough on the cpu and potentially i/o. Add inn a dash of USB overload and you&#039;re may see trouble.&lt;br /&gt;
&lt;br /&gt;
Still - a pi3 should be able to handle the load, but it might help to prioritise corretly. The octoprint process is the important part here, so we could give that full priority both in CPU and I/O and. Unfortunately, it doesn&#039;t seem like the current octopi has been migrated to using systemd for the startup. We&#039;ll deal with this later. To fix this in the old SysV init style file present there, the following patch should work against the file /etc/init.d/octoprint&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;diff&amp;quot;&amp;gt;&lt;br /&gt;
--- octoprint.old	2020-07-20 18:46:10.166651965 +0200&lt;br /&gt;
+++ octoprint	2020-07-20 18:53:21.724803211 +0200&lt;br /&gt;
@@ -22,6 +22,9 @@&lt;br /&gt;
 PIDFILE=/var/run/$NAME.pid&lt;br /&gt;
 PKGNAME=octoprint&lt;br /&gt;
 SCRIPTNAME=/etc/init.d/$PKGNAME&lt;br /&gt;
+NICELEVEL=-19                        # Top CPU priority&lt;br /&gt;
+IONICE_CLASS=1                       # Realtime I/O class&lt;br /&gt;
+IONICE_PRIORITY=0                    # Realtime I/O priority (probably not needed with class=realtime)&lt;br /&gt;
&lt;br /&gt;
 # Read configuration variable file if it is present&lt;br /&gt;
 [ -r /etc/default/$PKGNAME ] &amp;amp;&amp;amp; . /etc/default/$PKGNAME&lt;br /&gt;
@@ -70,10 +73,11 @@&lt;br /&gt;
&lt;br /&gt;
    is_alive $PIDFILE&lt;br /&gt;
    RETVAL=&amp;quot;$?&amp;quot;&lt;br /&gt;
-&lt;br /&gt;
    if [ $RETVAL != 0 ]; then&lt;br /&gt;
        start-stop-daemon --start --background --quiet --pidfile $PIDFILE --make-pidfile \&lt;br /&gt;
-       --exec $DAEMON --chuid $OCTOPRINT_USER --user $OCTOPRINT_USER --umask $UMASK -- serve $DAEMON_ARGS&lt;br /&gt;
+       --exec $DAEMON --chuid $OCTOPRINT_USER --user $OCTOPRINT_USER --umask $UMASK \&lt;br /&gt;
+       --nicelevel $NICELEVEL --ioched $IONICE_CLASS:$IONICE_PRIORITY \&lt;br /&gt;
+       --serve $DAEMON_ARGS&lt;br /&gt;
        RETVAL=&amp;quot;$?&amp;quot;&lt;br /&gt;
    fi&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This ismply upgrades the process to be allowed to use most of the resources on the pi, regardless of what other processes are whining about.&lt;br /&gt;
&lt;br /&gt;
PS: Code not tested - I don&#039;t have a pi right here. Will test later, but I&#039;m pretty sure it&#039;ll work. After all, it&#039;s just a few new arguments to start-stop-daemon&lt;br /&gt;
&lt;br /&gt;
roy&lt;/div&gt;</summary>
		<author><name>Roy</name></author>
	</entry>
	<entry>
		<id>https://wiki.malinux.no/index.php?title=Roy%27s_notes&amp;diff=171</id>
		<title>Roy&#039;s notes</title>
		<link rel="alternate" type="text/html" href="https://wiki.malinux.no/index.php?title=Roy%27s_notes&amp;diff=171"/>
		<updated>2020-08-25T10:11:06Z</updated>

		<summary type="html">&lt;p&gt;Roy: /* Create LVM cache */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= LVM, md and friends =&lt;br /&gt;
&lt;br /&gt;
== Linux&#039; Logical Volume Manager (LVM) ==&lt;br /&gt;
&lt;br /&gt;
=== LVM in general ===&lt;br /&gt;
&lt;br /&gt;
LVM is designed to be an abstraction layer on top of physical drives or RAID, typically [https://raid.wiki.kernel.org/index.php/RAID_setup mdraid] or [https://help.ubuntu.com/community/FakeRaidHowto fakeraid]. Keep in mind that fakeraid should be avoided unless you really need it, like in conjunction with dual-booting linux and windows on fakeraid. LVM broadly consists of three elements, the &amp;quot;physical&amp;quot; devices (PV), the volume group (VG) and the logical volume (LV). There can be multiple PVs, VGs and LVs, depending on requirement. More about this below. All commands are given as examples, and all of them can be fine-tuned using extra flags in need of so. In my experience, the defaults work well for most usecases.&lt;br /&gt;
&lt;br /&gt;
I&#039;m mentioning filesystem below too. Where I write ext4, the samme applies to ext2 and ext3.&lt;br /&gt;
&lt;br /&gt;
==== Create a PV ====&lt;br /&gt;
&lt;br /&gt;
A PV is the &amp;quot;physical&amp;quot; parts. This does not need to be a physical disk, but can also be another RAID, be it an mdraid, fakeraid, hardware raid, a virtual disk on a SAN or otherwisee or a partition on one of those. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#  These add three PVs, one on a drive (or hardware raid) and another two on mdraids.&lt;br /&gt;
pvcreate /dev/sdb&lt;br /&gt;
pvcreate /dev/md1 /dev/md2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For more information about pvcreate, see [https://linux.die.net/man/8/pvcreate the manual].&lt;br /&gt;
&lt;br /&gt;
==== Create a VG ====&lt;br /&gt;
&lt;br /&gt;
The volume group consists of one or more PVs grouped together on which LVs can be placed. If several PVs are grouped in a VG, it&#039;s generally a good idea to make sure these PVs have some sort of redundancy, as in mdraid/fakeraid or hwraid. Otherwise it will be like using a [https://en.wikipedia.org/wiki/RAID RAID-0] with a single point of failure on each of the independant drives. LVM has [https://unix.stackexchange.com/questions/150644/raiding-with-lvm-vs-mdraid-pros-and-cons  RAID code in it] as well, so you can use that. I haven&#039;t done so myself, as I generally stick to mraid. The reason is mdraid is, in my opinion older and more stable and has more users (meaning bugs are reported and fixed faster whenever they are found). That said, I beleive the actual RAID code used in LVM RAID are the same function calls as for mdraid, so it may not be much of a difference. I still stick with mdraid. To create a VG, run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create volume group my_vg&lt;br /&gt;
vgcreate my_vg /dev/md1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that if vgcreate is run with a PV (as /dev/md1 above) that is not defined as a PV (like above), this is done implicitly, so if you don&#039;t need any special flags to pvcreate, you can simply skip it and let vgcreate do that for you.&lt;br /&gt;
&lt;br /&gt;
==== Create an LV ====&lt;br /&gt;
&lt;br /&gt;
LVs can be compared to partitions, somehow, since they are bounderies of a fraction or all of that of a VG. The difference between them and a partition, however, is that they can be grown or shrunk easily and also moved around between PVs without downtime. This flexibility makes them superiour to partitions as your system can be changed without users noticing it. By default, an LV is alloated &amp;quot;thickly&amp;quot;, meaning all the data given to it, is allocated from the VG and thus the PV. The following makes a 100GB LV named &amp;quot;thicklv&amp;quot;. When making an LV, I usually allocate what&#039;s needed plus some more, but not everything, just to make sure it&#039;s space available for growth on any of the LVs on the VG, or new LVs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a thick provisioned LV named thicklv on the VG my_vg&lt;br /&gt;
lvcreate -n thicklv -L 100G my_vg&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After the LV is created, a filesystem can be placed on it unless it is meant to be used directly. The application for direct use include swap space, VM storage and certain database systems. Most of these will, however, work on filesystems too, although my testing has shown that on swap space, there is a significant performance gain for using dedicated storage without a filesystem. As for filesystems, most Linux users use either ext4 or xfs. Personally, I generally use XFS these days. See my notes below on filesystem choice.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a filesystem on the LV - this could have been mkfs -t ext4 or whatever filesystem you choose&lt;br /&gt;
mkfs -t xfs /dev/my_vg/thicklv&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then just edit /etc/fstab with correct data and run mount -a, and you should be all set.&lt;br /&gt;
&lt;br /&gt;
==== Create LVM cache ====&lt;br /&gt;
LVMcache is LVM&#039;s solution to caching a slowish filesystem on spinning rust with the help of much faster SSDs. For this to work, use a separate SSD or a mirror or two (just in case) an add the new disk/md dev to the same VG. In this case, we use a small mirror, md1. LVM is not able to cache to a disk or partition outside the volume group.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
vgextend data /dev/md1&lt;br /&gt;
  Physical volume &amp;quot;/dev/md1&amp;quot; successfully created.&lt;br /&gt;
  Volume group &amp;quot;data&amp;quot; successfully extended&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Thn create two LVs, one for the data (contents of files) and one for the metadata (filenames, directories, attributes etc). Typically, the metadata part won&#039;t need to be very large. 100M should usually do unless you have ekstremely many small files. I guess there are ways to calculate it, but again, 1GB should do for everyone (or was that 640k?). As for the data cache, I chose to use 40G here for a 15TB RAID. It will only cache what actively use anyway, so no need for overkill.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
lvcreate -L 1G -n _cache_meta data /dev/md1&lt;br /&gt;
lvcreate -L 100G -n _cache data /dev/md1&lt;br /&gt;
&lt;br /&gt;
# Some would want --cachemode writeback, but seriously, I wouldn&#039;t recommend it. Metadata or data can be easily corrupted in case of failure.&lt;br /&gt;
lvconvert --type cache-pool --cachemode writethrough --poolmetadata data/_cache_meta data/_cache&lt;br /&gt;
lvconvert --type cache --cachepool data/_cache data/data&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
That should be it. If you benchmarked the disk before this, you should try again and you&#039;ll probably get a nice surprise. If not, well, see below how to turn this off again :)&lt;br /&gt;
&lt;br /&gt;
==== Disabling LVM cache ====&lt;br /&gt;
&lt;br /&gt;
If you for some reason want to disable caching, this will do it cleanly and remove the LVs earlier created for caching the main device.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
lvconvert --uncache data/data&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Growing devices ====&lt;br /&gt;
&lt;br /&gt;
LVM objects can be grown and shrunk. If a PV resides on a RAID where a new drive has been added or otherwise grown, or on a partition or virtual disk that has been extended, the PV must be updated to reflect these changes. The following command will grow the PV to the maximum available on the underlying storage. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Resize the PV /dev/md (not the RAID, only the PV on the RAID) to its full size&lt;br /&gt;
pvresize /dev/md1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If a new PV is added, the VG can be grown to add the space on that in addition to what&#039;s there already. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Extend my_vg to include md2 and its space&lt;br /&gt;
vgextend my_vg /dev/md2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
With more space available in the VG, the LV can now be extended. Let&#039;s add another 50GB to it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Extend thicklv - add 50GB. If you know you won&#039;t need the space anywhere else, you may want to&lt;br /&gt;
# lvresize -l+100%FREE instead. Keep in mind the difference between -l (extents) and -L (bytes)&lt;br /&gt;
lvresize -L +50G my_vg/thicklv&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Growing filesystems ====&lt;br /&gt;
After the LV has grown, run &#039;&#039;xfs_growfs&#039;&#039; (xfs) or &#039;&#039;resize2fs&#039;&#039; (ext4) to make use of the new data. To grow the filesystem to all available space on ext4, run the below command.  To partly grow the filesystem or to shrink it or otherwise, please see the manuals.&lt;br /&gt;
&lt;br /&gt;
The filesystem can be mounted when this is run. If you for some reason get an &#039;&#039;&#039;access denied&#039;&#039;&#039; error when running this as root or with sudo, it&#039;s likely caused by a filesystem error. To fix this, unmount the filesystem first and run &#039;&#039;&#039;fsck -f /dev/my_vg/thicklv&#039;&#039;&#039; and remount it before retrying to extend it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
resize2fs /dev/my_vg/thicklv&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Similarly, with XFS, but note that xfs_growfs doesn&#039;t take the device name, but the filesystem&#039;s mount point. In the case of XFS, also note that the filesystem &#039;&#039;&#039;&#039;&#039;must&#039;&#039;&#039;&#039;&#039; be mounted to be grown. This, in contrast to how it was in the old days when filesystems had to be unmounted to be grown.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
xfs_growfs /my_mountpoint&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Rename system VG ====&lt;br /&gt;
&lt;br /&gt;
Some distros create VG names like those-from-a-sysadmin-with-a-well-developed-paranoia-not-to-hit-a-duplicate. Debian, for instance, uses names like &amp;quot;my-full-hostname-vg&amp;quot;. Personally, I don&#039;t like these, since if I were to move a disk or vdisk around to somewhere else, I&#039;d make sure not to add a disk named &#039;sys&#039; to an existing system. If you do, most distros will refuse to use the VGs with duplicate names, resulting in the OS not booting until either one is specified by its UUID or just one removed. As I&#039;m aware of this, I stick to the super-risky thing of all system VGs named &#039;sys&#039; and so on.&lt;br /&gt;
&lt;br /&gt;
If you do this, keep in mind that it may blow up your computer and take your girl- or boyfriend with it or even make either of them pregnant, allowing Trump to rule your life and generally make things suck. You&#039;re on your own!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Rename the VG&lt;br /&gt;
vgrename my-full-hostname-vg sys&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, in /boot/grub/grub.cfg, change the old lv path from something like &#039;/dev/mapper/debian--stretch--machine--vg-root&#039; to your new and fancy &#039;/dev/sys/root. Likewise, in /etc/fstab, change occurences of &#039;/dev/mapper/debian--stretch--machine--vg-&#039; (or similar) with &#039;/dev/sys/&#039;. Here, this was like this - the old ones commented out.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;fstab&amp;quot;&amp;gt;&lt;br /&gt;
#/dev/mapper/debian--stretch--box--vg-root      /               ext4            errors=remount-ro,discard       0       1&lt;br /&gt;
/dev/sys/root                                   /               ext4            errors=remount-ro,discard       0       1&lt;br /&gt;
# /boot was on /dev/vda1 during installation&lt;br /&gt;
UUID=myverylonguuidwithatonofgoodinfoinit       /boot           ext2            defaults                        0       2&lt;br /&gt;
#/dev/mapper/debian--stretch--box--vg-swap_1    none            swap            sw                              0       0&lt;br /&gt;
/dev/sys/swap_1                                 none            swap            sw                              0       0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Update /etc/initramfs-tools/conf.d/resume with similar data for swap.&lt;br /&gt;
&lt;br /&gt;
You might want to run &#039;update-initramfs -u -k all&#039; after this, but I&#039;m not sure if it&#039;s needed.&lt;br /&gt;
&lt;br /&gt;
Now, pray to the nearest god(s) and give it a reboot and it should (probably) work.&lt;br /&gt;
&lt;br /&gt;
After reboot, run &#039;&#039;&#039;swapoff -a&#039;&#039;&#039;, then &#039;&#039;&#039;mkswap /dev/sys/swap_1&#039;&#039;&#039; (or whatever it&#039;s called on your system) and &#039;&#039;&#039;swapon -a&#039;&#039;&#039; again. You may want to give it another reboot or two for kicks, but it should work well even without that.&lt;br /&gt;
&lt;br /&gt;
=== Migration tools ===&lt;br /&gt;
&lt;br /&gt;
At times, storage regimes change, new storage is added and sometimes it&#039;s not easy to migrate with the current hardware or its support systems. Once I had to migrate a 45TiB fileserver from one storage system to another, preferably without downtime. The server originally had three 15TiB PVs of which two were full and the third half full. I resorted to using [https://linux.die.net/man/8/pvmove pvmove] to just move the data on the PVs in use to a new PV. We started out with creating a new 50TiB PV, sde, and then to pvmove.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Attach /dev/sde to the VG my_vg&lt;br /&gt;
vgextend my_vg /dev/sde&lt;br /&gt;
&lt;br /&gt;
# Move the contents from /dev/sdb over to /dev/sde block by block. If a target is not given in pvmove,&lt;br /&gt;
# the contents of the source (sdb here) will be put somewhere else in the pool.&lt;br /&gt;
pvmove /dev/sdb /dev/sde&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This took a while (as in a week or so) - the pvmove command uses old code and logic (or at least did that when I migrated this in November 2016), but it affected performance on the server very little, so users didn&#039;t notice. After the first PV was migrated, I continued with the other two, one after the other, and after a month or so, it was migrated. We used this on a number of large fileservers, and it worked flawlessly. Before doing the production servers I also tried interrupting pvmove in various ways, including hard resets, and it just kept on after the reboot.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;NOTE:&#039;&#039;&#039;&#039;&#039; &#039;&#039;Even though it worked well for us, &#039;&#039;&#039;always&#039;&#039;&#039; keep a good backup before doing this. Things may go wrong, and without a good backup, you may be looking for a hard-to-find new job the next morning&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
==== mdadm workarounds ====&lt;br /&gt;
&lt;br /&gt;
===== Migrate from a mirror (raid-1) to raid-10 =====&lt;br /&gt;
&lt;br /&gt;
Create a mirror&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sdb /dev/sdc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
LVM (pv/vg/lv) on md0 (see above), put a filesystem on the lv and fill it with some data.&lt;br /&gt;
&lt;br /&gt;
Now, some months later, you want to change this to raid-10 to allow for the same amount of redundancy, but to allow more disks into the system.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mdadm --grow /dev/md0 --level=10&lt;br /&gt;
mdadm: Impossibly level change request for RAID1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So - no - doesn&#039;t work. But - we&#039;re on &lt;br /&gt;
&lt;br /&gt;
Since we&#039;re on lvm already, this&#039;ll be easy. If you&#039;re using filesystems directly on partitions, you can do this the same way, but without the pvmove part, using rsync or whateever you like instead. I&#039;d recommend using lvm for for the new raid, which should be rather obvious from this article. Now plug in a new drive and create a new raid10 on that one. If you two new drives, install both. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# change &amp;quot;missing&amp;quot; to the other device name if you installed two new drives&lt;br /&gt;
mdadm --create /dev/md1 --level=10 --raid-devices=2 /dev/vdd missing&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, as described above, just vgextend the vg, adding the new raid and run pvmove to move the data from the old pv (residing on the old raid1) to the new pv (on raid10). Afte rpvmove is finished (which may take awile, see above), just&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
vgreduce raidtest /dev/md0&lt;br /&gt;
pvremove /dev/md0&lt;br /&gt;
mdadm --stop /dev/md0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
…and your disk is free to be added to the new array. If the new raid is running in degraded mode (if you created it with just one drive), better don&#039;t wait too long, since you don&#039;t have redundancy. Just mdadm --add the devs.&lt;br /&gt;
&lt;br /&gt;
If you now have /dev/mdstat telling you your raid10 is active and have three drives, of which one is a spare, it should look something like this&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5] [raid4] [raid10]&lt;br /&gt;
md1 : active raid10 vdc[3](S) vdb[2] vdd[0]&lt;br /&gt;
      8380416 blocks super 1.2 2 near-copies [2/2] [UU]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Just mdadm --grow --raid-devices=3 /dev/md1&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;RAID section is not complete. I&#039;ll write more on migraing from raid10 to raid6 later. It&#039;s not straight forward, but easier than this one :)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== Thin provisioned LVs ===&lt;br /&gt;
&lt;br /&gt;
Thin provisioning on LVM is a method used for not allocating all the space given to an LV. For instance, if you have a 1TB VG and want to give an LV 500GB, although it currently only uses a fraction of that, a thin lv can be a good alternative. This will allow for adding a limit to how much it can use, but also to let it grow dynamically without manual work by the sysadmin. Thin provisioning adds another layer of abstaction by creating a special LV as a &#039;&#039;thin pool&#039;&#039; from which data is allocated to the &#039;&#039;thin volume(s)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== Create a thin pool ====&lt;br /&gt;
&lt;br /&gt;
Allocate 1TB to the thin pool to be used for thinly provisioned LVs. Keep in mind that the space allocated to the thin pool is in fact thick provisioned. Only the volumes put on &#039;&#039;thinpool&#039;&#039; are thin provisioned. This will create two hidden LVs, one for data and one for metadata. Normally the defaults will do, but check the manual if the data doesn&#039;t match the usual patterns (such as billions of files, resulting in huge amounts of metadata). I &#039;&#039;beleive&#039;&#039; the metadata part should be resizable at a later time if needed, but I have not tested it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a pool for thin LVs. Keep in mind that the pool itself is not thin provisioned, only the volumes residing on it&lt;br /&gt;
lvcreate --size 1T --type thin-pool --thinpool thinpool my_vg&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Create a thin volume ====&lt;br /&gt;
&lt;br /&gt;
You have the thinpool, now put a thin volume on it. It will allocate some space for metadata, but probably not much (a few megs, perhaps).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Now, create a volume with a virtual (-V) size of half a terabyte named thin_pool, but using the thinpool (-T) named thin_pool for storage&lt;br /&gt;
lvcreate -V 500G -T my_vg/thin_pool --name thinvol&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The new volume&#039;s device name will be /dev/thinvol. Now, create a filesystem on it, add to fstab and mount it. The &#039;&#039;&#039;df&#039;&#039;&#039; command will return available space according to the virtual size (-V), while lvs will show how much data is actually used on each of the thinly provisioned volumes.&lt;br /&gt;
&lt;br /&gt;
== Filesystem dilemmas ==&lt;br /&gt;
&lt;br /&gt;
=== XFS or ext4 or something else ===&lt;br /&gt;
The choice of filesystem varies for your use. Distros such as RHEL/CentOS has moved to XFS by default from v7. Debian/Ubuntu still sticks to ext4, like most other. I&#039;ll discuss my thoughts below on ext4 vs XFS and leave the other filesystems for later.&lt;br /&gt;
&lt;br /&gt;
==== ext4 ====&lt;br /&gt;
ext4 is probably the most used filesystem on linux as of writing. It&#039;s rock stable and has been extended by a lot of extensions since the original ext2. It still retains backward compatibility, being able to mount and fsck ext2 and ext3 with the ext4 driver. However, it doesn&#039;t handle large filesystems very well. If a filesystem is created for &amp;lt;16TiB, it cannot be grown to anything larger than 16TiB. This may have changed lately, though. One other issue is handling errors. If a large filesystem (say 10TiB) is damaged, an fsck may take several hours, leading to long downtime. When I refer to ext4 further in this text, the same applies to ext2 and ext3 unless otherwise specified.&lt;br /&gt;
&lt;br /&gt;
==== XFS ====&lt;br /&gt;
XFS, originally developed by SGI some time in the bronze age, but has been worked on heavily after that. RHEL and Centos version 7 and forward, uses XFS as the default filesystem. It is quick, it scales well, but it lacks at least two things ext4 has. It cannot be shrunk (not that you normally need that, but nice if you have a typo or you need to change things). Also, it doesn&#039;t allow for automatic fsck on bootup. If something is messed up on the filesystem, you&#039;ll have to login as root on the console (not ssh), which might be an issue on some systems. The fsck equivalent, xfs_repair, is a *lot* faster than ext4&#039;s fsck, though.&lt;br /&gt;
&lt;br /&gt;
==== ZFS ====&lt;br /&gt;
ZFS is like a combination of RAID, LVM and a filesystem, supporting full checksumming, auto-healing (given sufficient redundancy), compression, encryption, replication, deduplication (if you&#039;re brave and have a &#039;&#039;ton&#039;&#039; of memory) and a lot more. It&#039;s a separate chapter and needs a lot more talk than paragraph here.&lt;br /&gt;
&lt;br /&gt;
==== btrfs ====&lt;br /&gt;
btrfs, pronounced &amp;quot;butterfs&amp;quot; or &amp;quot;betterfs&amp;quot; or just spelled out, is a filesystem that mimics that of ZFS. It has been around for 10 years or so, but hasn&#039;t yet proven to be really stable. Following the progress of it for those years, I&#039;ve found it to be a nice toy with which to play, but not to be used in production. Again, others may say otherwise, but these are just my words.&lt;br /&gt;
&lt;br /&gt;
== Low level disk handling ==&lt;br /&gt;
&lt;br /&gt;
This section is for low-level handling of disks, regardless of storage system elsewhere. These apply to mdraid, lvmraid and zfs and possibly other solutions, with the exception of individual drives on hwraid (and maybe fakeraid), since there, the drives are hidden from Linux (or whatever OS).&lt;br /&gt;
&lt;br /&gt;
=== S.M.A.R.T. and slow drives ===&lt;br /&gt;
Modern (that is, from about 1990 or later) have S.M.A.R.T. (or just smart, since it&#039;s easier to type) monitoring built in, meaning the disk&#039;s controller is monitoring itself. This is handy and will ideally tell you in advance that a drive is flakey or dying. Modern (2010+) smart monitoring is more or less the same. It can be trusted about 50% of the time. Usually, if smart detects an error, it&#039;s a real error. I don&#039;t think I&#039;ve seen it reporting a false positive, but others may know better. &lt;br /&gt;
&lt;br /&gt;
==== smartmontools ====&lt;br /&gt;
First, install smartmontool and run smartclt -H /dev/yourdisk (/dev/sda or something) to get a health report. Then perhaps run smartctl -a /dev/yourdisk and look for &#039;current pending sectors&#039; This should be zero. Also check the temperature, which normally should be much above 50.&lt;br /&gt;
&lt;br /&gt;
==== single, slow drive ====&lt;br /&gt;
What may happen, is smart not seeing anything and life goes on like before, only slower and less prouductive, without telling anyone. If you stubler over this issue, you&#039;ll probably see it during a large rsync/zfs send/receive or a resync/rebuild/resilver of the raid/zpool. During this, it feels like everything is slow and your RAID has turned into a RAIF (redundant array of inexpensive floppies). To check if you have a single drive messing up it all, check with &#039;&#039;&#039;iostat -x 2&#039;&#039;&#039;, having 2 being the delay between each measurement. Interrupt it with ctrl+x. If there&#039;s a rougue drive there, it should stand out like sdg below&lt;br /&gt;
&lt;br /&gt;
 avg-cpu:  %user   %nice %system %iowait  %steal   %idle&lt;br /&gt;
            0.38    0.00    1.75    0.00    0.00   97.87&lt;br /&gt;
&lt;br /&gt;
 Device            r/s     w/s     rkB/s     wkB/s   rrqm/s   wrqm/s  %rrqm  %wrqm r_await w_await aqu-sz rareq-sz wareq-sz  svctm  %util&lt;br /&gt;
 sda              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdb              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdc              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdd              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sde              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdf              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdg              3.50    0.00   2352.00      0.00     0.00     0.00   0.00   0.00 14306.29    0.00  13.85   672.00     0.00 285.71 100.00&lt;br /&gt;
 sdh              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
&lt;br /&gt;
In ZFS land, you should be able to get similar data with &#039;&#039;&#039;zpool iostat -v &amp;lt;pool&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Now you know the bad drive (sdg), pull it from the raid with &#039;&#039;&#039;mdadm --fail /dev/mdX /dev/sdX&#039;&#039;&#039;. Now test the drive&#039;s performance manually, just simply:&lt;br /&gt;
&lt;br /&gt;
 # hdparm -t /dev/sdg&lt;br /&gt;
 &lt;br /&gt;
 /dev/sdg:&lt;br /&gt;
  Timing buffered disk reads:   2 MB in  5.37 seconds = 381.46 kB/sec&lt;br /&gt;
&lt;br /&gt;
Bingo - nothing you&#039;d want to keep. For a good drive, it should be something like 100-200MB/s&lt;br /&gt;
&lt;br /&gt;
PS: Keep in mind that you have a degraded RAID by now in case you had a spare waiting for things to happen.&lt;br /&gt;
&lt;br /&gt;
Try to replace the cable and/or try the disk on another port/controller. If the result from hdparm persists, it&#039;s probably a bad cable&lt;br /&gt;
&lt;br /&gt;
So, then, just psycially locate the drive, pull it out, take out the discs and magnets and recycle the rest.&lt;br /&gt;
&lt;br /&gt;
=== &amp;quot;Unplug&amp;quot; drive from system ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Find the device unit&#039;s number with something like&lt;br /&gt;
find /sys/bus/scsi/devices/*/block/ -name sdd&lt;br /&gt;
# returning /sys/bus/scsi/devices/3:0:0:0/block/sdd here, &lt;br /&gt;
# meaning 3:0:0:0 is the SCSI device we&#039;re looking for.&lt;br /&gt;
&lt;br /&gt;
# Given this is the correct device, and you want to &#039;unplug&#039; it, do so by&lt;br /&gt;
echo 1 &amp;gt; /sys/bus/scsi/devices/3:0:0:0/delete&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Rescan disk controllers ===&lt;br /&gt;
If a drive is added and for some reason doesn&#039;t get detected, or is removed by the command above, it can be rediscovered with a sysfs command to the scsi host to which it is connected. Since there may be quite a few of these, an easy way is to just scan them all and check the output of &#039;&#039;&#039;dmesg -T&#039;&#039;&#039; after running it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Make a list of controllers and send a rescan message to each of them. It won&#039;t do anything &lt;br /&gt;
# for those where nothing has changed, but it will show new drives where they have been added.&lt;br /&gt;
for host_scan in /sys/class/scsi_host/host*/scan&lt;br /&gt;
do&lt;br /&gt;
  echo &#039;- - -&#039; &amp;gt; $host_scan&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Fail injection with debugfs ===&lt;br /&gt;
[https://lxadm.com/Using_fault_injection https://lxadm.com/Using_fault_injection]&lt;br /&gt;
&lt;br /&gt;
== mdadm stuff ==&lt;br /&gt;
=== Resync ===&lt;br /&gt;
To resync a raid, that is, check, run&lt;br /&gt;
&lt;br /&gt;
 echo check &amp;gt; /sys/block/$dev/md/sync_action&lt;br /&gt;
&lt;br /&gt;
where $dev is something like md0. If you have several raids, something like this should work&lt;br /&gt;
&lt;br /&gt;
 for dev in md{0,1}&lt;br /&gt;
 do&lt;br /&gt;
   echo repair &amp;gt; /sys/block/$dev/md/sync_action&lt;br /&gt;
 done&lt;br /&gt;
&lt;br /&gt;
Also useful in a one-liner like&lt;br /&gt;
&lt;br /&gt;
 for dev in md{0,1} ; do echo repair &amp;gt; /sys/block/$dev/md/sync_action ; done&lt;br /&gt;
&lt;br /&gt;
Different raids on different drives will do this in parallel. If the drives are shared somehow with partitions or similar, the check or repair will wait for the other to finish before going on.&lt;br /&gt;
&lt;br /&gt;
As for repair vs check, [https://raid.wiki.kernel.org/index.php/RAID_Administration this article] describes it well. I stick to using repair unless it&#039;s something rare where I don&#039;t want to touch the data.&lt;br /&gt;
&lt;br /&gt;
=== Spare pools ===&lt;br /&gt;
In the old itmes, mdadm supported only a dedicated spare per md device, so if working with a large set of drives (20? 40?), where you&#039;d want to setup more raid sets to increase redundancy, you&#039;d dedicate a spare to each of the raid sets. This has changed (some time ago?), so in these modern, heathen days, you can change mdadm.conf, usually placed under /etc/mdadm, and add &#039;spare-group=somegroup&#039; where &#039;somegroup&#039; is a string identifying the spare group. After doing this, run &#039;&#039;&#039;update-initramfs -u&#039;&#039;&#039; and reboot and add a spare to one of the raid sets in the spare group, and md will use that or those spares for all the raidsets in that group.&lt;br /&gt;
&lt;br /&gt;
As some pointed out on #linux-raid @ irc.freenode.net, this feature is very badly documented, but as far as I can see, it works well.&lt;br /&gt;
&lt;br /&gt;
==== Example config ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create two raidsets&lt;br /&gt;
&lt;br /&gt;
mdadm --create /dev/md1 --level=6 --raid-devices=6 /dev/vd[efghij]&lt;br /&gt;
mdadm --create /dev/md2 --level=6 --raid-devices=6 /dev/vd[klmnop]&lt;br /&gt;
&lt;br /&gt;
# get their UUID etc&lt;br /&gt;
&lt;br /&gt;
mdadm --detail --scan&lt;br /&gt;
ARRAY /dev/md/1 metadata=1.2 name=raidtest:1 UUID=1a8cbdcb:f4092350:348b6b80:c054d74c&lt;br /&gt;
ARRAY /dev/md/2 metadata=1.2 name=raidtest:2 UUID=894b1b7c:cb7eba70:917d6033:ea5afd2b&lt;br /&gt;
&lt;br /&gt;
# Put those lines into /etc/mdadm/mdadm.conf and and add the spare-group&lt;br /&gt;
&lt;br /&gt;
ARRAY /dev/md/1 metadata=1.2 name=raidtest:1 spare-group=raidtest UUID=1a8cbdcb:f4092350:348b6b80:c054d74c&lt;br /&gt;
ARRAY /dev/md/2 metadata=1.2 name=raidtest:2 spare-group=raidtest UUID=894b1b7c:cb7eba70:917d6033:ea5afd2b&lt;br /&gt;
&lt;br /&gt;
# update the initramfs and reboot&lt;br /&gt;
&lt;br /&gt;
update-initramfs -u&lt;br /&gt;
reboot&lt;br /&gt;
&lt;br /&gt;
# add a spare drive to one of the raids&lt;br /&gt;
&lt;br /&gt;
mdadm --add /dev/md1 /dev/vdq&lt;br /&gt;
&lt;br /&gt;
# fail a drive on the other raid&lt;br /&gt;
&lt;br /&gt;
mdadm --fail /dev/md2 /dev/vdn&lt;br /&gt;
&lt;br /&gt;
# check /proc/mdstat to see md2 rebuilding with the spare from md1&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Recovery ===&lt;br /&gt;
&lt;br /&gt;
The other day, I came across a problem a user had on #linux-raid@irc.freenode.net. He had an old Qnap NAS that had died and tried plugging the drives in to his Linux machine and got various errors. The two-drive RAID-1 did not come up as it should, &#039;&#039;&#039;dmesg&#039;&#039;&#039; was full of errors from one of the drives (both connected on USB) and so forth.&lt;br /&gt;
&lt;br /&gt;
We went on and started by taking down the machine and just connecting one of the drives. I had him check what was assembled with&lt;br /&gt;
&lt;br /&gt;
 cat /proc/mdstat&lt;br /&gt;
&lt;br /&gt;
That returned /proc/md127 assembled, but LVM didn&#039;t find anything. So running a manual scan&lt;br /&gt;
&lt;br /&gt;
 pvscan --cache /dev/md127&lt;br /&gt;
&lt;br /&gt;
This made linux find the PV, VG and a couple of LVs, but probably because the mdraid was degraded, the LVs were deactivated, according to &#039;&#039;&#039;lvscan&#039;&#039;&#039;. Activating the one with a filesystem manually&lt;br /&gt;
&lt;br /&gt;
 lvchange -a y /dev/&amp;lt;vg&amp;gt;/&amp;lt;lv&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Substitute &amp;lt;vg&amp;gt; and &amp;lt;lv&amp;gt; with the names listed by vgs and lvs.&lt;br /&gt;
&lt;br /&gt;
This worked, and the filesystem on /dev/&amp;lt;vg&amp;gt;/&amp;lt;lv&amp;gt; could be mounted correctly.&lt;br /&gt;
&lt;br /&gt;
== Tuning ==&lt;br /&gt;
&lt;br /&gt;
While trying to compare a 12-disk RAID (8TB disks) to a hwraid, mdraid was slower, so we did a few things to speed things up:&lt;br /&gt;
&lt;br /&gt;
While testing with [https://linux.die.net/man/1/fio fio], monitor /sys/block/md0/md/stripe_cache_active, and see if it&#039;s close to /sys/block/md0/md/stripe_cache_size. If it is, double the size of the latter&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
echo 4096 &amp;gt; /sys/block/md0/md/stripe_cache_size&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Continue until stripe_cache_active stabilises, and then you&#039;ve found the limit you&#039;ll need. You may want to double that for good measure. &lt;br /&gt;
&lt;br /&gt;
(to be continued)&lt;br /&gt;
&lt;br /&gt;
== Links ==&lt;br /&gt;
&lt;br /&gt;
Below are a few links with useful info&lt;br /&gt;
&lt;br /&gt;
* [https://raid.wiki.kernel.org/index.php/Irreversible_mdadm_failure_recovery Irreversible mdadm failure recovery]&lt;br /&gt;
&lt;br /&gt;
= ZFS =&lt;br /&gt;
&lt;br /&gt;
ZFS can do a lot of things most filesystems or volume managers can&#039;t. It checksums all data and metadata and so long that the system uses ECC enabled memory (RAM), it will have complete control over the whole data set, and when (not if) an error occurs, it&#039;ll fix the issue without even throwing a warning. To fix the issue, you&#039;ll obviously need sufficient redundancy (mirrors or RAIDzN). &lt;br /&gt;
&lt;br /&gt;
== ZFS send/receive between machines ==&lt;br /&gt;
&lt;br /&gt;
ZFS has a send/receive mechanism that allows for snapshots to be sent over the wire to a receiving end. This can be a full filesystem, or an incremental change since last send/reveive. In a WAN scenario, you&#039;ll probably want to use VPN for this. On a controlled network, sending in cleartext is also possible. You may as well use ssh, but keep in mind that ssh was never designed to be used as a fullblown vpn solution and is just too slow or the task with large amounts of data. You may, though, use mbuffer, if on a loal LAN.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Allow traffic from the sending IP in whatever firewall interface you&#039;re using (if you&#039;re using a firewall at all, that is)&lt;br /&gt;
ufw allow from x.x.x.x&lt;br /&gt;
# &lt;br /&gt;
# Start the receiver first. This listens on port 9090, has a 1GB buffer,&lt;br /&gt;
    and uses 128kb chunks (same as zfs):&lt;br /&gt;
&lt;br /&gt;
mbuffer -s 128k -m 1G -I 9090 | zfs receive data/filesystem&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To be continued one day… See [https://everycity.co.uk/alasdair/2010/07/using-mbuffer-to-speed-up-slow-zfs-send-zfs-receive/ this] for some more. I&#039;ll get back with details on it.&lt;br /&gt;
&lt;br /&gt;
= General Linux system control =&lt;br /&gt;
&lt;br /&gt;
== Add a new CPU (core) ==&lt;br /&gt;
&lt;br /&gt;
If working with virtual machines, adding a new core can be useful if the VM is slow and the load is multithreaded or multiprocess. To do this, add a new CPU in the hypervisor (be it KVM or VMware or Hyper-V or whatever). Some hypervisors, like VMware, will activate it automatically if open-vm-tools is installed. Please note that open-vm-tools is for VMware only. I don&#039;t know of any such thing for KVM or other hypervisors (although I beleive VirtualBox has its own set of tools, but not as a package). If this doesn&#039;t work, run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
echo 1 &amp;gt; /sys/devices/system/cpu/cpuX/online&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where X is the CPU number you want to add. You can &#039;cat /sys/devices/system/cpu/cpuX/online&#039; to check if it&#039;s online.&lt;br /&gt;
&lt;br /&gt;
= Mount partitions on a disk image =&lt;br /&gt;
&lt;br /&gt;
Sometimes you&#039;ll have a disk image, either from recovering a bad drive after hours (or days or weeks) of ddrescue, and sometimes you just have a disk image from a virtual machine where you want to mount the partitions inside the image. There are three main methods of doing this, which are more or less synonmous, but some easier than the other.&lt;br /&gt;
&lt;br /&gt;
== Basics ==&lt;br /&gt;
&lt;br /&gt;
A disk image is usually like a disk, consisting of either a large filesystem, a PV or a partition table with one or partitions onto which resides a filesystem, a pv, swap or something else. If it&#039;s partitioned, and you want your operating system to mount a filesystem or allow it to see whatever LVM stuff lies on it, you need to isolate the partitions. &lt;br /&gt;
&lt;br /&gt;
== Manual mapping ==&lt;br /&gt;
&lt;br /&gt;
In the oldern days, this was done manually, something like this&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
root@mymachine:~# fdisk -l /dev/vda&lt;br /&gt;
Disk /dev/vda: 25 GiB, 26843545600 bytes, 52428800 sectors&lt;br /&gt;
Units: sectors of 1 * 512 = 512 bytes&lt;br /&gt;
Sector size (logical/physical): 512 bytes / 512 bytes&lt;br /&gt;
I/O size (minimum/optimal): 512 bytes / 512 bytes&lt;br /&gt;
Disklabel type: dos&lt;br /&gt;
Disk identifier: 0xc37b7ea5&lt;br /&gt;
&lt;br /&gt;
Device     Boot    Start      End  Sectors  Size Id Type&lt;br /&gt;
/dev/vda1  *        2048 50333311 50331264   24G 83 Linux&lt;br /&gt;
/dev/vda2       50333312 52426369  2093058 1022M  5 Extended&lt;br /&gt;
/dev/vda5       50333314 52426369  2093056 1022M 82 Linux swap / Solaris&lt;br /&gt;
root@mymachine:~#&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To calculate the start and end of each partition, you just take the start sector and multiply it by the sector size (512 bytes here) and you have the offset in bytes. After this, it&#039;s merely an losetup -o &amp;lt;offset&amp;gt; /dev/loopX &amp;lt;nameofimagefile&amp;gt; and you have the partition mapped to your /dev/loopX (having X being something typically 0-255. After this, just mount it or run pvscan/vgscan/lvscan to probe whatever lvm config is there, and you should be able to mount it like any other filesystem.&lt;br /&gt;
&lt;br /&gt;
== kpartx ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;kpartx&#039;&#039;&#039; does the same as above, more or less, just without so much hassle. Most of it should be automatic and easy to deal with, except it may fail to disconnect the loopback devices sometimes, so you may have to &#039;&#039;&#039;losetup -d&#039;&#039;&#039; them manually. See the manual, &#039;&#039;&#039;kpartx (8)&#039;&#039;&#039;. Please note that &#039;&#039;&#039;partx&#039;&#039;&#039; works similarly and I&#039;d guess the authors of the two tools are arguing a lot of which one&#039;s the best.&lt;br /&gt;
&lt;br /&gt;
== guestmount ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;guestmount&#039;&#039;&#039; is something similar again, but also supports file formats like &#039;&#039;&#039;qcow2&#039;&#039;&#039; and possibly other, proprietary filesystems like &#039;&#039;&#039;vmdk&#039;&#039;&#039; and &#039;&#039;&#039;vdi&#039;&#039;&#039;, but don&#039;t take my word for it - I haven&#039;t tested. Again, see the manual or just read up on the description [http://ask.xmodulo.com/mount-qcow2-disk-image-linux.html?fbclid=IwAR3snTeZvGzp9PLdX11EQhCfOpux6I93CiJ3A2pUomkkRLly9Xo4851mkTY here]. It seems rather trivial.&lt;br /&gt;
&lt;br /&gt;
= Linux on laptops =&lt;br /&gt;
&lt;br /&gt;
== Wifi with HP EliteBook 725/745 on Ubuntu ==&lt;br /&gt;
&lt;br /&gt;
The HP EliteBook 725/745 and similar are equipped with a BCM4352 wifi chip. As with a lot of other stuff from Broadcom, this lacks an open hardware description, so thus no open driver exist. The proper fix, is to replace the NIC with something with an open driver, but again, this isn&#039;t always possible, so a binary driver exists. In ubuntu, run, somehow connect the machine to the internet and run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install bcmwl-kernel-source&lt;br /&gt;
sudo modprobe wl&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you can&#039;t connect the machine to the internet, download the needed packages on another machine and put it on some usb storage. These packages should suffice:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# apt-cache depends bcmwl-kernel-source&lt;br /&gt;
bcmwl-kernel-source&lt;br /&gt;
  Depends: dkms&lt;br /&gt;
  Depends: linux-libc-dev&lt;br /&gt;
  Depends: libc6-dev&lt;br /&gt;
  Conflicts: &amp;lt;bcmwl-modaliases&amp;gt;&lt;br /&gt;
  Replaces: &amp;lt;bcmwl-modaliases&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then install manually with &#039;&#039;&#039;dpkg -i file1.deb file2.deb&#039;&#039;&#039; etc&lt;br /&gt;
&lt;br /&gt;
After this, ip/ifconfig/iwconfig shouldd see the new wifi nic, probably &#039;&#039;&#039;wlan0&#039;&#039;&#039;, but due to a [https://bugs.launchpad.net/ubuntu/+source/broadcom-sta/+bug/1343151 old, ignored bug], you won&#039;t find any wifi networks. This is because the driver from Broadcom apparently does not support interrupt remapping, commonly used on x64 machines. To turn this off, change &#039;&#039;&#039;/etc/default/grub&#039;&#039;&#039; and change the line &#039;&#039;&#039;GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;quiet splash&amp;quot;&#039;&#039;&#039;, adding intremap=off to the end before the quote: &#039;&#039;&#039;GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;quiet splash intremap=off&amp;quot;&#039;&#039;&#039;. Save the file and run &#039;&#039;&#039;sudo update-grub&#039;&#039;&#039; and reboot. After this, wifi should work well.&lt;br /&gt;
&lt;br /&gt;
== Wifi with HP Compaq Presario CQ57 on Ubuntu ==&lt;br /&gt;
&lt;br /&gt;
The HP Compaq Presario CQ57 uses the RT5390 wifi chipset. This has been supported for quite some time now, and I was quite surprised to find it not working on a laptop a friend was having. The driver loaded correctly, but Ubuntu insisted of the laptop being in &#039;&#039;&#039;flight mode&#039;&#039;&#039;. Checking &#039;&#039;&#039;rfkill&#039;&#039;&#039;, it showed me two NICs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# rfkill list all&lt;br /&gt;
0: phy0: Wireless LAN&lt;br /&gt;
	Soft blocked: no&lt;br /&gt;
	Hard blocked: yes&lt;br /&gt;
1: hp-wifi: Wireless LAN&lt;br /&gt;
	Soft blocked: yes&lt;br /&gt;
	Hard blocked: no&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Turning rfkill on and off resulted in nothing much, except some error messages in the kernel log (dmesg)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] ACPI Error: Field [B128] at bit offset/length 128/1024 exceeds size of target Buffer (160 bits) (20170831/dsopcode-235)&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]&lt;br /&gt;
                            Initialized Local Variables for Method [HWCD]:&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Local0: 00000000a34b7928 &amp;lt;Obj&amp;gt;           Integer 0000000000000000&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Local1: 00000000b0aa6865 &amp;lt;Obj&amp;gt;           Buffer(8) 46 41 49 4C 04 00 00 00&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Local5: 00000000a9811efd &amp;lt;Obj&amp;gt;           Integer 0000000000000004&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] Initialized Arguments for Method [HWCD]:  (2 arguments defined for method invocation)&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Arg0:   0000000078957d1b &amp;lt;Obj&amp;gt;           Integer 0000000000000001&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Arg1:   00000000725c9c6e &amp;lt;Obj&amp;gt;           Buffer(20) 53 45 43 55 02 00 00 00&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] ACPI Error: Method parse/execution failed \_SB.WMID.HWCD, AE_AML_BUFFER_LIMIT (20170831/psparse-550)&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] ACPI Error: Method parse/execution failed \_SB.WMID.WMAD, AE_AML_BUFFER_LIMIT (20170831/psparse-550)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After upgrading BIOS and testing different kernels, I was asked to try to unload the &#039;&#039;&#039;hp_wmi&#039;&#039;&#039; driver. I did, and things changed a bit, so I tried blacklisting it, creating the file &#039;&#039;&#039;/etc/modprobe.d/blacklist-hp_wmi.conf&#039;&#039;&#039; with the following content&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Blacklist this - it doesn&#039;t work!&lt;br /&gt;
blacklist hp_wmi&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
I gave the machine a reboot and afte that, the &#039;&#039;&#039;hp-wifi&#039;&#039;&#039; entry was gone in the rfkill output, and things works.&lt;br /&gt;
&lt;br /&gt;
= Raspberry pi =&lt;br /&gt;
&lt;br /&gt;
I couldn&#039;t quite decide if the raspberry pi should be a separate section or part of Linux, but hell, it can run more than Linux, although 99,lots% of people just uses Linux on them. This is a small list of things to know about them; things not on the front page of the manual or perhaps hidden even better.&lt;br /&gt;
&lt;br /&gt;
== Which pi? ==&lt;br /&gt;
&lt;br /&gt;
I just setup three raspberry pi machines and although some are quite different, like v1 to vEverythingelse or the Pi zero versions to the normal ones, not all of us remember how to distinguish between them, and sometimes they&#039;re in a nice 3d printed (or otherwise) chassis or otherwise hidden. So, how to check three different ones:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
root@home-assistant:~ $ cat /proc/device-tree/model ; echo&lt;br /&gt;
Raspberry Pi 2 Model B Rev 1.1&lt;br /&gt;
&lt;br /&gt;
root@green-pi:~ $ cat /proc/device-tree/model ; echo&lt;br /&gt;
Raspberry Pi 3 Model B Rev 1.2&lt;br /&gt;
&lt;br /&gt;
roy@yellow-pi:~ $cat /proc/device-tree/model ; echo&lt;br /&gt;
Raspberry Pi 4 Model B Rev 1.1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
While this works well, for the latter, the pi4, it doesn&#039;t tell how much memory I have. It comes in variants of 1, 2 and 4GB, and this is the latter.&lt;br /&gt;
&lt;br /&gt;
== Monitoring ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;vcgencmd&#039;&#039;&#039; from &#039;&#039;&#039;/opt/vc/bin&#039;&#039;&#039;, but symlinked to &#039;&#039;&#039;/usr/bin&#039;&#039;&#039; so it&#039;s available in path, is useful for fetching hardware info about the pi. For example, measuring the temperature&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
root@yellow-pi:~# vcgencmd measure_temp&lt;br /&gt;
temp=63.0&#039;C&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The command is generally badly documented and parts of it seems outdated for newer hardware. Here&#039;s the output from a Raspberry pi 4 with 4GB RAM&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
roy@yellow-pi:~ $ vcgencmd get_mem arm&lt;br /&gt;
arm=948M&lt;br /&gt;
roy@yellow-pi:~ $ vcgencmd get_mem gpu&lt;br /&gt;
gpu=76M&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= BIOS upgrade from Linux =&lt;br /&gt;
&lt;br /&gt;
Generally, BIOS upgrades have been moved to the BIOS itself these days. This saves a lot of work and quite possibly lives after those who earier rammed their heads through walls, now can upgrade directly from the internet instead of using obscure operating systems best avoided. Sometimes, however, one must use these nevertheless. This is a quick run-through on your options.&lt;br /&gt;
&lt;br /&gt;
== DOS ==&lt;br /&gt;
&lt;br /&gt;
Most non-automatic BIOS upgrades are installed from DOS. Doing a BIOS upgrade this way, is generally non-problematic. Just install a USB thingie with [https://www.freedos.org/ FreeDOS], copy your file(s) onto the thing and boot on it. The commandline is the same as old MS/DOS, except a wee bit more userfriendly, but not a lot.&lt;br /&gt;
&lt;br /&gt;
== Windows ==&lt;br /&gt;
&lt;br /&gt;
Some macahines, like laptops from &#039;&#039;&#039;HP&#039;&#039;&#039;, may have BIOS upgrades that are made to be installed from Windows and won&#039;t run in FreeDOS or MS/DOS, instead throwing an error, saying &#039;&#039;&#039;This program cannot be run in DOS mode&#039;&#039;&#039;. This means you&#039;ll have to boot on a Windows rescue disc and do the job from there. Googling this, tells you it&#039;s quite easy, you just choose &#039;make rescue disc&#039; from Windows, and it&#039;s all good, except if you don&#039;t run Windows, that is. To remedy this problem, do as follows:&lt;br /&gt;
&lt;br /&gt;
=== Download Windows ===&lt;br /&gt;
&lt;br /&gt;
Since you don&#039;t run Windows and possibly don&#039;t have a spouse or friend around with such unhealthy habits either, you need to get it. It&#039;s quite easy - just google &#039;download windows&#039; and it&#039;ll send you to [https://www.microsoft.com/en-us/software-download/windows10ISO somewhere like this].&lt;br /&gt;
&lt;br /&gt;
=== Burn it! ===&lt;br /&gt;
&lt;br /&gt;
Now it&#039;s time to burn the installer on a DVD ROM. You&#039;ll need a double-layered one, since the OS is &amp;gt; 4.7GiB, but I&#039;m sure you have a ton of those lying around. Now, just place your optical medium in your optical drive and burn, baby, burn!&lt;br /&gt;
&lt;br /&gt;
=== Or make a USB thing? ===&lt;br /&gt;
&lt;br /&gt;
Not a lot of machines have optical drives these days, so you may want to use an USB pen drive or something instead. This is easy, just make the USB bootable with the Windows application Microsoft has made for this. Unfortunately, this only runs on Windows, and unlike stuff like Debian, where the &#039;&#039;&#039;iso&#039;&#039;&#039; file can be dd&#039;ed directly onto a USB drive to make it bootable, the Windows &#039;&#039;&#039;iso&#039;&#039;&#039;s don&#039;t come with this luxury. There are lots of methods to make bootable USB things from iso files out there, but the only thing most of them have in common, is that they generally don&#039;t work.&lt;br /&gt;
&lt;br /&gt;
==== WoeUSB ====&lt;br /&gt;
&lt;br /&gt;
After hours of swearing, it&#039;s nice to come across software like [https://github.com/slacka/WoeUSB WoeUSB]. It may not be perfect, it relies on a bunch of GUI stuff you&#039;ll never need and so on, but it &#039;&#039;&#039;&#039;&#039;works&#039;&#039;&#039;&#039;&#039;, and that&#039;s the important part! Just clone the repo and RTFM and it&#039;s all nice. It&#039;s slow, but hell, getting a windows machine and/or an optical drive might be slower.&lt;br /&gt;
&lt;br /&gt;
WoeUSB does nothing fancy, but it &#039;&#039;&#039;does&#039;&#039;&#039; work. It will create a filesystem, FAT32 or NTFS (better use NTFS, FAT32 has its limits). It creates normal filesystems and so on. Just make sure to copy in the BIOS update file, usually an exe file, to run when Windows is up and running.&lt;br /&gt;
&lt;br /&gt;
==== Install BIOS ====&lt;br /&gt;
&lt;br /&gt;
Boot on the Windows USB thing and choose &#039;repair computer&#039; and then &#039;command prompt&#039;. Find the install file, and if you&#039;re lucky, you&#039;ll find it needs a 32bit OS, just like I did. Since the 64bit version doesn&#039;t include 32bit compatibility in the installer, revert to downloading the 32bit version of windows and start over. Pray to your favourite god(s) not to get across such machines again - it might help.&lt;br /&gt;
&lt;br /&gt;
= 3D printer stuff =&lt;br /&gt;
&lt;br /&gt;
Below are a number of not very ordered paragraphs about 3D printer related stuff, mostly based on my experience. Their content may be interesting or perhaps practical knowledge, but then, that depends on the reader.&lt;br /&gt;
&lt;br /&gt;
== 3D printer related introductions on youtube or elsewhere ==&lt;br /&gt;
&lt;br /&gt;
First off, I&#039;d like to mention some youtube videos that are all (or mostly) a nice start if you&#039;re new to 3D printers.&lt;br /&gt;
&lt;br /&gt;
=== [https://www.youtube.com/watch?v=nb-Bzf4nQdE&amp;amp;list=PLDJMid0lOOYnkcFhz6rfQ6Uj8x7meNJJx Thomas Salanderer&#039;s 10-video series on 3D printing basics] ===&lt;br /&gt;
&lt;br /&gt;
Thomas Salanderer is a an experienced 3D printer user/admin/fixer/etc and he has a lot of interesting videos. Some accuse him for being a [Prusa https://www.prusa3d.com/] fanboy, which he quite obviously is, but that doesn&#039;t stop him from making interesting and somewhat neutral videos. The series walks you thought the first steps of how things work and so on and hopefully opens more doors than anything else I&#039;ve seen.&lt;br /&gt;
&lt;br /&gt;
=== [https://www.youtube.com/watch?v=rp3r921DBGI Teaching Tech&#039;s &amp;quot;3D printer tuning reborn&amp;quot;] ===&lt;br /&gt;
&lt;br /&gt;
Teaching Tech is, like Salanderer or even more, good pedagogically and explains a lot. They (or he) do a bunch of testing and describing pros and cons with different things, just like other youtubers in the sme business. The mentioned video shows how to tune a 3D printer after you have first learned the basics, and leans on a webpage made to help you out without too much manual work.&lt;br /&gt;
&lt;br /&gt;
This was a short list, but I guess it&#039;ll grow over time.&lt;br /&gt;
&lt;br /&gt;
== Hydrophilic filament ==&lt;br /&gt;
&lt;br /&gt;
Most popular filament types, including PLA, PETG, PP or PA (Polyamide, normally known as Nylon) and virtualy any filament type named [https://www.matterhackers.com/news/filament-and-water poly-something] (and thus with an acronym of P-something) are hydrophilic (also (somewhat incorrectly) called hydroscopic), meaning so long they&#039;re dryer than the atmosphere around them, they&#039;ll do their best to suck out the atmosphere&#039;s humidity. This is why most filament are shrink-wrapped with a small bag of silica gel in it. If such filament is exposed for normal humid air for some time, it&#039;ll become very hard to use. Most of my experience is with PLA, which can handle a bit (depending on make), but still not a lot. With PLA, if you end up with prints where the filament seems not to stick, it may help with a higher temperature. Otherwise, the filament must be [https://all3dp.com/2/how-to-dry-filament-pla-abs-and-nylon/ baked]. If you don&#039;t want to use your oven, try something like a [https://www.jula.no/catalog/hjem-og-husholdning/kjokkenmaskiner/mattilberedningsapparater/frukt-sopptorker/frukt-sopptorker-001641/#tab02 fruit and mushroom dryer]. Then get a good, sealble plastic box and add something like half a kilogram of [https://www.ebay.com/sch/sis.html?_nkw=1KG+Orange+Replacement+Desiccant+Indicating+Silica+Gel+Beads+for+Drawers%2C+Camera&amp;amp;_id=131938742628&amp;amp;&amp;amp;_trksid=p2057872.m2749.l2658 silica gel] to an old sock, tie it and put it in the your new dry box.&lt;br /&gt;
&lt;br /&gt;
Please note that ABS is hydrophobic, so you won&#039;t have to worry too much there. Also, remember that PA/Nylon is extremely hydrophilic. Even a couple of days in normal air humidity can ruin it completely and will require baking.&lt;br /&gt;
&lt;br /&gt;
== Upgrading the firmware on an Ender 3 ==&lt;br /&gt;
&lt;br /&gt;
This is about upgrading the firmware, and thus also flashing a bootloader to the Creality Ender 3 3D printer. Most of this is well documented on several place, like o [https://www.youtube.com/watch?v=fIl5X2ffdyo the video from Teaching tech] and elsewhere, but I&#039;ll just summarise some issues I had.&lt;br /&gt;
&lt;br /&gt;
=== Using an arduino Nano as a programmer ===&lt;br /&gt;
&lt;br /&gt;
Quick note before you read on. If you have an Ender 3 controller version 1.1.5 or newer (or perhaps even a bit older), a CR-10S or some other more or less modern printers or controllers, they come with a bootloader installed already, so don&#039;t bother flashing one. The one that&#039;s in there already, should work well. So if you have one of these, just skip this and jump to the [[Roy&#039;s_notes#Flashing_the_printer|next section]].&lt;br /&gt;
&lt;br /&gt;
However, the normal CR-10 (without the S), Ender 3 and a few other printers from Creality come without a bootloader, so you&#039;ll need to flash one before upgrading the firmware. Well, strictly speakning, you don&#039;t need one, you can save those 8kB or so for other stuff and use a programmer to write the whole firmware, but then you&#039;ll need to wire up everything every time you want a new firmware, so in my world, you &#039;&#039;&#039;do&#039;&#039;&#039; need the bootloader, since it&#039;s easier.&lt;br /&gt;
&lt;br /&gt;
To install a bootloader, you&#039;ll need a programmer, and I didn&#039;t have one available. Having some el-cheapo china-copies of Arduinos around, I read I could use one and tried so. Although the docs mostly mention the Uno etc, it&#039;s just as simple with the Nano copy.&lt;br /&gt;
&lt;br /&gt;
So, grab an arduino, plug it to your machine with a USB cable, and, using the Arduino IDE, use the ArduinoISP sketch there (found under Examples) to burn the software needed for the arduino to work as a programmer. When this is done, connect a 10µF capacitor between RST and GND to stop it from resetting when used as a programmer. Connect the MOSI, MISO and SCK pins from the ICSP block (that little isolated 6-pin block on top of the ardu). See [https://www.arduino.cc/en/Tutorial/ArduinoISP here] for a pinout. Then find Vcc and GND either on the ICSP block or elsewhere. Some sites say that on some boards you shouldn&#039;t use the pins on the ICSP block for this. I doubt it matters, though. Then connect another jumper wire from pin 10 on the ardu to work as the reset pin outwards to the chip being programmed (that is, on the printer). The ICSP jumper block pin layout is the same on the printer and on the ardu, and probably elsewhere. Sometimes [https://xkcd.com/927/ standardisation] actually works…&lt;br /&gt;
&lt;br /&gt;
See https://cloud.karlsbakk.net/index.php/s/zw48YJjzaf8Rc2F for a pic with the ardu (this wiki is broken atm, will fix it later)&lt;br /&gt;
&lt;br /&gt;
== Flashing the printer ==&lt;br /&gt;
&lt;br /&gt;
When the boot loader is in place, possibly after some wierd errors from during the process, the screen on the 3d printer will go blank and it&#039;ll behave like being bricked. This is ok. Now disconnect the wires and connect the USB cable between computer and printer. If you haven&#039;t installed support for the Sanguino board, that is, the variant of the 1284-chip and surrounding electronics that is the core of the, you need to install it first. In the Arduino IDE, choose the Tools / Boards / Boards manager boot option and search for Sanguino. After this, you should find the Sanguino or Sanguino 1284p in the boards menu. After this, you should be able to communicate with the printer&#039;s controller. Download the [https://www.th3dstudio.com/knowledgebase/th3d-unified-firmware-package/ TH3D unified firmware], making sure it&#039;s the last version. Uncompress the zip and with Finder/Explorer/whateversomething&#039;scalledonlinux, browse to &#039;&#039;&#039;TH3DUF_R2/Firmware/TH3DUF_R2.ino&#039;&#039;&#039; and open it. It should open directly in the Android IDE. Keep in mind that the names TH3DUF_R2 and TH3DUF_R2.ino will vary between versions, but you get the point. Now configure it for your particular needs. You&#039;ll find most of this in the Configuration.h tab (that&#039;s really a file). Most of the other files won&#039;t be necessary unless you&#039;re doing some more advanced stuff, like replacing th controller with something non-standard or similar, but then again, that&#039;s another chapter (or book, even). The video mentioned above describes this well. After flashing the new firmware, you&#039;ll probably get some timeouts and errors, since apparently it resets the printer after giving it the new firmware, but without notifying the flashing software of it doing so. If this happens, calm down and reboot the printer and check its tiny monitor - it should work. If it doesn&#039;t work, and if you flashed the bootload yourself, try to flash it again, and if that doesn&#039;t work, try flashing the programmer again yet another time, just for kicks. Again, if you have a newer controller like the v1.1.5, don&#039;t touch the bootloader, as the one already installed, should work well as it is.&lt;br /&gt;
&lt;br /&gt;
PS: I tried enabling &#039;&#039;&#039;MANUAL_MESH_LEVELING&#039;&#039;&#039;, which in the code says that &#039;&#039;If used with a 1284P board the bootscreen will be disabled to save space&#039;&#039;. This effectively disabled the whole printer, and apparently may be making the firmware image a wee bit too large for it to fit the 1284P on the ender. It works well without it, though, and it may be fixed by now, since I tested this back in early 2019.&lt;br /&gt;
&lt;br /&gt;
== And then… ==&lt;br /&gt;
&lt;br /&gt;
With the new firmware in place, the printer should work as before, although with thermal runaway protection to better avoid fires in case the shit hits the fan, and to allow for things like autolevelling. With any luck, [https://www.precisionpiezo.co.uk/ this thing] may be ready for use by the time you read this - it surely looks nice!&lt;br /&gt;
&lt;br /&gt;
= Octoprint/Octopi =&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;This could have been under some other section, but again, I just branch out even though most of it is about sections mentioned elsewhere.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
When setting up a 3d printer for the first time, you usually get an SD card for storage and transfer data to the printer using [https://en.wikipedia.org/wiki/Sneakernet Sneakernet]. Some printers use micro SD cards, while other fullsize SD cards, which imho is better, since they don&#039;t get lost that easily, but otherwise do the same thing. This works, but is somewhat tedious. If you want to control the printer from a PC or phone, there&#039;s a simple trick for that as well - octoprint.&lt;br /&gt;
&lt;br /&gt;
[https://octoprint.org/ Octoprint], written by Gina Häußge, runs on most platforms including linux, windows, BSD*, macos etc. It supports controlling a camera to some extent out of the box and there&#039;s a large number of plugins availablee to do a lot of things you possibly haven&#039;t thought of (and quite often, you&#039;d ever need). The easiest way to install it, is to just grab a Raspberry pi - preferably some of the newer models (will get to that later) and download [https://octoprint.org/download/ octopi] and follow the instructions on that page.&lt;br /&gt;
&lt;br /&gt;
== Performance issues ==&lt;br /&gt;
&lt;br /&gt;
Some report (and I have seen it myself) issues with the pi&#039;s performance with regards to both handling the octoprint processes (which should be as close to realtime as possible) and handling other stuff like I/O, networking etc. The point is that at pi3 or older, has all peripherals connected to an internal USB hub. This might be practical, but performance-wise it&#039;s &#039;&#039;&#039;&#039;&#039;not&#039;&#039;&#039;&#039;&#039;. If you in addition connect a webcam to USB, you&#039;re asking for trouble, since USB will be your bottleneck. With a raspberry pi camera, the ones connected to the pi directly with a ribbon cable, this should not use USB, so it&#039;s better. Still, again, for older pi&#039;s, there might be some shortage in therms of cpu or i/o. The octopi runs something like raspbian which is a fork of debian which is a linux distro, so it all boils down to knowing linux.&lt;br /&gt;
&lt;br /&gt;
Your typical octopi will run octoprint, a streamer, usually &#039;&#039;&#039;mjpg-streamer&#039;&#039;&#039;, a simple, lightweight videostreamer that outputs a stream of jpeg-images (about the same format as cinemas use - that is - not MPEG). This may be a bit tough on the cpu and potentially i/o. Add inn a dash of USB overload and you&#039;re may see trouble.&lt;br /&gt;
&lt;br /&gt;
Still - a pi3 should be able to handle the load, but it might help to prioritise corretly. The octoprint process is the important part here, so we could give that full priority both in CPU and I/O and. Unfortunately, it doesn&#039;t seem like the current octopi has been migrated to using systemd for the startup. We&#039;ll deal with this later. To fix this in the old SysV init style file present there, the following patch should work against the file /etc/init.d/octoprint&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;diff&amp;quot;&amp;gt;&lt;br /&gt;
--- octoprint.old	2020-07-20 18:46:10.166651965 +0200&lt;br /&gt;
+++ octoprint	2020-07-20 18:53:21.724803211 +0200&lt;br /&gt;
@@ -22,6 +22,9 @@&lt;br /&gt;
 PIDFILE=/var/run/$NAME.pid&lt;br /&gt;
 PKGNAME=octoprint&lt;br /&gt;
 SCRIPTNAME=/etc/init.d/$PKGNAME&lt;br /&gt;
+NICELEVEL=-19                        # Top CPU priority&lt;br /&gt;
+IONICE_CLASS=1                       # Realtime I/O class&lt;br /&gt;
+IONICE_PRIORITY=0                    # Realtime I/O priority (probably not needed with class=realtime)&lt;br /&gt;
&lt;br /&gt;
 # Read configuration variable file if it is present&lt;br /&gt;
 [ -r /etc/default/$PKGNAME ] &amp;amp;&amp;amp; . /etc/default/$PKGNAME&lt;br /&gt;
@@ -70,10 +73,11 @@&lt;br /&gt;
&lt;br /&gt;
    is_alive $PIDFILE&lt;br /&gt;
    RETVAL=&amp;quot;$?&amp;quot;&lt;br /&gt;
-&lt;br /&gt;
    if [ $RETVAL != 0 ]; then&lt;br /&gt;
        start-stop-daemon --start --background --quiet --pidfile $PIDFILE --make-pidfile \&lt;br /&gt;
-       --exec $DAEMON --chuid $OCTOPRINT_USER --user $OCTOPRINT_USER --umask $UMASK -- serve $DAEMON_ARGS&lt;br /&gt;
+       --exec $DAEMON --chuid $OCTOPRINT_USER --user $OCTOPRINT_USER --umask $UMASK \&lt;br /&gt;
+       --nicelevel $NICELEVEL --ioched $IONICE_CLASS:$IONICE_PRIORITY \&lt;br /&gt;
+       --serve $DAEMON_ARGS&lt;br /&gt;
        RETVAL=&amp;quot;$?&amp;quot;&lt;br /&gt;
    fi&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This ismply upgrades the process to be allowed to use most of the resources on the pi, regardless of what other processes are whining about.&lt;br /&gt;
&lt;br /&gt;
PS: Code not tested - I don&#039;t have a pi right here. Will test later, but I&#039;m pretty sure it&#039;ll work. After all, it&#039;s just a few new arguments to start-stop-daemon&lt;br /&gt;
&lt;br /&gt;
roy&lt;/div&gt;</summary>
		<author><name>Roy</name></author>
	</entry>
	<entry>
		<id>https://wiki.malinux.no/index.php?title=Roy%27s_notes&amp;diff=170</id>
		<title>Roy&#039;s notes</title>
		<link rel="alternate" type="text/html" href="https://wiki.malinux.no/index.php?title=Roy%27s_notes&amp;diff=170"/>
		<updated>2020-08-19T17:05:04Z</updated>

		<summary type="html">&lt;p&gt;Roy: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= LVM, md and friends =&lt;br /&gt;
&lt;br /&gt;
== Linux&#039; Logical Volume Manager (LVM) ==&lt;br /&gt;
&lt;br /&gt;
=== LVM in general ===&lt;br /&gt;
&lt;br /&gt;
LVM is designed to be an abstraction layer on top of physical drives or RAID, typically [https://raid.wiki.kernel.org/index.php/RAID_setup mdraid] or [https://help.ubuntu.com/community/FakeRaidHowto fakeraid]. Keep in mind that fakeraid should be avoided unless you really need it, like in conjunction with dual-booting linux and windows on fakeraid. LVM broadly consists of three elements, the &amp;quot;physical&amp;quot; devices (PV), the volume group (VG) and the logical volume (LV). There can be multiple PVs, VGs and LVs, depending on requirement. More about this below. All commands are given as examples, and all of them can be fine-tuned using extra flags in need of so. In my experience, the defaults work well for most usecases.&lt;br /&gt;
&lt;br /&gt;
I&#039;m mentioning filesystem below too. Where I write ext4, the samme applies to ext2 and ext3.&lt;br /&gt;
&lt;br /&gt;
==== Create a PV ====&lt;br /&gt;
&lt;br /&gt;
A PV is the &amp;quot;physical&amp;quot; parts. This does not need to be a physical disk, but can also be another RAID, be it an mdraid, fakeraid, hardware raid, a virtual disk on a SAN or otherwisee or a partition on one of those. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#  These add three PVs, one on a drive (or hardware raid) and another two on mdraids.&lt;br /&gt;
pvcreate /dev/sdb&lt;br /&gt;
pvcreate /dev/md1 /dev/md2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For more information about pvcreate, see [https://linux.die.net/man/8/pvcreate the manual].&lt;br /&gt;
&lt;br /&gt;
==== Create a VG ====&lt;br /&gt;
&lt;br /&gt;
The volume group consists of one or more PVs grouped together on which LVs can be placed. If several PVs are grouped in a VG, it&#039;s generally a good idea to make sure these PVs have some sort of redundancy, as in mdraid/fakeraid or hwraid. Otherwise it will be like using a [https://en.wikipedia.org/wiki/RAID RAID-0] with a single point of failure on each of the independant drives. LVM has [https://unix.stackexchange.com/questions/150644/raiding-with-lvm-vs-mdraid-pros-and-cons  RAID code in it] as well, so you can use that. I haven&#039;t done so myself, as I generally stick to mraid. The reason is mdraid is, in my opinion older and more stable and has more users (meaning bugs are reported and fixed faster whenever they are found). That said, I beleive the actual RAID code used in LVM RAID are the same function calls as for mdraid, so it may not be much of a difference. I still stick with mdraid. To create a VG, run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create volume group my_vg&lt;br /&gt;
vgcreate my_vg /dev/md1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that if vgcreate is run with a PV (as /dev/md1 above) that is not defined as a PV (like above), this is done implicitly, so if you don&#039;t need any special flags to pvcreate, you can simply skip it and let vgcreate do that for you.&lt;br /&gt;
&lt;br /&gt;
==== Create an LV ====&lt;br /&gt;
&lt;br /&gt;
LVs can be compared to partitions, somehow, since they are bounderies of a fraction or all of that of a VG. The difference between them and a partition, however, is that they can be grown or shrunk easily and also moved around between PVs without downtime. This flexibility makes them superiour to partitions as your system can be changed without users noticing it. By default, an LV is alloated &amp;quot;thickly&amp;quot;, meaning all the data given to it, is allocated from the VG and thus the PV. The following makes a 100GB LV named &amp;quot;thicklv&amp;quot;. When making an LV, I usually allocate what&#039;s needed plus some more, but not everything, just to make sure it&#039;s space available for growth on any of the LVs on the VG, or new LVs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a thick provisioned LV named thicklv on the VG my_vg&lt;br /&gt;
lvcreate -n thicklv -L 100G my_vg&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After the LV is created, a filesystem can be placed on it unless it is meant to be used directly. The application for direct use include swap space, VM storage and certain database systems. Most of these will, however, work on filesystems too, although my testing has shown that on swap space, there is a significant performance gain for using dedicated storage without a filesystem. As for filesystems, most Linux users use either ext4 or xfs. Personally, I generally use XFS these days. See my notes below on filesystem choice.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a filesystem on the LV - this could have been mkfs -t ext4 or whatever filesystem you choose&lt;br /&gt;
mkfs -t xfs /dev/my_vg/thicklv&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then just edit /etc/fstab with correct data and run mount -a, and you should be all set.&lt;br /&gt;
&lt;br /&gt;
==== Create LVM cache ====&lt;br /&gt;
LVMcache is LVM&#039;s solution to caching a slowish filesystem on spinning rust with the help of much faster SSDs. For this to work, use a separate SSD or a mirror or two (just in case) an add the new disk/md dev to the same VG. In this case, we use a small mirror, md1. LVM is not able to cache to a disk or partition outside the volume group.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
vgextend data /dev/md1&lt;br /&gt;
  Physical volume &amp;quot;/dev/md1&amp;quot; successfully created.&lt;br /&gt;
  Volume group &amp;quot;data&amp;quot; successfully extended&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Thn create two LVs, one for the data (contents of files) and one for the metadata (filenames, directories, attributes etc). Typically, the metadata part won&#039;t need to be very large. 100M should usually do unless you have ekstremely many small files. I guess there are ways to calculate it, but again, 1GB should do for everyone (or was that 640k?). As for the data cache, I chose to use 40G here for a 15TB RAID. It will only cache what actively use anyway, so no need for overkill.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
lvcreate -L 1G -n _cache_meta data /dev/md1&lt;br /&gt;
lvcreate -l 100G -n _cache data /dev/md1&lt;br /&gt;
&lt;br /&gt;
# Some would want --cachemode writeback, but seriously, I wouldn&#039;t recommend it. Metadata or data can be easily corrupted in case of failure.&lt;br /&gt;
lvconvert --type cache-pool --cachemode writethrough --poolmetadata data/_cache_meta data/_cache&lt;br /&gt;
lvconvert --type cache --cachepool data/_cache data/data&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
That should be it. If you benchmarked the disk before this, you should try again and you&#039;ll probably get a nice surprise. If not, well, see below how to turn this off again :)&lt;br /&gt;
&lt;br /&gt;
==== Disabling LVM cache ====&lt;br /&gt;
&lt;br /&gt;
If you for some reason want to disable caching, this will do it cleanly and remove the LVs earlier created for caching the main device.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
lvconvert --uncache data/data&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Growing devices ====&lt;br /&gt;
&lt;br /&gt;
LVM objects can be grown and shrunk. If a PV resides on a RAID where a new drive has been added or otherwise grown, or on a partition or virtual disk that has been extended, the PV must be updated to reflect these changes. The following command will grow the PV to the maximum available on the underlying storage. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Resize the PV /dev/md (not the RAID, only the PV on the RAID) to its full size&lt;br /&gt;
pvresize /dev/md1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If a new PV is added, the VG can be grown to add the space on that in addition to what&#039;s there already. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Extend my_vg to include md2 and its space&lt;br /&gt;
vgextend my_vg /dev/md2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
With more space available in the VG, the LV can now be extended. Let&#039;s add another 50GB to it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Extend thicklv - add 50GB. If you know you won&#039;t need the space anywhere else, you may want to&lt;br /&gt;
# lvresize -l+100%FREE instead. Keep in mind the difference between -l (extents) and -L (bytes)&lt;br /&gt;
lvresize -L +50G my_vg/thicklv&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Growing filesystems ====&lt;br /&gt;
After the LV has grown, run &#039;&#039;xfs_growfs&#039;&#039; (xfs) or &#039;&#039;resize2fs&#039;&#039; (ext4) to make use of the new data. To grow the filesystem to all available space on ext4, run the below command.  To partly grow the filesystem or to shrink it or otherwise, please see the manuals.&lt;br /&gt;
&lt;br /&gt;
The filesystem can be mounted when this is run. If you for some reason get an &#039;&#039;&#039;access denied&#039;&#039;&#039; error when running this as root or with sudo, it&#039;s likely caused by a filesystem error. To fix this, unmount the filesystem first and run &#039;&#039;&#039;fsck -f /dev/my_vg/thicklv&#039;&#039;&#039; and remount it before retrying to extend it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
resize2fs /dev/my_vg/thicklv&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Similarly, with XFS, but note that xfs_growfs doesn&#039;t take the device name, but the filesystem&#039;s mount point. In the case of XFS, also note that the filesystem &#039;&#039;&#039;&#039;&#039;must&#039;&#039;&#039;&#039;&#039; be mounted to be grown. This, in contrast to how it was in the old days when filesystems had to be unmounted to be grown.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
xfs_growfs /my_mountpoint&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Rename system VG ====&lt;br /&gt;
&lt;br /&gt;
Some distros create VG names like those-from-a-sysadmin-with-a-well-developed-paranoia-not-to-hit-a-duplicate. Debian, for instance, uses names like &amp;quot;my-full-hostname-vg&amp;quot;. Personally, I don&#039;t like these, since if I were to move a disk or vdisk around to somewhere else, I&#039;d make sure not to add a disk named &#039;sys&#039; to an existing system. If you do, most distros will refuse to use the VGs with duplicate names, resulting in the OS not booting until either one is specified by its UUID or just one removed. As I&#039;m aware of this, I stick to the super-risky thing of all system VGs named &#039;sys&#039; and so on.&lt;br /&gt;
&lt;br /&gt;
If you do this, keep in mind that it may blow up your computer and take your girl- or boyfriend with it or even make either of them pregnant, allowing Trump to rule your life and generally make things suck. You&#039;re on your own!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Rename the VG&lt;br /&gt;
vgrename my-full-hostname-vg sys&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, in /boot/grub/grub.cfg, change the old lv path from something like &#039;/dev/mapper/debian--stretch--machine--vg-root&#039; to your new and fancy &#039;/dev/sys/root. Likewise, in /etc/fstab, change occurences of &#039;/dev/mapper/debian--stretch--machine--vg-&#039; (or similar) with &#039;/dev/sys/&#039;. Here, this was like this - the old ones commented out.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;fstab&amp;quot;&amp;gt;&lt;br /&gt;
#/dev/mapper/debian--stretch--box--vg-root      /               ext4            errors=remount-ro,discard       0       1&lt;br /&gt;
/dev/sys/root                                   /               ext4            errors=remount-ro,discard       0       1&lt;br /&gt;
# /boot was on /dev/vda1 during installation&lt;br /&gt;
UUID=myverylonguuidwithatonofgoodinfoinit       /boot           ext2            defaults                        0       2&lt;br /&gt;
#/dev/mapper/debian--stretch--box--vg-swap_1    none            swap            sw                              0       0&lt;br /&gt;
/dev/sys/swap_1                                 none            swap            sw                              0       0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Update /etc/initramfs-tools/conf.d/resume with similar data for swap.&lt;br /&gt;
&lt;br /&gt;
You might want to run &#039;update-initramfs -u -k all&#039; after this, but I&#039;m not sure if it&#039;s needed.&lt;br /&gt;
&lt;br /&gt;
Now, pray to the nearest god(s) and give it a reboot and it should (probably) work.&lt;br /&gt;
&lt;br /&gt;
After reboot, run &#039;&#039;&#039;swapoff -a&#039;&#039;&#039;, then &#039;&#039;&#039;mkswap /dev/sys/swap_1&#039;&#039;&#039; (or whatever it&#039;s called on your system) and &#039;&#039;&#039;swapon -a&#039;&#039;&#039; again. You may want to give it another reboot or two for kicks, but it should work well even without that.&lt;br /&gt;
&lt;br /&gt;
=== Migration tools ===&lt;br /&gt;
&lt;br /&gt;
At times, storage regimes change, new storage is added and sometimes it&#039;s not easy to migrate with the current hardware or its support systems. Once I had to migrate a 45TiB fileserver from one storage system to another, preferably without downtime. The server originally had three 15TiB PVs of which two were full and the third half full. I resorted to using [https://linux.die.net/man/8/pvmove pvmove] to just move the data on the PVs in use to a new PV. We started out with creating a new 50TiB PV, sde, and then to pvmove.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Attach /dev/sde to the VG my_vg&lt;br /&gt;
vgextend my_vg /dev/sde&lt;br /&gt;
&lt;br /&gt;
# Move the contents from /dev/sdb over to /dev/sde block by block. If a target is not given in pvmove,&lt;br /&gt;
# the contents of the source (sdb here) will be put somewhere else in the pool.&lt;br /&gt;
pvmove /dev/sdb /dev/sde&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This took a while (as in a week or so) - the pvmove command uses old code and logic (or at least did that when I migrated this in November 2016), but it affected performance on the server very little, so users didn&#039;t notice. After the first PV was migrated, I continued with the other two, one after the other, and after a month or so, it was migrated. We used this on a number of large fileservers, and it worked flawlessly. Before doing the production servers I also tried interrupting pvmove in various ways, including hard resets, and it just kept on after the reboot.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;NOTE:&#039;&#039;&#039;&#039;&#039; &#039;&#039;Even though it worked well for us, &#039;&#039;&#039;always&#039;&#039;&#039; keep a good backup before doing this. Things may go wrong, and without a good backup, you may be looking for a hard-to-find new job the next morning&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
==== mdadm workarounds ====&lt;br /&gt;
&lt;br /&gt;
===== Migrate from a mirror (raid-1) to raid-10 =====&lt;br /&gt;
&lt;br /&gt;
Create a mirror&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sdb /dev/sdc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
LVM (pv/vg/lv) on md0 (see above), put a filesystem on the lv and fill it with some data.&lt;br /&gt;
&lt;br /&gt;
Now, some months later, you want to change this to raid-10 to allow for the same amount of redundancy, but to allow more disks into the system.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mdadm --grow /dev/md0 --level=10&lt;br /&gt;
mdadm: Impossibly level change request for RAID1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So - no - doesn&#039;t work. But - we&#039;re on &lt;br /&gt;
&lt;br /&gt;
Since we&#039;re on lvm already, this&#039;ll be easy. If you&#039;re using filesystems directly on partitions, you can do this the same way, but without the pvmove part, using rsync or whateever you like instead. I&#039;d recommend using lvm for for the new raid, which should be rather obvious from this article. Now plug in a new drive and create a new raid10 on that one. If you two new drives, install both. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# change &amp;quot;missing&amp;quot; to the other device name if you installed two new drives&lt;br /&gt;
mdadm --create /dev/md1 --level=10 --raid-devices=2 /dev/vdd missing&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, as described above, just vgextend the vg, adding the new raid and run pvmove to move the data from the old pv (residing on the old raid1) to the new pv (on raid10). Afte rpvmove is finished (which may take awile, see above), just&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
vgreduce raidtest /dev/md0&lt;br /&gt;
pvremove /dev/md0&lt;br /&gt;
mdadm --stop /dev/md0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
…and your disk is free to be added to the new array. If the new raid is running in degraded mode (if you created it with just one drive), better don&#039;t wait too long, since you don&#039;t have redundancy. Just mdadm --add the devs.&lt;br /&gt;
&lt;br /&gt;
If you now have /dev/mdstat telling you your raid10 is active and have three drives, of which one is a spare, it should look something like this&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5] [raid4] [raid10]&lt;br /&gt;
md1 : active raid10 vdc[3](S) vdb[2] vdd[0]&lt;br /&gt;
      8380416 blocks super 1.2 2 near-copies [2/2] [UU]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Just mdadm --grow --raid-devices=3 /dev/md1&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;RAID section is not complete. I&#039;ll write more on migraing from raid10 to raid6 later. It&#039;s not straight forward, but easier than this one :)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== Thin provisioned LVs ===&lt;br /&gt;
&lt;br /&gt;
Thin provisioning on LVM is a method used for not allocating all the space given to an LV. For instance, if you have a 1TB VG and want to give an LV 500GB, although it currently only uses a fraction of that, a thin lv can be a good alternative. This will allow for adding a limit to how much it can use, but also to let it grow dynamically without manual work by the sysadmin. Thin provisioning adds another layer of abstaction by creating a special LV as a &#039;&#039;thin pool&#039;&#039; from which data is allocated to the &#039;&#039;thin volume(s)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== Create a thin pool ====&lt;br /&gt;
&lt;br /&gt;
Allocate 1TB to the thin pool to be used for thinly provisioned LVs. Keep in mind that the space allocated to the thin pool is in fact thick provisioned. Only the volumes put on &#039;&#039;thinpool&#039;&#039; are thin provisioned. This will create two hidden LVs, one for data and one for metadata. Normally the defaults will do, but check the manual if the data doesn&#039;t match the usual patterns (such as billions of files, resulting in huge amounts of metadata). I &#039;&#039;beleive&#039;&#039; the metadata part should be resizable at a later time if needed, but I have not tested it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a pool for thin LVs. Keep in mind that the pool itself is not thin provisioned, only the volumes residing on it&lt;br /&gt;
lvcreate --size 1T --type thin-pool --thinpool thinpool my_vg&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Create a thin volume ====&lt;br /&gt;
&lt;br /&gt;
You have the thinpool, now put a thin volume on it. It will allocate some space for metadata, but probably not much (a few megs, perhaps).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Now, create a volume with a virtual (-V) size of half a terabyte named thin_pool, but using the thinpool (-T) named thin_pool for storage&lt;br /&gt;
lvcreate -V 500G -T my_vg/thin_pool --name thinvol&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The new volume&#039;s device name will be /dev/thinvol. Now, create a filesystem on it, add to fstab and mount it. The &#039;&#039;&#039;df&#039;&#039;&#039; command will return available space according to the virtual size (-V), while lvs will show how much data is actually used on each of the thinly provisioned volumes.&lt;br /&gt;
&lt;br /&gt;
== Filesystem dilemmas ==&lt;br /&gt;
&lt;br /&gt;
=== XFS or ext4 or something else ===&lt;br /&gt;
The choice of filesystem varies for your use. Distros such as RHEL/CentOS has moved to XFS by default from v7. Debian/Ubuntu still sticks to ext4, like most other. I&#039;ll discuss my thoughts below on ext4 vs XFS and leave the other filesystems for later.&lt;br /&gt;
&lt;br /&gt;
==== ext4 ====&lt;br /&gt;
ext4 is probably the most used filesystem on linux as of writing. It&#039;s rock stable and has been extended by a lot of extensions since the original ext2. It still retains backward compatibility, being able to mount and fsck ext2 and ext3 with the ext4 driver. However, it doesn&#039;t handle large filesystems very well. If a filesystem is created for &amp;lt;16TiB, it cannot be grown to anything larger than 16TiB. This may have changed lately, though. One other issue is handling errors. If a large filesystem (say 10TiB) is damaged, an fsck may take several hours, leading to long downtime. When I refer to ext4 further in this text, the same applies to ext2 and ext3 unless otherwise specified.&lt;br /&gt;
&lt;br /&gt;
==== XFS ====&lt;br /&gt;
XFS, originally developed by SGI some time in the bronze age, but has been worked on heavily after that. RHEL and Centos version 7 and forward, uses XFS as the default filesystem. It is quick, it scales well, but it lacks at least two things ext4 has. It cannot be shrunk (not that you normally need that, but nice if you have a typo or you need to change things). Also, it doesn&#039;t allow for automatic fsck on bootup. If something is messed up on the filesystem, you&#039;ll have to login as root on the console (not ssh), which might be an issue on some systems. The fsck equivalent, xfs_repair, is a *lot* faster than ext4&#039;s fsck, though.&lt;br /&gt;
&lt;br /&gt;
==== ZFS ====&lt;br /&gt;
ZFS is like a combination of RAID, LVM and a filesystem, supporting full checksumming, auto-healing (given sufficient redundancy), compression, encryption, replication, deduplication (if you&#039;re brave and have a &#039;&#039;ton&#039;&#039; of memory) and a lot more. It&#039;s a separate chapter and needs a lot more talk than paragraph here.&lt;br /&gt;
&lt;br /&gt;
==== btrfs ====&lt;br /&gt;
btrfs, pronounced &amp;quot;butterfs&amp;quot; or &amp;quot;betterfs&amp;quot; or just spelled out, is a filesystem that mimics that of ZFS. It has been around for 10 years or so, but hasn&#039;t yet proven to be really stable. Following the progress of it for those years, I&#039;ve found it to be a nice toy with which to play, but not to be used in production. Again, others may say otherwise, but these are just my words.&lt;br /&gt;
&lt;br /&gt;
== Low level disk handling ==&lt;br /&gt;
&lt;br /&gt;
This section is for low-level handling of disks, regardless of storage system elsewhere. These apply to mdraid, lvmraid and zfs and possibly other solutions, with the exception of individual drives on hwraid (and maybe fakeraid), since there, the drives are hidden from Linux (or whatever OS).&lt;br /&gt;
&lt;br /&gt;
=== S.M.A.R.T. and slow drives ===&lt;br /&gt;
Modern (that is, from about 1990 or later) have S.M.A.R.T. (or just smart, since it&#039;s easier to type) monitoring built in, meaning the disk&#039;s controller is monitoring itself. This is handy and will ideally tell you in advance that a drive is flakey or dying. Modern (2010+) smart monitoring is more or less the same. It can be trusted about 50% of the time. Usually, if smart detects an error, it&#039;s a real error. I don&#039;t think I&#039;ve seen it reporting a false positive, but others may know better. &lt;br /&gt;
&lt;br /&gt;
==== smartmontools ====&lt;br /&gt;
First, install smartmontool and run smartclt -H /dev/yourdisk (/dev/sda or something) to get a health report. Then perhaps run smartctl -a /dev/yourdisk and look for &#039;current pending sectors&#039; This should be zero. Also check the temperature, which normally should be much above 50.&lt;br /&gt;
&lt;br /&gt;
==== single, slow drive ====&lt;br /&gt;
What may happen, is smart not seeing anything and life goes on like before, only slower and less prouductive, without telling anyone. If you stubler over this issue, you&#039;ll probably see it during a large rsync/zfs send/receive or a resync/rebuild/resilver of the raid/zpool. During this, it feels like everything is slow and your RAID has turned into a RAIF (redundant array of inexpensive floppies). To check if you have a single drive messing up it all, check with &#039;&#039;&#039;iostat -x 2&#039;&#039;&#039;, having 2 being the delay between each measurement. Interrupt it with ctrl+x. If there&#039;s a rougue drive there, it should stand out like sdg below&lt;br /&gt;
&lt;br /&gt;
 avg-cpu:  %user   %nice %system %iowait  %steal   %idle&lt;br /&gt;
            0.38    0.00    1.75    0.00    0.00   97.87&lt;br /&gt;
&lt;br /&gt;
 Device            r/s     w/s     rkB/s     wkB/s   rrqm/s   wrqm/s  %rrqm  %wrqm r_await w_await aqu-sz rareq-sz wareq-sz  svctm  %util&lt;br /&gt;
 sda              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdb              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdc              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdd              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sde              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdf              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdg              3.50    0.00   2352.00      0.00     0.00     0.00   0.00   0.00 14306.29    0.00  13.85   672.00     0.00 285.71 100.00&lt;br /&gt;
 sdh              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
&lt;br /&gt;
In ZFS land, you should be able to get similar data with &#039;&#039;&#039;zpool iostat -v &amp;lt;pool&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Now you know the bad drive (sdg), pull it from the raid with &#039;&#039;&#039;mdadm --fail /dev/mdX /dev/sdX&#039;&#039;&#039;. Now test the drive&#039;s performance manually, just simply:&lt;br /&gt;
&lt;br /&gt;
 # hdparm -t /dev/sdg&lt;br /&gt;
 &lt;br /&gt;
 /dev/sdg:&lt;br /&gt;
  Timing buffered disk reads:   2 MB in  5.37 seconds = 381.46 kB/sec&lt;br /&gt;
&lt;br /&gt;
Bingo - nothing you&#039;d want to keep. For a good drive, it should be something like 100-200MB/s&lt;br /&gt;
&lt;br /&gt;
PS: Keep in mind that you have a degraded RAID by now in case you had a spare waiting for things to happen.&lt;br /&gt;
&lt;br /&gt;
Try to replace the cable and/or try the disk on another port/controller. If the result from hdparm persists, it&#039;s probably a bad cable&lt;br /&gt;
&lt;br /&gt;
So, then, just psycially locate the drive, pull it out, take out the discs and magnets and recycle the rest.&lt;br /&gt;
&lt;br /&gt;
=== &amp;quot;Unplug&amp;quot; drive from system ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Find the device unit&#039;s number with something like&lt;br /&gt;
find /sys/bus/scsi/devices/*/block/ -name sdd&lt;br /&gt;
# returning /sys/bus/scsi/devices/3:0:0:0/block/sdd here, &lt;br /&gt;
# meaning 3:0:0:0 is the SCSI device we&#039;re looking for.&lt;br /&gt;
&lt;br /&gt;
# Given this is the correct device, and you want to &#039;unplug&#039; it, do so by&lt;br /&gt;
echo 1 &amp;gt; /sys/bus/scsi/devices/3:0:0:0/delete&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Rescan disk controllers ===&lt;br /&gt;
If a drive is added and for some reason doesn&#039;t get detected, or is removed by the command above, it can be rediscovered with a sysfs command to the scsi host to which it is connected. Since there may be quite a few of these, an easy way is to just scan them all and check the output of &#039;&#039;&#039;dmesg -T&#039;&#039;&#039; after running it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Make a list of controllers and send a rescan message to each of them. It won&#039;t do anything &lt;br /&gt;
# for those where nothing has changed, but it will show new drives where they have been added.&lt;br /&gt;
for host_scan in /sys/class/scsi_host/host*/scan&lt;br /&gt;
do&lt;br /&gt;
  echo &#039;- - -&#039; &amp;gt; $host_scan&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Fail injection with debugfs ===&lt;br /&gt;
[https://lxadm.com/Using_fault_injection https://lxadm.com/Using_fault_injection]&lt;br /&gt;
&lt;br /&gt;
== mdadm stuff ==&lt;br /&gt;
=== Resync ===&lt;br /&gt;
To resync a raid, that is, check, run&lt;br /&gt;
&lt;br /&gt;
 echo check &amp;gt; /sys/block/$dev/md/sync_action&lt;br /&gt;
&lt;br /&gt;
where $dev is something like md0. If you have several raids, something like this should work&lt;br /&gt;
&lt;br /&gt;
 for dev in md{0,1}&lt;br /&gt;
 do&lt;br /&gt;
   echo repair &amp;gt; /sys/block/$dev/md/sync_action&lt;br /&gt;
 done&lt;br /&gt;
&lt;br /&gt;
Also useful in a one-liner like&lt;br /&gt;
&lt;br /&gt;
 for dev in md{0,1} ; do echo repair &amp;gt; /sys/block/$dev/md/sync_action ; done&lt;br /&gt;
&lt;br /&gt;
Different raids on different drives will do this in parallel. If the drives are shared somehow with partitions or similar, the check or repair will wait for the other to finish before going on.&lt;br /&gt;
&lt;br /&gt;
As for repair vs check, [https://raid.wiki.kernel.org/index.php/RAID_Administration this article] describes it well. I stick to using repair unless it&#039;s something rare where I don&#039;t want to touch the data.&lt;br /&gt;
&lt;br /&gt;
=== Spare pools ===&lt;br /&gt;
In the old itmes, mdadm supported only a dedicated spare per md device, so if working with a large set of drives (20? 40?), where you&#039;d want to setup more raid sets to increase redundancy, you&#039;d dedicate a spare to each of the raid sets. This has changed (some time ago?), so in these modern, heathen days, you can change mdadm.conf, usually placed under /etc/mdadm, and add &#039;spare-group=somegroup&#039; where &#039;somegroup&#039; is a string identifying the spare group. After doing this, run &#039;&#039;&#039;update-initramfs -u&#039;&#039;&#039; and reboot and add a spare to one of the raid sets in the spare group, and md will use that or those spares for all the raidsets in that group.&lt;br /&gt;
&lt;br /&gt;
As some pointed out on #linux-raid @ irc.freenode.net, this feature is very badly documented, but as far as I can see, it works well.&lt;br /&gt;
&lt;br /&gt;
==== Example config ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create two raidsets&lt;br /&gt;
&lt;br /&gt;
mdadm --create /dev/md1 --level=6 --raid-devices=6 /dev/vd[efghij]&lt;br /&gt;
mdadm --create /dev/md2 --level=6 --raid-devices=6 /dev/vd[klmnop]&lt;br /&gt;
&lt;br /&gt;
# get their UUID etc&lt;br /&gt;
&lt;br /&gt;
mdadm --detail --scan&lt;br /&gt;
ARRAY /dev/md/1 metadata=1.2 name=raidtest:1 UUID=1a8cbdcb:f4092350:348b6b80:c054d74c&lt;br /&gt;
ARRAY /dev/md/2 metadata=1.2 name=raidtest:2 UUID=894b1b7c:cb7eba70:917d6033:ea5afd2b&lt;br /&gt;
&lt;br /&gt;
# Put those lines into /etc/mdadm/mdadm.conf and and add the spare-group&lt;br /&gt;
&lt;br /&gt;
ARRAY /dev/md/1 metadata=1.2 name=raidtest:1 spare-group=raidtest UUID=1a8cbdcb:f4092350:348b6b80:c054d74c&lt;br /&gt;
ARRAY /dev/md/2 metadata=1.2 name=raidtest:2 spare-group=raidtest UUID=894b1b7c:cb7eba70:917d6033:ea5afd2b&lt;br /&gt;
&lt;br /&gt;
# update the initramfs and reboot&lt;br /&gt;
&lt;br /&gt;
update-initramfs -u&lt;br /&gt;
reboot&lt;br /&gt;
&lt;br /&gt;
# add a spare drive to one of the raids&lt;br /&gt;
&lt;br /&gt;
mdadm --add /dev/md1 /dev/vdq&lt;br /&gt;
&lt;br /&gt;
# fail a drive on the other raid&lt;br /&gt;
&lt;br /&gt;
mdadm --fail /dev/md2 /dev/vdn&lt;br /&gt;
&lt;br /&gt;
# check /proc/mdstat to see md2 rebuilding with the spare from md1&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Recovery ===&lt;br /&gt;
&lt;br /&gt;
The other day, I came across a problem a user had on #linux-raid@irc.freenode.net. He had an old Qnap NAS that had died and tried plugging the drives in to his Linux machine and got various errors. The two-drive RAID-1 did not come up as it should, &#039;&#039;&#039;dmesg&#039;&#039;&#039; was full of errors from one of the drives (both connected on USB) and so forth.&lt;br /&gt;
&lt;br /&gt;
We went on and started by taking down the machine and just connecting one of the drives. I had him check what was assembled with&lt;br /&gt;
&lt;br /&gt;
 cat /proc/mdstat&lt;br /&gt;
&lt;br /&gt;
That returned /proc/md127 assembled, but LVM didn&#039;t find anything. So running a manual scan&lt;br /&gt;
&lt;br /&gt;
 pvscan --cache /dev/md127&lt;br /&gt;
&lt;br /&gt;
This made linux find the PV, VG and a couple of LVs, but probably because the mdraid was degraded, the LVs were deactivated, according to &#039;&#039;&#039;lvscan&#039;&#039;&#039;. Activating the one with a filesystem manually&lt;br /&gt;
&lt;br /&gt;
 lvchange -a y /dev/&amp;lt;vg&amp;gt;/&amp;lt;lv&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Substitute &amp;lt;vg&amp;gt; and &amp;lt;lv&amp;gt; with the names listed by vgs and lvs.&lt;br /&gt;
&lt;br /&gt;
This worked, and the filesystem on /dev/&amp;lt;vg&amp;gt;/&amp;lt;lv&amp;gt; could be mounted correctly.&lt;br /&gt;
&lt;br /&gt;
== Tuning ==&lt;br /&gt;
&lt;br /&gt;
While trying to compare a 12-disk RAID (8TB disks) to a hwraid, mdraid was slower, so we did a few things to speed things up:&lt;br /&gt;
&lt;br /&gt;
While testing with [https://linux.die.net/man/1/fio fio], monitor /sys/block/md0/md/stripe_cache_active, and see if it&#039;s close to /sys/block/md0/md/stripe_cache_size. If it is, double the size of the latter&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
echo 4096 &amp;gt; /sys/block/md0/md/stripe_cache_size&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Continue until stripe_cache_active stabilises, and then you&#039;ve found the limit you&#039;ll need. You may want to double that for good measure. &lt;br /&gt;
&lt;br /&gt;
(to be continued)&lt;br /&gt;
&lt;br /&gt;
== Links ==&lt;br /&gt;
&lt;br /&gt;
Below are a few links with useful info&lt;br /&gt;
&lt;br /&gt;
* [https://raid.wiki.kernel.org/index.php/Irreversible_mdadm_failure_recovery Irreversible mdadm failure recovery]&lt;br /&gt;
&lt;br /&gt;
= ZFS =&lt;br /&gt;
&lt;br /&gt;
ZFS can do a lot of things most filesystems or volume managers can&#039;t. It checksums all data and metadata and so long that the system uses ECC enabled memory (RAM), it will have complete control over the whole data set, and when (not if) an error occurs, it&#039;ll fix the issue without even throwing a warning. To fix the issue, you&#039;ll obviously need sufficient redundancy (mirrors or RAIDzN). &lt;br /&gt;
&lt;br /&gt;
== ZFS send/receive between machines ==&lt;br /&gt;
&lt;br /&gt;
ZFS has a send/receive mechanism that allows for snapshots to be sent over the wire to a receiving end. This can be a full filesystem, or an incremental change since last send/reveive. In a WAN scenario, you&#039;ll probably want to use VPN for this. On a controlled network, sending in cleartext is also possible. You may as well use ssh, but keep in mind that ssh was never designed to be used as a fullblown vpn solution and is just too slow or the task with large amounts of data. You may, though, use mbuffer, if on a loal LAN.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Allow traffic from the sending IP in whatever firewall interface you&#039;re using (if you&#039;re using a firewall at all, that is)&lt;br /&gt;
ufw allow from x.x.x.x&lt;br /&gt;
# &lt;br /&gt;
# Start the receiver first. This listens on port 9090, has a 1GB buffer,&lt;br /&gt;
    and uses 128kb chunks (same as zfs):&lt;br /&gt;
&lt;br /&gt;
mbuffer -s 128k -m 1G -I 9090 | zfs receive data/filesystem&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To be continued one day… See [https://everycity.co.uk/alasdair/2010/07/using-mbuffer-to-speed-up-slow-zfs-send-zfs-receive/ this] for some more. I&#039;ll get back with details on it.&lt;br /&gt;
&lt;br /&gt;
= General Linux system control =&lt;br /&gt;
&lt;br /&gt;
== Add a new CPU (core) ==&lt;br /&gt;
&lt;br /&gt;
If working with virtual machines, adding a new core can be useful if the VM is slow and the load is multithreaded or multiprocess. To do this, add a new CPU in the hypervisor (be it KVM or VMware or Hyper-V or whatever). Some hypervisors, like VMware, will activate it automatically if open-vm-tools is installed. Please note that open-vm-tools is for VMware only. I don&#039;t know of any such thing for KVM or other hypervisors (although I beleive VirtualBox has its own set of tools, but not as a package). If this doesn&#039;t work, run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
echo 1 &amp;gt; /sys/devices/system/cpu/cpuX/online&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where X is the CPU number you want to add. You can &#039;cat /sys/devices/system/cpu/cpuX/online&#039; to check if it&#039;s online.&lt;br /&gt;
&lt;br /&gt;
= Mount partitions on a disk image =&lt;br /&gt;
&lt;br /&gt;
Sometimes you&#039;ll have a disk image, either from recovering a bad drive after hours (or days or weeks) of ddrescue, and sometimes you just have a disk image from a virtual machine where you want to mount the partitions inside the image. There are three main methods of doing this, which are more or less synonmous, but some easier than the other.&lt;br /&gt;
&lt;br /&gt;
== Basics ==&lt;br /&gt;
&lt;br /&gt;
A disk image is usually like a disk, consisting of either a large filesystem, a PV or a partition table with one or partitions onto which resides a filesystem, a pv, swap or something else. If it&#039;s partitioned, and you want your operating system to mount a filesystem or allow it to see whatever LVM stuff lies on it, you need to isolate the partitions. &lt;br /&gt;
&lt;br /&gt;
== Manual mapping ==&lt;br /&gt;
&lt;br /&gt;
In the oldern days, this was done manually, something like this&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
root@mymachine:~# fdisk -l /dev/vda&lt;br /&gt;
Disk /dev/vda: 25 GiB, 26843545600 bytes, 52428800 sectors&lt;br /&gt;
Units: sectors of 1 * 512 = 512 bytes&lt;br /&gt;
Sector size (logical/physical): 512 bytes / 512 bytes&lt;br /&gt;
I/O size (minimum/optimal): 512 bytes / 512 bytes&lt;br /&gt;
Disklabel type: dos&lt;br /&gt;
Disk identifier: 0xc37b7ea5&lt;br /&gt;
&lt;br /&gt;
Device     Boot    Start      End  Sectors  Size Id Type&lt;br /&gt;
/dev/vda1  *        2048 50333311 50331264   24G 83 Linux&lt;br /&gt;
/dev/vda2       50333312 52426369  2093058 1022M  5 Extended&lt;br /&gt;
/dev/vda5       50333314 52426369  2093056 1022M 82 Linux swap / Solaris&lt;br /&gt;
root@mymachine:~#&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To calculate the start and end of each partition, you just take the start sector and multiply it by the sector size (512 bytes here) and you have the offset in bytes. After this, it&#039;s merely an losetup -o &amp;lt;offset&amp;gt; /dev/loopX &amp;lt;nameofimagefile&amp;gt; and you have the partition mapped to your /dev/loopX (having X being something typically 0-255. After this, just mount it or run pvscan/vgscan/lvscan to probe whatever lvm config is there, and you should be able to mount it like any other filesystem.&lt;br /&gt;
&lt;br /&gt;
== kpartx ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;kpartx&#039;&#039;&#039; does the same as above, more or less, just without so much hassle. Most of it should be automatic and easy to deal with, except it may fail to disconnect the loopback devices sometimes, so you may have to &#039;&#039;&#039;losetup -d&#039;&#039;&#039; them manually. See the manual, &#039;&#039;&#039;kpartx (8)&#039;&#039;&#039;. Please note that &#039;&#039;&#039;partx&#039;&#039;&#039; works similarly and I&#039;d guess the authors of the two tools are arguing a lot of which one&#039;s the best.&lt;br /&gt;
&lt;br /&gt;
== guestmount ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;guestmount&#039;&#039;&#039; is something similar again, but also supports file formats like &#039;&#039;&#039;qcow2&#039;&#039;&#039; and possibly other, proprietary filesystems like &#039;&#039;&#039;vmdk&#039;&#039;&#039; and &#039;&#039;&#039;vdi&#039;&#039;&#039;, but don&#039;t take my word for it - I haven&#039;t tested. Again, see the manual or just read up on the description [http://ask.xmodulo.com/mount-qcow2-disk-image-linux.html?fbclid=IwAR3snTeZvGzp9PLdX11EQhCfOpux6I93CiJ3A2pUomkkRLly9Xo4851mkTY here]. It seems rather trivial.&lt;br /&gt;
&lt;br /&gt;
= Linux on laptops =&lt;br /&gt;
&lt;br /&gt;
== Wifi with HP EliteBook 725/745 on Ubuntu ==&lt;br /&gt;
&lt;br /&gt;
The HP EliteBook 725/745 and similar are equipped with a BCM4352 wifi chip. As with a lot of other stuff from Broadcom, this lacks an open hardware description, so thus no open driver exist. The proper fix, is to replace the NIC with something with an open driver, but again, this isn&#039;t always possible, so a binary driver exists. In ubuntu, run, somehow connect the machine to the internet and run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install bcmwl-kernel-source&lt;br /&gt;
sudo modprobe wl&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you can&#039;t connect the machine to the internet, download the needed packages on another machine and put it on some usb storage. These packages should suffice:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# apt-cache depends bcmwl-kernel-source&lt;br /&gt;
bcmwl-kernel-source&lt;br /&gt;
  Depends: dkms&lt;br /&gt;
  Depends: linux-libc-dev&lt;br /&gt;
  Depends: libc6-dev&lt;br /&gt;
  Conflicts: &amp;lt;bcmwl-modaliases&amp;gt;&lt;br /&gt;
  Replaces: &amp;lt;bcmwl-modaliases&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then install manually with &#039;&#039;&#039;dpkg -i file1.deb file2.deb&#039;&#039;&#039; etc&lt;br /&gt;
&lt;br /&gt;
After this, ip/ifconfig/iwconfig shouldd see the new wifi nic, probably &#039;&#039;&#039;wlan0&#039;&#039;&#039;, but due to a [https://bugs.launchpad.net/ubuntu/+source/broadcom-sta/+bug/1343151 old, ignored bug], you won&#039;t find any wifi networks. This is because the driver from Broadcom apparently does not support interrupt remapping, commonly used on x64 machines. To turn this off, change &#039;&#039;&#039;/etc/default/grub&#039;&#039;&#039; and change the line &#039;&#039;&#039;GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;quiet splash&amp;quot;&#039;&#039;&#039;, adding intremap=off to the end before the quote: &#039;&#039;&#039;GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;quiet splash intremap=off&amp;quot;&#039;&#039;&#039;. Save the file and run &#039;&#039;&#039;sudo update-grub&#039;&#039;&#039; and reboot. After this, wifi should work well.&lt;br /&gt;
&lt;br /&gt;
== Wifi with HP Compaq Presario CQ57 on Ubuntu ==&lt;br /&gt;
&lt;br /&gt;
The HP Compaq Presario CQ57 uses the RT5390 wifi chipset. This has been supported for quite some time now, and I was quite surprised to find it not working on a laptop a friend was having. The driver loaded correctly, but Ubuntu insisted of the laptop being in &#039;&#039;&#039;flight mode&#039;&#039;&#039;. Checking &#039;&#039;&#039;rfkill&#039;&#039;&#039;, it showed me two NICs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# rfkill list all&lt;br /&gt;
0: phy0: Wireless LAN&lt;br /&gt;
	Soft blocked: no&lt;br /&gt;
	Hard blocked: yes&lt;br /&gt;
1: hp-wifi: Wireless LAN&lt;br /&gt;
	Soft blocked: yes&lt;br /&gt;
	Hard blocked: no&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Turning rfkill on and off resulted in nothing much, except some error messages in the kernel log (dmesg)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] ACPI Error: Field [B128] at bit offset/length 128/1024 exceeds size of target Buffer (160 bits) (20170831/dsopcode-235)&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]&lt;br /&gt;
                            Initialized Local Variables for Method [HWCD]:&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Local0: 00000000a34b7928 &amp;lt;Obj&amp;gt;           Integer 0000000000000000&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Local1: 00000000b0aa6865 &amp;lt;Obj&amp;gt;           Buffer(8) 46 41 49 4C 04 00 00 00&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Local5: 00000000a9811efd &amp;lt;Obj&amp;gt;           Integer 0000000000000004&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] Initialized Arguments for Method [HWCD]:  (2 arguments defined for method invocation)&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Arg0:   0000000078957d1b &amp;lt;Obj&amp;gt;           Integer 0000000000000001&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Arg1:   00000000725c9c6e &amp;lt;Obj&amp;gt;           Buffer(20) 53 45 43 55 02 00 00 00&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] ACPI Error: Method parse/execution failed \_SB.WMID.HWCD, AE_AML_BUFFER_LIMIT (20170831/psparse-550)&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] ACPI Error: Method parse/execution failed \_SB.WMID.WMAD, AE_AML_BUFFER_LIMIT (20170831/psparse-550)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After upgrading BIOS and testing different kernels, I was asked to try to unload the &#039;&#039;&#039;hp_wmi&#039;&#039;&#039; driver. I did, and things changed a bit, so I tried blacklisting it, creating the file &#039;&#039;&#039;/etc/modprobe.d/blacklist-hp_wmi.conf&#039;&#039;&#039; with the following content&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Blacklist this - it doesn&#039;t work!&lt;br /&gt;
blacklist hp_wmi&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
I gave the machine a reboot and afte that, the &#039;&#039;&#039;hp-wifi&#039;&#039;&#039; entry was gone in the rfkill output, and things works.&lt;br /&gt;
&lt;br /&gt;
= Raspberry pi =&lt;br /&gt;
&lt;br /&gt;
I couldn&#039;t quite decide if the raspberry pi should be a separate section or part of Linux, but hell, it can run more than Linux, although 99,lots% of people just uses Linux on them. This is a small list of things to know about them; things not on the front page of the manual or perhaps hidden even better.&lt;br /&gt;
&lt;br /&gt;
== Which pi? ==&lt;br /&gt;
&lt;br /&gt;
I just setup three raspberry pi machines and although some are quite different, like v1 to vEverythingelse or the Pi zero versions to the normal ones, not all of us remember how to distinguish between them, and sometimes they&#039;re in a nice 3d printed (or otherwise) chassis or otherwise hidden. So, how to check three different ones:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
root@home-assistant:~ $ cat /proc/device-tree/model ; echo&lt;br /&gt;
Raspberry Pi 2 Model B Rev 1.1&lt;br /&gt;
&lt;br /&gt;
root@green-pi:~ $ cat /proc/device-tree/model ; echo&lt;br /&gt;
Raspberry Pi 3 Model B Rev 1.2&lt;br /&gt;
&lt;br /&gt;
roy@yellow-pi:~ $cat /proc/device-tree/model ; echo&lt;br /&gt;
Raspberry Pi 4 Model B Rev 1.1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
While this works well, for the latter, the pi4, it doesn&#039;t tell how much memory I have. It comes in variants of 1, 2 and 4GB, and this is the latter.&lt;br /&gt;
&lt;br /&gt;
== Monitoring ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;vcgencmd&#039;&#039;&#039; from &#039;&#039;&#039;/opt/vc/bin&#039;&#039;&#039;, but symlinked to &#039;&#039;&#039;/usr/bin&#039;&#039;&#039; so it&#039;s available in path, is useful for fetching hardware info about the pi. For example, measuring the temperature&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
root@yellow-pi:~# vcgencmd measure_temp&lt;br /&gt;
temp=63.0&#039;C&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The command is generally badly documented and parts of it seems outdated for newer hardware. Here&#039;s the output from a Raspberry pi 4 with 4GB RAM&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
roy@yellow-pi:~ $ vcgencmd get_mem arm&lt;br /&gt;
arm=948M&lt;br /&gt;
roy@yellow-pi:~ $ vcgencmd get_mem gpu&lt;br /&gt;
gpu=76M&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= BIOS upgrade from Linux =&lt;br /&gt;
&lt;br /&gt;
Generally, BIOS upgrades have been moved to the BIOS itself these days. This saves a lot of work and quite possibly lives after those who earier rammed their heads through walls, now can upgrade directly from the internet instead of using obscure operating systems best avoided. Sometimes, however, one must use these nevertheless. This is a quick run-through on your options.&lt;br /&gt;
&lt;br /&gt;
== DOS ==&lt;br /&gt;
&lt;br /&gt;
Most non-automatic BIOS upgrades are installed from DOS. Doing a BIOS upgrade this way, is generally non-problematic. Just install a USB thingie with [https://www.freedos.org/ FreeDOS], copy your file(s) onto the thing and boot on it. The commandline is the same as old MS/DOS, except a wee bit more userfriendly, but not a lot.&lt;br /&gt;
&lt;br /&gt;
== Windows ==&lt;br /&gt;
&lt;br /&gt;
Some macahines, like laptops from &#039;&#039;&#039;HP&#039;&#039;&#039;, may have BIOS upgrades that are made to be installed from Windows and won&#039;t run in FreeDOS or MS/DOS, instead throwing an error, saying &#039;&#039;&#039;This program cannot be run in DOS mode&#039;&#039;&#039;. This means you&#039;ll have to boot on a Windows rescue disc and do the job from there. Googling this, tells you it&#039;s quite easy, you just choose &#039;make rescue disc&#039; from Windows, and it&#039;s all good, except if you don&#039;t run Windows, that is. To remedy this problem, do as follows:&lt;br /&gt;
&lt;br /&gt;
=== Download Windows ===&lt;br /&gt;
&lt;br /&gt;
Since you don&#039;t run Windows and possibly don&#039;t have a spouse or friend around with such unhealthy habits either, you need to get it. It&#039;s quite easy - just google &#039;download windows&#039; and it&#039;ll send you to [https://www.microsoft.com/en-us/software-download/windows10ISO somewhere like this].&lt;br /&gt;
&lt;br /&gt;
=== Burn it! ===&lt;br /&gt;
&lt;br /&gt;
Now it&#039;s time to burn the installer on a DVD ROM. You&#039;ll need a double-layered one, since the OS is &amp;gt; 4.7GiB, but I&#039;m sure you have a ton of those lying around. Now, just place your optical medium in your optical drive and burn, baby, burn!&lt;br /&gt;
&lt;br /&gt;
=== Or make a USB thing? ===&lt;br /&gt;
&lt;br /&gt;
Not a lot of machines have optical drives these days, so you may want to use an USB pen drive or something instead. This is easy, just make the USB bootable with the Windows application Microsoft has made for this. Unfortunately, this only runs on Windows, and unlike stuff like Debian, where the &#039;&#039;&#039;iso&#039;&#039;&#039; file can be dd&#039;ed directly onto a USB drive to make it bootable, the Windows &#039;&#039;&#039;iso&#039;&#039;&#039;s don&#039;t come with this luxury. There are lots of methods to make bootable USB things from iso files out there, but the only thing most of them have in common, is that they generally don&#039;t work.&lt;br /&gt;
&lt;br /&gt;
==== WoeUSB ====&lt;br /&gt;
&lt;br /&gt;
After hours of swearing, it&#039;s nice to come across software like [https://github.com/slacka/WoeUSB WoeUSB]. It may not be perfect, it relies on a bunch of GUI stuff you&#039;ll never need and so on, but it &#039;&#039;&#039;&#039;&#039;works&#039;&#039;&#039;&#039;&#039;, and that&#039;s the important part! Just clone the repo and RTFM and it&#039;s all nice. It&#039;s slow, but hell, getting a windows machine and/or an optical drive might be slower.&lt;br /&gt;
&lt;br /&gt;
WoeUSB does nothing fancy, but it &#039;&#039;&#039;does&#039;&#039;&#039; work. It will create a filesystem, FAT32 or NTFS (better use NTFS, FAT32 has its limits). It creates normal filesystems and so on. Just make sure to copy in the BIOS update file, usually an exe file, to run when Windows is up and running.&lt;br /&gt;
&lt;br /&gt;
==== Install BIOS ====&lt;br /&gt;
&lt;br /&gt;
Boot on the Windows USB thing and choose &#039;repair computer&#039; and then &#039;command prompt&#039;. Find the install file, and if you&#039;re lucky, you&#039;ll find it needs a 32bit OS, just like I did. Since the 64bit version doesn&#039;t include 32bit compatibility in the installer, revert to downloading the 32bit version of windows and start over. Pray to your favourite god(s) not to get across such machines again - it might help.&lt;br /&gt;
&lt;br /&gt;
= 3D printer stuff =&lt;br /&gt;
&lt;br /&gt;
Below are a number of not very ordered paragraphs about 3D printer related stuff, mostly based on my experience. Their content may be interesting or perhaps practical knowledge, but then, that depends on the reader.&lt;br /&gt;
&lt;br /&gt;
== 3D printer related introductions on youtube or elsewhere ==&lt;br /&gt;
&lt;br /&gt;
First off, I&#039;d like to mention some youtube videos that are all (or mostly) a nice start if you&#039;re new to 3D printers.&lt;br /&gt;
&lt;br /&gt;
=== [https://www.youtube.com/watch?v=nb-Bzf4nQdE&amp;amp;list=PLDJMid0lOOYnkcFhz6rfQ6Uj8x7meNJJx Thomas Salanderer&#039;s 10-video series on 3D printing basics] ===&lt;br /&gt;
&lt;br /&gt;
Thomas Salanderer is a an experienced 3D printer user/admin/fixer/etc and he has a lot of interesting videos. Some accuse him for being a [Prusa https://www.prusa3d.com/] fanboy, which he quite obviously is, but that doesn&#039;t stop him from making interesting and somewhat neutral videos. The series walks you thought the first steps of how things work and so on and hopefully opens more doors than anything else I&#039;ve seen.&lt;br /&gt;
&lt;br /&gt;
=== [https://www.youtube.com/watch?v=rp3r921DBGI Teaching Tech&#039;s &amp;quot;3D printer tuning reborn&amp;quot;] ===&lt;br /&gt;
&lt;br /&gt;
Teaching Tech is, like Salanderer or even more, good pedagogically and explains a lot. They (or he) do a bunch of testing and describing pros and cons with different things, just like other youtubers in the sme business. The mentioned video shows how to tune a 3D printer after you have first learned the basics, and leans on a webpage made to help you out without too much manual work.&lt;br /&gt;
&lt;br /&gt;
This was a short list, but I guess it&#039;ll grow over time.&lt;br /&gt;
&lt;br /&gt;
== Hydrophilic filament ==&lt;br /&gt;
&lt;br /&gt;
Most popular filament types, including PLA, PETG, PP or PA (Polyamide, normally known as Nylon) and virtualy any filament type named [https://www.matterhackers.com/news/filament-and-water poly-something] (and thus with an acronym of P-something) are hydrophilic (also (somewhat incorrectly) called hydroscopic), meaning so long they&#039;re dryer than the atmosphere around them, they&#039;ll do their best to suck out the atmosphere&#039;s humidity. This is why most filament are shrink-wrapped with a small bag of silica gel in it. If such filament is exposed for normal humid air for some time, it&#039;ll become very hard to use. Most of my experience is with PLA, which can handle a bit (depending on make), but still not a lot. With PLA, if you end up with prints where the filament seems not to stick, it may help with a higher temperature. Otherwise, the filament must be [https://all3dp.com/2/how-to-dry-filament-pla-abs-and-nylon/ baked]. If you don&#039;t want to use your oven, try something like a [https://www.jula.no/catalog/hjem-og-husholdning/kjokkenmaskiner/mattilberedningsapparater/frukt-sopptorker/frukt-sopptorker-001641/#tab02 fruit and mushroom dryer]. Then get a good, sealble plastic box and add something like half a kilogram of [https://www.ebay.com/sch/sis.html?_nkw=1KG+Orange+Replacement+Desiccant+Indicating+Silica+Gel+Beads+for+Drawers%2C+Camera&amp;amp;_id=131938742628&amp;amp;&amp;amp;_trksid=p2057872.m2749.l2658 silica gel] to an old sock, tie it and put it in the your new dry box.&lt;br /&gt;
&lt;br /&gt;
Please note that ABS is hydrophobic, so you won&#039;t have to worry too much there. Also, remember that PA/Nylon is extremely hydrophilic. Even a couple of days in normal air humidity can ruin it completely and will require baking.&lt;br /&gt;
&lt;br /&gt;
== Upgrading the firmware on an Ender 3 ==&lt;br /&gt;
&lt;br /&gt;
This is about upgrading the firmware, and thus also flashing a bootloader to the Creality Ender 3 3D printer. Most of this is well documented on several place, like o [https://www.youtube.com/watch?v=fIl5X2ffdyo the video from Teaching tech] and elsewhere, but I&#039;ll just summarise some issues I had.&lt;br /&gt;
&lt;br /&gt;
=== Using an arduino Nano as a programmer ===&lt;br /&gt;
&lt;br /&gt;
Quick note before you read on. If you have an Ender 3 controller version 1.1.5 or newer (or perhaps even a bit older), a CR-10S or some other more or less modern printers or controllers, they come with a bootloader installed already, so don&#039;t bother flashing one. The one that&#039;s in there already, should work well. So if you have one of these, just skip this and jump to the [[Roy&#039;s_notes#Flashing_the_printer|next section]].&lt;br /&gt;
&lt;br /&gt;
However, the normal CR-10 (without the S), Ender 3 and a few other printers from Creality come without a bootloader, so you&#039;ll need to flash one before upgrading the firmware. Well, strictly speakning, you don&#039;t need one, you can save those 8kB or so for other stuff and use a programmer to write the whole firmware, but then you&#039;ll need to wire up everything every time you want a new firmware, so in my world, you &#039;&#039;&#039;do&#039;&#039;&#039; need the bootloader, since it&#039;s easier.&lt;br /&gt;
&lt;br /&gt;
To install a bootloader, you&#039;ll need a programmer, and I didn&#039;t have one available. Having some el-cheapo china-copies of Arduinos around, I read I could use one and tried so. Although the docs mostly mention the Uno etc, it&#039;s just as simple with the Nano copy.&lt;br /&gt;
&lt;br /&gt;
So, grab an arduino, plug it to your machine with a USB cable, and, using the Arduino IDE, use the ArduinoISP sketch there (found under Examples) to burn the software needed for the arduino to work as a programmer. When this is done, connect a 10µF capacitor between RST and GND to stop it from resetting when used as a programmer. Connect the MOSI, MISO and SCK pins from the ICSP block (that little isolated 6-pin block on top of the ardu). See [https://www.arduino.cc/en/Tutorial/ArduinoISP here] for a pinout. Then find Vcc and GND either on the ICSP block or elsewhere. Some sites say that on some boards you shouldn&#039;t use the pins on the ICSP block for this. I doubt it matters, though. Then connect another jumper wire from pin 10 on the ardu to work as the reset pin outwards to the chip being programmed (that is, on the printer). The ICSP jumper block pin layout is the same on the printer and on the ardu, and probably elsewhere. Sometimes [https://xkcd.com/927/ standardisation] actually works…&lt;br /&gt;
&lt;br /&gt;
See https://cloud.karlsbakk.net/index.php/s/zw48YJjzaf8Rc2F for a pic with the ardu (this wiki is broken atm, will fix it later)&lt;br /&gt;
&lt;br /&gt;
== Flashing the printer ==&lt;br /&gt;
&lt;br /&gt;
When the boot loader is in place, possibly after some wierd errors from during the process, the screen on the 3d printer will go blank and it&#039;ll behave like being bricked. This is ok. Now disconnect the wires and connect the USB cable between computer and printer. If you haven&#039;t installed support for the Sanguino board, that is, the variant of the 1284-chip and surrounding electronics that is the core of the, you need to install it first. In the Arduino IDE, choose the Tools / Boards / Boards manager boot option and search for Sanguino. After this, you should find the Sanguino or Sanguino 1284p in the boards menu. After this, you should be able to communicate with the printer&#039;s controller. Download the [https://www.th3dstudio.com/knowledgebase/th3d-unified-firmware-package/ TH3D unified firmware], making sure it&#039;s the last version. Uncompress the zip and with Finder/Explorer/whateversomething&#039;scalledonlinux, browse to &#039;&#039;&#039;TH3DUF_R2/Firmware/TH3DUF_R2.ino&#039;&#039;&#039; and open it. It should open directly in the Android IDE. Keep in mind that the names TH3DUF_R2 and TH3DUF_R2.ino will vary between versions, but you get the point. Now configure it for your particular needs. You&#039;ll find most of this in the Configuration.h tab (that&#039;s really a file). Most of the other files won&#039;t be necessary unless you&#039;re doing some more advanced stuff, like replacing th controller with something non-standard or similar, but then again, that&#039;s another chapter (or book, even). The video mentioned above describes this well. After flashing the new firmware, you&#039;ll probably get some timeouts and errors, since apparently it resets the printer after giving it the new firmware, but without notifying the flashing software of it doing so. If this happens, calm down and reboot the printer and check its tiny monitor - it should work. If it doesn&#039;t work, and if you flashed the bootload yourself, try to flash it again, and if that doesn&#039;t work, try flashing the programmer again yet another time, just for kicks. Again, if you have a newer controller like the v1.1.5, don&#039;t touch the bootloader, as the one already installed, should work well as it is.&lt;br /&gt;
&lt;br /&gt;
PS: I tried enabling &#039;&#039;&#039;MANUAL_MESH_LEVELING&#039;&#039;&#039;, which in the code says that &#039;&#039;If used with a 1284P board the bootscreen will be disabled to save space&#039;&#039;. This effectively disabled the whole printer, and apparently may be making the firmware image a wee bit too large for it to fit the 1284P on the ender. It works well without it, though, and it may be fixed by now, since I tested this back in early 2019.&lt;br /&gt;
&lt;br /&gt;
== And then… ==&lt;br /&gt;
&lt;br /&gt;
With the new firmware in place, the printer should work as before, although with thermal runaway protection to better avoid fires in case the shit hits the fan, and to allow for things like autolevelling. With any luck, [https://www.precisionpiezo.co.uk/ this thing] may be ready for use by the time you read this - it surely looks nice!&lt;br /&gt;
&lt;br /&gt;
= Octoprint/Octopi =&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;This could have been under some other section, but again, I just branch out even though most of it is about sections mentioned elsewhere.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
When setting up a 3d printer for the first time, you usually get an SD card for storage and transfer data to the printer using [https://en.wikipedia.org/wiki/Sneakernet Sneakernet]. Some printers use micro SD cards, while other fullsize SD cards, which imho is better, since they don&#039;t get lost that easily, but otherwise do the same thing. This works, but is somewhat tedious. If you want to control the printer from a PC or phone, there&#039;s a simple trick for that as well - octoprint.&lt;br /&gt;
&lt;br /&gt;
[https://octoprint.org/ Octoprint], written by Gina Häußge, runs on most platforms including linux, windows, BSD*, macos etc. It supports controlling a camera to some extent out of the box and there&#039;s a large number of plugins availablee to do a lot of things you possibly haven&#039;t thought of (and quite often, you&#039;d ever need). The easiest way to install it, is to just grab a Raspberry pi - preferably some of the newer models (will get to that later) and download [https://octoprint.org/download/ octopi] and follow the instructions on that page.&lt;br /&gt;
&lt;br /&gt;
== Performance issues ==&lt;br /&gt;
&lt;br /&gt;
Some report (and I have seen it myself) issues with the pi&#039;s performance with regards to both handling the octoprint processes (which should be as close to realtime as possible) and handling other stuff like I/O, networking etc. The point is that at pi3 or older, has all peripherals connected to an internal USB hub. This might be practical, but performance-wise it&#039;s &#039;&#039;&#039;&#039;&#039;not&#039;&#039;&#039;&#039;&#039;. If you in addition connect a webcam to USB, you&#039;re asking for trouble, since USB will be your bottleneck. With a raspberry pi camera, the ones connected to the pi directly with a ribbon cable, this should not use USB, so it&#039;s better. Still, again, for older pi&#039;s, there might be some shortage in therms of cpu or i/o. The octopi runs something like raspbian which is a fork of debian which is a linux distro, so it all boils down to knowing linux.&lt;br /&gt;
&lt;br /&gt;
Your typical octopi will run octoprint, a streamer, usually &#039;&#039;&#039;mjpg-streamer&#039;&#039;&#039;, a simple, lightweight videostreamer that outputs a stream of jpeg-images (about the same format as cinemas use - that is - not MPEG). This may be a bit tough on the cpu and potentially i/o. Add inn a dash of USB overload and you&#039;re may see trouble.&lt;br /&gt;
&lt;br /&gt;
Still - a pi3 should be able to handle the load, but it might help to prioritise corretly. The octoprint process is the important part here, so we could give that full priority both in CPU and I/O and. Unfortunately, it doesn&#039;t seem like the current octopi has been migrated to using systemd for the startup. We&#039;ll deal with this later. To fix this in the old SysV init style file present there, the following patch should work against the file /etc/init.d/octoprint&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;diff&amp;quot;&amp;gt;&lt;br /&gt;
--- octoprint.old	2020-07-20 18:46:10.166651965 +0200&lt;br /&gt;
+++ octoprint	2020-07-20 18:53:21.724803211 +0200&lt;br /&gt;
@@ -22,6 +22,9 @@&lt;br /&gt;
 PIDFILE=/var/run/$NAME.pid&lt;br /&gt;
 PKGNAME=octoprint&lt;br /&gt;
 SCRIPTNAME=/etc/init.d/$PKGNAME&lt;br /&gt;
+NICELEVEL=-19                        # Top CPU priority&lt;br /&gt;
+IONICE_CLASS=1                       # Realtime I/O class&lt;br /&gt;
+IONICE_PRIORITY=0                    # Realtime I/O priority (probably not needed with class=realtime)&lt;br /&gt;
&lt;br /&gt;
 # Read configuration variable file if it is present&lt;br /&gt;
 [ -r /etc/default/$PKGNAME ] &amp;amp;&amp;amp; . /etc/default/$PKGNAME&lt;br /&gt;
@@ -70,10 +73,11 @@&lt;br /&gt;
&lt;br /&gt;
    is_alive $PIDFILE&lt;br /&gt;
    RETVAL=&amp;quot;$?&amp;quot;&lt;br /&gt;
-&lt;br /&gt;
    if [ $RETVAL != 0 ]; then&lt;br /&gt;
        start-stop-daemon --start --background --quiet --pidfile $PIDFILE --make-pidfile \&lt;br /&gt;
-       --exec $DAEMON --chuid $OCTOPRINT_USER --user $OCTOPRINT_USER --umask $UMASK -- serve $DAEMON_ARGS&lt;br /&gt;
+       --exec $DAEMON --chuid $OCTOPRINT_USER --user $OCTOPRINT_USER --umask $UMASK \&lt;br /&gt;
+       --nicelevel $NICELEVEL --ioched $IONICE_CLASS:$IONICE_PRIORITY \&lt;br /&gt;
+       --serve $DAEMON_ARGS&lt;br /&gt;
        RETVAL=&amp;quot;$?&amp;quot;&lt;br /&gt;
    fi&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This ismply upgrades the process to be allowed to use most of the resources on the pi, regardless of what other processes are whining about.&lt;br /&gt;
&lt;br /&gt;
PS: Code not tested - I don&#039;t have a pi right here. Will test later, but I&#039;m pretty sure it&#039;ll work. After all, it&#039;s just a few new arguments to start-stop-daemon&lt;br /&gt;
&lt;br /&gt;
roy&lt;/div&gt;</summary>
		<author><name>Roy</name></author>
	</entry>
	<entry>
		<id>https://wiki.malinux.no/index.php?title=Roy%27s_notes&amp;diff=169</id>
		<title>Roy&#039;s notes</title>
		<link rel="alternate" type="text/html" href="https://wiki.malinux.no/index.php?title=Roy%27s_notes&amp;diff=169"/>
		<updated>2020-08-06T14:46:55Z</updated>

		<summary type="html">&lt;p&gt;Roy: /* Create LVM cache */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= LVM, md and friends =&lt;br /&gt;
&lt;br /&gt;
== Linux&#039; Logical Volume Manager (LVM) ==&lt;br /&gt;
&lt;br /&gt;
=== LVM in general ===&lt;br /&gt;
&lt;br /&gt;
LVM is designed to be an abstraction layer on top of physical drives or RAID, typically [https://raid.wiki.kernel.org/index.php/RAID_setup mdraid] or [https://help.ubuntu.com/community/FakeRaidHowto fakeraid]. Keep in mind that fakeraid should be avoided unless you really need it, like in conjunction with dual-booting linux and windows on fakeraid. LVM broadly consists of three elements, the &amp;quot;physical&amp;quot; devices (PV), the volume group (VG) and the logical volume (LV). There can be multiple PVs, VGs and LVs, depending on requirement. More about this below. All commands are given as examples, and all of them can be fine-tuned using extra flags in need of so. In my experience, the defaults work well for most usecases.&lt;br /&gt;
&lt;br /&gt;
I&#039;m mentioning filesystem below too. Where I write ext4, the samme applies to ext2 and ext3.&lt;br /&gt;
&lt;br /&gt;
==== Create a PV ====&lt;br /&gt;
&lt;br /&gt;
A PV is the &amp;quot;physical&amp;quot; parts. This does not need to be a physical disk, but can also be another RAID, be it an mdraid, fakeraid, hardware raid, a virtual disk on a SAN or otherwisee or a partition on one of those. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#  These add three PVs, one on a drive (or hardware raid) and another two on mdraids.&lt;br /&gt;
pvcreate /dev/sdb&lt;br /&gt;
pvcreate /dev/md1 /dev/md2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For more information about pvcreate, see [https://linux.die.net/man/8/pvcreate the manual].&lt;br /&gt;
&lt;br /&gt;
==== Create a VG ====&lt;br /&gt;
&lt;br /&gt;
The volume group consists of one or more PVs grouped together on which LVs can be placed. If several PVs are grouped in a VG, it&#039;s generally a good idea to make sure these PVs have some sort of redundancy, as in mdraid/fakeraid or hwraid. Otherwise it will be like using a [https://en.wikipedia.org/wiki/RAID RAID-0] with a single point of failure on each of the independant drives. LVM has [https://unix.stackexchange.com/questions/150644/raiding-with-lvm-vs-mdraid-pros-and-cons  RAID code in it] as well, so you can use that. I haven&#039;t done so myself, as I generally stick to mraid. The reason is mdraid is, in my opinion older and more stable and has more users (meaning bugs are reported and fixed faster whenever they are found). That said, I beleive the actual RAID code used in LVM RAID are the same function calls as for mdraid, so it may not be much of a difference. I still stick with mdraid. To create a VG, run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create volume group my_vg&lt;br /&gt;
vgcreate my_vg /dev/md1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that if vgcreate is run with a PV (as /dev/md1 above) that is not defined as a PV (like above), this is done implicitly, so if you don&#039;t need any special flags to pvcreate, you can simply skip it and let vgcreate do that for you.&lt;br /&gt;
&lt;br /&gt;
==== Create an LV ====&lt;br /&gt;
&lt;br /&gt;
LVs can be compared to partitions, somehow, since they are bounderies of a fraction or all of that of a VG. The difference between them and a partition, however, is that they can be grown or shrunk easily and also moved around between PVs without downtime. This flexibility makes them superiour to partitions as your system can be changed without users noticing it. By default, an LV is alloated &amp;quot;thickly&amp;quot;, meaning all the data given to it, is allocated from the VG and thus the PV. The following makes a 100GB LV named &amp;quot;thicklv&amp;quot;. When making an LV, I usually allocate what&#039;s needed plus some more, but not everything, just to make sure it&#039;s space available for growth on any of the LVs on the VG, or new LVs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a thick provisioned LV named thicklv on the VG my_vg&lt;br /&gt;
lvcreate -n thicklv -L 100G my_vg&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After the LV is created, a filesystem can be placed on it unless it is meant to be used directly. The application for direct use include swap space, VM storage and certain database systems. Most of these will, however, work on filesystems too, although my testing has shown that on swap space, there is a significant performance gain for using dedicated storage without a filesystem. As for filesystems, most Linux users use either ext4 or xfs. Personally, I generally use XFS these days. See my notes below on filesystem choice.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a filesystem on the LV - this could have been mkfs -t ext4 or whatever filesystem you choose&lt;br /&gt;
mkfs -t xfs /dev/my_vg/thicklv&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then just edit /etc/fstab with correct data and run mount -a, and you should be all set.&lt;br /&gt;
&lt;br /&gt;
==== Create LVM cache ====&lt;br /&gt;
LVMcache is LVM&#039;s solution to caching a slowish filesystem on spinning rust with the help of much faster SSDs. For this to work, use a separate SSD or a mirror or two (just in case) an add the new disk/md dev to the same VG. In this case, we use a small mirror, md1. LVM is not able to cache to a disk or partition outside the volume group.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
vgextend data /dev/md1&lt;br /&gt;
  Physical volume &amp;quot;/dev/md1&amp;quot; successfully created.&lt;br /&gt;
  Volume group &amp;quot;data&amp;quot; successfully extended&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Thn create two LVs, one for the data (contents of files) and one for the metadata (filenames, directories, attributes etc). Typically, the metadata part won&#039;t need to be very large. 100M should usually do unless you have ekstremely many small files. I guess there are ways to calculate it, but again, 1GB should do for everyone (or was that 640k?). As for the data cache, I chose to use 40G here for a 15TB RAID. It will only cache what actively use anyway, so no need for overkill.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
lvcreate -L 1G -n _cache_meta data /dev/md1&lt;br /&gt;
lvcreate -l 100G -n _cache data /dev/md1&lt;br /&gt;
&lt;br /&gt;
# Some would want --cachemode writeback, but seriously, I wouldn&#039;t recommend it. Metadata or data can be easily corrupted in case of failure.&lt;br /&gt;
lvconvert --type cache-pool --cachemode writethrough --poolmetadata data/_cache_meta data/_cache&lt;br /&gt;
lvconvert --type cache --cachepool data/_cache data/data&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
That should be it. If you benchmarked the disk before this, you should try again and you&#039;ll probably get a nice surprise. If not, well, see below how to turn this off again :)&lt;br /&gt;
&lt;br /&gt;
==== Disabling LVM cache ====&lt;br /&gt;
&lt;br /&gt;
If you for some reason want to disable caching, this will do it cleanly and remove the LVs earlier created for caching the main device.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
lvconvert --uncache data/data&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Growing devices ====&lt;br /&gt;
&lt;br /&gt;
LVM objects can be grown and shrunk. If a PV resides on a RAID where a new drive has been added or otherwise grown, or on a partition or virtual disk that has been extended, the PV must be updated to reflect these changes. The following command will grow the PV to the maximum available on the underlying storage. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Resize the PV /dev/md (not the RAID, only the PV on the RAID) to its full size&lt;br /&gt;
pvresize /dev/md1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If a new PV is added, the VG can be grown to add the space on that in addition to what&#039;s there already. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Extend my_vg to include md2 and its space&lt;br /&gt;
vgextend my_vg /dev/md2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
With more space available in the VG, the LV can now be extended. Let&#039;s add another 50GB to it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Extend thicklv - add 50GB. If you know you won&#039;t need the space anywhere else, you may want to&lt;br /&gt;
# lvresize -l+100%FREE instead. Keep in mind the difference between -l (extents) and -L (bytes)&lt;br /&gt;
lvresize -L +50G my_vg/thicklv&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Growing filesystems ====&lt;br /&gt;
After the LV has grown, run &#039;&#039;xfs_growfs&#039;&#039; (xfs) or &#039;&#039;resize2fs&#039;&#039; (ext4) to make use of the new data. To grow the filesystem to all available space on ext4, run the below command.  To partly grow the filesystem or to shrink it or otherwise, please see the manuals.&lt;br /&gt;
&lt;br /&gt;
The filesystem can be mounted when this is run. If you for some reason get an &#039;&#039;&#039;access denied&#039;&#039;&#039; error when running this as root or with sudo, it&#039;s likely caused by a filesystem error. To fix this, unmount the filesystem first and run &#039;&#039;&#039;fsck -f /dev/my_vg/thicklv&#039;&#039;&#039; and remount it before retrying to extend it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
resize2fs /dev/my_vg/thicklv&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Similarly, with XFS, but note that xfs_growfs doesn&#039;t take the device name, but the filesystem&#039;s mount point. In the case of XFS, also note that the filesystem &#039;&#039;&#039;&#039;&#039;must&#039;&#039;&#039;&#039;&#039; be mounted to be grown. This, in contrast to how it was in the old days when filesystems had to be unmounted to be grown.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
xfs_growfs /my_mountpoint&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Rename system VG ====&lt;br /&gt;
&lt;br /&gt;
Some distros create VG names like those-from-a-sysadmin-with-a-well-developed-paranoia-not-to-hit-a-duplicate. Debian, for instance, uses names like &amp;quot;my-full-hostname-vg&amp;quot;. Personally, I don&#039;t like these, since if I were to move a disk or vdisk around to somewhere else, I&#039;d make sure not to add a disk named &#039;sys&#039; to an existing system. If you do, most distros will refuse to use the VGs with duplicate names, resulting in the OS not booting until either one is specified by its UUID or just one removed. As I&#039;m aware of this, I stick to the super-risky thing of all system VGs named &#039;sys&#039; and so on.&lt;br /&gt;
&lt;br /&gt;
If you do this, keep in mind that it may blow up your computer and take your girl- or boyfriend with it or even make either of them pregnant, allowing Trump to rule your life and generally make things suck. You&#039;re on your own!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Rename the VG&lt;br /&gt;
vgrename my-full-hostname-vg sys&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, in /boot/grub/grub.cfg, change the old lv path from something like &#039;/dev/mapper/debian--stretch--machine--vg-root&#039; to your new and fancy &#039;/dev/sys/root. Likewise, in /etc/fstab, change occurences of &#039;/dev/mapper/debian--stretch--machine--vg-&#039; (or similar) with &#039;/dev/sys/&#039;. Here, this was like this - the old ones commented out.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;fstab&amp;quot;&amp;gt;&lt;br /&gt;
#/dev/mapper/debian--stretch--box--vg-root      /               ext4            errors=remount-ro,discard       0       1&lt;br /&gt;
/dev/sys/root                                   /               ext4            errors=remount-ro,discard       0       1&lt;br /&gt;
# /boot was on /dev/vda1 during installation&lt;br /&gt;
UUID=myverylonguuidwithatonofgoodinfoinit       /boot           ext2            defaults                        0       2&lt;br /&gt;
#/dev/mapper/debian--stretch--box--vg-swap_1    none            swap            sw                              0       0&lt;br /&gt;
/dev/sys/swap_1                                 none            swap            sw                              0       0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Update /etc/initramfs-tools/conf.d/resume with similar data for swap.&lt;br /&gt;
&lt;br /&gt;
You might want to run &#039;update-initramfs -u -k all&#039; after this, but I&#039;m not sure if it&#039;s needed.&lt;br /&gt;
&lt;br /&gt;
Now, pray to the nearest god(s) and give it a reboot and it should (probably) work.&lt;br /&gt;
&lt;br /&gt;
After reboot, run &#039;&#039;&#039;swapoff -a&#039;&#039;&#039;, then &#039;&#039;&#039;mkswap /dev/sys/swap_1&#039;&#039;&#039; (or whatever it&#039;s called on your system) and &#039;&#039;&#039;swapon -a&#039;&#039;&#039; again. You may want to give it another reboot or two for kicks, but it should work well even without that.&lt;br /&gt;
&lt;br /&gt;
=== Migration tools ===&lt;br /&gt;
&lt;br /&gt;
At times, storage regimes change, new storage is added and sometimes it&#039;s not easy to migrate with the current hardware or its support systems. Once I had to migrate a 45TiB fileserver from one storage system to another, preferably without downtime. The server originally had three 15TiB PVs of which two were full and the third half full. I resorted to using [https://linux.die.net/man/8/pvmove pvmove] to just move the data on the PVs in use to a new PV. We started out with creating a new 50TiB PV, sde, and then to pvmove.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Attach /dev/sde to the VG my_vg&lt;br /&gt;
vgextend my_vg /dev/sde&lt;br /&gt;
&lt;br /&gt;
# Move the contents from /dev/sdb over to /dev/sde block by block. If a target is not given in pvmove,&lt;br /&gt;
# the contents of the source (sdb here) will be put somewhere else in the pool.&lt;br /&gt;
pvmove /dev/sdb /dev/sde&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This took a while (as in a week or so) - the pvmove command uses old code and logic (or at least did that when I migrated this in November 2016), but it affected performance on the server very little, so users didn&#039;t notice. After the first PV was migrated, I continued with the other two, one after the other, and after a month or so, it was migrated. We used this on a number of large fileservers, and it worked flawlessly. Before doing the production servers I also tried interrupting pvmove in various ways, including hard resets, and it just kept on after the reboot.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;NOTE:&#039;&#039;&#039;&#039;&#039; &#039;&#039;Even though it worked well for us, &#039;&#039;&#039;always&#039;&#039;&#039; keep a good backup before doing this. Things may go wrong, and without a good backup, you may be looking for a hard-to-find new job the next morning&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
==== mdadm workarounds ====&lt;br /&gt;
&lt;br /&gt;
===== Migrate from a mirror (raid-1) to raid-10 =====&lt;br /&gt;
&lt;br /&gt;
Create a mirror&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sdb /dev/sdc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
LVM (pv/vg/lv) on md0 (see above), put a filesystem on the lv and fill it with some data.&lt;br /&gt;
&lt;br /&gt;
Now, some months later, you want to change this to raid-10 to allow for the same amount of redundancy, but to allow more disks into the system.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mdadm --grow /dev/md0 --level=10&lt;br /&gt;
mdadm: Impossibly level change request for RAID1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So - no - doesn&#039;t work. But - we&#039;re on &lt;br /&gt;
&lt;br /&gt;
Since we&#039;re on lvm already, this&#039;ll be easy. If you&#039;re using filesystems directly on partitions, you can do this the same way, but without the pvmove part, using rsync or whateever you like instead. I&#039;d recommend using lvm for for the new raid, which should be rather obvious from this article. Now plug in a new drive and create a new raid10 on that one. If you two new drives, install both. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# change &amp;quot;missing&amp;quot; to the other device name if you installed two new drives&lt;br /&gt;
mdadm --create /dev/md1 --level=10 --raid-devices=2 /dev/vdd missing&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, as described above, just vgextend the vg, adding the new raid and run pvmove to move the data from the old pv (residing on the old raid1) to the new pv (on raid10). Afte rpvmove is finished (which may take awile, see above), just&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
vgreduce raidtest /dev/md0&lt;br /&gt;
pvremove /dev/md0&lt;br /&gt;
mdadm --stop /dev/md0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
…and your disk is free to be added to the new array. If the new raid is running in degraded mode (if you created it with just one drive), better don&#039;t wait too long, since you don&#039;t have redundancy. Just mdadm --add the devs.&lt;br /&gt;
&lt;br /&gt;
If you now have /dev/mdstat telling you your raid10 is active and have three drives, of which one is a spare, it should look something like this&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5] [raid4] [raid10]&lt;br /&gt;
md1 : active raid10 vdc[3](S) vdb[2] vdd[0]&lt;br /&gt;
      8380416 blocks super 1.2 2 near-copies [2/2] [UU]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Just mdadm --grow --raid-devices=3 /dev/md1&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;RAID section is not complete. I&#039;ll write more on migraing from raid10 to raid6 later. It&#039;s not straight forward, but easier than this one :)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== Thin provisioned LVs ===&lt;br /&gt;
&lt;br /&gt;
Thin provisioning on LVM is a method used for not allocating all the space given to an LV. For instance, if you have a 1TB VG and want to give an LV 500GB, although it currently only uses a fraction of that, a thin lv can be a good alternative. This will allow for adding a limit to how much it can use, but also to let it grow dynamically without manual work by the sysadmin. Thin provisioning adds another layer of abstaction by creating a special LV as a &#039;&#039;thin pool&#039;&#039; from which data is allocated to the &#039;&#039;thin volume(s)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== Create a thin pool ====&lt;br /&gt;
&lt;br /&gt;
Allocate 1TB to the thin pool to be used for thinly provisioned LVs. Keep in mind that the space allocated to the thin pool is in fact thick provisioned. Only the volumes put on &#039;&#039;thinpool&#039;&#039; are thin provisioned. This will create two hidden LVs, one for data and one for metadata. Normally the defaults will do, but check the manual if the data doesn&#039;t match the usual patterns (such as billions of files, resulting in huge amounts of metadata). I &#039;&#039;beleive&#039;&#039; the metadata part should be resizable at a later time if needed, but I have not tested it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a pool for thin LVs. Keep in mind that the pool itself is not thin provisioned, only the volumes residing on it&lt;br /&gt;
lvcreate --size 1T --type thin-pool --thinpool thinpool my_vg&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Create a thin volume ====&lt;br /&gt;
&lt;br /&gt;
You have the thinpool, now put a thin volume on it. It will allocate some space for metadata, but probably not much (a few megs, perhaps).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Now, create a volume with a virtual (-V) size of half a terabyte named thin_pool, but using the thinpool (-T) named thin_pool for storage&lt;br /&gt;
lvcreate -V 500G -T my_vg/thin_pool --name thinvol&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The new volume&#039;s device name will be /dev/thinvol. Now, create a filesystem on it, add to fstab and mount it. The &#039;&#039;&#039;df&#039;&#039;&#039; command will return available space according to the virtual size (-V), while lvs will show how much data is actually used on each of the thinly provisioned volumes.&lt;br /&gt;
&lt;br /&gt;
== Filesystem dilemmas ==&lt;br /&gt;
&lt;br /&gt;
=== XFS or ext4 or something else ===&lt;br /&gt;
The choice of filesystem varies for your use. Distros such as RHEL/CentOS has moved to XFS by default from v7. Debian/Ubuntu still sticks to ext4, like most other. I&#039;ll discuss my thoughts below on ext4 vs XFS and leave the other filesystems for later.&lt;br /&gt;
&lt;br /&gt;
==== ext4 ====&lt;br /&gt;
ext4 is probably the most used filesystem on linux as of writing. It&#039;s rock stable and has been extended by a lot of extensions since the original ext2. It still retains backward compatibility, being able to mount and fsck ext2 and ext3 with the ext4 driver. However, it doesn&#039;t handle large filesystems very well. If a filesystem is created for &amp;lt;16TiB, it cannot be grown to anything larger than 16TiB. This may have changed lately, though. One other issue is handling errors. If a large filesystem (say 10TiB) is damaged, an fsck may take several hours, leading to long downtime. When I refer to ext4 further in this text, the same applies to ext2 and ext3 unless otherwise specified.&lt;br /&gt;
&lt;br /&gt;
==== XFS ====&lt;br /&gt;
XFS, originally developed by SGI some time in the bronze age, but has been worked on heavily after that. RHEL and Centos version 7 and forward, uses XFS as the default filesystem. It is quick, it scales well, but it lacks at least two things ext4 has. It cannot be shrunk (not that you normally need that, but nice if you have a typo or you need to change things). Also, it doesn&#039;t allow for automatic fsck on bootup. If something is messed up on the filesystem, you&#039;ll have to login as root on the console (not ssh), which might be an issue on some systems. The fsck equivalent, xfs_repair, is a *lot* faster than ext4&#039;s fsck, though.&lt;br /&gt;
&lt;br /&gt;
==== ZFS ====&lt;br /&gt;
ZFS is like a combination of RAID, LVM and a filesystem, supporting full checksumming, auto-healing (given sufficient redundancy), compression, encryption, replication, deduplication (if you&#039;re brave and have a &#039;&#039;ton&#039;&#039; of memory) and a lot more. It&#039;s a separate chapter and needs a lot more talk than paragraph here.&lt;br /&gt;
&lt;br /&gt;
==== btrfs ====&lt;br /&gt;
btrfs, pronounced &amp;quot;butterfs&amp;quot; or &amp;quot;betterfs&amp;quot; or just spelled out, is a filesystem that mimics that of ZFS. It has been around for 10 years or so, but hasn&#039;t yet proven to be really stable. Following the progress of it for those years, I&#039;ve found it to be a nice toy with which to play, but not to be used in production. Again, others may say otherwise, but these are just my words.&lt;br /&gt;
&lt;br /&gt;
== Low level disk handling ==&lt;br /&gt;
&lt;br /&gt;
This section is for low-level handling of disks, regardless of storage system elsewhere. These apply to mdraid, lvmraid and zfs and possibly other solutions, with the exception of individual drives on hwraid (and maybe fakeraid), since there, the drives are hidden from Linux (or whatever OS).&lt;br /&gt;
&lt;br /&gt;
=== S.M.A.R.T. and slow drives ===&lt;br /&gt;
Modern (that is, from about 1990 or later) have S.M.A.R.T. (or just smart, since it&#039;s easier to type) monitoring built in, meaning the disk&#039;s controller is monitoring itself. This is handy and will ideally tell you in advance that a drive is flakey or dying. Modern (2010+) smart monitoring is more or less the same. It can be trusted about 50% of the time. Usually, if smart detects an error, it&#039;s a real error. I don&#039;t think I&#039;ve seen it reporting a false positive, but others may know better. &lt;br /&gt;
&lt;br /&gt;
==== smartmontools ====&lt;br /&gt;
First, install smartmontool and run smartclt -H /dev/yourdisk (/dev/sda or something) to get a health report. Then perhaps run smartctl -a /dev/yourdisk and look for &#039;current pending sectors&#039; This should be zero. Also check the temperature, which normally should be much above 50.&lt;br /&gt;
&lt;br /&gt;
==== single, slow drive ====&lt;br /&gt;
What may happen, is smart not seeing anything and life goes on like before, only slower and less prouductive, without telling anyone. If you stubler over this issue, you&#039;ll probably see it during a large rsync/zfs send/receive or a resync/rebuild/resilver of the raid/zpool. During this, it feels like everything is slow and your RAID has turned into a RAIF (redundant array of inexpensive floppies). To check if you have a single drive messing up it all, check with &#039;&#039;&#039;iostat -x 2&#039;&#039;&#039;, having 2 being the delay between each measurement. Interrupt it with ctrl+x. If there&#039;s a rougue drive there, it should stand out like sdg below&lt;br /&gt;
&lt;br /&gt;
 avg-cpu:  %user   %nice %system %iowait  %steal   %idle&lt;br /&gt;
            0.38    0.00    1.75    0.00    0.00   97.87&lt;br /&gt;
&lt;br /&gt;
 Device            r/s     w/s     rkB/s     wkB/s   rrqm/s   wrqm/s  %rrqm  %wrqm r_await w_await aqu-sz rareq-sz wareq-sz  svctm  %util&lt;br /&gt;
 sda              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdb              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdc              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdd              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sde              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdf              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdg              3.50    0.00   2352.00      0.00     0.00     0.00   0.00   0.00 14306.29    0.00  13.85   672.00     0.00 285.71 100.00&lt;br /&gt;
 sdh              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
&lt;br /&gt;
In ZFS land, you should be able to get similar data with &#039;&#039;&#039;zpool iostat -v &amp;lt;pool&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Now you know the bad drive (sdg), pull it from the raid with &#039;&#039;&#039;mdadm --fail /dev/mdX /dev/sdX&#039;&#039;&#039;. Now test the drive&#039;s performance manually, just simply:&lt;br /&gt;
&lt;br /&gt;
 # hdparm -t /dev/sdg&lt;br /&gt;
 &lt;br /&gt;
 /dev/sdg:&lt;br /&gt;
  Timing buffered disk reads:   2 MB in  5.37 seconds = 381.46 kB/sec&lt;br /&gt;
&lt;br /&gt;
Bingo - nothing you&#039;d want to keep. For a good drive, it should be something like 100-200MB/s&lt;br /&gt;
&lt;br /&gt;
PS: Keep in mind that you have a degraded RAID by now in case you had a spare waiting for things to happen.&lt;br /&gt;
&lt;br /&gt;
Try to replace the cable and/or try the disk on another port/controller. If the result from hdparm persists, it&#039;s probably a bad cable&lt;br /&gt;
&lt;br /&gt;
So, then, just psycially locate the drive, pull it out, take out the discs and magnets and recycle the rest.&lt;br /&gt;
&lt;br /&gt;
=== &amp;quot;Unplug&amp;quot; drive from system ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Find the device unit&#039;s number with something like&lt;br /&gt;
find /sys/bus/scsi/devices/*/block/ -name sdd&lt;br /&gt;
# returning /sys/bus/scsi/devices/3:0:0:0/block/sdd here, &lt;br /&gt;
# meaning 3:0:0:0 is the SCSI device we&#039;re looking for.&lt;br /&gt;
&lt;br /&gt;
# Given this is the correct device, and you want to &#039;unplug&#039; it, do so by&lt;br /&gt;
echo 1 &amp;gt; /sys/bus/scsi/devices/3:0:0:0/delete&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Rescan disk controllers ===&lt;br /&gt;
If a drive is added and for some reason doesn&#039;t get detected, or is removed by the command above, it can be rediscovered with a sysfs command to the scsi host to which it is connected. Since there may be quite a few of these, an easy way is to just scan them all and check the output of &#039;&#039;&#039;dmesg -T&#039;&#039;&#039; after running it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Make a list of controllers and send a rescan message to each of them. It won&#039;t do anything &lt;br /&gt;
# for those where nothing has changed, but it will show new drives where they have been added.&lt;br /&gt;
for host_scan in /sys/class/scsi_host/host*/scan&lt;br /&gt;
do&lt;br /&gt;
  echo &#039;- - -&#039; &amp;gt; $host_scan&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Fail injection with debugfs ===&lt;br /&gt;
[https://lxadm.com/Using_fault_injection https://lxadm.com/Using_fault_injection]&lt;br /&gt;
&lt;br /&gt;
== mdadm stuff ==&lt;br /&gt;
=== Resync ===&lt;br /&gt;
To resync a raid, that is, check, run&lt;br /&gt;
&lt;br /&gt;
 echo check &amp;gt; /sys/block/$dev/md/sync_action&lt;br /&gt;
&lt;br /&gt;
where $dev is something like md0. If you have several raids, something like this should work&lt;br /&gt;
&lt;br /&gt;
 for dev in md{0,1}&lt;br /&gt;
 do&lt;br /&gt;
   echo repair &amp;gt; /sys/block/$dev/md/sync_action&lt;br /&gt;
 done&lt;br /&gt;
&lt;br /&gt;
Also useful in a one-liner like&lt;br /&gt;
&lt;br /&gt;
 for dev in md{0,1} ; do echo repair &amp;gt; /sys/block/$dev/md/sync_action ; done&lt;br /&gt;
&lt;br /&gt;
Different raids on different drives will do this in parallel. If the drives are shared somehow with partitions or similar, the check or repair will wait for the other to finish before going on.&lt;br /&gt;
&lt;br /&gt;
As for repair vs check, [https://raid.wiki.kernel.org/index.php/RAID_Administration this article] describes it well. I stick to using repair unless it&#039;s something rare where I don&#039;t want to touch the data.&lt;br /&gt;
&lt;br /&gt;
=== Spare pools ===&lt;br /&gt;
In the old itmes, mdadm supported only a dedicated spare per md device, so if working with a large set of drives (20? 40?), where you&#039;d want to setup more raid sets to increase redundancy, you&#039;d dedicate a spare to each of the raid sets. This has changed (some time ago?), so in these modern, heathen days, you can change mdadm.conf, usually placed under /etc/mdadm, and add &#039;spare-group=somegroup&#039; where &#039;somegroup&#039; is a string identifying the spare group. After doing this, run &#039;&#039;&#039;update-initramfs -u&#039;&#039;&#039; and reboot and add a spare to one of the raid sets in the spare group, and md will use that or those spares for all the raidsets in that group.&lt;br /&gt;
&lt;br /&gt;
As some pointed out on #linux-raid @ irc.freenode.net, this feature is very badly documented, but as far as I can see, it works well.&lt;br /&gt;
&lt;br /&gt;
==== Example config ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create two raidsets&lt;br /&gt;
&lt;br /&gt;
mdadm --create /dev/md1 --level=6 --raid-devices=6 /dev/vd[efghij]&lt;br /&gt;
mdadm --create /dev/md2 --level=6 --raid-devices=6 /dev/vd[klmnop]&lt;br /&gt;
&lt;br /&gt;
# get their UUID etc&lt;br /&gt;
&lt;br /&gt;
mdadm --detail --scan&lt;br /&gt;
ARRAY /dev/md/1 metadata=1.2 name=raidtest:1 UUID=1a8cbdcb:f4092350:348b6b80:c054d74c&lt;br /&gt;
ARRAY /dev/md/2 metadata=1.2 name=raidtest:2 UUID=894b1b7c:cb7eba70:917d6033:ea5afd2b&lt;br /&gt;
&lt;br /&gt;
# Put those lines into /etc/mdadm/mdadm.conf and and add the spare-group&lt;br /&gt;
&lt;br /&gt;
ARRAY /dev/md/1 metadata=1.2 name=raidtest:1 spare-group=raidtest UUID=1a8cbdcb:f4092350:348b6b80:c054d74c&lt;br /&gt;
ARRAY /dev/md/2 metadata=1.2 name=raidtest:2 spare-group=raidtest UUID=894b1b7c:cb7eba70:917d6033:ea5afd2b&lt;br /&gt;
&lt;br /&gt;
# update the initramfs and reboot&lt;br /&gt;
&lt;br /&gt;
update-initramfs -u&lt;br /&gt;
reboot&lt;br /&gt;
&lt;br /&gt;
# add a spare drive to one of the raids&lt;br /&gt;
&lt;br /&gt;
mdadm --add /dev/md1 /dev/vdq&lt;br /&gt;
&lt;br /&gt;
# fail a drive on the other raid&lt;br /&gt;
&lt;br /&gt;
mdadm --fail /dev/md2 /dev/vdn&lt;br /&gt;
&lt;br /&gt;
# check /proc/mdstat to see md2 rebuilding with the spare from md1&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Recovery ===&lt;br /&gt;
&lt;br /&gt;
The other day, I came across a problem a user had on #linux-raid@irc.freenode.net. He had an old Qnap NAS that had died and tried plugging the drives in to his Linux machine and got various errors. The two-drive RAID-1 did not come up as it should, &#039;&#039;&#039;dmesg&#039;&#039;&#039; was full of errors from one of the drives (both connected on USB) and so forth.&lt;br /&gt;
&lt;br /&gt;
We went on and started by taking down the machine and just connecting one of the drives. I had him check what was assembled with&lt;br /&gt;
&lt;br /&gt;
 cat /proc/mdstat&lt;br /&gt;
&lt;br /&gt;
That returned /proc/md127 assembled, but LVM didn&#039;t find anything. So running a manual scan&lt;br /&gt;
&lt;br /&gt;
 pvscan --cache /dev/md127&lt;br /&gt;
&lt;br /&gt;
This made linux find the PV, VG and a couple of LVs, but probably because the mdraid was degraded, the LVs were deactivated, according to &#039;&#039;&#039;lvscan&#039;&#039;&#039;. Activating the one with a filesystem manually&lt;br /&gt;
&lt;br /&gt;
 lvchange -a y /dev/&amp;lt;vg&amp;gt;/&amp;lt;lv&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Substitute &amp;lt;vg&amp;gt; and &amp;lt;lv&amp;gt; with the names listed by vgs and lvs.&lt;br /&gt;
&lt;br /&gt;
This worked, and the filesystem on /dev/&amp;lt;vg&amp;gt;/&amp;lt;lv&amp;gt; could be mounted correctly.&lt;br /&gt;
&lt;br /&gt;
== Tuning ==&lt;br /&gt;
&lt;br /&gt;
While trying to compare a 12-disk RAID (8TB disks) to a hwraid, mdraid was slower, so we did a few things to speed things up:&lt;br /&gt;
&lt;br /&gt;
While testing with [https://linux.die.net/man/1/fio fio], monitor /sys/block/md0/md/stripe_cache_active, and see if it&#039;s close to /sys/block/md0/md/stripe_cache_size. If it is, double the size of the latter&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
echo 4096 &amp;gt; /sys/block/md0/md/stripe_cache_size&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Continue until stripe_cache_active stabilises, and then you&#039;ve found the limit you&#039;ll need. You may want to double that for good measure. &lt;br /&gt;
&lt;br /&gt;
(to be continued)&lt;br /&gt;
&lt;br /&gt;
== Links ==&lt;br /&gt;
&lt;br /&gt;
Below are a few links with useful info&lt;br /&gt;
&lt;br /&gt;
* [https://raid.wiki.kernel.org/index.php/Irreversible_mdadm_failure_recovery Irreversible mdadm failure recovery]&lt;br /&gt;
&lt;br /&gt;
= ZFS =&lt;br /&gt;
&lt;br /&gt;
ZFS can do a lot of things most filesystems or volume managers can&#039;t. It checksums all data and metadata and so long that the system uses ECC enabled memory (RAM), it will have complete control over the whole data set, and when (not if) an error occurs, it&#039;ll fix the issue without even throwing a warning. To fix the issue, you&#039;ll obviously need sufficient redundancy (mirrors or RAIDzN). &lt;br /&gt;
&lt;br /&gt;
== ZFS send/receive between machines ==&lt;br /&gt;
&lt;br /&gt;
ZFS has a send/receive mechanism that allows for snapshots to be sent over the wire to a receiving end. This can be a full filesystem, or an incremental change since last send/reveive. In a WAN scenario, you&#039;ll probably want to use VPN for this. On a controlled network, sending in cleartext is also possible. You may as well use ssh, but keep in mind that ssh was never designed to be used as a fullblown vpn solution and is just too slow or the task with large amounts of data. You may, though, use mbuffer, if on a loal LAN.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Allow traffic from the sending IP in whatever firewall interface you&#039;re using (if you&#039;re using a firewall at all, that is)&lt;br /&gt;
ufw allow from x.x.x.x&lt;br /&gt;
# &lt;br /&gt;
# Start the receiver first. This listens on port 9090, has a 1GB buffer,&lt;br /&gt;
    and uses 128kb chunks (same as zfs):&lt;br /&gt;
&lt;br /&gt;
mbuffer -s 128k -m 1G -I 9090 | zfs receive data/filesystem&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To be continued one day… See [https://everycity.co.uk/alasdair/2010/07/using-mbuffer-to-speed-up-slow-zfs-send-zfs-receive/ this] for some more. I&#039;ll get back with details on it.&lt;br /&gt;
&lt;br /&gt;
= General Linux system control =&lt;br /&gt;
&lt;br /&gt;
== Add a new CPU (core) ==&lt;br /&gt;
&lt;br /&gt;
If working with virtual machines, adding a new core can be useful if the VM is slow and the load is multithreaded or multiprocess. To do this, add a new CPU in the hypervisor (be it KVM or VMware or Hyper-V or whatever). Some hypervisors, like VMware, will activate it automatically if open-vm-tools is installed. Please note that open-vm-tools is for VMware only. I don&#039;t know of any such thing for KVM or other hypervisors (although I beleive VirtualBox has its own set of tools, but not as a package). If this doesn&#039;t work, run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
echo 1 &amp;gt; /sys/devices/system/cpu/cpuX/online&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where X is the CPU number you want to add. You can &#039;cat /sys/devices/system/cpu/cpuX/online&#039; to check if it&#039;s online.&lt;br /&gt;
&lt;br /&gt;
= Mount partitions on a disk image =&lt;br /&gt;
&lt;br /&gt;
Sometimes you&#039;ll have a disk image, either from recovering a bad drive after hours (or days or weeks) of ddrescue, and sometimes you just have a disk image from a virtual machine where you want to mount the partitions inside the image. There are three main methods of doing this, which are more or less synonmous, but some easier than the other.&lt;br /&gt;
&lt;br /&gt;
== Basics ==&lt;br /&gt;
&lt;br /&gt;
A disk image is usually like a disk, consisting of either a large filesystem, a PV or a partition table with one or partitions onto which resides a filesystem, a pv, swap or something else. If it&#039;s partitioned, and you want your operating system to mount a filesystem or allow it to see whatever LVM stuff lies on it, you need to isolate the partitions. &lt;br /&gt;
&lt;br /&gt;
== Manual mapping ==&lt;br /&gt;
&lt;br /&gt;
In the oldern days, this was done manually, something like this&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
root@mymachine:~# fdisk -l /dev/vda&lt;br /&gt;
Disk /dev/vda: 25 GiB, 26843545600 bytes, 52428800 sectors&lt;br /&gt;
Units: sectors of 1 * 512 = 512 bytes&lt;br /&gt;
Sector size (logical/physical): 512 bytes / 512 bytes&lt;br /&gt;
I/O size (minimum/optimal): 512 bytes / 512 bytes&lt;br /&gt;
Disklabel type: dos&lt;br /&gt;
Disk identifier: 0xc37b7ea5&lt;br /&gt;
&lt;br /&gt;
Device     Boot    Start      End  Sectors  Size Id Type&lt;br /&gt;
/dev/vda1  *        2048 50333311 50331264   24G 83 Linux&lt;br /&gt;
/dev/vda2       50333312 52426369  2093058 1022M  5 Extended&lt;br /&gt;
/dev/vda5       50333314 52426369  2093056 1022M 82 Linux swap / Solaris&lt;br /&gt;
root@mymachine:~#&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To calculate the start and end of each partition, you just take the start sector and multiply it by the sector size (512 bytes here) and you have the offset in bytes. After this, it&#039;s merely an losetup -o &amp;lt;offset&amp;gt; /dev/loopX &amp;lt;nameofimagefile&amp;gt; and you have the partition mapped to your /dev/loopX (having X being something typically 0-255. After this, just mount it or run pvscan/vgscan/lvscan to probe whatever lvm config is there, and you should be able to mount it like any other filesystem.&lt;br /&gt;
&lt;br /&gt;
== kpartx ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;kpartx&#039;&#039;&#039; does the same as above, more or less, just without so much hassle. Most of it should be automatic and easy to deal with, except it may fail to disconnect the loopback devices sometimes, so you may have to &#039;&#039;&#039;losetup -d&#039;&#039;&#039; them manually. See the manual, &#039;&#039;&#039;kpartx (8)&#039;&#039;&#039;. Please note that &#039;&#039;&#039;partx&#039;&#039;&#039; works similarly and I&#039;d guess the authors of the two tools are arguing a lot of which one&#039;s the best.&lt;br /&gt;
&lt;br /&gt;
== guestmount ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;guestmount&#039;&#039;&#039; is something similar again, but also supports file formats like &#039;&#039;&#039;qcow2&#039;&#039;&#039; and possibly other, proprietary filesystems like &#039;&#039;&#039;vmdk&#039;&#039;&#039; and &#039;&#039;&#039;vdi&#039;&#039;&#039;, but don&#039;t take my word for it - I haven&#039;t tested. Again, see the manual or just read up on the description [http://ask.xmodulo.com/mount-qcow2-disk-image-linux.html?fbclid=IwAR3snTeZvGzp9PLdX11EQhCfOpux6I93CiJ3A2pUomkkRLly9Xo4851mkTY here]. It seems rather trivial.&lt;br /&gt;
&lt;br /&gt;
= Linux on laptops =&lt;br /&gt;
&lt;br /&gt;
== Wifi with HP EliteBook 725/745 on Ubuntu ==&lt;br /&gt;
&lt;br /&gt;
The HP EliteBook 725/745 and similar are equipped with a BCM4352 wifi chip. As with a lot of other stuff from Broadcom, this lacks an open hardware description, so thus no open driver exist. The proper fix, is to replace the NIC with something with an open driver, but again, this isn&#039;t always possible, so a binary driver exists. In ubuntu, run, somehow connect the machine to the internet and run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install bcmwl-kernel-source&lt;br /&gt;
sudo modprobe wl&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you can&#039;t connect the machine to the internet, download the needed packages on another machine and put it on some usb storage. These packages should suffice:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# apt-cache depends bcmwl-kernel-source&lt;br /&gt;
bcmwl-kernel-source&lt;br /&gt;
  Depends: dkms&lt;br /&gt;
  Depends: linux-libc-dev&lt;br /&gt;
  Depends: libc6-dev&lt;br /&gt;
  Conflicts: &amp;lt;bcmwl-modaliases&amp;gt;&lt;br /&gt;
  Replaces: &amp;lt;bcmwl-modaliases&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then install manually with &#039;&#039;&#039;dpkg -i file1.deb file2.deb&#039;&#039;&#039; etc&lt;br /&gt;
&lt;br /&gt;
After this, ip/ifconfig/iwconfig shouldd see the new wifi nic, probably &#039;&#039;&#039;wlan0&#039;&#039;&#039;, but due to a [https://bugs.launchpad.net/ubuntu/+source/broadcom-sta/+bug/1343151 old, ignored bug], you won&#039;t find any wifi networks. This is because the driver from Broadcom apparently does not support interrupt remapping, commonly used on x64 machines. To turn this off, change &#039;&#039;&#039;/etc/default/grub&#039;&#039;&#039; and change the line &#039;&#039;&#039;GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;quiet splash&amp;quot;&#039;&#039;&#039;, adding intremap=off to the end before the quote: &#039;&#039;&#039;GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;quiet splash intremap=off&amp;quot;&#039;&#039;&#039;. Save the file and run &#039;&#039;&#039;sudo update-grub&#039;&#039;&#039; and reboot. After this, wifi should work well.&lt;br /&gt;
&lt;br /&gt;
== Wifi with HP Compaq Presario CQ57 on Ubuntu ==&lt;br /&gt;
&lt;br /&gt;
The HP Compaq Presario CQ57 uses the RT5390 wifi chipset. This has been supported for quite some time now, and I was quite surprised to find it not working on a laptop a friend was having. The driver loaded correctly, but Ubuntu insisted of the laptop being in &#039;&#039;&#039;flight mode&#039;&#039;&#039;. Checking &#039;&#039;&#039;rfkill&#039;&#039;&#039;, it showed me two NICs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# rfkill list all&lt;br /&gt;
0: phy0: Wireless LAN&lt;br /&gt;
	Soft blocked: no&lt;br /&gt;
	Hard blocked: yes&lt;br /&gt;
1: hp-wifi: Wireless LAN&lt;br /&gt;
	Soft blocked: yes&lt;br /&gt;
	Hard blocked: no&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Turning rfkill on and off resulted in nothing much, except some error messages in the kernel log (dmesg)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] ACPI Error: Field [B128] at bit offset/length 128/1024 exceeds size of target Buffer (160 bits) (20170831/dsopcode-235)&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]&lt;br /&gt;
                            Initialized Local Variables for Method [HWCD]:&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Local0: 00000000a34b7928 &amp;lt;Obj&amp;gt;           Integer 0000000000000000&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Local1: 00000000b0aa6865 &amp;lt;Obj&amp;gt;           Buffer(8) 46 41 49 4C 04 00 00 00&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Local5: 00000000a9811efd &amp;lt;Obj&amp;gt;           Integer 0000000000000004&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] Initialized Arguments for Method [HWCD]:  (2 arguments defined for method invocation)&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Arg0:   0000000078957d1b &amp;lt;Obj&amp;gt;           Integer 0000000000000001&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Arg1:   00000000725c9c6e &amp;lt;Obj&amp;gt;           Buffer(20) 53 45 43 55 02 00 00 00&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] ACPI Error: Method parse/execution failed \_SB.WMID.HWCD, AE_AML_BUFFER_LIMIT (20170831/psparse-550)&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] ACPI Error: Method parse/execution failed \_SB.WMID.WMAD, AE_AML_BUFFER_LIMIT (20170831/psparse-550)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After upgrading BIOS and testing different kernels, I was asked to try to unload the &#039;&#039;&#039;hp_wmi&#039;&#039;&#039; driver. I did, and things changed a bit, so I tried blacklisting it, creating the file &#039;&#039;&#039;/etc/modprobe.d/blacklist-hp_wmi.conf&#039;&#039;&#039; with the following content&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Blacklist this - it doesn&#039;t work!&lt;br /&gt;
blacklist hp_wmi&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
I gave the machine a reboot and afte that, the &#039;&#039;&#039;hp-wifi&#039;&#039;&#039; entry was gone in the rfkill output, and things works.&lt;br /&gt;
&lt;br /&gt;
= Raspberry pi =&lt;br /&gt;
&lt;br /&gt;
I couldn&#039;t quite decide if the raspberry pi should be a separate section or part of Linux, but hell, it can run more than Linux, although 99,lots% of people just uses Linux on them. This is a small list of things to know about them; things not on the front page of the manual or perhaps hidden even better.&lt;br /&gt;
&lt;br /&gt;
== Which pi? ==&lt;br /&gt;
&lt;br /&gt;
I just setup three raspberry pi machines and although some are quite different, like v1 to vEverythingelse or the Pi zero versions to the normal ones, not all of us remember how to distinguish between them, and sometimes they&#039;re in a nice 3d printed (or otherwise) chassis or otherwise hidden. So, how to check three different ones:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
root@home-assistant:~ $ cat /proc/device-tree/model ; echo&lt;br /&gt;
Raspberry Pi 2 Model B Rev 1.1&lt;br /&gt;
&lt;br /&gt;
root@green-pi:~ $ cat /proc/device-tree/model ; echo&lt;br /&gt;
Raspberry Pi 3 Model B Rev 1.2&lt;br /&gt;
&lt;br /&gt;
roy@yellow-pi:~ $cat /proc/device-tree/model ; echo&lt;br /&gt;
Raspberry Pi 4 Model B Rev 1.1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
While this works well, for the latter, the pi4, it doesn&#039;t tell how much memory I have. It comes in variants of 1, 2 and 4GB, and this is the latter.&lt;br /&gt;
&lt;br /&gt;
== Monitoring ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;vcgencmd&#039;&#039;&#039; from &#039;&#039;&#039;/opt/vc/bin&#039;&#039;&#039;, but symlinked to &#039;&#039;&#039;/usr/bin&#039;&#039;&#039; so it&#039;s available in path, is useful for fetching hardware info about the pi. For example, measuring the temperature&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
root@yellow-pi:~# vcgencmd measure_temp&lt;br /&gt;
temp=63.0&#039;C&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The command is generally badly documented and parts of it seems outdated for newer hardware. Here&#039;s the output from a Raspberry pi 4 with 4GB RAM&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
roy@yellow-pi:~ $ vcgencmd get_mem arm&lt;br /&gt;
arm=948M&lt;br /&gt;
roy@yellow-pi:~ $ vcgencmd get_mem gpu&lt;br /&gt;
gpu=76M&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= BIOS upgrade from Linux =&lt;br /&gt;
&lt;br /&gt;
Generally, BIOS upgrades have been moved to the BIOS itself these days. This saves a lot of work and quite possibly lives after those who earier rammed their heads through walls, now can upgrade directly from the internet instead of using obscure operating systems best avoided. Sometimes, however, one must use these nevertheless. This is a quick run-through on your options.&lt;br /&gt;
&lt;br /&gt;
== DOS ==&lt;br /&gt;
&lt;br /&gt;
Most non-automatic BIOS upgrades are installed from DOS. Doing a BIOS upgrade this way, is generally non-problematic. Just install a USB thingie with [https://www.freedos.org/ FreeDOS], copy your file(s) onto the thing and boot on it. The commandline is the same as old MS/DOS, except a wee bit more userfriendly, but not a lot.&lt;br /&gt;
&lt;br /&gt;
== Windows ==&lt;br /&gt;
&lt;br /&gt;
Some macahines, like laptops from &#039;&#039;&#039;HP&#039;&#039;&#039;, may have BIOS upgrades that are made to be installed from Windows and won&#039;t run in FreeDOS or MS/DOS, instead throwing an error, saying &#039;&#039;&#039;This program cannot be run in DOS mode&#039;&#039;&#039;. This means you&#039;ll have to boot on a Windows rescue disc and do the job from there. Googling this, tells you it&#039;s quite easy, you just choose &#039;make rescue disc&#039; from Windows, and it&#039;s all good, except if you don&#039;t run Windows, that is. To remedy this problem, do as follows:&lt;br /&gt;
&lt;br /&gt;
=== Download Windows ===&lt;br /&gt;
&lt;br /&gt;
Since you don&#039;t run Windows and possibly don&#039;t have a spouse or friend around with such unhealthy habits either, you need to get it. It&#039;s quite easy - just google &#039;download windows&#039; and it&#039;ll send you to [https://www.microsoft.com/en-us/software-download/windows10ISO somewhere like this].&lt;br /&gt;
&lt;br /&gt;
=== Burn it! ===&lt;br /&gt;
&lt;br /&gt;
Now it&#039;s time to burn the installer on a DVD ROM. You&#039;ll need a double-layered one, since the OS is &amp;gt; 4.7GiB, but I&#039;m sure you have a ton of those lying around. Now, just place your optical medium in your optical drive and burn, baby, burn!&lt;br /&gt;
&lt;br /&gt;
=== Or make a USB thing? ===&lt;br /&gt;
&lt;br /&gt;
Not a lot of machines have optical drives these days, so you may want to use an USB pen drive or something instead. This is easy, just make the USB bootable with the Windows application Microsoft has made for this. Unfortunately, this only runs on Windows, and unlike stuff like Debian, where the &#039;&#039;&#039;iso&#039;&#039;&#039; file can be dd&#039;ed directly onto a USB drive to make it bootable, the Windows &#039;&#039;&#039;iso&#039;&#039;&#039;s don&#039;t come with this luxury. There are lots of methods to make bootable USB things from iso files out there, but the only thing most of them have in common, is that they generally don&#039;t work.&lt;br /&gt;
&lt;br /&gt;
==== WoeUSB ====&lt;br /&gt;
&lt;br /&gt;
After hours of swearing, it&#039;s nice to come across software like [https://github.com/slacka/WoeUSB WoeUSB]. It may not be perfect, it relies on a bunch of GUI stuff you&#039;ll never need and so on, but it &#039;&#039;&#039;&#039;&#039;works&#039;&#039;&#039;&#039;&#039;, and that&#039;s the important part! Just clone the repo and RTFM and it&#039;s all nice. It&#039;s slow, but hell, getting a windows machine and/or an optical drive might be slower.&lt;br /&gt;
&lt;br /&gt;
WoeUSB does nothing fancy, but it &#039;&#039;&#039;does&#039;&#039;&#039; work. It will create a filesystem, FAT32 or NTFS (better use NTFS, FAT32 has its limits). It creates normal filesystems and so on. Just make sure to copy in the BIOS update file, usually an exe file, to run when Windows is up and running.&lt;br /&gt;
&lt;br /&gt;
==== Install BIOS ====&lt;br /&gt;
&lt;br /&gt;
Boot on the Windows USB thing and choose &#039;repair computer&#039; and then &#039;command prompt&#039;. Find the install file, and if you&#039;re lucky, you&#039;ll find it needs a 32bit OS, just like I did. Since the 64bit version doesn&#039;t include 32bit compatibility in the installer, revert to downloading the 32bit version of windows and start over. Pray to your favourite god(s) not to get across such machines again - it might help.&lt;br /&gt;
&lt;br /&gt;
= 3D printer stuff =&lt;br /&gt;
&lt;br /&gt;
== Hydrophilic filament ==&lt;br /&gt;
&lt;br /&gt;
Most popular filament types, including PLA, PETG, PP or PA (Polyamide, normally known as Nylon) and virtualy any filament type named [https://www.matterhackers.com/news/filament-and-water poly-something] (and thus with an acronym of P-something) are hydrophilic (also (somewhat incorrectly) called hydroscopic), meaning so long they&#039;re dryer than the atmosphere around them, they&#039;ll do their best to suck out the atmosphere&#039;s humidity. This is why most filament are shrink-wrapped with a small bag of silica gel in it. If such filament is exposed for normal humid air for some time, it&#039;ll become very hard to use. Most of my experience is with PLA, which can handle a bit (depending on make), but still not a lot. With PLA, if you end up with prints where the filament seems not to stick, it may help with a higher temperature. Otherwise, the filament must be [https://all3dp.com/2/how-to-dry-filament-pla-abs-and-nylon/ baked]. If you don&#039;t want to use your oven, try something like a [https://www.jula.no/catalog/hjem-og-husholdning/kjokkenmaskiner/mattilberedningsapparater/frukt-sopptorker/frukt-sopptorker-001641/#tab02 fruit and mushroom dryer]. Then get a good, sealble plastic box and add something like half a kilogram of [https://www.ebay.com/sch/sis.html?_nkw=1KG+Orange+Replacement+Desiccant+Indicating+Silica+Gel+Beads+for+Drawers%2C+Camera&amp;amp;_id=131938742628&amp;amp;&amp;amp;_trksid=p2057872.m2749.l2658 silica gel] to an old sock, tie it and put it in the your new dry box.&lt;br /&gt;
&lt;br /&gt;
Please note that ABS is hydrophobic, so you won&#039;t have to worry too much there. Also, remember that PA/Nylon is extremely hydrophilic. Even a couple of days in normal air humidity can ruin it completely and will require baking.&lt;br /&gt;
&lt;br /&gt;
== Upgrading the firmware on an Ender 3 ==&lt;br /&gt;
&lt;br /&gt;
This is about upgrading the firmware, and thus also flashing a bootloader to the Creality Ender 3 3D printer. Most of this is well documented on several place, like o [https://www.youtube.com/watch?v=fIl5X2ffdyo the video from Teaching tech] and elsewhere, but I&#039;ll just summarise some issues I had.&lt;br /&gt;
&lt;br /&gt;
=== Using an arduino Nano as a programmer ===&lt;br /&gt;
&lt;br /&gt;
Quick note before you read on. If you have an Ender 3 controller version 1.1.5 or newer (or perhaps even a bit older), a CR-10S or some other more or less modern printers or controllers, they come with a bootloader installed already, so don&#039;t bother flashing one. The one that&#039;s in there already, should work well. So if you have one of these, just skip this and jump to the [[Roy&#039;s_notes#Flashing_the_printer|next section]].&lt;br /&gt;
&lt;br /&gt;
However, the normal CR-10 (without the S), Ender 3 and a few other printers from Creality come without a bootloader, so you&#039;ll need to flash one before upgrading the firmware. Well, strictly speakning, you don&#039;t need one, you can save those 8kB or so for other stuff and use a programmer to write the whole firmware, but then you&#039;ll need to wire up everything every time you want a new firmware, so in my world, you &#039;&#039;&#039;do&#039;&#039;&#039; need the bootloader, since it&#039;s easier.&lt;br /&gt;
&lt;br /&gt;
To install a bootloader, you&#039;ll need a programmer, and I didn&#039;t have one available. Having some el-cheapo china-copies of Arduinos around, I read I could use one and tried so. Although the docs mostly mention the Uno etc, it&#039;s just as simple with the Nano copy.&lt;br /&gt;
&lt;br /&gt;
So, grab an arduino, plug it to your machine with a USB cable, and, using the Arduino IDE, use the ArduinoISP sketch there (found under Examples) to burn the software needed for the arduino to work as a programmer. When this is done, connect a 10µF capacitor between RST and GND to stop it from resetting when used as a programmer. Connect the MOSI, MISO and SCK pins from the ICSP block (that little isolated 6-pin block on top of the ardu). See [https://www.arduino.cc/en/Tutorial/ArduinoISP here] for a pinout. Then find Vcc and GND either on the ICSP block or elsewhere. Some sites say that on some boards you shouldn&#039;t use the pins on the ICSP block for this. I doubt it matters, though. Then connect another jumper wire from pin 10 on the ardu to work as the reset pin outwards to the chip being programmed (that is, on the printer). The ICSP jumper block pin layout is the same on the printer and on the ardu, and probably elsewhere. Sometimes [https://xkcd.com/927/ standardisation] actually works…&lt;br /&gt;
&lt;br /&gt;
See https://cloud.karlsbakk.net/index.php/s/zw48YJjzaf8Rc2F for a pic with the ardu (this wiki is broken atm, will fix it later)&lt;br /&gt;
&lt;br /&gt;
== Flashing the printer ==&lt;br /&gt;
&lt;br /&gt;
When the boot loader is in place, possibly after some wierd errors from during the process, the screen on the 3d printer will go blank and it&#039;ll behave like being bricked. This is ok. Now disconnect the wires and connect the USB cable between computer and printer. If you haven&#039;t installed support for the Sanguino board, that is, the variant of the 1284-chip and surrounding electronics that is the core of the, you need to install it first. In the Arduino IDE, choose the Tools / Boards / Boards manager boot option and search for Sanguino. After this, you should find the Sanguino or Sanguino 1284p in the boards menu. After this, you should be able to communicate with the printer&#039;s controller. Download the [https://www.th3dstudio.com/knowledgebase/th3d-unified-firmware-package/ TH3D unified firmware], making sure it&#039;s the last version. Uncompress the zip and with Finder/Explorer/whateversomething&#039;scalledonlinux, browse to &#039;&#039;&#039;TH3DUF_R2/Firmware/TH3DUF_R2.ino&#039;&#039;&#039; and open it. It should open directly in the Android IDE. Keep in mind that the names TH3DUF_R2 and TH3DUF_R2.ino will vary between versions, but you get the point. Now configure it for your particular needs. You&#039;ll find most of this in the Configuration.h tab (that&#039;s really a file). Most of the other files won&#039;t be necessary unless you&#039;re doing some more advanced stuff, like replacing th controller with something non-standard or similar, but then again, that&#039;s another chapter (or book, even). The video mentioned above describes this well. After flashing the new firmware, you&#039;ll probably get some timeouts and errors, since apparently it resets the printer after giving it the new firmware, but without notifying the flashing software of it doing so. If this happens, calm down and reboot the printer and check its tiny monitor - it should work. If it doesn&#039;t work, and if you flashed the bootload yourself, try to flash it again, and if that doesn&#039;t work, try flashing the programmer again yet another time, just for kicks. Again, if you have a newer controller like the v1.1.5, don&#039;t touch the bootloader, as the one already installed, should work well as it is.&lt;br /&gt;
&lt;br /&gt;
PS: I tried enabling &#039;&#039;&#039;MANUAL_MESH_LEVELING&#039;&#039;&#039;, which in the code says that &#039;&#039;If used with a 1284P board the bootscreen will be disabled to save space&#039;&#039;. This effectively disabled the whole printer, and apparently may be making the firmware image a wee bit too large for it to fit the 1284P on the ender. It works well without it, though, and it may be fixed by now, since I tested this back in early 2019.&lt;br /&gt;
&lt;br /&gt;
== And then… ==&lt;br /&gt;
&lt;br /&gt;
With the new firmware in place, the printer should work as before, although with thermal runaway protection to better avoid fires in case the shit hits the fan, and to allow for things like autolevelling. With any luck, [https://www.precisionpiezo.co.uk/ this thing] may be ready for use by the time you read this - it surely looks nice!&lt;br /&gt;
&lt;br /&gt;
= Octoprint/Octopi =&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;This could have been under some other section, but again, I just branch out even though most of it is about sections mentioned elsewhere.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
When setting up a 3d printer for the first time, you usually get an SD card for storage and transfer data to the printer using [https://en.wikipedia.org/wiki/Sneakernet Sneakernet]. Some printers use micro SD cards, while other fullsize SD cards, which imho is better, since they don&#039;t get lost that easily, but otherwise do the same thing. This works, but is somewhat tedious. If you want to control the printer from a PC or phone, there&#039;s a simple trick for that as well - octoprint.&lt;br /&gt;
&lt;br /&gt;
[https://octoprint.org/ Octoprint], written by Gina Häußge, runs on most platforms including linux, windows, BSD*, macos etc. It supports controlling a camera to some extent out of the box and there&#039;s a large number of plugins availablee to do a lot of things you possibly haven&#039;t thought of (and quite often, you&#039;d ever need). The easiest way to install it, is to just grab a Raspberry pi - preferably some of the newer models (will get to that later) and download [https://octoprint.org/download/ octopi] and follow the instructions on that page.&lt;br /&gt;
&lt;br /&gt;
== Performance issues ==&lt;br /&gt;
&lt;br /&gt;
Some report (and I have seen it myself) issues with the pi&#039;s performance with regards to both handling the octoprint processes (which should be as close to realtime as possible) and handling other stuff like I/O, networking etc. The point is that at pi3 or older, has all peripherals connected to an internal USB hub. This might be practical, but performance-wise it&#039;s &#039;&#039;&#039;&#039;&#039;not&#039;&#039;&#039;&#039;&#039;. If you in addition connect a webcam to USB, you&#039;re asking for trouble, since USB will be your bottleneck. With a raspberry pi camera, the ones connected to the pi directly with a ribbon cable, this should not use USB, so it&#039;s better. Still, again, for older pi&#039;s, there might be some shortage in therms of cpu or i/o. The octopi runs something like raspbian which is a fork of debian which is a linux distro, so it all boils down to knowing linux.&lt;br /&gt;
&lt;br /&gt;
Your typical octopi will run octoprint, a streamer, usually &#039;&#039;&#039;mjpg-streamer&#039;&#039;&#039;, a simple, lightweight videostreamer that outputs a stream of jpeg-images (about the same format as cinemas use - that is - not MPEG). This may be a bit tough on the cpu and potentially i/o. Add inn a dash of USB overload and you&#039;re may see trouble.&lt;br /&gt;
&lt;br /&gt;
Still - a pi3 should be able to handle the load, but it might help to prioritise corretly. The octoprint process is the important part here, so we could give that full priority both in CPU and I/O and. Unfortunately, it doesn&#039;t seem like the current octopi has been migrated to using systemd for the startup. We&#039;ll deal with this later. To fix this in the old SysV init style file present there, the following patch should work against the file /etc/init.d/octoprint&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;diff&amp;quot;&amp;gt;&lt;br /&gt;
--- octoprint.old	2020-07-20 18:46:10.166651965 +0200&lt;br /&gt;
+++ octoprint	2020-07-20 18:53:21.724803211 +0200&lt;br /&gt;
@@ -22,6 +22,9 @@&lt;br /&gt;
 PIDFILE=/var/run/$NAME.pid&lt;br /&gt;
 PKGNAME=octoprint&lt;br /&gt;
 SCRIPTNAME=/etc/init.d/$PKGNAME&lt;br /&gt;
+NICELEVEL=-19                        # Top CPU priority&lt;br /&gt;
+IONICE_CLASS=1                       # Realtime I/O class&lt;br /&gt;
+IONICE_PRIORITY=0                    # Realtime I/O priority (probably not needed with class=realtime)&lt;br /&gt;
&lt;br /&gt;
 # Read configuration variable file if it is present&lt;br /&gt;
 [ -r /etc/default/$PKGNAME ] &amp;amp;&amp;amp; . /etc/default/$PKGNAME&lt;br /&gt;
@@ -70,10 +73,11 @@&lt;br /&gt;
&lt;br /&gt;
    is_alive $PIDFILE&lt;br /&gt;
    RETVAL=&amp;quot;$?&amp;quot;&lt;br /&gt;
-&lt;br /&gt;
    if [ $RETVAL != 0 ]; then&lt;br /&gt;
        start-stop-daemon --start --background --quiet --pidfile $PIDFILE --make-pidfile \&lt;br /&gt;
-       --exec $DAEMON --chuid $OCTOPRINT_USER --user $OCTOPRINT_USER --umask $UMASK -- serve $DAEMON_ARGS&lt;br /&gt;
+       --exec $DAEMON --chuid $OCTOPRINT_USER --user $OCTOPRINT_USER --umask $UMASK \&lt;br /&gt;
+       --nicelevel $NICELEVEL --ioched $IONICE_CLASS:$IONICE_PRIORITY \&lt;br /&gt;
+       --serve $DAEMON_ARGS&lt;br /&gt;
        RETVAL=&amp;quot;$?&amp;quot;&lt;br /&gt;
    fi&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This ismply upgrades the process to be allowed to use most of the resources on the pi, regardless of what other processes are whining about.&lt;br /&gt;
&lt;br /&gt;
PS: Code not tested - I don&#039;t have a pi right here. Will test later, but I&#039;m pretty sure it&#039;ll work. After all, it&#039;s just a few new arguments to start-stop-daemon&lt;br /&gt;
&lt;br /&gt;
roy&lt;/div&gt;</summary>
		<author><name>Roy</name></author>
	</entry>
	<entry>
		<id>https://wiki.malinux.no/index.php?title=Roy%27s_notes&amp;diff=168</id>
		<title>Roy&#039;s notes</title>
		<link rel="alternate" type="text/html" href="https://wiki.malinux.no/index.php?title=Roy%27s_notes&amp;diff=168"/>
		<updated>2020-07-20T17:03:55Z</updated>

		<summary type="html">&lt;p&gt;Roy: /* Performance issues */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= LVM, md and friends =&lt;br /&gt;
&lt;br /&gt;
== Linux&#039; Logical Volume Manager (LVM) ==&lt;br /&gt;
&lt;br /&gt;
=== LVM in general ===&lt;br /&gt;
&lt;br /&gt;
LVM is designed to be an abstraction layer on top of physical drives or RAID, typically [https://raid.wiki.kernel.org/index.php/RAID_setup mdraid] or [https://help.ubuntu.com/community/FakeRaidHowto fakeraid]. Keep in mind that fakeraid should be avoided unless you really need it, like in conjunction with dual-booting linux and windows on fakeraid. LVM broadly consists of three elements, the &amp;quot;physical&amp;quot; devices (PV), the volume group (VG) and the logical volume (LV). There can be multiple PVs, VGs and LVs, depending on requirement. More about this below. All commands are given as examples, and all of them can be fine-tuned using extra flags in need of so. In my experience, the defaults work well for most usecases.&lt;br /&gt;
&lt;br /&gt;
I&#039;m mentioning filesystem below too. Where I write ext4, the samme applies to ext2 and ext3.&lt;br /&gt;
&lt;br /&gt;
==== Create a PV ====&lt;br /&gt;
&lt;br /&gt;
A PV is the &amp;quot;physical&amp;quot; parts. This does not need to be a physical disk, but can also be another RAID, be it an mdraid, fakeraid, hardware raid, a virtual disk on a SAN or otherwisee or a partition on one of those. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#  These add three PVs, one on a drive (or hardware raid) and another two on mdraids.&lt;br /&gt;
pvcreate /dev/sdb&lt;br /&gt;
pvcreate /dev/md1 /dev/md2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For more information about pvcreate, see [https://linux.die.net/man/8/pvcreate the manual].&lt;br /&gt;
&lt;br /&gt;
==== Create a VG ====&lt;br /&gt;
&lt;br /&gt;
The volume group consists of one or more PVs grouped together on which LVs can be placed. If several PVs are grouped in a VG, it&#039;s generally a good idea to make sure these PVs have some sort of redundancy, as in mdraid/fakeraid or hwraid. Otherwise it will be like using a [https://en.wikipedia.org/wiki/RAID RAID-0] with a single point of failure on each of the independant drives. LVM has [https://unix.stackexchange.com/questions/150644/raiding-with-lvm-vs-mdraid-pros-and-cons  RAID code in it] as well, so you can use that. I haven&#039;t done so myself, as I generally stick to mraid. The reason is mdraid is, in my opinion older and more stable and has more users (meaning bugs are reported and fixed faster whenever they are found). That said, I beleive the actual RAID code used in LVM RAID are the same function calls as for mdraid, so it may not be much of a difference. I still stick with mdraid. To create a VG, run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create volume group my_vg&lt;br /&gt;
vgcreate my_vg /dev/md1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that if vgcreate is run with a PV (as /dev/md1 above) that is not defined as a PV (like above), this is done implicitly, so if you don&#039;t need any special flags to pvcreate, you can simply skip it and let vgcreate do that for you.&lt;br /&gt;
&lt;br /&gt;
==== Create an LV ====&lt;br /&gt;
&lt;br /&gt;
LVs can be compared to partitions, somehow, since they are bounderies of a fraction or all of that of a VG. The difference between them and a partition, however, is that they can be grown or shrunk easily and also moved around between PVs without downtime. This flexibility makes them superiour to partitions as your system can be changed without users noticing it. By default, an LV is alloated &amp;quot;thickly&amp;quot;, meaning all the data given to it, is allocated from the VG and thus the PV. The following makes a 100GB LV named &amp;quot;thicklv&amp;quot;. When making an LV, I usually allocate what&#039;s needed plus some more, but not everything, just to make sure it&#039;s space available for growth on any of the LVs on the VG, or new LVs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a thick provisioned LV named thicklv on the VG my_vg&lt;br /&gt;
lvcreate -n thicklv -L 100G my_vg&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After the LV is created, a filesystem can be placed on it unless it is meant to be used directly. The application for direct use include swap space, VM storage and certain database systems. Most of these will, however, work on filesystems too, although my testing has shown that on swap space, there is a significant performance gain for using dedicated storage without a filesystem. As for filesystems, most Linux users use either ext4 or xfs. Personally, I generally use XFS these days. See my notes below on filesystem choice.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a filesystem on the LV - this could have been mkfs -t ext4 or whatever filesystem you choose&lt;br /&gt;
mkfs -t xfs /dev/my_vg/thicklv&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then just edit /etc/fstab with correct data and run mount -a, and you should be all set.&lt;br /&gt;
&lt;br /&gt;
==== Create LVM cache ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
lvcreate -L 1G -n _cache_meta data /dev/md1&lt;br /&gt;
&lt;br /&gt;
lvcreate -l100%FREE -n _cache data /dev/md1&lt;br /&gt;
&lt;br /&gt;
# Some would want --cachemode writeback, but seriously, I wouldn&#039;t recommend it. Metadata or data can be easily corrupted in case of failure.&lt;br /&gt;
lvconvert --type cache-pool --cachemode writethrough --poolmetadata data/_cache_meta data/_cache&lt;br /&gt;
&lt;br /&gt;
lvconvert --type cache --cachepool data/_cache data/data&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Disabling LVM cache ====&lt;br /&gt;
&lt;br /&gt;
If you for some reason want to disable caching, this will do it cleanly and remove the LVs earlier created for caching the main device.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
lvconvert --uncache data/data&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Growing devices ====&lt;br /&gt;
&lt;br /&gt;
LVM objects can be grown and shrunk. If a PV resides on a RAID where a new drive has been added or otherwise grown, or on a partition or virtual disk that has been extended, the PV must be updated to reflect these changes. The following command will grow the PV to the maximum available on the underlying storage. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Resize the PV /dev/md (not the RAID, only the PV on the RAID) to its full size&lt;br /&gt;
pvresize /dev/md1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If a new PV is added, the VG can be grown to add the space on that in addition to what&#039;s there already. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Extend my_vg to include md2 and its space&lt;br /&gt;
vgextend my_vg /dev/md2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
With more space available in the VG, the LV can now be extended. Let&#039;s add another 50GB to it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Extend thicklv - add 50GB. If you know you won&#039;t need the space anywhere else, you may want to&lt;br /&gt;
# lvresize -l+100%FREE instead. Keep in mind the difference between -l (extents) and -L (bytes)&lt;br /&gt;
lvresize -L +50G my_vg/thicklv&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Growing filesystems ====&lt;br /&gt;
After the LV has grown, run &#039;&#039;xfs_growfs&#039;&#039; (xfs) or &#039;&#039;resize2fs&#039;&#039; (ext4) to make use of the new data. To grow the filesystem to all available space on ext4, run the below command.  To partly grow the filesystem or to shrink it or otherwise, please see the manuals.&lt;br /&gt;
&lt;br /&gt;
The filesystem can be mounted when this is run. If you for some reason get an &#039;&#039;&#039;access denied&#039;&#039;&#039; error when running this as root or with sudo, it&#039;s likely caused by a filesystem error. To fix this, unmount the filesystem first and run &#039;&#039;&#039;fsck -f /dev/my_vg/thicklv&#039;&#039;&#039; and remount it before retrying to extend it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
resize2fs /dev/my_vg/thicklv&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Similarly, with XFS, but note that xfs_growfs doesn&#039;t take the device name, but the filesystem&#039;s mount point. In the case of XFS, also note that the filesystem &#039;&#039;&#039;&#039;&#039;must&#039;&#039;&#039;&#039;&#039; be mounted to be grown. This, in contrast to how it was in the old days when filesystems had to be unmounted to be grown.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
xfs_growfs /my_mountpoint&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Rename system VG ====&lt;br /&gt;
&lt;br /&gt;
Some distros create VG names like those-from-a-sysadmin-with-a-well-developed-paranoia-not-to-hit-a-duplicate. Debian, for instance, uses names like &amp;quot;my-full-hostname-vg&amp;quot;. Personally, I don&#039;t like these, since if I were to move a disk or vdisk around to somewhere else, I&#039;d make sure not to add a disk named &#039;sys&#039; to an existing system. If you do, most distros will refuse to use the VGs with duplicate names, resulting in the OS not booting until either one is specified by its UUID or just one removed. As I&#039;m aware of this, I stick to the super-risky thing of all system VGs named &#039;sys&#039; and so on.&lt;br /&gt;
&lt;br /&gt;
If you do this, keep in mind that it may blow up your computer and take your girl- or boyfriend with it or even make either of them pregnant, allowing Trump to rule your life and generally make things suck. You&#039;re on your own!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Rename the VG&lt;br /&gt;
vgrename my-full-hostname-vg sys&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, in /boot/grub/grub.cfg, change the old lv path from something like &#039;/dev/mapper/debian--stretch--machine--vg-root&#039; to your new and fancy &#039;/dev/sys/root. Likewise, in /etc/fstab, change occurences of &#039;/dev/mapper/debian--stretch--machine--vg-&#039; (or similar) with &#039;/dev/sys/&#039;. Here, this was like this - the old ones commented out.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;fstab&amp;quot;&amp;gt;&lt;br /&gt;
#/dev/mapper/debian--stretch--box--vg-root      /               ext4            errors=remount-ro,discard       0       1&lt;br /&gt;
/dev/sys/root                                   /               ext4            errors=remount-ro,discard       0       1&lt;br /&gt;
# /boot was on /dev/vda1 during installation&lt;br /&gt;
UUID=myverylonguuidwithatonofgoodinfoinit       /boot           ext2            defaults                        0       2&lt;br /&gt;
#/dev/mapper/debian--stretch--box--vg-swap_1    none            swap            sw                              0       0&lt;br /&gt;
/dev/sys/swap_1                                 none            swap            sw                              0       0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Update /etc/initramfs-tools/conf.d/resume with similar data for swap.&lt;br /&gt;
&lt;br /&gt;
You might want to run &#039;update-initramfs -u -k all&#039; after this, but I&#039;m not sure if it&#039;s needed.&lt;br /&gt;
&lt;br /&gt;
Now, pray to the nearest god(s) and give it a reboot and it should (probably) work.&lt;br /&gt;
&lt;br /&gt;
After reboot, run &#039;&#039;&#039;swapoff -a&#039;&#039;&#039;, then &#039;&#039;&#039;mkswap /dev/sys/swap_1&#039;&#039;&#039; (or whatever it&#039;s called on your system) and &#039;&#039;&#039;swapon -a&#039;&#039;&#039; again. You may want to give it another reboot or two for kicks, but it should work well even without that.&lt;br /&gt;
&lt;br /&gt;
=== Migration tools ===&lt;br /&gt;
&lt;br /&gt;
At times, storage regimes change, new storage is added and sometimes it&#039;s not easy to migrate with the current hardware or its support systems. Once I had to migrate a 45TiB fileserver from one storage system to another, preferably without downtime. The server originally had three 15TiB PVs of which two were full and the third half full. I resorted to using [https://linux.die.net/man/8/pvmove pvmove] to just move the data on the PVs in use to a new PV. We started out with creating a new 50TiB PV, sde, and then to pvmove.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Attach /dev/sde to the VG my_vg&lt;br /&gt;
vgextend my_vg /dev/sde&lt;br /&gt;
&lt;br /&gt;
# Move the contents from /dev/sdb over to /dev/sde block by block. If a target is not given in pvmove,&lt;br /&gt;
# the contents of the source (sdb here) will be put somewhere else in the pool.&lt;br /&gt;
pvmove /dev/sdb /dev/sde&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This took a while (as in a week or so) - the pvmove command uses old code and logic (or at least did that when I migrated this in November 2016), but it affected performance on the server very little, so users didn&#039;t notice. After the first PV was migrated, I continued with the other two, one after the other, and after a month or so, it was migrated. We used this on a number of large fileservers, and it worked flawlessly. Before doing the production servers I also tried interrupting pvmove in various ways, including hard resets, and it just kept on after the reboot.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;NOTE:&#039;&#039;&#039;&#039;&#039; &#039;&#039;Even though it worked well for us, &#039;&#039;&#039;always&#039;&#039;&#039; keep a good backup before doing this. Things may go wrong, and without a good backup, you may be looking for a hard-to-find new job the next morning&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
==== mdadm workarounds ====&lt;br /&gt;
&lt;br /&gt;
===== Migrate from a mirror (raid-1) to raid-10 =====&lt;br /&gt;
&lt;br /&gt;
Create a mirror&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sdb /dev/sdc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
LVM (pv/vg/lv) on md0 (see above), put a filesystem on the lv and fill it with some data.&lt;br /&gt;
&lt;br /&gt;
Now, some months later, you want to change this to raid-10 to allow for the same amount of redundancy, but to allow more disks into the system.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mdadm --grow /dev/md0 --level=10&lt;br /&gt;
mdadm: Impossibly level change request for RAID1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So - no - doesn&#039;t work. But - we&#039;re on &lt;br /&gt;
&lt;br /&gt;
Since we&#039;re on lvm already, this&#039;ll be easy. If you&#039;re using filesystems directly on partitions, you can do this the same way, but without the pvmove part, using rsync or whateever you like instead. I&#039;d recommend using lvm for for the new raid, which should be rather obvious from this article. Now plug in a new drive and create a new raid10 on that one. If you two new drives, install both. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# change &amp;quot;missing&amp;quot; to the other device name if you installed two new drives&lt;br /&gt;
mdadm --create /dev/md1 --level=10 --raid-devices=2 /dev/vdd missing&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, as described above, just vgextend the vg, adding the new raid and run pvmove to move the data from the old pv (residing on the old raid1) to the new pv (on raid10). Afte rpvmove is finished (which may take awile, see above), just&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
vgreduce raidtest /dev/md0&lt;br /&gt;
pvremove /dev/md0&lt;br /&gt;
mdadm --stop /dev/md0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
…and your disk is free to be added to the new array. If the new raid is running in degraded mode (if you created it with just one drive), better don&#039;t wait too long, since you don&#039;t have redundancy. Just mdadm --add the devs.&lt;br /&gt;
&lt;br /&gt;
If you now have /dev/mdstat telling you your raid10 is active and have three drives, of which one is a spare, it should look something like this&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5] [raid4] [raid10]&lt;br /&gt;
md1 : active raid10 vdc[3](S) vdb[2] vdd[0]&lt;br /&gt;
      8380416 blocks super 1.2 2 near-copies [2/2] [UU]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Just mdadm --grow --raid-devices=3 /dev/md1&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;RAID section is not complete. I&#039;ll write more on migraing from raid10 to raid6 later. It&#039;s not straight forward, but easier than this one :)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== Thin provisioned LVs ===&lt;br /&gt;
&lt;br /&gt;
Thin provisioning on LVM is a method used for not allocating all the space given to an LV. For instance, if you have a 1TB VG and want to give an LV 500GB, although it currently only uses a fraction of that, a thin lv can be a good alternative. This will allow for adding a limit to how much it can use, but also to let it grow dynamically without manual work by the sysadmin. Thin provisioning adds another layer of abstaction by creating a special LV as a &#039;&#039;thin pool&#039;&#039; from which data is allocated to the &#039;&#039;thin volume(s)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== Create a thin pool ====&lt;br /&gt;
&lt;br /&gt;
Allocate 1TB to the thin pool to be used for thinly provisioned LVs. Keep in mind that the space allocated to the thin pool is in fact thick provisioned. Only the volumes put on &#039;&#039;thinpool&#039;&#039; are thin provisioned. This will create two hidden LVs, one for data and one for metadata. Normally the defaults will do, but check the manual if the data doesn&#039;t match the usual patterns (such as billions of files, resulting in huge amounts of metadata). I &#039;&#039;beleive&#039;&#039; the metadata part should be resizable at a later time if needed, but I have not tested it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a pool for thin LVs. Keep in mind that the pool itself is not thin provisioned, only the volumes residing on it&lt;br /&gt;
lvcreate --size 1T --type thin-pool --thinpool thinpool my_vg&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Create a thin volume ====&lt;br /&gt;
&lt;br /&gt;
You have the thinpool, now put a thin volume on it. It will allocate some space for metadata, but probably not much (a few megs, perhaps).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Now, create a volume with a virtual (-V) size of half a terabyte named thin_pool, but using the thinpool (-T) named thin_pool for storage&lt;br /&gt;
lvcreate -V 500G -T my_vg/thin_pool --name thinvol&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The new volume&#039;s device name will be /dev/thinvol. Now, create a filesystem on it, add to fstab and mount it. The &#039;&#039;&#039;df&#039;&#039;&#039; command will return available space according to the virtual size (-V), while lvs will show how much data is actually used on each of the thinly provisioned volumes.&lt;br /&gt;
&lt;br /&gt;
== Filesystem dilemmas ==&lt;br /&gt;
&lt;br /&gt;
=== XFS or ext4 or something else ===&lt;br /&gt;
The choice of filesystem varies for your use. Distros such as RHEL/CentOS has moved to XFS by default from v7. Debian/Ubuntu still sticks to ext4, like most other. I&#039;ll discuss my thoughts below on ext4 vs XFS and leave the other filesystems for later.&lt;br /&gt;
&lt;br /&gt;
==== ext4 ====&lt;br /&gt;
ext4 is probably the most used filesystem on linux as of writing. It&#039;s rock stable and has been extended by a lot of extensions since the original ext2. It still retains backward compatibility, being able to mount and fsck ext2 and ext3 with the ext4 driver. However, it doesn&#039;t handle large filesystems very well. If a filesystem is created for &amp;lt;16TiB, it cannot be grown to anything larger than 16TiB. This may have changed lately, though. One other issue is handling errors. If a large filesystem (say 10TiB) is damaged, an fsck may take several hours, leading to long downtime. When I refer to ext4 further in this text, the same applies to ext2 and ext3 unless otherwise specified.&lt;br /&gt;
&lt;br /&gt;
==== XFS ====&lt;br /&gt;
XFS, originally developed by SGI some time in the bronze age, but has been worked on heavily after that. RHEL and Centos version 7 and forward, uses XFS as the default filesystem. It is quick, it scales well, but it lacks at least two things ext4 has. It cannot be shrunk (not that you normally need that, but nice if you have a typo or you need to change things). Also, it doesn&#039;t allow for automatic fsck on bootup. If something is messed up on the filesystem, you&#039;ll have to login as root on the console (not ssh), which might be an issue on some systems. The fsck equivalent, xfs_repair, is a *lot* faster than ext4&#039;s fsck, though.&lt;br /&gt;
&lt;br /&gt;
==== ZFS ====&lt;br /&gt;
ZFS is like a combination of RAID, LVM and a filesystem, supporting full checksumming, auto-healing (given sufficient redundancy), compression, encryption, replication, deduplication (if you&#039;re brave and have a &#039;&#039;ton&#039;&#039; of memory) and a lot more. It&#039;s a separate chapter and needs a lot more talk than paragraph here.&lt;br /&gt;
&lt;br /&gt;
==== btrfs ====&lt;br /&gt;
btrfs, pronounced &amp;quot;butterfs&amp;quot; or &amp;quot;betterfs&amp;quot; or just spelled out, is a filesystem that mimics that of ZFS. It has been around for 10 years or so, but hasn&#039;t yet proven to be really stable. Following the progress of it for those years, I&#039;ve found it to be a nice toy with which to play, but not to be used in production. Again, others may say otherwise, but these are just my words.&lt;br /&gt;
&lt;br /&gt;
== Low level disk handling ==&lt;br /&gt;
&lt;br /&gt;
This section is for low-level handling of disks, regardless of storage system elsewhere. These apply to mdraid, lvmraid and zfs and possibly other solutions, with the exception of individual drives on hwraid (and maybe fakeraid), since there, the drives are hidden from Linux (or whatever OS).&lt;br /&gt;
&lt;br /&gt;
=== S.M.A.R.T. and slow drives ===&lt;br /&gt;
Modern (that is, from about 1990 or later) have S.M.A.R.T. (or just smart, since it&#039;s easier to type) monitoring built in, meaning the disk&#039;s controller is monitoring itself. This is handy and will ideally tell you in advance that a drive is flakey or dying. Modern (2010+) smart monitoring is more or less the same. It can be trusted about 50% of the time. Usually, if smart detects an error, it&#039;s a real error. I don&#039;t think I&#039;ve seen it reporting a false positive, but others may know better. &lt;br /&gt;
&lt;br /&gt;
==== smartmontools ====&lt;br /&gt;
First, install smartmontool and run smartclt -H /dev/yourdisk (/dev/sda or something) to get a health report. Then perhaps run smartctl -a /dev/yourdisk and look for &#039;current pending sectors&#039; This should be zero. Also check the temperature, which normally should be much above 50.&lt;br /&gt;
&lt;br /&gt;
==== single, slow drive ====&lt;br /&gt;
What may happen, is smart not seeing anything and life goes on like before, only slower and less prouductive, without telling anyone. If you stubler over this issue, you&#039;ll probably see it during a large rsync/zfs send/receive or a resync/rebuild/resilver of the raid/zpool. During this, it feels like everything is slow and your RAID has turned into a RAIF (redundant array of inexpensive floppies). To check if you have a single drive messing up it all, check with &#039;&#039;&#039;iostat -x 2&#039;&#039;&#039;, having 2 being the delay between each measurement. Interrupt it with ctrl+x. If there&#039;s a rougue drive there, it should stand out like sdg below&lt;br /&gt;
&lt;br /&gt;
 avg-cpu:  %user   %nice %system %iowait  %steal   %idle&lt;br /&gt;
            0.38    0.00    1.75    0.00    0.00   97.87&lt;br /&gt;
&lt;br /&gt;
 Device            r/s     w/s     rkB/s     wkB/s   rrqm/s   wrqm/s  %rrqm  %wrqm r_await w_await aqu-sz rareq-sz wareq-sz  svctm  %util&lt;br /&gt;
 sda              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdb              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdc              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdd              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sde              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdf              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdg              3.50    0.00   2352.00      0.00     0.00     0.00   0.00   0.00 14306.29    0.00  13.85   672.00     0.00 285.71 100.00&lt;br /&gt;
 sdh              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
&lt;br /&gt;
In ZFS land, you should be able to get similar data with &#039;&#039;&#039;zpool iostat -v &amp;lt;pool&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Now you know the bad drive (sdg), pull it from the raid with &#039;&#039;&#039;mdadm --fail /dev/mdX /dev/sdX&#039;&#039;&#039;. Now test the drive&#039;s performance manually, just simply:&lt;br /&gt;
&lt;br /&gt;
 # hdparm -t /dev/sdg&lt;br /&gt;
 &lt;br /&gt;
 /dev/sdg:&lt;br /&gt;
  Timing buffered disk reads:   2 MB in  5.37 seconds = 381.46 kB/sec&lt;br /&gt;
&lt;br /&gt;
Bingo - nothing you&#039;d want to keep. For a good drive, it should be something like 100-200MB/s&lt;br /&gt;
&lt;br /&gt;
PS: Keep in mind that you have a degraded RAID by now in case you had a spare waiting for things to happen.&lt;br /&gt;
&lt;br /&gt;
Try to replace the cable and/or try the disk on another port/controller. If the result from hdparm persists, it&#039;s probably a bad cable&lt;br /&gt;
&lt;br /&gt;
So, then, just psycially locate the drive, pull it out, take out the discs and magnets and recycle the rest.&lt;br /&gt;
&lt;br /&gt;
=== &amp;quot;Unplug&amp;quot; drive from system ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Find the device unit&#039;s number with something like&lt;br /&gt;
find /sys/bus/scsi/devices/*/block/ -name sdd&lt;br /&gt;
# returning /sys/bus/scsi/devices/3:0:0:0/block/sdd here, &lt;br /&gt;
# meaning 3:0:0:0 is the SCSI device we&#039;re looking for.&lt;br /&gt;
&lt;br /&gt;
# Given this is the correct device, and you want to &#039;unplug&#039; it, do so by&lt;br /&gt;
echo 1 &amp;gt; /sys/bus/scsi/devices/3:0:0:0/delete&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Rescan disk controllers ===&lt;br /&gt;
If a drive is added and for some reason doesn&#039;t get detected, or is removed by the command above, it can be rediscovered with a sysfs command to the scsi host to which it is connected. Since there may be quite a few of these, an easy way is to just scan them all and check the output of &#039;&#039;&#039;dmesg -T&#039;&#039;&#039; after running it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Make a list of controllers and send a rescan message to each of them. It won&#039;t do anything &lt;br /&gt;
# for those where nothing has changed, but it will show new drives where they have been added.&lt;br /&gt;
for host_scan in /sys/class/scsi_host/host*/scan&lt;br /&gt;
do&lt;br /&gt;
  echo &#039;- - -&#039; &amp;gt; $host_scan&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Fail injection with debugfs ===&lt;br /&gt;
[https://lxadm.com/Using_fault_injection https://lxadm.com/Using_fault_injection]&lt;br /&gt;
&lt;br /&gt;
== mdadm stuff ==&lt;br /&gt;
=== Resync ===&lt;br /&gt;
To resync a raid, that is, check, run&lt;br /&gt;
&lt;br /&gt;
 echo check &amp;gt; /sys/block/$dev/md/sync_action&lt;br /&gt;
&lt;br /&gt;
where $dev is something like md0. If you have several raids, something like this should work&lt;br /&gt;
&lt;br /&gt;
 for dev in md{0,1}&lt;br /&gt;
 do&lt;br /&gt;
   echo repair &amp;gt; /sys/block/$dev/md/sync_action&lt;br /&gt;
 done&lt;br /&gt;
&lt;br /&gt;
Also useful in a one-liner like&lt;br /&gt;
&lt;br /&gt;
 for dev in md{0,1} ; do echo repair &amp;gt; /sys/block/$dev/md/sync_action ; done&lt;br /&gt;
&lt;br /&gt;
Different raids on different drives will do this in parallel. If the drives are shared somehow with partitions or similar, the check or repair will wait for the other to finish before going on.&lt;br /&gt;
&lt;br /&gt;
As for repair vs check, [https://raid.wiki.kernel.org/index.php/RAID_Administration this article] describes it well. I stick to using repair unless it&#039;s something rare where I don&#039;t want to touch the data.&lt;br /&gt;
&lt;br /&gt;
=== Spare pools ===&lt;br /&gt;
In the old itmes, mdadm supported only a dedicated spare per md device, so if working with a large set of drives (20? 40?), where you&#039;d want to setup more raid sets to increase redundancy, you&#039;d dedicate a spare to each of the raid sets. This has changed (some time ago?), so in these modern, heathen days, you can change mdadm.conf, usually placed under /etc/mdadm, and add &#039;spare-group=somegroup&#039; where &#039;somegroup&#039; is a string identifying the spare group. After doing this, run &#039;&#039;&#039;update-initramfs -u&#039;&#039;&#039; and reboot and add a spare to one of the raid sets in the spare group, and md will use that or those spares for all the raidsets in that group.&lt;br /&gt;
&lt;br /&gt;
As some pointed out on #linux-raid @ irc.freenode.net, this feature is very badly documented, but as far as I can see, it works well.&lt;br /&gt;
&lt;br /&gt;
==== Example config ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create two raidsets&lt;br /&gt;
&lt;br /&gt;
mdadm --create /dev/md1 --level=6 --raid-devices=6 /dev/vd[efghij]&lt;br /&gt;
mdadm --create /dev/md2 --level=6 --raid-devices=6 /dev/vd[klmnop]&lt;br /&gt;
&lt;br /&gt;
# get their UUID etc&lt;br /&gt;
&lt;br /&gt;
mdadm --detail --scan&lt;br /&gt;
ARRAY /dev/md/1 metadata=1.2 name=raidtest:1 UUID=1a8cbdcb:f4092350:348b6b80:c054d74c&lt;br /&gt;
ARRAY /dev/md/2 metadata=1.2 name=raidtest:2 UUID=894b1b7c:cb7eba70:917d6033:ea5afd2b&lt;br /&gt;
&lt;br /&gt;
# Put those lines into /etc/mdadm/mdadm.conf and and add the spare-group&lt;br /&gt;
&lt;br /&gt;
ARRAY /dev/md/1 metadata=1.2 name=raidtest:1 spare-group=raidtest UUID=1a8cbdcb:f4092350:348b6b80:c054d74c&lt;br /&gt;
ARRAY /dev/md/2 metadata=1.2 name=raidtest:2 spare-group=raidtest UUID=894b1b7c:cb7eba70:917d6033:ea5afd2b&lt;br /&gt;
&lt;br /&gt;
# update the initramfs and reboot&lt;br /&gt;
&lt;br /&gt;
update-initramfs -u&lt;br /&gt;
reboot&lt;br /&gt;
&lt;br /&gt;
# add a spare drive to one of the raids&lt;br /&gt;
&lt;br /&gt;
mdadm --add /dev/md1 /dev/vdq&lt;br /&gt;
&lt;br /&gt;
# fail a drive on the other raid&lt;br /&gt;
&lt;br /&gt;
mdadm --fail /dev/md2 /dev/vdn&lt;br /&gt;
&lt;br /&gt;
# check /proc/mdstat to see md2 rebuilding with the spare from md1&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Recovery ===&lt;br /&gt;
&lt;br /&gt;
The other day, I came across a problem a user had on #linux-raid@irc.freenode.net. He had an old Qnap NAS that had died and tried plugging the drives in to his Linux machine and got various errors. The two-drive RAID-1 did not come up as it should, &#039;&#039;&#039;dmesg&#039;&#039;&#039; was full of errors from one of the drives (both connected on USB) and so forth.&lt;br /&gt;
&lt;br /&gt;
We went on and started by taking down the machine and just connecting one of the drives. I had him check what was assembled with&lt;br /&gt;
&lt;br /&gt;
 cat /proc/mdstat&lt;br /&gt;
&lt;br /&gt;
That returned /proc/md127 assembled, but LVM didn&#039;t find anything. So running a manual scan&lt;br /&gt;
&lt;br /&gt;
 pvscan --cache /dev/md127&lt;br /&gt;
&lt;br /&gt;
This made linux find the PV, VG and a couple of LVs, but probably because the mdraid was degraded, the LVs were deactivated, according to &#039;&#039;&#039;lvscan&#039;&#039;&#039;. Activating the one with a filesystem manually&lt;br /&gt;
&lt;br /&gt;
 lvchange -a y /dev/&amp;lt;vg&amp;gt;/&amp;lt;lv&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Substitute &amp;lt;vg&amp;gt; and &amp;lt;lv&amp;gt; with the names listed by vgs and lvs.&lt;br /&gt;
&lt;br /&gt;
This worked, and the filesystem on /dev/&amp;lt;vg&amp;gt;/&amp;lt;lv&amp;gt; could be mounted correctly.&lt;br /&gt;
&lt;br /&gt;
== Tuning ==&lt;br /&gt;
&lt;br /&gt;
While trying to compare a 12-disk RAID (8TB disks) to a hwraid, mdraid was slower, so we did a few things to speed things up:&lt;br /&gt;
&lt;br /&gt;
While testing with [https://linux.die.net/man/1/fio fio], monitor /sys/block/md0/md/stripe_cache_active, and see if it&#039;s close to /sys/block/md0/md/stripe_cache_size. If it is, double the size of the latter&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
echo 4096 &amp;gt; /sys/block/md0/md/stripe_cache_size&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Continue until stripe_cache_active stabilises, and then you&#039;ve found the limit you&#039;ll need. You may want to double that for good measure. &lt;br /&gt;
&lt;br /&gt;
(to be continued)&lt;br /&gt;
&lt;br /&gt;
== Links ==&lt;br /&gt;
&lt;br /&gt;
Below are a few links with useful info&lt;br /&gt;
&lt;br /&gt;
* [https://raid.wiki.kernel.org/index.php/Irreversible_mdadm_failure_recovery Irreversible mdadm failure recovery]&lt;br /&gt;
&lt;br /&gt;
= ZFS =&lt;br /&gt;
&lt;br /&gt;
ZFS can do a lot of things most filesystems or volume managers can&#039;t. It checksums all data and metadata and so long that the system uses ECC enabled memory (RAM), it will have complete control over the whole data set, and when (not if) an error occurs, it&#039;ll fix the issue without even throwing a warning. To fix the issue, you&#039;ll obviously need sufficient redundancy (mirrors or RAIDzN). &lt;br /&gt;
&lt;br /&gt;
== ZFS send/receive between machines ==&lt;br /&gt;
&lt;br /&gt;
ZFS has a send/receive mechanism that allows for snapshots to be sent over the wire to a receiving end. This can be a full filesystem, or an incremental change since last send/reveive. In a WAN scenario, you&#039;ll probably want to use VPN for this. On a controlled network, sending in cleartext is also possible. You may as well use ssh, but keep in mind that ssh was never designed to be used as a fullblown vpn solution and is just too slow or the task with large amounts of data. You may, though, use mbuffer, if on a loal LAN.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Allow traffic from the sending IP in whatever firewall interface you&#039;re using (if you&#039;re using a firewall at all, that is)&lt;br /&gt;
ufw allow from x.x.x.x&lt;br /&gt;
# &lt;br /&gt;
# Start the receiver first. This listens on port 9090, has a 1GB buffer,&lt;br /&gt;
    and uses 128kb chunks (same as zfs):&lt;br /&gt;
&lt;br /&gt;
mbuffer -s 128k -m 1G -I 9090 | zfs receive data/filesystem&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To be continued one day… See [https://everycity.co.uk/alasdair/2010/07/using-mbuffer-to-speed-up-slow-zfs-send-zfs-receive/ this] for some more. I&#039;ll get back with details on it.&lt;br /&gt;
&lt;br /&gt;
= General Linux system control =&lt;br /&gt;
&lt;br /&gt;
== Add a new CPU (core) ==&lt;br /&gt;
&lt;br /&gt;
If working with virtual machines, adding a new core can be useful if the VM is slow and the load is multithreaded or multiprocess. To do this, add a new CPU in the hypervisor (be it KVM or VMware or Hyper-V or whatever). Some hypervisors, like VMware, will activate it automatically if open-vm-tools is installed. Please note that open-vm-tools is for VMware only. I don&#039;t know of any such thing for KVM or other hypervisors (although I beleive VirtualBox has its own set of tools, but not as a package). If this doesn&#039;t work, run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
echo 1 &amp;gt; /sys/devices/system/cpu/cpuX/online&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where X is the CPU number you want to add. You can &#039;cat /sys/devices/system/cpu/cpuX/online&#039; to check if it&#039;s online.&lt;br /&gt;
&lt;br /&gt;
= Mount partitions on a disk image =&lt;br /&gt;
&lt;br /&gt;
Sometimes you&#039;ll have a disk image, either from recovering a bad drive after hours (or days or weeks) of ddrescue, and sometimes you just have a disk image from a virtual machine where you want to mount the partitions inside the image. There are three main methods of doing this, which are more or less synonmous, but some easier than the other.&lt;br /&gt;
&lt;br /&gt;
== Basics ==&lt;br /&gt;
&lt;br /&gt;
A disk image is usually like a disk, consisting of either a large filesystem, a PV or a partition table with one or partitions onto which resides a filesystem, a pv, swap or something else. If it&#039;s partitioned, and you want your operating system to mount a filesystem or allow it to see whatever LVM stuff lies on it, you need to isolate the partitions. &lt;br /&gt;
&lt;br /&gt;
== Manual mapping ==&lt;br /&gt;
&lt;br /&gt;
In the oldern days, this was done manually, something like this&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
root@mymachine:~# fdisk -l /dev/vda&lt;br /&gt;
Disk /dev/vda: 25 GiB, 26843545600 bytes, 52428800 sectors&lt;br /&gt;
Units: sectors of 1 * 512 = 512 bytes&lt;br /&gt;
Sector size (logical/physical): 512 bytes / 512 bytes&lt;br /&gt;
I/O size (minimum/optimal): 512 bytes / 512 bytes&lt;br /&gt;
Disklabel type: dos&lt;br /&gt;
Disk identifier: 0xc37b7ea5&lt;br /&gt;
&lt;br /&gt;
Device     Boot    Start      End  Sectors  Size Id Type&lt;br /&gt;
/dev/vda1  *        2048 50333311 50331264   24G 83 Linux&lt;br /&gt;
/dev/vda2       50333312 52426369  2093058 1022M  5 Extended&lt;br /&gt;
/dev/vda5       50333314 52426369  2093056 1022M 82 Linux swap / Solaris&lt;br /&gt;
root@mymachine:~#&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To calculate the start and end of each partition, you just take the start sector and multiply it by the sector size (512 bytes here) and you have the offset in bytes. After this, it&#039;s merely an losetup -o &amp;lt;offset&amp;gt; /dev/loopX &amp;lt;nameofimagefile&amp;gt; and you have the partition mapped to your /dev/loopX (having X being something typically 0-255. After this, just mount it or run pvscan/vgscan/lvscan to probe whatever lvm config is there, and you should be able to mount it like any other filesystem.&lt;br /&gt;
&lt;br /&gt;
== kpartx ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;kpartx&#039;&#039;&#039; does the same as above, more or less, just without so much hassle. Most of it should be automatic and easy to deal with, except it may fail to disconnect the loopback devices sometimes, so you may have to &#039;&#039;&#039;losetup -d&#039;&#039;&#039; them manually. See the manual, &#039;&#039;&#039;kpartx (8)&#039;&#039;&#039;. Please note that &#039;&#039;&#039;partx&#039;&#039;&#039; works similarly and I&#039;d guess the authors of the two tools are arguing a lot of which one&#039;s the best.&lt;br /&gt;
&lt;br /&gt;
== guestmount ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;guestmount&#039;&#039;&#039; is something similar again, but also supports file formats like &#039;&#039;&#039;qcow2&#039;&#039;&#039; and possibly other, proprietary filesystems like &#039;&#039;&#039;vmdk&#039;&#039;&#039; and &#039;&#039;&#039;vdi&#039;&#039;&#039;, but don&#039;t take my word for it - I haven&#039;t tested. Again, see the manual or just read up on the description [http://ask.xmodulo.com/mount-qcow2-disk-image-linux.html?fbclid=IwAR3snTeZvGzp9PLdX11EQhCfOpux6I93CiJ3A2pUomkkRLly9Xo4851mkTY here]. It seems rather trivial.&lt;br /&gt;
&lt;br /&gt;
= Linux on laptops =&lt;br /&gt;
&lt;br /&gt;
== Wifi with HP EliteBook 725/745 on Ubuntu ==&lt;br /&gt;
&lt;br /&gt;
The HP EliteBook 725/745 and similar are equipped with a BCM4352 wifi chip. As with a lot of other stuff from Broadcom, this lacks an open hardware description, so thus no open driver exist. The proper fix, is to replace the NIC with something with an open driver, but again, this isn&#039;t always possible, so a binary driver exists. In ubuntu, run, somehow connect the machine to the internet and run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install bcmwl-kernel-source&lt;br /&gt;
sudo modprobe wl&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you can&#039;t connect the machine to the internet, download the needed packages on another machine and put it on some usb storage. These packages should suffice:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# apt-cache depends bcmwl-kernel-source&lt;br /&gt;
bcmwl-kernel-source&lt;br /&gt;
  Depends: dkms&lt;br /&gt;
  Depends: linux-libc-dev&lt;br /&gt;
  Depends: libc6-dev&lt;br /&gt;
  Conflicts: &amp;lt;bcmwl-modaliases&amp;gt;&lt;br /&gt;
  Replaces: &amp;lt;bcmwl-modaliases&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then install manually with &#039;&#039;&#039;dpkg -i file1.deb file2.deb&#039;&#039;&#039; etc&lt;br /&gt;
&lt;br /&gt;
After this, ip/ifconfig/iwconfig shouldd see the new wifi nic, probably &#039;&#039;&#039;wlan0&#039;&#039;&#039;, but due to a [https://bugs.launchpad.net/ubuntu/+source/broadcom-sta/+bug/1343151 old, ignored bug], you won&#039;t find any wifi networks. This is because the driver from Broadcom apparently does not support interrupt remapping, commonly used on x64 machines. To turn this off, change &#039;&#039;&#039;/etc/default/grub&#039;&#039;&#039; and change the line &#039;&#039;&#039;GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;quiet splash&amp;quot;&#039;&#039;&#039;, adding intremap=off to the end before the quote: &#039;&#039;&#039;GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;quiet splash intremap=off&amp;quot;&#039;&#039;&#039;. Save the file and run &#039;&#039;&#039;sudo update-grub&#039;&#039;&#039; and reboot. After this, wifi should work well.&lt;br /&gt;
&lt;br /&gt;
== Wifi with HP Compaq Presario CQ57 on Ubuntu ==&lt;br /&gt;
&lt;br /&gt;
The HP Compaq Presario CQ57 uses the RT5390 wifi chipset. This has been supported for quite some time now, and I was quite surprised to find it not working on a laptop a friend was having. The driver loaded correctly, but Ubuntu insisted of the laptop being in &#039;&#039;&#039;flight mode&#039;&#039;&#039;. Checking &#039;&#039;&#039;rfkill&#039;&#039;&#039;, it showed me two NICs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# rfkill list all&lt;br /&gt;
0: phy0: Wireless LAN&lt;br /&gt;
	Soft blocked: no&lt;br /&gt;
	Hard blocked: yes&lt;br /&gt;
1: hp-wifi: Wireless LAN&lt;br /&gt;
	Soft blocked: yes&lt;br /&gt;
	Hard blocked: no&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Turning rfkill on and off resulted in nothing much, except some error messages in the kernel log (dmesg)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] ACPI Error: Field [B128] at bit offset/length 128/1024 exceeds size of target Buffer (160 bits) (20170831/dsopcode-235)&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]&lt;br /&gt;
                            Initialized Local Variables for Method [HWCD]:&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Local0: 00000000a34b7928 &amp;lt;Obj&amp;gt;           Integer 0000000000000000&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Local1: 00000000b0aa6865 &amp;lt;Obj&amp;gt;           Buffer(8) 46 41 49 4C 04 00 00 00&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Local5: 00000000a9811efd &amp;lt;Obj&amp;gt;           Integer 0000000000000004&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] Initialized Arguments for Method [HWCD]:  (2 arguments defined for method invocation)&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Arg0:   0000000078957d1b &amp;lt;Obj&amp;gt;           Integer 0000000000000001&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Arg1:   00000000725c9c6e &amp;lt;Obj&amp;gt;           Buffer(20) 53 45 43 55 02 00 00 00&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] ACPI Error: Method parse/execution failed \_SB.WMID.HWCD, AE_AML_BUFFER_LIMIT (20170831/psparse-550)&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] ACPI Error: Method parse/execution failed \_SB.WMID.WMAD, AE_AML_BUFFER_LIMIT (20170831/psparse-550)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After upgrading BIOS and testing different kernels, I was asked to try to unload the &#039;&#039;&#039;hp_wmi&#039;&#039;&#039; driver. I did, and things changed a bit, so I tried blacklisting it, creating the file &#039;&#039;&#039;/etc/modprobe.d/blacklist-hp_wmi.conf&#039;&#039;&#039; with the following content&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Blacklist this - it doesn&#039;t work!&lt;br /&gt;
blacklist hp_wmi&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
I gave the machine a reboot and afte that, the &#039;&#039;&#039;hp-wifi&#039;&#039;&#039; entry was gone in the rfkill output, and things works.&lt;br /&gt;
&lt;br /&gt;
= Raspberry pi =&lt;br /&gt;
&lt;br /&gt;
I couldn&#039;t quite decide if the raspberry pi should be a separate section or part of Linux, but hell, it can run more than Linux, although 99,lots% of people just uses Linux on them. This is a small list of things to know about them; things not on the front page of the manual or perhaps hidden even better.&lt;br /&gt;
&lt;br /&gt;
== Which pi? ==&lt;br /&gt;
&lt;br /&gt;
I just setup three raspberry pi machines and although some are quite different, like v1 to vEverythingelse or the Pi zero versions to the normal ones, not all of us remember how to distinguish between them, and sometimes they&#039;re in a nice 3d printed (or otherwise) chassis or otherwise hidden. So, how to check three different ones:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
root@home-assistant:~ $ cat /proc/device-tree/model ; echo&lt;br /&gt;
Raspberry Pi 2 Model B Rev 1.1&lt;br /&gt;
&lt;br /&gt;
root@green-pi:~ $ cat /proc/device-tree/model ; echo&lt;br /&gt;
Raspberry Pi 3 Model B Rev 1.2&lt;br /&gt;
&lt;br /&gt;
roy@yellow-pi:~ $cat /proc/device-tree/model ; echo&lt;br /&gt;
Raspberry Pi 4 Model B Rev 1.1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
While this works well, for the latter, the pi4, it doesn&#039;t tell how much memory I have. It comes in variants of 1, 2 and 4GB, and this is the latter.&lt;br /&gt;
&lt;br /&gt;
== Monitoring ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;vcgencmd&#039;&#039;&#039; from &#039;&#039;&#039;/opt/vc/bin&#039;&#039;&#039;, but symlinked to &#039;&#039;&#039;/usr/bin&#039;&#039;&#039; so it&#039;s available in path, is useful for fetching hardware info about the pi. For example, measuring the temperature&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
root@yellow-pi:~# vcgencmd measure_temp&lt;br /&gt;
temp=63.0&#039;C&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The command is generally badly documented and parts of it seems outdated for newer hardware. Here&#039;s the output from a Raspberry pi 4 with 4GB RAM&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
roy@yellow-pi:~ $ vcgencmd get_mem arm&lt;br /&gt;
arm=948M&lt;br /&gt;
roy@yellow-pi:~ $ vcgencmd get_mem gpu&lt;br /&gt;
gpu=76M&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= BIOS upgrade from Linux =&lt;br /&gt;
&lt;br /&gt;
Generally, BIOS upgrades have been moved to the BIOS itself these days. This saves a lot of work and quite possibly lives after those who earier rammed their heads through walls, now can upgrade directly from the internet instead of using obscure operating systems best avoided. Sometimes, however, one must use these nevertheless. This is a quick run-through on your options.&lt;br /&gt;
&lt;br /&gt;
== DOS ==&lt;br /&gt;
&lt;br /&gt;
Most non-automatic BIOS upgrades are installed from DOS. Doing a BIOS upgrade this way, is generally non-problematic. Just install a USB thingie with [https://www.freedos.org/ FreeDOS], copy your file(s) onto the thing and boot on it. The commandline is the same as old MS/DOS, except a wee bit more userfriendly, but not a lot.&lt;br /&gt;
&lt;br /&gt;
== Windows ==&lt;br /&gt;
&lt;br /&gt;
Some macahines, like laptops from &#039;&#039;&#039;HP&#039;&#039;&#039;, may have BIOS upgrades that are made to be installed from Windows and won&#039;t run in FreeDOS or MS/DOS, instead throwing an error, saying &#039;&#039;&#039;This program cannot be run in DOS mode&#039;&#039;&#039;. This means you&#039;ll have to boot on a Windows rescue disc and do the job from there. Googling this, tells you it&#039;s quite easy, you just choose &#039;make rescue disc&#039; from Windows, and it&#039;s all good, except if you don&#039;t run Windows, that is. To remedy this problem, do as follows:&lt;br /&gt;
&lt;br /&gt;
=== Download Windows ===&lt;br /&gt;
&lt;br /&gt;
Since you don&#039;t run Windows and possibly don&#039;t have a spouse or friend around with such unhealthy habits either, you need to get it. It&#039;s quite easy - just google &#039;download windows&#039; and it&#039;ll send you to [https://www.microsoft.com/en-us/software-download/windows10ISO somewhere like this].&lt;br /&gt;
&lt;br /&gt;
=== Burn it! ===&lt;br /&gt;
&lt;br /&gt;
Now it&#039;s time to burn the installer on a DVD ROM. You&#039;ll need a double-layered one, since the OS is &amp;gt; 4.7GiB, but I&#039;m sure you have a ton of those lying around. Now, just place your optical medium in your optical drive and burn, baby, burn!&lt;br /&gt;
&lt;br /&gt;
=== Or make a USB thing? ===&lt;br /&gt;
&lt;br /&gt;
Not a lot of machines have optical drives these days, so you may want to use an USB pen drive or something instead. This is easy, just make the USB bootable with the Windows application Microsoft has made for this. Unfortunately, this only runs on Windows, and unlike stuff like Debian, where the &#039;&#039;&#039;iso&#039;&#039;&#039; file can be dd&#039;ed directly onto a USB drive to make it bootable, the Windows &#039;&#039;&#039;iso&#039;&#039;&#039;s don&#039;t come with this luxury. There are lots of methods to make bootable USB things from iso files out there, but the only thing most of them have in common, is that they generally don&#039;t work.&lt;br /&gt;
&lt;br /&gt;
==== WoeUSB ====&lt;br /&gt;
&lt;br /&gt;
After hours of swearing, it&#039;s nice to come across software like [https://github.com/slacka/WoeUSB WoeUSB]. It may not be perfect, it relies on a bunch of GUI stuff you&#039;ll never need and so on, but it &#039;&#039;&#039;&#039;&#039;works&#039;&#039;&#039;&#039;&#039;, and that&#039;s the important part! Just clone the repo and RTFM and it&#039;s all nice. It&#039;s slow, but hell, getting a windows machine and/or an optical drive might be slower.&lt;br /&gt;
&lt;br /&gt;
WoeUSB does nothing fancy, but it &#039;&#039;&#039;does&#039;&#039;&#039; work. It will create a filesystem, FAT32 or NTFS (better use NTFS, FAT32 has its limits). It creates normal filesystems and so on. Just make sure to copy in the BIOS update file, usually an exe file, to run when Windows is up and running.&lt;br /&gt;
&lt;br /&gt;
==== Install BIOS ====&lt;br /&gt;
&lt;br /&gt;
Boot on the Windows USB thing and choose &#039;repair computer&#039; and then &#039;command prompt&#039;. Find the install file, and if you&#039;re lucky, you&#039;ll find it needs a 32bit OS, just like I did. Since the 64bit version doesn&#039;t include 32bit compatibility in the installer, revert to downloading the 32bit version of windows and start over. Pray to your favourite god(s) not to get across such machines again - it might help.&lt;br /&gt;
&lt;br /&gt;
= 3D printer stuff =&lt;br /&gt;
&lt;br /&gt;
== Hydrophilic filament ==&lt;br /&gt;
&lt;br /&gt;
Most popular filament types, including PLA, PETG, PP or PA (Polyamide, normally known as Nylon) and virtualy any filament type named [https://www.matterhackers.com/news/filament-and-water poly-something] (and thus with an acronym of P-something) are hydrophilic (also (somewhat incorrectly) called hydroscopic), meaning so long they&#039;re dryer than the atmosphere around them, they&#039;ll do their best to suck out the atmosphere&#039;s humidity. This is why most filament are shrink-wrapped with a small bag of silica gel in it. If such filament is exposed for normal humid air for some time, it&#039;ll become very hard to use. Most of my experience is with PLA, which can handle a bit (depending on make), but still not a lot. With PLA, if you end up with prints where the filament seems not to stick, it may help with a higher temperature. Otherwise, the filament must be [https://all3dp.com/2/how-to-dry-filament-pla-abs-and-nylon/ baked]. If you don&#039;t want to use your oven, try something like a [https://www.jula.no/catalog/hjem-og-husholdning/kjokkenmaskiner/mattilberedningsapparater/frukt-sopptorker/frukt-sopptorker-001641/#tab02 fruit and mushroom dryer]. Then get a good, sealble plastic box and add something like half a kilogram of [https://www.ebay.com/sch/sis.html?_nkw=1KG+Orange+Replacement+Desiccant+Indicating+Silica+Gel+Beads+for+Drawers%2C+Camera&amp;amp;_id=131938742628&amp;amp;&amp;amp;_trksid=p2057872.m2749.l2658 silica gel] to an old sock, tie it and put it in the your new dry box.&lt;br /&gt;
&lt;br /&gt;
Please note that ABS is hydrophobic, so you won&#039;t have to worry too much there. Also, remember that PA/Nylon is extremely hydrophilic. Even a couple of days in normal air humidity can ruin it completely and will require baking.&lt;br /&gt;
&lt;br /&gt;
== Upgrading the firmware on an Ender 3 ==&lt;br /&gt;
&lt;br /&gt;
This is about upgrading the firmware, and thus also flashing a bootloader to the Creality Ender 3 3D printer. Most of this is well documented on several place, like o [https://www.youtube.com/watch?v=fIl5X2ffdyo the video from Teaching tech] and elsewhere, but I&#039;ll just summarise some issues I had.&lt;br /&gt;
&lt;br /&gt;
=== Using an arduino Nano as a programmer ===&lt;br /&gt;
&lt;br /&gt;
Quick note before you read on. If you have an Ender 3 controller version 1.1.5 or newer (or perhaps even a bit older), a CR-10S or some other more or less modern printers or controllers, they come with a bootloader installed already, so don&#039;t bother flashing one. The one that&#039;s in there already, should work well. So if you have one of these, just skip this and jump to the [[Roy&#039;s_notes#Flashing_the_printer|next section]].&lt;br /&gt;
&lt;br /&gt;
However, the normal CR-10 (without the S), Ender 3 and a few other printers from Creality come without a bootloader, so you&#039;ll need to flash one before upgrading the firmware. Well, strictly speakning, you don&#039;t need one, you can save those 8kB or so for other stuff and use a programmer to write the whole firmware, but then you&#039;ll need to wire up everything every time you want a new firmware, so in my world, you &#039;&#039;&#039;do&#039;&#039;&#039; need the bootloader, since it&#039;s easier.&lt;br /&gt;
&lt;br /&gt;
To install a bootloader, you&#039;ll need a programmer, and I didn&#039;t have one available. Having some el-cheapo china-copies of Arduinos around, I read I could use one and tried so. Although the docs mostly mention the Uno etc, it&#039;s just as simple with the Nano copy.&lt;br /&gt;
&lt;br /&gt;
So, grab an arduino, plug it to your machine with a USB cable, and, using the Arduino IDE, use the ArduinoISP sketch there (found under Examples) to burn the software needed for the arduino to work as a programmer. When this is done, connect a 10µF capacitor between RST and GND to stop it from resetting when used as a programmer. Connect the MOSI, MISO and SCK pins from the ICSP block (that little isolated 6-pin block on top of the ardu). See [https://www.arduino.cc/en/Tutorial/ArduinoISP here] for a pinout. Then find Vcc and GND either on the ICSP block or elsewhere. Some sites say that on some boards you shouldn&#039;t use the pins on the ICSP block for this. I doubt it matters, though. Then connect another jumper wire from pin 10 on the ardu to work as the reset pin outwards to the chip being programmed (that is, on the printer). The ICSP jumper block pin layout is the same on the printer and on the ardu, and probably elsewhere. Sometimes [https://xkcd.com/927/ standardisation] actually works…&lt;br /&gt;
&lt;br /&gt;
See https://cloud.karlsbakk.net/index.php/s/zw48YJjzaf8Rc2F for a pic with the ardu (this wiki is broken atm, will fix it later)&lt;br /&gt;
&lt;br /&gt;
== Flashing the printer ==&lt;br /&gt;
&lt;br /&gt;
When the boot loader is in place, possibly after some wierd errors from during the process, the screen on the 3d printer will go blank and it&#039;ll behave like being bricked. This is ok. Now disconnect the wires and connect the USB cable between computer and printer. If you haven&#039;t installed support for the Sanguino board, that is, the variant of the 1284-chip and surrounding electronics that is the core of the, you need to install it first. In the Arduino IDE, choose the Tools / Boards / Boards manager boot option and search for Sanguino. After this, you should find the Sanguino or Sanguino 1284p in the boards menu. After this, you should be able to communicate with the printer&#039;s controller. Download the [https://www.th3dstudio.com/knowledgebase/th3d-unified-firmware-package/ TH3D unified firmware], making sure it&#039;s the last version. Uncompress the zip and with Finder/Explorer/whateversomething&#039;scalledonlinux, browse to &#039;&#039;&#039;TH3DUF_R2/Firmware/TH3DUF_R2.ino&#039;&#039;&#039; and open it. It should open directly in the Android IDE. Keep in mind that the names TH3DUF_R2 and TH3DUF_R2.ino will vary between versions, but you get the point. Now configure it for your particular needs. You&#039;ll find most of this in the Configuration.h tab (that&#039;s really a file). Most of the other files won&#039;t be necessary unless you&#039;re doing some more advanced stuff, like replacing th controller with something non-standard or similar, but then again, that&#039;s another chapter (or book, even). The video mentioned above describes this well. After flashing the new firmware, you&#039;ll probably get some timeouts and errors, since apparently it resets the printer after giving it the new firmware, but without notifying the flashing software of it doing so. If this happens, calm down and reboot the printer and check its tiny monitor - it should work. If it doesn&#039;t work, and if you flashed the bootload yourself, try to flash it again, and if that doesn&#039;t work, try flashing the programmer again yet another time, just for kicks. Again, if you have a newer controller like the v1.1.5, don&#039;t touch the bootloader, as the one already installed, should work well as it is.&lt;br /&gt;
&lt;br /&gt;
PS: I tried enabling &#039;&#039;&#039;MANUAL_MESH_LEVELING&#039;&#039;&#039;, which in the code says that &#039;&#039;If used with a 1284P board the bootscreen will be disabled to save space&#039;&#039;. This effectively disabled the whole printer, and apparently may be making the firmware image a wee bit too large for it to fit the 1284P on the ender. It works well without it, though, and it may be fixed by now, since I tested this back in early 2019.&lt;br /&gt;
&lt;br /&gt;
== And then… ==&lt;br /&gt;
&lt;br /&gt;
With the new firmware in place, the printer should work as before, although with thermal runaway protection to better avoid fires in case the shit hits the fan, and to allow for things like autolevelling. With any luck, [https://www.precisionpiezo.co.uk/ this thing] may be ready for use by the time you read this - it surely looks nice!&lt;br /&gt;
&lt;br /&gt;
= Octoprint/Octopi =&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;This could have been under some other section, but again, I just branch out even though most of it is about sections mentioned elsewhere.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
When setting up a 3d printer for the first time, you usually get an SD card for storage and transfer data to the printer using [https://en.wikipedia.org/wiki/Sneakernet Sneakernet]. Some printers use micro SD cards, while other fullsize SD cards, which imho is better, since they don&#039;t get lost that easily, but otherwise do the same thing. This works, but is somewhat tedious. If you want to control the printer from a PC or phone, there&#039;s a simple trick for that as well - octoprint.&lt;br /&gt;
&lt;br /&gt;
[https://octoprint.org/ Octoprint], written by Gina Häußge, runs on most platforms including linux, windows, BSD*, macos etc. It supports controlling a camera to some extent out of the box and there&#039;s a large number of plugins availablee to do a lot of things you possibly haven&#039;t thought of (and quite often, you&#039;d ever need). The easiest way to install it, is to just grab a Raspberry pi - preferably some of the newer models (will get to that later) and download [https://octoprint.org/download/ octopi] and follow the instructions on that page.&lt;br /&gt;
&lt;br /&gt;
== Performance issues ==&lt;br /&gt;
&lt;br /&gt;
Some report (and I have seen it myself) issues with the pi&#039;s performance with regards to both handling the octoprint processes (which should be as close to realtime as possible) and handling other stuff like I/O, networking etc. The point is that at pi3 or older, has all peripherals connected to an internal USB hub. This might be practical, but performance-wise it&#039;s &#039;&#039;&#039;&#039;&#039;not&#039;&#039;&#039;&#039;&#039;. If you in addition connect a webcam to USB, you&#039;re asking for trouble, since USB will be your bottleneck. With a raspberry pi camera, the ones connected to the pi directly with a ribbon cable, this should not use USB, so it&#039;s better. Still, again, for older pi&#039;s, there might be some shortage in therms of cpu or i/o. The octopi runs something like raspbian which is a fork of debian which is a linux distro, so it all boils down to knowing linux.&lt;br /&gt;
&lt;br /&gt;
Your typical octopi will run octoprint, a streamer, usually &#039;&#039;&#039;mjpg-streamer&#039;&#039;&#039;, a simple, lightweight videostreamer that outputs a stream of jpeg-images (about the same format as cinemas use - that is - not MPEG). This may be a bit tough on the cpu and potentially i/o. Add inn a dash of USB overload and you&#039;re may see trouble.&lt;br /&gt;
&lt;br /&gt;
Still - a pi3 should be able to handle the load, but it might help to prioritise corretly. The octoprint process is the important part here, so we could give that full priority both in CPU and I/O and. Unfortunately, it doesn&#039;t seem like the current octopi has been migrated to using systemd for the startup. We&#039;ll deal with this later. To fix this in the old SysV init style file present there, the following patch should work against the file /etc/init.d/octoprint&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;diff&amp;quot;&amp;gt;&lt;br /&gt;
--- octoprint.old	2020-07-20 18:46:10.166651965 +0200&lt;br /&gt;
+++ octoprint	2020-07-20 18:53:21.724803211 +0200&lt;br /&gt;
@@ -22,6 +22,9 @@&lt;br /&gt;
 PIDFILE=/var/run/$NAME.pid&lt;br /&gt;
 PKGNAME=octoprint&lt;br /&gt;
 SCRIPTNAME=/etc/init.d/$PKGNAME&lt;br /&gt;
+NICELEVEL=-19                        # Top CPU priority&lt;br /&gt;
+IONICE_CLASS=1                       # Realtime I/O class&lt;br /&gt;
+IONICE_PRIORITY=0                    # Realtime I/O priority (probably not needed with class=realtime)&lt;br /&gt;
&lt;br /&gt;
 # Read configuration variable file if it is present&lt;br /&gt;
 [ -r /etc/default/$PKGNAME ] &amp;amp;&amp;amp; . /etc/default/$PKGNAME&lt;br /&gt;
@@ -70,10 +73,11 @@&lt;br /&gt;
&lt;br /&gt;
    is_alive $PIDFILE&lt;br /&gt;
    RETVAL=&amp;quot;$?&amp;quot;&lt;br /&gt;
-&lt;br /&gt;
    if [ $RETVAL != 0 ]; then&lt;br /&gt;
        start-stop-daemon --start --background --quiet --pidfile $PIDFILE --make-pidfile \&lt;br /&gt;
-       --exec $DAEMON --chuid $OCTOPRINT_USER --user $OCTOPRINT_USER --umask $UMASK -- serve $DAEMON_ARGS&lt;br /&gt;
+       --exec $DAEMON --chuid $OCTOPRINT_USER --user $OCTOPRINT_USER --umask $UMASK \&lt;br /&gt;
+       --nicelevel $NICELEVEL --ioched $IONICE_CLASS:$IONICE_PRIORITY \&lt;br /&gt;
+       --serve $DAEMON_ARGS&lt;br /&gt;
        RETVAL=&amp;quot;$?&amp;quot;&lt;br /&gt;
    fi&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This ismply upgrades the process to be allowed to use most of the resources on the pi, regardless of what other processes are whining about.&lt;br /&gt;
&lt;br /&gt;
PS: Code not tested - I don&#039;t have a pi right here. Will test later, but I&#039;m pretty sure it&#039;ll work. After all, it&#039;s just a few new arguments to start-stop-daemon&lt;br /&gt;
&lt;br /&gt;
roy&lt;/div&gt;</summary>
		<author><name>Roy</name></author>
	</entry>
	<entry>
		<id>https://wiki.malinux.no/index.php?title=Roy%27s_notes&amp;diff=167</id>
		<title>Roy&#039;s notes</title>
		<link rel="alternate" type="text/html" href="https://wiki.malinux.no/index.php?title=Roy%27s_notes&amp;diff=167"/>
		<updated>2020-07-20T17:02:05Z</updated>

		<summary type="html">&lt;p&gt;Roy: /* Performance issues */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= LVM, md and friends =&lt;br /&gt;
&lt;br /&gt;
== Linux&#039; Logical Volume Manager (LVM) ==&lt;br /&gt;
&lt;br /&gt;
=== LVM in general ===&lt;br /&gt;
&lt;br /&gt;
LVM is designed to be an abstraction layer on top of physical drives or RAID, typically [https://raid.wiki.kernel.org/index.php/RAID_setup mdraid] or [https://help.ubuntu.com/community/FakeRaidHowto fakeraid]. Keep in mind that fakeraid should be avoided unless you really need it, like in conjunction with dual-booting linux and windows on fakeraid. LVM broadly consists of three elements, the &amp;quot;physical&amp;quot; devices (PV), the volume group (VG) and the logical volume (LV). There can be multiple PVs, VGs and LVs, depending on requirement. More about this below. All commands are given as examples, and all of them can be fine-tuned using extra flags in need of so. In my experience, the defaults work well for most usecases.&lt;br /&gt;
&lt;br /&gt;
I&#039;m mentioning filesystem below too. Where I write ext4, the samme applies to ext2 and ext3.&lt;br /&gt;
&lt;br /&gt;
==== Create a PV ====&lt;br /&gt;
&lt;br /&gt;
A PV is the &amp;quot;physical&amp;quot; parts. This does not need to be a physical disk, but can also be another RAID, be it an mdraid, fakeraid, hardware raid, a virtual disk on a SAN or otherwisee or a partition on one of those. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#  These add three PVs, one on a drive (or hardware raid) and another two on mdraids.&lt;br /&gt;
pvcreate /dev/sdb&lt;br /&gt;
pvcreate /dev/md1 /dev/md2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For more information about pvcreate, see [https://linux.die.net/man/8/pvcreate the manual].&lt;br /&gt;
&lt;br /&gt;
==== Create a VG ====&lt;br /&gt;
&lt;br /&gt;
The volume group consists of one or more PVs grouped together on which LVs can be placed. If several PVs are grouped in a VG, it&#039;s generally a good idea to make sure these PVs have some sort of redundancy, as in mdraid/fakeraid or hwraid. Otherwise it will be like using a [https://en.wikipedia.org/wiki/RAID RAID-0] with a single point of failure on each of the independant drives. LVM has [https://unix.stackexchange.com/questions/150644/raiding-with-lvm-vs-mdraid-pros-and-cons  RAID code in it] as well, so you can use that. I haven&#039;t done so myself, as I generally stick to mraid. The reason is mdraid is, in my opinion older and more stable and has more users (meaning bugs are reported and fixed faster whenever they are found). That said, I beleive the actual RAID code used in LVM RAID are the same function calls as for mdraid, so it may not be much of a difference. I still stick with mdraid. To create a VG, run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create volume group my_vg&lt;br /&gt;
vgcreate my_vg /dev/md1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that if vgcreate is run with a PV (as /dev/md1 above) that is not defined as a PV (like above), this is done implicitly, so if you don&#039;t need any special flags to pvcreate, you can simply skip it and let vgcreate do that for you.&lt;br /&gt;
&lt;br /&gt;
==== Create an LV ====&lt;br /&gt;
&lt;br /&gt;
LVs can be compared to partitions, somehow, since they are bounderies of a fraction or all of that of a VG. The difference between them and a partition, however, is that they can be grown or shrunk easily and also moved around between PVs without downtime. This flexibility makes them superiour to partitions as your system can be changed without users noticing it. By default, an LV is alloated &amp;quot;thickly&amp;quot;, meaning all the data given to it, is allocated from the VG and thus the PV. The following makes a 100GB LV named &amp;quot;thicklv&amp;quot;. When making an LV, I usually allocate what&#039;s needed plus some more, but not everything, just to make sure it&#039;s space available for growth on any of the LVs on the VG, or new LVs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a thick provisioned LV named thicklv on the VG my_vg&lt;br /&gt;
lvcreate -n thicklv -L 100G my_vg&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After the LV is created, a filesystem can be placed on it unless it is meant to be used directly. The application for direct use include swap space, VM storage and certain database systems. Most of these will, however, work on filesystems too, although my testing has shown that on swap space, there is a significant performance gain for using dedicated storage without a filesystem. As for filesystems, most Linux users use either ext4 or xfs. Personally, I generally use XFS these days. See my notes below on filesystem choice.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a filesystem on the LV - this could have been mkfs -t ext4 or whatever filesystem you choose&lt;br /&gt;
mkfs -t xfs /dev/my_vg/thicklv&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then just edit /etc/fstab with correct data and run mount -a, and you should be all set.&lt;br /&gt;
&lt;br /&gt;
==== Create LVM cache ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
lvcreate -L 1G -n _cache_meta data /dev/md1&lt;br /&gt;
&lt;br /&gt;
lvcreate -l100%FREE -n _cache data /dev/md1&lt;br /&gt;
&lt;br /&gt;
# Some would want --cachemode writeback, but seriously, I wouldn&#039;t recommend it. Metadata or data can be easily corrupted in case of failure.&lt;br /&gt;
lvconvert --type cache-pool --cachemode writethrough --poolmetadata data/_cache_meta data/_cache&lt;br /&gt;
&lt;br /&gt;
lvconvert --type cache --cachepool data/_cache data/data&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Disabling LVM cache ====&lt;br /&gt;
&lt;br /&gt;
If you for some reason want to disable caching, this will do it cleanly and remove the LVs earlier created for caching the main device.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
lvconvert --uncache data/data&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Growing devices ====&lt;br /&gt;
&lt;br /&gt;
LVM objects can be grown and shrunk. If a PV resides on a RAID where a new drive has been added or otherwise grown, or on a partition or virtual disk that has been extended, the PV must be updated to reflect these changes. The following command will grow the PV to the maximum available on the underlying storage. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Resize the PV /dev/md (not the RAID, only the PV on the RAID) to its full size&lt;br /&gt;
pvresize /dev/md1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If a new PV is added, the VG can be grown to add the space on that in addition to what&#039;s there already. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Extend my_vg to include md2 and its space&lt;br /&gt;
vgextend my_vg /dev/md2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
With more space available in the VG, the LV can now be extended. Let&#039;s add another 50GB to it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Extend thicklv - add 50GB. If you know you won&#039;t need the space anywhere else, you may want to&lt;br /&gt;
# lvresize -l+100%FREE instead. Keep in mind the difference between -l (extents) and -L (bytes)&lt;br /&gt;
lvresize -L +50G my_vg/thicklv&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Growing filesystems ====&lt;br /&gt;
After the LV has grown, run &#039;&#039;xfs_growfs&#039;&#039; (xfs) or &#039;&#039;resize2fs&#039;&#039; (ext4) to make use of the new data. To grow the filesystem to all available space on ext4, run the below command.  To partly grow the filesystem or to shrink it or otherwise, please see the manuals.&lt;br /&gt;
&lt;br /&gt;
The filesystem can be mounted when this is run. If you for some reason get an &#039;&#039;&#039;access denied&#039;&#039;&#039; error when running this as root or with sudo, it&#039;s likely caused by a filesystem error. To fix this, unmount the filesystem first and run &#039;&#039;&#039;fsck -f /dev/my_vg/thicklv&#039;&#039;&#039; and remount it before retrying to extend it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
resize2fs /dev/my_vg/thicklv&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Similarly, with XFS, but note that xfs_growfs doesn&#039;t take the device name, but the filesystem&#039;s mount point. In the case of XFS, also note that the filesystem &#039;&#039;&#039;&#039;&#039;must&#039;&#039;&#039;&#039;&#039; be mounted to be grown. This, in contrast to how it was in the old days when filesystems had to be unmounted to be grown.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
xfs_growfs /my_mountpoint&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Rename system VG ====&lt;br /&gt;
&lt;br /&gt;
Some distros create VG names like those-from-a-sysadmin-with-a-well-developed-paranoia-not-to-hit-a-duplicate. Debian, for instance, uses names like &amp;quot;my-full-hostname-vg&amp;quot;. Personally, I don&#039;t like these, since if I were to move a disk or vdisk around to somewhere else, I&#039;d make sure not to add a disk named &#039;sys&#039; to an existing system. If you do, most distros will refuse to use the VGs with duplicate names, resulting in the OS not booting until either one is specified by its UUID or just one removed. As I&#039;m aware of this, I stick to the super-risky thing of all system VGs named &#039;sys&#039; and so on.&lt;br /&gt;
&lt;br /&gt;
If you do this, keep in mind that it may blow up your computer and take your girl- or boyfriend with it or even make either of them pregnant, allowing Trump to rule your life and generally make things suck. You&#039;re on your own!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Rename the VG&lt;br /&gt;
vgrename my-full-hostname-vg sys&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, in /boot/grub/grub.cfg, change the old lv path from something like &#039;/dev/mapper/debian--stretch--machine--vg-root&#039; to your new and fancy &#039;/dev/sys/root. Likewise, in /etc/fstab, change occurences of &#039;/dev/mapper/debian--stretch--machine--vg-&#039; (or similar) with &#039;/dev/sys/&#039;. Here, this was like this - the old ones commented out.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;fstab&amp;quot;&amp;gt;&lt;br /&gt;
#/dev/mapper/debian--stretch--box--vg-root      /               ext4            errors=remount-ro,discard       0       1&lt;br /&gt;
/dev/sys/root                                   /               ext4            errors=remount-ro,discard       0       1&lt;br /&gt;
# /boot was on /dev/vda1 during installation&lt;br /&gt;
UUID=myverylonguuidwithatonofgoodinfoinit       /boot           ext2            defaults                        0       2&lt;br /&gt;
#/dev/mapper/debian--stretch--box--vg-swap_1    none            swap            sw                              0       0&lt;br /&gt;
/dev/sys/swap_1                                 none            swap            sw                              0       0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Update /etc/initramfs-tools/conf.d/resume with similar data for swap.&lt;br /&gt;
&lt;br /&gt;
You might want to run &#039;update-initramfs -u -k all&#039; after this, but I&#039;m not sure if it&#039;s needed.&lt;br /&gt;
&lt;br /&gt;
Now, pray to the nearest god(s) and give it a reboot and it should (probably) work.&lt;br /&gt;
&lt;br /&gt;
After reboot, run &#039;&#039;&#039;swapoff -a&#039;&#039;&#039;, then &#039;&#039;&#039;mkswap /dev/sys/swap_1&#039;&#039;&#039; (or whatever it&#039;s called on your system) and &#039;&#039;&#039;swapon -a&#039;&#039;&#039; again. You may want to give it another reboot or two for kicks, but it should work well even without that.&lt;br /&gt;
&lt;br /&gt;
=== Migration tools ===&lt;br /&gt;
&lt;br /&gt;
At times, storage regimes change, new storage is added and sometimes it&#039;s not easy to migrate with the current hardware or its support systems. Once I had to migrate a 45TiB fileserver from one storage system to another, preferably without downtime. The server originally had three 15TiB PVs of which two were full and the third half full. I resorted to using [https://linux.die.net/man/8/pvmove pvmove] to just move the data on the PVs in use to a new PV. We started out with creating a new 50TiB PV, sde, and then to pvmove.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Attach /dev/sde to the VG my_vg&lt;br /&gt;
vgextend my_vg /dev/sde&lt;br /&gt;
&lt;br /&gt;
# Move the contents from /dev/sdb over to /dev/sde block by block. If a target is not given in pvmove,&lt;br /&gt;
# the contents of the source (sdb here) will be put somewhere else in the pool.&lt;br /&gt;
pvmove /dev/sdb /dev/sde&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This took a while (as in a week or so) - the pvmove command uses old code and logic (or at least did that when I migrated this in November 2016), but it affected performance on the server very little, so users didn&#039;t notice. After the first PV was migrated, I continued with the other two, one after the other, and after a month or so, it was migrated. We used this on a number of large fileservers, and it worked flawlessly. Before doing the production servers I also tried interrupting pvmove in various ways, including hard resets, and it just kept on after the reboot.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;NOTE:&#039;&#039;&#039;&#039;&#039; &#039;&#039;Even though it worked well for us, &#039;&#039;&#039;always&#039;&#039;&#039; keep a good backup before doing this. Things may go wrong, and without a good backup, you may be looking for a hard-to-find new job the next morning&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
==== mdadm workarounds ====&lt;br /&gt;
&lt;br /&gt;
===== Migrate from a mirror (raid-1) to raid-10 =====&lt;br /&gt;
&lt;br /&gt;
Create a mirror&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sdb /dev/sdc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
LVM (pv/vg/lv) on md0 (see above), put a filesystem on the lv and fill it with some data.&lt;br /&gt;
&lt;br /&gt;
Now, some months later, you want to change this to raid-10 to allow for the same amount of redundancy, but to allow more disks into the system.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mdadm --grow /dev/md0 --level=10&lt;br /&gt;
mdadm: Impossibly level change request for RAID1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So - no - doesn&#039;t work. But - we&#039;re on &lt;br /&gt;
&lt;br /&gt;
Since we&#039;re on lvm already, this&#039;ll be easy. If you&#039;re using filesystems directly on partitions, you can do this the same way, but without the pvmove part, using rsync or whateever you like instead. I&#039;d recommend using lvm for for the new raid, which should be rather obvious from this article. Now plug in a new drive and create a new raid10 on that one. If you two new drives, install both. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# change &amp;quot;missing&amp;quot; to the other device name if you installed two new drives&lt;br /&gt;
mdadm --create /dev/md1 --level=10 --raid-devices=2 /dev/vdd missing&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, as described above, just vgextend the vg, adding the new raid and run pvmove to move the data from the old pv (residing on the old raid1) to the new pv (on raid10). Afte rpvmove is finished (which may take awile, see above), just&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
vgreduce raidtest /dev/md0&lt;br /&gt;
pvremove /dev/md0&lt;br /&gt;
mdadm --stop /dev/md0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
…and your disk is free to be added to the new array. If the new raid is running in degraded mode (if you created it with just one drive), better don&#039;t wait too long, since you don&#039;t have redundancy. Just mdadm --add the devs.&lt;br /&gt;
&lt;br /&gt;
If you now have /dev/mdstat telling you your raid10 is active and have three drives, of which one is a spare, it should look something like this&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5] [raid4] [raid10]&lt;br /&gt;
md1 : active raid10 vdc[3](S) vdb[2] vdd[0]&lt;br /&gt;
      8380416 blocks super 1.2 2 near-copies [2/2] [UU]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Just mdadm --grow --raid-devices=3 /dev/md1&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;RAID section is not complete. I&#039;ll write more on migraing from raid10 to raid6 later. It&#039;s not straight forward, but easier than this one :)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== Thin provisioned LVs ===&lt;br /&gt;
&lt;br /&gt;
Thin provisioning on LVM is a method used for not allocating all the space given to an LV. For instance, if you have a 1TB VG and want to give an LV 500GB, although it currently only uses a fraction of that, a thin lv can be a good alternative. This will allow for adding a limit to how much it can use, but also to let it grow dynamically without manual work by the sysadmin. Thin provisioning adds another layer of abstaction by creating a special LV as a &#039;&#039;thin pool&#039;&#039; from which data is allocated to the &#039;&#039;thin volume(s)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== Create a thin pool ====&lt;br /&gt;
&lt;br /&gt;
Allocate 1TB to the thin pool to be used for thinly provisioned LVs. Keep in mind that the space allocated to the thin pool is in fact thick provisioned. Only the volumes put on &#039;&#039;thinpool&#039;&#039; are thin provisioned. This will create two hidden LVs, one for data and one for metadata. Normally the defaults will do, but check the manual if the data doesn&#039;t match the usual patterns (such as billions of files, resulting in huge amounts of metadata). I &#039;&#039;beleive&#039;&#039; the metadata part should be resizable at a later time if needed, but I have not tested it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a pool for thin LVs. Keep in mind that the pool itself is not thin provisioned, only the volumes residing on it&lt;br /&gt;
lvcreate --size 1T --type thin-pool --thinpool thinpool my_vg&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Create a thin volume ====&lt;br /&gt;
&lt;br /&gt;
You have the thinpool, now put a thin volume on it. It will allocate some space for metadata, but probably not much (a few megs, perhaps).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Now, create a volume with a virtual (-V) size of half a terabyte named thin_pool, but using the thinpool (-T) named thin_pool for storage&lt;br /&gt;
lvcreate -V 500G -T my_vg/thin_pool --name thinvol&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The new volume&#039;s device name will be /dev/thinvol. Now, create a filesystem on it, add to fstab and mount it. The &#039;&#039;&#039;df&#039;&#039;&#039; command will return available space according to the virtual size (-V), while lvs will show how much data is actually used on each of the thinly provisioned volumes.&lt;br /&gt;
&lt;br /&gt;
== Filesystem dilemmas ==&lt;br /&gt;
&lt;br /&gt;
=== XFS or ext4 or something else ===&lt;br /&gt;
The choice of filesystem varies for your use. Distros such as RHEL/CentOS has moved to XFS by default from v7. Debian/Ubuntu still sticks to ext4, like most other. I&#039;ll discuss my thoughts below on ext4 vs XFS and leave the other filesystems for later.&lt;br /&gt;
&lt;br /&gt;
==== ext4 ====&lt;br /&gt;
ext4 is probably the most used filesystem on linux as of writing. It&#039;s rock stable and has been extended by a lot of extensions since the original ext2. It still retains backward compatibility, being able to mount and fsck ext2 and ext3 with the ext4 driver. However, it doesn&#039;t handle large filesystems very well. If a filesystem is created for &amp;lt;16TiB, it cannot be grown to anything larger than 16TiB. This may have changed lately, though. One other issue is handling errors. If a large filesystem (say 10TiB) is damaged, an fsck may take several hours, leading to long downtime. When I refer to ext4 further in this text, the same applies to ext2 and ext3 unless otherwise specified.&lt;br /&gt;
&lt;br /&gt;
==== XFS ====&lt;br /&gt;
XFS, originally developed by SGI some time in the bronze age, but has been worked on heavily after that. RHEL and Centos version 7 and forward, uses XFS as the default filesystem. It is quick, it scales well, but it lacks at least two things ext4 has. It cannot be shrunk (not that you normally need that, but nice if you have a typo or you need to change things). Also, it doesn&#039;t allow for automatic fsck on bootup. If something is messed up on the filesystem, you&#039;ll have to login as root on the console (not ssh), which might be an issue on some systems. The fsck equivalent, xfs_repair, is a *lot* faster than ext4&#039;s fsck, though.&lt;br /&gt;
&lt;br /&gt;
==== ZFS ====&lt;br /&gt;
ZFS is like a combination of RAID, LVM and a filesystem, supporting full checksumming, auto-healing (given sufficient redundancy), compression, encryption, replication, deduplication (if you&#039;re brave and have a &#039;&#039;ton&#039;&#039; of memory) and a lot more. It&#039;s a separate chapter and needs a lot more talk than paragraph here.&lt;br /&gt;
&lt;br /&gt;
==== btrfs ====&lt;br /&gt;
btrfs, pronounced &amp;quot;butterfs&amp;quot; or &amp;quot;betterfs&amp;quot; or just spelled out, is a filesystem that mimics that of ZFS. It has been around for 10 years or so, but hasn&#039;t yet proven to be really stable. Following the progress of it for those years, I&#039;ve found it to be a nice toy with which to play, but not to be used in production. Again, others may say otherwise, but these are just my words.&lt;br /&gt;
&lt;br /&gt;
== Low level disk handling ==&lt;br /&gt;
&lt;br /&gt;
This section is for low-level handling of disks, regardless of storage system elsewhere. These apply to mdraid, lvmraid and zfs and possibly other solutions, with the exception of individual drives on hwraid (and maybe fakeraid), since there, the drives are hidden from Linux (or whatever OS).&lt;br /&gt;
&lt;br /&gt;
=== S.M.A.R.T. and slow drives ===&lt;br /&gt;
Modern (that is, from about 1990 or later) have S.M.A.R.T. (or just smart, since it&#039;s easier to type) monitoring built in, meaning the disk&#039;s controller is monitoring itself. This is handy and will ideally tell you in advance that a drive is flakey or dying. Modern (2010+) smart monitoring is more or less the same. It can be trusted about 50% of the time. Usually, if smart detects an error, it&#039;s a real error. I don&#039;t think I&#039;ve seen it reporting a false positive, but others may know better. &lt;br /&gt;
&lt;br /&gt;
==== smartmontools ====&lt;br /&gt;
First, install smartmontool and run smartclt -H /dev/yourdisk (/dev/sda or something) to get a health report. Then perhaps run smartctl -a /dev/yourdisk and look for &#039;current pending sectors&#039; This should be zero. Also check the temperature, which normally should be much above 50.&lt;br /&gt;
&lt;br /&gt;
==== single, slow drive ====&lt;br /&gt;
What may happen, is smart not seeing anything and life goes on like before, only slower and less prouductive, without telling anyone. If you stubler over this issue, you&#039;ll probably see it during a large rsync/zfs send/receive or a resync/rebuild/resilver of the raid/zpool. During this, it feels like everything is slow and your RAID has turned into a RAIF (redundant array of inexpensive floppies). To check if you have a single drive messing up it all, check with &#039;&#039;&#039;iostat -x 2&#039;&#039;&#039;, having 2 being the delay between each measurement. Interrupt it with ctrl+x. If there&#039;s a rougue drive there, it should stand out like sdg below&lt;br /&gt;
&lt;br /&gt;
 avg-cpu:  %user   %nice %system %iowait  %steal   %idle&lt;br /&gt;
            0.38    0.00    1.75    0.00    0.00   97.87&lt;br /&gt;
&lt;br /&gt;
 Device            r/s     w/s     rkB/s     wkB/s   rrqm/s   wrqm/s  %rrqm  %wrqm r_await w_await aqu-sz rareq-sz wareq-sz  svctm  %util&lt;br /&gt;
 sda              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdb              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdc              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdd              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sde              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdf              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdg              3.50    0.00   2352.00      0.00     0.00     0.00   0.00   0.00 14306.29    0.00  13.85   672.00     0.00 285.71 100.00&lt;br /&gt;
 sdh              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
&lt;br /&gt;
In ZFS land, you should be able to get similar data with &#039;&#039;&#039;zpool iostat -v &amp;lt;pool&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Now you know the bad drive (sdg), pull it from the raid with &#039;&#039;&#039;mdadm --fail /dev/mdX /dev/sdX&#039;&#039;&#039;. Now test the drive&#039;s performance manually, just simply:&lt;br /&gt;
&lt;br /&gt;
 # hdparm -t /dev/sdg&lt;br /&gt;
 &lt;br /&gt;
 /dev/sdg:&lt;br /&gt;
  Timing buffered disk reads:   2 MB in  5.37 seconds = 381.46 kB/sec&lt;br /&gt;
&lt;br /&gt;
Bingo - nothing you&#039;d want to keep. For a good drive, it should be something like 100-200MB/s&lt;br /&gt;
&lt;br /&gt;
PS: Keep in mind that you have a degraded RAID by now in case you had a spare waiting for things to happen.&lt;br /&gt;
&lt;br /&gt;
Try to replace the cable and/or try the disk on another port/controller. If the result from hdparm persists, it&#039;s probably a bad cable&lt;br /&gt;
&lt;br /&gt;
So, then, just psycially locate the drive, pull it out, take out the discs and magnets and recycle the rest.&lt;br /&gt;
&lt;br /&gt;
=== &amp;quot;Unplug&amp;quot; drive from system ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Find the device unit&#039;s number with something like&lt;br /&gt;
find /sys/bus/scsi/devices/*/block/ -name sdd&lt;br /&gt;
# returning /sys/bus/scsi/devices/3:0:0:0/block/sdd here, &lt;br /&gt;
# meaning 3:0:0:0 is the SCSI device we&#039;re looking for.&lt;br /&gt;
&lt;br /&gt;
# Given this is the correct device, and you want to &#039;unplug&#039; it, do so by&lt;br /&gt;
echo 1 &amp;gt; /sys/bus/scsi/devices/3:0:0:0/delete&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Rescan disk controllers ===&lt;br /&gt;
If a drive is added and for some reason doesn&#039;t get detected, or is removed by the command above, it can be rediscovered with a sysfs command to the scsi host to which it is connected. Since there may be quite a few of these, an easy way is to just scan them all and check the output of &#039;&#039;&#039;dmesg -T&#039;&#039;&#039; after running it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Make a list of controllers and send a rescan message to each of them. It won&#039;t do anything &lt;br /&gt;
# for those where nothing has changed, but it will show new drives where they have been added.&lt;br /&gt;
for host_scan in /sys/class/scsi_host/host*/scan&lt;br /&gt;
do&lt;br /&gt;
  echo &#039;- - -&#039; &amp;gt; $host_scan&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Fail injection with debugfs ===&lt;br /&gt;
[https://lxadm.com/Using_fault_injection https://lxadm.com/Using_fault_injection]&lt;br /&gt;
&lt;br /&gt;
== mdadm stuff ==&lt;br /&gt;
=== Resync ===&lt;br /&gt;
To resync a raid, that is, check, run&lt;br /&gt;
&lt;br /&gt;
 echo check &amp;gt; /sys/block/$dev/md/sync_action&lt;br /&gt;
&lt;br /&gt;
where $dev is something like md0. If you have several raids, something like this should work&lt;br /&gt;
&lt;br /&gt;
 for dev in md{0,1}&lt;br /&gt;
 do&lt;br /&gt;
   echo repair &amp;gt; /sys/block/$dev/md/sync_action&lt;br /&gt;
 done&lt;br /&gt;
&lt;br /&gt;
Also useful in a one-liner like&lt;br /&gt;
&lt;br /&gt;
 for dev in md{0,1} ; do echo repair &amp;gt; /sys/block/$dev/md/sync_action ; done&lt;br /&gt;
&lt;br /&gt;
Different raids on different drives will do this in parallel. If the drives are shared somehow with partitions or similar, the check or repair will wait for the other to finish before going on.&lt;br /&gt;
&lt;br /&gt;
As for repair vs check, [https://raid.wiki.kernel.org/index.php/RAID_Administration this article] describes it well. I stick to using repair unless it&#039;s something rare where I don&#039;t want to touch the data.&lt;br /&gt;
&lt;br /&gt;
=== Spare pools ===&lt;br /&gt;
In the old itmes, mdadm supported only a dedicated spare per md device, so if working with a large set of drives (20? 40?), where you&#039;d want to setup more raid sets to increase redundancy, you&#039;d dedicate a spare to each of the raid sets. This has changed (some time ago?), so in these modern, heathen days, you can change mdadm.conf, usually placed under /etc/mdadm, and add &#039;spare-group=somegroup&#039; where &#039;somegroup&#039; is a string identifying the spare group. After doing this, run &#039;&#039;&#039;update-initramfs -u&#039;&#039;&#039; and reboot and add a spare to one of the raid sets in the spare group, and md will use that or those spares for all the raidsets in that group.&lt;br /&gt;
&lt;br /&gt;
As some pointed out on #linux-raid @ irc.freenode.net, this feature is very badly documented, but as far as I can see, it works well.&lt;br /&gt;
&lt;br /&gt;
==== Example config ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create two raidsets&lt;br /&gt;
&lt;br /&gt;
mdadm --create /dev/md1 --level=6 --raid-devices=6 /dev/vd[efghij]&lt;br /&gt;
mdadm --create /dev/md2 --level=6 --raid-devices=6 /dev/vd[klmnop]&lt;br /&gt;
&lt;br /&gt;
# get their UUID etc&lt;br /&gt;
&lt;br /&gt;
mdadm --detail --scan&lt;br /&gt;
ARRAY /dev/md/1 metadata=1.2 name=raidtest:1 UUID=1a8cbdcb:f4092350:348b6b80:c054d74c&lt;br /&gt;
ARRAY /dev/md/2 metadata=1.2 name=raidtest:2 UUID=894b1b7c:cb7eba70:917d6033:ea5afd2b&lt;br /&gt;
&lt;br /&gt;
# Put those lines into /etc/mdadm/mdadm.conf and and add the spare-group&lt;br /&gt;
&lt;br /&gt;
ARRAY /dev/md/1 metadata=1.2 name=raidtest:1 spare-group=raidtest UUID=1a8cbdcb:f4092350:348b6b80:c054d74c&lt;br /&gt;
ARRAY /dev/md/2 metadata=1.2 name=raidtest:2 spare-group=raidtest UUID=894b1b7c:cb7eba70:917d6033:ea5afd2b&lt;br /&gt;
&lt;br /&gt;
# update the initramfs and reboot&lt;br /&gt;
&lt;br /&gt;
update-initramfs -u&lt;br /&gt;
reboot&lt;br /&gt;
&lt;br /&gt;
# add a spare drive to one of the raids&lt;br /&gt;
&lt;br /&gt;
mdadm --add /dev/md1 /dev/vdq&lt;br /&gt;
&lt;br /&gt;
# fail a drive on the other raid&lt;br /&gt;
&lt;br /&gt;
mdadm --fail /dev/md2 /dev/vdn&lt;br /&gt;
&lt;br /&gt;
# check /proc/mdstat to see md2 rebuilding with the spare from md1&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Recovery ===&lt;br /&gt;
&lt;br /&gt;
The other day, I came across a problem a user had on #linux-raid@irc.freenode.net. He had an old Qnap NAS that had died and tried plugging the drives in to his Linux machine and got various errors. The two-drive RAID-1 did not come up as it should, &#039;&#039;&#039;dmesg&#039;&#039;&#039; was full of errors from one of the drives (both connected on USB) and so forth.&lt;br /&gt;
&lt;br /&gt;
We went on and started by taking down the machine and just connecting one of the drives. I had him check what was assembled with&lt;br /&gt;
&lt;br /&gt;
 cat /proc/mdstat&lt;br /&gt;
&lt;br /&gt;
That returned /proc/md127 assembled, but LVM didn&#039;t find anything. So running a manual scan&lt;br /&gt;
&lt;br /&gt;
 pvscan --cache /dev/md127&lt;br /&gt;
&lt;br /&gt;
This made linux find the PV, VG and a couple of LVs, but probably because the mdraid was degraded, the LVs were deactivated, according to &#039;&#039;&#039;lvscan&#039;&#039;&#039;. Activating the one with a filesystem manually&lt;br /&gt;
&lt;br /&gt;
 lvchange -a y /dev/&amp;lt;vg&amp;gt;/&amp;lt;lv&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Substitute &amp;lt;vg&amp;gt; and &amp;lt;lv&amp;gt; with the names listed by vgs and lvs.&lt;br /&gt;
&lt;br /&gt;
This worked, and the filesystem on /dev/&amp;lt;vg&amp;gt;/&amp;lt;lv&amp;gt; could be mounted correctly.&lt;br /&gt;
&lt;br /&gt;
== Tuning ==&lt;br /&gt;
&lt;br /&gt;
While trying to compare a 12-disk RAID (8TB disks) to a hwraid, mdraid was slower, so we did a few things to speed things up:&lt;br /&gt;
&lt;br /&gt;
While testing with [https://linux.die.net/man/1/fio fio], monitor /sys/block/md0/md/stripe_cache_active, and see if it&#039;s close to /sys/block/md0/md/stripe_cache_size. If it is, double the size of the latter&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
echo 4096 &amp;gt; /sys/block/md0/md/stripe_cache_size&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Continue until stripe_cache_active stabilises, and then you&#039;ve found the limit you&#039;ll need. You may want to double that for good measure. &lt;br /&gt;
&lt;br /&gt;
(to be continued)&lt;br /&gt;
&lt;br /&gt;
== Links ==&lt;br /&gt;
&lt;br /&gt;
Below are a few links with useful info&lt;br /&gt;
&lt;br /&gt;
* [https://raid.wiki.kernel.org/index.php/Irreversible_mdadm_failure_recovery Irreversible mdadm failure recovery]&lt;br /&gt;
&lt;br /&gt;
= ZFS =&lt;br /&gt;
&lt;br /&gt;
ZFS can do a lot of things most filesystems or volume managers can&#039;t. It checksums all data and metadata and so long that the system uses ECC enabled memory (RAM), it will have complete control over the whole data set, and when (not if) an error occurs, it&#039;ll fix the issue without even throwing a warning. To fix the issue, you&#039;ll obviously need sufficient redundancy (mirrors or RAIDzN). &lt;br /&gt;
&lt;br /&gt;
== ZFS send/receive between machines ==&lt;br /&gt;
&lt;br /&gt;
ZFS has a send/receive mechanism that allows for snapshots to be sent over the wire to a receiving end. This can be a full filesystem, or an incremental change since last send/reveive. In a WAN scenario, you&#039;ll probably want to use VPN for this. On a controlled network, sending in cleartext is also possible. You may as well use ssh, but keep in mind that ssh was never designed to be used as a fullblown vpn solution and is just too slow or the task with large amounts of data. You may, though, use mbuffer, if on a loal LAN.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Allow traffic from the sending IP in whatever firewall interface you&#039;re using (if you&#039;re using a firewall at all, that is)&lt;br /&gt;
ufw allow from x.x.x.x&lt;br /&gt;
# &lt;br /&gt;
# Start the receiver first. This listens on port 9090, has a 1GB buffer,&lt;br /&gt;
    and uses 128kb chunks (same as zfs):&lt;br /&gt;
&lt;br /&gt;
mbuffer -s 128k -m 1G -I 9090 | zfs receive data/filesystem&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To be continued one day… See [https://everycity.co.uk/alasdair/2010/07/using-mbuffer-to-speed-up-slow-zfs-send-zfs-receive/ this] for some more. I&#039;ll get back with details on it.&lt;br /&gt;
&lt;br /&gt;
= General Linux system control =&lt;br /&gt;
&lt;br /&gt;
== Add a new CPU (core) ==&lt;br /&gt;
&lt;br /&gt;
If working with virtual machines, adding a new core can be useful if the VM is slow and the load is multithreaded or multiprocess. To do this, add a new CPU in the hypervisor (be it KVM or VMware or Hyper-V or whatever). Some hypervisors, like VMware, will activate it automatically if open-vm-tools is installed. Please note that open-vm-tools is for VMware only. I don&#039;t know of any such thing for KVM or other hypervisors (although I beleive VirtualBox has its own set of tools, but not as a package). If this doesn&#039;t work, run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
echo 1 &amp;gt; /sys/devices/system/cpu/cpuX/online&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where X is the CPU number you want to add. You can &#039;cat /sys/devices/system/cpu/cpuX/online&#039; to check if it&#039;s online.&lt;br /&gt;
&lt;br /&gt;
= Mount partitions on a disk image =&lt;br /&gt;
&lt;br /&gt;
Sometimes you&#039;ll have a disk image, either from recovering a bad drive after hours (or days or weeks) of ddrescue, and sometimes you just have a disk image from a virtual machine where you want to mount the partitions inside the image. There are three main methods of doing this, which are more or less synonmous, but some easier than the other.&lt;br /&gt;
&lt;br /&gt;
== Basics ==&lt;br /&gt;
&lt;br /&gt;
A disk image is usually like a disk, consisting of either a large filesystem, a PV or a partition table with one or partitions onto which resides a filesystem, a pv, swap or something else. If it&#039;s partitioned, and you want your operating system to mount a filesystem or allow it to see whatever LVM stuff lies on it, you need to isolate the partitions. &lt;br /&gt;
&lt;br /&gt;
== Manual mapping ==&lt;br /&gt;
&lt;br /&gt;
In the oldern days, this was done manually, something like this&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
root@mymachine:~# fdisk -l /dev/vda&lt;br /&gt;
Disk /dev/vda: 25 GiB, 26843545600 bytes, 52428800 sectors&lt;br /&gt;
Units: sectors of 1 * 512 = 512 bytes&lt;br /&gt;
Sector size (logical/physical): 512 bytes / 512 bytes&lt;br /&gt;
I/O size (minimum/optimal): 512 bytes / 512 bytes&lt;br /&gt;
Disklabel type: dos&lt;br /&gt;
Disk identifier: 0xc37b7ea5&lt;br /&gt;
&lt;br /&gt;
Device     Boot    Start      End  Sectors  Size Id Type&lt;br /&gt;
/dev/vda1  *        2048 50333311 50331264   24G 83 Linux&lt;br /&gt;
/dev/vda2       50333312 52426369  2093058 1022M  5 Extended&lt;br /&gt;
/dev/vda5       50333314 52426369  2093056 1022M 82 Linux swap / Solaris&lt;br /&gt;
root@mymachine:~#&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To calculate the start and end of each partition, you just take the start sector and multiply it by the sector size (512 bytes here) and you have the offset in bytes. After this, it&#039;s merely an losetup -o &amp;lt;offset&amp;gt; /dev/loopX &amp;lt;nameofimagefile&amp;gt; and you have the partition mapped to your /dev/loopX (having X being something typically 0-255. After this, just mount it or run pvscan/vgscan/lvscan to probe whatever lvm config is there, and you should be able to mount it like any other filesystem.&lt;br /&gt;
&lt;br /&gt;
== kpartx ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;kpartx&#039;&#039;&#039; does the same as above, more or less, just without so much hassle. Most of it should be automatic and easy to deal with, except it may fail to disconnect the loopback devices sometimes, so you may have to &#039;&#039;&#039;losetup -d&#039;&#039;&#039; them manually. See the manual, &#039;&#039;&#039;kpartx (8)&#039;&#039;&#039;. Please note that &#039;&#039;&#039;partx&#039;&#039;&#039; works similarly and I&#039;d guess the authors of the two tools are arguing a lot of which one&#039;s the best.&lt;br /&gt;
&lt;br /&gt;
== guestmount ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;guestmount&#039;&#039;&#039; is something similar again, but also supports file formats like &#039;&#039;&#039;qcow2&#039;&#039;&#039; and possibly other, proprietary filesystems like &#039;&#039;&#039;vmdk&#039;&#039;&#039; and &#039;&#039;&#039;vdi&#039;&#039;&#039;, but don&#039;t take my word for it - I haven&#039;t tested. Again, see the manual or just read up on the description [http://ask.xmodulo.com/mount-qcow2-disk-image-linux.html?fbclid=IwAR3snTeZvGzp9PLdX11EQhCfOpux6I93CiJ3A2pUomkkRLly9Xo4851mkTY here]. It seems rather trivial.&lt;br /&gt;
&lt;br /&gt;
= Linux on laptops =&lt;br /&gt;
&lt;br /&gt;
== Wifi with HP EliteBook 725/745 on Ubuntu ==&lt;br /&gt;
&lt;br /&gt;
The HP EliteBook 725/745 and similar are equipped with a BCM4352 wifi chip. As with a lot of other stuff from Broadcom, this lacks an open hardware description, so thus no open driver exist. The proper fix, is to replace the NIC with something with an open driver, but again, this isn&#039;t always possible, so a binary driver exists. In ubuntu, run, somehow connect the machine to the internet and run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install bcmwl-kernel-source&lt;br /&gt;
sudo modprobe wl&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you can&#039;t connect the machine to the internet, download the needed packages on another machine and put it on some usb storage. These packages should suffice:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# apt-cache depends bcmwl-kernel-source&lt;br /&gt;
bcmwl-kernel-source&lt;br /&gt;
  Depends: dkms&lt;br /&gt;
  Depends: linux-libc-dev&lt;br /&gt;
  Depends: libc6-dev&lt;br /&gt;
  Conflicts: &amp;lt;bcmwl-modaliases&amp;gt;&lt;br /&gt;
  Replaces: &amp;lt;bcmwl-modaliases&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then install manually with &#039;&#039;&#039;dpkg -i file1.deb file2.deb&#039;&#039;&#039; etc&lt;br /&gt;
&lt;br /&gt;
After this, ip/ifconfig/iwconfig shouldd see the new wifi nic, probably &#039;&#039;&#039;wlan0&#039;&#039;&#039;, but due to a [https://bugs.launchpad.net/ubuntu/+source/broadcom-sta/+bug/1343151 old, ignored bug], you won&#039;t find any wifi networks. This is because the driver from Broadcom apparently does not support interrupt remapping, commonly used on x64 machines. To turn this off, change &#039;&#039;&#039;/etc/default/grub&#039;&#039;&#039; and change the line &#039;&#039;&#039;GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;quiet splash&amp;quot;&#039;&#039;&#039;, adding intremap=off to the end before the quote: &#039;&#039;&#039;GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;quiet splash intremap=off&amp;quot;&#039;&#039;&#039;. Save the file and run &#039;&#039;&#039;sudo update-grub&#039;&#039;&#039; and reboot. After this, wifi should work well.&lt;br /&gt;
&lt;br /&gt;
== Wifi with HP Compaq Presario CQ57 on Ubuntu ==&lt;br /&gt;
&lt;br /&gt;
The HP Compaq Presario CQ57 uses the RT5390 wifi chipset. This has been supported for quite some time now, and I was quite surprised to find it not working on a laptop a friend was having. The driver loaded correctly, but Ubuntu insisted of the laptop being in &#039;&#039;&#039;flight mode&#039;&#039;&#039;. Checking &#039;&#039;&#039;rfkill&#039;&#039;&#039;, it showed me two NICs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# rfkill list all&lt;br /&gt;
0: phy0: Wireless LAN&lt;br /&gt;
	Soft blocked: no&lt;br /&gt;
	Hard blocked: yes&lt;br /&gt;
1: hp-wifi: Wireless LAN&lt;br /&gt;
	Soft blocked: yes&lt;br /&gt;
	Hard blocked: no&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Turning rfkill on and off resulted in nothing much, except some error messages in the kernel log (dmesg)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] ACPI Error: Field [B128] at bit offset/length 128/1024 exceeds size of target Buffer (160 bits) (20170831/dsopcode-235)&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]&lt;br /&gt;
                            Initialized Local Variables for Method [HWCD]:&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Local0: 00000000a34b7928 &amp;lt;Obj&amp;gt;           Integer 0000000000000000&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Local1: 00000000b0aa6865 &amp;lt;Obj&amp;gt;           Buffer(8) 46 41 49 4C 04 00 00 00&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Local5: 00000000a9811efd &amp;lt;Obj&amp;gt;           Integer 0000000000000004&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] Initialized Arguments for Method [HWCD]:  (2 arguments defined for method invocation)&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Arg0:   0000000078957d1b &amp;lt;Obj&amp;gt;           Integer 0000000000000001&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Arg1:   00000000725c9c6e &amp;lt;Obj&amp;gt;           Buffer(20) 53 45 43 55 02 00 00 00&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] ACPI Error: Method parse/execution failed \_SB.WMID.HWCD, AE_AML_BUFFER_LIMIT (20170831/psparse-550)&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] ACPI Error: Method parse/execution failed \_SB.WMID.WMAD, AE_AML_BUFFER_LIMIT (20170831/psparse-550)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After upgrading BIOS and testing different kernels, I was asked to try to unload the &#039;&#039;&#039;hp_wmi&#039;&#039;&#039; driver. I did, and things changed a bit, so I tried blacklisting it, creating the file &#039;&#039;&#039;/etc/modprobe.d/blacklist-hp_wmi.conf&#039;&#039;&#039; with the following content&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Blacklist this - it doesn&#039;t work!&lt;br /&gt;
blacklist hp_wmi&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
I gave the machine a reboot and afte that, the &#039;&#039;&#039;hp-wifi&#039;&#039;&#039; entry was gone in the rfkill output, and things works.&lt;br /&gt;
&lt;br /&gt;
= Raspberry pi =&lt;br /&gt;
&lt;br /&gt;
I couldn&#039;t quite decide if the raspberry pi should be a separate section or part of Linux, but hell, it can run more than Linux, although 99,lots% of people just uses Linux on them. This is a small list of things to know about them; things not on the front page of the manual or perhaps hidden even better.&lt;br /&gt;
&lt;br /&gt;
== Which pi? ==&lt;br /&gt;
&lt;br /&gt;
I just setup three raspberry pi machines and although some are quite different, like v1 to vEverythingelse or the Pi zero versions to the normal ones, not all of us remember how to distinguish between them, and sometimes they&#039;re in a nice 3d printed (or otherwise) chassis or otherwise hidden. So, how to check three different ones:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
root@home-assistant:~ $ cat /proc/device-tree/model ; echo&lt;br /&gt;
Raspberry Pi 2 Model B Rev 1.1&lt;br /&gt;
&lt;br /&gt;
root@green-pi:~ $ cat /proc/device-tree/model ; echo&lt;br /&gt;
Raspberry Pi 3 Model B Rev 1.2&lt;br /&gt;
&lt;br /&gt;
roy@yellow-pi:~ $cat /proc/device-tree/model ; echo&lt;br /&gt;
Raspberry Pi 4 Model B Rev 1.1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
While this works well, for the latter, the pi4, it doesn&#039;t tell how much memory I have. It comes in variants of 1, 2 and 4GB, and this is the latter.&lt;br /&gt;
&lt;br /&gt;
== Monitoring ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;vcgencmd&#039;&#039;&#039; from &#039;&#039;&#039;/opt/vc/bin&#039;&#039;&#039;, but symlinked to &#039;&#039;&#039;/usr/bin&#039;&#039;&#039; so it&#039;s available in path, is useful for fetching hardware info about the pi. For example, measuring the temperature&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
root@yellow-pi:~# vcgencmd measure_temp&lt;br /&gt;
temp=63.0&#039;C&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The command is generally badly documented and parts of it seems outdated for newer hardware. Here&#039;s the output from a Raspberry pi 4 with 4GB RAM&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
roy@yellow-pi:~ $ vcgencmd get_mem arm&lt;br /&gt;
arm=948M&lt;br /&gt;
roy@yellow-pi:~ $ vcgencmd get_mem gpu&lt;br /&gt;
gpu=76M&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= BIOS upgrade from Linux =&lt;br /&gt;
&lt;br /&gt;
Generally, BIOS upgrades have been moved to the BIOS itself these days. This saves a lot of work and quite possibly lives after those who earier rammed their heads through walls, now can upgrade directly from the internet instead of using obscure operating systems best avoided. Sometimes, however, one must use these nevertheless. This is a quick run-through on your options.&lt;br /&gt;
&lt;br /&gt;
== DOS ==&lt;br /&gt;
&lt;br /&gt;
Most non-automatic BIOS upgrades are installed from DOS. Doing a BIOS upgrade this way, is generally non-problematic. Just install a USB thingie with [https://www.freedos.org/ FreeDOS], copy your file(s) onto the thing and boot on it. The commandline is the same as old MS/DOS, except a wee bit more userfriendly, but not a lot.&lt;br /&gt;
&lt;br /&gt;
== Windows ==&lt;br /&gt;
&lt;br /&gt;
Some macahines, like laptops from &#039;&#039;&#039;HP&#039;&#039;&#039;, may have BIOS upgrades that are made to be installed from Windows and won&#039;t run in FreeDOS or MS/DOS, instead throwing an error, saying &#039;&#039;&#039;This program cannot be run in DOS mode&#039;&#039;&#039;. This means you&#039;ll have to boot on a Windows rescue disc and do the job from there. Googling this, tells you it&#039;s quite easy, you just choose &#039;make rescue disc&#039; from Windows, and it&#039;s all good, except if you don&#039;t run Windows, that is. To remedy this problem, do as follows:&lt;br /&gt;
&lt;br /&gt;
=== Download Windows ===&lt;br /&gt;
&lt;br /&gt;
Since you don&#039;t run Windows and possibly don&#039;t have a spouse or friend around with such unhealthy habits either, you need to get it. It&#039;s quite easy - just google &#039;download windows&#039; and it&#039;ll send you to [https://www.microsoft.com/en-us/software-download/windows10ISO somewhere like this].&lt;br /&gt;
&lt;br /&gt;
=== Burn it! ===&lt;br /&gt;
&lt;br /&gt;
Now it&#039;s time to burn the installer on a DVD ROM. You&#039;ll need a double-layered one, since the OS is &amp;gt; 4.7GiB, but I&#039;m sure you have a ton of those lying around. Now, just place your optical medium in your optical drive and burn, baby, burn!&lt;br /&gt;
&lt;br /&gt;
=== Or make a USB thing? ===&lt;br /&gt;
&lt;br /&gt;
Not a lot of machines have optical drives these days, so you may want to use an USB pen drive or something instead. This is easy, just make the USB bootable with the Windows application Microsoft has made for this. Unfortunately, this only runs on Windows, and unlike stuff like Debian, where the &#039;&#039;&#039;iso&#039;&#039;&#039; file can be dd&#039;ed directly onto a USB drive to make it bootable, the Windows &#039;&#039;&#039;iso&#039;&#039;&#039;s don&#039;t come with this luxury. There are lots of methods to make bootable USB things from iso files out there, but the only thing most of them have in common, is that they generally don&#039;t work.&lt;br /&gt;
&lt;br /&gt;
==== WoeUSB ====&lt;br /&gt;
&lt;br /&gt;
After hours of swearing, it&#039;s nice to come across software like [https://github.com/slacka/WoeUSB WoeUSB]. It may not be perfect, it relies on a bunch of GUI stuff you&#039;ll never need and so on, but it &#039;&#039;&#039;&#039;&#039;works&#039;&#039;&#039;&#039;&#039;, and that&#039;s the important part! Just clone the repo and RTFM and it&#039;s all nice. It&#039;s slow, but hell, getting a windows machine and/or an optical drive might be slower.&lt;br /&gt;
&lt;br /&gt;
WoeUSB does nothing fancy, but it &#039;&#039;&#039;does&#039;&#039;&#039; work. It will create a filesystem, FAT32 or NTFS (better use NTFS, FAT32 has its limits). It creates normal filesystems and so on. Just make sure to copy in the BIOS update file, usually an exe file, to run when Windows is up and running.&lt;br /&gt;
&lt;br /&gt;
==== Install BIOS ====&lt;br /&gt;
&lt;br /&gt;
Boot on the Windows USB thing and choose &#039;repair computer&#039; and then &#039;command prompt&#039;. Find the install file, and if you&#039;re lucky, you&#039;ll find it needs a 32bit OS, just like I did. Since the 64bit version doesn&#039;t include 32bit compatibility in the installer, revert to downloading the 32bit version of windows and start over. Pray to your favourite god(s) not to get across such machines again - it might help.&lt;br /&gt;
&lt;br /&gt;
= 3D printer stuff =&lt;br /&gt;
&lt;br /&gt;
== Hydrophilic filament ==&lt;br /&gt;
&lt;br /&gt;
Most popular filament types, including PLA, PETG, PP or PA (Polyamide, normally known as Nylon) and virtualy any filament type named [https://www.matterhackers.com/news/filament-and-water poly-something] (and thus with an acronym of P-something) are hydrophilic (also (somewhat incorrectly) called hydroscopic), meaning so long they&#039;re dryer than the atmosphere around them, they&#039;ll do their best to suck out the atmosphere&#039;s humidity. This is why most filament are shrink-wrapped with a small bag of silica gel in it. If such filament is exposed for normal humid air for some time, it&#039;ll become very hard to use. Most of my experience is with PLA, which can handle a bit (depending on make), but still not a lot. With PLA, if you end up with prints where the filament seems not to stick, it may help with a higher temperature. Otherwise, the filament must be [https://all3dp.com/2/how-to-dry-filament-pla-abs-and-nylon/ baked]. If you don&#039;t want to use your oven, try something like a [https://www.jula.no/catalog/hjem-og-husholdning/kjokkenmaskiner/mattilberedningsapparater/frukt-sopptorker/frukt-sopptorker-001641/#tab02 fruit and mushroom dryer]. Then get a good, sealble plastic box and add something like half a kilogram of [https://www.ebay.com/sch/sis.html?_nkw=1KG+Orange+Replacement+Desiccant+Indicating+Silica+Gel+Beads+for+Drawers%2C+Camera&amp;amp;_id=131938742628&amp;amp;&amp;amp;_trksid=p2057872.m2749.l2658 silica gel] to an old sock, tie it and put it in the your new dry box.&lt;br /&gt;
&lt;br /&gt;
Please note that ABS is hydrophobic, so you won&#039;t have to worry too much there. Also, remember that PA/Nylon is extremely hydrophilic. Even a couple of days in normal air humidity can ruin it completely and will require baking.&lt;br /&gt;
&lt;br /&gt;
== Upgrading the firmware on an Ender 3 ==&lt;br /&gt;
&lt;br /&gt;
This is about upgrading the firmware, and thus also flashing a bootloader to the Creality Ender 3 3D printer. Most of this is well documented on several place, like o [https://www.youtube.com/watch?v=fIl5X2ffdyo the video from Teaching tech] and elsewhere, but I&#039;ll just summarise some issues I had.&lt;br /&gt;
&lt;br /&gt;
=== Using an arduino Nano as a programmer ===&lt;br /&gt;
&lt;br /&gt;
Quick note before you read on. If you have an Ender 3 controller version 1.1.5 or newer (or perhaps even a bit older), a CR-10S or some other more or less modern printers or controllers, they come with a bootloader installed already, so don&#039;t bother flashing one. The one that&#039;s in there already, should work well. So if you have one of these, just skip this and jump to the [[Roy&#039;s_notes#Flashing_the_printer|next section]].&lt;br /&gt;
&lt;br /&gt;
However, the normal CR-10 (without the S), Ender 3 and a few other printers from Creality come without a bootloader, so you&#039;ll need to flash one before upgrading the firmware. Well, strictly speakning, you don&#039;t need one, you can save those 8kB or so for other stuff and use a programmer to write the whole firmware, but then you&#039;ll need to wire up everything every time you want a new firmware, so in my world, you &#039;&#039;&#039;do&#039;&#039;&#039; need the bootloader, since it&#039;s easier.&lt;br /&gt;
&lt;br /&gt;
To install a bootloader, you&#039;ll need a programmer, and I didn&#039;t have one available. Having some el-cheapo china-copies of Arduinos around, I read I could use one and tried so. Although the docs mostly mention the Uno etc, it&#039;s just as simple with the Nano copy.&lt;br /&gt;
&lt;br /&gt;
So, grab an arduino, plug it to your machine with a USB cable, and, using the Arduino IDE, use the ArduinoISP sketch there (found under Examples) to burn the software needed for the arduino to work as a programmer. When this is done, connect a 10µF capacitor between RST and GND to stop it from resetting when used as a programmer. Connect the MOSI, MISO and SCK pins from the ICSP block (that little isolated 6-pin block on top of the ardu). See [https://www.arduino.cc/en/Tutorial/ArduinoISP here] for a pinout. Then find Vcc and GND either on the ICSP block or elsewhere. Some sites say that on some boards you shouldn&#039;t use the pins on the ICSP block for this. I doubt it matters, though. Then connect another jumper wire from pin 10 on the ardu to work as the reset pin outwards to the chip being programmed (that is, on the printer). The ICSP jumper block pin layout is the same on the printer and on the ardu, and probably elsewhere. Sometimes [https://xkcd.com/927/ standardisation] actually works…&lt;br /&gt;
&lt;br /&gt;
See https://cloud.karlsbakk.net/index.php/s/zw48YJjzaf8Rc2F for a pic with the ardu (this wiki is broken atm, will fix it later)&lt;br /&gt;
&lt;br /&gt;
== Flashing the printer ==&lt;br /&gt;
&lt;br /&gt;
When the boot loader is in place, possibly after some wierd errors from during the process, the screen on the 3d printer will go blank and it&#039;ll behave like being bricked. This is ok. Now disconnect the wires and connect the USB cable between computer and printer. If you haven&#039;t installed support for the Sanguino board, that is, the variant of the 1284-chip and surrounding electronics that is the core of the, you need to install it first. In the Arduino IDE, choose the Tools / Boards / Boards manager boot option and search for Sanguino. After this, you should find the Sanguino or Sanguino 1284p in the boards menu. After this, you should be able to communicate with the printer&#039;s controller. Download the [https://www.th3dstudio.com/knowledgebase/th3d-unified-firmware-package/ TH3D unified firmware], making sure it&#039;s the last version. Uncompress the zip and with Finder/Explorer/whateversomething&#039;scalledonlinux, browse to &#039;&#039;&#039;TH3DUF_R2/Firmware/TH3DUF_R2.ino&#039;&#039;&#039; and open it. It should open directly in the Android IDE. Keep in mind that the names TH3DUF_R2 and TH3DUF_R2.ino will vary between versions, but you get the point. Now configure it for your particular needs. You&#039;ll find most of this in the Configuration.h tab (that&#039;s really a file). Most of the other files won&#039;t be necessary unless you&#039;re doing some more advanced stuff, like replacing th controller with something non-standard or similar, but then again, that&#039;s another chapter (or book, even). The video mentioned above describes this well. After flashing the new firmware, you&#039;ll probably get some timeouts and errors, since apparently it resets the printer after giving it the new firmware, but without notifying the flashing software of it doing so. If this happens, calm down and reboot the printer and check its tiny monitor - it should work. If it doesn&#039;t work, and if you flashed the bootload yourself, try to flash it again, and if that doesn&#039;t work, try flashing the programmer again yet another time, just for kicks. Again, if you have a newer controller like the v1.1.5, don&#039;t touch the bootloader, as the one already installed, should work well as it is.&lt;br /&gt;
&lt;br /&gt;
PS: I tried enabling &#039;&#039;&#039;MANUAL_MESH_LEVELING&#039;&#039;&#039;, which in the code says that &#039;&#039;If used with a 1284P board the bootscreen will be disabled to save space&#039;&#039;. This effectively disabled the whole printer, and apparently may be making the firmware image a wee bit too large for it to fit the 1284P on the ender. It works well without it, though, and it may be fixed by now, since I tested this back in early 2019.&lt;br /&gt;
&lt;br /&gt;
== And then… ==&lt;br /&gt;
&lt;br /&gt;
With the new firmware in place, the printer should work as before, although with thermal runaway protection to better avoid fires in case the shit hits the fan, and to allow for things like autolevelling. With any luck, [https://www.precisionpiezo.co.uk/ this thing] may be ready for use by the time you read this - it surely looks nice!&lt;br /&gt;
&lt;br /&gt;
= Octoprint/Octopi =&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;This could have been under some other section, but again, I just branch out even though most of it is about sections mentioned elsewhere.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
When setting up a 3d printer for the first time, you usually get an SD card for storage and transfer data to the printer using [https://en.wikipedia.org/wiki/Sneakernet Sneakernet]. Some printers use micro SD cards, while other fullsize SD cards, which imho is better, since they don&#039;t get lost that easily, but otherwise do the same thing. This works, but is somewhat tedious. If you want to control the printer from a PC or phone, there&#039;s a simple trick for that as well - octoprint.&lt;br /&gt;
&lt;br /&gt;
[https://octoprint.org/ Octoprint], written by Gina Häußge, runs on most platforms including linux, windows, BSD*, macos etc. It supports controlling a camera to some extent out of the box and there&#039;s a large number of plugins availablee to do a lot of things you possibly haven&#039;t thought of (and quite often, you&#039;d ever need). The easiest way to install it, is to just grab a Raspberry pi - preferably some of the newer models (will get to that later) and download [https://octoprint.org/download/ octopi] and follow the instructions on that page.&lt;br /&gt;
&lt;br /&gt;
== Performance issues ==&lt;br /&gt;
&lt;br /&gt;
Some report (and I have seen it myself) issues with the pi&#039;s performance with regards to both handling the octoprint processes (which should be as close to realtime as possible) and handling other stuff like I/O, networking etc. The point is that at pi3 or older, has all peripherals connected to an internal USB hub. This might be practical, but performance-wise it&#039;s &#039;&#039;&#039;&#039;&#039;not&#039;&#039;&#039;&#039;&#039;. If you in addition connect a webcam to USB, you&#039;re asking for trouble, since USB will be your bottleneck. With a raspberry pi camera, the ones connected to the pi directly with a ribbon cable, this should not use USB, so it&#039;s better. Still, again, for older pi&#039;s, there might be some shortage in therms of cpu or i/o. The octopi runs something like raspbian which is a fork of debian which is a linux distro, so it all boils down to knowing linux.&lt;br /&gt;
&lt;br /&gt;
Your typical octopi will run octoprint, a streamer, usually &#039;&#039;&#039;mjpg-streamer&#039;&#039;&#039;, a simple, lightweight videostreamer that outputs a stream of jpeg-images (about the same format as cinemas use - that is - not MPEG). This may be a bit tough on the cpu and potentially i/o. Add inn a dash over USB overload and you&#039;re booked for a flight of trouble.&lt;br /&gt;
&lt;br /&gt;
Still - a pi3 should be able to handle the load, but it might help to prioritise corretly. The octoprint process is the important part here, so we could give that full priority both in CPU and I/O and. Unfortunately, it doesn&#039;t seem like the current octopi has been migrated to using systemd for the startup. We&#039;ll deal with this later. To fix this in the old SysV init style file present there, the following patch should work against the file /etc/init.d/octoprint&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;diff&amp;quot;&amp;gt;&lt;br /&gt;
--- octoprint.old	2020-07-20 18:46:10.166651965 +0200&lt;br /&gt;
+++ octoprint	2020-07-20 18:53:21.724803211 +0200&lt;br /&gt;
@@ -22,6 +22,9 @@&lt;br /&gt;
 PIDFILE=/var/run/$NAME.pid&lt;br /&gt;
 PKGNAME=octoprint&lt;br /&gt;
 SCRIPTNAME=/etc/init.d/$PKGNAME&lt;br /&gt;
+NICELEVEL=-19                        # Top CPU priority&lt;br /&gt;
+IONICE_CLASS=1                       # Realtime I/O class&lt;br /&gt;
+IONICE_PRIORITY=0                    # Realtime I/O priority (probably not needed with class=realtime)&lt;br /&gt;
&lt;br /&gt;
 # Read configuration variable file if it is present&lt;br /&gt;
 [ -r /etc/default/$PKGNAME ] &amp;amp;&amp;amp; . /etc/default/$PKGNAME&lt;br /&gt;
@@ -70,10 +73,11 @@&lt;br /&gt;
&lt;br /&gt;
    is_alive $PIDFILE&lt;br /&gt;
    RETVAL=&amp;quot;$?&amp;quot;&lt;br /&gt;
-&lt;br /&gt;
    if [ $RETVAL != 0 ]; then&lt;br /&gt;
        start-stop-daemon --start --background --quiet --pidfile $PIDFILE --make-pidfile \&lt;br /&gt;
-       --exec $DAEMON --chuid $OCTOPRINT_USER --user $OCTOPRINT_USER --umask $UMASK -- serve $DAEMON_ARGS&lt;br /&gt;
+       --exec $DAEMON --chuid $OCTOPRINT_USER --user $OCTOPRINT_USER --umask $UMASK \&lt;br /&gt;
+       --nicelevel $NICELEVEL --ioched $IONICE_CLASS:$IONICE_PRIORITY \&lt;br /&gt;
+       --serve $DAEMON_ARGS&lt;br /&gt;
        RETVAL=&amp;quot;$?&amp;quot;&lt;br /&gt;
    fi&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This ismply upgrades the process to be allowed to use most of the resources on the pi, regardless of what other processes are whining about.&lt;br /&gt;
&lt;br /&gt;
PS: Code not tested - I don&#039;t have a pi right here. Will test later, but I&#039;m pretty sure it&#039;ll work. After all, it&#039;s just a few new arguments to start-stop-daemon&lt;br /&gt;
&lt;br /&gt;
roy&lt;/div&gt;</summary>
		<author><name>Roy</name></author>
	</entry>
	<entry>
		<id>https://wiki.malinux.no/index.php?title=Roy%27s_notes&amp;diff=166</id>
		<title>Roy&#039;s notes</title>
		<link rel="alternate" type="text/html" href="https://wiki.malinux.no/index.php?title=Roy%27s_notes&amp;diff=166"/>
		<updated>2020-07-20T17:01:04Z</updated>

		<summary type="html">&lt;p&gt;Roy: /* Octoprint/Octopi */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= LVM, md and friends =&lt;br /&gt;
&lt;br /&gt;
== Linux&#039; Logical Volume Manager (LVM) ==&lt;br /&gt;
&lt;br /&gt;
=== LVM in general ===&lt;br /&gt;
&lt;br /&gt;
LVM is designed to be an abstraction layer on top of physical drives or RAID, typically [https://raid.wiki.kernel.org/index.php/RAID_setup mdraid] or [https://help.ubuntu.com/community/FakeRaidHowto fakeraid]. Keep in mind that fakeraid should be avoided unless you really need it, like in conjunction with dual-booting linux and windows on fakeraid. LVM broadly consists of three elements, the &amp;quot;physical&amp;quot; devices (PV), the volume group (VG) and the logical volume (LV). There can be multiple PVs, VGs and LVs, depending on requirement. More about this below. All commands are given as examples, and all of them can be fine-tuned using extra flags in need of so. In my experience, the defaults work well for most usecases.&lt;br /&gt;
&lt;br /&gt;
I&#039;m mentioning filesystem below too. Where I write ext4, the samme applies to ext2 and ext3.&lt;br /&gt;
&lt;br /&gt;
==== Create a PV ====&lt;br /&gt;
&lt;br /&gt;
A PV is the &amp;quot;physical&amp;quot; parts. This does not need to be a physical disk, but can also be another RAID, be it an mdraid, fakeraid, hardware raid, a virtual disk on a SAN or otherwisee or a partition on one of those. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#  These add three PVs, one on a drive (or hardware raid) and another two on mdraids.&lt;br /&gt;
pvcreate /dev/sdb&lt;br /&gt;
pvcreate /dev/md1 /dev/md2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For more information about pvcreate, see [https://linux.die.net/man/8/pvcreate the manual].&lt;br /&gt;
&lt;br /&gt;
==== Create a VG ====&lt;br /&gt;
&lt;br /&gt;
The volume group consists of one or more PVs grouped together on which LVs can be placed. If several PVs are grouped in a VG, it&#039;s generally a good idea to make sure these PVs have some sort of redundancy, as in mdraid/fakeraid or hwraid. Otherwise it will be like using a [https://en.wikipedia.org/wiki/RAID RAID-0] with a single point of failure on each of the independant drives. LVM has [https://unix.stackexchange.com/questions/150644/raiding-with-lvm-vs-mdraid-pros-and-cons  RAID code in it] as well, so you can use that. I haven&#039;t done so myself, as I generally stick to mraid. The reason is mdraid is, in my opinion older and more stable and has more users (meaning bugs are reported and fixed faster whenever they are found). That said, I beleive the actual RAID code used in LVM RAID are the same function calls as for mdraid, so it may not be much of a difference. I still stick with mdraid. To create a VG, run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create volume group my_vg&lt;br /&gt;
vgcreate my_vg /dev/md1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that if vgcreate is run with a PV (as /dev/md1 above) that is not defined as a PV (like above), this is done implicitly, so if you don&#039;t need any special flags to pvcreate, you can simply skip it and let vgcreate do that for you.&lt;br /&gt;
&lt;br /&gt;
==== Create an LV ====&lt;br /&gt;
&lt;br /&gt;
LVs can be compared to partitions, somehow, since they are bounderies of a fraction or all of that of a VG. The difference between them and a partition, however, is that they can be grown or shrunk easily and also moved around between PVs without downtime. This flexibility makes them superiour to partitions as your system can be changed without users noticing it. By default, an LV is alloated &amp;quot;thickly&amp;quot;, meaning all the data given to it, is allocated from the VG and thus the PV. The following makes a 100GB LV named &amp;quot;thicklv&amp;quot;. When making an LV, I usually allocate what&#039;s needed plus some more, but not everything, just to make sure it&#039;s space available for growth on any of the LVs on the VG, or new LVs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a thick provisioned LV named thicklv on the VG my_vg&lt;br /&gt;
lvcreate -n thicklv -L 100G my_vg&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After the LV is created, a filesystem can be placed on it unless it is meant to be used directly. The application for direct use include swap space, VM storage and certain database systems. Most of these will, however, work on filesystems too, although my testing has shown that on swap space, there is a significant performance gain for using dedicated storage without a filesystem. As for filesystems, most Linux users use either ext4 or xfs. Personally, I generally use XFS these days. See my notes below on filesystem choice.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a filesystem on the LV - this could have been mkfs -t ext4 or whatever filesystem you choose&lt;br /&gt;
mkfs -t xfs /dev/my_vg/thicklv&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then just edit /etc/fstab with correct data and run mount -a, and you should be all set.&lt;br /&gt;
&lt;br /&gt;
==== Create LVM cache ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
lvcreate -L 1G -n _cache_meta data /dev/md1&lt;br /&gt;
&lt;br /&gt;
lvcreate -l100%FREE -n _cache data /dev/md1&lt;br /&gt;
&lt;br /&gt;
# Some would want --cachemode writeback, but seriously, I wouldn&#039;t recommend it. Metadata or data can be easily corrupted in case of failure.&lt;br /&gt;
lvconvert --type cache-pool --cachemode writethrough --poolmetadata data/_cache_meta data/_cache&lt;br /&gt;
&lt;br /&gt;
lvconvert --type cache --cachepool data/_cache data/data&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Disabling LVM cache ====&lt;br /&gt;
&lt;br /&gt;
If you for some reason want to disable caching, this will do it cleanly and remove the LVs earlier created for caching the main device.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
lvconvert --uncache data/data&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Growing devices ====&lt;br /&gt;
&lt;br /&gt;
LVM objects can be grown and shrunk. If a PV resides on a RAID where a new drive has been added or otherwise grown, or on a partition or virtual disk that has been extended, the PV must be updated to reflect these changes. The following command will grow the PV to the maximum available on the underlying storage. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Resize the PV /dev/md (not the RAID, only the PV on the RAID) to its full size&lt;br /&gt;
pvresize /dev/md1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If a new PV is added, the VG can be grown to add the space on that in addition to what&#039;s there already. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Extend my_vg to include md2 and its space&lt;br /&gt;
vgextend my_vg /dev/md2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
With more space available in the VG, the LV can now be extended. Let&#039;s add another 50GB to it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Extend thicklv - add 50GB. If you know you won&#039;t need the space anywhere else, you may want to&lt;br /&gt;
# lvresize -l+100%FREE instead. Keep in mind the difference between -l (extents) and -L (bytes)&lt;br /&gt;
lvresize -L +50G my_vg/thicklv&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Growing filesystems ====&lt;br /&gt;
After the LV has grown, run &#039;&#039;xfs_growfs&#039;&#039; (xfs) or &#039;&#039;resize2fs&#039;&#039; (ext4) to make use of the new data. To grow the filesystem to all available space on ext4, run the below command.  To partly grow the filesystem or to shrink it or otherwise, please see the manuals.&lt;br /&gt;
&lt;br /&gt;
The filesystem can be mounted when this is run. If you for some reason get an &#039;&#039;&#039;access denied&#039;&#039;&#039; error when running this as root or with sudo, it&#039;s likely caused by a filesystem error. To fix this, unmount the filesystem first and run &#039;&#039;&#039;fsck -f /dev/my_vg/thicklv&#039;&#039;&#039; and remount it before retrying to extend it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
resize2fs /dev/my_vg/thicklv&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Similarly, with XFS, but note that xfs_growfs doesn&#039;t take the device name, but the filesystem&#039;s mount point. In the case of XFS, also note that the filesystem &#039;&#039;&#039;&#039;&#039;must&#039;&#039;&#039;&#039;&#039; be mounted to be grown. This, in contrast to how it was in the old days when filesystems had to be unmounted to be grown.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
xfs_growfs /my_mountpoint&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Rename system VG ====&lt;br /&gt;
&lt;br /&gt;
Some distros create VG names like those-from-a-sysadmin-with-a-well-developed-paranoia-not-to-hit-a-duplicate. Debian, for instance, uses names like &amp;quot;my-full-hostname-vg&amp;quot;. Personally, I don&#039;t like these, since if I were to move a disk or vdisk around to somewhere else, I&#039;d make sure not to add a disk named &#039;sys&#039; to an existing system. If you do, most distros will refuse to use the VGs with duplicate names, resulting in the OS not booting until either one is specified by its UUID or just one removed. As I&#039;m aware of this, I stick to the super-risky thing of all system VGs named &#039;sys&#039; and so on.&lt;br /&gt;
&lt;br /&gt;
If you do this, keep in mind that it may blow up your computer and take your girl- or boyfriend with it or even make either of them pregnant, allowing Trump to rule your life and generally make things suck. You&#039;re on your own!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Rename the VG&lt;br /&gt;
vgrename my-full-hostname-vg sys&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, in /boot/grub/grub.cfg, change the old lv path from something like &#039;/dev/mapper/debian--stretch--machine--vg-root&#039; to your new and fancy &#039;/dev/sys/root. Likewise, in /etc/fstab, change occurences of &#039;/dev/mapper/debian--stretch--machine--vg-&#039; (or similar) with &#039;/dev/sys/&#039;. Here, this was like this - the old ones commented out.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;fstab&amp;quot;&amp;gt;&lt;br /&gt;
#/dev/mapper/debian--stretch--box--vg-root      /               ext4            errors=remount-ro,discard       0       1&lt;br /&gt;
/dev/sys/root                                   /               ext4            errors=remount-ro,discard       0       1&lt;br /&gt;
# /boot was on /dev/vda1 during installation&lt;br /&gt;
UUID=myverylonguuidwithatonofgoodinfoinit       /boot           ext2            defaults                        0       2&lt;br /&gt;
#/dev/mapper/debian--stretch--box--vg-swap_1    none            swap            sw                              0       0&lt;br /&gt;
/dev/sys/swap_1                                 none            swap            sw                              0       0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Update /etc/initramfs-tools/conf.d/resume with similar data for swap.&lt;br /&gt;
&lt;br /&gt;
You might want to run &#039;update-initramfs -u -k all&#039; after this, but I&#039;m not sure if it&#039;s needed.&lt;br /&gt;
&lt;br /&gt;
Now, pray to the nearest god(s) and give it a reboot and it should (probably) work.&lt;br /&gt;
&lt;br /&gt;
After reboot, run &#039;&#039;&#039;swapoff -a&#039;&#039;&#039;, then &#039;&#039;&#039;mkswap /dev/sys/swap_1&#039;&#039;&#039; (or whatever it&#039;s called on your system) and &#039;&#039;&#039;swapon -a&#039;&#039;&#039; again. You may want to give it another reboot or two for kicks, but it should work well even without that.&lt;br /&gt;
&lt;br /&gt;
=== Migration tools ===&lt;br /&gt;
&lt;br /&gt;
At times, storage regimes change, new storage is added and sometimes it&#039;s not easy to migrate with the current hardware or its support systems. Once I had to migrate a 45TiB fileserver from one storage system to another, preferably without downtime. The server originally had three 15TiB PVs of which two were full and the third half full. I resorted to using [https://linux.die.net/man/8/pvmove pvmove] to just move the data on the PVs in use to a new PV. We started out with creating a new 50TiB PV, sde, and then to pvmove.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Attach /dev/sde to the VG my_vg&lt;br /&gt;
vgextend my_vg /dev/sde&lt;br /&gt;
&lt;br /&gt;
# Move the contents from /dev/sdb over to /dev/sde block by block. If a target is not given in pvmove,&lt;br /&gt;
# the contents of the source (sdb here) will be put somewhere else in the pool.&lt;br /&gt;
pvmove /dev/sdb /dev/sde&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This took a while (as in a week or so) - the pvmove command uses old code and logic (or at least did that when I migrated this in November 2016), but it affected performance on the server very little, so users didn&#039;t notice. After the first PV was migrated, I continued with the other two, one after the other, and after a month or so, it was migrated. We used this on a number of large fileservers, and it worked flawlessly. Before doing the production servers I also tried interrupting pvmove in various ways, including hard resets, and it just kept on after the reboot.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;NOTE:&#039;&#039;&#039;&#039;&#039; &#039;&#039;Even though it worked well for us, &#039;&#039;&#039;always&#039;&#039;&#039; keep a good backup before doing this. Things may go wrong, and without a good backup, you may be looking for a hard-to-find new job the next morning&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
==== mdadm workarounds ====&lt;br /&gt;
&lt;br /&gt;
===== Migrate from a mirror (raid-1) to raid-10 =====&lt;br /&gt;
&lt;br /&gt;
Create a mirror&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sdb /dev/sdc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
LVM (pv/vg/lv) on md0 (see above), put a filesystem on the lv and fill it with some data.&lt;br /&gt;
&lt;br /&gt;
Now, some months later, you want to change this to raid-10 to allow for the same amount of redundancy, but to allow more disks into the system.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mdadm --grow /dev/md0 --level=10&lt;br /&gt;
mdadm: Impossibly level change request for RAID1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So - no - doesn&#039;t work. But - we&#039;re on &lt;br /&gt;
&lt;br /&gt;
Since we&#039;re on lvm already, this&#039;ll be easy. If you&#039;re using filesystems directly on partitions, you can do this the same way, but without the pvmove part, using rsync or whateever you like instead. I&#039;d recommend using lvm for for the new raid, which should be rather obvious from this article. Now plug in a new drive and create a new raid10 on that one. If you two new drives, install both. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# change &amp;quot;missing&amp;quot; to the other device name if you installed two new drives&lt;br /&gt;
mdadm --create /dev/md1 --level=10 --raid-devices=2 /dev/vdd missing&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, as described above, just vgextend the vg, adding the new raid and run pvmove to move the data from the old pv (residing on the old raid1) to the new pv (on raid10). Afte rpvmove is finished (which may take awile, see above), just&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
vgreduce raidtest /dev/md0&lt;br /&gt;
pvremove /dev/md0&lt;br /&gt;
mdadm --stop /dev/md0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
…and your disk is free to be added to the new array. If the new raid is running in degraded mode (if you created it with just one drive), better don&#039;t wait too long, since you don&#039;t have redundancy. Just mdadm --add the devs.&lt;br /&gt;
&lt;br /&gt;
If you now have /dev/mdstat telling you your raid10 is active and have three drives, of which one is a spare, it should look something like this&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5] [raid4] [raid10]&lt;br /&gt;
md1 : active raid10 vdc[3](S) vdb[2] vdd[0]&lt;br /&gt;
      8380416 blocks super 1.2 2 near-copies [2/2] [UU]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Just mdadm --grow --raid-devices=3 /dev/md1&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;RAID section is not complete. I&#039;ll write more on migraing from raid10 to raid6 later. It&#039;s not straight forward, but easier than this one :)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== Thin provisioned LVs ===&lt;br /&gt;
&lt;br /&gt;
Thin provisioning on LVM is a method used for not allocating all the space given to an LV. For instance, if you have a 1TB VG and want to give an LV 500GB, although it currently only uses a fraction of that, a thin lv can be a good alternative. This will allow for adding a limit to how much it can use, but also to let it grow dynamically without manual work by the sysadmin. Thin provisioning adds another layer of abstaction by creating a special LV as a &#039;&#039;thin pool&#039;&#039; from which data is allocated to the &#039;&#039;thin volume(s)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== Create a thin pool ====&lt;br /&gt;
&lt;br /&gt;
Allocate 1TB to the thin pool to be used for thinly provisioned LVs. Keep in mind that the space allocated to the thin pool is in fact thick provisioned. Only the volumes put on &#039;&#039;thinpool&#039;&#039; are thin provisioned. This will create two hidden LVs, one for data and one for metadata. Normally the defaults will do, but check the manual if the data doesn&#039;t match the usual patterns (such as billions of files, resulting in huge amounts of metadata). I &#039;&#039;beleive&#039;&#039; the metadata part should be resizable at a later time if needed, but I have not tested it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a pool for thin LVs. Keep in mind that the pool itself is not thin provisioned, only the volumes residing on it&lt;br /&gt;
lvcreate --size 1T --type thin-pool --thinpool thinpool my_vg&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Create a thin volume ====&lt;br /&gt;
&lt;br /&gt;
You have the thinpool, now put a thin volume on it. It will allocate some space for metadata, but probably not much (a few megs, perhaps).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Now, create a volume with a virtual (-V) size of half a terabyte named thin_pool, but using the thinpool (-T) named thin_pool for storage&lt;br /&gt;
lvcreate -V 500G -T my_vg/thin_pool --name thinvol&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The new volume&#039;s device name will be /dev/thinvol. Now, create a filesystem on it, add to fstab and mount it. The &#039;&#039;&#039;df&#039;&#039;&#039; command will return available space according to the virtual size (-V), while lvs will show how much data is actually used on each of the thinly provisioned volumes.&lt;br /&gt;
&lt;br /&gt;
== Filesystem dilemmas ==&lt;br /&gt;
&lt;br /&gt;
=== XFS or ext4 or something else ===&lt;br /&gt;
The choice of filesystem varies for your use. Distros such as RHEL/CentOS has moved to XFS by default from v7. Debian/Ubuntu still sticks to ext4, like most other. I&#039;ll discuss my thoughts below on ext4 vs XFS and leave the other filesystems for later.&lt;br /&gt;
&lt;br /&gt;
==== ext4 ====&lt;br /&gt;
ext4 is probably the most used filesystem on linux as of writing. It&#039;s rock stable and has been extended by a lot of extensions since the original ext2. It still retains backward compatibility, being able to mount and fsck ext2 and ext3 with the ext4 driver. However, it doesn&#039;t handle large filesystems very well. If a filesystem is created for &amp;lt;16TiB, it cannot be grown to anything larger than 16TiB. This may have changed lately, though. One other issue is handling errors. If a large filesystem (say 10TiB) is damaged, an fsck may take several hours, leading to long downtime. When I refer to ext4 further in this text, the same applies to ext2 and ext3 unless otherwise specified.&lt;br /&gt;
&lt;br /&gt;
==== XFS ====&lt;br /&gt;
XFS, originally developed by SGI some time in the bronze age, but has been worked on heavily after that. RHEL and Centos version 7 and forward, uses XFS as the default filesystem. It is quick, it scales well, but it lacks at least two things ext4 has. It cannot be shrunk (not that you normally need that, but nice if you have a typo or you need to change things). Also, it doesn&#039;t allow for automatic fsck on bootup. If something is messed up on the filesystem, you&#039;ll have to login as root on the console (not ssh), which might be an issue on some systems. The fsck equivalent, xfs_repair, is a *lot* faster than ext4&#039;s fsck, though.&lt;br /&gt;
&lt;br /&gt;
==== ZFS ====&lt;br /&gt;
ZFS is like a combination of RAID, LVM and a filesystem, supporting full checksumming, auto-healing (given sufficient redundancy), compression, encryption, replication, deduplication (if you&#039;re brave and have a &#039;&#039;ton&#039;&#039; of memory) and a lot more. It&#039;s a separate chapter and needs a lot more talk than paragraph here.&lt;br /&gt;
&lt;br /&gt;
==== btrfs ====&lt;br /&gt;
btrfs, pronounced &amp;quot;butterfs&amp;quot; or &amp;quot;betterfs&amp;quot; or just spelled out, is a filesystem that mimics that of ZFS. It has been around for 10 years or so, but hasn&#039;t yet proven to be really stable. Following the progress of it for those years, I&#039;ve found it to be a nice toy with which to play, but not to be used in production. Again, others may say otherwise, but these are just my words.&lt;br /&gt;
&lt;br /&gt;
== Low level disk handling ==&lt;br /&gt;
&lt;br /&gt;
This section is for low-level handling of disks, regardless of storage system elsewhere. These apply to mdraid, lvmraid and zfs and possibly other solutions, with the exception of individual drives on hwraid (and maybe fakeraid), since there, the drives are hidden from Linux (or whatever OS).&lt;br /&gt;
&lt;br /&gt;
=== S.M.A.R.T. and slow drives ===&lt;br /&gt;
Modern (that is, from about 1990 or later) have S.M.A.R.T. (or just smart, since it&#039;s easier to type) monitoring built in, meaning the disk&#039;s controller is monitoring itself. This is handy and will ideally tell you in advance that a drive is flakey or dying. Modern (2010+) smart monitoring is more or less the same. It can be trusted about 50% of the time. Usually, if smart detects an error, it&#039;s a real error. I don&#039;t think I&#039;ve seen it reporting a false positive, but others may know better. &lt;br /&gt;
&lt;br /&gt;
==== smartmontools ====&lt;br /&gt;
First, install smartmontool and run smartclt -H /dev/yourdisk (/dev/sda or something) to get a health report. Then perhaps run smartctl -a /dev/yourdisk and look for &#039;current pending sectors&#039; This should be zero. Also check the temperature, which normally should be much above 50.&lt;br /&gt;
&lt;br /&gt;
==== single, slow drive ====&lt;br /&gt;
What may happen, is smart not seeing anything and life goes on like before, only slower and less prouductive, without telling anyone. If you stubler over this issue, you&#039;ll probably see it during a large rsync/zfs send/receive or a resync/rebuild/resilver of the raid/zpool. During this, it feels like everything is slow and your RAID has turned into a RAIF (redundant array of inexpensive floppies). To check if you have a single drive messing up it all, check with &#039;&#039;&#039;iostat -x 2&#039;&#039;&#039;, having 2 being the delay between each measurement. Interrupt it with ctrl+x. If there&#039;s a rougue drive there, it should stand out like sdg below&lt;br /&gt;
&lt;br /&gt;
 avg-cpu:  %user   %nice %system %iowait  %steal   %idle&lt;br /&gt;
            0.38    0.00    1.75    0.00    0.00   97.87&lt;br /&gt;
&lt;br /&gt;
 Device            r/s     w/s     rkB/s     wkB/s   rrqm/s   wrqm/s  %rrqm  %wrqm r_await w_await aqu-sz rareq-sz wareq-sz  svctm  %util&lt;br /&gt;
 sda              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdb              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdc              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdd              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sde              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdf              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdg              3.50    0.00   2352.00      0.00     0.00     0.00   0.00   0.00 14306.29    0.00  13.85   672.00     0.00 285.71 100.00&lt;br /&gt;
 sdh              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
&lt;br /&gt;
In ZFS land, you should be able to get similar data with &#039;&#039;&#039;zpool iostat -v &amp;lt;pool&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Now you know the bad drive (sdg), pull it from the raid with &#039;&#039;&#039;mdadm --fail /dev/mdX /dev/sdX&#039;&#039;&#039;. Now test the drive&#039;s performance manually, just simply:&lt;br /&gt;
&lt;br /&gt;
 # hdparm -t /dev/sdg&lt;br /&gt;
 &lt;br /&gt;
 /dev/sdg:&lt;br /&gt;
  Timing buffered disk reads:   2 MB in  5.37 seconds = 381.46 kB/sec&lt;br /&gt;
&lt;br /&gt;
Bingo - nothing you&#039;d want to keep. For a good drive, it should be something like 100-200MB/s&lt;br /&gt;
&lt;br /&gt;
PS: Keep in mind that you have a degraded RAID by now in case you had a spare waiting for things to happen.&lt;br /&gt;
&lt;br /&gt;
Try to replace the cable and/or try the disk on another port/controller. If the result from hdparm persists, it&#039;s probably a bad cable&lt;br /&gt;
&lt;br /&gt;
So, then, just psycially locate the drive, pull it out, take out the discs and magnets and recycle the rest.&lt;br /&gt;
&lt;br /&gt;
=== &amp;quot;Unplug&amp;quot; drive from system ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Find the device unit&#039;s number with something like&lt;br /&gt;
find /sys/bus/scsi/devices/*/block/ -name sdd&lt;br /&gt;
# returning /sys/bus/scsi/devices/3:0:0:0/block/sdd here, &lt;br /&gt;
# meaning 3:0:0:0 is the SCSI device we&#039;re looking for.&lt;br /&gt;
&lt;br /&gt;
# Given this is the correct device, and you want to &#039;unplug&#039; it, do so by&lt;br /&gt;
echo 1 &amp;gt; /sys/bus/scsi/devices/3:0:0:0/delete&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Rescan disk controllers ===&lt;br /&gt;
If a drive is added and for some reason doesn&#039;t get detected, or is removed by the command above, it can be rediscovered with a sysfs command to the scsi host to which it is connected. Since there may be quite a few of these, an easy way is to just scan them all and check the output of &#039;&#039;&#039;dmesg -T&#039;&#039;&#039; after running it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Make a list of controllers and send a rescan message to each of them. It won&#039;t do anything &lt;br /&gt;
# for those where nothing has changed, but it will show new drives where they have been added.&lt;br /&gt;
for host_scan in /sys/class/scsi_host/host*/scan&lt;br /&gt;
do&lt;br /&gt;
  echo &#039;- - -&#039; &amp;gt; $host_scan&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Fail injection with debugfs ===&lt;br /&gt;
[https://lxadm.com/Using_fault_injection https://lxadm.com/Using_fault_injection]&lt;br /&gt;
&lt;br /&gt;
== mdadm stuff ==&lt;br /&gt;
=== Resync ===&lt;br /&gt;
To resync a raid, that is, check, run&lt;br /&gt;
&lt;br /&gt;
 echo check &amp;gt; /sys/block/$dev/md/sync_action&lt;br /&gt;
&lt;br /&gt;
where $dev is something like md0. If you have several raids, something like this should work&lt;br /&gt;
&lt;br /&gt;
 for dev in md{0,1}&lt;br /&gt;
 do&lt;br /&gt;
   echo repair &amp;gt; /sys/block/$dev/md/sync_action&lt;br /&gt;
 done&lt;br /&gt;
&lt;br /&gt;
Also useful in a one-liner like&lt;br /&gt;
&lt;br /&gt;
 for dev in md{0,1} ; do echo repair &amp;gt; /sys/block/$dev/md/sync_action ; done&lt;br /&gt;
&lt;br /&gt;
Different raids on different drives will do this in parallel. If the drives are shared somehow with partitions or similar, the check or repair will wait for the other to finish before going on.&lt;br /&gt;
&lt;br /&gt;
As for repair vs check, [https://raid.wiki.kernel.org/index.php/RAID_Administration this article] describes it well. I stick to using repair unless it&#039;s something rare where I don&#039;t want to touch the data.&lt;br /&gt;
&lt;br /&gt;
=== Spare pools ===&lt;br /&gt;
In the old itmes, mdadm supported only a dedicated spare per md device, so if working with a large set of drives (20? 40?), where you&#039;d want to setup more raid sets to increase redundancy, you&#039;d dedicate a spare to each of the raid sets. This has changed (some time ago?), so in these modern, heathen days, you can change mdadm.conf, usually placed under /etc/mdadm, and add &#039;spare-group=somegroup&#039; where &#039;somegroup&#039; is a string identifying the spare group. After doing this, run &#039;&#039;&#039;update-initramfs -u&#039;&#039;&#039; and reboot and add a spare to one of the raid sets in the spare group, and md will use that or those spares for all the raidsets in that group.&lt;br /&gt;
&lt;br /&gt;
As some pointed out on #linux-raid @ irc.freenode.net, this feature is very badly documented, but as far as I can see, it works well.&lt;br /&gt;
&lt;br /&gt;
==== Example config ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create two raidsets&lt;br /&gt;
&lt;br /&gt;
mdadm --create /dev/md1 --level=6 --raid-devices=6 /dev/vd[efghij]&lt;br /&gt;
mdadm --create /dev/md2 --level=6 --raid-devices=6 /dev/vd[klmnop]&lt;br /&gt;
&lt;br /&gt;
# get their UUID etc&lt;br /&gt;
&lt;br /&gt;
mdadm --detail --scan&lt;br /&gt;
ARRAY /dev/md/1 metadata=1.2 name=raidtest:1 UUID=1a8cbdcb:f4092350:348b6b80:c054d74c&lt;br /&gt;
ARRAY /dev/md/2 metadata=1.2 name=raidtest:2 UUID=894b1b7c:cb7eba70:917d6033:ea5afd2b&lt;br /&gt;
&lt;br /&gt;
# Put those lines into /etc/mdadm/mdadm.conf and and add the spare-group&lt;br /&gt;
&lt;br /&gt;
ARRAY /dev/md/1 metadata=1.2 name=raidtest:1 spare-group=raidtest UUID=1a8cbdcb:f4092350:348b6b80:c054d74c&lt;br /&gt;
ARRAY /dev/md/2 metadata=1.2 name=raidtest:2 spare-group=raidtest UUID=894b1b7c:cb7eba70:917d6033:ea5afd2b&lt;br /&gt;
&lt;br /&gt;
# update the initramfs and reboot&lt;br /&gt;
&lt;br /&gt;
update-initramfs -u&lt;br /&gt;
reboot&lt;br /&gt;
&lt;br /&gt;
# add a spare drive to one of the raids&lt;br /&gt;
&lt;br /&gt;
mdadm --add /dev/md1 /dev/vdq&lt;br /&gt;
&lt;br /&gt;
# fail a drive on the other raid&lt;br /&gt;
&lt;br /&gt;
mdadm --fail /dev/md2 /dev/vdn&lt;br /&gt;
&lt;br /&gt;
# check /proc/mdstat to see md2 rebuilding with the spare from md1&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Recovery ===&lt;br /&gt;
&lt;br /&gt;
The other day, I came across a problem a user had on #linux-raid@irc.freenode.net. He had an old Qnap NAS that had died and tried plugging the drives in to his Linux machine and got various errors. The two-drive RAID-1 did not come up as it should, &#039;&#039;&#039;dmesg&#039;&#039;&#039; was full of errors from one of the drives (both connected on USB) and so forth.&lt;br /&gt;
&lt;br /&gt;
We went on and started by taking down the machine and just connecting one of the drives. I had him check what was assembled with&lt;br /&gt;
&lt;br /&gt;
 cat /proc/mdstat&lt;br /&gt;
&lt;br /&gt;
That returned /proc/md127 assembled, but LVM didn&#039;t find anything. So running a manual scan&lt;br /&gt;
&lt;br /&gt;
 pvscan --cache /dev/md127&lt;br /&gt;
&lt;br /&gt;
This made linux find the PV, VG and a couple of LVs, but probably because the mdraid was degraded, the LVs were deactivated, according to &#039;&#039;&#039;lvscan&#039;&#039;&#039;. Activating the one with a filesystem manually&lt;br /&gt;
&lt;br /&gt;
 lvchange -a y /dev/&amp;lt;vg&amp;gt;/&amp;lt;lv&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Substitute &amp;lt;vg&amp;gt; and &amp;lt;lv&amp;gt; with the names listed by vgs and lvs.&lt;br /&gt;
&lt;br /&gt;
This worked, and the filesystem on /dev/&amp;lt;vg&amp;gt;/&amp;lt;lv&amp;gt; could be mounted correctly.&lt;br /&gt;
&lt;br /&gt;
== Tuning ==&lt;br /&gt;
&lt;br /&gt;
While trying to compare a 12-disk RAID (8TB disks) to a hwraid, mdraid was slower, so we did a few things to speed things up:&lt;br /&gt;
&lt;br /&gt;
While testing with [https://linux.die.net/man/1/fio fio], monitor /sys/block/md0/md/stripe_cache_active, and see if it&#039;s close to /sys/block/md0/md/stripe_cache_size. If it is, double the size of the latter&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
echo 4096 &amp;gt; /sys/block/md0/md/stripe_cache_size&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Continue until stripe_cache_active stabilises, and then you&#039;ve found the limit you&#039;ll need. You may want to double that for good measure. &lt;br /&gt;
&lt;br /&gt;
(to be continued)&lt;br /&gt;
&lt;br /&gt;
== Links ==&lt;br /&gt;
&lt;br /&gt;
Below are a few links with useful info&lt;br /&gt;
&lt;br /&gt;
* [https://raid.wiki.kernel.org/index.php/Irreversible_mdadm_failure_recovery Irreversible mdadm failure recovery]&lt;br /&gt;
&lt;br /&gt;
= ZFS =&lt;br /&gt;
&lt;br /&gt;
ZFS can do a lot of things most filesystems or volume managers can&#039;t. It checksums all data and metadata and so long that the system uses ECC enabled memory (RAM), it will have complete control over the whole data set, and when (not if) an error occurs, it&#039;ll fix the issue without even throwing a warning. To fix the issue, you&#039;ll obviously need sufficient redundancy (mirrors or RAIDzN). &lt;br /&gt;
&lt;br /&gt;
== ZFS send/receive between machines ==&lt;br /&gt;
&lt;br /&gt;
ZFS has a send/receive mechanism that allows for snapshots to be sent over the wire to a receiving end. This can be a full filesystem, or an incremental change since last send/reveive. In a WAN scenario, you&#039;ll probably want to use VPN for this. On a controlled network, sending in cleartext is also possible. You may as well use ssh, but keep in mind that ssh was never designed to be used as a fullblown vpn solution and is just too slow or the task with large amounts of data. You may, though, use mbuffer, if on a loal LAN.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Allow traffic from the sending IP in whatever firewall interface you&#039;re using (if you&#039;re using a firewall at all, that is)&lt;br /&gt;
ufw allow from x.x.x.x&lt;br /&gt;
# &lt;br /&gt;
# Start the receiver first. This listens on port 9090, has a 1GB buffer,&lt;br /&gt;
    and uses 128kb chunks (same as zfs):&lt;br /&gt;
&lt;br /&gt;
mbuffer -s 128k -m 1G -I 9090 | zfs receive data/filesystem&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To be continued one day… See [https://everycity.co.uk/alasdair/2010/07/using-mbuffer-to-speed-up-slow-zfs-send-zfs-receive/ this] for some more. I&#039;ll get back with details on it.&lt;br /&gt;
&lt;br /&gt;
= General Linux system control =&lt;br /&gt;
&lt;br /&gt;
== Add a new CPU (core) ==&lt;br /&gt;
&lt;br /&gt;
If working with virtual machines, adding a new core can be useful if the VM is slow and the load is multithreaded or multiprocess. To do this, add a new CPU in the hypervisor (be it KVM or VMware or Hyper-V or whatever). Some hypervisors, like VMware, will activate it automatically if open-vm-tools is installed. Please note that open-vm-tools is for VMware only. I don&#039;t know of any such thing for KVM or other hypervisors (although I beleive VirtualBox has its own set of tools, but not as a package). If this doesn&#039;t work, run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
echo 1 &amp;gt; /sys/devices/system/cpu/cpuX/online&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where X is the CPU number you want to add. You can &#039;cat /sys/devices/system/cpu/cpuX/online&#039; to check if it&#039;s online.&lt;br /&gt;
&lt;br /&gt;
= Mount partitions on a disk image =&lt;br /&gt;
&lt;br /&gt;
Sometimes you&#039;ll have a disk image, either from recovering a bad drive after hours (or days or weeks) of ddrescue, and sometimes you just have a disk image from a virtual machine where you want to mount the partitions inside the image. There are three main methods of doing this, which are more or less synonmous, but some easier than the other.&lt;br /&gt;
&lt;br /&gt;
== Basics ==&lt;br /&gt;
&lt;br /&gt;
A disk image is usually like a disk, consisting of either a large filesystem, a PV or a partition table with one or partitions onto which resides a filesystem, a pv, swap or something else. If it&#039;s partitioned, and you want your operating system to mount a filesystem or allow it to see whatever LVM stuff lies on it, you need to isolate the partitions. &lt;br /&gt;
&lt;br /&gt;
== Manual mapping ==&lt;br /&gt;
&lt;br /&gt;
In the oldern days, this was done manually, something like this&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
root@mymachine:~# fdisk -l /dev/vda&lt;br /&gt;
Disk /dev/vda: 25 GiB, 26843545600 bytes, 52428800 sectors&lt;br /&gt;
Units: sectors of 1 * 512 = 512 bytes&lt;br /&gt;
Sector size (logical/physical): 512 bytes / 512 bytes&lt;br /&gt;
I/O size (minimum/optimal): 512 bytes / 512 bytes&lt;br /&gt;
Disklabel type: dos&lt;br /&gt;
Disk identifier: 0xc37b7ea5&lt;br /&gt;
&lt;br /&gt;
Device     Boot    Start      End  Sectors  Size Id Type&lt;br /&gt;
/dev/vda1  *        2048 50333311 50331264   24G 83 Linux&lt;br /&gt;
/dev/vda2       50333312 52426369  2093058 1022M  5 Extended&lt;br /&gt;
/dev/vda5       50333314 52426369  2093056 1022M 82 Linux swap / Solaris&lt;br /&gt;
root@mymachine:~#&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To calculate the start and end of each partition, you just take the start sector and multiply it by the sector size (512 bytes here) and you have the offset in bytes. After this, it&#039;s merely an losetup -o &amp;lt;offset&amp;gt; /dev/loopX &amp;lt;nameofimagefile&amp;gt; and you have the partition mapped to your /dev/loopX (having X being something typically 0-255. After this, just mount it or run pvscan/vgscan/lvscan to probe whatever lvm config is there, and you should be able to mount it like any other filesystem.&lt;br /&gt;
&lt;br /&gt;
== kpartx ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;kpartx&#039;&#039;&#039; does the same as above, more or less, just without so much hassle. Most of it should be automatic and easy to deal with, except it may fail to disconnect the loopback devices sometimes, so you may have to &#039;&#039;&#039;losetup -d&#039;&#039;&#039; them manually. See the manual, &#039;&#039;&#039;kpartx (8)&#039;&#039;&#039;. Please note that &#039;&#039;&#039;partx&#039;&#039;&#039; works similarly and I&#039;d guess the authors of the two tools are arguing a lot of which one&#039;s the best.&lt;br /&gt;
&lt;br /&gt;
== guestmount ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;guestmount&#039;&#039;&#039; is something similar again, but also supports file formats like &#039;&#039;&#039;qcow2&#039;&#039;&#039; and possibly other, proprietary filesystems like &#039;&#039;&#039;vmdk&#039;&#039;&#039; and &#039;&#039;&#039;vdi&#039;&#039;&#039;, but don&#039;t take my word for it - I haven&#039;t tested. Again, see the manual or just read up on the description [http://ask.xmodulo.com/mount-qcow2-disk-image-linux.html?fbclid=IwAR3snTeZvGzp9PLdX11EQhCfOpux6I93CiJ3A2pUomkkRLly9Xo4851mkTY here]. It seems rather trivial.&lt;br /&gt;
&lt;br /&gt;
= Linux on laptops =&lt;br /&gt;
&lt;br /&gt;
== Wifi with HP EliteBook 725/745 on Ubuntu ==&lt;br /&gt;
&lt;br /&gt;
The HP EliteBook 725/745 and similar are equipped with a BCM4352 wifi chip. As with a lot of other stuff from Broadcom, this lacks an open hardware description, so thus no open driver exist. The proper fix, is to replace the NIC with something with an open driver, but again, this isn&#039;t always possible, so a binary driver exists. In ubuntu, run, somehow connect the machine to the internet and run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install bcmwl-kernel-source&lt;br /&gt;
sudo modprobe wl&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you can&#039;t connect the machine to the internet, download the needed packages on another machine and put it on some usb storage. These packages should suffice:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# apt-cache depends bcmwl-kernel-source&lt;br /&gt;
bcmwl-kernel-source&lt;br /&gt;
  Depends: dkms&lt;br /&gt;
  Depends: linux-libc-dev&lt;br /&gt;
  Depends: libc6-dev&lt;br /&gt;
  Conflicts: &amp;lt;bcmwl-modaliases&amp;gt;&lt;br /&gt;
  Replaces: &amp;lt;bcmwl-modaliases&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then install manually with &#039;&#039;&#039;dpkg -i file1.deb file2.deb&#039;&#039;&#039; etc&lt;br /&gt;
&lt;br /&gt;
After this, ip/ifconfig/iwconfig shouldd see the new wifi nic, probably &#039;&#039;&#039;wlan0&#039;&#039;&#039;, but due to a [https://bugs.launchpad.net/ubuntu/+source/broadcom-sta/+bug/1343151 old, ignored bug], you won&#039;t find any wifi networks. This is because the driver from Broadcom apparently does not support interrupt remapping, commonly used on x64 machines. To turn this off, change &#039;&#039;&#039;/etc/default/grub&#039;&#039;&#039; and change the line &#039;&#039;&#039;GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;quiet splash&amp;quot;&#039;&#039;&#039;, adding intremap=off to the end before the quote: &#039;&#039;&#039;GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;quiet splash intremap=off&amp;quot;&#039;&#039;&#039;. Save the file and run &#039;&#039;&#039;sudo update-grub&#039;&#039;&#039; and reboot. After this, wifi should work well.&lt;br /&gt;
&lt;br /&gt;
== Wifi with HP Compaq Presario CQ57 on Ubuntu ==&lt;br /&gt;
&lt;br /&gt;
The HP Compaq Presario CQ57 uses the RT5390 wifi chipset. This has been supported for quite some time now, and I was quite surprised to find it not working on a laptop a friend was having. The driver loaded correctly, but Ubuntu insisted of the laptop being in &#039;&#039;&#039;flight mode&#039;&#039;&#039;. Checking &#039;&#039;&#039;rfkill&#039;&#039;&#039;, it showed me two NICs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# rfkill list all&lt;br /&gt;
0: phy0: Wireless LAN&lt;br /&gt;
	Soft blocked: no&lt;br /&gt;
	Hard blocked: yes&lt;br /&gt;
1: hp-wifi: Wireless LAN&lt;br /&gt;
	Soft blocked: yes&lt;br /&gt;
	Hard blocked: no&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Turning rfkill on and off resulted in nothing much, except some error messages in the kernel log (dmesg)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] ACPI Error: Field [B128] at bit offset/length 128/1024 exceeds size of target Buffer (160 bits) (20170831/dsopcode-235)&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]&lt;br /&gt;
                            Initialized Local Variables for Method [HWCD]:&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Local0: 00000000a34b7928 &amp;lt;Obj&amp;gt;           Integer 0000000000000000&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Local1: 00000000b0aa6865 &amp;lt;Obj&amp;gt;           Buffer(8) 46 41 49 4C 04 00 00 00&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Local5: 00000000a9811efd &amp;lt;Obj&amp;gt;           Integer 0000000000000004&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] Initialized Arguments for Method [HWCD]:  (2 arguments defined for method invocation)&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Arg0:   0000000078957d1b &amp;lt;Obj&amp;gt;           Integer 0000000000000001&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Arg1:   00000000725c9c6e &amp;lt;Obj&amp;gt;           Buffer(20) 53 45 43 55 02 00 00 00&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] ACPI Error: Method parse/execution failed \_SB.WMID.HWCD, AE_AML_BUFFER_LIMIT (20170831/psparse-550)&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] ACPI Error: Method parse/execution failed \_SB.WMID.WMAD, AE_AML_BUFFER_LIMIT (20170831/psparse-550)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After upgrading BIOS and testing different kernels, I was asked to try to unload the &#039;&#039;&#039;hp_wmi&#039;&#039;&#039; driver. I did, and things changed a bit, so I tried blacklisting it, creating the file &#039;&#039;&#039;/etc/modprobe.d/blacklist-hp_wmi.conf&#039;&#039;&#039; with the following content&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Blacklist this - it doesn&#039;t work!&lt;br /&gt;
blacklist hp_wmi&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
I gave the machine a reboot and afte that, the &#039;&#039;&#039;hp-wifi&#039;&#039;&#039; entry was gone in the rfkill output, and things works.&lt;br /&gt;
&lt;br /&gt;
= Raspberry pi =&lt;br /&gt;
&lt;br /&gt;
I couldn&#039;t quite decide if the raspberry pi should be a separate section or part of Linux, but hell, it can run more than Linux, although 99,lots% of people just uses Linux on them. This is a small list of things to know about them; things not on the front page of the manual or perhaps hidden even better.&lt;br /&gt;
&lt;br /&gt;
== Which pi? ==&lt;br /&gt;
&lt;br /&gt;
I just setup three raspberry pi machines and although some are quite different, like v1 to vEverythingelse or the Pi zero versions to the normal ones, not all of us remember how to distinguish between them, and sometimes they&#039;re in a nice 3d printed (or otherwise) chassis or otherwise hidden. So, how to check three different ones:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
root@home-assistant:~ $ cat /proc/device-tree/model ; echo&lt;br /&gt;
Raspberry Pi 2 Model B Rev 1.1&lt;br /&gt;
&lt;br /&gt;
root@green-pi:~ $ cat /proc/device-tree/model ; echo&lt;br /&gt;
Raspberry Pi 3 Model B Rev 1.2&lt;br /&gt;
&lt;br /&gt;
roy@yellow-pi:~ $cat /proc/device-tree/model ; echo&lt;br /&gt;
Raspberry Pi 4 Model B Rev 1.1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
While this works well, for the latter, the pi4, it doesn&#039;t tell how much memory I have. It comes in variants of 1, 2 and 4GB, and this is the latter.&lt;br /&gt;
&lt;br /&gt;
== Monitoring ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;vcgencmd&#039;&#039;&#039; from &#039;&#039;&#039;/opt/vc/bin&#039;&#039;&#039;, but symlinked to &#039;&#039;&#039;/usr/bin&#039;&#039;&#039; so it&#039;s available in path, is useful for fetching hardware info about the pi. For example, measuring the temperature&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
root@yellow-pi:~# vcgencmd measure_temp&lt;br /&gt;
temp=63.0&#039;C&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The command is generally badly documented and parts of it seems outdated for newer hardware. Here&#039;s the output from a Raspberry pi 4 with 4GB RAM&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
roy@yellow-pi:~ $ vcgencmd get_mem arm&lt;br /&gt;
arm=948M&lt;br /&gt;
roy@yellow-pi:~ $ vcgencmd get_mem gpu&lt;br /&gt;
gpu=76M&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= BIOS upgrade from Linux =&lt;br /&gt;
&lt;br /&gt;
Generally, BIOS upgrades have been moved to the BIOS itself these days. This saves a lot of work and quite possibly lives after those who earier rammed their heads through walls, now can upgrade directly from the internet instead of using obscure operating systems best avoided. Sometimes, however, one must use these nevertheless. This is a quick run-through on your options.&lt;br /&gt;
&lt;br /&gt;
== DOS ==&lt;br /&gt;
&lt;br /&gt;
Most non-automatic BIOS upgrades are installed from DOS. Doing a BIOS upgrade this way, is generally non-problematic. Just install a USB thingie with [https://www.freedos.org/ FreeDOS], copy your file(s) onto the thing and boot on it. The commandline is the same as old MS/DOS, except a wee bit more userfriendly, but not a lot.&lt;br /&gt;
&lt;br /&gt;
== Windows ==&lt;br /&gt;
&lt;br /&gt;
Some macahines, like laptops from &#039;&#039;&#039;HP&#039;&#039;&#039;, may have BIOS upgrades that are made to be installed from Windows and won&#039;t run in FreeDOS or MS/DOS, instead throwing an error, saying &#039;&#039;&#039;This program cannot be run in DOS mode&#039;&#039;&#039;. This means you&#039;ll have to boot on a Windows rescue disc and do the job from there. Googling this, tells you it&#039;s quite easy, you just choose &#039;make rescue disc&#039; from Windows, and it&#039;s all good, except if you don&#039;t run Windows, that is. To remedy this problem, do as follows:&lt;br /&gt;
&lt;br /&gt;
=== Download Windows ===&lt;br /&gt;
&lt;br /&gt;
Since you don&#039;t run Windows and possibly don&#039;t have a spouse or friend around with such unhealthy habits either, you need to get it. It&#039;s quite easy - just google &#039;download windows&#039; and it&#039;ll send you to [https://www.microsoft.com/en-us/software-download/windows10ISO somewhere like this].&lt;br /&gt;
&lt;br /&gt;
=== Burn it! ===&lt;br /&gt;
&lt;br /&gt;
Now it&#039;s time to burn the installer on a DVD ROM. You&#039;ll need a double-layered one, since the OS is &amp;gt; 4.7GiB, but I&#039;m sure you have a ton of those lying around. Now, just place your optical medium in your optical drive and burn, baby, burn!&lt;br /&gt;
&lt;br /&gt;
=== Or make a USB thing? ===&lt;br /&gt;
&lt;br /&gt;
Not a lot of machines have optical drives these days, so you may want to use an USB pen drive or something instead. This is easy, just make the USB bootable with the Windows application Microsoft has made for this. Unfortunately, this only runs on Windows, and unlike stuff like Debian, where the &#039;&#039;&#039;iso&#039;&#039;&#039; file can be dd&#039;ed directly onto a USB drive to make it bootable, the Windows &#039;&#039;&#039;iso&#039;&#039;&#039;s don&#039;t come with this luxury. There are lots of methods to make bootable USB things from iso files out there, but the only thing most of them have in common, is that they generally don&#039;t work.&lt;br /&gt;
&lt;br /&gt;
==== WoeUSB ====&lt;br /&gt;
&lt;br /&gt;
After hours of swearing, it&#039;s nice to come across software like [https://github.com/slacka/WoeUSB WoeUSB]. It may not be perfect, it relies on a bunch of GUI stuff you&#039;ll never need and so on, but it &#039;&#039;&#039;&#039;&#039;works&#039;&#039;&#039;&#039;&#039;, and that&#039;s the important part! Just clone the repo and RTFM and it&#039;s all nice. It&#039;s slow, but hell, getting a windows machine and/or an optical drive might be slower.&lt;br /&gt;
&lt;br /&gt;
WoeUSB does nothing fancy, but it &#039;&#039;&#039;does&#039;&#039;&#039; work. It will create a filesystem, FAT32 or NTFS (better use NTFS, FAT32 has its limits). It creates normal filesystems and so on. Just make sure to copy in the BIOS update file, usually an exe file, to run when Windows is up and running.&lt;br /&gt;
&lt;br /&gt;
==== Install BIOS ====&lt;br /&gt;
&lt;br /&gt;
Boot on the Windows USB thing and choose &#039;repair computer&#039; and then &#039;command prompt&#039;. Find the install file, and if you&#039;re lucky, you&#039;ll find it needs a 32bit OS, just like I did. Since the 64bit version doesn&#039;t include 32bit compatibility in the installer, revert to downloading the 32bit version of windows and start over. Pray to your favourite god(s) not to get across such machines again - it might help.&lt;br /&gt;
&lt;br /&gt;
= 3D printer stuff =&lt;br /&gt;
&lt;br /&gt;
== Hydrophilic filament ==&lt;br /&gt;
&lt;br /&gt;
Most popular filament types, including PLA, PETG, PP or PA (Polyamide, normally known as Nylon) and virtualy any filament type named [https://www.matterhackers.com/news/filament-and-water poly-something] (and thus with an acronym of P-something) are hydrophilic (also (somewhat incorrectly) called hydroscopic), meaning so long they&#039;re dryer than the atmosphere around them, they&#039;ll do their best to suck out the atmosphere&#039;s humidity. This is why most filament are shrink-wrapped with a small bag of silica gel in it. If such filament is exposed for normal humid air for some time, it&#039;ll become very hard to use. Most of my experience is with PLA, which can handle a bit (depending on make), but still not a lot. With PLA, if you end up with prints where the filament seems not to stick, it may help with a higher temperature. Otherwise, the filament must be [https://all3dp.com/2/how-to-dry-filament-pla-abs-and-nylon/ baked]. If you don&#039;t want to use your oven, try something like a [https://www.jula.no/catalog/hjem-og-husholdning/kjokkenmaskiner/mattilberedningsapparater/frukt-sopptorker/frukt-sopptorker-001641/#tab02 fruit and mushroom dryer]. Then get a good, sealble plastic box and add something like half a kilogram of [https://www.ebay.com/sch/sis.html?_nkw=1KG+Orange+Replacement+Desiccant+Indicating+Silica+Gel+Beads+for+Drawers%2C+Camera&amp;amp;_id=131938742628&amp;amp;&amp;amp;_trksid=p2057872.m2749.l2658 silica gel] to an old sock, tie it and put it in the your new dry box.&lt;br /&gt;
&lt;br /&gt;
Please note that ABS is hydrophobic, so you won&#039;t have to worry too much there. Also, remember that PA/Nylon is extremely hydrophilic. Even a couple of days in normal air humidity can ruin it completely and will require baking.&lt;br /&gt;
&lt;br /&gt;
== Upgrading the firmware on an Ender 3 ==&lt;br /&gt;
&lt;br /&gt;
This is about upgrading the firmware, and thus also flashing a bootloader to the Creality Ender 3 3D printer. Most of this is well documented on several place, like o [https://www.youtube.com/watch?v=fIl5X2ffdyo the video from Teaching tech] and elsewhere, but I&#039;ll just summarise some issues I had.&lt;br /&gt;
&lt;br /&gt;
=== Using an arduino Nano as a programmer ===&lt;br /&gt;
&lt;br /&gt;
Quick note before you read on. If you have an Ender 3 controller version 1.1.5 or newer (or perhaps even a bit older), a CR-10S or some other more or less modern printers or controllers, they come with a bootloader installed already, so don&#039;t bother flashing one. The one that&#039;s in there already, should work well. So if you have one of these, just skip this and jump to the [[Roy&#039;s_notes#Flashing_the_printer|next section]].&lt;br /&gt;
&lt;br /&gt;
However, the normal CR-10 (without the S), Ender 3 and a few other printers from Creality come without a bootloader, so you&#039;ll need to flash one before upgrading the firmware. Well, strictly speakning, you don&#039;t need one, you can save those 8kB or so for other stuff and use a programmer to write the whole firmware, but then you&#039;ll need to wire up everything every time you want a new firmware, so in my world, you &#039;&#039;&#039;do&#039;&#039;&#039; need the bootloader, since it&#039;s easier.&lt;br /&gt;
&lt;br /&gt;
To install a bootloader, you&#039;ll need a programmer, and I didn&#039;t have one available. Having some el-cheapo china-copies of Arduinos around, I read I could use one and tried so. Although the docs mostly mention the Uno etc, it&#039;s just as simple with the Nano copy.&lt;br /&gt;
&lt;br /&gt;
So, grab an arduino, plug it to your machine with a USB cable, and, using the Arduino IDE, use the ArduinoISP sketch there (found under Examples) to burn the software needed for the arduino to work as a programmer. When this is done, connect a 10µF capacitor between RST and GND to stop it from resetting when used as a programmer. Connect the MOSI, MISO and SCK pins from the ICSP block (that little isolated 6-pin block on top of the ardu). See [https://www.arduino.cc/en/Tutorial/ArduinoISP here] for a pinout. Then find Vcc and GND either on the ICSP block or elsewhere. Some sites say that on some boards you shouldn&#039;t use the pins on the ICSP block for this. I doubt it matters, though. Then connect another jumper wire from pin 10 on the ardu to work as the reset pin outwards to the chip being programmed (that is, on the printer). The ICSP jumper block pin layout is the same on the printer and on the ardu, and probably elsewhere. Sometimes [https://xkcd.com/927/ standardisation] actually works…&lt;br /&gt;
&lt;br /&gt;
See https://cloud.karlsbakk.net/index.php/s/zw48YJjzaf8Rc2F for a pic with the ardu (this wiki is broken atm, will fix it later)&lt;br /&gt;
&lt;br /&gt;
== Flashing the printer ==&lt;br /&gt;
&lt;br /&gt;
When the boot loader is in place, possibly after some wierd errors from during the process, the screen on the 3d printer will go blank and it&#039;ll behave like being bricked. This is ok. Now disconnect the wires and connect the USB cable between computer and printer. If you haven&#039;t installed support for the Sanguino board, that is, the variant of the 1284-chip and surrounding electronics that is the core of the, you need to install it first. In the Arduino IDE, choose the Tools / Boards / Boards manager boot option and search for Sanguino. After this, you should find the Sanguino or Sanguino 1284p in the boards menu. After this, you should be able to communicate with the printer&#039;s controller. Download the [https://www.th3dstudio.com/knowledgebase/th3d-unified-firmware-package/ TH3D unified firmware], making sure it&#039;s the last version. Uncompress the zip and with Finder/Explorer/whateversomething&#039;scalledonlinux, browse to &#039;&#039;&#039;TH3DUF_R2/Firmware/TH3DUF_R2.ino&#039;&#039;&#039; and open it. It should open directly in the Android IDE. Keep in mind that the names TH3DUF_R2 and TH3DUF_R2.ino will vary between versions, but you get the point. Now configure it for your particular needs. You&#039;ll find most of this in the Configuration.h tab (that&#039;s really a file). Most of the other files won&#039;t be necessary unless you&#039;re doing some more advanced stuff, like replacing th controller with something non-standard or similar, but then again, that&#039;s another chapter (or book, even). The video mentioned above describes this well. After flashing the new firmware, you&#039;ll probably get some timeouts and errors, since apparently it resets the printer after giving it the new firmware, but without notifying the flashing software of it doing so. If this happens, calm down and reboot the printer and check its tiny monitor - it should work. If it doesn&#039;t work, and if you flashed the bootload yourself, try to flash it again, and if that doesn&#039;t work, try flashing the programmer again yet another time, just for kicks. Again, if you have a newer controller like the v1.1.5, don&#039;t touch the bootloader, as the one already installed, should work well as it is.&lt;br /&gt;
&lt;br /&gt;
PS: I tried enabling &#039;&#039;&#039;MANUAL_MESH_LEVELING&#039;&#039;&#039;, which in the code says that &#039;&#039;If used with a 1284P board the bootscreen will be disabled to save space&#039;&#039;. This effectively disabled the whole printer, and apparently may be making the firmware image a wee bit too large for it to fit the 1284P on the ender. It works well without it, though, and it may be fixed by now, since I tested this back in early 2019.&lt;br /&gt;
&lt;br /&gt;
== And then… ==&lt;br /&gt;
&lt;br /&gt;
With the new firmware in place, the printer should work as before, although with thermal runaway protection to better avoid fires in case the shit hits the fan, and to allow for things like autolevelling. With any luck, [https://www.precisionpiezo.co.uk/ this thing] may be ready for use by the time you read this - it surely looks nice!&lt;br /&gt;
&lt;br /&gt;
= Octoprint/Octopi =&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;This could have been under some other section, but again, I just branch out even though most of it is about sections mentioned elsewhere.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
When setting up a 3d printer for the first time, you usually get an SD card for storage and transfer data to the printer using [https://en.wikipedia.org/wiki/Sneakernet Sneakernet]. Some printers use micro SD cards, while other fullsize SD cards, which imho is better, since they don&#039;t get lost that easily, but otherwise do the same thing. This works, but is somewhat tedious. If you want to control the printer from a PC or phone, there&#039;s a simple trick for that as well - octoprint.&lt;br /&gt;
&lt;br /&gt;
[https://octoprint.org/ Octoprint], written by Gina Häußge, runs on most platforms including linux, windows, BSD*, macos etc. It supports controlling a camera to some extent out of the box and there&#039;s a large number of plugins availablee to do a lot of things you possibly haven&#039;t thought of (and quite often, you&#039;d ever need). The easiest way to install it, is to just grab a Raspberry pi - preferably some of the newer models (will get to that later) and download [https://octoprint.org/download/ octopi] and follow the instructions on that page.&lt;br /&gt;
&lt;br /&gt;
== Performance issues ==&lt;br /&gt;
&lt;br /&gt;
Some report (and I have seen it myself) issues with the pi&#039;s performance with regards to both handling the octoprint processes (which should be as close to realtime as possible) and handling other stuff like I/O, networking etc. The point is that at pi3 or older, has all peripherals connected to an internal USB hub. This might be practical, but performance-wise it&#039;s &#039;&#039;&#039;&#039;&#039;not&#039;&#039;&#039;&#039;&#039;. If you in addition connect a webcam to USB, you&#039;re asking for trouble, since USB will be your bottleneck. With a raspberry pi camera, the ones connected to the pi directly with a ribbon cable, this should not use USB, so it&#039;s better. Still, again, for older pi&#039;s, there might be some shortage in therms of cpu or i/o. The octopi runs something like raspbian which is a fork of debian which is a linux distro, so it all boils down to knowing linux.&lt;br /&gt;
&lt;br /&gt;
Your typical octopi will run octoprint, a streamer, usually &#039;&#039;&#039;mjpg-streamer&#039;&#039;&#039;, a simple, lightweight videostreamer that outputs a stream of jpeg-images (about the same format as cinemas use - that is - not MPEG). This may be a bit tough on the cpu and potentially i/o. Add inn a dash over USB overload and you&#039;re booked for a flight of trouble.&lt;br /&gt;
&lt;br /&gt;
Still - a pi3 should be able to handle the load, but it might help to prioritise corretly. The octoprint process is the important part here, so we could give that full priority both in CPU and I/O and. Unfortunately, it doesn&#039;t seem like the current octopi has been migrated to using systemd for the startup. We&#039;ll deal with this later. To fix this in the old SysV init style file present there, the following patch should work&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;diff&amp;quot;&amp;gt;&lt;br /&gt;
--- octoprint.old	2020-07-20 18:46:10.166651965 +0200&lt;br /&gt;
+++ octoprint	2020-07-20 18:53:21.724803211 +0200&lt;br /&gt;
@@ -22,6 +22,9 @@&lt;br /&gt;
 PIDFILE=/var/run/$NAME.pid&lt;br /&gt;
 PKGNAME=octoprint&lt;br /&gt;
 SCRIPTNAME=/etc/init.d/$PKGNAME&lt;br /&gt;
+NICELEVEL=-19                        # Top CPU priority&lt;br /&gt;
+IONICE_CLASS=1                       # Realtime I/O class&lt;br /&gt;
+IONICE_PRIORITY=0                    # Realtime I/O priority (probably not needed with class=realtime)&lt;br /&gt;
&lt;br /&gt;
 # Read configuration variable file if it is present&lt;br /&gt;
 [ -r /etc/default/$PKGNAME ] &amp;amp;&amp;amp; . /etc/default/$PKGNAME&lt;br /&gt;
@@ -70,10 +73,11 @@&lt;br /&gt;
&lt;br /&gt;
    is_alive $PIDFILE&lt;br /&gt;
    RETVAL=&amp;quot;$?&amp;quot;&lt;br /&gt;
-&lt;br /&gt;
    if [ $RETVAL != 0 ]; then&lt;br /&gt;
        start-stop-daemon --start --background --quiet --pidfile $PIDFILE --make-pidfile \&lt;br /&gt;
-       --exec $DAEMON --chuid $OCTOPRINT_USER --user $OCTOPRINT_USER --umask $UMASK -- serve $DAEMON_ARGS&lt;br /&gt;
+       --exec $DAEMON --chuid $OCTOPRINT_USER --user $OCTOPRINT_USER --umask $UMASK \&lt;br /&gt;
+       --nicelevel $NICELEVEL --ioched $IONICE_CLASS:$IONICE_PRIORITY \&lt;br /&gt;
+       --serve $DAEMON_ARGS&lt;br /&gt;
        RETVAL=&amp;quot;$?&amp;quot;&lt;br /&gt;
    fi&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This ismply upgrades the process to be allowed to use most of the resources on the pi, regardless of what other processes are whining about.&lt;br /&gt;
&lt;br /&gt;
PS: Code not tested - I don&#039;t have a pi right here. Will test later, but I&#039;m pretty sure it&#039;ll work. After all, it&#039;s just a few new arguments to start-stop-daemon&lt;br /&gt;
&lt;br /&gt;
roy&lt;/div&gt;</summary>
		<author><name>Roy</name></author>
	</entry>
	<entry>
		<id>https://wiki.malinux.no/index.php?title=Roy%27s_notes&amp;diff=165</id>
		<title>Roy&#039;s notes</title>
		<link rel="alternate" type="text/html" href="https://wiki.malinux.no/index.php?title=Roy%27s_notes&amp;diff=165"/>
		<updated>2020-07-20T15:55:59Z</updated>

		<summary type="html">&lt;p&gt;Roy: /* And then… */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= LVM, md and friends =&lt;br /&gt;
&lt;br /&gt;
== Linux&#039; Logical Volume Manager (LVM) ==&lt;br /&gt;
&lt;br /&gt;
=== LVM in general ===&lt;br /&gt;
&lt;br /&gt;
LVM is designed to be an abstraction layer on top of physical drives or RAID, typically [https://raid.wiki.kernel.org/index.php/RAID_setup mdraid] or [https://help.ubuntu.com/community/FakeRaidHowto fakeraid]. Keep in mind that fakeraid should be avoided unless you really need it, like in conjunction with dual-booting linux and windows on fakeraid. LVM broadly consists of three elements, the &amp;quot;physical&amp;quot; devices (PV), the volume group (VG) and the logical volume (LV). There can be multiple PVs, VGs and LVs, depending on requirement. More about this below. All commands are given as examples, and all of them can be fine-tuned using extra flags in need of so. In my experience, the defaults work well for most usecases.&lt;br /&gt;
&lt;br /&gt;
I&#039;m mentioning filesystem below too. Where I write ext4, the samme applies to ext2 and ext3.&lt;br /&gt;
&lt;br /&gt;
==== Create a PV ====&lt;br /&gt;
&lt;br /&gt;
A PV is the &amp;quot;physical&amp;quot; parts. This does not need to be a physical disk, but can also be another RAID, be it an mdraid, fakeraid, hardware raid, a virtual disk on a SAN or otherwisee or a partition on one of those. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#  These add three PVs, one on a drive (or hardware raid) and another two on mdraids.&lt;br /&gt;
pvcreate /dev/sdb&lt;br /&gt;
pvcreate /dev/md1 /dev/md2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For more information about pvcreate, see [https://linux.die.net/man/8/pvcreate the manual].&lt;br /&gt;
&lt;br /&gt;
==== Create a VG ====&lt;br /&gt;
&lt;br /&gt;
The volume group consists of one or more PVs grouped together on which LVs can be placed. If several PVs are grouped in a VG, it&#039;s generally a good idea to make sure these PVs have some sort of redundancy, as in mdraid/fakeraid or hwraid. Otherwise it will be like using a [https://en.wikipedia.org/wiki/RAID RAID-0] with a single point of failure on each of the independant drives. LVM has [https://unix.stackexchange.com/questions/150644/raiding-with-lvm-vs-mdraid-pros-and-cons  RAID code in it] as well, so you can use that. I haven&#039;t done so myself, as I generally stick to mraid. The reason is mdraid is, in my opinion older and more stable and has more users (meaning bugs are reported and fixed faster whenever they are found). That said, I beleive the actual RAID code used in LVM RAID are the same function calls as for mdraid, so it may not be much of a difference. I still stick with mdraid. To create a VG, run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create volume group my_vg&lt;br /&gt;
vgcreate my_vg /dev/md1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that if vgcreate is run with a PV (as /dev/md1 above) that is not defined as a PV (like above), this is done implicitly, so if you don&#039;t need any special flags to pvcreate, you can simply skip it and let vgcreate do that for you.&lt;br /&gt;
&lt;br /&gt;
==== Create an LV ====&lt;br /&gt;
&lt;br /&gt;
LVs can be compared to partitions, somehow, since they are bounderies of a fraction or all of that of a VG. The difference between them and a partition, however, is that they can be grown or shrunk easily and also moved around between PVs without downtime. This flexibility makes them superiour to partitions as your system can be changed without users noticing it. By default, an LV is alloated &amp;quot;thickly&amp;quot;, meaning all the data given to it, is allocated from the VG and thus the PV. The following makes a 100GB LV named &amp;quot;thicklv&amp;quot;. When making an LV, I usually allocate what&#039;s needed plus some more, but not everything, just to make sure it&#039;s space available for growth on any of the LVs on the VG, or new LVs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a thick provisioned LV named thicklv on the VG my_vg&lt;br /&gt;
lvcreate -n thicklv -L 100G my_vg&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After the LV is created, a filesystem can be placed on it unless it is meant to be used directly. The application for direct use include swap space, VM storage and certain database systems. Most of these will, however, work on filesystems too, although my testing has shown that on swap space, there is a significant performance gain for using dedicated storage without a filesystem. As for filesystems, most Linux users use either ext4 or xfs. Personally, I generally use XFS these days. See my notes below on filesystem choice.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a filesystem on the LV - this could have been mkfs -t ext4 or whatever filesystem you choose&lt;br /&gt;
mkfs -t xfs /dev/my_vg/thicklv&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then just edit /etc/fstab with correct data and run mount -a, and you should be all set.&lt;br /&gt;
&lt;br /&gt;
==== Create LVM cache ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
lvcreate -L 1G -n _cache_meta data /dev/md1&lt;br /&gt;
&lt;br /&gt;
lvcreate -l100%FREE -n _cache data /dev/md1&lt;br /&gt;
&lt;br /&gt;
# Some would want --cachemode writeback, but seriously, I wouldn&#039;t recommend it. Metadata or data can be easily corrupted in case of failure.&lt;br /&gt;
lvconvert --type cache-pool --cachemode writethrough --poolmetadata data/_cache_meta data/_cache&lt;br /&gt;
&lt;br /&gt;
lvconvert --type cache --cachepool data/_cache data/data&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Disabling LVM cache ====&lt;br /&gt;
&lt;br /&gt;
If you for some reason want to disable caching, this will do it cleanly and remove the LVs earlier created for caching the main device.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
lvconvert --uncache data/data&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Growing devices ====&lt;br /&gt;
&lt;br /&gt;
LVM objects can be grown and shrunk. If a PV resides on a RAID where a new drive has been added or otherwise grown, or on a partition or virtual disk that has been extended, the PV must be updated to reflect these changes. The following command will grow the PV to the maximum available on the underlying storage. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Resize the PV /dev/md (not the RAID, only the PV on the RAID) to its full size&lt;br /&gt;
pvresize /dev/md1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If a new PV is added, the VG can be grown to add the space on that in addition to what&#039;s there already. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Extend my_vg to include md2 and its space&lt;br /&gt;
vgextend my_vg /dev/md2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
With more space available in the VG, the LV can now be extended. Let&#039;s add another 50GB to it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Extend thicklv - add 50GB. If you know you won&#039;t need the space anywhere else, you may want to&lt;br /&gt;
# lvresize -l+100%FREE instead. Keep in mind the difference between -l (extents) and -L (bytes)&lt;br /&gt;
lvresize -L +50G my_vg/thicklv&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Growing filesystems ====&lt;br /&gt;
After the LV has grown, run &#039;&#039;xfs_growfs&#039;&#039; (xfs) or &#039;&#039;resize2fs&#039;&#039; (ext4) to make use of the new data. To grow the filesystem to all available space on ext4, run the below command.  To partly grow the filesystem or to shrink it or otherwise, please see the manuals.&lt;br /&gt;
&lt;br /&gt;
The filesystem can be mounted when this is run. If you for some reason get an &#039;&#039;&#039;access denied&#039;&#039;&#039; error when running this as root or with sudo, it&#039;s likely caused by a filesystem error. To fix this, unmount the filesystem first and run &#039;&#039;&#039;fsck -f /dev/my_vg/thicklv&#039;&#039;&#039; and remount it before retrying to extend it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
resize2fs /dev/my_vg/thicklv&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Similarly, with XFS, but note that xfs_growfs doesn&#039;t take the device name, but the filesystem&#039;s mount point. In the case of XFS, also note that the filesystem &#039;&#039;&#039;&#039;&#039;must&#039;&#039;&#039;&#039;&#039; be mounted to be grown. This, in contrast to how it was in the old days when filesystems had to be unmounted to be grown.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
xfs_growfs /my_mountpoint&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Rename system VG ====&lt;br /&gt;
&lt;br /&gt;
Some distros create VG names like those-from-a-sysadmin-with-a-well-developed-paranoia-not-to-hit-a-duplicate. Debian, for instance, uses names like &amp;quot;my-full-hostname-vg&amp;quot;. Personally, I don&#039;t like these, since if I were to move a disk or vdisk around to somewhere else, I&#039;d make sure not to add a disk named &#039;sys&#039; to an existing system. If you do, most distros will refuse to use the VGs with duplicate names, resulting in the OS not booting until either one is specified by its UUID or just one removed. As I&#039;m aware of this, I stick to the super-risky thing of all system VGs named &#039;sys&#039; and so on.&lt;br /&gt;
&lt;br /&gt;
If you do this, keep in mind that it may blow up your computer and take your girl- or boyfriend with it or even make either of them pregnant, allowing Trump to rule your life and generally make things suck. You&#039;re on your own!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Rename the VG&lt;br /&gt;
vgrename my-full-hostname-vg sys&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, in /boot/grub/grub.cfg, change the old lv path from something like &#039;/dev/mapper/debian--stretch--machine--vg-root&#039; to your new and fancy &#039;/dev/sys/root. Likewise, in /etc/fstab, change occurences of &#039;/dev/mapper/debian--stretch--machine--vg-&#039; (or similar) with &#039;/dev/sys/&#039;. Here, this was like this - the old ones commented out.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;fstab&amp;quot;&amp;gt;&lt;br /&gt;
#/dev/mapper/debian--stretch--box--vg-root      /               ext4            errors=remount-ro,discard       0       1&lt;br /&gt;
/dev/sys/root                                   /               ext4            errors=remount-ro,discard       0       1&lt;br /&gt;
# /boot was on /dev/vda1 during installation&lt;br /&gt;
UUID=myverylonguuidwithatonofgoodinfoinit       /boot           ext2            defaults                        0       2&lt;br /&gt;
#/dev/mapper/debian--stretch--box--vg-swap_1    none            swap            sw                              0       0&lt;br /&gt;
/dev/sys/swap_1                                 none            swap            sw                              0       0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Update /etc/initramfs-tools/conf.d/resume with similar data for swap.&lt;br /&gt;
&lt;br /&gt;
You might want to run &#039;update-initramfs -u -k all&#039; after this, but I&#039;m not sure if it&#039;s needed.&lt;br /&gt;
&lt;br /&gt;
Now, pray to the nearest god(s) and give it a reboot and it should (probably) work.&lt;br /&gt;
&lt;br /&gt;
After reboot, run &#039;&#039;&#039;swapoff -a&#039;&#039;&#039;, then &#039;&#039;&#039;mkswap /dev/sys/swap_1&#039;&#039;&#039; (or whatever it&#039;s called on your system) and &#039;&#039;&#039;swapon -a&#039;&#039;&#039; again. You may want to give it another reboot or two for kicks, but it should work well even without that.&lt;br /&gt;
&lt;br /&gt;
=== Migration tools ===&lt;br /&gt;
&lt;br /&gt;
At times, storage regimes change, new storage is added and sometimes it&#039;s not easy to migrate with the current hardware or its support systems. Once I had to migrate a 45TiB fileserver from one storage system to another, preferably without downtime. The server originally had three 15TiB PVs of which two were full and the third half full. I resorted to using [https://linux.die.net/man/8/pvmove pvmove] to just move the data on the PVs in use to a new PV. We started out with creating a new 50TiB PV, sde, and then to pvmove.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Attach /dev/sde to the VG my_vg&lt;br /&gt;
vgextend my_vg /dev/sde&lt;br /&gt;
&lt;br /&gt;
# Move the contents from /dev/sdb over to /dev/sde block by block. If a target is not given in pvmove,&lt;br /&gt;
# the contents of the source (sdb here) will be put somewhere else in the pool.&lt;br /&gt;
pvmove /dev/sdb /dev/sde&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This took a while (as in a week or so) - the pvmove command uses old code and logic (or at least did that when I migrated this in November 2016), but it affected performance on the server very little, so users didn&#039;t notice. After the first PV was migrated, I continued with the other two, one after the other, and after a month or so, it was migrated. We used this on a number of large fileservers, and it worked flawlessly. Before doing the production servers I also tried interrupting pvmove in various ways, including hard resets, and it just kept on after the reboot.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;NOTE:&#039;&#039;&#039;&#039;&#039; &#039;&#039;Even though it worked well for us, &#039;&#039;&#039;always&#039;&#039;&#039; keep a good backup before doing this. Things may go wrong, and without a good backup, you may be looking for a hard-to-find new job the next morning&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
==== mdadm workarounds ====&lt;br /&gt;
&lt;br /&gt;
===== Migrate from a mirror (raid-1) to raid-10 =====&lt;br /&gt;
&lt;br /&gt;
Create a mirror&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sdb /dev/sdc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
LVM (pv/vg/lv) on md0 (see above), put a filesystem on the lv and fill it with some data.&lt;br /&gt;
&lt;br /&gt;
Now, some months later, you want to change this to raid-10 to allow for the same amount of redundancy, but to allow more disks into the system.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mdadm --grow /dev/md0 --level=10&lt;br /&gt;
mdadm: Impossibly level change request for RAID1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So - no - doesn&#039;t work. But - we&#039;re on &lt;br /&gt;
&lt;br /&gt;
Since we&#039;re on lvm already, this&#039;ll be easy. If you&#039;re using filesystems directly on partitions, you can do this the same way, but without the pvmove part, using rsync or whateever you like instead. I&#039;d recommend using lvm for for the new raid, which should be rather obvious from this article. Now plug in a new drive and create a new raid10 on that one. If you two new drives, install both. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# change &amp;quot;missing&amp;quot; to the other device name if you installed two new drives&lt;br /&gt;
mdadm --create /dev/md1 --level=10 --raid-devices=2 /dev/vdd missing&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, as described above, just vgextend the vg, adding the new raid and run pvmove to move the data from the old pv (residing on the old raid1) to the new pv (on raid10). Afte rpvmove is finished (which may take awile, see above), just&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
vgreduce raidtest /dev/md0&lt;br /&gt;
pvremove /dev/md0&lt;br /&gt;
mdadm --stop /dev/md0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
…and your disk is free to be added to the new array. If the new raid is running in degraded mode (if you created it with just one drive), better don&#039;t wait too long, since you don&#039;t have redundancy. Just mdadm --add the devs.&lt;br /&gt;
&lt;br /&gt;
If you now have /dev/mdstat telling you your raid10 is active and have three drives, of which one is a spare, it should look something like this&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5] [raid4] [raid10]&lt;br /&gt;
md1 : active raid10 vdc[3](S) vdb[2] vdd[0]&lt;br /&gt;
      8380416 blocks super 1.2 2 near-copies [2/2] [UU]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Just mdadm --grow --raid-devices=3 /dev/md1&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;RAID section is not complete. I&#039;ll write more on migraing from raid10 to raid6 later. It&#039;s not straight forward, but easier than this one :)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== Thin provisioned LVs ===&lt;br /&gt;
&lt;br /&gt;
Thin provisioning on LVM is a method used for not allocating all the space given to an LV. For instance, if you have a 1TB VG and want to give an LV 500GB, although it currently only uses a fraction of that, a thin lv can be a good alternative. This will allow for adding a limit to how much it can use, but also to let it grow dynamically without manual work by the sysadmin. Thin provisioning adds another layer of abstaction by creating a special LV as a &#039;&#039;thin pool&#039;&#039; from which data is allocated to the &#039;&#039;thin volume(s)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== Create a thin pool ====&lt;br /&gt;
&lt;br /&gt;
Allocate 1TB to the thin pool to be used for thinly provisioned LVs. Keep in mind that the space allocated to the thin pool is in fact thick provisioned. Only the volumes put on &#039;&#039;thinpool&#039;&#039; are thin provisioned. This will create two hidden LVs, one for data and one for metadata. Normally the defaults will do, but check the manual if the data doesn&#039;t match the usual patterns (such as billions of files, resulting in huge amounts of metadata). I &#039;&#039;beleive&#039;&#039; the metadata part should be resizable at a later time if needed, but I have not tested it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a pool for thin LVs. Keep in mind that the pool itself is not thin provisioned, only the volumes residing on it&lt;br /&gt;
lvcreate --size 1T --type thin-pool --thinpool thinpool my_vg&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Create a thin volume ====&lt;br /&gt;
&lt;br /&gt;
You have the thinpool, now put a thin volume on it. It will allocate some space for metadata, but probably not much (a few megs, perhaps).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Now, create a volume with a virtual (-V) size of half a terabyte named thin_pool, but using the thinpool (-T) named thin_pool for storage&lt;br /&gt;
lvcreate -V 500G -T my_vg/thin_pool --name thinvol&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The new volume&#039;s device name will be /dev/thinvol. Now, create a filesystem on it, add to fstab and mount it. The &#039;&#039;&#039;df&#039;&#039;&#039; command will return available space according to the virtual size (-V), while lvs will show how much data is actually used on each of the thinly provisioned volumes.&lt;br /&gt;
&lt;br /&gt;
== Filesystem dilemmas ==&lt;br /&gt;
&lt;br /&gt;
=== XFS or ext4 or something else ===&lt;br /&gt;
The choice of filesystem varies for your use. Distros such as RHEL/CentOS has moved to XFS by default from v7. Debian/Ubuntu still sticks to ext4, like most other. I&#039;ll discuss my thoughts below on ext4 vs XFS and leave the other filesystems for later.&lt;br /&gt;
&lt;br /&gt;
==== ext4 ====&lt;br /&gt;
ext4 is probably the most used filesystem on linux as of writing. It&#039;s rock stable and has been extended by a lot of extensions since the original ext2. It still retains backward compatibility, being able to mount and fsck ext2 and ext3 with the ext4 driver. However, it doesn&#039;t handle large filesystems very well. If a filesystem is created for &amp;lt;16TiB, it cannot be grown to anything larger than 16TiB. This may have changed lately, though. One other issue is handling errors. If a large filesystem (say 10TiB) is damaged, an fsck may take several hours, leading to long downtime. When I refer to ext4 further in this text, the same applies to ext2 and ext3 unless otherwise specified.&lt;br /&gt;
&lt;br /&gt;
==== XFS ====&lt;br /&gt;
XFS, originally developed by SGI some time in the bronze age, but has been worked on heavily after that. RHEL and Centos version 7 and forward, uses XFS as the default filesystem. It is quick, it scales well, but it lacks at least two things ext4 has. It cannot be shrunk (not that you normally need that, but nice if you have a typo or you need to change things). Also, it doesn&#039;t allow for automatic fsck on bootup. If something is messed up on the filesystem, you&#039;ll have to login as root on the console (not ssh), which might be an issue on some systems. The fsck equivalent, xfs_repair, is a *lot* faster than ext4&#039;s fsck, though.&lt;br /&gt;
&lt;br /&gt;
==== ZFS ====&lt;br /&gt;
ZFS is like a combination of RAID, LVM and a filesystem, supporting full checksumming, auto-healing (given sufficient redundancy), compression, encryption, replication, deduplication (if you&#039;re brave and have a &#039;&#039;ton&#039;&#039; of memory) and a lot more. It&#039;s a separate chapter and needs a lot more talk than paragraph here.&lt;br /&gt;
&lt;br /&gt;
==== btrfs ====&lt;br /&gt;
btrfs, pronounced &amp;quot;butterfs&amp;quot; or &amp;quot;betterfs&amp;quot; or just spelled out, is a filesystem that mimics that of ZFS. It has been around for 10 years or so, but hasn&#039;t yet proven to be really stable. Following the progress of it for those years, I&#039;ve found it to be a nice toy with which to play, but not to be used in production. Again, others may say otherwise, but these are just my words.&lt;br /&gt;
&lt;br /&gt;
== Low level disk handling ==&lt;br /&gt;
&lt;br /&gt;
This section is for low-level handling of disks, regardless of storage system elsewhere. These apply to mdraid, lvmraid and zfs and possibly other solutions, with the exception of individual drives on hwraid (and maybe fakeraid), since there, the drives are hidden from Linux (or whatever OS).&lt;br /&gt;
&lt;br /&gt;
=== S.M.A.R.T. and slow drives ===&lt;br /&gt;
Modern (that is, from about 1990 or later) have S.M.A.R.T. (or just smart, since it&#039;s easier to type) monitoring built in, meaning the disk&#039;s controller is monitoring itself. This is handy and will ideally tell you in advance that a drive is flakey or dying. Modern (2010+) smart monitoring is more or less the same. It can be trusted about 50% of the time. Usually, if smart detects an error, it&#039;s a real error. I don&#039;t think I&#039;ve seen it reporting a false positive, but others may know better. &lt;br /&gt;
&lt;br /&gt;
==== smartmontools ====&lt;br /&gt;
First, install smartmontool and run smartclt -H /dev/yourdisk (/dev/sda or something) to get a health report. Then perhaps run smartctl -a /dev/yourdisk and look for &#039;current pending sectors&#039; This should be zero. Also check the temperature, which normally should be much above 50.&lt;br /&gt;
&lt;br /&gt;
==== single, slow drive ====&lt;br /&gt;
What may happen, is smart not seeing anything and life goes on like before, only slower and less prouductive, without telling anyone. If you stubler over this issue, you&#039;ll probably see it during a large rsync/zfs send/receive or a resync/rebuild/resilver of the raid/zpool. During this, it feels like everything is slow and your RAID has turned into a RAIF (redundant array of inexpensive floppies). To check if you have a single drive messing up it all, check with &#039;&#039;&#039;iostat -x 2&#039;&#039;&#039;, having 2 being the delay between each measurement. Interrupt it with ctrl+x. If there&#039;s a rougue drive there, it should stand out like sdg below&lt;br /&gt;
&lt;br /&gt;
 avg-cpu:  %user   %nice %system %iowait  %steal   %idle&lt;br /&gt;
            0.38    0.00    1.75    0.00    0.00   97.87&lt;br /&gt;
&lt;br /&gt;
 Device            r/s     w/s     rkB/s     wkB/s   rrqm/s   wrqm/s  %rrqm  %wrqm r_await w_await aqu-sz rareq-sz wareq-sz  svctm  %util&lt;br /&gt;
 sda              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdb              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdc              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdd              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sde              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdf              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdg              3.50    0.00   2352.00      0.00     0.00     0.00   0.00   0.00 14306.29    0.00  13.85   672.00     0.00 285.71 100.00&lt;br /&gt;
 sdh              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
&lt;br /&gt;
In ZFS land, you should be able to get similar data with &#039;&#039;&#039;zpool iostat -v &amp;lt;pool&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Now you know the bad drive (sdg), pull it from the raid with &#039;&#039;&#039;mdadm --fail /dev/mdX /dev/sdX&#039;&#039;&#039;. Now test the drive&#039;s performance manually, just simply:&lt;br /&gt;
&lt;br /&gt;
 # hdparm -t /dev/sdg&lt;br /&gt;
 &lt;br /&gt;
 /dev/sdg:&lt;br /&gt;
  Timing buffered disk reads:   2 MB in  5.37 seconds = 381.46 kB/sec&lt;br /&gt;
&lt;br /&gt;
Bingo - nothing you&#039;d want to keep. For a good drive, it should be something like 100-200MB/s&lt;br /&gt;
&lt;br /&gt;
PS: Keep in mind that you have a degraded RAID by now in case you had a spare waiting for things to happen.&lt;br /&gt;
&lt;br /&gt;
Try to replace the cable and/or try the disk on another port/controller. If the result from hdparm persists, it&#039;s probably a bad cable&lt;br /&gt;
&lt;br /&gt;
So, then, just psycially locate the drive, pull it out, take out the discs and magnets and recycle the rest.&lt;br /&gt;
&lt;br /&gt;
=== &amp;quot;Unplug&amp;quot; drive from system ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Find the device unit&#039;s number with something like&lt;br /&gt;
find /sys/bus/scsi/devices/*/block/ -name sdd&lt;br /&gt;
# returning /sys/bus/scsi/devices/3:0:0:0/block/sdd here, &lt;br /&gt;
# meaning 3:0:0:0 is the SCSI device we&#039;re looking for.&lt;br /&gt;
&lt;br /&gt;
# Given this is the correct device, and you want to &#039;unplug&#039; it, do so by&lt;br /&gt;
echo 1 &amp;gt; /sys/bus/scsi/devices/3:0:0:0/delete&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Rescan disk controllers ===&lt;br /&gt;
If a drive is added and for some reason doesn&#039;t get detected, or is removed by the command above, it can be rediscovered with a sysfs command to the scsi host to which it is connected. Since there may be quite a few of these, an easy way is to just scan them all and check the output of &#039;&#039;&#039;dmesg -T&#039;&#039;&#039; after running it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Make a list of controllers and send a rescan message to each of them. It won&#039;t do anything &lt;br /&gt;
# for those where nothing has changed, but it will show new drives where they have been added.&lt;br /&gt;
for host_scan in /sys/class/scsi_host/host*/scan&lt;br /&gt;
do&lt;br /&gt;
  echo &#039;- - -&#039; &amp;gt; $host_scan&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Fail injection with debugfs ===&lt;br /&gt;
[https://lxadm.com/Using_fault_injection https://lxadm.com/Using_fault_injection]&lt;br /&gt;
&lt;br /&gt;
== mdadm stuff ==&lt;br /&gt;
=== Resync ===&lt;br /&gt;
To resync a raid, that is, check, run&lt;br /&gt;
&lt;br /&gt;
 echo check &amp;gt; /sys/block/$dev/md/sync_action&lt;br /&gt;
&lt;br /&gt;
where $dev is something like md0. If you have several raids, something like this should work&lt;br /&gt;
&lt;br /&gt;
 for dev in md{0,1}&lt;br /&gt;
 do&lt;br /&gt;
   echo repair &amp;gt; /sys/block/$dev/md/sync_action&lt;br /&gt;
 done&lt;br /&gt;
&lt;br /&gt;
Also useful in a one-liner like&lt;br /&gt;
&lt;br /&gt;
 for dev in md{0,1} ; do echo repair &amp;gt; /sys/block/$dev/md/sync_action ; done&lt;br /&gt;
&lt;br /&gt;
Different raids on different drives will do this in parallel. If the drives are shared somehow with partitions or similar, the check or repair will wait for the other to finish before going on.&lt;br /&gt;
&lt;br /&gt;
As for repair vs check, [https://raid.wiki.kernel.org/index.php/RAID_Administration this article] describes it well. I stick to using repair unless it&#039;s something rare where I don&#039;t want to touch the data.&lt;br /&gt;
&lt;br /&gt;
=== Spare pools ===&lt;br /&gt;
In the old itmes, mdadm supported only a dedicated spare per md device, so if working with a large set of drives (20? 40?), where you&#039;d want to setup more raid sets to increase redundancy, you&#039;d dedicate a spare to each of the raid sets. This has changed (some time ago?), so in these modern, heathen days, you can change mdadm.conf, usually placed under /etc/mdadm, and add &#039;spare-group=somegroup&#039; where &#039;somegroup&#039; is a string identifying the spare group. After doing this, run &#039;&#039;&#039;update-initramfs -u&#039;&#039;&#039; and reboot and add a spare to one of the raid sets in the spare group, and md will use that or those spares for all the raidsets in that group.&lt;br /&gt;
&lt;br /&gt;
As some pointed out on #linux-raid @ irc.freenode.net, this feature is very badly documented, but as far as I can see, it works well.&lt;br /&gt;
&lt;br /&gt;
==== Example config ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create two raidsets&lt;br /&gt;
&lt;br /&gt;
mdadm --create /dev/md1 --level=6 --raid-devices=6 /dev/vd[efghij]&lt;br /&gt;
mdadm --create /dev/md2 --level=6 --raid-devices=6 /dev/vd[klmnop]&lt;br /&gt;
&lt;br /&gt;
# get their UUID etc&lt;br /&gt;
&lt;br /&gt;
mdadm --detail --scan&lt;br /&gt;
ARRAY /dev/md/1 metadata=1.2 name=raidtest:1 UUID=1a8cbdcb:f4092350:348b6b80:c054d74c&lt;br /&gt;
ARRAY /dev/md/2 metadata=1.2 name=raidtest:2 UUID=894b1b7c:cb7eba70:917d6033:ea5afd2b&lt;br /&gt;
&lt;br /&gt;
# Put those lines into /etc/mdadm/mdadm.conf and and add the spare-group&lt;br /&gt;
&lt;br /&gt;
ARRAY /dev/md/1 metadata=1.2 name=raidtest:1 spare-group=raidtest UUID=1a8cbdcb:f4092350:348b6b80:c054d74c&lt;br /&gt;
ARRAY /dev/md/2 metadata=1.2 name=raidtest:2 spare-group=raidtest UUID=894b1b7c:cb7eba70:917d6033:ea5afd2b&lt;br /&gt;
&lt;br /&gt;
# update the initramfs and reboot&lt;br /&gt;
&lt;br /&gt;
update-initramfs -u&lt;br /&gt;
reboot&lt;br /&gt;
&lt;br /&gt;
# add a spare drive to one of the raids&lt;br /&gt;
&lt;br /&gt;
mdadm --add /dev/md1 /dev/vdq&lt;br /&gt;
&lt;br /&gt;
# fail a drive on the other raid&lt;br /&gt;
&lt;br /&gt;
mdadm --fail /dev/md2 /dev/vdn&lt;br /&gt;
&lt;br /&gt;
# check /proc/mdstat to see md2 rebuilding with the spare from md1&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Recovery ===&lt;br /&gt;
&lt;br /&gt;
The other day, I came across a problem a user had on #linux-raid@irc.freenode.net. He had an old Qnap NAS that had died and tried plugging the drives in to his Linux machine and got various errors. The two-drive RAID-1 did not come up as it should, &#039;&#039;&#039;dmesg&#039;&#039;&#039; was full of errors from one of the drives (both connected on USB) and so forth.&lt;br /&gt;
&lt;br /&gt;
We went on and started by taking down the machine and just connecting one of the drives. I had him check what was assembled with&lt;br /&gt;
&lt;br /&gt;
 cat /proc/mdstat&lt;br /&gt;
&lt;br /&gt;
That returned /proc/md127 assembled, but LVM didn&#039;t find anything. So running a manual scan&lt;br /&gt;
&lt;br /&gt;
 pvscan --cache /dev/md127&lt;br /&gt;
&lt;br /&gt;
This made linux find the PV, VG and a couple of LVs, but probably because the mdraid was degraded, the LVs were deactivated, according to &#039;&#039;&#039;lvscan&#039;&#039;&#039;. Activating the one with a filesystem manually&lt;br /&gt;
&lt;br /&gt;
 lvchange -a y /dev/&amp;lt;vg&amp;gt;/&amp;lt;lv&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Substitute &amp;lt;vg&amp;gt; and &amp;lt;lv&amp;gt; with the names listed by vgs and lvs.&lt;br /&gt;
&lt;br /&gt;
This worked, and the filesystem on /dev/&amp;lt;vg&amp;gt;/&amp;lt;lv&amp;gt; could be mounted correctly.&lt;br /&gt;
&lt;br /&gt;
== Tuning ==&lt;br /&gt;
&lt;br /&gt;
While trying to compare a 12-disk RAID (8TB disks) to a hwraid, mdraid was slower, so we did a few things to speed things up:&lt;br /&gt;
&lt;br /&gt;
While testing with [https://linux.die.net/man/1/fio fio], monitor /sys/block/md0/md/stripe_cache_active, and see if it&#039;s close to /sys/block/md0/md/stripe_cache_size. If it is, double the size of the latter&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
echo 4096 &amp;gt; /sys/block/md0/md/stripe_cache_size&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Continue until stripe_cache_active stabilises, and then you&#039;ve found the limit you&#039;ll need. You may want to double that for good measure. &lt;br /&gt;
&lt;br /&gt;
(to be continued)&lt;br /&gt;
&lt;br /&gt;
== Links ==&lt;br /&gt;
&lt;br /&gt;
Below are a few links with useful info&lt;br /&gt;
&lt;br /&gt;
* [https://raid.wiki.kernel.org/index.php/Irreversible_mdadm_failure_recovery Irreversible mdadm failure recovery]&lt;br /&gt;
&lt;br /&gt;
= ZFS =&lt;br /&gt;
&lt;br /&gt;
ZFS can do a lot of things most filesystems or volume managers can&#039;t. It checksums all data and metadata and so long that the system uses ECC enabled memory (RAM), it will have complete control over the whole data set, and when (not if) an error occurs, it&#039;ll fix the issue without even throwing a warning. To fix the issue, you&#039;ll obviously need sufficient redundancy (mirrors or RAIDzN). &lt;br /&gt;
&lt;br /&gt;
== ZFS send/receive between machines ==&lt;br /&gt;
&lt;br /&gt;
ZFS has a send/receive mechanism that allows for snapshots to be sent over the wire to a receiving end. This can be a full filesystem, or an incremental change since last send/reveive. In a WAN scenario, you&#039;ll probably want to use VPN for this. On a controlled network, sending in cleartext is also possible. You may as well use ssh, but keep in mind that ssh was never designed to be used as a fullblown vpn solution and is just too slow or the task with large amounts of data. You may, though, use mbuffer, if on a loal LAN.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Allow traffic from the sending IP in whatever firewall interface you&#039;re using (if you&#039;re using a firewall at all, that is)&lt;br /&gt;
ufw allow from x.x.x.x&lt;br /&gt;
# &lt;br /&gt;
# Start the receiver first. This listens on port 9090, has a 1GB buffer,&lt;br /&gt;
    and uses 128kb chunks (same as zfs):&lt;br /&gt;
&lt;br /&gt;
mbuffer -s 128k -m 1G -I 9090 | zfs receive data/filesystem&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To be continued one day… See [https://everycity.co.uk/alasdair/2010/07/using-mbuffer-to-speed-up-slow-zfs-send-zfs-receive/ this] for some more. I&#039;ll get back with details on it.&lt;br /&gt;
&lt;br /&gt;
= General Linux system control =&lt;br /&gt;
&lt;br /&gt;
== Add a new CPU (core) ==&lt;br /&gt;
&lt;br /&gt;
If working with virtual machines, adding a new core can be useful if the VM is slow and the load is multithreaded or multiprocess. To do this, add a new CPU in the hypervisor (be it KVM or VMware or Hyper-V or whatever). Some hypervisors, like VMware, will activate it automatically if open-vm-tools is installed. Please note that open-vm-tools is for VMware only. I don&#039;t know of any such thing for KVM or other hypervisors (although I beleive VirtualBox has its own set of tools, but not as a package). If this doesn&#039;t work, run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
echo 1 &amp;gt; /sys/devices/system/cpu/cpuX/online&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where X is the CPU number you want to add. You can &#039;cat /sys/devices/system/cpu/cpuX/online&#039; to check if it&#039;s online.&lt;br /&gt;
&lt;br /&gt;
= Mount partitions on a disk image =&lt;br /&gt;
&lt;br /&gt;
Sometimes you&#039;ll have a disk image, either from recovering a bad drive after hours (or days or weeks) of ddrescue, and sometimes you just have a disk image from a virtual machine where you want to mount the partitions inside the image. There are three main methods of doing this, which are more or less synonmous, but some easier than the other.&lt;br /&gt;
&lt;br /&gt;
== Basics ==&lt;br /&gt;
&lt;br /&gt;
A disk image is usually like a disk, consisting of either a large filesystem, a PV or a partition table with one or partitions onto which resides a filesystem, a pv, swap or something else. If it&#039;s partitioned, and you want your operating system to mount a filesystem or allow it to see whatever LVM stuff lies on it, you need to isolate the partitions. &lt;br /&gt;
&lt;br /&gt;
== Manual mapping ==&lt;br /&gt;
&lt;br /&gt;
In the oldern days, this was done manually, something like this&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
root@mymachine:~# fdisk -l /dev/vda&lt;br /&gt;
Disk /dev/vda: 25 GiB, 26843545600 bytes, 52428800 sectors&lt;br /&gt;
Units: sectors of 1 * 512 = 512 bytes&lt;br /&gt;
Sector size (logical/physical): 512 bytes / 512 bytes&lt;br /&gt;
I/O size (minimum/optimal): 512 bytes / 512 bytes&lt;br /&gt;
Disklabel type: dos&lt;br /&gt;
Disk identifier: 0xc37b7ea5&lt;br /&gt;
&lt;br /&gt;
Device     Boot    Start      End  Sectors  Size Id Type&lt;br /&gt;
/dev/vda1  *        2048 50333311 50331264   24G 83 Linux&lt;br /&gt;
/dev/vda2       50333312 52426369  2093058 1022M  5 Extended&lt;br /&gt;
/dev/vda5       50333314 52426369  2093056 1022M 82 Linux swap / Solaris&lt;br /&gt;
root@mymachine:~#&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To calculate the start and end of each partition, you just take the start sector and multiply it by the sector size (512 bytes here) and you have the offset in bytes. After this, it&#039;s merely an losetup -o &amp;lt;offset&amp;gt; /dev/loopX &amp;lt;nameofimagefile&amp;gt; and you have the partition mapped to your /dev/loopX (having X being something typically 0-255. After this, just mount it or run pvscan/vgscan/lvscan to probe whatever lvm config is there, and you should be able to mount it like any other filesystem.&lt;br /&gt;
&lt;br /&gt;
== kpartx ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;kpartx&#039;&#039;&#039; does the same as above, more or less, just without so much hassle. Most of it should be automatic and easy to deal with, except it may fail to disconnect the loopback devices sometimes, so you may have to &#039;&#039;&#039;losetup -d&#039;&#039;&#039; them manually. See the manual, &#039;&#039;&#039;kpartx (8)&#039;&#039;&#039;. Please note that &#039;&#039;&#039;partx&#039;&#039;&#039; works similarly and I&#039;d guess the authors of the two tools are arguing a lot of which one&#039;s the best.&lt;br /&gt;
&lt;br /&gt;
== guestmount ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;guestmount&#039;&#039;&#039; is something similar again, but also supports file formats like &#039;&#039;&#039;qcow2&#039;&#039;&#039; and possibly other, proprietary filesystems like &#039;&#039;&#039;vmdk&#039;&#039;&#039; and &#039;&#039;&#039;vdi&#039;&#039;&#039;, but don&#039;t take my word for it - I haven&#039;t tested. Again, see the manual or just read up on the description [http://ask.xmodulo.com/mount-qcow2-disk-image-linux.html?fbclid=IwAR3snTeZvGzp9PLdX11EQhCfOpux6I93CiJ3A2pUomkkRLly9Xo4851mkTY here]. It seems rather trivial.&lt;br /&gt;
&lt;br /&gt;
= Linux on laptops =&lt;br /&gt;
&lt;br /&gt;
== Wifi with HP EliteBook 725/745 on Ubuntu ==&lt;br /&gt;
&lt;br /&gt;
The HP EliteBook 725/745 and similar are equipped with a BCM4352 wifi chip. As with a lot of other stuff from Broadcom, this lacks an open hardware description, so thus no open driver exist. The proper fix, is to replace the NIC with something with an open driver, but again, this isn&#039;t always possible, so a binary driver exists. In ubuntu, run, somehow connect the machine to the internet and run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install bcmwl-kernel-source&lt;br /&gt;
sudo modprobe wl&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you can&#039;t connect the machine to the internet, download the needed packages on another machine and put it on some usb storage. These packages should suffice:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# apt-cache depends bcmwl-kernel-source&lt;br /&gt;
bcmwl-kernel-source&lt;br /&gt;
  Depends: dkms&lt;br /&gt;
  Depends: linux-libc-dev&lt;br /&gt;
  Depends: libc6-dev&lt;br /&gt;
  Conflicts: &amp;lt;bcmwl-modaliases&amp;gt;&lt;br /&gt;
  Replaces: &amp;lt;bcmwl-modaliases&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then install manually with &#039;&#039;&#039;dpkg -i file1.deb file2.deb&#039;&#039;&#039; etc&lt;br /&gt;
&lt;br /&gt;
After this, ip/ifconfig/iwconfig shouldd see the new wifi nic, probably &#039;&#039;&#039;wlan0&#039;&#039;&#039;, but due to a [https://bugs.launchpad.net/ubuntu/+source/broadcom-sta/+bug/1343151 old, ignored bug], you won&#039;t find any wifi networks. This is because the driver from Broadcom apparently does not support interrupt remapping, commonly used on x64 machines. To turn this off, change &#039;&#039;&#039;/etc/default/grub&#039;&#039;&#039; and change the line &#039;&#039;&#039;GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;quiet splash&amp;quot;&#039;&#039;&#039;, adding intremap=off to the end before the quote: &#039;&#039;&#039;GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;quiet splash intremap=off&amp;quot;&#039;&#039;&#039;. Save the file and run &#039;&#039;&#039;sudo update-grub&#039;&#039;&#039; and reboot. After this, wifi should work well.&lt;br /&gt;
&lt;br /&gt;
== Wifi with HP Compaq Presario CQ57 on Ubuntu ==&lt;br /&gt;
&lt;br /&gt;
The HP Compaq Presario CQ57 uses the RT5390 wifi chipset. This has been supported for quite some time now, and I was quite surprised to find it not working on a laptop a friend was having. The driver loaded correctly, but Ubuntu insisted of the laptop being in &#039;&#039;&#039;flight mode&#039;&#039;&#039;. Checking &#039;&#039;&#039;rfkill&#039;&#039;&#039;, it showed me two NICs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# rfkill list all&lt;br /&gt;
0: phy0: Wireless LAN&lt;br /&gt;
	Soft blocked: no&lt;br /&gt;
	Hard blocked: yes&lt;br /&gt;
1: hp-wifi: Wireless LAN&lt;br /&gt;
	Soft blocked: yes&lt;br /&gt;
	Hard blocked: no&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Turning rfkill on and off resulted in nothing much, except some error messages in the kernel log (dmesg)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] ACPI Error: Field [B128] at bit offset/length 128/1024 exceeds size of target Buffer (160 bits) (20170831/dsopcode-235)&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]&lt;br /&gt;
                            Initialized Local Variables for Method [HWCD]:&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Local0: 00000000a34b7928 &amp;lt;Obj&amp;gt;           Integer 0000000000000000&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Local1: 00000000b0aa6865 &amp;lt;Obj&amp;gt;           Buffer(8) 46 41 49 4C 04 00 00 00&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Local5: 00000000a9811efd &amp;lt;Obj&amp;gt;           Integer 0000000000000004&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] Initialized Arguments for Method [HWCD]:  (2 arguments defined for method invocation)&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Arg0:   0000000078957d1b &amp;lt;Obj&amp;gt;           Integer 0000000000000001&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Arg1:   00000000725c9c6e &amp;lt;Obj&amp;gt;           Buffer(20) 53 45 43 55 02 00 00 00&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] ACPI Error: Method parse/execution failed \_SB.WMID.HWCD, AE_AML_BUFFER_LIMIT (20170831/psparse-550)&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] ACPI Error: Method parse/execution failed \_SB.WMID.WMAD, AE_AML_BUFFER_LIMIT (20170831/psparse-550)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After upgrading BIOS and testing different kernels, I was asked to try to unload the &#039;&#039;&#039;hp_wmi&#039;&#039;&#039; driver. I did, and things changed a bit, so I tried blacklisting it, creating the file &#039;&#039;&#039;/etc/modprobe.d/blacklist-hp_wmi.conf&#039;&#039;&#039; with the following content&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Blacklist this - it doesn&#039;t work!&lt;br /&gt;
blacklist hp_wmi&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
I gave the machine a reboot and afte that, the &#039;&#039;&#039;hp-wifi&#039;&#039;&#039; entry was gone in the rfkill output, and things works.&lt;br /&gt;
&lt;br /&gt;
= Raspberry pi =&lt;br /&gt;
&lt;br /&gt;
I couldn&#039;t quite decide if the raspberry pi should be a separate section or part of Linux, but hell, it can run more than Linux, although 99,lots% of people just uses Linux on them. This is a small list of things to know about them; things not on the front page of the manual or perhaps hidden even better.&lt;br /&gt;
&lt;br /&gt;
== Which pi? ==&lt;br /&gt;
&lt;br /&gt;
I just setup three raspberry pi machines and although some are quite different, like v1 to vEverythingelse or the Pi zero versions to the normal ones, not all of us remember how to distinguish between them, and sometimes they&#039;re in a nice 3d printed (or otherwise) chassis or otherwise hidden. So, how to check three different ones:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
root@home-assistant:~ $ cat /proc/device-tree/model ; echo&lt;br /&gt;
Raspberry Pi 2 Model B Rev 1.1&lt;br /&gt;
&lt;br /&gt;
root@green-pi:~ $ cat /proc/device-tree/model ; echo&lt;br /&gt;
Raspberry Pi 3 Model B Rev 1.2&lt;br /&gt;
&lt;br /&gt;
roy@yellow-pi:~ $cat /proc/device-tree/model ; echo&lt;br /&gt;
Raspberry Pi 4 Model B Rev 1.1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
While this works well, for the latter, the pi4, it doesn&#039;t tell how much memory I have. It comes in variants of 1, 2 and 4GB, and this is the latter.&lt;br /&gt;
&lt;br /&gt;
== Monitoring ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;vcgencmd&#039;&#039;&#039; from &#039;&#039;&#039;/opt/vc/bin&#039;&#039;&#039;, but symlinked to &#039;&#039;&#039;/usr/bin&#039;&#039;&#039; so it&#039;s available in path, is useful for fetching hardware info about the pi. For example, measuring the temperature&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
root@yellow-pi:~# vcgencmd measure_temp&lt;br /&gt;
temp=63.0&#039;C&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The command is generally badly documented and parts of it seems outdated for newer hardware. Here&#039;s the output from a Raspberry pi 4 with 4GB RAM&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
roy@yellow-pi:~ $ vcgencmd get_mem arm&lt;br /&gt;
arm=948M&lt;br /&gt;
roy@yellow-pi:~ $ vcgencmd get_mem gpu&lt;br /&gt;
gpu=76M&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= BIOS upgrade from Linux =&lt;br /&gt;
&lt;br /&gt;
Generally, BIOS upgrades have been moved to the BIOS itself these days. This saves a lot of work and quite possibly lives after those who earier rammed their heads through walls, now can upgrade directly from the internet instead of using obscure operating systems best avoided. Sometimes, however, one must use these nevertheless. This is a quick run-through on your options.&lt;br /&gt;
&lt;br /&gt;
== DOS ==&lt;br /&gt;
&lt;br /&gt;
Most non-automatic BIOS upgrades are installed from DOS. Doing a BIOS upgrade this way, is generally non-problematic. Just install a USB thingie with [https://www.freedos.org/ FreeDOS], copy your file(s) onto the thing and boot on it. The commandline is the same as old MS/DOS, except a wee bit more userfriendly, but not a lot.&lt;br /&gt;
&lt;br /&gt;
== Windows ==&lt;br /&gt;
&lt;br /&gt;
Some macahines, like laptops from &#039;&#039;&#039;HP&#039;&#039;&#039;, may have BIOS upgrades that are made to be installed from Windows and won&#039;t run in FreeDOS or MS/DOS, instead throwing an error, saying &#039;&#039;&#039;This program cannot be run in DOS mode&#039;&#039;&#039;. This means you&#039;ll have to boot on a Windows rescue disc and do the job from there. Googling this, tells you it&#039;s quite easy, you just choose &#039;make rescue disc&#039; from Windows, and it&#039;s all good, except if you don&#039;t run Windows, that is. To remedy this problem, do as follows:&lt;br /&gt;
&lt;br /&gt;
=== Download Windows ===&lt;br /&gt;
&lt;br /&gt;
Since you don&#039;t run Windows and possibly don&#039;t have a spouse or friend around with such unhealthy habits either, you need to get it. It&#039;s quite easy - just google &#039;download windows&#039; and it&#039;ll send you to [https://www.microsoft.com/en-us/software-download/windows10ISO somewhere like this].&lt;br /&gt;
&lt;br /&gt;
=== Burn it! ===&lt;br /&gt;
&lt;br /&gt;
Now it&#039;s time to burn the installer on a DVD ROM. You&#039;ll need a double-layered one, since the OS is &amp;gt; 4.7GiB, but I&#039;m sure you have a ton of those lying around. Now, just place your optical medium in your optical drive and burn, baby, burn!&lt;br /&gt;
&lt;br /&gt;
=== Or make a USB thing? ===&lt;br /&gt;
&lt;br /&gt;
Not a lot of machines have optical drives these days, so you may want to use an USB pen drive or something instead. This is easy, just make the USB bootable with the Windows application Microsoft has made for this. Unfortunately, this only runs on Windows, and unlike stuff like Debian, where the &#039;&#039;&#039;iso&#039;&#039;&#039; file can be dd&#039;ed directly onto a USB drive to make it bootable, the Windows &#039;&#039;&#039;iso&#039;&#039;&#039;s don&#039;t come with this luxury. There are lots of methods to make bootable USB things from iso files out there, but the only thing most of them have in common, is that they generally don&#039;t work.&lt;br /&gt;
&lt;br /&gt;
==== WoeUSB ====&lt;br /&gt;
&lt;br /&gt;
After hours of swearing, it&#039;s nice to come across software like [https://github.com/slacka/WoeUSB WoeUSB]. It may not be perfect, it relies on a bunch of GUI stuff you&#039;ll never need and so on, but it &#039;&#039;&#039;&#039;&#039;works&#039;&#039;&#039;&#039;&#039;, and that&#039;s the important part! Just clone the repo and RTFM and it&#039;s all nice. It&#039;s slow, but hell, getting a windows machine and/or an optical drive might be slower.&lt;br /&gt;
&lt;br /&gt;
WoeUSB does nothing fancy, but it &#039;&#039;&#039;does&#039;&#039;&#039; work. It will create a filesystem, FAT32 or NTFS (better use NTFS, FAT32 has its limits). It creates normal filesystems and so on. Just make sure to copy in the BIOS update file, usually an exe file, to run when Windows is up and running.&lt;br /&gt;
&lt;br /&gt;
==== Install BIOS ====&lt;br /&gt;
&lt;br /&gt;
Boot on the Windows USB thing and choose &#039;repair computer&#039; and then &#039;command prompt&#039;. Find the install file, and if you&#039;re lucky, you&#039;ll find it needs a 32bit OS, just like I did. Since the 64bit version doesn&#039;t include 32bit compatibility in the installer, revert to downloading the 32bit version of windows and start over. Pray to your favourite god(s) not to get across such machines again - it might help.&lt;br /&gt;
&lt;br /&gt;
= 3D printer stuff =&lt;br /&gt;
&lt;br /&gt;
== Hydrophilic filament ==&lt;br /&gt;
&lt;br /&gt;
Most popular filament types, including PLA, PETG, PP or PA (Polyamide, normally known as Nylon) and virtualy any filament type named [https://www.matterhackers.com/news/filament-and-water poly-something] (and thus with an acronym of P-something) are hydrophilic (also (somewhat incorrectly) called hydroscopic), meaning so long they&#039;re dryer than the atmosphere around them, they&#039;ll do their best to suck out the atmosphere&#039;s humidity. This is why most filament are shrink-wrapped with a small bag of silica gel in it. If such filament is exposed for normal humid air for some time, it&#039;ll become very hard to use. Most of my experience is with PLA, which can handle a bit (depending on make), but still not a lot. With PLA, if you end up with prints where the filament seems not to stick, it may help with a higher temperature. Otherwise, the filament must be [https://all3dp.com/2/how-to-dry-filament-pla-abs-and-nylon/ baked]. If you don&#039;t want to use your oven, try something like a [https://www.jula.no/catalog/hjem-og-husholdning/kjokkenmaskiner/mattilberedningsapparater/frukt-sopptorker/frukt-sopptorker-001641/#tab02 fruit and mushroom dryer]. Then get a good, sealble plastic box and add something like half a kilogram of [https://www.ebay.com/sch/sis.html?_nkw=1KG+Orange+Replacement+Desiccant+Indicating+Silica+Gel+Beads+for+Drawers%2C+Camera&amp;amp;_id=131938742628&amp;amp;&amp;amp;_trksid=p2057872.m2749.l2658 silica gel] to an old sock, tie it and put it in the your new dry box.&lt;br /&gt;
&lt;br /&gt;
Please note that ABS is hydrophobic, so you won&#039;t have to worry too much there. Also, remember that PA/Nylon is extremely hydrophilic. Even a couple of days in normal air humidity can ruin it completely and will require baking.&lt;br /&gt;
&lt;br /&gt;
== Upgrading the firmware on an Ender 3 ==&lt;br /&gt;
&lt;br /&gt;
This is about upgrading the firmware, and thus also flashing a bootloader to the Creality Ender 3 3D printer. Most of this is well documented on several place, like o [https://www.youtube.com/watch?v=fIl5X2ffdyo the video from Teaching tech] and elsewhere, but I&#039;ll just summarise some issues I had.&lt;br /&gt;
&lt;br /&gt;
=== Using an arduino Nano as a programmer ===&lt;br /&gt;
&lt;br /&gt;
Quick note before you read on. If you have an Ender 3 controller version 1.1.5 or newer (or perhaps even a bit older), a CR-10S or some other more or less modern printers or controllers, they come with a bootloader installed already, so don&#039;t bother flashing one. The one that&#039;s in there already, should work well. So if you have one of these, just skip this and jump to the [[Roy&#039;s_notes#Flashing_the_printer|next section]].&lt;br /&gt;
&lt;br /&gt;
However, the normal CR-10 (without the S), Ender 3 and a few other printers from Creality come without a bootloader, so you&#039;ll need to flash one before upgrading the firmware. Well, strictly speakning, you don&#039;t need one, you can save those 8kB or so for other stuff and use a programmer to write the whole firmware, but then you&#039;ll need to wire up everything every time you want a new firmware, so in my world, you &#039;&#039;&#039;do&#039;&#039;&#039; need the bootloader, since it&#039;s easier.&lt;br /&gt;
&lt;br /&gt;
To install a bootloader, you&#039;ll need a programmer, and I didn&#039;t have one available. Having some el-cheapo china-copies of Arduinos around, I read I could use one and tried so. Although the docs mostly mention the Uno etc, it&#039;s just as simple with the Nano copy.&lt;br /&gt;
&lt;br /&gt;
So, grab an arduino, plug it to your machine with a USB cable, and, using the Arduino IDE, use the ArduinoISP sketch there (found under Examples) to burn the software needed for the arduino to work as a programmer. When this is done, connect a 10µF capacitor between RST and GND to stop it from resetting when used as a programmer. Connect the MOSI, MISO and SCK pins from the ICSP block (that little isolated 6-pin block on top of the ardu). See [https://www.arduino.cc/en/Tutorial/ArduinoISP here] for a pinout. Then find Vcc and GND either on the ICSP block or elsewhere. Some sites say that on some boards you shouldn&#039;t use the pins on the ICSP block for this. I doubt it matters, though. Then connect another jumper wire from pin 10 on the ardu to work as the reset pin outwards to the chip being programmed (that is, on the printer). The ICSP jumper block pin layout is the same on the printer and on the ardu, and probably elsewhere. Sometimes [https://xkcd.com/927/ standardisation] actually works…&lt;br /&gt;
&lt;br /&gt;
See https://cloud.karlsbakk.net/index.php/s/zw48YJjzaf8Rc2F for a pic with the ardu (this wiki is broken atm, will fix it later)&lt;br /&gt;
&lt;br /&gt;
== Flashing the printer ==&lt;br /&gt;
&lt;br /&gt;
When the boot loader is in place, possibly after some wierd errors from during the process, the screen on the 3d printer will go blank and it&#039;ll behave like being bricked. This is ok. Now disconnect the wires and connect the USB cable between computer and printer. If you haven&#039;t installed support for the Sanguino board, that is, the variant of the 1284-chip and surrounding electronics that is the core of the, you need to install it first. In the Arduino IDE, choose the Tools / Boards / Boards manager boot option and search for Sanguino. After this, you should find the Sanguino or Sanguino 1284p in the boards menu. After this, you should be able to communicate with the printer&#039;s controller. Download the [https://www.th3dstudio.com/knowledgebase/th3d-unified-firmware-package/ TH3D unified firmware], making sure it&#039;s the last version. Uncompress the zip and with Finder/Explorer/whateversomething&#039;scalledonlinux, browse to &#039;&#039;&#039;TH3DUF_R2/Firmware/TH3DUF_R2.ino&#039;&#039;&#039; and open it. It should open directly in the Android IDE. Keep in mind that the names TH3DUF_R2 and TH3DUF_R2.ino will vary between versions, but you get the point. Now configure it for your particular needs. You&#039;ll find most of this in the Configuration.h tab (that&#039;s really a file). Most of the other files won&#039;t be necessary unless you&#039;re doing some more advanced stuff, like replacing th controller with something non-standard or similar, but then again, that&#039;s another chapter (or book, even). The video mentioned above describes this well. After flashing the new firmware, you&#039;ll probably get some timeouts and errors, since apparently it resets the printer after giving it the new firmware, but without notifying the flashing software of it doing so. If this happens, calm down and reboot the printer and check its tiny monitor - it should work. If it doesn&#039;t work, and if you flashed the bootload yourself, try to flash it again, and if that doesn&#039;t work, try flashing the programmer again yet another time, just for kicks. Again, if you have a newer controller like the v1.1.5, don&#039;t touch the bootloader, as the one already installed, should work well as it is.&lt;br /&gt;
&lt;br /&gt;
PS: I tried enabling &#039;&#039;&#039;MANUAL_MESH_LEVELING&#039;&#039;&#039;, which in the code says that &#039;&#039;If used with a 1284P board the bootscreen will be disabled to save space&#039;&#039;. This effectively disabled the whole printer, and apparently may be making the firmware image a wee bit too large for it to fit the 1284P on the ender. It works well without it, though, and it may be fixed by now, since I tested this back in early 2019.&lt;br /&gt;
&lt;br /&gt;
== And then… ==&lt;br /&gt;
&lt;br /&gt;
With the new firmware in place, the printer should work as before, although with thermal runaway protection to better avoid fires in case the shit hits the fan, and to allow for things like autolevelling. With any luck, [https://www.precisionpiezo.co.uk/ this thing] may be ready for use by the time you read this - it surely looks nice!&lt;br /&gt;
&lt;br /&gt;
= Octoprint/Octopi =&lt;br /&gt;
roy&lt;/div&gt;</summary>
		<author><name>Roy</name></author>
	</entry>
	<entry>
		<id>https://wiki.malinux.no/index.php?title=Roy%27s_notes&amp;diff=164</id>
		<title>Roy&#039;s notes</title>
		<link rel="alternate" type="text/html" href="https://wiki.malinux.no/index.php?title=Roy%27s_notes&amp;diff=164"/>
		<updated>2020-07-20T15:54:26Z</updated>

		<summary type="html">&lt;p&gt;Roy: /* Raspberry pi */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= LVM, md and friends =&lt;br /&gt;
&lt;br /&gt;
== Linux&#039; Logical Volume Manager (LVM) ==&lt;br /&gt;
&lt;br /&gt;
=== LVM in general ===&lt;br /&gt;
&lt;br /&gt;
LVM is designed to be an abstraction layer on top of physical drives or RAID, typically [https://raid.wiki.kernel.org/index.php/RAID_setup mdraid] or [https://help.ubuntu.com/community/FakeRaidHowto fakeraid]. Keep in mind that fakeraid should be avoided unless you really need it, like in conjunction with dual-booting linux and windows on fakeraid. LVM broadly consists of three elements, the &amp;quot;physical&amp;quot; devices (PV), the volume group (VG) and the logical volume (LV). There can be multiple PVs, VGs and LVs, depending on requirement. More about this below. All commands are given as examples, and all of them can be fine-tuned using extra flags in need of so. In my experience, the defaults work well for most usecases.&lt;br /&gt;
&lt;br /&gt;
I&#039;m mentioning filesystem below too. Where I write ext4, the samme applies to ext2 and ext3.&lt;br /&gt;
&lt;br /&gt;
==== Create a PV ====&lt;br /&gt;
&lt;br /&gt;
A PV is the &amp;quot;physical&amp;quot; parts. This does not need to be a physical disk, but can also be another RAID, be it an mdraid, fakeraid, hardware raid, a virtual disk on a SAN or otherwisee or a partition on one of those. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#  These add three PVs, one on a drive (or hardware raid) and another two on mdraids.&lt;br /&gt;
pvcreate /dev/sdb&lt;br /&gt;
pvcreate /dev/md1 /dev/md2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For more information about pvcreate, see [https://linux.die.net/man/8/pvcreate the manual].&lt;br /&gt;
&lt;br /&gt;
==== Create a VG ====&lt;br /&gt;
&lt;br /&gt;
The volume group consists of one or more PVs grouped together on which LVs can be placed. If several PVs are grouped in a VG, it&#039;s generally a good idea to make sure these PVs have some sort of redundancy, as in mdraid/fakeraid or hwraid. Otherwise it will be like using a [https://en.wikipedia.org/wiki/RAID RAID-0] with a single point of failure on each of the independant drives. LVM has [https://unix.stackexchange.com/questions/150644/raiding-with-lvm-vs-mdraid-pros-and-cons  RAID code in it] as well, so you can use that. I haven&#039;t done so myself, as I generally stick to mraid. The reason is mdraid is, in my opinion older and more stable and has more users (meaning bugs are reported and fixed faster whenever they are found). That said, I beleive the actual RAID code used in LVM RAID are the same function calls as for mdraid, so it may not be much of a difference. I still stick with mdraid. To create a VG, run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create volume group my_vg&lt;br /&gt;
vgcreate my_vg /dev/md1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that if vgcreate is run with a PV (as /dev/md1 above) that is not defined as a PV (like above), this is done implicitly, so if you don&#039;t need any special flags to pvcreate, you can simply skip it and let vgcreate do that for you.&lt;br /&gt;
&lt;br /&gt;
==== Create an LV ====&lt;br /&gt;
&lt;br /&gt;
LVs can be compared to partitions, somehow, since they are bounderies of a fraction or all of that of a VG. The difference between them and a partition, however, is that they can be grown or shrunk easily and also moved around between PVs without downtime. This flexibility makes them superiour to partitions as your system can be changed without users noticing it. By default, an LV is alloated &amp;quot;thickly&amp;quot;, meaning all the data given to it, is allocated from the VG and thus the PV. The following makes a 100GB LV named &amp;quot;thicklv&amp;quot;. When making an LV, I usually allocate what&#039;s needed plus some more, but not everything, just to make sure it&#039;s space available for growth on any of the LVs on the VG, or new LVs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a thick provisioned LV named thicklv on the VG my_vg&lt;br /&gt;
lvcreate -n thicklv -L 100G my_vg&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After the LV is created, a filesystem can be placed on it unless it is meant to be used directly. The application for direct use include swap space, VM storage and certain database systems. Most of these will, however, work on filesystems too, although my testing has shown that on swap space, there is a significant performance gain for using dedicated storage without a filesystem. As for filesystems, most Linux users use either ext4 or xfs. Personally, I generally use XFS these days. See my notes below on filesystem choice.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a filesystem on the LV - this could have been mkfs -t ext4 or whatever filesystem you choose&lt;br /&gt;
mkfs -t xfs /dev/my_vg/thicklv&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then just edit /etc/fstab with correct data and run mount -a, and you should be all set.&lt;br /&gt;
&lt;br /&gt;
==== Create LVM cache ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
lvcreate -L 1G -n _cache_meta data /dev/md1&lt;br /&gt;
&lt;br /&gt;
lvcreate -l100%FREE -n _cache data /dev/md1&lt;br /&gt;
&lt;br /&gt;
# Some would want --cachemode writeback, but seriously, I wouldn&#039;t recommend it. Metadata or data can be easily corrupted in case of failure.&lt;br /&gt;
lvconvert --type cache-pool --cachemode writethrough --poolmetadata data/_cache_meta data/_cache&lt;br /&gt;
&lt;br /&gt;
lvconvert --type cache --cachepool data/_cache data/data&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Disabling LVM cache ====&lt;br /&gt;
&lt;br /&gt;
If you for some reason want to disable caching, this will do it cleanly and remove the LVs earlier created for caching the main device.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
lvconvert --uncache data/data&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Growing devices ====&lt;br /&gt;
&lt;br /&gt;
LVM objects can be grown and shrunk. If a PV resides on a RAID where a new drive has been added or otherwise grown, or on a partition or virtual disk that has been extended, the PV must be updated to reflect these changes. The following command will grow the PV to the maximum available on the underlying storage. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Resize the PV /dev/md (not the RAID, only the PV on the RAID) to its full size&lt;br /&gt;
pvresize /dev/md1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If a new PV is added, the VG can be grown to add the space on that in addition to what&#039;s there already. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Extend my_vg to include md2 and its space&lt;br /&gt;
vgextend my_vg /dev/md2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
With more space available in the VG, the LV can now be extended. Let&#039;s add another 50GB to it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Extend thicklv - add 50GB. If you know you won&#039;t need the space anywhere else, you may want to&lt;br /&gt;
# lvresize -l+100%FREE instead. Keep in mind the difference between -l (extents) and -L (bytes)&lt;br /&gt;
lvresize -L +50G my_vg/thicklv&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Growing filesystems ====&lt;br /&gt;
After the LV has grown, run &#039;&#039;xfs_growfs&#039;&#039; (xfs) or &#039;&#039;resize2fs&#039;&#039; (ext4) to make use of the new data. To grow the filesystem to all available space on ext4, run the below command.  To partly grow the filesystem or to shrink it or otherwise, please see the manuals.&lt;br /&gt;
&lt;br /&gt;
The filesystem can be mounted when this is run. If you for some reason get an &#039;&#039;&#039;access denied&#039;&#039;&#039; error when running this as root or with sudo, it&#039;s likely caused by a filesystem error. To fix this, unmount the filesystem first and run &#039;&#039;&#039;fsck -f /dev/my_vg/thicklv&#039;&#039;&#039; and remount it before retrying to extend it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
resize2fs /dev/my_vg/thicklv&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Similarly, with XFS, but note that xfs_growfs doesn&#039;t take the device name, but the filesystem&#039;s mount point. In the case of XFS, also note that the filesystem &#039;&#039;&#039;&#039;&#039;must&#039;&#039;&#039;&#039;&#039; be mounted to be grown. This, in contrast to how it was in the old days when filesystems had to be unmounted to be grown.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
xfs_growfs /my_mountpoint&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Rename system VG ====&lt;br /&gt;
&lt;br /&gt;
Some distros create VG names like those-from-a-sysadmin-with-a-well-developed-paranoia-not-to-hit-a-duplicate. Debian, for instance, uses names like &amp;quot;my-full-hostname-vg&amp;quot;. Personally, I don&#039;t like these, since if I were to move a disk or vdisk around to somewhere else, I&#039;d make sure not to add a disk named &#039;sys&#039; to an existing system. If you do, most distros will refuse to use the VGs with duplicate names, resulting in the OS not booting until either one is specified by its UUID or just one removed. As I&#039;m aware of this, I stick to the super-risky thing of all system VGs named &#039;sys&#039; and so on.&lt;br /&gt;
&lt;br /&gt;
If you do this, keep in mind that it may blow up your computer and take your girl- or boyfriend with it or even make either of them pregnant, allowing Trump to rule your life and generally make things suck. You&#039;re on your own!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Rename the VG&lt;br /&gt;
vgrename my-full-hostname-vg sys&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, in /boot/grub/grub.cfg, change the old lv path from something like &#039;/dev/mapper/debian--stretch--machine--vg-root&#039; to your new and fancy &#039;/dev/sys/root. Likewise, in /etc/fstab, change occurences of &#039;/dev/mapper/debian--stretch--machine--vg-&#039; (or similar) with &#039;/dev/sys/&#039;. Here, this was like this - the old ones commented out.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;fstab&amp;quot;&amp;gt;&lt;br /&gt;
#/dev/mapper/debian--stretch--box--vg-root      /               ext4            errors=remount-ro,discard       0       1&lt;br /&gt;
/dev/sys/root                                   /               ext4            errors=remount-ro,discard       0       1&lt;br /&gt;
# /boot was on /dev/vda1 during installation&lt;br /&gt;
UUID=myverylonguuidwithatonofgoodinfoinit       /boot           ext2            defaults                        0       2&lt;br /&gt;
#/dev/mapper/debian--stretch--box--vg-swap_1    none            swap            sw                              0       0&lt;br /&gt;
/dev/sys/swap_1                                 none            swap            sw                              0       0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Update /etc/initramfs-tools/conf.d/resume with similar data for swap.&lt;br /&gt;
&lt;br /&gt;
You might want to run &#039;update-initramfs -u -k all&#039; after this, but I&#039;m not sure if it&#039;s needed.&lt;br /&gt;
&lt;br /&gt;
Now, pray to the nearest god(s) and give it a reboot and it should (probably) work.&lt;br /&gt;
&lt;br /&gt;
After reboot, run &#039;&#039;&#039;swapoff -a&#039;&#039;&#039;, then &#039;&#039;&#039;mkswap /dev/sys/swap_1&#039;&#039;&#039; (or whatever it&#039;s called on your system) and &#039;&#039;&#039;swapon -a&#039;&#039;&#039; again. You may want to give it another reboot or two for kicks, but it should work well even without that.&lt;br /&gt;
&lt;br /&gt;
=== Migration tools ===&lt;br /&gt;
&lt;br /&gt;
At times, storage regimes change, new storage is added and sometimes it&#039;s not easy to migrate with the current hardware or its support systems. Once I had to migrate a 45TiB fileserver from one storage system to another, preferably without downtime. The server originally had three 15TiB PVs of which two were full and the third half full. I resorted to using [https://linux.die.net/man/8/pvmove pvmove] to just move the data on the PVs in use to a new PV. We started out with creating a new 50TiB PV, sde, and then to pvmove.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Attach /dev/sde to the VG my_vg&lt;br /&gt;
vgextend my_vg /dev/sde&lt;br /&gt;
&lt;br /&gt;
# Move the contents from /dev/sdb over to /dev/sde block by block. If a target is not given in pvmove,&lt;br /&gt;
# the contents of the source (sdb here) will be put somewhere else in the pool.&lt;br /&gt;
pvmove /dev/sdb /dev/sde&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This took a while (as in a week or so) - the pvmove command uses old code and logic (or at least did that when I migrated this in November 2016), but it affected performance on the server very little, so users didn&#039;t notice. After the first PV was migrated, I continued with the other two, one after the other, and after a month or so, it was migrated. We used this on a number of large fileservers, and it worked flawlessly. Before doing the production servers I also tried interrupting pvmove in various ways, including hard resets, and it just kept on after the reboot.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;NOTE:&#039;&#039;&#039;&#039;&#039; &#039;&#039;Even though it worked well for us, &#039;&#039;&#039;always&#039;&#039;&#039; keep a good backup before doing this. Things may go wrong, and without a good backup, you may be looking for a hard-to-find new job the next morning&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
==== mdadm workarounds ====&lt;br /&gt;
&lt;br /&gt;
===== Migrate from a mirror (raid-1) to raid-10 =====&lt;br /&gt;
&lt;br /&gt;
Create a mirror&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sdb /dev/sdc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
LVM (pv/vg/lv) on md0 (see above), put a filesystem on the lv and fill it with some data.&lt;br /&gt;
&lt;br /&gt;
Now, some months later, you want to change this to raid-10 to allow for the same amount of redundancy, but to allow more disks into the system.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mdadm --grow /dev/md0 --level=10&lt;br /&gt;
mdadm: Impossibly level change request for RAID1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So - no - doesn&#039;t work. But - we&#039;re on &lt;br /&gt;
&lt;br /&gt;
Since we&#039;re on lvm already, this&#039;ll be easy. If you&#039;re using filesystems directly on partitions, you can do this the same way, but without the pvmove part, using rsync or whateever you like instead. I&#039;d recommend using lvm for for the new raid, which should be rather obvious from this article. Now plug in a new drive and create a new raid10 on that one. If you two new drives, install both. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# change &amp;quot;missing&amp;quot; to the other device name if you installed two new drives&lt;br /&gt;
mdadm --create /dev/md1 --level=10 --raid-devices=2 /dev/vdd missing&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, as described above, just vgextend the vg, adding the new raid and run pvmove to move the data from the old pv (residing on the old raid1) to the new pv (on raid10). Afte rpvmove is finished (which may take awile, see above), just&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
vgreduce raidtest /dev/md0&lt;br /&gt;
pvremove /dev/md0&lt;br /&gt;
mdadm --stop /dev/md0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
…and your disk is free to be added to the new array. If the new raid is running in degraded mode (if you created it with just one drive), better don&#039;t wait too long, since you don&#039;t have redundancy. Just mdadm --add the devs.&lt;br /&gt;
&lt;br /&gt;
If you now have /dev/mdstat telling you your raid10 is active and have three drives, of which one is a spare, it should look something like this&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5] [raid4] [raid10]&lt;br /&gt;
md1 : active raid10 vdc[3](S) vdb[2] vdd[0]&lt;br /&gt;
      8380416 blocks super 1.2 2 near-copies [2/2] [UU]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Just mdadm --grow --raid-devices=3 /dev/md1&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;RAID section is not complete. I&#039;ll write more on migraing from raid10 to raid6 later. It&#039;s not straight forward, but easier than this one :)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== Thin provisioned LVs ===&lt;br /&gt;
&lt;br /&gt;
Thin provisioning on LVM is a method used for not allocating all the space given to an LV. For instance, if you have a 1TB VG and want to give an LV 500GB, although it currently only uses a fraction of that, a thin lv can be a good alternative. This will allow for adding a limit to how much it can use, but also to let it grow dynamically without manual work by the sysadmin. Thin provisioning adds another layer of abstaction by creating a special LV as a &#039;&#039;thin pool&#039;&#039; from which data is allocated to the &#039;&#039;thin volume(s)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== Create a thin pool ====&lt;br /&gt;
&lt;br /&gt;
Allocate 1TB to the thin pool to be used for thinly provisioned LVs. Keep in mind that the space allocated to the thin pool is in fact thick provisioned. Only the volumes put on &#039;&#039;thinpool&#039;&#039; are thin provisioned. This will create two hidden LVs, one for data and one for metadata. Normally the defaults will do, but check the manual if the data doesn&#039;t match the usual patterns (such as billions of files, resulting in huge amounts of metadata). I &#039;&#039;beleive&#039;&#039; the metadata part should be resizable at a later time if needed, but I have not tested it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a pool for thin LVs. Keep in mind that the pool itself is not thin provisioned, only the volumes residing on it&lt;br /&gt;
lvcreate --size 1T --type thin-pool --thinpool thinpool my_vg&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Create a thin volume ====&lt;br /&gt;
&lt;br /&gt;
You have the thinpool, now put a thin volume on it. It will allocate some space for metadata, but probably not much (a few megs, perhaps).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Now, create a volume with a virtual (-V) size of half a terabyte named thin_pool, but using the thinpool (-T) named thin_pool for storage&lt;br /&gt;
lvcreate -V 500G -T my_vg/thin_pool --name thinvol&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The new volume&#039;s device name will be /dev/thinvol. Now, create a filesystem on it, add to fstab and mount it. The &#039;&#039;&#039;df&#039;&#039;&#039; command will return available space according to the virtual size (-V), while lvs will show how much data is actually used on each of the thinly provisioned volumes.&lt;br /&gt;
&lt;br /&gt;
== Filesystem dilemmas ==&lt;br /&gt;
&lt;br /&gt;
=== XFS or ext4 or something else ===&lt;br /&gt;
The choice of filesystem varies for your use. Distros such as RHEL/CentOS has moved to XFS by default from v7. Debian/Ubuntu still sticks to ext4, like most other. I&#039;ll discuss my thoughts below on ext4 vs XFS and leave the other filesystems for later.&lt;br /&gt;
&lt;br /&gt;
==== ext4 ====&lt;br /&gt;
ext4 is probably the most used filesystem on linux as of writing. It&#039;s rock stable and has been extended by a lot of extensions since the original ext2. It still retains backward compatibility, being able to mount and fsck ext2 and ext3 with the ext4 driver. However, it doesn&#039;t handle large filesystems very well. If a filesystem is created for &amp;lt;16TiB, it cannot be grown to anything larger than 16TiB. This may have changed lately, though. One other issue is handling errors. If a large filesystem (say 10TiB) is damaged, an fsck may take several hours, leading to long downtime. When I refer to ext4 further in this text, the same applies to ext2 and ext3 unless otherwise specified.&lt;br /&gt;
&lt;br /&gt;
==== XFS ====&lt;br /&gt;
XFS, originally developed by SGI some time in the bronze age, but has been worked on heavily after that. RHEL and Centos version 7 and forward, uses XFS as the default filesystem. It is quick, it scales well, but it lacks at least two things ext4 has. It cannot be shrunk (not that you normally need that, but nice if you have a typo or you need to change things). Also, it doesn&#039;t allow for automatic fsck on bootup. If something is messed up on the filesystem, you&#039;ll have to login as root on the console (not ssh), which might be an issue on some systems. The fsck equivalent, xfs_repair, is a *lot* faster than ext4&#039;s fsck, though.&lt;br /&gt;
&lt;br /&gt;
==== ZFS ====&lt;br /&gt;
ZFS is like a combination of RAID, LVM and a filesystem, supporting full checksumming, auto-healing (given sufficient redundancy), compression, encryption, replication, deduplication (if you&#039;re brave and have a &#039;&#039;ton&#039;&#039; of memory) and a lot more. It&#039;s a separate chapter and needs a lot more talk than paragraph here.&lt;br /&gt;
&lt;br /&gt;
==== btrfs ====&lt;br /&gt;
btrfs, pronounced &amp;quot;butterfs&amp;quot; or &amp;quot;betterfs&amp;quot; or just spelled out, is a filesystem that mimics that of ZFS. It has been around for 10 years or so, but hasn&#039;t yet proven to be really stable. Following the progress of it for those years, I&#039;ve found it to be a nice toy with which to play, but not to be used in production. Again, others may say otherwise, but these are just my words.&lt;br /&gt;
&lt;br /&gt;
== Low level disk handling ==&lt;br /&gt;
&lt;br /&gt;
This section is for low-level handling of disks, regardless of storage system elsewhere. These apply to mdraid, lvmraid and zfs and possibly other solutions, with the exception of individual drives on hwraid (and maybe fakeraid), since there, the drives are hidden from Linux (or whatever OS).&lt;br /&gt;
&lt;br /&gt;
=== S.M.A.R.T. and slow drives ===&lt;br /&gt;
Modern (that is, from about 1990 or later) have S.M.A.R.T. (or just smart, since it&#039;s easier to type) monitoring built in, meaning the disk&#039;s controller is monitoring itself. This is handy and will ideally tell you in advance that a drive is flakey or dying. Modern (2010+) smart monitoring is more or less the same. It can be trusted about 50% of the time. Usually, if smart detects an error, it&#039;s a real error. I don&#039;t think I&#039;ve seen it reporting a false positive, but others may know better. &lt;br /&gt;
&lt;br /&gt;
==== smartmontools ====&lt;br /&gt;
First, install smartmontool and run smartclt -H /dev/yourdisk (/dev/sda or something) to get a health report. Then perhaps run smartctl -a /dev/yourdisk and look for &#039;current pending sectors&#039; This should be zero. Also check the temperature, which normally should be much above 50.&lt;br /&gt;
&lt;br /&gt;
==== single, slow drive ====&lt;br /&gt;
What may happen, is smart not seeing anything and life goes on like before, only slower and less prouductive, without telling anyone. If you stubler over this issue, you&#039;ll probably see it during a large rsync/zfs send/receive or a resync/rebuild/resilver of the raid/zpool. During this, it feels like everything is slow and your RAID has turned into a RAIF (redundant array of inexpensive floppies). To check if you have a single drive messing up it all, check with &#039;&#039;&#039;iostat -x 2&#039;&#039;&#039;, having 2 being the delay between each measurement. Interrupt it with ctrl+x. If there&#039;s a rougue drive there, it should stand out like sdg below&lt;br /&gt;
&lt;br /&gt;
 avg-cpu:  %user   %nice %system %iowait  %steal   %idle&lt;br /&gt;
            0.38    0.00    1.75    0.00    0.00   97.87&lt;br /&gt;
&lt;br /&gt;
 Device            r/s     w/s     rkB/s     wkB/s   rrqm/s   wrqm/s  %rrqm  %wrqm r_await w_await aqu-sz rareq-sz wareq-sz  svctm  %util&lt;br /&gt;
 sda              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdb              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdc              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdd              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sde              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdf              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdg              3.50    0.00   2352.00      0.00     0.00     0.00   0.00   0.00 14306.29    0.00  13.85   672.00     0.00 285.71 100.00&lt;br /&gt;
 sdh              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
&lt;br /&gt;
In ZFS land, you should be able to get similar data with &#039;&#039;&#039;zpool iostat -v &amp;lt;pool&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Now you know the bad drive (sdg), pull it from the raid with &#039;&#039;&#039;mdadm --fail /dev/mdX /dev/sdX&#039;&#039;&#039;. Now test the drive&#039;s performance manually, just simply:&lt;br /&gt;
&lt;br /&gt;
 # hdparm -t /dev/sdg&lt;br /&gt;
 &lt;br /&gt;
 /dev/sdg:&lt;br /&gt;
  Timing buffered disk reads:   2 MB in  5.37 seconds = 381.46 kB/sec&lt;br /&gt;
&lt;br /&gt;
Bingo - nothing you&#039;d want to keep. For a good drive, it should be something like 100-200MB/s&lt;br /&gt;
&lt;br /&gt;
PS: Keep in mind that you have a degraded RAID by now in case you had a spare waiting for things to happen.&lt;br /&gt;
&lt;br /&gt;
Try to replace the cable and/or try the disk on another port/controller. If the result from hdparm persists, it&#039;s probably a bad cable&lt;br /&gt;
&lt;br /&gt;
So, then, just psycially locate the drive, pull it out, take out the discs and magnets and recycle the rest.&lt;br /&gt;
&lt;br /&gt;
=== &amp;quot;Unplug&amp;quot; drive from system ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Find the device unit&#039;s number with something like&lt;br /&gt;
find /sys/bus/scsi/devices/*/block/ -name sdd&lt;br /&gt;
# returning /sys/bus/scsi/devices/3:0:0:0/block/sdd here, &lt;br /&gt;
# meaning 3:0:0:0 is the SCSI device we&#039;re looking for.&lt;br /&gt;
&lt;br /&gt;
# Given this is the correct device, and you want to &#039;unplug&#039; it, do so by&lt;br /&gt;
echo 1 &amp;gt; /sys/bus/scsi/devices/3:0:0:0/delete&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Rescan disk controllers ===&lt;br /&gt;
If a drive is added and for some reason doesn&#039;t get detected, or is removed by the command above, it can be rediscovered with a sysfs command to the scsi host to which it is connected. Since there may be quite a few of these, an easy way is to just scan them all and check the output of &#039;&#039;&#039;dmesg -T&#039;&#039;&#039; after running it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Make a list of controllers and send a rescan message to each of them. It won&#039;t do anything &lt;br /&gt;
# for those where nothing has changed, but it will show new drives where they have been added.&lt;br /&gt;
for host_scan in /sys/class/scsi_host/host*/scan&lt;br /&gt;
do&lt;br /&gt;
  echo &#039;- - -&#039; &amp;gt; $host_scan&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Fail injection with debugfs ===&lt;br /&gt;
[https://lxadm.com/Using_fault_injection https://lxadm.com/Using_fault_injection]&lt;br /&gt;
&lt;br /&gt;
== mdadm stuff ==&lt;br /&gt;
=== Resync ===&lt;br /&gt;
To resync a raid, that is, check, run&lt;br /&gt;
&lt;br /&gt;
 echo check &amp;gt; /sys/block/$dev/md/sync_action&lt;br /&gt;
&lt;br /&gt;
where $dev is something like md0. If you have several raids, something like this should work&lt;br /&gt;
&lt;br /&gt;
 for dev in md{0,1}&lt;br /&gt;
 do&lt;br /&gt;
   echo repair &amp;gt; /sys/block/$dev/md/sync_action&lt;br /&gt;
 done&lt;br /&gt;
&lt;br /&gt;
Also useful in a one-liner like&lt;br /&gt;
&lt;br /&gt;
 for dev in md{0,1} ; do echo repair &amp;gt; /sys/block/$dev/md/sync_action ; done&lt;br /&gt;
&lt;br /&gt;
Different raids on different drives will do this in parallel. If the drives are shared somehow with partitions or similar, the check or repair will wait for the other to finish before going on.&lt;br /&gt;
&lt;br /&gt;
As for repair vs check, [https://raid.wiki.kernel.org/index.php/RAID_Administration this article] describes it well. I stick to using repair unless it&#039;s something rare where I don&#039;t want to touch the data.&lt;br /&gt;
&lt;br /&gt;
=== Spare pools ===&lt;br /&gt;
In the old itmes, mdadm supported only a dedicated spare per md device, so if working with a large set of drives (20? 40?), where you&#039;d want to setup more raid sets to increase redundancy, you&#039;d dedicate a spare to each of the raid sets. This has changed (some time ago?), so in these modern, heathen days, you can change mdadm.conf, usually placed under /etc/mdadm, and add &#039;spare-group=somegroup&#039; where &#039;somegroup&#039; is a string identifying the spare group. After doing this, run &#039;&#039;&#039;update-initramfs -u&#039;&#039;&#039; and reboot and add a spare to one of the raid sets in the spare group, and md will use that or those spares for all the raidsets in that group.&lt;br /&gt;
&lt;br /&gt;
As some pointed out on #linux-raid @ irc.freenode.net, this feature is very badly documented, but as far as I can see, it works well.&lt;br /&gt;
&lt;br /&gt;
==== Example config ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create two raidsets&lt;br /&gt;
&lt;br /&gt;
mdadm --create /dev/md1 --level=6 --raid-devices=6 /dev/vd[efghij]&lt;br /&gt;
mdadm --create /dev/md2 --level=6 --raid-devices=6 /dev/vd[klmnop]&lt;br /&gt;
&lt;br /&gt;
# get their UUID etc&lt;br /&gt;
&lt;br /&gt;
mdadm --detail --scan&lt;br /&gt;
ARRAY /dev/md/1 metadata=1.2 name=raidtest:1 UUID=1a8cbdcb:f4092350:348b6b80:c054d74c&lt;br /&gt;
ARRAY /dev/md/2 metadata=1.2 name=raidtest:2 UUID=894b1b7c:cb7eba70:917d6033:ea5afd2b&lt;br /&gt;
&lt;br /&gt;
# Put those lines into /etc/mdadm/mdadm.conf and and add the spare-group&lt;br /&gt;
&lt;br /&gt;
ARRAY /dev/md/1 metadata=1.2 name=raidtest:1 spare-group=raidtest UUID=1a8cbdcb:f4092350:348b6b80:c054d74c&lt;br /&gt;
ARRAY /dev/md/2 metadata=1.2 name=raidtest:2 spare-group=raidtest UUID=894b1b7c:cb7eba70:917d6033:ea5afd2b&lt;br /&gt;
&lt;br /&gt;
# update the initramfs and reboot&lt;br /&gt;
&lt;br /&gt;
update-initramfs -u&lt;br /&gt;
reboot&lt;br /&gt;
&lt;br /&gt;
# add a spare drive to one of the raids&lt;br /&gt;
&lt;br /&gt;
mdadm --add /dev/md1 /dev/vdq&lt;br /&gt;
&lt;br /&gt;
# fail a drive on the other raid&lt;br /&gt;
&lt;br /&gt;
mdadm --fail /dev/md2 /dev/vdn&lt;br /&gt;
&lt;br /&gt;
# check /proc/mdstat to see md2 rebuilding with the spare from md1&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Recovery ===&lt;br /&gt;
&lt;br /&gt;
The other day, I came across a problem a user had on #linux-raid@irc.freenode.net. He had an old Qnap NAS that had died and tried plugging the drives in to his Linux machine and got various errors. The two-drive RAID-1 did not come up as it should, &#039;&#039;&#039;dmesg&#039;&#039;&#039; was full of errors from one of the drives (both connected on USB) and so forth.&lt;br /&gt;
&lt;br /&gt;
We went on and started by taking down the machine and just connecting one of the drives. I had him check what was assembled with&lt;br /&gt;
&lt;br /&gt;
 cat /proc/mdstat&lt;br /&gt;
&lt;br /&gt;
That returned /proc/md127 assembled, but LVM didn&#039;t find anything. So running a manual scan&lt;br /&gt;
&lt;br /&gt;
 pvscan --cache /dev/md127&lt;br /&gt;
&lt;br /&gt;
This made linux find the PV, VG and a couple of LVs, but probably because the mdraid was degraded, the LVs were deactivated, according to &#039;&#039;&#039;lvscan&#039;&#039;&#039;. Activating the one with a filesystem manually&lt;br /&gt;
&lt;br /&gt;
 lvchange -a y /dev/&amp;lt;vg&amp;gt;/&amp;lt;lv&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Substitute &amp;lt;vg&amp;gt; and &amp;lt;lv&amp;gt; with the names listed by vgs and lvs.&lt;br /&gt;
&lt;br /&gt;
This worked, and the filesystem on /dev/&amp;lt;vg&amp;gt;/&amp;lt;lv&amp;gt; could be mounted correctly.&lt;br /&gt;
&lt;br /&gt;
== Tuning ==&lt;br /&gt;
&lt;br /&gt;
While trying to compare a 12-disk RAID (8TB disks) to a hwraid, mdraid was slower, so we did a few things to speed things up:&lt;br /&gt;
&lt;br /&gt;
While testing with [https://linux.die.net/man/1/fio fio], monitor /sys/block/md0/md/stripe_cache_active, and see if it&#039;s close to /sys/block/md0/md/stripe_cache_size. If it is, double the size of the latter&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
echo 4096 &amp;gt; /sys/block/md0/md/stripe_cache_size&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Continue until stripe_cache_active stabilises, and then you&#039;ve found the limit you&#039;ll need. You may want to double that for good measure. &lt;br /&gt;
&lt;br /&gt;
(to be continued)&lt;br /&gt;
&lt;br /&gt;
== Links ==&lt;br /&gt;
&lt;br /&gt;
Below are a few links with useful info&lt;br /&gt;
&lt;br /&gt;
* [https://raid.wiki.kernel.org/index.php/Irreversible_mdadm_failure_recovery Irreversible mdadm failure recovery]&lt;br /&gt;
&lt;br /&gt;
= ZFS =&lt;br /&gt;
&lt;br /&gt;
ZFS can do a lot of things most filesystems or volume managers can&#039;t. It checksums all data and metadata and so long that the system uses ECC enabled memory (RAM), it will have complete control over the whole data set, and when (not if) an error occurs, it&#039;ll fix the issue without even throwing a warning. To fix the issue, you&#039;ll obviously need sufficient redundancy (mirrors or RAIDzN). &lt;br /&gt;
&lt;br /&gt;
== ZFS send/receive between machines ==&lt;br /&gt;
&lt;br /&gt;
ZFS has a send/receive mechanism that allows for snapshots to be sent over the wire to a receiving end. This can be a full filesystem, or an incremental change since last send/reveive. In a WAN scenario, you&#039;ll probably want to use VPN for this. On a controlled network, sending in cleartext is also possible. You may as well use ssh, but keep in mind that ssh was never designed to be used as a fullblown vpn solution and is just too slow or the task with large amounts of data. You may, though, use mbuffer, if on a loal LAN.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Allow traffic from the sending IP in whatever firewall interface you&#039;re using (if you&#039;re using a firewall at all, that is)&lt;br /&gt;
ufw allow from x.x.x.x&lt;br /&gt;
# &lt;br /&gt;
# Start the receiver first. This listens on port 9090, has a 1GB buffer,&lt;br /&gt;
    and uses 128kb chunks (same as zfs):&lt;br /&gt;
&lt;br /&gt;
mbuffer -s 128k -m 1G -I 9090 | zfs receive data/filesystem&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To be continued one day… See [https://everycity.co.uk/alasdair/2010/07/using-mbuffer-to-speed-up-slow-zfs-send-zfs-receive/ this] for some more. I&#039;ll get back with details on it.&lt;br /&gt;
&lt;br /&gt;
= General Linux system control =&lt;br /&gt;
&lt;br /&gt;
== Add a new CPU (core) ==&lt;br /&gt;
&lt;br /&gt;
If working with virtual machines, adding a new core can be useful if the VM is slow and the load is multithreaded or multiprocess. To do this, add a new CPU in the hypervisor (be it KVM or VMware or Hyper-V or whatever). Some hypervisors, like VMware, will activate it automatically if open-vm-tools is installed. Please note that open-vm-tools is for VMware only. I don&#039;t know of any such thing for KVM or other hypervisors (although I beleive VirtualBox has its own set of tools, but not as a package). If this doesn&#039;t work, run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
echo 1 &amp;gt; /sys/devices/system/cpu/cpuX/online&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where X is the CPU number you want to add. You can &#039;cat /sys/devices/system/cpu/cpuX/online&#039; to check if it&#039;s online.&lt;br /&gt;
&lt;br /&gt;
= Mount partitions on a disk image =&lt;br /&gt;
&lt;br /&gt;
Sometimes you&#039;ll have a disk image, either from recovering a bad drive after hours (or days or weeks) of ddrescue, and sometimes you just have a disk image from a virtual machine where you want to mount the partitions inside the image. There are three main methods of doing this, which are more or less synonmous, but some easier than the other.&lt;br /&gt;
&lt;br /&gt;
== Basics ==&lt;br /&gt;
&lt;br /&gt;
A disk image is usually like a disk, consisting of either a large filesystem, a PV or a partition table with one or partitions onto which resides a filesystem, a pv, swap or something else. If it&#039;s partitioned, and you want your operating system to mount a filesystem or allow it to see whatever LVM stuff lies on it, you need to isolate the partitions. &lt;br /&gt;
&lt;br /&gt;
== Manual mapping ==&lt;br /&gt;
&lt;br /&gt;
In the oldern days, this was done manually, something like this&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
root@mymachine:~# fdisk -l /dev/vda&lt;br /&gt;
Disk /dev/vda: 25 GiB, 26843545600 bytes, 52428800 sectors&lt;br /&gt;
Units: sectors of 1 * 512 = 512 bytes&lt;br /&gt;
Sector size (logical/physical): 512 bytes / 512 bytes&lt;br /&gt;
I/O size (minimum/optimal): 512 bytes / 512 bytes&lt;br /&gt;
Disklabel type: dos&lt;br /&gt;
Disk identifier: 0xc37b7ea5&lt;br /&gt;
&lt;br /&gt;
Device     Boot    Start      End  Sectors  Size Id Type&lt;br /&gt;
/dev/vda1  *        2048 50333311 50331264   24G 83 Linux&lt;br /&gt;
/dev/vda2       50333312 52426369  2093058 1022M  5 Extended&lt;br /&gt;
/dev/vda5       50333314 52426369  2093056 1022M 82 Linux swap / Solaris&lt;br /&gt;
root@mymachine:~#&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To calculate the start and end of each partition, you just take the start sector and multiply it by the sector size (512 bytes here) and you have the offset in bytes. After this, it&#039;s merely an losetup -o &amp;lt;offset&amp;gt; /dev/loopX &amp;lt;nameofimagefile&amp;gt; and you have the partition mapped to your /dev/loopX (having X being something typically 0-255. After this, just mount it or run pvscan/vgscan/lvscan to probe whatever lvm config is there, and you should be able to mount it like any other filesystem.&lt;br /&gt;
&lt;br /&gt;
== kpartx ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;kpartx&#039;&#039;&#039; does the same as above, more or less, just without so much hassle. Most of it should be automatic and easy to deal with, except it may fail to disconnect the loopback devices sometimes, so you may have to &#039;&#039;&#039;losetup -d&#039;&#039;&#039; them manually. See the manual, &#039;&#039;&#039;kpartx (8)&#039;&#039;&#039;. Please note that &#039;&#039;&#039;partx&#039;&#039;&#039; works similarly and I&#039;d guess the authors of the two tools are arguing a lot of which one&#039;s the best.&lt;br /&gt;
&lt;br /&gt;
== guestmount ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;guestmount&#039;&#039;&#039; is something similar again, but also supports file formats like &#039;&#039;&#039;qcow2&#039;&#039;&#039; and possibly other, proprietary filesystems like &#039;&#039;&#039;vmdk&#039;&#039;&#039; and &#039;&#039;&#039;vdi&#039;&#039;&#039;, but don&#039;t take my word for it - I haven&#039;t tested. Again, see the manual or just read up on the description [http://ask.xmodulo.com/mount-qcow2-disk-image-linux.html?fbclid=IwAR3snTeZvGzp9PLdX11EQhCfOpux6I93CiJ3A2pUomkkRLly9Xo4851mkTY here]. It seems rather trivial.&lt;br /&gt;
&lt;br /&gt;
= Linux on laptops =&lt;br /&gt;
&lt;br /&gt;
== Wifi with HP EliteBook 725/745 on Ubuntu ==&lt;br /&gt;
&lt;br /&gt;
The HP EliteBook 725/745 and similar are equipped with a BCM4352 wifi chip. As with a lot of other stuff from Broadcom, this lacks an open hardware description, so thus no open driver exist. The proper fix, is to replace the NIC with something with an open driver, but again, this isn&#039;t always possible, so a binary driver exists. In ubuntu, run, somehow connect the machine to the internet and run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install bcmwl-kernel-source&lt;br /&gt;
sudo modprobe wl&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you can&#039;t connect the machine to the internet, download the needed packages on another machine and put it on some usb storage. These packages should suffice:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# apt-cache depends bcmwl-kernel-source&lt;br /&gt;
bcmwl-kernel-source&lt;br /&gt;
  Depends: dkms&lt;br /&gt;
  Depends: linux-libc-dev&lt;br /&gt;
  Depends: libc6-dev&lt;br /&gt;
  Conflicts: &amp;lt;bcmwl-modaliases&amp;gt;&lt;br /&gt;
  Replaces: &amp;lt;bcmwl-modaliases&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then install manually with &#039;&#039;&#039;dpkg -i file1.deb file2.deb&#039;&#039;&#039; etc&lt;br /&gt;
&lt;br /&gt;
After this, ip/ifconfig/iwconfig shouldd see the new wifi nic, probably &#039;&#039;&#039;wlan0&#039;&#039;&#039;, but due to a [https://bugs.launchpad.net/ubuntu/+source/broadcom-sta/+bug/1343151 old, ignored bug], you won&#039;t find any wifi networks. This is because the driver from Broadcom apparently does not support interrupt remapping, commonly used on x64 machines. To turn this off, change &#039;&#039;&#039;/etc/default/grub&#039;&#039;&#039; and change the line &#039;&#039;&#039;GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;quiet splash&amp;quot;&#039;&#039;&#039;, adding intremap=off to the end before the quote: &#039;&#039;&#039;GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;quiet splash intremap=off&amp;quot;&#039;&#039;&#039;. Save the file and run &#039;&#039;&#039;sudo update-grub&#039;&#039;&#039; and reboot. After this, wifi should work well.&lt;br /&gt;
&lt;br /&gt;
== Wifi with HP Compaq Presario CQ57 on Ubuntu ==&lt;br /&gt;
&lt;br /&gt;
The HP Compaq Presario CQ57 uses the RT5390 wifi chipset. This has been supported for quite some time now, and I was quite surprised to find it not working on a laptop a friend was having. The driver loaded correctly, but Ubuntu insisted of the laptop being in &#039;&#039;&#039;flight mode&#039;&#039;&#039;. Checking &#039;&#039;&#039;rfkill&#039;&#039;&#039;, it showed me two NICs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# rfkill list all&lt;br /&gt;
0: phy0: Wireless LAN&lt;br /&gt;
	Soft blocked: no&lt;br /&gt;
	Hard blocked: yes&lt;br /&gt;
1: hp-wifi: Wireless LAN&lt;br /&gt;
	Soft blocked: yes&lt;br /&gt;
	Hard blocked: no&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Turning rfkill on and off resulted in nothing much, except some error messages in the kernel log (dmesg)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] ACPI Error: Field [B128] at bit offset/length 128/1024 exceeds size of target Buffer (160 bits) (20170831/dsopcode-235)&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]&lt;br /&gt;
                            Initialized Local Variables for Method [HWCD]:&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Local0: 00000000a34b7928 &amp;lt;Obj&amp;gt;           Integer 0000000000000000&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Local1: 00000000b0aa6865 &amp;lt;Obj&amp;gt;           Buffer(8) 46 41 49 4C 04 00 00 00&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Local5: 00000000a9811efd &amp;lt;Obj&amp;gt;           Integer 0000000000000004&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] Initialized Arguments for Method [HWCD]:  (2 arguments defined for method invocation)&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Arg0:   0000000078957d1b &amp;lt;Obj&amp;gt;           Integer 0000000000000001&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Arg1:   00000000725c9c6e &amp;lt;Obj&amp;gt;           Buffer(20) 53 45 43 55 02 00 00 00&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] ACPI Error: Method parse/execution failed \_SB.WMID.HWCD, AE_AML_BUFFER_LIMIT (20170831/psparse-550)&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] ACPI Error: Method parse/execution failed \_SB.WMID.WMAD, AE_AML_BUFFER_LIMIT (20170831/psparse-550)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After upgrading BIOS and testing different kernels, I was asked to try to unload the &#039;&#039;&#039;hp_wmi&#039;&#039;&#039; driver. I did, and things changed a bit, so I tried blacklisting it, creating the file &#039;&#039;&#039;/etc/modprobe.d/blacklist-hp_wmi.conf&#039;&#039;&#039; with the following content&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Blacklist this - it doesn&#039;t work!&lt;br /&gt;
blacklist hp_wmi&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
I gave the machine a reboot and afte that, the &#039;&#039;&#039;hp-wifi&#039;&#039;&#039; entry was gone in the rfkill output, and things works.&lt;br /&gt;
&lt;br /&gt;
= Raspberry pi =&lt;br /&gt;
&lt;br /&gt;
I couldn&#039;t quite decide if the raspberry pi should be a separate section or part of Linux, but hell, it can run more than Linux, although 99,lots% of people just uses Linux on them. This is a small list of things to know about them; things not on the front page of the manual or perhaps hidden even better.&lt;br /&gt;
&lt;br /&gt;
== Which pi? ==&lt;br /&gt;
&lt;br /&gt;
I just setup three raspberry pi machines and although some are quite different, like v1 to vEverythingelse or the Pi zero versions to the normal ones, not all of us remember how to distinguish between them, and sometimes they&#039;re in a nice 3d printed (or otherwise) chassis or otherwise hidden. So, how to check three different ones:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
root@home-assistant:~ $ cat /proc/device-tree/model ; echo&lt;br /&gt;
Raspberry Pi 2 Model B Rev 1.1&lt;br /&gt;
&lt;br /&gt;
root@green-pi:~ $ cat /proc/device-tree/model ; echo&lt;br /&gt;
Raspberry Pi 3 Model B Rev 1.2&lt;br /&gt;
&lt;br /&gt;
roy@yellow-pi:~ $cat /proc/device-tree/model ; echo&lt;br /&gt;
Raspberry Pi 4 Model B Rev 1.1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
While this works well, for the latter, the pi4, it doesn&#039;t tell how much memory I have. It comes in variants of 1, 2 and 4GB, and this is the latter.&lt;br /&gt;
&lt;br /&gt;
== Monitoring ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;vcgencmd&#039;&#039;&#039; from &#039;&#039;&#039;/opt/vc/bin&#039;&#039;&#039;, but symlinked to &#039;&#039;&#039;/usr/bin&#039;&#039;&#039; so it&#039;s available in path, is useful for fetching hardware info about the pi. For example, measuring the temperature&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
root@yellow-pi:~# vcgencmd measure_temp&lt;br /&gt;
temp=63.0&#039;C&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The command is generally badly documented and parts of it seems outdated for newer hardware. Here&#039;s the output from a Raspberry pi 4 with 4GB RAM&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
roy@yellow-pi:~ $ vcgencmd get_mem arm&lt;br /&gt;
arm=948M&lt;br /&gt;
roy@yellow-pi:~ $ vcgencmd get_mem gpu&lt;br /&gt;
gpu=76M&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= BIOS upgrade from Linux =&lt;br /&gt;
&lt;br /&gt;
Generally, BIOS upgrades have been moved to the BIOS itself these days. This saves a lot of work and quite possibly lives after those who earier rammed their heads through walls, now can upgrade directly from the internet instead of using obscure operating systems best avoided. Sometimes, however, one must use these nevertheless. This is a quick run-through on your options.&lt;br /&gt;
&lt;br /&gt;
== DOS ==&lt;br /&gt;
&lt;br /&gt;
Most non-automatic BIOS upgrades are installed from DOS. Doing a BIOS upgrade this way, is generally non-problematic. Just install a USB thingie with [https://www.freedos.org/ FreeDOS], copy your file(s) onto the thing and boot on it. The commandline is the same as old MS/DOS, except a wee bit more userfriendly, but not a lot.&lt;br /&gt;
&lt;br /&gt;
== Windows ==&lt;br /&gt;
&lt;br /&gt;
Some macahines, like laptops from &#039;&#039;&#039;HP&#039;&#039;&#039;, may have BIOS upgrades that are made to be installed from Windows and won&#039;t run in FreeDOS or MS/DOS, instead throwing an error, saying &#039;&#039;&#039;This program cannot be run in DOS mode&#039;&#039;&#039;. This means you&#039;ll have to boot on a Windows rescue disc and do the job from there. Googling this, tells you it&#039;s quite easy, you just choose &#039;make rescue disc&#039; from Windows, and it&#039;s all good, except if you don&#039;t run Windows, that is. To remedy this problem, do as follows:&lt;br /&gt;
&lt;br /&gt;
=== Download Windows ===&lt;br /&gt;
&lt;br /&gt;
Since you don&#039;t run Windows and possibly don&#039;t have a spouse or friend around with such unhealthy habits either, you need to get it. It&#039;s quite easy - just google &#039;download windows&#039; and it&#039;ll send you to [https://www.microsoft.com/en-us/software-download/windows10ISO somewhere like this].&lt;br /&gt;
&lt;br /&gt;
=== Burn it! ===&lt;br /&gt;
&lt;br /&gt;
Now it&#039;s time to burn the installer on a DVD ROM. You&#039;ll need a double-layered one, since the OS is &amp;gt; 4.7GiB, but I&#039;m sure you have a ton of those lying around. Now, just place your optical medium in your optical drive and burn, baby, burn!&lt;br /&gt;
&lt;br /&gt;
=== Or make a USB thing? ===&lt;br /&gt;
&lt;br /&gt;
Not a lot of machines have optical drives these days, so you may want to use an USB pen drive or something instead. This is easy, just make the USB bootable with the Windows application Microsoft has made for this. Unfortunately, this only runs on Windows, and unlike stuff like Debian, where the &#039;&#039;&#039;iso&#039;&#039;&#039; file can be dd&#039;ed directly onto a USB drive to make it bootable, the Windows &#039;&#039;&#039;iso&#039;&#039;&#039;s don&#039;t come with this luxury. There are lots of methods to make bootable USB things from iso files out there, but the only thing most of them have in common, is that they generally don&#039;t work.&lt;br /&gt;
&lt;br /&gt;
==== WoeUSB ====&lt;br /&gt;
&lt;br /&gt;
After hours of swearing, it&#039;s nice to come across software like [https://github.com/slacka/WoeUSB WoeUSB]. It may not be perfect, it relies on a bunch of GUI stuff you&#039;ll never need and so on, but it &#039;&#039;&#039;&#039;&#039;works&#039;&#039;&#039;&#039;&#039;, and that&#039;s the important part! Just clone the repo and RTFM and it&#039;s all nice. It&#039;s slow, but hell, getting a windows machine and/or an optical drive might be slower.&lt;br /&gt;
&lt;br /&gt;
WoeUSB does nothing fancy, but it &#039;&#039;&#039;does&#039;&#039;&#039; work. It will create a filesystem, FAT32 or NTFS (better use NTFS, FAT32 has its limits). It creates normal filesystems and so on. Just make sure to copy in the BIOS update file, usually an exe file, to run when Windows is up and running.&lt;br /&gt;
&lt;br /&gt;
==== Install BIOS ====&lt;br /&gt;
&lt;br /&gt;
Boot on the Windows USB thing and choose &#039;repair computer&#039; and then &#039;command prompt&#039;. Find the install file, and if you&#039;re lucky, you&#039;ll find it needs a 32bit OS, just like I did. Since the 64bit version doesn&#039;t include 32bit compatibility in the installer, revert to downloading the 32bit version of windows and start over. Pray to your favourite god(s) not to get across such machines again - it might help.&lt;br /&gt;
&lt;br /&gt;
= 3D printer stuff =&lt;br /&gt;
&lt;br /&gt;
== Hydrophilic filament ==&lt;br /&gt;
&lt;br /&gt;
Most popular filament types, including PLA, PETG, PP or PA (Polyamide, normally known as Nylon) and virtualy any filament type named [https://www.matterhackers.com/news/filament-and-water poly-something] (and thus with an acronym of P-something) are hydrophilic (also (somewhat incorrectly) called hydroscopic), meaning so long they&#039;re dryer than the atmosphere around them, they&#039;ll do their best to suck out the atmosphere&#039;s humidity. This is why most filament are shrink-wrapped with a small bag of silica gel in it. If such filament is exposed for normal humid air for some time, it&#039;ll become very hard to use. Most of my experience is with PLA, which can handle a bit (depending on make), but still not a lot. With PLA, if you end up with prints where the filament seems not to stick, it may help with a higher temperature. Otherwise, the filament must be [https://all3dp.com/2/how-to-dry-filament-pla-abs-and-nylon/ baked]. If you don&#039;t want to use your oven, try something like a [https://www.jula.no/catalog/hjem-og-husholdning/kjokkenmaskiner/mattilberedningsapparater/frukt-sopptorker/frukt-sopptorker-001641/#tab02 fruit and mushroom dryer]. Then get a good, sealble plastic box and add something like half a kilogram of [https://www.ebay.com/sch/sis.html?_nkw=1KG+Orange+Replacement+Desiccant+Indicating+Silica+Gel+Beads+for+Drawers%2C+Camera&amp;amp;_id=131938742628&amp;amp;&amp;amp;_trksid=p2057872.m2749.l2658 silica gel] to an old sock, tie it and put it in the your new dry box.&lt;br /&gt;
&lt;br /&gt;
Please note that ABS is hydrophobic, so you won&#039;t have to worry too much there. Also, remember that PA/Nylon is extremely hydrophilic. Even a couple of days in normal air humidity can ruin it completely and will require baking.&lt;br /&gt;
&lt;br /&gt;
== Upgrading the firmware on an Ender 3 ==&lt;br /&gt;
&lt;br /&gt;
This is about upgrading the firmware, and thus also flashing a bootloader to the Creality Ender 3 3D printer. Most of this is well documented on several place, like o [https://www.youtube.com/watch?v=fIl5X2ffdyo the video from Teaching tech] and elsewhere, but I&#039;ll just summarise some issues I had.&lt;br /&gt;
&lt;br /&gt;
=== Using an arduino Nano as a programmer ===&lt;br /&gt;
&lt;br /&gt;
Quick note before you read on. If you have an Ender 3 controller version 1.1.5 or newer (or perhaps even a bit older), a CR-10S or some other more or less modern printers or controllers, they come with a bootloader installed already, so don&#039;t bother flashing one. The one that&#039;s in there already, should work well. So if you have one of these, just skip this and jump to the [[Roy&#039;s_notes#Flashing_the_printer|next section]].&lt;br /&gt;
&lt;br /&gt;
However, the normal CR-10 (without the S), Ender 3 and a few other printers from Creality come without a bootloader, so you&#039;ll need to flash one before upgrading the firmware. Well, strictly speakning, you don&#039;t need one, you can save those 8kB or so for other stuff and use a programmer to write the whole firmware, but then you&#039;ll need to wire up everything every time you want a new firmware, so in my world, you &#039;&#039;&#039;do&#039;&#039;&#039; need the bootloader, since it&#039;s easier.&lt;br /&gt;
&lt;br /&gt;
To install a bootloader, you&#039;ll need a programmer, and I didn&#039;t have one available. Having some el-cheapo china-copies of Arduinos around, I read I could use one and tried so. Although the docs mostly mention the Uno etc, it&#039;s just as simple with the Nano copy.&lt;br /&gt;
&lt;br /&gt;
So, grab an arduino, plug it to your machine with a USB cable, and, using the Arduino IDE, use the ArduinoISP sketch there (found under Examples) to burn the software needed for the arduino to work as a programmer. When this is done, connect a 10µF capacitor between RST and GND to stop it from resetting when used as a programmer. Connect the MOSI, MISO and SCK pins from the ICSP block (that little isolated 6-pin block on top of the ardu). See [https://www.arduino.cc/en/Tutorial/ArduinoISP here] for a pinout. Then find Vcc and GND either on the ICSP block or elsewhere. Some sites say that on some boards you shouldn&#039;t use the pins on the ICSP block for this. I doubt it matters, though. Then connect another jumper wire from pin 10 on the ardu to work as the reset pin outwards to the chip being programmed (that is, on the printer). The ICSP jumper block pin layout is the same on the printer and on the ardu, and probably elsewhere. Sometimes [https://xkcd.com/927/ standardisation] actually works…&lt;br /&gt;
&lt;br /&gt;
See https://cloud.karlsbakk.net/index.php/s/zw48YJjzaf8Rc2F for a pic with the ardu (this wiki is broken atm, will fix it later)&lt;br /&gt;
&lt;br /&gt;
== Flashing the printer ==&lt;br /&gt;
&lt;br /&gt;
When the boot loader is in place, possibly after some wierd errors from during the process, the screen on the 3d printer will go blank and it&#039;ll behave like being bricked. This is ok. Now disconnect the wires and connect the USB cable between computer and printer. If you haven&#039;t installed support for the Sanguino board, that is, the variant of the 1284-chip and surrounding electronics that is the core of the, you need to install it first. In the Arduino IDE, choose the Tools / Boards / Boards manager boot option and search for Sanguino. After this, you should find the Sanguino or Sanguino 1284p in the boards menu. After this, you should be able to communicate with the printer&#039;s controller. Download the [https://www.th3dstudio.com/knowledgebase/th3d-unified-firmware-package/ TH3D unified firmware], making sure it&#039;s the last version. Uncompress the zip and with Finder/Explorer/whateversomething&#039;scalledonlinux, browse to &#039;&#039;&#039;TH3DUF_R2/Firmware/TH3DUF_R2.ino&#039;&#039;&#039; and open it. It should open directly in the Android IDE. Keep in mind that the names TH3DUF_R2 and TH3DUF_R2.ino will vary between versions, but you get the point. Now configure it for your particular needs. You&#039;ll find most of this in the Configuration.h tab (that&#039;s really a file). Most of the other files won&#039;t be necessary unless you&#039;re doing some more advanced stuff, like replacing th controller with something non-standard or similar, but then again, that&#039;s another chapter (or book, even). The video mentioned above describes this well. After flashing the new firmware, you&#039;ll probably get some timeouts and errors, since apparently it resets the printer after giving it the new firmware, but without notifying the flashing software of it doing so. If this happens, calm down and reboot the printer and check its tiny monitor - it should work. If it doesn&#039;t work, and if you flashed the bootload yourself, try to flash it again, and if that doesn&#039;t work, try flashing the programmer again yet another time, just for kicks. Again, if you have a newer controller like the v1.1.5, don&#039;t touch the bootloader, as the one already installed, should work well as it is.&lt;br /&gt;
&lt;br /&gt;
PS: I tried enabling &#039;&#039;&#039;MANUAL_MESH_LEVELING&#039;&#039;&#039;, which in the code says that &#039;&#039;If used with a 1284P board the bootscreen will be disabled to save space&#039;&#039;. This effectively disabled the whole printer, and apparently may be making the firmware image a wee bit too large for it to fit the 1284P on the ender. It works well without it, though, and it may be fixed by now, since I tested this back in early 2019.&lt;br /&gt;
&lt;br /&gt;
== And then… ==&lt;br /&gt;
&lt;br /&gt;
With the new firmware in place, the printer should work as before, although with thermal runaway protection to better avoid fires in case the shit hits the fan, and to allow for things like autolevelling. With any luck, [https://www.precisionpiezo.co.uk/ this thing] may be ready for use by the time you read this - it surely looks nice!&lt;br /&gt;
&lt;br /&gt;
roy&lt;/div&gt;</summary>
		<author><name>Roy</name></author>
	</entry>
	<entry>
		<id>https://wiki.malinux.no/index.php?title=Roy%27s_notes&amp;diff=163</id>
		<title>Roy&#039;s notes</title>
		<link rel="alternate" type="text/html" href="https://wiki.malinux.no/index.php?title=Roy%27s_notes&amp;diff=163"/>
		<updated>2020-06-22T12:23:04Z</updated>

		<summary type="html">&lt;p&gt;Roy: /* Using an arduino Nano as a programmer */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= LVM, md and friends =&lt;br /&gt;
&lt;br /&gt;
== Linux&#039; Logical Volume Manager (LVM) ==&lt;br /&gt;
&lt;br /&gt;
=== LVM in general ===&lt;br /&gt;
&lt;br /&gt;
LVM is designed to be an abstraction layer on top of physical drives or RAID, typically [https://raid.wiki.kernel.org/index.php/RAID_setup mdraid] or [https://help.ubuntu.com/community/FakeRaidHowto fakeraid]. Keep in mind that fakeraid should be avoided unless you really need it, like in conjunction with dual-booting linux and windows on fakeraid. LVM broadly consists of three elements, the &amp;quot;physical&amp;quot; devices (PV), the volume group (VG) and the logical volume (LV). There can be multiple PVs, VGs and LVs, depending on requirement. More about this below. All commands are given as examples, and all of them can be fine-tuned using extra flags in need of so. In my experience, the defaults work well for most usecases.&lt;br /&gt;
&lt;br /&gt;
I&#039;m mentioning filesystem below too. Where I write ext4, the samme applies to ext2 and ext3.&lt;br /&gt;
&lt;br /&gt;
==== Create a PV ====&lt;br /&gt;
&lt;br /&gt;
A PV is the &amp;quot;physical&amp;quot; parts. This does not need to be a physical disk, but can also be another RAID, be it an mdraid, fakeraid, hardware raid, a virtual disk on a SAN or otherwisee or a partition on one of those. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#  These add three PVs, one on a drive (or hardware raid) and another two on mdraids.&lt;br /&gt;
pvcreate /dev/sdb&lt;br /&gt;
pvcreate /dev/md1 /dev/md2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For more information about pvcreate, see [https://linux.die.net/man/8/pvcreate the manual].&lt;br /&gt;
&lt;br /&gt;
==== Create a VG ====&lt;br /&gt;
&lt;br /&gt;
The volume group consists of one or more PVs grouped together on which LVs can be placed. If several PVs are grouped in a VG, it&#039;s generally a good idea to make sure these PVs have some sort of redundancy, as in mdraid/fakeraid or hwraid. Otherwise it will be like using a [https://en.wikipedia.org/wiki/RAID RAID-0] with a single point of failure on each of the independant drives. LVM has [https://unix.stackexchange.com/questions/150644/raiding-with-lvm-vs-mdraid-pros-and-cons  RAID code in it] as well, so you can use that. I haven&#039;t done so myself, as I generally stick to mraid. The reason is mdraid is, in my opinion older and more stable and has more users (meaning bugs are reported and fixed faster whenever they are found). That said, I beleive the actual RAID code used in LVM RAID are the same function calls as for mdraid, so it may not be much of a difference. I still stick with mdraid. To create a VG, run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create volume group my_vg&lt;br /&gt;
vgcreate my_vg /dev/md1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that if vgcreate is run with a PV (as /dev/md1 above) that is not defined as a PV (like above), this is done implicitly, so if you don&#039;t need any special flags to pvcreate, you can simply skip it and let vgcreate do that for you.&lt;br /&gt;
&lt;br /&gt;
==== Create an LV ====&lt;br /&gt;
&lt;br /&gt;
LVs can be compared to partitions, somehow, since they are bounderies of a fraction or all of that of a VG. The difference between them and a partition, however, is that they can be grown or shrunk easily and also moved around between PVs without downtime. This flexibility makes them superiour to partitions as your system can be changed without users noticing it. By default, an LV is alloated &amp;quot;thickly&amp;quot;, meaning all the data given to it, is allocated from the VG and thus the PV. The following makes a 100GB LV named &amp;quot;thicklv&amp;quot;. When making an LV, I usually allocate what&#039;s needed plus some more, but not everything, just to make sure it&#039;s space available for growth on any of the LVs on the VG, or new LVs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a thick provisioned LV named thicklv on the VG my_vg&lt;br /&gt;
lvcreate -n thicklv -L 100G my_vg&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After the LV is created, a filesystem can be placed on it unless it is meant to be used directly. The application for direct use include swap space, VM storage and certain database systems. Most of these will, however, work on filesystems too, although my testing has shown that on swap space, there is a significant performance gain for using dedicated storage without a filesystem. As for filesystems, most Linux users use either ext4 or xfs. Personally, I generally use XFS these days. See my notes below on filesystem choice.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a filesystem on the LV - this could have been mkfs -t ext4 or whatever filesystem you choose&lt;br /&gt;
mkfs -t xfs /dev/my_vg/thicklv&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then just edit /etc/fstab with correct data and run mount -a, and you should be all set.&lt;br /&gt;
&lt;br /&gt;
==== Create LVM cache ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
lvcreate -L 1G -n _cache_meta data /dev/md1&lt;br /&gt;
&lt;br /&gt;
lvcreate -l100%FREE -n _cache data /dev/md1&lt;br /&gt;
&lt;br /&gt;
# Some would want --cachemode writeback, but seriously, I wouldn&#039;t recommend it. Metadata or data can be easily corrupted in case of failure.&lt;br /&gt;
lvconvert --type cache-pool --cachemode writethrough --poolmetadata data/_cache_meta data/_cache&lt;br /&gt;
&lt;br /&gt;
lvconvert --type cache --cachepool data/_cache data/data&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Disabling LVM cache ====&lt;br /&gt;
&lt;br /&gt;
If you for some reason want to disable caching, this will do it cleanly and remove the LVs earlier created for caching the main device.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
lvconvert --uncache data/data&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Growing devices ====&lt;br /&gt;
&lt;br /&gt;
LVM objects can be grown and shrunk. If a PV resides on a RAID where a new drive has been added or otherwise grown, or on a partition or virtual disk that has been extended, the PV must be updated to reflect these changes. The following command will grow the PV to the maximum available on the underlying storage. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Resize the PV /dev/md (not the RAID, only the PV on the RAID) to its full size&lt;br /&gt;
pvresize /dev/md1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If a new PV is added, the VG can be grown to add the space on that in addition to what&#039;s there already. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Extend my_vg to include md2 and its space&lt;br /&gt;
vgextend my_vg /dev/md2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
With more space available in the VG, the LV can now be extended. Let&#039;s add another 50GB to it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Extend thicklv - add 50GB. If you know you won&#039;t need the space anywhere else, you may want to&lt;br /&gt;
# lvresize -l+100%FREE instead. Keep in mind the difference between -l (extents) and -L (bytes)&lt;br /&gt;
lvresize -L +50G my_vg/thicklv&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Growing filesystems ====&lt;br /&gt;
After the LV has grown, run &#039;&#039;xfs_growfs&#039;&#039; (xfs) or &#039;&#039;resize2fs&#039;&#039; (ext4) to make use of the new data. To grow the filesystem to all available space on ext4, run the below command.  To partly grow the filesystem or to shrink it or otherwise, please see the manuals.&lt;br /&gt;
&lt;br /&gt;
The filesystem can be mounted when this is run. If you for some reason get an &#039;&#039;&#039;access denied&#039;&#039;&#039; error when running this as root or with sudo, it&#039;s likely caused by a filesystem error. To fix this, unmount the filesystem first and run &#039;&#039;&#039;fsck -f /dev/my_vg/thicklv&#039;&#039;&#039; and remount it before retrying to extend it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
resize2fs /dev/my_vg/thicklv&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Similarly, with XFS, but note that xfs_growfs doesn&#039;t take the device name, but the filesystem&#039;s mount point. In the case of XFS, also note that the filesystem &#039;&#039;&#039;&#039;&#039;must&#039;&#039;&#039;&#039;&#039; be mounted to be grown. This, in contrast to how it was in the old days when filesystems had to be unmounted to be grown.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
xfs_growfs /my_mountpoint&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Rename system VG ====&lt;br /&gt;
&lt;br /&gt;
Some distros create VG names like those-from-a-sysadmin-with-a-well-developed-paranoia-not-to-hit-a-duplicate. Debian, for instance, uses names like &amp;quot;my-full-hostname-vg&amp;quot;. Personally, I don&#039;t like these, since if I were to move a disk or vdisk around to somewhere else, I&#039;d make sure not to add a disk named &#039;sys&#039; to an existing system. If you do, most distros will refuse to use the VGs with duplicate names, resulting in the OS not booting until either one is specified by its UUID or just one removed. As I&#039;m aware of this, I stick to the super-risky thing of all system VGs named &#039;sys&#039; and so on.&lt;br /&gt;
&lt;br /&gt;
If you do this, keep in mind that it may blow up your computer and take your girl- or boyfriend with it or even make either of them pregnant, allowing Trump to rule your life and generally make things suck. You&#039;re on your own!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Rename the VG&lt;br /&gt;
vgrename my-full-hostname-vg sys&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, in /boot/grub/grub.cfg, change the old lv path from something like &#039;/dev/mapper/debian--stretch--machine--vg-root&#039; to your new and fancy &#039;/dev/sys/root. Likewise, in /etc/fstab, change occurences of &#039;/dev/mapper/debian--stretch--machine--vg-&#039; (or similar) with &#039;/dev/sys/&#039;. Here, this was like this - the old ones commented out.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;fstab&amp;quot;&amp;gt;&lt;br /&gt;
#/dev/mapper/debian--stretch--box--vg-root      /               ext4            errors=remount-ro,discard       0       1&lt;br /&gt;
/dev/sys/root                                   /               ext4            errors=remount-ro,discard       0       1&lt;br /&gt;
# /boot was on /dev/vda1 during installation&lt;br /&gt;
UUID=myverylonguuidwithatonofgoodinfoinit       /boot           ext2            defaults                        0       2&lt;br /&gt;
#/dev/mapper/debian--stretch--box--vg-swap_1    none            swap            sw                              0       0&lt;br /&gt;
/dev/sys/swap_1                                 none            swap            sw                              0       0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Update /etc/initramfs-tools/conf.d/resume with similar data for swap.&lt;br /&gt;
&lt;br /&gt;
You might want to run &#039;update-initramfs -u -k all&#039; after this, but I&#039;m not sure if it&#039;s needed.&lt;br /&gt;
&lt;br /&gt;
Now, pray to the nearest god(s) and give it a reboot and it should (probably) work.&lt;br /&gt;
&lt;br /&gt;
After reboot, run &#039;&#039;&#039;swapoff -a&#039;&#039;&#039;, then &#039;&#039;&#039;mkswap /dev/sys/swap_1&#039;&#039;&#039; (or whatever it&#039;s called on your system) and &#039;&#039;&#039;swapon -a&#039;&#039;&#039; again. You may want to give it another reboot or two for kicks, but it should work well even without that.&lt;br /&gt;
&lt;br /&gt;
=== Migration tools ===&lt;br /&gt;
&lt;br /&gt;
At times, storage regimes change, new storage is added and sometimes it&#039;s not easy to migrate with the current hardware or its support systems. Once I had to migrate a 45TiB fileserver from one storage system to another, preferably without downtime. The server originally had three 15TiB PVs of which two were full and the third half full. I resorted to using [https://linux.die.net/man/8/pvmove pvmove] to just move the data on the PVs in use to a new PV. We started out with creating a new 50TiB PV, sde, and then to pvmove.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Attach /dev/sde to the VG my_vg&lt;br /&gt;
vgextend my_vg /dev/sde&lt;br /&gt;
&lt;br /&gt;
# Move the contents from /dev/sdb over to /dev/sde block by block. If a target is not given in pvmove,&lt;br /&gt;
# the contents of the source (sdb here) will be put somewhere else in the pool.&lt;br /&gt;
pvmove /dev/sdb /dev/sde&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This took a while (as in a week or so) - the pvmove command uses old code and logic (or at least did that when I migrated this in November 2016), but it affected performance on the server very little, so users didn&#039;t notice. After the first PV was migrated, I continued with the other two, one after the other, and after a month or so, it was migrated. We used this on a number of large fileservers, and it worked flawlessly. Before doing the production servers I also tried interrupting pvmove in various ways, including hard resets, and it just kept on after the reboot.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;NOTE:&#039;&#039;&#039;&#039;&#039; &#039;&#039;Even though it worked well for us, &#039;&#039;&#039;always&#039;&#039;&#039; keep a good backup before doing this. Things may go wrong, and without a good backup, you may be looking for a hard-to-find new job the next morning&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
==== mdadm workarounds ====&lt;br /&gt;
&lt;br /&gt;
===== Migrate from a mirror (raid-1) to raid-10 =====&lt;br /&gt;
&lt;br /&gt;
Create a mirror&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sdb /dev/sdc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
LVM (pv/vg/lv) on md0 (see above), put a filesystem on the lv and fill it with some data.&lt;br /&gt;
&lt;br /&gt;
Now, some months later, you want to change this to raid-10 to allow for the same amount of redundancy, but to allow more disks into the system.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mdadm --grow /dev/md0 --level=10&lt;br /&gt;
mdadm: Impossibly level change request for RAID1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So - no - doesn&#039;t work. But - we&#039;re on &lt;br /&gt;
&lt;br /&gt;
Since we&#039;re on lvm already, this&#039;ll be easy. If you&#039;re using filesystems directly on partitions, you can do this the same way, but without the pvmove part, using rsync or whateever you like instead. I&#039;d recommend using lvm for for the new raid, which should be rather obvious from this article. Now plug in a new drive and create a new raid10 on that one. If you two new drives, install both. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# change &amp;quot;missing&amp;quot; to the other device name if you installed two new drives&lt;br /&gt;
mdadm --create /dev/md1 --level=10 --raid-devices=2 /dev/vdd missing&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, as described above, just vgextend the vg, adding the new raid and run pvmove to move the data from the old pv (residing on the old raid1) to the new pv (on raid10). Afte rpvmove is finished (which may take awile, see above), just&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
vgreduce raidtest /dev/md0&lt;br /&gt;
pvremove /dev/md0&lt;br /&gt;
mdadm --stop /dev/md0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
…and your disk is free to be added to the new array. If the new raid is running in degraded mode (if you created it with just one drive), better don&#039;t wait too long, since you don&#039;t have redundancy. Just mdadm --add the devs.&lt;br /&gt;
&lt;br /&gt;
If you now have /dev/mdstat telling you your raid10 is active and have three drives, of which one is a spare, it should look something like this&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5] [raid4] [raid10]&lt;br /&gt;
md1 : active raid10 vdc[3](S) vdb[2] vdd[0]&lt;br /&gt;
      8380416 blocks super 1.2 2 near-copies [2/2] [UU]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Just mdadm --grow --raid-devices=3 /dev/md1&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;RAID section is not complete. I&#039;ll write more on migraing from raid10 to raid6 later. It&#039;s not straight forward, but easier than this one :)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== Thin provisioned LVs ===&lt;br /&gt;
&lt;br /&gt;
Thin provisioning on LVM is a method used for not allocating all the space given to an LV. For instance, if you have a 1TB VG and want to give an LV 500GB, although it currently only uses a fraction of that, a thin lv can be a good alternative. This will allow for adding a limit to how much it can use, but also to let it grow dynamically without manual work by the sysadmin. Thin provisioning adds another layer of abstaction by creating a special LV as a &#039;&#039;thin pool&#039;&#039; from which data is allocated to the &#039;&#039;thin volume(s)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== Create a thin pool ====&lt;br /&gt;
&lt;br /&gt;
Allocate 1TB to the thin pool to be used for thinly provisioned LVs. Keep in mind that the space allocated to the thin pool is in fact thick provisioned. Only the volumes put on &#039;&#039;thinpool&#039;&#039; are thin provisioned. This will create two hidden LVs, one for data and one for metadata. Normally the defaults will do, but check the manual if the data doesn&#039;t match the usual patterns (such as billions of files, resulting in huge amounts of metadata). I &#039;&#039;beleive&#039;&#039; the metadata part should be resizable at a later time if needed, but I have not tested it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a pool for thin LVs. Keep in mind that the pool itself is not thin provisioned, only the volumes residing on it&lt;br /&gt;
lvcreate --size 1T --type thin-pool --thinpool thinpool my_vg&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Create a thin volume ====&lt;br /&gt;
&lt;br /&gt;
You have the thinpool, now put a thin volume on it. It will allocate some space for metadata, but probably not much (a few megs, perhaps).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Now, create a volume with a virtual (-V) size of half a terabyte named thin_pool, but using the thinpool (-T) named thin_pool for storage&lt;br /&gt;
lvcreate -V 500G -T my_vg/thin_pool --name thinvol&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The new volume&#039;s device name will be /dev/thinvol. Now, create a filesystem on it, add to fstab and mount it. The &#039;&#039;&#039;df&#039;&#039;&#039; command will return available space according to the virtual size (-V), while lvs will show how much data is actually used on each of the thinly provisioned volumes.&lt;br /&gt;
&lt;br /&gt;
== Filesystem dilemmas ==&lt;br /&gt;
&lt;br /&gt;
=== XFS or ext4 or something else ===&lt;br /&gt;
The choice of filesystem varies for your use. Distros such as RHEL/CentOS has moved to XFS by default from v7. Debian/Ubuntu still sticks to ext4, like most other. I&#039;ll discuss my thoughts below on ext4 vs XFS and leave the other filesystems for later.&lt;br /&gt;
&lt;br /&gt;
==== ext4 ====&lt;br /&gt;
ext4 is probably the most used filesystem on linux as of writing. It&#039;s rock stable and has been extended by a lot of extensions since the original ext2. It still retains backward compatibility, being able to mount and fsck ext2 and ext3 with the ext4 driver. However, it doesn&#039;t handle large filesystems very well. If a filesystem is created for &amp;lt;16TiB, it cannot be grown to anything larger than 16TiB. This may have changed lately, though. One other issue is handling errors. If a large filesystem (say 10TiB) is damaged, an fsck may take several hours, leading to long downtime. When I refer to ext4 further in this text, the same applies to ext2 and ext3 unless otherwise specified.&lt;br /&gt;
&lt;br /&gt;
==== XFS ====&lt;br /&gt;
XFS, originally developed by SGI some time in the bronze age, but has been worked on heavily after that. RHEL and Centos version 7 and forward, uses XFS as the default filesystem. It is quick, it scales well, but it lacks at least two things ext4 has. It cannot be shrunk (not that you normally need that, but nice if you have a typo or you need to change things). Also, it doesn&#039;t allow for automatic fsck on bootup. If something is messed up on the filesystem, you&#039;ll have to login as root on the console (not ssh), which might be an issue on some systems. The fsck equivalent, xfs_repair, is a *lot* faster than ext4&#039;s fsck, though.&lt;br /&gt;
&lt;br /&gt;
==== ZFS ====&lt;br /&gt;
ZFS is like a combination of RAID, LVM and a filesystem, supporting full checksumming, auto-healing (given sufficient redundancy), compression, encryption, replication, deduplication (if you&#039;re brave and have a &#039;&#039;ton&#039;&#039; of memory) and a lot more. It&#039;s a separate chapter and needs a lot more talk than paragraph here.&lt;br /&gt;
&lt;br /&gt;
==== btrfs ====&lt;br /&gt;
btrfs, pronounced &amp;quot;butterfs&amp;quot; or &amp;quot;betterfs&amp;quot; or just spelled out, is a filesystem that mimics that of ZFS. It has been around for 10 years or so, but hasn&#039;t yet proven to be really stable. Following the progress of it for those years, I&#039;ve found it to be a nice toy with which to play, but not to be used in production. Again, others may say otherwise, but these are just my words.&lt;br /&gt;
&lt;br /&gt;
== Low level disk handling ==&lt;br /&gt;
&lt;br /&gt;
This section is for low-level handling of disks, regardless of storage system elsewhere. These apply to mdraid, lvmraid and zfs and possibly other solutions, with the exception of individual drives on hwraid (and maybe fakeraid), since there, the drives are hidden from Linux (or whatever OS).&lt;br /&gt;
&lt;br /&gt;
=== S.M.A.R.T. and slow drives ===&lt;br /&gt;
Modern (that is, from about 1990 or later) have S.M.A.R.T. (or just smart, since it&#039;s easier to type) monitoring built in, meaning the disk&#039;s controller is monitoring itself. This is handy and will ideally tell you in advance that a drive is flakey or dying. Modern (2010+) smart monitoring is more or less the same. It can be trusted about 50% of the time. Usually, if smart detects an error, it&#039;s a real error. I don&#039;t think I&#039;ve seen it reporting a false positive, but others may know better. &lt;br /&gt;
&lt;br /&gt;
==== smartmontools ====&lt;br /&gt;
First, install smartmontool and run smartclt -H /dev/yourdisk (/dev/sda or something) to get a health report. Then perhaps run smartctl -a /dev/yourdisk and look for &#039;current pending sectors&#039; This should be zero. Also check the temperature, which normally should be much above 50.&lt;br /&gt;
&lt;br /&gt;
==== single, slow drive ====&lt;br /&gt;
What may happen, is smart not seeing anything and life goes on like before, only slower and less prouductive, without telling anyone. If you stubler over this issue, you&#039;ll probably see it during a large rsync/zfs send/receive or a resync/rebuild/resilver of the raid/zpool. During this, it feels like everything is slow and your RAID has turned into a RAIF (redundant array of inexpensive floppies). To check if you have a single drive messing up it all, check with &#039;&#039;&#039;iostat -x 2&#039;&#039;&#039;, having 2 being the delay between each measurement. Interrupt it with ctrl+x. If there&#039;s a rougue drive there, it should stand out like sdg below&lt;br /&gt;
&lt;br /&gt;
 avg-cpu:  %user   %nice %system %iowait  %steal   %idle&lt;br /&gt;
            0.38    0.00    1.75    0.00    0.00   97.87&lt;br /&gt;
&lt;br /&gt;
 Device            r/s     w/s     rkB/s     wkB/s   rrqm/s   wrqm/s  %rrqm  %wrqm r_await w_await aqu-sz rareq-sz wareq-sz  svctm  %util&lt;br /&gt;
 sda              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdb              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdc              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdd              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sde              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdf              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdg              3.50    0.00   2352.00      0.00     0.00     0.00   0.00   0.00 14306.29    0.00  13.85   672.00     0.00 285.71 100.00&lt;br /&gt;
 sdh              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
&lt;br /&gt;
In ZFS land, you should be able to get similar data with &#039;&#039;&#039;zpool iostat -v &amp;lt;pool&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Now you know the bad drive (sdg), pull it from the raid with &#039;&#039;&#039;mdadm --fail /dev/mdX /dev/sdX&#039;&#039;&#039;. Now test the drive&#039;s performance manually, just simply:&lt;br /&gt;
&lt;br /&gt;
 # hdparm -t /dev/sdg&lt;br /&gt;
 &lt;br /&gt;
 /dev/sdg:&lt;br /&gt;
  Timing buffered disk reads:   2 MB in  5.37 seconds = 381.46 kB/sec&lt;br /&gt;
&lt;br /&gt;
Bingo - nothing you&#039;d want to keep. For a good drive, it should be something like 100-200MB/s&lt;br /&gt;
&lt;br /&gt;
PS: Keep in mind that you have a degraded RAID by now in case you had a spare waiting for things to happen.&lt;br /&gt;
&lt;br /&gt;
Try to replace the cable and/or try the disk on another port/controller. If the result from hdparm persists, it&#039;s probably a bad cable&lt;br /&gt;
&lt;br /&gt;
So, then, just psycially locate the drive, pull it out, take out the discs and magnets and recycle the rest.&lt;br /&gt;
&lt;br /&gt;
=== &amp;quot;Unplug&amp;quot; drive from system ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Find the device unit&#039;s number with something like&lt;br /&gt;
find /sys/bus/scsi/devices/*/block/ -name sdd&lt;br /&gt;
# returning /sys/bus/scsi/devices/3:0:0:0/block/sdd here, &lt;br /&gt;
# meaning 3:0:0:0 is the SCSI device we&#039;re looking for.&lt;br /&gt;
&lt;br /&gt;
# Given this is the correct device, and you want to &#039;unplug&#039; it, do so by&lt;br /&gt;
echo 1 &amp;gt; /sys/bus/scsi/devices/3:0:0:0/delete&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Rescan disk controllers ===&lt;br /&gt;
If a drive is added and for some reason doesn&#039;t get detected, or is removed by the command above, it can be rediscovered with a sysfs command to the scsi host to which it is connected. Since there may be quite a few of these, an easy way is to just scan them all and check the output of &#039;&#039;&#039;dmesg -T&#039;&#039;&#039; after running it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Make a list of controllers and send a rescan message to each of them. It won&#039;t do anything &lt;br /&gt;
# for those where nothing has changed, but it will show new drives where they have been added.&lt;br /&gt;
for host_scan in /sys/class/scsi_host/host*/scan&lt;br /&gt;
do&lt;br /&gt;
  echo &#039;- - -&#039; &amp;gt; $host_scan&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Fail injection with debugfs ===&lt;br /&gt;
[https://lxadm.com/Using_fault_injection https://lxadm.com/Using_fault_injection]&lt;br /&gt;
&lt;br /&gt;
== mdadm stuff ==&lt;br /&gt;
=== Resync ===&lt;br /&gt;
To resync a raid, that is, check, run&lt;br /&gt;
&lt;br /&gt;
 echo check &amp;gt; /sys/block/$dev/md/sync_action&lt;br /&gt;
&lt;br /&gt;
where $dev is something like md0. If you have several raids, something like this should work&lt;br /&gt;
&lt;br /&gt;
 for dev in md{0,1}&lt;br /&gt;
 do&lt;br /&gt;
   echo repair &amp;gt; /sys/block/$dev/md/sync_action&lt;br /&gt;
 done&lt;br /&gt;
&lt;br /&gt;
Also useful in a one-liner like&lt;br /&gt;
&lt;br /&gt;
 for dev in md{0,1} ; do echo repair &amp;gt; /sys/block/$dev/md/sync_action ; done&lt;br /&gt;
&lt;br /&gt;
Different raids on different drives will do this in parallel. If the drives are shared somehow with partitions or similar, the check or repair will wait for the other to finish before going on.&lt;br /&gt;
&lt;br /&gt;
As for repair vs check, [https://raid.wiki.kernel.org/index.php/RAID_Administration this article] describes it well. I stick to using repair unless it&#039;s something rare where I don&#039;t want to touch the data.&lt;br /&gt;
&lt;br /&gt;
=== Spare pools ===&lt;br /&gt;
In the old itmes, mdadm supported only a dedicated spare per md device, so if working with a large set of drives (20? 40?), where you&#039;d want to setup more raid sets to increase redundancy, you&#039;d dedicate a spare to each of the raid sets. This has changed (some time ago?), so in these modern, heathen days, you can change mdadm.conf, usually placed under /etc/mdadm, and add &#039;spare-group=somegroup&#039; where &#039;somegroup&#039; is a string identifying the spare group. After doing this, run &#039;&#039;&#039;update-initramfs -u&#039;&#039;&#039; and reboot and add a spare to one of the raid sets in the spare group, and md will use that or those spares for all the raidsets in that group.&lt;br /&gt;
&lt;br /&gt;
As some pointed out on #linux-raid @ irc.freenode.net, this feature is very badly documented, but as far as I can see, it works well.&lt;br /&gt;
&lt;br /&gt;
==== Example config ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create two raidsets&lt;br /&gt;
&lt;br /&gt;
mdadm --create /dev/md1 --level=6 --raid-devices=6 /dev/vd[efghij]&lt;br /&gt;
mdadm --create /dev/md2 --level=6 --raid-devices=6 /dev/vd[klmnop]&lt;br /&gt;
&lt;br /&gt;
# get their UUID etc&lt;br /&gt;
&lt;br /&gt;
mdadm --detail --scan&lt;br /&gt;
ARRAY /dev/md/1 metadata=1.2 name=raidtest:1 UUID=1a8cbdcb:f4092350:348b6b80:c054d74c&lt;br /&gt;
ARRAY /dev/md/2 metadata=1.2 name=raidtest:2 UUID=894b1b7c:cb7eba70:917d6033:ea5afd2b&lt;br /&gt;
&lt;br /&gt;
# Put those lines into /etc/mdadm/mdadm.conf and and add the spare-group&lt;br /&gt;
&lt;br /&gt;
ARRAY /dev/md/1 metadata=1.2 name=raidtest:1 spare-group=raidtest UUID=1a8cbdcb:f4092350:348b6b80:c054d74c&lt;br /&gt;
ARRAY /dev/md/2 metadata=1.2 name=raidtest:2 spare-group=raidtest UUID=894b1b7c:cb7eba70:917d6033:ea5afd2b&lt;br /&gt;
&lt;br /&gt;
# update the initramfs and reboot&lt;br /&gt;
&lt;br /&gt;
update-initramfs -u&lt;br /&gt;
reboot&lt;br /&gt;
&lt;br /&gt;
# add a spare drive to one of the raids&lt;br /&gt;
&lt;br /&gt;
mdadm --add /dev/md1 /dev/vdq&lt;br /&gt;
&lt;br /&gt;
# fail a drive on the other raid&lt;br /&gt;
&lt;br /&gt;
mdadm --fail /dev/md2 /dev/vdn&lt;br /&gt;
&lt;br /&gt;
# check /proc/mdstat to see md2 rebuilding with the spare from md1&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Recovery ===&lt;br /&gt;
&lt;br /&gt;
The other day, I came across a problem a user had on #linux-raid@irc.freenode.net. He had an old Qnap NAS that had died and tried plugging the drives in to his Linux machine and got various errors. The two-drive RAID-1 did not come up as it should, &#039;&#039;&#039;dmesg&#039;&#039;&#039; was full of errors from one of the drives (both connected on USB) and so forth.&lt;br /&gt;
&lt;br /&gt;
We went on and started by taking down the machine and just connecting one of the drives. I had him check what was assembled with&lt;br /&gt;
&lt;br /&gt;
 cat /proc/mdstat&lt;br /&gt;
&lt;br /&gt;
That returned /proc/md127 assembled, but LVM didn&#039;t find anything. So running a manual scan&lt;br /&gt;
&lt;br /&gt;
 pvscan --cache /dev/md127&lt;br /&gt;
&lt;br /&gt;
This made linux find the PV, VG and a couple of LVs, but probably because the mdraid was degraded, the LVs were deactivated, according to &#039;&#039;&#039;lvscan&#039;&#039;&#039;. Activating the one with a filesystem manually&lt;br /&gt;
&lt;br /&gt;
 lvchange -a y /dev/&amp;lt;vg&amp;gt;/&amp;lt;lv&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Substitute &amp;lt;vg&amp;gt; and &amp;lt;lv&amp;gt; with the names listed by vgs and lvs.&lt;br /&gt;
&lt;br /&gt;
This worked, and the filesystem on /dev/&amp;lt;vg&amp;gt;/&amp;lt;lv&amp;gt; could be mounted correctly.&lt;br /&gt;
&lt;br /&gt;
== Tuning ==&lt;br /&gt;
&lt;br /&gt;
While trying to compare a 12-disk RAID (8TB disks) to a hwraid, mdraid was slower, so we did a few things to speed things up:&lt;br /&gt;
&lt;br /&gt;
While testing with [https://linux.die.net/man/1/fio fio], monitor /sys/block/md0/md/stripe_cache_active, and see if it&#039;s close to /sys/block/md0/md/stripe_cache_size. If it is, double the size of the latter&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
echo 4096 &amp;gt; /sys/block/md0/md/stripe_cache_size&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Continue until stripe_cache_active stabilises, and then you&#039;ve found the limit you&#039;ll need. You may want to double that for good measure. &lt;br /&gt;
&lt;br /&gt;
(to be continued)&lt;br /&gt;
&lt;br /&gt;
== Links ==&lt;br /&gt;
&lt;br /&gt;
Below are a few links with useful info&lt;br /&gt;
&lt;br /&gt;
* [https://raid.wiki.kernel.org/index.php/Irreversible_mdadm_failure_recovery Irreversible mdadm failure recovery]&lt;br /&gt;
&lt;br /&gt;
= ZFS =&lt;br /&gt;
&lt;br /&gt;
ZFS can do a lot of things most filesystems or volume managers can&#039;t. It checksums all data and metadata and so long that the system uses ECC enabled memory (RAM), it will have complete control over the whole data set, and when (not if) an error occurs, it&#039;ll fix the issue without even throwing a warning. To fix the issue, you&#039;ll obviously need sufficient redundancy (mirrors or RAIDzN). &lt;br /&gt;
&lt;br /&gt;
== ZFS send/receive between machines ==&lt;br /&gt;
&lt;br /&gt;
ZFS has a send/receive mechanism that allows for snapshots to be sent over the wire to a receiving end. This can be a full filesystem, or an incremental change since last send/reveive. In a WAN scenario, you&#039;ll probably want to use VPN for this. On a controlled network, sending in cleartext is also possible. You may as well use ssh, but keep in mind that ssh was never designed to be used as a fullblown vpn solution and is just too slow or the task with large amounts of data. You may, though, use mbuffer, if on a loal LAN.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Allow traffic from the sending IP in whatever firewall interface you&#039;re using (if you&#039;re using a firewall at all, that is)&lt;br /&gt;
ufw allow from x.x.x.x&lt;br /&gt;
# &lt;br /&gt;
# Start the receiver first. This listens on port 9090, has a 1GB buffer,&lt;br /&gt;
    and uses 128kb chunks (same as zfs):&lt;br /&gt;
&lt;br /&gt;
mbuffer -s 128k -m 1G -I 9090 | zfs receive data/filesystem&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To be continued one day… See [https://everycity.co.uk/alasdair/2010/07/using-mbuffer-to-speed-up-slow-zfs-send-zfs-receive/ this] for some more. I&#039;ll get back with details on it.&lt;br /&gt;
&lt;br /&gt;
= General Linux system control =&lt;br /&gt;
&lt;br /&gt;
== Add a new CPU (core) ==&lt;br /&gt;
&lt;br /&gt;
If working with virtual machines, adding a new core can be useful if the VM is slow and the load is multithreaded or multiprocess. To do this, add a new CPU in the hypervisor (be it KVM or VMware or Hyper-V or whatever). Some hypervisors, like VMware, will activate it automatically if open-vm-tools is installed. Please note that open-vm-tools is for VMware only. I don&#039;t know of any such thing for KVM or other hypervisors (although I beleive VirtualBox has its own set of tools, but not as a package). If this doesn&#039;t work, run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
echo 1 &amp;gt; /sys/devices/system/cpu/cpuX/online&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where X is the CPU number you want to add. You can &#039;cat /sys/devices/system/cpu/cpuX/online&#039; to check if it&#039;s online.&lt;br /&gt;
&lt;br /&gt;
= Mount partitions on a disk image =&lt;br /&gt;
&lt;br /&gt;
Sometimes you&#039;ll have a disk image, either from recovering a bad drive after hours (or days or weeks) of ddrescue, and sometimes you just have a disk image from a virtual machine where you want to mount the partitions inside the image. There are three main methods of doing this, which are more or less synonmous, but some easier than the other.&lt;br /&gt;
&lt;br /&gt;
== Basics ==&lt;br /&gt;
&lt;br /&gt;
A disk image is usually like a disk, consisting of either a large filesystem, a PV or a partition table with one or partitions onto which resides a filesystem, a pv, swap or something else. If it&#039;s partitioned, and you want your operating system to mount a filesystem or allow it to see whatever LVM stuff lies on it, you need to isolate the partitions. &lt;br /&gt;
&lt;br /&gt;
== Manual mapping ==&lt;br /&gt;
&lt;br /&gt;
In the oldern days, this was done manually, something like this&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
root@mymachine:~# fdisk -l /dev/vda&lt;br /&gt;
Disk /dev/vda: 25 GiB, 26843545600 bytes, 52428800 sectors&lt;br /&gt;
Units: sectors of 1 * 512 = 512 bytes&lt;br /&gt;
Sector size (logical/physical): 512 bytes / 512 bytes&lt;br /&gt;
I/O size (minimum/optimal): 512 bytes / 512 bytes&lt;br /&gt;
Disklabel type: dos&lt;br /&gt;
Disk identifier: 0xc37b7ea5&lt;br /&gt;
&lt;br /&gt;
Device     Boot    Start      End  Sectors  Size Id Type&lt;br /&gt;
/dev/vda1  *        2048 50333311 50331264   24G 83 Linux&lt;br /&gt;
/dev/vda2       50333312 52426369  2093058 1022M  5 Extended&lt;br /&gt;
/dev/vda5       50333314 52426369  2093056 1022M 82 Linux swap / Solaris&lt;br /&gt;
root@mymachine:~#&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To calculate the start and end of each partition, you just take the start sector and multiply it by the sector size (512 bytes here) and you have the offset in bytes. After this, it&#039;s merely an losetup -o &amp;lt;offset&amp;gt; /dev/loopX &amp;lt;nameofimagefile&amp;gt; and you have the partition mapped to your /dev/loopX (having X being something typically 0-255. After this, just mount it or run pvscan/vgscan/lvscan to probe whatever lvm config is there, and you should be able to mount it like any other filesystem.&lt;br /&gt;
&lt;br /&gt;
== kpartx ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;kpartx&#039;&#039;&#039; does the same as above, more or less, just without so much hassle. Most of it should be automatic and easy to deal with, except it may fail to disconnect the loopback devices sometimes, so you may have to &#039;&#039;&#039;losetup -d&#039;&#039;&#039; them manually. See the manual, &#039;&#039;&#039;kpartx (8)&#039;&#039;&#039;. Please note that &#039;&#039;&#039;partx&#039;&#039;&#039; works similarly and I&#039;d guess the authors of the two tools are arguing a lot of which one&#039;s the best.&lt;br /&gt;
&lt;br /&gt;
== guestmount ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;guestmount&#039;&#039;&#039; is something similar again, but also supports file formats like &#039;&#039;&#039;qcow2&#039;&#039;&#039; and possibly other, proprietary filesystems like &#039;&#039;&#039;vmdk&#039;&#039;&#039; and &#039;&#039;&#039;vdi&#039;&#039;&#039;, but don&#039;t take my word for it - I haven&#039;t tested. Again, see the manual or just read up on the description [http://ask.xmodulo.com/mount-qcow2-disk-image-linux.html?fbclid=IwAR3snTeZvGzp9PLdX11EQhCfOpux6I93CiJ3A2pUomkkRLly9Xo4851mkTY here]. It seems rather trivial.&lt;br /&gt;
&lt;br /&gt;
= Linux on laptops =&lt;br /&gt;
&lt;br /&gt;
== Wifi with HP EliteBook 725/745 on Ubuntu ==&lt;br /&gt;
&lt;br /&gt;
The HP EliteBook 725/745 and similar are equipped with a BCM4352 wifi chip. As with a lot of other stuff from Broadcom, this lacks an open hardware description, so thus no open driver exist. The proper fix, is to replace the NIC with something with an open driver, but again, this isn&#039;t always possible, so a binary driver exists. In ubuntu, run, somehow connect the machine to the internet and run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install bcmwl-kernel-source&lt;br /&gt;
sudo modprobe wl&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you can&#039;t connect the machine to the internet, download the needed packages on another machine and put it on some usb storage. These packages should suffice:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# apt-cache depends bcmwl-kernel-source&lt;br /&gt;
bcmwl-kernel-source&lt;br /&gt;
  Depends: dkms&lt;br /&gt;
  Depends: linux-libc-dev&lt;br /&gt;
  Depends: libc6-dev&lt;br /&gt;
  Conflicts: &amp;lt;bcmwl-modaliases&amp;gt;&lt;br /&gt;
  Replaces: &amp;lt;bcmwl-modaliases&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then install manually with &#039;&#039;&#039;dpkg -i file1.deb file2.deb&#039;&#039;&#039; etc&lt;br /&gt;
&lt;br /&gt;
After this, ip/ifconfig/iwconfig shouldd see the new wifi nic, probably &#039;&#039;&#039;wlan0&#039;&#039;&#039;, but due to a [https://bugs.launchpad.net/ubuntu/+source/broadcom-sta/+bug/1343151 old, ignored bug], you won&#039;t find any wifi networks. This is because the driver from Broadcom apparently does not support interrupt remapping, commonly used on x64 machines. To turn this off, change &#039;&#039;&#039;/etc/default/grub&#039;&#039;&#039; and change the line &#039;&#039;&#039;GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;quiet splash&amp;quot;&#039;&#039;&#039;, adding intremap=off to the end before the quote: &#039;&#039;&#039;GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;quiet splash intremap=off&amp;quot;&#039;&#039;&#039;. Save the file and run &#039;&#039;&#039;sudo update-grub&#039;&#039;&#039; and reboot. After this, wifi should work well.&lt;br /&gt;
&lt;br /&gt;
== Wifi with HP Compaq Presario CQ57 on Ubuntu ==&lt;br /&gt;
&lt;br /&gt;
The HP Compaq Presario CQ57 uses the RT5390 wifi chipset. This has been supported for quite some time now, and I was quite surprised to find it not working on a laptop a friend was having. The driver loaded correctly, but Ubuntu insisted of the laptop being in &#039;&#039;&#039;flight mode&#039;&#039;&#039;. Checking &#039;&#039;&#039;rfkill&#039;&#039;&#039;, it showed me two NICs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# rfkill list all&lt;br /&gt;
0: phy0: Wireless LAN&lt;br /&gt;
	Soft blocked: no&lt;br /&gt;
	Hard blocked: yes&lt;br /&gt;
1: hp-wifi: Wireless LAN&lt;br /&gt;
	Soft blocked: yes&lt;br /&gt;
	Hard blocked: no&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Turning rfkill on and off resulted in nothing much, except some error messages in the kernel log (dmesg)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] ACPI Error: Field [B128] at bit offset/length 128/1024 exceeds size of target Buffer (160 bits) (20170831/dsopcode-235)&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]&lt;br /&gt;
                            Initialized Local Variables for Method [HWCD]:&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Local0: 00000000a34b7928 &amp;lt;Obj&amp;gt;           Integer 0000000000000000&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Local1: 00000000b0aa6865 &amp;lt;Obj&amp;gt;           Buffer(8) 46 41 49 4C 04 00 00 00&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Local5: 00000000a9811efd &amp;lt;Obj&amp;gt;           Integer 0000000000000004&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] Initialized Arguments for Method [HWCD]:  (2 arguments defined for method invocation)&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Arg0:   0000000078957d1b &amp;lt;Obj&amp;gt;           Integer 0000000000000001&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Arg1:   00000000725c9c6e &amp;lt;Obj&amp;gt;           Buffer(20) 53 45 43 55 02 00 00 00&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] ACPI Error: Method parse/execution failed \_SB.WMID.HWCD, AE_AML_BUFFER_LIMIT (20170831/psparse-550)&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] ACPI Error: Method parse/execution failed \_SB.WMID.WMAD, AE_AML_BUFFER_LIMIT (20170831/psparse-550)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After upgrading BIOS and testing different kernels, I was asked to try to unload the &#039;&#039;&#039;hp_wmi&#039;&#039;&#039; driver. I did, and things changed a bit, so I tried blacklisting it, creating the file &#039;&#039;&#039;/etc/modprobe.d/blacklist-hp_wmi.conf&#039;&#039;&#039; with the following content&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Blacklist this - it doesn&#039;t work!&lt;br /&gt;
blacklist hp_wmi&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
I gave the machine a reboot and afte that, the &#039;&#039;&#039;hp-wifi&#039;&#039;&#039; entry was gone in the rfkill output, and things works.&lt;br /&gt;
&lt;br /&gt;
= Raspberry pi =&lt;br /&gt;
&lt;br /&gt;
I couldn&#039;t quite decide if the raspberry pi should be a separate section or part of Linux, but hell, it can run more than Linux, although 99,lots% of people just uses Linux on them. This is a small list of things to know about them; things not on the front page of the manual or perhaps hidden even better.&lt;br /&gt;
&lt;br /&gt;
== Which pi? ==&lt;br /&gt;
&lt;br /&gt;
I just setup three raspberry pi machines and although some are quite different, like v1 to vEverythingelse or the Pi zero versions to the normal ones, not all of us remember how to distinguish between them, and sometimes they&#039;re in a nice 3d printed (or otherwise) chassis or otherwise hidden. So, how to check three different ones:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
root@home-assistant:~ $ cat /proc/device-tree/model ; echo&lt;br /&gt;
Raspberry Pi 2 Model B Rev 1.1&lt;br /&gt;
&lt;br /&gt;
root@green-pi:~ $ cat /proc/device-tree/model ; echo&lt;br /&gt;
Raspberry Pi 3 Model B Rev 1.2&lt;br /&gt;
&lt;br /&gt;
roy@yellow-pi:~ $cat /proc/device-tree/model ; echo&lt;br /&gt;
Raspberry Pi 4 Model B Rev 1.1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
While this works well, for the latter, the pi4, it doesn&#039;t tell how much memory I have. It comes in variants of 1, 2 and 4GB, and this is the latter.&lt;br /&gt;
&lt;br /&gt;
== Monitoring ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;vcgencmd&#039;&#039;&#039; from &#039;&#039;&#039;/opt/vc/bin&#039;&#039;&#039;, but symlinked to &#039;&#039;&#039;/usr/bin&#039;&#039;&#039; so it&#039;s available in path, is useful for fetching hardware info about the pi. For example, measuring the temperature&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
root@yellow-pi:~# vcgencmd measure_temp&lt;br /&gt;
temp=63.0&#039;C&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The command is generally badly documented and parts of it seems outdated for newer hardware. Here&#039;s the output from a Raspberry pi 4 with 4GB RAM&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
roy@yellow-pi:~ $ vcgencmd get_mem arm&lt;br /&gt;
arm=948M&lt;br /&gt;
roy@yellow-pi:~ $ vcgencmd get_mem gpu&lt;br /&gt;
gpu=76M&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== BIOS upgrade from Linux ==&lt;br /&gt;
&lt;br /&gt;
Generally, BIOS upgrades have been moved to the BIOS itself these days. This saves a lot of work and quite possibly lives after those who earier rammed their heads through walls, now can upgrade directly from the internet instead of using obscure operating systems best avoided. Sometimes, however, one must use these nevertheless. This is a quick run-through on your options.&lt;br /&gt;
&lt;br /&gt;
=== DOS ===&lt;br /&gt;
&lt;br /&gt;
Most non-automatic BIOS upgrades are installed from DOS. Doing a BIOS upgrade this way, is generally non-problematic. Just install a USB thingie with [https://www.freedos.org/ FreeDOS], copy your file(s) onto the thing and boot on it. The commandline is the same as old MS/DOS, except a wee bit more userfriendly, but not a lot.&lt;br /&gt;
&lt;br /&gt;
=== Windows ===&lt;br /&gt;
&lt;br /&gt;
Some macahines, like laptops from &#039;&#039;&#039;HP&#039;&#039;&#039;, may have BIOS upgrades that are made to be installed from Windows and won&#039;t run in FreeDOS or MS/DOS, instead throwing an error, saying &#039;&#039;&#039;This program cannot be run in DOS mode&#039;&#039;&#039;. This means you&#039;ll have to boot on a Windows rescue disc and do the job from there. Googling this, tells you it&#039;s quite easy, you just choose &#039;make rescue disc&#039; from Windows, and it&#039;s all good, except if you don&#039;t run Windows, that is. To remedy this problem, do as follows:&lt;br /&gt;
&lt;br /&gt;
==== Download Windows ====&lt;br /&gt;
&lt;br /&gt;
Since you don&#039;t run Windows and possibly don&#039;t have a spouse or friend around with such unhealthy habits either, you need to get it. It&#039;s quite easy - just google &#039;download windows&#039; and it&#039;ll send you to [https://www.microsoft.com/en-us/software-download/windows10ISO somewhere like this].&lt;br /&gt;
&lt;br /&gt;
==== Burn it! ====&lt;br /&gt;
&lt;br /&gt;
Now it&#039;s time to burn the installer on a DVD ROM. You&#039;ll need a double-layered one, since the OS is &amp;gt; 4.7GiB, but I&#039;m sure you have a ton of those lying around. Now, just place your optical medium in your optical drive and burn, baby, burn!&lt;br /&gt;
&lt;br /&gt;
==== Or make a USB thing? ====&lt;br /&gt;
&lt;br /&gt;
Not a lot of machines have optical drives these days, so you may want to use an USB pen drive or something instead. This is easy, just make the USB bootable with the Windows application Microsoft has made for this. Unfortunately, this only runs on Windows, and unlike stuff like Debian, where the &#039;&#039;&#039;iso&#039;&#039;&#039; file can be dd&#039;ed directly onto a USB drive to make it bootable, the Windows &#039;&#039;&#039;iso&#039;&#039;&#039;s don&#039;t come with this luxury. There are lots of methods to make bootable USB things from iso files out there, but the only thing most of them have in common, is that they generally don&#039;t work.&lt;br /&gt;
&lt;br /&gt;
===== WoeUSB =====&lt;br /&gt;
&lt;br /&gt;
After hours of swearing, it&#039;s nice to come across software like [https://github.com/slacka/WoeUSB WoeUSB]. It may not be perfect, it relies on a bunch of GUI stuff you&#039;ll never need and so on, but it &#039;&#039;&#039;&#039;&#039;works&#039;&#039;&#039;&#039;&#039;, and that&#039;s the important part! Just clone the repo and RTFM and it&#039;s all nice. It&#039;s slow, but hell, getting a windows machine and/or an optical drive might be slower.&lt;br /&gt;
&lt;br /&gt;
WoeUSB does nothing fancy, but it &#039;&#039;&#039;does&#039;&#039;&#039; work. It will create a filesystem, FAT32 or NTFS (better use NTFS, FAT32 has its limits). It creates normal filesystems and so on. Just make sure to copy in the BIOS update file, usually an exe file, to run when Windows is up and running.&lt;br /&gt;
&lt;br /&gt;
===== Install BIOS =====&lt;br /&gt;
&lt;br /&gt;
Boot on the Windows USB thing and choose &#039;repair computer&#039; and then &#039;command prompt&#039;. Find the install file, and if you&#039;re lucky, you&#039;ll find it needs a 32bit OS, just like I did. Since the 64bit version doesn&#039;t include 32bit compatibility in the installer, revert to downloading the 32bit version of windows and start over. Pray to your favourite god(s) not to get across such machines again - it might help.&lt;br /&gt;
&lt;br /&gt;
= 3D printer stuff =&lt;br /&gt;
&lt;br /&gt;
== Hydrophilic filament ==&lt;br /&gt;
&lt;br /&gt;
Most popular filament types, including PLA, PETG, PP or PA (Polyamide, normally known as Nylon) and virtualy any filament type named [https://www.matterhackers.com/news/filament-and-water poly-something] (and thus with an acronym of P-something) are hydrophilic (also (somewhat incorrectly) called hydroscopic), meaning so long they&#039;re dryer than the atmosphere around them, they&#039;ll do their best to suck out the atmosphere&#039;s humidity. This is why most filament are shrink-wrapped with a small bag of silica gel in it. If such filament is exposed for normal humid air for some time, it&#039;ll become very hard to use. Most of my experience is with PLA, which can handle a bit (depending on make), but still not a lot. With PLA, if you end up with prints where the filament seems not to stick, it may help with a higher temperature. Otherwise, the filament must be [https://all3dp.com/2/how-to-dry-filament-pla-abs-and-nylon/ baked]. If you don&#039;t want to use your oven, try something like a [https://www.jula.no/catalog/hjem-og-husholdning/kjokkenmaskiner/mattilberedningsapparater/frukt-sopptorker/frukt-sopptorker-001641/#tab02 fruit and mushroom dryer]. Then get a good, sealble plastic box and add something like half a kilogram of [https://www.ebay.com/sch/sis.html?_nkw=1KG+Orange+Replacement+Desiccant+Indicating+Silica+Gel+Beads+for+Drawers%2C+Camera&amp;amp;_id=131938742628&amp;amp;&amp;amp;_trksid=p2057872.m2749.l2658 silica gel] to an old sock, tie it and put it in the your new dry box.&lt;br /&gt;
&lt;br /&gt;
Please note that ABS is hydrophobic, so you won&#039;t have to worry too much there. Also, remember that PA/Nylon is extremely hydrophilic. Even a couple of days in normal air humidity can ruin it completely and will require baking.&lt;br /&gt;
&lt;br /&gt;
== Upgrading the firmware on an Ender 3 ==&lt;br /&gt;
&lt;br /&gt;
This is about upgrading the firmware, and thus also flashing a bootloader to the Creality Ender 3 3D printer. Most of this is well documented on several place, like o [https://www.youtube.com/watch?v=fIl5X2ffdyo the video from Teaching tech] and elsewhere, but I&#039;ll just summarise some issues I had.&lt;br /&gt;
&lt;br /&gt;
=== Using an arduino Nano as a programmer ===&lt;br /&gt;
&lt;br /&gt;
Quick note before you read on. If you have an Ender 3 controller version 1.1.5 or newer (or perhaps even a bit older), a CR-10S or some other more or less modern printers or controllers, they come with a bootloader installed already, so don&#039;t bother flashing one. The one that&#039;s in there already, should work well. So if you have one of these, just skip this and jump to the [[Roy&#039;s_notes#Flashing_the_printer|next section]].&lt;br /&gt;
&lt;br /&gt;
However, the normal CR-10 (without the S), Ender 3 and a few other printers from Creality come without a bootloader, so you&#039;ll need to flash one before upgrading the firmware. Well, strictly speakning, you don&#039;t need one, you can save those 8kB or so for other stuff and use a programmer to write the whole firmware, but then you&#039;ll need to wire up everything every time you want a new firmware, so in my world, you &#039;&#039;&#039;do&#039;&#039;&#039; need the bootloader, since it&#039;s easier.&lt;br /&gt;
&lt;br /&gt;
To install a bootloader, you&#039;ll need a programmer, and I didn&#039;t have one available. Having some el-cheapo china-copies of Arduinos around, I read I could use one and tried so. Although the docs mostly mention the Uno etc, it&#039;s just as simple with the Nano copy.&lt;br /&gt;
&lt;br /&gt;
So, grab an arduino, plug it to your machine with a USB cable, and, using the Arduino IDE, use the ArduinoISP sketch there (found under Examples) to burn the software needed for the arduino to work as a programmer. When this is done, connect a 10µF capacitor between RST and GND to stop it from resetting when used as a programmer. Connect the MOSI, MISO and SCK pins from the ICSP block (that little isolated 6-pin block on top of the ardu). See [https://www.arduino.cc/en/Tutorial/ArduinoISP here] for a pinout. Then find Vcc and GND either on the ICSP block or elsewhere. Some sites say that on some boards you shouldn&#039;t use the pins on the ICSP block for this. I doubt it matters, though. Then connect another jumper wire from pin 10 on the ardu to work as the reset pin outwards to the chip being programmed (that is, on the printer). The ICSP jumper block pin layout is the same on the printer and on the ardu, and probably elsewhere. Sometimes [https://xkcd.com/927/ standardisation] actually works…&lt;br /&gt;
&lt;br /&gt;
See https://cloud.karlsbakk.net/index.php/s/zw48YJjzaf8Rc2F for a pic with the ardu (this wiki is broken atm, will fix it later)&lt;br /&gt;
&lt;br /&gt;
== Flashing the printer ==&lt;br /&gt;
&lt;br /&gt;
When the boot loader is in place, possibly after some wierd errors from during the process, the screen on the 3d printer will go blank and it&#039;ll behave like being bricked. This is ok. Now disconnect the wires and connect the USB cable between computer and printer. If you haven&#039;t installed support for the Sanguino board, that is, the variant of the 1284-chip and surrounding electronics that is the core of the, you need to install it first. In the Arduino IDE, choose the Tools / Boards / Boards manager boot option and search for Sanguino. After this, you should find the Sanguino or Sanguino 1284p in the boards menu. After this, you should be able to communicate with the printer&#039;s controller. Download the [https://www.th3dstudio.com/knowledgebase/th3d-unified-firmware-package/ TH3D unified firmware], making sure it&#039;s the last version. Uncompress the zip and with Finder/Explorer/whateversomething&#039;scalledonlinux, browse to &#039;&#039;&#039;TH3DUF_R2/Firmware/TH3DUF_R2.ino&#039;&#039;&#039; and open it. It should open directly in the Android IDE. Keep in mind that the names TH3DUF_R2 and TH3DUF_R2.ino will vary between versions, but you get the point. Now configure it for your particular needs. You&#039;ll find most of this in the Configuration.h tab (that&#039;s really a file). Most of the other files won&#039;t be necessary unless you&#039;re doing some more advanced stuff, like replacing th controller with something non-standard or similar, but then again, that&#039;s another chapter (or book, even). The video mentioned above describes this well. After flashing the new firmware, you&#039;ll probably get some timeouts and errors, since apparently it resets the printer after giving it the new firmware, but without notifying the flashing software of it doing so. If this happens, calm down and reboot the printer and check its tiny monitor - it should work. If it doesn&#039;t work, and if you flashed the bootload yourself, try to flash it again, and if that doesn&#039;t work, try flashing the programmer again yet another time, just for kicks. Again, if you have a newer controller like the v1.1.5, don&#039;t touch the bootloader, as the one already installed, should work well as it is.&lt;br /&gt;
&lt;br /&gt;
PS: I tried enabling &#039;&#039;&#039;MANUAL_MESH_LEVELING&#039;&#039;&#039;, which in the code says that &#039;&#039;If used with a 1284P board the bootscreen will be disabled to save space&#039;&#039;. This effectively disabled the whole printer, and apparently may be making the firmware image a wee bit too large for it to fit the 1284P on the ender. It works well without it, though, and it may be fixed by now, since I tested this back in early 2019.&lt;br /&gt;
&lt;br /&gt;
== And then… ==&lt;br /&gt;
&lt;br /&gt;
With the new firmware in place, the printer should work as before, although with thermal runaway protection to better avoid fires in case the shit hits the fan, and to allow for things like autolevelling. With any luck, [https://www.precisionpiezo.co.uk/ this thing] may be ready for use by the time you read this - it surely looks nice!&lt;br /&gt;
&lt;br /&gt;
roy&lt;/div&gt;</summary>
		<author><name>Roy</name></author>
	</entry>
	<entry>
		<id>https://wiki.malinux.no/index.php?title=Roy%27s_notes&amp;diff=162</id>
		<title>Roy&#039;s notes</title>
		<link rel="alternate" type="text/html" href="https://wiki.malinux.no/index.php?title=Roy%27s_notes&amp;diff=162"/>
		<updated>2020-05-22T01:58:49Z</updated>

		<summary type="html">&lt;p&gt;Roy: /* Flashing the printer */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= LVM, md and friends =&lt;br /&gt;
&lt;br /&gt;
== Linux&#039; Logical Volume Manager (LVM) ==&lt;br /&gt;
&lt;br /&gt;
=== LVM in general ===&lt;br /&gt;
&lt;br /&gt;
LVM is designed to be an abstraction layer on top of physical drives or RAID, typically [https://raid.wiki.kernel.org/index.php/RAID_setup mdraid] or [https://help.ubuntu.com/community/FakeRaidHowto fakeraid]. Keep in mind that fakeraid should be avoided unless you really need it, like in conjunction with dual-booting linux and windows on fakeraid. LVM broadly consists of three elements, the &amp;quot;physical&amp;quot; devices (PV), the volume group (VG) and the logical volume (LV). There can be multiple PVs, VGs and LVs, depending on requirement. More about this below. All commands are given as examples, and all of them can be fine-tuned using extra flags in need of so. In my experience, the defaults work well for most usecases.&lt;br /&gt;
&lt;br /&gt;
I&#039;m mentioning filesystem below too. Where I write ext4, the samme applies to ext2 and ext3.&lt;br /&gt;
&lt;br /&gt;
==== Create a PV ====&lt;br /&gt;
&lt;br /&gt;
A PV is the &amp;quot;physical&amp;quot; parts. This does not need to be a physical disk, but can also be another RAID, be it an mdraid, fakeraid, hardware raid, a virtual disk on a SAN or otherwisee or a partition on one of those. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#  These add three PVs, one on a drive (or hardware raid) and another two on mdraids.&lt;br /&gt;
pvcreate /dev/sdb&lt;br /&gt;
pvcreate /dev/md1 /dev/md2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For more information about pvcreate, see [https://linux.die.net/man/8/pvcreate the manual].&lt;br /&gt;
&lt;br /&gt;
==== Create a VG ====&lt;br /&gt;
&lt;br /&gt;
The volume group consists of one or more PVs grouped together on which LVs can be placed. If several PVs are grouped in a VG, it&#039;s generally a good idea to make sure these PVs have some sort of redundancy, as in mdraid/fakeraid or hwraid. Otherwise it will be like using a [https://en.wikipedia.org/wiki/RAID RAID-0] with a single point of failure on each of the independant drives. LVM has [https://unix.stackexchange.com/questions/150644/raiding-with-lvm-vs-mdraid-pros-and-cons  RAID code in it] as well, so you can use that. I haven&#039;t done so myself, as I generally stick to mraid. The reason is mdraid is, in my opinion older and more stable and has more users (meaning bugs are reported and fixed faster whenever they are found). That said, I beleive the actual RAID code used in LVM RAID are the same function calls as for mdraid, so it may not be much of a difference. I still stick with mdraid. To create a VG, run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create volume group my_vg&lt;br /&gt;
vgcreate my_vg /dev/md1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that if vgcreate is run with a PV (as /dev/md1 above) that is not defined as a PV (like above), this is done implicitly, so if you don&#039;t need any special flags to pvcreate, you can simply skip it and let vgcreate do that for you.&lt;br /&gt;
&lt;br /&gt;
==== Create an LV ====&lt;br /&gt;
&lt;br /&gt;
LVs can be compared to partitions, somehow, since they are bounderies of a fraction or all of that of a VG. The difference between them and a partition, however, is that they can be grown or shrunk easily and also moved around between PVs without downtime. This flexibility makes them superiour to partitions as your system can be changed without users noticing it. By default, an LV is alloated &amp;quot;thickly&amp;quot;, meaning all the data given to it, is allocated from the VG and thus the PV. The following makes a 100GB LV named &amp;quot;thicklv&amp;quot;. When making an LV, I usually allocate what&#039;s needed plus some more, but not everything, just to make sure it&#039;s space available for growth on any of the LVs on the VG, or new LVs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a thick provisioned LV named thicklv on the VG my_vg&lt;br /&gt;
lvcreate -n thicklv -L 100G my_vg&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After the LV is created, a filesystem can be placed on it unless it is meant to be used directly. The application for direct use include swap space, VM storage and certain database systems. Most of these will, however, work on filesystems too, although my testing has shown that on swap space, there is a significant performance gain for using dedicated storage without a filesystem. As for filesystems, most Linux users use either ext4 or xfs. Personally, I generally use XFS these days. See my notes below on filesystem choice.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a filesystem on the LV - this could have been mkfs -t ext4 or whatever filesystem you choose&lt;br /&gt;
mkfs -t xfs /dev/my_vg/thicklv&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then just edit /etc/fstab with correct data and run mount -a, and you should be all set.&lt;br /&gt;
&lt;br /&gt;
==== Create LVM cache ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
lvcreate -L 1G -n _cache_meta data /dev/md1&lt;br /&gt;
&lt;br /&gt;
lvcreate -l100%FREE -n _cache data /dev/md1&lt;br /&gt;
&lt;br /&gt;
# Some would want --cachemode writeback, but seriously, I wouldn&#039;t recommend it. Metadata or data can be easily corrupted in case of failure.&lt;br /&gt;
lvconvert --type cache-pool --cachemode writethrough --poolmetadata data/_cache_meta data/_cache&lt;br /&gt;
&lt;br /&gt;
lvconvert --type cache --cachepool data/_cache data/data&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Disabling LVM cache ====&lt;br /&gt;
&lt;br /&gt;
If you for some reason want to disable caching, this will do it cleanly and remove the LVs earlier created for caching the main device.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
lvconvert --uncache data/data&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Growing devices ====&lt;br /&gt;
&lt;br /&gt;
LVM objects can be grown and shrunk. If a PV resides on a RAID where a new drive has been added or otherwise grown, or on a partition or virtual disk that has been extended, the PV must be updated to reflect these changes. The following command will grow the PV to the maximum available on the underlying storage. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Resize the PV /dev/md (not the RAID, only the PV on the RAID) to its full size&lt;br /&gt;
pvresize /dev/md1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If a new PV is added, the VG can be grown to add the space on that in addition to what&#039;s there already. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Extend my_vg to include md2 and its space&lt;br /&gt;
vgextend my_vg /dev/md2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
With more space available in the VG, the LV can now be extended. Let&#039;s add another 50GB to it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Extend thicklv - add 50GB. If you know you won&#039;t need the space anywhere else, you may want to&lt;br /&gt;
# lvresize -l+100%FREE instead. Keep in mind the difference between -l (extents) and -L (bytes)&lt;br /&gt;
lvresize -L +50G my_vg/thicklv&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Growing filesystems ====&lt;br /&gt;
After the LV has grown, run &#039;&#039;xfs_growfs&#039;&#039; (xfs) or &#039;&#039;resize2fs&#039;&#039; (ext4) to make use of the new data. To grow the filesystem to all available space on ext4, run the below command.  To partly grow the filesystem or to shrink it or otherwise, please see the manuals.&lt;br /&gt;
&lt;br /&gt;
The filesystem can be mounted when this is run. If you for some reason get an &#039;&#039;&#039;access denied&#039;&#039;&#039; error when running this as root or with sudo, it&#039;s likely caused by a filesystem error. To fix this, unmount the filesystem first and run &#039;&#039;&#039;fsck -f /dev/my_vg/thicklv&#039;&#039;&#039; and remount it before retrying to extend it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
resize2fs /dev/my_vg/thicklv&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Similarly, with XFS, but note that xfs_growfs doesn&#039;t take the device name, but the filesystem&#039;s mount point. In the case of XFS, also note that the filesystem &#039;&#039;&#039;&#039;&#039;must&#039;&#039;&#039;&#039;&#039; be mounted to be grown. This, in contrast to how it was in the old days when filesystems had to be unmounted to be grown.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
xfs_growfs /my_mountpoint&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Rename system VG ====&lt;br /&gt;
&lt;br /&gt;
Some distros create VG names like those-from-a-sysadmin-with-a-well-developed-paranoia-not-to-hit-a-duplicate. Debian, for instance, uses names like &amp;quot;my-full-hostname-vg&amp;quot;. Personally, I don&#039;t like these, since if I were to move a disk or vdisk around to somewhere else, I&#039;d make sure not to add a disk named &#039;sys&#039; to an existing system. If you do, most distros will refuse to use the VGs with duplicate names, resulting in the OS not booting until either one is specified by its UUID or just one removed. As I&#039;m aware of this, I stick to the super-risky thing of all system VGs named &#039;sys&#039; and so on.&lt;br /&gt;
&lt;br /&gt;
If you do this, keep in mind that it may blow up your computer and take your girl- or boyfriend with it or even make either of them pregnant, allowing Trump to rule your life and generally make things suck. You&#039;re on your own!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Rename the VG&lt;br /&gt;
vgrename my-full-hostname-vg sys&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, in /boot/grub/grub.cfg, change the old lv path from something like &#039;/dev/mapper/debian--stretch--machine--vg-root&#039; to your new and fancy &#039;/dev/sys/root. Likewise, in /etc/fstab, change occurences of &#039;/dev/mapper/debian--stretch--machine--vg-&#039; (or similar) with &#039;/dev/sys/&#039;. Here, this was like this - the old ones commented out.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;fstab&amp;quot;&amp;gt;&lt;br /&gt;
#/dev/mapper/debian--stretch--box--vg-root      /               ext4            errors=remount-ro,discard       0       1&lt;br /&gt;
/dev/sys/root                                   /               ext4            errors=remount-ro,discard       0       1&lt;br /&gt;
# /boot was on /dev/vda1 during installation&lt;br /&gt;
UUID=myverylonguuidwithatonofgoodinfoinit       /boot           ext2            defaults                        0       2&lt;br /&gt;
#/dev/mapper/debian--stretch--box--vg-swap_1    none            swap            sw                              0       0&lt;br /&gt;
/dev/sys/swap_1                                 none            swap            sw                              0       0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Update /etc/initramfs-tools/conf.d/resume with similar data for swap.&lt;br /&gt;
&lt;br /&gt;
You might want to run &#039;update-initramfs -u -k all&#039; after this, but I&#039;m not sure if it&#039;s needed.&lt;br /&gt;
&lt;br /&gt;
Now, pray to the nearest god(s) and give it a reboot and it should (probably) work.&lt;br /&gt;
&lt;br /&gt;
After reboot, run &#039;&#039;&#039;swapoff -a&#039;&#039;&#039;, then &#039;&#039;&#039;mkswap /dev/sys/swap_1&#039;&#039;&#039; (or whatever it&#039;s called on your system) and &#039;&#039;&#039;swapon -a&#039;&#039;&#039; again. You may want to give it another reboot or two for kicks, but it should work well even without that.&lt;br /&gt;
&lt;br /&gt;
=== Migration tools ===&lt;br /&gt;
&lt;br /&gt;
At times, storage regimes change, new storage is added and sometimes it&#039;s not easy to migrate with the current hardware or its support systems. Once I had to migrate a 45TiB fileserver from one storage system to another, preferably without downtime. The server originally had three 15TiB PVs of which two were full and the third half full. I resorted to using [https://linux.die.net/man/8/pvmove pvmove] to just move the data on the PVs in use to a new PV. We started out with creating a new 50TiB PV, sde, and then to pvmove.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Attach /dev/sde to the VG my_vg&lt;br /&gt;
vgextend my_vg /dev/sde&lt;br /&gt;
&lt;br /&gt;
# Move the contents from /dev/sdb over to /dev/sde block by block. If a target is not given in pvmove,&lt;br /&gt;
# the contents of the source (sdb here) will be put somewhere else in the pool.&lt;br /&gt;
pvmove /dev/sdb /dev/sde&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This took a while (as in a week or so) - the pvmove command uses old code and logic (or at least did that when I migrated this in November 2016), but it affected performance on the server very little, so users didn&#039;t notice. After the first PV was migrated, I continued with the other two, one after the other, and after a month or so, it was migrated. We used this on a number of large fileservers, and it worked flawlessly. Before doing the production servers I also tried interrupting pvmove in various ways, including hard resets, and it just kept on after the reboot.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;NOTE:&#039;&#039;&#039;&#039;&#039; &#039;&#039;Even though it worked well for us, &#039;&#039;&#039;always&#039;&#039;&#039; keep a good backup before doing this. Things may go wrong, and without a good backup, you may be looking for a hard-to-find new job the next morning&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
==== mdadm workarounds ====&lt;br /&gt;
&lt;br /&gt;
===== Migrate from a mirror (raid-1) to raid-10 =====&lt;br /&gt;
&lt;br /&gt;
Create a mirror&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sdb /dev/sdc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
LVM (pv/vg/lv) on md0 (see above), put a filesystem on the lv and fill it with some data.&lt;br /&gt;
&lt;br /&gt;
Now, some months later, you want to change this to raid-10 to allow for the same amount of redundancy, but to allow more disks into the system.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mdadm --grow /dev/md0 --level=10&lt;br /&gt;
mdadm: Impossibly level change request for RAID1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So - no - doesn&#039;t work. But - we&#039;re on &lt;br /&gt;
&lt;br /&gt;
Since we&#039;re on lvm already, this&#039;ll be easy. If you&#039;re using filesystems directly on partitions, you can do this the same way, but without the pvmove part, using rsync or whateever you like instead. I&#039;d recommend using lvm for for the new raid, which should be rather obvious from this article. Now plug in a new drive and create a new raid10 on that one. If you two new drives, install both. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# change &amp;quot;missing&amp;quot; to the other device name if you installed two new drives&lt;br /&gt;
mdadm --create /dev/md1 --level=10 --raid-devices=2 /dev/vdd missing&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, as described above, just vgextend the vg, adding the new raid and run pvmove to move the data from the old pv (residing on the old raid1) to the new pv (on raid10). Afte rpvmove is finished (which may take awile, see above), just&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
vgreduce raidtest /dev/md0&lt;br /&gt;
pvremove /dev/md0&lt;br /&gt;
mdadm --stop /dev/md0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
…and your disk is free to be added to the new array. If the new raid is running in degraded mode (if you created it with just one drive), better don&#039;t wait too long, since you don&#039;t have redundancy. Just mdadm --add the devs.&lt;br /&gt;
&lt;br /&gt;
If you now have /dev/mdstat telling you your raid10 is active and have three drives, of which one is a spare, it should look something like this&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5] [raid4] [raid10]&lt;br /&gt;
md1 : active raid10 vdc[3](S) vdb[2] vdd[0]&lt;br /&gt;
      8380416 blocks super 1.2 2 near-copies [2/2] [UU]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Just mdadm --grow --raid-devices=3 /dev/md1&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;RAID section is not complete. I&#039;ll write more on migraing from raid10 to raid6 later. It&#039;s not straight forward, but easier than this one :)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== Thin provisioned LVs ===&lt;br /&gt;
&lt;br /&gt;
Thin provisioning on LVM is a method used for not allocating all the space given to an LV. For instance, if you have a 1TB VG and want to give an LV 500GB, although it currently only uses a fraction of that, a thin lv can be a good alternative. This will allow for adding a limit to how much it can use, but also to let it grow dynamically without manual work by the sysadmin. Thin provisioning adds another layer of abstaction by creating a special LV as a &#039;&#039;thin pool&#039;&#039; from which data is allocated to the &#039;&#039;thin volume(s)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== Create a thin pool ====&lt;br /&gt;
&lt;br /&gt;
Allocate 1TB to the thin pool to be used for thinly provisioned LVs. Keep in mind that the space allocated to the thin pool is in fact thick provisioned. Only the volumes put on &#039;&#039;thinpool&#039;&#039; are thin provisioned. This will create two hidden LVs, one for data and one for metadata. Normally the defaults will do, but check the manual if the data doesn&#039;t match the usual patterns (such as billions of files, resulting in huge amounts of metadata). I &#039;&#039;beleive&#039;&#039; the metadata part should be resizable at a later time if needed, but I have not tested it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a pool for thin LVs. Keep in mind that the pool itself is not thin provisioned, only the volumes residing on it&lt;br /&gt;
lvcreate --size 1T --type thin-pool --thinpool thinpool my_vg&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Create a thin volume ====&lt;br /&gt;
&lt;br /&gt;
You have the thinpool, now put a thin volume on it. It will allocate some space for metadata, but probably not much (a few megs, perhaps).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Now, create a volume with a virtual (-V) size of half a terabyte named thin_pool, but using the thinpool (-T) named thin_pool for storage&lt;br /&gt;
lvcreate -V 500G -T my_vg/thin_pool --name thinvol&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The new volume&#039;s device name will be /dev/thinvol. Now, create a filesystem on it, add to fstab and mount it. The &#039;&#039;&#039;df&#039;&#039;&#039; command will return available space according to the virtual size (-V), while lvs will show how much data is actually used on each of the thinly provisioned volumes.&lt;br /&gt;
&lt;br /&gt;
== Filesystem dilemmas ==&lt;br /&gt;
&lt;br /&gt;
=== XFS or ext4 or something else ===&lt;br /&gt;
The choice of filesystem varies for your use. Distros such as RHEL/CentOS has moved to XFS by default from v7. Debian/Ubuntu still sticks to ext4, like most other. I&#039;ll discuss my thoughts below on ext4 vs XFS and leave the other filesystems for later.&lt;br /&gt;
&lt;br /&gt;
==== ext4 ====&lt;br /&gt;
ext4 is probably the most used filesystem on linux as of writing. It&#039;s rock stable and has been extended by a lot of extensions since the original ext2. It still retains backward compatibility, being able to mount and fsck ext2 and ext3 with the ext4 driver. However, it doesn&#039;t handle large filesystems very well. If a filesystem is created for &amp;lt;16TiB, it cannot be grown to anything larger than 16TiB. This may have changed lately, though. One other issue is handling errors. If a large filesystem (say 10TiB) is damaged, an fsck may take several hours, leading to long downtime. When I refer to ext4 further in this text, the same applies to ext2 and ext3 unless otherwise specified.&lt;br /&gt;
&lt;br /&gt;
==== XFS ====&lt;br /&gt;
XFS, originally developed by SGI some time in the bronze age, but has been worked on heavily after that. RHEL and Centos version 7 and forward, uses XFS as the default filesystem. It is quick, it scales well, but it lacks at least two things ext4 has. It cannot be shrunk (not that you normally need that, but nice if you have a typo or you need to change things). Also, it doesn&#039;t allow for automatic fsck on bootup. If something is messed up on the filesystem, you&#039;ll have to login as root on the console (not ssh), which might be an issue on some systems. The fsck equivalent, xfs_repair, is a *lot* faster than ext4&#039;s fsck, though.&lt;br /&gt;
&lt;br /&gt;
==== ZFS ====&lt;br /&gt;
ZFS is like a combination of RAID, LVM and a filesystem, supporting full checksumming, auto-healing (given sufficient redundancy), compression, encryption, replication, deduplication (if you&#039;re brave and have a &#039;&#039;ton&#039;&#039; of memory) and a lot more. It&#039;s a separate chapter and needs a lot more talk than paragraph here.&lt;br /&gt;
&lt;br /&gt;
==== btrfs ====&lt;br /&gt;
btrfs, pronounced &amp;quot;butterfs&amp;quot; or &amp;quot;betterfs&amp;quot; or just spelled out, is a filesystem that mimics that of ZFS. It has been around for 10 years or so, but hasn&#039;t yet proven to be really stable. Following the progress of it for those years, I&#039;ve found it to be a nice toy with which to play, but not to be used in production. Again, others may say otherwise, but these are just my words.&lt;br /&gt;
&lt;br /&gt;
== Low level disk handling ==&lt;br /&gt;
&lt;br /&gt;
This section is for low-level handling of disks, regardless of storage system elsewhere. These apply to mdraid, lvmraid and zfs and possibly other solutions, with the exception of individual drives on hwraid (and maybe fakeraid), since there, the drives are hidden from Linux (or whatever OS).&lt;br /&gt;
&lt;br /&gt;
=== S.M.A.R.T. and slow drives ===&lt;br /&gt;
Modern (that is, from about 1990 or later) have S.M.A.R.T. (or just smart, since it&#039;s easier to type) monitoring built in, meaning the disk&#039;s controller is monitoring itself. This is handy and will ideally tell you in advance that a drive is flakey or dying. Modern (2010+) smart monitoring is more or less the same. It can be trusted about 50% of the time. Usually, if smart detects an error, it&#039;s a real error. I don&#039;t think I&#039;ve seen it reporting a false positive, but others may know better. &lt;br /&gt;
&lt;br /&gt;
==== smartmontools ====&lt;br /&gt;
First, install smartmontool and run smartclt -H /dev/yourdisk (/dev/sda or something) to get a health report. Then perhaps run smartctl -a /dev/yourdisk and look for &#039;current pending sectors&#039; This should be zero. Also check the temperature, which normally should be much above 50.&lt;br /&gt;
&lt;br /&gt;
==== single, slow drive ====&lt;br /&gt;
What may happen, is smart not seeing anything and life goes on like before, only slower and less prouductive, without telling anyone. If you stubler over this issue, you&#039;ll probably see it during a large rsync/zfs send/receive or a resync/rebuild/resilver of the raid/zpool. During this, it feels like everything is slow and your RAID has turned into a RAIF (redundant array of inexpensive floppies). To check if you have a single drive messing up it all, check with &#039;&#039;&#039;iostat -x 2&#039;&#039;&#039;, having 2 being the delay between each measurement. Interrupt it with ctrl+x. If there&#039;s a rougue drive there, it should stand out like sdg below&lt;br /&gt;
&lt;br /&gt;
 avg-cpu:  %user   %nice %system %iowait  %steal   %idle&lt;br /&gt;
            0.38    0.00    1.75    0.00    0.00   97.87&lt;br /&gt;
&lt;br /&gt;
 Device            r/s     w/s     rkB/s     wkB/s   rrqm/s   wrqm/s  %rrqm  %wrqm r_await w_await aqu-sz rareq-sz wareq-sz  svctm  %util&lt;br /&gt;
 sda              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdb              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdc              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdd              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sde              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdf              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdg              3.50    0.00   2352.00      0.00     0.00     0.00   0.00   0.00 14306.29    0.00  13.85   672.00     0.00 285.71 100.00&lt;br /&gt;
 sdh              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
&lt;br /&gt;
In ZFS land, you should be able to get similar data with &#039;&#039;&#039;zpool iostat -v &amp;lt;pool&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Now you know the bad drive (sdg), pull it from the raid with &#039;&#039;&#039;mdadm --fail /dev/mdX /dev/sdX&#039;&#039;&#039;. Now test the drive&#039;s performance manually, just simply:&lt;br /&gt;
&lt;br /&gt;
 # hdparm -t /dev/sdg&lt;br /&gt;
 &lt;br /&gt;
 /dev/sdg:&lt;br /&gt;
  Timing buffered disk reads:   2 MB in  5.37 seconds = 381.46 kB/sec&lt;br /&gt;
&lt;br /&gt;
Bingo - nothing you&#039;d want to keep. For a good drive, it should be something like 100-200MB/s&lt;br /&gt;
&lt;br /&gt;
PS: Keep in mind that you have a degraded RAID by now in case you had a spare waiting for things to happen.&lt;br /&gt;
&lt;br /&gt;
Try to replace the cable and/or try the disk on another port/controller. If the result from hdparm persists, it&#039;s probably a bad cable&lt;br /&gt;
&lt;br /&gt;
So, then, just psycially locate the drive, pull it out, take out the discs and magnets and recycle the rest.&lt;br /&gt;
&lt;br /&gt;
=== &amp;quot;Unplug&amp;quot; drive from system ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Find the device unit&#039;s number with something like&lt;br /&gt;
find /sys/bus/scsi/devices/*/block/ -name sdd&lt;br /&gt;
# returning /sys/bus/scsi/devices/3:0:0:0/block/sdd here, &lt;br /&gt;
# meaning 3:0:0:0 is the SCSI device we&#039;re looking for.&lt;br /&gt;
&lt;br /&gt;
# Given this is the correct device, and you want to &#039;unplug&#039; it, do so by&lt;br /&gt;
echo 1 &amp;gt; /sys/bus/scsi/devices/3:0:0:0/delete&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Rescan disk controllers ===&lt;br /&gt;
If a drive is added and for some reason doesn&#039;t get detected, or is removed by the command above, it can be rediscovered with a sysfs command to the scsi host to which it is connected. Since there may be quite a few of these, an easy way is to just scan them all and check the output of &#039;&#039;&#039;dmesg -T&#039;&#039;&#039; after running it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Make a list of controllers and send a rescan message to each of them. It won&#039;t do anything &lt;br /&gt;
# for those where nothing has changed, but it will show new drives where they have been added.&lt;br /&gt;
for host_scan in /sys/class/scsi_host/host*/scan&lt;br /&gt;
do&lt;br /&gt;
  echo &#039;- - -&#039; &amp;gt; $host_scan&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Fail injection with debugfs ===&lt;br /&gt;
[https://lxadm.com/Using_fault_injection https://lxadm.com/Using_fault_injection]&lt;br /&gt;
&lt;br /&gt;
== mdadm stuff ==&lt;br /&gt;
=== Resync ===&lt;br /&gt;
To resync a raid, that is, check, run&lt;br /&gt;
&lt;br /&gt;
 echo check &amp;gt; /sys/block/$dev/md/sync_action&lt;br /&gt;
&lt;br /&gt;
where $dev is something like md0. If you have several raids, something like this should work&lt;br /&gt;
&lt;br /&gt;
 for dev in md{0,1}&lt;br /&gt;
 do&lt;br /&gt;
   echo repair &amp;gt; /sys/block/$dev/md/sync_action&lt;br /&gt;
 done&lt;br /&gt;
&lt;br /&gt;
Also useful in a one-liner like&lt;br /&gt;
&lt;br /&gt;
 for dev in md{0,1} ; do echo repair &amp;gt; /sys/block/$dev/md/sync_action ; done&lt;br /&gt;
&lt;br /&gt;
Different raids on different drives will do this in parallel. If the drives are shared somehow with partitions or similar, the check or repair will wait for the other to finish before going on.&lt;br /&gt;
&lt;br /&gt;
As for repair vs check, [https://raid.wiki.kernel.org/index.php/RAID_Administration this article] describes it well. I stick to using repair unless it&#039;s something rare where I don&#039;t want to touch the data.&lt;br /&gt;
&lt;br /&gt;
=== Spare pools ===&lt;br /&gt;
In the old itmes, mdadm supported only a dedicated spare per md device, so if working with a large set of drives (20? 40?), where you&#039;d want to setup more raid sets to increase redundancy, you&#039;d dedicate a spare to each of the raid sets. This has changed (some time ago?), so in these modern, heathen days, you can change mdadm.conf, usually placed under /etc/mdadm, and add &#039;spare-group=somegroup&#039; where &#039;somegroup&#039; is a string identifying the spare group. After doing this, run &#039;&#039;&#039;update-initramfs -u&#039;&#039;&#039; and reboot and add a spare to one of the raid sets in the spare group, and md will use that or those spares for all the raidsets in that group.&lt;br /&gt;
&lt;br /&gt;
As some pointed out on #linux-raid @ irc.freenode.net, this feature is very badly documented, but as far as I can see, it works well.&lt;br /&gt;
&lt;br /&gt;
==== Example config ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create two raidsets&lt;br /&gt;
&lt;br /&gt;
mdadm --create /dev/md1 --level=6 --raid-devices=6 /dev/vd[efghij]&lt;br /&gt;
mdadm --create /dev/md2 --level=6 --raid-devices=6 /dev/vd[klmnop]&lt;br /&gt;
&lt;br /&gt;
# get their UUID etc&lt;br /&gt;
&lt;br /&gt;
mdadm --detail --scan&lt;br /&gt;
ARRAY /dev/md/1 metadata=1.2 name=raidtest:1 UUID=1a8cbdcb:f4092350:348b6b80:c054d74c&lt;br /&gt;
ARRAY /dev/md/2 metadata=1.2 name=raidtest:2 UUID=894b1b7c:cb7eba70:917d6033:ea5afd2b&lt;br /&gt;
&lt;br /&gt;
# Put those lines into /etc/mdadm/mdadm.conf and and add the spare-group&lt;br /&gt;
&lt;br /&gt;
ARRAY /dev/md/1 metadata=1.2 name=raidtest:1 spare-group=raidtest UUID=1a8cbdcb:f4092350:348b6b80:c054d74c&lt;br /&gt;
ARRAY /dev/md/2 metadata=1.2 name=raidtest:2 spare-group=raidtest UUID=894b1b7c:cb7eba70:917d6033:ea5afd2b&lt;br /&gt;
&lt;br /&gt;
# update the initramfs and reboot&lt;br /&gt;
&lt;br /&gt;
update-initramfs -u&lt;br /&gt;
reboot&lt;br /&gt;
&lt;br /&gt;
# add a spare drive to one of the raids&lt;br /&gt;
&lt;br /&gt;
mdadm --add /dev/md1 /dev/vdq&lt;br /&gt;
&lt;br /&gt;
# fail a drive on the other raid&lt;br /&gt;
&lt;br /&gt;
mdadm --fail /dev/md2 /dev/vdn&lt;br /&gt;
&lt;br /&gt;
# check /proc/mdstat to see md2 rebuilding with the spare from md1&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Recovery ===&lt;br /&gt;
&lt;br /&gt;
The other day, I came across a problem a user had on #linux-raid@irc.freenode.net. He had an old Qnap NAS that had died and tried plugging the drives in to his Linux machine and got various errors. The two-drive RAID-1 did not come up as it should, &#039;&#039;&#039;dmesg&#039;&#039;&#039; was full of errors from one of the drives (both connected on USB) and so forth.&lt;br /&gt;
&lt;br /&gt;
We went on and started by taking down the machine and just connecting one of the drives. I had him check what was assembled with&lt;br /&gt;
&lt;br /&gt;
 cat /proc/mdstat&lt;br /&gt;
&lt;br /&gt;
That returned /proc/md127 assembled, but LVM didn&#039;t find anything. So running a manual scan&lt;br /&gt;
&lt;br /&gt;
 pvscan --cache /dev/md127&lt;br /&gt;
&lt;br /&gt;
This made linux find the PV, VG and a couple of LVs, but probably because the mdraid was degraded, the LVs were deactivated, according to &#039;&#039;&#039;lvscan&#039;&#039;&#039;. Activating the one with a filesystem manually&lt;br /&gt;
&lt;br /&gt;
 lvchange -a y /dev/&amp;lt;vg&amp;gt;/&amp;lt;lv&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Substitute &amp;lt;vg&amp;gt; and &amp;lt;lv&amp;gt; with the names listed by vgs and lvs.&lt;br /&gt;
&lt;br /&gt;
This worked, and the filesystem on /dev/&amp;lt;vg&amp;gt;/&amp;lt;lv&amp;gt; could be mounted correctly.&lt;br /&gt;
&lt;br /&gt;
== Tuning ==&lt;br /&gt;
&lt;br /&gt;
While trying to compare a 12-disk RAID (8TB disks) to a hwraid, mdraid was slower, so we did a few things to speed things up:&lt;br /&gt;
&lt;br /&gt;
While testing with [https://linux.die.net/man/1/fio fio], monitor /sys/block/md0/md/stripe_cache_active, and see if it&#039;s close to /sys/block/md0/md/stripe_cache_size. If it is, double the size of the latter&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
echo 4096 &amp;gt; /sys/block/md0/md/stripe_cache_size&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Continue until stripe_cache_active stabilises, and then you&#039;ve found the limit you&#039;ll need. You may want to double that for good measure. &lt;br /&gt;
&lt;br /&gt;
(to be continued)&lt;br /&gt;
&lt;br /&gt;
== Links ==&lt;br /&gt;
&lt;br /&gt;
Below are a few links with useful info&lt;br /&gt;
&lt;br /&gt;
* [https://raid.wiki.kernel.org/index.php/Irreversible_mdadm_failure_recovery Irreversible mdadm failure recovery]&lt;br /&gt;
&lt;br /&gt;
= ZFS =&lt;br /&gt;
&lt;br /&gt;
ZFS can do a lot of things most filesystems or volume managers can&#039;t. It checksums all data and metadata and so long that the system uses ECC enabled memory (RAM), it will have complete control over the whole data set, and when (not if) an error occurs, it&#039;ll fix the issue without even throwing a warning. To fix the issue, you&#039;ll obviously need sufficient redundancy (mirrors or RAIDzN). &lt;br /&gt;
&lt;br /&gt;
== ZFS send/receive between machines ==&lt;br /&gt;
&lt;br /&gt;
ZFS has a send/receive mechanism that allows for snapshots to be sent over the wire to a receiving end. This can be a full filesystem, or an incremental change since last send/reveive. In a WAN scenario, you&#039;ll probably want to use VPN for this. On a controlled network, sending in cleartext is also possible. You may as well use ssh, but keep in mind that ssh was never designed to be used as a fullblown vpn solution and is just too slow or the task with large amounts of data. You may, though, use mbuffer, if on a loal LAN.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Allow traffic from the sending IP in whatever firewall interface you&#039;re using (if you&#039;re using a firewall at all, that is)&lt;br /&gt;
ufw allow from x.x.x.x&lt;br /&gt;
# &lt;br /&gt;
# Start the receiver first. This listens on port 9090, has a 1GB buffer,&lt;br /&gt;
    and uses 128kb chunks (same as zfs):&lt;br /&gt;
&lt;br /&gt;
mbuffer -s 128k -m 1G -I 9090 | zfs receive data/filesystem&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To be continued one day… See [https://everycity.co.uk/alasdair/2010/07/using-mbuffer-to-speed-up-slow-zfs-send-zfs-receive/ this] for some more. I&#039;ll get back with details on it.&lt;br /&gt;
&lt;br /&gt;
= General Linux system control =&lt;br /&gt;
&lt;br /&gt;
== Add a new CPU (core) ==&lt;br /&gt;
&lt;br /&gt;
If working with virtual machines, adding a new core can be useful if the VM is slow and the load is multithreaded or multiprocess. To do this, add a new CPU in the hypervisor (be it KVM or VMware or Hyper-V or whatever). Some hypervisors, like VMware, will activate it automatically if open-vm-tools is installed. Please note that open-vm-tools is for VMware only. I don&#039;t know of any such thing for KVM or other hypervisors (although I beleive VirtualBox has its own set of tools, but not as a package). If this doesn&#039;t work, run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
echo 1 &amp;gt; /sys/devices/system/cpu/cpuX/online&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where X is the CPU number you want to add. You can &#039;cat /sys/devices/system/cpu/cpuX/online&#039; to check if it&#039;s online.&lt;br /&gt;
&lt;br /&gt;
= Mount partitions on a disk image =&lt;br /&gt;
&lt;br /&gt;
Sometimes you&#039;ll have a disk image, either from recovering a bad drive after hours (or days or weeks) of ddrescue, and sometimes you just have a disk image from a virtual machine where you want to mount the partitions inside the image. There are three main methods of doing this, which are more or less synonmous, but some easier than the other.&lt;br /&gt;
&lt;br /&gt;
== Basics ==&lt;br /&gt;
&lt;br /&gt;
A disk image is usually like a disk, consisting of either a large filesystem, a PV or a partition table with one or partitions onto which resides a filesystem, a pv, swap or something else. If it&#039;s partitioned, and you want your operating system to mount a filesystem or allow it to see whatever LVM stuff lies on it, you need to isolate the partitions. &lt;br /&gt;
&lt;br /&gt;
== Manual mapping ==&lt;br /&gt;
&lt;br /&gt;
In the oldern days, this was done manually, something like this&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
root@mymachine:~# fdisk -l /dev/vda&lt;br /&gt;
Disk /dev/vda: 25 GiB, 26843545600 bytes, 52428800 sectors&lt;br /&gt;
Units: sectors of 1 * 512 = 512 bytes&lt;br /&gt;
Sector size (logical/physical): 512 bytes / 512 bytes&lt;br /&gt;
I/O size (minimum/optimal): 512 bytes / 512 bytes&lt;br /&gt;
Disklabel type: dos&lt;br /&gt;
Disk identifier: 0xc37b7ea5&lt;br /&gt;
&lt;br /&gt;
Device     Boot    Start      End  Sectors  Size Id Type&lt;br /&gt;
/dev/vda1  *        2048 50333311 50331264   24G 83 Linux&lt;br /&gt;
/dev/vda2       50333312 52426369  2093058 1022M  5 Extended&lt;br /&gt;
/dev/vda5       50333314 52426369  2093056 1022M 82 Linux swap / Solaris&lt;br /&gt;
root@mymachine:~#&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To calculate the start and end of each partition, you just take the start sector and multiply it by the sector size (512 bytes here) and you have the offset in bytes. After this, it&#039;s merely an losetup -o &amp;lt;offset&amp;gt; /dev/loopX &amp;lt;nameofimagefile&amp;gt; and you have the partition mapped to your /dev/loopX (having X being something typically 0-255. After this, just mount it or run pvscan/vgscan/lvscan to probe whatever lvm config is there, and you should be able to mount it like any other filesystem.&lt;br /&gt;
&lt;br /&gt;
== kpartx ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;kpartx&#039;&#039;&#039; does the same as above, more or less, just without so much hassle. Most of it should be automatic and easy to deal with, except it may fail to disconnect the loopback devices sometimes, so you may have to &#039;&#039;&#039;losetup -d&#039;&#039;&#039; them manually. See the manual, &#039;&#039;&#039;kpartx (8)&#039;&#039;&#039;. Please note that &#039;&#039;&#039;partx&#039;&#039;&#039; works similarly and I&#039;d guess the authors of the two tools are arguing a lot of which one&#039;s the best.&lt;br /&gt;
&lt;br /&gt;
== guestmount ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;guestmount&#039;&#039;&#039; is something similar again, but also supports file formats like &#039;&#039;&#039;qcow2&#039;&#039;&#039; and possibly other, proprietary filesystems like &#039;&#039;&#039;vmdk&#039;&#039;&#039; and &#039;&#039;&#039;vdi&#039;&#039;&#039;, but don&#039;t take my word for it - I haven&#039;t tested. Again, see the manual or just read up on the description [http://ask.xmodulo.com/mount-qcow2-disk-image-linux.html?fbclid=IwAR3snTeZvGzp9PLdX11EQhCfOpux6I93CiJ3A2pUomkkRLly9Xo4851mkTY here]. It seems rather trivial.&lt;br /&gt;
&lt;br /&gt;
= Linux on laptops =&lt;br /&gt;
&lt;br /&gt;
== Wifi with HP EliteBook 725/745 on Ubuntu ==&lt;br /&gt;
&lt;br /&gt;
The HP EliteBook 725/745 and similar are equipped with a BCM4352 wifi chip. As with a lot of other stuff from Broadcom, this lacks an open hardware description, so thus no open driver exist. The proper fix, is to replace the NIC with something with an open driver, but again, this isn&#039;t always possible, so a binary driver exists. In ubuntu, run, somehow connect the machine to the internet and run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install bcmwl-kernel-source&lt;br /&gt;
sudo modprobe wl&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you can&#039;t connect the machine to the internet, download the needed packages on another machine and put it on some usb storage. These packages should suffice:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# apt-cache depends bcmwl-kernel-source&lt;br /&gt;
bcmwl-kernel-source&lt;br /&gt;
  Depends: dkms&lt;br /&gt;
  Depends: linux-libc-dev&lt;br /&gt;
  Depends: libc6-dev&lt;br /&gt;
  Conflicts: &amp;lt;bcmwl-modaliases&amp;gt;&lt;br /&gt;
  Replaces: &amp;lt;bcmwl-modaliases&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then install manually with &#039;&#039;&#039;dpkg -i file1.deb file2.deb&#039;&#039;&#039; etc&lt;br /&gt;
&lt;br /&gt;
After this, ip/ifconfig/iwconfig shouldd see the new wifi nic, probably &#039;&#039;&#039;wlan0&#039;&#039;&#039;, but due to a [https://bugs.launchpad.net/ubuntu/+source/broadcom-sta/+bug/1343151 old, ignored bug], you won&#039;t find any wifi networks. This is because the driver from Broadcom apparently does not support interrupt remapping, commonly used on x64 machines. To turn this off, change &#039;&#039;&#039;/etc/default/grub&#039;&#039;&#039; and change the line &#039;&#039;&#039;GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;quiet splash&amp;quot;&#039;&#039;&#039;, adding intremap=off to the end before the quote: &#039;&#039;&#039;GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;quiet splash intremap=off&amp;quot;&#039;&#039;&#039;. Save the file and run &#039;&#039;&#039;sudo update-grub&#039;&#039;&#039; and reboot. After this, wifi should work well.&lt;br /&gt;
&lt;br /&gt;
== Wifi with HP Compaq Presario CQ57 on Ubuntu ==&lt;br /&gt;
&lt;br /&gt;
The HP Compaq Presario CQ57 uses the RT5390 wifi chipset. This has been supported for quite some time now, and I was quite surprised to find it not working on a laptop a friend was having. The driver loaded correctly, but Ubuntu insisted of the laptop being in &#039;&#039;&#039;flight mode&#039;&#039;&#039;. Checking &#039;&#039;&#039;rfkill&#039;&#039;&#039;, it showed me two NICs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# rfkill list all&lt;br /&gt;
0: phy0: Wireless LAN&lt;br /&gt;
	Soft blocked: no&lt;br /&gt;
	Hard blocked: yes&lt;br /&gt;
1: hp-wifi: Wireless LAN&lt;br /&gt;
	Soft blocked: yes&lt;br /&gt;
	Hard blocked: no&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Turning rfkill on and off resulted in nothing much, except some error messages in the kernel log (dmesg)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] ACPI Error: Field [B128] at bit offset/length 128/1024 exceeds size of target Buffer (160 bits) (20170831/dsopcode-235)&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]&lt;br /&gt;
                            Initialized Local Variables for Method [HWCD]:&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Local0: 00000000a34b7928 &amp;lt;Obj&amp;gt;           Integer 0000000000000000&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Local1: 00000000b0aa6865 &amp;lt;Obj&amp;gt;           Buffer(8) 46 41 49 4C 04 00 00 00&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Local5: 00000000a9811efd &amp;lt;Obj&amp;gt;           Integer 0000000000000004&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] Initialized Arguments for Method [HWCD]:  (2 arguments defined for method invocation)&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Arg0:   0000000078957d1b &amp;lt;Obj&amp;gt;           Integer 0000000000000001&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Arg1:   00000000725c9c6e &amp;lt;Obj&amp;gt;           Buffer(20) 53 45 43 55 02 00 00 00&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] ACPI Error: Method parse/execution failed \_SB.WMID.HWCD, AE_AML_BUFFER_LIMIT (20170831/psparse-550)&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] ACPI Error: Method parse/execution failed \_SB.WMID.WMAD, AE_AML_BUFFER_LIMIT (20170831/psparse-550)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After upgrading BIOS and testing different kernels, I was asked to try to unload the &#039;&#039;&#039;hp_wmi&#039;&#039;&#039; driver. I did, and things changed a bit, so I tried blacklisting it, creating the file &#039;&#039;&#039;/etc/modprobe.d/blacklist-hp_wmi.conf&#039;&#039;&#039; with the following content&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Blacklist this - it doesn&#039;t work!&lt;br /&gt;
blacklist hp_wmi&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
I gave the machine a reboot and afte that, the &#039;&#039;&#039;hp-wifi&#039;&#039;&#039; entry was gone in the rfkill output, and things works.&lt;br /&gt;
&lt;br /&gt;
= Raspberry pi =&lt;br /&gt;
&lt;br /&gt;
I couldn&#039;t quite decide if the raspberry pi should be a separate section or part of Linux, but hell, it can run more than Linux, although 99,lots% of people just uses Linux on them. This is a small list of things to know about them; things not on the front page of the manual or perhaps hidden even better.&lt;br /&gt;
&lt;br /&gt;
== Which pi? ==&lt;br /&gt;
&lt;br /&gt;
I just setup three raspberry pi machines and although some are quite different, like v1 to vEverythingelse or the Pi zero versions to the normal ones, not all of us remember how to distinguish between them, and sometimes they&#039;re in a nice 3d printed (or otherwise) chassis or otherwise hidden. So, how to check three different ones:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
root@home-assistant:~ $ cat /proc/device-tree/model ; echo&lt;br /&gt;
Raspberry Pi 2 Model B Rev 1.1&lt;br /&gt;
&lt;br /&gt;
root@green-pi:~ $ cat /proc/device-tree/model ; echo&lt;br /&gt;
Raspberry Pi 3 Model B Rev 1.2&lt;br /&gt;
&lt;br /&gt;
roy@yellow-pi:~ $cat /proc/device-tree/model ; echo&lt;br /&gt;
Raspberry Pi 4 Model B Rev 1.1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
While this works well, for the latter, the pi4, it doesn&#039;t tell how much memory I have. It comes in variants of 1, 2 and 4GB, and this is the latter.&lt;br /&gt;
&lt;br /&gt;
== Monitoring ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;vcgencmd&#039;&#039;&#039; from &#039;&#039;&#039;/opt/vc/bin&#039;&#039;&#039;, but symlinked to &#039;&#039;&#039;/usr/bin&#039;&#039;&#039; so it&#039;s available in path, is useful for fetching hardware info about the pi. For example, measuring the temperature&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
root@yellow-pi:~# vcgencmd measure_temp&lt;br /&gt;
temp=63.0&#039;C&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The command is generally badly documented and parts of it seems outdated for newer hardware. Here&#039;s the output from a Raspberry pi 4 with 4GB RAM&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
roy@yellow-pi:~ $ vcgencmd get_mem arm&lt;br /&gt;
arm=948M&lt;br /&gt;
roy@yellow-pi:~ $ vcgencmd get_mem gpu&lt;br /&gt;
gpu=76M&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== BIOS upgrade from Linux ==&lt;br /&gt;
&lt;br /&gt;
Generally, BIOS upgrades have been moved to the BIOS itself these days. This saves a lot of work and quite possibly lives after those who earier rammed their heads through walls, now can upgrade directly from the internet instead of using obscure operating systems best avoided. Sometimes, however, one must use these nevertheless. This is a quick run-through on your options.&lt;br /&gt;
&lt;br /&gt;
=== DOS ===&lt;br /&gt;
&lt;br /&gt;
Most non-automatic BIOS upgrades are installed from DOS. Doing a BIOS upgrade this way, is generally non-problematic. Just install a USB thingie with [https://www.freedos.org/ FreeDOS], copy your file(s) onto the thing and boot on it. The commandline is the same as old MS/DOS, except a wee bit more userfriendly, but not a lot.&lt;br /&gt;
&lt;br /&gt;
=== Windows ===&lt;br /&gt;
&lt;br /&gt;
Some macahines, like laptops from &#039;&#039;&#039;HP&#039;&#039;&#039;, may have BIOS upgrades that are made to be installed from Windows and won&#039;t run in FreeDOS or MS/DOS, instead throwing an error, saying &#039;&#039;&#039;This program cannot be run in DOS mode&#039;&#039;&#039;. This means you&#039;ll have to boot on a Windows rescue disc and do the job from there. Googling this, tells you it&#039;s quite easy, you just choose &#039;make rescue disc&#039; from Windows, and it&#039;s all good, except if you don&#039;t run Windows, that is. To remedy this problem, do as follows:&lt;br /&gt;
&lt;br /&gt;
==== Download Windows ====&lt;br /&gt;
&lt;br /&gt;
Since you don&#039;t run Windows and possibly don&#039;t have a spouse or friend around with such unhealthy habits either, you need to get it. It&#039;s quite easy - just google &#039;download windows&#039; and it&#039;ll send you to [https://www.microsoft.com/en-us/software-download/windows10ISO somewhere like this].&lt;br /&gt;
&lt;br /&gt;
==== Burn it! ====&lt;br /&gt;
&lt;br /&gt;
Now it&#039;s time to burn the installer on a DVD ROM. You&#039;ll need a double-layered one, since the OS is &amp;gt; 4.7GiB, but I&#039;m sure you have a ton of those lying around. Now, just place your optical medium in your optical drive and burn, baby, burn!&lt;br /&gt;
&lt;br /&gt;
==== Or make a USB thing? ====&lt;br /&gt;
&lt;br /&gt;
Not a lot of machines have optical drives these days, so you may want to use an USB pen drive or something instead. This is easy, just make the USB bootable with the Windows application Microsoft has made for this. Unfortunately, this only runs on Windows, and unlike stuff like Debian, where the &#039;&#039;&#039;iso&#039;&#039;&#039; file can be dd&#039;ed directly onto a USB drive to make it bootable, the Windows &#039;&#039;&#039;iso&#039;&#039;&#039;s don&#039;t come with this luxury. There are lots of methods to make bootable USB things from iso files out there, but the only thing most of them have in common, is that they generally don&#039;t work.&lt;br /&gt;
&lt;br /&gt;
===== WoeUSB =====&lt;br /&gt;
&lt;br /&gt;
After hours of swearing, it&#039;s nice to come across software like [https://github.com/slacka/WoeUSB WoeUSB]. It may not be perfect, it relies on a bunch of GUI stuff you&#039;ll never need and so on, but it &#039;&#039;&#039;&#039;&#039;works&#039;&#039;&#039;&#039;&#039;, and that&#039;s the important part! Just clone the repo and RTFM and it&#039;s all nice. It&#039;s slow, but hell, getting a windows machine and/or an optical drive might be slower.&lt;br /&gt;
&lt;br /&gt;
WoeUSB does nothing fancy, but it &#039;&#039;&#039;does&#039;&#039;&#039; work. It will create a filesystem, FAT32 or NTFS (better use NTFS, FAT32 has its limits). It creates normal filesystems and so on. Just make sure to copy in the BIOS update file, usually an exe file, to run when Windows is up and running.&lt;br /&gt;
&lt;br /&gt;
===== Install BIOS =====&lt;br /&gt;
&lt;br /&gt;
Boot on the Windows USB thing and choose &#039;repair computer&#039; and then &#039;command prompt&#039;. Find the install file, and if you&#039;re lucky, you&#039;ll find it needs a 32bit OS, just like I did. Since the 64bit version doesn&#039;t include 32bit compatibility in the installer, revert to downloading the 32bit version of windows and start over. Pray to your favourite god(s) not to get across such machines again - it might help.&lt;br /&gt;
&lt;br /&gt;
= 3D printer stuff =&lt;br /&gt;
&lt;br /&gt;
== Hydrophilic filament ==&lt;br /&gt;
&lt;br /&gt;
Most popular filament types, including PLA, PETG, PP or PA (Polyamide, normally known as Nylon) and virtualy any filament type named [https://www.matterhackers.com/news/filament-and-water poly-something] (and thus with an acronym of P-something) are hydrophilic (also (somewhat incorrectly) called hydroscopic), meaning so long they&#039;re dryer than the atmosphere around them, they&#039;ll do their best to suck out the atmosphere&#039;s humidity. This is why most filament are shrink-wrapped with a small bag of silica gel in it. If such filament is exposed for normal humid air for some time, it&#039;ll become very hard to use. Most of my experience is with PLA, which can handle a bit (depending on make), but still not a lot. With PLA, if you end up with prints where the filament seems not to stick, it may help with a higher temperature. Otherwise, the filament must be [https://all3dp.com/2/how-to-dry-filament-pla-abs-and-nylon/ baked]. If you don&#039;t want to use your oven, try something like a [https://www.jula.no/catalog/hjem-og-husholdning/kjokkenmaskiner/mattilberedningsapparater/frukt-sopptorker/frukt-sopptorker-001641/#tab02 fruit and mushroom dryer]. Then get a good, sealble plastic box and add something like half a kilogram of [https://www.ebay.com/sch/sis.html?_nkw=1KG+Orange+Replacement+Desiccant+Indicating+Silica+Gel+Beads+for+Drawers%2C+Camera&amp;amp;_id=131938742628&amp;amp;&amp;amp;_trksid=p2057872.m2749.l2658 silica gel] to an old sock, tie it and put it in the your new dry box.&lt;br /&gt;
&lt;br /&gt;
Please note that ABS is hydrophobic, so you won&#039;t have to worry too much there. Also, remember that PA/Nylon is extremely hydrophilic. Even a couple of days in normal air humidity can ruin it completely and will require baking.&lt;br /&gt;
&lt;br /&gt;
== Upgrading the firmware on an Ender 3 ==&lt;br /&gt;
&lt;br /&gt;
This is about upgrading the firmware, and thus also flashing a bootloader to the Creality Ender 3 3D printer. Most of this is well documented on several place, like o [https://www.youtube.com/watch?v=fIl5X2ffdyo the video from Teaching tech] and elsewhere, but I&#039;ll just summarise some issues I had.&lt;br /&gt;
&lt;br /&gt;
=== Using an arduino Nano as a programmer ===&lt;br /&gt;
&lt;br /&gt;
Quick note before you read on. If you have an Ender 3 controller version 1.1.5 or newer (or perhaps even a bit older), a CR-10S or some other more or less modern printers or controllers, they come with a bootloader installed already, so don&#039;t bother flashing one. The one that&#039;s in there already, should work well. So if you have one of these, just skip this and jump to the [[Roy&#039;s_notes#Flashing_the_printer|next section]].&lt;br /&gt;
&lt;br /&gt;
However, the normal CR-10 (without the S), Ender 3 and a few other printers from Creality come without a bootloader, so you&#039;ll need to flash one before upgrading the firmware. Well, strictly speakning, you don&#039;t need one, you can save those 8kB or so for other stuff and use a programmer to write the whole firmware, but then you&#039;ll need to wire up everything every time you want a new firmware, so in my world, you &#039;&#039;&#039;do&#039;&#039;&#039; need the bootloader, since it&#039;s easier.&lt;br /&gt;
&lt;br /&gt;
To install a bootloader, you&#039;ll need a programmer, and I didn&#039;t have one available. Having some el-cheapo china-copies of Ardinos around, I read I could use one and tried so. Although the docs mostly mention the Uno etc, it&#039;s just as simple with the Nano copy.&lt;br /&gt;
&lt;br /&gt;
So, grab an arduino, plug it to your machine with a USB cable, and, using the Arduino IDE, use the ArduinoISP sketch there (found under Examples) to burn the software needed for the arduino to work as a programmer. When this is done, connect a 10µF capacitor between RST and GND to stop it from resetting when used as a programmer. Connect the MOSI, MISO and SCK pins from the ICSP block (that little isolated 6-pin block on top of the ardu). See [https://www.arduino.cc/en/Tutorial/ArduinoISP here] for a pinout. Then find Vcc and GND either on the ICSP block or elsewhere. Some sites say that on some boards you shouldn&#039;t use the pins on the ICSP block for this. I doubt it matters, though. Then connect another jumper wire from pin 10 on the ardu to work as the reset pin outwards to the chip being programmed (that is, on the printer). The ICSP jumper block pin layout is the same on the printer and on the ardu, and probably elsewhere. Sometimes [https://xkcd.com/927/ standardisation] actually works…&lt;br /&gt;
&lt;br /&gt;
See https://cloud.karlsbakk.net/index.php/s/zw48YJjzaf8Rc2F for a pic with the ardu (this wiki is broken atm, will fix it later)&lt;br /&gt;
&lt;br /&gt;
== Flashing the printer ==&lt;br /&gt;
&lt;br /&gt;
When the boot loader is in place, possibly after some wierd errors from during the process, the screen on the 3d printer will go blank and it&#039;ll behave like being bricked. This is ok. Now disconnect the wires and connect the USB cable between computer and printer. If you haven&#039;t installed support for the Sanguino board, that is, the variant of the 1284-chip and surrounding electronics that is the core of the, you need to install it first. In the Arduino IDE, choose the Tools / Boards / Boards manager boot option and search for Sanguino. After this, you should find the Sanguino or Sanguino 1284p in the boards menu. After this, you should be able to communicate with the printer&#039;s controller. Download the [https://www.th3dstudio.com/knowledgebase/th3d-unified-firmware-package/ TH3D unified firmware], making sure it&#039;s the last version. Uncompress the zip and with Finder/Explorer/whateversomething&#039;scalledonlinux, browse to &#039;&#039;&#039;TH3DUF_R2/Firmware/TH3DUF_R2.ino&#039;&#039;&#039; and open it. It should open directly in the Android IDE. Keep in mind that the names TH3DUF_R2 and TH3DUF_R2.ino will vary between versions, but you get the point. Now configure it for your particular needs. You&#039;ll find most of this in the Configuration.h tab (that&#039;s really a file). Most of the other files won&#039;t be necessary unless you&#039;re doing some more advanced stuff, like replacing th controller with something non-standard or similar, but then again, that&#039;s another chapter (or book, even). The video mentioned above describes this well. After flashing the new firmware, you&#039;ll probably get some timeouts and errors, since apparently it resets the printer after giving it the new firmware, but without notifying the flashing software of it doing so. If this happens, calm down and reboot the printer and check its tiny monitor - it should work. If it doesn&#039;t work, and if you flashed the bootload yourself, try to flash it again, and if that doesn&#039;t work, try flashing the programmer again yet another time, just for kicks. Again, if you have a newer controller like the v1.1.5, don&#039;t touch the bootloader, as the one already installed, should work well as it is.&lt;br /&gt;
&lt;br /&gt;
PS: I tried enabling &#039;&#039;&#039;MANUAL_MESH_LEVELING&#039;&#039;&#039;, which in the code says that &#039;&#039;If used with a 1284P board the bootscreen will be disabled to save space&#039;&#039;. This effectively disabled the whole printer, and apparently may be making the firmware image a wee bit too large for it to fit the 1284P on the ender. It works well without it, though, and it may be fixed by now, since I tested this back in early 2019.&lt;br /&gt;
&lt;br /&gt;
== And then… ==&lt;br /&gt;
&lt;br /&gt;
With the new firmware in place, the printer should work as before, although with thermal runaway protection to better avoid fires in case the shit hits the fan, and to allow for things like autolevelling. With any luck, [https://www.precisionpiezo.co.uk/ this thing] may be ready for use by the time you read this - it surely looks nice!&lt;br /&gt;
&lt;br /&gt;
roy&lt;/div&gt;</summary>
		<author><name>Roy</name></author>
	</entry>
	<entry>
		<id>https://wiki.malinux.no/index.php?title=Roy%27s_notes&amp;diff=161</id>
		<title>Roy&#039;s notes</title>
		<link rel="alternate" type="text/html" href="https://wiki.malinux.no/index.php?title=Roy%27s_notes&amp;diff=161"/>
		<updated>2020-05-22T01:57:39Z</updated>

		<summary type="html">&lt;p&gt;Roy: /* Using an arduino Nano as a programmer */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= LVM, md and friends =&lt;br /&gt;
&lt;br /&gt;
== Linux&#039; Logical Volume Manager (LVM) ==&lt;br /&gt;
&lt;br /&gt;
=== LVM in general ===&lt;br /&gt;
&lt;br /&gt;
LVM is designed to be an abstraction layer on top of physical drives or RAID, typically [https://raid.wiki.kernel.org/index.php/RAID_setup mdraid] or [https://help.ubuntu.com/community/FakeRaidHowto fakeraid]. Keep in mind that fakeraid should be avoided unless you really need it, like in conjunction with dual-booting linux and windows on fakeraid. LVM broadly consists of three elements, the &amp;quot;physical&amp;quot; devices (PV), the volume group (VG) and the logical volume (LV). There can be multiple PVs, VGs and LVs, depending on requirement. More about this below. All commands are given as examples, and all of them can be fine-tuned using extra flags in need of so. In my experience, the defaults work well for most usecases.&lt;br /&gt;
&lt;br /&gt;
I&#039;m mentioning filesystem below too. Where I write ext4, the samme applies to ext2 and ext3.&lt;br /&gt;
&lt;br /&gt;
==== Create a PV ====&lt;br /&gt;
&lt;br /&gt;
A PV is the &amp;quot;physical&amp;quot; parts. This does not need to be a physical disk, but can also be another RAID, be it an mdraid, fakeraid, hardware raid, a virtual disk on a SAN or otherwisee or a partition on one of those. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#  These add three PVs, one on a drive (or hardware raid) and another two on mdraids.&lt;br /&gt;
pvcreate /dev/sdb&lt;br /&gt;
pvcreate /dev/md1 /dev/md2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For more information about pvcreate, see [https://linux.die.net/man/8/pvcreate the manual].&lt;br /&gt;
&lt;br /&gt;
==== Create a VG ====&lt;br /&gt;
&lt;br /&gt;
The volume group consists of one or more PVs grouped together on which LVs can be placed. If several PVs are grouped in a VG, it&#039;s generally a good idea to make sure these PVs have some sort of redundancy, as in mdraid/fakeraid or hwraid. Otherwise it will be like using a [https://en.wikipedia.org/wiki/RAID RAID-0] with a single point of failure on each of the independant drives. LVM has [https://unix.stackexchange.com/questions/150644/raiding-with-lvm-vs-mdraid-pros-and-cons  RAID code in it] as well, so you can use that. I haven&#039;t done so myself, as I generally stick to mraid. The reason is mdraid is, in my opinion older and more stable and has more users (meaning bugs are reported and fixed faster whenever they are found). That said, I beleive the actual RAID code used in LVM RAID are the same function calls as for mdraid, so it may not be much of a difference. I still stick with mdraid. To create a VG, run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create volume group my_vg&lt;br /&gt;
vgcreate my_vg /dev/md1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that if vgcreate is run with a PV (as /dev/md1 above) that is not defined as a PV (like above), this is done implicitly, so if you don&#039;t need any special flags to pvcreate, you can simply skip it and let vgcreate do that for you.&lt;br /&gt;
&lt;br /&gt;
==== Create an LV ====&lt;br /&gt;
&lt;br /&gt;
LVs can be compared to partitions, somehow, since they are bounderies of a fraction or all of that of a VG. The difference between them and a partition, however, is that they can be grown or shrunk easily and also moved around between PVs without downtime. This flexibility makes them superiour to partitions as your system can be changed without users noticing it. By default, an LV is alloated &amp;quot;thickly&amp;quot;, meaning all the data given to it, is allocated from the VG and thus the PV. The following makes a 100GB LV named &amp;quot;thicklv&amp;quot;. When making an LV, I usually allocate what&#039;s needed plus some more, but not everything, just to make sure it&#039;s space available for growth on any of the LVs on the VG, or new LVs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a thick provisioned LV named thicklv on the VG my_vg&lt;br /&gt;
lvcreate -n thicklv -L 100G my_vg&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After the LV is created, a filesystem can be placed on it unless it is meant to be used directly. The application for direct use include swap space, VM storage and certain database systems. Most of these will, however, work on filesystems too, although my testing has shown that on swap space, there is a significant performance gain for using dedicated storage without a filesystem. As for filesystems, most Linux users use either ext4 or xfs. Personally, I generally use XFS these days. See my notes below on filesystem choice.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a filesystem on the LV - this could have been mkfs -t ext4 or whatever filesystem you choose&lt;br /&gt;
mkfs -t xfs /dev/my_vg/thicklv&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then just edit /etc/fstab with correct data and run mount -a, and you should be all set.&lt;br /&gt;
&lt;br /&gt;
==== Create LVM cache ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
lvcreate -L 1G -n _cache_meta data /dev/md1&lt;br /&gt;
&lt;br /&gt;
lvcreate -l100%FREE -n _cache data /dev/md1&lt;br /&gt;
&lt;br /&gt;
# Some would want --cachemode writeback, but seriously, I wouldn&#039;t recommend it. Metadata or data can be easily corrupted in case of failure.&lt;br /&gt;
lvconvert --type cache-pool --cachemode writethrough --poolmetadata data/_cache_meta data/_cache&lt;br /&gt;
&lt;br /&gt;
lvconvert --type cache --cachepool data/_cache data/data&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Disabling LVM cache ====&lt;br /&gt;
&lt;br /&gt;
If you for some reason want to disable caching, this will do it cleanly and remove the LVs earlier created for caching the main device.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
lvconvert --uncache data/data&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Growing devices ====&lt;br /&gt;
&lt;br /&gt;
LVM objects can be grown and shrunk. If a PV resides on a RAID where a new drive has been added or otherwise grown, or on a partition or virtual disk that has been extended, the PV must be updated to reflect these changes. The following command will grow the PV to the maximum available on the underlying storage. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Resize the PV /dev/md (not the RAID, only the PV on the RAID) to its full size&lt;br /&gt;
pvresize /dev/md1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If a new PV is added, the VG can be grown to add the space on that in addition to what&#039;s there already. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Extend my_vg to include md2 and its space&lt;br /&gt;
vgextend my_vg /dev/md2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
With more space available in the VG, the LV can now be extended. Let&#039;s add another 50GB to it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Extend thicklv - add 50GB. If you know you won&#039;t need the space anywhere else, you may want to&lt;br /&gt;
# lvresize -l+100%FREE instead. Keep in mind the difference between -l (extents) and -L (bytes)&lt;br /&gt;
lvresize -L +50G my_vg/thicklv&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Growing filesystems ====&lt;br /&gt;
After the LV has grown, run &#039;&#039;xfs_growfs&#039;&#039; (xfs) or &#039;&#039;resize2fs&#039;&#039; (ext4) to make use of the new data. To grow the filesystem to all available space on ext4, run the below command.  To partly grow the filesystem or to shrink it or otherwise, please see the manuals.&lt;br /&gt;
&lt;br /&gt;
The filesystem can be mounted when this is run. If you for some reason get an &#039;&#039;&#039;access denied&#039;&#039;&#039; error when running this as root or with sudo, it&#039;s likely caused by a filesystem error. To fix this, unmount the filesystem first and run &#039;&#039;&#039;fsck -f /dev/my_vg/thicklv&#039;&#039;&#039; and remount it before retrying to extend it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
resize2fs /dev/my_vg/thicklv&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Similarly, with XFS, but note that xfs_growfs doesn&#039;t take the device name, but the filesystem&#039;s mount point. In the case of XFS, also note that the filesystem &#039;&#039;&#039;&#039;&#039;must&#039;&#039;&#039;&#039;&#039; be mounted to be grown. This, in contrast to how it was in the old days when filesystems had to be unmounted to be grown.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
xfs_growfs /my_mountpoint&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Rename system VG ====&lt;br /&gt;
&lt;br /&gt;
Some distros create VG names like those-from-a-sysadmin-with-a-well-developed-paranoia-not-to-hit-a-duplicate. Debian, for instance, uses names like &amp;quot;my-full-hostname-vg&amp;quot;. Personally, I don&#039;t like these, since if I were to move a disk or vdisk around to somewhere else, I&#039;d make sure not to add a disk named &#039;sys&#039; to an existing system. If you do, most distros will refuse to use the VGs with duplicate names, resulting in the OS not booting until either one is specified by its UUID or just one removed. As I&#039;m aware of this, I stick to the super-risky thing of all system VGs named &#039;sys&#039; and so on.&lt;br /&gt;
&lt;br /&gt;
If you do this, keep in mind that it may blow up your computer and take your girl- or boyfriend with it or even make either of them pregnant, allowing Trump to rule your life and generally make things suck. You&#039;re on your own!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Rename the VG&lt;br /&gt;
vgrename my-full-hostname-vg sys&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, in /boot/grub/grub.cfg, change the old lv path from something like &#039;/dev/mapper/debian--stretch--machine--vg-root&#039; to your new and fancy &#039;/dev/sys/root. Likewise, in /etc/fstab, change occurences of &#039;/dev/mapper/debian--stretch--machine--vg-&#039; (or similar) with &#039;/dev/sys/&#039;. Here, this was like this - the old ones commented out.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;fstab&amp;quot;&amp;gt;&lt;br /&gt;
#/dev/mapper/debian--stretch--box--vg-root      /               ext4            errors=remount-ro,discard       0       1&lt;br /&gt;
/dev/sys/root                                   /               ext4            errors=remount-ro,discard       0       1&lt;br /&gt;
# /boot was on /dev/vda1 during installation&lt;br /&gt;
UUID=myverylonguuidwithatonofgoodinfoinit       /boot           ext2            defaults                        0       2&lt;br /&gt;
#/dev/mapper/debian--stretch--box--vg-swap_1    none            swap            sw                              0       0&lt;br /&gt;
/dev/sys/swap_1                                 none            swap            sw                              0       0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Update /etc/initramfs-tools/conf.d/resume with similar data for swap.&lt;br /&gt;
&lt;br /&gt;
You might want to run &#039;update-initramfs -u -k all&#039; after this, but I&#039;m not sure if it&#039;s needed.&lt;br /&gt;
&lt;br /&gt;
Now, pray to the nearest god(s) and give it a reboot and it should (probably) work.&lt;br /&gt;
&lt;br /&gt;
After reboot, run &#039;&#039;&#039;swapoff -a&#039;&#039;&#039;, then &#039;&#039;&#039;mkswap /dev/sys/swap_1&#039;&#039;&#039; (or whatever it&#039;s called on your system) and &#039;&#039;&#039;swapon -a&#039;&#039;&#039; again. You may want to give it another reboot or two for kicks, but it should work well even without that.&lt;br /&gt;
&lt;br /&gt;
=== Migration tools ===&lt;br /&gt;
&lt;br /&gt;
At times, storage regimes change, new storage is added and sometimes it&#039;s not easy to migrate with the current hardware or its support systems. Once I had to migrate a 45TiB fileserver from one storage system to another, preferably without downtime. The server originally had three 15TiB PVs of which two were full and the third half full. I resorted to using [https://linux.die.net/man/8/pvmove pvmove] to just move the data on the PVs in use to a new PV. We started out with creating a new 50TiB PV, sde, and then to pvmove.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Attach /dev/sde to the VG my_vg&lt;br /&gt;
vgextend my_vg /dev/sde&lt;br /&gt;
&lt;br /&gt;
# Move the contents from /dev/sdb over to /dev/sde block by block. If a target is not given in pvmove,&lt;br /&gt;
# the contents of the source (sdb here) will be put somewhere else in the pool.&lt;br /&gt;
pvmove /dev/sdb /dev/sde&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This took a while (as in a week or so) - the pvmove command uses old code and logic (or at least did that when I migrated this in November 2016), but it affected performance on the server very little, so users didn&#039;t notice. After the first PV was migrated, I continued with the other two, one after the other, and after a month or so, it was migrated. We used this on a number of large fileservers, and it worked flawlessly. Before doing the production servers I also tried interrupting pvmove in various ways, including hard resets, and it just kept on after the reboot.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;NOTE:&#039;&#039;&#039;&#039;&#039; &#039;&#039;Even though it worked well for us, &#039;&#039;&#039;always&#039;&#039;&#039; keep a good backup before doing this. Things may go wrong, and without a good backup, you may be looking for a hard-to-find new job the next morning&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
==== mdadm workarounds ====&lt;br /&gt;
&lt;br /&gt;
===== Migrate from a mirror (raid-1) to raid-10 =====&lt;br /&gt;
&lt;br /&gt;
Create a mirror&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sdb /dev/sdc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
LVM (pv/vg/lv) on md0 (see above), put a filesystem on the lv and fill it with some data.&lt;br /&gt;
&lt;br /&gt;
Now, some months later, you want to change this to raid-10 to allow for the same amount of redundancy, but to allow more disks into the system.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mdadm --grow /dev/md0 --level=10&lt;br /&gt;
mdadm: Impossibly level change request for RAID1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So - no - doesn&#039;t work. But - we&#039;re on &lt;br /&gt;
&lt;br /&gt;
Since we&#039;re on lvm already, this&#039;ll be easy. If you&#039;re using filesystems directly on partitions, you can do this the same way, but without the pvmove part, using rsync or whateever you like instead. I&#039;d recommend using lvm for for the new raid, which should be rather obvious from this article. Now plug in a new drive and create a new raid10 on that one. If you two new drives, install both. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# change &amp;quot;missing&amp;quot; to the other device name if you installed two new drives&lt;br /&gt;
mdadm --create /dev/md1 --level=10 --raid-devices=2 /dev/vdd missing&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, as described above, just vgextend the vg, adding the new raid and run pvmove to move the data from the old pv (residing on the old raid1) to the new pv (on raid10). Afte rpvmove is finished (which may take awile, see above), just&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
vgreduce raidtest /dev/md0&lt;br /&gt;
pvremove /dev/md0&lt;br /&gt;
mdadm --stop /dev/md0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
…and your disk is free to be added to the new array. If the new raid is running in degraded mode (if you created it with just one drive), better don&#039;t wait too long, since you don&#039;t have redundancy. Just mdadm --add the devs.&lt;br /&gt;
&lt;br /&gt;
If you now have /dev/mdstat telling you your raid10 is active and have three drives, of which one is a spare, it should look something like this&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5] [raid4] [raid10]&lt;br /&gt;
md1 : active raid10 vdc[3](S) vdb[2] vdd[0]&lt;br /&gt;
      8380416 blocks super 1.2 2 near-copies [2/2] [UU]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Just mdadm --grow --raid-devices=3 /dev/md1&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;RAID section is not complete. I&#039;ll write more on migraing from raid10 to raid6 later. It&#039;s not straight forward, but easier than this one :)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== Thin provisioned LVs ===&lt;br /&gt;
&lt;br /&gt;
Thin provisioning on LVM is a method used for not allocating all the space given to an LV. For instance, if you have a 1TB VG and want to give an LV 500GB, although it currently only uses a fraction of that, a thin lv can be a good alternative. This will allow for adding a limit to how much it can use, but also to let it grow dynamically without manual work by the sysadmin. Thin provisioning adds another layer of abstaction by creating a special LV as a &#039;&#039;thin pool&#039;&#039; from which data is allocated to the &#039;&#039;thin volume(s)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== Create a thin pool ====&lt;br /&gt;
&lt;br /&gt;
Allocate 1TB to the thin pool to be used for thinly provisioned LVs. Keep in mind that the space allocated to the thin pool is in fact thick provisioned. Only the volumes put on &#039;&#039;thinpool&#039;&#039; are thin provisioned. This will create two hidden LVs, one for data and one for metadata. Normally the defaults will do, but check the manual if the data doesn&#039;t match the usual patterns (such as billions of files, resulting in huge amounts of metadata). I &#039;&#039;beleive&#039;&#039; the metadata part should be resizable at a later time if needed, but I have not tested it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a pool for thin LVs. Keep in mind that the pool itself is not thin provisioned, only the volumes residing on it&lt;br /&gt;
lvcreate --size 1T --type thin-pool --thinpool thinpool my_vg&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Create a thin volume ====&lt;br /&gt;
&lt;br /&gt;
You have the thinpool, now put a thin volume on it. It will allocate some space for metadata, but probably not much (a few megs, perhaps).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Now, create a volume with a virtual (-V) size of half a terabyte named thin_pool, but using the thinpool (-T) named thin_pool for storage&lt;br /&gt;
lvcreate -V 500G -T my_vg/thin_pool --name thinvol&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The new volume&#039;s device name will be /dev/thinvol. Now, create a filesystem on it, add to fstab and mount it. The &#039;&#039;&#039;df&#039;&#039;&#039; command will return available space according to the virtual size (-V), while lvs will show how much data is actually used on each of the thinly provisioned volumes.&lt;br /&gt;
&lt;br /&gt;
== Filesystem dilemmas ==&lt;br /&gt;
&lt;br /&gt;
=== XFS or ext4 or something else ===&lt;br /&gt;
The choice of filesystem varies for your use. Distros such as RHEL/CentOS has moved to XFS by default from v7. Debian/Ubuntu still sticks to ext4, like most other. I&#039;ll discuss my thoughts below on ext4 vs XFS and leave the other filesystems for later.&lt;br /&gt;
&lt;br /&gt;
==== ext4 ====&lt;br /&gt;
ext4 is probably the most used filesystem on linux as of writing. It&#039;s rock stable and has been extended by a lot of extensions since the original ext2. It still retains backward compatibility, being able to mount and fsck ext2 and ext3 with the ext4 driver. However, it doesn&#039;t handle large filesystems very well. If a filesystem is created for &amp;lt;16TiB, it cannot be grown to anything larger than 16TiB. This may have changed lately, though. One other issue is handling errors. If a large filesystem (say 10TiB) is damaged, an fsck may take several hours, leading to long downtime. When I refer to ext4 further in this text, the same applies to ext2 and ext3 unless otherwise specified.&lt;br /&gt;
&lt;br /&gt;
==== XFS ====&lt;br /&gt;
XFS, originally developed by SGI some time in the bronze age, but has been worked on heavily after that. RHEL and Centos version 7 and forward, uses XFS as the default filesystem. It is quick, it scales well, but it lacks at least two things ext4 has. It cannot be shrunk (not that you normally need that, but nice if you have a typo or you need to change things). Also, it doesn&#039;t allow for automatic fsck on bootup. If something is messed up on the filesystem, you&#039;ll have to login as root on the console (not ssh), which might be an issue on some systems. The fsck equivalent, xfs_repair, is a *lot* faster than ext4&#039;s fsck, though.&lt;br /&gt;
&lt;br /&gt;
==== ZFS ====&lt;br /&gt;
ZFS is like a combination of RAID, LVM and a filesystem, supporting full checksumming, auto-healing (given sufficient redundancy), compression, encryption, replication, deduplication (if you&#039;re brave and have a &#039;&#039;ton&#039;&#039; of memory) and a lot more. It&#039;s a separate chapter and needs a lot more talk than paragraph here.&lt;br /&gt;
&lt;br /&gt;
==== btrfs ====&lt;br /&gt;
btrfs, pronounced &amp;quot;butterfs&amp;quot; or &amp;quot;betterfs&amp;quot; or just spelled out, is a filesystem that mimics that of ZFS. It has been around for 10 years or so, but hasn&#039;t yet proven to be really stable. Following the progress of it for those years, I&#039;ve found it to be a nice toy with which to play, but not to be used in production. Again, others may say otherwise, but these are just my words.&lt;br /&gt;
&lt;br /&gt;
== Low level disk handling ==&lt;br /&gt;
&lt;br /&gt;
This section is for low-level handling of disks, regardless of storage system elsewhere. These apply to mdraid, lvmraid and zfs and possibly other solutions, with the exception of individual drives on hwraid (and maybe fakeraid), since there, the drives are hidden from Linux (or whatever OS).&lt;br /&gt;
&lt;br /&gt;
=== S.M.A.R.T. and slow drives ===&lt;br /&gt;
Modern (that is, from about 1990 or later) have S.M.A.R.T. (or just smart, since it&#039;s easier to type) monitoring built in, meaning the disk&#039;s controller is monitoring itself. This is handy and will ideally tell you in advance that a drive is flakey or dying. Modern (2010+) smart monitoring is more or less the same. It can be trusted about 50% of the time. Usually, if smart detects an error, it&#039;s a real error. I don&#039;t think I&#039;ve seen it reporting a false positive, but others may know better. &lt;br /&gt;
&lt;br /&gt;
==== smartmontools ====&lt;br /&gt;
First, install smartmontool and run smartclt -H /dev/yourdisk (/dev/sda or something) to get a health report. Then perhaps run smartctl -a /dev/yourdisk and look for &#039;current pending sectors&#039; This should be zero. Also check the temperature, which normally should be much above 50.&lt;br /&gt;
&lt;br /&gt;
==== single, slow drive ====&lt;br /&gt;
What may happen, is smart not seeing anything and life goes on like before, only slower and less prouductive, without telling anyone. If you stubler over this issue, you&#039;ll probably see it during a large rsync/zfs send/receive or a resync/rebuild/resilver of the raid/zpool. During this, it feels like everything is slow and your RAID has turned into a RAIF (redundant array of inexpensive floppies). To check if you have a single drive messing up it all, check with &#039;&#039;&#039;iostat -x 2&#039;&#039;&#039;, having 2 being the delay between each measurement. Interrupt it with ctrl+x. If there&#039;s a rougue drive there, it should stand out like sdg below&lt;br /&gt;
&lt;br /&gt;
 avg-cpu:  %user   %nice %system %iowait  %steal   %idle&lt;br /&gt;
            0.38    0.00    1.75    0.00    0.00   97.87&lt;br /&gt;
&lt;br /&gt;
 Device            r/s     w/s     rkB/s     wkB/s   rrqm/s   wrqm/s  %rrqm  %wrqm r_await w_await aqu-sz rareq-sz wareq-sz  svctm  %util&lt;br /&gt;
 sda              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdb              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdc              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdd              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sde              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdf              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdg              3.50    0.00   2352.00      0.00     0.00     0.00   0.00   0.00 14306.29    0.00  13.85   672.00     0.00 285.71 100.00&lt;br /&gt;
 sdh              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
&lt;br /&gt;
In ZFS land, you should be able to get similar data with &#039;&#039;&#039;zpool iostat -v &amp;lt;pool&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Now you know the bad drive (sdg), pull it from the raid with &#039;&#039;&#039;mdadm --fail /dev/mdX /dev/sdX&#039;&#039;&#039;. Now test the drive&#039;s performance manually, just simply:&lt;br /&gt;
&lt;br /&gt;
 # hdparm -t /dev/sdg&lt;br /&gt;
 &lt;br /&gt;
 /dev/sdg:&lt;br /&gt;
  Timing buffered disk reads:   2 MB in  5.37 seconds = 381.46 kB/sec&lt;br /&gt;
&lt;br /&gt;
Bingo - nothing you&#039;d want to keep. For a good drive, it should be something like 100-200MB/s&lt;br /&gt;
&lt;br /&gt;
PS: Keep in mind that you have a degraded RAID by now in case you had a spare waiting for things to happen.&lt;br /&gt;
&lt;br /&gt;
Try to replace the cable and/or try the disk on another port/controller. If the result from hdparm persists, it&#039;s probably a bad cable&lt;br /&gt;
&lt;br /&gt;
So, then, just psycially locate the drive, pull it out, take out the discs and magnets and recycle the rest.&lt;br /&gt;
&lt;br /&gt;
=== &amp;quot;Unplug&amp;quot; drive from system ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Find the device unit&#039;s number with something like&lt;br /&gt;
find /sys/bus/scsi/devices/*/block/ -name sdd&lt;br /&gt;
# returning /sys/bus/scsi/devices/3:0:0:0/block/sdd here, &lt;br /&gt;
# meaning 3:0:0:0 is the SCSI device we&#039;re looking for.&lt;br /&gt;
&lt;br /&gt;
# Given this is the correct device, and you want to &#039;unplug&#039; it, do so by&lt;br /&gt;
echo 1 &amp;gt; /sys/bus/scsi/devices/3:0:0:0/delete&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Rescan disk controllers ===&lt;br /&gt;
If a drive is added and for some reason doesn&#039;t get detected, or is removed by the command above, it can be rediscovered with a sysfs command to the scsi host to which it is connected. Since there may be quite a few of these, an easy way is to just scan them all and check the output of &#039;&#039;&#039;dmesg -T&#039;&#039;&#039; after running it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Make a list of controllers and send a rescan message to each of them. It won&#039;t do anything &lt;br /&gt;
# for those where nothing has changed, but it will show new drives where they have been added.&lt;br /&gt;
for host_scan in /sys/class/scsi_host/host*/scan&lt;br /&gt;
do&lt;br /&gt;
  echo &#039;- - -&#039; &amp;gt; $host_scan&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Fail injection with debugfs ===&lt;br /&gt;
[https://lxadm.com/Using_fault_injection https://lxadm.com/Using_fault_injection]&lt;br /&gt;
&lt;br /&gt;
== mdadm stuff ==&lt;br /&gt;
=== Resync ===&lt;br /&gt;
To resync a raid, that is, check, run&lt;br /&gt;
&lt;br /&gt;
 echo check &amp;gt; /sys/block/$dev/md/sync_action&lt;br /&gt;
&lt;br /&gt;
where $dev is something like md0. If you have several raids, something like this should work&lt;br /&gt;
&lt;br /&gt;
 for dev in md{0,1}&lt;br /&gt;
 do&lt;br /&gt;
   echo repair &amp;gt; /sys/block/$dev/md/sync_action&lt;br /&gt;
 done&lt;br /&gt;
&lt;br /&gt;
Also useful in a one-liner like&lt;br /&gt;
&lt;br /&gt;
 for dev in md{0,1} ; do echo repair &amp;gt; /sys/block/$dev/md/sync_action ; done&lt;br /&gt;
&lt;br /&gt;
Different raids on different drives will do this in parallel. If the drives are shared somehow with partitions or similar, the check or repair will wait for the other to finish before going on.&lt;br /&gt;
&lt;br /&gt;
As for repair vs check, [https://raid.wiki.kernel.org/index.php/RAID_Administration this article] describes it well. I stick to using repair unless it&#039;s something rare where I don&#039;t want to touch the data.&lt;br /&gt;
&lt;br /&gt;
=== Spare pools ===&lt;br /&gt;
In the old itmes, mdadm supported only a dedicated spare per md device, so if working with a large set of drives (20? 40?), where you&#039;d want to setup more raid sets to increase redundancy, you&#039;d dedicate a spare to each of the raid sets. This has changed (some time ago?), so in these modern, heathen days, you can change mdadm.conf, usually placed under /etc/mdadm, and add &#039;spare-group=somegroup&#039; where &#039;somegroup&#039; is a string identifying the spare group. After doing this, run &#039;&#039;&#039;update-initramfs -u&#039;&#039;&#039; and reboot and add a spare to one of the raid sets in the spare group, and md will use that or those spares for all the raidsets in that group.&lt;br /&gt;
&lt;br /&gt;
As some pointed out on #linux-raid @ irc.freenode.net, this feature is very badly documented, but as far as I can see, it works well.&lt;br /&gt;
&lt;br /&gt;
==== Example config ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create two raidsets&lt;br /&gt;
&lt;br /&gt;
mdadm --create /dev/md1 --level=6 --raid-devices=6 /dev/vd[efghij]&lt;br /&gt;
mdadm --create /dev/md2 --level=6 --raid-devices=6 /dev/vd[klmnop]&lt;br /&gt;
&lt;br /&gt;
# get their UUID etc&lt;br /&gt;
&lt;br /&gt;
mdadm --detail --scan&lt;br /&gt;
ARRAY /dev/md/1 metadata=1.2 name=raidtest:1 UUID=1a8cbdcb:f4092350:348b6b80:c054d74c&lt;br /&gt;
ARRAY /dev/md/2 metadata=1.2 name=raidtest:2 UUID=894b1b7c:cb7eba70:917d6033:ea5afd2b&lt;br /&gt;
&lt;br /&gt;
# Put those lines into /etc/mdadm/mdadm.conf and and add the spare-group&lt;br /&gt;
&lt;br /&gt;
ARRAY /dev/md/1 metadata=1.2 name=raidtest:1 spare-group=raidtest UUID=1a8cbdcb:f4092350:348b6b80:c054d74c&lt;br /&gt;
ARRAY /dev/md/2 metadata=1.2 name=raidtest:2 spare-group=raidtest UUID=894b1b7c:cb7eba70:917d6033:ea5afd2b&lt;br /&gt;
&lt;br /&gt;
# update the initramfs and reboot&lt;br /&gt;
&lt;br /&gt;
update-initramfs -u&lt;br /&gt;
reboot&lt;br /&gt;
&lt;br /&gt;
# add a spare drive to one of the raids&lt;br /&gt;
&lt;br /&gt;
mdadm --add /dev/md1 /dev/vdq&lt;br /&gt;
&lt;br /&gt;
# fail a drive on the other raid&lt;br /&gt;
&lt;br /&gt;
mdadm --fail /dev/md2 /dev/vdn&lt;br /&gt;
&lt;br /&gt;
# check /proc/mdstat to see md2 rebuilding with the spare from md1&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Recovery ===&lt;br /&gt;
&lt;br /&gt;
The other day, I came across a problem a user had on #linux-raid@irc.freenode.net. He had an old Qnap NAS that had died and tried plugging the drives in to his Linux machine and got various errors. The two-drive RAID-1 did not come up as it should, &#039;&#039;&#039;dmesg&#039;&#039;&#039; was full of errors from one of the drives (both connected on USB) and so forth.&lt;br /&gt;
&lt;br /&gt;
We went on and started by taking down the machine and just connecting one of the drives. I had him check what was assembled with&lt;br /&gt;
&lt;br /&gt;
 cat /proc/mdstat&lt;br /&gt;
&lt;br /&gt;
That returned /proc/md127 assembled, but LVM didn&#039;t find anything. So running a manual scan&lt;br /&gt;
&lt;br /&gt;
 pvscan --cache /dev/md127&lt;br /&gt;
&lt;br /&gt;
This made linux find the PV, VG and a couple of LVs, but probably because the mdraid was degraded, the LVs were deactivated, according to &#039;&#039;&#039;lvscan&#039;&#039;&#039;. Activating the one with a filesystem manually&lt;br /&gt;
&lt;br /&gt;
 lvchange -a y /dev/&amp;lt;vg&amp;gt;/&amp;lt;lv&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Substitute &amp;lt;vg&amp;gt; and &amp;lt;lv&amp;gt; with the names listed by vgs and lvs.&lt;br /&gt;
&lt;br /&gt;
This worked, and the filesystem on /dev/&amp;lt;vg&amp;gt;/&amp;lt;lv&amp;gt; could be mounted correctly.&lt;br /&gt;
&lt;br /&gt;
== Tuning ==&lt;br /&gt;
&lt;br /&gt;
While trying to compare a 12-disk RAID (8TB disks) to a hwraid, mdraid was slower, so we did a few things to speed things up:&lt;br /&gt;
&lt;br /&gt;
While testing with [https://linux.die.net/man/1/fio fio], monitor /sys/block/md0/md/stripe_cache_active, and see if it&#039;s close to /sys/block/md0/md/stripe_cache_size. If it is, double the size of the latter&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
echo 4096 &amp;gt; /sys/block/md0/md/stripe_cache_size&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Continue until stripe_cache_active stabilises, and then you&#039;ve found the limit you&#039;ll need. You may want to double that for good measure. &lt;br /&gt;
&lt;br /&gt;
(to be continued)&lt;br /&gt;
&lt;br /&gt;
== Links ==&lt;br /&gt;
&lt;br /&gt;
Below are a few links with useful info&lt;br /&gt;
&lt;br /&gt;
* [https://raid.wiki.kernel.org/index.php/Irreversible_mdadm_failure_recovery Irreversible mdadm failure recovery]&lt;br /&gt;
&lt;br /&gt;
= ZFS =&lt;br /&gt;
&lt;br /&gt;
ZFS can do a lot of things most filesystems or volume managers can&#039;t. It checksums all data and metadata and so long that the system uses ECC enabled memory (RAM), it will have complete control over the whole data set, and when (not if) an error occurs, it&#039;ll fix the issue without even throwing a warning. To fix the issue, you&#039;ll obviously need sufficient redundancy (mirrors or RAIDzN). &lt;br /&gt;
&lt;br /&gt;
== ZFS send/receive between machines ==&lt;br /&gt;
&lt;br /&gt;
ZFS has a send/receive mechanism that allows for snapshots to be sent over the wire to a receiving end. This can be a full filesystem, or an incremental change since last send/reveive. In a WAN scenario, you&#039;ll probably want to use VPN for this. On a controlled network, sending in cleartext is also possible. You may as well use ssh, but keep in mind that ssh was never designed to be used as a fullblown vpn solution and is just too slow or the task with large amounts of data. You may, though, use mbuffer, if on a loal LAN.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Allow traffic from the sending IP in whatever firewall interface you&#039;re using (if you&#039;re using a firewall at all, that is)&lt;br /&gt;
ufw allow from x.x.x.x&lt;br /&gt;
# &lt;br /&gt;
# Start the receiver first. This listens on port 9090, has a 1GB buffer,&lt;br /&gt;
    and uses 128kb chunks (same as zfs):&lt;br /&gt;
&lt;br /&gt;
mbuffer -s 128k -m 1G -I 9090 | zfs receive data/filesystem&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To be continued one day… See [https://everycity.co.uk/alasdair/2010/07/using-mbuffer-to-speed-up-slow-zfs-send-zfs-receive/ this] for some more. I&#039;ll get back with details on it.&lt;br /&gt;
&lt;br /&gt;
= General Linux system control =&lt;br /&gt;
&lt;br /&gt;
== Add a new CPU (core) ==&lt;br /&gt;
&lt;br /&gt;
If working with virtual machines, adding a new core can be useful if the VM is slow and the load is multithreaded or multiprocess. To do this, add a new CPU in the hypervisor (be it KVM or VMware or Hyper-V or whatever). Some hypervisors, like VMware, will activate it automatically if open-vm-tools is installed. Please note that open-vm-tools is for VMware only. I don&#039;t know of any such thing for KVM or other hypervisors (although I beleive VirtualBox has its own set of tools, but not as a package). If this doesn&#039;t work, run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
echo 1 &amp;gt; /sys/devices/system/cpu/cpuX/online&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where X is the CPU number you want to add. You can &#039;cat /sys/devices/system/cpu/cpuX/online&#039; to check if it&#039;s online.&lt;br /&gt;
&lt;br /&gt;
= Mount partitions on a disk image =&lt;br /&gt;
&lt;br /&gt;
Sometimes you&#039;ll have a disk image, either from recovering a bad drive after hours (or days or weeks) of ddrescue, and sometimes you just have a disk image from a virtual machine where you want to mount the partitions inside the image. There are three main methods of doing this, which are more or less synonmous, but some easier than the other.&lt;br /&gt;
&lt;br /&gt;
== Basics ==&lt;br /&gt;
&lt;br /&gt;
A disk image is usually like a disk, consisting of either a large filesystem, a PV or a partition table with one or partitions onto which resides a filesystem, a pv, swap or something else. If it&#039;s partitioned, and you want your operating system to mount a filesystem or allow it to see whatever LVM stuff lies on it, you need to isolate the partitions. &lt;br /&gt;
&lt;br /&gt;
== Manual mapping ==&lt;br /&gt;
&lt;br /&gt;
In the oldern days, this was done manually, something like this&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
root@mymachine:~# fdisk -l /dev/vda&lt;br /&gt;
Disk /dev/vda: 25 GiB, 26843545600 bytes, 52428800 sectors&lt;br /&gt;
Units: sectors of 1 * 512 = 512 bytes&lt;br /&gt;
Sector size (logical/physical): 512 bytes / 512 bytes&lt;br /&gt;
I/O size (minimum/optimal): 512 bytes / 512 bytes&lt;br /&gt;
Disklabel type: dos&lt;br /&gt;
Disk identifier: 0xc37b7ea5&lt;br /&gt;
&lt;br /&gt;
Device     Boot    Start      End  Sectors  Size Id Type&lt;br /&gt;
/dev/vda1  *        2048 50333311 50331264   24G 83 Linux&lt;br /&gt;
/dev/vda2       50333312 52426369  2093058 1022M  5 Extended&lt;br /&gt;
/dev/vda5       50333314 52426369  2093056 1022M 82 Linux swap / Solaris&lt;br /&gt;
root@mymachine:~#&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To calculate the start and end of each partition, you just take the start sector and multiply it by the sector size (512 bytes here) and you have the offset in bytes. After this, it&#039;s merely an losetup -o &amp;lt;offset&amp;gt; /dev/loopX &amp;lt;nameofimagefile&amp;gt; and you have the partition mapped to your /dev/loopX (having X being something typically 0-255. After this, just mount it or run pvscan/vgscan/lvscan to probe whatever lvm config is there, and you should be able to mount it like any other filesystem.&lt;br /&gt;
&lt;br /&gt;
== kpartx ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;kpartx&#039;&#039;&#039; does the same as above, more or less, just without so much hassle. Most of it should be automatic and easy to deal with, except it may fail to disconnect the loopback devices sometimes, so you may have to &#039;&#039;&#039;losetup -d&#039;&#039;&#039; them manually. See the manual, &#039;&#039;&#039;kpartx (8)&#039;&#039;&#039;. Please note that &#039;&#039;&#039;partx&#039;&#039;&#039; works similarly and I&#039;d guess the authors of the two tools are arguing a lot of which one&#039;s the best.&lt;br /&gt;
&lt;br /&gt;
== guestmount ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;guestmount&#039;&#039;&#039; is something similar again, but also supports file formats like &#039;&#039;&#039;qcow2&#039;&#039;&#039; and possibly other, proprietary filesystems like &#039;&#039;&#039;vmdk&#039;&#039;&#039; and &#039;&#039;&#039;vdi&#039;&#039;&#039;, but don&#039;t take my word for it - I haven&#039;t tested. Again, see the manual or just read up on the description [http://ask.xmodulo.com/mount-qcow2-disk-image-linux.html?fbclid=IwAR3snTeZvGzp9PLdX11EQhCfOpux6I93CiJ3A2pUomkkRLly9Xo4851mkTY here]. It seems rather trivial.&lt;br /&gt;
&lt;br /&gt;
= Linux on laptops =&lt;br /&gt;
&lt;br /&gt;
== Wifi with HP EliteBook 725/745 on Ubuntu ==&lt;br /&gt;
&lt;br /&gt;
The HP EliteBook 725/745 and similar are equipped with a BCM4352 wifi chip. As with a lot of other stuff from Broadcom, this lacks an open hardware description, so thus no open driver exist. The proper fix, is to replace the NIC with something with an open driver, but again, this isn&#039;t always possible, so a binary driver exists. In ubuntu, run, somehow connect the machine to the internet and run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install bcmwl-kernel-source&lt;br /&gt;
sudo modprobe wl&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you can&#039;t connect the machine to the internet, download the needed packages on another machine and put it on some usb storage. These packages should suffice:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# apt-cache depends bcmwl-kernel-source&lt;br /&gt;
bcmwl-kernel-source&lt;br /&gt;
  Depends: dkms&lt;br /&gt;
  Depends: linux-libc-dev&lt;br /&gt;
  Depends: libc6-dev&lt;br /&gt;
  Conflicts: &amp;lt;bcmwl-modaliases&amp;gt;&lt;br /&gt;
  Replaces: &amp;lt;bcmwl-modaliases&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then install manually with &#039;&#039;&#039;dpkg -i file1.deb file2.deb&#039;&#039;&#039; etc&lt;br /&gt;
&lt;br /&gt;
After this, ip/ifconfig/iwconfig shouldd see the new wifi nic, probably &#039;&#039;&#039;wlan0&#039;&#039;&#039;, but due to a [https://bugs.launchpad.net/ubuntu/+source/broadcom-sta/+bug/1343151 old, ignored bug], you won&#039;t find any wifi networks. This is because the driver from Broadcom apparently does not support interrupt remapping, commonly used on x64 machines. To turn this off, change &#039;&#039;&#039;/etc/default/grub&#039;&#039;&#039; and change the line &#039;&#039;&#039;GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;quiet splash&amp;quot;&#039;&#039;&#039;, adding intremap=off to the end before the quote: &#039;&#039;&#039;GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;quiet splash intremap=off&amp;quot;&#039;&#039;&#039;. Save the file and run &#039;&#039;&#039;sudo update-grub&#039;&#039;&#039; and reboot. After this, wifi should work well.&lt;br /&gt;
&lt;br /&gt;
== Wifi with HP Compaq Presario CQ57 on Ubuntu ==&lt;br /&gt;
&lt;br /&gt;
The HP Compaq Presario CQ57 uses the RT5390 wifi chipset. This has been supported for quite some time now, and I was quite surprised to find it not working on a laptop a friend was having. The driver loaded correctly, but Ubuntu insisted of the laptop being in &#039;&#039;&#039;flight mode&#039;&#039;&#039;. Checking &#039;&#039;&#039;rfkill&#039;&#039;&#039;, it showed me two NICs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# rfkill list all&lt;br /&gt;
0: phy0: Wireless LAN&lt;br /&gt;
	Soft blocked: no&lt;br /&gt;
	Hard blocked: yes&lt;br /&gt;
1: hp-wifi: Wireless LAN&lt;br /&gt;
	Soft blocked: yes&lt;br /&gt;
	Hard blocked: no&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Turning rfkill on and off resulted in nothing much, except some error messages in the kernel log (dmesg)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] ACPI Error: Field [B128] at bit offset/length 128/1024 exceeds size of target Buffer (160 bits) (20170831/dsopcode-235)&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]&lt;br /&gt;
                            Initialized Local Variables for Method [HWCD]:&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Local0: 00000000a34b7928 &amp;lt;Obj&amp;gt;           Integer 0000000000000000&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Local1: 00000000b0aa6865 &amp;lt;Obj&amp;gt;           Buffer(8) 46 41 49 4C 04 00 00 00&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Local5: 00000000a9811efd &amp;lt;Obj&amp;gt;           Integer 0000000000000004&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] Initialized Arguments for Method [HWCD]:  (2 arguments defined for method invocation)&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Arg0:   0000000078957d1b &amp;lt;Obj&amp;gt;           Integer 0000000000000001&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Arg1:   00000000725c9c6e &amp;lt;Obj&amp;gt;           Buffer(20) 53 45 43 55 02 00 00 00&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] ACPI Error: Method parse/execution failed \_SB.WMID.HWCD, AE_AML_BUFFER_LIMIT (20170831/psparse-550)&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] ACPI Error: Method parse/execution failed \_SB.WMID.WMAD, AE_AML_BUFFER_LIMIT (20170831/psparse-550)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After upgrading BIOS and testing different kernels, I was asked to try to unload the &#039;&#039;&#039;hp_wmi&#039;&#039;&#039; driver. I did, and things changed a bit, so I tried blacklisting it, creating the file &#039;&#039;&#039;/etc/modprobe.d/blacklist-hp_wmi.conf&#039;&#039;&#039; with the following content&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Blacklist this - it doesn&#039;t work!&lt;br /&gt;
blacklist hp_wmi&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
I gave the machine a reboot and afte that, the &#039;&#039;&#039;hp-wifi&#039;&#039;&#039; entry was gone in the rfkill output, and things works.&lt;br /&gt;
&lt;br /&gt;
= Raspberry pi =&lt;br /&gt;
&lt;br /&gt;
I couldn&#039;t quite decide if the raspberry pi should be a separate section or part of Linux, but hell, it can run more than Linux, although 99,lots% of people just uses Linux on them. This is a small list of things to know about them; things not on the front page of the manual or perhaps hidden even better.&lt;br /&gt;
&lt;br /&gt;
== Which pi? ==&lt;br /&gt;
&lt;br /&gt;
I just setup three raspberry pi machines and although some are quite different, like v1 to vEverythingelse or the Pi zero versions to the normal ones, not all of us remember how to distinguish between them, and sometimes they&#039;re in a nice 3d printed (or otherwise) chassis or otherwise hidden. So, how to check three different ones:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
root@home-assistant:~ $ cat /proc/device-tree/model ; echo&lt;br /&gt;
Raspberry Pi 2 Model B Rev 1.1&lt;br /&gt;
&lt;br /&gt;
root@green-pi:~ $ cat /proc/device-tree/model ; echo&lt;br /&gt;
Raspberry Pi 3 Model B Rev 1.2&lt;br /&gt;
&lt;br /&gt;
roy@yellow-pi:~ $cat /proc/device-tree/model ; echo&lt;br /&gt;
Raspberry Pi 4 Model B Rev 1.1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
While this works well, for the latter, the pi4, it doesn&#039;t tell how much memory I have. It comes in variants of 1, 2 and 4GB, and this is the latter.&lt;br /&gt;
&lt;br /&gt;
== Monitoring ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;vcgencmd&#039;&#039;&#039; from &#039;&#039;&#039;/opt/vc/bin&#039;&#039;&#039;, but symlinked to &#039;&#039;&#039;/usr/bin&#039;&#039;&#039; so it&#039;s available in path, is useful for fetching hardware info about the pi. For example, measuring the temperature&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
root@yellow-pi:~# vcgencmd measure_temp&lt;br /&gt;
temp=63.0&#039;C&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The command is generally badly documented and parts of it seems outdated for newer hardware. Here&#039;s the output from a Raspberry pi 4 with 4GB RAM&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
roy@yellow-pi:~ $ vcgencmd get_mem arm&lt;br /&gt;
arm=948M&lt;br /&gt;
roy@yellow-pi:~ $ vcgencmd get_mem gpu&lt;br /&gt;
gpu=76M&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== BIOS upgrade from Linux ==&lt;br /&gt;
&lt;br /&gt;
Generally, BIOS upgrades have been moved to the BIOS itself these days. This saves a lot of work and quite possibly lives after those who earier rammed their heads through walls, now can upgrade directly from the internet instead of using obscure operating systems best avoided. Sometimes, however, one must use these nevertheless. This is a quick run-through on your options.&lt;br /&gt;
&lt;br /&gt;
=== DOS ===&lt;br /&gt;
&lt;br /&gt;
Most non-automatic BIOS upgrades are installed from DOS. Doing a BIOS upgrade this way, is generally non-problematic. Just install a USB thingie with [https://www.freedos.org/ FreeDOS], copy your file(s) onto the thing and boot on it. The commandline is the same as old MS/DOS, except a wee bit more userfriendly, but not a lot.&lt;br /&gt;
&lt;br /&gt;
=== Windows ===&lt;br /&gt;
&lt;br /&gt;
Some macahines, like laptops from &#039;&#039;&#039;HP&#039;&#039;&#039;, may have BIOS upgrades that are made to be installed from Windows and won&#039;t run in FreeDOS or MS/DOS, instead throwing an error, saying &#039;&#039;&#039;This program cannot be run in DOS mode&#039;&#039;&#039;. This means you&#039;ll have to boot on a Windows rescue disc and do the job from there. Googling this, tells you it&#039;s quite easy, you just choose &#039;make rescue disc&#039; from Windows, and it&#039;s all good, except if you don&#039;t run Windows, that is. To remedy this problem, do as follows:&lt;br /&gt;
&lt;br /&gt;
==== Download Windows ====&lt;br /&gt;
&lt;br /&gt;
Since you don&#039;t run Windows and possibly don&#039;t have a spouse or friend around with such unhealthy habits either, you need to get it. It&#039;s quite easy - just google &#039;download windows&#039; and it&#039;ll send you to [https://www.microsoft.com/en-us/software-download/windows10ISO somewhere like this].&lt;br /&gt;
&lt;br /&gt;
==== Burn it! ====&lt;br /&gt;
&lt;br /&gt;
Now it&#039;s time to burn the installer on a DVD ROM. You&#039;ll need a double-layered one, since the OS is &amp;gt; 4.7GiB, but I&#039;m sure you have a ton of those lying around. Now, just place your optical medium in your optical drive and burn, baby, burn!&lt;br /&gt;
&lt;br /&gt;
==== Or make a USB thing? ====&lt;br /&gt;
&lt;br /&gt;
Not a lot of machines have optical drives these days, so you may want to use an USB pen drive or something instead. This is easy, just make the USB bootable with the Windows application Microsoft has made for this. Unfortunately, this only runs on Windows, and unlike stuff like Debian, where the &#039;&#039;&#039;iso&#039;&#039;&#039; file can be dd&#039;ed directly onto a USB drive to make it bootable, the Windows &#039;&#039;&#039;iso&#039;&#039;&#039;s don&#039;t come with this luxury. There are lots of methods to make bootable USB things from iso files out there, but the only thing most of them have in common, is that they generally don&#039;t work.&lt;br /&gt;
&lt;br /&gt;
===== WoeUSB =====&lt;br /&gt;
&lt;br /&gt;
After hours of swearing, it&#039;s nice to come across software like [https://github.com/slacka/WoeUSB WoeUSB]. It may not be perfect, it relies on a bunch of GUI stuff you&#039;ll never need and so on, but it &#039;&#039;&#039;&#039;&#039;works&#039;&#039;&#039;&#039;&#039;, and that&#039;s the important part! Just clone the repo and RTFM and it&#039;s all nice. It&#039;s slow, but hell, getting a windows machine and/or an optical drive might be slower.&lt;br /&gt;
&lt;br /&gt;
WoeUSB does nothing fancy, but it &#039;&#039;&#039;does&#039;&#039;&#039; work. It will create a filesystem, FAT32 or NTFS (better use NTFS, FAT32 has its limits). It creates normal filesystems and so on. Just make sure to copy in the BIOS update file, usually an exe file, to run when Windows is up and running.&lt;br /&gt;
&lt;br /&gt;
===== Install BIOS =====&lt;br /&gt;
&lt;br /&gt;
Boot on the Windows USB thing and choose &#039;repair computer&#039; and then &#039;command prompt&#039;. Find the install file, and if you&#039;re lucky, you&#039;ll find it needs a 32bit OS, just like I did. Since the 64bit version doesn&#039;t include 32bit compatibility in the installer, revert to downloading the 32bit version of windows and start over. Pray to your favourite god(s) not to get across such machines again - it might help.&lt;br /&gt;
&lt;br /&gt;
= 3D printer stuff =&lt;br /&gt;
&lt;br /&gt;
== Hydrophilic filament ==&lt;br /&gt;
&lt;br /&gt;
Most popular filament types, including PLA, PETG, PP or PA (Polyamide, normally known as Nylon) and virtualy any filament type named [https://www.matterhackers.com/news/filament-and-water poly-something] (and thus with an acronym of P-something) are hydrophilic (also (somewhat incorrectly) called hydroscopic), meaning so long they&#039;re dryer than the atmosphere around them, they&#039;ll do their best to suck out the atmosphere&#039;s humidity. This is why most filament are shrink-wrapped with a small bag of silica gel in it. If such filament is exposed for normal humid air for some time, it&#039;ll become very hard to use. Most of my experience is with PLA, which can handle a bit (depending on make), but still not a lot. With PLA, if you end up with prints where the filament seems not to stick, it may help with a higher temperature. Otherwise, the filament must be [https://all3dp.com/2/how-to-dry-filament-pla-abs-and-nylon/ baked]. If you don&#039;t want to use your oven, try something like a [https://www.jula.no/catalog/hjem-og-husholdning/kjokkenmaskiner/mattilberedningsapparater/frukt-sopptorker/frukt-sopptorker-001641/#tab02 fruit and mushroom dryer]. Then get a good, sealble plastic box and add something like half a kilogram of [https://www.ebay.com/sch/sis.html?_nkw=1KG+Orange+Replacement+Desiccant+Indicating+Silica+Gel+Beads+for+Drawers%2C+Camera&amp;amp;_id=131938742628&amp;amp;&amp;amp;_trksid=p2057872.m2749.l2658 silica gel] to an old sock, tie it and put it in the your new dry box.&lt;br /&gt;
&lt;br /&gt;
Please note that ABS is hydrophobic, so you won&#039;t have to worry too much there. Also, remember that PA/Nylon is extremely hydrophilic. Even a couple of days in normal air humidity can ruin it completely and will require baking.&lt;br /&gt;
&lt;br /&gt;
== Upgrading the firmware on an Ender 3 ==&lt;br /&gt;
&lt;br /&gt;
This is about upgrading the firmware, and thus also flashing a bootloader to the Creality Ender 3 3D printer. Most of this is well documented on several place, like o [https://www.youtube.com/watch?v=fIl5X2ffdyo the video from Teaching tech] and elsewhere, but I&#039;ll just summarise some issues I had.&lt;br /&gt;
&lt;br /&gt;
=== Using an arduino Nano as a programmer ===&lt;br /&gt;
&lt;br /&gt;
Quick note before you read on. If you have an Ender 3 controller version 1.1.5 or newer (or perhaps even a bit older), a CR-10S or some other more or less modern printers or controllers, they come with a bootloader installed already, so don&#039;t bother flashing one. The one that&#039;s in there already, should work well. So if you have one of these, just skip this and jump to the [[Roy&#039;s_notes#Flashing_the_printer|next section]].&lt;br /&gt;
&lt;br /&gt;
However, the normal CR-10 (without the S), Ender 3 and a few other printers from Creality come without a bootloader, so you&#039;ll need to flash one before upgrading the firmware. Well, strictly speakning, you don&#039;t need one, you can save those 8kB or so for other stuff and use a programmer to write the whole firmware, but then you&#039;ll need to wire up everything every time you want a new firmware, so in my world, you &#039;&#039;&#039;do&#039;&#039;&#039; need the bootloader, since it&#039;s easier.&lt;br /&gt;
&lt;br /&gt;
To install a bootloader, you&#039;ll need a programmer, and I didn&#039;t have one available. Having some el-cheapo china-copies of Ardinos around, I read I could use one and tried so. Although the docs mostly mention the Uno etc, it&#039;s just as simple with the Nano copy.&lt;br /&gt;
&lt;br /&gt;
So, grab an arduino, plug it to your machine with a USB cable, and, using the Arduino IDE, use the ArduinoISP sketch there (found under Examples) to burn the software needed for the arduino to work as a programmer. When this is done, connect a 10µF capacitor between RST and GND to stop it from resetting when used as a programmer. Connect the MOSI, MISO and SCK pins from the ICSP block (that little isolated 6-pin block on top of the ardu). See [https://www.arduino.cc/en/Tutorial/ArduinoISP here] for a pinout. Then find Vcc and GND either on the ICSP block or elsewhere. Some sites say that on some boards you shouldn&#039;t use the pins on the ICSP block for this. I doubt it matters, though. Then connect another jumper wire from pin 10 on the ardu to work as the reset pin outwards to the chip being programmed (that is, on the printer). The ICSP jumper block pin layout is the same on the printer and on the ardu, and probably elsewhere. Sometimes [https://xkcd.com/927/ standardisation] actually works…&lt;br /&gt;
&lt;br /&gt;
See https://cloud.karlsbakk.net/index.php/s/zw48YJjzaf8Rc2F for a pic with the ardu (this wiki is broken atm, will fix it later)&lt;br /&gt;
&lt;br /&gt;
== Flashing the printer ==&lt;br /&gt;
&lt;br /&gt;
When the boot loader is in place, possibly after some wierd errors from during the process, the screen on the 3d printer will go blank and it&#039;ll behave like being bricked. This is ok. Now disconnect the wires and connect the USB cable between computer and printer. If you haven&#039;t installed support for the Sanguino board, that is, the variant of the 1284-chip and surrounding electronics that is the core of the, you need to install it first. In the Arduino IDE, choose the Tools / Boards / Boards manager boot option and search for Sanguino. After this, you should find the Sanguino or Sanguino 1284p in the boards menu. After this, you should be able to communicate with the printer&#039;s controller. Download the [https://www.th3dstudio.com/knowledgebase/th3d-unified-firmware-package/ TH3D unified firmware], making sure it&#039;s the last version. Uncompress the zip and with Finder/Explorer/whateversomething&#039;scalledonlinux, browse to &#039;&#039;&#039;TH3DUF_R2/Firmware/TH3DUF_R2.ino&#039;&#039;&#039; and open it. It should open directly in the Android IDE. Keep in mind that the names TH3DUF_R2 and TH3DUF_R2.ino will vary between versions, but you get the point. Now configure it for your particular needs. You&#039;ll find most of this in the Configuration.h tab (that&#039;s really a file). Most of the other files won&#039;t be necessary unless you&#039;re doing some more advanced stuff, like replacing th controller with something non-standard or similar, but then again, that&#039;s another chapter (or book, even). The video mentioned above describes this well. After flashing the new firmware, you&#039;ll probably get some timeouts and errors, since apparently it resets the printer after giving it the new firmware, but without notifying the flashing software of it doing so. If this happens, calm down and reboot the printer and check its tiny monitor - it should work. If it doesn&#039;t work, and if you flashed the bootload yourself, try to flash it again, and if that doesn&#039;t work, try flashing the programmer again yet another time, just for kicks. Again, if you have a newer controller like the v1.1.5, don&#039;t touch the bootloader, as the one already installed, should work well as it is.&lt;br /&gt;
&lt;br /&gt;
PS: I tried enabling &#039;&#039;&#039;MANUAL_MESH_LEVELING&#039;&#039;&#039;, which in the code says that &#039;&#039;If used with a 1284P board the bootscreen will be disabled to save space&#039;&#039;. This effectively disabled the whole printer, and apparently may be making the firmware image a wee bit too large for it to fit the 1284P on the ender. It works well without it, though.&lt;br /&gt;
&lt;br /&gt;
== And then… ==&lt;br /&gt;
&lt;br /&gt;
With the new firmware in place, the printer should work as before, although with thermal runaway protection to better avoid fires in case the shit hits the fan, and to allow for things like autolevelling. With any luck, [https://www.precisionpiezo.co.uk/ this thing] may be ready for use by the time you read this - it surely looks nice!&lt;br /&gt;
&lt;br /&gt;
roy&lt;/div&gt;</summary>
		<author><name>Roy</name></author>
	</entry>
	<entry>
		<id>https://wiki.malinux.no/index.php?title=Roy%27s_notes&amp;diff=160</id>
		<title>Roy&#039;s notes</title>
		<link rel="alternate" type="text/html" href="https://wiki.malinux.no/index.php?title=Roy%27s_notes&amp;diff=160"/>
		<updated>2020-05-22T01:56:40Z</updated>

		<summary type="html">&lt;p&gt;Roy: /* Flashing the printer */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= LVM, md and friends =&lt;br /&gt;
&lt;br /&gt;
== Linux&#039; Logical Volume Manager (LVM) ==&lt;br /&gt;
&lt;br /&gt;
=== LVM in general ===&lt;br /&gt;
&lt;br /&gt;
LVM is designed to be an abstraction layer on top of physical drives or RAID, typically [https://raid.wiki.kernel.org/index.php/RAID_setup mdraid] or [https://help.ubuntu.com/community/FakeRaidHowto fakeraid]. Keep in mind that fakeraid should be avoided unless you really need it, like in conjunction with dual-booting linux and windows on fakeraid. LVM broadly consists of three elements, the &amp;quot;physical&amp;quot; devices (PV), the volume group (VG) and the logical volume (LV). There can be multiple PVs, VGs and LVs, depending on requirement. More about this below. All commands are given as examples, and all of them can be fine-tuned using extra flags in need of so. In my experience, the defaults work well for most usecases.&lt;br /&gt;
&lt;br /&gt;
I&#039;m mentioning filesystem below too. Where I write ext4, the samme applies to ext2 and ext3.&lt;br /&gt;
&lt;br /&gt;
==== Create a PV ====&lt;br /&gt;
&lt;br /&gt;
A PV is the &amp;quot;physical&amp;quot; parts. This does not need to be a physical disk, but can also be another RAID, be it an mdraid, fakeraid, hardware raid, a virtual disk on a SAN or otherwisee or a partition on one of those. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#  These add three PVs, one on a drive (or hardware raid) and another two on mdraids.&lt;br /&gt;
pvcreate /dev/sdb&lt;br /&gt;
pvcreate /dev/md1 /dev/md2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For more information about pvcreate, see [https://linux.die.net/man/8/pvcreate the manual].&lt;br /&gt;
&lt;br /&gt;
==== Create a VG ====&lt;br /&gt;
&lt;br /&gt;
The volume group consists of one or more PVs grouped together on which LVs can be placed. If several PVs are grouped in a VG, it&#039;s generally a good idea to make sure these PVs have some sort of redundancy, as in mdraid/fakeraid or hwraid. Otherwise it will be like using a [https://en.wikipedia.org/wiki/RAID RAID-0] with a single point of failure on each of the independant drives. LVM has [https://unix.stackexchange.com/questions/150644/raiding-with-lvm-vs-mdraid-pros-and-cons  RAID code in it] as well, so you can use that. I haven&#039;t done so myself, as I generally stick to mraid. The reason is mdraid is, in my opinion older and more stable and has more users (meaning bugs are reported and fixed faster whenever they are found). That said, I beleive the actual RAID code used in LVM RAID are the same function calls as for mdraid, so it may not be much of a difference. I still stick with mdraid. To create a VG, run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create volume group my_vg&lt;br /&gt;
vgcreate my_vg /dev/md1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that if vgcreate is run with a PV (as /dev/md1 above) that is not defined as a PV (like above), this is done implicitly, so if you don&#039;t need any special flags to pvcreate, you can simply skip it and let vgcreate do that for you.&lt;br /&gt;
&lt;br /&gt;
==== Create an LV ====&lt;br /&gt;
&lt;br /&gt;
LVs can be compared to partitions, somehow, since they are bounderies of a fraction or all of that of a VG. The difference between them and a partition, however, is that they can be grown or shrunk easily and also moved around between PVs without downtime. This flexibility makes them superiour to partitions as your system can be changed without users noticing it. By default, an LV is alloated &amp;quot;thickly&amp;quot;, meaning all the data given to it, is allocated from the VG and thus the PV. The following makes a 100GB LV named &amp;quot;thicklv&amp;quot;. When making an LV, I usually allocate what&#039;s needed plus some more, but not everything, just to make sure it&#039;s space available for growth on any of the LVs on the VG, or new LVs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a thick provisioned LV named thicklv on the VG my_vg&lt;br /&gt;
lvcreate -n thicklv -L 100G my_vg&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After the LV is created, a filesystem can be placed on it unless it is meant to be used directly. The application for direct use include swap space, VM storage and certain database systems. Most of these will, however, work on filesystems too, although my testing has shown that on swap space, there is a significant performance gain for using dedicated storage without a filesystem. As for filesystems, most Linux users use either ext4 or xfs. Personally, I generally use XFS these days. See my notes below on filesystem choice.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a filesystem on the LV - this could have been mkfs -t ext4 or whatever filesystem you choose&lt;br /&gt;
mkfs -t xfs /dev/my_vg/thicklv&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then just edit /etc/fstab with correct data and run mount -a, and you should be all set.&lt;br /&gt;
&lt;br /&gt;
==== Create LVM cache ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
lvcreate -L 1G -n _cache_meta data /dev/md1&lt;br /&gt;
&lt;br /&gt;
lvcreate -l100%FREE -n _cache data /dev/md1&lt;br /&gt;
&lt;br /&gt;
# Some would want --cachemode writeback, but seriously, I wouldn&#039;t recommend it. Metadata or data can be easily corrupted in case of failure.&lt;br /&gt;
lvconvert --type cache-pool --cachemode writethrough --poolmetadata data/_cache_meta data/_cache&lt;br /&gt;
&lt;br /&gt;
lvconvert --type cache --cachepool data/_cache data/data&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Disabling LVM cache ====&lt;br /&gt;
&lt;br /&gt;
If you for some reason want to disable caching, this will do it cleanly and remove the LVs earlier created for caching the main device.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
lvconvert --uncache data/data&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Growing devices ====&lt;br /&gt;
&lt;br /&gt;
LVM objects can be grown and shrunk. If a PV resides on a RAID where a new drive has been added or otherwise grown, or on a partition or virtual disk that has been extended, the PV must be updated to reflect these changes. The following command will grow the PV to the maximum available on the underlying storage. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Resize the PV /dev/md (not the RAID, only the PV on the RAID) to its full size&lt;br /&gt;
pvresize /dev/md1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If a new PV is added, the VG can be grown to add the space on that in addition to what&#039;s there already. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Extend my_vg to include md2 and its space&lt;br /&gt;
vgextend my_vg /dev/md2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
With more space available in the VG, the LV can now be extended. Let&#039;s add another 50GB to it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Extend thicklv - add 50GB. If you know you won&#039;t need the space anywhere else, you may want to&lt;br /&gt;
# lvresize -l+100%FREE instead. Keep in mind the difference between -l (extents) and -L (bytes)&lt;br /&gt;
lvresize -L +50G my_vg/thicklv&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Growing filesystems ====&lt;br /&gt;
After the LV has grown, run &#039;&#039;xfs_growfs&#039;&#039; (xfs) or &#039;&#039;resize2fs&#039;&#039; (ext4) to make use of the new data. To grow the filesystem to all available space on ext4, run the below command.  To partly grow the filesystem or to shrink it or otherwise, please see the manuals.&lt;br /&gt;
&lt;br /&gt;
The filesystem can be mounted when this is run. If you for some reason get an &#039;&#039;&#039;access denied&#039;&#039;&#039; error when running this as root or with sudo, it&#039;s likely caused by a filesystem error. To fix this, unmount the filesystem first and run &#039;&#039;&#039;fsck -f /dev/my_vg/thicklv&#039;&#039;&#039; and remount it before retrying to extend it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
resize2fs /dev/my_vg/thicklv&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Similarly, with XFS, but note that xfs_growfs doesn&#039;t take the device name, but the filesystem&#039;s mount point. In the case of XFS, also note that the filesystem &#039;&#039;&#039;&#039;&#039;must&#039;&#039;&#039;&#039;&#039; be mounted to be grown. This, in contrast to how it was in the old days when filesystems had to be unmounted to be grown.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
xfs_growfs /my_mountpoint&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Rename system VG ====&lt;br /&gt;
&lt;br /&gt;
Some distros create VG names like those-from-a-sysadmin-with-a-well-developed-paranoia-not-to-hit-a-duplicate. Debian, for instance, uses names like &amp;quot;my-full-hostname-vg&amp;quot;. Personally, I don&#039;t like these, since if I were to move a disk or vdisk around to somewhere else, I&#039;d make sure not to add a disk named &#039;sys&#039; to an existing system. If you do, most distros will refuse to use the VGs with duplicate names, resulting in the OS not booting until either one is specified by its UUID or just one removed. As I&#039;m aware of this, I stick to the super-risky thing of all system VGs named &#039;sys&#039; and so on.&lt;br /&gt;
&lt;br /&gt;
If you do this, keep in mind that it may blow up your computer and take your girl- or boyfriend with it or even make either of them pregnant, allowing Trump to rule your life and generally make things suck. You&#039;re on your own!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Rename the VG&lt;br /&gt;
vgrename my-full-hostname-vg sys&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, in /boot/grub/grub.cfg, change the old lv path from something like &#039;/dev/mapper/debian--stretch--machine--vg-root&#039; to your new and fancy &#039;/dev/sys/root. Likewise, in /etc/fstab, change occurences of &#039;/dev/mapper/debian--stretch--machine--vg-&#039; (or similar) with &#039;/dev/sys/&#039;. Here, this was like this - the old ones commented out.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;fstab&amp;quot;&amp;gt;&lt;br /&gt;
#/dev/mapper/debian--stretch--box--vg-root      /               ext4            errors=remount-ro,discard       0       1&lt;br /&gt;
/dev/sys/root                                   /               ext4            errors=remount-ro,discard       0       1&lt;br /&gt;
# /boot was on /dev/vda1 during installation&lt;br /&gt;
UUID=myverylonguuidwithatonofgoodinfoinit       /boot           ext2            defaults                        0       2&lt;br /&gt;
#/dev/mapper/debian--stretch--box--vg-swap_1    none            swap            sw                              0       0&lt;br /&gt;
/dev/sys/swap_1                                 none            swap            sw                              0       0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Update /etc/initramfs-tools/conf.d/resume with similar data for swap.&lt;br /&gt;
&lt;br /&gt;
You might want to run &#039;update-initramfs -u -k all&#039; after this, but I&#039;m not sure if it&#039;s needed.&lt;br /&gt;
&lt;br /&gt;
Now, pray to the nearest god(s) and give it a reboot and it should (probably) work.&lt;br /&gt;
&lt;br /&gt;
After reboot, run &#039;&#039;&#039;swapoff -a&#039;&#039;&#039;, then &#039;&#039;&#039;mkswap /dev/sys/swap_1&#039;&#039;&#039; (or whatever it&#039;s called on your system) and &#039;&#039;&#039;swapon -a&#039;&#039;&#039; again. You may want to give it another reboot or two for kicks, but it should work well even without that.&lt;br /&gt;
&lt;br /&gt;
=== Migration tools ===&lt;br /&gt;
&lt;br /&gt;
At times, storage regimes change, new storage is added and sometimes it&#039;s not easy to migrate with the current hardware or its support systems. Once I had to migrate a 45TiB fileserver from one storage system to another, preferably without downtime. The server originally had three 15TiB PVs of which two were full and the third half full. I resorted to using [https://linux.die.net/man/8/pvmove pvmove] to just move the data on the PVs in use to a new PV. We started out with creating a new 50TiB PV, sde, and then to pvmove.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Attach /dev/sde to the VG my_vg&lt;br /&gt;
vgextend my_vg /dev/sde&lt;br /&gt;
&lt;br /&gt;
# Move the contents from /dev/sdb over to /dev/sde block by block. If a target is not given in pvmove,&lt;br /&gt;
# the contents of the source (sdb here) will be put somewhere else in the pool.&lt;br /&gt;
pvmove /dev/sdb /dev/sde&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This took a while (as in a week or so) - the pvmove command uses old code and logic (or at least did that when I migrated this in November 2016), but it affected performance on the server very little, so users didn&#039;t notice. After the first PV was migrated, I continued with the other two, one after the other, and after a month or so, it was migrated. We used this on a number of large fileservers, and it worked flawlessly. Before doing the production servers I also tried interrupting pvmove in various ways, including hard resets, and it just kept on after the reboot.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;NOTE:&#039;&#039;&#039;&#039;&#039; &#039;&#039;Even though it worked well for us, &#039;&#039;&#039;always&#039;&#039;&#039; keep a good backup before doing this. Things may go wrong, and without a good backup, you may be looking for a hard-to-find new job the next morning&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
==== mdadm workarounds ====&lt;br /&gt;
&lt;br /&gt;
===== Migrate from a mirror (raid-1) to raid-10 =====&lt;br /&gt;
&lt;br /&gt;
Create a mirror&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sdb /dev/sdc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
LVM (pv/vg/lv) on md0 (see above), put a filesystem on the lv and fill it with some data.&lt;br /&gt;
&lt;br /&gt;
Now, some months later, you want to change this to raid-10 to allow for the same amount of redundancy, but to allow more disks into the system.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mdadm --grow /dev/md0 --level=10&lt;br /&gt;
mdadm: Impossibly level change request for RAID1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So - no - doesn&#039;t work. But - we&#039;re on &lt;br /&gt;
&lt;br /&gt;
Since we&#039;re on lvm already, this&#039;ll be easy. If you&#039;re using filesystems directly on partitions, you can do this the same way, but without the pvmove part, using rsync or whateever you like instead. I&#039;d recommend using lvm for for the new raid, which should be rather obvious from this article. Now plug in a new drive and create a new raid10 on that one. If you two new drives, install both. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# change &amp;quot;missing&amp;quot; to the other device name if you installed two new drives&lt;br /&gt;
mdadm --create /dev/md1 --level=10 --raid-devices=2 /dev/vdd missing&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, as described above, just vgextend the vg, adding the new raid and run pvmove to move the data from the old pv (residing on the old raid1) to the new pv (on raid10). Afte rpvmove is finished (which may take awile, see above), just&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
vgreduce raidtest /dev/md0&lt;br /&gt;
pvremove /dev/md0&lt;br /&gt;
mdadm --stop /dev/md0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
…and your disk is free to be added to the new array. If the new raid is running in degraded mode (if you created it with just one drive), better don&#039;t wait too long, since you don&#039;t have redundancy. Just mdadm --add the devs.&lt;br /&gt;
&lt;br /&gt;
If you now have /dev/mdstat telling you your raid10 is active and have three drives, of which one is a spare, it should look something like this&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5] [raid4] [raid10]&lt;br /&gt;
md1 : active raid10 vdc[3](S) vdb[2] vdd[0]&lt;br /&gt;
      8380416 blocks super 1.2 2 near-copies [2/2] [UU]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Just mdadm --grow --raid-devices=3 /dev/md1&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;RAID section is not complete. I&#039;ll write more on migraing from raid10 to raid6 later. It&#039;s not straight forward, but easier than this one :)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== Thin provisioned LVs ===&lt;br /&gt;
&lt;br /&gt;
Thin provisioning on LVM is a method used for not allocating all the space given to an LV. For instance, if you have a 1TB VG and want to give an LV 500GB, although it currently only uses a fraction of that, a thin lv can be a good alternative. This will allow for adding a limit to how much it can use, but also to let it grow dynamically without manual work by the sysadmin. Thin provisioning adds another layer of abstaction by creating a special LV as a &#039;&#039;thin pool&#039;&#039; from which data is allocated to the &#039;&#039;thin volume(s)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== Create a thin pool ====&lt;br /&gt;
&lt;br /&gt;
Allocate 1TB to the thin pool to be used for thinly provisioned LVs. Keep in mind that the space allocated to the thin pool is in fact thick provisioned. Only the volumes put on &#039;&#039;thinpool&#039;&#039; are thin provisioned. This will create two hidden LVs, one for data and one for metadata. Normally the defaults will do, but check the manual if the data doesn&#039;t match the usual patterns (such as billions of files, resulting in huge amounts of metadata). I &#039;&#039;beleive&#039;&#039; the metadata part should be resizable at a later time if needed, but I have not tested it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a pool for thin LVs. Keep in mind that the pool itself is not thin provisioned, only the volumes residing on it&lt;br /&gt;
lvcreate --size 1T --type thin-pool --thinpool thinpool my_vg&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Create a thin volume ====&lt;br /&gt;
&lt;br /&gt;
You have the thinpool, now put a thin volume on it. It will allocate some space for metadata, but probably not much (a few megs, perhaps).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Now, create a volume with a virtual (-V) size of half a terabyte named thin_pool, but using the thinpool (-T) named thin_pool for storage&lt;br /&gt;
lvcreate -V 500G -T my_vg/thin_pool --name thinvol&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The new volume&#039;s device name will be /dev/thinvol. Now, create a filesystem on it, add to fstab and mount it. The &#039;&#039;&#039;df&#039;&#039;&#039; command will return available space according to the virtual size (-V), while lvs will show how much data is actually used on each of the thinly provisioned volumes.&lt;br /&gt;
&lt;br /&gt;
== Filesystem dilemmas ==&lt;br /&gt;
&lt;br /&gt;
=== XFS or ext4 or something else ===&lt;br /&gt;
The choice of filesystem varies for your use. Distros such as RHEL/CentOS has moved to XFS by default from v7. Debian/Ubuntu still sticks to ext4, like most other. I&#039;ll discuss my thoughts below on ext4 vs XFS and leave the other filesystems for later.&lt;br /&gt;
&lt;br /&gt;
==== ext4 ====&lt;br /&gt;
ext4 is probably the most used filesystem on linux as of writing. It&#039;s rock stable and has been extended by a lot of extensions since the original ext2. It still retains backward compatibility, being able to mount and fsck ext2 and ext3 with the ext4 driver. However, it doesn&#039;t handle large filesystems very well. If a filesystem is created for &amp;lt;16TiB, it cannot be grown to anything larger than 16TiB. This may have changed lately, though. One other issue is handling errors. If a large filesystem (say 10TiB) is damaged, an fsck may take several hours, leading to long downtime. When I refer to ext4 further in this text, the same applies to ext2 and ext3 unless otherwise specified.&lt;br /&gt;
&lt;br /&gt;
==== XFS ====&lt;br /&gt;
XFS, originally developed by SGI some time in the bronze age, but has been worked on heavily after that. RHEL and Centos version 7 and forward, uses XFS as the default filesystem. It is quick, it scales well, but it lacks at least two things ext4 has. It cannot be shrunk (not that you normally need that, but nice if you have a typo or you need to change things). Also, it doesn&#039;t allow for automatic fsck on bootup. If something is messed up on the filesystem, you&#039;ll have to login as root on the console (not ssh), which might be an issue on some systems. The fsck equivalent, xfs_repair, is a *lot* faster than ext4&#039;s fsck, though.&lt;br /&gt;
&lt;br /&gt;
==== ZFS ====&lt;br /&gt;
ZFS is like a combination of RAID, LVM and a filesystem, supporting full checksumming, auto-healing (given sufficient redundancy), compression, encryption, replication, deduplication (if you&#039;re brave and have a &#039;&#039;ton&#039;&#039; of memory) and a lot more. It&#039;s a separate chapter and needs a lot more talk than paragraph here.&lt;br /&gt;
&lt;br /&gt;
==== btrfs ====&lt;br /&gt;
btrfs, pronounced &amp;quot;butterfs&amp;quot; or &amp;quot;betterfs&amp;quot; or just spelled out, is a filesystem that mimics that of ZFS. It has been around for 10 years or so, but hasn&#039;t yet proven to be really stable. Following the progress of it for those years, I&#039;ve found it to be a nice toy with which to play, but not to be used in production. Again, others may say otherwise, but these are just my words.&lt;br /&gt;
&lt;br /&gt;
== Low level disk handling ==&lt;br /&gt;
&lt;br /&gt;
This section is for low-level handling of disks, regardless of storage system elsewhere. These apply to mdraid, lvmraid and zfs and possibly other solutions, with the exception of individual drives on hwraid (and maybe fakeraid), since there, the drives are hidden from Linux (or whatever OS).&lt;br /&gt;
&lt;br /&gt;
=== S.M.A.R.T. and slow drives ===&lt;br /&gt;
Modern (that is, from about 1990 or later) have S.M.A.R.T. (or just smart, since it&#039;s easier to type) monitoring built in, meaning the disk&#039;s controller is monitoring itself. This is handy and will ideally tell you in advance that a drive is flakey or dying. Modern (2010+) smart monitoring is more or less the same. It can be trusted about 50% of the time. Usually, if smart detects an error, it&#039;s a real error. I don&#039;t think I&#039;ve seen it reporting a false positive, but others may know better. &lt;br /&gt;
&lt;br /&gt;
==== smartmontools ====&lt;br /&gt;
First, install smartmontool and run smartclt -H /dev/yourdisk (/dev/sda or something) to get a health report. Then perhaps run smartctl -a /dev/yourdisk and look for &#039;current pending sectors&#039; This should be zero. Also check the temperature, which normally should be much above 50.&lt;br /&gt;
&lt;br /&gt;
==== single, slow drive ====&lt;br /&gt;
What may happen, is smart not seeing anything and life goes on like before, only slower and less prouductive, without telling anyone. If you stubler over this issue, you&#039;ll probably see it during a large rsync/zfs send/receive or a resync/rebuild/resilver of the raid/zpool. During this, it feels like everything is slow and your RAID has turned into a RAIF (redundant array of inexpensive floppies). To check if you have a single drive messing up it all, check with &#039;&#039;&#039;iostat -x 2&#039;&#039;&#039;, having 2 being the delay between each measurement. Interrupt it with ctrl+x. If there&#039;s a rougue drive there, it should stand out like sdg below&lt;br /&gt;
&lt;br /&gt;
 avg-cpu:  %user   %nice %system %iowait  %steal   %idle&lt;br /&gt;
            0.38    0.00    1.75    0.00    0.00   97.87&lt;br /&gt;
&lt;br /&gt;
 Device            r/s     w/s     rkB/s     wkB/s   rrqm/s   wrqm/s  %rrqm  %wrqm r_await w_await aqu-sz rareq-sz wareq-sz  svctm  %util&lt;br /&gt;
 sda              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdb              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdc              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdd              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sde              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdf              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdg              3.50    0.00   2352.00      0.00     0.00     0.00   0.00   0.00 14306.29    0.00  13.85   672.00     0.00 285.71 100.00&lt;br /&gt;
 sdh              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
&lt;br /&gt;
In ZFS land, you should be able to get similar data with &#039;&#039;&#039;zpool iostat -v &amp;lt;pool&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Now you know the bad drive (sdg), pull it from the raid with &#039;&#039;&#039;mdadm --fail /dev/mdX /dev/sdX&#039;&#039;&#039;. Now test the drive&#039;s performance manually, just simply:&lt;br /&gt;
&lt;br /&gt;
 # hdparm -t /dev/sdg&lt;br /&gt;
 &lt;br /&gt;
 /dev/sdg:&lt;br /&gt;
  Timing buffered disk reads:   2 MB in  5.37 seconds = 381.46 kB/sec&lt;br /&gt;
&lt;br /&gt;
Bingo - nothing you&#039;d want to keep. For a good drive, it should be something like 100-200MB/s&lt;br /&gt;
&lt;br /&gt;
PS: Keep in mind that you have a degraded RAID by now in case you had a spare waiting for things to happen.&lt;br /&gt;
&lt;br /&gt;
Try to replace the cable and/or try the disk on another port/controller. If the result from hdparm persists, it&#039;s probably a bad cable&lt;br /&gt;
&lt;br /&gt;
So, then, just psycially locate the drive, pull it out, take out the discs and magnets and recycle the rest.&lt;br /&gt;
&lt;br /&gt;
=== &amp;quot;Unplug&amp;quot; drive from system ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Find the device unit&#039;s number with something like&lt;br /&gt;
find /sys/bus/scsi/devices/*/block/ -name sdd&lt;br /&gt;
# returning /sys/bus/scsi/devices/3:0:0:0/block/sdd here, &lt;br /&gt;
# meaning 3:0:0:0 is the SCSI device we&#039;re looking for.&lt;br /&gt;
&lt;br /&gt;
# Given this is the correct device, and you want to &#039;unplug&#039; it, do so by&lt;br /&gt;
echo 1 &amp;gt; /sys/bus/scsi/devices/3:0:0:0/delete&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Rescan disk controllers ===&lt;br /&gt;
If a drive is added and for some reason doesn&#039;t get detected, or is removed by the command above, it can be rediscovered with a sysfs command to the scsi host to which it is connected. Since there may be quite a few of these, an easy way is to just scan them all and check the output of &#039;&#039;&#039;dmesg -T&#039;&#039;&#039; after running it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Make a list of controllers and send a rescan message to each of them. It won&#039;t do anything &lt;br /&gt;
# for those where nothing has changed, but it will show new drives where they have been added.&lt;br /&gt;
for host_scan in /sys/class/scsi_host/host*/scan&lt;br /&gt;
do&lt;br /&gt;
  echo &#039;- - -&#039; &amp;gt; $host_scan&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Fail injection with debugfs ===&lt;br /&gt;
[https://lxadm.com/Using_fault_injection https://lxadm.com/Using_fault_injection]&lt;br /&gt;
&lt;br /&gt;
== mdadm stuff ==&lt;br /&gt;
=== Resync ===&lt;br /&gt;
To resync a raid, that is, check, run&lt;br /&gt;
&lt;br /&gt;
 echo check &amp;gt; /sys/block/$dev/md/sync_action&lt;br /&gt;
&lt;br /&gt;
where $dev is something like md0. If you have several raids, something like this should work&lt;br /&gt;
&lt;br /&gt;
 for dev in md{0,1}&lt;br /&gt;
 do&lt;br /&gt;
   echo repair &amp;gt; /sys/block/$dev/md/sync_action&lt;br /&gt;
 done&lt;br /&gt;
&lt;br /&gt;
Also useful in a one-liner like&lt;br /&gt;
&lt;br /&gt;
 for dev in md{0,1} ; do echo repair &amp;gt; /sys/block/$dev/md/sync_action ; done&lt;br /&gt;
&lt;br /&gt;
Different raids on different drives will do this in parallel. If the drives are shared somehow with partitions or similar, the check or repair will wait for the other to finish before going on.&lt;br /&gt;
&lt;br /&gt;
As for repair vs check, [https://raid.wiki.kernel.org/index.php/RAID_Administration this article] describes it well. I stick to using repair unless it&#039;s something rare where I don&#039;t want to touch the data.&lt;br /&gt;
&lt;br /&gt;
=== Spare pools ===&lt;br /&gt;
In the old itmes, mdadm supported only a dedicated spare per md device, so if working with a large set of drives (20? 40?), where you&#039;d want to setup more raid sets to increase redundancy, you&#039;d dedicate a spare to each of the raid sets. This has changed (some time ago?), so in these modern, heathen days, you can change mdadm.conf, usually placed under /etc/mdadm, and add &#039;spare-group=somegroup&#039; where &#039;somegroup&#039; is a string identifying the spare group. After doing this, run &#039;&#039;&#039;update-initramfs -u&#039;&#039;&#039; and reboot and add a spare to one of the raid sets in the spare group, and md will use that or those spares for all the raidsets in that group.&lt;br /&gt;
&lt;br /&gt;
As some pointed out on #linux-raid @ irc.freenode.net, this feature is very badly documented, but as far as I can see, it works well.&lt;br /&gt;
&lt;br /&gt;
==== Example config ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create two raidsets&lt;br /&gt;
&lt;br /&gt;
mdadm --create /dev/md1 --level=6 --raid-devices=6 /dev/vd[efghij]&lt;br /&gt;
mdadm --create /dev/md2 --level=6 --raid-devices=6 /dev/vd[klmnop]&lt;br /&gt;
&lt;br /&gt;
# get their UUID etc&lt;br /&gt;
&lt;br /&gt;
mdadm --detail --scan&lt;br /&gt;
ARRAY /dev/md/1 metadata=1.2 name=raidtest:1 UUID=1a8cbdcb:f4092350:348b6b80:c054d74c&lt;br /&gt;
ARRAY /dev/md/2 metadata=1.2 name=raidtest:2 UUID=894b1b7c:cb7eba70:917d6033:ea5afd2b&lt;br /&gt;
&lt;br /&gt;
# Put those lines into /etc/mdadm/mdadm.conf and and add the spare-group&lt;br /&gt;
&lt;br /&gt;
ARRAY /dev/md/1 metadata=1.2 name=raidtest:1 spare-group=raidtest UUID=1a8cbdcb:f4092350:348b6b80:c054d74c&lt;br /&gt;
ARRAY /dev/md/2 metadata=1.2 name=raidtest:2 spare-group=raidtest UUID=894b1b7c:cb7eba70:917d6033:ea5afd2b&lt;br /&gt;
&lt;br /&gt;
# update the initramfs and reboot&lt;br /&gt;
&lt;br /&gt;
update-initramfs -u&lt;br /&gt;
reboot&lt;br /&gt;
&lt;br /&gt;
# add a spare drive to one of the raids&lt;br /&gt;
&lt;br /&gt;
mdadm --add /dev/md1 /dev/vdq&lt;br /&gt;
&lt;br /&gt;
# fail a drive on the other raid&lt;br /&gt;
&lt;br /&gt;
mdadm --fail /dev/md2 /dev/vdn&lt;br /&gt;
&lt;br /&gt;
# check /proc/mdstat to see md2 rebuilding with the spare from md1&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Recovery ===&lt;br /&gt;
&lt;br /&gt;
The other day, I came across a problem a user had on #linux-raid@irc.freenode.net. He had an old Qnap NAS that had died and tried plugging the drives in to his Linux machine and got various errors. The two-drive RAID-1 did not come up as it should, &#039;&#039;&#039;dmesg&#039;&#039;&#039; was full of errors from one of the drives (both connected on USB) and so forth.&lt;br /&gt;
&lt;br /&gt;
We went on and started by taking down the machine and just connecting one of the drives. I had him check what was assembled with&lt;br /&gt;
&lt;br /&gt;
 cat /proc/mdstat&lt;br /&gt;
&lt;br /&gt;
That returned /proc/md127 assembled, but LVM didn&#039;t find anything. So running a manual scan&lt;br /&gt;
&lt;br /&gt;
 pvscan --cache /dev/md127&lt;br /&gt;
&lt;br /&gt;
This made linux find the PV, VG and a couple of LVs, but probably because the mdraid was degraded, the LVs were deactivated, according to &#039;&#039;&#039;lvscan&#039;&#039;&#039;. Activating the one with a filesystem manually&lt;br /&gt;
&lt;br /&gt;
 lvchange -a y /dev/&amp;lt;vg&amp;gt;/&amp;lt;lv&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Substitute &amp;lt;vg&amp;gt; and &amp;lt;lv&amp;gt; with the names listed by vgs and lvs.&lt;br /&gt;
&lt;br /&gt;
This worked, and the filesystem on /dev/&amp;lt;vg&amp;gt;/&amp;lt;lv&amp;gt; could be mounted correctly.&lt;br /&gt;
&lt;br /&gt;
== Tuning ==&lt;br /&gt;
&lt;br /&gt;
While trying to compare a 12-disk RAID (8TB disks) to a hwraid, mdraid was slower, so we did a few things to speed things up:&lt;br /&gt;
&lt;br /&gt;
While testing with [https://linux.die.net/man/1/fio fio], monitor /sys/block/md0/md/stripe_cache_active, and see if it&#039;s close to /sys/block/md0/md/stripe_cache_size. If it is, double the size of the latter&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
echo 4096 &amp;gt; /sys/block/md0/md/stripe_cache_size&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Continue until stripe_cache_active stabilises, and then you&#039;ve found the limit you&#039;ll need. You may want to double that for good measure. &lt;br /&gt;
&lt;br /&gt;
(to be continued)&lt;br /&gt;
&lt;br /&gt;
== Links ==&lt;br /&gt;
&lt;br /&gt;
Below are a few links with useful info&lt;br /&gt;
&lt;br /&gt;
* [https://raid.wiki.kernel.org/index.php/Irreversible_mdadm_failure_recovery Irreversible mdadm failure recovery]&lt;br /&gt;
&lt;br /&gt;
= ZFS =&lt;br /&gt;
&lt;br /&gt;
ZFS can do a lot of things most filesystems or volume managers can&#039;t. It checksums all data and metadata and so long that the system uses ECC enabled memory (RAM), it will have complete control over the whole data set, and when (not if) an error occurs, it&#039;ll fix the issue without even throwing a warning. To fix the issue, you&#039;ll obviously need sufficient redundancy (mirrors or RAIDzN). &lt;br /&gt;
&lt;br /&gt;
== ZFS send/receive between machines ==&lt;br /&gt;
&lt;br /&gt;
ZFS has a send/receive mechanism that allows for snapshots to be sent over the wire to a receiving end. This can be a full filesystem, or an incremental change since last send/reveive. In a WAN scenario, you&#039;ll probably want to use VPN for this. On a controlled network, sending in cleartext is also possible. You may as well use ssh, but keep in mind that ssh was never designed to be used as a fullblown vpn solution and is just too slow or the task with large amounts of data. You may, though, use mbuffer, if on a loal LAN.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Allow traffic from the sending IP in whatever firewall interface you&#039;re using (if you&#039;re using a firewall at all, that is)&lt;br /&gt;
ufw allow from x.x.x.x&lt;br /&gt;
# &lt;br /&gt;
# Start the receiver first. This listens on port 9090, has a 1GB buffer,&lt;br /&gt;
    and uses 128kb chunks (same as zfs):&lt;br /&gt;
&lt;br /&gt;
mbuffer -s 128k -m 1G -I 9090 | zfs receive data/filesystem&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To be continued one day… See [https://everycity.co.uk/alasdair/2010/07/using-mbuffer-to-speed-up-slow-zfs-send-zfs-receive/ this] for some more. I&#039;ll get back with details on it.&lt;br /&gt;
&lt;br /&gt;
= General Linux system control =&lt;br /&gt;
&lt;br /&gt;
== Add a new CPU (core) ==&lt;br /&gt;
&lt;br /&gt;
If working with virtual machines, adding a new core can be useful if the VM is slow and the load is multithreaded or multiprocess. To do this, add a new CPU in the hypervisor (be it KVM or VMware or Hyper-V or whatever). Some hypervisors, like VMware, will activate it automatically if open-vm-tools is installed. Please note that open-vm-tools is for VMware only. I don&#039;t know of any such thing for KVM or other hypervisors (although I beleive VirtualBox has its own set of tools, but not as a package). If this doesn&#039;t work, run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
echo 1 &amp;gt; /sys/devices/system/cpu/cpuX/online&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where X is the CPU number you want to add. You can &#039;cat /sys/devices/system/cpu/cpuX/online&#039; to check if it&#039;s online.&lt;br /&gt;
&lt;br /&gt;
= Mount partitions on a disk image =&lt;br /&gt;
&lt;br /&gt;
Sometimes you&#039;ll have a disk image, either from recovering a bad drive after hours (or days or weeks) of ddrescue, and sometimes you just have a disk image from a virtual machine where you want to mount the partitions inside the image. There are three main methods of doing this, which are more or less synonmous, but some easier than the other.&lt;br /&gt;
&lt;br /&gt;
== Basics ==&lt;br /&gt;
&lt;br /&gt;
A disk image is usually like a disk, consisting of either a large filesystem, a PV or a partition table with one or partitions onto which resides a filesystem, a pv, swap or something else. If it&#039;s partitioned, and you want your operating system to mount a filesystem or allow it to see whatever LVM stuff lies on it, you need to isolate the partitions. &lt;br /&gt;
&lt;br /&gt;
== Manual mapping ==&lt;br /&gt;
&lt;br /&gt;
In the oldern days, this was done manually, something like this&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
root@mymachine:~# fdisk -l /dev/vda&lt;br /&gt;
Disk /dev/vda: 25 GiB, 26843545600 bytes, 52428800 sectors&lt;br /&gt;
Units: sectors of 1 * 512 = 512 bytes&lt;br /&gt;
Sector size (logical/physical): 512 bytes / 512 bytes&lt;br /&gt;
I/O size (minimum/optimal): 512 bytes / 512 bytes&lt;br /&gt;
Disklabel type: dos&lt;br /&gt;
Disk identifier: 0xc37b7ea5&lt;br /&gt;
&lt;br /&gt;
Device     Boot    Start      End  Sectors  Size Id Type&lt;br /&gt;
/dev/vda1  *        2048 50333311 50331264   24G 83 Linux&lt;br /&gt;
/dev/vda2       50333312 52426369  2093058 1022M  5 Extended&lt;br /&gt;
/dev/vda5       50333314 52426369  2093056 1022M 82 Linux swap / Solaris&lt;br /&gt;
root@mymachine:~#&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To calculate the start and end of each partition, you just take the start sector and multiply it by the sector size (512 bytes here) and you have the offset in bytes. After this, it&#039;s merely an losetup -o &amp;lt;offset&amp;gt; /dev/loopX &amp;lt;nameofimagefile&amp;gt; and you have the partition mapped to your /dev/loopX (having X being something typically 0-255. After this, just mount it or run pvscan/vgscan/lvscan to probe whatever lvm config is there, and you should be able to mount it like any other filesystem.&lt;br /&gt;
&lt;br /&gt;
== kpartx ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;kpartx&#039;&#039;&#039; does the same as above, more or less, just without so much hassle. Most of it should be automatic and easy to deal with, except it may fail to disconnect the loopback devices sometimes, so you may have to &#039;&#039;&#039;losetup -d&#039;&#039;&#039; them manually. See the manual, &#039;&#039;&#039;kpartx (8)&#039;&#039;&#039;. Please note that &#039;&#039;&#039;partx&#039;&#039;&#039; works similarly and I&#039;d guess the authors of the two tools are arguing a lot of which one&#039;s the best.&lt;br /&gt;
&lt;br /&gt;
== guestmount ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;guestmount&#039;&#039;&#039; is something similar again, but also supports file formats like &#039;&#039;&#039;qcow2&#039;&#039;&#039; and possibly other, proprietary filesystems like &#039;&#039;&#039;vmdk&#039;&#039;&#039; and &#039;&#039;&#039;vdi&#039;&#039;&#039;, but don&#039;t take my word for it - I haven&#039;t tested. Again, see the manual or just read up on the description [http://ask.xmodulo.com/mount-qcow2-disk-image-linux.html?fbclid=IwAR3snTeZvGzp9PLdX11EQhCfOpux6I93CiJ3A2pUomkkRLly9Xo4851mkTY here]. It seems rather trivial.&lt;br /&gt;
&lt;br /&gt;
= Linux on laptops =&lt;br /&gt;
&lt;br /&gt;
== Wifi with HP EliteBook 725/745 on Ubuntu ==&lt;br /&gt;
&lt;br /&gt;
The HP EliteBook 725/745 and similar are equipped with a BCM4352 wifi chip. As with a lot of other stuff from Broadcom, this lacks an open hardware description, so thus no open driver exist. The proper fix, is to replace the NIC with something with an open driver, but again, this isn&#039;t always possible, so a binary driver exists. In ubuntu, run, somehow connect the machine to the internet and run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install bcmwl-kernel-source&lt;br /&gt;
sudo modprobe wl&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you can&#039;t connect the machine to the internet, download the needed packages on another machine and put it on some usb storage. These packages should suffice:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# apt-cache depends bcmwl-kernel-source&lt;br /&gt;
bcmwl-kernel-source&lt;br /&gt;
  Depends: dkms&lt;br /&gt;
  Depends: linux-libc-dev&lt;br /&gt;
  Depends: libc6-dev&lt;br /&gt;
  Conflicts: &amp;lt;bcmwl-modaliases&amp;gt;&lt;br /&gt;
  Replaces: &amp;lt;bcmwl-modaliases&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then install manually with &#039;&#039;&#039;dpkg -i file1.deb file2.deb&#039;&#039;&#039; etc&lt;br /&gt;
&lt;br /&gt;
After this, ip/ifconfig/iwconfig shouldd see the new wifi nic, probably &#039;&#039;&#039;wlan0&#039;&#039;&#039;, but due to a [https://bugs.launchpad.net/ubuntu/+source/broadcom-sta/+bug/1343151 old, ignored bug], you won&#039;t find any wifi networks. This is because the driver from Broadcom apparently does not support interrupt remapping, commonly used on x64 machines. To turn this off, change &#039;&#039;&#039;/etc/default/grub&#039;&#039;&#039; and change the line &#039;&#039;&#039;GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;quiet splash&amp;quot;&#039;&#039;&#039;, adding intremap=off to the end before the quote: &#039;&#039;&#039;GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;quiet splash intremap=off&amp;quot;&#039;&#039;&#039;. Save the file and run &#039;&#039;&#039;sudo update-grub&#039;&#039;&#039; and reboot. After this, wifi should work well.&lt;br /&gt;
&lt;br /&gt;
== Wifi with HP Compaq Presario CQ57 on Ubuntu ==&lt;br /&gt;
&lt;br /&gt;
The HP Compaq Presario CQ57 uses the RT5390 wifi chipset. This has been supported for quite some time now, and I was quite surprised to find it not working on a laptop a friend was having. The driver loaded correctly, but Ubuntu insisted of the laptop being in &#039;&#039;&#039;flight mode&#039;&#039;&#039;. Checking &#039;&#039;&#039;rfkill&#039;&#039;&#039;, it showed me two NICs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# rfkill list all&lt;br /&gt;
0: phy0: Wireless LAN&lt;br /&gt;
	Soft blocked: no&lt;br /&gt;
	Hard blocked: yes&lt;br /&gt;
1: hp-wifi: Wireless LAN&lt;br /&gt;
	Soft blocked: yes&lt;br /&gt;
	Hard blocked: no&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Turning rfkill on and off resulted in nothing much, except some error messages in the kernel log (dmesg)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] ACPI Error: Field [B128] at bit offset/length 128/1024 exceeds size of target Buffer (160 bits) (20170831/dsopcode-235)&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]&lt;br /&gt;
                            Initialized Local Variables for Method [HWCD]:&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Local0: 00000000a34b7928 &amp;lt;Obj&amp;gt;           Integer 0000000000000000&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Local1: 00000000b0aa6865 &amp;lt;Obj&amp;gt;           Buffer(8) 46 41 49 4C 04 00 00 00&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Local5: 00000000a9811efd &amp;lt;Obj&amp;gt;           Integer 0000000000000004&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] Initialized Arguments for Method [HWCD]:  (2 arguments defined for method invocation)&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Arg0:   0000000078957d1b &amp;lt;Obj&amp;gt;           Integer 0000000000000001&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Arg1:   00000000725c9c6e &amp;lt;Obj&amp;gt;           Buffer(20) 53 45 43 55 02 00 00 00&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] ACPI Error: Method parse/execution failed \_SB.WMID.HWCD, AE_AML_BUFFER_LIMIT (20170831/psparse-550)&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] ACPI Error: Method parse/execution failed \_SB.WMID.WMAD, AE_AML_BUFFER_LIMIT (20170831/psparse-550)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After upgrading BIOS and testing different kernels, I was asked to try to unload the &#039;&#039;&#039;hp_wmi&#039;&#039;&#039; driver. I did, and things changed a bit, so I tried blacklisting it, creating the file &#039;&#039;&#039;/etc/modprobe.d/blacklist-hp_wmi.conf&#039;&#039;&#039; with the following content&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Blacklist this - it doesn&#039;t work!&lt;br /&gt;
blacklist hp_wmi&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
I gave the machine a reboot and afte that, the &#039;&#039;&#039;hp-wifi&#039;&#039;&#039; entry was gone in the rfkill output, and things works.&lt;br /&gt;
&lt;br /&gt;
= Raspberry pi =&lt;br /&gt;
&lt;br /&gt;
I couldn&#039;t quite decide if the raspberry pi should be a separate section or part of Linux, but hell, it can run more than Linux, although 99,lots% of people just uses Linux on them. This is a small list of things to know about them; things not on the front page of the manual or perhaps hidden even better.&lt;br /&gt;
&lt;br /&gt;
== Which pi? ==&lt;br /&gt;
&lt;br /&gt;
I just setup three raspberry pi machines and although some are quite different, like v1 to vEverythingelse or the Pi zero versions to the normal ones, not all of us remember how to distinguish between them, and sometimes they&#039;re in a nice 3d printed (or otherwise) chassis or otherwise hidden. So, how to check three different ones:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
root@home-assistant:~ $ cat /proc/device-tree/model ; echo&lt;br /&gt;
Raspberry Pi 2 Model B Rev 1.1&lt;br /&gt;
&lt;br /&gt;
root@green-pi:~ $ cat /proc/device-tree/model ; echo&lt;br /&gt;
Raspberry Pi 3 Model B Rev 1.2&lt;br /&gt;
&lt;br /&gt;
roy@yellow-pi:~ $cat /proc/device-tree/model ; echo&lt;br /&gt;
Raspberry Pi 4 Model B Rev 1.1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
While this works well, for the latter, the pi4, it doesn&#039;t tell how much memory I have. It comes in variants of 1, 2 and 4GB, and this is the latter.&lt;br /&gt;
&lt;br /&gt;
== Monitoring ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;vcgencmd&#039;&#039;&#039; from &#039;&#039;&#039;/opt/vc/bin&#039;&#039;&#039;, but symlinked to &#039;&#039;&#039;/usr/bin&#039;&#039;&#039; so it&#039;s available in path, is useful for fetching hardware info about the pi. For example, measuring the temperature&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
root@yellow-pi:~# vcgencmd measure_temp&lt;br /&gt;
temp=63.0&#039;C&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The command is generally badly documented and parts of it seems outdated for newer hardware. Here&#039;s the output from a Raspberry pi 4 with 4GB RAM&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
roy@yellow-pi:~ $ vcgencmd get_mem arm&lt;br /&gt;
arm=948M&lt;br /&gt;
roy@yellow-pi:~ $ vcgencmd get_mem gpu&lt;br /&gt;
gpu=76M&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== BIOS upgrade from Linux ==&lt;br /&gt;
&lt;br /&gt;
Generally, BIOS upgrades have been moved to the BIOS itself these days. This saves a lot of work and quite possibly lives after those who earier rammed their heads through walls, now can upgrade directly from the internet instead of using obscure operating systems best avoided. Sometimes, however, one must use these nevertheless. This is a quick run-through on your options.&lt;br /&gt;
&lt;br /&gt;
=== DOS ===&lt;br /&gt;
&lt;br /&gt;
Most non-automatic BIOS upgrades are installed from DOS. Doing a BIOS upgrade this way, is generally non-problematic. Just install a USB thingie with [https://www.freedos.org/ FreeDOS], copy your file(s) onto the thing and boot on it. The commandline is the same as old MS/DOS, except a wee bit more userfriendly, but not a lot.&lt;br /&gt;
&lt;br /&gt;
=== Windows ===&lt;br /&gt;
&lt;br /&gt;
Some macahines, like laptops from &#039;&#039;&#039;HP&#039;&#039;&#039;, may have BIOS upgrades that are made to be installed from Windows and won&#039;t run in FreeDOS or MS/DOS, instead throwing an error, saying &#039;&#039;&#039;This program cannot be run in DOS mode&#039;&#039;&#039;. This means you&#039;ll have to boot on a Windows rescue disc and do the job from there. Googling this, tells you it&#039;s quite easy, you just choose &#039;make rescue disc&#039; from Windows, and it&#039;s all good, except if you don&#039;t run Windows, that is. To remedy this problem, do as follows:&lt;br /&gt;
&lt;br /&gt;
==== Download Windows ====&lt;br /&gt;
&lt;br /&gt;
Since you don&#039;t run Windows and possibly don&#039;t have a spouse or friend around with such unhealthy habits either, you need to get it. It&#039;s quite easy - just google &#039;download windows&#039; and it&#039;ll send you to [https://www.microsoft.com/en-us/software-download/windows10ISO somewhere like this].&lt;br /&gt;
&lt;br /&gt;
==== Burn it! ====&lt;br /&gt;
&lt;br /&gt;
Now it&#039;s time to burn the installer on a DVD ROM. You&#039;ll need a double-layered one, since the OS is &amp;gt; 4.7GiB, but I&#039;m sure you have a ton of those lying around. Now, just place your optical medium in your optical drive and burn, baby, burn!&lt;br /&gt;
&lt;br /&gt;
==== Or make a USB thing? ====&lt;br /&gt;
&lt;br /&gt;
Not a lot of machines have optical drives these days, so you may want to use an USB pen drive or something instead. This is easy, just make the USB bootable with the Windows application Microsoft has made for this. Unfortunately, this only runs on Windows, and unlike stuff like Debian, where the &#039;&#039;&#039;iso&#039;&#039;&#039; file can be dd&#039;ed directly onto a USB drive to make it bootable, the Windows &#039;&#039;&#039;iso&#039;&#039;&#039;s don&#039;t come with this luxury. There are lots of methods to make bootable USB things from iso files out there, but the only thing most of them have in common, is that they generally don&#039;t work.&lt;br /&gt;
&lt;br /&gt;
===== WoeUSB =====&lt;br /&gt;
&lt;br /&gt;
After hours of swearing, it&#039;s nice to come across software like [https://github.com/slacka/WoeUSB WoeUSB]. It may not be perfect, it relies on a bunch of GUI stuff you&#039;ll never need and so on, but it &#039;&#039;&#039;&#039;&#039;works&#039;&#039;&#039;&#039;&#039;, and that&#039;s the important part! Just clone the repo and RTFM and it&#039;s all nice. It&#039;s slow, but hell, getting a windows machine and/or an optical drive might be slower.&lt;br /&gt;
&lt;br /&gt;
WoeUSB does nothing fancy, but it &#039;&#039;&#039;does&#039;&#039;&#039; work. It will create a filesystem, FAT32 or NTFS (better use NTFS, FAT32 has its limits). It creates normal filesystems and so on. Just make sure to copy in the BIOS update file, usually an exe file, to run when Windows is up and running.&lt;br /&gt;
&lt;br /&gt;
===== Install BIOS =====&lt;br /&gt;
&lt;br /&gt;
Boot on the Windows USB thing and choose &#039;repair computer&#039; and then &#039;command prompt&#039;. Find the install file, and if you&#039;re lucky, you&#039;ll find it needs a 32bit OS, just like I did. Since the 64bit version doesn&#039;t include 32bit compatibility in the installer, revert to downloading the 32bit version of windows and start over. Pray to your favourite god(s) not to get across such machines again - it might help.&lt;br /&gt;
&lt;br /&gt;
= 3D printer stuff =&lt;br /&gt;
&lt;br /&gt;
== Hydrophilic filament ==&lt;br /&gt;
&lt;br /&gt;
Most popular filament types, including PLA, PETG, PP or PA (Polyamide, normally known as Nylon) and virtualy any filament type named [https://www.matterhackers.com/news/filament-and-water poly-something] (and thus with an acronym of P-something) are hydrophilic (also (somewhat incorrectly) called hydroscopic), meaning so long they&#039;re dryer than the atmosphere around them, they&#039;ll do their best to suck out the atmosphere&#039;s humidity. This is why most filament are shrink-wrapped with a small bag of silica gel in it. If such filament is exposed for normal humid air for some time, it&#039;ll become very hard to use. Most of my experience is with PLA, which can handle a bit (depending on make), but still not a lot. With PLA, if you end up with prints where the filament seems not to stick, it may help with a higher temperature. Otherwise, the filament must be [https://all3dp.com/2/how-to-dry-filament-pla-abs-and-nylon/ baked]. If you don&#039;t want to use your oven, try something like a [https://www.jula.no/catalog/hjem-og-husholdning/kjokkenmaskiner/mattilberedningsapparater/frukt-sopptorker/frukt-sopptorker-001641/#tab02 fruit and mushroom dryer]. Then get a good, sealble plastic box and add something like half a kilogram of [https://www.ebay.com/sch/sis.html?_nkw=1KG+Orange+Replacement+Desiccant+Indicating+Silica+Gel+Beads+for+Drawers%2C+Camera&amp;amp;_id=131938742628&amp;amp;&amp;amp;_trksid=p2057872.m2749.l2658 silica gel] to an old sock, tie it and put it in the your new dry box.&lt;br /&gt;
&lt;br /&gt;
Please note that ABS is hydrophobic, so you won&#039;t have to worry too much there. Also, remember that PA/Nylon is extremely hydrophilic. Even a couple of days in normal air humidity can ruin it completely and will require baking.&lt;br /&gt;
&lt;br /&gt;
== Upgrading the firmware on an Ender 3 ==&lt;br /&gt;
&lt;br /&gt;
This is about upgrading the firmware, and thus also flashing a bootloader to the Creality Ender 3 3D printer. Most of this is well documented on several place, like o [https://www.youtube.com/watch?v=fIl5X2ffdyo the video from Teaching tech] and elsewhere, but I&#039;ll just summarise some issues I had.&lt;br /&gt;
&lt;br /&gt;
=== Using an arduino Nano as a programmer ===&lt;br /&gt;
&lt;br /&gt;
Quick note before you read on. If you have an Ender 3 controller version 1.1.5 or newer (or perhaps even a bit older), an CR-10S or some other more or less modern printers or controllers, they come with a bootloader installed already, so don&#039;t bother flashing one. The one that&#039;s in there already, should work well. So if you have one of these, just skip this and jump to the [[Roy&#039;s_notes#Flashing_the_printer|next section]].&lt;br /&gt;
&lt;br /&gt;
However, the normal CR-10 (without the S), Ender 3 and a few other printers from Creality come without a bootloader, so you&#039;ll need to flash one before upgrading the firmware. Well, strictly speakning, you don&#039;t need one, you can save those 8kB or so for other stuff and use a programmer to write the whole firmware, but then you&#039;ll need to wire up everything every time you want a new firmware, so in my world, you &#039;&#039;&#039;do&#039;&#039;&#039; need the bootloader, since it&#039;s easier.&lt;br /&gt;
&lt;br /&gt;
To install a bootloader, you&#039;ll need a programmer, and I didn&#039;t have one available. Having some el-cheapo china-copies of Ardinos around, I read I could use one and tried so. Although the docs mostly mention the Uno etc, it&#039;s just as simple with the Nano copy.&lt;br /&gt;
&lt;br /&gt;
So, grab an arduino, plug it to your machine with a USB cable, and, using the Arduino IDE, use the ArduinoISP sketch there (found under Examples) to burn the software needed for the arduino to work as a programmer. When this is done, connect a 10µF capacitor between RST and GND to stop it from resetting when used as a programmer. Connect the MOSI, MISO and SCK pins from the ICSP block (that little isolated 6-pin block on top of the ardu). See [https://www.arduino.cc/en/Tutorial/ArduinoISP here] for a pinout. Then find Vcc and GND either on the ICSP block or elsewhere. Some sites say that on some boards you shouldn&#039;t use the pins on the ICSP block for this. I doubt it matters, though. Then connect another jumper wire from pin 10 on the ardu to work as the reset pin outwards to the chip being programmed (that is, on the printer). The ICSP jumper block pin layout is the same on the printer and on the ardu, and probably elsewhere. Sometimes [https://xkcd.com/927/ standardisation] actually works…&lt;br /&gt;
&lt;br /&gt;
See https://cloud.karlsbakk.net/index.php/s/zw48YJjzaf8Rc2F for a pic with the ardu (this wiki is broken atm, will fix it later)&lt;br /&gt;
&lt;br /&gt;
== Flashing the printer ==&lt;br /&gt;
&lt;br /&gt;
When the boot loader is in place, possibly after some wierd errors from during the process, the screen on the 3d printer will go blank and it&#039;ll behave like being bricked. This is ok. Now disconnect the wires and connect the USB cable between computer and printer. If you haven&#039;t installed support for the Sanguino board, that is, the variant of the 1284-chip and surrounding electronics that is the core of the, you need to install it first. In the Arduino IDE, choose the Tools / Boards / Boards manager boot option and search for Sanguino. After this, you should find the Sanguino or Sanguino 1284p in the boards menu. After this, you should be able to communicate with the printer&#039;s controller. Download the [https://www.th3dstudio.com/knowledgebase/th3d-unified-firmware-package/ TH3D unified firmware], making sure it&#039;s the last version. Uncompress the zip and with Finder/Explorer/whateversomething&#039;scalledonlinux, browse to &#039;&#039;&#039;TH3DUF_R2/Firmware/TH3DUF_R2.ino&#039;&#039;&#039; and open it. It should open directly in the Android IDE. Keep in mind that the names TH3DUF_R2 and TH3DUF_R2.ino will vary between versions, but you get the point. Now configure it for your particular needs. You&#039;ll find most of this in the Configuration.h tab (that&#039;s really a file). Most of the other files won&#039;t be necessary unless you&#039;re doing some more advanced stuff, like replacing th controller with something non-standard or similar, but then again, that&#039;s another chapter (or book, even). The video mentioned above describes this well. After flashing the new firmware, you&#039;ll probably get some timeouts and errors, since apparently it resets the printer after giving it the new firmware, but without notifying the flashing software of it doing so. If this happens, calm down and reboot the printer and check its tiny monitor - it should work. If it doesn&#039;t work, and if you flashed the bootload yourself, try to flash it again, and if that doesn&#039;t work, try flashing the programmer again yet another time, just for kicks. Again, if you have a newer controller like the v1.1.5, don&#039;t touch the bootloader, as the one already installed, should work well as it is.&lt;br /&gt;
&lt;br /&gt;
PS: I tried enabling &#039;&#039;&#039;MANUAL_MESH_LEVELING&#039;&#039;&#039;, which in the code says that &#039;&#039;If used with a 1284P board the bootscreen will be disabled to save space&#039;&#039;. This effectively disabled the whole printer, and apparently may be making the firmware image a wee bit too large for it to fit the 1284P on the ender. It works well without it, though.&lt;br /&gt;
&lt;br /&gt;
== And then… ==&lt;br /&gt;
&lt;br /&gt;
With the new firmware in place, the printer should work as before, although with thermal runaway protection to better avoid fires in case the shit hits the fan, and to allow for things like autolevelling. With any luck, [https://www.precisionpiezo.co.uk/ this thing] may be ready for use by the time you read this - it surely looks nice!&lt;br /&gt;
&lt;br /&gt;
roy&lt;/div&gt;</summary>
		<author><name>Roy</name></author>
	</entry>
	<entry>
		<id>https://wiki.malinux.no/index.php?title=Roy%27s_notes&amp;diff=159</id>
		<title>Roy&#039;s notes</title>
		<link rel="alternate" type="text/html" href="https://wiki.malinux.no/index.php?title=Roy%27s_notes&amp;diff=159"/>
		<updated>2020-05-22T01:55:37Z</updated>

		<summary type="html">&lt;p&gt;Roy: /* Using an arduino Nano as a programmer */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= LVM, md and friends =&lt;br /&gt;
&lt;br /&gt;
== Linux&#039; Logical Volume Manager (LVM) ==&lt;br /&gt;
&lt;br /&gt;
=== LVM in general ===&lt;br /&gt;
&lt;br /&gt;
LVM is designed to be an abstraction layer on top of physical drives or RAID, typically [https://raid.wiki.kernel.org/index.php/RAID_setup mdraid] or [https://help.ubuntu.com/community/FakeRaidHowto fakeraid]. Keep in mind that fakeraid should be avoided unless you really need it, like in conjunction with dual-booting linux and windows on fakeraid. LVM broadly consists of three elements, the &amp;quot;physical&amp;quot; devices (PV), the volume group (VG) and the logical volume (LV). There can be multiple PVs, VGs and LVs, depending on requirement. More about this below. All commands are given as examples, and all of them can be fine-tuned using extra flags in need of so. In my experience, the defaults work well for most usecases.&lt;br /&gt;
&lt;br /&gt;
I&#039;m mentioning filesystem below too. Where I write ext4, the samme applies to ext2 and ext3.&lt;br /&gt;
&lt;br /&gt;
==== Create a PV ====&lt;br /&gt;
&lt;br /&gt;
A PV is the &amp;quot;physical&amp;quot; parts. This does not need to be a physical disk, but can also be another RAID, be it an mdraid, fakeraid, hardware raid, a virtual disk on a SAN or otherwisee or a partition on one of those. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#  These add three PVs, one on a drive (or hardware raid) and another two on mdraids.&lt;br /&gt;
pvcreate /dev/sdb&lt;br /&gt;
pvcreate /dev/md1 /dev/md2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For more information about pvcreate, see [https://linux.die.net/man/8/pvcreate the manual].&lt;br /&gt;
&lt;br /&gt;
==== Create a VG ====&lt;br /&gt;
&lt;br /&gt;
The volume group consists of one or more PVs grouped together on which LVs can be placed. If several PVs are grouped in a VG, it&#039;s generally a good idea to make sure these PVs have some sort of redundancy, as in mdraid/fakeraid or hwraid. Otherwise it will be like using a [https://en.wikipedia.org/wiki/RAID RAID-0] with a single point of failure on each of the independant drives. LVM has [https://unix.stackexchange.com/questions/150644/raiding-with-lvm-vs-mdraid-pros-and-cons  RAID code in it] as well, so you can use that. I haven&#039;t done so myself, as I generally stick to mraid. The reason is mdraid is, in my opinion older and more stable and has more users (meaning bugs are reported and fixed faster whenever they are found). That said, I beleive the actual RAID code used in LVM RAID are the same function calls as for mdraid, so it may not be much of a difference. I still stick with mdraid. To create a VG, run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create volume group my_vg&lt;br /&gt;
vgcreate my_vg /dev/md1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that if vgcreate is run with a PV (as /dev/md1 above) that is not defined as a PV (like above), this is done implicitly, so if you don&#039;t need any special flags to pvcreate, you can simply skip it and let vgcreate do that for you.&lt;br /&gt;
&lt;br /&gt;
==== Create an LV ====&lt;br /&gt;
&lt;br /&gt;
LVs can be compared to partitions, somehow, since they are bounderies of a fraction or all of that of a VG. The difference between them and a partition, however, is that they can be grown or shrunk easily and also moved around between PVs without downtime. This flexibility makes them superiour to partitions as your system can be changed without users noticing it. By default, an LV is alloated &amp;quot;thickly&amp;quot;, meaning all the data given to it, is allocated from the VG and thus the PV. The following makes a 100GB LV named &amp;quot;thicklv&amp;quot;. When making an LV, I usually allocate what&#039;s needed plus some more, but not everything, just to make sure it&#039;s space available for growth on any of the LVs on the VG, or new LVs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a thick provisioned LV named thicklv on the VG my_vg&lt;br /&gt;
lvcreate -n thicklv -L 100G my_vg&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After the LV is created, a filesystem can be placed on it unless it is meant to be used directly. The application for direct use include swap space, VM storage and certain database systems. Most of these will, however, work on filesystems too, although my testing has shown that on swap space, there is a significant performance gain for using dedicated storage without a filesystem. As for filesystems, most Linux users use either ext4 or xfs. Personally, I generally use XFS these days. See my notes below on filesystem choice.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a filesystem on the LV - this could have been mkfs -t ext4 or whatever filesystem you choose&lt;br /&gt;
mkfs -t xfs /dev/my_vg/thicklv&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then just edit /etc/fstab with correct data and run mount -a, and you should be all set.&lt;br /&gt;
&lt;br /&gt;
==== Create LVM cache ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
lvcreate -L 1G -n _cache_meta data /dev/md1&lt;br /&gt;
&lt;br /&gt;
lvcreate -l100%FREE -n _cache data /dev/md1&lt;br /&gt;
&lt;br /&gt;
# Some would want --cachemode writeback, but seriously, I wouldn&#039;t recommend it. Metadata or data can be easily corrupted in case of failure.&lt;br /&gt;
lvconvert --type cache-pool --cachemode writethrough --poolmetadata data/_cache_meta data/_cache&lt;br /&gt;
&lt;br /&gt;
lvconvert --type cache --cachepool data/_cache data/data&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Disabling LVM cache ====&lt;br /&gt;
&lt;br /&gt;
If you for some reason want to disable caching, this will do it cleanly and remove the LVs earlier created for caching the main device.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
lvconvert --uncache data/data&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Growing devices ====&lt;br /&gt;
&lt;br /&gt;
LVM objects can be grown and shrunk. If a PV resides on a RAID where a new drive has been added or otherwise grown, or on a partition or virtual disk that has been extended, the PV must be updated to reflect these changes. The following command will grow the PV to the maximum available on the underlying storage. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Resize the PV /dev/md (not the RAID, only the PV on the RAID) to its full size&lt;br /&gt;
pvresize /dev/md1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If a new PV is added, the VG can be grown to add the space on that in addition to what&#039;s there already. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Extend my_vg to include md2 and its space&lt;br /&gt;
vgextend my_vg /dev/md2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
With more space available in the VG, the LV can now be extended. Let&#039;s add another 50GB to it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Extend thicklv - add 50GB. If you know you won&#039;t need the space anywhere else, you may want to&lt;br /&gt;
# lvresize -l+100%FREE instead. Keep in mind the difference between -l (extents) and -L (bytes)&lt;br /&gt;
lvresize -L +50G my_vg/thicklv&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Growing filesystems ====&lt;br /&gt;
After the LV has grown, run &#039;&#039;xfs_growfs&#039;&#039; (xfs) or &#039;&#039;resize2fs&#039;&#039; (ext4) to make use of the new data. To grow the filesystem to all available space on ext4, run the below command.  To partly grow the filesystem or to shrink it or otherwise, please see the manuals.&lt;br /&gt;
&lt;br /&gt;
The filesystem can be mounted when this is run. If you for some reason get an &#039;&#039;&#039;access denied&#039;&#039;&#039; error when running this as root or with sudo, it&#039;s likely caused by a filesystem error. To fix this, unmount the filesystem first and run &#039;&#039;&#039;fsck -f /dev/my_vg/thicklv&#039;&#039;&#039; and remount it before retrying to extend it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
resize2fs /dev/my_vg/thicklv&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Similarly, with XFS, but note that xfs_growfs doesn&#039;t take the device name, but the filesystem&#039;s mount point. In the case of XFS, also note that the filesystem &#039;&#039;&#039;&#039;&#039;must&#039;&#039;&#039;&#039;&#039; be mounted to be grown. This, in contrast to how it was in the old days when filesystems had to be unmounted to be grown.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
xfs_growfs /my_mountpoint&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Rename system VG ====&lt;br /&gt;
&lt;br /&gt;
Some distros create VG names like those-from-a-sysadmin-with-a-well-developed-paranoia-not-to-hit-a-duplicate. Debian, for instance, uses names like &amp;quot;my-full-hostname-vg&amp;quot;. Personally, I don&#039;t like these, since if I were to move a disk or vdisk around to somewhere else, I&#039;d make sure not to add a disk named &#039;sys&#039; to an existing system. If you do, most distros will refuse to use the VGs with duplicate names, resulting in the OS not booting until either one is specified by its UUID or just one removed. As I&#039;m aware of this, I stick to the super-risky thing of all system VGs named &#039;sys&#039; and so on.&lt;br /&gt;
&lt;br /&gt;
If you do this, keep in mind that it may blow up your computer and take your girl- or boyfriend with it or even make either of them pregnant, allowing Trump to rule your life and generally make things suck. You&#039;re on your own!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Rename the VG&lt;br /&gt;
vgrename my-full-hostname-vg sys&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, in /boot/grub/grub.cfg, change the old lv path from something like &#039;/dev/mapper/debian--stretch--machine--vg-root&#039; to your new and fancy &#039;/dev/sys/root. Likewise, in /etc/fstab, change occurences of &#039;/dev/mapper/debian--stretch--machine--vg-&#039; (or similar) with &#039;/dev/sys/&#039;. Here, this was like this - the old ones commented out.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;fstab&amp;quot;&amp;gt;&lt;br /&gt;
#/dev/mapper/debian--stretch--box--vg-root      /               ext4            errors=remount-ro,discard       0       1&lt;br /&gt;
/dev/sys/root                                   /               ext4            errors=remount-ro,discard       0       1&lt;br /&gt;
# /boot was on /dev/vda1 during installation&lt;br /&gt;
UUID=myverylonguuidwithatonofgoodinfoinit       /boot           ext2            defaults                        0       2&lt;br /&gt;
#/dev/mapper/debian--stretch--box--vg-swap_1    none            swap            sw                              0       0&lt;br /&gt;
/dev/sys/swap_1                                 none            swap            sw                              0       0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Update /etc/initramfs-tools/conf.d/resume with similar data for swap.&lt;br /&gt;
&lt;br /&gt;
You might want to run &#039;update-initramfs -u -k all&#039; after this, but I&#039;m not sure if it&#039;s needed.&lt;br /&gt;
&lt;br /&gt;
Now, pray to the nearest god(s) and give it a reboot and it should (probably) work.&lt;br /&gt;
&lt;br /&gt;
After reboot, run &#039;&#039;&#039;swapoff -a&#039;&#039;&#039;, then &#039;&#039;&#039;mkswap /dev/sys/swap_1&#039;&#039;&#039; (or whatever it&#039;s called on your system) and &#039;&#039;&#039;swapon -a&#039;&#039;&#039; again. You may want to give it another reboot or two for kicks, but it should work well even without that.&lt;br /&gt;
&lt;br /&gt;
=== Migration tools ===&lt;br /&gt;
&lt;br /&gt;
At times, storage regimes change, new storage is added and sometimes it&#039;s not easy to migrate with the current hardware or its support systems. Once I had to migrate a 45TiB fileserver from one storage system to another, preferably without downtime. The server originally had three 15TiB PVs of which two were full and the third half full. I resorted to using [https://linux.die.net/man/8/pvmove pvmove] to just move the data on the PVs in use to a new PV. We started out with creating a new 50TiB PV, sde, and then to pvmove.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Attach /dev/sde to the VG my_vg&lt;br /&gt;
vgextend my_vg /dev/sde&lt;br /&gt;
&lt;br /&gt;
# Move the contents from /dev/sdb over to /dev/sde block by block. If a target is not given in pvmove,&lt;br /&gt;
# the contents of the source (sdb here) will be put somewhere else in the pool.&lt;br /&gt;
pvmove /dev/sdb /dev/sde&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This took a while (as in a week or so) - the pvmove command uses old code and logic (or at least did that when I migrated this in November 2016), but it affected performance on the server very little, so users didn&#039;t notice. After the first PV was migrated, I continued with the other two, one after the other, and after a month or so, it was migrated. We used this on a number of large fileservers, and it worked flawlessly. Before doing the production servers I also tried interrupting pvmove in various ways, including hard resets, and it just kept on after the reboot.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;NOTE:&#039;&#039;&#039;&#039;&#039; &#039;&#039;Even though it worked well for us, &#039;&#039;&#039;always&#039;&#039;&#039; keep a good backup before doing this. Things may go wrong, and without a good backup, you may be looking for a hard-to-find new job the next morning&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
==== mdadm workarounds ====&lt;br /&gt;
&lt;br /&gt;
===== Migrate from a mirror (raid-1) to raid-10 =====&lt;br /&gt;
&lt;br /&gt;
Create a mirror&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sdb /dev/sdc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
LVM (pv/vg/lv) on md0 (see above), put a filesystem on the lv and fill it with some data.&lt;br /&gt;
&lt;br /&gt;
Now, some months later, you want to change this to raid-10 to allow for the same amount of redundancy, but to allow more disks into the system.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mdadm --grow /dev/md0 --level=10&lt;br /&gt;
mdadm: Impossibly level change request for RAID1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So - no - doesn&#039;t work. But - we&#039;re on &lt;br /&gt;
&lt;br /&gt;
Since we&#039;re on lvm already, this&#039;ll be easy. If you&#039;re using filesystems directly on partitions, you can do this the same way, but without the pvmove part, using rsync or whateever you like instead. I&#039;d recommend using lvm for for the new raid, which should be rather obvious from this article. Now plug in a new drive and create a new raid10 on that one. If you two new drives, install both. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# change &amp;quot;missing&amp;quot; to the other device name if you installed two new drives&lt;br /&gt;
mdadm --create /dev/md1 --level=10 --raid-devices=2 /dev/vdd missing&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, as described above, just vgextend the vg, adding the new raid and run pvmove to move the data from the old pv (residing on the old raid1) to the new pv (on raid10). Afte rpvmove is finished (which may take awile, see above), just&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
vgreduce raidtest /dev/md0&lt;br /&gt;
pvremove /dev/md0&lt;br /&gt;
mdadm --stop /dev/md0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
…and your disk is free to be added to the new array. If the new raid is running in degraded mode (if you created it with just one drive), better don&#039;t wait too long, since you don&#039;t have redundancy. Just mdadm --add the devs.&lt;br /&gt;
&lt;br /&gt;
If you now have /dev/mdstat telling you your raid10 is active and have three drives, of which one is a spare, it should look something like this&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5] [raid4] [raid10]&lt;br /&gt;
md1 : active raid10 vdc[3](S) vdb[2] vdd[0]&lt;br /&gt;
      8380416 blocks super 1.2 2 near-copies [2/2] [UU]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Just mdadm --grow --raid-devices=3 /dev/md1&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;RAID section is not complete. I&#039;ll write more on migraing from raid10 to raid6 later. It&#039;s not straight forward, but easier than this one :)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== Thin provisioned LVs ===&lt;br /&gt;
&lt;br /&gt;
Thin provisioning on LVM is a method used for not allocating all the space given to an LV. For instance, if you have a 1TB VG and want to give an LV 500GB, although it currently only uses a fraction of that, a thin lv can be a good alternative. This will allow for adding a limit to how much it can use, but also to let it grow dynamically without manual work by the sysadmin. Thin provisioning adds another layer of abstaction by creating a special LV as a &#039;&#039;thin pool&#039;&#039; from which data is allocated to the &#039;&#039;thin volume(s)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== Create a thin pool ====&lt;br /&gt;
&lt;br /&gt;
Allocate 1TB to the thin pool to be used for thinly provisioned LVs. Keep in mind that the space allocated to the thin pool is in fact thick provisioned. Only the volumes put on &#039;&#039;thinpool&#039;&#039; are thin provisioned. This will create two hidden LVs, one for data and one for metadata. Normally the defaults will do, but check the manual if the data doesn&#039;t match the usual patterns (such as billions of files, resulting in huge amounts of metadata). I &#039;&#039;beleive&#039;&#039; the metadata part should be resizable at a later time if needed, but I have not tested it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a pool for thin LVs. Keep in mind that the pool itself is not thin provisioned, only the volumes residing on it&lt;br /&gt;
lvcreate --size 1T --type thin-pool --thinpool thinpool my_vg&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Create a thin volume ====&lt;br /&gt;
&lt;br /&gt;
You have the thinpool, now put a thin volume on it. It will allocate some space for metadata, but probably not much (a few megs, perhaps).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Now, create a volume with a virtual (-V) size of half a terabyte named thin_pool, but using the thinpool (-T) named thin_pool for storage&lt;br /&gt;
lvcreate -V 500G -T my_vg/thin_pool --name thinvol&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The new volume&#039;s device name will be /dev/thinvol. Now, create a filesystem on it, add to fstab and mount it. The &#039;&#039;&#039;df&#039;&#039;&#039; command will return available space according to the virtual size (-V), while lvs will show how much data is actually used on each of the thinly provisioned volumes.&lt;br /&gt;
&lt;br /&gt;
== Filesystem dilemmas ==&lt;br /&gt;
&lt;br /&gt;
=== XFS or ext4 or something else ===&lt;br /&gt;
The choice of filesystem varies for your use. Distros such as RHEL/CentOS has moved to XFS by default from v7. Debian/Ubuntu still sticks to ext4, like most other. I&#039;ll discuss my thoughts below on ext4 vs XFS and leave the other filesystems for later.&lt;br /&gt;
&lt;br /&gt;
==== ext4 ====&lt;br /&gt;
ext4 is probably the most used filesystem on linux as of writing. It&#039;s rock stable and has been extended by a lot of extensions since the original ext2. It still retains backward compatibility, being able to mount and fsck ext2 and ext3 with the ext4 driver. However, it doesn&#039;t handle large filesystems very well. If a filesystem is created for &amp;lt;16TiB, it cannot be grown to anything larger than 16TiB. This may have changed lately, though. One other issue is handling errors. If a large filesystem (say 10TiB) is damaged, an fsck may take several hours, leading to long downtime. When I refer to ext4 further in this text, the same applies to ext2 and ext3 unless otherwise specified.&lt;br /&gt;
&lt;br /&gt;
==== XFS ====&lt;br /&gt;
XFS, originally developed by SGI some time in the bronze age, but has been worked on heavily after that. RHEL and Centos version 7 and forward, uses XFS as the default filesystem. It is quick, it scales well, but it lacks at least two things ext4 has. It cannot be shrunk (not that you normally need that, but nice if you have a typo or you need to change things). Also, it doesn&#039;t allow for automatic fsck on bootup. If something is messed up on the filesystem, you&#039;ll have to login as root on the console (not ssh), which might be an issue on some systems. The fsck equivalent, xfs_repair, is a *lot* faster than ext4&#039;s fsck, though.&lt;br /&gt;
&lt;br /&gt;
==== ZFS ====&lt;br /&gt;
ZFS is like a combination of RAID, LVM and a filesystem, supporting full checksumming, auto-healing (given sufficient redundancy), compression, encryption, replication, deduplication (if you&#039;re brave and have a &#039;&#039;ton&#039;&#039; of memory) and a lot more. It&#039;s a separate chapter and needs a lot more talk than paragraph here.&lt;br /&gt;
&lt;br /&gt;
==== btrfs ====&lt;br /&gt;
btrfs, pronounced &amp;quot;butterfs&amp;quot; or &amp;quot;betterfs&amp;quot; or just spelled out, is a filesystem that mimics that of ZFS. It has been around for 10 years or so, but hasn&#039;t yet proven to be really stable. Following the progress of it for those years, I&#039;ve found it to be a nice toy with which to play, but not to be used in production. Again, others may say otherwise, but these are just my words.&lt;br /&gt;
&lt;br /&gt;
== Low level disk handling ==&lt;br /&gt;
&lt;br /&gt;
This section is for low-level handling of disks, regardless of storage system elsewhere. These apply to mdraid, lvmraid and zfs and possibly other solutions, with the exception of individual drives on hwraid (and maybe fakeraid), since there, the drives are hidden from Linux (or whatever OS).&lt;br /&gt;
&lt;br /&gt;
=== S.M.A.R.T. and slow drives ===&lt;br /&gt;
Modern (that is, from about 1990 or later) have S.M.A.R.T. (or just smart, since it&#039;s easier to type) monitoring built in, meaning the disk&#039;s controller is monitoring itself. This is handy and will ideally tell you in advance that a drive is flakey or dying. Modern (2010+) smart monitoring is more or less the same. It can be trusted about 50% of the time. Usually, if smart detects an error, it&#039;s a real error. I don&#039;t think I&#039;ve seen it reporting a false positive, but others may know better. &lt;br /&gt;
&lt;br /&gt;
==== smartmontools ====&lt;br /&gt;
First, install smartmontool and run smartclt -H /dev/yourdisk (/dev/sda or something) to get a health report. Then perhaps run smartctl -a /dev/yourdisk and look for &#039;current pending sectors&#039; This should be zero. Also check the temperature, which normally should be much above 50.&lt;br /&gt;
&lt;br /&gt;
==== single, slow drive ====&lt;br /&gt;
What may happen, is smart not seeing anything and life goes on like before, only slower and less prouductive, without telling anyone. If you stubler over this issue, you&#039;ll probably see it during a large rsync/zfs send/receive or a resync/rebuild/resilver of the raid/zpool. During this, it feels like everything is slow and your RAID has turned into a RAIF (redundant array of inexpensive floppies). To check if you have a single drive messing up it all, check with &#039;&#039;&#039;iostat -x 2&#039;&#039;&#039;, having 2 being the delay between each measurement. Interrupt it with ctrl+x. If there&#039;s a rougue drive there, it should stand out like sdg below&lt;br /&gt;
&lt;br /&gt;
 avg-cpu:  %user   %nice %system %iowait  %steal   %idle&lt;br /&gt;
            0.38    0.00    1.75    0.00    0.00   97.87&lt;br /&gt;
&lt;br /&gt;
 Device            r/s     w/s     rkB/s     wkB/s   rrqm/s   wrqm/s  %rrqm  %wrqm r_await w_await aqu-sz rareq-sz wareq-sz  svctm  %util&lt;br /&gt;
 sda              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdb              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdc              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdd              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sde              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdf              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdg              3.50    0.00   2352.00      0.00     0.00     0.00   0.00   0.00 14306.29    0.00  13.85   672.00     0.00 285.71 100.00&lt;br /&gt;
 sdh              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
&lt;br /&gt;
In ZFS land, you should be able to get similar data with &#039;&#039;&#039;zpool iostat -v &amp;lt;pool&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Now you know the bad drive (sdg), pull it from the raid with &#039;&#039;&#039;mdadm --fail /dev/mdX /dev/sdX&#039;&#039;&#039;. Now test the drive&#039;s performance manually, just simply:&lt;br /&gt;
&lt;br /&gt;
 # hdparm -t /dev/sdg&lt;br /&gt;
 &lt;br /&gt;
 /dev/sdg:&lt;br /&gt;
  Timing buffered disk reads:   2 MB in  5.37 seconds = 381.46 kB/sec&lt;br /&gt;
&lt;br /&gt;
Bingo - nothing you&#039;d want to keep. For a good drive, it should be something like 100-200MB/s&lt;br /&gt;
&lt;br /&gt;
PS: Keep in mind that you have a degraded RAID by now in case you had a spare waiting for things to happen.&lt;br /&gt;
&lt;br /&gt;
Try to replace the cable and/or try the disk on another port/controller. If the result from hdparm persists, it&#039;s probably a bad cable&lt;br /&gt;
&lt;br /&gt;
So, then, just psycially locate the drive, pull it out, take out the discs and magnets and recycle the rest.&lt;br /&gt;
&lt;br /&gt;
=== &amp;quot;Unplug&amp;quot; drive from system ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Find the device unit&#039;s number with something like&lt;br /&gt;
find /sys/bus/scsi/devices/*/block/ -name sdd&lt;br /&gt;
# returning /sys/bus/scsi/devices/3:0:0:0/block/sdd here, &lt;br /&gt;
# meaning 3:0:0:0 is the SCSI device we&#039;re looking for.&lt;br /&gt;
&lt;br /&gt;
# Given this is the correct device, and you want to &#039;unplug&#039; it, do so by&lt;br /&gt;
echo 1 &amp;gt; /sys/bus/scsi/devices/3:0:0:0/delete&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Rescan disk controllers ===&lt;br /&gt;
If a drive is added and for some reason doesn&#039;t get detected, or is removed by the command above, it can be rediscovered with a sysfs command to the scsi host to which it is connected. Since there may be quite a few of these, an easy way is to just scan them all and check the output of &#039;&#039;&#039;dmesg -T&#039;&#039;&#039; after running it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Make a list of controllers and send a rescan message to each of them. It won&#039;t do anything &lt;br /&gt;
# for those where nothing has changed, but it will show new drives where they have been added.&lt;br /&gt;
for host_scan in /sys/class/scsi_host/host*/scan&lt;br /&gt;
do&lt;br /&gt;
  echo &#039;- - -&#039; &amp;gt; $host_scan&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Fail injection with debugfs ===&lt;br /&gt;
[https://lxadm.com/Using_fault_injection https://lxadm.com/Using_fault_injection]&lt;br /&gt;
&lt;br /&gt;
== mdadm stuff ==&lt;br /&gt;
=== Resync ===&lt;br /&gt;
To resync a raid, that is, check, run&lt;br /&gt;
&lt;br /&gt;
 echo check &amp;gt; /sys/block/$dev/md/sync_action&lt;br /&gt;
&lt;br /&gt;
where $dev is something like md0. If you have several raids, something like this should work&lt;br /&gt;
&lt;br /&gt;
 for dev in md{0,1}&lt;br /&gt;
 do&lt;br /&gt;
   echo repair &amp;gt; /sys/block/$dev/md/sync_action&lt;br /&gt;
 done&lt;br /&gt;
&lt;br /&gt;
Also useful in a one-liner like&lt;br /&gt;
&lt;br /&gt;
 for dev in md{0,1} ; do echo repair &amp;gt; /sys/block/$dev/md/sync_action ; done&lt;br /&gt;
&lt;br /&gt;
Different raids on different drives will do this in parallel. If the drives are shared somehow with partitions or similar, the check or repair will wait for the other to finish before going on.&lt;br /&gt;
&lt;br /&gt;
As for repair vs check, [https://raid.wiki.kernel.org/index.php/RAID_Administration this article] describes it well. I stick to using repair unless it&#039;s something rare where I don&#039;t want to touch the data.&lt;br /&gt;
&lt;br /&gt;
=== Spare pools ===&lt;br /&gt;
In the old itmes, mdadm supported only a dedicated spare per md device, so if working with a large set of drives (20? 40?), where you&#039;d want to setup more raid sets to increase redundancy, you&#039;d dedicate a spare to each of the raid sets. This has changed (some time ago?), so in these modern, heathen days, you can change mdadm.conf, usually placed under /etc/mdadm, and add &#039;spare-group=somegroup&#039; where &#039;somegroup&#039; is a string identifying the spare group. After doing this, run &#039;&#039;&#039;update-initramfs -u&#039;&#039;&#039; and reboot and add a spare to one of the raid sets in the spare group, and md will use that or those spares for all the raidsets in that group.&lt;br /&gt;
&lt;br /&gt;
As some pointed out on #linux-raid @ irc.freenode.net, this feature is very badly documented, but as far as I can see, it works well.&lt;br /&gt;
&lt;br /&gt;
==== Example config ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create two raidsets&lt;br /&gt;
&lt;br /&gt;
mdadm --create /dev/md1 --level=6 --raid-devices=6 /dev/vd[efghij]&lt;br /&gt;
mdadm --create /dev/md2 --level=6 --raid-devices=6 /dev/vd[klmnop]&lt;br /&gt;
&lt;br /&gt;
# get their UUID etc&lt;br /&gt;
&lt;br /&gt;
mdadm --detail --scan&lt;br /&gt;
ARRAY /dev/md/1 metadata=1.2 name=raidtest:1 UUID=1a8cbdcb:f4092350:348b6b80:c054d74c&lt;br /&gt;
ARRAY /dev/md/2 metadata=1.2 name=raidtest:2 UUID=894b1b7c:cb7eba70:917d6033:ea5afd2b&lt;br /&gt;
&lt;br /&gt;
# Put those lines into /etc/mdadm/mdadm.conf and and add the spare-group&lt;br /&gt;
&lt;br /&gt;
ARRAY /dev/md/1 metadata=1.2 name=raidtest:1 spare-group=raidtest UUID=1a8cbdcb:f4092350:348b6b80:c054d74c&lt;br /&gt;
ARRAY /dev/md/2 metadata=1.2 name=raidtest:2 spare-group=raidtest UUID=894b1b7c:cb7eba70:917d6033:ea5afd2b&lt;br /&gt;
&lt;br /&gt;
# update the initramfs and reboot&lt;br /&gt;
&lt;br /&gt;
update-initramfs -u&lt;br /&gt;
reboot&lt;br /&gt;
&lt;br /&gt;
# add a spare drive to one of the raids&lt;br /&gt;
&lt;br /&gt;
mdadm --add /dev/md1 /dev/vdq&lt;br /&gt;
&lt;br /&gt;
# fail a drive on the other raid&lt;br /&gt;
&lt;br /&gt;
mdadm --fail /dev/md2 /dev/vdn&lt;br /&gt;
&lt;br /&gt;
# check /proc/mdstat to see md2 rebuilding with the spare from md1&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Recovery ===&lt;br /&gt;
&lt;br /&gt;
The other day, I came across a problem a user had on #linux-raid@irc.freenode.net. He had an old Qnap NAS that had died and tried plugging the drives in to his Linux machine and got various errors. The two-drive RAID-1 did not come up as it should, &#039;&#039;&#039;dmesg&#039;&#039;&#039; was full of errors from one of the drives (both connected on USB) and so forth.&lt;br /&gt;
&lt;br /&gt;
We went on and started by taking down the machine and just connecting one of the drives. I had him check what was assembled with&lt;br /&gt;
&lt;br /&gt;
 cat /proc/mdstat&lt;br /&gt;
&lt;br /&gt;
That returned /proc/md127 assembled, but LVM didn&#039;t find anything. So running a manual scan&lt;br /&gt;
&lt;br /&gt;
 pvscan --cache /dev/md127&lt;br /&gt;
&lt;br /&gt;
This made linux find the PV, VG and a couple of LVs, but probably because the mdraid was degraded, the LVs were deactivated, according to &#039;&#039;&#039;lvscan&#039;&#039;&#039;. Activating the one with a filesystem manually&lt;br /&gt;
&lt;br /&gt;
 lvchange -a y /dev/&amp;lt;vg&amp;gt;/&amp;lt;lv&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Substitute &amp;lt;vg&amp;gt; and &amp;lt;lv&amp;gt; with the names listed by vgs and lvs.&lt;br /&gt;
&lt;br /&gt;
This worked, and the filesystem on /dev/&amp;lt;vg&amp;gt;/&amp;lt;lv&amp;gt; could be mounted correctly.&lt;br /&gt;
&lt;br /&gt;
== Tuning ==&lt;br /&gt;
&lt;br /&gt;
While trying to compare a 12-disk RAID (8TB disks) to a hwraid, mdraid was slower, so we did a few things to speed things up:&lt;br /&gt;
&lt;br /&gt;
While testing with [https://linux.die.net/man/1/fio fio], monitor /sys/block/md0/md/stripe_cache_active, and see if it&#039;s close to /sys/block/md0/md/stripe_cache_size. If it is, double the size of the latter&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
echo 4096 &amp;gt; /sys/block/md0/md/stripe_cache_size&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Continue until stripe_cache_active stabilises, and then you&#039;ve found the limit you&#039;ll need. You may want to double that for good measure. &lt;br /&gt;
&lt;br /&gt;
(to be continued)&lt;br /&gt;
&lt;br /&gt;
== Links ==&lt;br /&gt;
&lt;br /&gt;
Below are a few links with useful info&lt;br /&gt;
&lt;br /&gt;
* [https://raid.wiki.kernel.org/index.php/Irreversible_mdadm_failure_recovery Irreversible mdadm failure recovery]&lt;br /&gt;
&lt;br /&gt;
= ZFS =&lt;br /&gt;
&lt;br /&gt;
ZFS can do a lot of things most filesystems or volume managers can&#039;t. It checksums all data and metadata and so long that the system uses ECC enabled memory (RAM), it will have complete control over the whole data set, and when (not if) an error occurs, it&#039;ll fix the issue without even throwing a warning. To fix the issue, you&#039;ll obviously need sufficient redundancy (mirrors or RAIDzN). &lt;br /&gt;
&lt;br /&gt;
== ZFS send/receive between machines ==&lt;br /&gt;
&lt;br /&gt;
ZFS has a send/receive mechanism that allows for snapshots to be sent over the wire to a receiving end. This can be a full filesystem, or an incremental change since last send/reveive. In a WAN scenario, you&#039;ll probably want to use VPN for this. On a controlled network, sending in cleartext is also possible. You may as well use ssh, but keep in mind that ssh was never designed to be used as a fullblown vpn solution and is just too slow or the task with large amounts of data. You may, though, use mbuffer, if on a loal LAN.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Allow traffic from the sending IP in whatever firewall interface you&#039;re using (if you&#039;re using a firewall at all, that is)&lt;br /&gt;
ufw allow from x.x.x.x&lt;br /&gt;
# &lt;br /&gt;
# Start the receiver first. This listens on port 9090, has a 1GB buffer,&lt;br /&gt;
    and uses 128kb chunks (same as zfs):&lt;br /&gt;
&lt;br /&gt;
mbuffer -s 128k -m 1G -I 9090 | zfs receive data/filesystem&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To be continued one day… See [https://everycity.co.uk/alasdair/2010/07/using-mbuffer-to-speed-up-slow-zfs-send-zfs-receive/ this] for some more. I&#039;ll get back with details on it.&lt;br /&gt;
&lt;br /&gt;
= General Linux system control =&lt;br /&gt;
&lt;br /&gt;
== Add a new CPU (core) ==&lt;br /&gt;
&lt;br /&gt;
If working with virtual machines, adding a new core can be useful if the VM is slow and the load is multithreaded or multiprocess. To do this, add a new CPU in the hypervisor (be it KVM or VMware or Hyper-V or whatever). Some hypervisors, like VMware, will activate it automatically if open-vm-tools is installed. Please note that open-vm-tools is for VMware only. I don&#039;t know of any such thing for KVM or other hypervisors (although I beleive VirtualBox has its own set of tools, but not as a package). If this doesn&#039;t work, run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
echo 1 &amp;gt; /sys/devices/system/cpu/cpuX/online&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where X is the CPU number you want to add. You can &#039;cat /sys/devices/system/cpu/cpuX/online&#039; to check if it&#039;s online.&lt;br /&gt;
&lt;br /&gt;
= Mount partitions on a disk image =&lt;br /&gt;
&lt;br /&gt;
Sometimes you&#039;ll have a disk image, either from recovering a bad drive after hours (or days or weeks) of ddrescue, and sometimes you just have a disk image from a virtual machine where you want to mount the partitions inside the image. There are three main methods of doing this, which are more or less synonmous, but some easier than the other.&lt;br /&gt;
&lt;br /&gt;
== Basics ==&lt;br /&gt;
&lt;br /&gt;
A disk image is usually like a disk, consisting of either a large filesystem, a PV or a partition table with one or partitions onto which resides a filesystem, a pv, swap or something else. If it&#039;s partitioned, and you want your operating system to mount a filesystem or allow it to see whatever LVM stuff lies on it, you need to isolate the partitions. &lt;br /&gt;
&lt;br /&gt;
== Manual mapping ==&lt;br /&gt;
&lt;br /&gt;
In the oldern days, this was done manually, something like this&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
root@mymachine:~# fdisk -l /dev/vda&lt;br /&gt;
Disk /dev/vda: 25 GiB, 26843545600 bytes, 52428800 sectors&lt;br /&gt;
Units: sectors of 1 * 512 = 512 bytes&lt;br /&gt;
Sector size (logical/physical): 512 bytes / 512 bytes&lt;br /&gt;
I/O size (minimum/optimal): 512 bytes / 512 bytes&lt;br /&gt;
Disklabel type: dos&lt;br /&gt;
Disk identifier: 0xc37b7ea5&lt;br /&gt;
&lt;br /&gt;
Device     Boot    Start      End  Sectors  Size Id Type&lt;br /&gt;
/dev/vda1  *        2048 50333311 50331264   24G 83 Linux&lt;br /&gt;
/dev/vda2       50333312 52426369  2093058 1022M  5 Extended&lt;br /&gt;
/dev/vda5       50333314 52426369  2093056 1022M 82 Linux swap / Solaris&lt;br /&gt;
root@mymachine:~#&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To calculate the start and end of each partition, you just take the start sector and multiply it by the sector size (512 bytes here) and you have the offset in bytes. After this, it&#039;s merely an losetup -o &amp;lt;offset&amp;gt; /dev/loopX &amp;lt;nameofimagefile&amp;gt; and you have the partition mapped to your /dev/loopX (having X being something typically 0-255. After this, just mount it or run pvscan/vgscan/lvscan to probe whatever lvm config is there, and you should be able to mount it like any other filesystem.&lt;br /&gt;
&lt;br /&gt;
== kpartx ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;kpartx&#039;&#039;&#039; does the same as above, more or less, just without so much hassle. Most of it should be automatic and easy to deal with, except it may fail to disconnect the loopback devices sometimes, so you may have to &#039;&#039;&#039;losetup -d&#039;&#039;&#039; them manually. See the manual, &#039;&#039;&#039;kpartx (8)&#039;&#039;&#039;. Please note that &#039;&#039;&#039;partx&#039;&#039;&#039; works similarly and I&#039;d guess the authors of the two tools are arguing a lot of which one&#039;s the best.&lt;br /&gt;
&lt;br /&gt;
== guestmount ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;guestmount&#039;&#039;&#039; is something similar again, but also supports file formats like &#039;&#039;&#039;qcow2&#039;&#039;&#039; and possibly other, proprietary filesystems like &#039;&#039;&#039;vmdk&#039;&#039;&#039; and &#039;&#039;&#039;vdi&#039;&#039;&#039;, but don&#039;t take my word for it - I haven&#039;t tested. Again, see the manual or just read up on the description [http://ask.xmodulo.com/mount-qcow2-disk-image-linux.html?fbclid=IwAR3snTeZvGzp9PLdX11EQhCfOpux6I93CiJ3A2pUomkkRLly9Xo4851mkTY here]. It seems rather trivial.&lt;br /&gt;
&lt;br /&gt;
= Linux on laptops =&lt;br /&gt;
&lt;br /&gt;
== Wifi with HP EliteBook 725/745 on Ubuntu ==&lt;br /&gt;
&lt;br /&gt;
The HP EliteBook 725/745 and similar are equipped with a BCM4352 wifi chip. As with a lot of other stuff from Broadcom, this lacks an open hardware description, so thus no open driver exist. The proper fix, is to replace the NIC with something with an open driver, but again, this isn&#039;t always possible, so a binary driver exists. In ubuntu, run, somehow connect the machine to the internet and run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install bcmwl-kernel-source&lt;br /&gt;
sudo modprobe wl&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you can&#039;t connect the machine to the internet, download the needed packages on another machine and put it on some usb storage. These packages should suffice:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# apt-cache depends bcmwl-kernel-source&lt;br /&gt;
bcmwl-kernel-source&lt;br /&gt;
  Depends: dkms&lt;br /&gt;
  Depends: linux-libc-dev&lt;br /&gt;
  Depends: libc6-dev&lt;br /&gt;
  Conflicts: &amp;lt;bcmwl-modaliases&amp;gt;&lt;br /&gt;
  Replaces: &amp;lt;bcmwl-modaliases&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then install manually with &#039;&#039;&#039;dpkg -i file1.deb file2.deb&#039;&#039;&#039; etc&lt;br /&gt;
&lt;br /&gt;
After this, ip/ifconfig/iwconfig shouldd see the new wifi nic, probably &#039;&#039;&#039;wlan0&#039;&#039;&#039;, but due to a [https://bugs.launchpad.net/ubuntu/+source/broadcom-sta/+bug/1343151 old, ignored bug], you won&#039;t find any wifi networks. This is because the driver from Broadcom apparently does not support interrupt remapping, commonly used on x64 machines. To turn this off, change &#039;&#039;&#039;/etc/default/grub&#039;&#039;&#039; and change the line &#039;&#039;&#039;GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;quiet splash&amp;quot;&#039;&#039;&#039;, adding intremap=off to the end before the quote: &#039;&#039;&#039;GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;quiet splash intremap=off&amp;quot;&#039;&#039;&#039;. Save the file and run &#039;&#039;&#039;sudo update-grub&#039;&#039;&#039; and reboot. After this, wifi should work well.&lt;br /&gt;
&lt;br /&gt;
== Wifi with HP Compaq Presario CQ57 on Ubuntu ==&lt;br /&gt;
&lt;br /&gt;
The HP Compaq Presario CQ57 uses the RT5390 wifi chipset. This has been supported for quite some time now, and I was quite surprised to find it not working on a laptop a friend was having. The driver loaded correctly, but Ubuntu insisted of the laptop being in &#039;&#039;&#039;flight mode&#039;&#039;&#039;. Checking &#039;&#039;&#039;rfkill&#039;&#039;&#039;, it showed me two NICs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# rfkill list all&lt;br /&gt;
0: phy0: Wireless LAN&lt;br /&gt;
	Soft blocked: no&lt;br /&gt;
	Hard blocked: yes&lt;br /&gt;
1: hp-wifi: Wireless LAN&lt;br /&gt;
	Soft blocked: yes&lt;br /&gt;
	Hard blocked: no&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Turning rfkill on and off resulted in nothing much, except some error messages in the kernel log (dmesg)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] ACPI Error: Field [B128] at bit offset/length 128/1024 exceeds size of target Buffer (160 bits) (20170831/dsopcode-235)&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]&lt;br /&gt;
                            Initialized Local Variables for Method [HWCD]:&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Local0: 00000000a34b7928 &amp;lt;Obj&amp;gt;           Integer 0000000000000000&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Local1: 00000000b0aa6865 &amp;lt;Obj&amp;gt;           Buffer(8) 46 41 49 4C 04 00 00 00&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Local5: 00000000a9811efd &amp;lt;Obj&amp;gt;           Integer 0000000000000004&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] Initialized Arguments for Method [HWCD]:  (2 arguments defined for method invocation)&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Arg0:   0000000078957d1b &amp;lt;Obj&amp;gt;           Integer 0000000000000001&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Arg1:   00000000725c9c6e &amp;lt;Obj&amp;gt;           Buffer(20) 53 45 43 55 02 00 00 00&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] ACPI Error: Method parse/execution failed \_SB.WMID.HWCD, AE_AML_BUFFER_LIMIT (20170831/psparse-550)&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] ACPI Error: Method parse/execution failed \_SB.WMID.WMAD, AE_AML_BUFFER_LIMIT (20170831/psparse-550)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After upgrading BIOS and testing different kernels, I was asked to try to unload the &#039;&#039;&#039;hp_wmi&#039;&#039;&#039; driver. I did, and things changed a bit, so I tried blacklisting it, creating the file &#039;&#039;&#039;/etc/modprobe.d/blacklist-hp_wmi.conf&#039;&#039;&#039; with the following content&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Blacklist this - it doesn&#039;t work!&lt;br /&gt;
blacklist hp_wmi&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
I gave the machine a reboot and afte that, the &#039;&#039;&#039;hp-wifi&#039;&#039;&#039; entry was gone in the rfkill output, and things works.&lt;br /&gt;
&lt;br /&gt;
= Raspberry pi =&lt;br /&gt;
&lt;br /&gt;
I couldn&#039;t quite decide if the raspberry pi should be a separate section or part of Linux, but hell, it can run more than Linux, although 99,lots% of people just uses Linux on them. This is a small list of things to know about them; things not on the front page of the manual or perhaps hidden even better.&lt;br /&gt;
&lt;br /&gt;
== Which pi? ==&lt;br /&gt;
&lt;br /&gt;
I just setup three raspberry pi machines and although some are quite different, like v1 to vEverythingelse or the Pi zero versions to the normal ones, not all of us remember how to distinguish between them, and sometimes they&#039;re in a nice 3d printed (or otherwise) chassis or otherwise hidden. So, how to check three different ones:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
root@home-assistant:~ $ cat /proc/device-tree/model ; echo&lt;br /&gt;
Raspberry Pi 2 Model B Rev 1.1&lt;br /&gt;
&lt;br /&gt;
root@green-pi:~ $ cat /proc/device-tree/model ; echo&lt;br /&gt;
Raspberry Pi 3 Model B Rev 1.2&lt;br /&gt;
&lt;br /&gt;
roy@yellow-pi:~ $cat /proc/device-tree/model ; echo&lt;br /&gt;
Raspberry Pi 4 Model B Rev 1.1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
While this works well, for the latter, the pi4, it doesn&#039;t tell how much memory I have. It comes in variants of 1, 2 and 4GB, and this is the latter.&lt;br /&gt;
&lt;br /&gt;
== Monitoring ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;vcgencmd&#039;&#039;&#039; from &#039;&#039;&#039;/opt/vc/bin&#039;&#039;&#039;, but symlinked to &#039;&#039;&#039;/usr/bin&#039;&#039;&#039; so it&#039;s available in path, is useful for fetching hardware info about the pi. For example, measuring the temperature&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
root@yellow-pi:~# vcgencmd measure_temp&lt;br /&gt;
temp=63.0&#039;C&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The command is generally badly documented and parts of it seems outdated for newer hardware. Here&#039;s the output from a Raspberry pi 4 with 4GB RAM&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
roy@yellow-pi:~ $ vcgencmd get_mem arm&lt;br /&gt;
arm=948M&lt;br /&gt;
roy@yellow-pi:~ $ vcgencmd get_mem gpu&lt;br /&gt;
gpu=76M&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== BIOS upgrade from Linux ==&lt;br /&gt;
&lt;br /&gt;
Generally, BIOS upgrades have been moved to the BIOS itself these days. This saves a lot of work and quite possibly lives after those who earier rammed their heads through walls, now can upgrade directly from the internet instead of using obscure operating systems best avoided. Sometimes, however, one must use these nevertheless. This is a quick run-through on your options.&lt;br /&gt;
&lt;br /&gt;
=== DOS ===&lt;br /&gt;
&lt;br /&gt;
Most non-automatic BIOS upgrades are installed from DOS. Doing a BIOS upgrade this way, is generally non-problematic. Just install a USB thingie with [https://www.freedos.org/ FreeDOS], copy your file(s) onto the thing and boot on it. The commandline is the same as old MS/DOS, except a wee bit more userfriendly, but not a lot.&lt;br /&gt;
&lt;br /&gt;
=== Windows ===&lt;br /&gt;
&lt;br /&gt;
Some macahines, like laptops from &#039;&#039;&#039;HP&#039;&#039;&#039;, may have BIOS upgrades that are made to be installed from Windows and won&#039;t run in FreeDOS or MS/DOS, instead throwing an error, saying &#039;&#039;&#039;This program cannot be run in DOS mode&#039;&#039;&#039;. This means you&#039;ll have to boot on a Windows rescue disc and do the job from there. Googling this, tells you it&#039;s quite easy, you just choose &#039;make rescue disc&#039; from Windows, and it&#039;s all good, except if you don&#039;t run Windows, that is. To remedy this problem, do as follows:&lt;br /&gt;
&lt;br /&gt;
==== Download Windows ====&lt;br /&gt;
&lt;br /&gt;
Since you don&#039;t run Windows and possibly don&#039;t have a spouse or friend around with such unhealthy habits either, you need to get it. It&#039;s quite easy - just google &#039;download windows&#039; and it&#039;ll send you to [https://www.microsoft.com/en-us/software-download/windows10ISO somewhere like this].&lt;br /&gt;
&lt;br /&gt;
==== Burn it! ====&lt;br /&gt;
&lt;br /&gt;
Now it&#039;s time to burn the installer on a DVD ROM. You&#039;ll need a double-layered one, since the OS is &amp;gt; 4.7GiB, but I&#039;m sure you have a ton of those lying around. Now, just place your optical medium in your optical drive and burn, baby, burn!&lt;br /&gt;
&lt;br /&gt;
==== Or make a USB thing? ====&lt;br /&gt;
&lt;br /&gt;
Not a lot of machines have optical drives these days, so you may want to use an USB pen drive or something instead. This is easy, just make the USB bootable with the Windows application Microsoft has made for this. Unfortunately, this only runs on Windows, and unlike stuff like Debian, where the &#039;&#039;&#039;iso&#039;&#039;&#039; file can be dd&#039;ed directly onto a USB drive to make it bootable, the Windows &#039;&#039;&#039;iso&#039;&#039;&#039;s don&#039;t come with this luxury. There are lots of methods to make bootable USB things from iso files out there, but the only thing most of them have in common, is that they generally don&#039;t work.&lt;br /&gt;
&lt;br /&gt;
===== WoeUSB =====&lt;br /&gt;
&lt;br /&gt;
After hours of swearing, it&#039;s nice to come across software like [https://github.com/slacka/WoeUSB WoeUSB]. It may not be perfect, it relies on a bunch of GUI stuff you&#039;ll never need and so on, but it &#039;&#039;&#039;&#039;&#039;works&#039;&#039;&#039;&#039;&#039;, and that&#039;s the important part! Just clone the repo and RTFM and it&#039;s all nice. It&#039;s slow, but hell, getting a windows machine and/or an optical drive might be slower.&lt;br /&gt;
&lt;br /&gt;
WoeUSB does nothing fancy, but it &#039;&#039;&#039;does&#039;&#039;&#039; work. It will create a filesystem, FAT32 or NTFS (better use NTFS, FAT32 has its limits). It creates normal filesystems and so on. Just make sure to copy in the BIOS update file, usually an exe file, to run when Windows is up and running.&lt;br /&gt;
&lt;br /&gt;
===== Install BIOS =====&lt;br /&gt;
&lt;br /&gt;
Boot on the Windows USB thing and choose &#039;repair computer&#039; and then &#039;command prompt&#039;. Find the install file, and if you&#039;re lucky, you&#039;ll find it needs a 32bit OS, just like I did. Since the 64bit version doesn&#039;t include 32bit compatibility in the installer, revert to downloading the 32bit version of windows and start over. Pray to your favourite god(s) not to get across such machines again - it might help.&lt;br /&gt;
&lt;br /&gt;
= 3D printer stuff =&lt;br /&gt;
&lt;br /&gt;
== Hydrophilic filament ==&lt;br /&gt;
&lt;br /&gt;
Most popular filament types, including PLA, PETG, PP or PA (Polyamide, normally known as Nylon) and virtualy any filament type named [https://www.matterhackers.com/news/filament-and-water poly-something] (and thus with an acronym of P-something) are hydrophilic (also (somewhat incorrectly) called hydroscopic), meaning so long they&#039;re dryer than the atmosphere around them, they&#039;ll do their best to suck out the atmosphere&#039;s humidity. This is why most filament are shrink-wrapped with a small bag of silica gel in it. If such filament is exposed for normal humid air for some time, it&#039;ll become very hard to use. Most of my experience is with PLA, which can handle a bit (depending on make), but still not a lot. With PLA, if you end up with prints where the filament seems not to stick, it may help with a higher temperature. Otherwise, the filament must be [https://all3dp.com/2/how-to-dry-filament-pla-abs-and-nylon/ baked]. If you don&#039;t want to use your oven, try something like a [https://www.jula.no/catalog/hjem-og-husholdning/kjokkenmaskiner/mattilberedningsapparater/frukt-sopptorker/frukt-sopptorker-001641/#tab02 fruit and mushroom dryer]. Then get a good, sealble plastic box and add something like half a kilogram of [https://www.ebay.com/sch/sis.html?_nkw=1KG+Orange+Replacement+Desiccant+Indicating+Silica+Gel+Beads+for+Drawers%2C+Camera&amp;amp;_id=131938742628&amp;amp;&amp;amp;_trksid=p2057872.m2749.l2658 silica gel] to an old sock, tie it and put it in the your new dry box.&lt;br /&gt;
&lt;br /&gt;
Please note that ABS is hydrophobic, so you won&#039;t have to worry too much there. Also, remember that PA/Nylon is extremely hydrophilic. Even a couple of days in normal air humidity can ruin it completely and will require baking.&lt;br /&gt;
&lt;br /&gt;
== Upgrading the firmware on an Ender 3 ==&lt;br /&gt;
&lt;br /&gt;
This is about upgrading the firmware, and thus also flashing a bootloader to the Creality Ender 3 3D printer. Most of this is well documented on several place, like o [https://www.youtube.com/watch?v=fIl5X2ffdyo the video from Teaching tech] and elsewhere, but I&#039;ll just summarise some issues I had.&lt;br /&gt;
&lt;br /&gt;
=== Using an arduino Nano as a programmer ===&lt;br /&gt;
&lt;br /&gt;
Quick note before you read on. If you have an Ender 3 controller version 1.1.5 or newer (or perhaps even a bit older), an CR-10S or some other more or less modern printers or controllers, they come with a bootloader installed already, so don&#039;t bother flashing one. The one that&#039;s in there already, should work well. So if you have one of these, just skip this and jump to the [[Roy&#039;s_notes#Flashing_the_printer|next section]].&lt;br /&gt;
&lt;br /&gt;
However, the normal CR-10 (without the S), Ender 3 and a few other printers from Creality come without a bootloader, so you&#039;ll need to flash one before upgrading the firmware. Well, strictly speakning, you don&#039;t need one, you can save those 8kB or so for other stuff and use a programmer to write the whole firmware, but then you&#039;ll need to wire up everything every time you want a new firmware, so in my world, you &#039;&#039;&#039;do&#039;&#039;&#039; need the bootloader, since it&#039;s easier.&lt;br /&gt;
&lt;br /&gt;
To install a bootloader, you&#039;ll need a programmer, and I didn&#039;t have one available. Having some el-cheapo china-copies of Ardinos around, I read I could use one and tried so. Although the docs mostly mention the Uno etc, it&#039;s just as simple with the Nano copy.&lt;br /&gt;
&lt;br /&gt;
So, grab an arduino, plug it to your machine with a USB cable, and, using the Arduino IDE, use the ArduinoISP sketch there (found under Examples) to burn the software needed for the arduino to work as a programmer. When this is done, connect a 10µF capacitor between RST and GND to stop it from resetting when used as a programmer. Connect the MOSI, MISO and SCK pins from the ICSP block (that little isolated 6-pin block on top of the ardu). See [https://www.arduino.cc/en/Tutorial/ArduinoISP here] for a pinout. Then find Vcc and GND either on the ICSP block or elsewhere. Some sites say that on some boards you shouldn&#039;t use the pins on the ICSP block for this. I doubt it matters, though. Then connect another jumper wire from pin 10 on the ardu to work as the reset pin outwards to the chip being programmed (that is, on the printer). The ICSP jumper block pin layout is the same on the printer and on the ardu, and probably elsewhere. Sometimes [https://xkcd.com/927/ standardisation] actually works…&lt;br /&gt;
&lt;br /&gt;
See https://cloud.karlsbakk.net/index.php/s/zw48YJjzaf8Rc2F for a pic with the ardu (this wiki is broken atm, will fix it later)&lt;br /&gt;
&lt;br /&gt;
== Flashing the printer ==&lt;br /&gt;
&lt;br /&gt;
When the boot loader is in place, possibly after some wierd errors from during the process, the screen on the 3d printer will go blank and it&#039;ll behave like being bricked. This is ok. Now disconnect the wires and connect the USB cable between computer and printer. If you haven&#039;t installed support for the Sanguino board, that is, the variant of the 1284-chip and surrounding electronics that is the core of the, you need to install it first. In the Arduino IDE, choose the Tools / Boards / Boards manager boot option and search for Sanguino. After this, you should find the Sanguino or Sanguino 1284p in the boards menu. After this, you should be able to communicate with the printer&#039;s controller. Download the [https://www.th3dstudio.com/knowledgebase/th3d-unified-firmware-package/ TH3D unified firmware], making sure it&#039;s the last version. Uncompress the zip and with Finder/Explorer/whateversomething&#039;scalledonlinux, browse to &#039;&#039;&#039;TH3DUF_R2/Firmware/TH3DUF_R2.ino&#039;&#039;&#039; and open it. It should open directly in the Android IDE. Keep in mind that the names TH3DUF_R2 and TH3DUF_R2.ino will vary between versions, but you get the point. Now configure it for your particular needs. You&#039;ll find most of this in the Configuration.h tab (that&#039;s really a file). Most of the other files won&#039;t be necessary unless you&#039;re doing some more advanced stuff, like replacing th controller with something non-standard or similar, but then again, that&#039;s another chapter (or book, even). The video mentioned above describes this well. After flashing the new firmware, you&#039;ll probably get some timeouts and errors, since apparently it resets the printer after giving it the new firmware, but without notifying the flashing software of it doing so. If this happens, calm down and reboot the printer and check its tiny monitor - it should work. If it doesn&#039;t work, and if you flashed the bootload yourself, try to flash it again, and if that doesn&#039;t work, try flashing the programmer again yet another time, just for kicks. Again, if you have a newer controller like the v1.1.5, don&#039;t touch the bootloader, as the one already installed, should work well as it is.&lt;br /&gt;
&lt;br /&gt;
PS: I tried enabling &#039;&#039;&#039;MANUAL_MESH_LEVELING&#039;&#039;&#039;, which in the code says that &#039;&#039;If used with a 1284P board the bootscreen will be disabled to save space&#039;&#039;. This effectively disabled the whole thing, and apparently may be making the firmware image a wee bit too large for it to fit the 1284P on the ender. It works well without it, though.&lt;br /&gt;
&lt;br /&gt;
== And then… ==&lt;br /&gt;
&lt;br /&gt;
With the new firmware in place, the printer should work as before, although with thermal runaway protection to better avoid fires in case the shit hits the fan, and to allow for things like autolevelling. With any luck, [https://www.precisionpiezo.co.uk/ this thing] may be ready for use by the time you read this - it surely looks nice!&lt;br /&gt;
&lt;br /&gt;
roy&lt;/div&gt;</summary>
		<author><name>Roy</name></author>
	</entry>
	<entry>
		<id>https://wiki.malinux.no/index.php?title=Roy%27s_notes&amp;diff=158</id>
		<title>Roy&#039;s notes</title>
		<link rel="alternate" type="text/html" href="https://wiki.malinux.no/index.php?title=Roy%27s_notes&amp;diff=158"/>
		<updated>2020-05-22T01:53:31Z</updated>

		<summary type="html">&lt;p&gt;Roy: /* Using an arduino Nano as a programmer */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= LVM, md and friends =&lt;br /&gt;
&lt;br /&gt;
== Linux&#039; Logical Volume Manager (LVM) ==&lt;br /&gt;
&lt;br /&gt;
=== LVM in general ===&lt;br /&gt;
&lt;br /&gt;
LVM is designed to be an abstraction layer on top of physical drives or RAID, typically [https://raid.wiki.kernel.org/index.php/RAID_setup mdraid] or [https://help.ubuntu.com/community/FakeRaidHowto fakeraid]. Keep in mind that fakeraid should be avoided unless you really need it, like in conjunction with dual-booting linux and windows on fakeraid. LVM broadly consists of three elements, the &amp;quot;physical&amp;quot; devices (PV), the volume group (VG) and the logical volume (LV). There can be multiple PVs, VGs and LVs, depending on requirement. More about this below. All commands are given as examples, and all of them can be fine-tuned using extra flags in need of so. In my experience, the defaults work well for most usecases.&lt;br /&gt;
&lt;br /&gt;
I&#039;m mentioning filesystem below too. Where I write ext4, the samme applies to ext2 and ext3.&lt;br /&gt;
&lt;br /&gt;
==== Create a PV ====&lt;br /&gt;
&lt;br /&gt;
A PV is the &amp;quot;physical&amp;quot; parts. This does not need to be a physical disk, but can also be another RAID, be it an mdraid, fakeraid, hardware raid, a virtual disk on a SAN or otherwisee or a partition on one of those. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#  These add three PVs, one on a drive (or hardware raid) and another two on mdraids.&lt;br /&gt;
pvcreate /dev/sdb&lt;br /&gt;
pvcreate /dev/md1 /dev/md2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For more information about pvcreate, see [https://linux.die.net/man/8/pvcreate the manual].&lt;br /&gt;
&lt;br /&gt;
==== Create a VG ====&lt;br /&gt;
&lt;br /&gt;
The volume group consists of one or more PVs grouped together on which LVs can be placed. If several PVs are grouped in a VG, it&#039;s generally a good idea to make sure these PVs have some sort of redundancy, as in mdraid/fakeraid or hwraid. Otherwise it will be like using a [https://en.wikipedia.org/wiki/RAID RAID-0] with a single point of failure on each of the independant drives. LVM has [https://unix.stackexchange.com/questions/150644/raiding-with-lvm-vs-mdraid-pros-and-cons  RAID code in it] as well, so you can use that. I haven&#039;t done so myself, as I generally stick to mraid. The reason is mdraid is, in my opinion older and more stable and has more users (meaning bugs are reported and fixed faster whenever they are found). That said, I beleive the actual RAID code used in LVM RAID are the same function calls as for mdraid, so it may not be much of a difference. I still stick with mdraid. To create a VG, run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create volume group my_vg&lt;br /&gt;
vgcreate my_vg /dev/md1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that if vgcreate is run with a PV (as /dev/md1 above) that is not defined as a PV (like above), this is done implicitly, so if you don&#039;t need any special flags to pvcreate, you can simply skip it and let vgcreate do that for you.&lt;br /&gt;
&lt;br /&gt;
==== Create an LV ====&lt;br /&gt;
&lt;br /&gt;
LVs can be compared to partitions, somehow, since they are bounderies of a fraction or all of that of a VG. The difference between them and a partition, however, is that they can be grown or shrunk easily and also moved around between PVs without downtime. This flexibility makes them superiour to partitions as your system can be changed without users noticing it. By default, an LV is alloated &amp;quot;thickly&amp;quot;, meaning all the data given to it, is allocated from the VG and thus the PV. The following makes a 100GB LV named &amp;quot;thicklv&amp;quot;. When making an LV, I usually allocate what&#039;s needed plus some more, but not everything, just to make sure it&#039;s space available for growth on any of the LVs on the VG, or new LVs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a thick provisioned LV named thicklv on the VG my_vg&lt;br /&gt;
lvcreate -n thicklv -L 100G my_vg&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After the LV is created, a filesystem can be placed on it unless it is meant to be used directly. The application for direct use include swap space, VM storage and certain database systems. Most of these will, however, work on filesystems too, although my testing has shown that on swap space, there is a significant performance gain for using dedicated storage without a filesystem. As for filesystems, most Linux users use either ext4 or xfs. Personally, I generally use XFS these days. See my notes below on filesystem choice.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a filesystem on the LV - this could have been mkfs -t ext4 or whatever filesystem you choose&lt;br /&gt;
mkfs -t xfs /dev/my_vg/thicklv&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then just edit /etc/fstab with correct data and run mount -a, and you should be all set.&lt;br /&gt;
&lt;br /&gt;
==== Create LVM cache ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
lvcreate -L 1G -n _cache_meta data /dev/md1&lt;br /&gt;
&lt;br /&gt;
lvcreate -l100%FREE -n _cache data /dev/md1&lt;br /&gt;
&lt;br /&gt;
# Some would want --cachemode writeback, but seriously, I wouldn&#039;t recommend it. Metadata or data can be easily corrupted in case of failure.&lt;br /&gt;
lvconvert --type cache-pool --cachemode writethrough --poolmetadata data/_cache_meta data/_cache&lt;br /&gt;
&lt;br /&gt;
lvconvert --type cache --cachepool data/_cache data/data&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Disabling LVM cache ====&lt;br /&gt;
&lt;br /&gt;
If you for some reason want to disable caching, this will do it cleanly and remove the LVs earlier created for caching the main device.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
lvconvert --uncache data/data&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Growing devices ====&lt;br /&gt;
&lt;br /&gt;
LVM objects can be grown and shrunk. If a PV resides on a RAID where a new drive has been added or otherwise grown, or on a partition or virtual disk that has been extended, the PV must be updated to reflect these changes. The following command will grow the PV to the maximum available on the underlying storage. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Resize the PV /dev/md (not the RAID, only the PV on the RAID) to its full size&lt;br /&gt;
pvresize /dev/md1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If a new PV is added, the VG can be grown to add the space on that in addition to what&#039;s there already. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Extend my_vg to include md2 and its space&lt;br /&gt;
vgextend my_vg /dev/md2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
With more space available in the VG, the LV can now be extended. Let&#039;s add another 50GB to it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Extend thicklv - add 50GB. If you know you won&#039;t need the space anywhere else, you may want to&lt;br /&gt;
# lvresize -l+100%FREE instead. Keep in mind the difference between -l (extents) and -L (bytes)&lt;br /&gt;
lvresize -L +50G my_vg/thicklv&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Growing filesystems ====&lt;br /&gt;
After the LV has grown, run &#039;&#039;xfs_growfs&#039;&#039; (xfs) or &#039;&#039;resize2fs&#039;&#039; (ext4) to make use of the new data. To grow the filesystem to all available space on ext4, run the below command.  To partly grow the filesystem or to shrink it or otherwise, please see the manuals.&lt;br /&gt;
&lt;br /&gt;
The filesystem can be mounted when this is run. If you for some reason get an &#039;&#039;&#039;access denied&#039;&#039;&#039; error when running this as root or with sudo, it&#039;s likely caused by a filesystem error. To fix this, unmount the filesystem first and run &#039;&#039;&#039;fsck -f /dev/my_vg/thicklv&#039;&#039;&#039; and remount it before retrying to extend it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
resize2fs /dev/my_vg/thicklv&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Similarly, with XFS, but note that xfs_growfs doesn&#039;t take the device name, but the filesystem&#039;s mount point. In the case of XFS, also note that the filesystem &#039;&#039;&#039;&#039;&#039;must&#039;&#039;&#039;&#039;&#039; be mounted to be grown. This, in contrast to how it was in the old days when filesystems had to be unmounted to be grown.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
xfs_growfs /my_mountpoint&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Rename system VG ====&lt;br /&gt;
&lt;br /&gt;
Some distros create VG names like those-from-a-sysadmin-with-a-well-developed-paranoia-not-to-hit-a-duplicate. Debian, for instance, uses names like &amp;quot;my-full-hostname-vg&amp;quot;. Personally, I don&#039;t like these, since if I were to move a disk or vdisk around to somewhere else, I&#039;d make sure not to add a disk named &#039;sys&#039; to an existing system. If you do, most distros will refuse to use the VGs with duplicate names, resulting in the OS not booting until either one is specified by its UUID or just one removed. As I&#039;m aware of this, I stick to the super-risky thing of all system VGs named &#039;sys&#039; and so on.&lt;br /&gt;
&lt;br /&gt;
If you do this, keep in mind that it may blow up your computer and take your girl- or boyfriend with it or even make either of them pregnant, allowing Trump to rule your life and generally make things suck. You&#039;re on your own!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Rename the VG&lt;br /&gt;
vgrename my-full-hostname-vg sys&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, in /boot/grub/grub.cfg, change the old lv path from something like &#039;/dev/mapper/debian--stretch--machine--vg-root&#039; to your new and fancy &#039;/dev/sys/root. Likewise, in /etc/fstab, change occurences of &#039;/dev/mapper/debian--stretch--machine--vg-&#039; (or similar) with &#039;/dev/sys/&#039;. Here, this was like this - the old ones commented out.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;fstab&amp;quot;&amp;gt;&lt;br /&gt;
#/dev/mapper/debian--stretch--box--vg-root      /               ext4            errors=remount-ro,discard       0       1&lt;br /&gt;
/dev/sys/root                                   /               ext4            errors=remount-ro,discard       0       1&lt;br /&gt;
# /boot was on /dev/vda1 during installation&lt;br /&gt;
UUID=myverylonguuidwithatonofgoodinfoinit       /boot           ext2            defaults                        0       2&lt;br /&gt;
#/dev/mapper/debian--stretch--box--vg-swap_1    none            swap            sw                              0       0&lt;br /&gt;
/dev/sys/swap_1                                 none            swap            sw                              0       0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Update /etc/initramfs-tools/conf.d/resume with similar data for swap.&lt;br /&gt;
&lt;br /&gt;
You might want to run &#039;update-initramfs -u -k all&#039; after this, but I&#039;m not sure if it&#039;s needed.&lt;br /&gt;
&lt;br /&gt;
Now, pray to the nearest god(s) and give it a reboot and it should (probably) work.&lt;br /&gt;
&lt;br /&gt;
After reboot, run &#039;&#039;&#039;swapoff -a&#039;&#039;&#039;, then &#039;&#039;&#039;mkswap /dev/sys/swap_1&#039;&#039;&#039; (or whatever it&#039;s called on your system) and &#039;&#039;&#039;swapon -a&#039;&#039;&#039; again. You may want to give it another reboot or two for kicks, but it should work well even without that.&lt;br /&gt;
&lt;br /&gt;
=== Migration tools ===&lt;br /&gt;
&lt;br /&gt;
At times, storage regimes change, new storage is added and sometimes it&#039;s not easy to migrate with the current hardware or its support systems. Once I had to migrate a 45TiB fileserver from one storage system to another, preferably without downtime. The server originally had three 15TiB PVs of which two were full and the third half full. I resorted to using [https://linux.die.net/man/8/pvmove pvmove] to just move the data on the PVs in use to a new PV. We started out with creating a new 50TiB PV, sde, and then to pvmove.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Attach /dev/sde to the VG my_vg&lt;br /&gt;
vgextend my_vg /dev/sde&lt;br /&gt;
&lt;br /&gt;
# Move the contents from /dev/sdb over to /dev/sde block by block. If a target is not given in pvmove,&lt;br /&gt;
# the contents of the source (sdb here) will be put somewhere else in the pool.&lt;br /&gt;
pvmove /dev/sdb /dev/sde&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This took a while (as in a week or so) - the pvmove command uses old code and logic (or at least did that when I migrated this in November 2016), but it affected performance on the server very little, so users didn&#039;t notice. After the first PV was migrated, I continued with the other two, one after the other, and after a month or so, it was migrated. We used this on a number of large fileservers, and it worked flawlessly. Before doing the production servers I also tried interrupting pvmove in various ways, including hard resets, and it just kept on after the reboot.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;NOTE:&#039;&#039;&#039;&#039;&#039; &#039;&#039;Even though it worked well for us, &#039;&#039;&#039;always&#039;&#039;&#039; keep a good backup before doing this. Things may go wrong, and without a good backup, you may be looking for a hard-to-find new job the next morning&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
==== mdadm workarounds ====&lt;br /&gt;
&lt;br /&gt;
===== Migrate from a mirror (raid-1) to raid-10 =====&lt;br /&gt;
&lt;br /&gt;
Create a mirror&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sdb /dev/sdc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
LVM (pv/vg/lv) on md0 (see above), put a filesystem on the lv and fill it with some data.&lt;br /&gt;
&lt;br /&gt;
Now, some months later, you want to change this to raid-10 to allow for the same amount of redundancy, but to allow more disks into the system.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mdadm --grow /dev/md0 --level=10&lt;br /&gt;
mdadm: Impossibly level change request for RAID1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So - no - doesn&#039;t work. But - we&#039;re on &lt;br /&gt;
&lt;br /&gt;
Since we&#039;re on lvm already, this&#039;ll be easy. If you&#039;re using filesystems directly on partitions, you can do this the same way, but without the pvmove part, using rsync or whateever you like instead. I&#039;d recommend using lvm for for the new raid, which should be rather obvious from this article. Now plug in a new drive and create a new raid10 on that one. If you two new drives, install both. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# change &amp;quot;missing&amp;quot; to the other device name if you installed two new drives&lt;br /&gt;
mdadm --create /dev/md1 --level=10 --raid-devices=2 /dev/vdd missing&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, as described above, just vgextend the vg, adding the new raid and run pvmove to move the data from the old pv (residing on the old raid1) to the new pv (on raid10). Afte rpvmove is finished (which may take awile, see above), just&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
vgreduce raidtest /dev/md0&lt;br /&gt;
pvremove /dev/md0&lt;br /&gt;
mdadm --stop /dev/md0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
…and your disk is free to be added to the new array. If the new raid is running in degraded mode (if you created it with just one drive), better don&#039;t wait too long, since you don&#039;t have redundancy. Just mdadm --add the devs.&lt;br /&gt;
&lt;br /&gt;
If you now have /dev/mdstat telling you your raid10 is active and have three drives, of which one is a spare, it should look something like this&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5] [raid4] [raid10]&lt;br /&gt;
md1 : active raid10 vdc[3](S) vdb[2] vdd[0]&lt;br /&gt;
      8380416 blocks super 1.2 2 near-copies [2/2] [UU]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Just mdadm --grow --raid-devices=3 /dev/md1&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;RAID section is not complete. I&#039;ll write more on migraing from raid10 to raid6 later. It&#039;s not straight forward, but easier than this one :)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== Thin provisioned LVs ===&lt;br /&gt;
&lt;br /&gt;
Thin provisioning on LVM is a method used for not allocating all the space given to an LV. For instance, if you have a 1TB VG and want to give an LV 500GB, although it currently only uses a fraction of that, a thin lv can be a good alternative. This will allow for adding a limit to how much it can use, but also to let it grow dynamically without manual work by the sysadmin. Thin provisioning adds another layer of abstaction by creating a special LV as a &#039;&#039;thin pool&#039;&#039; from which data is allocated to the &#039;&#039;thin volume(s)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== Create a thin pool ====&lt;br /&gt;
&lt;br /&gt;
Allocate 1TB to the thin pool to be used for thinly provisioned LVs. Keep in mind that the space allocated to the thin pool is in fact thick provisioned. Only the volumes put on &#039;&#039;thinpool&#039;&#039; are thin provisioned. This will create two hidden LVs, one for data and one for metadata. Normally the defaults will do, but check the manual if the data doesn&#039;t match the usual patterns (such as billions of files, resulting in huge amounts of metadata). I &#039;&#039;beleive&#039;&#039; the metadata part should be resizable at a later time if needed, but I have not tested it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a pool for thin LVs. Keep in mind that the pool itself is not thin provisioned, only the volumes residing on it&lt;br /&gt;
lvcreate --size 1T --type thin-pool --thinpool thinpool my_vg&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Create a thin volume ====&lt;br /&gt;
&lt;br /&gt;
You have the thinpool, now put a thin volume on it. It will allocate some space for metadata, but probably not much (a few megs, perhaps).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Now, create a volume with a virtual (-V) size of half a terabyte named thin_pool, but using the thinpool (-T) named thin_pool for storage&lt;br /&gt;
lvcreate -V 500G -T my_vg/thin_pool --name thinvol&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The new volume&#039;s device name will be /dev/thinvol. Now, create a filesystem on it, add to fstab and mount it. The &#039;&#039;&#039;df&#039;&#039;&#039; command will return available space according to the virtual size (-V), while lvs will show how much data is actually used on each of the thinly provisioned volumes.&lt;br /&gt;
&lt;br /&gt;
== Filesystem dilemmas ==&lt;br /&gt;
&lt;br /&gt;
=== XFS or ext4 or something else ===&lt;br /&gt;
The choice of filesystem varies for your use. Distros such as RHEL/CentOS has moved to XFS by default from v7. Debian/Ubuntu still sticks to ext4, like most other. I&#039;ll discuss my thoughts below on ext4 vs XFS and leave the other filesystems for later.&lt;br /&gt;
&lt;br /&gt;
==== ext4 ====&lt;br /&gt;
ext4 is probably the most used filesystem on linux as of writing. It&#039;s rock stable and has been extended by a lot of extensions since the original ext2. It still retains backward compatibility, being able to mount and fsck ext2 and ext3 with the ext4 driver. However, it doesn&#039;t handle large filesystems very well. If a filesystem is created for &amp;lt;16TiB, it cannot be grown to anything larger than 16TiB. This may have changed lately, though. One other issue is handling errors. If a large filesystem (say 10TiB) is damaged, an fsck may take several hours, leading to long downtime. When I refer to ext4 further in this text, the same applies to ext2 and ext3 unless otherwise specified.&lt;br /&gt;
&lt;br /&gt;
==== XFS ====&lt;br /&gt;
XFS, originally developed by SGI some time in the bronze age, but has been worked on heavily after that. RHEL and Centos version 7 and forward, uses XFS as the default filesystem. It is quick, it scales well, but it lacks at least two things ext4 has. It cannot be shrunk (not that you normally need that, but nice if you have a typo or you need to change things). Also, it doesn&#039;t allow for automatic fsck on bootup. If something is messed up on the filesystem, you&#039;ll have to login as root on the console (not ssh), which might be an issue on some systems. The fsck equivalent, xfs_repair, is a *lot* faster than ext4&#039;s fsck, though.&lt;br /&gt;
&lt;br /&gt;
==== ZFS ====&lt;br /&gt;
ZFS is like a combination of RAID, LVM and a filesystem, supporting full checksumming, auto-healing (given sufficient redundancy), compression, encryption, replication, deduplication (if you&#039;re brave and have a &#039;&#039;ton&#039;&#039; of memory) and a lot more. It&#039;s a separate chapter and needs a lot more talk than paragraph here.&lt;br /&gt;
&lt;br /&gt;
==== btrfs ====&lt;br /&gt;
btrfs, pronounced &amp;quot;butterfs&amp;quot; or &amp;quot;betterfs&amp;quot; or just spelled out, is a filesystem that mimics that of ZFS. It has been around for 10 years or so, but hasn&#039;t yet proven to be really stable. Following the progress of it for those years, I&#039;ve found it to be a nice toy with which to play, but not to be used in production. Again, others may say otherwise, but these are just my words.&lt;br /&gt;
&lt;br /&gt;
== Low level disk handling ==&lt;br /&gt;
&lt;br /&gt;
This section is for low-level handling of disks, regardless of storage system elsewhere. These apply to mdraid, lvmraid and zfs and possibly other solutions, with the exception of individual drives on hwraid (and maybe fakeraid), since there, the drives are hidden from Linux (or whatever OS).&lt;br /&gt;
&lt;br /&gt;
=== S.M.A.R.T. and slow drives ===&lt;br /&gt;
Modern (that is, from about 1990 or later) have S.M.A.R.T. (or just smart, since it&#039;s easier to type) monitoring built in, meaning the disk&#039;s controller is monitoring itself. This is handy and will ideally tell you in advance that a drive is flakey or dying. Modern (2010+) smart monitoring is more or less the same. It can be trusted about 50% of the time. Usually, if smart detects an error, it&#039;s a real error. I don&#039;t think I&#039;ve seen it reporting a false positive, but others may know better. &lt;br /&gt;
&lt;br /&gt;
==== smartmontools ====&lt;br /&gt;
First, install smartmontool and run smartclt -H /dev/yourdisk (/dev/sda or something) to get a health report. Then perhaps run smartctl -a /dev/yourdisk and look for &#039;current pending sectors&#039; This should be zero. Also check the temperature, which normally should be much above 50.&lt;br /&gt;
&lt;br /&gt;
==== single, slow drive ====&lt;br /&gt;
What may happen, is smart not seeing anything and life goes on like before, only slower and less prouductive, without telling anyone. If you stubler over this issue, you&#039;ll probably see it during a large rsync/zfs send/receive or a resync/rebuild/resilver of the raid/zpool. During this, it feels like everything is slow and your RAID has turned into a RAIF (redundant array of inexpensive floppies). To check if you have a single drive messing up it all, check with &#039;&#039;&#039;iostat -x 2&#039;&#039;&#039;, having 2 being the delay between each measurement. Interrupt it with ctrl+x. If there&#039;s a rougue drive there, it should stand out like sdg below&lt;br /&gt;
&lt;br /&gt;
 avg-cpu:  %user   %nice %system %iowait  %steal   %idle&lt;br /&gt;
            0.38    0.00    1.75    0.00    0.00   97.87&lt;br /&gt;
&lt;br /&gt;
 Device            r/s     w/s     rkB/s     wkB/s   rrqm/s   wrqm/s  %rrqm  %wrqm r_await w_await aqu-sz rareq-sz wareq-sz  svctm  %util&lt;br /&gt;
 sda              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdb              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdc              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdd              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sde              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdf              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdg              3.50    0.00   2352.00      0.00     0.00     0.00   0.00   0.00 14306.29    0.00  13.85   672.00     0.00 285.71 100.00&lt;br /&gt;
 sdh              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
&lt;br /&gt;
In ZFS land, you should be able to get similar data with &#039;&#039;&#039;zpool iostat -v &amp;lt;pool&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Now you know the bad drive (sdg), pull it from the raid with &#039;&#039;&#039;mdadm --fail /dev/mdX /dev/sdX&#039;&#039;&#039;. Now test the drive&#039;s performance manually, just simply:&lt;br /&gt;
&lt;br /&gt;
 # hdparm -t /dev/sdg&lt;br /&gt;
 &lt;br /&gt;
 /dev/sdg:&lt;br /&gt;
  Timing buffered disk reads:   2 MB in  5.37 seconds = 381.46 kB/sec&lt;br /&gt;
&lt;br /&gt;
Bingo - nothing you&#039;d want to keep. For a good drive, it should be something like 100-200MB/s&lt;br /&gt;
&lt;br /&gt;
PS: Keep in mind that you have a degraded RAID by now in case you had a spare waiting for things to happen.&lt;br /&gt;
&lt;br /&gt;
Try to replace the cable and/or try the disk on another port/controller. If the result from hdparm persists, it&#039;s probably a bad cable&lt;br /&gt;
&lt;br /&gt;
So, then, just psycially locate the drive, pull it out, take out the discs and magnets and recycle the rest.&lt;br /&gt;
&lt;br /&gt;
=== &amp;quot;Unplug&amp;quot; drive from system ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Find the device unit&#039;s number with something like&lt;br /&gt;
find /sys/bus/scsi/devices/*/block/ -name sdd&lt;br /&gt;
# returning /sys/bus/scsi/devices/3:0:0:0/block/sdd here, &lt;br /&gt;
# meaning 3:0:0:0 is the SCSI device we&#039;re looking for.&lt;br /&gt;
&lt;br /&gt;
# Given this is the correct device, and you want to &#039;unplug&#039; it, do so by&lt;br /&gt;
echo 1 &amp;gt; /sys/bus/scsi/devices/3:0:0:0/delete&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Rescan disk controllers ===&lt;br /&gt;
If a drive is added and for some reason doesn&#039;t get detected, or is removed by the command above, it can be rediscovered with a sysfs command to the scsi host to which it is connected. Since there may be quite a few of these, an easy way is to just scan them all and check the output of &#039;&#039;&#039;dmesg -T&#039;&#039;&#039; after running it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Make a list of controllers and send a rescan message to each of them. It won&#039;t do anything &lt;br /&gt;
# for those where nothing has changed, but it will show new drives where they have been added.&lt;br /&gt;
for host_scan in /sys/class/scsi_host/host*/scan&lt;br /&gt;
do&lt;br /&gt;
  echo &#039;- - -&#039; &amp;gt; $host_scan&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Fail injection with debugfs ===&lt;br /&gt;
[https://lxadm.com/Using_fault_injection https://lxadm.com/Using_fault_injection]&lt;br /&gt;
&lt;br /&gt;
== mdadm stuff ==&lt;br /&gt;
=== Resync ===&lt;br /&gt;
To resync a raid, that is, check, run&lt;br /&gt;
&lt;br /&gt;
 echo check &amp;gt; /sys/block/$dev/md/sync_action&lt;br /&gt;
&lt;br /&gt;
where $dev is something like md0. If you have several raids, something like this should work&lt;br /&gt;
&lt;br /&gt;
 for dev in md{0,1}&lt;br /&gt;
 do&lt;br /&gt;
   echo repair &amp;gt; /sys/block/$dev/md/sync_action&lt;br /&gt;
 done&lt;br /&gt;
&lt;br /&gt;
Also useful in a one-liner like&lt;br /&gt;
&lt;br /&gt;
 for dev in md{0,1} ; do echo repair &amp;gt; /sys/block/$dev/md/sync_action ; done&lt;br /&gt;
&lt;br /&gt;
Different raids on different drives will do this in parallel. If the drives are shared somehow with partitions or similar, the check or repair will wait for the other to finish before going on.&lt;br /&gt;
&lt;br /&gt;
As for repair vs check, [https://raid.wiki.kernel.org/index.php/RAID_Administration this article] describes it well. I stick to using repair unless it&#039;s something rare where I don&#039;t want to touch the data.&lt;br /&gt;
&lt;br /&gt;
=== Spare pools ===&lt;br /&gt;
In the old itmes, mdadm supported only a dedicated spare per md device, so if working with a large set of drives (20? 40?), where you&#039;d want to setup more raid sets to increase redundancy, you&#039;d dedicate a spare to each of the raid sets. This has changed (some time ago?), so in these modern, heathen days, you can change mdadm.conf, usually placed under /etc/mdadm, and add &#039;spare-group=somegroup&#039; where &#039;somegroup&#039; is a string identifying the spare group. After doing this, run &#039;&#039;&#039;update-initramfs -u&#039;&#039;&#039; and reboot and add a spare to one of the raid sets in the spare group, and md will use that or those spares for all the raidsets in that group.&lt;br /&gt;
&lt;br /&gt;
As some pointed out on #linux-raid @ irc.freenode.net, this feature is very badly documented, but as far as I can see, it works well.&lt;br /&gt;
&lt;br /&gt;
==== Example config ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create two raidsets&lt;br /&gt;
&lt;br /&gt;
mdadm --create /dev/md1 --level=6 --raid-devices=6 /dev/vd[efghij]&lt;br /&gt;
mdadm --create /dev/md2 --level=6 --raid-devices=6 /dev/vd[klmnop]&lt;br /&gt;
&lt;br /&gt;
# get their UUID etc&lt;br /&gt;
&lt;br /&gt;
mdadm --detail --scan&lt;br /&gt;
ARRAY /dev/md/1 metadata=1.2 name=raidtest:1 UUID=1a8cbdcb:f4092350:348b6b80:c054d74c&lt;br /&gt;
ARRAY /dev/md/2 metadata=1.2 name=raidtest:2 UUID=894b1b7c:cb7eba70:917d6033:ea5afd2b&lt;br /&gt;
&lt;br /&gt;
# Put those lines into /etc/mdadm/mdadm.conf and and add the spare-group&lt;br /&gt;
&lt;br /&gt;
ARRAY /dev/md/1 metadata=1.2 name=raidtest:1 spare-group=raidtest UUID=1a8cbdcb:f4092350:348b6b80:c054d74c&lt;br /&gt;
ARRAY /dev/md/2 metadata=1.2 name=raidtest:2 spare-group=raidtest UUID=894b1b7c:cb7eba70:917d6033:ea5afd2b&lt;br /&gt;
&lt;br /&gt;
# update the initramfs and reboot&lt;br /&gt;
&lt;br /&gt;
update-initramfs -u&lt;br /&gt;
reboot&lt;br /&gt;
&lt;br /&gt;
# add a spare drive to one of the raids&lt;br /&gt;
&lt;br /&gt;
mdadm --add /dev/md1 /dev/vdq&lt;br /&gt;
&lt;br /&gt;
# fail a drive on the other raid&lt;br /&gt;
&lt;br /&gt;
mdadm --fail /dev/md2 /dev/vdn&lt;br /&gt;
&lt;br /&gt;
# check /proc/mdstat to see md2 rebuilding with the spare from md1&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Recovery ===&lt;br /&gt;
&lt;br /&gt;
The other day, I came across a problem a user had on #linux-raid@irc.freenode.net. He had an old Qnap NAS that had died and tried plugging the drives in to his Linux machine and got various errors. The two-drive RAID-1 did not come up as it should, &#039;&#039;&#039;dmesg&#039;&#039;&#039; was full of errors from one of the drives (both connected on USB) and so forth.&lt;br /&gt;
&lt;br /&gt;
We went on and started by taking down the machine and just connecting one of the drives. I had him check what was assembled with&lt;br /&gt;
&lt;br /&gt;
 cat /proc/mdstat&lt;br /&gt;
&lt;br /&gt;
That returned /proc/md127 assembled, but LVM didn&#039;t find anything. So running a manual scan&lt;br /&gt;
&lt;br /&gt;
 pvscan --cache /dev/md127&lt;br /&gt;
&lt;br /&gt;
This made linux find the PV, VG and a couple of LVs, but probably because the mdraid was degraded, the LVs were deactivated, according to &#039;&#039;&#039;lvscan&#039;&#039;&#039;. Activating the one with a filesystem manually&lt;br /&gt;
&lt;br /&gt;
 lvchange -a y /dev/&amp;lt;vg&amp;gt;/&amp;lt;lv&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Substitute &amp;lt;vg&amp;gt; and &amp;lt;lv&amp;gt; with the names listed by vgs and lvs.&lt;br /&gt;
&lt;br /&gt;
This worked, and the filesystem on /dev/&amp;lt;vg&amp;gt;/&amp;lt;lv&amp;gt; could be mounted correctly.&lt;br /&gt;
&lt;br /&gt;
== Tuning ==&lt;br /&gt;
&lt;br /&gt;
While trying to compare a 12-disk RAID (8TB disks) to a hwraid, mdraid was slower, so we did a few things to speed things up:&lt;br /&gt;
&lt;br /&gt;
While testing with [https://linux.die.net/man/1/fio fio], monitor /sys/block/md0/md/stripe_cache_active, and see if it&#039;s close to /sys/block/md0/md/stripe_cache_size. If it is, double the size of the latter&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
echo 4096 &amp;gt; /sys/block/md0/md/stripe_cache_size&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Continue until stripe_cache_active stabilises, and then you&#039;ve found the limit you&#039;ll need. You may want to double that for good measure. &lt;br /&gt;
&lt;br /&gt;
(to be continued)&lt;br /&gt;
&lt;br /&gt;
== Links ==&lt;br /&gt;
&lt;br /&gt;
Below are a few links with useful info&lt;br /&gt;
&lt;br /&gt;
* [https://raid.wiki.kernel.org/index.php/Irreversible_mdadm_failure_recovery Irreversible mdadm failure recovery]&lt;br /&gt;
&lt;br /&gt;
= ZFS =&lt;br /&gt;
&lt;br /&gt;
ZFS can do a lot of things most filesystems or volume managers can&#039;t. It checksums all data and metadata and so long that the system uses ECC enabled memory (RAM), it will have complete control over the whole data set, and when (not if) an error occurs, it&#039;ll fix the issue without even throwing a warning. To fix the issue, you&#039;ll obviously need sufficient redundancy (mirrors or RAIDzN). &lt;br /&gt;
&lt;br /&gt;
== ZFS send/receive between machines ==&lt;br /&gt;
&lt;br /&gt;
ZFS has a send/receive mechanism that allows for snapshots to be sent over the wire to a receiving end. This can be a full filesystem, or an incremental change since last send/reveive. In a WAN scenario, you&#039;ll probably want to use VPN for this. On a controlled network, sending in cleartext is also possible. You may as well use ssh, but keep in mind that ssh was never designed to be used as a fullblown vpn solution and is just too slow or the task with large amounts of data. You may, though, use mbuffer, if on a loal LAN.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Allow traffic from the sending IP in whatever firewall interface you&#039;re using (if you&#039;re using a firewall at all, that is)&lt;br /&gt;
ufw allow from x.x.x.x&lt;br /&gt;
# &lt;br /&gt;
# Start the receiver first. This listens on port 9090, has a 1GB buffer,&lt;br /&gt;
    and uses 128kb chunks (same as zfs):&lt;br /&gt;
&lt;br /&gt;
mbuffer -s 128k -m 1G -I 9090 | zfs receive data/filesystem&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To be continued one day… See [https://everycity.co.uk/alasdair/2010/07/using-mbuffer-to-speed-up-slow-zfs-send-zfs-receive/ this] for some more. I&#039;ll get back with details on it.&lt;br /&gt;
&lt;br /&gt;
= General Linux system control =&lt;br /&gt;
&lt;br /&gt;
== Add a new CPU (core) ==&lt;br /&gt;
&lt;br /&gt;
If working with virtual machines, adding a new core can be useful if the VM is slow and the load is multithreaded or multiprocess. To do this, add a new CPU in the hypervisor (be it KVM or VMware or Hyper-V or whatever). Some hypervisors, like VMware, will activate it automatically if open-vm-tools is installed. Please note that open-vm-tools is for VMware only. I don&#039;t know of any such thing for KVM or other hypervisors (although I beleive VirtualBox has its own set of tools, but not as a package). If this doesn&#039;t work, run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
echo 1 &amp;gt; /sys/devices/system/cpu/cpuX/online&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where X is the CPU number you want to add. You can &#039;cat /sys/devices/system/cpu/cpuX/online&#039; to check if it&#039;s online.&lt;br /&gt;
&lt;br /&gt;
= Mount partitions on a disk image =&lt;br /&gt;
&lt;br /&gt;
Sometimes you&#039;ll have a disk image, either from recovering a bad drive after hours (or days or weeks) of ddrescue, and sometimes you just have a disk image from a virtual machine where you want to mount the partitions inside the image. There are three main methods of doing this, which are more or less synonmous, but some easier than the other.&lt;br /&gt;
&lt;br /&gt;
== Basics ==&lt;br /&gt;
&lt;br /&gt;
A disk image is usually like a disk, consisting of either a large filesystem, a PV or a partition table with one or partitions onto which resides a filesystem, a pv, swap or something else. If it&#039;s partitioned, and you want your operating system to mount a filesystem or allow it to see whatever LVM stuff lies on it, you need to isolate the partitions. &lt;br /&gt;
&lt;br /&gt;
== Manual mapping ==&lt;br /&gt;
&lt;br /&gt;
In the oldern days, this was done manually, something like this&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
root@mymachine:~# fdisk -l /dev/vda&lt;br /&gt;
Disk /dev/vda: 25 GiB, 26843545600 bytes, 52428800 sectors&lt;br /&gt;
Units: sectors of 1 * 512 = 512 bytes&lt;br /&gt;
Sector size (logical/physical): 512 bytes / 512 bytes&lt;br /&gt;
I/O size (minimum/optimal): 512 bytes / 512 bytes&lt;br /&gt;
Disklabel type: dos&lt;br /&gt;
Disk identifier: 0xc37b7ea5&lt;br /&gt;
&lt;br /&gt;
Device     Boot    Start      End  Sectors  Size Id Type&lt;br /&gt;
/dev/vda1  *        2048 50333311 50331264   24G 83 Linux&lt;br /&gt;
/dev/vda2       50333312 52426369  2093058 1022M  5 Extended&lt;br /&gt;
/dev/vda5       50333314 52426369  2093056 1022M 82 Linux swap / Solaris&lt;br /&gt;
root@mymachine:~#&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To calculate the start and end of each partition, you just take the start sector and multiply it by the sector size (512 bytes here) and you have the offset in bytes. After this, it&#039;s merely an losetup -o &amp;lt;offset&amp;gt; /dev/loopX &amp;lt;nameofimagefile&amp;gt; and you have the partition mapped to your /dev/loopX (having X being something typically 0-255. After this, just mount it or run pvscan/vgscan/lvscan to probe whatever lvm config is there, and you should be able to mount it like any other filesystem.&lt;br /&gt;
&lt;br /&gt;
== kpartx ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;kpartx&#039;&#039;&#039; does the same as above, more or less, just without so much hassle. Most of it should be automatic and easy to deal with, except it may fail to disconnect the loopback devices sometimes, so you may have to &#039;&#039;&#039;losetup -d&#039;&#039;&#039; them manually. See the manual, &#039;&#039;&#039;kpartx (8)&#039;&#039;&#039;. Please note that &#039;&#039;&#039;partx&#039;&#039;&#039; works similarly and I&#039;d guess the authors of the two tools are arguing a lot of which one&#039;s the best.&lt;br /&gt;
&lt;br /&gt;
== guestmount ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;guestmount&#039;&#039;&#039; is something similar again, but also supports file formats like &#039;&#039;&#039;qcow2&#039;&#039;&#039; and possibly other, proprietary filesystems like &#039;&#039;&#039;vmdk&#039;&#039;&#039; and &#039;&#039;&#039;vdi&#039;&#039;&#039;, but don&#039;t take my word for it - I haven&#039;t tested. Again, see the manual or just read up on the description [http://ask.xmodulo.com/mount-qcow2-disk-image-linux.html?fbclid=IwAR3snTeZvGzp9PLdX11EQhCfOpux6I93CiJ3A2pUomkkRLly9Xo4851mkTY here]. It seems rather trivial.&lt;br /&gt;
&lt;br /&gt;
= Linux on laptops =&lt;br /&gt;
&lt;br /&gt;
== Wifi with HP EliteBook 725/745 on Ubuntu ==&lt;br /&gt;
&lt;br /&gt;
The HP EliteBook 725/745 and similar are equipped with a BCM4352 wifi chip. As with a lot of other stuff from Broadcom, this lacks an open hardware description, so thus no open driver exist. The proper fix, is to replace the NIC with something with an open driver, but again, this isn&#039;t always possible, so a binary driver exists. In ubuntu, run, somehow connect the machine to the internet and run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install bcmwl-kernel-source&lt;br /&gt;
sudo modprobe wl&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you can&#039;t connect the machine to the internet, download the needed packages on another machine and put it on some usb storage. These packages should suffice:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# apt-cache depends bcmwl-kernel-source&lt;br /&gt;
bcmwl-kernel-source&lt;br /&gt;
  Depends: dkms&lt;br /&gt;
  Depends: linux-libc-dev&lt;br /&gt;
  Depends: libc6-dev&lt;br /&gt;
  Conflicts: &amp;lt;bcmwl-modaliases&amp;gt;&lt;br /&gt;
  Replaces: &amp;lt;bcmwl-modaliases&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then install manually with &#039;&#039;&#039;dpkg -i file1.deb file2.deb&#039;&#039;&#039; etc&lt;br /&gt;
&lt;br /&gt;
After this, ip/ifconfig/iwconfig shouldd see the new wifi nic, probably &#039;&#039;&#039;wlan0&#039;&#039;&#039;, but due to a [https://bugs.launchpad.net/ubuntu/+source/broadcom-sta/+bug/1343151 old, ignored bug], you won&#039;t find any wifi networks. This is because the driver from Broadcom apparently does not support interrupt remapping, commonly used on x64 machines. To turn this off, change &#039;&#039;&#039;/etc/default/grub&#039;&#039;&#039; and change the line &#039;&#039;&#039;GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;quiet splash&amp;quot;&#039;&#039;&#039;, adding intremap=off to the end before the quote: &#039;&#039;&#039;GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;quiet splash intremap=off&amp;quot;&#039;&#039;&#039;. Save the file and run &#039;&#039;&#039;sudo update-grub&#039;&#039;&#039; and reboot. After this, wifi should work well.&lt;br /&gt;
&lt;br /&gt;
== Wifi with HP Compaq Presario CQ57 on Ubuntu ==&lt;br /&gt;
&lt;br /&gt;
The HP Compaq Presario CQ57 uses the RT5390 wifi chipset. This has been supported for quite some time now, and I was quite surprised to find it not working on a laptop a friend was having. The driver loaded correctly, but Ubuntu insisted of the laptop being in &#039;&#039;&#039;flight mode&#039;&#039;&#039;. Checking &#039;&#039;&#039;rfkill&#039;&#039;&#039;, it showed me two NICs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# rfkill list all&lt;br /&gt;
0: phy0: Wireless LAN&lt;br /&gt;
	Soft blocked: no&lt;br /&gt;
	Hard blocked: yes&lt;br /&gt;
1: hp-wifi: Wireless LAN&lt;br /&gt;
	Soft blocked: yes&lt;br /&gt;
	Hard blocked: no&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Turning rfkill on and off resulted in nothing much, except some error messages in the kernel log (dmesg)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] ACPI Error: Field [B128] at bit offset/length 128/1024 exceeds size of target Buffer (160 bits) (20170831/dsopcode-235)&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]&lt;br /&gt;
                            Initialized Local Variables for Method [HWCD]:&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Local0: 00000000a34b7928 &amp;lt;Obj&amp;gt;           Integer 0000000000000000&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Local1: 00000000b0aa6865 &amp;lt;Obj&amp;gt;           Buffer(8) 46 41 49 4C 04 00 00 00&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Local5: 00000000a9811efd &amp;lt;Obj&amp;gt;           Integer 0000000000000004&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] Initialized Arguments for Method [HWCD]:  (2 arguments defined for method invocation)&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Arg0:   0000000078957d1b &amp;lt;Obj&amp;gt;           Integer 0000000000000001&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Arg1:   00000000725c9c6e &amp;lt;Obj&amp;gt;           Buffer(20) 53 45 43 55 02 00 00 00&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] ACPI Error: Method parse/execution failed \_SB.WMID.HWCD, AE_AML_BUFFER_LIMIT (20170831/psparse-550)&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] ACPI Error: Method parse/execution failed \_SB.WMID.WMAD, AE_AML_BUFFER_LIMIT (20170831/psparse-550)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After upgrading BIOS and testing different kernels, I was asked to try to unload the &#039;&#039;&#039;hp_wmi&#039;&#039;&#039; driver. I did, and things changed a bit, so I tried blacklisting it, creating the file &#039;&#039;&#039;/etc/modprobe.d/blacklist-hp_wmi.conf&#039;&#039;&#039; with the following content&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Blacklist this - it doesn&#039;t work!&lt;br /&gt;
blacklist hp_wmi&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
I gave the machine a reboot and afte that, the &#039;&#039;&#039;hp-wifi&#039;&#039;&#039; entry was gone in the rfkill output, and things works.&lt;br /&gt;
&lt;br /&gt;
= Raspberry pi =&lt;br /&gt;
&lt;br /&gt;
I couldn&#039;t quite decide if the raspberry pi should be a separate section or part of Linux, but hell, it can run more than Linux, although 99,lots% of people just uses Linux on them. This is a small list of things to know about them; things not on the front page of the manual or perhaps hidden even better.&lt;br /&gt;
&lt;br /&gt;
== Which pi? ==&lt;br /&gt;
&lt;br /&gt;
I just setup three raspberry pi machines and although some are quite different, like v1 to vEverythingelse or the Pi zero versions to the normal ones, not all of us remember how to distinguish between them, and sometimes they&#039;re in a nice 3d printed (or otherwise) chassis or otherwise hidden. So, how to check three different ones:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
root@home-assistant:~ $ cat /proc/device-tree/model ; echo&lt;br /&gt;
Raspberry Pi 2 Model B Rev 1.1&lt;br /&gt;
&lt;br /&gt;
root@green-pi:~ $ cat /proc/device-tree/model ; echo&lt;br /&gt;
Raspberry Pi 3 Model B Rev 1.2&lt;br /&gt;
&lt;br /&gt;
roy@yellow-pi:~ $cat /proc/device-tree/model ; echo&lt;br /&gt;
Raspberry Pi 4 Model B Rev 1.1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
While this works well, for the latter, the pi4, it doesn&#039;t tell how much memory I have. It comes in variants of 1, 2 and 4GB, and this is the latter.&lt;br /&gt;
&lt;br /&gt;
== Monitoring ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;vcgencmd&#039;&#039;&#039; from &#039;&#039;&#039;/opt/vc/bin&#039;&#039;&#039;, but symlinked to &#039;&#039;&#039;/usr/bin&#039;&#039;&#039; so it&#039;s available in path, is useful for fetching hardware info about the pi. For example, measuring the temperature&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
root@yellow-pi:~# vcgencmd measure_temp&lt;br /&gt;
temp=63.0&#039;C&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The command is generally badly documented and parts of it seems outdated for newer hardware. Here&#039;s the output from a Raspberry pi 4 with 4GB RAM&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
roy@yellow-pi:~ $ vcgencmd get_mem arm&lt;br /&gt;
arm=948M&lt;br /&gt;
roy@yellow-pi:~ $ vcgencmd get_mem gpu&lt;br /&gt;
gpu=76M&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== BIOS upgrade from Linux ==&lt;br /&gt;
&lt;br /&gt;
Generally, BIOS upgrades have been moved to the BIOS itself these days. This saves a lot of work and quite possibly lives after those who earier rammed their heads through walls, now can upgrade directly from the internet instead of using obscure operating systems best avoided. Sometimes, however, one must use these nevertheless. This is a quick run-through on your options.&lt;br /&gt;
&lt;br /&gt;
=== DOS ===&lt;br /&gt;
&lt;br /&gt;
Most non-automatic BIOS upgrades are installed from DOS. Doing a BIOS upgrade this way, is generally non-problematic. Just install a USB thingie with [https://www.freedos.org/ FreeDOS], copy your file(s) onto the thing and boot on it. The commandline is the same as old MS/DOS, except a wee bit more userfriendly, but not a lot.&lt;br /&gt;
&lt;br /&gt;
=== Windows ===&lt;br /&gt;
&lt;br /&gt;
Some macahines, like laptops from &#039;&#039;&#039;HP&#039;&#039;&#039;, may have BIOS upgrades that are made to be installed from Windows and won&#039;t run in FreeDOS or MS/DOS, instead throwing an error, saying &#039;&#039;&#039;This program cannot be run in DOS mode&#039;&#039;&#039;. This means you&#039;ll have to boot on a Windows rescue disc and do the job from there. Googling this, tells you it&#039;s quite easy, you just choose &#039;make rescue disc&#039; from Windows, and it&#039;s all good, except if you don&#039;t run Windows, that is. To remedy this problem, do as follows:&lt;br /&gt;
&lt;br /&gt;
==== Download Windows ====&lt;br /&gt;
&lt;br /&gt;
Since you don&#039;t run Windows and possibly don&#039;t have a spouse or friend around with such unhealthy habits either, you need to get it. It&#039;s quite easy - just google &#039;download windows&#039; and it&#039;ll send you to [https://www.microsoft.com/en-us/software-download/windows10ISO somewhere like this].&lt;br /&gt;
&lt;br /&gt;
==== Burn it! ====&lt;br /&gt;
&lt;br /&gt;
Now it&#039;s time to burn the installer on a DVD ROM. You&#039;ll need a double-layered one, since the OS is &amp;gt; 4.7GiB, but I&#039;m sure you have a ton of those lying around. Now, just place your optical medium in your optical drive and burn, baby, burn!&lt;br /&gt;
&lt;br /&gt;
==== Or make a USB thing? ====&lt;br /&gt;
&lt;br /&gt;
Not a lot of machines have optical drives these days, so you may want to use an USB pen drive or something instead. This is easy, just make the USB bootable with the Windows application Microsoft has made for this. Unfortunately, this only runs on Windows, and unlike stuff like Debian, where the &#039;&#039;&#039;iso&#039;&#039;&#039; file can be dd&#039;ed directly onto a USB drive to make it bootable, the Windows &#039;&#039;&#039;iso&#039;&#039;&#039;s don&#039;t come with this luxury. There are lots of methods to make bootable USB things from iso files out there, but the only thing most of them have in common, is that they generally don&#039;t work.&lt;br /&gt;
&lt;br /&gt;
===== WoeUSB =====&lt;br /&gt;
&lt;br /&gt;
After hours of swearing, it&#039;s nice to come across software like [https://github.com/slacka/WoeUSB WoeUSB]. It may not be perfect, it relies on a bunch of GUI stuff you&#039;ll never need and so on, but it &#039;&#039;&#039;&#039;&#039;works&#039;&#039;&#039;&#039;&#039;, and that&#039;s the important part! Just clone the repo and RTFM and it&#039;s all nice. It&#039;s slow, but hell, getting a windows machine and/or an optical drive might be slower.&lt;br /&gt;
&lt;br /&gt;
WoeUSB does nothing fancy, but it &#039;&#039;&#039;does&#039;&#039;&#039; work. It will create a filesystem, FAT32 or NTFS (better use NTFS, FAT32 has its limits). It creates normal filesystems and so on. Just make sure to copy in the BIOS update file, usually an exe file, to run when Windows is up and running.&lt;br /&gt;
&lt;br /&gt;
===== Install BIOS =====&lt;br /&gt;
&lt;br /&gt;
Boot on the Windows USB thing and choose &#039;repair computer&#039; and then &#039;command prompt&#039;. Find the install file, and if you&#039;re lucky, you&#039;ll find it needs a 32bit OS, just like I did. Since the 64bit version doesn&#039;t include 32bit compatibility in the installer, revert to downloading the 32bit version of windows and start over. Pray to your favourite god(s) not to get across such machines again - it might help.&lt;br /&gt;
&lt;br /&gt;
= 3D printer stuff =&lt;br /&gt;
&lt;br /&gt;
== Hydrophilic filament ==&lt;br /&gt;
&lt;br /&gt;
Most popular filament types, including PLA, PETG, PP or PA (Polyamide, normally known as Nylon) and virtualy any filament type named [https://www.matterhackers.com/news/filament-and-water poly-something] (and thus with an acronym of P-something) are hydrophilic (also (somewhat incorrectly) called hydroscopic), meaning so long they&#039;re dryer than the atmosphere around them, they&#039;ll do their best to suck out the atmosphere&#039;s humidity. This is why most filament are shrink-wrapped with a small bag of silica gel in it. If such filament is exposed for normal humid air for some time, it&#039;ll become very hard to use. Most of my experience is with PLA, which can handle a bit (depending on make), but still not a lot. With PLA, if you end up with prints where the filament seems not to stick, it may help with a higher temperature. Otherwise, the filament must be [https://all3dp.com/2/how-to-dry-filament-pla-abs-and-nylon/ baked]. If you don&#039;t want to use your oven, try something like a [https://www.jula.no/catalog/hjem-og-husholdning/kjokkenmaskiner/mattilberedningsapparater/frukt-sopptorker/frukt-sopptorker-001641/#tab02 fruit and mushroom dryer]. Then get a good, sealble plastic box and add something like half a kilogram of [https://www.ebay.com/sch/sis.html?_nkw=1KG+Orange+Replacement+Desiccant+Indicating+Silica+Gel+Beads+for+Drawers%2C+Camera&amp;amp;_id=131938742628&amp;amp;&amp;amp;_trksid=p2057872.m2749.l2658 silica gel] to an old sock, tie it and put it in the your new dry box.&lt;br /&gt;
&lt;br /&gt;
Please note that ABS is hydrophobic, so you won&#039;t have to worry too much there. Also, remember that PA/Nylon is extremely hydrophilic. Even a couple of days in normal air humidity can ruin it completely and will require baking.&lt;br /&gt;
&lt;br /&gt;
== Upgrading the firmware on an Ender 3 ==&lt;br /&gt;
&lt;br /&gt;
This is about upgrading the firmware, and thus also flashing a bootloader to the Creality Ender 3 3D printer. Most of this is well documented on several place, like o [https://www.youtube.com/watch?v=fIl5X2ffdyo the video from Teaching tech] and elsewhere, but I&#039;ll just summarise some issues I had.&lt;br /&gt;
&lt;br /&gt;
=== Using an arduino Nano as a programmer ===&lt;br /&gt;
&lt;br /&gt;
Quick note before you read on. If you have an Ender 3 controller version 1.1.5 or newer (or perhaps even a bit older), an CR-10S or some other more or less modern printers or controllers, they come with a bootloader installed already, so don&#039;t bother flashing one. The one that&#039;s in there already, should work well. So if you have one of these, just skip this and jump to the next section.&lt;br /&gt;
&lt;br /&gt;
However, the normal CR-10 (without the S), Ender 3 and a few other printers from Creality come without a bootloader, so you&#039;ll need to flash one before upgrading the firmware. Well, strictly speakning, you don&#039;t need one, you can save those 8kB or so for other stuff and use a programmer to write the whole firmware, but then you&#039;ll need to wire up everything every time you want a new firmware, so in my world, you &#039;&#039;&#039;do&#039;&#039;&#039; need the bootloader, since it&#039;s easier.&lt;br /&gt;
&lt;br /&gt;
To install a bootloader, you&#039;ll need a programmer, and I didn&#039;t have one available. Having some el-cheapo china-copies of Ardinos around, I read I could use one and tried so. Although the docs mostly mention the Uno etc, it&#039;s just as simple with the Nano copy.&lt;br /&gt;
&lt;br /&gt;
So, grab an arduino, plug it to your machine with a USB cable, and, using the Arduino IDE, use the ArduinoISP sketch there (found under Examples) to burn the software needed for the arduino to work as a programmer. When this is done, connect a 10µF capacitor between RST and GND to stop it from resetting when used as a programmer. Connect the MOSI, MISO and SCK pins from the ICSP block (that little isolated 6-pin block on top of the ardu). See [https://www.arduino.cc/en/Tutorial/ArduinoISP here] for a pinout. Then find Vcc and GND either on the ICSP block or elsewhere. Some sites say that on some boards you shouldn&#039;t use the pins on the ICSP block for this. I doubt it matters, though. Then connect another jumper wire from pin 10 on the ardu to work as the reset pin outwards to the chip being programmed (that is, on the printer). The ICSP jumper block pin layout is the same on the printer and on the ardu, and probably elsewhere. Sometimes [https://xkcd.com/927/ standardisation] actually works…&lt;br /&gt;
&lt;br /&gt;
See https://cloud.karlsbakk.net/index.php/s/zw48YJjzaf8Rc2F for a pic with the ardu (this wiki is broken atm, will fix it later)&lt;br /&gt;
&lt;br /&gt;
== Flashing the printer ==&lt;br /&gt;
&lt;br /&gt;
When the boot loader is in place, possibly after some wierd errors from during the process, the screen on the 3d printer will go blank and it&#039;ll behave like being bricked. This is ok. Now disconnect the wires and connect the USB cable between computer and printer. If you haven&#039;t installed support for the Sanguino board, that is, the variant of the 1284-chip and surrounding electronics that is the core of the, you need to install it first. In the Arduino IDE, choose the Tools / Boards / Boards manager boot option and search for Sanguino. After this, you should find the Sanguino or Sanguino 1284p in the boards menu. After this, you should be able to communicate with the printer&#039;s controller. Download the [https://www.th3dstudio.com/knowledgebase/th3d-unified-firmware-package/ TH3D unified firmware], making sure it&#039;s the last version. Uncompress the zip and with Finder/Explorer/whateversomething&#039;scalledonlinux, browse to &#039;&#039;&#039;TH3DUF_R2/Firmware/TH3DUF_R2.ino&#039;&#039;&#039; and open it. It should open directly in the Android IDE. Keep in mind that the names TH3DUF_R2 and TH3DUF_R2.ino will vary between versions, but you get the point. Now configure it for your particular needs. You&#039;ll find most of this in the Configuration.h tab (that&#039;s really a file). Most of the other files won&#039;t be necessary unless you&#039;re doing some more advanced stuff, like replacing th controller with something non-standard or similar, but then again, that&#039;s another chapter (or book, even). The video mentioned above describes this well. After flashing the new firmware, you&#039;ll probably get some timeouts and errors, since apparently it resets the printer after giving it the new firmware, but without notifying the flashing software of it doing so. If this happens, calm down and reboot the printer and check its tiny monitor - it should work. If it doesn&#039;t work, and if you flashed the bootload yourself, try to flash it again, and if that doesn&#039;t work, try flashing the programmer again yet another time, just for kicks. Again, if you have a newer controller like the v1.1.5, don&#039;t touch the bootloader, as the one already installed, should work well as it is.&lt;br /&gt;
&lt;br /&gt;
PS: I tried enabling &#039;&#039;&#039;MANUAL_MESH_LEVELING&#039;&#039;&#039;, which in the code says that &#039;&#039;If used with a 1284P board the bootscreen will be disabled to save space&#039;&#039;. This effectively disabled the whole thing, and apparently may be making the firmware image a wee bit too large for it to fit the 1284P on the ender. It works well without it, though.&lt;br /&gt;
&lt;br /&gt;
== And then… ==&lt;br /&gt;
&lt;br /&gt;
With the new firmware in place, the printer should work as before, although with thermal runaway protection to better avoid fires in case the shit hits the fan, and to allow for things like autolevelling. With any luck, [https://www.precisionpiezo.co.uk/ this thing] may be ready for use by the time you read this - it surely looks nice!&lt;br /&gt;
&lt;br /&gt;
roy&lt;/div&gt;</summary>
		<author><name>Roy</name></author>
	</entry>
	<entry>
		<id>https://wiki.malinux.no/index.php?title=Roy%27s_notes&amp;diff=157</id>
		<title>Roy&#039;s notes</title>
		<link rel="alternate" type="text/html" href="https://wiki.malinux.no/index.php?title=Roy%27s_notes&amp;diff=157"/>
		<updated>2020-05-22T01:49:51Z</updated>

		<summary type="html">&lt;p&gt;Roy: /* Flashing the printer */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= LVM, md and friends =&lt;br /&gt;
&lt;br /&gt;
== Linux&#039; Logical Volume Manager (LVM) ==&lt;br /&gt;
&lt;br /&gt;
=== LVM in general ===&lt;br /&gt;
&lt;br /&gt;
LVM is designed to be an abstraction layer on top of physical drives or RAID, typically [https://raid.wiki.kernel.org/index.php/RAID_setup mdraid] or [https://help.ubuntu.com/community/FakeRaidHowto fakeraid]. Keep in mind that fakeraid should be avoided unless you really need it, like in conjunction with dual-booting linux and windows on fakeraid. LVM broadly consists of three elements, the &amp;quot;physical&amp;quot; devices (PV), the volume group (VG) and the logical volume (LV). There can be multiple PVs, VGs and LVs, depending on requirement. More about this below. All commands are given as examples, and all of them can be fine-tuned using extra flags in need of so. In my experience, the defaults work well for most usecases.&lt;br /&gt;
&lt;br /&gt;
I&#039;m mentioning filesystem below too. Where I write ext4, the samme applies to ext2 and ext3.&lt;br /&gt;
&lt;br /&gt;
==== Create a PV ====&lt;br /&gt;
&lt;br /&gt;
A PV is the &amp;quot;physical&amp;quot; parts. This does not need to be a physical disk, but can also be another RAID, be it an mdraid, fakeraid, hardware raid, a virtual disk on a SAN or otherwisee or a partition on one of those. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#  These add three PVs, one on a drive (or hardware raid) and another two on mdraids.&lt;br /&gt;
pvcreate /dev/sdb&lt;br /&gt;
pvcreate /dev/md1 /dev/md2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For more information about pvcreate, see [https://linux.die.net/man/8/pvcreate the manual].&lt;br /&gt;
&lt;br /&gt;
==== Create a VG ====&lt;br /&gt;
&lt;br /&gt;
The volume group consists of one or more PVs grouped together on which LVs can be placed. If several PVs are grouped in a VG, it&#039;s generally a good idea to make sure these PVs have some sort of redundancy, as in mdraid/fakeraid or hwraid. Otherwise it will be like using a [https://en.wikipedia.org/wiki/RAID RAID-0] with a single point of failure on each of the independant drives. LVM has [https://unix.stackexchange.com/questions/150644/raiding-with-lvm-vs-mdraid-pros-and-cons  RAID code in it] as well, so you can use that. I haven&#039;t done so myself, as I generally stick to mraid. The reason is mdraid is, in my opinion older and more stable and has more users (meaning bugs are reported and fixed faster whenever they are found). That said, I beleive the actual RAID code used in LVM RAID are the same function calls as for mdraid, so it may not be much of a difference. I still stick with mdraid. To create a VG, run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create volume group my_vg&lt;br /&gt;
vgcreate my_vg /dev/md1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that if vgcreate is run with a PV (as /dev/md1 above) that is not defined as a PV (like above), this is done implicitly, so if you don&#039;t need any special flags to pvcreate, you can simply skip it and let vgcreate do that for you.&lt;br /&gt;
&lt;br /&gt;
==== Create an LV ====&lt;br /&gt;
&lt;br /&gt;
LVs can be compared to partitions, somehow, since they are bounderies of a fraction or all of that of a VG. The difference between them and a partition, however, is that they can be grown or shrunk easily and also moved around between PVs without downtime. This flexibility makes them superiour to partitions as your system can be changed without users noticing it. By default, an LV is alloated &amp;quot;thickly&amp;quot;, meaning all the data given to it, is allocated from the VG and thus the PV. The following makes a 100GB LV named &amp;quot;thicklv&amp;quot;. When making an LV, I usually allocate what&#039;s needed plus some more, but not everything, just to make sure it&#039;s space available for growth on any of the LVs on the VG, or new LVs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a thick provisioned LV named thicklv on the VG my_vg&lt;br /&gt;
lvcreate -n thicklv -L 100G my_vg&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After the LV is created, a filesystem can be placed on it unless it is meant to be used directly. The application for direct use include swap space, VM storage and certain database systems. Most of these will, however, work on filesystems too, although my testing has shown that on swap space, there is a significant performance gain for using dedicated storage without a filesystem. As for filesystems, most Linux users use either ext4 or xfs. Personally, I generally use XFS these days. See my notes below on filesystem choice.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a filesystem on the LV - this could have been mkfs -t ext4 or whatever filesystem you choose&lt;br /&gt;
mkfs -t xfs /dev/my_vg/thicklv&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then just edit /etc/fstab with correct data and run mount -a, and you should be all set.&lt;br /&gt;
&lt;br /&gt;
==== Create LVM cache ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
lvcreate -L 1G -n _cache_meta data /dev/md1&lt;br /&gt;
&lt;br /&gt;
lvcreate -l100%FREE -n _cache data /dev/md1&lt;br /&gt;
&lt;br /&gt;
# Some would want --cachemode writeback, but seriously, I wouldn&#039;t recommend it. Metadata or data can be easily corrupted in case of failure.&lt;br /&gt;
lvconvert --type cache-pool --cachemode writethrough --poolmetadata data/_cache_meta data/_cache&lt;br /&gt;
&lt;br /&gt;
lvconvert --type cache --cachepool data/_cache data/data&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Disabling LVM cache ====&lt;br /&gt;
&lt;br /&gt;
If you for some reason want to disable caching, this will do it cleanly and remove the LVs earlier created for caching the main device.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
lvconvert --uncache data/data&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Growing devices ====&lt;br /&gt;
&lt;br /&gt;
LVM objects can be grown and shrunk. If a PV resides on a RAID where a new drive has been added or otherwise grown, or on a partition or virtual disk that has been extended, the PV must be updated to reflect these changes. The following command will grow the PV to the maximum available on the underlying storage. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Resize the PV /dev/md (not the RAID, only the PV on the RAID) to its full size&lt;br /&gt;
pvresize /dev/md1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If a new PV is added, the VG can be grown to add the space on that in addition to what&#039;s there already. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Extend my_vg to include md2 and its space&lt;br /&gt;
vgextend my_vg /dev/md2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
With more space available in the VG, the LV can now be extended. Let&#039;s add another 50GB to it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Extend thicklv - add 50GB. If you know you won&#039;t need the space anywhere else, you may want to&lt;br /&gt;
# lvresize -l+100%FREE instead. Keep in mind the difference between -l (extents) and -L (bytes)&lt;br /&gt;
lvresize -L +50G my_vg/thicklv&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Growing filesystems ====&lt;br /&gt;
After the LV has grown, run &#039;&#039;xfs_growfs&#039;&#039; (xfs) or &#039;&#039;resize2fs&#039;&#039; (ext4) to make use of the new data. To grow the filesystem to all available space on ext4, run the below command.  To partly grow the filesystem or to shrink it or otherwise, please see the manuals.&lt;br /&gt;
&lt;br /&gt;
The filesystem can be mounted when this is run. If you for some reason get an &#039;&#039;&#039;access denied&#039;&#039;&#039; error when running this as root or with sudo, it&#039;s likely caused by a filesystem error. To fix this, unmount the filesystem first and run &#039;&#039;&#039;fsck -f /dev/my_vg/thicklv&#039;&#039;&#039; and remount it before retrying to extend it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
resize2fs /dev/my_vg/thicklv&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Similarly, with XFS, but note that xfs_growfs doesn&#039;t take the device name, but the filesystem&#039;s mount point. In the case of XFS, also note that the filesystem &#039;&#039;&#039;&#039;&#039;must&#039;&#039;&#039;&#039;&#039; be mounted to be grown. This, in contrast to how it was in the old days when filesystems had to be unmounted to be grown.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
xfs_growfs /my_mountpoint&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Rename system VG ====&lt;br /&gt;
&lt;br /&gt;
Some distros create VG names like those-from-a-sysadmin-with-a-well-developed-paranoia-not-to-hit-a-duplicate. Debian, for instance, uses names like &amp;quot;my-full-hostname-vg&amp;quot;. Personally, I don&#039;t like these, since if I were to move a disk or vdisk around to somewhere else, I&#039;d make sure not to add a disk named &#039;sys&#039; to an existing system. If you do, most distros will refuse to use the VGs with duplicate names, resulting in the OS not booting until either one is specified by its UUID or just one removed. As I&#039;m aware of this, I stick to the super-risky thing of all system VGs named &#039;sys&#039; and so on.&lt;br /&gt;
&lt;br /&gt;
If you do this, keep in mind that it may blow up your computer and take your girl- or boyfriend with it or even make either of them pregnant, allowing Trump to rule your life and generally make things suck. You&#039;re on your own!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Rename the VG&lt;br /&gt;
vgrename my-full-hostname-vg sys&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, in /boot/grub/grub.cfg, change the old lv path from something like &#039;/dev/mapper/debian--stretch--machine--vg-root&#039; to your new and fancy &#039;/dev/sys/root. Likewise, in /etc/fstab, change occurences of &#039;/dev/mapper/debian--stretch--machine--vg-&#039; (or similar) with &#039;/dev/sys/&#039;. Here, this was like this - the old ones commented out.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;fstab&amp;quot;&amp;gt;&lt;br /&gt;
#/dev/mapper/debian--stretch--box--vg-root      /               ext4            errors=remount-ro,discard       0       1&lt;br /&gt;
/dev/sys/root                                   /               ext4            errors=remount-ro,discard       0       1&lt;br /&gt;
# /boot was on /dev/vda1 during installation&lt;br /&gt;
UUID=myverylonguuidwithatonofgoodinfoinit       /boot           ext2            defaults                        0       2&lt;br /&gt;
#/dev/mapper/debian--stretch--box--vg-swap_1    none            swap            sw                              0       0&lt;br /&gt;
/dev/sys/swap_1                                 none            swap            sw                              0       0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Update /etc/initramfs-tools/conf.d/resume with similar data for swap.&lt;br /&gt;
&lt;br /&gt;
You might want to run &#039;update-initramfs -u -k all&#039; after this, but I&#039;m not sure if it&#039;s needed.&lt;br /&gt;
&lt;br /&gt;
Now, pray to the nearest god(s) and give it a reboot and it should (probably) work.&lt;br /&gt;
&lt;br /&gt;
After reboot, run &#039;&#039;&#039;swapoff -a&#039;&#039;&#039;, then &#039;&#039;&#039;mkswap /dev/sys/swap_1&#039;&#039;&#039; (or whatever it&#039;s called on your system) and &#039;&#039;&#039;swapon -a&#039;&#039;&#039; again. You may want to give it another reboot or two for kicks, but it should work well even without that.&lt;br /&gt;
&lt;br /&gt;
=== Migration tools ===&lt;br /&gt;
&lt;br /&gt;
At times, storage regimes change, new storage is added and sometimes it&#039;s not easy to migrate with the current hardware or its support systems. Once I had to migrate a 45TiB fileserver from one storage system to another, preferably without downtime. The server originally had three 15TiB PVs of which two were full and the third half full. I resorted to using [https://linux.die.net/man/8/pvmove pvmove] to just move the data on the PVs in use to a new PV. We started out with creating a new 50TiB PV, sde, and then to pvmove.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Attach /dev/sde to the VG my_vg&lt;br /&gt;
vgextend my_vg /dev/sde&lt;br /&gt;
&lt;br /&gt;
# Move the contents from /dev/sdb over to /dev/sde block by block. If a target is not given in pvmove,&lt;br /&gt;
# the contents of the source (sdb here) will be put somewhere else in the pool.&lt;br /&gt;
pvmove /dev/sdb /dev/sde&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This took a while (as in a week or so) - the pvmove command uses old code and logic (or at least did that when I migrated this in November 2016), but it affected performance on the server very little, so users didn&#039;t notice. After the first PV was migrated, I continued with the other two, one after the other, and after a month or so, it was migrated. We used this on a number of large fileservers, and it worked flawlessly. Before doing the production servers I also tried interrupting pvmove in various ways, including hard resets, and it just kept on after the reboot.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;NOTE:&#039;&#039;&#039;&#039;&#039; &#039;&#039;Even though it worked well for us, &#039;&#039;&#039;always&#039;&#039;&#039; keep a good backup before doing this. Things may go wrong, and without a good backup, you may be looking for a hard-to-find new job the next morning&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
==== mdadm workarounds ====&lt;br /&gt;
&lt;br /&gt;
===== Migrate from a mirror (raid-1) to raid-10 =====&lt;br /&gt;
&lt;br /&gt;
Create a mirror&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sdb /dev/sdc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
LVM (pv/vg/lv) on md0 (see above), put a filesystem on the lv and fill it with some data.&lt;br /&gt;
&lt;br /&gt;
Now, some months later, you want to change this to raid-10 to allow for the same amount of redundancy, but to allow more disks into the system.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mdadm --grow /dev/md0 --level=10&lt;br /&gt;
mdadm: Impossibly level change request for RAID1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So - no - doesn&#039;t work. But - we&#039;re on &lt;br /&gt;
&lt;br /&gt;
Since we&#039;re on lvm already, this&#039;ll be easy. If you&#039;re using filesystems directly on partitions, you can do this the same way, but without the pvmove part, using rsync or whateever you like instead. I&#039;d recommend using lvm for for the new raid, which should be rather obvious from this article. Now plug in a new drive and create a new raid10 on that one. If you two new drives, install both. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# change &amp;quot;missing&amp;quot; to the other device name if you installed two new drives&lt;br /&gt;
mdadm --create /dev/md1 --level=10 --raid-devices=2 /dev/vdd missing&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, as described above, just vgextend the vg, adding the new raid and run pvmove to move the data from the old pv (residing on the old raid1) to the new pv (on raid10). Afte rpvmove is finished (which may take awile, see above), just&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
vgreduce raidtest /dev/md0&lt;br /&gt;
pvremove /dev/md0&lt;br /&gt;
mdadm --stop /dev/md0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
…and your disk is free to be added to the new array. If the new raid is running in degraded mode (if you created it with just one drive), better don&#039;t wait too long, since you don&#039;t have redundancy. Just mdadm --add the devs.&lt;br /&gt;
&lt;br /&gt;
If you now have /dev/mdstat telling you your raid10 is active and have three drives, of which one is a spare, it should look something like this&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5] [raid4] [raid10]&lt;br /&gt;
md1 : active raid10 vdc[3](S) vdb[2] vdd[0]&lt;br /&gt;
      8380416 blocks super 1.2 2 near-copies [2/2] [UU]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Just mdadm --grow --raid-devices=3 /dev/md1&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;RAID section is not complete. I&#039;ll write more on migraing from raid10 to raid6 later. It&#039;s not straight forward, but easier than this one :)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== Thin provisioned LVs ===&lt;br /&gt;
&lt;br /&gt;
Thin provisioning on LVM is a method used for not allocating all the space given to an LV. For instance, if you have a 1TB VG and want to give an LV 500GB, although it currently only uses a fraction of that, a thin lv can be a good alternative. This will allow for adding a limit to how much it can use, but also to let it grow dynamically without manual work by the sysadmin. Thin provisioning adds another layer of abstaction by creating a special LV as a &#039;&#039;thin pool&#039;&#039; from which data is allocated to the &#039;&#039;thin volume(s)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== Create a thin pool ====&lt;br /&gt;
&lt;br /&gt;
Allocate 1TB to the thin pool to be used for thinly provisioned LVs. Keep in mind that the space allocated to the thin pool is in fact thick provisioned. Only the volumes put on &#039;&#039;thinpool&#039;&#039; are thin provisioned. This will create two hidden LVs, one for data and one for metadata. Normally the defaults will do, but check the manual if the data doesn&#039;t match the usual patterns (such as billions of files, resulting in huge amounts of metadata). I &#039;&#039;beleive&#039;&#039; the metadata part should be resizable at a later time if needed, but I have not tested it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a pool for thin LVs. Keep in mind that the pool itself is not thin provisioned, only the volumes residing on it&lt;br /&gt;
lvcreate --size 1T --type thin-pool --thinpool thinpool my_vg&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Create a thin volume ====&lt;br /&gt;
&lt;br /&gt;
You have the thinpool, now put a thin volume on it. It will allocate some space for metadata, but probably not much (a few megs, perhaps).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Now, create a volume with a virtual (-V) size of half a terabyte named thin_pool, but using the thinpool (-T) named thin_pool for storage&lt;br /&gt;
lvcreate -V 500G -T my_vg/thin_pool --name thinvol&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The new volume&#039;s device name will be /dev/thinvol. Now, create a filesystem on it, add to fstab and mount it. The &#039;&#039;&#039;df&#039;&#039;&#039; command will return available space according to the virtual size (-V), while lvs will show how much data is actually used on each of the thinly provisioned volumes.&lt;br /&gt;
&lt;br /&gt;
== Filesystem dilemmas ==&lt;br /&gt;
&lt;br /&gt;
=== XFS or ext4 or something else ===&lt;br /&gt;
The choice of filesystem varies for your use. Distros such as RHEL/CentOS has moved to XFS by default from v7. Debian/Ubuntu still sticks to ext4, like most other. I&#039;ll discuss my thoughts below on ext4 vs XFS and leave the other filesystems for later.&lt;br /&gt;
&lt;br /&gt;
==== ext4 ====&lt;br /&gt;
ext4 is probably the most used filesystem on linux as of writing. It&#039;s rock stable and has been extended by a lot of extensions since the original ext2. It still retains backward compatibility, being able to mount and fsck ext2 and ext3 with the ext4 driver. However, it doesn&#039;t handle large filesystems very well. If a filesystem is created for &amp;lt;16TiB, it cannot be grown to anything larger than 16TiB. This may have changed lately, though. One other issue is handling errors. If a large filesystem (say 10TiB) is damaged, an fsck may take several hours, leading to long downtime. When I refer to ext4 further in this text, the same applies to ext2 and ext3 unless otherwise specified.&lt;br /&gt;
&lt;br /&gt;
==== XFS ====&lt;br /&gt;
XFS, originally developed by SGI some time in the bronze age, but has been worked on heavily after that. RHEL and Centos version 7 and forward, uses XFS as the default filesystem. It is quick, it scales well, but it lacks at least two things ext4 has. It cannot be shrunk (not that you normally need that, but nice if you have a typo or you need to change things). Also, it doesn&#039;t allow for automatic fsck on bootup. If something is messed up on the filesystem, you&#039;ll have to login as root on the console (not ssh), which might be an issue on some systems. The fsck equivalent, xfs_repair, is a *lot* faster than ext4&#039;s fsck, though.&lt;br /&gt;
&lt;br /&gt;
==== ZFS ====&lt;br /&gt;
ZFS is like a combination of RAID, LVM and a filesystem, supporting full checksumming, auto-healing (given sufficient redundancy), compression, encryption, replication, deduplication (if you&#039;re brave and have a &#039;&#039;ton&#039;&#039; of memory) and a lot more. It&#039;s a separate chapter and needs a lot more talk than paragraph here.&lt;br /&gt;
&lt;br /&gt;
==== btrfs ====&lt;br /&gt;
btrfs, pronounced &amp;quot;butterfs&amp;quot; or &amp;quot;betterfs&amp;quot; or just spelled out, is a filesystem that mimics that of ZFS. It has been around for 10 years or so, but hasn&#039;t yet proven to be really stable. Following the progress of it for those years, I&#039;ve found it to be a nice toy with which to play, but not to be used in production. Again, others may say otherwise, but these are just my words.&lt;br /&gt;
&lt;br /&gt;
== Low level disk handling ==&lt;br /&gt;
&lt;br /&gt;
This section is for low-level handling of disks, regardless of storage system elsewhere. These apply to mdraid, lvmraid and zfs and possibly other solutions, with the exception of individual drives on hwraid (and maybe fakeraid), since there, the drives are hidden from Linux (or whatever OS).&lt;br /&gt;
&lt;br /&gt;
=== S.M.A.R.T. and slow drives ===&lt;br /&gt;
Modern (that is, from about 1990 or later) have S.M.A.R.T. (or just smart, since it&#039;s easier to type) monitoring built in, meaning the disk&#039;s controller is monitoring itself. This is handy and will ideally tell you in advance that a drive is flakey or dying. Modern (2010+) smart monitoring is more or less the same. It can be trusted about 50% of the time. Usually, if smart detects an error, it&#039;s a real error. I don&#039;t think I&#039;ve seen it reporting a false positive, but others may know better. &lt;br /&gt;
&lt;br /&gt;
==== smartmontools ====&lt;br /&gt;
First, install smartmontool and run smartclt -H /dev/yourdisk (/dev/sda or something) to get a health report. Then perhaps run smartctl -a /dev/yourdisk and look for &#039;current pending sectors&#039; This should be zero. Also check the temperature, which normally should be much above 50.&lt;br /&gt;
&lt;br /&gt;
==== single, slow drive ====&lt;br /&gt;
What may happen, is smart not seeing anything and life goes on like before, only slower and less prouductive, without telling anyone. If you stubler over this issue, you&#039;ll probably see it during a large rsync/zfs send/receive or a resync/rebuild/resilver of the raid/zpool. During this, it feels like everything is slow and your RAID has turned into a RAIF (redundant array of inexpensive floppies). To check if you have a single drive messing up it all, check with &#039;&#039;&#039;iostat -x 2&#039;&#039;&#039;, having 2 being the delay between each measurement. Interrupt it with ctrl+x. If there&#039;s a rougue drive there, it should stand out like sdg below&lt;br /&gt;
&lt;br /&gt;
 avg-cpu:  %user   %nice %system %iowait  %steal   %idle&lt;br /&gt;
            0.38    0.00    1.75    0.00    0.00   97.87&lt;br /&gt;
&lt;br /&gt;
 Device            r/s     w/s     rkB/s     wkB/s   rrqm/s   wrqm/s  %rrqm  %wrqm r_await w_await aqu-sz rareq-sz wareq-sz  svctm  %util&lt;br /&gt;
 sda              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdb              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdc              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdd              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sde              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdf              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdg              3.50    0.00   2352.00      0.00     0.00     0.00   0.00   0.00 14306.29    0.00  13.85   672.00     0.00 285.71 100.00&lt;br /&gt;
 sdh              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
&lt;br /&gt;
In ZFS land, you should be able to get similar data with &#039;&#039;&#039;zpool iostat -v &amp;lt;pool&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Now you know the bad drive (sdg), pull it from the raid with &#039;&#039;&#039;mdadm --fail /dev/mdX /dev/sdX&#039;&#039;&#039;. Now test the drive&#039;s performance manually, just simply:&lt;br /&gt;
&lt;br /&gt;
 # hdparm -t /dev/sdg&lt;br /&gt;
 &lt;br /&gt;
 /dev/sdg:&lt;br /&gt;
  Timing buffered disk reads:   2 MB in  5.37 seconds = 381.46 kB/sec&lt;br /&gt;
&lt;br /&gt;
Bingo - nothing you&#039;d want to keep. For a good drive, it should be something like 100-200MB/s&lt;br /&gt;
&lt;br /&gt;
PS: Keep in mind that you have a degraded RAID by now in case you had a spare waiting for things to happen.&lt;br /&gt;
&lt;br /&gt;
Try to replace the cable and/or try the disk on another port/controller. If the result from hdparm persists, it&#039;s probably a bad cable&lt;br /&gt;
&lt;br /&gt;
So, then, just psycially locate the drive, pull it out, take out the discs and magnets and recycle the rest.&lt;br /&gt;
&lt;br /&gt;
=== &amp;quot;Unplug&amp;quot; drive from system ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Find the device unit&#039;s number with something like&lt;br /&gt;
find /sys/bus/scsi/devices/*/block/ -name sdd&lt;br /&gt;
# returning /sys/bus/scsi/devices/3:0:0:0/block/sdd here, &lt;br /&gt;
# meaning 3:0:0:0 is the SCSI device we&#039;re looking for.&lt;br /&gt;
&lt;br /&gt;
# Given this is the correct device, and you want to &#039;unplug&#039; it, do so by&lt;br /&gt;
echo 1 &amp;gt; /sys/bus/scsi/devices/3:0:0:0/delete&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Rescan disk controllers ===&lt;br /&gt;
If a drive is added and for some reason doesn&#039;t get detected, or is removed by the command above, it can be rediscovered with a sysfs command to the scsi host to which it is connected. Since there may be quite a few of these, an easy way is to just scan them all and check the output of &#039;&#039;&#039;dmesg -T&#039;&#039;&#039; after running it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Make a list of controllers and send a rescan message to each of them. It won&#039;t do anything &lt;br /&gt;
# for those where nothing has changed, but it will show new drives where they have been added.&lt;br /&gt;
for host_scan in /sys/class/scsi_host/host*/scan&lt;br /&gt;
do&lt;br /&gt;
  echo &#039;- - -&#039; &amp;gt; $host_scan&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Fail injection with debugfs ===&lt;br /&gt;
[https://lxadm.com/Using_fault_injection https://lxadm.com/Using_fault_injection]&lt;br /&gt;
&lt;br /&gt;
== mdadm stuff ==&lt;br /&gt;
=== Resync ===&lt;br /&gt;
To resync a raid, that is, check, run&lt;br /&gt;
&lt;br /&gt;
 echo check &amp;gt; /sys/block/$dev/md/sync_action&lt;br /&gt;
&lt;br /&gt;
where $dev is something like md0. If you have several raids, something like this should work&lt;br /&gt;
&lt;br /&gt;
 for dev in md{0,1}&lt;br /&gt;
 do&lt;br /&gt;
   echo repair &amp;gt; /sys/block/$dev/md/sync_action&lt;br /&gt;
 done&lt;br /&gt;
&lt;br /&gt;
Also useful in a one-liner like&lt;br /&gt;
&lt;br /&gt;
 for dev in md{0,1} ; do echo repair &amp;gt; /sys/block/$dev/md/sync_action ; done&lt;br /&gt;
&lt;br /&gt;
Different raids on different drives will do this in parallel. If the drives are shared somehow with partitions or similar, the check or repair will wait for the other to finish before going on.&lt;br /&gt;
&lt;br /&gt;
As for repair vs check, [https://raid.wiki.kernel.org/index.php/RAID_Administration this article] describes it well. I stick to using repair unless it&#039;s something rare where I don&#039;t want to touch the data.&lt;br /&gt;
&lt;br /&gt;
=== Spare pools ===&lt;br /&gt;
In the old itmes, mdadm supported only a dedicated spare per md device, so if working with a large set of drives (20? 40?), where you&#039;d want to setup more raid sets to increase redundancy, you&#039;d dedicate a spare to each of the raid sets. This has changed (some time ago?), so in these modern, heathen days, you can change mdadm.conf, usually placed under /etc/mdadm, and add &#039;spare-group=somegroup&#039; where &#039;somegroup&#039; is a string identifying the spare group. After doing this, run &#039;&#039;&#039;update-initramfs -u&#039;&#039;&#039; and reboot and add a spare to one of the raid sets in the spare group, and md will use that or those spares for all the raidsets in that group.&lt;br /&gt;
&lt;br /&gt;
As some pointed out on #linux-raid @ irc.freenode.net, this feature is very badly documented, but as far as I can see, it works well.&lt;br /&gt;
&lt;br /&gt;
==== Example config ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create two raidsets&lt;br /&gt;
&lt;br /&gt;
mdadm --create /dev/md1 --level=6 --raid-devices=6 /dev/vd[efghij]&lt;br /&gt;
mdadm --create /dev/md2 --level=6 --raid-devices=6 /dev/vd[klmnop]&lt;br /&gt;
&lt;br /&gt;
# get their UUID etc&lt;br /&gt;
&lt;br /&gt;
mdadm --detail --scan&lt;br /&gt;
ARRAY /dev/md/1 metadata=1.2 name=raidtest:1 UUID=1a8cbdcb:f4092350:348b6b80:c054d74c&lt;br /&gt;
ARRAY /dev/md/2 metadata=1.2 name=raidtest:2 UUID=894b1b7c:cb7eba70:917d6033:ea5afd2b&lt;br /&gt;
&lt;br /&gt;
# Put those lines into /etc/mdadm/mdadm.conf and and add the spare-group&lt;br /&gt;
&lt;br /&gt;
ARRAY /dev/md/1 metadata=1.2 name=raidtest:1 spare-group=raidtest UUID=1a8cbdcb:f4092350:348b6b80:c054d74c&lt;br /&gt;
ARRAY /dev/md/2 metadata=1.2 name=raidtest:2 spare-group=raidtest UUID=894b1b7c:cb7eba70:917d6033:ea5afd2b&lt;br /&gt;
&lt;br /&gt;
# update the initramfs and reboot&lt;br /&gt;
&lt;br /&gt;
update-initramfs -u&lt;br /&gt;
reboot&lt;br /&gt;
&lt;br /&gt;
# add a spare drive to one of the raids&lt;br /&gt;
&lt;br /&gt;
mdadm --add /dev/md1 /dev/vdq&lt;br /&gt;
&lt;br /&gt;
# fail a drive on the other raid&lt;br /&gt;
&lt;br /&gt;
mdadm --fail /dev/md2 /dev/vdn&lt;br /&gt;
&lt;br /&gt;
# check /proc/mdstat to see md2 rebuilding with the spare from md1&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Recovery ===&lt;br /&gt;
&lt;br /&gt;
The other day, I came across a problem a user had on #linux-raid@irc.freenode.net. He had an old Qnap NAS that had died and tried plugging the drives in to his Linux machine and got various errors. The two-drive RAID-1 did not come up as it should, &#039;&#039;&#039;dmesg&#039;&#039;&#039; was full of errors from one of the drives (both connected on USB) and so forth.&lt;br /&gt;
&lt;br /&gt;
We went on and started by taking down the machine and just connecting one of the drives. I had him check what was assembled with&lt;br /&gt;
&lt;br /&gt;
 cat /proc/mdstat&lt;br /&gt;
&lt;br /&gt;
That returned /proc/md127 assembled, but LVM didn&#039;t find anything. So running a manual scan&lt;br /&gt;
&lt;br /&gt;
 pvscan --cache /dev/md127&lt;br /&gt;
&lt;br /&gt;
This made linux find the PV, VG and a couple of LVs, but probably because the mdraid was degraded, the LVs were deactivated, according to &#039;&#039;&#039;lvscan&#039;&#039;&#039;. Activating the one with a filesystem manually&lt;br /&gt;
&lt;br /&gt;
 lvchange -a y /dev/&amp;lt;vg&amp;gt;/&amp;lt;lv&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Substitute &amp;lt;vg&amp;gt; and &amp;lt;lv&amp;gt; with the names listed by vgs and lvs.&lt;br /&gt;
&lt;br /&gt;
This worked, and the filesystem on /dev/&amp;lt;vg&amp;gt;/&amp;lt;lv&amp;gt; could be mounted correctly.&lt;br /&gt;
&lt;br /&gt;
== Tuning ==&lt;br /&gt;
&lt;br /&gt;
While trying to compare a 12-disk RAID (8TB disks) to a hwraid, mdraid was slower, so we did a few things to speed things up:&lt;br /&gt;
&lt;br /&gt;
While testing with [https://linux.die.net/man/1/fio fio], monitor /sys/block/md0/md/stripe_cache_active, and see if it&#039;s close to /sys/block/md0/md/stripe_cache_size. If it is, double the size of the latter&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
echo 4096 &amp;gt; /sys/block/md0/md/stripe_cache_size&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Continue until stripe_cache_active stabilises, and then you&#039;ve found the limit you&#039;ll need. You may want to double that for good measure. &lt;br /&gt;
&lt;br /&gt;
(to be continued)&lt;br /&gt;
&lt;br /&gt;
== Links ==&lt;br /&gt;
&lt;br /&gt;
Below are a few links with useful info&lt;br /&gt;
&lt;br /&gt;
* [https://raid.wiki.kernel.org/index.php/Irreversible_mdadm_failure_recovery Irreversible mdadm failure recovery]&lt;br /&gt;
&lt;br /&gt;
= ZFS =&lt;br /&gt;
&lt;br /&gt;
ZFS can do a lot of things most filesystems or volume managers can&#039;t. It checksums all data and metadata and so long that the system uses ECC enabled memory (RAM), it will have complete control over the whole data set, and when (not if) an error occurs, it&#039;ll fix the issue without even throwing a warning. To fix the issue, you&#039;ll obviously need sufficient redundancy (mirrors or RAIDzN). &lt;br /&gt;
&lt;br /&gt;
== ZFS send/receive between machines ==&lt;br /&gt;
&lt;br /&gt;
ZFS has a send/receive mechanism that allows for snapshots to be sent over the wire to a receiving end. This can be a full filesystem, or an incremental change since last send/reveive. In a WAN scenario, you&#039;ll probably want to use VPN for this. On a controlled network, sending in cleartext is also possible. You may as well use ssh, but keep in mind that ssh was never designed to be used as a fullblown vpn solution and is just too slow or the task with large amounts of data. You may, though, use mbuffer, if on a loal LAN.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Allow traffic from the sending IP in whatever firewall interface you&#039;re using (if you&#039;re using a firewall at all, that is)&lt;br /&gt;
ufw allow from x.x.x.x&lt;br /&gt;
# &lt;br /&gt;
# Start the receiver first. This listens on port 9090, has a 1GB buffer,&lt;br /&gt;
    and uses 128kb chunks (same as zfs):&lt;br /&gt;
&lt;br /&gt;
mbuffer -s 128k -m 1G -I 9090 | zfs receive data/filesystem&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To be continued one day… See [https://everycity.co.uk/alasdair/2010/07/using-mbuffer-to-speed-up-slow-zfs-send-zfs-receive/ this] for some more. I&#039;ll get back with details on it.&lt;br /&gt;
&lt;br /&gt;
= General Linux system control =&lt;br /&gt;
&lt;br /&gt;
== Add a new CPU (core) ==&lt;br /&gt;
&lt;br /&gt;
If working with virtual machines, adding a new core can be useful if the VM is slow and the load is multithreaded or multiprocess. To do this, add a new CPU in the hypervisor (be it KVM or VMware or Hyper-V or whatever). Some hypervisors, like VMware, will activate it automatically if open-vm-tools is installed. Please note that open-vm-tools is for VMware only. I don&#039;t know of any such thing for KVM or other hypervisors (although I beleive VirtualBox has its own set of tools, but not as a package). If this doesn&#039;t work, run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
echo 1 &amp;gt; /sys/devices/system/cpu/cpuX/online&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where X is the CPU number you want to add. You can &#039;cat /sys/devices/system/cpu/cpuX/online&#039; to check if it&#039;s online.&lt;br /&gt;
&lt;br /&gt;
= Mount partitions on a disk image =&lt;br /&gt;
&lt;br /&gt;
Sometimes you&#039;ll have a disk image, either from recovering a bad drive after hours (or days or weeks) of ddrescue, and sometimes you just have a disk image from a virtual machine where you want to mount the partitions inside the image. There are three main methods of doing this, which are more or less synonmous, but some easier than the other.&lt;br /&gt;
&lt;br /&gt;
== Basics ==&lt;br /&gt;
&lt;br /&gt;
A disk image is usually like a disk, consisting of either a large filesystem, a PV or a partition table with one or partitions onto which resides a filesystem, a pv, swap or something else. If it&#039;s partitioned, and you want your operating system to mount a filesystem or allow it to see whatever LVM stuff lies on it, you need to isolate the partitions. &lt;br /&gt;
&lt;br /&gt;
== Manual mapping ==&lt;br /&gt;
&lt;br /&gt;
In the oldern days, this was done manually, something like this&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
root@mymachine:~# fdisk -l /dev/vda&lt;br /&gt;
Disk /dev/vda: 25 GiB, 26843545600 bytes, 52428800 sectors&lt;br /&gt;
Units: sectors of 1 * 512 = 512 bytes&lt;br /&gt;
Sector size (logical/physical): 512 bytes / 512 bytes&lt;br /&gt;
I/O size (minimum/optimal): 512 bytes / 512 bytes&lt;br /&gt;
Disklabel type: dos&lt;br /&gt;
Disk identifier: 0xc37b7ea5&lt;br /&gt;
&lt;br /&gt;
Device     Boot    Start      End  Sectors  Size Id Type&lt;br /&gt;
/dev/vda1  *        2048 50333311 50331264   24G 83 Linux&lt;br /&gt;
/dev/vda2       50333312 52426369  2093058 1022M  5 Extended&lt;br /&gt;
/dev/vda5       50333314 52426369  2093056 1022M 82 Linux swap / Solaris&lt;br /&gt;
root@mymachine:~#&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To calculate the start and end of each partition, you just take the start sector and multiply it by the sector size (512 bytes here) and you have the offset in bytes. After this, it&#039;s merely an losetup -o &amp;lt;offset&amp;gt; /dev/loopX &amp;lt;nameofimagefile&amp;gt; and you have the partition mapped to your /dev/loopX (having X being something typically 0-255. After this, just mount it or run pvscan/vgscan/lvscan to probe whatever lvm config is there, and you should be able to mount it like any other filesystem.&lt;br /&gt;
&lt;br /&gt;
== kpartx ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;kpartx&#039;&#039;&#039; does the same as above, more or less, just without so much hassle. Most of it should be automatic and easy to deal with, except it may fail to disconnect the loopback devices sometimes, so you may have to &#039;&#039;&#039;losetup -d&#039;&#039;&#039; them manually. See the manual, &#039;&#039;&#039;kpartx (8)&#039;&#039;&#039;. Please note that &#039;&#039;&#039;partx&#039;&#039;&#039; works similarly and I&#039;d guess the authors of the two tools are arguing a lot of which one&#039;s the best.&lt;br /&gt;
&lt;br /&gt;
== guestmount ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;guestmount&#039;&#039;&#039; is something similar again, but also supports file formats like &#039;&#039;&#039;qcow2&#039;&#039;&#039; and possibly other, proprietary filesystems like &#039;&#039;&#039;vmdk&#039;&#039;&#039; and &#039;&#039;&#039;vdi&#039;&#039;&#039;, but don&#039;t take my word for it - I haven&#039;t tested. Again, see the manual or just read up on the description [http://ask.xmodulo.com/mount-qcow2-disk-image-linux.html?fbclid=IwAR3snTeZvGzp9PLdX11EQhCfOpux6I93CiJ3A2pUomkkRLly9Xo4851mkTY here]. It seems rather trivial.&lt;br /&gt;
&lt;br /&gt;
= Linux on laptops =&lt;br /&gt;
&lt;br /&gt;
== Wifi with HP EliteBook 725/745 on Ubuntu ==&lt;br /&gt;
&lt;br /&gt;
The HP EliteBook 725/745 and similar are equipped with a BCM4352 wifi chip. As with a lot of other stuff from Broadcom, this lacks an open hardware description, so thus no open driver exist. The proper fix, is to replace the NIC with something with an open driver, but again, this isn&#039;t always possible, so a binary driver exists. In ubuntu, run, somehow connect the machine to the internet and run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install bcmwl-kernel-source&lt;br /&gt;
sudo modprobe wl&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you can&#039;t connect the machine to the internet, download the needed packages on another machine and put it on some usb storage. These packages should suffice:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# apt-cache depends bcmwl-kernel-source&lt;br /&gt;
bcmwl-kernel-source&lt;br /&gt;
  Depends: dkms&lt;br /&gt;
  Depends: linux-libc-dev&lt;br /&gt;
  Depends: libc6-dev&lt;br /&gt;
  Conflicts: &amp;lt;bcmwl-modaliases&amp;gt;&lt;br /&gt;
  Replaces: &amp;lt;bcmwl-modaliases&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then install manually with &#039;&#039;&#039;dpkg -i file1.deb file2.deb&#039;&#039;&#039; etc&lt;br /&gt;
&lt;br /&gt;
After this, ip/ifconfig/iwconfig shouldd see the new wifi nic, probably &#039;&#039;&#039;wlan0&#039;&#039;&#039;, but due to a [https://bugs.launchpad.net/ubuntu/+source/broadcom-sta/+bug/1343151 old, ignored bug], you won&#039;t find any wifi networks. This is because the driver from Broadcom apparently does not support interrupt remapping, commonly used on x64 machines. To turn this off, change &#039;&#039;&#039;/etc/default/grub&#039;&#039;&#039; and change the line &#039;&#039;&#039;GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;quiet splash&amp;quot;&#039;&#039;&#039;, adding intremap=off to the end before the quote: &#039;&#039;&#039;GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;quiet splash intremap=off&amp;quot;&#039;&#039;&#039;. Save the file and run &#039;&#039;&#039;sudo update-grub&#039;&#039;&#039; and reboot. After this, wifi should work well.&lt;br /&gt;
&lt;br /&gt;
== Wifi with HP Compaq Presario CQ57 on Ubuntu ==&lt;br /&gt;
&lt;br /&gt;
The HP Compaq Presario CQ57 uses the RT5390 wifi chipset. This has been supported for quite some time now, and I was quite surprised to find it not working on a laptop a friend was having. The driver loaded correctly, but Ubuntu insisted of the laptop being in &#039;&#039;&#039;flight mode&#039;&#039;&#039;. Checking &#039;&#039;&#039;rfkill&#039;&#039;&#039;, it showed me two NICs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# rfkill list all&lt;br /&gt;
0: phy0: Wireless LAN&lt;br /&gt;
	Soft blocked: no&lt;br /&gt;
	Hard blocked: yes&lt;br /&gt;
1: hp-wifi: Wireless LAN&lt;br /&gt;
	Soft blocked: yes&lt;br /&gt;
	Hard blocked: no&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Turning rfkill on and off resulted in nothing much, except some error messages in the kernel log (dmesg)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] ACPI Error: Field [B128] at bit offset/length 128/1024 exceeds size of target Buffer (160 bits) (20170831/dsopcode-235)&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]&lt;br /&gt;
                            Initialized Local Variables for Method [HWCD]:&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Local0: 00000000a34b7928 &amp;lt;Obj&amp;gt;           Integer 0000000000000000&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Local1: 00000000b0aa6865 &amp;lt;Obj&amp;gt;           Buffer(8) 46 41 49 4C 04 00 00 00&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Local5: 00000000a9811efd &amp;lt;Obj&amp;gt;           Integer 0000000000000004&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] Initialized Arguments for Method [HWCD]:  (2 arguments defined for method invocation)&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Arg0:   0000000078957d1b &amp;lt;Obj&amp;gt;           Integer 0000000000000001&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Arg1:   00000000725c9c6e &amp;lt;Obj&amp;gt;           Buffer(20) 53 45 43 55 02 00 00 00&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] ACPI Error: Method parse/execution failed \_SB.WMID.HWCD, AE_AML_BUFFER_LIMIT (20170831/psparse-550)&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] ACPI Error: Method parse/execution failed \_SB.WMID.WMAD, AE_AML_BUFFER_LIMIT (20170831/psparse-550)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After upgrading BIOS and testing different kernels, I was asked to try to unload the &#039;&#039;&#039;hp_wmi&#039;&#039;&#039; driver. I did, and things changed a bit, so I tried blacklisting it, creating the file &#039;&#039;&#039;/etc/modprobe.d/blacklist-hp_wmi.conf&#039;&#039;&#039; with the following content&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Blacklist this - it doesn&#039;t work!&lt;br /&gt;
blacklist hp_wmi&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
I gave the machine a reboot and afte that, the &#039;&#039;&#039;hp-wifi&#039;&#039;&#039; entry was gone in the rfkill output, and things works.&lt;br /&gt;
&lt;br /&gt;
= Raspberry pi =&lt;br /&gt;
&lt;br /&gt;
I couldn&#039;t quite decide if the raspberry pi should be a separate section or part of Linux, but hell, it can run more than Linux, although 99,lots% of people just uses Linux on them. This is a small list of things to know about them; things not on the front page of the manual or perhaps hidden even better.&lt;br /&gt;
&lt;br /&gt;
== Which pi? ==&lt;br /&gt;
&lt;br /&gt;
I just setup three raspberry pi machines and although some are quite different, like v1 to vEverythingelse or the Pi zero versions to the normal ones, not all of us remember how to distinguish between them, and sometimes they&#039;re in a nice 3d printed (or otherwise) chassis or otherwise hidden. So, how to check three different ones:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
root@home-assistant:~ $ cat /proc/device-tree/model ; echo&lt;br /&gt;
Raspberry Pi 2 Model B Rev 1.1&lt;br /&gt;
&lt;br /&gt;
root@green-pi:~ $ cat /proc/device-tree/model ; echo&lt;br /&gt;
Raspberry Pi 3 Model B Rev 1.2&lt;br /&gt;
&lt;br /&gt;
roy@yellow-pi:~ $cat /proc/device-tree/model ; echo&lt;br /&gt;
Raspberry Pi 4 Model B Rev 1.1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
While this works well, for the latter, the pi4, it doesn&#039;t tell how much memory I have. It comes in variants of 1, 2 and 4GB, and this is the latter.&lt;br /&gt;
&lt;br /&gt;
== Monitoring ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;vcgencmd&#039;&#039;&#039; from &#039;&#039;&#039;/opt/vc/bin&#039;&#039;&#039;, but symlinked to &#039;&#039;&#039;/usr/bin&#039;&#039;&#039; so it&#039;s available in path, is useful for fetching hardware info about the pi. For example, measuring the temperature&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
root@yellow-pi:~# vcgencmd measure_temp&lt;br /&gt;
temp=63.0&#039;C&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The command is generally badly documented and parts of it seems outdated for newer hardware. Here&#039;s the output from a Raspberry pi 4 with 4GB RAM&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
roy@yellow-pi:~ $ vcgencmd get_mem arm&lt;br /&gt;
arm=948M&lt;br /&gt;
roy@yellow-pi:~ $ vcgencmd get_mem gpu&lt;br /&gt;
gpu=76M&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== BIOS upgrade from Linux ==&lt;br /&gt;
&lt;br /&gt;
Generally, BIOS upgrades have been moved to the BIOS itself these days. This saves a lot of work and quite possibly lives after those who earier rammed their heads through walls, now can upgrade directly from the internet instead of using obscure operating systems best avoided. Sometimes, however, one must use these nevertheless. This is a quick run-through on your options.&lt;br /&gt;
&lt;br /&gt;
=== DOS ===&lt;br /&gt;
&lt;br /&gt;
Most non-automatic BIOS upgrades are installed from DOS. Doing a BIOS upgrade this way, is generally non-problematic. Just install a USB thingie with [https://www.freedos.org/ FreeDOS], copy your file(s) onto the thing and boot on it. The commandline is the same as old MS/DOS, except a wee bit more userfriendly, but not a lot.&lt;br /&gt;
&lt;br /&gt;
=== Windows ===&lt;br /&gt;
&lt;br /&gt;
Some macahines, like laptops from &#039;&#039;&#039;HP&#039;&#039;&#039;, may have BIOS upgrades that are made to be installed from Windows and won&#039;t run in FreeDOS or MS/DOS, instead throwing an error, saying &#039;&#039;&#039;This program cannot be run in DOS mode&#039;&#039;&#039;. This means you&#039;ll have to boot on a Windows rescue disc and do the job from there. Googling this, tells you it&#039;s quite easy, you just choose &#039;make rescue disc&#039; from Windows, and it&#039;s all good, except if you don&#039;t run Windows, that is. To remedy this problem, do as follows:&lt;br /&gt;
&lt;br /&gt;
==== Download Windows ====&lt;br /&gt;
&lt;br /&gt;
Since you don&#039;t run Windows and possibly don&#039;t have a spouse or friend around with such unhealthy habits either, you need to get it. It&#039;s quite easy - just google &#039;download windows&#039; and it&#039;ll send you to [https://www.microsoft.com/en-us/software-download/windows10ISO somewhere like this].&lt;br /&gt;
&lt;br /&gt;
==== Burn it! ====&lt;br /&gt;
&lt;br /&gt;
Now it&#039;s time to burn the installer on a DVD ROM. You&#039;ll need a double-layered one, since the OS is &amp;gt; 4.7GiB, but I&#039;m sure you have a ton of those lying around. Now, just place your optical medium in your optical drive and burn, baby, burn!&lt;br /&gt;
&lt;br /&gt;
==== Or make a USB thing? ====&lt;br /&gt;
&lt;br /&gt;
Not a lot of machines have optical drives these days, so you may want to use an USB pen drive or something instead. This is easy, just make the USB bootable with the Windows application Microsoft has made for this. Unfortunately, this only runs on Windows, and unlike stuff like Debian, where the &#039;&#039;&#039;iso&#039;&#039;&#039; file can be dd&#039;ed directly onto a USB drive to make it bootable, the Windows &#039;&#039;&#039;iso&#039;&#039;&#039;s don&#039;t come with this luxury. There are lots of methods to make bootable USB things from iso files out there, but the only thing most of them have in common, is that they generally don&#039;t work.&lt;br /&gt;
&lt;br /&gt;
===== WoeUSB =====&lt;br /&gt;
&lt;br /&gt;
After hours of swearing, it&#039;s nice to come across software like [https://github.com/slacka/WoeUSB WoeUSB]. It may not be perfect, it relies on a bunch of GUI stuff you&#039;ll never need and so on, but it &#039;&#039;&#039;&#039;&#039;works&#039;&#039;&#039;&#039;&#039;, and that&#039;s the important part! Just clone the repo and RTFM and it&#039;s all nice. It&#039;s slow, but hell, getting a windows machine and/or an optical drive might be slower.&lt;br /&gt;
&lt;br /&gt;
WoeUSB does nothing fancy, but it &#039;&#039;&#039;does&#039;&#039;&#039; work. It will create a filesystem, FAT32 or NTFS (better use NTFS, FAT32 has its limits). It creates normal filesystems and so on. Just make sure to copy in the BIOS update file, usually an exe file, to run when Windows is up and running.&lt;br /&gt;
&lt;br /&gt;
===== Install BIOS =====&lt;br /&gt;
&lt;br /&gt;
Boot on the Windows USB thing and choose &#039;repair computer&#039; and then &#039;command prompt&#039;. Find the install file, and if you&#039;re lucky, you&#039;ll find it needs a 32bit OS, just like I did. Since the 64bit version doesn&#039;t include 32bit compatibility in the installer, revert to downloading the 32bit version of windows and start over. Pray to your favourite god(s) not to get across such machines again - it might help.&lt;br /&gt;
&lt;br /&gt;
= 3D printer stuff =&lt;br /&gt;
&lt;br /&gt;
== Hydrophilic filament ==&lt;br /&gt;
&lt;br /&gt;
Most popular filament types, including PLA, PETG, PP or PA (Polyamide, normally known as Nylon) and virtualy any filament type named [https://www.matterhackers.com/news/filament-and-water poly-something] (and thus with an acronym of P-something) are hydrophilic (also (somewhat incorrectly) called hydroscopic), meaning so long they&#039;re dryer than the atmosphere around them, they&#039;ll do their best to suck out the atmosphere&#039;s humidity. This is why most filament are shrink-wrapped with a small bag of silica gel in it. If such filament is exposed for normal humid air for some time, it&#039;ll become very hard to use. Most of my experience is with PLA, which can handle a bit (depending on make), but still not a lot. With PLA, if you end up with prints where the filament seems not to stick, it may help with a higher temperature. Otherwise, the filament must be [https://all3dp.com/2/how-to-dry-filament-pla-abs-and-nylon/ baked]. If you don&#039;t want to use your oven, try something like a [https://www.jula.no/catalog/hjem-og-husholdning/kjokkenmaskiner/mattilberedningsapparater/frukt-sopptorker/frukt-sopptorker-001641/#tab02 fruit and mushroom dryer]. Then get a good, sealble plastic box and add something like half a kilogram of [https://www.ebay.com/sch/sis.html?_nkw=1KG+Orange+Replacement+Desiccant+Indicating+Silica+Gel+Beads+for+Drawers%2C+Camera&amp;amp;_id=131938742628&amp;amp;&amp;amp;_trksid=p2057872.m2749.l2658 silica gel] to an old sock, tie it and put it in the your new dry box.&lt;br /&gt;
&lt;br /&gt;
Please note that ABS is hydrophobic, so you won&#039;t have to worry too much there. Also, remember that PA/Nylon is extremely hydrophilic. Even a couple of days in normal air humidity can ruin it completely and will require baking.&lt;br /&gt;
&lt;br /&gt;
== Upgrading the firmware on an Ender 3 ==&lt;br /&gt;
&lt;br /&gt;
This is about upgrading the firmware, and thus also flashing a bootloader to the Creality Ender 3 3D printer. Most of this is well documented on several place, like o [https://www.youtube.com/watch?v=fIl5X2ffdyo the video from Teaching tech] and elsewhere, but I&#039;ll just summarise some issues I had.&lt;br /&gt;
&lt;br /&gt;
=== Using an arduino Nano as a programmer ===&lt;br /&gt;
&lt;br /&gt;
The CR-10, Ender 3 and a few other printers from Creality come without a bootloader, so you&#039;ll need to flash one before upgrading the firmware. Well, strictly speakning, you don&#039;t need one, you can save those 8kB or so for other stuff and use a programmer to write the whole firmware, but then you&#039;ll need to wire up everything every time you want a new firmware, so in my world, you &#039;&#039;&#039;do&#039;&#039;&#039; need the bootloader, since it&#039;s easier. Note that some newer printers, like the CR-10S and possibly all newer ones, come with the bootloader already and thus won&#039;t need another.&lt;br /&gt;
&lt;br /&gt;
To install a bootloader, you&#039;ll need a programmer, and I didn&#039;t have one available. Having some el-cheapo china-copies of Ardinos around, I read I could use one and tried so. Although the docs mostly mention the Uno etc, it&#039;s just as simple with the Nano copy.&lt;br /&gt;
&lt;br /&gt;
So, grab an arduino, plug it to your machine with a USB cable, and, using the Arduino IDE, use the ArduinoISP sketch there (found under Examples) to burn the software needed for the arduino to work as a programmer. When this is done, connect a 10µF capacitor between RST and GND to stop it from resetting when used as a programmer. Connect the MOSI, MISO and SCK pins from the ICSP block (that little isolated 6-pin block on top of the ardu). See [https://www.arduino.cc/en/Tutorial/ArduinoISP here] for a pinout. Then find Vcc and GND either on the ICSP block or elsewhere. Some sites say that on some boards you shouldn&#039;t use the pins on the ICSP block for this. I doubt it matters, though. Then connect another jumper wire from pin 10 on the ardu to work as the reset pin outwards to the chip being programmed (that is, on the printer). The ICSP jumper block pin layout is the same on the printer and on the ardu, and probably elsewhere. Sometimes [https://xkcd.com/927/ standardisation] actually works…&lt;br /&gt;
&lt;br /&gt;
See https://cloud.karlsbakk.net/index.php/s/zw48YJjzaf8Rc2F for a pic with the ardu (this wiki is broken atm, will fix it later)&lt;br /&gt;
&lt;br /&gt;
== Flashing the printer ==&lt;br /&gt;
&lt;br /&gt;
When the boot loader is in place, possibly after some wierd errors from during the process, the screen on the 3d printer will go blank and it&#039;ll behave like being bricked. This is ok. Now disconnect the wires and connect the USB cable between computer and printer. If you haven&#039;t installed support for the Sanguino board, that is, the variant of the 1284-chip and surrounding electronics that is the core of the, you need to install it first. In the Arduino IDE, choose the Tools / Boards / Boards manager boot option and search for Sanguino. After this, you should find the Sanguino or Sanguino 1284p in the boards menu. After this, you should be able to communicate with the printer&#039;s controller. Download the [https://www.th3dstudio.com/knowledgebase/th3d-unified-firmware-package/ TH3D unified firmware], making sure it&#039;s the last version. Uncompress the zip and with Finder/Explorer/whateversomething&#039;scalledonlinux, browse to &#039;&#039;&#039;TH3DUF_R2/Firmware/TH3DUF_R2.ino&#039;&#039;&#039; and open it. It should open directly in the Android IDE. Keep in mind that the names TH3DUF_R2 and TH3DUF_R2.ino will vary between versions, but you get the point. Now configure it for your particular needs. You&#039;ll find most of this in the Configuration.h tab (that&#039;s really a file). Most of the other files won&#039;t be necessary unless you&#039;re doing some more advanced stuff, like replacing th controller with something non-standard or similar, but then again, that&#039;s another chapter (or book, even). The video mentioned above describes this well. After flashing the new firmware, you&#039;ll probably get some timeouts and errors, since apparently it resets the printer after giving it the new firmware, but without notifying the flashing software of it doing so. If this happens, calm down and reboot the printer and check its tiny monitor - it should work. If it doesn&#039;t work, and if you flashed the bootload yourself, try to flash it again, and if that doesn&#039;t work, try flashing the programmer again yet another time, just for kicks. Again, if you have a newer controller like the v1.1.5, don&#039;t touch the bootloader, as the one already installed, should work well as it is.&lt;br /&gt;
&lt;br /&gt;
PS: I tried enabling &#039;&#039;&#039;MANUAL_MESH_LEVELING&#039;&#039;&#039;, which in the code says that &#039;&#039;If used with a 1284P board the bootscreen will be disabled to save space&#039;&#039;. This effectively disabled the whole thing, and apparently may be making the firmware image a wee bit too large for it to fit the 1284P on the ender. It works well without it, though.&lt;br /&gt;
&lt;br /&gt;
== And then… ==&lt;br /&gt;
&lt;br /&gt;
With the new firmware in place, the printer should work as before, although with thermal runaway protection to better avoid fires in case the shit hits the fan, and to allow for things like autolevelling. With any luck, [https://www.precisionpiezo.co.uk/ this thing] may be ready for use by the time you read this - it surely looks nice!&lt;br /&gt;
&lt;br /&gt;
roy&lt;/div&gt;</summary>
		<author><name>Roy</name></author>
	</entry>
	<entry>
		<id>https://wiki.malinux.no/index.php?title=Roy%27s_notes&amp;diff=156</id>
		<title>Roy&#039;s notes</title>
		<link rel="alternate" type="text/html" href="https://wiki.malinux.no/index.php?title=Roy%27s_notes&amp;diff=156"/>
		<updated>2020-05-04T11:20:14Z</updated>

		<summary type="html">&lt;p&gt;Roy: /* Using an arduino Nano as a programmer */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= LVM, md and friends =&lt;br /&gt;
&lt;br /&gt;
== Linux&#039; Logical Volume Manager (LVM) ==&lt;br /&gt;
&lt;br /&gt;
=== LVM in general ===&lt;br /&gt;
&lt;br /&gt;
LVM is designed to be an abstraction layer on top of physical drives or RAID, typically [https://raid.wiki.kernel.org/index.php/RAID_setup mdraid] or [https://help.ubuntu.com/community/FakeRaidHowto fakeraid]. Keep in mind that fakeraid should be avoided unless you really need it, like in conjunction with dual-booting linux and windows on fakeraid. LVM broadly consists of three elements, the &amp;quot;physical&amp;quot; devices (PV), the volume group (VG) and the logical volume (LV). There can be multiple PVs, VGs and LVs, depending on requirement. More about this below. All commands are given as examples, and all of them can be fine-tuned using extra flags in need of so. In my experience, the defaults work well for most usecases.&lt;br /&gt;
&lt;br /&gt;
I&#039;m mentioning filesystem below too. Where I write ext4, the samme applies to ext2 and ext3.&lt;br /&gt;
&lt;br /&gt;
==== Create a PV ====&lt;br /&gt;
&lt;br /&gt;
A PV is the &amp;quot;physical&amp;quot; parts. This does not need to be a physical disk, but can also be another RAID, be it an mdraid, fakeraid, hardware raid, a virtual disk on a SAN or otherwisee or a partition on one of those. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#  These add three PVs, one on a drive (or hardware raid) and another two on mdraids.&lt;br /&gt;
pvcreate /dev/sdb&lt;br /&gt;
pvcreate /dev/md1 /dev/md2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For more information about pvcreate, see [https://linux.die.net/man/8/pvcreate the manual].&lt;br /&gt;
&lt;br /&gt;
==== Create a VG ====&lt;br /&gt;
&lt;br /&gt;
The volume group consists of one or more PVs grouped together on which LVs can be placed. If several PVs are grouped in a VG, it&#039;s generally a good idea to make sure these PVs have some sort of redundancy, as in mdraid/fakeraid or hwraid. Otherwise it will be like using a [https://en.wikipedia.org/wiki/RAID RAID-0] with a single point of failure on each of the independant drives. LVM has [https://unix.stackexchange.com/questions/150644/raiding-with-lvm-vs-mdraid-pros-and-cons  RAID code in it] as well, so you can use that. I haven&#039;t done so myself, as I generally stick to mraid. The reason is mdraid is, in my opinion older and more stable and has more users (meaning bugs are reported and fixed faster whenever they are found). That said, I beleive the actual RAID code used in LVM RAID are the same function calls as for mdraid, so it may not be much of a difference. I still stick with mdraid. To create a VG, run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create volume group my_vg&lt;br /&gt;
vgcreate my_vg /dev/md1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that if vgcreate is run with a PV (as /dev/md1 above) that is not defined as a PV (like above), this is done implicitly, so if you don&#039;t need any special flags to pvcreate, you can simply skip it and let vgcreate do that for you.&lt;br /&gt;
&lt;br /&gt;
==== Create an LV ====&lt;br /&gt;
&lt;br /&gt;
LVs can be compared to partitions, somehow, since they are bounderies of a fraction or all of that of a VG. The difference between them and a partition, however, is that they can be grown or shrunk easily and also moved around between PVs without downtime. This flexibility makes them superiour to partitions as your system can be changed without users noticing it. By default, an LV is alloated &amp;quot;thickly&amp;quot;, meaning all the data given to it, is allocated from the VG and thus the PV. The following makes a 100GB LV named &amp;quot;thicklv&amp;quot;. When making an LV, I usually allocate what&#039;s needed plus some more, but not everything, just to make sure it&#039;s space available for growth on any of the LVs on the VG, or new LVs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a thick provisioned LV named thicklv on the VG my_vg&lt;br /&gt;
lvcreate -n thicklv -L 100G my_vg&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After the LV is created, a filesystem can be placed on it unless it is meant to be used directly. The application for direct use include swap space, VM storage and certain database systems. Most of these will, however, work on filesystems too, although my testing has shown that on swap space, there is a significant performance gain for using dedicated storage without a filesystem. As for filesystems, most Linux users use either ext4 or xfs. Personally, I generally use XFS these days. See my notes below on filesystem choice.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a filesystem on the LV - this could have been mkfs -t ext4 or whatever filesystem you choose&lt;br /&gt;
mkfs -t xfs /dev/my_vg/thicklv&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then just edit /etc/fstab with correct data and run mount -a, and you should be all set.&lt;br /&gt;
&lt;br /&gt;
==== Create LVM cache ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
lvcreate -L 1G -n _cache_meta data /dev/md1&lt;br /&gt;
&lt;br /&gt;
lvcreate -l100%FREE -n _cache data /dev/md1&lt;br /&gt;
&lt;br /&gt;
# Some would want --cachemode writeback, but seriously, I wouldn&#039;t recommend it. Metadata or data can be easily corrupted in case of failure.&lt;br /&gt;
lvconvert --type cache-pool --cachemode writethrough --poolmetadata data/_cache_meta data/_cache&lt;br /&gt;
&lt;br /&gt;
lvconvert --type cache --cachepool data/_cache data/data&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Disabling LVM cache ====&lt;br /&gt;
&lt;br /&gt;
If you for some reason want to disable caching, this will do it cleanly and remove the LVs earlier created for caching the main device.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
lvconvert --uncache data/data&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Growing devices ====&lt;br /&gt;
&lt;br /&gt;
LVM objects can be grown and shrunk. If a PV resides on a RAID where a new drive has been added or otherwise grown, or on a partition or virtual disk that has been extended, the PV must be updated to reflect these changes. The following command will grow the PV to the maximum available on the underlying storage. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Resize the PV /dev/md (not the RAID, only the PV on the RAID) to its full size&lt;br /&gt;
pvresize /dev/md1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If a new PV is added, the VG can be grown to add the space on that in addition to what&#039;s there already. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Extend my_vg to include md2 and its space&lt;br /&gt;
vgextend my_vg /dev/md2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
With more space available in the VG, the LV can now be extended. Let&#039;s add another 50GB to it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Extend thicklv - add 50GB. If you know you won&#039;t need the space anywhere else, you may want to&lt;br /&gt;
# lvresize -l+100%FREE instead. Keep in mind the difference between -l (extents) and -L (bytes)&lt;br /&gt;
lvresize -L +50G my_vg/thicklv&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Growing filesystems ====&lt;br /&gt;
After the LV has grown, run &#039;&#039;xfs_growfs&#039;&#039; (xfs) or &#039;&#039;resize2fs&#039;&#039; (ext4) to make use of the new data. To grow the filesystem to all available space on ext4, run the below command.  To partly grow the filesystem or to shrink it or otherwise, please see the manuals.&lt;br /&gt;
&lt;br /&gt;
The filesystem can be mounted when this is run. If you for some reason get an &#039;&#039;&#039;access denied&#039;&#039;&#039; error when running this as root or with sudo, it&#039;s likely caused by a filesystem error. To fix this, unmount the filesystem first and run &#039;&#039;&#039;fsck -f /dev/my_vg/thicklv&#039;&#039;&#039; and remount it before retrying to extend it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
resize2fs /dev/my_vg/thicklv&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Similarly, with XFS, but note that xfs_growfs doesn&#039;t take the device name, but the filesystem&#039;s mount point. In the case of XFS, also note that the filesystem &#039;&#039;&#039;&#039;&#039;must&#039;&#039;&#039;&#039;&#039; be mounted to be grown. This, in contrast to how it was in the old days when filesystems had to be unmounted to be grown.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
xfs_growfs /my_mountpoint&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Rename system VG ====&lt;br /&gt;
&lt;br /&gt;
Some distros create VG names like those-from-a-sysadmin-with-a-well-developed-paranoia-not-to-hit-a-duplicate. Debian, for instance, uses names like &amp;quot;my-full-hostname-vg&amp;quot;. Personally, I don&#039;t like these, since if I were to move a disk or vdisk around to somewhere else, I&#039;d make sure not to add a disk named &#039;sys&#039; to an existing system. If you do, most distros will refuse to use the VGs with duplicate names, resulting in the OS not booting until either one is specified by its UUID or just one removed. As I&#039;m aware of this, I stick to the super-risky thing of all system VGs named &#039;sys&#039; and so on.&lt;br /&gt;
&lt;br /&gt;
If you do this, keep in mind that it may blow up your computer and take your girl- or boyfriend with it or even make either of them pregnant, allowing Trump to rule your life and generally make things suck. You&#039;re on your own!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Rename the VG&lt;br /&gt;
vgrename my-full-hostname-vg sys&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, in /boot/grub/grub.cfg, change the old lv path from something like &#039;/dev/mapper/debian--stretch--machine--vg-root&#039; to your new and fancy &#039;/dev/sys/root. Likewise, in /etc/fstab, change occurences of &#039;/dev/mapper/debian--stretch--machine--vg-&#039; (or similar) with &#039;/dev/sys/&#039;. Here, this was like this - the old ones commented out.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;fstab&amp;quot;&amp;gt;&lt;br /&gt;
#/dev/mapper/debian--stretch--box--vg-root      /               ext4            errors=remount-ro,discard       0       1&lt;br /&gt;
/dev/sys/root                                   /               ext4            errors=remount-ro,discard       0       1&lt;br /&gt;
# /boot was on /dev/vda1 during installation&lt;br /&gt;
UUID=myverylonguuidwithatonofgoodinfoinit       /boot           ext2            defaults                        0       2&lt;br /&gt;
#/dev/mapper/debian--stretch--box--vg-swap_1    none            swap            sw                              0       0&lt;br /&gt;
/dev/sys/swap_1                                 none            swap            sw                              0       0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Update /etc/initramfs-tools/conf.d/resume with similar data for swap.&lt;br /&gt;
&lt;br /&gt;
You might want to run &#039;update-initramfs -u -k all&#039; after this, but I&#039;m not sure if it&#039;s needed.&lt;br /&gt;
&lt;br /&gt;
Now, pray to the nearest god(s) and give it a reboot and it should (probably) work.&lt;br /&gt;
&lt;br /&gt;
After reboot, run &#039;&#039;&#039;swapoff -a&#039;&#039;&#039;, then &#039;&#039;&#039;mkswap /dev/sys/swap_1&#039;&#039;&#039; (or whatever it&#039;s called on your system) and &#039;&#039;&#039;swapon -a&#039;&#039;&#039; again. You may want to give it another reboot or two for kicks, but it should work well even without that.&lt;br /&gt;
&lt;br /&gt;
=== Migration tools ===&lt;br /&gt;
&lt;br /&gt;
At times, storage regimes change, new storage is added and sometimes it&#039;s not easy to migrate with the current hardware or its support systems. Once I had to migrate a 45TiB fileserver from one storage system to another, preferably without downtime. The server originally had three 15TiB PVs of which two were full and the third half full. I resorted to using [https://linux.die.net/man/8/pvmove pvmove] to just move the data on the PVs in use to a new PV. We started out with creating a new 50TiB PV, sde, and then to pvmove.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Attach /dev/sde to the VG my_vg&lt;br /&gt;
vgextend my_vg /dev/sde&lt;br /&gt;
&lt;br /&gt;
# Move the contents from /dev/sdb over to /dev/sde block by block. If a target is not given in pvmove,&lt;br /&gt;
# the contents of the source (sdb here) will be put somewhere else in the pool.&lt;br /&gt;
pvmove /dev/sdb /dev/sde&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This took a while (as in a week or so) - the pvmove command uses old code and logic (or at least did that when I migrated this in November 2016), but it affected performance on the server very little, so users didn&#039;t notice. After the first PV was migrated, I continued with the other two, one after the other, and after a month or so, it was migrated. We used this on a number of large fileservers, and it worked flawlessly. Before doing the production servers I also tried interrupting pvmove in various ways, including hard resets, and it just kept on after the reboot.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;NOTE:&#039;&#039;&#039;&#039;&#039; &#039;&#039;Even though it worked well for us, &#039;&#039;&#039;always&#039;&#039;&#039; keep a good backup before doing this. Things may go wrong, and without a good backup, you may be looking for a hard-to-find new job the next morning&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
==== mdadm workarounds ====&lt;br /&gt;
&lt;br /&gt;
===== Migrate from a mirror (raid-1) to raid-10 =====&lt;br /&gt;
&lt;br /&gt;
Create a mirror&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sdb /dev/sdc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
LVM (pv/vg/lv) on md0 (see above), put a filesystem on the lv and fill it with some data.&lt;br /&gt;
&lt;br /&gt;
Now, some months later, you want to change this to raid-10 to allow for the same amount of redundancy, but to allow more disks into the system.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mdadm --grow /dev/md0 --level=10&lt;br /&gt;
mdadm: Impossibly level change request for RAID1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So - no - doesn&#039;t work. But - we&#039;re on &lt;br /&gt;
&lt;br /&gt;
Since we&#039;re on lvm already, this&#039;ll be easy. If you&#039;re using filesystems directly on partitions, you can do this the same way, but without the pvmove part, using rsync or whateever you like instead. I&#039;d recommend using lvm for for the new raid, which should be rather obvious from this article. Now plug in a new drive and create a new raid10 on that one. If you two new drives, install both. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# change &amp;quot;missing&amp;quot; to the other device name if you installed two new drives&lt;br /&gt;
mdadm --create /dev/md1 --level=10 --raid-devices=2 /dev/vdd missing&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, as described above, just vgextend the vg, adding the new raid and run pvmove to move the data from the old pv (residing on the old raid1) to the new pv (on raid10). Afte rpvmove is finished (which may take awile, see above), just&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
vgreduce raidtest /dev/md0&lt;br /&gt;
pvremove /dev/md0&lt;br /&gt;
mdadm --stop /dev/md0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
…and your disk is free to be added to the new array. If the new raid is running in degraded mode (if you created it with just one drive), better don&#039;t wait too long, since you don&#039;t have redundancy. Just mdadm --add the devs.&lt;br /&gt;
&lt;br /&gt;
If you now have /dev/mdstat telling you your raid10 is active and have three drives, of which one is a spare, it should look something like this&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5] [raid4] [raid10]&lt;br /&gt;
md1 : active raid10 vdc[3](S) vdb[2] vdd[0]&lt;br /&gt;
      8380416 blocks super 1.2 2 near-copies [2/2] [UU]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Just mdadm --grow --raid-devices=3 /dev/md1&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;RAID section is not complete. I&#039;ll write more on migraing from raid10 to raid6 later. It&#039;s not straight forward, but easier than this one :)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== Thin provisioned LVs ===&lt;br /&gt;
&lt;br /&gt;
Thin provisioning on LVM is a method used for not allocating all the space given to an LV. For instance, if you have a 1TB VG and want to give an LV 500GB, although it currently only uses a fraction of that, a thin lv can be a good alternative. This will allow for adding a limit to how much it can use, but also to let it grow dynamically without manual work by the sysadmin. Thin provisioning adds another layer of abstaction by creating a special LV as a &#039;&#039;thin pool&#039;&#039; from which data is allocated to the &#039;&#039;thin volume(s)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== Create a thin pool ====&lt;br /&gt;
&lt;br /&gt;
Allocate 1TB to the thin pool to be used for thinly provisioned LVs. Keep in mind that the space allocated to the thin pool is in fact thick provisioned. Only the volumes put on &#039;&#039;thinpool&#039;&#039; are thin provisioned. This will create two hidden LVs, one for data and one for metadata. Normally the defaults will do, but check the manual if the data doesn&#039;t match the usual patterns (such as billions of files, resulting in huge amounts of metadata). I &#039;&#039;beleive&#039;&#039; the metadata part should be resizable at a later time if needed, but I have not tested it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a pool for thin LVs. Keep in mind that the pool itself is not thin provisioned, only the volumes residing on it&lt;br /&gt;
lvcreate --size 1T --type thin-pool --thinpool thinpool my_vg&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Create a thin volume ====&lt;br /&gt;
&lt;br /&gt;
You have the thinpool, now put a thin volume on it. It will allocate some space for metadata, but probably not much (a few megs, perhaps).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Now, create a volume with a virtual (-V) size of half a terabyte named thin_pool, but using the thinpool (-T) named thin_pool for storage&lt;br /&gt;
lvcreate -V 500G -T my_vg/thin_pool --name thinvol&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The new volume&#039;s device name will be /dev/thinvol. Now, create a filesystem on it, add to fstab and mount it. The &#039;&#039;&#039;df&#039;&#039;&#039; command will return available space according to the virtual size (-V), while lvs will show how much data is actually used on each of the thinly provisioned volumes.&lt;br /&gt;
&lt;br /&gt;
== Filesystem dilemmas ==&lt;br /&gt;
&lt;br /&gt;
=== XFS or ext4 or something else ===&lt;br /&gt;
The choice of filesystem varies for your use. Distros such as RHEL/CentOS has moved to XFS by default from v7. Debian/Ubuntu still sticks to ext4, like most other. I&#039;ll discuss my thoughts below on ext4 vs XFS and leave the other filesystems for later.&lt;br /&gt;
&lt;br /&gt;
==== ext4 ====&lt;br /&gt;
ext4 is probably the most used filesystem on linux as of writing. It&#039;s rock stable and has been extended by a lot of extensions since the original ext2. It still retains backward compatibility, being able to mount and fsck ext2 and ext3 with the ext4 driver. However, it doesn&#039;t handle large filesystems very well. If a filesystem is created for &amp;lt;16TiB, it cannot be grown to anything larger than 16TiB. This may have changed lately, though. One other issue is handling errors. If a large filesystem (say 10TiB) is damaged, an fsck may take several hours, leading to long downtime. When I refer to ext4 further in this text, the same applies to ext2 and ext3 unless otherwise specified.&lt;br /&gt;
&lt;br /&gt;
==== XFS ====&lt;br /&gt;
XFS, originally developed by SGI some time in the bronze age, but has been worked on heavily after that. RHEL and Centos version 7 and forward, uses XFS as the default filesystem. It is quick, it scales well, but it lacks at least two things ext4 has. It cannot be shrunk (not that you normally need that, but nice if you have a typo or you need to change things). Also, it doesn&#039;t allow for automatic fsck on bootup. If something is messed up on the filesystem, you&#039;ll have to login as root on the console (not ssh), which might be an issue on some systems. The fsck equivalent, xfs_repair, is a *lot* faster than ext4&#039;s fsck, though.&lt;br /&gt;
&lt;br /&gt;
==== ZFS ====&lt;br /&gt;
ZFS is like a combination of RAID, LVM and a filesystem, supporting full checksumming, auto-healing (given sufficient redundancy), compression, encryption, replication, deduplication (if you&#039;re brave and have a &#039;&#039;ton&#039;&#039; of memory) and a lot more. It&#039;s a separate chapter and needs a lot more talk than paragraph here.&lt;br /&gt;
&lt;br /&gt;
==== btrfs ====&lt;br /&gt;
btrfs, pronounced &amp;quot;butterfs&amp;quot; or &amp;quot;betterfs&amp;quot; or just spelled out, is a filesystem that mimics that of ZFS. It has been around for 10 years or so, but hasn&#039;t yet proven to be really stable. Following the progress of it for those years, I&#039;ve found it to be a nice toy with which to play, but not to be used in production. Again, others may say otherwise, but these are just my words.&lt;br /&gt;
&lt;br /&gt;
== Low level disk handling ==&lt;br /&gt;
&lt;br /&gt;
This section is for low-level handling of disks, regardless of storage system elsewhere. These apply to mdraid, lvmraid and zfs and possibly other solutions, with the exception of individual drives on hwraid (and maybe fakeraid), since there, the drives are hidden from Linux (or whatever OS).&lt;br /&gt;
&lt;br /&gt;
=== S.M.A.R.T. and slow drives ===&lt;br /&gt;
Modern (that is, from about 1990 or later) have S.M.A.R.T. (or just smart, since it&#039;s easier to type) monitoring built in, meaning the disk&#039;s controller is monitoring itself. This is handy and will ideally tell you in advance that a drive is flakey or dying. Modern (2010+) smart monitoring is more or less the same. It can be trusted about 50% of the time. Usually, if smart detects an error, it&#039;s a real error. I don&#039;t think I&#039;ve seen it reporting a false positive, but others may know better. &lt;br /&gt;
&lt;br /&gt;
==== smartmontools ====&lt;br /&gt;
First, install smartmontool and run smartclt -H /dev/yourdisk (/dev/sda or something) to get a health report. Then perhaps run smartctl -a /dev/yourdisk and look for &#039;current pending sectors&#039; This should be zero. Also check the temperature, which normally should be much above 50.&lt;br /&gt;
&lt;br /&gt;
==== single, slow drive ====&lt;br /&gt;
What may happen, is smart not seeing anything and life goes on like before, only slower and less prouductive, without telling anyone. If you stubler over this issue, you&#039;ll probably see it during a large rsync/zfs send/receive or a resync/rebuild/resilver of the raid/zpool. During this, it feels like everything is slow and your RAID has turned into a RAIF (redundant array of inexpensive floppies). To check if you have a single drive messing up it all, check with &#039;&#039;&#039;iostat -x 2&#039;&#039;&#039;, having 2 being the delay between each measurement. Interrupt it with ctrl+x. If there&#039;s a rougue drive there, it should stand out like sdg below&lt;br /&gt;
&lt;br /&gt;
 avg-cpu:  %user   %nice %system %iowait  %steal   %idle&lt;br /&gt;
            0.38    0.00    1.75    0.00    0.00   97.87&lt;br /&gt;
&lt;br /&gt;
 Device            r/s     w/s     rkB/s     wkB/s   rrqm/s   wrqm/s  %rrqm  %wrqm r_await w_await aqu-sz rareq-sz wareq-sz  svctm  %util&lt;br /&gt;
 sda              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdb              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdc              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdd              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sde              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdf              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdg              3.50    0.00   2352.00      0.00     0.00     0.00   0.00   0.00 14306.29    0.00  13.85   672.00     0.00 285.71 100.00&lt;br /&gt;
 sdh              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
&lt;br /&gt;
In ZFS land, you should be able to get similar data with &#039;&#039;&#039;zpool iostat -v &amp;lt;pool&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Now you know the bad drive (sdg), pull it from the raid with &#039;&#039;&#039;mdadm --fail /dev/mdX /dev/sdX&#039;&#039;&#039;. Now test the drive&#039;s performance manually, just simply:&lt;br /&gt;
&lt;br /&gt;
 # hdparm -t /dev/sdg&lt;br /&gt;
 &lt;br /&gt;
 /dev/sdg:&lt;br /&gt;
  Timing buffered disk reads:   2 MB in  5.37 seconds = 381.46 kB/sec&lt;br /&gt;
&lt;br /&gt;
Bingo - nothing you&#039;d want to keep. For a good drive, it should be something like 100-200MB/s&lt;br /&gt;
&lt;br /&gt;
PS: Keep in mind that you have a degraded RAID by now in case you had a spare waiting for things to happen.&lt;br /&gt;
&lt;br /&gt;
Try to replace the cable and/or try the disk on another port/controller. If the result from hdparm persists, it&#039;s probably a bad cable&lt;br /&gt;
&lt;br /&gt;
So, then, just psycially locate the drive, pull it out, take out the discs and magnets and recycle the rest.&lt;br /&gt;
&lt;br /&gt;
=== &amp;quot;Unplug&amp;quot; drive from system ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Find the device unit&#039;s number with something like&lt;br /&gt;
find /sys/bus/scsi/devices/*/block/ -name sdd&lt;br /&gt;
# returning /sys/bus/scsi/devices/3:0:0:0/block/sdd here, &lt;br /&gt;
# meaning 3:0:0:0 is the SCSI device we&#039;re looking for.&lt;br /&gt;
&lt;br /&gt;
# Given this is the correct device, and you want to &#039;unplug&#039; it, do so by&lt;br /&gt;
echo 1 &amp;gt; /sys/bus/scsi/devices/3:0:0:0/delete&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Rescan disk controllers ===&lt;br /&gt;
If a drive is added and for some reason doesn&#039;t get detected, or is removed by the command above, it can be rediscovered with a sysfs command to the scsi host to which it is connected. Since there may be quite a few of these, an easy way is to just scan them all and check the output of &#039;&#039;&#039;dmesg -T&#039;&#039;&#039; after running it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Make a list of controllers and send a rescan message to each of them. It won&#039;t do anything &lt;br /&gt;
# for those where nothing has changed, but it will show new drives where they have been added.&lt;br /&gt;
for host_scan in /sys/class/scsi_host/host*/scan&lt;br /&gt;
do&lt;br /&gt;
  echo &#039;- - -&#039; &amp;gt; $host_scan&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Fail injection with debugfs ===&lt;br /&gt;
[https://lxadm.com/Using_fault_injection https://lxadm.com/Using_fault_injection]&lt;br /&gt;
&lt;br /&gt;
== mdadm stuff ==&lt;br /&gt;
=== Resync ===&lt;br /&gt;
To resync a raid, that is, check, run&lt;br /&gt;
&lt;br /&gt;
 echo check &amp;gt; /sys/block/$dev/md/sync_action&lt;br /&gt;
&lt;br /&gt;
where $dev is something like md0. If you have several raids, something like this should work&lt;br /&gt;
&lt;br /&gt;
 for dev in md{0,1}&lt;br /&gt;
 do&lt;br /&gt;
   echo repair &amp;gt; /sys/block/$dev/md/sync_action&lt;br /&gt;
 done&lt;br /&gt;
&lt;br /&gt;
Also useful in a one-liner like&lt;br /&gt;
&lt;br /&gt;
 for dev in md{0,1} ; do echo repair &amp;gt; /sys/block/$dev/md/sync_action ; done&lt;br /&gt;
&lt;br /&gt;
Different raids on different drives will do this in parallel. If the drives are shared somehow with partitions or similar, the check or repair will wait for the other to finish before going on.&lt;br /&gt;
&lt;br /&gt;
As for repair vs check, [https://raid.wiki.kernel.org/index.php/RAID_Administration this article] describes it well. I stick to using repair unless it&#039;s something rare where I don&#039;t want to touch the data.&lt;br /&gt;
&lt;br /&gt;
=== Spare pools ===&lt;br /&gt;
In the old itmes, mdadm supported only a dedicated spare per md device, so if working with a large set of drives (20? 40?), where you&#039;d want to setup more raid sets to increase redundancy, you&#039;d dedicate a spare to each of the raid sets. This has changed (some time ago?), so in these modern, heathen days, you can change mdadm.conf, usually placed under /etc/mdadm, and add &#039;spare-group=somegroup&#039; where &#039;somegroup&#039; is a string identifying the spare group. After doing this, run &#039;&#039;&#039;update-initramfs -u&#039;&#039;&#039; and reboot and add a spare to one of the raid sets in the spare group, and md will use that or those spares for all the raidsets in that group.&lt;br /&gt;
&lt;br /&gt;
As some pointed out on #linux-raid @ irc.freenode.net, this feature is very badly documented, but as far as I can see, it works well.&lt;br /&gt;
&lt;br /&gt;
==== Example config ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create two raidsets&lt;br /&gt;
&lt;br /&gt;
mdadm --create /dev/md1 --level=6 --raid-devices=6 /dev/vd[efghij]&lt;br /&gt;
mdadm --create /dev/md2 --level=6 --raid-devices=6 /dev/vd[klmnop]&lt;br /&gt;
&lt;br /&gt;
# get their UUID etc&lt;br /&gt;
&lt;br /&gt;
mdadm --detail --scan&lt;br /&gt;
ARRAY /dev/md/1 metadata=1.2 name=raidtest:1 UUID=1a8cbdcb:f4092350:348b6b80:c054d74c&lt;br /&gt;
ARRAY /dev/md/2 metadata=1.2 name=raidtest:2 UUID=894b1b7c:cb7eba70:917d6033:ea5afd2b&lt;br /&gt;
&lt;br /&gt;
# Put those lines into /etc/mdadm/mdadm.conf and and add the spare-group&lt;br /&gt;
&lt;br /&gt;
ARRAY /dev/md/1 metadata=1.2 name=raidtest:1 spare-group=raidtest UUID=1a8cbdcb:f4092350:348b6b80:c054d74c&lt;br /&gt;
ARRAY /dev/md/2 metadata=1.2 name=raidtest:2 spare-group=raidtest UUID=894b1b7c:cb7eba70:917d6033:ea5afd2b&lt;br /&gt;
&lt;br /&gt;
# update the initramfs and reboot&lt;br /&gt;
&lt;br /&gt;
update-initramfs -u&lt;br /&gt;
reboot&lt;br /&gt;
&lt;br /&gt;
# add a spare drive to one of the raids&lt;br /&gt;
&lt;br /&gt;
mdadm --add /dev/md1 /dev/vdq&lt;br /&gt;
&lt;br /&gt;
# fail a drive on the other raid&lt;br /&gt;
&lt;br /&gt;
mdadm --fail /dev/md2 /dev/vdn&lt;br /&gt;
&lt;br /&gt;
# check /proc/mdstat to see md2 rebuilding with the spare from md1&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Recovery ===&lt;br /&gt;
&lt;br /&gt;
The other day, I came across a problem a user had on #linux-raid@irc.freenode.net. He had an old Qnap NAS that had died and tried plugging the drives in to his Linux machine and got various errors. The two-drive RAID-1 did not come up as it should, &#039;&#039;&#039;dmesg&#039;&#039;&#039; was full of errors from one of the drives (both connected on USB) and so forth.&lt;br /&gt;
&lt;br /&gt;
We went on and started by taking down the machine and just connecting one of the drives. I had him check what was assembled with&lt;br /&gt;
&lt;br /&gt;
 cat /proc/mdstat&lt;br /&gt;
&lt;br /&gt;
That returned /proc/md127 assembled, but LVM didn&#039;t find anything. So running a manual scan&lt;br /&gt;
&lt;br /&gt;
 pvscan --cache /dev/md127&lt;br /&gt;
&lt;br /&gt;
This made linux find the PV, VG and a couple of LVs, but probably because the mdraid was degraded, the LVs were deactivated, according to &#039;&#039;&#039;lvscan&#039;&#039;&#039;. Activating the one with a filesystem manually&lt;br /&gt;
&lt;br /&gt;
 lvchange -a y /dev/&amp;lt;vg&amp;gt;/&amp;lt;lv&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Substitute &amp;lt;vg&amp;gt; and &amp;lt;lv&amp;gt; with the names listed by vgs and lvs.&lt;br /&gt;
&lt;br /&gt;
This worked, and the filesystem on /dev/&amp;lt;vg&amp;gt;/&amp;lt;lv&amp;gt; could be mounted correctly.&lt;br /&gt;
&lt;br /&gt;
== Tuning ==&lt;br /&gt;
&lt;br /&gt;
While trying to compare a 12-disk RAID (8TB disks) to a hwraid, mdraid was slower, so we did a few things to speed things up:&lt;br /&gt;
&lt;br /&gt;
While testing with [https://linux.die.net/man/1/fio fio], monitor /sys/block/md0/md/stripe_cache_active, and see if it&#039;s close to /sys/block/md0/md/stripe_cache_size. If it is, double the size of the latter&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
echo 4096 &amp;gt; /sys/block/md0/md/stripe_cache_size&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Continue until stripe_cache_active stabilises, and then you&#039;ve found the limit you&#039;ll need. You may want to double that for good measure. &lt;br /&gt;
&lt;br /&gt;
(to be continued)&lt;br /&gt;
&lt;br /&gt;
== Links ==&lt;br /&gt;
&lt;br /&gt;
Below are a few links with useful info&lt;br /&gt;
&lt;br /&gt;
* [https://raid.wiki.kernel.org/index.php/Irreversible_mdadm_failure_recovery Irreversible mdadm failure recovery]&lt;br /&gt;
&lt;br /&gt;
= ZFS =&lt;br /&gt;
&lt;br /&gt;
ZFS can do a lot of things most filesystems or volume managers can&#039;t. It checksums all data and metadata and so long that the system uses ECC enabled memory (RAM), it will have complete control over the whole data set, and when (not if) an error occurs, it&#039;ll fix the issue without even throwing a warning. To fix the issue, you&#039;ll obviously need sufficient redundancy (mirrors or RAIDzN). &lt;br /&gt;
&lt;br /&gt;
== ZFS send/receive between machines ==&lt;br /&gt;
&lt;br /&gt;
ZFS has a send/receive mechanism that allows for snapshots to be sent over the wire to a receiving end. This can be a full filesystem, or an incremental change since last send/reveive. In a WAN scenario, you&#039;ll probably want to use VPN for this. On a controlled network, sending in cleartext is also possible. You may as well use ssh, but keep in mind that ssh was never designed to be used as a fullblown vpn solution and is just too slow or the task with large amounts of data. You may, though, use mbuffer, if on a loal LAN.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Allow traffic from the sending IP in whatever firewall interface you&#039;re using (if you&#039;re using a firewall at all, that is)&lt;br /&gt;
ufw allow from x.x.x.x&lt;br /&gt;
# &lt;br /&gt;
# Start the receiver first. This listens on port 9090, has a 1GB buffer,&lt;br /&gt;
    and uses 128kb chunks (same as zfs):&lt;br /&gt;
&lt;br /&gt;
mbuffer -s 128k -m 1G -I 9090 | zfs receive data/filesystem&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To be continued one day… See [https://everycity.co.uk/alasdair/2010/07/using-mbuffer-to-speed-up-slow-zfs-send-zfs-receive/ this] for some more. I&#039;ll get back with details on it.&lt;br /&gt;
&lt;br /&gt;
= General Linux system control =&lt;br /&gt;
&lt;br /&gt;
== Add a new CPU (core) ==&lt;br /&gt;
&lt;br /&gt;
If working with virtual machines, adding a new core can be useful if the VM is slow and the load is multithreaded or multiprocess. To do this, add a new CPU in the hypervisor (be it KVM or VMware or Hyper-V or whatever). Some hypervisors, like VMware, will activate it automatically if open-vm-tools is installed. Please note that open-vm-tools is for VMware only. I don&#039;t know of any such thing for KVM or other hypervisors (although I beleive VirtualBox has its own set of tools, but not as a package). If this doesn&#039;t work, run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
echo 1 &amp;gt; /sys/devices/system/cpu/cpuX/online&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where X is the CPU number you want to add. You can &#039;cat /sys/devices/system/cpu/cpuX/online&#039; to check if it&#039;s online.&lt;br /&gt;
&lt;br /&gt;
= Mount partitions on a disk image =&lt;br /&gt;
&lt;br /&gt;
Sometimes you&#039;ll have a disk image, either from recovering a bad drive after hours (or days or weeks) of ddrescue, and sometimes you just have a disk image from a virtual machine where you want to mount the partitions inside the image. There are three main methods of doing this, which are more or less synonmous, but some easier than the other.&lt;br /&gt;
&lt;br /&gt;
== Basics ==&lt;br /&gt;
&lt;br /&gt;
A disk image is usually like a disk, consisting of either a large filesystem, a PV or a partition table with one or partitions onto which resides a filesystem, a pv, swap or something else. If it&#039;s partitioned, and you want your operating system to mount a filesystem or allow it to see whatever LVM stuff lies on it, you need to isolate the partitions. &lt;br /&gt;
&lt;br /&gt;
== Manual mapping ==&lt;br /&gt;
&lt;br /&gt;
In the oldern days, this was done manually, something like this&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
root@mymachine:~# fdisk -l /dev/vda&lt;br /&gt;
Disk /dev/vda: 25 GiB, 26843545600 bytes, 52428800 sectors&lt;br /&gt;
Units: sectors of 1 * 512 = 512 bytes&lt;br /&gt;
Sector size (logical/physical): 512 bytes / 512 bytes&lt;br /&gt;
I/O size (minimum/optimal): 512 bytes / 512 bytes&lt;br /&gt;
Disklabel type: dos&lt;br /&gt;
Disk identifier: 0xc37b7ea5&lt;br /&gt;
&lt;br /&gt;
Device     Boot    Start      End  Sectors  Size Id Type&lt;br /&gt;
/dev/vda1  *        2048 50333311 50331264   24G 83 Linux&lt;br /&gt;
/dev/vda2       50333312 52426369  2093058 1022M  5 Extended&lt;br /&gt;
/dev/vda5       50333314 52426369  2093056 1022M 82 Linux swap / Solaris&lt;br /&gt;
root@mymachine:~#&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To calculate the start and end of each partition, you just take the start sector and multiply it by the sector size (512 bytes here) and you have the offset in bytes. After this, it&#039;s merely an losetup -o &amp;lt;offset&amp;gt; /dev/loopX &amp;lt;nameofimagefile&amp;gt; and you have the partition mapped to your /dev/loopX (having X being something typically 0-255. After this, just mount it or run pvscan/vgscan/lvscan to probe whatever lvm config is there, and you should be able to mount it like any other filesystem.&lt;br /&gt;
&lt;br /&gt;
== kpartx ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;kpartx&#039;&#039;&#039; does the same as above, more or less, just without so much hassle. Most of it should be automatic and easy to deal with, except it may fail to disconnect the loopback devices sometimes, so you may have to &#039;&#039;&#039;losetup -d&#039;&#039;&#039; them manually. See the manual, &#039;&#039;&#039;kpartx (8)&#039;&#039;&#039;. Please note that &#039;&#039;&#039;partx&#039;&#039;&#039; works similarly and I&#039;d guess the authors of the two tools are arguing a lot of which one&#039;s the best.&lt;br /&gt;
&lt;br /&gt;
== guestmount ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;guestmount&#039;&#039;&#039; is something similar again, but also supports file formats like &#039;&#039;&#039;qcow2&#039;&#039;&#039; and possibly other, proprietary filesystems like &#039;&#039;&#039;vmdk&#039;&#039;&#039; and &#039;&#039;&#039;vdi&#039;&#039;&#039;, but don&#039;t take my word for it - I haven&#039;t tested. Again, see the manual or just read up on the description [http://ask.xmodulo.com/mount-qcow2-disk-image-linux.html?fbclid=IwAR3snTeZvGzp9PLdX11EQhCfOpux6I93CiJ3A2pUomkkRLly9Xo4851mkTY here]. It seems rather trivial.&lt;br /&gt;
&lt;br /&gt;
= Linux on laptops =&lt;br /&gt;
&lt;br /&gt;
== Wifi with HP EliteBook 725/745 on Ubuntu ==&lt;br /&gt;
&lt;br /&gt;
The HP EliteBook 725/745 and similar are equipped with a BCM4352 wifi chip. As with a lot of other stuff from Broadcom, this lacks an open hardware description, so thus no open driver exist. The proper fix, is to replace the NIC with something with an open driver, but again, this isn&#039;t always possible, so a binary driver exists. In ubuntu, run, somehow connect the machine to the internet and run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install bcmwl-kernel-source&lt;br /&gt;
sudo modprobe wl&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you can&#039;t connect the machine to the internet, download the needed packages on another machine and put it on some usb storage. These packages should suffice:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# apt-cache depends bcmwl-kernel-source&lt;br /&gt;
bcmwl-kernel-source&lt;br /&gt;
  Depends: dkms&lt;br /&gt;
  Depends: linux-libc-dev&lt;br /&gt;
  Depends: libc6-dev&lt;br /&gt;
  Conflicts: &amp;lt;bcmwl-modaliases&amp;gt;&lt;br /&gt;
  Replaces: &amp;lt;bcmwl-modaliases&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then install manually with &#039;&#039;&#039;dpkg -i file1.deb file2.deb&#039;&#039;&#039; etc&lt;br /&gt;
&lt;br /&gt;
After this, ip/ifconfig/iwconfig shouldd see the new wifi nic, probably &#039;&#039;&#039;wlan0&#039;&#039;&#039;, but due to a [https://bugs.launchpad.net/ubuntu/+source/broadcom-sta/+bug/1343151 old, ignored bug], you won&#039;t find any wifi networks. This is because the driver from Broadcom apparently does not support interrupt remapping, commonly used on x64 machines. To turn this off, change &#039;&#039;&#039;/etc/default/grub&#039;&#039;&#039; and change the line &#039;&#039;&#039;GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;quiet splash&amp;quot;&#039;&#039;&#039;, adding intremap=off to the end before the quote: &#039;&#039;&#039;GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;quiet splash intremap=off&amp;quot;&#039;&#039;&#039;. Save the file and run &#039;&#039;&#039;sudo update-grub&#039;&#039;&#039; and reboot. After this, wifi should work well.&lt;br /&gt;
&lt;br /&gt;
== Wifi with HP Compaq Presario CQ57 on Ubuntu ==&lt;br /&gt;
&lt;br /&gt;
The HP Compaq Presario CQ57 uses the RT5390 wifi chipset. This has been supported for quite some time now, and I was quite surprised to find it not working on a laptop a friend was having. The driver loaded correctly, but Ubuntu insisted of the laptop being in &#039;&#039;&#039;flight mode&#039;&#039;&#039;. Checking &#039;&#039;&#039;rfkill&#039;&#039;&#039;, it showed me two NICs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# rfkill list all&lt;br /&gt;
0: phy0: Wireless LAN&lt;br /&gt;
	Soft blocked: no&lt;br /&gt;
	Hard blocked: yes&lt;br /&gt;
1: hp-wifi: Wireless LAN&lt;br /&gt;
	Soft blocked: yes&lt;br /&gt;
	Hard blocked: no&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Turning rfkill on and off resulted in nothing much, except some error messages in the kernel log (dmesg)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] ACPI Error: Field [B128] at bit offset/length 128/1024 exceeds size of target Buffer (160 bits) (20170831/dsopcode-235)&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]&lt;br /&gt;
                            Initialized Local Variables for Method [HWCD]:&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Local0: 00000000a34b7928 &amp;lt;Obj&amp;gt;           Integer 0000000000000000&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Local1: 00000000b0aa6865 &amp;lt;Obj&amp;gt;           Buffer(8) 46 41 49 4C 04 00 00 00&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Local5: 00000000a9811efd &amp;lt;Obj&amp;gt;           Integer 0000000000000004&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] Initialized Arguments for Method [HWCD]:  (2 arguments defined for method invocation)&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Arg0:   0000000078957d1b &amp;lt;Obj&amp;gt;           Integer 0000000000000001&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Arg1:   00000000725c9c6e &amp;lt;Obj&amp;gt;           Buffer(20) 53 45 43 55 02 00 00 00&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] ACPI Error: Method parse/execution failed \_SB.WMID.HWCD, AE_AML_BUFFER_LIMIT (20170831/psparse-550)&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] ACPI Error: Method parse/execution failed \_SB.WMID.WMAD, AE_AML_BUFFER_LIMIT (20170831/psparse-550)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After upgrading BIOS and testing different kernels, I was asked to try to unload the &#039;&#039;&#039;hp_wmi&#039;&#039;&#039; driver. I did, and things changed a bit, so I tried blacklisting it, creating the file &#039;&#039;&#039;/etc/modprobe.d/blacklist-hp_wmi.conf&#039;&#039;&#039; with the following content&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Blacklist this - it doesn&#039;t work!&lt;br /&gt;
blacklist hp_wmi&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
I gave the machine a reboot and afte that, the &#039;&#039;&#039;hp-wifi&#039;&#039;&#039; entry was gone in the rfkill output, and things works.&lt;br /&gt;
&lt;br /&gt;
= Raspberry pi =&lt;br /&gt;
&lt;br /&gt;
I couldn&#039;t quite decide if the raspberry pi should be a separate section or part of Linux, but hell, it can run more than Linux, although 99,lots% of people just uses Linux on them. This is a small list of things to know about them; things not on the front page of the manual or perhaps hidden even better.&lt;br /&gt;
&lt;br /&gt;
== Which pi? ==&lt;br /&gt;
&lt;br /&gt;
I just setup three raspberry pi machines and although some are quite different, like v1 to vEverythingelse or the Pi zero versions to the normal ones, not all of us remember how to distinguish between them, and sometimes they&#039;re in a nice 3d printed (or otherwise) chassis or otherwise hidden. So, how to check three different ones:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
root@home-assistant:~ $ cat /proc/device-tree/model ; echo&lt;br /&gt;
Raspberry Pi 2 Model B Rev 1.1&lt;br /&gt;
&lt;br /&gt;
root@green-pi:~ $ cat /proc/device-tree/model ; echo&lt;br /&gt;
Raspberry Pi 3 Model B Rev 1.2&lt;br /&gt;
&lt;br /&gt;
roy@yellow-pi:~ $cat /proc/device-tree/model ; echo&lt;br /&gt;
Raspberry Pi 4 Model B Rev 1.1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
While this works well, for the latter, the pi4, it doesn&#039;t tell how much memory I have. It comes in variants of 1, 2 and 4GB, and this is the latter.&lt;br /&gt;
&lt;br /&gt;
== Monitoring ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;vcgencmd&#039;&#039;&#039; from &#039;&#039;&#039;/opt/vc/bin&#039;&#039;&#039;, but symlinked to &#039;&#039;&#039;/usr/bin&#039;&#039;&#039; so it&#039;s available in path, is useful for fetching hardware info about the pi. For example, measuring the temperature&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
root@yellow-pi:~# vcgencmd measure_temp&lt;br /&gt;
temp=63.0&#039;C&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The command is generally badly documented and parts of it seems outdated for newer hardware. Here&#039;s the output from a Raspberry pi 4 with 4GB RAM&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
roy@yellow-pi:~ $ vcgencmd get_mem arm&lt;br /&gt;
arm=948M&lt;br /&gt;
roy@yellow-pi:~ $ vcgencmd get_mem gpu&lt;br /&gt;
gpu=76M&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== BIOS upgrade from Linux ==&lt;br /&gt;
&lt;br /&gt;
Generally, BIOS upgrades have been moved to the BIOS itself these days. This saves a lot of work and quite possibly lives after those who earier rammed their heads through walls, now can upgrade directly from the internet instead of using obscure operating systems best avoided. Sometimes, however, one must use these nevertheless. This is a quick run-through on your options.&lt;br /&gt;
&lt;br /&gt;
=== DOS ===&lt;br /&gt;
&lt;br /&gt;
Most non-automatic BIOS upgrades are installed from DOS. Doing a BIOS upgrade this way, is generally non-problematic. Just install a USB thingie with [https://www.freedos.org/ FreeDOS], copy your file(s) onto the thing and boot on it. The commandline is the same as old MS/DOS, except a wee bit more userfriendly, but not a lot.&lt;br /&gt;
&lt;br /&gt;
=== Windows ===&lt;br /&gt;
&lt;br /&gt;
Some macahines, like laptops from &#039;&#039;&#039;HP&#039;&#039;&#039;, may have BIOS upgrades that are made to be installed from Windows and won&#039;t run in FreeDOS or MS/DOS, instead throwing an error, saying &#039;&#039;&#039;This program cannot be run in DOS mode&#039;&#039;&#039;. This means you&#039;ll have to boot on a Windows rescue disc and do the job from there. Googling this, tells you it&#039;s quite easy, you just choose &#039;make rescue disc&#039; from Windows, and it&#039;s all good, except if you don&#039;t run Windows, that is. To remedy this problem, do as follows:&lt;br /&gt;
&lt;br /&gt;
==== Download Windows ====&lt;br /&gt;
&lt;br /&gt;
Since you don&#039;t run Windows and possibly don&#039;t have a spouse or friend around with such unhealthy habits either, you need to get it. It&#039;s quite easy - just google &#039;download windows&#039; and it&#039;ll send you to [https://www.microsoft.com/en-us/software-download/windows10ISO somewhere like this].&lt;br /&gt;
&lt;br /&gt;
==== Burn it! ====&lt;br /&gt;
&lt;br /&gt;
Now it&#039;s time to burn the installer on a DVD ROM. You&#039;ll need a double-layered one, since the OS is &amp;gt; 4.7GiB, but I&#039;m sure you have a ton of those lying around. Now, just place your optical medium in your optical drive and burn, baby, burn!&lt;br /&gt;
&lt;br /&gt;
==== Or make a USB thing? ====&lt;br /&gt;
&lt;br /&gt;
Not a lot of machines have optical drives these days, so you may want to use an USB pen drive or something instead. This is easy, just make the USB bootable with the Windows application Microsoft has made for this. Unfortunately, this only runs on Windows, and unlike stuff like Debian, where the &#039;&#039;&#039;iso&#039;&#039;&#039; file can be dd&#039;ed directly onto a USB drive to make it bootable, the Windows &#039;&#039;&#039;iso&#039;&#039;&#039;s don&#039;t come with this luxury. There are lots of methods to make bootable USB things from iso files out there, but the only thing most of them have in common, is that they generally don&#039;t work.&lt;br /&gt;
&lt;br /&gt;
===== WoeUSB =====&lt;br /&gt;
&lt;br /&gt;
After hours of swearing, it&#039;s nice to come across software like [https://github.com/slacka/WoeUSB WoeUSB]. It may not be perfect, it relies on a bunch of GUI stuff you&#039;ll never need and so on, but it &#039;&#039;&#039;&#039;&#039;works&#039;&#039;&#039;&#039;&#039;, and that&#039;s the important part! Just clone the repo and RTFM and it&#039;s all nice. It&#039;s slow, but hell, getting a windows machine and/or an optical drive might be slower.&lt;br /&gt;
&lt;br /&gt;
WoeUSB does nothing fancy, but it &#039;&#039;&#039;does&#039;&#039;&#039; work. It will create a filesystem, FAT32 or NTFS (better use NTFS, FAT32 has its limits). It creates normal filesystems and so on. Just make sure to copy in the BIOS update file, usually an exe file, to run when Windows is up and running.&lt;br /&gt;
&lt;br /&gt;
===== Install BIOS =====&lt;br /&gt;
&lt;br /&gt;
Boot on the Windows USB thing and choose &#039;repair computer&#039; and then &#039;command prompt&#039;. Find the install file, and if you&#039;re lucky, you&#039;ll find it needs a 32bit OS, just like I did. Since the 64bit version doesn&#039;t include 32bit compatibility in the installer, revert to downloading the 32bit version of windows and start over. Pray to your favourite god(s) not to get across such machines again - it might help.&lt;br /&gt;
&lt;br /&gt;
= 3D printer stuff =&lt;br /&gt;
&lt;br /&gt;
== Hydrophilic filament ==&lt;br /&gt;
&lt;br /&gt;
Most popular filament types, including PLA, PETG, PP or PA (Polyamide, normally known as Nylon) and virtualy any filament type named [https://www.matterhackers.com/news/filament-and-water poly-something] (and thus with an acronym of P-something) are hydrophilic (also (somewhat incorrectly) called hydroscopic), meaning so long they&#039;re dryer than the atmosphere around them, they&#039;ll do their best to suck out the atmosphere&#039;s humidity. This is why most filament are shrink-wrapped with a small bag of silica gel in it. If such filament is exposed for normal humid air for some time, it&#039;ll become very hard to use. Most of my experience is with PLA, which can handle a bit (depending on make), but still not a lot. With PLA, if you end up with prints where the filament seems not to stick, it may help with a higher temperature. Otherwise, the filament must be [https://all3dp.com/2/how-to-dry-filament-pla-abs-and-nylon/ baked]. If you don&#039;t want to use your oven, try something like a [https://www.jula.no/catalog/hjem-og-husholdning/kjokkenmaskiner/mattilberedningsapparater/frukt-sopptorker/frukt-sopptorker-001641/#tab02 fruit and mushroom dryer]. Then get a good, sealble plastic box and add something like half a kilogram of [https://www.ebay.com/sch/sis.html?_nkw=1KG+Orange+Replacement+Desiccant+Indicating+Silica+Gel+Beads+for+Drawers%2C+Camera&amp;amp;_id=131938742628&amp;amp;&amp;amp;_trksid=p2057872.m2749.l2658 silica gel] to an old sock, tie it and put it in the your new dry box.&lt;br /&gt;
&lt;br /&gt;
Please note that ABS is hydrophobic, so you won&#039;t have to worry too much there. Also, remember that PA/Nylon is extremely hydrophilic. Even a couple of days in normal air humidity can ruin it completely and will require baking.&lt;br /&gt;
&lt;br /&gt;
== Upgrading the firmware on an Ender 3 ==&lt;br /&gt;
&lt;br /&gt;
This is about upgrading the firmware, and thus also flashing a bootloader to the Creality Ender 3 3D printer. Most of this is well documented on several place, like o [https://www.youtube.com/watch?v=fIl5X2ffdyo the video from Teaching tech] and elsewhere, but I&#039;ll just summarise some issues I had.&lt;br /&gt;
&lt;br /&gt;
=== Using an arduino Nano as a programmer ===&lt;br /&gt;
&lt;br /&gt;
The CR-10, Ender 3 and a few other printers from Creality come without a bootloader, so you&#039;ll need to flash one before upgrading the firmware. Well, strictly speakning, you don&#039;t need one, you can save those 8kB or so for other stuff and use a programmer to write the whole firmware, but then you&#039;ll need to wire up everything every time you want a new firmware, so in my world, you &#039;&#039;&#039;do&#039;&#039;&#039; need the bootloader, since it&#039;s easier. Note that some newer printers, like the CR-10S and possibly all newer ones, come with the bootloader already and thus won&#039;t need another.&lt;br /&gt;
&lt;br /&gt;
To install a bootloader, you&#039;ll need a programmer, and I didn&#039;t have one available. Having some el-cheapo china-copies of Ardinos around, I read I could use one and tried so. Although the docs mostly mention the Uno etc, it&#039;s just as simple with the Nano copy.&lt;br /&gt;
&lt;br /&gt;
So, grab an arduino, plug it to your machine with a USB cable, and, using the Arduino IDE, use the ArduinoISP sketch there (found under Examples) to burn the software needed for the arduino to work as a programmer. When this is done, connect a 10µF capacitor between RST and GND to stop it from resetting when used as a programmer. Connect the MOSI, MISO and SCK pins from the ICSP block (that little isolated 6-pin block on top of the ardu). See [https://www.arduino.cc/en/Tutorial/ArduinoISP here] for a pinout. Then find Vcc and GND either on the ICSP block or elsewhere. Some sites say that on some boards you shouldn&#039;t use the pins on the ICSP block for this. I doubt it matters, though. Then connect another jumper wire from pin 10 on the ardu to work as the reset pin outwards to the chip being programmed (that is, on the printer). The ICSP jumper block pin layout is the same on the printer and on the ardu, and probably elsewhere. Sometimes [https://xkcd.com/927/ standardisation] actually works…&lt;br /&gt;
&lt;br /&gt;
See https://cloud.karlsbakk.net/index.php/s/zw48YJjzaf8Rc2F for a pic with the ardu (this wiki is broken atm, will fix it later)&lt;br /&gt;
&lt;br /&gt;
== Flashing the printer ==&lt;br /&gt;
&lt;br /&gt;
When the boot loader is in place, possibly after some wierd errors from during the process, the screen on the 3d printer will go blank and it&#039;ll behave like being bricked. This is ok. Now disconnect the wires and connect the USB cable between computer and printer, download the [https://www.th3dstudio.com/knowledgebase/th3d-unified-firmware-package/ TH3D unified firmware] and configure it for your particular needs. The video mentioned above describes this well. After flashing the new firmware, you&#039;ll probably get some timeouts and errors, since apparently it resets the printer after giving it the new firmware, but without notifying the flashing software of it doing so. If this happens, hold your breath and reboot the printer and check its tiny monitor - it should work. If it doesn&#039;t work, try to flash it again, and if that doesn&#039;t work, try flashing the programmer again yet another time, just for kicks.&lt;br /&gt;
&lt;br /&gt;
PS: I tried enabling &#039;&#039;&#039;MANUAL_MESH_LEVELING&#039;&#039;&#039;, which in the code says that &#039;&#039;If used with a 1284P board the bootscreen will be disabled to save space&#039;&#039;. This effectively disabled the whole thing, and apparently may be making the firmware image a wee bit too large for it to fit the 1284P on the ender. It works well without it, though.&lt;br /&gt;
&lt;br /&gt;
== And then… ==&lt;br /&gt;
&lt;br /&gt;
With the new firmware in place, the printer should work as before, although with thermal runaway protection to better avoid fires in case the shit hits the fan, and to allow for things like autolevelling. With any luck, [https://www.precisionpiezo.co.uk/ this thing] may be ready for use by the time you read this - it surely looks nice!&lt;br /&gt;
&lt;br /&gt;
roy&lt;/div&gt;</summary>
		<author><name>Roy</name></author>
	</entry>
	<entry>
		<id>https://wiki.malinux.no/index.php?title=Roy%27s_notes&amp;diff=155</id>
		<title>Roy&#039;s notes</title>
		<link rel="alternate" type="text/html" href="https://wiki.malinux.no/index.php?title=Roy%27s_notes&amp;diff=155"/>
		<updated>2020-04-16T14:14:01Z</updated>

		<summary type="html">&lt;p&gt;Roy: /* ZFS */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= LVM, md and friends =&lt;br /&gt;
&lt;br /&gt;
== Linux&#039; Logical Volume Manager (LVM) ==&lt;br /&gt;
&lt;br /&gt;
=== LVM in general ===&lt;br /&gt;
&lt;br /&gt;
LVM is designed to be an abstraction layer on top of physical drives or RAID, typically [https://raid.wiki.kernel.org/index.php/RAID_setup mdraid] or [https://help.ubuntu.com/community/FakeRaidHowto fakeraid]. Keep in mind that fakeraid should be avoided unless you really need it, like in conjunction with dual-booting linux and windows on fakeraid. LVM broadly consists of three elements, the &amp;quot;physical&amp;quot; devices (PV), the volume group (VG) and the logical volume (LV). There can be multiple PVs, VGs and LVs, depending on requirement. More about this below. All commands are given as examples, and all of them can be fine-tuned using extra flags in need of so. In my experience, the defaults work well for most usecases.&lt;br /&gt;
&lt;br /&gt;
I&#039;m mentioning filesystem below too. Where I write ext4, the samme applies to ext2 and ext3.&lt;br /&gt;
&lt;br /&gt;
==== Create a PV ====&lt;br /&gt;
&lt;br /&gt;
A PV is the &amp;quot;physical&amp;quot; parts. This does not need to be a physical disk, but can also be another RAID, be it an mdraid, fakeraid, hardware raid, a virtual disk on a SAN or otherwisee or a partition on one of those. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#  These add three PVs, one on a drive (or hardware raid) and another two on mdraids.&lt;br /&gt;
pvcreate /dev/sdb&lt;br /&gt;
pvcreate /dev/md1 /dev/md2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For more information about pvcreate, see [https://linux.die.net/man/8/pvcreate the manual].&lt;br /&gt;
&lt;br /&gt;
==== Create a VG ====&lt;br /&gt;
&lt;br /&gt;
The volume group consists of one or more PVs grouped together on which LVs can be placed. If several PVs are grouped in a VG, it&#039;s generally a good idea to make sure these PVs have some sort of redundancy, as in mdraid/fakeraid or hwraid. Otherwise it will be like using a [https://en.wikipedia.org/wiki/RAID RAID-0] with a single point of failure on each of the independant drives. LVM has [https://unix.stackexchange.com/questions/150644/raiding-with-lvm-vs-mdraid-pros-and-cons  RAID code in it] as well, so you can use that. I haven&#039;t done so myself, as I generally stick to mraid. The reason is mdraid is, in my opinion older and more stable and has more users (meaning bugs are reported and fixed faster whenever they are found). That said, I beleive the actual RAID code used in LVM RAID are the same function calls as for mdraid, so it may not be much of a difference. I still stick with mdraid. To create a VG, run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create volume group my_vg&lt;br /&gt;
vgcreate my_vg /dev/md1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that if vgcreate is run with a PV (as /dev/md1 above) that is not defined as a PV (like above), this is done implicitly, so if you don&#039;t need any special flags to pvcreate, you can simply skip it and let vgcreate do that for you.&lt;br /&gt;
&lt;br /&gt;
==== Create an LV ====&lt;br /&gt;
&lt;br /&gt;
LVs can be compared to partitions, somehow, since they are bounderies of a fraction or all of that of a VG. The difference between them and a partition, however, is that they can be grown or shrunk easily and also moved around between PVs without downtime. This flexibility makes them superiour to partitions as your system can be changed without users noticing it. By default, an LV is alloated &amp;quot;thickly&amp;quot;, meaning all the data given to it, is allocated from the VG and thus the PV. The following makes a 100GB LV named &amp;quot;thicklv&amp;quot;. When making an LV, I usually allocate what&#039;s needed plus some more, but not everything, just to make sure it&#039;s space available for growth on any of the LVs on the VG, or new LVs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a thick provisioned LV named thicklv on the VG my_vg&lt;br /&gt;
lvcreate -n thicklv -L 100G my_vg&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After the LV is created, a filesystem can be placed on it unless it is meant to be used directly. The application for direct use include swap space, VM storage and certain database systems. Most of these will, however, work on filesystems too, although my testing has shown that on swap space, there is a significant performance gain for using dedicated storage without a filesystem. As for filesystems, most Linux users use either ext4 or xfs. Personally, I generally use XFS these days. See my notes below on filesystem choice.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a filesystem on the LV - this could have been mkfs -t ext4 or whatever filesystem you choose&lt;br /&gt;
mkfs -t xfs /dev/my_vg/thicklv&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then just edit /etc/fstab with correct data and run mount -a, and you should be all set.&lt;br /&gt;
&lt;br /&gt;
==== Create LVM cache ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
lvcreate -L 1G -n _cache_meta data /dev/md1&lt;br /&gt;
&lt;br /&gt;
lvcreate -l100%FREE -n _cache data /dev/md1&lt;br /&gt;
&lt;br /&gt;
# Some would want --cachemode writeback, but seriously, I wouldn&#039;t recommend it. Metadata or data can be easily corrupted in case of failure.&lt;br /&gt;
lvconvert --type cache-pool --cachemode writethrough --poolmetadata data/_cache_meta data/_cache&lt;br /&gt;
&lt;br /&gt;
lvconvert --type cache --cachepool data/_cache data/data&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Disabling LVM cache ====&lt;br /&gt;
&lt;br /&gt;
If you for some reason want to disable caching, this will do it cleanly and remove the LVs earlier created for caching the main device.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
lvconvert --uncache data/data&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Growing devices ====&lt;br /&gt;
&lt;br /&gt;
LVM objects can be grown and shrunk. If a PV resides on a RAID where a new drive has been added or otherwise grown, or on a partition or virtual disk that has been extended, the PV must be updated to reflect these changes. The following command will grow the PV to the maximum available on the underlying storage. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Resize the PV /dev/md (not the RAID, only the PV on the RAID) to its full size&lt;br /&gt;
pvresize /dev/md1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If a new PV is added, the VG can be grown to add the space on that in addition to what&#039;s there already. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Extend my_vg to include md2 and its space&lt;br /&gt;
vgextend my_vg /dev/md2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
With more space available in the VG, the LV can now be extended. Let&#039;s add another 50GB to it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Extend thicklv - add 50GB. If you know you won&#039;t need the space anywhere else, you may want to&lt;br /&gt;
# lvresize -l+100%FREE instead. Keep in mind the difference between -l (extents) and -L (bytes)&lt;br /&gt;
lvresize -L +50G my_vg/thicklv&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Growing filesystems ====&lt;br /&gt;
After the LV has grown, run &#039;&#039;xfs_growfs&#039;&#039; (xfs) or &#039;&#039;resize2fs&#039;&#039; (ext4) to make use of the new data. To grow the filesystem to all available space on ext4, run the below command.  To partly grow the filesystem or to shrink it or otherwise, please see the manuals.&lt;br /&gt;
&lt;br /&gt;
The filesystem can be mounted when this is run. If you for some reason get an &#039;&#039;&#039;access denied&#039;&#039;&#039; error when running this as root or with sudo, it&#039;s likely caused by a filesystem error. To fix this, unmount the filesystem first and run &#039;&#039;&#039;fsck -f /dev/my_vg/thicklv&#039;&#039;&#039; and remount it before retrying to extend it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
resize2fs /dev/my_vg/thicklv&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Similarly, with XFS, but note that xfs_growfs doesn&#039;t take the device name, but the filesystem&#039;s mount point. In the case of XFS, also note that the filesystem &#039;&#039;&#039;&#039;&#039;must&#039;&#039;&#039;&#039;&#039; be mounted to be grown. This, in contrast to how it was in the old days when filesystems had to be unmounted to be grown.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
xfs_growfs /my_mountpoint&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Rename system VG ====&lt;br /&gt;
&lt;br /&gt;
Some distros create VG names like those-from-a-sysadmin-with-a-well-developed-paranoia-not-to-hit-a-duplicate. Debian, for instance, uses names like &amp;quot;my-full-hostname-vg&amp;quot;. Personally, I don&#039;t like these, since if I were to move a disk or vdisk around to somewhere else, I&#039;d make sure not to add a disk named &#039;sys&#039; to an existing system. If you do, most distros will refuse to use the VGs with duplicate names, resulting in the OS not booting until either one is specified by its UUID or just one removed. As I&#039;m aware of this, I stick to the super-risky thing of all system VGs named &#039;sys&#039; and so on.&lt;br /&gt;
&lt;br /&gt;
If you do this, keep in mind that it may blow up your computer and take your girl- or boyfriend with it or even make either of them pregnant, allowing Trump to rule your life and generally make things suck. You&#039;re on your own!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Rename the VG&lt;br /&gt;
vgrename my-full-hostname-vg sys&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, in /boot/grub/grub.cfg, change the old lv path from something like &#039;/dev/mapper/debian--stretch--machine--vg-root&#039; to your new and fancy &#039;/dev/sys/root. Likewise, in /etc/fstab, change occurences of &#039;/dev/mapper/debian--stretch--machine--vg-&#039; (or similar) with &#039;/dev/sys/&#039;. Here, this was like this - the old ones commented out.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;fstab&amp;quot;&amp;gt;&lt;br /&gt;
#/dev/mapper/debian--stretch--box--vg-root      /               ext4            errors=remount-ro,discard       0       1&lt;br /&gt;
/dev/sys/root                                   /               ext4            errors=remount-ro,discard       0       1&lt;br /&gt;
# /boot was on /dev/vda1 during installation&lt;br /&gt;
UUID=myverylonguuidwithatonofgoodinfoinit       /boot           ext2            defaults                        0       2&lt;br /&gt;
#/dev/mapper/debian--stretch--box--vg-swap_1    none            swap            sw                              0       0&lt;br /&gt;
/dev/sys/swap_1                                 none            swap            sw                              0       0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Update /etc/initramfs-tools/conf.d/resume with similar data for swap.&lt;br /&gt;
&lt;br /&gt;
You might want to run &#039;update-initramfs -u -k all&#039; after this, but I&#039;m not sure if it&#039;s needed.&lt;br /&gt;
&lt;br /&gt;
Now, pray to the nearest god(s) and give it a reboot and it should (probably) work.&lt;br /&gt;
&lt;br /&gt;
After reboot, run &#039;&#039;&#039;swapoff -a&#039;&#039;&#039;, then &#039;&#039;&#039;mkswap /dev/sys/swap_1&#039;&#039;&#039; (or whatever it&#039;s called on your system) and &#039;&#039;&#039;swapon -a&#039;&#039;&#039; again. You may want to give it another reboot or two for kicks, but it should work well even without that.&lt;br /&gt;
&lt;br /&gt;
=== Migration tools ===&lt;br /&gt;
&lt;br /&gt;
At times, storage regimes change, new storage is added and sometimes it&#039;s not easy to migrate with the current hardware or its support systems. Once I had to migrate a 45TiB fileserver from one storage system to another, preferably without downtime. The server originally had three 15TiB PVs of which two were full and the third half full. I resorted to using [https://linux.die.net/man/8/pvmove pvmove] to just move the data on the PVs in use to a new PV. We started out with creating a new 50TiB PV, sde, and then to pvmove.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Attach /dev/sde to the VG my_vg&lt;br /&gt;
vgextend my_vg /dev/sde&lt;br /&gt;
&lt;br /&gt;
# Move the contents from /dev/sdb over to /dev/sde block by block. If a target is not given in pvmove,&lt;br /&gt;
# the contents of the source (sdb here) will be put somewhere else in the pool.&lt;br /&gt;
pvmove /dev/sdb /dev/sde&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This took a while (as in a week or so) - the pvmove command uses old code and logic (or at least did that when I migrated this in November 2016), but it affected performance on the server very little, so users didn&#039;t notice. After the first PV was migrated, I continued with the other two, one after the other, and after a month or so, it was migrated. We used this on a number of large fileservers, and it worked flawlessly. Before doing the production servers I also tried interrupting pvmove in various ways, including hard resets, and it just kept on after the reboot.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;NOTE:&#039;&#039;&#039;&#039;&#039; &#039;&#039;Even though it worked well for us, &#039;&#039;&#039;always&#039;&#039;&#039; keep a good backup before doing this. Things may go wrong, and without a good backup, you may be looking for a hard-to-find new job the next morning&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
==== mdadm workarounds ====&lt;br /&gt;
&lt;br /&gt;
===== Migrate from a mirror (raid-1) to raid-10 =====&lt;br /&gt;
&lt;br /&gt;
Create a mirror&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sdb /dev/sdc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
LVM (pv/vg/lv) on md0 (see above), put a filesystem on the lv and fill it with some data.&lt;br /&gt;
&lt;br /&gt;
Now, some months later, you want to change this to raid-10 to allow for the same amount of redundancy, but to allow more disks into the system.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mdadm --grow /dev/md0 --level=10&lt;br /&gt;
mdadm: Impossibly level change request for RAID1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So - no - doesn&#039;t work. But - we&#039;re on &lt;br /&gt;
&lt;br /&gt;
Since we&#039;re on lvm already, this&#039;ll be easy. If you&#039;re using filesystems directly on partitions, you can do this the same way, but without the pvmove part, using rsync or whateever you like instead. I&#039;d recommend using lvm for for the new raid, which should be rather obvious from this article. Now plug in a new drive and create a new raid10 on that one. If you two new drives, install both. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# change &amp;quot;missing&amp;quot; to the other device name if you installed two new drives&lt;br /&gt;
mdadm --create /dev/md1 --level=10 --raid-devices=2 /dev/vdd missing&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, as described above, just vgextend the vg, adding the new raid and run pvmove to move the data from the old pv (residing on the old raid1) to the new pv (on raid10). Afte rpvmove is finished (which may take awile, see above), just&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
vgreduce raidtest /dev/md0&lt;br /&gt;
pvremove /dev/md0&lt;br /&gt;
mdadm --stop /dev/md0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
…and your disk is free to be added to the new array. If the new raid is running in degraded mode (if you created it with just one drive), better don&#039;t wait too long, since you don&#039;t have redundancy. Just mdadm --add the devs.&lt;br /&gt;
&lt;br /&gt;
If you now have /dev/mdstat telling you your raid10 is active and have three drives, of which one is a spare, it should look something like this&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5] [raid4] [raid10]&lt;br /&gt;
md1 : active raid10 vdc[3](S) vdb[2] vdd[0]&lt;br /&gt;
      8380416 blocks super 1.2 2 near-copies [2/2] [UU]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Just mdadm --grow --raid-devices=3 /dev/md1&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;RAID section is not complete. I&#039;ll write more on migraing from raid10 to raid6 later. It&#039;s not straight forward, but easier than this one :)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== Thin provisioned LVs ===&lt;br /&gt;
&lt;br /&gt;
Thin provisioning on LVM is a method used for not allocating all the space given to an LV. For instance, if you have a 1TB VG and want to give an LV 500GB, although it currently only uses a fraction of that, a thin lv can be a good alternative. This will allow for adding a limit to how much it can use, but also to let it grow dynamically without manual work by the sysadmin. Thin provisioning adds another layer of abstaction by creating a special LV as a &#039;&#039;thin pool&#039;&#039; from which data is allocated to the &#039;&#039;thin volume(s)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== Create a thin pool ====&lt;br /&gt;
&lt;br /&gt;
Allocate 1TB to the thin pool to be used for thinly provisioned LVs. Keep in mind that the space allocated to the thin pool is in fact thick provisioned. Only the volumes put on &#039;&#039;thinpool&#039;&#039; are thin provisioned. This will create two hidden LVs, one for data and one for metadata. Normally the defaults will do, but check the manual if the data doesn&#039;t match the usual patterns (such as billions of files, resulting in huge amounts of metadata). I &#039;&#039;beleive&#039;&#039; the metadata part should be resizable at a later time if needed, but I have not tested it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a pool for thin LVs. Keep in mind that the pool itself is not thin provisioned, only the volumes residing on it&lt;br /&gt;
lvcreate --size 1T --type thin-pool --thinpool thinpool my_vg&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Create a thin volume ====&lt;br /&gt;
&lt;br /&gt;
You have the thinpool, now put a thin volume on it. It will allocate some space for metadata, but probably not much (a few megs, perhaps).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Now, create a volume with a virtual (-V) size of half a terabyte named thin_pool, but using the thinpool (-T) named thin_pool for storage&lt;br /&gt;
lvcreate -V 500G -T my_vg/thin_pool --name thinvol&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The new volume&#039;s device name will be /dev/thinvol. Now, create a filesystem on it, add to fstab and mount it. The &#039;&#039;&#039;df&#039;&#039;&#039; command will return available space according to the virtual size (-V), while lvs will show how much data is actually used on each of the thinly provisioned volumes.&lt;br /&gt;
&lt;br /&gt;
== Filesystem dilemmas ==&lt;br /&gt;
&lt;br /&gt;
=== XFS or ext4 or something else ===&lt;br /&gt;
The choice of filesystem varies for your use. Distros such as RHEL/CentOS has moved to XFS by default from v7. Debian/Ubuntu still sticks to ext4, like most other. I&#039;ll discuss my thoughts below on ext4 vs XFS and leave the other filesystems for later.&lt;br /&gt;
&lt;br /&gt;
==== ext4 ====&lt;br /&gt;
ext4 is probably the most used filesystem on linux as of writing. It&#039;s rock stable and has been extended by a lot of extensions since the original ext2. It still retains backward compatibility, being able to mount and fsck ext2 and ext3 with the ext4 driver. However, it doesn&#039;t handle large filesystems very well. If a filesystem is created for &amp;lt;16TiB, it cannot be grown to anything larger than 16TiB. This may have changed lately, though. One other issue is handling errors. If a large filesystem (say 10TiB) is damaged, an fsck may take several hours, leading to long downtime. When I refer to ext4 further in this text, the same applies to ext2 and ext3 unless otherwise specified.&lt;br /&gt;
&lt;br /&gt;
==== XFS ====&lt;br /&gt;
XFS, originally developed by SGI some time in the bronze age, but has been worked on heavily after that. RHEL and Centos version 7 and forward, uses XFS as the default filesystem. It is quick, it scales well, but it lacks at least two things ext4 has. It cannot be shrunk (not that you normally need that, but nice if you have a typo or you need to change things). Also, it doesn&#039;t allow for automatic fsck on bootup. If something is messed up on the filesystem, you&#039;ll have to login as root on the console (not ssh), which might be an issue on some systems. The fsck equivalent, xfs_repair, is a *lot* faster than ext4&#039;s fsck, though.&lt;br /&gt;
&lt;br /&gt;
==== ZFS ====&lt;br /&gt;
ZFS is like a combination of RAID, LVM and a filesystem, supporting full checksumming, auto-healing (given sufficient redundancy), compression, encryption, replication, deduplication (if you&#039;re brave and have a &#039;&#039;ton&#039;&#039; of memory) and a lot more. It&#039;s a separate chapter and needs a lot more talk than paragraph here.&lt;br /&gt;
&lt;br /&gt;
==== btrfs ====&lt;br /&gt;
btrfs, pronounced &amp;quot;butterfs&amp;quot; or &amp;quot;betterfs&amp;quot; or just spelled out, is a filesystem that mimics that of ZFS. It has been around for 10 years or so, but hasn&#039;t yet proven to be really stable. Following the progress of it for those years, I&#039;ve found it to be a nice toy with which to play, but not to be used in production. Again, others may say otherwise, but these are just my words.&lt;br /&gt;
&lt;br /&gt;
== Low level disk handling ==&lt;br /&gt;
&lt;br /&gt;
This section is for low-level handling of disks, regardless of storage system elsewhere. These apply to mdraid, lvmraid and zfs and possibly other solutions, with the exception of individual drives on hwraid (and maybe fakeraid), since there, the drives are hidden from Linux (or whatever OS).&lt;br /&gt;
&lt;br /&gt;
=== S.M.A.R.T. and slow drives ===&lt;br /&gt;
Modern (that is, from about 1990 or later) have S.M.A.R.T. (or just smart, since it&#039;s easier to type) monitoring built in, meaning the disk&#039;s controller is monitoring itself. This is handy and will ideally tell you in advance that a drive is flakey or dying. Modern (2010+) smart monitoring is more or less the same. It can be trusted about 50% of the time. Usually, if smart detects an error, it&#039;s a real error. I don&#039;t think I&#039;ve seen it reporting a false positive, but others may know better. &lt;br /&gt;
&lt;br /&gt;
==== smartmontools ====&lt;br /&gt;
First, install smartmontool and run smartclt -H /dev/yourdisk (/dev/sda or something) to get a health report. Then perhaps run smartctl -a /dev/yourdisk and look for &#039;current pending sectors&#039; This should be zero. Also check the temperature, which normally should be much above 50.&lt;br /&gt;
&lt;br /&gt;
==== single, slow drive ====&lt;br /&gt;
What may happen, is smart not seeing anything and life goes on like before, only slower and less prouductive, without telling anyone. If you stubler over this issue, you&#039;ll probably see it during a large rsync/zfs send/receive or a resync/rebuild/resilver of the raid/zpool. During this, it feels like everything is slow and your RAID has turned into a RAIF (redundant array of inexpensive floppies). To check if you have a single drive messing up it all, check with &#039;&#039;&#039;iostat -x 2&#039;&#039;&#039;, having 2 being the delay between each measurement. Interrupt it with ctrl+x. If there&#039;s a rougue drive there, it should stand out like sdg below&lt;br /&gt;
&lt;br /&gt;
 avg-cpu:  %user   %nice %system %iowait  %steal   %idle&lt;br /&gt;
            0.38    0.00    1.75    0.00    0.00   97.87&lt;br /&gt;
&lt;br /&gt;
 Device            r/s     w/s     rkB/s     wkB/s   rrqm/s   wrqm/s  %rrqm  %wrqm r_await w_await aqu-sz rareq-sz wareq-sz  svctm  %util&lt;br /&gt;
 sda              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdb              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdc              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdd              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sde              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdf              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdg              3.50    0.00   2352.00      0.00     0.00     0.00   0.00   0.00 14306.29    0.00  13.85   672.00     0.00 285.71 100.00&lt;br /&gt;
 sdh              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
&lt;br /&gt;
In ZFS land, you should be able to get similar data with &#039;&#039;&#039;zpool iostat -v &amp;lt;pool&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Now you know the bad drive (sdg), pull it from the raid with &#039;&#039;&#039;mdadm --fail /dev/mdX /dev/sdX&#039;&#039;&#039;. Now test the drive&#039;s performance manually, just simply:&lt;br /&gt;
&lt;br /&gt;
 # hdparm -t /dev/sdg&lt;br /&gt;
 &lt;br /&gt;
 /dev/sdg:&lt;br /&gt;
  Timing buffered disk reads:   2 MB in  5.37 seconds = 381.46 kB/sec&lt;br /&gt;
&lt;br /&gt;
Bingo - nothing you&#039;d want to keep. For a good drive, it should be something like 100-200MB/s&lt;br /&gt;
&lt;br /&gt;
PS: Keep in mind that you have a degraded RAID by now in case you had a spare waiting for things to happen.&lt;br /&gt;
&lt;br /&gt;
Try to replace the cable and/or try the disk on another port/controller. If the result from hdparm persists, it&#039;s probably a bad cable&lt;br /&gt;
&lt;br /&gt;
So, then, just psycially locate the drive, pull it out, take out the discs and magnets and recycle the rest.&lt;br /&gt;
&lt;br /&gt;
=== &amp;quot;Unplug&amp;quot; drive from system ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Find the device unit&#039;s number with something like&lt;br /&gt;
find /sys/bus/scsi/devices/*/block/ -name sdd&lt;br /&gt;
# returning /sys/bus/scsi/devices/3:0:0:0/block/sdd here, &lt;br /&gt;
# meaning 3:0:0:0 is the SCSI device we&#039;re looking for.&lt;br /&gt;
&lt;br /&gt;
# Given this is the correct device, and you want to &#039;unplug&#039; it, do so by&lt;br /&gt;
echo 1 &amp;gt; /sys/bus/scsi/devices/3:0:0:0/delete&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Rescan disk controllers ===&lt;br /&gt;
If a drive is added and for some reason doesn&#039;t get detected, or is removed by the command above, it can be rediscovered with a sysfs command to the scsi host to which it is connected. Since there may be quite a few of these, an easy way is to just scan them all and check the output of &#039;&#039;&#039;dmesg -T&#039;&#039;&#039; after running it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Make a list of controllers and send a rescan message to each of them. It won&#039;t do anything &lt;br /&gt;
# for those where nothing has changed, but it will show new drives where they have been added.&lt;br /&gt;
for host_scan in /sys/class/scsi_host/host*/scan&lt;br /&gt;
do&lt;br /&gt;
  echo &#039;- - -&#039; &amp;gt; $host_scan&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Fail injection with debugfs ===&lt;br /&gt;
[https://lxadm.com/Using_fault_injection https://lxadm.com/Using_fault_injection]&lt;br /&gt;
&lt;br /&gt;
== mdadm stuff ==&lt;br /&gt;
=== Resync ===&lt;br /&gt;
To resync a raid, that is, check, run&lt;br /&gt;
&lt;br /&gt;
 echo check &amp;gt; /sys/block/$dev/md/sync_action&lt;br /&gt;
&lt;br /&gt;
where $dev is something like md0. If you have several raids, something like this should work&lt;br /&gt;
&lt;br /&gt;
 for dev in md{0,1}&lt;br /&gt;
 do&lt;br /&gt;
   echo repair &amp;gt; /sys/block/$dev/md/sync_action&lt;br /&gt;
 done&lt;br /&gt;
&lt;br /&gt;
Also useful in a one-liner like&lt;br /&gt;
&lt;br /&gt;
 for dev in md{0,1} ; do echo repair &amp;gt; /sys/block/$dev/md/sync_action ; done&lt;br /&gt;
&lt;br /&gt;
Different raids on different drives will do this in parallel. If the drives are shared somehow with partitions or similar, the check or repair will wait for the other to finish before going on.&lt;br /&gt;
&lt;br /&gt;
As for repair vs check, [https://raid.wiki.kernel.org/index.php/RAID_Administration this article] describes it well. I stick to using repair unless it&#039;s something rare where I don&#039;t want to touch the data.&lt;br /&gt;
&lt;br /&gt;
=== Spare pools ===&lt;br /&gt;
In the old itmes, mdadm supported only a dedicated spare per md device, so if working with a large set of drives (20? 40?), where you&#039;d want to setup more raid sets to increase redundancy, you&#039;d dedicate a spare to each of the raid sets. This has changed (some time ago?), so in these modern, heathen days, you can change mdadm.conf, usually placed under /etc/mdadm, and add &#039;spare-group=somegroup&#039; where &#039;somegroup&#039; is a string identifying the spare group. After doing this, run &#039;&#039;&#039;update-initramfs -u&#039;&#039;&#039; and reboot and add a spare to one of the raid sets in the spare group, and md will use that or those spares for all the raidsets in that group.&lt;br /&gt;
&lt;br /&gt;
As some pointed out on #linux-raid @ irc.freenode.net, this feature is very badly documented, but as far as I can see, it works well.&lt;br /&gt;
&lt;br /&gt;
==== Example config ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create two raidsets&lt;br /&gt;
&lt;br /&gt;
mdadm --create /dev/md1 --level=6 --raid-devices=6 /dev/vd[efghij]&lt;br /&gt;
mdadm --create /dev/md2 --level=6 --raid-devices=6 /dev/vd[klmnop]&lt;br /&gt;
&lt;br /&gt;
# get their UUID etc&lt;br /&gt;
&lt;br /&gt;
mdadm --detail --scan&lt;br /&gt;
ARRAY /dev/md/1 metadata=1.2 name=raidtest:1 UUID=1a8cbdcb:f4092350:348b6b80:c054d74c&lt;br /&gt;
ARRAY /dev/md/2 metadata=1.2 name=raidtest:2 UUID=894b1b7c:cb7eba70:917d6033:ea5afd2b&lt;br /&gt;
&lt;br /&gt;
# Put those lines into /etc/mdadm/mdadm.conf and and add the spare-group&lt;br /&gt;
&lt;br /&gt;
ARRAY /dev/md/1 metadata=1.2 name=raidtest:1 spare-group=raidtest UUID=1a8cbdcb:f4092350:348b6b80:c054d74c&lt;br /&gt;
ARRAY /dev/md/2 metadata=1.2 name=raidtest:2 spare-group=raidtest UUID=894b1b7c:cb7eba70:917d6033:ea5afd2b&lt;br /&gt;
&lt;br /&gt;
# update the initramfs and reboot&lt;br /&gt;
&lt;br /&gt;
update-initramfs -u&lt;br /&gt;
reboot&lt;br /&gt;
&lt;br /&gt;
# add a spare drive to one of the raids&lt;br /&gt;
&lt;br /&gt;
mdadm --add /dev/md1 /dev/vdq&lt;br /&gt;
&lt;br /&gt;
# fail a drive on the other raid&lt;br /&gt;
&lt;br /&gt;
mdadm --fail /dev/md2 /dev/vdn&lt;br /&gt;
&lt;br /&gt;
# check /proc/mdstat to see md2 rebuilding with the spare from md1&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Recovery ===&lt;br /&gt;
&lt;br /&gt;
The other day, I came across a problem a user had on #linux-raid@irc.freenode.net. He had an old Qnap NAS that had died and tried plugging the drives in to his Linux machine and got various errors. The two-drive RAID-1 did not come up as it should, &#039;&#039;&#039;dmesg&#039;&#039;&#039; was full of errors from one of the drives (both connected on USB) and so forth.&lt;br /&gt;
&lt;br /&gt;
We went on and started by taking down the machine and just connecting one of the drives. I had him check what was assembled with&lt;br /&gt;
&lt;br /&gt;
 cat /proc/mdstat&lt;br /&gt;
&lt;br /&gt;
That returned /proc/md127 assembled, but LVM didn&#039;t find anything. So running a manual scan&lt;br /&gt;
&lt;br /&gt;
 pvscan --cache /dev/md127&lt;br /&gt;
&lt;br /&gt;
This made linux find the PV, VG and a couple of LVs, but probably because the mdraid was degraded, the LVs were deactivated, according to &#039;&#039;&#039;lvscan&#039;&#039;&#039;. Activating the one with a filesystem manually&lt;br /&gt;
&lt;br /&gt;
 lvchange -a y /dev/&amp;lt;vg&amp;gt;/&amp;lt;lv&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Substitute &amp;lt;vg&amp;gt; and &amp;lt;lv&amp;gt; with the names listed by vgs and lvs.&lt;br /&gt;
&lt;br /&gt;
This worked, and the filesystem on /dev/&amp;lt;vg&amp;gt;/&amp;lt;lv&amp;gt; could be mounted correctly.&lt;br /&gt;
&lt;br /&gt;
== Tuning ==&lt;br /&gt;
&lt;br /&gt;
While trying to compare a 12-disk RAID (8TB disks) to a hwraid, mdraid was slower, so we did a few things to speed things up:&lt;br /&gt;
&lt;br /&gt;
While testing with [https://linux.die.net/man/1/fio fio], monitor /sys/block/md0/md/stripe_cache_active, and see if it&#039;s close to /sys/block/md0/md/stripe_cache_size. If it is, double the size of the latter&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
echo 4096 &amp;gt; /sys/block/md0/md/stripe_cache_size&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Continue until stripe_cache_active stabilises, and then you&#039;ve found the limit you&#039;ll need. You may want to double that for good measure. &lt;br /&gt;
&lt;br /&gt;
(to be continued)&lt;br /&gt;
&lt;br /&gt;
== Links ==&lt;br /&gt;
&lt;br /&gt;
Below are a few links with useful info&lt;br /&gt;
&lt;br /&gt;
* [https://raid.wiki.kernel.org/index.php/Irreversible_mdadm_failure_recovery Irreversible mdadm failure recovery]&lt;br /&gt;
&lt;br /&gt;
= ZFS =&lt;br /&gt;
&lt;br /&gt;
ZFS can do a lot of things most filesystems or volume managers can&#039;t. It checksums all data and metadata and so long that the system uses ECC enabled memory (RAM), it will have complete control over the whole data set, and when (not if) an error occurs, it&#039;ll fix the issue without even throwing a warning. To fix the issue, you&#039;ll obviously need sufficient redundancy (mirrors or RAIDzN). &lt;br /&gt;
&lt;br /&gt;
== ZFS send/receive between machines ==&lt;br /&gt;
&lt;br /&gt;
ZFS has a send/receive mechanism that allows for snapshots to be sent over the wire to a receiving end. This can be a full filesystem, or an incremental change since last send/reveive. In a WAN scenario, you&#039;ll probably want to use VPN for this. On a controlled network, sending in cleartext is also possible. You may as well use ssh, but keep in mind that ssh was never designed to be used as a fullblown vpn solution and is just too slow or the task with large amounts of data. You may, though, use mbuffer, if on a loal LAN.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Allow traffic from the sending IP in whatever firewall interface you&#039;re using (if you&#039;re using a firewall at all, that is)&lt;br /&gt;
ufw allow from x.x.x.x&lt;br /&gt;
# &lt;br /&gt;
# Start the receiver first. This listens on port 9090, has a 1GB buffer,&lt;br /&gt;
    and uses 128kb chunks (same as zfs):&lt;br /&gt;
&lt;br /&gt;
mbuffer -s 128k -m 1G -I 9090 | zfs receive data/filesystem&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To be continued one day… See [https://everycity.co.uk/alasdair/2010/07/using-mbuffer-to-speed-up-slow-zfs-send-zfs-receive/ this] for some more. I&#039;ll get back with details on it.&lt;br /&gt;
&lt;br /&gt;
= General Linux system control =&lt;br /&gt;
&lt;br /&gt;
== Add a new CPU (core) ==&lt;br /&gt;
&lt;br /&gt;
If working with virtual machines, adding a new core can be useful if the VM is slow and the load is multithreaded or multiprocess. To do this, add a new CPU in the hypervisor (be it KVM or VMware or Hyper-V or whatever). Some hypervisors, like VMware, will activate it automatically if open-vm-tools is installed. Please note that open-vm-tools is for VMware only. I don&#039;t know of any such thing for KVM or other hypervisors (although I beleive VirtualBox has its own set of tools, but not as a package). If this doesn&#039;t work, run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
echo 1 &amp;gt; /sys/devices/system/cpu/cpuX/online&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where X is the CPU number you want to add. You can &#039;cat /sys/devices/system/cpu/cpuX/online&#039; to check if it&#039;s online.&lt;br /&gt;
&lt;br /&gt;
= Mount partitions on a disk image =&lt;br /&gt;
&lt;br /&gt;
Sometimes you&#039;ll have a disk image, either from recovering a bad drive after hours (or days or weeks) of ddrescue, and sometimes you just have a disk image from a virtual machine where you want to mount the partitions inside the image. There are three main methods of doing this, which are more or less synonmous, but some easier than the other.&lt;br /&gt;
&lt;br /&gt;
== Basics ==&lt;br /&gt;
&lt;br /&gt;
A disk image is usually like a disk, consisting of either a large filesystem, a PV or a partition table with one or partitions onto which resides a filesystem, a pv, swap or something else. If it&#039;s partitioned, and you want your operating system to mount a filesystem or allow it to see whatever LVM stuff lies on it, you need to isolate the partitions. &lt;br /&gt;
&lt;br /&gt;
== Manual mapping ==&lt;br /&gt;
&lt;br /&gt;
In the oldern days, this was done manually, something like this&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
root@mymachine:~# fdisk -l /dev/vda&lt;br /&gt;
Disk /dev/vda: 25 GiB, 26843545600 bytes, 52428800 sectors&lt;br /&gt;
Units: sectors of 1 * 512 = 512 bytes&lt;br /&gt;
Sector size (logical/physical): 512 bytes / 512 bytes&lt;br /&gt;
I/O size (minimum/optimal): 512 bytes / 512 bytes&lt;br /&gt;
Disklabel type: dos&lt;br /&gt;
Disk identifier: 0xc37b7ea5&lt;br /&gt;
&lt;br /&gt;
Device     Boot    Start      End  Sectors  Size Id Type&lt;br /&gt;
/dev/vda1  *        2048 50333311 50331264   24G 83 Linux&lt;br /&gt;
/dev/vda2       50333312 52426369  2093058 1022M  5 Extended&lt;br /&gt;
/dev/vda5       50333314 52426369  2093056 1022M 82 Linux swap / Solaris&lt;br /&gt;
root@mymachine:~#&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To calculate the start and end of each partition, you just take the start sector and multiply it by the sector size (512 bytes here) and you have the offset in bytes. After this, it&#039;s merely an losetup -o &amp;lt;offset&amp;gt; /dev/loopX &amp;lt;nameofimagefile&amp;gt; and you have the partition mapped to your /dev/loopX (having X being something typically 0-255. After this, just mount it or run pvscan/vgscan/lvscan to probe whatever lvm config is there, and you should be able to mount it like any other filesystem.&lt;br /&gt;
&lt;br /&gt;
== kpartx ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;kpartx&#039;&#039;&#039; does the same as above, more or less, just without so much hassle. Most of it should be automatic and easy to deal with, except it may fail to disconnect the loopback devices sometimes, so you may have to &#039;&#039;&#039;losetup -d&#039;&#039;&#039; them manually. See the manual, &#039;&#039;&#039;kpartx (8)&#039;&#039;&#039;. Please note that &#039;&#039;&#039;partx&#039;&#039;&#039; works similarly and I&#039;d guess the authors of the two tools are arguing a lot of which one&#039;s the best.&lt;br /&gt;
&lt;br /&gt;
== guestmount ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;guestmount&#039;&#039;&#039; is something similar again, but also supports file formats like &#039;&#039;&#039;qcow2&#039;&#039;&#039; and possibly other, proprietary filesystems like &#039;&#039;&#039;vmdk&#039;&#039;&#039; and &#039;&#039;&#039;vdi&#039;&#039;&#039;, but don&#039;t take my word for it - I haven&#039;t tested. Again, see the manual or just read up on the description [http://ask.xmodulo.com/mount-qcow2-disk-image-linux.html?fbclid=IwAR3snTeZvGzp9PLdX11EQhCfOpux6I93CiJ3A2pUomkkRLly9Xo4851mkTY here]. It seems rather trivial.&lt;br /&gt;
&lt;br /&gt;
= Linux on laptops =&lt;br /&gt;
&lt;br /&gt;
== Wifi with HP EliteBook 725/745 on Ubuntu ==&lt;br /&gt;
&lt;br /&gt;
The HP EliteBook 725/745 and similar are equipped with a BCM4352 wifi chip. As with a lot of other stuff from Broadcom, this lacks an open hardware description, so thus no open driver exist. The proper fix, is to replace the NIC with something with an open driver, but again, this isn&#039;t always possible, so a binary driver exists. In ubuntu, run, somehow connect the machine to the internet and run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install bcmwl-kernel-source&lt;br /&gt;
sudo modprobe wl&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you can&#039;t connect the machine to the internet, download the needed packages on another machine and put it on some usb storage. These packages should suffice:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# apt-cache depends bcmwl-kernel-source&lt;br /&gt;
bcmwl-kernel-source&lt;br /&gt;
  Depends: dkms&lt;br /&gt;
  Depends: linux-libc-dev&lt;br /&gt;
  Depends: libc6-dev&lt;br /&gt;
  Conflicts: &amp;lt;bcmwl-modaliases&amp;gt;&lt;br /&gt;
  Replaces: &amp;lt;bcmwl-modaliases&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then install manually with &#039;&#039;&#039;dpkg -i file1.deb file2.deb&#039;&#039;&#039; etc&lt;br /&gt;
&lt;br /&gt;
After this, ip/ifconfig/iwconfig shouldd see the new wifi nic, probably &#039;&#039;&#039;wlan0&#039;&#039;&#039;, but due to a [https://bugs.launchpad.net/ubuntu/+source/broadcom-sta/+bug/1343151 old, ignored bug], you won&#039;t find any wifi networks. This is because the driver from Broadcom apparently does not support interrupt remapping, commonly used on x64 machines. To turn this off, change &#039;&#039;&#039;/etc/default/grub&#039;&#039;&#039; and change the line &#039;&#039;&#039;GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;quiet splash&amp;quot;&#039;&#039;&#039;, adding intremap=off to the end before the quote: &#039;&#039;&#039;GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;quiet splash intremap=off&amp;quot;&#039;&#039;&#039;. Save the file and run &#039;&#039;&#039;sudo update-grub&#039;&#039;&#039; and reboot. After this, wifi should work well.&lt;br /&gt;
&lt;br /&gt;
== Wifi with HP Compaq Presario CQ57 on Ubuntu ==&lt;br /&gt;
&lt;br /&gt;
The HP Compaq Presario CQ57 uses the RT5390 wifi chipset. This has been supported for quite some time now, and I was quite surprised to find it not working on a laptop a friend was having. The driver loaded correctly, but Ubuntu insisted of the laptop being in &#039;&#039;&#039;flight mode&#039;&#039;&#039;. Checking &#039;&#039;&#039;rfkill&#039;&#039;&#039;, it showed me two NICs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# rfkill list all&lt;br /&gt;
0: phy0: Wireless LAN&lt;br /&gt;
	Soft blocked: no&lt;br /&gt;
	Hard blocked: yes&lt;br /&gt;
1: hp-wifi: Wireless LAN&lt;br /&gt;
	Soft blocked: yes&lt;br /&gt;
	Hard blocked: no&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Turning rfkill on and off resulted in nothing much, except some error messages in the kernel log (dmesg)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] ACPI Error: Field [B128] at bit offset/length 128/1024 exceeds size of target Buffer (160 bits) (20170831/dsopcode-235)&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]&lt;br /&gt;
                            Initialized Local Variables for Method [HWCD]:&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Local0: 00000000a34b7928 &amp;lt;Obj&amp;gt;           Integer 0000000000000000&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Local1: 00000000b0aa6865 &amp;lt;Obj&amp;gt;           Buffer(8) 46 41 49 4C 04 00 00 00&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Local5: 00000000a9811efd &amp;lt;Obj&amp;gt;           Integer 0000000000000004&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] Initialized Arguments for Method [HWCD]:  (2 arguments defined for method invocation)&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Arg0:   0000000078957d1b &amp;lt;Obj&amp;gt;           Integer 0000000000000001&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Arg1:   00000000725c9c6e &amp;lt;Obj&amp;gt;           Buffer(20) 53 45 43 55 02 00 00 00&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] ACPI Error: Method parse/execution failed \_SB.WMID.HWCD, AE_AML_BUFFER_LIMIT (20170831/psparse-550)&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] ACPI Error: Method parse/execution failed \_SB.WMID.WMAD, AE_AML_BUFFER_LIMIT (20170831/psparse-550)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After upgrading BIOS and testing different kernels, I was asked to try to unload the &#039;&#039;&#039;hp_wmi&#039;&#039;&#039; driver. I did, and things changed a bit, so I tried blacklisting it, creating the file &#039;&#039;&#039;/etc/modprobe.d/blacklist-hp_wmi.conf&#039;&#039;&#039; with the following content&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Blacklist this - it doesn&#039;t work!&lt;br /&gt;
blacklist hp_wmi&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
I gave the machine a reboot and afte that, the &#039;&#039;&#039;hp-wifi&#039;&#039;&#039; entry was gone in the rfkill output, and things works.&lt;br /&gt;
&lt;br /&gt;
= Raspberry pi =&lt;br /&gt;
&lt;br /&gt;
I couldn&#039;t quite decide if the raspberry pi should be a separate section or part of Linux, but hell, it can run more than Linux, although 99,lots% of people just uses Linux on them. This is a small list of things to know about them; things not on the front page of the manual or perhaps hidden even better.&lt;br /&gt;
&lt;br /&gt;
== Which pi? ==&lt;br /&gt;
&lt;br /&gt;
I just setup three raspberry pi machines and although some are quite different, like v1 to vEverythingelse or the Pi zero versions to the normal ones, not all of us remember how to distinguish between them, and sometimes they&#039;re in a nice 3d printed (or otherwise) chassis or otherwise hidden. So, how to check three different ones:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
root@home-assistant:~ $ cat /proc/device-tree/model ; echo&lt;br /&gt;
Raspberry Pi 2 Model B Rev 1.1&lt;br /&gt;
&lt;br /&gt;
root@green-pi:~ $ cat /proc/device-tree/model ; echo&lt;br /&gt;
Raspberry Pi 3 Model B Rev 1.2&lt;br /&gt;
&lt;br /&gt;
roy@yellow-pi:~ $cat /proc/device-tree/model ; echo&lt;br /&gt;
Raspberry Pi 4 Model B Rev 1.1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
While this works well, for the latter, the pi4, it doesn&#039;t tell how much memory I have. It comes in variants of 1, 2 and 4GB, and this is the latter.&lt;br /&gt;
&lt;br /&gt;
== Monitoring ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;vcgencmd&#039;&#039;&#039; from &#039;&#039;&#039;/opt/vc/bin&#039;&#039;&#039;, but symlinked to &#039;&#039;&#039;/usr/bin&#039;&#039;&#039; so it&#039;s available in path, is useful for fetching hardware info about the pi. For example, measuring the temperature&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
root@yellow-pi:~# vcgencmd measure_temp&lt;br /&gt;
temp=63.0&#039;C&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The command is generally badly documented and parts of it seems outdated for newer hardware. Here&#039;s the output from a Raspberry pi 4 with 4GB RAM&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
roy@yellow-pi:~ $ vcgencmd get_mem arm&lt;br /&gt;
arm=948M&lt;br /&gt;
roy@yellow-pi:~ $ vcgencmd get_mem gpu&lt;br /&gt;
gpu=76M&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== BIOS upgrade from Linux ==&lt;br /&gt;
&lt;br /&gt;
Generally, BIOS upgrades have been moved to the BIOS itself these days. This saves a lot of work and quite possibly lives after those who earier rammed their heads through walls, now can upgrade directly from the internet instead of using obscure operating systems best avoided. Sometimes, however, one must use these nevertheless. This is a quick run-through on your options.&lt;br /&gt;
&lt;br /&gt;
=== DOS ===&lt;br /&gt;
&lt;br /&gt;
Most non-automatic BIOS upgrades are installed from DOS. Doing a BIOS upgrade this way, is generally non-problematic. Just install a USB thingie with [https://www.freedos.org/ FreeDOS], copy your file(s) onto the thing and boot on it. The commandline is the same as old MS/DOS, except a wee bit more userfriendly, but not a lot.&lt;br /&gt;
&lt;br /&gt;
=== Windows ===&lt;br /&gt;
&lt;br /&gt;
Some macahines, like laptops from &#039;&#039;&#039;HP&#039;&#039;&#039;, may have BIOS upgrades that are made to be installed from Windows and won&#039;t run in FreeDOS or MS/DOS, instead throwing an error, saying &#039;&#039;&#039;This program cannot be run in DOS mode&#039;&#039;&#039;. This means you&#039;ll have to boot on a Windows rescue disc and do the job from there. Googling this, tells you it&#039;s quite easy, you just choose &#039;make rescue disc&#039; from Windows, and it&#039;s all good, except if you don&#039;t run Windows, that is. To remedy this problem, do as follows:&lt;br /&gt;
&lt;br /&gt;
==== Download Windows ====&lt;br /&gt;
&lt;br /&gt;
Since you don&#039;t run Windows and possibly don&#039;t have a spouse or friend around with such unhealthy habits either, you need to get it. It&#039;s quite easy - just google &#039;download windows&#039; and it&#039;ll send you to [https://www.microsoft.com/en-us/software-download/windows10ISO somewhere like this].&lt;br /&gt;
&lt;br /&gt;
==== Burn it! ====&lt;br /&gt;
&lt;br /&gt;
Now it&#039;s time to burn the installer on a DVD ROM. You&#039;ll need a double-layered one, since the OS is &amp;gt; 4.7GiB, but I&#039;m sure you have a ton of those lying around. Now, just place your optical medium in your optical drive and burn, baby, burn!&lt;br /&gt;
&lt;br /&gt;
==== Or make a USB thing? ====&lt;br /&gt;
&lt;br /&gt;
Not a lot of machines have optical drives these days, so you may want to use an USB pen drive or something instead. This is easy, just make the USB bootable with the Windows application Microsoft has made for this. Unfortunately, this only runs on Windows, and unlike stuff like Debian, where the &#039;&#039;&#039;iso&#039;&#039;&#039; file can be dd&#039;ed directly onto a USB drive to make it bootable, the Windows &#039;&#039;&#039;iso&#039;&#039;&#039;s don&#039;t come with this luxury. There are lots of methods to make bootable USB things from iso files out there, but the only thing most of them have in common, is that they generally don&#039;t work.&lt;br /&gt;
&lt;br /&gt;
===== WoeUSB =====&lt;br /&gt;
&lt;br /&gt;
After hours of swearing, it&#039;s nice to come across software like [https://github.com/slacka/WoeUSB WoeUSB]. It may not be perfect, it relies on a bunch of GUI stuff you&#039;ll never need and so on, but it &#039;&#039;&#039;&#039;&#039;works&#039;&#039;&#039;&#039;&#039;, and that&#039;s the important part! Just clone the repo and RTFM and it&#039;s all nice. It&#039;s slow, but hell, getting a windows machine and/or an optical drive might be slower.&lt;br /&gt;
&lt;br /&gt;
WoeUSB does nothing fancy, but it &#039;&#039;&#039;does&#039;&#039;&#039; work. It will create a filesystem, FAT32 or NTFS (better use NTFS, FAT32 has its limits). It creates normal filesystems and so on. Just make sure to copy in the BIOS update file, usually an exe file, to run when Windows is up and running.&lt;br /&gt;
&lt;br /&gt;
===== Install BIOS =====&lt;br /&gt;
&lt;br /&gt;
Boot on the Windows USB thing and choose &#039;repair computer&#039; and then &#039;command prompt&#039;. Find the install file, and if you&#039;re lucky, you&#039;ll find it needs a 32bit OS, just like I did. Since the 64bit version doesn&#039;t include 32bit compatibility in the installer, revert to downloading the 32bit version of windows and start over. Pray to your favourite god(s) not to get across such machines again - it might help.&lt;br /&gt;
&lt;br /&gt;
= 3D printer stuff =&lt;br /&gt;
&lt;br /&gt;
== Hydrophilic filament ==&lt;br /&gt;
&lt;br /&gt;
Most popular filament types, including PLA, PETG, PP or PA (Polyamide, normally known as Nylon) and virtualy any filament type named [https://www.matterhackers.com/news/filament-and-water poly-something] (and thus with an acronym of P-something) are hydrophilic (also (somewhat incorrectly) called hydroscopic), meaning so long they&#039;re dryer than the atmosphere around them, they&#039;ll do their best to suck out the atmosphere&#039;s humidity. This is why most filament are shrink-wrapped with a small bag of silica gel in it. If such filament is exposed for normal humid air for some time, it&#039;ll become very hard to use. Most of my experience is with PLA, which can handle a bit (depending on make), but still not a lot. With PLA, if you end up with prints where the filament seems not to stick, it may help with a higher temperature. Otherwise, the filament must be [https://all3dp.com/2/how-to-dry-filament-pla-abs-and-nylon/ baked]. If you don&#039;t want to use your oven, try something like a [https://www.jula.no/catalog/hjem-og-husholdning/kjokkenmaskiner/mattilberedningsapparater/frukt-sopptorker/frukt-sopptorker-001641/#tab02 fruit and mushroom dryer]. Then get a good, sealble plastic box and add something like half a kilogram of [https://www.ebay.com/sch/sis.html?_nkw=1KG+Orange+Replacement+Desiccant+Indicating+Silica+Gel+Beads+for+Drawers%2C+Camera&amp;amp;_id=131938742628&amp;amp;&amp;amp;_trksid=p2057872.m2749.l2658 silica gel] to an old sock, tie it and put it in the your new dry box.&lt;br /&gt;
&lt;br /&gt;
Please note that ABS is hydrophobic, so you won&#039;t have to worry too much there. Also, remember that PA/Nylon is extremely hydrophilic. Even a couple of days in normal air humidity can ruin it completely and will require baking.&lt;br /&gt;
&lt;br /&gt;
== Upgrading the firmware on an Ender 3 ==&lt;br /&gt;
&lt;br /&gt;
This is about upgrading the firmware, and thus also flashing a bootloader to the Creality Ender 3 3D printer. Most of this is well documented on several place, like o [https://www.youtube.com/watch?v=fIl5X2ffdyo the video from Teaching tech] and elsewhere, but I&#039;ll just summarise some issues I had.&lt;br /&gt;
&lt;br /&gt;
=== Using an arduino Nano as a programmer ===&lt;br /&gt;
&lt;br /&gt;
The CR-10, Ender 3 and a few other printers from Creality come without a bootloader, so you&#039;ll need to flash one before upgrading the firmware. Well, strictly speakning, you don&#039;t need one, you can save those 8kB or so for other stuff and use a programmer to write the whole firmware, but then you&#039;ll need to wire up everything every time you want a new firmware, so in my world, you &#039;&#039;&#039;do&#039;&#039;&#039; need the bootloader, since it&#039;s easier. Note that some newer printers, like the CR-10S and possibly all newer ones, come with the bootloader already and thus won&#039;t need another.&lt;br /&gt;
&lt;br /&gt;
To install a bootloader, you&#039;ll need a programmer, and I didn&#039;t have one available. Having some el-cheapo china-copies of Ardinos around, I read I could use one and tried so. Although the docs mostly mention the Uno etc, it&#039;s just as simple with the Nano copy.&lt;br /&gt;
&lt;br /&gt;
So, grab an arduino, plug it to your machine with an USB cable, and, using the Arduino IDE, use the ArduinoISP sketch there (found under Examples) to burn the software needed for the arduino to work as a programmer. When this is done, connect a 10µF capacitor between RST and GND to stop it from resetting when used as a programmer. Connect the MOSI, MISO and SCK pins from the ICSP block (that little isolated 6-pin block on top of the ardu). See [https://www.arduino.cc/en/Tutorial/ArduinoISP here] for a pinout. Then find Vcc and GND either onthe ICSP block or elsewhere. Some sites say that on some boards you shouldn&#039;t use the pins on the ICSP block for this. I doubt it matters, though. Then connect another jumper wire from pin 10 on the ardu to work as the reset pin outwards to the chip being programmed (that is, on the printer). The ICSP jumper block pin layout is the same on the printer and on the ardu, and probably elsewhere. Sometimes [https://xkcd.com/927/ standardisation] actually works…&lt;br /&gt;
&lt;br /&gt;
See https://cloud.karlsbakk.net/index.php/s/zw48YJjzaf8Rc2F for a pic with the ardu (this wiki is broken atm, will fix it later)&lt;br /&gt;
&lt;br /&gt;
== Flashing the printer ==&lt;br /&gt;
&lt;br /&gt;
When the boot loader is in place, possibly after some wierd errors from during the process, the screen on the 3d printer will go blank and it&#039;ll behave like being bricked. This is ok. Now disconnect the wires and connect the USB cable between computer and printer, download the [https://www.th3dstudio.com/knowledgebase/th3d-unified-firmware-package/ TH3D unified firmware] and configure it for your particular needs. The video mentioned above describes this well. After flashing the new firmware, you&#039;ll probably get some timeouts and errors, since apparently it resets the printer after giving it the new firmware, but without notifying the flashing software of it doing so. If this happens, hold your breath and reboot the printer and check its tiny monitor - it should work. If it doesn&#039;t work, try to flash it again, and if that doesn&#039;t work, try flashing the programmer again yet another time, just for kicks.&lt;br /&gt;
&lt;br /&gt;
PS: I tried enabling &#039;&#039;&#039;MANUAL_MESH_LEVELING&#039;&#039;&#039;, which in the code says that &#039;&#039;If used with a 1284P board the bootscreen will be disabled to save space&#039;&#039;. This effectively disabled the whole thing, and apparently may be making the firmware image a wee bit too large for it to fit the 1284P on the ender. It works well without it, though.&lt;br /&gt;
&lt;br /&gt;
== And then… ==&lt;br /&gt;
&lt;br /&gt;
With the new firmware in place, the printer should work as before, although with thermal runaway protection to better avoid fires in case the shit hits the fan, and to allow for things like autolevelling. With any luck, [https://www.precisionpiezo.co.uk/ this thing] may be ready for use by the time you read this - it surely looks nice!&lt;br /&gt;
&lt;br /&gt;
roy&lt;/div&gt;</summary>
		<author><name>Roy</name></author>
	</entry>
	<entry>
		<id>https://wiki.malinux.no/index.php?title=Roy%27s_notes&amp;diff=154</id>
		<title>Roy&#039;s notes</title>
		<link rel="alternate" type="text/html" href="https://wiki.malinux.no/index.php?title=Roy%27s_notes&amp;diff=154"/>
		<updated>2020-03-22T16:00:16Z</updated>

		<summary type="html">&lt;p&gt;Roy: /* mdadm stuff */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= LVM, md and friends =&lt;br /&gt;
&lt;br /&gt;
== Linux&#039; Logical Volume Manager (LVM) ==&lt;br /&gt;
&lt;br /&gt;
=== LVM in general ===&lt;br /&gt;
&lt;br /&gt;
LVM is designed to be an abstraction layer on top of physical drives or RAID, typically [https://raid.wiki.kernel.org/index.php/RAID_setup mdraid] or [https://help.ubuntu.com/community/FakeRaidHowto fakeraid]. Keep in mind that fakeraid should be avoided unless you really need it, like in conjunction with dual-booting linux and windows on fakeraid. LVM broadly consists of three elements, the &amp;quot;physical&amp;quot; devices (PV), the volume group (VG) and the logical volume (LV). There can be multiple PVs, VGs and LVs, depending on requirement. More about this below. All commands are given as examples, and all of them can be fine-tuned using extra flags in need of so. In my experience, the defaults work well for most usecases.&lt;br /&gt;
&lt;br /&gt;
I&#039;m mentioning filesystem below too. Where I write ext4, the samme applies to ext2 and ext3.&lt;br /&gt;
&lt;br /&gt;
==== Create a PV ====&lt;br /&gt;
&lt;br /&gt;
A PV is the &amp;quot;physical&amp;quot; parts. This does not need to be a physical disk, but can also be another RAID, be it an mdraid, fakeraid, hardware raid, a virtual disk on a SAN or otherwisee or a partition on one of those. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#  These add three PVs, one on a drive (or hardware raid) and another two on mdraids.&lt;br /&gt;
pvcreate /dev/sdb&lt;br /&gt;
pvcreate /dev/md1 /dev/md2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For more information about pvcreate, see [https://linux.die.net/man/8/pvcreate the manual].&lt;br /&gt;
&lt;br /&gt;
==== Create a VG ====&lt;br /&gt;
&lt;br /&gt;
The volume group consists of one or more PVs grouped together on which LVs can be placed. If several PVs are grouped in a VG, it&#039;s generally a good idea to make sure these PVs have some sort of redundancy, as in mdraid/fakeraid or hwraid. Otherwise it will be like using a [https://en.wikipedia.org/wiki/RAID RAID-0] with a single point of failure on each of the independant drives. LVM has [https://unix.stackexchange.com/questions/150644/raiding-with-lvm-vs-mdraid-pros-and-cons  RAID code in it] as well, so you can use that. I haven&#039;t done so myself, as I generally stick to mraid. The reason is mdraid is, in my opinion older and more stable and has more users (meaning bugs are reported and fixed faster whenever they are found). That said, I beleive the actual RAID code used in LVM RAID are the same function calls as for mdraid, so it may not be much of a difference. I still stick with mdraid. To create a VG, run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create volume group my_vg&lt;br /&gt;
vgcreate my_vg /dev/md1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that if vgcreate is run with a PV (as /dev/md1 above) that is not defined as a PV (like above), this is done implicitly, so if you don&#039;t need any special flags to pvcreate, you can simply skip it and let vgcreate do that for you.&lt;br /&gt;
&lt;br /&gt;
==== Create an LV ====&lt;br /&gt;
&lt;br /&gt;
LVs can be compared to partitions, somehow, since they are bounderies of a fraction or all of that of a VG. The difference between them and a partition, however, is that they can be grown or shrunk easily and also moved around between PVs without downtime. This flexibility makes them superiour to partitions as your system can be changed without users noticing it. By default, an LV is alloated &amp;quot;thickly&amp;quot;, meaning all the data given to it, is allocated from the VG and thus the PV. The following makes a 100GB LV named &amp;quot;thicklv&amp;quot;. When making an LV, I usually allocate what&#039;s needed plus some more, but not everything, just to make sure it&#039;s space available for growth on any of the LVs on the VG, or new LVs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a thick provisioned LV named thicklv on the VG my_vg&lt;br /&gt;
lvcreate -n thicklv -L 100G my_vg&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After the LV is created, a filesystem can be placed on it unless it is meant to be used directly. The application for direct use include swap space, VM storage and certain database systems. Most of these will, however, work on filesystems too, although my testing has shown that on swap space, there is a significant performance gain for using dedicated storage without a filesystem. As for filesystems, most Linux users use either ext4 or xfs. Personally, I generally use XFS these days. See my notes below on filesystem choice.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a filesystem on the LV - this could have been mkfs -t ext4 or whatever filesystem you choose&lt;br /&gt;
mkfs -t xfs /dev/my_vg/thicklv&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then just edit /etc/fstab with correct data and run mount -a, and you should be all set.&lt;br /&gt;
&lt;br /&gt;
==== Create LVM cache ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
lvcreate -L 1G -n _cache_meta data /dev/md1&lt;br /&gt;
&lt;br /&gt;
lvcreate -l100%FREE -n _cache data /dev/md1&lt;br /&gt;
&lt;br /&gt;
# Some would want --cachemode writeback, but seriously, I wouldn&#039;t recommend it. Metadata or data can be easily corrupted in case of failure.&lt;br /&gt;
lvconvert --type cache-pool --cachemode writethrough --poolmetadata data/_cache_meta data/_cache&lt;br /&gt;
&lt;br /&gt;
lvconvert --type cache --cachepool data/_cache data/data&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Disabling LVM cache ====&lt;br /&gt;
&lt;br /&gt;
If you for some reason want to disable caching, this will do it cleanly and remove the LVs earlier created for caching the main device.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
lvconvert --uncache data/data&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Growing devices ====&lt;br /&gt;
&lt;br /&gt;
LVM objects can be grown and shrunk. If a PV resides on a RAID where a new drive has been added or otherwise grown, or on a partition or virtual disk that has been extended, the PV must be updated to reflect these changes. The following command will grow the PV to the maximum available on the underlying storage. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Resize the PV /dev/md (not the RAID, only the PV on the RAID) to its full size&lt;br /&gt;
pvresize /dev/md1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If a new PV is added, the VG can be grown to add the space on that in addition to what&#039;s there already. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Extend my_vg to include md2 and its space&lt;br /&gt;
vgextend my_vg /dev/md2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
With more space available in the VG, the LV can now be extended. Let&#039;s add another 50GB to it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Extend thicklv - add 50GB. If you know you won&#039;t need the space anywhere else, you may want to&lt;br /&gt;
# lvresize -l+100%FREE instead. Keep in mind the difference between -l (extents) and -L (bytes)&lt;br /&gt;
lvresize -L +50G my_vg/thicklv&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Growing filesystems ====&lt;br /&gt;
After the LV has grown, run &#039;&#039;xfs_growfs&#039;&#039; (xfs) or &#039;&#039;resize2fs&#039;&#039; (ext4) to make use of the new data. To grow the filesystem to all available space on ext4, run the below command.  To partly grow the filesystem or to shrink it or otherwise, please see the manuals.&lt;br /&gt;
&lt;br /&gt;
The filesystem can be mounted when this is run. If you for some reason get an &#039;&#039;&#039;access denied&#039;&#039;&#039; error when running this as root or with sudo, it&#039;s likely caused by a filesystem error. To fix this, unmount the filesystem first and run &#039;&#039;&#039;fsck -f /dev/my_vg/thicklv&#039;&#039;&#039; and remount it before retrying to extend it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
resize2fs /dev/my_vg/thicklv&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Similarly, with XFS, but note that xfs_growfs doesn&#039;t take the device name, but the filesystem&#039;s mount point. In the case of XFS, also note that the filesystem &#039;&#039;&#039;&#039;&#039;must&#039;&#039;&#039;&#039;&#039; be mounted to be grown. This, in contrast to how it was in the old days when filesystems had to be unmounted to be grown.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
xfs_growfs /my_mountpoint&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Rename system VG ====&lt;br /&gt;
&lt;br /&gt;
Some distros create VG names like those-from-a-sysadmin-with-a-well-developed-paranoia-not-to-hit-a-duplicate. Debian, for instance, uses names like &amp;quot;my-full-hostname-vg&amp;quot;. Personally, I don&#039;t like these, since if I were to move a disk or vdisk around to somewhere else, I&#039;d make sure not to add a disk named &#039;sys&#039; to an existing system. If you do, most distros will refuse to use the VGs with duplicate names, resulting in the OS not booting until either one is specified by its UUID or just one removed. As I&#039;m aware of this, I stick to the super-risky thing of all system VGs named &#039;sys&#039; and so on.&lt;br /&gt;
&lt;br /&gt;
If you do this, keep in mind that it may blow up your computer and take your girl- or boyfriend with it or even make either of them pregnant, allowing Trump to rule your life and generally make things suck. You&#039;re on your own!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Rename the VG&lt;br /&gt;
vgrename my-full-hostname-vg sys&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, in /boot/grub/grub.cfg, change the old lv path from something like &#039;/dev/mapper/debian--stretch--machine--vg-root&#039; to your new and fancy &#039;/dev/sys/root. Likewise, in /etc/fstab, change occurences of &#039;/dev/mapper/debian--stretch--machine--vg-&#039; (or similar) with &#039;/dev/sys/&#039;. Here, this was like this - the old ones commented out.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;fstab&amp;quot;&amp;gt;&lt;br /&gt;
#/dev/mapper/debian--stretch--box--vg-root      /               ext4            errors=remount-ro,discard       0       1&lt;br /&gt;
/dev/sys/root                                   /               ext4            errors=remount-ro,discard       0       1&lt;br /&gt;
# /boot was on /dev/vda1 during installation&lt;br /&gt;
UUID=myverylonguuidwithatonofgoodinfoinit       /boot           ext2            defaults                        0       2&lt;br /&gt;
#/dev/mapper/debian--stretch--box--vg-swap_1    none            swap            sw                              0       0&lt;br /&gt;
/dev/sys/swap_1                                 none            swap            sw                              0       0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Update /etc/initramfs-tools/conf.d/resume with similar data for swap.&lt;br /&gt;
&lt;br /&gt;
You might want to run &#039;update-initramfs -u -k all&#039; after this, but I&#039;m not sure if it&#039;s needed.&lt;br /&gt;
&lt;br /&gt;
Now, pray to the nearest god(s) and give it a reboot and it should (probably) work.&lt;br /&gt;
&lt;br /&gt;
After reboot, run &#039;&#039;&#039;swapoff -a&#039;&#039;&#039;, then &#039;&#039;&#039;mkswap /dev/sys/swap_1&#039;&#039;&#039; (or whatever it&#039;s called on your system) and &#039;&#039;&#039;swapon -a&#039;&#039;&#039; again. You may want to give it another reboot or two for kicks, but it should work well even without that.&lt;br /&gt;
&lt;br /&gt;
=== Migration tools ===&lt;br /&gt;
&lt;br /&gt;
At times, storage regimes change, new storage is added and sometimes it&#039;s not easy to migrate with the current hardware or its support systems. Once I had to migrate a 45TiB fileserver from one storage system to another, preferably without downtime. The server originally had three 15TiB PVs of which two were full and the third half full. I resorted to using [https://linux.die.net/man/8/pvmove pvmove] to just move the data on the PVs in use to a new PV. We started out with creating a new 50TiB PV, sde, and then to pvmove.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Attach /dev/sde to the VG my_vg&lt;br /&gt;
vgextend my_vg /dev/sde&lt;br /&gt;
&lt;br /&gt;
# Move the contents from /dev/sdb over to /dev/sde block by block. If a target is not given in pvmove,&lt;br /&gt;
# the contents of the source (sdb here) will be put somewhere else in the pool.&lt;br /&gt;
pvmove /dev/sdb /dev/sde&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This took a while (as in a week or so) - the pvmove command uses old code and logic (or at least did that when I migrated this in November 2016), but it affected performance on the server very little, so users didn&#039;t notice. After the first PV was migrated, I continued with the other two, one after the other, and after a month or so, it was migrated. We used this on a number of large fileservers, and it worked flawlessly. Before doing the production servers I also tried interrupting pvmove in various ways, including hard resets, and it just kept on after the reboot.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;NOTE:&#039;&#039;&#039;&#039;&#039; &#039;&#039;Even though it worked well for us, &#039;&#039;&#039;always&#039;&#039;&#039; keep a good backup before doing this. Things may go wrong, and without a good backup, you may be looking for a hard-to-find new job the next morning&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
==== mdadm workarounds ====&lt;br /&gt;
&lt;br /&gt;
===== Migrate from a mirror (raid-1) to raid-10 =====&lt;br /&gt;
&lt;br /&gt;
Create a mirror&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sdb /dev/sdc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
LVM (pv/vg/lv) on md0 (see above), put a filesystem on the lv and fill it with some data.&lt;br /&gt;
&lt;br /&gt;
Now, some months later, you want to change this to raid-10 to allow for the same amount of redundancy, but to allow more disks into the system.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mdadm --grow /dev/md0 --level=10&lt;br /&gt;
mdadm: Impossibly level change request for RAID1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So - no - doesn&#039;t work. But - we&#039;re on &lt;br /&gt;
&lt;br /&gt;
Since we&#039;re on lvm already, this&#039;ll be easy. If you&#039;re using filesystems directly on partitions, you can do this the same way, but without the pvmove part, using rsync or whateever you like instead. I&#039;d recommend using lvm for for the new raid, which should be rather obvious from this article. Now plug in a new drive and create a new raid10 on that one. If you two new drives, install both. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# change &amp;quot;missing&amp;quot; to the other device name if you installed two new drives&lt;br /&gt;
mdadm --create /dev/md1 --level=10 --raid-devices=2 /dev/vdd missing&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, as described above, just vgextend the vg, adding the new raid and run pvmove to move the data from the old pv (residing on the old raid1) to the new pv (on raid10). Afte rpvmove is finished (which may take awile, see above), just&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
vgreduce raidtest /dev/md0&lt;br /&gt;
pvremove /dev/md0&lt;br /&gt;
mdadm --stop /dev/md0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
…and your disk is free to be added to the new array. If the new raid is running in degraded mode (if you created it with just one drive), better don&#039;t wait too long, since you don&#039;t have redundancy. Just mdadm --add the devs.&lt;br /&gt;
&lt;br /&gt;
If you now have /dev/mdstat telling you your raid10 is active and have three drives, of which one is a spare, it should look something like this&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5] [raid4] [raid10]&lt;br /&gt;
md1 : active raid10 vdc[3](S) vdb[2] vdd[0]&lt;br /&gt;
      8380416 blocks super 1.2 2 near-copies [2/2] [UU]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Just mdadm --grow --raid-devices=3 /dev/md1&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;RAID section is not complete. I&#039;ll write more on migraing from raid10 to raid6 later. It&#039;s not straight forward, but easier than this one :)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== Thin provisioned LVs ===&lt;br /&gt;
&lt;br /&gt;
Thin provisioning on LVM is a method used for not allocating all the space given to an LV. For instance, if you have a 1TB VG and want to give an LV 500GB, although it currently only uses a fraction of that, a thin lv can be a good alternative. This will allow for adding a limit to how much it can use, but also to let it grow dynamically without manual work by the sysadmin. Thin provisioning adds another layer of abstaction by creating a special LV as a &#039;&#039;thin pool&#039;&#039; from which data is allocated to the &#039;&#039;thin volume(s)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== Create a thin pool ====&lt;br /&gt;
&lt;br /&gt;
Allocate 1TB to the thin pool to be used for thinly provisioned LVs. Keep in mind that the space allocated to the thin pool is in fact thick provisioned. Only the volumes put on &#039;&#039;thinpool&#039;&#039; are thin provisioned. This will create two hidden LVs, one for data and one for metadata. Normally the defaults will do, but check the manual if the data doesn&#039;t match the usual patterns (such as billions of files, resulting in huge amounts of metadata). I &#039;&#039;beleive&#039;&#039; the metadata part should be resizable at a later time if needed, but I have not tested it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a pool for thin LVs. Keep in mind that the pool itself is not thin provisioned, only the volumes residing on it&lt;br /&gt;
lvcreate --size 1T --type thin-pool --thinpool thinpool my_vg&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Create a thin volume ====&lt;br /&gt;
&lt;br /&gt;
You have the thinpool, now put a thin volume on it. It will allocate some space for metadata, but probably not much (a few megs, perhaps).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Now, create a volume with a virtual (-V) size of half a terabyte named thin_pool, but using the thinpool (-T) named thin_pool for storage&lt;br /&gt;
lvcreate -V 500G -T my_vg/thin_pool --name thinvol&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The new volume&#039;s device name will be /dev/thinvol. Now, create a filesystem on it, add to fstab and mount it. The &#039;&#039;&#039;df&#039;&#039;&#039; command will return available space according to the virtual size (-V), while lvs will show how much data is actually used on each of the thinly provisioned volumes.&lt;br /&gt;
&lt;br /&gt;
== Filesystem dilemmas ==&lt;br /&gt;
&lt;br /&gt;
=== XFS or ext4 or something else ===&lt;br /&gt;
The choice of filesystem varies for your use. Distros such as RHEL/CentOS has moved to XFS by default from v7. Debian/Ubuntu still sticks to ext4, like most other. I&#039;ll discuss my thoughts below on ext4 vs XFS and leave the other filesystems for later.&lt;br /&gt;
&lt;br /&gt;
==== ext4 ====&lt;br /&gt;
ext4 is probably the most used filesystem on linux as of writing. It&#039;s rock stable and has been extended by a lot of extensions since the original ext2. It still retains backward compatibility, being able to mount and fsck ext2 and ext3 with the ext4 driver. However, it doesn&#039;t handle large filesystems very well. If a filesystem is created for &amp;lt;16TiB, it cannot be grown to anything larger than 16TiB. This may have changed lately, though. One other issue is handling errors. If a large filesystem (say 10TiB) is damaged, an fsck may take several hours, leading to long downtime. When I refer to ext4 further in this text, the same applies to ext2 and ext3 unless otherwise specified.&lt;br /&gt;
&lt;br /&gt;
==== XFS ====&lt;br /&gt;
XFS, originally developed by SGI some time in the bronze age, but has been worked on heavily after that. RHEL and Centos version 7 and forward, uses XFS as the default filesystem. It is quick, it scales well, but it lacks at least two things ext4 has. It cannot be shrunk (not that you normally need that, but nice if you have a typo or you need to change things). Also, it doesn&#039;t allow for automatic fsck on bootup. If something is messed up on the filesystem, you&#039;ll have to login as root on the console (not ssh), which might be an issue on some systems. The fsck equivalent, xfs_repair, is a *lot* faster than ext4&#039;s fsck, though.&lt;br /&gt;
&lt;br /&gt;
==== ZFS ====&lt;br /&gt;
ZFS is like a combination of RAID, LVM and a filesystem, supporting full checksumming, auto-healing (given sufficient redundancy), compression, encryption, replication, deduplication (if you&#039;re brave and have a &#039;&#039;ton&#039;&#039; of memory) and a lot more. It&#039;s a separate chapter and needs a lot more talk than paragraph here.&lt;br /&gt;
&lt;br /&gt;
== Low level disk handling ==&lt;br /&gt;
&lt;br /&gt;
This section is for low-level handling of disks, regardless of storage system elsewhere. These apply to mdraid, lvmraid and zfs and possibly other solutions, with the exception of individual drives on hwraid (and maybe fakeraid), since there, the drives are hidden from Linux (or whatever OS).&lt;br /&gt;
&lt;br /&gt;
=== S.M.A.R.T. and slow drives ===&lt;br /&gt;
Modern (that is, from about 1990 or later) have S.M.A.R.T. (or just smart, since it&#039;s easier to type) monitoring built in, meaning the disk&#039;s controller is monitoring itself. This is handy and will ideally tell you in advance that a drive is flakey or dying. Modern (2010+) smart monitoring is more or less the same. It can be trusted about 50% of the time. Usually, if smart detects an error, it&#039;s a real error. I don&#039;t think I&#039;ve seen it reporting a false positive, but others may know better. &lt;br /&gt;
&lt;br /&gt;
==== smartmontools ====&lt;br /&gt;
First, install smartmontool and run smartclt -H /dev/yourdisk (/dev/sda or something) to get a health report. Then perhaps run smartctl -a /dev/yourdisk and look for &#039;current pending sectors&#039; This should be zero. Also check the temperature, which normally should be much above 50.&lt;br /&gt;
&lt;br /&gt;
==== single, slow drive ====&lt;br /&gt;
What may happen, is smart not seeing anything and life goes on like before, only slower and less prouductive, without telling anyone. If you stubler over this issue, you&#039;ll probably see it during a large rsync/zfs send/receive or a resync/rebuild/resilver of the raid/zpool. During this, it feels like everything is slow and your RAID has turned into a RAIF (redundant array of inexpensive floppies). To check if you have a single drive messing up it all, check with &#039;&#039;&#039;iostat -x 2&#039;&#039;&#039;, having 2 being the delay between each measurement. Interrupt it with ctrl+x. If there&#039;s a rougue drive there, it should stand out like sdg below&lt;br /&gt;
&lt;br /&gt;
 avg-cpu:  %user   %nice %system %iowait  %steal   %idle&lt;br /&gt;
            0.38    0.00    1.75    0.00    0.00   97.87&lt;br /&gt;
&lt;br /&gt;
 Device            r/s     w/s     rkB/s     wkB/s   rrqm/s   wrqm/s  %rrqm  %wrqm r_await w_await aqu-sz rareq-sz wareq-sz  svctm  %util&lt;br /&gt;
 sda              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdb              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdc              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdd              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sde              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdf              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdg              3.50    0.00   2352.00      0.00     0.00     0.00   0.00   0.00 14306.29    0.00  13.85   672.00     0.00 285.71 100.00&lt;br /&gt;
 sdh              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
&lt;br /&gt;
In ZFS land, you should be able to get similar data with &#039;&#039;&#039;zpool iostat -v &amp;lt;pool&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Now you know the bad drive (sdg), pull it from the raid with &#039;&#039;&#039;mdadm --fail /dev/mdX /dev/sdX&#039;&#039;&#039;. Now test the drive&#039;s performance manually, just simply:&lt;br /&gt;
&lt;br /&gt;
 # hdparm -t /dev/sdg&lt;br /&gt;
 &lt;br /&gt;
 /dev/sdg:&lt;br /&gt;
  Timing buffered disk reads:   2 MB in  5.37 seconds = 381.46 kB/sec&lt;br /&gt;
&lt;br /&gt;
Bingo - nothing you&#039;d want to keep. For a good drive, it should be something like 100-200MB/s&lt;br /&gt;
&lt;br /&gt;
PS: Keep in mind that you have a degraded RAID by now in case you had a spare waiting for things to happen.&lt;br /&gt;
&lt;br /&gt;
Try to replace the cable and/or try the disk on another port/controller. If the result from hdparm persists, it&#039;s probably a bad cable&lt;br /&gt;
&lt;br /&gt;
So, then, just psycially locate the drive, pull it out, take out the discs and magnets and recycle the rest.&lt;br /&gt;
&lt;br /&gt;
=== &amp;quot;Unplug&amp;quot; drive from system ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Find the device unit&#039;s number with something like&lt;br /&gt;
find /sys/bus/scsi/devices/*/block/ -name sdd&lt;br /&gt;
# returning /sys/bus/scsi/devices/3:0:0:0/block/sdd here, &lt;br /&gt;
# meaning 3:0:0:0 is the SCSI device we&#039;re looking for.&lt;br /&gt;
&lt;br /&gt;
# Given this is the correct device, and you want to &#039;unplug&#039; it, do so by&lt;br /&gt;
echo 1 &amp;gt; /sys/bus/scsi/devices/3:0:0:0/delete&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Rescan disk controllers ===&lt;br /&gt;
If a drive is added and for some reason doesn&#039;t get detected, or is removed by the command above, it can be rediscovered with a sysfs command to the scsi host to which it is connected. Since there may be quite a few of these, an easy way is to just scan them all and check the output of &#039;&#039;&#039;dmesg -T&#039;&#039;&#039; after running it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Make a list of controllers and send a rescan message to each of them. It won&#039;t do anything &lt;br /&gt;
# for those where nothing has changed, but it will show new drives where they have been added.&lt;br /&gt;
for host_scan in /sys/class/scsi_host/host*/scan&lt;br /&gt;
do&lt;br /&gt;
  echo &#039;- - -&#039; &amp;gt; $host_scan&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Fail injection with debugfs ===&lt;br /&gt;
[https://lxadm.com/Using_fault_injection https://lxadm.com/Using_fault_injection]&lt;br /&gt;
&lt;br /&gt;
== mdadm stuff ==&lt;br /&gt;
=== Resync ===&lt;br /&gt;
To resync a raid, that is, check, run&lt;br /&gt;
&lt;br /&gt;
 echo check &amp;gt; /sys/block/$dev/md/sync_action&lt;br /&gt;
&lt;br /&gt;
where $dev is something like md0. If you have several raids, something like this should work&lt;br /&gt;
&lt;br /&gt;
 for dev in md{0,1}&lt;br /&gt;
 do&lt;br /&gt;
   echo repair &amp;gt; /sys/block/$dev/md/sync_action&lt;br /&gt;
 done&lt;br /&gt;
&lt;br /&gt;
Also useful in a one-liner like&lt;br /&gt;
&lt;br /&gt;
 for dev in md{0,1} ; do echo repair &amp;gt; /sys/block/$dev/md/sync_action ; done&lt;br /&gt;
&lt;br /&gt;
Different raids on different drives will do this in parallel. If the drives are shared somehow with partitions or similar, the check or repair will wait for the other to finish before going on.&lt;br /&gt;
&lt;br /&gt;
As for repair vs check, [https://raid.wiki.kernel.org/index.php/RAID_Administration this article] describes it well. I stick to using repair unless it&#039;s something rare where I don&#039;t want to touch the data.&lt;br /&gt;
&lt;br /&gt;
=== Spare pools ===&lt;br /&gt;
In the old itmes, mdadm supported only a dedicated spare per md device, so if working with a large set of drives (20? 40?), where you&#039;d want to setup more raid sets to increase redundancy, you&#039;d dedicate a spare to each of the raid sets. This has changed (some time ago?), so in these modern, heathen days, you can change mdadm.conf, usually placed under /etc/mdadm, and add &#039;spare-group=somegroup&#039; where &#039;somegroup&#039; is a string identifying the spare group. After doing this, run &#039;&#039;&#039;update-initramfs -u&#039;&#039;&#039; and reboot and add a spare to one of the raid sets in the spare group, and md will use that or those spares for all the raidsets in that group.&lt;br /&gt;
&lt;br /&gt;
As some pointed out on #linux-raid @ irc.freenode.net, this feature is very badly documented, but as far as I can see, it works well.&lt;br /&gt;
&lt;br /&gt;
==== Example config ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create two raidsets&lt;br /&gt;
&lt;br /&gt;
mdadm --create /dev/md1 --level=6 --raid-devices=6 /dev/vd[efghij]&lt;br /&gt;
mdadm --create /dev/md2 --level=6 --raid-devices=6 /dev/vd[klmnop]&lt;br /&gt;
&lt;br /&gt;
# get their UUID etc&lt;br /&gt;
&lt;br /&gt;
mdadm --detail --scan&lt;br /&gt;
ARRAY /dev/md/1 metadata=1.2 name=raidtest:1 UUID=1a8cbdcb:f4092350:348b6b80:c054d74c&lt;br /&gt;
ARRAY /dev/md/2 metadata=1.2 name=raidtest:2 UUID=894b1b7c:cb7eba70:917d6033:ea5afd2b&lt;br /&gt;
&lt;br /&gt;
# Put those lines into /etc/mdadm/mdadm.conf and and add the spare-group&lt;br /&gt;
&lt;br /&gt;
ARRAY /dev/md/1 metadata=1.2 name=raidtest:1 spare-group=raidtest UUID=1a8cbdcb:f4092350:348b6b80:c054d74c&lt;br /&gt;
ARRAY /dev/md/2 metadata=1.2 name=raidtest:2 spare-group=raidtest UUID=894b1b7c:cb7eba70:917d6033:ea5afd2b&lt;br /&gt;
&lt;br /&gt;
# update the initramfs and reboot&lt;br /&gt;
&lt;br /&gt;
update-initramfs -u&lt;br /&gt;
reboot&lt;br /&gt;
&lt;br /&gt;
# add a spare drive to one of the raids&lt;br /&gt;
&lt;br /&gt;
mdadm --add /dev/md1 /dev/vdq&lt;br /&gt;
&lt;br /&gt;
# fail a drive on the other raid&lt;br /&gt;
&lt;br /&gt;
mdadm --fail /dev/md2 /dev/vdn&lt;br /&gt;
&lt;br /&gt;
# check /proc/mdstat to see md2 rebuilding with the spare from md1&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Recovery ===&lt;br /&gt;
&lt;br /&gt;
The other day, I came across a problem a user had on #linux-raid@irc.freenode.net. He had an old Qnap NAS that had died and tried plugging the drives in to his Linux machine and got various errors. The two-drive RAID-1 did not come up as it should, &#039;&#039;&#039;dmesg&#039;&#039;&#039; was full of errors from one of the drives (both connected on USB) and so forth.&lt;br /&gt;
&lt;br /&gt;
We went on and started by taking down the machine and just connecting one of the drives. I had him check what was assembled with&lt;br /&gt;
&lt;br /&gt;
 cat /proc/mdstat&lt;br /&gt;
&lt;br /&gt;
That returned /proc/md127 assembled, but LVM didn&#039;t find anything. So running a manual scan&lt;br /&gt;
&lt;br /&gt;
 pvscan --cache /dev/md127&lt;br /&gt;
&lt;br /&gt;
This made linux find the PV, VG and a couple of LVs, but probably because the mdraid was degraded, the LVs were deactivated, according to &#039;&#039;&#039;lvscan&#039;&#039;&#039;. Activating the one with a filesystem manually&lt;br /&gt;
&lt;br /&gt;
 lvchange -a y /dev/&amp;lt;vg&amp;gt;/&amp;lt;lv&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Substitute &amp;lt;vg&amp;gt; and &amp;lt;lv&amp;gt; with the names listed by vgs and lvs.&lt;br /&gt;
&lt;br /&gt;
This worked, and the filesystem on /dev/&amp;lt;vg&amp;gt;/&amp;lt;lv&amp;gt; could be mounted correctly.&lt;br /&gt;
&lt;br /&gt;
== Tuning ==&lt;br /&gt;
&lt;br /&gt;
While trying to compare a 12-disk RAID (8TB disks) to a hwraid, mdraid was slower, so we did a few things to speed things up:&lt;br /&gt;
&lt;br /&gt;
While testing with [https://linux.die.net/man/1/fio fio], monitor /sys/block/md0/md/stripe_cache_active, and see if it&#039;s close to /sys/block/md0/md/stripe_cache_size. If it is, double the size of the latter&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
echo 4096 &amp;gt; /sys/block/md0/md/stripe_cache_size&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Continue until stripe_cache_active stabilises, and then you&#039;ve found the limit you&#039;ll need. You may want to double that for good measure. &lt;br /&gt;
&lt;br /&gt;
(to be continued)&lt;br /&gt;
&lt;br /&gt;
== Links ==&lt;br /&gt;
&lt;br /&gt;
Below are a few links with useful info&lt;br /&gt;
&lt;br /&gt;
* [https://raid.wiki.kernel.org/index.php/Irreversible_mdadm_failure_recovery Irreversible mdadm failure recovery]&lt;br /&gt;
&lt;br /&gt;
= ZFS =&lt;br /&gt;
&lt;br /&gt;
ZFS can do a lot of things most filesystems or volume managers can&#039;t. It checksums all data and metadata and so long that the system uses ECC enabled memory (RAM), it will have complete control over the whole data set, and when (not if) an error occurs, it&#039;ll fix the issue without even throwing a warning. To fix the issue, you&#039;ll obviously need sufficient redundancy (mirrors or RAIDzN). &lt;br /&gt;
&lt;br /&gt;
== ZFS send/receive between machines ==&lt;br /&gt;
&lt;br /&gt;
ZFS has a send/receive mechanism that allows for snapshots to be sent over the wire to a receiving end. This can be a full filesystem, or an incremental change since last send/reveive. In a WAN scenario, you&#039;ll probably want to use VPN for this. On a controlled network, sending in cleartext is also possible. You may as well use ssh, but keep in mind that ssh was never designed to be used as a fullblown vpn solution and is just too slow or the task with large amounts of data. You may, though, use mbuffer, if on a loal LAN.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Allow traffic from the sending IP in whatever firewall interface you&#039;re using (if you&#039;re using a firewall at all, that is)&lt;br /&gt;
ufw allow from x.x.x.x&lt;br /&gt;
# &lt;br /&gt;
# Start the receiver first. This listens on port 9090, has a 1GB buffer,&lt;br /&gt;
    and uses 128kb chunks (same as zfs):&lt;br /&gt;
&lt;br /&gt;
mbuffer -s 128k -m 1G -I 9090 | zfs receive data/filesystem&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To be continued one day… See [https://everycity.co.uk/alasdair/2010/07/using-mbuffer-to-speed-up-slow-zfs-send-zfs-receive/ this] for some more. I&#039;ll get back with details on it.&lt;br /&gt;
&lt;br /&gt;
= General Linux system control =&lt;br /&gt;
&lt;br /&gt;
== Add a new CPU (core) ==&lt;br /&gt;
&lt;br /&gt;
If working with virtual machines, adding a new core can be useful if the VM is slow and the load is multithreaded or multiprocess. To do this, add a new CPU in the hypervisor (be it KVM or VMware or Hyper-V or whatever). Some hypervisors, like VMware, will activate it automatically if open-vm-tools is installed. Please note that open-vm-tools is for VMware only. I don&#039;t know of any such thing for KVM or other hypervisors (although I beleive VirtualBox has its own set of tools, but not as a package). If this doesn&#039;t work, run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
echo 1 &amp;gt; /sys/devices/system/cpu/cpuX/online&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where X is the CPU number you want to add. You can &#039;cat /sys/devices/system/cpu/cpuX/online&#039; to check if it&#039;s online.&lt;br /&gt;
&lt;br /&gt;
= Mount partitions on a disk image =&lt;br /&gt;
&lt;br /&gt;
Sometimes you&#039;ll have a disk image, either from recovering a bad drive after hours (or days or weeks) of ddrescue, and sometimes you just have a disk image from a virtual machine where you want to mount the partitions inside the image. There are three main methods of doing this, which are more or less synonmous, but some easier than the other.&lt;br /&gt;
&lt;br /&gt;
== Basics ==&lt;br /&gt;
&lt;br /&gt;
A disk image is usually like a disk, consisting of either a large filesystem, a PV or a partition table with one or partitions onto which resides a filesystem, a pv, swap or something else. If it&#039;s partitioned, and you want your operating system to mount a filesystem or allow it to see whatever LVM stuff lies on it, you need to isolate the partitions. &lt;br /&gt;
&lt;br /&gt;
== Manual mapping ==&lt;br /&gt;
&lt;br /&gt;
In the oldern days, this was done manually, something like this&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
root@mymachine:~# fdisk -l /dev/vda&lt;br /&gt;
Disk /dev/vda: 25 GiB, 26843545600 bytes, 52428800 sectors&lt;br /&gt;
Units: sectors of 1 * 512 = 512 bytes&lt;br /&gt;
Sector size (logical/physical): 512 bytes / 512 bytes&lt;br /&gt;
I/O size (minimum/optimal): 512 bytes / 512 bytes&lt;br /&gt;
Disklabel type: dos&lt;br /&gt;
Disk identifier: 0xc37b7ea5&lt;br /&gt;
&lt;br /&gt;
Device     Boot    Start      End  Sectors  Size Id Type&lt;br /&gt;
/dev/vda1  *        2048 50333311 50331264   24G 83 Linux&lt;br /&gt;
/dev/vda2       50333312 52426369  2093058 1022M  5 Extended&lt;br /&gt;
/dev/vda5       50333314 52426369  2093056 1022M 82 Linux swap / Solaris&lt;br /&gt;
root@mymachine:~#&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To calculate the start and end of each partition, you just take the start sector and multiply it by the sector size (512 bytes here) and you have the offset in bytes. After this, it&#039;s merely an losetup -o &amp;lt;offset&amp;gt; /dev/loopX &amp;lt;nameofimagefile&amp;gt; and you have the partition mapped to your /dev/loopX (having X being something typically 0-255. After this, just mount it or run pvscan/vgscan/lvscan to probe whatever lvm config is there, and you should be able to mount it like any other filesystem.&lt;br /&gt;
&lt;br /&gt;
== kpartx ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;kpartx&#039;&#039;&#039; does the same as above, more or less, just without so much hassle. Most of it should be automatic and easy to deal with, except it may fail to disconnect the loopback devices sometimes, so you may have to &#039;&#039;&#039;losetup -d&#039;&#039;&#039; them manually. See the manual, &#039;&#039;&#039;kpartx (8)&#039;&#039;&#039;. Please note that &#039;&#039;&#039;partx&#039;&#039;&#039; works similarly and I&#039;d guess the authors of the two tools are arguing a lot of which one&#039;s the best.&lt;br /&gt;
&lt;br /&gt;
== guestmount ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;guestmount&#039;&#039;&#039; is something similar again, but also supports file formats like &#039;&#039;&#039;qcow2&#039;&#039;&#039; and possibly other, proprietary filesystems like &#039;&#039;&#039;vmdk&#039;&#039;&#039; and &#039;&#039;&#039;vdi&#039;&#039;&#039;, but don&#039;t take my word for it - I haven&#039;t tested. Again, see the manual or just read up on the description [http://ask.xmodulo.com/mount-qcow2-disk-image-linux.html?fbclid=IwAR3snTeZvGzp9PLdX11EQhCfOpux6I93CiJ3A2pUomkkRLly9Xo4851mkTY here]. It seems rather trivial.&lt;br /&gt;
&lt;br /&gt;
= Linux on laptops =&lt;br /&gt;
&lt;br /&gt;
== Wifi with HP EliteBook 725/745 on Ubuntu ==&lt;br /&gt;
&lt;br /&gt;
The HP EliteBook 725/745 and similar are equipped with a BCM4352 wifi chip. As with a lot of other stuff from Broadcom, this lacks an open hardware description, so thus no open driver exist. The proper fix, is to replace the NIC with something with an open driver, but again, this isn&#039;t always possible, so a binary driver exists. In ubuntu, run, somehow connect the machine to the internet and run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install bcmwl-kernel-source&lt;br /&gt;
sudo modprobe wl&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you can&#039;t connect the machine to the internet, download the needed packages on another machine and put it on some usb storage. These packages should suffice:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# apt-cache depends bcmwl-kernel-source&lt;br /&gt;
bcmwl-kernel-source&lt;br /&gt;
  Depends: dkms&lt;br /&gt;
  Depends: linux-libc-dev&lt;br /&gt;
  Depends: libc6-dev&lt;br /&gt;
  Conflicts: &amp;lt;bcmwl-modaliases&amp;gt;&lt;br /&gt;
  Replaces: &amp;lt;bcmwl-modaliases&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then install manually with &#039;&#039;&#039;dpkg -i file1.deb file2.deb&#039;&#039;&#039; etc&lt;br /&gt;
&lt;br /&gt;
After this, ip/ifconfig/iwconfig shouldd see the new wifi nic, probably &#039;&#039;&#039;wlan0&#039;&#039;&#039;, but due to a [https://bugs.launchpad.net/ubuntu/+source/broadcom-sta/+bug/1343151 old, ignored bug], you won&#039;t find any wifi networks. This is because the driver from Broadcom apparently does not support interrupt remapping, commonly used on x64 machines. To turn this off, change &#039;&#039;&#039;/etc/default/grub&#039;&#039;&#039; and change the line &#039;&#039;&#039;GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;quiet splash&amp;quot;&#039;&#039;&#039;, adding intremap=off to the end before the quote: &#039;&#039;&#039;GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;quiet splash intremap=off&amp;quot;&#039;&#039;&#039;. Save the file and run &#039;&#039;&#039;sudo update-grub&#039;&#039;&#039; and reboot. After this, wifi should work well.&lt;br /&gt;
&lt;br /&gt;
== Wifi with HP Compaq Presario CQ57 on Ubuntu ==&lt;br /&gt;
&lt;br /&gt;
The HP Compaq Presario CQ57 uses the RT5390 wifi chipset. This has been supported for quite some time now, and I was quite surprised to find it not working on a laptop a friend was having. The driver loaded correctly, but Ubuntu insisted of the laptop being in &#039;&#039;&#039;flight mode&#039;&#039;&#039;. Checking &#039;&#039;&#039;rfkill&#039;&#039;&#039;, it showed me two NICs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# rfkill list all&lt;br /&gt;
0: phy0: Wireless LAN&lt;br /&gt;
	Soft blocked: no&lt;br /&gt;
	Hard blocked: yes&lt;br /&gt;
1: hp-wifi: Wireless LAN&lt;br /&gt;
	Soft blocked: yes&lt;br /&gt;
	Hard blocked: no&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Turning rfkill on and off resulted in nothing much, except some error messages in the kernel log (dmesg)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] ACPI Error: Field [B128] at bit offset/length 128/1024 exceeds size of target Buffer (160 bits) (20170831/dsopcode-235)&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]&lt;br /&gt;
                            Initialized Local Variables for Method [HWCD]:&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Local0: 00000000a34b7928 &amp;lt;Obj&amp;gt;           Integer 0000000000000000&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Local1: 00000000b0aa6865 &amp;lt;Obj&amp;gt;           Buffer(8) 46 41 49 4C 04 00 00 00&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Local5: 00000000a9811efd &amp;lt;Obj&amp;gt;           Integer 0000000000000004&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] Initialized Arguments for Method [HWCD]:  (2 arguments defined for method invocation)&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Arg0:   0000000078957d1b &amp;lt;Obj&amp;gt;           Integer 0000000000000001&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Arg1:   00000000725c9c6e &amp;lt;Obj&amp;gt;           Buffer(20) 53 45 43 55 02 00 00 00&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] ACPI Error: Method parse/execution failed \_SB.WMID.HWCD, AE_AML_BUFFER_LIMIT (20170831/psparse-550)&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] ACPI Error: Method parse/execution failed \_SB.WMID.WMAD, AE_AML_BUFFER_LIMIT (20170831/psparse-550)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After upgrading BIOS and testing different kernels, I was asked to try to unload the &#039;&#039;&#039;hp_wmi&#039;&#039;&#039; driver. I did, and things changed a bit, so I tried blacklisting it, creating the file &#039;&#039;&#039;/etc/modprobe.d/blacklist-hp_wmi.conf&#039;&#039;&#039; with the following content&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Blacklist this - it doesn&#039;t work!&lt;br /&gt;
blacklist hp_wmi&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
I gave the machine a reboot and afte that, the &#039;&#039;&#039;hp-wifi&#039;&#039;&#039; entry was gone in the rfkill output, and things works.&lt;br /&gt;
&lt;br /&gt;
= Raspberry pi =&lt;br /&gt;
&lt;br /&gt;
I couldn&#039;t quite decide if the raspberry pi should be a separate section or part of Linux, but hell, it can run more than Linux, although 99,lots% of people just uses Linux on them. This is a small list of things to know about them; things not on the front page of the manual or perhaps hidden even better.&lt;br /&gt;
&lt;br /&gt;
== Which pi? ==&lt;br /&gt;
&lt;br /&gt;
I just setup three raspberry pi machines and although some are quite different, like v1 to vEverythingelse or the Pi zero versions to the normal ones, not all of us remember how to distinguish between them, and sometimes they&#039;re in a nice 3d printed (or otherwise) chassis or otherwise hidden. So, how to check three different ones:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
root@home-assistant:~ $ cat /proc/device-tree/model ; echo&lt;br /&gt;
Raspberry Pi 2 Model B Rev 1.1&lt;br /&gt;
&lt;br /&gt;
root@green-pi:~ $ cat /proc/device-tree/model ; echo&lt;br /&gt;
Raspberry Pi 3 Model B Rev 1.2&lt;br /&gt;
&lt;br /&gt;
roy@yellow-pi:~ $cat /proc/device-tree/model ; echo&lt;br /&gt;
Raspberry Pi 4 Model B Rev 1.1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
While this works well, for the latter, the pi4, it doesn&#039;t tell how much memory I have. It comes in variants of 1, 2 and 4GB, and this is the latter.&lt;br /&gt;
&lt;br /&gt;
== Monitoring ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;vcgencmd&#039;&#039;&#039; from &#039;&#039;&#039;/opt/vc/bin&#039;&#039;&#039;, but symlinked to &#039;&#039;&#039;/usr/bin&#039;&#039;&#039; so it&#039;s available in path, is useful for fetching hardware info about the pi. For example, measuring the temperature&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
root@yellow-pi:~# vcgencmd measure_temp&lt;br /&gt;
temp=63.0&#039;C&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The command is generally badly documented and parts of it seems outdated for newer hardware. Here&#039;s the output from a Raspberry pi 4 with 4GB RAM&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
roy@yellow-pi:~ $ vcgencmd get_mem arm&lt;br /&gt;
arm=948M&lt;br /&gt;
roy@yellow-pi:~ $ vcgencmd get_mem gpu&lt;br /&gt;
gpu=76M&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== BIOS upgrade from Linux ==&lt;br /&gt;
&lt;br /&gt;
Generally, BIOS upgrades have been moved to the BIOS itself these days. This saves a lot of work and quite possibly lives after those who earier rammed their heads through walls, now can upgrade directly from the internet instead of using obscure operating systems best avoided. Sometimes, however, one must use these nevertheless. This is a quick run-through on your options.&lt;br /&gt;
&lt;br /&gt;
=== DOS ===&lt;br /&gt;
&lt;br /&gt;
Most non-automatic BIOS upgrades are installed from DOS. Doing a BIOS upgrade this way, is generally non-problematic. Just install a USB thingie with [https://www.freedos.org/ FreeDOS], copy your file(s) onto the thing and boot on it. The commandline is the same as old MS/DOS, except a wee bit more userfriendly, but not a lot.&lt;br /&gt;
&lt;br /&gt;
=== Windows ===&lt;br /&gt;
&lt;br /&gt;
Some macahines, like laptops from &#039;&#039;&#039;HP&#039;&#039;&#039;, may have BIOS upgrades that are made to be installed from Windows and won&#039;t run in FreeDOS or MS/DOS, instead throwing an error, saying &#039;&#039;&#039;This program cannot be run in DOS mode&#039;&#039;&#039;. This means you&#039;ll have to boot on a Windows rescue disc and do the job from there. Googling this, tells you it&#039;s quite easy, you just choose &#039;make rescue disc&#039; from Windows, and it&#039;s all good, except if you don&#039;t run Windows, that is. To remedy this problem, do as follows:&lt;br /&gt;
&lt;br /&gt;
==== Download Windows ====&lt;br /&gt;
&lt;br /&gt;
Since you don&#039;t run Windows and possibly don&#039;t have a spouse or friend around with such unhealthy habits either, you need to get it. It&#039;s quite easy - just google &#039;download windows&#039; and it&#039;ll send you to [https://www.microsoft.com/en-us/software-download/windows10ISO somewhere like this].&lt;br /&gt;
&lt;br /&gt;
==== Burn it! ====&lt;br /&gt;
&lt;br /&gt;
Now it&#039;s time to burn the installer on a DVD ROM. You&#039;ll need a double-layered one, since the OS is &amp;gt; 4.7GiB, but I&#039;m sure you have a ton of those lying around. Now, just place your optical medium in your optical drive and burn, baby, burn!&lt;br /&gt;
&lt;br /&gt;
==== Or make a USB thing? ====&lt;br /&gt;
&lt;br /&gt;
Not a lot of machines have optical drives these days, so you may want to use an USB pen drive or something instead. This is easy, just make the USB bootable with the Windows application Microsoft has made for this. Unfortunately, this only runs on Windows, and unlike stuff like Debian, where the &#039;&#039;&#039;iso&#039;&#039;&#039; file can be dd&#039;ed directly onto a USB drive to make it bootable, the Windows &#039;&#039;&#039;iso&#039;&#039;&#039;s don&#039;t come with this luxury. There are lots of methods to make bootable USB things from iso files out there, but the only thing most of them have in common, is that they generally don&#039;t work.&lt;br /&gt;
&lt;br /&gt;
===== WoeUSB =====&lt;br /&gt;
&lt;br /&gt;
After hours of swearing, it&#039;s nice to come across software like [https://github.com/slacka/WoeUSB WoeUSB]. It may not be perfect, it relies on a bunch of GUI stuff you&#039;ll never need and so on, but it &#039;&#039;&#039;&#039;&#039;works&#039;&#039;&#039;&#039;&#039;, and that&#039;s the important part! Just clone the repo and RTFM and it&#039;s all nice. It&#039;s slow, but hell, getting a windows machine and/or an optical drive might be slower.&lt;br /&gt;
&lt;br /&gt;
WoeUSB does nothing fancy, but it &#039;&#039;&#039;does&#039;&#039;&#039; work. It will create a filesystem, FAT32 or NTFS (better use NTFS, FAT32 has its limits). It creates normal filesystems and so on. Just make sure to copy in the BIOS update file, usually an exe file, to run when Windows is up and running.&lt;br /&gt;
&lt;br /&gt;
===== Install BIOS =====&lt;br /&gt;
&lt;br /&gt;
Boot on the Windows USB thing and choose &#039;repair computer&#039; and then &#039;command prompt&#039;. Find the install file, and if you&#039;re lucky, you&#039;ll find it needs a 32bit OS, just like I did. Since the 64bit version doesn&#039;t include 32bit compatibility in the installer, revert to downloading the 32bit version of windows and start over. Pray to your favourite god(s) not to get across such machines again - it might help.&lt;br /&gt;
&lt;br /&gt;
= 3D printer stuff =&lt;br /&gt;
&lt;br /&gt;
== Hydrophilic filament ==&lt;br /&gt;
&lt;br /&gt;
Most popular filament types, including PLA, PETG, PP or PA (Polyamide, normally known as Nylon) and virtualy any filament type named [https://www.matterhackers.com/news/filament-and-water poly-something] (and thus with an acronym of P-something) are hydrophilic (also (somewhat incorrectly) called hydroscopic), meaning so long they&#039;re dryer than the atmosphere around them, they&#039;ll do their best to suck out the atmosphere&#039;s humidity. This is why most filament are shrink-wrapped with a small bag of silica gel in it. If such filament is exposed for normal humid air for some time, it&#039;ll become very hard to use. Most of my experience is with PLA, which can handle a bit (depending on make), but still not a lot. With PLA, if you end up with prints where the filament seems not to stick, it may help with a higher temperature. Otherwise, the filament must be [https://all3dp.com/2/how-to-dry-filament-pla-abs-and-nylon/ baked]. If you don&#039;t want to use your oven, try something like a [https://www.jula.no/catalog/hjem-og-husholdning/kjokkenmaskiner/mattilberedningsapparater/frukt-sopptorker/frukt-sopptorker-001641/#tab02 fruit and mushroom dryer]. Then get a good, sealble plastic box and add something like half a kilogram of [https://www.ebay.com/sch/sis.html?_nkw=1KG+Orange+Replacement+Desiccant+Indicating+Silica+Gel+Beads+for+Drawers%2C+Camera&amp;amp;_id=131938742628&amp;amp;&amp;amp;_trksid=p2057872.m2749.l2658 silica gel] to an old sock, tie it and put it in the your new dry box.&lt;br /&gt;
&lt;br /&gt;
Please note that ABS is hydrophobic, so you won&#039;t have to worry too much there. Also, remember that PA/Nylon is extremely hydrophilic. Even a couple of days in normal air humidity can ruin it completely and will require baking.&lt;br /&gt;
&lt;br /&gt;
== Upgrading the firmware on an Ender 3 ==&lt;br /&gt;
&lt;br /&gt;
This is about upgrading the firmware, and thus also flashing a bootloader to the Creality Ender 3 3D printer. Most of this is well documented on several place, like o [https://www.youtube.com/watch?v=fIl5X2ffdyo the video from Teaching tech] and elsewhere, but I&#039;ll just summarise some issues I had.&lt;br /&gt;
&lt;br /&gt;
=== Using an arduino Nano as a programmer ===&lt;br /&gt;
&lt;br /&gt;
The CR-10, Ender 3 and a few other printers from Creality come without a bootloader, so you&#039;ll need to flash one before upgrading the firmware. Well, strictly speakning, you don&#039;t need one, you can save those 8kB or so for other stuff and use a programmer to write the whole firmware, but then you&#039;ll need to wire up everything every time you want a new firmware, so in my world, you &#039;&#039;&#039;do&#039;&#039;&#039; need the bootloader, since it&#039;s easier. Note that some newer printers, like the CR-10S and possibly all newer ones, come with the bootloader already and thus won&#039;t need another.&lt;br /&gt;
&lt;br /&gt;
To install a bootloader, you&#039;ll need a programmer, and I didn&#039;t have one available. Having some el-cheapo china-copies of Ardinos around, I read I could use one and tried so. Although the docs mostly mention the Uno etc, it&#039;s just as simple with the Nano copy.&lt;br /&gt;
&lt;br /&gt;
So, grab an arduino, plug it to your machine with an USB cable, and, using the Arduino IDE, use the ArduinoISP sketch there (found under Examples) to burn the software needed for the arduino to work as a programmer. When this is done, connect a 10µF capacitor between RST and GND to stop it from resetting when used as a programmer. Connect the MOSI, MISO and SCK pins from the ICSP block (that little isolated 6-pin block on top of the ardu). See [https://www.arduino.cc/en/Tutorial/ArduinoISP here] for a pinout. Then find Vcc and GND either onthe ICSP block or elsewhere. Some sites say that on some boards you shouldn&#039;t use the pins on the ICSP block for this. I doubt it matters, though. Then connect another jumper wire from pin 10 on the ardu to work as the reset pin outwards to the chip being programmed (that is, on the printer). The ICSP jumper block pin layout is the same on the printer and on the ardu, and probably elsewhere. Sometimes [https://xkcd.com/927/ standardisation] actually works…&lt;br /&gt;
&lt;br /&gt;
See https://cloud.karlsbakk.net/index.php/s/zw48YJjzaf8Rc2F for a pic with the ardu (this wiki is broken atm, will fix it later)&lt;br /&gt;
&lt;br /&gt;
== Flashing the printer ==&lt;br /&gt;
&lt;br /&gt;
When the boot loader is in place, possibly after some wierd errors from during the process, the screen on the 3d printer will go blank and it&#039;ll behave like being bricked. This is ok. Now disconnect the wires and connect the USB cable between computer and printer, download the [https://www.th3dstudio.com/knowledgebase/th3d-unified-firmware-package/ TH3D unified firmware] and configure it for your particular needs. The video mentioned above describes this well. After flashing the new firmware, you&#039;ll probably get some timeouts and errors, since apparently it resets the printer after giving it the new firmware, but without notifying the flashing software of it doing so. If this happens, hold your breath and reboot the printer and check its tiny monitor - it should work. If it doesn&#039;t work, try to flash it again, and if that doesn&#039;t work, try flashing the programmer again yet another time, just for kicks.&lt;br /&gt;
&lt;br /&gt;
PS: I tried enabling &#039;&#039;&#039;MANUAL_MESH_LEVELING&#039;&#039;&#039;, which in the code says that &#039;&#039;If used with a 1284P board the bootscreen will be disabled to save space&#039;&#039;. This effectively disabled the whole thing, and apparently may be making the firmware image a wee bit too large for it to fit the 1284P on the ender. It works well without it, though.&lt;br /&gt;
&lt;br /&gt;
== And then… ==&lt;br /&gt;
&lt;br /&gt;
With the new firmware in place, the printer should work as before, although with thermal runaway protection to better avoid fires in case the shit hits the fan, and to allow for things like autolevelling. With any luck, [https://www.precisionpiezo.co.uk/ this thing] may be ready for use by the time you read this - it surely looks nice!&lt;br /&gt;
&lt;br /&gt;
roy&lt;/div&gt;</summary>
		<author><name>Roy</name></author>
	</entry>
	<entry>
		<id>https://wiki.malinux.no/index.php?title=Roy%27s_notes&amp;diff=153</id>
		<title>Roy&#039;s notes</title>
		<link rel="alternate" type="text/html" href="https://wiki.malinux.no/index.php?title=Roy%27s_notes&amp;diff=153"/>
		<updated>2020-02-11T01:01:12Z</updated>

		<summary type="html">&lt;p&gt;Roy: /* Wifi with HP Compaq Presario CQ57 on Ubuntu */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= LVM, md and friends =&lt;br /&gt;
&lt;br /&gt;
== Linux&#039; Logical Volume Manager (LVM) ==&lt;br /&gt;
&lt;br /&gt;
=== LVM in general ===&lt;br /&gt;
&lt;br /&gt;
LVM is designed to be an abstraction layer on top of physical drives or RAID, typically [https://raid.wiki.kernel.org/index.php/RAID_setup mdraid] or [https://help.ubuntu.com/community/FakeRaidHowto fakeraid]. Keep in mind that fakeraid should be avoided unless you really need it, like in conjunction with dual-booting linux and windows on fakeraid. LVM broadly consists of three elements, the &amp;quot;physical&amp;quot; devices (PV), the volume group (VG) and the logical volume (LV). There can be multiple PVs, VGs and LVs, depending on requirement. More about this below. All commands are given as examples, and all of them can be fine-tuned using extra flags in need of so. In my experience, the defaults work well for most usecases.&lt;br /&gt;
&lt;br /&gt;
I&#039;m mentioning filesystem below too. Where I write ext4, the samme applies to ext2 and ext3.&lt;br /&gt;
&lt;br /&gt;
==== Create a PV ====&lt;br /&gt;
&lt;br /&gt;
A PV is the &amp;quot;physical&amp;quot; parts. This does not need to be a physical disk, but can also be another RAID, be it an mdraid, fakeraid, hardware raid, a virtual disk on a SAN or otherwisee or a partition on one of those. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#  These add three PVs, one on a drive (or hardware raid) and another two on mdraids.&lt;br /&gt;
pvcreate /dev/sdb&lt;br /&gt;
pvcreate /dev/md1 /dev/md2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For more information about pvcreate, see [https://linux.die.net/man/8/pvcreate the manual].&lt;br /&gt;
&lt;br /&gt;
==== Create a VG ====&lt;br /&gt;
&lt;br /&gt;
The volume group consists of one or more PVs grouped together on which LVs can be placed. If several PVs are grouped in a VG, it&#039;s generally a good idea to make sure these PVs have some sort of redundancy, as in mdraid/fakeraid or hwraid. Otherwise it will be like using a [https://en.wikipedia.org/wiki/RAID RAID-0] with a single point of failure on each of the independant drives. LVM has [https://unix.stackexchange.com/questions/150644/raiding-with-lvm-vs-mdraid-pros-and-cons  RAID code in it] as well, so you can use that. I haven&#039;t done so myself, as I generally stick to mraid. The reason is mdraid is, in my opinion older and more stable and has more users (meaning bugs are reported and fixed faster whenever they are found). That said, I beleive the actual RAID code used in LVM RAID are the same function calls as for mdraid, so it may not be much of a difference. I still stick with mdraid. To create a VG, run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create volume group my_vg&lt;br /&gt;
vgcreate my_vg /dev/md1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that if vgcreate is run with a PV (as /dev/md1 above) that is not defined as a PV (like above), this is done implicitly, so if you don&#039;t need any special flags to pvcreate, you can simply skip it and let vgcreate do that for you.&lt;br /&gt;
&lt;br /&gt;
==== Create an LV ====&lt;br /&gt;
&lt;br /&gt;
LVs can be compared to partitions, somehow, since they are bounderies of a fraction or all of that of a VG. The difference between them and a partition, however, is that they can be grown or shrunk easily and also moved around between PVs without downtime. This flexibility makes them superiour to partitions as your system can be changed without users noticing it. By default, an LV is alloated &amp;quot;thickly&amp;quot;, meaning all the data given to it, is allocated from the VG and thus the PV. The following makes a 100GB LV named &amp;quot;thicklv&amp;quot;. When making an LV, I usually allocate what&#039;s needed plus some more, but not everything, just to make sure it&#039;s space available for growth on any of the LVs on the VG, or new LVs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a thick provisioned LV named thicklv on the VG my_vg&lt;br /&gt;
lvcreate -n thicklv -L 100G my_vg&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After the LV is created, a filesystem can be placed on it unless it is meant to be used directly. The application for direct use include swap space, VM storage and certain database systems. Most of these will, however, work on filesystems too, although my testing has shown that on swap space, there is a significant performance gain for using dedicated storage without a filesystem. As for filesystems, most Linux users use either ext4 or xfs. Personally, I generally use XFS these days. See my notes below on filesystem choice.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a filesystem on the LV - this could have been mkfs -t ext4 or whatever filesystem you choose&lt;br /&gt;
mkfs -t xfs /dev/my_vg/thicklv&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then just edit /etc/fstab with correct data and run mount -a, and you should be all set.&lt;br /&gt;
&lt;br /&gt;
==== Create LVM cache ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
lvcreate -L 1G -n _cache_meta data /dev/md1&lt;br /&gt;
&lt;br /&gt;
lvcreate -l100%FREE -n _cache data /dev/md1&lt;br /&gt;
&lt;br /&gt;
# Some would want --cachemode writeback, but seriously, I wouldn&#039;t recommend it. Metadata or data can be easily corrupted in case of failure.&lt;br /&gt;
lvconvert --type cache-pool --cachemode writethrough --poolmetadata data/_cache_meta data/_cache&lt;br /&gt;
&lt;br /&gt;
lvconvert --type cache --cachepool data/_cache data/data&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Disabling LVM cache ====&lt;br /&gt;
&lt;br /&gt;
If you for some reason want to disable caching, this will do it cleanly and remove the LVs earlier created for caching the main device.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
lvconvert --uncache data/data&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Growing devices ====&lt;br /&gt;
&lt;br /&gt;
LVM objects can be grown and shrunk. If a PV resides on a RAID where a new drive has been added or otherwise grown, or on a partition or virtual disk that has been extended, the PV must be updated to reflect these changes. The following command will grow the PV to the maximum available on the underlying storage. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Resize the PV /dev/md (not the RAID, only the PV on the RAID) to its full size&lt;br /&gt;
pvresize /dev/md1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If a new PV is added, the VG can be grown to add the space on that in addition to what&#039;s there already. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Extend my_vg to include md2 and its space&lt;br /&gt;
vgextend my_vg /dev/md2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
With more space available in the VG, the LV can now be extended. Let&#039;s add another 50GB to it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Extend thicklv - add 50GB. If you know you won&#039;t need the space anywhere else, you may want to&lt;br /&gt;
# lvresize -l+100%FREE instead. Keep in mind the difference between -l (extents) and -L (bytes)&lt;br /&gt;
lvresize -L +50G my_vg/thicklv&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Growing filesystems ====&lt;br /&gt;
After the LV has grown, run &#039;&#039;xfs_growfs&#039;&#039; (xfs) or &#039;&#039;resize2fs&#039;&#039; (ext4) to make use of the new data. To grow the filesystem to all available space on ext4, run the below command.  To partly grow the filesystem or to shrink it or otherwise, please see the manuals.&lt;br /&gt;
&lt;br /&gt;
The filesystem can be mounted when this is run. If you for some reason get an &#039;&#039;&#039;access denied&#039;&#039;&#039; error when running this as root or with sudo, it&#039;s likely caused by a filesystem error. To fix this, unmount the filesystem first and run &#039;&#039;&#039;fsck -f /dev/my_vg/thicklv&#039;&#039;&#039; and remount it before retrying to extend it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
resize2fs /dev/my_vg/thicklv&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Similarly, with XFS, but note that xfs_growfs doesn&#039;t take the device name, but the filesystem&#039;s mount point. In the case of XFS, also note that the filesystem &#039;&#039;&#039;&#039;&#039;must&#039;&#039;&#039;&#039;&#039; be mounted to be grown. This, in contrast to how it was in the old days when filesystems had to be unmounted to be grown.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
xfs_growfs /my_mountpoint&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Rename system VG ====&lt;br /&gt;
&lt;br /&gt;
Some distros create VG names like those-from-a-sysadmin-with-a-well-developed-paranoia-not-to-hit-a-duplicate. Debian, for instance, uses names like &amp;quot;my-full-hostname-vg&amp;quot;. Personally, I don&#039;t like these, since if I were to move a disk or vdisk around to somewhere else, I&#039;d make sure not to add a disk named &#039;sys&#039; to an existing system. If you do, most distros will refuse to use the VGs with duplicate names, resulting in the OS not booting until either one is specified by its UUID or just one removed. As I&#039;m aware of this, I stick to the super-risky thing of all system VGs named &#039;sys&#039; and so on.&lt;br /&gt;
&lt;br /&gt;
If you do this, keep in mind that it may blow up your computer and take your girl- or boyfriend with it or even make either of them pregnant, allowing Trump to rule your life and generally make things suck. You&#039;re on your own!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Rename the VG&lt;br /&gt;
vgrename my-full-hostname-vg sys&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, in /boot/grub/grub.cfg, change the old lv path from something like &#039;/dev/mapper/debian--stretch--machine--vg-root&#039; to your new and fancy &#039;/dev/sys/root. Likewise, in /etc/fstab, change occurences of &#039;/dev/mapper/debian--stretch--machine--vg-&#039; (or similar) with &#039;/dev/sys/&#039;. Here, this was like this - the old ones commented out.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;fstab&amp;quot;&amp;gt;&lt;br /&gt;
#/dev/mapper/debian--stretch--box--vg-root      /               ext4            errors=remount-ro,discard       0       1&lt;br /&gt;
/dev/sys/root                                   /               ext4            errors=remount-ro,discard       0       1&lt;br /&gt;
# /boot was on /dev/vda1 during installation&lt;br /&gt;
UUID=myverylonguuidwithatonofgoodinfoinit       /boot           ext2            defaults                        0       2&lt;br /&gt;
#/dev/mapper/debian--stretch--box--vg-swap_1    none            swap            sw                              0       0&lt;br /&gt;
/dev/sys/swap_1                                 none            swap            sw                              0       0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Update /etc/initramfs-tools/conf.d/resume with similar data for swap.&lt;br /&gt;
&lt;br /&gt;
You might want to run &#039;update-initramfs -u -k all&#039; after this, but I&#039;m not sure if it&#039;s needed.&lt;br /&gt;
&lt;br /&gt;
Now, pray to the nearest god(s) and give it a reboot and it should (probably) work.&lt;br /&gt;
&lt;br /&gt;
After reboot, run &#039;&#039;&#039;swapoff -a&#039;&#039;&#039;, then &#039;&#039;&#039;mkswap /dev/sys/swap_1&#039;&#039;&#039; (or whatever it&#039;s called on your system) and &#039;&#039;&#039;swapon -a&#039;&#039;&#039; again. You may want to give it another reboot or two for kicks, but it should work well even without that.&lt;br /&gt;
&lt;br /&gt;
=== Migration tools ===&lt;br /&gt;
&lt;br /&gt;
At times, storage regimes change, new storage is added and sometimes it&#039;s not easy to migrate with the current hardware or its support systems. Once I had to migrate a 45TiB fileserver from one storage system to another, preferably without downtime. The server originally had three 15TiB PVs of which two were full and the third half full. I resorted to using [https://linux.die.net/man/8/pvmove pvmove] to just move the data on the PVs in use to a new PV. We started out with creating a new 50TiB PV, sde, and then to pvmove.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Attach /dev/sde to the VG my_vg&lt;br /&gt;
vgextend my_vg /dev/sde&lt;br /&gt;
&lt;br /&gt;
# Move the contents from /dev/sdb over to /dev/sde block by block. If a target is not given in pvmove,&lt;br /&gt;
# the contents of the source (sdb here) will be put somewhere else in the pool.&lt;br /&gt;
pvmove /dev/sdb /dev/sde&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This took a while (as in a week or so) - the pvmove command uses old code and logic (or at least did that when I migrated this in November 2016), but it affected performance on the server very little, so users didn&#039;t notice. After the first PV was migrated, I continued with the other two, one after the other, and after a month or so, it was migrated. We used this on a number of large fileservers, and it worked flawlessly. Before doing the production servers I also tried interrupting pvmove in various ways, including hard resets, and it just kept on after the reboot.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;NOTE:&#039;&#039;&#039;&#039;&#039; &#039;&#039;Even though it worked well for us, &#039;&#039;&#039;always&#039;&#039;&#039; keep a good backup before doing this. Things may go wrong, and without a good backup, you may be looking for a hard-to-find new job the next morning&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
==== mdadm workarounds ====&lt;br /&gt;
&lt;br /&gt;
===== Migrate from a mirror (raid-1) to raid-10 =====&lt;br /&gt;
&lt;br /&gt;
Create a mirror&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sdb /dev/sdc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
LVM (pv/vg/lv) on md0 (see above), put a filesystem on the lv and fill it with some data.&lt;br /&gt;
&lt;br /&gt;
Now, some months later, you want to change this to raid-10 to allow for the same amount of redundancy, but to allow more disks into the system.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mdadm --grow /dev/md0 --level=10&lt;br /&gt;
mdadm: Impossibly level change request for RAID1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So - no - doesn&#039;t work. But - we&#039;re on &lt;br /&gt;
&lt;br /&gt;
Since we&#039;re on lvm already, this&#039;ll be easy. If you&#039;re using filesystems directly on partitions, you can do this the same way, but without the pvmove part, using rsync or whateever you like instead. I&#039;d recommend using lvm for for the new raid, which should be rather obvious from this article. Now plug in a new drive and create a new raid10 on that one. If you two new drives, install both. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# change &amp;quot;missing&amp;quot; to the other device name if you installed two new drives&lt;br /&gt;
mdadm --create /dev/md1 --level=10 --raid-devices=2 /dev/vdd missing&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, as described above, just vgextend the vg, adding the new raid and run pvmove to move the data from the old pv (residing on the old raid1) to the new pv (on raid10). Afte rpvmove is finished (which may take awile, see above), just&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
vgreduce raidtest /dev/md0&lt;br /&gt;
pvremove /dev/md0&lt;br /&gt;
mdadm --stop /dev/md0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
…and your disk is free to be added to the new array. If the new raid is running in degraded mode (if you created it with just one drive), better don&#039;t wait too long, since you don&#039;t have redundancy. Just mdadm --add the devs.&lt;br /&gt;
&lt;br /&gt;
If you now have /dev/mdstat telling you your raid10 is active and have three drives, of which one is a spare, it should look something like this&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5] [raid4] [raid10]&lt;br /&gt;
md1 : active raid10 vdc[3](S) vdb[2] vdd[0]&lt;br /&gt;
      8380416 blocks super 1.2 2 near-copies [2/2] [UU]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Just mdadm --grow --raid-devices=3 /dev/md1&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;RAID section is not complete. I&#039;ll write more on migraing from raid10 to raid6 later. It&#039;s not straight forward, but easier than this one :)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== Thin provisioned LVs ===&lt;br /&gt;
&lt;br /&gt;
Thin provisioning on LVM is a method used for not allocating all the space given to an LV. For instance, if you have a 1TB VG and want to give an LV 500GB, although it currently only uses a fraction of that, a thin lv can be a good alternative. This will allow for adding a limit to how much it can use, but also to let it grow dynamically without manual work by the sysadmin. Thin provisioning adds another layer of abstaction by creating a special LV as a &#039;&#039;thin pool&#039;&#039; from which data is allocated to the &#039;&#039;thin volume(s)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== Create a thin pool ====&lt;br /&gt;
&lt;br /&gt;
Allocate 1TB to the thin pool to be used for thinly provisioned LVs. Keep in mind that the space allocated to the thin pool is in fact thick provisioned. Only the volumes put on &#039;&#039;thinpool&#039;&#039; are thin provisioned. This will create two hidden LVs, one for data and one for metadata. Normally the defaults will do, but check the manual if the data doesn&#039;t match the usual patterns (such as billions of files, resulting in huge amounts of metadata). I &#039;&#039;beleive&#039;&#039; the metadata part should be resizable at a later time if needed, but I have not tested it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a pool for thin LVs. Keep in mind that the pool itself is not thin provisioned, only the volumes residing on it&lt;br /&gt;
lvcreate --size 1T --type thin-pool --thinpool thinpool my_vg&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Create a thin volume ====&lt;br /&gt;
&lt;br /&gt;
You have the thinpool, now put a thin volume on it. It will allocate some space for metadata, but probably not much (a few megs, perhaps).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Now, create a volume with a virtual (-V) size of half a terabyte named thin_pool, but using the thinpool (-T) named thin_pool for storage&lt;br /&gt;
lvcreate -V 500G -T my_vg/thin_pool --name thinvol&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The new volume&#039;s device name will be /dev/thinvol. Now, create a filesystem on it, add to fstab and mount it. The &#039;&#039;&#039;df&#039;&#039;&#039; command will return available space according to the virtual size (-V), while lvs will show how much data is actually used on each of the thinly provisioned volumes.&lt;br /&gt;
&lt;br /&gt;
== Filesystem dilemmas ==&lt;br /&gt;
&lt;br /&gt;
=== XFS or ext4 or something else ===&lt;br /&gt;
The choice of filesystem varies for your use. Distros such as RHEL/CentOS has moved to XFS by default from v7. Debian/Ubuntu still sticks to ext4, like most other. I&#039;ll discuss my thoughts below on ext4 vs XFS and leave the other filesystems for later.&lt;br /&gt;
&lt;br /&gt;
==== ext4 ====&lt;br /&gt;
ext4 is probably the most used filesystem on linux as of writing. It&#039;s rock stable and has been extended by a lot of extensions since the original ext2. It still retains backward compatibility, being able to mount and fsck ext2 and ext3 with the ext4 driver. However, it doesn&#039;t handle large filesystems very well. If a filesystem is created for &amp;lt;16TiB, it cannot be grown to anything larger than 16TiB. This may have changed lately, though. One other issue is handling errors. If a large filesystem (say 10TiB) is damaged, an fsck may take several hours, leading to long downtime. When I refer to ext4 further in this text, the same applies to ext2 and ext3 unless otherwise specified.&lt;br /&gt;
&lt;br /&gt;
==== XFS ====&lt;br /&gt;
XFS, originally developed by SGI some time in the bronze age, but has been worked on heavily after that. RHEL and Centos version 7 and forward, uses XFS as the default filesystem. It is quick, it scales well, but it lacks at least two things ext4 has. It cannot be shrunk (not that you normally need that, but nice if you have a typo or you need to change things). Also, it doesn&#039;t allow for automatic fsck on bootup. If something is messed up on the filesystem, you&#039;ll have to login as root on the console (not ssh), which might be an issue on some systems. The fsck equivalent, xfs_repair, is a *lot* faster than ext4&#039;s fsck, though.&lt;br /&gt;
&lt;br /&gt;
==== ZFS ====&lt;br /&gt;
ZFS is like a combination of RAID, LVM and a filesystem, supporting full checksumming, auto-healing (given sufficient redundancy), compression, encryption, replication, deduplication (if you&#039;re brave and have a &#039;&#039;ton&#039;&#039; of memory) and a lot more. It&#039;s a separate chapter and needs a lot more talk than paragraph here.&lt;br /&gt;
&lt;br /&gt;
== Low level disk handling ==&lt;br /&gt;
&lt;br /&gt;
This section is for low-level handling of disks, regardless of storage system elsewhere. These apply to mdraid, lvmraid and zfs and possibly other solutions, with the exception of individual drives on hwraid (and maybe fakeraid), since there, the drives are hidden from Linux (or whatever OS).&lt;br /&gt;
&lt;br /&gt;
=== S.M.A.R.T. and slow drives ===&lt;br /&gt;
Modern (that is, from about 1990 or later) have S.M.A.R.T. (or just smart, since it&#039;s easier to type) monitoring built in, meaning the disk&#039;s controller is monitoring itself. This is handy and will ideally tell you in advance that a drive is flakey or dying. Modern (2010+) smart monitoring is more or less the same. It can be trusted about 50% of the time. Usually, if smart detects an error, it&#039;s a real error. I don&#039;t think I&#039;ve seen it reporting a false positive, but others may know better. &lt;br /&gt;
&lt;br /&gt;
==== smartmontools ====&lt;br /&gt;
First, install smartmontool and run smartclt -H /dev/yourdisk (/dev/sda or something) to get a health report. Then perhaps run smartctl -a /dev/yourdisk and look for &#039;current pending sectors&#039; This should be zero. Also check the temperature, which normally should be much above 50.&lt;br /&gt;
&lt;br /&gt;
==== single, slow drive ====&lt;br /&gt;
What may happen, is smart not seeing anything and life goes on like before, only slower and less prouductive, without telling anyone. If you stubler over this issue, you&#039;ll probably see it during a large rsync/zfs send/receive or a resync/rebuild/resilver of the raid/zpool. During this, it feels like everything is slow and your RAID has turned into a RAIF (redundant array of inexpensive floppies). To check if you have a single drive messing up it all, check with &#039;&#039;&#039;iostat -x 2&#039;&#039;&#039;, having 2 being the delay between each measurement. Interrupt it with ctrl+x. If there&#039;s a rougue drive there, it should stand out like sdg below&lt;br /&gt;
&lt;br /&gt;
 avg-cpu:  %user   %nice %system %iowait  %steal   %idle&lt;br /&gt;
            0.38    0.00    1.75    0.00    0.00   97.87&lt;br /&gt;
&lt;br /&gt;
 Device            r/s     w/s     rkB/s     wkB/s   rrqm/s   wrqm/s  %rrqm  %wrqm r_await w_await aqu-sz rareq-sz wareq-sz  svctm  %util&lt;br /&gt;
 sda              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdb              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdc              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdd              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sde              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdf              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdg              3.50    0.00   2352.00      0.00     0.00     0.00   0.00   0.00 14306.29    0.00  13.85   672.00     0.00 285.71 100.00&lt;br /&gt;
 sdh              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
&lt;br /&gt;
In ZFS land, you should be able to get similar data with &#039;&#039;&#039;zpool iostat -v &amp;lt;pool&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Now you know the bad drive (sdg), pull it from the raid with &#039;&#039;&#039;mdadm --fail /dev/mdX /dev/sdX&#039;&#039;&#039;. Now test the drive&#039;s performance manually, just simply:&lt;br /&gt;
&lt;br /&gt;
 # hdparm -t /dev/sdg&lt;br /&gt;
 &lt;br /&gt;
 /dev/sdg:&lt;br /&gt;
  Timing buffered disk reads:   2 MB in  5.37 seconds = 381.46 kB/sec&lt;br /&gt;
&lt;br /&gt;
Bingo - nothing you&#039;d want to keep. For a good drive, it should be something like 100-200MB/s&lt;br /&gt;
&lt;br /&gt;
PS: Keep in mind that you have a degraded RAID by now in case you had a spare waiting for things to happen.&lt;br /&gt;
&lt;br /&gt;
Try to replace the cable and/or try the disk on another port/controller. If the result from hdparm persists, it&#039;s probably a bad cable&lt;br /&gt;
&lt;br /&gt;
So, then, just psycially locate the drive, pull it out, take out the discs and magnets and recycle the rest.&lt;br /&gt;
&lt;br /&gt;
=== &amp;quot;Unplug&amp;quot; drive from system ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Find the device unit&#039;s number with something like&lt;br /&gt;
find /sys/bus/scsi/devices/*/block/ -name sdd&lt;br /&gt;
# returning /sys/bus/scsi/devices/3:0:0:0/block/sdd here, &lt;br /&gt;
# meaning 3:0:0:0 is the SCSI device we&#039;re looking for.&lt;br /&gt;
&lt;br /&gt;
# Given this is the correct device, and you want to &#039;unplug&#039; it, do so by&lt;br /&gt;
echo 1 &amp;gt; /sys/bus/scsi/devices/3:0:0:0/delete&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Rescan disk controllers ===&lt;br /&gt;
If a drive is added and for some reason doesn&#039;t get detected, or is removed by the command above, it can be rediscovered with a sysfs command to the scsi host to which it is connected. Since there may be quite a few of these, an easy way is to just scan them all and check the output of &#039;&#039;&#039;dmesg -T&#039;&#039;&#039; after running it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Make a list of controllers and send a rescan message to each of them. It won&#039;t do anything &lt;br /&gt;
# for those where nothing has changed, but it will show new drives where they have been added.&lt;br /&gt;
for host_scan in /sys/class/scsi_host/host*/scan&lt;br /&gt;
do&lt;br /&gt;
  echo &#039;- - -&#039; &amp;gt; $host_scan&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Fail injection with debugfs ===&lt;br /&gt;
[https://lxadm.com/Using_fault_injection https://lxadm.com/Using_fault_injection]&lt;br /&gt;
&lt;br /&gt;
== mdadm stuff ==&lt;br /&gt;
=== Spare pools ===&lt;br /&gt;
In the old itmes, mdadm supported only a dedicated spare per md device, so if working with a large set of drives (20? 40?), where you&#039;d want to setup more raid sets to increase redundancy, you&#039;d dedicate a spare to each of the raid sets. This has changed (some time ago?), so in these modern, heathen days, you can change mdadm.conf, usually placed under /etc/mdadm, and add &#039;spare-group=somegroup&#039; where &#039;somegroup&#039; is a string identifying the spare group. After doing this, run &#039;&#039;&#039;update-initramfs -u&#039;&#039;&#039; and reboot and add a spare to one of the raid sets in the spare group, and md will use that or those spares for all the raidsets in that group.&lt;br /&gt;
&lt;br /&gt;
As some pointed out on #linux-raid @ irc.freenode.net, this feature is very badly documented, but as far as I can see, it works well.&lt;br /&gt;
&lt;br /&gt;
==== Example config ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create two raidsets&lt;br /&gt;
&lt;br /&gt;
mdadm --create /dev/md1 --level=6 --raid-devices=6 /dev/vd[efghij]&lt;br /&gt;
mdadm --create /dev/md2 --level=6 --raid-devices=6 /dev/vd[klmnop]&lt;br /&gt;
&lt;br /&gt;
# get their UUID etc&lt;br /&gt;
&lt;br /&gt;
mdadm --detail --scan&lt;br /&gt;
ARRAY /dev/md/1 metadata=1.2 name=raidtest:1 UUID=1a8cbdcb:f4092350:348b6b80:c054d74c&lt;br /&gt;
ARRAY /dev/md/2 metadata=1.2 name=raidtest:2 UUID=894b1b7c:cb7eba70:917d6033:ea5afd2b&lt;br /&gt;
&lt;br /&gt;
# Put those lines into /etc/mdadm/mdadm.conf and and add the spare-group&lt;br /&gt;
&lt;br /&gt;
ARRAY /dev/md/1 metadata=1.2 name=raidtest:1 spare-group=raidtest UUID=1a8cbdcb:f4092350:348b6b80:c054d74c&lt;br /&gt;
ARRAY /dev/md/2 metadata=1.2 name=raidtest:2 spare-group=raidtest UUID=894b1b7c:cb7eba70:917d6033:ea5afd2b&lt;br /&gt;
&lt;br /&gt;
# update the initramfs and reboot&lt;br /&gt;
&lt;br /&gt;
update-initramfs -u&lt;br /&gt;
reboot&lt;br /&gt;
&lt;br /&gt;
# add a spare drive to one of the raids&lt;br /&gt;
&lt;br /&gt;
mdadm --add /dev/md1 /dev/vdq&lt;br /&gt;
&lt;br /&gt;
# fail a drive on the other raid&lt;br /&gt;
&lt;br /&gt;
mdadm --fail /dev/md2 /dev/vdn&lt;br /&gt;
&lt;br /&gt;
# check /proc/mdstat to see md2 rebuilding with the spare from md1&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Recovery ===&lt;br /&gt;
&lt;br /&gt;
The other day, I came across a problem a user had on #linux-raid@irc.freenode.net. He had an old Qnap NAS that had died and tried plugging the drives in to his Linux machine and got various errors. The two-drive RAID-1 did not come up as it should, &#039;&#039;&#039;dmesg&#039;&#039;&#039; was full of errors from one of the drives (both connected on USB) and so forth.&lt;br /&gt;
&lt;br /&gt;
We went on and started by taking down the machine and just connecting one of the drives. I had him check what was assembled with&lt;br /&gt;
&lt;br /&gt;
 cat /proc/mdstat&lt;br /&gt;
&lt;br /&gt;
That returned /proc/md127 assembled, but LVM didn&#039;t find anything. So running a manual scan&lt;br /&gt;
&lt;br /&gt;
 pvscan --cache /dev/md127&lt;br /&gt;
&lt;br /&gt;
This made linux find the PV, VG and a couple of LVs, but probably because the mdraid was degraded, the LVs were deactivated, according to &#039;&#039;&#039;lvscan&#039;&#039;&#039;. Activating the one with a filesystem manually&lt;br /&gt;
&lt;br /&gt;
 lvchange -a y /dev/&amp;lt;vg&amp;gt;/&amp;lt;lv&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Substitute &amp;lt;vg&amp;gt; and &amp;lt;lv&amp;gt; with the names listed by vgs and lvs.&lt;br /&gt;
&lt;br /&gt;
This worked, and the filesystem on /dev/&amp;lt;vg&amp;gt;/&amp;lt;lv&amp;gt; could be mounted correctly.&lt;br /&gt;
&lt;br /&gt;
== Tuning ==&lt;br /&gt;
&lt;br /&gt;
While trying to compare a 12-disk RAID (8TB disks) to a hwraid, mdraid was slower, so we did a few things to speed things up:&lt;br /&gt;
&lt;br /&gt;
While testing with [https://linux.die.net/man/1/fio fio], monitor /sys/block/md0/md/stripe_cache_active, and see if it&#039;s close to /sys/block/md0/md/stripe_cache_size. If it is, double the size of the latter&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
echo 4096 &amp;gt; /sys/block/md0/md/stripe_cache_size&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Continue until stripe_cache_active stabilises, and then you&#039;ve found the limit you&#039;ll need. You may want to double that for good measure. &lt;br /&gt;
&lt;br /&gt;
(to be continued)&lt;br /&gt;
&lt;br /&gt;
== Links ==&lt;br /&gt;
&lt;br /&gt;
Below are a few links with useful info&lt;br /&gt;
&lt;br /&gt;
* [https://raid.wiki.kernel.org/index.php/Irreversible_mdadm_failure_recovery Irreversible mdadm failure recovery]&lt;br /&gt;
&lt;br /&gt;
= ZFS =&lt;br /&gt;
&lt;br /&gt;
ZFS can do a lot of things most filesystems or volume managers can&#039;t. It checksums all data and metadata and so long that the system uses ECC enabled memory (RAM), it will have complete control over the whole data set, and when (not if) an error occurs, it&#039;ll fix the issue without even throwing a warning. To fix the issue, you&#039;ll obviously need sufficient redundancy (mirrors or RAIDzN). &lt;br /&gt;
&lt;br /&gt;
== ZFS send/receive between machines ==&lt;br /&gt;
&lt;br /&gt;
ZFS has a send/receive mechanism that allows for snapshots to be sent over the wire to a receiving end. This can be a full filesystem, or an incremental change since last send/reveive. In a WAN scenario, you&#039;ll probably want to use VPN for this. On a controlled network, sending in cleartext is also possible. You may as well use ssh, but keep in mind that ssh was never designed to be used as a fullblown vpn solution and is just too slow or the task with large amounts of data. You may, though, use mbuffer, if on a loal LAN.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Allow traffic from the sending IP in whatever firewall interface you&#039;re using (if you&#039;re using a firewall at all, that is)&lt;br /&gt;
ufw allow from x.x.x.x&lt;br /&gt;
# &lt;br /&gt;
# Start the receiver first. This listens on port 9090, has a 1GB buffer,&lt;br /&gt;
    and uses 128kb chunks (same as zfs):&lt;br /&gt;
&lt;br /&gt;
mbuffer -s 128k -m 1G -I 9090 | zfs receive data/filesystem&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To be continued one day… See [https://everycity.co.uk/alasdair/2010/07/using-mbuffer-to-speed-up-slow-zfs-send-zfs-receive/ this] for some more. I&#039;ll get back with details on it.&lt;br /&gt;
&lt;br /&gt;
= General Linux system control =&lt;br /&gt;
&lt;br /&gt;
== Add a new CPU (core) ==&lt;br /&gt;
&lt;br /&gt;
If working with virtual machines, adding a new core can be useful if the VM is slow and the load is multithreaded or multiprocess. To do this, add a new CPU in the hypervisor (be it KVM or VMware or Hyper-V or whatever). Some hypervisors, like VMware, will activate it automatically if open-vm-tools is installed. Please note that open-vm-tools is for VMware only. I don&#039;t know of any such thing for KVM or other hypervisors (although I beleive VirtualBox has its own set of tools, but not as a package). If this doesn&#039;t work, run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
echo 1 &amp;gt; /sys/devices/system/cpu/cpuX/online&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where X is the CPU number you want to add. You can &#039;cat /sys/devices/system/cpu/cpuX/online&#039; to check if it&#039;s online.&lt;br /&gt;
&lt;br /&gt;
= Mount partitions on a disk image =&lt;br /&gt;
&lt;br /&gt;
Sometimes you&#039;ll have a disk image, either from recovering a bad drive after hours (or days or weeks) of ddrescue, and sometimes you just have a disk image from a virtual machine where you want to mount the partitions inside the image. There are three main methods of doing this, which are more or less synonmous, but some easier than the other.&lt;br /&gt;
&lt;br /&gt;
== Basics ==&lt;br /&gt;
&lt;br /&gt;
A disk image is usually like a disk, consisting of either a large filesystem, a PV or a partition table with one or partitions onto which resides a filesystem, a pv, swap or something else. If it&#039;s partitioned, and you want your operating system to mount a filesystem or allow it to see whatever LVM stuff lies on it, you need to isolate the partitions. &lt;br /&gt;
&lt;br /&gt;
== Manual mapping ==&lt;br /&gt;
&lt;br /&gt;
In the oldern days, this was done manually, something like this&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
root@mymachine:~# fdisk -l /dev/vda&lt;br /&gt;
Disk /dev/vda: 25 GiB, 26843545600 bytes, 52428800 sectors&lt;br /&gt;
Units: sectors of 1 * 512 = 512 bytes&lt;br /&gt;
Sector size (logical/physical): 512 bytes / 512 bytes&lt;br /&gt;
I/O size (minimum/optimal): 512 bytes / 512 bytes&lt;br /&gt;
Disklabel type: dos&lt;br /&gt;
Disk identifier: 0xc37b7ea5&lt;br /&gt;
&lt;br /&gt;
Device     Boot    Start      End  Sectors  Size Id Type&lt;br /&gt;
/dev/vda1  *        2048 50333311 50331264   24G 83 Linux&lt;br /&gt;
/dev/vda2       50333312 52426369  2093058 1022M  5 Extended&lt;br /&gt;
/dev/vda5       50333314 52426369  2093056 1022M 82 Linux swap / Solaris&lt;br /&gt;
root@mymachine:~#&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To calculate the start and end of each partition, you just take the start sector and multiply it by the sector size (512 bytes here) and you have the offset in bytes. After this, it&#039;s merely an losetup -o &amp;lt;offset&amp;gt; /dev/loopX &amp;lt;nameofimagefile&amp;gt; and you have the partition mapped to your /dev/loopX (having X being something typically 0-255. After this, just mount it or run pvscan/vgscan/lvscan to probe whatever lvm config is there, and you should be able to mount it like any other filesystem.&lt;br /&gt;
&lt;br /&gt;
== kpartx ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;kpartx&#039;&#039;&#039; does the same as above, more or less, just without so much hassle. Most of it should be automatic and easy to deal with, except it may fail to disconnect the loopback devices sometimes, so you may have to &#039;&#039;&#039;losetup -d&#039;&#039;&#039; them manually. See the manual, &#039;&#039;&#039;kpartx (8)&#039;&#039;&#039;. Please note that &#039;&#039;&#039;partx&#039;&#039;&#039; works similarly and I&#039;d guess the authors of the two tools are arguing a lot of which one&#039;s the best.&lt;br /&gt;
&lt;br /&gt;
== guestmount ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;guestmount&#039;&#039;&#039; is something similar again, but also supports file formats like &#039;&#039;&#039;qcow2&#039;&#039;&#039; and possibly other, proprietary filesystems like &#039;&#039;&#039;vmdk&#039;&#039;&#039; and &#039;&#039;&#039;vdi&#039;&#039;&#039;, but don&#039;t take my word for it - I haven&#039;t tested. Again, see the manual or just read up on the description [http://ask.xmodulo.com/mount-qcow2-disk-image-linux.html?fbclid=IwAR3snTeZvGzp9PLdX11EQhCfOpux6I93CiJ3A2pUomkkRLly9Xo4851mkTY here]. It seems rather trivial.&lt;br /&gt;
&lt;br /&gt;
= Linux on laptops =&lt;br /&gt;
&lt;br /&gt;
== Wifi with HP EliteBook 725/745 on Ubuntu ==&lt;br /&gt;
&lt;br /&gt;
The HP EliteBook 725/745 and similar are equipped with a BCM4352 wifi chip. As with a lot of other stuff from Broadcom, this lacks an open hardware description, so thus no open driver exist. The proper fix, is to replace the NIC with something with an open driver, but again, this isn&#039;t always possible, so a binary driver exists. In ubuntu, run, somehow connect the machine to the internet and run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install bcmwl-kernel-source&lt;br /&gt;
sudo modprobe wl&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you can&#039;t connect the machine to the internet, download the needed packages on another machine and put it on some usb storage. These packages should suffice:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# apt-cache depends bcmwl-kernel-source&lt;br /&gt;
bcmwl-kernel-source&lt;br /&gt;
  Depends: dkms&lt;br /&gt;
  Depends: linux-libc-dev&lt;br /&gt;
  Depends: libc6-dev&lt;br /&gt;
  Conflicts: &amp;lt;bcmwl-modaliases&amp;gt;&lt;br /&gt;
  Replaces: &amp;lt;bcmwl-modaliases&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then install manually with &#039;&#039;&#039;dpkg -i file1.deb file2.deb&#039;&#039;&#039; etc&lt;br /&gt;
&lt;br /&gt;
After this, ip/ifconfig/iwconfig shouldd see the new wifi nic, probably &#039;&#039;&#039;wlan0&#039;&#039;&#039;, but due to a [https://bugs.launchpad.net/ubuntu/+source/broadcom-sta/+bug/1343151 old, ignored bug], you won&#039;t find any wifi networks. This is because the driver from Broadcom apparently does not support interrupt remapping, commonly used on x64 machines. To turn this off, change &#039;&#039;&#039;/etc/default/grub&#039;&#039;&#039; and change the line &#039;&#039;&#039;GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;quiet splash&amp;quot;&#039;&#039;&#039;, adding intremap=off to the end before the quote: &#039;&#039;&#039;GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;quiet splash intremap=off&amp;quot;&#039;&#039;&#039;. Save the file and run &#039;&#039;&#039;sudo update-grub&#039;&#039;&#039; and reboot. After this, wifi should work well.&lt;br /&gt;
&lt;br /&gt;
== Wifi with HP Compaq Presario CQ57 on Ubuntu ==&lt;br /&gt;
&lt;br /&gt;
The HP Compaq Presario CQ57 uses the RT5390 wifi chipset. This has been supported for quite some time now, and I was quite surprised to find it not working on a laptop a friend was having. The driver loaded correctly, but Ubuntu insisted of the laptop being in &#039;&#039;&#039;flight mode&#039;&#039;&#039;. Checking &#039;&#039;&#039;rfkill&#039;&#039;&#039;, it showed me two NICs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# rfkill list all&lt;br /&gt;
0: phy0: Wireless LAN&lt;br /&gt;
	Soft blocked: no&lt;br /&gt;
	Hard blocked: yes&lt;br /&gt;
1: hp-wifi: Wireless LAN&lt;br /&gt;
	Soft blocked: yes&lt;br /&gt;
	Hard blocked: no&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Turning rfkill on and off resulted in nothing much, except some error messages in the kernel log (dmesg)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] ACPI Error: Field [B128] at bit offset/length 128/1024 exceeds size of target Buffer (160 bits) (20170831/dsopcode-235)&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]&lt;br /&gt;
                            Initialized Local Variables for Method [HWCD]:&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Local0: 00000000a34b7928 &amp;lt;Obj&amp;gt;           Integer 0000000000000000&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Local1: 00000000b0aa6865 &amp;lt;Obj&amp;gt;           Buffer(8) 46 41 49 4C 04 00 00 00&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Local5: 00000000a9811efd &amp;lt;Obj&amp;gt;           Integer 0000000000000004&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] Initialized Arguments for Method [HWCD]:  (2 arguments defined for method invocation)&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Arg0:   0000000078957d1b &amp;lt;Obj&amp;gt;           Integer 0000000000000001&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Arg1:   00000000725c9c6e &amp;lt;Obj&amp;gt;           Buffer(20) 53 45 43 55 02 00 00 00&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] ACPI Error: Method parse/execution failed \_SB.WMID.HWCD, AE_AML_BUFFER_LIMIT (20170831/psparse-550)&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] ACPI Error: Method parse/execution failed \_SB.WMID.WMAD, AE_AML_BUFFER_LIMIT (20170831/psparse-550)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After upgrading BIOS and testing different kernels, I was asked to try to unload the &#039;&#039;&#039;hp_wmi&#039;&#039;&#039; driver. I did, and things changed a bit, so I tried blacklisting it, creating the file &#039;&#039;&#039;/etc/modprobe.d/blacklist-hp_wmi.conf&#039;&#039;&#039; with the following content&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Blacklist this - it doesn&#039;t work!&lt;br /&gt;
blacklist hp_wmi&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
I gave the machine a reboot and afte that, the &#039;&#039;&#039;hp-wifi&#039;&#039;&#039; entry was gone in the rfkill output, and things works.&lt;br /&gt;
&lt;br /&gt;
= Raspberry pi =&lt;br /&gt;
&lt;br /&gt;
I couldn&#039;t quite decide if the raspberry pi should be a separate section or part of Linux, but hell, it can run more than Linux, although 99,lots% of people just uses Linux on them. This is a small list of things to know about them; things not on the front page of the manual or perhaps hidden even better.&lt;br /&gt;
&lt;br /&gt;
== Which pi? ==&lt;br /&gt;
&lt;br /&gt;
I just setup three raspberry pi machines and although some are quite different, like v1 to vEverythingelse or the Pi zero versions to the normal ones, not all of us remember how to distinguish between them, and sometimes they&#039;re in a nice 3d printed (or otherwise) chassis or otherwise hidden. So, how to check three different ones:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
root@home-assistant:~ $ cat /proc/device-tree/model ; echo&lt;br /&gt;
Raspberry Pi 2 Model B Rev 1.1&lt;br /&gt;
&lt;br /&gt;
root@green-pi:~ $ cat /proc/device-tree/model ; echo&lt;br /&gt;
Raspberry Pi 3 Model B Rev 1.2&lt;br /&gt;
&lt;br /&gt;
roy@yellow-pi:~ $cat /proc/device-tree/model ; echo&lt;br /&gt;
Raspberry Pi 4 Model B Rev 1.1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
While this works well, for the latter, the pi4, it doesn&#039;t tell how much memory I have. It comes in variants of 1, 2 and 4GB, and this is the latter.&lt;br /&gt;
&lt;br /&gt;
== Monitoring ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;vcgencmd&#039;&#039;&#039; from &#039;&#039;&#039;/opt/vc/bin&#039;&#039;&#039;, but symlinked to &#039;&#039;&#039;/usr/bin&#039;&#039;&#039; so it&#039;s available in path, is useful for fetching hardware info about the pi. For example, measuring the temperature&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
root@yellow-pi:~# vcgencmd measure_temp&lt;br /&gt;
temp=63.0&#039;C&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The command is generally badly documented and parts of it seems outdated for newer hardware. Here&#039;s the output from a Raspberry pi 4 with 4GB RAM&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
roy@yellow-pi:~ $ vcgencmd get_mem arm&lt;br /&gt;
arm=948M&lt;br /&gt;
roy@yellow-pi:~ $ vcgencmd get_mem gpu&lt;br /&gt;
gpu=76M&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== BIOS upgrade from Linux ==&lt;br /&gt;
&lt;br /&gt;
Generally, BIOS upgrades have been moved to the BIOS itself these days. This saves a lot of work and quite possibly lives after those who earier rammed their heads through walls, now can upgrade directly from the internet instead of using obscure operating systems best avoided. Sometimes, however, one must use these nevertheless. This is a quick run-through on your options.&lt;br /&gt;
&lt;br /&gt;
=== DOS ===&lt;br /&gt;
&lt;br /&gt;
Most non-automatic BIOS upgrades are installed from DOS. Doing a BIOS upgrade this way, is generally non-problematic. Just install a USB thingie with [https://www.freedos.org/ FreeDOS], copy your file(s) onto the thing and boot on it. The commandline is the same as old MS/DOS, except a wee bit more userfriendly, but not a lot.&lt;br /&gt;
&lt;br /&gt;
=== Windows ===&lt;br /&gt;
&lt;br /&gt;
Some macahines, like laptops from &#039;&#039;&#039;HP&#039;&#039;&#039;, may have BIOS upgrades that are made to be installed from Windows and won&#039;t run in FreeDOS or MS/DOS, instead throwing an error, saying &#039;&#039;&#039;This program cannot be run in DOS mode&#039;&#039;&#039;. This means you&#039;ll have to boot on a Windows rescue disc and do the job from there. Googling this, tells you it&#039;s quite easy, you just choose &#039;make rescue disc&#039; from Windows, and it&#039;s all good, except if you don&#039;t run Windows, that is. To remedy this problem, do as follows:&lt;br /&gt;
&lt;br /&gt;
==== Download Windows ====&lt;br /&gt;
&lt;br /&gt;
Since you don&#039;t run Windows and possibly don&#039;t have a spouse or friend around with such unhealthy habits either, you need to get it. It&#039;s quite easy - just google &#039;download windows&#039; and it&#039;ll send you to [https://www.microsoft.com/en-us/software-download/windows10ISO somewhere like this].&lt;br /&gt;
&lt;br /&gt;
==== Burn it! ====&lt;br /&gt;
&lt;br /&gt;
Now it&#039;s time to burn the installer on a DVD ROM. You&#039;ll need a double-layered one, since the OS is &amp;gt; 4.7GiB, but I&#039;m sure you have a ton of those lying around. Now, just place your optical medium in your optical drive and burn, baby, burn!&lt;br /&gt;
&lt;br /&gt;
==== Or make a USB thing? ====&lt;br /&gt;
&lt;br /&gt;
Not a lot of machines have optical drives these days, so you may want to use an USB pen drive or something instead. This is easy, just make the USB bootable with the Windows application Microsoft has made for this. Unfortunately, this only runs on Windows, and unlike stuff like Debian, where the &#039;&#039;&#039;iso&#039;&#039;&#039; file can be dd&#039;ed directly onto a USB drive to make it bootable, the Windows &#039;&#039;&#039;iso&#039;&#039;&#039;s don&#039;t come with this luxury. There are lots of methods to make bootable USB things from iso files out there, but the only thing most of them have in common, is that they generally don&#039;t work.&lt;br /&gt;
&lt;br /&gt;
===== WoeUSB =====&lt;br /&gt;
&lt;br /&gt;
After hours of swearing, it&#039;s nice to come across software like [https://github.com/slacka/WoeUSB WoeUSB]. It may not be perfect, it relies on a bunch of GUI stuff you&#039;ll never need and so on, but it &#039;&#039;&#039;&#039;&#039;works&#039;&#039;&#039;&#039;&#039;, and that&#039;s the important part! Just clone the repo and RTFM and it&#039;s all nice. It&#039;s slow, but hell, getting a windows machine and/or an optical drive might be slower.&lt;br /&gt;
&lt;br /&gt;
WoeUSB does nothing fancy, but it &#039;&#039;&#039;does&#039;&#039;&#039; work. It will create a filesystem, FAT32 or NTFS (better use NTFS, FAT32 has its limits). It creates normal filesystems and so on. Just make sure to copy in the BIOS update file, usually an exe file, to run when Windows is up and running.&lt;br /&gt;
&lt;br /&gt;
===== Install BIOS =====&lt;br /&gt;
&lt;br /&gt;
Boot on the Windows USB thing and choose &#039;repair computer&#039; and then &#039;command prompt&#039;. Find the install file, and if you&#039;re lucky, you&#039;ll find it needs a 32bit OS, just like I did. Since the 64bit version doesn&#039;t include 32bit compatibility in the installer, revert to downloading the 32bit version of windows and start over. Pray to your favourite god(s) not to get across such machines again - it might help.&lt;br /&gt;
&lt;br /&gt;
= 3D printer stuff =&lt;br /&gt;
&lt;br /&gt;
== Hydrophilic filament ==&lt;br /&gt;
&lt;br /&gt;
Most popular filament types, including PLA, PETG, PP or PA (Polyamide, normally known as Nylon) and virtualy any filament type named [https://www.matterhackers.com/news/filament-and-water poly-something] (and thus with an acronym of P-something) are hydrophilic (also (somewhat incorrectly) called hydroscopic), meaning so long they&#039;re dryer than the atmosphere around them, they&#039;ll do their best to suck out the atmosphere&#039;s humidity. This is why most filament are shrink-wrapped with a small bag of silica gel in it. If such filament is exposed for normal humid air for some time, it&#039;ll become very hard to use. Most of my experience is with PLA, which can handle a bit (depending on make), but still not a lot. With PLA, if you end up with prints where the filament seems not to stick, it may help with a higher temperature. Otherwise, the filament must be [https://all3dp.com/2/how-to-dry-filament-pla-abs-and-nylon/ baked]. If you don&#039;t want to use your oven, try something like a [https://www.jula.no/catalog/hjem-og-husholdning/kjokkenmaskiner/mattilberedningsapparater/frukt-sopptorker/frukt-sopptorker-001641/#tab02 fruit and mushroom dryer]. Then get a good, sealble plastic box and add something like half a kilogram of [https://www.ebay.com/sch/sis.html?_nkw=1KG+Orange+Replacement+Desiccant+Indicating+Silica+Gel+Beads+for+Drawers%2C+Camera&amp;amp;_id=131938742628&amp;amp;&amp;amp;_trksid=p2057872.m2749.l2658 silica gel] to an old sock, tie it and put it in the your new dry box.&lt;br /&gt;
&lt;br /&gt;
Please note that ABS is hydrophobic, so you won&#039;t have to worry too much there. Also, remember that PA/Nylon is extremely hydrophilic. Even a couple of days in normal air humidity can ruin it completely and will require baking.&lt;br /&gt;
&lt;br /&gt;
== Upgrading the firmware on an Ender 3 ==&lt;br /&gt;
&lt;br /&gt;
This is about upgrading the firmware, and thus also flashing a bootloader to the Creality Ender 3 3D printer. Most of this is well documented on several place, like o [https://www.youtube.com/watch?v=fIl5X2ffdyo the video from Teaching tech] and elsewhere, but I&#039;ll just summarise some issues I had.&lt;br /&gt;
&lt;br /&gt;
=== Using an arduino Nano as a programmer ===&lt;br /&gt;
&lt;br /&gt;
The CR-10, Ender 3 and a few other printers from Creality come without a bootloader, so you&#039;ll need to flash one before upgrading the firmware. Well, strictly speakning, you don&#039;t need one, you can save those 8kB or so for other stuff and use a programmer to write the whole firmware, but then you&#039;ll need to wire up everything every time you want a new firmware, so in my world, you &#039;&#039;&#039;do&#039;&#039;&#039; need the bootloader, since it&#039;s easier. Note that some newer printers, like the CR-10S and possibly all newer ones, come with the bootloader already and thus won&#039;t need another.&lt;br /&gt;
&lt;br /&gt;
To install a bootloader, you&#039;ll need a programmer, and I didn&#039;t have one available. Having some el-cheapo china-copies of Ardinos around, I read I could use one and tried so. Although the docs mostly mention the Uno etc, it&#039;s just as simple with the Nano copy.&lt;br /&gt;
&lt;br /&gt;
So, grab an arduino, plug it to your machine with an USB cable, and, using the Arduino IDE, use the ArduinoISP sketch there (found under Examples) to burn the software needed for the arduino to work as a programmer. When this is done, connect a 10µF capacitor between RST and GND to stop it from resetting when used as a programmer. Connect the MOSI, MISO and SCK pins from the ICSP block (that little isolated 6-pin block on top of the ardu). See [https://www.arduino.cc/en/Tutorial/ArduinoISP here] for a pinout. Then find Vcc and GND either onthe ICSP block or elsewhere. Some sites say that on some boards you shouldn&#039;t use the pins on the ICSP block for this. I doubt it matters, though. Then connect another jumper wire from pin 10 on the ardu to work as the reset pin outwards to the chip being programmed (that is, on the printer). The ICSP jumper block pin layout is the same on the printer and on the ardu, and probably elsewhere. Sometimes [https://xkcd.com/927/ standardisation] actually works…&lt;br /&gt;
&lt;br /&gt;
See https://cloud.karlsbakk.net/index.php/s/zw48YJjzaf8Rc2F for a pic with the ardu (this wiki is broken atm, will fix it later)&lt;br /&gt;
&lt;br /&gt;
== Flashing the printer ==&lt;br /&gt;
&lt;br /&gt;
When the boot loader is in place, possibly after some wierd errors from during the process, the screen on the 3d printer will go blank and it&#039;ll behave like being bricked. This is ok. Now disconnect the wires and connect the USB cable between computer and printer, download the [https://www.th3dstudio.com/knowledgebase/th3d-unified-firmware-package/ TH3D unified firmware] and configure it for your particular needs. The video mentioned above describes this well. After flashing the new firmware, you&#039;ll probably get some timeouts and errors, since apparently it resets the printer after giving it the new firmware, but without notifying the flashing software of it doing so. If this happens, hold your breath and reboot the printer and check its tiny monitor - it should work. If it doesn&#039;t work, try to flash it again, and if that doesn&#039;t work, try flashing the programmer again yet another time, just for kicks.&lt;br /&gt;
&lt;br /&gt;
PS: I tried enabling &#039;&#039;&#039;MANUAL_MESH_LEVELING&#039;&#039;&#039;, which in the code says that &#039;&#039;If used with a 1284P board the bootscreen will be disabled to save space&#039;&#039;. This effectively disabled the whole thing, and apparently may be making the firmware image a wee bit too large for it to fit the 1284P on the ender. It works well without it, though.&lt;br /&gt;
&lt;br /&gt;
== And then… ==&lt;br /&gt;
&lt;br /&gt;
With the new firmware in place, the printer should work as before, although with thermal runaway protection to better avoid fires in case the shit hits the fan, and to allow for things like autolevelling. With any luck, [https://www.precisionpiezo.co.uk/ this thing] may be ready for use by the time you read this - it surely looks nice!&lt;br /&gt;
&lt;br /&gt;
roy&lt;/div&gt;</summary>
		<author><name>Roy</name></author>
	</entry>
	<entry>
		<id>https://wiki.malinux.no/index.php?title=Roy%27s_notes&amp;diff=152</id>
		<title>Roy&#039;s notes</title>
		<link rel="alternate" type="text/html" href="https://wiki.malinux.no/index.php?title=Roy%27s_notes&amp;diff=152"/>
		<updated>2020-01-28T02:05:20Z</updated>

		<summary type="html">&lt;p&gt;Roy: /* Growing filesystems */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= LVM, md and friends =&lt;br /&gt;
&lt;br /&gt;
== Linux&#039; Logical Volume Manager (LVM) ==&lt;br /&gt;
&lt;br /&gt;
=== LVM in general ===&lt;br /&gt;
&lt;br /&gt;
LVM is designed to be an abstraction layer on top of physical drives or RAID, typically [https://raid.wiki.kernel.org/index.php/RAID_setup mdraid] or [https://help.ubuntu.com/community/FakeRaidHowto fakeraid]. Keep in mind that fakeraid should be avoided unless you really need it, like in conjunction with dual-booting linux and windows on fakeraid. LVM broadly consists of three elements, the &amp;quot;physical&amp;quot; devices (PV), the volume group (VG) and the logical volume (LV). There can be multiple PVs, VGs and LVs, depending on requirement. More about this below. All commands are given as examples, and all of them can be fine-tuned using extra flags in need of so. In my experience, the defaults work well for most usecases.&lt;br /&gt;
&lt;br /&gt;
I&#039;m mentioning filesystem below too. Where I write ext4, the samme applies to ext2 and ext3.&lt;br /&gt;
&lt;br /&gt;
==== Create a PV ====&lt;br /&gt;
&lt;br /&gt;
A PV is the &amp;quot;physical&amp;quot; parts. This does not need to be a physical disk, but can also be another RAID, be it an mdraid, fakeraid, hardware raid, a virtual disk on a SAN or otherwisee or a partition on one of those. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#  These add three PVs, one on a drive (or hardware raid) and another two on mdraids.&lt;br /&gt;
pvcreate /dev/sdb&lt;br /&gt;
pvcreate /dev/md1 /dev/md2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For more information about pvcreate, see [https://linux.die.net/man/8/pvcreate the manual].&lt;br /&gt;
&lt;br /&gt;
==== Create a VG ====&lt;br /&gt;
&lt;br /&gt;
The volume group consists of one or more PVs grouped together on which LVs can be placed. If several PVs are grouped in a VG, it&#039;s generally a good idea to make sure these PVs have some sort of redundancy, as in mdraid/fakeraid or hwraid. Otherwise it will be like using a [https://en.wikipedia.org/wiki/RAID RAID-0] with a single point of failure on each of the independant drives. LVM has [https://unix.stackexchange.com/questions/150644/raiding-with-lvm-vs-mdraid-pros-and-cons  RAID code in it] as well, so you can use that. I haven&#039;t done so myself, as I generally stick to mraid. The reason is mdraid is, in my opinion older and more stable and has more users (meaning bugs are reported and fixed faster whenever they are found). That said, I beleive the actual RAID code used in LVM RAID are the same function calls as for mdraid, so it may not be much of a difference. I still stick with mdraid. To create a VG, run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create volume group my_vg&lt;br /&gt;
vgcreate my_vg /dev/md1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that if vgcreate is run with a PV (as /dev/md1 above) that is not defined as a PV (like above), this is done implicitly, so if you don&#039;t need any special flags to pvcreate, you can simply skip it and let vgcreate do that for you.&lt;br /&gt;
&lt;br /&gt;
==== Create an LV ====&lt;br /&gt;
&lt;br /&gt;
LVs can be compared to partitions, somehow, since they are bounderies of a fraction or all of that of a VG. The difference between them and a partition, however, is that they can be grown or shrunk easily and also moved around between PVs without downtime. This flexibility makes them superiour to partitions as your system can be changed without users noticing it. By default, an LV is alloated &amp;quot;thickly&amp;quot;, meaning all the data given to it, is allocated from the VG and thus the PV. The following makes a 100GB LV named &amp;quot;thicklv&amp;quot;. When making an LV, I usually allocate what&#039;s needed plus some more, but not everything, just to make sure it&#039;s space available for growth on any of the LVs on the VG, or new LVs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a thick provisioned LV named thicklv on the VG my_vg&lt;br /&gt;
lvcreate -n thicklv -L 100G my_vg&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After the LV is created, a filesystem can be placed on it unless it is meant to be used directly. The application for direct use include swap space, VM storage and certain database systems. Most of these will, however, work on filesystems too, although my testing has shown that on swap space, there is a significant performance gain for using dedicated storage without a filesystem. As for filesystems, most Linux users use either ext4 or xfs. Personally, I generally use XFS these days. See my notes below on filesystem choice.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a filesystem on the LV - this could have been mkfs -t ext4 or whatever filesystem you choose&lt;br /&gt;
mkfs -t xfs /dev/my_vg/thicklv&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then just edit /etc/fstab with correct data and run mount -a, and you should be all set.&lt;br /&gt;
&lt;br /&gt;
==== Create LVM cache ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
lvcreate -L 1G -n _cache_meta data /dev/md1&lt;br /&gt;
&lt;br /&gt;
lvcreate -l100%FREE -n _cache data /dev/md1&lt;br /&gt;
&lt;br /&gt;
# Some would want --cachemode writeback, but seriously, I wouldn&#039;t recommend it. Metadata or data can be easily corrupted in case of failure.&lt;br /&gt;
lvconvert --type cache-pool --cachemode writethrough --poolmetadata data/_cache_meta data/_cache&lt;br /&gt;
&lt;br /&gt;
lvconvert --type cache --cachepool data/_cache data/data&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Disabling LVM cache ====&lt;br /&gt;
&lt;br /&gt;
If you for some reason want to disable caching, this will do it cleanly and remove the LVs earlier created for caching the main device.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
lvconvert --uncache data/data&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Growing devices ====&lt;br /&gt;
&lt;br /&gt;
LVM objects can be grown and shrunk. If a PV resides on a RAID where a new drive has been added or otherwise grown, or on a partition or virtual disk that has been extended, the PV must be updated to reflect these changes. The following command will grow the PV to the maximum available on the underlying storage. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Resize the PV /dev/md (not the RAID, only the PV on the RAID) to its full size&lt;br /&gt;
pvresize /dev/md1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If a new PV is added, the VG can be grown to add the space on that in addition to what&#039;s there already. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Extend my_vg to include md2 and its space&lt;br /&gt;
vgextend my_vg /dev/md2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
With more space available in the VG, the LV can now be extended. Let&#039;s add another 50GB to it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Extend thicklv - add 50GB. If you know you won&#039;t need the space anywhere else, you may want to&lt;br /&gt;
# lvresize -l+100%FREE instead. Keep in mind the difference between -l (extents) and -L (bytes)&lt;br /&gt;
lvresize -L +50G my_vg/thicklv&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Growing filesystems ====&lt;br /&gt;
After the LV has grown, run &#039;&#039;xfs_growfs&#039;&#039; (xfs) or &#039;&#039;resize2fs&#039;&#039; (ext4) to make use of the new data. To grow the filesystem to all available space on ext4, run the below command.  To partly grow the filesystem or to shrink it or otherwise, please see the manuals.&lt;br /&gt;
&lt;br /&gt;
The filesystem can be mounted when this is run. If you for some reason get an &#039;&#039;&#039;access denied&#039;&#039;&#039; error when running this as root or with sudo, it&#039;s likely caused by a filesystem error. To fix this, unmount the filesystem first and run &#039;&#039;&#039;fsck -f /dev/my_vg/thicklv&#039;&#039;&#039; and remount it before retrying to extend it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
resize2fs /dev/my_vg/thicklv&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Similarly, with XFS, but note that xfs_growfs doesn&#039;t take the device name, but the filesystem&#039;s mount point. In the case of XFS, also note that the filesystem &#039;&#039;&#039;&#039;&#039;must&#039;&#039;&#039;&#039;&#039; be mounted to be grown. This, in contrast to how it was in the old days when filesystems had to be unmounted to be grown.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
xfs_growfs /my_mountpoint&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Rename system VG ====&lt;br /&gt;
&lt;br /&gt;
Some distros create VG names like those-from-a-sysadmin-with-a-well-developed-paranoia-not-to-hit-a-duplicate. Debian, for instance, uses names like &amp;quot;my-full-hostname-vg&amp;quot;. Personally, I don&#039;t like these, since if I were to move a disk or vdisk around to somewhere else, I&#039;d make sure not to add a disk named &#039;sys&#039; to an existing system. If you do, most distros will refuse to use the VGs with duplicate names, resulting in the OS not booting until either one is specified by its UUID or just one removed. As I&#039;m aware of this, I stick to the super-risky thing of all system VGs named &#039;sys&#039; and so on.&lt;br /&gt;
&lt;br /&gt;
If you do this, keep in mind that it may blow up your computer and take your girl- or boyfriend with it or even make either of them pregnant, allowing Trump to rule your life and generally make things suck. You&#039;re on your own!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Rename the VG&lt;br /&gt;
vgrename my-full-hostname-vg sys&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, in /boot/grub/grub.cfg, change the old lv path from something like &#039;/dev/mapper/debian--stretch--machine--vg-root&#039; to your new and fancy &#039;/dev/sys/root. Likewise, in /etc/fstab, change occurences of &#039;/dev/mapper/debian--stretch--machine--vg-&#039; (or similar) with &#039;/dev/sys/&#039;. Here, this was like this - the old ones commented out.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;fstab&amp;quot;&amp;gt;&lt;br /&gt;
#/dev/mapper/debian--stretch--box--vg-root      /               ext4            errors=remount-ro,discard       0       1&lt;br /&gt;
/dev/sys/root                                   /               ext4            errors=remount-ro,discard       0       1&lt;br /&gt;
# /boot was on /dev/vda1 during installation&lt;br /&gt;
UUID=myverylonguuidwithatonofgoodinfoinit       /boot           ext2            defaults                        0       2&lt;br /&gt;
#/dev/mapper/debian--stretch--box--vg-swap_1    none            swap            sw                              0       0&lt;br /&gt;
/dev/sys/swap_1                                 none            swap            sw                              0       0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Update /etc/initramfs-tools/conf.d/resume with similar data for swap.&lt;br /&gt;
&lt;br /&gt;
You might want to run &#039;update-initramfs -u -k all&#039; after this, but I&#039;m not sure if it&#039;s needed.&lt;br /&gt;
&lt;br /&gt;
Now, pray to the nearest god(s) and give it a reboot and it should (probably) work.&lt;br /&gt;
&lt;br /&gt;
After reboot, run &#039;&#039;&#039;swapoff -a&#039;&#039;&#039;, then &#039;&#039;&#039;mkswap /dev/sys/swap_1&#039;&#039;&#039; (or whatever it&#039;s called on your system) and &#039;&#039;&#039;swapon -a&#039;&#039;&#039; again. You may want to give it another reboot or two for kicks, but it should work well even without that.&lt;br /&gt;
&lt;br /&gt;
=== Migration tools ===&lt;br /&gt;
&lt;br /&gt;
At times, storage regimes change, new storage is added and sometimes it&#039;s not easy to migrate with the current hardware or its support systems. Once I had to migrate a 45TiB fileserver from one storage system to another, preferably without downtime. The server originally had three 15TiB PVs of which two were full and the third half full. I resorted to using [https://linux.die.net/man/8/pvmove pvmove] to just move the data on the PVs in use to a new PV. We started out with creating a new 50TiB PV, sde, and then to pvmove.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Attach /dev/sde to the VG my_vg&lt;br /&gt;
vgextend my_vg /dev/sde&lt;br /&gt;
&lt;br /&gt;
# Move the contents from /dev/sdb over to /dev/sde block by block. If a target is not given in pvmove,&lt;br /&gt;
# the contents of the source (sdb here) will be put somewhere else in the pool.&lt;br /&gt;
pvmove /dev/sdb /dev/sde&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This took a while (as in a week or so) - the pvmove command uses old code and logic (or at least did that when I migrated this in November 2016), but it affected performance on the server very little, so users didn&#039;t notice. After the first PV was migrated, I continued with the other two, one after the other, and after a month or so, it was migrated. We used this on a number of large fileservers, and it worked flawlessly. Before doing the production servers I also tried interrupting pvmove in various ways, including hard resets, and it just kept on after the reboot.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;NOTE:&#039;&#039;&#039;&#039;&#039; &#039;&#039;Even though it worked well for us, &#039;&#039;&#039;always&#039;&#039;&#039; keep a good backup before doing this. Things may go wrong, and without a good backup, you may be looking for a hard-to-find new job the next morning&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
==== mdadm workarounds ====&lt;br /&gt;
&lt;br /&gt;
===== Migrate from a mirror (raid-1) to raid-10 =====&lt;br /&gt;
&lt;br /&gt;
Create a mirror&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sdb /dev/sdc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
LVM (pv/vg/lv) on md0 (see above), put a filesystem on the lv and fill it with some data.&lt;br /&gt;
&lt;br /&gt;
Now, some months later, you want to change this to raid-10 to allow for the same amount of redundancy, but to allow more disks into the system.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mdadm --grow /dev/md0 --level=10&lt;br /&gt;
mdadm: Impossibly level change request for RAID1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So - no - doesn&#039;t work. But - we&#039;re on &lt;br /&gt;
&lt;br /&gt;
Since we&#039;re on lvm already, this&#039;ll be easy. If you&#039;re using filesystems directly on partitions, you can do this the same way, but without the pvmove part, using rsync or whateever you like instead. I&#039;d recommend using lvm for for the new raid, which should be rather obvious from this article. Now plug in a new drive and create a new raid10 on that one. If you two new drives, install both. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# change &amp;quot;missing&amp;quot; to the other device name if you installed two new drives&lt;br /&gt;
mdadm --create /dev/md1 --level=10 --raid-devices=2 /dev/vdd missing&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, as described above, just vgextend the vg, adding the new raid and run pvmove to move the data from the old pv (residing on the old raid1) to the new pv (on raid10). Afte rpvmove is finished (which may take awile, see above), just&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
vgreduce raidtest /dev/md0&lt;br /&gt;
pvremove /dev/md0&lt;br /&gt;
mdadm --stop /dev/md0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
…and your disk is free to be added to the new array. If the new raid is running in degraded mode (if you created it with just one drive), better don&#039;t wait too long, since you don&#039;t have redundancy. Just mdadm --add the devs.&lt;br /&gt;
&lt;br /&gt;
If you now have /dev/mdstat telling you your raid10 is active and have three drives, of which one is a spare, it should look something like this&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5] [raid4] [raid10]&lt;br /&gt;
md1 : active raid10 vdc[3](S) vdb[2] vdd[0]&lt;br /&gt;
      8380416 blocks super 1.2 2 near-copies [2/2] [UU]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Just mdadm --grow --raid-devices=3 /dev/md1&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;RAID section is not complete. I&#039;ll write more on migraing from raid10 to raid6 later. It&#039;s not straight forward, but easier than this one :)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== Thin provisioned LVs ===&lt;br /&gt;
&lt;br /&gt;
Thin provisioning on LVM is a method used for not allocating all the space given to an LV. For instance, if you have a 1TB VG and want to give an LV 500GB, although it currently only uses a fraction of that, a thin lv can be a good alternative. This will allow for adding a limit to how much it can use, but also to let it grow dynamically without manual work by the sysadmin. Thin provisioning adds another layer of abstaction by creating a special LV as a &#039;&#039;thin pool&#039;&#039; from which data is allocated to the &#039;&#039;thin volume(s)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== Create a thin pool ====&lt;br /&gt;
&lt;br /&gt;
Allocate 1TB to the thin pool to be used for thinly provisioned LVs. Keep in mind that the space allocated to the thin pool is in fact thick provisioned. Only the volumes put on &#039;&#039;thinpool&#039;&#039; are thin provisioned. This will create two hidden LVs, one for data and one for metadata. Normally the defaults will do, but check the manual if the data doesn&#039;t match the usual patterns (such as billions of files, resulting in huge amounts of metadata). I &#039;&#039;beleive&#039;&#039; the metadata part should be resizable at a later time if needed, but I have not tested it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a pool for thin LVs. Keep in mind that the pool itself is not thin provisioned, only the volumes residing on it&lt;br /&gt;
lvcreate --size 1T --type thin-pool --thinpool thinpool my_vg&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Create a thin volume ====&lt;br /&gt;
&lt;br /&gt;
You have the thinpool, now put a thin volume on it. It will allocate some space for metadata, but probably not much (a few megs, perhaps).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Now, create a volume with a virtual (-V) size of half a terabyte named thin_pool, but using the thinpool (-T) named thin_pool for storage&lt;br /&gt;
lvcreate -V 500G -T my_vg/thin_pool --name thinvol&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The new volume&#039;s device name will be /dev/thinvol. Now, create a filesystem on it, add to fstab and mount it. The &#039;&#039;&#039;df&#039;&#039;&#039; command will return available space according to the virtual size (-V), while lvs will show how much data is actually used on each of the thinly provisioned volumes.&lt;br /&gt;
&lt;br /&gt;
== Filesystem dilemmas ==&lt;br /&gt;
&lt;br /&gt;
=== XFS or ext4 or something else ===&lt;br /&gt;
The choice of filesystem varies for your use. Distros such as RHEL/CentOS has moved to XFS by default from v7. Debian/Ubuntu still sticks to ext4, like most other. I&#039;ll discuss my thoughts below on ext4 vs XFS and leave the other filesystems for later.&lt;br /&gt;
&lt;br /&gt;
==== ext4 ====&lt;br /&gt;
ext4 is probably the most used filesystem on linux as of writing. It&#039;s rock stable and has been extended by a lot of extensions since the original ext2. It still retains backward compatibility, being able to mount and fsck ext2 and ext3 with the ext4 driver. However, it doesn&#039;t handle large filesystems very well. If a filesystem is created for &amp;lt;16TiB, it cannot be grown to anything larger than 16TiB. This may have changed lately, though. One other issue is handling errors. If a large filesystem (say 10TiB) is damaged, an fsck may take several hours, leading to long downtime. When I refer to ext4 further in this text, the same applies to ext2 and ext3 unless otherwise specified.&lt;br /&gt;
&lt;br /&gt;
==== XFS ====&lt;br /&gt;
XFS, originally developed by SGI some time in the bronze age, but has been worked on heavily after that. RHEL and Centos version 7 and forward, uses XFS as the default filesystem. It is quick, it scales well, but it lacks at least two things ext4 has. It cannot be shrunk (not that you normally need that, but nice if you have a typo or you need to change things). Also, it doesn&#039;t allow for automatic fsck on bootup. If something is messed up on the filesystem, you&#039;ll have to login as root on the console (not ssh), which might be an issue on some systems. The fsck equivalent, xfs_repair, is a *lot* faster than ext4&#039;s fsck, though.&lt;br /&gt;
&lt;br /&gt;
==== ZFS ====&lt;br /&gt;
ZFS is like a combination of RAID, LVM and a filesystem, supporting full checksumming, auto-healing (given sufficient redundancy), compression, encryption, replication, deduplication (if you&#039;re brave and have a &#039;&#039;ton&#039;&#039; of memory) and a lot more. It&#039;s a separate chapter and needs a lot more talk than paragraph here.&lt;br /&gt;
&lt;br /&gt;
== Low level disk handling ==&lt;br /&gt;
&lt;br /&gt;
This section is for low-level handling of disks, regardless of storage system elsewhere. These apply to mdraid, lvmraid and zfs and possibly other solutions, with the exception of individual drives on hwraid (and maybe fakeraid), since there, the drives are hidden from Linux (or whatever OS).&lt;br /&gt;
&lt;br /&gt;
=== S.M.A.R.T. and slow drives ===&lt;br /&gt;
Modern (that is, from about 1990 or later) have S.M.A.R.T. (or just smart, since it&#039;s easier to type) monitoring built in, meaning the disk&#039;s controller is monitoring itself. This is handy and will ideally tell you in advance that a drive is flakey or dying. Modern (2010+) smart monitoring is more or less the same. It can be trusted about 50% of the time. Usually, if smart detects an error, it&#039;s a real error. I don&#039;t think I&#039;ve seen it reporting a false positive, but others may know better. &lt;br /&gt;
&lt;br /&gt;
==== smartmontools ====&lt;br /&gt;
First, install smartmontool and run smartclt -H /dev/yourdisk (/dev/sda or something) to get a health report. Then perhaps run smartctl -a /dev/yourdisk and look for &#039;current pending sectors&#039; This should be zero. Also check the temperature, which normally should be much above 50.&lt;br /&gt;
&lt;br /&gt;
==== single, slow drive ====&lt;br /&gt;
What may happen, is smart not seeing anything and life goes on like before, only slower and less prouductive, without telling anyone. If you stubler over this issue, you&#039;ll probably see it during a large rsync/zfs send/receive or a resync/rebuild/resilver of the raid/zpool. During this, it feels like everything is slow and your RAID has turned into a RAIF (redundant array of inexpensive floppies). To check if you have a single drive messing up it all, check with &#039;&#039;&#039;iostat -x 2&#039;&#039;&#039;, having 2 being the delay between each measurement. Interrupt it with ctrl+x. If there&#039;s a rougue drive there, it should stand out like sdg below&lt;br /&gt;
&lt;br /&gt;
 avg-cpu:  %user   %nice %system %iowait  %steal   %idle&lt;br /&gt;
            0.38    0.00    1.75    0.00    0.00   97.87&lt;br /&gt;
&lt;br /&gt;
 Device            r/s     w/s     rkB/s     wkB/s   rrqm/s   wrqm/s  %rrqm  %wrqm r_await w_await aqu-sz rareq-sz wareq-sz  svctm  %util&lt;br /&gt;
 sda              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdb              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdc              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdd              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sde              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdf              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdg              3.50    0.00   2352.00      0.00     0.00     0.00   0.00   0.00 14306.29    0.00  13.85   672.00     0.00 285.71 100.00&lt;br /&gt;
 sdh              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
&lt;br /&gt;
In ZFS land, you should be able to get similar data with &#039;&#039;&#039;zpool iostat -v &amp;lt;pool&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Now you know the bad drive (sdg), pull it from the raid with &#039;&#039;&#039;mdadm --fail /dev/mdX /dev/sdX&#039;&#039;&#039;. Now test the drive&#039;s performance manually, just simply:&lt;br /&gt;
&lt;br /&gt;
 # hdparm -t /dev/sdg&lt;br /&gt;
 &lt;br /&gt;
 /dev/sdg:&lt;br /&gt;
  Timing buffered disk reads:   2 MB in  5.37 seconds = 381.46 kB/sec&lt;br /&gt;
&lt;br /&gt;
Bingo - nothing you&#039;d want to keep. For a good drive, it should be something like 100-200MB/s&lt;br /&gt;
&lt;br /&gt;
PS: Keep in mind that you have a degraded RAID by now in case you had a spare waiting for things to happen.&lt;br /&gt;
&lt;br /&gt;
Try to replace the cable and/or try the disk on another port/controller. If the result from hdparm persists, it&#039;s probably a bad cable&lt;br /&gt;
&lt;br /&gt;
So, then, just psycially locate the drive, pull it out, take out the discs and magnets and recycle the rest.&lt;br /&gt;
&lt;br /&gt;
=== &amp;quot;Unplug&amp;quot; drive from system ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Find the device unit&#039;s number with something like&lt;br /&gt;
find /sys/bus/scsi/devices/*/block/ -name sdd&lt;br /&gt;
# returning /sys/bus/scsi/devices/3:0:0:0/block/sdd here, &lt;br /&gt;
# meaning 3:0:0:0 is the SCSI device we&#039;re looking for.&lt;br /&gt;
&lt;br /&gt;
# Given this is the correct device, and you want to &#039;unplug&#039; it, do so by&lt;br /&gt;
echo 1 &amp;gt; /sys/bus/scsi/devices/3:0:0:0/delete&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Rescan disk controllers ===&lt;br /&gt;
If a drive is added and for some reason doesn&#039;t get detected, or is removed by the command above, it can be rediscovered with a sysfs command to the scsi host to which it is connected. Since there may be quite a few of these, an easy way is to just scan them all and check the output of &#039;&#039;&#039;dmesg -T&#039;&#039;&#039; after running it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Make a list of controllers and send a rescan message to each of them. It won&#039;t do anything &lt;br /&gt;
# for those where nothing has changed, but it will show new drives where they have been added.&lt;br /&gt;
for host_scan in /sys/class/scsi_host/host*/scan&lt;br /&gt;
do&lt;br /&gt;
  echo &#039;- - -&#039; &amp;gt; $host_scan&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Fail injection with debugfs ===&lt;br /&gt;
[https://lxadm.com/Using_fault_injection https://lxadm.com/Using_fault_injection]&lt;br /&gt;
&lt;br /&gt;
== mdadm stuff ==&lt;br /&gt;
=== Spare pools ===&lt;br /&gt;
In the old itmes, mdadm supported only a dedicated spare per md device, so if working with a large set of drives (20? 40?), where you&#039;d want to setup more raid sets to increase redundancy, you&#039;d dedicate a spare to each of the raid sets. This has changed (some time ago?), so in these modern, heathen days, you can change mdadm.conf, usually placed under /etc/mdadm, and add &#039;spare-group=somegroup&#039; where &#039;somegroup&#039; is a string identifying the spare group. After doing this, run &#039;&#039;&#039;update-initramfs -u&#039;&#039;&#039; and reboot and add a spare to one of the raid sets in the spare group, and md will use that or those spares for all the raidsets in that group.&lt;br /&gt;
&lt;br /&gt;
As some pointed out on #linux-raid @ irc.freenode.net, this feature is very badly documented, but as far as I can see, it works well.&lt;br /&gt;
&lt;br /&gt;
==== Example config ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create two raidsets&lt;br /&gt;
&lt;br /&gt;
mdadm --create /dev/md1 --level=6 --raid-devices=6 /dev/vd[efghij]&lt;br /&gt;
mdadm --create /dev/md2 --level=6 --raid-devices=6 /dev/vd[klmnop]&lt;br /&gt;
&lt;br /&gt;
# get their UUID etc&lt;br /&gt;
&lt;br /&gt;
mdadm --detail --scan&lt;br /&gt;
ARRAY /dev/md/1 metadata=1.2 name=raidtest:1 UUID=1a8cbdcb:f4092350:348b6b80:c054d74c&lt;br /&gt;
ARRAY /dev/md/2 metadata=1.2 name=raidtest:2 UUID=894b1b7c:cb7eba70:917d6033:ea5afd2b&lt;br /&gt;
&lt;br /&gt;
# Put those lines into /etc/mdadm/mdadm.conf and and add the spare-group&lt;br /&gt;
&lt;br /&gt;
ARRAY /dev/md/1 metadata=1.2 name=raidtest:1 spare-group=raidtest UUID=1a8cbdcb:f4092350:348b6b80:c054d74c&lt;br /&gt;
ARRAY /dev/md/2 metadata=1.2 name=raidtest:2 spare-group=raidtest UUID=894b1b7c:cb7eba70:917d6033:ea5afd2b&lt;br /&gt;
&lt;br /&gt;
# update the initramfs and reboot&lt;br /&gt;
&lt;br /&gt;
update-initramfs -u&lt;br /&gt;
reboot&lt;br /&gt;
&lt;br /&gt;
# add a spare drive to one of the raids&lt;br /&gt;
&lt;br /&gt;
mdadm --add /dev/md1 /dev/vdq&lt;br /&gt;
&lt;br /&gt;
# fail a drive on the other raid&lt;br /&gt;
&lt;br /&gt;
mdadm --fail /dev/md2 /dev/vdn&lt;br /&gt;
&lt;br /&gt;
# check /proc/mdstat to see md2 rebuilding with the spare from md1&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Recovery ===&lt;br /&gt;
&lt;br /&gt;
The other day, I came across a problem a user had on #linux-raid@irc.freenode.net. He had an old Qnap NAS that had died and tried plugging the drives in to his Linux machine and got various errors. The two-drive RAID-1 did not come up as it should, &#039;&#039;&#039;dmesg&#039;&#039;&#039; was full of errors from one of the drives (both connected on USB) and so forth.&lt;br /&gt;
&lt;br /&gt;
We went on and started by taking down the machine and just connecting one of the drives. I had him check what was assembled with&lt;br /&gt;
&lt;br /&gt;
 cat /proc/mdstat&lt;br /&gt;
&lt;br /&gt;
That returned /proc/md127 assembled, but LVM didn&#039;t find anything. So running a manual scan&lt;br /&gt;
&lt;br /&gt;
 pvscan --cache /dev/md127&lt;br /&gt;
&lt;br /&gt;
This made linux find the PV, VG and a couple of LVs, but probably because the mdraid was degraded, the LVs were deactivated, according to &#039;&#039;&#039;lvscan&#039;&#039;&#039;. Activating the one with a filesystem manually&lt;br /&gt;
&lt;br /&gt;
 lvchange -a y /dev/&amp;lt;vg&amp;gt;/&amp;lt;lv&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Substitute &amp;lt;vg&amp;gt; and &amp;lt;lv&amp;gt; with the names listed by vgs and lvs.&lt;br /&gt;
&lt;br /&gt;
This worked, and the filesystem on /dev/&amp;lt;vg&amp;gt;/&amp;lt;lv&amp;gt; could be mounted correctly.&lt;br /&gt;
&lt;br /&gt;
== Tuning ==&lt;br /&gt;
&lt;br /&gt;
While trying to compare a 12-disk RAID (8TB disks) to a hwraid, mdraid was slower, so we did a few things to speed things up:&lt;br /&gt;
&lt;br /&gt;
While testing with [https://linux.die.net/man/1/fio fio], monitor /sys/block/md0/md/stripe_cache_active, and see if it&#039;s close to /sys/block/md0/md/stripe_cache_size. If it is, double the size of the latter&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
echo 4096 &amp;gt; /sys/block/md0/md/stripe_cache_size&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Continue until stripe_cache_active stabilises, and then you&#039;ve found the limit you&#039;ll need. You may want to double that for good measure. &lt;br /&gt;
&lt;br /&gt;
(to be continued)&lt;br /&gt;
&lt;br /&gt;
== Links ==&lt;br /&gt;
&lt;br /&gt;
Below are a few links with useful info&lt;br /&gt;
&lt;br /&gt;
* [https://raid.wiki.kernel.org/index.php/Irreversible_mdadm_failure_recovery Irreversible mdadm failure recovery]&lt;br /&gt;
&lt;br /&gt;
= ZFS =&lt;br /&gt;
&lt;br /&gt;
ZFS can do a lot of things most filesystems or volume managers can&#039;t. It checksums all data and metadata and so long that the system uses ECC enabled memory (RAM), it will have complete control over the whole data set, and when (not if) an error occurs, it&#039;ll fix the issue without even throwing a warning. To fix the issue, you&#039;ll obviously need sufficient redundancy (mirrors or RAIDzN). &lt;br /&gt;
&lt;br /&gt;
== ZFS send/receive between machines ==&lt;br /&gt;
&lt;br /&gt;
ZFS has a send/receive mechanism that allows for snapshots to be sent over the wire to a receiving end. This can be a full filesystem, or an incremental change since last send/reveive. In a WAN scenario, you&#039;ll probably want to use VPN for this. On a controlled network, sending in cleartext is also possible. You may as well use ssh, but keep in mind that ssh was never designed to be used as a fullblown vpn solution and is just too slow or the task with large amounts of data. You may, though, use mbuffer, if on a loal LAN.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Allow traffic from the sending IP in whatever firewall interface you&#039;re using (if you&#039;re using a firewall at all, that is)&lt;br /&gt;
ufw allow from x.x.x.x&lt;br /&gt;
# &lt;br /&gt;
# Start the receiver first. This listens on port 9090, has a 1GB buffer,&lt;br /&gt;
    and uses 128kb chunks (same as zfs):&lt;br /&gt;
&lt;br /&gt;
mbuffer -s 128k -m 1G -I 9090 | zfs receive data/filesystem&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To be continued one day… See [https://everycity.co.uk/alasdair/2010/07/using-mbuffer-to-speed-up-slow-zfs-send-zfs-receive/ this] for some more. I&#039;ll get back with details on it.&lt;br /&gt;
&lt;br /&gt;
= General Linux system control =&lt;br /&gt;
&lt;br /&gt;
== Add a new CPU (core) ==&lt;br /&gt;
&lt;br /&gt;
If working with virtual machines, adding a new core can be useful if the VM is slow and the load is multithreaded or multiprocess. To do this, add a new CPU in the hypervisor (be it KVM or VMware or Hyper-V or whatever). Some hypervisors, like VMware, will activate it automatically if open-vm-tools is installed. Please note that open-vm-tools is for VMware only. I don&#039;t know of any such thing for KVM or other hypervisors (although I beleive VirtualBox has its own set of tools, but not as a package). If this doesn&#039;t work, run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
echo 1 &amp;gt; /sys/devices/system/cpu/cpuX/online&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where X is the CPU number you want to add. You can &#039;cat /sys/devices/system/cpu/cpuX/online&#039; to check if it&#039;s online.&lt;br /&gt;
&lt;br /&gt;
= Mount partitions on a disk image =&lt;br /&gt;
&lt;br /&gt;
Sometimes you&#039;ll have a disk image, either from recovering a bad drive after hours (or days or weeks) of ddrescue, and sometimes you just have a disk image from a virtual machine where you want to mount the partitions inside the image. There are three main methods of doing this, which are more or less synonmous, but some easier than the other.&lt;br /&gt;
&lt;br /&gt;
== Basics ==&lt;br /&gt;
&lt;br /&gt;
A disk image is usually like a disk, consisting of either a large filesystem, a PV or a partition table with one or partitions onto which resides a filesystem, a pv, swap or something else. If it&#039;s partitioned, and you want your operating system to mount a filesystem or allow it to see whatever LVM stuff lies on it, you need to isolate the partitions. &lt;br /&gt;
&lt;br /&gt;
== Manual mapping ==&lt;br /&gt;
&lt;br /&gt;
In the oldern days, this was done manually, something like this&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
root@mymachine:~# fdisk -l /dev/vda&lt;br /&gt;
Disk /dev/vda: 25 GiB, 26843545600 bytes, 52428800 sectors&lt;br /&gt;
Units: sectors of 1 * 512 = 512 bytes&lt;br /&gt;
Sector size (logical/physical): 512 bytes / 512 bytes&lt;br /&gt;
I/O size (minimum/optimal): 512 bytes / 512 bytes&lt;br /&gt;
Disklabel type: dos&lt;br /&gt;
Disk identifier: 0xc37b7ea5&lt;br /&gt;
&lt;br /&gt;
Device     Boot    Start      End  Sectors  Size Id Type&lt;br /&gt;
/dev/vda1  *        2048 50333311 50331264   24G 83 Linux&lt;br /&gt;
/dev/vda2       50333312 52426369  2093058 1022M  5 Extended&lt;br /&gt;
/dev/vda5       50333314 52426369  2093056 1022M 82 Linux swap / Solaris&lt;br /&gt;
root@mymachine:~#&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To calculate the start and end of each partition, you just take the start sector and multiply it by the sector size (512 bytes here) and you have the offset in bytes. After this, it&#039;s merely an losetup -o &amp;lt;offset&amp;gt; /dev/loopX &amp;lt;nameofimagefile&amp;gt; and you have the partition mapped to your /dev/loopX (having X being something typically 0-255. After this, just mount it or run pvscan/vgscan/lvscan to probe whatever lvm config is there, and you should be able to mount it like any other filesystem.&lt;br /&gt;
&lt;br /&gt;
== kpartx ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;kpartx&#039;&#039;&#039; does the same as above, more or less, just without so much hassle. Most of it should be automatic and easy to deal with, except it may fail to disconnect the loopback devices sometimes, so you may have to &#039;&#039;&#039;losetup -d&#039;&#039;&#039; them manually. See the manual, &#039;&#039;&#039;kpartx (8)&#039;&#039;&#039;. Please note that &#039;&#039;&#039;partx&#039;&#039;&#039; works similarly and I&#039;d guess the authors of the two tools are arguing a lot of which one&#039;s the best.&lt;br /&gt;
&lt;br /&gt;
== guestmount ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;guestmount&#039;&#039;&#039; is something similar again, but also supports file formats like &#039;&#039;&#039;qcow2&#039;&#039;&#039; and possibly other, proprietary filesystems like &#039;&#039;&#039;vmdk&#039;&#039;&#039; and &#039;&#039;&#039;vdi&#039;&#039;&#039;, but don&#039;t take my word for it - I haven&#039;t tested. Again, see the manual or just read up on the description [http://ask.xmodulo.com/mount-qcow2-disk-image-linux.html?fbclid=IwAR3snTeZvGzp9PLdX11EQhCfOpux6I93CiJ3A2pUomkkRLly9Xo4851mkTY here]. It seems rather trivial.&lt;br /&gt;
&lt;br /&gt;
= Linux on laptops =&lt;br /&gt;
&lt;br /&gt;
== Wifi with HP EliteBook 725/745 on Ubuntu ==&lt;br /&gt;
&lt;br /&gt;
The HP EliteBook 725/745 and similar are equipped with a BCM4352 wifi chip. As with a lot of other stuff from Broadcom, this lacks an open hardware description, so thus no open driver exist. The proper fix, is to replace the NIC with something with an open driver, but again, this isn&#039;t always possible, so a binary driver exists. In ubuntu, run, somehow connect the machine to the internet and run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install bcmwl-kernel-source&lt;br /&gt;
sudo modprobe wl&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you can&#039;t connect the machine to the internet, download the needed packages on another machine and put it on some usb storage. These packages should suffice:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# apt-cache depends bcmwl-kernel-source&lt;br /&gt;
bcmwl-kernel-source&lt;br /&gt;
  Depends: dkms&lt;br /&gt;
  Depends: linux-libc-dev&lt;br /&gt;
  Depends: libc6-dev&lt;br /&gt;
  Conflicts: &amp;lt;bcmwl-modaliases&amp;gt;&lt;br /&gt;
  Replaces: &amp;lt;bcmwl-modaliases&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then install manually with &#039;&#039;&#039;dpkg -i file1.deb file2.deb&#039;&#039;&#039; etc&lt;br /&gt;
&lt;br /&gt;
After this, ip/ifconfig/iwconfig shouldd see the new wifi nic, probably &#039;&#039;&#039;wlan0&#039;&#039;&#039;, but due to a [https://bugs.launchpad.net/ubuntu/+source/broadcom-sta/+bug/1343151 old, ignored bug], you won&#039;t find any wifi networks. This is because the driver from Broadcom apparently does not support interrupt remapping, commonly used on x64 machines. To turn this off, change &#039;&#039;&#039;/etc/default/grub&#039;&#039;&#039; and change the line &#039;&#039;&#039;GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;quiet splash&amp;quot;&#039;&#039;&#039;, adding intremap=off to the end before the quote: &#039;&#039;&#039;GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;quiet splash intremap=off&amp;quot;&#039;&#039;&#039;. Save the file and run &#039;&#039;&#039;sudo update-grub&#039;&#039;&#039; and reboot. After this, wifi should work well.&lt;br /&gt;
&lt;br /&gt;
== Wifi with HP Compaq Presario CQ57 on Ubuntu ==&lt;br /&gt;
&lt;br /&gt;
The HP Compaq Presario CQ57 uses the RT5390 wifi chipset. This has been supported for quite some time now, and I was quite surprised to find it not working on a laptop a friend was having. The driver loaded correctly, but Ubuntu insisted of the laptop being in &#039;&#039;&#039;flight mode&#039;&#039;&#039;. Checking &#039;&#039;&#039;rfkill&#039;&#039;&#039;, it showed me two NICs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# rfkill list all&lt;br /&gt;
0: phy0: Wireless LAN&lt;br /&gt;
	Soft blocked: no&lt;br /&gt;
	Hard blocked: yes&lt;br /&gt;
1: hp-wifi: Wireless LAN&lt;br /&gt;
	Soft blocked: yes&lt;br /&gt;
	Hard blocked: no&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Turning rfkill on and off resulted in nothing much, except some error messages in the kernel log (dmesg)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] ACPI Error: Field [B128] at bit offset/length 128/1024 exceeds size of target Buffer (160 bits) (20170831/dsopcode-235)&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]&lt;br /&gt;
                            Initialized Local Variables for Method [HWCD]:&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Local0: 00000000a34b7928 &amp;lt;Obj&amp;gt;           Integer 0000000000000000&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Local1: 00000000b0aa6865 &amp;lt;Obj&amp;gt;           Buffer(8) 46 41 49 4C 04 00 00 00&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Local5: 00000000a9811efd &amp;lt;Obj&amp;gt;           Integer 0000000000000004&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] Initialized Arguments for Method [HWCD]:  (2 arguments defined for method invocation)&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Arg0:   0000000078957d1b &amp;lt;Obj&amp;gt;           Integer 0000000000000001&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Arg1:   00000000725c9c6e &amp;lt;Obj&amp;gt;           Buffer(20) 53 45 43 55 02 00 00 00&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] ACPI Error: Method parse/execution failed \_SB.WMID.HWCD, AE_AML_BUFFER_LIMIT (20170831/psparse-550)&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] ACPI Error: Method parse/execution failed \_SB.WMID.WMAD, AE_AML_BUFFER_LIMIT (20170831/psparse-550)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After upgrading BIOS and testing different kernels, I was asked to try to unload the &#039;&#039;&#039;hp_wmi&#039;&#039;&#039; driver. I did, and things changed a bit, so I tried blacklisting it, creating the file &#039;&#039;&#039;/etc/modprobe.d/blacklist-hp_wmi.conf&#039;&#039;&#039; with the following content&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Blacklist this - it doesn&#039;t work!&lt;br /&gt;
blacklist hp_wmi&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
I gave the machine a reboot and afte that, the &#039;&#039;&#039;hp-wifi&#039;&#039;&#039; entry was gone in the rfkill output, and things works.&lt;br /&gt;
&lt;br /&gt;
== BIOS upgrade from Linux ==&lt;br /&gt;
&lt;br /&gt;
Generally, BIOS upgrades have been moved to the BIOS itself these days. This saves a lot of work and quite possibly lives after those who earier rammed their heads through walls, now can upgrade directly from the internet instead of using obscure operating systems best avoided. Sometimes, however, one must use these nevertheless. This is a quick run-through on your options.&lt;br /&gt;
&lt;br /&gt;
=== DOS ===&lt;br /&gt;
&lt;br /&gt;
Most non-automatic BIOS upgrades are installed from DOS. Doing a BIOS upgrade this way, is generally non-problematic. Just install a USB thingie with [https://www.freedos.org/ FreeDOS], copy your file(s) onto the thing and boot on it. The commandline is the same as old MS/DOS, except a wee bit more userfriendly, but not a lot.&lt;br /&gt;
&lt;br /&gt;
=== Windows ===&lt;br /&gt;
&lt;br /&gt;
Some macahines, like laptops from &#039;&#039;&#039;HP&#039;&#039;&#039;, may have BIOS upgrades that are made to be installed from Windows and won&#039;t run in FreeDOS or MS/DOS, instead throwing an error, saying &#039;&#039;&#039;This program cannot be run in DOS mode&#039;&#039;&#039;. This means you&#039;ll have to boot on a Windows rescue disc and do the job from there. Googling this, tells you it&#039;s quite easy, you just choose &#039;make rescue disc&#039; from Windows, and it&#039;s all good, except if you don&#039;t run Windows, that is. To remedy this problem, do as follows:&lt;br /&gt;
&lt;br /&gt;
==== Download Windows ====&lt;br /&gt;
&lt;br /&gt;
Since you don&#039;t run Windows and possibly don&#039;t have a spouse or friend around with such unhealthy habits either, you need to get it. It&#039;s quite easy - just google &#039;download windows&#039; and it&#039;ll send you to [https://www.microsoft.com/en-us/software-download/windows10ISO somewhere like this].&lt;br /&gt;
&lt;br /&gt;
==== Burn it! ====&lt;br /&gt;
&lt;br /&gt;
Now it&#039;s time to burn the installer on a DVD ROM. You&#039;ll need a double-layered one, since the OS is &amp;gt; 4.7GiB, but I&#039;m sure you have a ton of those lying around. Now, just place your optical medium in your optical drive and burn, baby, burn!&lt;br /&gt;
&lt;br /&gt;
==== Or make a USB thing? ====&lt;br /&gt;
&lt;br /&gt;
Not a lot of machines have optical drives these days, so you may want to use an USB pen drive or something instead. This is easy, just make the USB bootable with the Windows application Microsoft has made for this. Unfortunately, this only runs on Windows, and unlike stuff like Debian, where the &#039;&#039;&#039;iso&#039;&#039;&#039; file can be dd&#039;ed directly onto a USB drive to make it bootable, the Windows &#039;&#039;&#039;iso&#039;&#039;&#039;s don&#039;t come with this luxury. There are lots of methods to make bootable USB things from iso files out there, but the only thing most of them have in common, is that they generally don&#039;t work.&lt;br /&gt;
&lt;br /&gt;
===== WoeUSB =====&lt;br /&gt;
&lt;br /&gt;
After hours of swearing, it&#039;s nice to come across software like [https://github.com/slacka/WoeUSB WoeUSB]. It may not be perfect, it relies on a bunch of GUI stuff you&#039;ll never need and so on, but it &#039;&#039;&#039;&#039;&#039;works&#039;&#039;&#039;&#039;&#039;, and that&#039;s the important part! Just clone the repo and RTFM and it&#039;s all nice. It&#039;s slow, but hell, getting a windows machine and/or an optical drive might be slower.&lt;br /&gt;
&lt;br /&gt;
WoeUSB does nothing fancy, but it &#039;&#039;&#039;does&#039;&#039;&#039; work. It will create a filesystem, FAT32 or NTFS (better use NTFS, FAT32 has its limits). It creates normal filesystems and so on. Just make sure to copy in the BIOS update file, usually an exe file, to run when Windows is up and running.&lt;br /&gt;
&lt;br /&gt;
===== Install BIOS =====&lt;br /&gt;
&lt;br /&gt;
Boot on the Windows USB thing and choose &#039;repair computer&#039; and then &#039;command prompt&#039;. Find the install file, and if you&#039;re lucky, you&#039;ll find it needs a 32bit OS, just like I did. Since the 64bit version doesn&#039;t include 32bit compatibility in the installer, revert to downloading the 32bit version of windows and start over. Pray to your favourite god(s) not to get across such machines again - it might help.&lt;br /&gt;
&lt;br /&gt;
= 3D printer stuff =&lt;br /&gt;
&lt;br /&gt;
== Hydrophilic filament ==&lt;br /&gt;
&lt;br /&gt;
Most popular filament types, including PLA, PETG, PP or PA (Polyamide, normally known as Nylon) and virtualy any filament type named [https://www.matterhackers.com/news/filament-and-water poly-something] (and thus with an acronym of P-something) are hydrophilic (also (somewhat incorrectly) called hydroscopic), meaning so long they&#039;re dryer than the atmosphere around them, they&#039;ll do their best to suck out the atmosphere&#039;s humidity. This is why most filament are shrink-wrapped with a small bag of silica gel in it. If such filament is exposed for normal humid air for some time, it&#039;ll become very hard to use. Most of my experience is with PLA, which can handle a bit (depending on make), but still not a lot. With PLA, if you end up with prints where the filament seems not to stick, it may help with a higher temperature. Otherwise, the filament must be [https://all3dp.com/2/how-to-dry-filament-pla-abs-and-nylon/ baked]. If you don&#039;t want to use your oven, try something like a [https://www.jula.no/catalog/hjem-og-husholdning/kjokkenmaskiner/mattilberedningsapparater/frukt-sopptorker/frukt-sopptorker-001641/#tab02 fruit and mushroom dryer]. Then get a good, sealble plastic box and add something like half a kilogram of [https://www.ebay.com/sch/sis.html?_nkw=1KG+Orange+Replacement+Desiccant+Indicating+Silica+Gel+Beads+for+Drawers%2C+Camera&amp;amp;_id=131938742628&amp;amp;&amp;amp;_trksid=p2057872.m2749.l2658 silica gel] to an old sock, tie it and put it in the your new dry box.&lt;br /&gt;
&lt;br /&gt;
Please note that ABS is hydrophobic, so you won&#039;t have to worry too much there. Also, remember that PA/Nylon is extremely hydrophilic. Even a couple of days in normal air humidity can ruin it completely and will require baking.&lt;br /&gt;
&lt;br /&gt;
== Upgrading the firmware on an Ender 3 ==&lt;br /&gt;
&lt;br /&gt;
This is about upgrading the firmware, and thus also flashing a bootloader to the Creality Ender 3 3D printer. Most of this is well documented on several place, like o [https://www.youtube.com/watch?v=fIl5X2ffdyo the video from Teaching tech] and elsewhere, but I&#039;ll just summarise some issues I had.&lt;br /&gt;
&lt;br /&gt;
=== Using an arduino Nano as a programmer ===&lt;br /&gt;
&lt;br /&gt;
The CR-10, Ender 3 and a few other printers from Creality come without a bootloader, so you&#039;ll need to flash one before upgrading the firmware. Well, strictly speakning, you don&#039;t need one, you can save those 8kB or so for other stuff and use a programmer to write the whole firmware, but then you&#039;ll need to wire up everything every time you want a new firmware, so in my world, you &#039;&#039;&#039;do&#039;&#039;&#039; need the bootloader, since it&#039;s easier. Note that some newer printers, like the CR-10S and possibly all newer ones, come with the bootloader already and thus won&#039;t need another.&lt;br /&gt;
&lt;br /&gt;
To install a bootloader, you&#039;ll need a programmer, and I didn&#039;t have one available. Having some el-cheapo china-copies of Ardinos around, I read I could use one and tried so. Although the docs mostly mention the Uno etc, it&#039;s just as simple with the Nano copy.&lt;br /&gt;
&lt;br /&gt;
So, grab an arduino, plug it to your machine with an USB cable, and, using the Arduino IDE, use the ArduinoISP sketch there (found under Examples) to burn the software needed for the arduino to work as a programmer. When this is done, connect a 10µF capacitor between RST and GND to stop it from resetting when used as a programmer. Connect the MOSI, MISO and SCK pins from the ICSP block (that little isolated 6-pin block on top of the ardu). See [https://www.arduino.cc/en/Tutorial/ArduinoISP here] for a pinout. Then find Vcc and GND either onthe ICSP block or elsewhere. Some sites say that on some boards you shouldn&#039;t use the pins on the ICSP block for this. I doubt it matters, though. Then connect another jumper wire from pin 10 on the ardu to work as the reset pin outwards to the chip being programmed (that is, on the printer). The ICSP jumper block pin layout is the same on the printer and on the ardu, and probably elsewhere. Sometimes [https://xkcd.com/927/ standardisation] actually works…&lt;br /&gt;
&lt;br /&gt;
See https://cloud.karlsbakk.net/index.php/s/zw48YJjzaf8Rc2F for a pic with the ardu (this wiki is broken atm, will fix it later)&lt;br /&gt;
&lt;br /&gt;
== Flashing the printer ==&lt;br /&gt;
&lt;br /&gt;
When the boot loader is in place, possibly after some wierd errors from during the process, the screen on the 3d printer will go blank and it&#039;ll behave like being bricked. This is ok. Now disconnect the wires and connect the USB cable between computer and printer, download the [https://www.th3dstudio.com/knowledgebase/th3d-unified-firmware-package/ TH3D unified firmware] and configure it for your particular needs. The video mentioned above describes this well. After flashing the new firmware, you&#039;ll probably get some timeouts and errors, since apparently it resets the printer after giving it the new firmware, but without notifying the flashing software of it doing so. If this happens, hold your breath and reboot the printer and check its tiny monitor - it should work. If it doesn&#039;t work, try to flash it again, and if that doesn&#039;t work, try flashing the programmer again yet another time, just for kicks.&lt;br /&gt;
&lt;br /&gt;
PS: I tried enabling &#039;&#039;&#039;MANUAL_MESH_LEVELING&#039;&#039;&#039;, which in the code says that &#039;&#039;If used with a 1284P board the bootscreen will be disabled to save space&#039;&#039;. This effectively disabled the whole thing, and apparently may be making the firmware image a wee bit too large for it to fit the 1284P on the ender. It works well without it, though.&lt;br /&gt;
&lt;br /&gt;
== And then… ==&lt;br /&gt;
&lt;br /&gt;
With the new firmware in place, the printer should work as before, although with thermal runaway protection to better avoid fires in case the shit hits the fan, and to allow for things like autolevelling. With any luck, [https://www.precisionpiezo.co.uk/ this thing] may be ready for use by the time you read this - it surely looks nice!&lt;br /&gt;
&lt;br /&gt;
roy&lt;/div&gt;</summary>
		<author><name>Roy</name></author>
	</entry>
	<entry>
		<id>https://wiki.malinux.no/index.php?title=Roy%27s_notes&amp;diff=151</id>
		<title>Roy&#039;s notes</title>
		<link rel="alternate" type="text/html" href="https://wiki.malinux.no/index.php?title=Roy%27s_notes&amp;diff=151"/>
		<updated>2020-01-28T02:04:45Z</updated>

		<summary type="html">&lt;p&gt;Roy: /* ext4 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= LVM, md and friends =&lt;br /&gt;
&lt;br /&gt;
== Linux&#039; Logical Volume Manager (LVM) ==&lt;br /&gt;
&lt;br /&gt;
=== LVM in general ===&lt;br /&gt;
&lt;br /&gt;
LVM is designed to be an abstraction layer on top of physical drives or RAID, typically [https://raid.wiki.kernel.org/index.php/RAID_setup mdraid] or [https://help.ubuntu.com/community/FakeRaidHowto fakeraid]. Keep in mind that fakeraid should be avoided unless you really need it, like in conjunction with dual-booting linux and windows on fakeraid. LVM broadly consists of three elements, the &amp;quot;physical&amp;quot; devices (PV), the volume group (VG) and the logical volume (LV). There can be multiple PVs, VGs and LVs, depending on requirement. More about this below. All commands are given as examples, and all of them can be fine-tuned using extra flags in need of so. In my experience, the defaults work well for most usecases.&lt;br /&gt;
&lt;br /&gt;
I&#039;m mentioning filesystem below too. Where I write ext4, the samme applies to ext2 and ext3.&lt;br /&gt;
&lt;br /&gt;
==== Create a PV ====&lt;br /&gt;
&lt;br /&gt;
A PV is the &amp;quot;physical&amp;quot; parts. This does not need to be a physical disk, but can also be another RAID, be it an mdraid, fakeraid, hardware raid, a virtual disk on a SAN or otherwisee or a partition on one of those. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#  These add three PVs, one on a drive (or hardware raid) and another two on mdraids.&lt;br /&gt;
pvcreate /dev/sdb&lt;br /&gt;
pvcreate /dev/md1 /dev/md2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For more information about pvcreate, see [https://linux.die.net/man/8/pvcreate the manual].&lt;br /&gt;
&lt;br /&gt;
==== Create a VG ====&lt;br /&gt;
&lt;br /&gt;
The volume group consists of one or more PVs grouped together on which LVs can be placed. If several PVs are grouped in a VG, it&#039;s generally a good idea to make sure these PVs have some sort of redundancy, as in mdraid/fakeraid or hwraid. Otherwise it will be like using a [https://en.wikipedia.org/wiki/RAID RAID-0] with a single point of failure on each of the independant drives. LVM has [https://unix.stackexchange.com/questions/150644/raiding-with-lvm-vs-mdraid-pros-and-cons  RAID code in it] as well, so you can use that. I haven&#039;t done so myself, as I generally stick to mraid. The reason is mdraid is, in my opinion older and more stable and has more users (meaning bugs are reported and fixed faster whenever they are found). That said, I beleive the actual RAID code used in LVM RAID are the same function calls as for mdraid, so it may not be much of a difference. I still stick with mdraid. To create a VG, run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create volume group my_vg&lt;br /&gt;
vgcreate my_vg /dev/md1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that if vgcreate is run with a PV (as /dev/md1 above) that is not defined as a PV (like above), this is done implicitly, so if you don&#039;t need any special flags to pvcreate, you can simply skip it and let vgcreate do that for you.&lt;br /&gt;
&lt;br /&gt;
==== Create an LV ====&lt;br /&gt;
&lt;br /&gt;
LVs can be compared to partitions, somehow, since they are bounderies of a fraction or all of that of a VG. The difference between them and a partition, however, is that they can be grown or shrunk easily and also moved around between PVs without downtime. This flexibility makes them superiour to partitions as your system can be changed without users noticing it. By default, an LV is alloated &amp;quot;thickly&amp;quot;, meaning all the data given to it, is allocated from the VG and thus the PV. The following makes a 100GB LV named &amp;quot;thicklv&amp;quot;. When making an LV, I usually allocate what&#039;s needed plus some more, but not everything, just to make sure it&#039;s space available for growth on any of the LVs on the VG, or new LVs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a thick provisioned LV named thicklv on the VG my_vg&lt;br /&gt;
lvcreate -n thicklv -L 100G my_vg&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After the LV is created, a filesystem can be placed on it unless it is meant to be used directly. The application for direct use include swap space, VM storage and certain database systems. Most of these will, however, work on filesystems too, although my testing has shown that on swap space, there is a significant performance gain for using dedicated storage without a filesystem. As for filesystems, most Linux users use either ext4 or xfs. Personally, I generally use XFS these days. See my notes below on filesystem choice.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a filesystem on the LV - this could have been mkfs -t ext4 or whatever filesystem you choose&lt;br /&gt;
mkfs -t xfs /dev/my_vg/thicklv&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then just edit /etc/fstab with correct data and run mount -a, and you should be all set.&lt;br /&gt;
&lt;br /&gt;
==== Create LVM cache ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
lvcreate -L 1G -n _cache_meta data /dev/md1&lt;br /&gt;
&lt;br /&gt;
lvcreate -l100%FREE -n _cache data /dev/md1&lt;br /&gt;
&lt;br /&gt;
# Some would want --cachemode writeback, but seriously, I wouldn&#039;t recommend it. Metadata or data can be easily corrupted in case of failure.&lt;br /&gt;
lvconvert --type cache-pool --cachemode writethrough --poolmetadata data/_cache_meta data/_cache&lt;br /&gt;
&lt;br /&gt;
lvconvert --type cache --cachepool data/_cache data/data&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Disabling LVM cache ====&lt;br /&gt;
&lt;br /&gt;
If you for some reason want to disable caching, this will do it cleanly and remove the LVs earlier created for caching the main device.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
lvconvert --uncache data/data&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Growing devices ====&lt;br /&gt;
&lt;br /&gt;
LVM objects can be grown and shrunk. If a PV resides on a RAID where a new drive has been added or otherwise grown, or on a partition or virtual disk that has been extended, the PV must be updated to reflect these changes. The following command will grow the PV to the maximum available on the underlying storage. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Resize the PV /dev/md (not the RAID, only the PV on the RAID) to its full size&lt;br /&gt;
pvresize /dev/md1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If a new PV is added, the VG can be grown to add the space on that in addition to what&#039;s there already. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Extend my_vg to include md2 and its space&lt;br /&gt;
vgextend my_vg /dev/md2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
With more space available in the VG, the LV can now be extended. Let&#039;s add another 50GB to it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Extend thicklv - add 50GB. If you know you won&#039;t need the space anywhere else, you may want to&lt;br /&gt;
# lvresize -l+100%FREE instead. Keep in mind the difference between -l (extents) and -L (bytes)&lt;br /&gt;
lvresize -L +50G my_vg/thicklv&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Growing filesystems ====&lt;br /&gt;
After the LV has grown, run &#039;&#039;xfs_growfs&#039;&#039; (xfs) or &#039;&#039;resize2fs&#039;&#039; (ext4) to make use of the new data. To grow the filesystem to all available space on ext[234], run the below command.  To partly grow the filesystem or to shrink it or otherwise, please see the manuals.&lt;br /&gt;
&lt;br /&gt;
The filesystem can be mounted when this is run. If you for some reason get an &#039;&#039;&#039;access denied&#039;&#039;&#039; error when running this as root or with sudo, it&#039;s likely caused by a filesystem error. To fix this, unmount the filesystem first and run &#039;&#039;&#039;fsck -f /dev/my_vg/thicklv&#039;&#039;&#039; and remount it before retrying to extend it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
resize2fs /dev/my_vg/thicklv&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Similarly, with XFS, but note that xfs_growfs doesn&#039;t take the device name, but the filesystem&#039;s mount point. In the case of XFS, also note that the filesystem &#039;&#039;&#039;&#039;&#039;must&#039;&#039;&#039;&#039;&#039; be mounted to be grown. This, in contrast to how it was in the old days when filesystems had to be unmounted to be grown.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
xfs_growfs /my_mountpoint&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Rename system VG ====&lt;br /&gt;
&lt;br /&gt;
Some distros create VG names like those-from-a-sysadmin-with-a-well-developed-paranoia-not-to-hit-a-duplicate. Debian, for instance, uses names like &amp;quot;my-full-hostname-vg&amp;quot;. Personally, I don&#039;t like these, since if I were to move a disk or vdisk around to somewhere else, I&#039;d make sure not to add a disk named &#039;sys&#039; to an existing system. If you do, most distros will refuse to use the VGs with duplicate names, resulting in the OS not booting until either one is specified by its UUID or just one removed. As I&#039;m aware of this, I stick to the super-risky thing of all system VGs named &#039;sys&#039; and so on.&lt;br /&gt;
&lt;br /&gt;
If you do this, keep in mind that it may blow up your computer and take your girl- or boyfriend with it or even make either of them pregnant, allowing Trump to rule your life and generally make things suck. You&#039;re on your own!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Rename the VG&lt;br /&gt;
vgrename my-full-hostname-vg sys&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, in /boot/grub/grub.cfg, change the old lv path from something like &#039;/dev/mapper/debian--stretch--machine--vg-root&#039; to your new and fancy &#039;/dev/sys/root. Likewise, in /etc/fstab, change occurences of &#039;/dev/mapper/debian--stretch--machine--vg-&#039; (or similar) with &#039;/dev/sys/&#039;. Here, this was like this - the old ones commented out.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;fstab&amp;quot;&amp;gt;&lt;br /&gt;
#/dev/mapper/debian--stretch--box--vg-root      /               ext4            errors=remount-ro,discard       0       1&lt;br /&gt;
/dev/sys/root                                   /               ext4            errors=remount-ro,discard       0       1&lt;br /&gt;
# /boot was on /dev/vda1 during installation&lt;br /&gt;
UUID=myverylonguuidwithatonofgoodinfoinit       /boot           ext2            defaults                        0       2&lt;br /&gt;
#/dev/mapper/debian--stretch--box--vg-swap_1    none            swap            sw                              0       0&lt;br /&gt;
/dev/sys/swap_1                                 none            swap            sw                              0       0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Update /etc/initramfs-tools/conf.d/resume with similar data for swap.&lt;br /&gt;
&lt;br /&gt;
You might want to run &#039;update-initramfs -u -k all&#039; after this, but I&#039;m not sure if it&#039;s needed.&lt;br /&gt;
&lt;br /&gt;
Now, pray to the nearest god(s) and give it a reboot and it should (probably) work.&lt;br /&gt;
&lt;br /&gt;
After reboot, run &#039;&#039;&#039;swapoff -a&#039;&#039;&#039;, then &#039;&#039;&#039;mkswap /dev/sys/swap_1&#039;&#039;&#039; (or whatever it&#039;s called on your system) and &#039;&#039;&#039;swapon -a&#039;&#039;&#039; again. You may want to give it another reboot or two for kicks, but it should work well even without that.&lt;br /&gt;
&lt;br /&gt;
=== Migration tools ===&lt;br /&gt;
&lt;br /&gt;
At times, storage regimes change, new storage is added and sometimes it&#039;s not easy to migrate with the current hardware or its support systems. Once I had to migrate a 45TiB fileserver from one storage system to another, preferably without downtime. The server originally had three 15TiB PVs of which two were full and the third half full. I resorted to using [https://linux.die.net/man/8/pvmove pvmove] to just move the data on the PVs in use to a new PV. We started out with creating a new 50TiB PV, sde, and then to pvmove.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Attach /dev/sde to the VG my_vg&lt;br /&gt;
vgextend my_vg /dev/sde&lt;br /&gt;
&lt;br /&gt;
# Move the contents from /dev/sdb over to /dev/sde block by block. If a target is not given in pvmove,&lt;br /&gt;
# the contents of the source (sdb here) will be put somewhere else in the pool.&lt;br /&gt;
pvmove /dev/sdb /dev/sde&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This took a while (as in a week or so) - the pvmove command uses old code and logic (or at least did that when I migrated this in November 2016), but it affected performance on the server very little, so users didn&#039;t notice. After the first PV was migrated, I continued with the other two, one after the other, and after a month or so, it was migrated. We used this on a number of large fileservers, and it worked flawlessly. Before doing the production servers I also tried interrupting pvmove in various ways, including hard resets, and it just kept on after the reboot.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;NOTE:&#039;&#039;&#039;&#039;&#039; &#039;&#039;Even though it worked well for us, &#039;&#039;&#039;always&#039;&#039;&#039; keep a good backup before doing this. Things may go wrong, and without a good backup, you may be looking for a hard-to-find new job the next morning&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
==== mdadm workarounds ====&lt;br /&gt;
&lt;br /&gt;
===== Migrate from a mirror (raid-1) to raid-10 =====&lt;br /&gt;
&lt;br /&gt;
Create a mirror&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sdb /dev/sdc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
LVM (pv/vg/lv) on md0 (see above), put a filesystem on the lv and fill it with some data.&lt;br /&gt;
&lt;br /&gt;
Now, some months later, you want to change this to raid-10 to allow for the same amount of redundancy, but to allow more disks into the system.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mdadm --grow /dev/md0 --level=10&lt;br /&gt;
mdadm: Impossibly level change request for RAID1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So - no - doesn&#039;t work. But - we&#039;re on &lt;br /&gt;
&lt;br /&gt;
Since we&#039;re on lvm already, this&#039;ll be easy. If you&#039;re using filesystems directly on partitions, you can do this the same way, but without the pvmove part, using rsync or whateever you like instead. I&#039;d recommend using lvm for for the new raid, which should be rather obvious from this article. Now plug in a new drive and create a new raid10 on that one. If you two new drives, install both. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# change &amp;quot;missing&amp;quot; to the other device name if you installed two new drives&lt;br /&gt;
mdadm --create /dev/md1 --level=10 --raid-devices=2 /dev/vdd missing&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, as described above, just vgextend the vg, adding the new raid and run pvmove to move the data from the old pv (residing on the old raid1) to the new pv (on raid10). Afte rpvmove is finished (which may take awile, see above), just&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
vgreduce raidtest /dev/md0&lt;br /&gt;
pvremove /dev/md0&lt;br /&gt;
mdadm --stop /dev/md0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
…and your disk is free to be added to the new array. If the new raid is running in degraded mode (if you created it with just one drive), better don&#039;t wait too long, since you don&#039;t have redundancy. Just mdadm --add the devs.&lt;br /&gt;
&lt;br /&gt;
If you now have /dev/mdstat telling you your raid10 is active and have three drives, of which one is a spare, it should look something like this&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5] [raid4] [raid10]&lt;br /&gt;
md1 : active raid10 vdc[3](S) vdb[2] vdd[0]&lt;br /&gt;
      8380416 blocks super 1.2 2 near-copies [2/2] [UU]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Just mdadm --grow --raid-devices=3 /dev/md1&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;RAID section is not complete. I&#039;ll write more on migraing from raid10 to raid6 later. It&#039;s not straight forward, but easier than this one :)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== Thin provisioned LVs ===&lt;br /&gt;
&lt;br /&gt;
Thin provisioning on LVM is a method used for not allocating all the space given to an LV. For instance, if you have a 1TB VG and want to give an LV 500GB, although it currently only uses a fraction of that, a thin lv can be a good alternative. This will allow for adding a limit to how much it can use, but also to let it grow dynamically without manual work by the sysadmin. Thin provisioning adds another layer of abstaction by creating a special LV as a &#039;&#039;thin pool&#039;&#039; from which data is allocated to the &#039;&#039;thin volume(s)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== Create a thin pool ====&lt;br /&gt;
&lt;br /&gt;
Allocate 1TB to the thin pool to be used for thinly provisioned LVs. Keep in mind that the space allocated to the thin pool is in fact thick provisioned. Only the volumes put on &#039;&#039;thinpool&#039;&#039; are thin provisioned. This will create two hidden LVs, one for data and one for metadata. Normally the defaults will do, but check the manual if the data doesn&#039;t match the usual patterns (such as billions of files, resulting in huge amounts of metadata). I &#039;&#039;beleive&#039;&#039; the metadata part should be resizable at a later time if needed, but I have not tested it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a pool for thin LVs. Keep in mind that the pool itself is not thin provisioned, only the volumes residing on it&lt;br /&gt;
lvcreate --size 1T --type thin-pool --thinpool thinpool my_vg&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Create a thin volume ====&lt;br /&gt;
&lt;br /&gt;
You have the thinpool, now put a thin volume on it. It will allocate some space for metadata, but probably not much (a few megs, perhaps).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Now, create a volume with a virtual (-V) size of half a terabyte named thin_pool, but using the thinpool (-T) named thin_pool for storage&lt;br /&gt;
lvcreate -V 500G -T my_vg/thin_pool --name thinvol&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The new volume&#039;s device name will be /dev/thinvol. Now, create a filesystem on it, add to fstab and mount it. The &#039;&#039;&#039;df&#039;&#039;&#039; command will return available space according to the virtual size (-V), while lvs will show how much data is actually used on each of the thinly provisioned volumes.&lt;br /&gt;
&lt;br /&gt;
== Filesystem dilemmas ==&lt;br /&gt;
&lt;br /&gt;
=== XFS or ext4 or something else ===&lt;br /&gt;
The choice of filesystem varies for your use. Distros such as RHEL/CentOS has moved to XFS by default from v7. Debian/Ubuntu still sticks to ext4, like most other. I&#039;ll discuss my thoughts below on ext4 vs XFS and leave the other filesystems for later.&lt;br /&gt;
&lt;br /&gt;
==== ext4 ====&lt;br /&gt;
ext4 is probably the most used filesystem on linux as of writing. It&#039;s rock stable and has been extended by a lot of extensions since the original ext2. It still retains backward compatibility, being able to mount and fsck ext2 and ext3 with the ext4 driver. However, it doesn&#039;t handle large filesystems very well. If a filesystem is created for &amp;lt;16TiB, it cannot be grown to anything larger than 16TiB. This may have changed lately, though. One other issue is handling errors. If a large filesystem (say 10TiB) is damaged, an fsck may take several hours, leading to long downtime. When I refer to ext4 further in this text, the same applies to ext2 and ext3 unless otherwise specified.&lt;br /&gt;
&lt;br /&gt;
==== XFS ====&lt;br /&gt;
XFS, originally developed by SGI some time in the bronze age, but has been worked on heavily after that. RHEL and Centos version 7 and forward, uses XFS as the default filesystem. It is quick, it scales well, but it lacks at least two things ext4 has. It cannot be shrunk (not that you normally need that, but nice if you have a typo or you need to change things). Also, it doesn&#039;t allow for automatic fsck on bootup. If something is messed up on the filesystem, you&#039;ll have to login as root on the console (not ssh), which might be an issue on some systems. The fsck equivalent, xfs_repair, is a *lot* faster than ext4&#039;s fsck, though.&lt;br /&gt;
&lt;br /&gt;
==== ZFS ====&lt;br /&gt;
ZFS is like a combination of RAID, LVM and a filesystem, supporting full checksumming, auto-healing (given sufficient redundancy), compression, encryption, replication, deduplication (if you&#039;re brave and have a &#039;&#039;ton&#039;&#039; of memory) and a lot more. It&#039;s a separate chapter and needs a lot more talk than paragraph here.&lt;br /&gt;
&lt;br /&gt;
== Low level disk handling ==&lt;br /&gt;
&lt;br /&gt;
This section is for low-level handling of disks, regardless of storage system elsewhere. These apply to mdraid, lvmraid and zfs and possibly other solutions, with the exception of individual drives on hwraid (and maybe fakeraid), since there, the drives are hidden from Linux (or whatever OS).&lt;br /&gt;
&lt;br /&gt;
=== S.M.A.R.T. and slow drives ===&lt;br /&gt;
Modern (that is, from about 1990 or later) have S.M.A.R.T. (or just smart, since it&#039;s easier to type) monitoring built in, meaning the disk&#039;s controller is monitoring itself. This is handy and will ideally tell you in advance that a drive is flakey or dying. Modern (2010+) smart monitoring is more or less the same. It can be trusted about 50% of the time. Usually, if smart detects an error, it&#039;s a real error. I don&#039;t think I&#039;ve seen it reporting a false positive, but others may know better. &lt;br /&gt;
&lt;br /&gt;
==== smartmontools ====&lt;br /&gt;
First, install smartmontool and run smartclt -H /dev/yourdisk (/dev/sda or something) to get a health report. Then perhaps run smartctl -a /dev/yourdisk and look for &#039;current pending sectors&#039; This should be zero. Also check the temperature, which normally should be much above 50.&lt;br /&gt;
&lt;br /&gt;
==== single, slow drive ====&lt;br /&gt;
What may happen, is smart not seeing anything and life goes on like before, only slower and less prouductive, without telling anyone. If you stubler over this issue, you&#039;ll probably see it during a large rsync/zfs send/receive or a resync/rebuild/resilver of the raid/zpool. During this, it feels like everything is slow and your RAID has turned into a RAIF (redundant array of inexpensive floppies). To check if you have a single drive messing up it all, check with &#039;&#039;&#039;iostat -x 2&#039;&#039;&#039;, having 2 being the delay between each measurement. Interrupt it with ctrl+x. If there&#039;s a rougue drive there, it should stand out like sdg below&lt;br /&gt;
&lt;br /&gt;
 avg-cpu:  %user   %nice %system %iowait  %steal   %idle&lt;br /&gt;
            0.38    0.00    1.75    0.00    0.00   97.87&lt;br /&gt;
&lt;br /&gt;
 Device            r/s     w/s     rkB/s     wkB/s   rrqm/s   wrqm/s  %rrqm  %wrqm r_await w_await aqu-sz rareq-sz wareq-sz  svctm  %util&lt;br /&gt;
 sda              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdb              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdc              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdd              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sde              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdf              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdg              3.50    0.00   2352.00      0.00     0.00     0.00   0.00   0.00 14306.29    0.00  13.85   672.00     0.00 285.71 100.00&lt;br /&gt;
 sdh              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
&lt;br /&gt;
In ZFS land, you should be able to get similar data with &#039;&#039;&#039;zpool iostat -v &amp;lt;pool&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Now you know the bad drive (sdg), pull it from the raid with &#039;&#039;&#039;mdadm --fail /dev/mdX /dev/sdX&#039;&#039;&#039;. Now test the drive&#039;s performance manually, just simply:&lt;br /&gt;
&lt;br /&gt;
 # hdparm -t /dev/sdg&lt;br /&gt;
 &lt;br /&gt;
 /dev/sdg:&lt;br /&gt;
  Timing buffered disk reads:   2 MB in  5.37 seconds = 381.46 kB/sec&lt;br /&gt;
&lt;br /&gt;
Bingo - nothing you&#039;d want to keep. For a good drive, it should be something like 100-200MB/s&lt;br /&gt;
&lt;br /&gt;
PS: Keep in mind that you have a degraded RAID by now in case you had a spare waiting for things to happen.&lt;br /&gt;
&lt;br /&gt;
Try to replace the cable and/or try the disk on another port/controller. If the result from hdparm persists, it&#039;s probably a bad cable&lt;br /&gt;
&lt;br /&gt;
So, then, just psycially locate the drive, pull it out, take out the discs and magnets and recycle the rest.&lt;br /&gt;
&lt;br /&gt;
=== &amp;quot;Unplug&amp;quot; drive from system ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Find the device unit&#039;s number with something like&lt;br /&gt;
find /sys/bus/scsi/devices/*/block/ -name sdd&lt;br /&gt;
# returning /sys/bus/scsi/devices/3:0:0:0/block/sdd here, &lt;br /&gt;
# meaning 3:0:0:0 is the SCSI device we&#039;re looking for.&lt;br /&gt;
&lt;br /&gt;
# Given this is the correct device, and you want to &#039;unplug&#039; it, do so by&lt;br /&gt;
echo 1 &amp;gt; /sys/bus/scsi/devices/3:0:0:0/delete&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Rescan disk controllers ===&lt;br /&gt;
If a drive is added and for some reason doesn&#039;t get detected, or is removed by the command above, it can be rediscovered with a sysfs command to the scsi host to which it is connected. Since there may be quite a few of these, an easy way is to just scan them all and check the output of &#039;&#039;&#039;dmesg -T&#039;&#039;&#039; after running it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Make a list of controllers and send a rescan message to each of them. It won&#039;t do anything &lt;br /&gt;
# for those where nothing has changed, but it will show new drives where they have been added.&lt;br /&gt;
for host_scan in /sys/class/scsi_host/host*/scan&lt;br /&gt;
do&lt;br /&gt;
  echo &#039;- - -&#039; &amp;gt; $host_scan&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Fail injection with debugfs ===&lt;br /&gt;
[https://lxadm.com/Using_fault_injection https://lxadm.com/Using_fault_injection]&lt;br /&gt;
&lt;br /&gt;
== mdadm stuff ==&lt;br /&gt;
=== Spare pools ===&lt;br /&gt;
In the old itmes, mdadm supported only a dedicated spare per md device, so if working with a large set of drives (20? 40?), where you&#039;d want to setup more raid sets to increase redundancy, you&#039;d dedicate a spare to each of the raid sets. This has changed (some time ago?), so in these modern, heathen days, you can change mdadm.conf, usually placed under /etc/mdadm, and add &#039;spare-group=somegroup&#039; where &#039;somegroup&#039; is a string identifying the spare group. After doing this, run &#039;&#039;&#039;update-initramfs -u&#039;&#039;&#039; and reboot and add a spare to one of the raid sets in the spare group, and md will use that or those spares for all the raidsets in that group.&lt;br /&gt;
&lt;br /&gt;
As some pointed out on #linux-raid @ irc.freenode.net, this feature is very badly documented, but as far as I can see, it works well.&lt;br /&gt;
&lt;br /&gt;
==== Example config ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create two raidsets&lt;br /&gt;
&lt;br /&gt;
mdadm --create /dev/md1 --level=6 --raid-devices=6 /dev/vd[efghij]&lt;br /&gt;
mdadm --create /dev/md2 --level=6 --raid-devices=6 /dev/vd[klmnop]&lt;br /&gt;
&lt;br /&gt;
# get their UUID etc&lt;br /&gt;
&lt;br /&gt;
mdadm --detail --scan&lt;br /&gt;
ARRAY /dev/md/1 metadata=1.2 name=raidtest:1 UUID=1a8cbdcb:f4092350:348b6b80:c054d74c&lt;br /&gt;
ARRAY /dev/md/2 metadata=1.2 name=raidtest:2 UUID=894b1b7c:cb7eba70:917d6033:ea5afd2b&lt;br /&gt;
&lt;br /&gt;
# Put those lines into /etc/mdadm/mdadm.conf and and add the spare-group&lt;br /&gt;
&lt;br /&gt;
ARRAY /dev/md/1 metadata=1.2 name=raidtest:1 spare-group=raidtest UUID=1a8cbdcb:f4092350:348b6b80:c054d74c&lt;br /&gt;
ARRAY /dev/md/2 metadata=1.2 name=raidtest:2 spare-group=raidtest UUID=894b1b7c:cb7eba70:917d6033:ea5afd2b&lt;br /&gt;
&lt;br /&gt;
# update the initramfs and reboot&lt;br /&gt;
&lt;br /&gt;
update-initramfs -u&lt;br /&gt;
reboot&lt;br /&gt;
&lt;br /&gt;
# add a spare drive to one of the raids&lt;br /&gt;
&lt;br /&gt;
mdadm --add /dev/md1 /dev/vdq&lt;br /&gt;
&lt;br /&gt;
# fail a drive on the other raid&lt;br /&gt;
&lt;br /&gt;
mdadm --fail /dev/md2 /dev/vdn&lt;br /&gt;
&lt;br /&gt;
# check /proc/mdstat to see md2 rebuilding with the spare from md1&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Recovery ===&lt;br /&gt;
&lt;br /&gt;
The other day, I came across a problem a user had on #linux-raid@irc.freenode.net. He had an old Qnap NAS that had died and tried plugging the drives in to his Linux machine and got various errors. The two-drive RAID-1 did not come up as it should, &#039;&#039;&#039;dmesg&#039;&#039;&#039; was full of errors from one of the drives (both connected on USB) and so forth.&lt;br /&gt;
&lt;br /&gt;
We went on and started by taking down the machine and just connecting one of the drives. I had him check what was assembled with&lt;br /&gt;
&lt;br /&gt;
 cat /proc/mdstat&lt;br /&gt;
&lt;br /&gt;
That returned /proc/md127 assembled, but LVM didn&#039;t find anything. So running a manual scan&lt;br /&gt;
&lt;br /&gt;
 pvscan --cache /dev/md127&lt;br /&gt;
&lt;br /&gt;
This made linux find the PV, VG and a couple of LVs, but probably because the mdraid was degraded, the LVs were deactivated, according to &#039;&#039;&#039;lvscan&#039;&#039;&#039;. Activating the one with a filesystem manually&lt;br /&gt;
&lt;br /&gt;
 lvchange -a y /dev/&amp;lt;vg&amp;gt;/&amp;lt;lv&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Substitute &amp;lt;vg&amp;gt; and &amp;lt;lv&amp;gt; with the names listed by vgs and lvs.&lt;br /&gt;
&lt;br /&gt;
This worked, and the filesystem on /dev/&amp;lt;vg&amp;gt;/&amp;lt;lv&amp;gt; could be mounted correctly.&lt;br /&gt;
&lt;br /&gt;
== Tuning ==&lt;br /&gt;
&lt;br /&gt;
While trying to compare a 12-disk RAID (8TB disks) to a hwraid, mdraid was slower, so we did a few things to speed things up:&lt;br /&gt;
&lt;br /&gt;
While testing with [https://linux.die.net/man/1/fio fio], monitor /sys/block/md0/md/stripe_cache_active, and see if it&#039;s close to /sys/block/md0/md/stripe_cache_size. If it is, double the size of the latter&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
echo 4096 &amp;gt; /sys/block/md0/md/stripe_cache_size&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Continue until stripe_cache_active stabilises, and then you&#039;ve found the limit you&#039;ll need. You may want to double that for good measure. &lt;br /&gt;
&lt;br /&gt;
(to be continued)&lt;br /&gt;
&lt;br /&gt;
== Links ==&lt;br /&gt;
&lt;br /&gt;
Below are a few links with useful info&lt;br /&gt;
&lt;br /&gt;
* [https://raid.wiki.kernel.org/index.php/Irreversible_mdadm_failure_recovery Irreversible mdadm failure recovery]&lt;br /&gt;
&lt;br /&gt;
= ZFS =&lt;br /&gt;
&lt;br /&gt;
ZFS can do a lot of things most filesystems or volume managers can&#039;t. It checksums all data and metadata and so long that the system uses ECC enabled memory (RAM), it will have complete control over the whole data set, and when (not if) an error occurs, it&#039;ll fix the issue without even throwing a warning. To fix the issue, you&#039;ll obviously need sufficient redundancy (mirrors or RAIDzN). &lt;br /&gt;
&lt;br /&gt;
== ZFS send/receive between machines ==&lt;br /&gt;
&lt;br /&gt;
ZFS has a send/receive mechanism that allows for snapshots to be sent over the wire to a receiving end. This can be a full filesystem, or an incremental change since last send/reveive. In a WAN scenario, you&#039;ll probably want to use VPN for this. On a controlled network, sending in cleartext is also possible. You may as well use ssh, but keep in mind that ssh was never designed to be used as a fullblown vpn solution and is just too slow or the task with large amounts of data. You may, though, use mbuffer, if on a loal LAN.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Allow traffic from the sending IP in whatever firewall interface you&#039;re using (if you&#039;re using a firewall at all, that is)&lt;br /&gt;
ufw allow from x.x.x.x&lt;br /&gt;
# &lt;br /&gt;
# Start the receiver first. This listens on port 9090, has a 1GB buffer,&lt;br /&gt;
    and uses 128kb chunks (same as zfs):&lt;br /&gt;
&lt;br /&gt;
mbuffer -s 128k -m 1G -I 9090 | zfs receive data/filesystem&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To be continued one day… See [https://everycity.co.uk/alasdair/2010/07/using-mbuffer-to-speed-up-slow-zfs-send-zfs-receive/ this] for some more. I&#039;ll get back with details on it.&lt;br /&gt;
&lt;br /&gt;
= General Linux system control =&lt;br /&gt;
&lt;br /&gt;
== Add a new CPU (core) ==&lt;br /&gt;
&lt;br /&gt;
If working with virtual machines, adding a new core can be useful if the VM is slow and the load is multithreaded or multiprocess. To do this, add a new CPU in the hypervisor (be it KVM or VMware or Hyper-V or whatever). Some hypervisors, like VMware, will activate it automatically if open-vm-tools is installed. Please note that open-vm-tools is for VMware only. I don&#039;t know of any such thing for KVM or other hypervisors (although I beleive VirtualBox has its own set of tools, but not as a package). If this doesn&#039;t work, run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
echo 1 &amp;gt; /sys/devices/system/cpu/cpuX/online&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where X is the CPU number you want to add. You can &#039;cat /sys/devices/system/cpu/cpuX/online&#039; to check if it&#039;s online.&lt;br /&gt;
&lt;br /&gt;
= Mount partitions on a disk image =&lt;br /&gt;
&lt;br /&gt;
Sometimes you&#039;ll have a disk image, either from recovering a bad drive after hours (or days or weeks) of ddrescue, and sometimes you just have a disk image from a virtual machine where you want to mount the partitions inside the image. There are three main methods of doing this, which are more or less synonmous, but some easier than the other.&lt;br /&gt;
&lt;br /&gt;
== Basics ==&lt;br /&gt;
&lt;br /&gt;
A disk image is usually like a disk, consisting of either a large filesystem, a PV or a partition table with one or partitions onto which resides a filesystem, a pv, swap or something else. If it&#039;s partitioned, and you want your operating system to mount a filesystem or allow it to see whatever LVM stuff lies on it, you need to isolate the partitions. &lt;br /&gt;
&lt;br /&gt;
== Manual mapping ==&lt;br /&gt;
&lt;br /&gt;
In the oldern days, this was done manually, something like this&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
root@mymachine:~# fdisk -l /dev/vda&lt;br /&gt;
Disk /dev/vda: 25 GiB, 26843545600 bytes, 52428800 sectors&lt;br /&gt;
Units: sectors of 1 * 512 = 512 bytes&lt;br /&gt;
Sector size (logical/physical): 512 bytes / 512 bytes&lt;br /&gt;
I/O size (minimum/optimal): 512 bytes / 512 bytes&lt;br /&gt;
Disklabel type: dos&lt;br /&gt;
Disk identifier: 0xc37b7ea5&lt;br /&gt;
&lt;br /&gt;
Device     Boot    Start      End  Sectors  Size Id Type&lt;br /&gt;
/dev/vda1  *        2048 50333311 50331264   24G 83 Linux&lt;br /&gt;
/dev/vda2       50333312 52426369  2093058 1022M  5 Extended&lt;br /&gt;
/dev/vda5       50333314 52426369  2093056 1022M 82 Linux swap / Solaris&lt;br /&gt;
root@mymachine:~#&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To calculate the start and end of each partition, you just take the start sector and multiply it by the sector size (512 bytes here) and you have the offset in bytes. After this, it&#039;s merely an losetup -o &amp;lt;offset&amp;gt; /dev/loopX &amp;lt;nameofimagefile&amp;gt; and you have the partition mapped to your /dev/loopX (having X being something typically 0-255. After this, just mount it or run pvscan/vgscan/lvscan to probe whatever lvm config is there, and you should be able to mount it like any other filesystem.&lt;br /&gt;
&lt;br /&gt;
== kpartx ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;kpartx&#039;&#039;&#039; does the same as above, more or less, just without so much hassle. Most of it should be automatic and easy to deal with, except it may fail to disconnect the loopback devices sometimes, so you may have to &#039;&#039;&#039;losetup -d&#039;&#039;&#039; them manually. See the manual, &#039;&#039;&#039;kpartx (8)&#039;&#039;&#039;. Please note that &#039;&#039;&#039;partx&#039;&#039;&#039; works similarly and I&#039;d guess the authors of the two tools are arguing a lot of which one&#039;s the best.&lt;br /&gt;
&lt;br /&gt;
== guestmount ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;guestmount&#039;&#039;&#039; is something similar again, but also supports file formats like &#039;&#039;&#039;qcow2&#039;&#039;&#039; and possibly other, proprietary filesystems like &#039;&#039;&#039;vmdk&#039;&#039;&#039; and &#039;&#039;&#039;vdi&#039;&#039;&#039;, but don&#039;t take my word for it - I haven&#039;t tested. Again, see the manual or just read up on the description [http://ask.xmodulo.com/mount-qcow2-disk-image-linux.html?fbclid=IwAR3snTeZvGzp9PLdX11EQhCfOpux6I93CiJ3A2pUomkkRLly9Xo4851mkTY here]. It seems rather trivial.&lt;br /&gt;
&lt;br /&gt;
= Linux on laptops =&lt;br /&gt;
&lt;br /&gt;
== Wifi with HP EliteBook 725/745 on Ubuntu ==&lt;br /&gt;
&lt;br /&gt;
The HP EliteBook 725/745 and similar are equipped with a BCM4352 wifi chip. As with a lot of other stuff from Broadcom, this lacks an open hardware description, so thus no open driver exist. The proper fix, is to replace the NIC with something with an open driver, but again, this isn&#039;t always possible, so a binary driver exists. In ubuntu, run, somehow connect the machine to the internet and run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install bcmwl-kernel-source&lt;br /&gt;
sudo modprobe wl&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you can&#039;t connect the machine to the internet, download the needed packages on another machine and put it on some usb storage. These packages should suffice:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# apt-cache depends bcmwl-kernel-source&lt;br /&gt;
bcmwl-kernel-source&lt;br /&gt;
  Depends: dkms&lt;br /&gt;
  Depends: linux-libc-dev&lt;br /&gt;
  Depends: libc6-dev&lt;br /&gt;
  Conflicts: &amp;lt;bcmwl-modaliases&amp;gt;&lt;br /&gt;
  Replaces: &amp;lt;bcmwl-modaliases&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then install manually with &#039;&#039;&#039;dpkg -i file1.deb file2.deb&#039;&#039;&#039; etc&lt;br /&gt;
&lt;br /&gt;
After this, ip/ifconfig/iwconfig shouldd see the new wifi nic, probably &#039;&#039;&#039;wlan0&#039;&#039;&#039;, but due to a [https://bugs.launchpad.net/ubuntu/+source/broadcom-sta/+bug/1343151 old, ignored bug], you won&#039;t find any wifi networks. This is because the driver from Broadcom apparently does not support interrupt remapping, commonly used on x64 machines. To turn this off, change &#039;&#039;&#039;/etc/default/grub&#039;&#039;&#039; and change the line &#039;&#039;&#039;GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;quiet splash&amp;quot;&#039;&#039;&#039;, adding intremap=off to the end before the quote: &#039;&#039;&#039;GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;quiet splash intremap=off&amp;quot;&#039;&#039;&#039;. Save the file and run &#039;&#039;&#039;sudo update-grub&#039;&#039;&#039; and reboot. After this, wifi should work well.&lt;br /&gt;
&lt;br /&gt;
== Wifi with HP Compaq Presario CQ57 on Ubuntu ==&lt;br /&gt;
&lt;br /&gt;
The HP Compaq Presario CQ57 uses the RT5390 wifi chipset. This has been supported for quite some time now, and I was quite surprised to find it not working on a laptop a friend was having. The driver loaded correctly, but Ubuntu insisted of the laptop being in &#039;&#039;&#039;flight mode&#039;&#039;&#039;. Checking &#039;&#039;&#039;rfkill&#039;&#039;&#039;, it showed me two NICs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# rfkill list all&lt;br /&gt;
0: phy0: Wireless LAN&lt;br /&gt;
	Soft blocked: no&lt;br /&gt;
	Hard blocked: yes&lt;br /&gt;
1: hp-wifi: Wireless LAN&lt;br /&gt;
	Soft blocked: yes&lt;br /&gt;
	Hard blocked: no&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Turning rfkill on and off resulted in nothing much, except some error messages in the kernel log (dmesg)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] ACPI Error: Field [B128] at bit offset/length 128/1024 exceeds size of target Buffer (160 bits) (20170831/dsopcode-235)&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]&lt;br /&gt;
                            Initialized Local Variables for Method [HWCD]:&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Local0: 00000000a34b7928 &amp;lt;Obj&amp;gt;           Integer 0000000000000000&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Local1: 00000000b0aa6865 &amp;lt;Obj&amp;gt;           Buffer(8) 46 41 49 4C 04 00 00 00&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Local5: 00000000a9811efd &amp;lt;Obj&amp;gt;           Integer 0000000000000004&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] Initialized Arguments for Method [HWCD]:  (2 arguments defined for method invocation)&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Arg0:   0000000078957d1b &amp;lt;Obj&amp;gt;           Integer 0000000000000001&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Arg1:   00000000725c9c6e &amp;lt;Obj&amp;gt;           Buffer(20) 53 45 43 55 02 00 00 00&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] ACPI Error: Method parse/execution failed \_SB.WMID.HWCD, AE_AML_BUFFER_LIMIT (20170831/psparse-550)&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] ACPI Error: Method parse/execution failed \_SB.WMID.WMAD, AE_AML_BUFFER_LIMIT (20170831/psparse-550)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After upgrading BIOS and testing different kernels, I was asked to try to unload the &#039;&#039;&#039;hp_wmi&#039;&#039;&#039; driver. I did, and things changed a bit, so I tried blacklisting it, creating the file &#039;&#039;&#039;/etc/modprobe.d/blacklist-hp_wmi.conf&#039;&#039;&#039; with the following content&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Blacklist this - it doesn&#039;t work!&lt;br /&gt;
blacklist hp_wmi&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
I gave the machine a reboot and afte that, the &#039;&#039;&#039;hp-wifi&#039;&#039;&#039; entry was gone in the rfkill output, and things works.&lt;br /&gt;
&lt;br /&gt;
== BIOS upgrade from Linux ==&lt;br /&gt;
&lt;br /&gt;
Generally, BIOS upgrades have been moved to the BIOS itself these days. This saves a lot of work and quite possibly lives after those who earier rammed their heads through walls, now can upgrade directly from the internet instead of using obscure operating systems best avoided. Sometimes, however, one must use these nevertheless. This is a quick run-through on your options.&lt;br /&gt;
&lt;br /&gt;
=== DOS ===&lt;br /&gt;
&lt;br /&gt;
Most non-automatic BIOS upgrades are installed from DOS. Doing a BIOS upgrade this way, is generally non-problematic. Just install a USB thingie with [https://www.freedos.org/ FreeDOS], copy your file(s) onto the thing and boot on it. The commandline is the same as old MS/DOS, except a wee bit more userfriendly, but not a lot.&lt;br /&gt;
&lt;br /&gt;
=== Windows ===&lt;br /&gt;
&lt;br /&gt;
Some macahines, like laptops from &#039;&#039;&#039;HP&#039;&#039;&#039;, may have BIOS upgrades that are made to be installed from Windows and won&#039;t run in FreeDOS or MS/DOS, instead throwing an error, saying &#039;&#039;&#039;This program cannot be run in DOS mode&#039;&#039;&#039;. This means you&#039;ll have to boot on a Windows rescue disc and do the job from there. Googling this, tells you it&#039;s quite easy, you just choose &#039;make rescue disc&#039; from Windows, and it&#039;s all good, except if you don&#039;t run Windows, that is. To remedy this problem, do as follows:&lt;br /&gt;
&lt;br /&gt;
==== Download Windows ====&lt;br /&gt;
&lt;br /&gt;
Since you don&#039;t run Windows and possibly don&#039;t have a spouse or friend around with such unhealthy habits either, you need to get it. It&#039;s quite easy - just google &#039;download windows&#039; and it&#039;ll send you to [https://www.microsoft.com/en-us/software-download/windows10ISO somewhere like this].&lt;br /&gt;
&lt;br /&gt;
==== Burn it! ====&lt;br /&gt;
&lt;br /&gt;
Now it&#039;s time to burn the installer on a DVD ROM. You&#039;ll need a double-layered one, since the OS is &amp;gt; 4.7GiB, but I&#039;m sure you have a ton of those lying around. Now, just place your optical medium in your optical drive and burn, baby, burn!&lt;br /&gt;
&lt;br /&gt;
==== Or make a USB thing? ====&lt;br /&gt;
&lt;br /&gt;
Not a lot of machines have optical drives these days, so you may want to use an USB pen drive or something instead. This is easy, just make the USB bootable with the Windows application Microsoft has made for this. Unfortunately, this only runs on Windows, and unlike stuff like Debian, where the &#039;&#039;&#039;iso&#039;&#039;&#039; file can be dd&#039;ed directly onto a USB drive to make it bootable, the Windows &#039;&#039;&#039;iso&#039;&#039;&#039;s don&#039;t come with this luxury. There are lots of methods to make bootable USB things from iso files out there, but the only thing most of them have in common, is that they generally don&#039;t work.&lt;br /&gt;
&lt;br /&gt;
===== WoeUSB =====&lt;br /&gt;
&lt;br /&gt;
After hours of swearing, it&#039;s nice to come across software like [https://github.com/slacka/WoeUSB WoeUSB]. It may not be perfect, it relies on a bunch of GUI stuff you&#039;ll never need and so on, but it &#039;&#039;&#039;&#039;&#039;works&#039;&#039;&#039;&#039;&#039;, and that&#039;s the important part! Just clone the repo and RTFM and it&#039;s all nice. It&#039;s slow, but hell, getting a windows machine and/or an optical drive might be slower.&lt;br /&gt;
&lt;br /&gt;
WoeUSB does nothing fancy, but it &#039;&#039;&#039;does&#039;&#039;&#039; work. It will create a filesystem, FAT32 or NTFS (better use NTFS, FAT32 has its limits). It creates normal filesystems and so on. Just make sure to copy in the BIOS update file, usually an exe file, to run when Windows is up and running.&lt;br /&gt;
&lt;br /&gt;
===== Install BIOS =====&lt;br /&gt;
&lt;br /&gt;
Boot on the Windows USB thing and choose &#039;repair computer&#039; and then &#039;command prompt&#039;. Find the install file, and if you&#039;re lucky, you&#039;ll find it needs a 32bit OS, just like I did. Since the 64bit version doesn&#039;t include 32bit compatibility in the installer, revert to downloading the 32bit version of windows and start over. Pray to your favourite god(s) not to get across such machines again - it might help.&lt;br /&gt;
&lt;br /&gt;
= 3D printer stuff =&lt;br /&gt;
&lt;br /&gt;
== Hydrophilic filament ==&lt;br /&gt;
&lt;br /&gt;
Most popular filament types, including PLA, PETG, PP or PA (Polyamide, normally known as Nylon) and virtualy any filament type named [https://www.matterhackers.com/news/filament-and-water poly-something] (and thus with an acronym of P-something) are hydrophilic (also (somewhat incorrectly) called hydroscopic), meaning so long they&#039;re dryer than the atmosphere around them, they&#039;ll do their best to suck out the atmosphere&#039;s humidity. This is why most filament are shrink-wrapped with a small bag of silica gel in it. If such filament is exposed for normal humid air for some time, it&#039;ll become very hard to use. Most of my experience is with PLA, which can handle a bit (depending on make), but still not a lot. With PLA, if you end up with prints where the filament seems not to stick, it may help with a higher temperature. Otherwise, the filament must be [https://all3dp.com/2/how-to-dry-filament-pla-abs-and-nylon/ baked]. If you don&#039;t want to use your oven, try something like a [https://www.jula.no/catalog/hjem-og-husholdning/kjokkenmaskiner/mattilberedningsapparater/frukt-sopptorker/frukt-sopptorker-001641/#tab02 fruit and mushroom dryer]. Then get a good, sealble plastic box and add something like half a kilogram of [https://www.ebay.com/sch/sis.html?_nkw=1KG+Orange+Replacement+Desiccant+Indicating+Silica+Gel+Beads+for+Drawers%2C+Camera&amp;amp;_id=131938742628&amp;amp;&amp;amp;_trksid=p2057872.m2749.l2658 silica gel] to an old sock, tie it and put it in the your new dry box.&lt;br /&gt;
&lt;br /&gt;
Please note that ABS is hydrophobic, so you won&#039;t have to worry too much there. Also, remember that PA/Nylon is extremely hydrophilic. Even a couple of days in normal air humidity can ruin it completely and will require baking.&lt;br /&gt;
&lt;br /&gt;
== Upgrading the firmware on an Ender 3 ==&lt;br /&gt;
&lt;br /&gt;
This is about upgrading the firmware, and thus also flashing a bootloader to the Creality Ender 3 3D printer. Most of this is well documented on several place, like o [https://www.youtube.com/watch?v=fIl5X2ffdyo the video from Teaching tech] and elsewhere, but I&#039;ll just summarise some issues I had.&lt;br /&gt;
&lt;br /&gt;
=== Using an arduino Nano as a programmer ===&lt;br /&gt;
&lt;br /&gt;
The CR-10, Ender 3 and a few other printers from Creality come without a bootloader, so you&#039;ll need to flash one before upgrading the firmware. Well, strictly speakning, you don&#039;t need one, you can save those 8kB or so for other stuff and use a programmer to write the whole firmware, but then you&#039;ll need to wire up everything every time you want a new firmware, so in my world, you &#039;&#039;&#039;do&#039;&#039;&#039; need the bootloader, since it&#039;s easier. Note that some newer printers, like the CR-10S and possibly all newer ones, come with the bootloader already and thus won&#039;t need another.&lt;br /&gt;
&lt;br /&gt;
To install a bootloader, you&#039;ll need a programmer, and I didn&#039;t have one available. Having some el-cheapo china-copies of Ardinos around, I read I could use one and tried so. Although the docs mostly mention the Uno etc, it&#039;s just as simple with the Nano copy.&lt;br /&gt;
&lt;br /&gt;
So, grab an arduino, plug it to your machine with an USB cable, and, using the Arduino IDE, use the ArduinoISP sketch there (found under Examples) to burn the software needed for the arduino to work as a programmer. When this is done, connect a 10µF capacitor between RST and GND to stop it from resetting when used as a programmer. Connect the MOSI, MISO and SCK pins from the ICSP block (that little isolated 6-pin block on top of the ardu). See [https://www.arduino.cc/en/Tutorial/ArduinoISP here] for a pinout. Then find Vcc and GND either onthe ICSP block or elsewhere. Some sites say that on some boards you shouldn&#039;t use the pins on the ICSP block for this. I doubt it matters, though. Then connect another jumper wire from pin 10 on the ardu to work as the reset pin outwards to the chip being programmed (that is, on the printer). The ICSP jumper block pin layout is the same on the printer and on the ardu, and probably elsewhere. Sometimes [https://xkcd.com/927/ standardisation] actually works…&lt;br /&gt;
&lt;br /&gt;
See https://cloud.karlsbakk.net/index.php/s/zw48YJjzaf8Rc2F for a pic with the ardu (this wiki is broken atm, will fix it later)&lt;br /&gt;
&lt;br /&gt;
== Flashing the printer ==&lt;br /&gt;
&lt;br /&gt;
When the boot loader is in place, possibly after some wierd errors from during the process, the screen on the 3d printer will go blank and it&#039;ll behave like being bricked. This is ok. Now disconnect the wires and connect the USB cable between computer and printer, download the [https://www.th3dstudio.com/knowledgebase/th3d-unified-firmware-package/ TH3D unified firmware] and configure it for your particular needs. The video mentioned above describes this well. After flashing the new firmware, you&#039;ll probably get some timeouts and errors, since apparently it resets the printer after giving it the new firmware, but without notifying the flashing software of it doing so. If this happens, hold your breath and reboot the printer and check its tiny monitor - it should work. If it doesn&#039;t work, try to flash it again, and if that doesn&#039;t work, try flashing the programmer again yet another time, just for kicks.&lt;br /&gt;
&lt;br /&gt;
PS: I tried enabling &#039;&#039;&#039;MANUAL_MESH_LEVELING&#039;&#039;&#039;, which in the code says that &#039;&#039;If used with a 1284P board the bootscreen will be disabled to save space&#039;&#039;. This effectively disabled the whole thing, and apparently may be making the firmware image a wee bit too large for it to fit the 1284P on the ender. It works well without it, though.&lt;br /&gt;
&lt;br /&gt;
== And then… ==&lt;br /&gt;
&lt;br /&gt;
With the new firmware in place, the printer should work as before, although with thermal runaway protection to better avoid fires in case the shit hits the fan, and to allow for things like autolevelling. With any luck, [https://www.precisionpiezo.co.uk/ this thing] may be ready for use by the time you read this - it surely looks nice!&lt;br /&gt;
&lt;br /&gt;
roy&lt;/div&gt;</summary>
		<author><name>Roy</name></author>
	</entry>
	<entry>
		<id>https://wiki.malinux.no/index.php?title=Roy%27s_notes&amp;diff=150</id>
		<title>Roy&#039;s notes</title>
		<link rel="alternate" type="text/html" href="https://wiki.malinux.no/index.php?title=Roy%27s_notes&amp;diff=150"/>
		<updated>2020-01-28T02:03:08Z</updated>

		<summary type="html">&lt;p&gt;Roy: /* Growing devices */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= LVM, md and friends =&lt;br /&gt;
&lt;br /&gt;
== Linux&#039; Logical Volume Manager (LVM) ==&lt;br /&gt;
&lt;br /&gt;
=== LVM in general ===&lt;br /&gt;
&lt;br /&gt;
LVM is designed to be an abstraction layer on top of physical drives or RAID, typically [https://raid.wiki.kernel.org/index.php/RAID_setup mdraid] or [https://help.ubuntu.com/community/FakeRaidHowto fakeraid]. Keep in mind that fakeraid should be avoided unless you really need it, like in conjunction with dual-booting linux and windows on fakeraid. LVM broadly consists of three elements, the &amp;quot;physical&amp;quot; devices (PV), the volume group (VG) and the logical volume (LV). There can be multiple PVs, VGs and LVs, depending on requirement. More about this below. All commands are given as examples, and all of them can be fine-tuned using extra flags in need of so. In my experience, the defaults work well for most usecases.&lt;br /&gt;
&lt;br /&gt;
I&#039;m mentioning filesystem below too. Where I write ext4, the samme applies to ext2 and ext3.&lt;br /&gt;
&lt;br /&gt;
==== Create a PV ====&lt;br /&gt;
&lt;br /&gt;
A PV is the &amp;quot;physical&amp;quot; parts. This does not need to be a physical disk, but can also be another RAID, be it an mdraid, fakeraid, hardware raid, a virtual disk on a SAN or otherwisee or a partition on one of those. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#  These add three PVs, one on a drive (or hardware raid) and another two on mdraids.&lt;br /&gt;
pvcreate /dev/sdb&lt;br /&gt;
pvcreate /dev/md1 /dev/md2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For more information about pvcreate, see [https://linux.die.net/man/8/pvcreate the manual].&lt;br /&gt;
&lt;br /&gt;
==== Create a VG ====&lt;br /&gt;
&lt;br /&gt;
The volume group consists of one or more PVs grouped together on which LVs can be placed. If several PVs are grouped in a VG, it&#039;s generally a good idea to make sure these PVs have some sort of redundancy, as in mdraid/fakeraid or hwraid. Otherwise it will be like using a [https://en.wikipedia.org/wiki/RAID RAID-0] with a single point of failure on each of the independant drives. LVM has [https://unix.stackexchange.com/questions/150644/raiding-with-lvm-vs-mdraid-pros-and-cons  RAID code in it] as well, so you can use that. I haven&#039;t done so myself, as I generally stick to mraid. The reason is mdraid is, in my opinion older and more stable and has more users (meaning bugs are reported and fixed faster whenever they are found). That said, I beleive the actual RAID code used in LVM RAID are the same function calls as for mdraid, so it may not be much of a difference. I still stick with mdraid. To create a VG, run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create volume group my_vg&lt;br /&gt;
vgcreate my_vg /dev/md1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that if vgcreate is run with a PV (as /dev/md1 above) that is not defined as a PV (like above), this is done implicitly, so if you don&#039;t need any special flags to pvcreate, you can simply skip it and let vgcreate do that for you.&lt;br /&gt;
&lt;br /&gt;
==== Create an LV ====&lt;br /&gt;
&lt;br /&gt;
LVs can be compared to partitions, somehow, since they are bounderies of a fraction or all of that of a VG. The difference between them and a partition, however, is that they can be grown or shrunk easily and also moved around between PVs without downtime. This flexibility makes them superiour to partitions as your system can be changed without users noticing it. By default, an LV is alloated &amp;quot;thickly&amp;quot;, meaning all the data given to it, is allocated from the VG and thus the PV. The following makes a 100GB LV named &amp;quot;thicklv&amp;quot;. When making an LV, I usually allocate what&#039;s needed plus some more, but not everything, just to make sure it&#039;s space available for growth on any of the LVs on the VG, or new LVs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a thick provisioned LV named thicklv on the VG my_vg&lt;br /&gt;
lvcreate -n thicklv -L 100G my_vg&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After the LV is created, a filesystem can be placed on it unless it is meant to be used directly. The application for direct use include swap space, VM storage and certain database systems. Most of these will, however, work on filesystems too, although my testing has shown that on swap space, there is a significant performance gain for using dedicated storage without a filesystem. As for filesystems, most Linux users use either ext4 or xfs. Personally, I generally use XFS these days. See my notes below on filesystem choice.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a filesystem on the LV - this could have been mkfs -t ext4 or whatever filesystem you choose&lt;br /&gt;
mkfs -t xfs /dev/my_vg/thicklv&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then just edit /etc/fstab with correct data and run mount -a, and you should be all set.&lt;br /&gt;
&lt;br /&gt;
==== Create LVM cache ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
lvcreate -L 1G -n _cache_meta data /dev/md1&lt;br /&gt;
&lt;br /&gt;
lvcreate -l100%FREE -n _cache data /dev/md1&lt;br /&gt;
&lt;br /&gt;
# Some would want --cachemode writeback, but seriously, I wouldn&#039;t recommend it. Metadata or data can be easily corrupted in case of failure.&lt;br /&gt;
lvconvert --type cache-pool --cachemode writethrough --poolmetadata data/_cache_meta data/_cache&lt;br /&gt;
&lt;br /&gt;
lvconvert --type cache --cachepool data/_cache data/data&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Disabling LVM cache ====&lt;br /&gt;
&lt;br /&gt;
If you for some reason want to disable caching, this will do it cleanly and remove the LVs earlier created for caching the main device.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
lvconvert --uncache data/data&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Growing devices ====&lt;br /&gt;
&lt;br /&gt;
LVM objects can be grown and shrunk. If a PV resides on a RAID where a new drive has been added or otherwise grown, or on a partition or virtual disk that has been extended, the PV must be updated to reflect these changes. The following command will grow the PV to the maximum available on the underlying storage. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Resize the PV /dev/md (not the RAID, only the PV on the RAID) to its full size&lt;br /&gt;
pvresize /dev/md1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If a new PV is added, the VG can be grown to add the space on that in addition to what&#039;s there already. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Extend my_vg to include md2 and its space&lt;br /&gt;
vgextend my_vg /dev/md2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
With more space available in the VG, the LV can now be extended. Let&#039;s add another 50GB to it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Extend thicklv - add 50GB. If you know you won&#039;t need the space anywhere else, you may want to&lt;br /&gt;
# lvresize -l+100%FREE instead. Keep in mind the difference between -l (extents) and -L (bytes)&lt;br /&gt;
lvresize -L +50G my_vg/thicklv&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Growing filesystems ====&lt;br /&gt;
After the LV has grown, run &#039;&#039;xfs_growfs&#039;&#039; (xfs) or &#039;&#039;resize2fs&#039;&#039; (ext4) to make use of the new data. To grow the filesystem to all available space on ext[234], run the below command.  To partly grow the filesystem or to shrink it or otherwise, please see the manuals.&lt;br /&gt;
&lt;br /&gt;
The filesystem can be mounted when this is run. If you for some reason get an &#039;&#039;&#039;access denied&#039;&#039;&#039; error when running this as root or with sudo, it&#039;s likely caused by a filesystem error. To fix this, unmount the filesystem first and run &#039;&#039;&#039;fsck -f /dev/my_vg/thicklv&#039;&#039;&#039; and remount it before retrying to extend it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
resize2fs /dev/my_vg/thicklv&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Similarly, with XFS, but note that xfs_growfs doesn&#039;t take the device name, but the filesystem&#039;s mount point. In the case of XFS, also note that the filesystem &#039;&#039;&#039;&#039;&#039;must&#039;&#039;&#039;&#039;&#039; be mounted to be grown. This, in contrast to how it was in the old days when filesystems had to be unmounted to be grown.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
xfs_growfs /my_mountpoint&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Rename system VG ====&lt;br /&gt;
&lt;br /&gt;
Some distros create VG names like those-from-a-sysadmin-with-a-well-developed-paranoia-not-to-hit-a-duplicate. Debian, for instance, uses names like &amp;quot;my-full-hostname-vg&amp;quot;. Personally, I don&#039;t like these, since if I were to move a disk or vdisk around to somewhere else, I&#039;d make sure not to add a disk named &#039;sys&#039; to an existing system. If you do, most distros will refuse to use the VGs with duplicate names, resulting in the OS not booting until either one is specified by its UUID or just one removed. As I&#039;m aware of this, I stick to the super-risky thing of all system VGs named &#039;sys&#039; and so on.&lt;br /&gt;
&lt;br /&gt;
If you do this, keep in mind that it may blow up your computer and take your girl- or boyfriend with it or even make either of them pregnant, allowing Trump to rule your life and generally make things suck. You&#039;re on your own!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Rename the VG&lt;br /&gt;
vgrename my-full-hostname-vg sys&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, in /boot/grub/grub.cfg, change the old lv path from something like &#039;/dev/mapper/debian--stretch--machine--vg-root&#039; to your new and fancy &#039;/dev/sys/root. Likewise, in /etc/fstab, change occurences of &#039;/dev/mapper/debian--stretch--machine--vg-&#039; (or similar) with &#039;/dev/sys/&#039;. Here, this was like this - the old ones commented out.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;fstab&amp;quot;&amp;gt;&lt;br /&gt;
#/dev/mapper/debian--stretch--box--vg-root      /               ext4            errors=remount-ro,discard       0       1&lt;br /&gt;
/dev/sys/root                                   /               ext4            errors=remount-ro,discard       0       1&lt;br /&gt;
# /boot was on /dev/vda1 during installation&lt;br /&gt;
UUID=myverylonguuidwithatonofgoodinfoinit       /boot           ext2            defaults                        0       2&lt;br /&gt;
#/dev/mapper/debian--stretch--box--vg-swap_1    none            swap            sw                              0       0&lt;br /&gt;
/dev/sys/swap_1                                 none            swap            sw                              0       0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Update /etc/initramfs-tools/conf.d/resume with similar data for swap.&lt;br /&gt;
&lt;br /&gt;
You might want to run &#039;update-initramfs -u -k all&#039; after this, but I&#039;m not sure if it&#039;s needed.&lt;br /&gt;
&lt;br /&gt;
Now, pray to the nearest god(s) and give it a reboot and it should (probably) work.&lt;br /&gt;
&lt;br /&gt;
After reboot, run &#039;&#039;&#039;swapoff -a&#039;&#039;&#039;, then &#039;&#039;&#039;mkswap /dev/sys/swap_1&#039;&#039;&#039; (or whatever it&#039;s called on your system) and &#039;&#039;&#039;swapon -a&#039;&#039;&#039; again. You may want to give it another reboot or two for kicks, but it should work well even without that.&lt;br /&gt;
&lt;br /&gt;
=== Migration tools ===&lt;br /&gt;
&lt;br /&gt;
At times, storage regimes change, new storage is added and sometimes it&#039;s not easy to migrate with the current hardware or its support systems. Once I had to migrate a 45TiB fileserver from one storage system to another, preferably without downtime. The server originally had three 15TiB PVs of which two were full and the third half full. I resorted to using [https://linux.die.net/man/8/pvmove pvmove] to just move the data on the PVs in use to a new PV. We started out with creating a new 50TiB PV, sde, and then to pvmove.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Attach /dev/sde to the VG my_vg&lt;br /&gt;
vgextend my_vg /dev/sde&lt;br /&gt;
&lt;br /&gt;
# Move the contents from /dev/sdb over to /dev/sde block by block. If a target is not given in pvmove,&lt;br /&gt;
# the contents of the source (sdb here) will be put somewhere else in the pool.&lt;br /&gt;
pvmove /dev/sdb /dev/sde&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This took a while (as in a week or so) - the pvmove command uses old code and logic (or at least did that when I migrated this in November 2016), but it affected performance on the server very little, so users didn&#039;t notice. After the first PV was migrated, I continued with the other two, one after the other, and after a month or so, it was migrated. We used this on a number of large fileservers, and it worked flawlessly. Before doing the production servers I also tried interrupting pvmove in various ways, including hard resets, and it just kept on after the reboot.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;NOTE:&#039;&#039;&#039;&#039;&#039; &#039;&#039;Even though it worked well for us, &#039;&#039;&#039;always&#039;&#039;&#039; keep a good backup before doing this. Things may go wrong, and without a good backup, you may be looking for a hard-to-find new job the next morning&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
==== mdadm workarounds ====&lt;br /&gt;
&lt;br /&gt;
===== Migrate from a mirror (raid-1) to raid-10 =====&lt;br /&gt;
&lt;br /&gt;
Create a mirror&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sdb /dev/sdc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
LVM (pv/vg/lv) on md0 (see above), put a filesystem on the lv and fill it with some data.&lt;br /&gt;
&lt;br /&gt;
Now, some months later, you want to change this to raid-10 to allow for the same amount of redundancy, but to allow more disks into the system.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mdadm --grow /dev/md0 --level=10&lt;br /&gt;
mdadm: Impossibly level change request for RAID1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So - no - doesn&#039;t work. But - we&#039;re on &lt;br /&gt;
&lt;br /&gt;
Since we&#039;re on lvm already, this&#039;ll be easy. If you&#039;re using filesystems directly on partitions, you can do this the same way, but without the pvmove part, using rsync or whateever you like instead. I&#039;d recommend using lvm for for the new raid, which should be rather obvious from this article. Now plug in a new drive and create a new raid10 on that one. If you two new drives, install both. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# change &amp;quot;missing&amp;quot; to the other device name if you installed two new drives&lt;br /&gt;
mdadm --create /dev/md1 --level=10 --raid-devices=2 /dev/vdd missing&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, as described above, just vgextend the vg, adding the new raid and run pvmove to move the data from the old pv (residing on the old raid1) to the new pv (on raid10). Afte rpvmove is finished (which may take awile, see above), just&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
vgreduce raidtest /dev/md0&lt;br /&gt;
pvremove /dev/md0&lt;br /&gt;
mdadm --stop /dev/md0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
…and your disk is free to be added to the new array. If the new raid is running in degraded mode (if you created it with just one drive), better don&#039;t wait too long, since you don&#039;t have redundancy. Just mdadm --add the devs.&lt;br /&gt;
&lt;br /&gt;
If you now have /dev/mdstat telling you your raid10 is active and have three drives, of which one is a spare, it should look something like this&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5] [raid4] [raid10]&lt;br /&gt;
md1 : active raid10 vdc[3](S) vdb[2] vdd[0]&lt;br /&gt;
      8380416 blocks super 1.2 2 near-copies [2/2] [UU]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Just mdadm --grow --raid-devices=3 /dev/md1&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;RAID section is not complete. I&#039;ll write more on migraing from raid10 to raid6 later. It&#039;s not straight forward, but easier than this one :)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== Thin provisioned LVs ===&lt;br /&gt;
&lt;br /&gt;
Thin provisioning on LVM is a method used for not allocating all the space given to an LV. For instance, if you have a 1TB VG and want to give an LV 500GB, although it currently only uses a fraction of that, a thin lv can be a good alternative. This will allow for adding a limit to how much it can use, but also to let it grow dynamically without manual work by the sysadmin. Thin provisioning adds another layer of abstaction by creating a special LV as a &#039;&#039;thin pool&#039;&#039; from which data is allocated to the &#039;&#039;thin volume(s)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== Create a thin pool ====&lt;br /&gt;
&lt;br /&gt;
Allocate 1TB to the thin pool to be used for thinly provisioned LVs. Keep in mind that the space allocated to the thin pool is in fact thick provisioned. Only the volumes put on &#039;&#039;thinpool&#039;&#039; are thin provisioned. This will create two hidden LVs, one for data and one for metadata. Normally the defaults will do, but check the manual if the data doesn&#039;t match the usual patterns (such as billions of files, resulting in huge amounts of metadata). I &#039;&#039;beleive&#039;&#039; the metadata part should be resizable at a later time if needed, but I have not tested it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a pool for thin LVs. Keep in mind that the pool itself is not thin provisioned, only the volumes residing on it&lt;br /&gt;
lvcreate --size 1T --type thin-pool --thinpool thinpool my_vg&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Create a thin volume ====&lt;br /&gt;
&lt;br /&gt;
You have the thinpool, now put a thin volume on it. It will allocate some space for metadata, but probably not much (a few megs, perhaps).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Now, create a volume with a virtual (-V) size of half a terabyte named thin_pool, but using the thinpool (-T) named thin_pool for storage&lt;br /&gt;
lvcreate -V 500G -T my_vg/thin_pool --name thinvol&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The new volume&#039;s device name will be /dev/thinvol. Now, create a filesystem on it, add to fstab and mount it. The &#039;&#039;&#039;df&#039;&#039;&#039; command will return available space according to the virtual size (-V), while lvs will show how much data is actually used on each of the thinly provisioned volumes.&lt;br /&gt;
&lt;br /&gt;
== Filesystem dilemmas ==&lt;br /&gt;
&lt;br /&gt;
=== XFS or ext4 or something else ===&lt;br /&gt;
The choice of filesystem varies for your use. Distros such as RHEL/CentOS has moved to XFS by default from v7. Debian/Ubuntu still sticks to ext4, like most other. I&#039;ll discuss my thoughts below on ext4 vs XFS and leave the other filesystems for later.&lt;br /&gt;
&lt;br /&gt;
==== ext4 ====&lt;br /&gt;
ext4 is probably the most used filesystem on linux as of writing. It&#039;s rock stable and has been extended by a lot of extensions since the original ext2. It still retains backward compatibility, being able to mount and fsck ext2 and ext3 with the ext4 driver. However, it doesn&#039;t handle large filesystems very well. If a filesystem is created for &amp;lt;16TiB, it cannot be grown to anything larger than 16TiB. This may have changed lately, though. One other issue is handling errors. If a large filesystem (say 10TiB) is damaged, an fsck may take several hours, leading to long downtime.&lt;br /&gt;
&lt;br /&gt;
==== XFS ====&lt;br /&gt;
XFS, originally developed by SGI some time in the bronze age, but has been worked on heavily after that. RHEL and Centos version 7 and forward, uses XFS as the default filesystem. It is quick, it scales well, but it lacks at least two things ext4 has. It cannot be shrunk (not that you normally need that, but nice if you have a typo or you need to change things). Also, it doesn&#039;t allow for automatic fsck on bootup. If something is messed up on the filesystem, you&#039;ll have to login as root on the console (not ssh), which might be an issue on some systems. The fsck equivalent, xfs_repair, is a *lot* faster than ext4&#039;s fsck, though.&lt;br /&gt;
&lt;br /&gt;
==== ZFS ====&lt;br /&gt;
ZFS is like a combination of RAID, LVM and a filesystem, supporting full checksumming, auto-healing (given sufficient redundancy), compression, encryption, replication, deduplication (if you&#039;re brave and have a &#039;&#039;ton&#039;&#039; of memory) and a lot more. It&#039;s a separate chapter and needs a lot more talk than paragraph here.&lt;br /&gt;
&lt;br /&gt;
== Low level disk handling ==&lt;br /&gt;
&lt;br /&gt;
This section is for low-level handling of disks, regardless of storage system elsewhere. These apply to mdraid, lvmraid and zfs and possibly other solutions, with the exception of individual drives on hwraid (and maybe fakeraid), since there, the drives are hidden from Linux (or whatever OS).&lt;br /&gt;
&lt;br /&gt;
=== S.M.A.R.T. and slow drives ===&lt;br /&gt;
Modern (that is, from about 1990 or later) have S.M.A.R.T. (or just smart, since it&#039;s easier to type) monitoring built in, meaning the disk&#039;s controller is monitoring itself. This is handy and will ideally tell you in advance that a drive is flakey or dying. Modern (2010+) smart monitoring is more or less the same. It can be trusted about 50% of the time. Usually, if smart detects an error, it&#039;s a real error. I don&#039;t think I&#039;ve seen it reporting a false positive, but others may know better. &lt;br /&gt;
&lt;br /&gt;
==== smartmontools ====&lt;br /&gt;
First, install smartmontool and run smartclt -H /dev/yourdisk (/dev/sda or something) to get a health report. Then perhaps run smartctl -a /dev/yourdisk and look for &#039;current pending sectors&#039; This should be zero. Also check the temperature, which normally should be much above 50.&lt;br /&gt;
&lt;br /&gt;
==== single, slow drive ====&lt;br /&gt;
What may happen, is smart not seeing anything and life goes on like before, only slower and less prouductive, without telling anyone. If you stubler over this issue, you&#039;ll probably see it during a large rsync/zfs send/receive or a resync/rebuild/resilver of the raid/zpool. During this, it feels like everything is slow and your RAID has turned into a RAIF (redundant array of inexpensive floppies). To check if you have a single drive messing up it all, check with &#039;&#039;&#039;iostat -x 2&#039;&#039;&#039;, having 2 being the delay between each measurement. Interrupt it with ctrl+x. If there&#039;s a rougue drive there, it should stand out like sdg below&lt;br /&gt;
&lt;br /&gt;
 avg-cpu:  %user   %nice %system %iowait  %steal   %idle&lt;br /&gt;
            0.38    0.00    1.75    0.00    0.00   97.87&lt;br /&gt;
&lt;br /&gt;
 Device            r/s     w/s     rkB/s     wkB/s   rrqm/s   wrqm/s  %rrqm  %wrqm r_await w_await aqu-sz rareq-sz wareq-sz  svctm  %util&lt;br /&gt;
 sda              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdb              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdc              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdd              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sde              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdf              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdg              3.50    0.00   2352.00      0.00     0.00     0.00   0.00   0.00 14306.29    0.00  13.85   672.00     0.00 285.71 100.00&lt;br /&gt;
 sdh              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
&lt;br /&gt;
In ZFS land, you should be able to get similar data with &#039;&#039;&#039;zpool iostat -v &amp;lt;pool&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Now you know the bad drive (sdg), pull it from the raid with &#039;&#039;&#039;mdadm --fail /dev/mdX /dev/sdX&#039;&#039;&#039;. Now test the drive&#039;s performance manually, just simply:&lt;br /&gt;
&lt;br /&gt;
 # hdparm -t /dev/sdg&lt;br /&gt;
 &lt;br /&gt;
 /dev/sdg:&lt;br /&gt;
  Timing buffered disk reads:   2 MB in  5.37 seconds = 381.46 kB/sec&lt;br /&gt;
&lt;br /&gt;
Bingo - nothing you&#039;d want to keep. For a good drive, it should be something like 100-200MB/s&lt;br /&gt;
&lt;br /&gt;
PS: Keep in mind that you have a degraded RAID by now in case you had a spare waiting for things to happen.&lt;br /&gt;
&lt;br /&gt;
Try to replace the cable and/or try the disk on another port/controller. If the result from hdparm persists, it&#039;s probably a bad cable&lt;br /&gt;
&lt;br /&gt;
So, then, just psycially locate the drive, pull it out, take out the discs and magnets and recycle the rest.&lt;br /&gt;
&lt;br /&gt;
=== &amp;quot;Unplug&amp;quot; drive from system ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Find the device unit&#039;s number with something like&lt;br /&gt;
find /sys/bus/scsi/devices/*/block/ -name sdd&lt;br /&gt;
# returning /sys/bus/scsi/devices/3:0:0:0/block/sdd here, &lt;br /&gt;
# meaning 3:0:0:0 is the SCSI device we&#039;re looking for.&lt;br /&gt;
&lt;br /&gt;
# Given this is the correct device, and you want to &#039;unplug&#039; it, do so by&lt;br /&gt;
echo 1 &amp;gt; /sys/bus/scsi/devices/3:0:0:0/delete&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Rescan disk controllers ===&lt;br /&gt;
If a drive is added and for some reason doesn&#039;t get detected, or is removed by the command above, it can be rediscovered with a sysfs command to the scsi host to which it is connected. Since there may be quite a few of these, an easy way is to just scan them all and check the output of &#039;&#039;&#039;dmesg -T&#039;&#039;&#039; after running it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Make a list of controllers and send a rescan message to each of them. It won&#039;t do anything &lt;br /&gt;
# for those where nothing has changed, but it will show new drives where they have been added.&lt;br /&gt;
for host_scan in /sys/class/scsi_host/host*/scan&lt;br /&gt;
do&lt;br /&gt;
  echo &#039;- - -&#039; &amp;gt; $host_scan&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Fail injection with debugfs ===&lt;br /&gt;
[https://lxadm.com/Using_fault_injection https://lxadm.com/Using_fault_injection]&lt;br /&gt;
&lt;br /&gt;
== mdadm stuff ==&lt;br /&gt;
=== Spare pools ===&lt;br /&gt;
In the old itmes, mdadm supported only a dedicated spare per md device, so if working with a large set of drives (20? 40?), where you&#039;d want to setup more raid sets to increase redundancy, you&#039;d dedicate a spare to each of the raid sets. This has changed (some time ago?), so in these modern, heathen days, you can change mdadm.conf, usually placed under /etc/mdadm, and add &#039;spare-group=somegroup&#039; where &#039;somegroup&#039; is a string identifying the spare group. After doing this, run &#039;&#039;&#039;update-initramfs -u&#039;&#039;&#039; and reboot and add a spare to one of the raid sets in the spare group, and md will use that or those spares for all the raidsets in that group.&lt;br /&gt;
&lt;br /&gt;
As some pointed out on #linux-raid @ irc.freenode.net, this feature is very badly documented, but as far as I can see, it works well.&lt;br /&gt;
&lt;br /&gt;
==== Example config ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create two raidsets&lt;br /&gt;
&lt;br /&gt;
mdadm --create /dev/md1 --level=6 --raid-devices=6 /dev/vd[efghij]&lt;br /&gt;
mdadm --create /dev/md2 --level=6 --raid-devices=6 /dev/vd[klmnop]&lt;br /&gt;
&lt;br /&gt;
# get their UUID etc&lt;br /&gt;
&lt;br /&gt;
mdadm --detail --scan&lt;br /&gt;
ARRAY /dev/md/1 metadata=1.2 name=raidtest:1 UUID=1a8cbdcb:f4092350:348b6b80:c054d74c&lt;br /&gt;
ARRAY /dev/md/2 metadata=1.2 name=raidtest:2 UUID=894b1b7c:cb7eba70:917d6033:ea5afd2b&lt;br /&gt;
&lt;br /&gt;
# Put those lines into /etc/mdadm/mdadm.conf and and add the spare-group&lt;br /&gt;
&lt;br /&gt;
ARRAY /dev/md/1 metadata=1.2 name=raidtest:1 spare-group=raidtest UUID=1a8cbdcb:f4092350:348b6b80:c054d74c&lt;br /&gt;
ARRAY /dev/md/2 metadata=1.2 name=raidtest:2 spare-group=raidtest UUID=894b1b7c:cb7eba70:917d6033:ea5afd2b&lt;br /&gt;
&lt;br /&gt;
# update the initramfs and reboot&lt;br /&gt;
&lt;br /&gt;
update-initramfs -u&lt;br /&gt;
reboot&lt;br /&gt;
&lt;br /&gt;
# add a spare drive to one of the raids&lt;br /&gt;
&lt;br /&gt;
mdadm --add /dev/md1 /dev/vdq&lt;br /&gt;
&lt;br /&gt;
# fail a drive on the other raid&lt;br /&gt;
&lt;br /&gt;
mdadm --fail /dev/md2 /dev/vdn&lt;br /&gt;
&lt;br /&gt;
# check /proc/mdstat to see md2 rebuilding with the spare from md1&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Recovery ===&lt;br /&gt;
&lt;br /&gt;
The other day, I came across a problem a user had on #linux-raid@irc.freenode.net. He had an old Qnap NAS that had died and tried plugging the drives in to his Linux machine and got various errors. The two-drive RAID-1 did not come up as it should, &#039;&#039;&#039;dmesg&#039;&#039;&#039; was full of errors from one of the drives (both connected on USB) and so forth.&lt;br /&gt;
&lt;br /&gt;
We went on and started by taking down the machine and just connecting one of the drives. I had him check what was assembled with&lt;br /&gt;
&lt;br /&gt;
 cat /proc/mdstat&lt;br /&gt;
&lt;br /&gt;
That returned /proc/md127 assembled, but LVM didn&#039;t find anything. So running a manual scan&lt;br /&gt;
&lt;br /&gt;
 pvscan --cache /dev/md127&lt;br /&gt;
&lt;br /&gt;
This made linux find the PV, VG and a couple of LVs, but probably because the mdraid was degraded, the LVs were deactivated, according to &#039;&#039;&#039;lvscan&#039;&#039;&#039;. Activating the one with a filesystem manually&lt;br /&gt;
&lt;br /&gt;
 lvchange -a y /dev/&amp;lt;vg&amp;gt;/&amp;lt;lv&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Substitute &amp;lt;vg&amp;gt; and &amp;lt;lv&amp;gt; with the names listed by vgs and lvs.&lt;br /&gt;
&lt;br /&gt;
This worked, and the filesystem on /dev/&amp;lt;vg&amp;gt;/&amp;lt;lv&amp;gt; could be mounted correctly.&lt;br /&gt;
&lt;br /&gt;
== Tuning ==&lt;br /&gt;
&lt;br /&gt;
While trying to compare a 12-disk RAID (8TB disks) to a hwraid, mdraid was slower, so we did a few things to speed things up:&lt;br /&gt;
&lt;br /&gt;
While testing with [https://linux.die.net/man/1/fio fio], monitor /sys/block/md0/md/stripe_cache_active, and see if it&#039;s close to /sys/block/md0/md/stripe_cache_size. If it is, double the size of the latter&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
echo 4096 &amp;gt; /sys/block/md0/md/stripe_cache_size&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Continue until stripe_cache_active stabilises, and then you&#039;ve found the limit you&#039;ll need. You may want to double that for good measure. &lt;br /&gt;
&lt;br /&gt;
(to be continued)&lt;br /&gt;
&lt;br /&gt;
== Links ==&lt;br /&gt;
&lt;br /&gt;
Below are a few links with useful info&lt;br /&gt;
&lt;br /&gt;
* [https://raid.wiki.kernel.org/index.php/Irreversible_mdadm_failure_recovery Irreversible mdadm failure recovery]&lt;br /&gt;
&lt;br /&gt;
= ZFS =&lt;br /&gt;
&lt;br /&gt;
ZFS can do a lot of things most filesystems or volume managers can&#039;t. It checksums all data and metadata and so long that the system uses ECC enabled memory (RAM), it will have complete control over the whole data set, and when (not if) an error occurs, it&#039;ll fix the issue without even throwing a warning. To fix the issue, you&#039;ll obviously need sufficient redundancy (mirrors or RAIDzN). &lt;br /&gt;
&lt;br /&gt;
== ZFS send/receive between machines ==&lt;br /&gt;
&lt;br /&gt;
ZFS has a send/receive mechanism that allows for snapshots to be sent over the wire to a receiving end. This can be a full filesystem, or an incremental change since last send/reveive. In a WAN scenario, you&#039;ll probably want to use VPN for this. On a controlled network, sending in cleartext is also possible. You may as well use ssh, but keep in mind that ssh was never designed to be used as a fullblown vpn solution and is just too slow or the task with large amounts of data. You may, though, use mbuffer, if on a loal LAN.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Allow traffic from the sending IP in whatever firewall interface you&#039;re using (if you&#039;re using a firewall at all, that is)&lt;br /&gt;
ufw allow from x.x.x.x&lt;br /&gt;
# &lt;br /&gt;
# Start the receiver first. This listens on port 9090, has a 1GB buffer,&lt;br /&gt;
    and uses 128kb chunks (same as zfs):&lt;br /&gt;
&lt;br /&gt;
mbuffer -s 128k -m 1G -I 9090 | zfs receive data/filesystem&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To be continued one day… See [https://everycity.co.uk/alasdair/2010/07/using-mbuffer-to-speed-up-slow-zfs-send-zfs-receive/ this] for some more. I&#039;ll get back with details on it.&lt;br /&gt;
&lt;br /&gt;
= General Linux system control =&lt;br /&gt;
&lt;br /&gt;
== Add a new CPU (core) ==&lt;br /&gt;
&lt;br /&gt;
If working with virtual machines, adding a new core can be useful if the VM is slow and the load is multithreaded or multiprocess. To do this, add a new CPU in the hypervisor (be it KVM or VMware or Hyper-V or whatever). Some hypervisors, like VMware, will activate it automatically if open-vm-tools is installed. Please note that open-vm-tools is for VMware only. I don&#039;t know of any such thing for KVM or other hypervisors (although I beleive VirtualBox has its own set of tools, but not as a package). If this doesn&#039;t work, run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
echo 1 &amp;gt; /sys/devices/system/cpu/cpuX/online&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where X is the CPU number you want to add. You can &#039;cat /sys/devices/system/cpu/cpuX/online&#039; to check if it&#039;s online.&lt;br /&gt;
&lt;br /&gt;
= Mount partitions on a disk image =&lt;br /&gt;
&lt;br /&gt;
Sometimes you&#039;ll have a disk image, either from recovering a bad drive after hours (or days or weeks) of ddrescue, and sometimes you just have a disk image from a virtual machine where you want to mount the partitions inside the image. There are three main methods of doing this, which are more or less synonmous, but some easier than the other.&lt;br /&gt;
&lt;br /&gt;
== Basics ==&lt;br /&gt;
&lt;br /&gt;
A disk image is usually like a disk, consisting of either a large filesystem, a PV or a partition table with one or partitions onto which resides a filesystem, a pv, swap or something else. If it&#039;s partitioned, and you want your operating system to mount a filesystem or allow it to see whatever LVM stuff lies on it, you need to isolate the partitions. &lt;br /&gt;
&lt;br /&gt;
== Manual mapping ==&lt;br /&gt;
&lt;br /&gt;
In the oldern days, this was done manually, something like this&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
root@mymachine:~# fdisk -l /dev/vda&lt;br /&gt;
Disk /dev/vda: 25 GiB, 26843545600 bytes, 52428800 sectors&lt;br /&gt;
Units: sectors of 1 * 512 = 512 bytes&lt;br /&gt;
Sector size (logical/physical): 512 bytes / 512 bytes&lt;br /&gt;
I/O size (minimum/optimal): 512 bytes / 512 bytes&lt;br /&gt;
Disklabel type: dos&lt;br /&gt;
Disk identifier: 0xc37b7ea5&lt;br /&gt;
&lt;br /&gt;
Device     Boot    Start      End  Sectors  Size Id Type&lt;br /&gt;
/dev/vda1  *        2048 50333311 50331264   24G 83 Linux&lt;br /&gt;
/dev/vda2       50333312 52426369  2093058 1022M  5 Extended&lt;br /&gt;
/dev/vda5       50333314 52426369  2093056 1022M 82 Linux swap / Solaris&lt;br /&gt;
root@mymachine:~#&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To calculate the start and end of each partition, you just take the start sector and multiply it by the sector size (512 bytes here) and you have the offset in bytes. After this, it&#039;s merely an losetup -o &amp;lt;offset&amp;gt; /dev/loopX &amp;lt;nameofimagefile&amp;gt; and you have the partition mapped to your /dev/loopX (having X being something typically 0-255. After this, just mount it or run pvscan/vgscan/lvscan to probe whatever lvm config is there, and you should be able to mount it like any other filesystem.&lt;br /&gt;
&lt;br /&gt;
== kpartx ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;kpartx&#039;&#039;&#039; does the same as above, more or less, just without so much hassle. Most of it should be automatic and easy to deal with, except it may fail to disconnect the loopback devices sometimes, so you may have to &#039;&#039;&#039;losetup -d&#039;&#039;&#039; them manually. See the manual, &#039;&#039;&#039;kpartx (8)&#039;&#039;&#039;. Please note that &#039;&#039;&#039;partx&#039;&#039;&#039; works similarly and I&#039;d guess the authors of the two tools are arguing a lot of which one&#039;s the best.&lt;br /&gt;
&lt;br /&gt;
== guestmount ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;guestmount&#039;&#039;&#039; is something similar again, but also supports file formats like &#039;&#039;&#039;qcow2&#039;&#039;&#039; and possibly other, proprietary filesystems like &#039;&#039;&#039;vmdk&#039;&#039;&#039; and &#039;&#039;&#039;vdi&#039;&#039;&#039;, but don&#039;t take my word for it - I haven&#039;t tested. Again, see the manual or just read up on the description [http://ask.xmodulo.com/mount-qcow2-disk-image-linux.html?fbclid=IwAR3snTeZvGzp9PLdX11EQhCfOpux6I93CiJ3A2pUomkkRLly9Xo4851mkTY here]. It seems rather trivial.&lt;br /&gt;
&lt;br /&gt;
= Linux on laptops =&lt;br /&gt;
&lt;br /&gt;
== Wifi with HP EliteBook 725/745 on Ubuntu ==&lt;br /&gt;
&lt;br /&gt;
The HP EliteBook 725/745 and similar are equipped with a BCM4352 wifi chip. As with a lot of other stuff from Broadcom, this lacks an open hardware description, so thus no open driver exist. The proper fix, is to replace the NIC with something with an open driver, but again, this isn&#039;t always possible, so a binary driver exists. In ubuntu, run, somehow connect the machine to the internet and run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install bcmwl-kernel-source&lt;br /&gt;
sudo modprobe wl&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you can&#039;t connect the machine to the internet, download the needed packages on another machine and put it on some usb storage. These packages should suffice:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# apt-cache depends bcmwl-kernel-source&lt;br /&gt;
bcmwl-kernel-source&lt;br /&gt;
  Depends: dkms&lt;br /&gt;
  Depends: linux-libc-dev&lt;br /&gt;
  Depends: libc6-dev&lt;br /&gt;
  Conflicts: &amp;lt;bcmwl-modaliases&amp;gt;&lt;br /&gt;
  Replaces: &amp;lt;bcmwl-modaliases&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then install manually with &#039;&#039;&#039;dpkg -i file1.deb file2.deb&#039;&#039;&#039; etc&lt;br /&gt;
&lt;br /&gt;
After this, ip/ifconfig/iwconfig shouldd see the new wifi nic, probably &#039;&#039;&#039;wlan0&#039;&#039;&#039;, but due to a [https://bugs.launchpad.net/ubuntu/+source/broadcom-sta/+bug/1343151 old, ignored bug], you won&#039;t find any wifi networks. This is because the driver from Broadcom apparently does not support interrupt remapping, commonly used on x64 machines. To turn this off, change &#039;&#039;&#039;/etc/default/grub&#039;&#039;&#039; and change the line &#039;&#039;&#039;GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;quiet splash&amp;quot;&#039;&#039;&#039;, adding intremap=off to the end before the quote: &#039;&#039;&#039;GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;quiet splash intremap=off&amp;quot;&#039;&#039;&#039;. Save the file and run &#039;&#039;&#039;sudo update-grub&#039;&#039;&#039; and reboot. After this, wifi should work well.&lt;br /&gt;
&lt;br /&gt;
== Wifi with HP Compaq Presario CQ57 on Ubuntu ==&lt;br /&gt;
&lt;br /&gt;
The HP Compaq Presario CQ57 uses the RT5390 wifi chipset. This has been supported for quite some time now, and I was quite surprised to find it not working on a laptop a friend was having. The driver loaded correctly, but Ubuntu insisted of the laptop being in &#039;&#039;&#039;flight mode&#039;&#039;&#039;. Checking &#039;&#039;&#039;rfkill&#039;&#039;&#039;, it showed me two NICs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# rfkill list all&lt;br /&gt;
0: phy0: Wireless LAN&lt;br /&gt;
	Soft blocked: no&lt;br /&gt;
	Hard blocked: yes&lt;br /&gt;
1: hp-wifi: Wireless LAN&lt;br /&gt;
	Soft blocked: yes&lt;br /&gt;
	Hard blocked: no&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Turning rfkill on and off resulted in nothing much, except some error messages in the kernel log (dmesg)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] ACPI Error: Field [B128] at bit offset/length 128/1024 exceeds size of target Buffer (160 bits) (20170831/dsopcode-235)&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]&lt;br /&gt;
                            Initialized Local Variables for Method [HWCD]:&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Local0: 00000000a34b7928 &amp;lt;Obj&amp;gt;           Integer 0000000000000000&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Local1: 00000000b0aa6865 &amp;lt;Obj&amp;gt;           Buffer(8) 46 41 49 4C 04 00 00 00&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Local5: 00000000a9811efd &amp;lt;Obj&amp;gt;           Integer 0000000000000004&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] Initialized Arguments for Method [HWCD]:  (2 arguments defined for method invocation)&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Arg0:   0000000078957d1b &amp;lt;Obj&amp;gt;           Integer 0000000000000001&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Arg1:   00000000725c9c6e &amp;lt;Obj&amp;gt;           Buffer(20) 53 45 43 55 02 00 00 00&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] ACPI Error: Method parse/execution failed \_SB.WMID.HWCD, AE_AML_BUFFER_LIMIT (20170831/psparse-550)&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] ACPI Error: Method parse/execution failed \_SB.WMID.WMAD, AE_AML_BUFFER_LIMIT (20170831/psparse-550)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After upgrading BIOS and testing different kernels, I was asked to try to unload the &#039;&#039;&#039;hp_wmi&#039;&#039;&#039; driver. I did, and things changed a bit, so I tried blacklisting it, creating the file &#039;&#039;&#039;/etc/modprobe.d/blacklist-hp_wmi.conf&#039;&#039;&#039; with the following content&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Blacklist this - it doesn&#039;t work!&lt;br /&gt;
blacklist hp_wmi&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
I gave the machine a reboot and afte that, the &#039;&#039;&#039;hp-wifi&#039;&#039;&#039; entry was gone in the rfkill output, and things works.&lt;br /&gt;
&lt;br /&gt;
== BIOS upgrade from Linux ==&lt;br /&gt;
&lt;br /&gt;
Generally, BIOS upgrades have been moved to the BIOS itself these days. This saves a lot of work and quite possibly lives after those who earier rammed their heads through walls, now can upgrade directly from the internet instead of using obscure operating systems best avoided. Sometimes, however, one must use these nevertheless. This is a quick run-through on your options.&lt;br /&gt;
&lt;br /&gt;
=== DOS ===&lt;br /&gt;
&lt;br /&gt;
Most non-automatic BIOS upgrades are installed from DOS. Doing a BIOS upgrade this way, is generally non-problematic. Just install a USB thingie with [https://www.freedos.org/ FreeDOS], copy your file(s) onto the thing and boot on it. The commandline is the same as old MS/DOS, except a wee bit more userfriendly, but not a lot.&lt;br /&gt;
&lt;br /&gt;
=== Windows ===&lt;br /&gt;
&lt;br /&gt;
Some macahines, like laptops from &#039;&#039;&#039;HP&#039;&#039;&#039;, may have BIOS upgrades that are made to be installed from Windows and won&#039;t run in FreeDOS or MS/DOS, instead throwing an error, saying &#039;&#039;&#039;This program cannot be run in DOS mode&#039;&#039;&#039;. This means you&#039;ll have to boot on a Windows rescue disc and do the job from there. Googling this, tells you it&#039;s quite easy, you just choose &#039;make rescue disc&#039; from Windows, and it&#039;s all good, except if you don&#039;t run Windows, that is. To remedy this problem, do as follows:&lt;br /&gt;
&lt;br /&gt;
==== Download Windows ====&lt;br /&gt;
&lt;br /&gt;
Since you don&#039;t run Windows and possibly don&#039;t have a spouse or friend around with such unhealthy habits either, you need to get it. It&#039;s quite easy - just google &#039;download windows&#039; and it&#039;ll send you to [https://www.microsoft.com/en-us/software-download/windows10ISO somewhere like this].&lt;br /&gt;
&lt;br /&gt;
==== Burn it! ====&lt;br /&gt;
&lt;br /&gt;
Now it&#039;s time to burn the installer on a DVD ROM. You&#039;ll need a double-layered one, since the OS is &amp;gt; 4.7GiB, but I&#039;m sure you have a ton of those lying around. Now, just place your optical medium in your optical drive and burn, baby, burn!&lt;br /&gt;
&lt;br /&gt;
==== Or make a USB thing? ====&lt;br /&gt;
&lt;br /&gt;
Not a lot of machines have optical drives these days, so you may want to use an USB pen drive or something instead. This is easy, just make the USB bootable with the Windows application Microsoft has made for this. Unfortunately, this only runs on Windows, and unlike stuff like Debian, where the &#039;&#039;&#039;iso&#039;&#039;&#039; file can be dd&#039;ed directly onto a USB drive to make it bootable, the Windows &#039;&#039;&#039;iso&#039;&#039;&#039;s don&#039;t come with this luxury. There are lots of methods to make bootable USB things from iso files out there, but the only thing most of them have in common, is that they generally don&#039;t work.&lt;br /&gt;
&lt;br /&gt;
===== WoeUSB =====&lt;br /&gt;
&lt;br /&gt;
After hours of swearing, it&#039;s nice to come across software like [https://github.com/slacka/WoeUSB WoeUSB]. It may not be perfect, it relies on a bunch of GUI stuff you&#039;ll never need and so on, but it &#039;&#039;&#039;&#039;&#039;works&#039;&#039;&#039;&#039;&#039;, and that&#039;s the important part! Just clone the repo and RTFM and it&#039;s all nice. It&#039;s slow, but hell, getting a windows machine and/or an optical drive might be slower.&lt;br /&gt;
&lt;br /&gt;
WoeUSB does nothing fancy, but it &#039;&#039;&#039;does&#039;&#039;&#039; work. It will create a filesystem, FAT32 or NTFS (better use NTFS, FAT32 has its limits). It creates normal filesystems and so on. Just make sure to copy in the BIOS update file, usually an exe file, to run when Windows is up and running.&lt;br /&gt;
&lt;br /&gt;
===== Install BIOS =====&lt;br /&gt;
&lt;br /&gt;
Boot on the Windows USB thing and choose &#039;repair computer&#039; and then &#039;command prompt&#039;. Find the install file, and if you&#039;re lucky, you&#039;ll find it needs a 32bit OS, just like I did. Since the 64bit version doesn&#039;t include 32bit compatibility in the installer, revert to downloading the 32bit version of windows and start over. Pray to your favourite god(s) not to get across such machines again - it might help.&lt;br /&gt;
&lt;br /&gt;
= 3D printer stuff =&lt;br /&gt;
&lt;br /&gt;
== Hydrophilic filament ==&lt;br /&gt;
&lt;br /&gt;
Most popular filament types, including PLA, PETG, PP or PA (Polyamide, normally known as Nylon) and virtualy any filament type named [https://www.matterhackers.com/news/filament-and-water poly-something] (and thus with an acronym of P-something) are hydrophilic (also (somewhat incorrectly) called hydroscopic), meaning so long they&#039;re dryer than the atmosphere around them, they&#039;ll do their best to suck out the atmosphere&#039;s humidity. This is why most filament are shrink-wrapped with a small bag of silica gel in it. If such filament is exposed for normal humid air for some time, it&#039;ll become very hard to use. Most of my experience is with PLA, which can handle a bit (depending on make), but still not a lot. With PLA, if you end up with prints where the filament seems not to stick, it may help with a higher temperature. Otherwise, the filament must be [https://all3dp.com/2/how-to-dry-filament-pla-abs-and-nylon/ baked]. If you don&#039;t want to use your oven, try something like a [https://www.jula.no/catalog/hjem-og-husholdning/kjokkenmaskiner/mattilberedningsapparater/frukt-sopptorker/frukt-sopptorker-001641/#tab02 fruit and mushroom dryer]. Then get a good, sealble plastic box and add something like half a kilogram of [https://www.ebay.com/sch/sis.html?_nkw=1KG+Orange+Replacement+Desiccant+Indicating+Silica+Gel+Beads+for+Drawers%2C+Camera&amp;amp;_id=131938742628&amp;amp;&amp;amp;_trksid=p2057872.m2749.l2658 silica gel] to an old sock, tie it and put it in the your new dry box.&lt;br /&gt;
&lt;br /&gt;
Please note that ABS is hydrophobic, so you won&#039;t have to worry too much there. Also, remember that PA/Nylon is extremely hydrophilic. Even a couple of days in normal air humidity can ruin it completely and will require baking.&lt;br /&gt;
&lt;br /&gt;
== Upgrading the firmware on an Ender 3 ==&lt;br /&gt;
&lt;br /&gt;
This is about upgrading the firmware, and thus also flashing a bootloader to the Creality Ender 3 3D printer. Most of this is well documented on several place, like o [https://www.youtube.com/watch?v=fIl5X2ffdyo the video from Teaching tech] and elsewhere, but I&#039;ll just summarise some issues I had.&lt;br /&gt;
&lt;br /&gt;
=== Using an arduino Nano as a programmer ===&lt;br /&gt;
&lt;br /&gt;
The CR-10, Ender 3 and a few other printers from Creality come without a bootloader, so you&#039;ll need to flash one before upgrading the firmware. Well, strictly speakning, you don&#039;t need one, you can save those 8kB or so for other stuff and use a programmer to write the whole firmware, but then you&#039;ll need to wire up everything every time you want a new firmware, so in my world, you &#039;&#039;&#039;do&#039;&#039;&#039; need the bootloader, since it&#039;s easier. Note that some newer printers, like the CR-10S and possibly all newer ones, come with the bootloader already and thus won&#039;t need another.&lt;br /&gt;
&lt;br /&gt;
To install a bootloader, you&#039;ll need a programmer, and I didn&#039;t have one available. Having some el-cheapo china-copies of Ardinos around, I read I could use one and tried so. Although the docs mostly mention the Uno etc, it&#039;s just as simple with the Nano copy.&lt;br /&gt;
&lt;br /&gt;
So, grab an arduino, plug it to your machine with an USB cable, and, using the Arduino IDE, use the ArduinoISP sketch there (found under Examples) to burn the software needed for the arduino to work as a programmer. When this is done, connect a 10µF capacitor between RST and GND to stop it from resetting when used as a programmer. Connect the MOSI, MISO and SCK pins from the ICSP block (that little isolated 6-pin block on top of the ardu). See [https://www.arduino.cc/en/Tutorial/ArduinoISP here] for a pinout. Then find Vcc and GND either onthe ICSP block or elsewhere. Some sites say that on some boards you shouldn&#039;t use the pins on the ICSP block for this. I doubt it matters, though. Then connect another jumper wire from pin 10 on the ardu to work as the reset pin outwards to the chip being programmed (that is, on the printer). The ICSP jumper block pin layout is the same on the printer and on the ardu, and probably elsewhere. Sometimes [https://xkcd.com/927/ standardisation] actually works…&lt;br /&gt;
&lt;br /&gt;
See https://cloud.karlsbakk.net/index.php/s/zw48YJjzaf8Rc2F for a pic with the ardu (this wiki is broken atm, will fix it later)&lt;br /&gt;
&lt;br /&gt;
== Flashing the printer ==&lt;br /&gt;
&lt;br /&gt;
When the boot loader is in place, possibly after some wierd errors from during the process, the screen on the 3d printer will go blank and it&#039;ll behave like being bricked. This is ok. Now disconnect the wires and connect the USB cable between computer and printer, download the [https://www.th3dstudio.com/knowledgebase/th3d-unified-firmware-package/ TH3D unified firmware] and configure it for your particular needs. The video mentioned above describes this well. After flashing the new firmware, you&#039;ll probably get some timeouts and errors, since apparently it resets the printer after giving it the new firmware, but without notifying the flashing software of it doing so. If this happens, hold your breath and reboot the printer and check its tiny monitor - it should work. If it doesn&#039;t work, try to flash it again, and if that doesn&#039;t work, try flashing the programmer again yet another time, just for kicks.&lt;br /&gt;
&lt;br /&gt;
PS: I tried enabling &#039;&#039;&#039;MANUAL_MESH_LEVELING&#039;&#039;&#039;, which in the code says that &#039;&#039;If used with a 1284P board the bootscreen will be disabled to save space&#039;&#039;. This effectively disabled the whole thing, and apparently may be making the firmware image a wee bit too large for it to fit the 1284P on the ender. It works well without it, though.&lt;br /&gt;
&lt;br /&gt;
== And then… ==&lt;br /&gt;
&lt;br /&gt;
With the new firmware in place, the printer should work as before, although with thermal runaway protection to better avoid fires in case the shit hits the fan, and to allow for things like autolevelling. With any luck, [https://www.precisionpiezo.co.uk/ this thing] may be ready for use by the time you read this - it surely looks nice!&lt;br /&gt;
&lt;br /&gt;
roy&lt;/div&gt;</summary>
		<author><name>Roy</name></author>
	</entry>
	<entry>
		<id>https://wiki.malinux.no/index.php?title=Roy%27s_notes&amp;diff=149</id>
		<title>Roy&#039;s notes</title>
		<link rel="alternate" type="text/html" href="https://wiki.malinux.no/index.php?title=Roy%27s_notes&amp;diff=149"/>
		<updated>2020-01-28T02:01:54Z</updated>

		<summary type="html">&lt;p&gt;Roy: /* Growing devices */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= LVM, md and friends =&lt;br /&gt;
&lt;br /&gt;
== Linux&#039; Logical Volume Manager (LVM) ==&lt;br /&gt;
&lt;br /&gt;
=== LVM in general ===&lt;br /&gt;
&lt;br /&gt;
LVM is designed to be an abstraction layer on top of physical drives or RAID, typically [https://raid.wiki.kernel.org/index.php/RAID_setup mdraid] or [https://help.ubuntu.com/community/FakeRaidHowto fakeraid]. Keep in mind that fakeraid should be avoided unless you really need it, like in conjunction with dual-booting linux and windows on fakeraid. LVM broadly consists of three elements, the &amp;quot;physical&amp;quot; devices (PV), the volume group (VG) and the logical volume (LV). There can be multiple PVs, VGs and LVs, depending on requirement. More about this below. All commands are given as examples, and all of them can be fine-tuned using extra flags in need of so. In my experience, the defaults work well for most usecases.&lt;br /&gt;
&lt;br /&gt;
I&#039;m mentioning filesystem below too. Where I write ext4, the samme applies to ext2 and ext3.&lt;br /&gt;
&lt;br /&gt;
==== Create a PV ====&lt;br /&gt;
&lt;br /&gt;
A PV is the &amp;quot;physical&amp;quot; parts. This does not need to be a physical disk, but can also be another RAID, be it an mdraid, fakeraid, hardware raid, a virtual disk on a SAN or otherwisee or a partition on one of those. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#  These add three PVs, one on a drive (or hardware raid) and another two on mdraids.&lt;br /&gt;
pvcreate /dev/sdb&lt;br /&gt;
pvcreate /dev/md1 /dev/md2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For more information about pvcreate, see [https://linux.die.net/man/8/pvcreate the manual].&lt;br /&gt;
&lt;br /&gt;
==== Create a VG ====&lt;br /&gt;
&lt;br /&gt;
The volume group consists of one or more PVs grouped together on which LVs can be placed. If several PVs are grouped in a VG, it&#039;s generally a good idea to make sure these PVs have some sort of redundancy, as in mdraid/fakeraid or hwraid. Otherwise it will be like using a [https://en.wikipedia.org/wiki/RAID RAID-0] with a single point of failure on each of the independant drives. LVM has [https://unix.stackexchange.com/questions/150644/raiding-with-lvm-vs-mdraid-pros-and-cons  RAID code in it] as well, so you can use that. I haven&#039;t done so myself, as I generally stick to mraid. The reason is mdraid is, in my opinion older and more stable and has more users (meaning bugs are reported and fixed faster whenever they are found). That said, I beleive the actual RAID code used in LVM RAID are the same function calls as for mdraid, so it may not be much of a difference. I still stick with mdraid. To create a VG, run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create volume group my_vg&lt;br /&gt;
vgcreate my_vg /dev/md1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that if vgcreate is run with a PV (as /dev/md1 above) that is not defined as a PV (like above), this is done implicitly, so if you don&#039;t need any special flags to pvcreate, you can simply skip it and let vgcreate do that for you.&lt;br /&gt;
&lt;br /&gt;
==== Create an LV ====&lt;br /&gt;
&lt;br /&gt;
LVs can be compared to partitions, somehow, since they are bounderies of a fraction or all of that of a VG. The difference between them and a partition, however, is that they can be grown or shrunk easily and also moved around between PVs without downtime. This flexibility makes them superiour to partitions as your system can be changed without users noticing it. By default, an LV is alloated &amp;quot;thickly&amp;quot;, meaning all the data given to it, is allocated from the VG and thus the PV. The following makes a 100GB LV named &amp;quot;thicklv&amp;quot;. When making an LV, I usually allocate what&#039;s needed plus some more, but not everything, just to make sure it&#039;s space available for growth on any of the LVs on the VG, or new LVs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a thick provisioned LV named thicklv on the VG my_vg&lt;br /&gt;
lvcreate -n thicklv -L 100G my_vg&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After the LV is created, a filesystem can be placed on it unless it is meant to be used directly. The application for direct use include swap space, VM storage and certain database systems. Most of these will, however, work on filesystems too, although my testing has shown that on swap space, there is a significant performance gain for using dedicated storage without a filesystem. As for filesystems, most Linux users use either ext4 or xfs. Personally, I generally use XFS these days. See my notes below on filesystem choice.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a filesystem on the LV - this could have been mkfs -t ext4 or whatever filesystem you choose&lt;br /&gt;
mkfs -t xfs /dev/my_vg/thicklv&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then just edit /etc/fstab with correct data and run mount -a, and you should be all set.&lt;br /&gt;
&lt;br /&gt;
==== Create LVM cache ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
lvcreate -L 1G -n _cache_meta data /dev/md1&lt;br /&gt;
&lt;br /&gt;
lvcreate -l100%FREE -n _cache data /dev/md1&lt;br /&gt;
&lt;br /&gt;
# Some would want --cachemode writeback, but seriously, I wouldn&#039;t recommend it. Metadata or data can be easily corrupted in case of failure.&lt;br /&gt;
lvconvert --type cache-pool --cachemode writethrough --poolmetadata data/_cache_meta data/_cache&lt;br /&gt;
&lt;br /&gt;
lvconvert --type cache --cachepool data/_cache data/data&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Disabling LVM cache ====&lt;br /&gt;
&lt;br /&gt;
If you for some reason want to disable caching, this will do it cleanly and remove the LVs earlier created for caching the main device.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
lvconvert --uncache data/data&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Growing devices ====&lt;br /&gt;
&lt;br /&gt;
LVM objects can be grown and shrunk. If a PV resides on a RAID where a new drive has been added or otherwise grown, or on a partition or virtual disk that has been extended, the PV must be updated to reflect these changes. The following command will grow the PV to the maximum available on the underlying storage. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Resize the PV /dev/md (not the RAID, only the PV on the RAID) to its full size&lt;br /&gt;
pvresize /dev/md1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If a new PV is added, the VG can be grown to add the space on that in addition to what&#039;s there already. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Extend my_vg to include md2 and its space&lt;br /&gt;
vgextend my_vg /dev/md2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
With more space available in the VG, the LV can now be extended. Let&#039;s add another 50GB to it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Extend thicklv - add 50GB. If you know you won&#039;t need the space anywhere else, you may want to&lt;br /&gt;
# lvresize -l+100%FREE instead. Keep in mind the difference between -l (extents) and -L (bytes)&lt;br /&gt;
lvresize -L +50G my_vg/thicklv&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After the LV has grown, run &#039;&#039;xfs_growfs&#039;&#039; (xfs) or &#039;&#039;resize2fs&#039;&#039; (ext4) to make use of the new data. To grow the filesystem to all available space on ext[234], run the below command. The filesystem can be mounted when this is run. If you for some reason get an &#039;&#039;&#039;access denied&#039;&#039;&#039; error when running this as root or with sudo, it&#039;s likely caused by a filesystem error. To fix this, unmount the filesystem first and run &#039;&#039;&#039;fsck -f /dev/my_vg/thicklv&#039;&#039;&#039; and remount it before retrying to extend it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
resize2fs /dev/my_vg/thicklv&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Similarly, with XFS, but note that xfs_growfs doesn&#039;t take the device name, but the filesystem&#039;s mount point. In the case of XFS, also note that the filesystem &#039;&#039;&#039;&#039;&#039;must&#039;&#039;&#039;&#039;&#039; be mounted to be grown. This, in contrast to how it was in the old days when filesystems had to be unmounted to be grown.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
xfs_growfs /my_mountpoint&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Rename system VG ====&lt;br /&gt;
&lt;br /&gt;
Some distros create VG names like those-from-a-sysadmin-with-a-well-developed-paranoia-not-to-hit-a-duplicate. Debian, for instance, uses names like &amp;quot;my-full-hostname-vg&amp;quot;. Personally, I don&#039;t like these, since if I were to move a disk or vdisk around to somewhere else, I&#039;d make sure not to add a disk named &#039;sys&#039; to an existing system. If you do, most distros will refuse to use the VGs with duplicate names, resulting in the OS not booting until either one is specified by its UUID or just one removed. As I&#039;m aware of this, I stick to the super-risky thing of all system VGs named &#039;sys&#039; and so on.&lt;br /&gt;
&lt;br /&gt;
If you do this, keep in mind that it may blow up your computer and take your girl- or boyfriend with it or even make either of them pregnant, allowing Trump to rule your life and generally make things suck. You&#039;re on your own!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Rename the VG&lt;br /&gt;
vgrename my-full-hostname-vg sys&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, in /boot/grub/grub.cfg, change the old lv path from something like &#039;/dev/mapper/debian--stretch--machine--vg-root&#039; to your new and fancy &#039;/dev/sys/root. Likewise, in /etc/fstab, change occurences of &#039;/dev/mapper/debian--stretch--machine--vg-&#039; (or similar) with &#039;/dev/sys/&#039;. Here, this was like this - the old ones commented out.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;fstab&amp;quot;&amp;gt;&lt;br /&gt;
#/dev/mapper/debian--stretch--box--vg-root      /               ext4            errors=remount-ro,discard       0       1&lt;br /&gt;
/dev/sys/root                                   /               ext4            errors=remount-ro,discard       0       1&lt;br /&gt;
# /boot was on /dev/vda1 during installation&lt;br /&gt;
UUID=myverylonguuidwithatonofgoodinfoinit       /boot           ext2            defaults                        0       2&lt;br /&gt;
#/dev/mapper/debian--stretch--box--vg-swap_1    none            swap            sw                              0       0&lt;br /&gt;
/dev/sys/swap_1                                 none            swap            sw                              0       0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Update /etc/initramfs-tools/conf.d/resume with similar data for swap.&lt;br /&gt;
&lt;br /&gt;
You might want to run &#039;update-initramfs -u -k all&#039; after this, but I&#039;m not sure if it&#039;s needed.&lt;br /&gt;
&lt;br /&gt;
Now, pray to the nearest god(s) and give it a reboot and it should (probably) work.&lt;br /&gt;
&lt;br /&gt;
After reboot, run &#039;&#039;&#039;swapoff -a&#039;&#039;&#039;, then &#039;&#039;&#039;mkswap /dev/sys/swap_1&#039;&#039;&#039; (or whatever it&#039;s called on your system) and &#039;&#039;&#039;swapon -a&#039;&#039;&#039; again. You may want to give it another reboot or two for kicks, but it should work well even without that.&lt;br /&gt;
&lt;br /&gt;
=== Migration tools ===&lt;br /&gt;
&lt;br /&gt;
At times, storage regimes change, new storage is added and sometimes it&#039;s not easy to migrate with the current hardware or its support systems. Once I had to migrate a 45TiB fileserver from one storage system to another, preferably without downtime. The server originally had three 15TiB PVs of which two were full and the third half full. I resorted to using [https://linux.die.net/man/8/pvmove pvmove] to just move the data on the PVs in use to a new PV. We started out with creating a new 50TiB PV, sde, and then to pvmove.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Attach /dev/sde to the VG my_vg&lt;br /&gt;
vgextend my_vg /dev/sde&lt;br /&gt;
&lt;br /&gt;
# Move the contents from /dev/sdb over to /dev/sde block by block. If a target is not given in pvmove,&lt;br /&gt;
# the contents of the source (sdb here) will be put somewhere else in the pool.&lt;br /&gt;
pvmove /dev/sdb /dev/sde&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This took a while (as in a week or so) - the pvmove command uses old code and logic (or at least did that when I migrated this in November 2016), but it affected performance on the server very little, so users didn&#039;t notice. After the first PV was migrated, I continued with the other two, one after the other, and after a month or so, it was migrated. We used this on a number of large fileservers, and it worked flawlessly. Before doing the production servers I also tried interrupting pvmove in various ways, including hard resets, and it just kept on after the reboot.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;NOTE:&#039;&#039;&#039;&#039;&#039; &#039;&#039;Even though it worked well for us, &#039;&#039;&#039;always&#039;&#039;&#039; keep a good backup before doing this. Things may go wrong, and without a good backup, you may be looking for a hard-to-find new job the next morning&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
==== mdadm workarounds ====&lt;br /&gt;
&lt;br /&gt;
===== Migrate from a mirror (raid-1) to raid-10 =====&lt;br /&gt;
&lt;br /&gt;
Create a mirror&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sdb /dev/sdc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
LVM (pv/vg/lv) on md0 (see above), put a filesystem on the lv and fill it with some data.&lt;br /&gt;
&lt;br /&gt;
Now, some months later, you want to change this to raid-10 to allow for the same amount of redundancy, but to allow more disks into the system.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mdadm --grow /dev/md0 --level=10&lt;br /&gt;
mdadm: Impossibly level change request for RAID1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So - no - doesn&#039;t work. But - we&#039;re on &lt;br /&gt;
&lt;br /&gt;
Since we&#039;re on lvm already, this&#039;ll be easy. If you&#039;re using filesystems directly on partitions, you can do this the same way, but without the pvmove part, using rsync or whateever you like instead. I&#039;d recommend using lvm for for the new raid, which should be rather obvious from this article. Now plug in a new drive and create a new raid10 on that one. If you two new drives, install both. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# change &amp;quot;missing&amp;quot; to the other device name if you installed two new drives&lt;br /&gt;
mdadm --create /dev/md1 --level=10 --raid-devices=2 /dev/vdd missing&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, as described above, just vgextend the vg, adding the new raid and run pvmove to move the data from the old pv (residing on the old raid1) to the new pv (on raid10). Afte rpvmove is finished (which may take awile, see above), just&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
vgreduce raidtest /dev/md0&lt;br /&gt;
pvremove /dev/md0&lt;br /&gt;
mdadm --stop /dev/md0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
…and your disk is free to be added to the new array. If the new raid is running in degraded mode (if you created it with just one drive), better don&#039;t wait too long, since you don&#039;t have redundancy. Just mdadm --add the devs.&lt;br /&gt;
&lt;br /&gt;
If you now have /dev/mdstat telling you your raid10 is active and have three drives, of which one is a spare, it should look something like this&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5] [raid4] [raid10]&lt;br /&gt;
md1 : active raid10 vdc[3](S) vdb[2] vdd[0]&lt;br /&gt;
      8380416 blocks super 1.2 2 near-copies [2/2] [UU]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Just mdadm --grow --raid-devices=3 /dev/md1&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;RAID section is not complete. I&#039;ll write more on migraing from raid10 to raid6 later. It&#039;s not straight forward, but easier than this one :)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== Thin provisioned LVs ===&lt;br /&gt;
&lt;br /&gt;
Thin provisioning on LVM is a method used for not allocating all the space given to an LV. For instance, if you have a 1TB VG and want to give an LV 500GB, although it currently only uses a fraction of that, a thin lv can be a good alternative. This will allow for adding a limit to how much it can use, but also to let it grow dynamically without manual work by the sysadmin. Thin provisioning adds another layer of abstaction by creating a special LV as a &#039;&#039;thin pool&#039;&#039; from which data is allocated to the &#039;&#039;thin volume(s)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== Create a thin pool ====&lt;br /&gt;
&lt;br /&gt;
Allocate 1TB to the thin pool to be used for thinly provisioned LVs. Keep in mind that the space allocated to the thin pool is in fact thick provisioned. Only the volumes put on &#039;&#039;thinpool&#039;&#039; are thin provisioned. This will create two hidden LVs, one for data and one for metadata. Normally the defaults will do, but check the manual if the data doesn&#039;t match the usual patterns (such as billions of files, resulting in huge amounts of metadata). I &#039;&#039;beleive&#039;&#039; the metadata part should be resizable at a later time if needed, but I have not tested it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a pool for thin LVs. Keep in mind that the pool itself is not thin provisioned, only the volumes residing on it&lt;br /&gt;
lvcreate --size 1T --type thin-pool --thinpool thinpool my_vg&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Create a thin volume ====&lt;br /&gt;
&lt;br /&gt;
You have the thinpool, now put a thin volume on it. It will allocate some space for metadata, but probably not much (a few megs, perhaps).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Now, create a volume with a virtual (-V) size of half a terabyte named thin_pool, but using the thinpool (-T) named thin_pool for storage&lt;br /&gt;
lvcreate -V 500G -T my_vg/thin_pool --name thinvol&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The new volume&#039;s device name will be /dev/thinvol. Now, create a filesystem on it, add to fstab and mount it. The &#039;&#039;&#039;df&#039;&#039;&#039; command will return available space according to the virtual size (-V), while lvs will show how much data is actually used on each of the thinly provisioned volumes.&lt;br /&gt;
&lt;br /&gt;
== Filesystem dilemmas ==&lt;br /&gt;
&lt;br /&gt;
=== XFS or ext4 or something else ===&lt;br /&gt;
The choice of filesystem varies for your use. Distros such as RHEL/CentOS has moved to XFS by default from v7. Debian/Ubuntu still sticks to ext4, like most other. I&#039;ll discuss my thoughts below on ext4 vs XFS and leave the other filesystems for later.&lt;br /&gt;
&lt;br /&gt;
==== ext4 ====&lt;br /&gt;
ext4 is probably the most used filesystem on linux as of writing. It&#039;s rock stable and has been extended by a lot of extensions since the original ext2. It still retains backward compatibility, being able to mount and fsck ext2 and ext3 with the ext4 driver. However, it doesn&#039;t handle large filesystems very well. If a filesystem is created for &amp;lt;16TiB, it cannot be grown to anything larger than 16TiB. This may have changed lately, though. One other issue is handling errors. If a large filesystem (say 10TiB) is damaged, an fsck may take several hours, leading to long downtime.&lt;br /&gt;
&lt;br /&gt;
==== XFS ====&lt;br /&gt;
XFS, originally developed by SGI some time in the bronze age, but has been worked on heavily after that. RHEL and Centos version 7 and forward, uses XFS as the default filesystem. It is quick, it scales well, but it lacks at least two things ext4 has. It cannot be shrunk (not that you normally need that, but nice if you have a typo or you need to change things). Also, it doesn&#039;t allow for automatic fsck on bootup. If something is messed up on the filesystem, you&#039;ll have to login as root on the console (not ssh), which might be an issue on some systems. The fsck equivalent, xfs_repair, is a *lot* faster than ext4&#039;s fsck, though.&lt;br /&gt;
&lt;br /&gt;
==== ZFS ====&lt;br /&gt;
ZFS is like a combination of RAID, LVM and a filesystem, supporting full checksumming, auto-healing (given sufficient redundancy), compression, encryption, replication, deduplication (if you&#039;re brave and have a &#039;&#039;ton&#039;&#039; of memory) and a lot more. It&#039;s a separate chapter and needs a lot more talk than paragraph here.&lt;br /&gt;
&lt;br /&gt;
== Low level disk handling ==&lt;br /&gt;
&lt;br /&gt;
This section is for low-level handling of disks, regardless of storage system elsewhere. These apply to mdraid, lvmraid and zfs and possibly other solutions, with the exception of individual drives on hwraid (and maybe fakeraid), since there, the drives are hidden from Linux (or whatever OS).&lt;br /&gt;
&lt;br /&gt;
=== S.M.A.R.T. and slow drives ===&lt;br /&gt;
Modern (that is, from about 1990 or later) have S.M.A.R.T. (or just smart, since it&#039;s easier to type) monitoring built in, meaning the disk&#039;s controller is monitoring itself. This is handy and will ideally tell you in advance that a drive is flakey or dying. Modern (2010+) smart monitoring is more or less the same. It can be trusted about 50% of the time. Usually, if smart detects an error, it&#039;s a real error. I don&#039;t think I&#039;ve seen it reporting a false positive, but others may know better. &lt;br /&gt;
&lt;br /&gt;
==== smartmontools ====&lt;br /&gt;
First, install smartmontool and run smartclt -H /dev/yourdisk (/dev/sda or something) to get a health report. Then perhaps run smartctl -a /dev/yourdisk and look for &#039;current pending sectors&#039; This should be zero. Also check the temperature, which normally should be much above 50.&lt;br /&gt;
&lt;br /&gt;
==== single, slow drive ====&lt;br /&gt;
What may happen, is smart not seeing anything and life goes on like before, only slower and less prouductive, without telling anyone. If you stubler over this issue, you&#039;ll probably see it during a large rsync/zfs send/receive or a resync/rebuild/resilver of the raid/zpool. During this, it feels like everything is slow and your RAID has turned into a RAIF (redundant array of inexpensive floppies). To check if you have a single drive messing up it all, check with &#039;&#039;&#039;iostat -x 2&#039;&#039;&#039;, having 2 being the delay between each measurement. Interrupt it with ctrl+x. If there&#039;s a rougue drive there, it should stand out like sdg below&lt;br /&gt;
&lt;br /&gt;
 avg-cpu:  %user   %nice %system %iowait  %steal   %idle&lt;br /&gt;
            0.38    0.00    1.75    0.00    0.00   97.87&lt;br /&gt;
&lt;br /&gt;
 Device            r/s     w/s     rkB/s     wkB/s   rrqm/s   wrqm/s  %rrqm  %wrqm r_await w_await aqu-sz rareq-sz wareq-sz  svctm  %util&lt;br /&gt;
 sda              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdb              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdc              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdd              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sde              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdf              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdg              3.50    0.00   2352.00      0.00     0.00     0.00   0.00   0.00 14306.29    0.00  13.85   672.00     0.00 285.71 100.00&lt;br /&gt;
 sdh              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
&lt;br /&gt;
In ZFS land, you should be able to get similar data with &#039;&#039;&#039;zpool iostat -v &amp;lt;pool&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Now you know the bad drive (sdg), pull it from the raid with &#039;&#039;&#039;mdadm --fail /dev/mdX /dev/sdX&#039;&#039;&#039;. Now test the drive&#039;s performance manually, just simply:&lt;br /&gt;
&lt;br /&gt;
 # hdparm -t /dev/sdg&lt;br /&gt;
 &lt;br /&gt;
 /dev/sdg:&lt;br /&gt;
  Timing buffered disk reads:   2 MB in  5.37 seconds = 381.46 kB/sec&lt;br /&gt;
&lt;br /&gt;
Bingo - nothing you&#039;d want to keep. For a good drive, it should be something like 100-200MB/s&lt;br /&gt;
&lt;br /&gt;
PS: Keep in mind that you have a degraded RAID by now in case you had a spare waiting for things to happen.&lt;br /&gt;
&lt;br /&gt;
Try to replace the cable and/or try the disk on another port/controller. If the result from hdparm persists, it&#039;s probably a bad cable&lt;br /&gt;
&lt;br /&gt;
So, then, just psycially locate the drive, pull it out, take out the discs and magnets and recycle the rest.&lt;br /&gt;
&lt;br /&gt;
=== &amp;quot;Unplug&amp;quot; drive from system ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Find the device unit&#039;s number with something like&lt;br /&gt;
find /sys/bus/scsi/devices/*/block/ -name sdd&lt;br /&gt;
# returning /sys/bus/scsi/devices/3:0:0:0/block/sdd here, &lt;br /&gt;
# meaning 3:0:0:0 is the SCSI device we&#039;re looking for.&lt;br /&gt;
&lt;br /&gt;
# Given this is the correct device, and you want to &#039;unplug&#039; it, do so by&lt;br /&gt;
echo 1 &amp;gt; /sys/bus/scsi/devices/3:0:0:0/delete&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Rescan disk controllers ===&lt;br /&gt;
If a drive is added and for some reason doesn&#039;t get detected, or is removed by the command above, it can be rediscovered with a sysfs command to the scsi host to which it is connected. Since there may be quite a few of these, an easy way is to just scan them all and check the output of &#039;&#039;&#039;dmesg -T&#039;&#039;&#039; after running it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Make a list of controllers and send a rescan message to each of them. It won&#039;t do anything &lt;br /&gt;
# for those where nothing has changed, but it will show new drives where they have been added.&lt;br /&gt;
for host_scan in /sys/class/scsi_host/host*/scan&lt;br /&gt;
do&lt;br /&gt;
  echo &#039;- - -&#039; &amp;gt; $host_scan&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Fail injection with debugfs ===&lt;br /&gt;
[https://lxadm.com/Using_fault_injection https://lxadm.com/Using_fault_injection]&lt;br /&gt;
&lt;br /&gt;
== mdadm stuff ==&lt;br /&gt;
=== Spare pools ===&lt;br /&gt;
In the old itmes, mdadm supported only a dedicated spare per md device, so if working with a large set of drives (20? 40?), where you&#039;d want to setup more raid sets to increase redundancy, you&#039;d dedicate a spare to each of the raid sets. This has changed (some time ago?), so in these modern, heathen days, you can change mdadm.conf, usually placed under /etc/mdadm, and add &#039;spare-group=somegroup&#039; where &#039;somegroup&#039; is a string identifying the spare group. After doing this, run &#039;&#039;&#039;update-initramfs -u&#039;&#039;&#039; and reboot and add a spare to one of the raid sets in the spare group, and md will use that or those spares for all the raidsets in that group.&lt;br /&gt;
&lt;br /&gt;
As some pointed out on #linux-raid @ irc.freenode.net, this feature is very badly documented, but as far as I can see, it works well.&lt;br /&gt;
&lt;br /&gt;
==== Example config ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create two raidsets&lt;br /&gt;
&lt;br /&gt;
mdadm --create /dev/md1 --level=6 --raid-devices=6 /dev/vd[efghij]&lt;br /&gt;
mdadm --create /dev/md2 --level=6 --raid-devices=6 /dev/vd[klmnop]&lt;br /&gt;
&lt;br /&gt;
# get their UUID etc&lt;br /&gt;
&lt;br /&gt;
mdadm --detail --scan&lt;br /&gt;
ARRAY /dev/md/1 metadata=1.2 name=raidtest:1 UUID=1a8cbdcb:f4092350:348b6b80:c054d74c&lt;br /&gt;
ARRAY /dev/md/2 metadata=1.2 name=raidtest:2 UUID=894b1b7c:cb7eba70:917d6033:ea5afd2b&lt;br /&gt;
&lt;br /&gt;
# Put those lines into /etc/mdadm/mdadm.conf and and add the spare-group&lt;br /&gt;
&lt;br /&gt;
ARRAY /dev/md/1 metadata=1.2 name=raidtest:1 spare-group=raidtest UUID=1a8cbdcb:f4092350:348b6b80:c054d74c&lt;br /&gt;
ARRAY /dev/md/2 metadata=1.2 name=raidtest:2 spare-group=raidtest UUID=894b1b7c:cb7eba70:917d6033:ea5afd2b&lt;br /&gt;
&lt;br /&gt;
# update the initramfs and reboot&lt;br /&gt;
&lt;br /&gt;
update-initramfs -u&lt;br /&gt;
reboot&lt;br /&gt;
&lt;br /&gt;
# add a spare drive to one of the raids&lt;br /&gt;
&lt;br /&gt;
mdadm --add /dev/md1 /dev/vdq&lt;br /&gt;
&lt;br /&gt;
# fail a drive on the other raid&lt;br /&gt;
&lt;br /&gt;
mdadm --fail /dev/md2 /dev/vdn&lt;br /&gt;
&lt;br /&gt;
# check /proc/mdstat to see md2 rebuilding with the spare from md1&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Recovery ===&lt;br /&gt;
&lt;br /&gt;
The other day, I came across a problem a user had on #linux-raid@irc.freenode.net. He had an old Qnap NAS that had died and tried plugging the drives in to his Linux machine and got various errors. The two-drive RAID-1 did not come up as it should, &#039;&#039;&#039;dmesg&#039;&#039;&#039; was full of errors from one of the drives (both connected on USB) and so forth.&lt;br /&gt;
&lt;br /&gt;
We went on and started by taking down the machine and just connecting one of the drives. I had him check what was assembled with&lt;br /&gt;
&lt;br /&gt;
 cat /proc/mdstat&lt;br /&gt;
&lt;br /&gt;
That returned /proc/md127 assembled, but LVM didn&#039;t find anything. So running a manual scan&lt;br /&gt;
&lt;br /&gt;
 pvscan --cache /dev/md127&lt;br /&gt;
&lt;br /&gt;
This made linux find the PV, VG and a couple of LVs, but probably because the mdraid was degraded, the LVs were deactivated, according to &#039;&#039;&#039;lvscan&#039;&#039;&#039;. Activating the one with a filesystem manually&lt;br /&gt;
&lt;br /&gt;
 lvchange -a y /dev/&amp;lt;vg&amp;gt;/&amp;lt;lv&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Substitute &amp;lt;vg&amp;gt; and &amp;lt;lv&amp;gt; with the names listed by vgs and lvs.&lt;br /&gt;
&lt;br /&gt;
This worked, and the filesystem on /dev/&amp;lt;vg&amp;gt;/&amp;lt;lv&amp;gt; could be mounted correctly.&lt;br /&gt;
&lt;br /&gt;
== Tuning ==&lt;br /&gt;
&lt;br /&gt;
While trying to compare a 12-disk RAID (8TB disks) to a hwraid, mdraid was slower, so we did a few things to speed things up:&lt;br /&gt;
&lt;br /&gt;
While testing with [https://linux.die.net/man/1/fio fio], monitor /sys/block/md0/md/stripe_cache_active, and see if it&#039;s close to /sys/block/md0/md/stripe_cache_size. If it is, double the size of the latter&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
echo 4096 &amp;gt; /sys/block/md0/md/stripe_cache_size&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Continue until stripe_cache_active stabilises, and then you&#039;ve found the limit you&#039;ll need. You may want to double that for good measure. &lt;br /&gt;
&lt;br /&gt;
(to be continued)&lt;br /&gt;
&lt;br /&gt;
== Links ==&lt;br /&gt;
&lt;br /&gt;
Below are a few links with useful info&lt;br /&gt;
&lt;br /&gt;
* [https://raid.wiki.kernel.org/index.php/Irreversible_mdadm_failure_recovery Irreversible mdadm failure recovery]&lt;br /&gt;
&lt;br /&gt;
= ZFS =&lt;br /&gt;
&lt;br /&gt;
ZFS can do a lot of things most filesystems or volume managers can&#039;t. It checksums all data and metadata and so long that the system uses ECC enabled memory (RAM), it will have complete control over the whole data set, and when (not if) an error occurs, it&#039;ll fix the issue without even throwing a warning. To fix the issue, you&#039;ll obviously need sufficient redundancy (mirrors or RAIDzN). &lt;br /&gt;
&lt;br /&gt;
== ZFS send/receive between machines ==&lt;br /&gt;
&lt;br /&gt;
ZFS has a send/receive mechanism that allows for snapshots to be sent over the wire to a receiving end. This can be a full filesystem, or an incremental change since last send/reveive. In a WAN scenario, you&#039;ll probably want to use VPN for this. On a controlled network, sending in cleartext is also possible. You may as well use ssh, but keep in mind that ssh was never designed to be used as a fullblown vpn solution and is just too slow or the task with large amounts of data. You may, though, use mbuffer, if on a loal LAN.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Allow traffic from the sending IP in whatever firewall interface you&#039;re using (if you&#039;re using a firewall at all, that is)&lt;br /&gt;
ufw allow from x.x.x.x&lt;br /&gt;
# &lt;br /&gt;
# Start the receiver first. This listens on port 9090, has a 1GB buffer,&lt;br /&gt;
    and uses 128kb chunks (same as zfs):&lt;br /&gt;
&lt;br /&gt;
mbuffer -s 128k -m 1G -I 9090 | zfs receive data/filesystem&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To be continued one day… See [https://everycity.co.uk/alasdair/2010/07/using-mbuffer-to-speed-up-slow-zfs-send-zfs-receive/ this] for some more. I&#039;ll get back with details on it.&lt;br /&gt;
&lt;br /&gt;
= General Linux system control =&lt;br /&gt;
&lt;br /&gt;
== Add a new CPU (core) ==&lt;br /&gt;
&lt;br /&gt;
If working with virtual machines, adding a new core can be useful if the VM is slow and the load is multithreaded or multiprocess. To do this, add a new CPU in the hypervisor (be it KVM or VMware or Hyper-V or whatever). Some hypervisors, like VMware, will activate it automatically if open-vm-tools is installed. Please note that open-vm-tools is for VMware only. I don&#039;t know of any such thing for KVM or other hypervisors (although I beleive VirtualBox has its own set of tools, but not as a package). If this doesn&#039;t work, run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
echo 1 &amp;gt; /sys/devices/system/cpu/cpuX/online&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where X is the CPU number you want to add. You can &#039;cat /sys/devices/system/cpu/cpuX/online&#039; to check if it&#039;s online.&lt;br /&gt;
&lt;br /&gt;
= Mount partitions on a disk image =&lt;br /&gt;
&lt;br /&gt;
Sometimes you&#039;ll have a disk image, either from recovering a bad drive after hours (or days or weeks) of ddrescue, and sometimes you just have a disk image from a virtual machine where you want to mount the partitions inside the image. There are three main methods of doing this, which are more or less synonmous, but some easier than the other.&lt;br /&gt;
&lt;br /&gt;
== Basics ==&lt;br /&gt;
&lt;br /&gt;
A disk image is usually like a disk, consisting of either a large filesystem, a PV or a partition table with one or partitions onto which resides a filesystem, a pv, swap or something else. If it&#039;s partitioned, and you want your operating system to mount a filesystem or allow it to see whatever LVM stuff lies on it, you need to isolate the partitions. &lt;br /&gt;
&lt;br /&gt;
== Manual mapping ==&lt;br /&gt;
&lt;br /&gt;
In the oldern days, this was done manually, something like this&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
root@mymachine:~# fdisk -l /dev/vda&lt;br /&gt;
Disk /dev/vda: 25 GiB, 26843545600 bytes, 52428800 sectors&lt;br /&gt;
Units: sectors of 1 * 512 = 512 bytes&lt;br /&gt;
Sector size (logical/physical): 512 bytes / 512 bytes&lt;br /&gt;
I/O size (minimum/optimal): 512 bytes / 512 bytes&lt;br /&gt;
Disklabel type: dos&lt;br /&gt;
Disk identifier: 0xc37b7ea5&lt;br /&gt;
&lt;br /&gt;
Device     Boot    Start      End  Sectors  Size Id Type&lt;br /&gt;
/dev/vda1  *        2048 50333311 50331264   24G 83 Linux&lt;br /&gt;
/dev/vda2       50333312 52426369  2093058 1022M  5 Extended&lt;br /&gt;
/dev/vda5       50333314 52426369  2093056 1022M 82 Linux swap / Solaris&lt;br /&gt;
root@mymachine:~#&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To calculate the start and end of each partition, you just take the start sector and multiply it by the sector size (512 bytes here) and you have the offset in bytes. After this, it&#039;s merely an losetup -o &amp;lt;offset&amp;gt; /dev/loopX &amp;lt;nameofimagefile&amp;gt; and you have the partition mapped to your /dev/loopX (having X being something typically 0-255. After this, just mount it or run pvscan/vgscan/lvscan to probe whatever lvm config is there, and you should be able to mount it like any other filesystem.&lt;br /&gt;
&lt;br /&gt;
== kpartx ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;kpartx&#039;&#039;&#039; does the same as above, more or less, just without so much hassle. Most of it should be automatic and easy to deal with, except it may fail to disconnect the loopback devices sometimes, so you may have to &#039;&#039;&#039;losetup -d&#039;&#039;&#039; them manually. See the manual, &#039;&#039;&#039;kpartx (8)&#039;&#039;&#039;. Please note that &#039;&#039;&#039;partx&#039;&#039;&#039; works similarly and I&#039;d guess the authors of the two tools are arguing a lot of which one&#039;s the best.&lt;br /&gt;
&lt;br /&gt;
== guestmount ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;guestmount&#039;&#039;&#039; is something similar again, but also supports file formats like &#039;&#039;&#039;qcow2&#039;&#039;&#039; and possibly other, proprietary filesystems like &#039;&#039;&#039;vmdk&#039;&#039;&#039; and &#039;&#039;&#039;vdi&#039;&#039;&#039;, but don&#039;t take my word for it - I haven&#039;t tested. Again, see the manual or just read up on the description [http://ask.xmodulo.com/mount-qcow2-disk-image-linux.html?fbclid=IwAR3snTeZvGzp9PLdX11EQhCfOpux6I93CiJ3A2pUomkkRLly9Xo4851mkTY here]. It seems rather trivial.&lt;br /&gt;
&lt;br /&gt;
= Linux on laptops =&lt;br /&gt;
&lt;br /&gt;
== Wifi with HP EliteBook 725/745 on Ubuntu ==&lt;br /&gt;
&lt;br /&gt;
The HP EliteBook 725/745 and similar are equipped with a BCM4352 wifi chip. As with a lot of other stuff from Broadcom, this lacks an open hardware description, so thus no open driver exist. The proper fix, is to replace the NIC with something with an open driver, but again, this isn&#039;t always possible, so a binary driver exists. In ubuntu, run, somehow connect the machine to the internet and run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install bcmwl-kernel-source&lt;br /&gt;
sudo modprobe wl&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you can&#039;t connect the machine to the internet, download the needed packages on another machine and put it on some usb storage. These packages should suffice:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# apt-cache depends bcmwl-kernel-source&lt;br /&gt;
bcmwl-kernel-source&lt;br /&gt;
  Depends: dkms&lt;br /&gt;
  Depends: linux-libc-dev&lt;br /&gt;
  Depends: libc6-dev&lt;br /&gt;
  Conflicts: &amp;lt;bcmwl-modaliases&amp;gt;&lt;br /&gt;
  Replaces: &amp;lt;bcmwl-modaliases&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then install manually with &#039;&#039;&#039;dpkg -i file1.deb file2.deb&#039;&#039;&#039; etc&lt;br /&gt;
&lt;br /&gt;
After this, ip/ifconfig/iwconfig shouldd see the new wifi nic, probably &#039;&#039;&#039;wlan0&#039;&#039;&#039;, but due to a [https://bugs.launchpad.net/ubuntu/+source/broadcom-sta/+bug/1343151 old, ignored bug], you won&#039;t find any wifi networks. This is because the driver from Broadcom apparently does not support interrupt remapping, commonly used on x64 machines. To turn this off, change &#039;&#039;&#039;/etc/default/grub&#039;&#039;&#039; and change the line &#039;&#039;&#039;GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;quiet splash&amp;quot;&#039;&#039;&#039;, adding intremap=off to the end before the quote: &#039;&#039;&#039;GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;quiet splash intremap=off&amp;quot;&#039;&#039;&#039;. Save the file and run &#039;&#039;&#039;sudo update-grub&#039;&#039;&#039; and reboot. After this, wifi should work well.&lt;br /&gt;
&lt;br /&gt;
== Wifi with HP Compaq Presario CQ57 on Ubuntu ==&lt;br /&gt;
&lt;br /&gt;
The HP Compaq Presario CQ57 uses the RT5390 wifi chipset. This has been supported for quite some time now, and I was quite surprised to find it not working on a laptop a friend was having. The driver loaded correctly, but Ubuntu insisted of the laptop being in &#039;&#039;&#039;flight mode&#039;&#039;&#039;. Checking &#039;&#039;&#039;rfkill&#039;&#039;&#039;, it showed me two NICs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# rfkill list all&lt;br /&gt;
0: phy0: Wireless LAN&lt;br /&gt;
	Soft blocked: no&lt;br /&gt;
	Hard blocked: yes&lt;br /&gt;
1: hp-wifi: Wireless LAN&lt;br /&gt;
	Soft blocked: yes&lt;br /&gt;
	Hard blocked: no&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Turning rfkill on and off resulted in nothing much, except some error messages in the kernel log (dmesg)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] ACPI Error: Field [B128] at bit offset/length 128/1024 exceeds size of target Buffer (160 bits) (20170831/dsopcode-235)&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]&lt;br /&gt;
                            Initialized Local Variables for Method [HWCD]:&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Local0: 00000000a34b7928 &amp;lt;Obj&amp;gt;           Integer 0000000000000000&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Local1: 00000000b0aa6865 &amp;lt;Obj&amp;gt;           Buffer(8) 46 41 49 4C 04 00 00 00&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Local5: 00000000a9811efd &amp;lt;Obj&amp;gt;           Integer 0000000000000004&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] Initialized Arguments for Method [HWCD]:  (2 arguments defined for method invocation)&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Arg0:   0000000078957d1b &amp;lt;Obj&amp;gt;           Integer 0000000000000001&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Arg1:   00000000725c9c6e &amp;lt;Obj&amp;gt;           Buffer(20) 53 45 43 55 02 00 00 00&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] ACPI Error: Method parse/execution failed \_SB.WMID.HWCD, AE_AML_BUFFER_LIMIT (20170831/psparse-550)&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] ACPI Error: Method parse/execution failed \_SB.WMID.WMAD, AE_AML_BUFFER_LIMIT (20170831/psparse-550)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After upgrading BIOS and testing different kernels, I was asked to try to unload the &#039;&#039;&#039;hp_wmi&#039;&#039;&#039; driver. I did, and things changed a bit, so I tried blacklisting it, creating the file &#039;&#039;&#039;/etc/modprobe.d/blacklist-hp_wmi.conf&#039;&#039;&#039; with the following content&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Blacklist this - it doesn&#039;t work!&lt;br /&gt;
blacklist hp_wmi&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
I gave the machine a reboot and afte that, the &#039;&#039;&#039;hp-wifi&#039;&#039;&#039; entry was gone in the rfkill output, and things works.&lt;br /&gt;
&lt;br /&gt;
== BIOS upgrade from Linux ==&lt;br /&gt;
&lt;br /&gt;
Generally, BIOS upgrades have been moved to the BIOS itself these days. This saves a lot of work and quite possibly lives after those who earier rammed their heads through walls, now can upgrade directly from the internet instead of using obscure operating systems best avoided. Sometimes, however, one must use these nevertheless. This is a quick run-through on your options.&lt;br /&gt;
&lt;br /&gt;
=== DOS ===&lt;br /&gt;
&lt;br /&gt;
Most non-automatic BIOS upgrades are installed from DOS. Doing a BIOS upgrade this way, is generally non-problematic. Just install a USB thingie with [https://www.freedos.org/ FreeDOS], copy your file(s) onto the thing and boot on it. The commandline is the same as old MS/DOS, except a wee bit more userfriendly, but not a lot.&lt;br /&gt;
&lt;br /&gt;
=== Windows ===&lt;br /&gt;
&lt;br /&gt;
Some macahines, like laptops from &#039;&#039;&#039;HP&#039;&#039;&#039;, may have BIOS upgrades that are made to be installed from Windows and won&#039;t run in FreeDOS or MS/DOS, instead throwing an error, saying &#039;&#039;&#039;This program cannot be run in DOS mode&#039;&#039;&#039;. This means you&#039;ll have to boot on a Windows rescue disc and do the job from there. Googling this, tells you it&#039;s quite easy, you just choose &#039;make rescue disc&#039; from Windows, and it&#039;s all good, except if you don&#039;t run Windows, that is. To remedy this problem, do as follows:&lt;br /&gt;
&lt;br /&gt;
==== Download Windows ====&lt;br /&gt;
&lt;br /&gt;
Since you don&#039;t run Windows and possibly don&#039;t have a spouse or friend around with such unhealthy habits either, you need to get it. It&#039;s quite easy - just google &#039;download windows&#039; and it&#039;ll send you to [https://www.microsoft.com/en-us/software-download/windows10ISO somewhere like this].&lt;br /&gt;
&lt;br /&gt;
==== Burn it! ====&lt;br /&gt;
&lt;br /&gt;
Now it&#039;s time to burn the installer on a DVD ROM. You&#039;ll need a double-layered one, since the OS is &amp;gt; 4.7GiB, but I&#039;m sure you have a ton of those lying around. Now, just place your optical medium in your optical drive and burn, baby, burn!&lt;br /&gt;
&lt;br /&gt;
==== Or make a USB thing? ====&lt;br /&gt;
&lt;br /&gt;
Not a lot of machines have optical drives these days, so you may want to use an USB pen drive or something instead. This is easy, just make the USB bootable with the Windows application Microsoft has made for this. Unfortunately, this only runs on Windows, and unlike stuff like Debian, where the &#039;&#039;&#039;iso&#039;&#039;&#039; file can be dd&#039;ed directly onto a USB drive to make it bootable, the Windows &#039;&#039;&#039;iso&#039;&#039;&#039;s don&#039;t come with this luxury. There are lots of methods to make bootable USB things from iso files out there, but the only thing most of them have in common, is that they generally don&#039;t work.&lt;br /&gt;
&lt;br /&gt;
===== WoeUSB =====&lt;br /&gt;
&lt;br /&gt;
After hours of swearing, it&#039;s nice to come across software like [https://github.com/slacka/WoeUSB WoeUSB]. It may not be perfect, it relies on a bunch of GUI stuff you&#039;ll never need and so on, but it &#039;&#039;&#039;&#039;&#039;works&#039;&#039;&#039;&#039;&#039;, and that&#039;s the important part! Just clone the repo and RTFM and it&#039;s all nice. It&#039;s slow, but hell, getting a windows machine and/or an optical drive might be slower.&lt;br /&gt;
&lt;br /&gt;
WoeUSB does nothing fancy, but it &#039;&#039;&#039;does&#039;&#039;&#039; work. It will create a filesystem, FAT32 or NTFS (better use NTFS, FAT32 has its limits). It creates normal filesystems and so on. Just make sure to copy in the BIOS update file, usually an exe file, to run when Windows is up and running.&lt;br /&gt;
&lt;br /&gt;
===== Install BIOS =====&lt;br /&gt;
&lt;br /&gt;
Boot on the Windows USB thing and choose &#039;repair computer&#039; and then &#039;command prompt&#039;. Find the install file, and if you&#039;re lucky, you&#039;ll find it needs a 32bit OS, just like I did. Since the 64bit version doesn&#039;t include 32bit compatibility in the installer, revert to downloading the 32bit version of windows and start over. Pray to your favourite god(s) not to get across such machines again - it might help.&lt;br /&gt;
&lt;br /&gt;
= 3D printer stuff =&lt;br /&gt;
&lt;br /&gt;
== Hydrophilic filament ==&lt;br /&gt;
&lt;br /&gt;
Most popular filament types, including PLA, PETG, PP or PA (Polyamide, normally known as Nylon) and virtualy any filament type named [https://www.matterhackers.com/news/filament-and-water poly-something] (and thus with an acronym of P-something) are hydrophilic (also (somewhat incorrectly) called hydroscopic), meaning so long they&#039;re dryer than the atmosphere around them, they&#039;ll do their best to suck out the atmosphere&#039;s humidity. This is why most filament are shrink-wrapped with a small bag of silica gel in it. If such filament is exposed for normal humid air for some time, it&#039;ll become very hard to use. Most of my experience is with PLA, which can handle a bit (depending on make), but still not a lot. With PLA, if you end up with prints where the filament seems not to stick, it may help with a higher temperature. Otherwise, the filament must be [https://all3dp.com/2/how-to-dry-filament-pla-abs-and-nylon/ baked]. If you don&#039;t want to use your oven, try something like a [https://www.jula.no/catalog/hjem-og-husholdning/kjokkenmaskiner/mattilberedningsapparater/frukt-sopptorker/frukt-sopptorker-001641/#tab02 fruit and mushroom dryer]. Then get a good, sealble plastic box and add something like half a kilogram of [https://www.ebay.com/sch/sis.html?_nkw=1KG+Orange+Replacement+Desiccant+Indicating+Silica+Gel+Beads+for+Drawers%2C+Camera&amp;amp;_id=131938742628&amp;amp;&amp;amp;_trksid=p2057872.m2749.l2658 silica gel] to an old sock, tie it and put it in the your new dry box.&lt;br /&gt;
&lt;br /&gt;
Please note that ABS is hydrophobic, so you won&#039;t have to worry too much there. Also, remember that PA/Nylon is extremely hydrophilic. Even a couple of days in normal air humidity can ruin it completely and will require baking.&lt;br /&gt;
&lt;br /&gt;
== Upgrading the firmware on an Ender 3 ==&lt;br /&gt;
&lt;br /&gt;
This is about upgrading the firmware, and thus also flashing a bootloader to the Creality Ender 3 3D printer. Most of this is well documented on several place, like o [https://www.youtube.com/watch?v=fIl5X2ffdyo the video from Teaching tech] and elsewhere, but I&#039;ll just summarise some issues I had.&lt;br /&gt;
&lt;br /&gt;
=== Using an arduino Nano as a programmer ===&lt;br /&gt;
&lt;br /&gt;
The CR-10, Ender 3 and a few other printers from Creality come without a bootloader, so you&#039;ll need to flash one before upgrading the firmware. Well, strictly speakning, you don&#039;t need one, you can save those 8kB or so for other stuff and use a programmer to write the whole firmware, but then you&#039;ll need to wire up everything every time you want a new firmware, so in my world, you &#039;&#039;&#039;do&#039;&#039;&#039; need the bootloader, since it&#039;s easier. Note that some newer printers, like the CR-10S and possibly all newer ones, come with the bootloader already and thus won&#039;t need another.&lt;br /&gt;
&lt;br /&gt;
To install a bootloader, you&#039;ll need a programmer, and I didn&#039;t have one available. Having some el-cheapo china-copies of Ardinos around, I read I could use one and tried so. Although the docs mostly mention the Uno etc, it&#039;s just as simple with the Nano copy.&lt;br /&gt;
&lt;br /&gt;
So, grab an arduino, plug it to your machine with an USB cable, and, using the Arduino IDE, use the ArduinoISP sketch there (found under Examples) to burn the software needed for the arduino to work as a programmer. When this is done, connect a 10µF capacitor between RST and GND to stop it from resetting when used as a programmer. Connect the MOSI, MISO and SCK pins from the ICSP block (that little isolated 6-pin block on top of the ardu). See [https://www.arduino.cc/en/Tutorial/ArduinoISP here] for a pinout. Then find Vcc and GND either onthe ICSP block or elsewhere. Some sites say that on some boards you shouldn&#039;t use the pins on the ICSP block for this. I doubt it matters, though. Then connect another jumper wire from pin 10 on the ardu to work as the reset pin outwards to the chip being programmed (that is, on the printer). The ICSP jumper block pin layout is the same on the printer and on the ardu, and probably elsewhere. Sometimes [https://xkcd.com/927/ standardisation] actually works…&lt;br /&gt;
&lt;br /&gt;
See https://cloud.karlsbakk.net/index.php/s/zw48YJjzaf8Rc2F for a pic with the ardu (this wiki is broken atm, will fix it later)&lt;br /&gt;
&lt;br /&gt;
== Flashing the printer ==&lt;br /&gt;
&lt;br /&gt;
When the boot loader is in place, possibly after some wierd errors from during the process, the screen on the 3d printer will go blank and it&#039;ll behave like being bricked. This is ok. Now disconnect the wires and connect the USB cable between computer and printer, download the [https://www.th3dstudio.com/knowledgebase/th3d-unified-firmware-package/ TH3D unified firmware] and configure it for your particular needs. The video mentioned above describes this well. After flashing the new firmware, you&#039;ll probably get some timeouts and errors, since apparently it resets the printer after giving it the new firmware, but without notifying the flashing software of it doing so. If this happens, hold your breath and reboot the printer and check its tiny monitor - it should work. If it doesn&#039;t work, try to flash it again, and if that doesn&#039;t work, try flashing the programmer again yet another time, just for kicks.&lt;br /&gt;
&lt;br /&gt;
PS: I tried enabling &#039;&#039;&#039;MANUAL_MESH_LEVELING&#039;&#039;&#039;, which in the code says that &#039;&#039;If used with a 1284P board the bootscreen will be disabled to save space&#039;&#039;. This effectively disabled the whole thing, and apparently may be making the firmware image a wee bit too large for it to fit the 1284P on the ender. It works well without it, though.&lt;br /&gt;
&lt;br /&gt;
== And then… ==&lt;br /&gt;
&lt;br /&gt;
With the new firmware in place, the printer should work as before, although with thermal runaway protection to better avoid fires in case the shit hits the fan, and to allow for things like autolevelling. With any luck, [https://www.precisionpiezo.co.uk/ this thing] may be ready for use by the time you read this - it surely looks nice!&lt;br /&gt;
&lt;br /&gt;
roy&lt;/div&gt;</summary>
		<author><name>Roy</name></author>
	</entry>
	<entry>
		<id>https://wiki.malinux.no/index.php?title=Roy%27s_notes&amp;diff=148</id>
		<title>Roy&#039;s notes</title>
		<link rel="alternate" type="text/html" href="https://wiki.malinux.no/index.php?title=Roy%27s_notes&amp;diff=148"/>
		<updated>2020-01-24T22:06:18Z</updated>

		<summary type="html">&lt;p&gt;Roy: /* Linux on laptops */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= LVM, md and friends =&lt;br /&gt;
&lt;br /&gt;
== Linux&#039; Logical Volume Manager (LVM) ==&lt;br /&gt;
&lt;br /&gt;
=== LVM in general ===&lt;br /&gt;
&lt;br /&gt;
LVM is designed to be an abstraction layer on top of physical drives or RAID, typically [https://raid.wiki.kernel.org/index.php/RAID_setup mdraid] or [https://help.ubuntu.com/community/FakeRaidHowto fakeraid]. Keep in mind that fakeraid should be avoided unless you really need it, like in conjunction with dual-booting linux and windows on fakeraid. LVM broadly consists of three elements, the &amp;quot;physical&amp;quot; devices (PV), the volume group (VG) and the logical volume (LV). There can be multiple PVs, VGs and LVs, depending on requirement. More about this below. All commands are given as examples, and all of them can be fine-tuned using extra flags in need of so. In my experience, the defaults work well for most usecases.&lt;br /&gt;
&lt;br /&gt;
I&#039;m mentioning filesystem below too. Where I write ext4, the samme applies to ext2 and ext3.&lt;br /&gt;
&lt;br /&gt;
==== Create a PV ====&lt;br /&gt;
&lt;br /&gt;
A PV is the &amp;quot;physical&amp;quot; parts. This does not need to be a physical disk, but can also be another RAID, be it an mdraid, fakeraid, hardware raid, a virtual disk on a SAN or otherwisee or a partition on one of those. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#  These add three PVs, one on a drive (or hardware raid) and another two on mdraids.&lt;br /&gt;
pvcreate /dev/sdb&lt;br /&gt;
pvcreate /dev/md1 /dev/md2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For more information about pvcreate, see [https://linux.die.net/man/8/pvcreate the manual].&lt;br /&gt;
&lt;br /&gt;
==== Create a VG ====&lt;br /&gt;
&lt;br /&gt;
The volume group consists of one or more PVs grouped together on which LVs can be placed. If several PVs are grouped in a VG, it&#039;s generally a good idea to make sure these PVs have some sort of redundancy, as in mdraid/fakeraid or hwraid. Otherwise it will be like using a [https://en.wikipedia.org/wiki/RAID RAID-0] with a single point of failure on each of the independant drives. LVM has [https://unix.stackexchange.com/questions/150644/raiding-with-lvm-vs-mdraid-pros-and-cons  RAID code in it] as well, so you can use that. I haven&#039;t done so myself, as I generally stick to mraid. The reason is mdraid is, in my opinion older and more stable and has more users (meaning bugs are reported and fixed faster whenever they are found). That said, I beleive the actual RAID code used in LVM RAID are the same function calls as for mdraid, so it may not be much of a difference. I still stick with mdraid. To create a VG, run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create volume group my_vg&lt;br /&gt;
vgcreate my_vg /dev/md1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that if vgcreate is run with a PV (as /dev/md1 above) that is not defined as a PV (like above), this is done implicitly, so if you don&#039;t need any special flags to pvcreate, you can simply skip it and let vgcreate do that for you.&lt;br /&gt;
&lt;br /&gt;
==== Create an LV ====&lt;br /&gt;
&lt;br /&gt;
LVs can be compared to partitions, somehow, since they are bounderies of a fraction or all of that of a VG. The difference between them and a partition, however, is that they can be grown or shrunk easily and also moved around between PVs without downtime. This flexibility makes them superiour to partitions as your system can be changed without users noticing it. By default, an LV is alloated &amp;quot;thickly&amp;quot;, meaning all the data given to it, is allocated from the VG and thus the PV. The following makes a 100GB LV named &amp;quot;thicklv&amp;quot;. When making an LV, I usually allocate what&#039;s needed plus some more, but not everything, just to make sure it&#039;s space available for growth on any of the LVs on the VG, or new LVs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a thick provisioned LV named thicklv on the VG my_vg&lt;br /&gt;
lvcreate -n thicklv -L 100G my_vg&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After the LV is created, a filesystem can be placed on it unless it is meant to be used directly. The application for direct use include swap space, VM storage and certain database systems. Most of these will, however, work on filesystems too, although my testing has shown that on swap space, there is a significant performance gain for using dedicated storage without a filesystem. As for filesystems, most Linux users use either ext4 or xfs. Personally, I generally use XFS these days. See my notes below on filesystem choice.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a filesystem on the LV - this could have been mkfs -t ext4 or whatever filesystem you choose&lt;br /&gt;
mkfs -t xfs /dev/my_vg/thicklv&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then just edit /etc/fstab with correct data and run mount -a, and you should be all set.&lt;br /&gt;
&lt;br /&gt;
==== Create LVM cache ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
lvcreate -L 1G -n _cache_meta data /dev/md1&lt;br /&gt;
&lt;br /&gt;
lvcreate -l100%FREE -n _cache data /dev/md1&lt;br /&gt;
&lt;br /&gt;
# Some would want --cachemode writeback, but seriously, I wouldn&#039;t recommend it. Metadata or data can be easily corrupted in case of failure.&lt;br /&gt;
lvconvert --type cache-pool --cachemode writethrough --poolmetadata data/_cache_meta data/_cache&lt;br /&gt;
&lt;br /&gt;
lvconvert --type cache --cachepool data/_cache data/data&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Disabling LVM cache ====&lt;br /&gt;
&lt;br /&gt;
If you for some reason want to disable caching, this will do it cleanly and remove the LVs earlier created for caching the main device.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
lvconvert --uncache data/data&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Growing devices ====&lt;br /&gt;
&lt;br /&gt;
LVM objects can be grown and shrunk. If a PV resides on a RAID where a new drive has been added or otherwise grown, or on a partition or virtual disk that has been extended, the PV must be updated to reflect these changes. The following command will grow the PV to the maximum available on the underlying storage. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Resize the PV /dev/md (not the RAID, only the PV on the RAID) to its full size&lt;br /&gt;
pvresize /dev/md1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If a new PV is added, the VG can be grown to add the space on that in addition to what&#039;s there already. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Extend my_vg to include md2 and its space&lt;br /&gt;
vgextend my_vg /dev/md2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
With more space available in the VG, the LV can now be extended. Let&#039;s add another 50GB to it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Extend thicklv - add 50GB. If you know you won&#039;t need the space anywhere else, you may want to&lt;br /&gt;
# lvresize -l+100%FREE instead. Keep in mind the difference between -l (extents) and -L (bytes)&lt;br /&gt;
lvresize -L +50G my_vg/thicklv&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After the LV has grown, run &#039;&#039;xfs_growfs&#039;&#039; (xfs) or &#039;&#039;resize2fs&#039;&#039; (ext4) to make use of the new data.&lt;br /&gt;
&lt;br /&gt;
==== Rename system VG ====&lt;br /&gt;
&lt;br /&gt;
Some distros create VG names like those-from-a-sysadmin-with-a-well-developed-paranoia-not-to-hit-a-duplicate. Debian, for instance, uses names like &amp;quot;my-full-hostname-vg&amp;quot;. Personally, I don&#039;t like these, since if I were to move a disk or vdisk around to somewhere else, I&#039;d make sure not to add a disk named &#039;sys&#039; to an existing system. If you do, most distros will refuse to use the VGs with duplicate names, resulting in the OS not booting until either one is specified by its UUID or just one removed. As I&#039;m aware of this, I stick to the super-risky thing of all system VGs named &#039;sys&#039; and so on.&lt;br /&gt;
&lt;br /&gt;
If you do this, keep in mind that it may blow up your computer and take your girl- or boyfriend with it or even make either of them pregnant, allowing Trump to rule your life and generally make things suck. You&#039;re on your own!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Rename the VG&lt;br /&gt;
vgrename my-full-hostname-vg sys&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, in /boot/grub/grub.cfg, change the old lv path from something like &#039;/dev/mapper/debian--stretch--machine--vg-root&#039; to your new and fancy &#039;/dev/sys/root. Likewise, in /etc/fstab, change occurences of &#039;/dev/mapper/debian--stretch--machine--vg-&#039; (or similar) with &#039;/dev/sys/&#039;. Here, this was like this - the old ones commented out.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;fstab&amp;quot;&amp;gt;&lt;br /&gt;
#/dev/mapper/debian--stretch--box--vg-root      /               ext4            errors=remount-ro,discard       0       1&lt;br /&gt;
/dev/sys/root                                   /               ext4            errors=remount-ro,discard       0       1&lt;br /&gt;
# /boot was on /dev/vda1 during installation&lt;br /&gt;
UUID=myverylonguuidwithatonofgoodinfoinit       /boot           ext2            defaults                        0       2&lt;br /&gt;
#/dev/mapper/debian--stretch--box--vg-swap_1    none            swap            sw                              0       0&lt;br /&gt;
/dev/sys/swap_1                                 none            swap            sw                              0       0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Update /etc/initramfs-tools/conf.d/resume with similar data for swap.&lt;br /&gt;
&lt;br /&gt;
You might want to run &#039;update-initramfs -u -k all&#039; after this, but I&#039;m not sure if it&#039;s needed.&lt;br /&gt;
&lt;br /&gt;
Now, pray to the nearest god(s) and give it a reboot and it should (probably) work.&lt;br /&gt;
&lt;br /&gt;
After reboot, run &#039;&#039;&#039;swapoff -a&#039;&#039;&#039;, then &#039;&#039;&#039;mkswap /dev/sys/swap_1&#039;&#039;&#039; (or whatever it&#039;s called on your system) and &#039;&#039;&#039;swapon -a&#039;&#039;&#039; again. You may want to give it another reboot or two for kicks, but it should work well even without that.&lt;br /&gt;
&lt;br /&gt;
=== Migration tools ===&lt;br /&gt;
&lt;br /&gt;
At times, storage regimes change, new storage is added and sometimes it&#039;s not easy to migrate with the current hardware or its support systems. Once I had to migrate a 45TiB fileserver from one storage system to another, preferably without downtime. The server originally had three 15TiB PVs of which two were full and the third half full. I resorted to using [https://linux.die.net/man/8/pvmove pvmove] to just move the data on the PVs in use to a new PV. We started out with creating a new 50TiB PV, sde, and then to pvmove.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Attach /dev/sde to the VG my_vg&lt;br /&gt;
vgextend my_vg /dev/sde&lt;br /&gt;
&lt;br /&gt;
# Move the contents from /dev/sdb over to /dev/sde block by block. If a target is not given in pvmove,&lt;br /&gt;
# the contents of the source (sdb here) will be put somewhere else in the pool.&lt;br /&gt;
pvmove /dev/sdb /dev/sde&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This took a while (as in a week or so) - the pvmove command uses old code and logic (or at least did that when I migrated this in November 2016), but it affected performance on the server very little, so users didn&#039;t notice. After the first PV was migrated, I continued with the other two, one after the other, and after a month or so, it was migrated. We used this on a number of large fileservers, and it worked flawlessly. Before doing the production servers I also tried interrupting pvmove in various ways, including hard resets, and it just kept on after the reboot.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;NOTE:&#039;&#039;&#039;&#039;&#039; &#039;&#039;Even though it worked well for us, &#039;&#039;&#039;always&#039;&#039;&#039; keep a good backup before doing this. Things may go wrong, and without a good backup, you may be looking for a hard-to-find new job the next morning&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
==== mdadm workarounds ====&lt;br /&gt;
&lt;br /&gt;
===== Migrate from a mirror (raid-1) to raid-10 =====&lt;br /&gt;
&lt;br /&gt;
Create a mirror&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sdb /dev/sdc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
LVM (pv/vg/lv) on md0 (see above), put a filesystem on the lv and fill it with some data.&lt;br /&gt;
&lt;br /&gt;
Now, some months later, you want to change this to raid-10 to allow for the same amount of redundancy, but to allow more disks into the system.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mdadm --grow /dev/md0 --level=10&lt;br /&gt;
mdadm: Impossibly level change request for RAID1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So - no - doesn&#039;t work. But - we&#039;re on &lt;br /&gt;
&lt;br /&gt;
Since we&#039;re on lvm already, this&#039;ll be easy. If you&#039;re using filesystems directly on partitions, you can do this the same way, but without the pvmove part, using rsync or whateever you like instead. I&#039;d recommend using lvm for for the new raid, which should be rather obvious from this article. Now plug in a new drive and create a new raid10 on that one. If you two new drives, install both. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# change &amp;quot;missing&amp;quot; to the other device name if you installed two new drives&lt;br /&gt;
mdadm --create /dev/md1 --level=10 --raid-devices=2 /dev/vdd missing&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, as described above, just vgextend the vg, adding the new raid and run pvmove to move the data from the old pv (residing on the old raid1) to the new pv (on raid10). Afte rpvmove is finished (which may take awile, see above), just&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
vgreduce raidtest /dev/md0&lt;br /&gt;
pvremove /dev/md0&lt;br /&gt;
mdadm --stop /dev/md0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
…and your disk is free to be added to the new array. If the new raid is running in degraded mode (if you created it with just one drive), better don&#039;t wait too long, since you don&#039;t have redundancy. Just mdadm --add the devs.&lt;br /&gt;
&lt;br /&gt;
If you now have /dev/mdstat telling you your raid10 is active and have three drives, of which one is a spare, it should look something like this&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5] [raid4] [raid10]&lt;br /&gt;
md1 : active raid10 vdc[3](S) vdb[2] vdd[0]&lt;br /&gt;
      8380416 blocks super 1.2 2 near-copies [2/2] [UU]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Just mdadm --grow --raid-devices=3 /dev/md1&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;RAID section is not complete. I&#039;ll write more on migraing from raid10 to raid6 later. It&#039;s not straight forward, but easier than this one :)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== Thin provisioned LVs ===&lt;br /&gt;
&lt;br /&gt;
Thin provisioning on LVM is a method used for not allocating all the space given to an LV. For instance, if you have a 1TB VG and want to give an LV 500GB, although it currently only uses a fraction of that, a thin lv can be a good alternative. This will allow for adding a limit to how much it can use, but also to let it grow dynamically without manual work by the sysadmin. Thin provisioning adds another layer of abstaction by creating a special LV as a &#039;&#039;thin pool&#039;&#039; from which data is allocated to the &#039;&#039;thin volume(s)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== Create a thin pool ====&lt;br /&gt;
&lt;br /&gt;
Allocate 1TB to the thin pool to be used for thinly provisioned LVs. Keep in mind that the space allocated to the thin pool is in fact thick provisioned. Only the volumes put on &#039;&#039;thinpool&#039;&#039; are thin provisioned. This will create two hidden LVs, one for data and one for metadata. Normally the defaults will do, but check the manual if the data doesn&#039;t match the usual patterns (such as billions of files, resulting in huge amounts of metadata). I &#039;&#039;beleive&#039;&#039; the metadata part should be resizable at a later time if needed, but I have not tested it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a pool for thin LVs. Keep in mind that the pool itself is not thin provisioned, only the volumes residing on it&lt;br /&gt;
lvcreate --size 1T --type thin-pool --thinpool thinpool my_vg&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Create a thin volume ====&lt;br /&gt;
&lt;br /&gt;
You have the thinpool, now put a thin volume on it. It will allocate some space for metadata, but probably not much (a few megs, perhaps).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Now, create a volume with a virtual (-V) size of half a terabyte named thin_pool, but using the thinpool (-T) named thin_pool for storage&lt;br /&gt;
lvcreate -V 500G -T my_vg/thin_pool --name thinvol&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The new volume&#039;s device name will be /dev/thinvol. Now, create a filesystem on it, add to fstab and mount it. The &#039;&#039;&#039;df&#039;&#039;&#039; command will return available space according to the virtual size (-V), while lvs will show how much data is actually used on each of the thinly provisioned volumes.&lt;br /&gt;
&lt;br /&gt;
== Filesystem dilemmas ==&lt;br /&gt;
&lt;br /&gt;
=== XFS or ext4 or something else ===&lt;br /&gt;
The choice of filesystem varies for your use. Distros such as RHEL/CentOS has moved to XFS by default from v7. Debian/Ubuntu still sticks to ext4, like most other. I&#039;ll discuss my thoughts below on ext4 vs XFS and leave the other filesystems for later.&lt;br /&gt;
&lt;br /&gt;
==== ext4 ====&lt;br /&gt;
ext4 is probably the most used filesystem on linux as of writing. It&#039;s rock stable and has been extended by a lot of extensions since the original ext2. It still retains backward compatibility, being able to mount and fsck ext2 and ext3 with the ext4 driver. However, it doesn&#039;t handle large filesystems very well. If a filesystem is created for &amp;lt;16TiB, it cannot be grown to anything larger than 16TiB. This may have changed lately, though. One other issue is handling errors. If a large filesystem (say 10TiB) is damaged, an fsck may take several hours, leading to long downtime.&lt;br /&gt;
&lt;br /&gt;
==== XFS ====&lt;br /&gt;
XFS, originally developed by SGI some time in the bronze age, but has been worked on heavily after that. RHEL and Centos version 7 and forward, uses XFS as the default filesystem. It is quick, it scales well, but it lacks at least two things ext4 has. It cannot be shrunk (not that you normally need that, but nice if you have a typo or you need to change things). Also, it doesn&#039;t allow for automatic fsck on bootup. If something is messed up on the filesystem, you&#039;ll have to login as root on the console (not ssh), which might be an issue on some systems. The fsck equivalent, xfs_repair, is a *lot* faster than ext4&#039;s fsck, though.&lt;br /&gt;
&lt;br /&gt;
==== ZFS ====&lt;br /&gt;
ZFS is like a combination of RAID, LVM and a filesystem, supporting full checksumming, auto-healing (given sufficient redundancy), compression, encryption, replication, deduplication (if you&#039;re brave and have a &#039;&#039;ton&#039;&#039; of memory) and a lot more. It&#039;s a separate chapter and needs a lot more talk than paragraph here.&lt;br /&gt;
&lt;br /&gt;
== Low level disk handling ==&lt;br /&gt;
&lt;br /&gt;
This section is for low-level handling of disks, regardless of storage system elsewhere. These apply to mdraid, lvmraid and zfs and possibly other solutions, with the exception of individual drives on hwraid (and maybe fakeraid), since there, the drives are hidden from Linux (or whatever OS).&lt;br /&gt;
&lt;br /&gt;
=== S.M.A.R.T. and slow drives ===&lt;br /&gt;
Modern (that is, from about 1990 or later) have S.M.A.R.T. (or just smart, since it&#039;s easier to type) monitoring built in, meaning the disk&#039;s controller is monitoring itself. This is handy and will ideally tell you in advance that a drive is flakey or dying. Modern (2010+) smart monitoring is more or less the same. It can be trusted about 50% of the time. Usually, if smart detects an error, it&#039;s a real error. I don&#039;t think I&#039;ve seen it reporting a false positive, but others may know better. &lt;br /&gt;
&lt;br /&gt;
==== smartmontools ====&lt;br /&gt;
First, install smartmontool and run smartclt -H /dev/yourdisk (/dev/sda or something) to get a health report. Then perhaps run smartctl -a /dev/yourdisk and look for &#039;current pending sectors&#039; This should be zero. Also check the temperature, which normally should be much above 50.&lt;br /&gt;
&lt;br /&gt;
==== single, slow drive ====&lt;br /&gt;
What may happen, is smart not seeing anything and life goes on like before, only slower and less prouductive, without telling anyone. If you stubler over this issue, you&#039;ll probably see it during a large rsync/zfs send/receive or a resync/rebuild/resilver of the raid/zpool. During this, it feels like everything is slow and your RAID has turned into a RAIF (redundant array of inexpensive floppies). To check if you have a single drive messing up it all, check with &#039;&#039;&#039;iostat -x 2&#039;&#039;&#039;, having 2 being the delay between each measurement. Interrupt it with ctrl+x. If there&#039;s a rougue drive there, it should stand out like sdg below&lt;br /&gt;
&lt;br /&gt;
 avg-cpu:  %user   %nice %system %iowait  %steal   %idle&lt;br /&gt;
            0.38    0.00    1.75    0.00    0.00   97.87&lt;br /&gt;
&lt;br /&gt;
 Device            r/s     w/s     rkB/s     wkB/s   rrqm/s   wrqm/s  %rrqm  %wrqm r_await w_await aqu-sz rareq-sz wareq-sz  svctm  %util&lt;br /&gt;
 sda              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdb              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdc              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdd              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sde              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdf              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdg              3.50    0.00   2352.00      0.00     0.00     0.00   0.00   0.00 14306.29    0.00  13.85   672.00     0.00 285.71 100.00&lt;br /&gt;
 sdh              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
&lt;br /&gt;
In ZFS land, you should be able to get similar data with &#039;&#039;&#039;zpool iostat -v &amp;lt;pool&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Now you know the bad drive (sdg), pull it from the raid with &#039;&#039;&#039;mdadm --fail /dev/mdX /dev/sdX&#039;&#039;&#039;. Now test the drive&#039;s performance manually, just simply:&lt;br /&gt;
&lt;br /&gt;
 # hdparm -t /dev/sdg&lt;br /&gt;
 &lt;br /&gt;
 /dev/sdg:&lt;br /&gt;
  Timing buffered disk reads:   2 MB in  5.37 seconds = 381.46 kB/sec&lt;br /&gt;
&lt;br /&gt;
Bingo - nothing you&#039;d want to keep. For a good drive, it should be something like 100-200MB/s&lt;br /&gt;
&lt;br /&gt;
PS: Keep in mind that you have a degraded RAID by now in case you had a spare waiting for things to happen.&lt;br /&gt;
&lt;br /&gt;
Try to replace the cable and/or try the disk on another port/controller. If the result from hdparm persists, it&#039;s probably a bad cable&lt;br /&gt;
&lt;br /&gt;
So, then, just psycially locate the drive, pull it out, take out the discs and magnets and recycle the rest.&lt;br /&gt;
&lt;br /&gt;
=== &amp;quot;Unplug&amp;quot; drive from system ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Find the device unit&#039;s number with something like&lt;br /&gt;
find /sys/bus/scsi/devices/*/block/ -name sdd&lt;br /&gt;
# returning /sys/bus/scsi/devices/3:0:0:0/block/sdd here, &lt;br /&gt;
# meaning 3:0:0:0 is the SCSI device we&#039;re looking for.&lt;br /&gt;
&lt;br /&gt;
# Given this is the correct device, and you want to &#039;unplug&#039; it, do so by&lt;br /&gt;
echo 1 &amp;gt; /sys/bus/scsi/devices/3:0:0:0/delete&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Rescan disk controllers ===&lt;br /&gt;
If a drive is added and for some reason doesn&#039;t get detected, or is removed by the command above, it can be rediscovered with a sysfs command to the scsi host to which it is connected. Since there may be quite a few of these, an easy way is to just scan them all and check the output of &#039;&#039;&#039;dmesg -T&#039;&#039;&#039; after running it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Make a list of controllers and send a rescan message to each of them. It won&#039;t do anything &lt;br /&gt;
# for those where nothing has changed, but it will show new drives where they have been added.&lt;br /&gt;
for host_scan in /sys/class/scsi_host/host*/scan&lt;br /&gt;
do&lt;br /&gt;
  echo &#039;- - -&#039; &amp;gt; $host_scan&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Fail injection with debugfs ===&lt;br /&gt;
[https://lxadm.com/Using_fault_injection https://lxadm.com/Using_fault_injection]&lt;br /&gt;
&lt;br /&gt;
== mdadm stuff ==&lt;br /&gt;
=== Spare pools ===&lt;br /&gt;
In the old itmes, mdadm supported only a dedicated spare per md device, so if working with a large set of drives (20? 40?), where you&#039;d want to setup more raid sets to increase redundancy, you&#039;d dedicate a spare to each of the raid sets. This has changed (some time ago?), so in these modern, heathen days, you can change mdadm.conf, usually placed under /etc/mdadm, and add &#039;spare-group=somegroup&#039; where &#039;somegroup&#039; is a string identifying the spare group. After doing this, run &#039;&#039;&#039;update-initramfs -u&#039;&#039;&#039; and reboot and add a spare to one of the raid sets in the spare group, and md will use that or those spares for all the raidsets in that group.&lt;br /&gt;
&lt;br /&gt;
As some pointed out on #linux-raid @ irc.freenode.net, this feature is very badly documented, but as far as I can see, it works well.&lt;br /&gt;
&lt;br /&gt;
==== Example config ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create two raidsets&lt;br /&gt;
&lt;br /&gt;
mdadm --create /dev/md1 --level=6 --raid-devices=6 /dev/vd[efghij]&lt;br /&gt;
mdadm --create /dev/md2 --level=6 --raid-devices=6 /dev/vd[klmnop]&lt;br /&gt;
&lt;br /&gt;
# get their UUID etc&lt;br /&gt;
&lt;br /&gt;
mdadm --detail --scan&lt;br /&gt;
ARRAY /dev/md/1 metadata=1.2 name=raidtest:1 UUID=1a8cbdcb:f4092350:348b6b80:c054d74c&lt;br /&gt;
ARRAY /dev/md/2 metadata=1.2 name=raidtest:2 UUID=894b1b7c:cb7eba70:917d6033:ea5afd2b&lt;br /&gt;
&lt;br /&gt;
# Put those lines into /etc/mdadm/mdadm.conf and and add the spare-group&lt;br /&gt;
&lt;br /&gt;
ARRAY /dev/md/1 metadata=1.2 name=raidtest:1 spare-group=raidtest UUID=1a8cbdcb:f4092350:348b6b80:c054d74c&lt;br /&gt;
ARRAY /dev/md/2 metadata=1.2 name=raidtest:2 spare-group=raidtest UUID=894b1b7c:cb7eba70:917d6033:ea5afd2b&lt;br /&gt;
&lt;br /&gt;
# update the initramfs and reboot&lt;br /&gt;
&lt;br /&gt;
update-initramfs -u&lt;br /&gt;
reboot&lt;br /&gt;
&lt;br /&gt;
# add a spare drive to one of the raids&lt;br /&gt;
&lt;br /&gt;
mdadm --add /dev/md1 /dev/vdq&lt;br /&gt;
&lt;br /&gt;
# fail a drive on the other raid&lt;br /&gt;
&lt;br /&gt;
mdadm --fail /dev/md2 /dev/vdn&lt;br /&gt;
&lt;br /&gt;
# check /proc/mdstat to see md2 rebuilding with the spare from md1&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Recovery ===&lt;br /&gt;
&lt;br /&gt;
The other day, I came across a problem a user had on #linux-raid@irc.freenode.net. He had an old Qnap NAS that had died and tried plugging the drives in to his Linux machine and got various errors. The two-drive RAID-1 did not come up as it should, &#039;&#039;&#039;dmesg&#039;&#039;&#039; was full of errors from one of the drives (both connected on USB) and so forth.&lt;br /&gt;
&lt;br /&gt;
We went on and started by taking down the machine and just connecting one of the drives. I had him check what was assembled with&lt;br /&gt;
&lt;br /&gt;
 cat /proc/mdstat&lt;br /&gt;
&lt;br /&gt;
That returned /proc/md127 assembled, but LVM didn&#039;t find anything. So running a manual scan&lt;br /&gt;
&lt;br /&gt;
 pvscan --cache /dev/md127&lt;br /&gt;
&lt;br /&gt;
This made linux find the PV, VG and a couple of LVs, but probably because the mdraid was degraded, the LVs were deactivated, according to &#039;&#039;&#039;lvscan&#039;&#039;&#039;. Activating the one with a filesystem manually&lt;br /&gt;
&lt;br /&gt;
 lvchange -a y /dev/&amp;lt;vg&amp;gt;/&amp;lt;lv&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Substitute &amp;lt;vg&amp;gt; and &amp;lt;lv&amp;gt; with the names listed by vgs and lvs.&lt;br /&gt;
&lt;br /&gt;
This worked, and the filesystem on /dev/&amp;lt;vg&amp;gt;/&amp;lt;lv&amp;gt; could be mounted correctly.&lt;br /&gt;
&lt;br /&gt;
== Tuning ==&lt;br /&gt;
&lt;br /&gt;
While trying to compare a 12-disk RAID (8TB disks) to a hwraid, mdraid was slower, so we did a few things to speed things up:&lt;br /&gt;
&lt;br /&gt;
While testing with [https://linux.die.net/man/1/fio fio], monitor /sys/block/md0/md/stripe_cache_active, and see if it&#039;s close to /sys/block/md0/md/stripe_cache_size. If it is, double the size of the latter&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
echo 4096 &amp;gt; /sys/block/md0/md/stripe_cache_size&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Continue until stripe_cache_active stabilises, and then you&#039;ve found the limit you&#039;ll need. You may want to double that for good measure. &lt;br /&gt;
&lt;br /&gt;
(to be continued)&lt;br /&gt;
&lt;br /&gt;
== Links ==&lt;br /&gt;
&lt;br /&gt;
Below are a few links with useful info&lt;br /&gt;
&lt;br /&gt;
* [https://raid.wiki.kernel.org/index.php/Irreversible_mdadm_failure_recovery Irreversible mdadm failure recovery]&lt;br /&gt;
&lt;br /&gt;
= ZFS =&lt;br /&gt;
&lt;br /&gt;
ZFS can do a lot of things most filesystems or volume managers can&#039;t. It checksums all data and metadata and so long that the system uses ECC enabled memory (RAM), it will have complete control over the whole data set, and when (not if) an error occurs, it&#039;ll fix the issue without even throwing a warning. To fix the issue, you&#039;ll obviously need sufficient redundancy (mirrors or RAIDzN). &lt;br /&gt;
&lt;br /&gt;
== ZFS send/receive between machines ==&lt;br /&gt;
&lt;br /&gt;
ZFS has a send/receive mechanism that allows for snapshots to be sent over the wire to a receiving end. This can be a full filesystem, or an incremental change since last send/reveive. In a WAN scenario, you&#039;ll probably want to use VPN for this. On a controlled network, sending in cleartext is also possible. You may as well use ssh, but keep in mind that ssh was never designed to be used as a fullblown vpn solution and is just too slow or the task with large amounts of data. You may, though, use mbuffer, if on a loal LAN.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Allow traffic from the sending IP in whatever firewall interface you&#039;re using (if you&#039;re using a firewall at all, that is)&lt;br /&gt;
ufw allow from x.x.x.x&lt;br /&gt;
# &lt;br /&gt;
# Start the receiver first. This listens on port 9090, has a 1GB buffer,&lt;br /&gt;
    and uses 128kb chunks (same as zfs):&lt;br /&gt;
&lt;br /&gt;
mbuffer -s 128k -m 1G -I 9090 | zfs receive data/filesystem&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To be continued one day… See [https://everycity.co.uk/alasdair/2010/07/using-mbuffer-to-speed-up-slow-zfs-send-zfs-receive/ this] for some more. I&#039;ll get back with details on it.&lt;br /&gt;
&lt;br /&gt;
= General Linux system control =&lt;br /&gt;
&lt;br /&gt;
== Add a new CPU (core) ==&lt;br /&gt;
&lt;br /&gt;
If working with virtual machines, adding a new core can be useful if the VM is slow and the load is multithreaded or multiprocess. To do this, add a new CPU in the hypervisor (be it KVM or VMware or Hyper-V or whatever). Some hypervisors, like VMware, will activate it automatically if open-vm-tools is installed. Please note that open-vm-tools is for VMware only. I don&#039;t know of any such thing for KVM or other hypervisors (although I beleive VirtualBox has its own set of tools, but not as a package). If this doesn&#039;t work, run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
echo 1 &amp;gt; /sys/devices/system/cpu/cpuX/online&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where X is the CPU number you want to add. You can &#039;cat /sys/devices/system/cpu/cpuX/online&#039; to check if it&#039;s online.&lt;br /&gt;
&lt;br /&gt;
= Mount partitions on a disk image =&lt;br /&gt;
&lt;br /&gt;
Sometimes you&#039;ll have a disk image, either from recovering a bad drive after hours (or days or weeks) of ddrescue, and sometimes you just have a disk image from a virtual machine where you want to mount the partitions inside the image. There are three main methods of doing this, which are more or less synonmous, but some easier than the other.&lt;br /&gt;
&lt;br /&gt;
== Basics ==&lt;br /&gt;
&lt;br /&gt;
A disk image is usually like a disk, consisting of either a large filesystem, a PV or a partition table with one or partitions onto which resides a filesystem, a pv, swap or something else. If it&#039;s partitioned, and you want your operating system to mount a filesystem or allow it to see whatever LVM stuff lies on it, you need to isolate the partitions. &lt;br /&gt;
&lt;br /&gt;
== Manual mapping ==&lt;br /&gt;
&lt;br /&gt;
In the oldern days, this was done manually, something like this&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
root@mymachine:~# fdisk -l /dev/vda&lt;br /&gt;
Disk /dev/vda: 25 GiB, 26843545600 bytes, 52428800 sectors&lt;br /&gt;
Units: sectors of 1 * 512 = 512 bytes&lt;br /&gt;
Sector size (logical/physical): 512 bytes / 512 bytes&lt;br /&gt;
I/O size (minimum/optimal): 512 bytes / 512 bytes&lt;br /&gt;
Disklabel type: dos&lt;br /&gt;
Disk identifier: 0xc37b7ea5&lt;br /&gt;
&lt;br /&gt;
Device     Boot    Start      End  Sectors  Size Id Type&lt;br /&gt;
/dev/vda1  *        2048 50333311 50331264   24G 83 Linux&lt;br /&gt;
/dev/vda2       50333312 52426369  2093058 1022M  5 Extended&lt;br /&gt;
/dev/vda5       50333314 52426369  2093056 1022M 82 Linux swap / Solaris&lt;br /&gt;
root@mymachine:~#&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To calculate the start and end of each partition, you just take the start sector and multiply it by the sector size (512 bytes here) and you have the offset in bytes. After this, it&#039;s merely an losetup -o &amp;lt;offset&amp;gt; /dev/loopX &amp;lt;nameofimagefile&amp;gt; and you have the partition mapped to your /dev/loopX (having X being something typically 0-255. After this, just mount it or run pvscan/vgscan/lvscan to probe whatever lvm config is there, and you should be able to mount it like any other filesystem.&lt;br /&gt;
&lt;br /&gt;
== kpartx ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;kpartx&#039;&#039;&#039; does the same as above, more or less, just without so much hassle. Most of it should be automatic and easy to deal with, except it may fail to disconnect the loopback devices sometimes, so you may have to &#039;&#039;&#039;losetup -d&#039;&#039;&#039; them manually. See the manual, &#039;&#039;&#039;kpartx (8)&#039;&#039;&#039;. Please note that &#039;&#039;&#039;partx&#039;&#039;&#039; works similarly and I&#039;d guess the authors of the two tools are arguing a lot of which one&#039;s the best.&lt;br /&gt;
&lt;br /&gt;
== guestmount ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;guestmount&#039;&#039;&#039; is something similar again, but also supports file formats like &#039;&#039;&#039;qcow2&#039;&#039;&#039; and possibly other, proprietary filesystems like &#039;&#039;&#039;vmdk&#039;&#039;&#039; and &#039;&#039;&#039;vdi&#039;&#039;&#039;, but don&#039;t take my word for it - I haven&#039;t tested. Again, see the manual or just read up on the description [http://ask.xmodulo.com/mount-qcow2-disk-image-linux.html?fbclid=IwAR3snTeZvGzp9PLdX11EQhCfOpux6I93CiJ3A2pUomkkRLly9Xo4851mkTY here]. It seems rather trivial.&lt;br /&gt;
&lt;br /&gt;
= Linux on laptops =&lt;br /&gt;
&lt;br /&gt;
== Wifi with HP EliteBook 725/745 on Ubuntu ==&lt;br /&gt;
&lt;br /&gt;
The HP EliteBook 725/745 and similar are equipped with a BCM4352 wifi chip. As with a lot of other stuff from Broadcom, this lacks an open hardware description, so thus no open driver exist. The proper fix, is to replace the NIC with something with an open driver, but again, this isn&#039;t always possible, so a binary driver exists. In ubuntu, run, somehow connect the machine to the internet and run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install bcmwl-kernel-source&lt;br /&gt;
sudo modprobe wl&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you can&#039;t connect the machine to the internet, download the needed packages on another machine and put it on some usb storage. These packages should suffice:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# apt-cache depends bcmwl-kernel-source&lt;br /&gt;
bcmwl-kernel-source&lt;br /&gt;
  Depends: dkms&lt;br /&gt;
  Depends: linux-libc-dev&lt;br /&gt;
  Depends: libc6-dev&lt;br /&gt;
  Conflicts: &amp;lt;bcmwl-modaliases&amp;gt;&lt;br /&gt;
  Replaces: &amp;lt;bcmwl-modaliases&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then install manually with &#039;&#039;&#039;dpkg -i file1.deb file2.deb&#039;&#039;&#039; etc&lt;br /&gt;
&lt;br /&gt;
After this, ip/ifconfig/iwconfig shouldd see the new wifi nic, probably &#039;&#039;&#039;wlan0&#039;&#039;&#039;, but due to a [https://bugs.launchpad.net/ubuntu/+source/broadcom-sta/+bug/1343151 old, ignored bug], you won&#039;t find any wifi networks. This is because the driver from Broadcom apparently does not support interrupt remapping, commonly used on x64 machines. To turn this off, change &#039;&#039;&#039;/etc/default/grub&#039;&#039;&#039; and change the line &#039;&#039;&#039;GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;quiet splash&amp;quot;&#039;&#039;&#039;, adding intremap=off to the end before the quote: &#039;&#039;&#039;GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;quiet splash intremap=off&amp;quot;&#039;&#039;&#039;. Save the file and run &#039;&#039;&#039;sudo update-grub&#039;&#039;&#039; and reboot. After this, wifi should work well.&lt;br /&gt;
&lt;br /&gt;
== Wifi with HP Compaq Presario CQ57 on Ubuntu ==&lt;br /&gt;
&lt;br /&gt;
The HP Compaq Presario CQ57 uses the RT5390 wifi chipset. This has been supported for quite some time now, and I was quite surprised to find it not working on a laptop a friend was having. The driver loaded correctly, but Ubuntu insisted of the laptop being in &#039;&#039;&#039;flight mode&#039;&#039;&#039;. Checking &#039;&#039;&#039;rfkill&#039;&#039;&#039;, it showed me two NICs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# rfkill list all&lt;br /&gt;
0: phy0: Wireless LAN&lt;br /&gt;
	Soft blocked: no&lt;br /&gt;
	Hard blocked: yes&lt;br /&gt;
1: hp-wifi: Wireless LAN&lt;br /&gt;
	Soft blocked: yes&lt;br /&gt;
	Hard blocked: no&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Turning rfkill on and off resulted in nothing much, except some error messages in the kernel log (dmesg)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] ACPI Error: Field [B128] at bit offset/length 128/1024 exceeds size of target Buffer (160 bits) (20170831/dsopcode-235)&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]&lt;br /&gt;
                            Initialized Local Variables for Method [HWCD]:&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Local0: 00000000a34b7928 &amp;lt;Obj&amp;gt;           Integer 0000000000000000&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Local1: 00000000b0aa6865 &amp;lt;Obj&amp;gt;           Buffer(8) 46 41 49 4C 04 00 00 00&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Local5: 00000000a9811efd &amp;lt;Obj&amp;gt;           Integer 0000000000000004&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] Initialized Arguments for Method [HWCD]:  (2 arguments defined for method invocation)&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Arg0:   0000000078957d1b &amp;lt;Obj&amp;gt;           Integer 0000000000000001&lt;br /&gt;
[fr. jan. 24 15:10:20 2020]   Arg1:   00000000725c9c6e &amp;lt;Obj&amp;gt;           Buffer(20) 53 45 43 55 02 00 00 00&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] ACPI Error: Method parse/execution failed \_SB.WMID.HWCD, AE_AML_BUFFER_LIMIT (20170831/psparse-550)&lt;br /&gt;
[fr. jan. 24 15:10:20 2020] ACPI Error: Method parse/execution failed \_SB.WMID.WMAD, AE_AML_BUFFER_LIMIT (20170831/psparse-550)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After upgrading BIOS and testing different kernels, I was asked to try to unload the &#039;&#039;&#039;hp_wmi&#039;&#039;&#039; driver. I did, and things changed a bit, so I tried blacklisting it, creating the file &#039;&#039;&#039;/etc/modprobe.d/blacklist-hp_wmi.conf&#039;&#039;&#039; with the following content&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Blacklist this - it doesn&#039;t work!&lt;br /&gt;
blacklist hp_wmi&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
I gave the machine a reboot and afte that, the &#039;&#039;&#039;hp-wifi&#039;&#039;&#039; entry was gone in the rfkill output, and things works.&lt;br /&gt;
&lt;br /&gt;
== BIOS upgrade from Linux ==&lt;br /&gt;
&lt;br /&gt;
Generally, BIOS upgrades have been moved to the BIOS itself these days. This saves a lot of work and quite possibly lives after those who earier rammed their heads through walls, now can upgrade directly from the internet instead of using obscure operating systems best avoided. Sometimes, however, one must use these nevertheless. This is a quick run-through on your options.&lt;br /&gt;
&lt;br /&gt;
=== DOS ===&lt;br /&gt;
&lt;br /&gt;
Most non-automatic BIOS upgrades are installed from DOS. Doing a BIOS upgrade this way, is generally non-problematic. Just install a USB thingie with [https://www.freedos.org/ FreeDOS], copy your file(s) onto the thing and boot on it. The commandline is the same as old MS/DOS, except a wee bit more userfriendly, but not a lot.&lt;br /&gt;
&lt;br /&gt;
=== Windows ===&lt;br /&gt;
&lt;br /&gt;
Some macahines, like laptops from &#039;&#039;&#039;HP&#039;&#039;&#039;, may have BIOS upgrades that are made to be installed from Windows and won&#039;t run in FreeDOS or MS/DOS, instead throwing an error, saying &#039;&#039;&#039;This program cannot be run in DOS mode&#039;&#039;&#039;. This means you&#039;ll have to boot on a Windows rescue disc and do the job from there. Googling this, tells you it&#039;s quite easy, you just choose &#039;make rescue disc&#039; from Windows, and it&#039;s all good, except if you don&#039;t run Windows, that is. To remedy this problem, do as follows:&lt;br /&gt;
&lt;br /&gt;
==== Download Windows ====&lt;br /&gt;
&lt;br /&gt;
Since you don&#039;t run Windows and possibly don&#039;t have a spouse or friend around with such unhealthy habits either, you need to get it. It&#039;s quite easy - just google &#039;download windows&#039; and it&#039;ll send you to [https://www.microsoft.com/en-us/software-download/windows10ISO somewhere like this].&lt;br /&gt;
&lt;br /&gt;
==== Burn it! ====&lt;br /&gt;
&lt;br /&gt;
Now it&#039;s time to burn the installer on a DVD ROM. You&#039;ll need a double-layered one, since the OS is &amp;gt; 4.7GiB, but I&#039;m sure you have a ton of those lying around. Now, just place your optical medium in your optical drive and burn, baby, burn!&lt;br /&gt;
&lt;br /&gt;
==== Or make a USB thing? ====&lt;br /&gt;
&lt;br /&gt;
Not a lot of machines have optical drives these days, so you may want to use an USB pen drive or something instead. This is easy, just make the USB bootable with the Windows application Microsoft has made for this. Unfortunately, this only runs on Windows, and unlike stuff like Debian, where the &#039;&#039;&#039;iso&#039;&#039;&#039; file can be dd&#039;ed directly onto a USB drive to make it bootable, the Windows &#039;&#039;&#039;iso&#039;&#039;&#039;s don&#039;t come with this luxury. There are lots of methods to make bootable USB things from iso files out there, but the only thing most of them have in common, is that they generally don&#039;t work.&lt;br /&gt;
&lt;br /&gt;
===== WoeUSB =====&lt;br /&gt;
&lt;br /&gt;
After hours of swearing, it&#039;s nice to come across software like [https://github.com/slacka/WoeUSB WoeUSB]. It may not be perfect, it relies on a bunch of GUI stuff you&#039;ll never need and so on, but it &#039;&#039;&#039;&#039;&#039;works&#039;&#039;&#039;&#039;&#039;, and that&#039;s the important part! Just clone the repo and RTFM and it&#039;s all nice. It&#039;s slow, but hell, getting a windows machine and/or an optical drive might be slower.&lt;br /&gt;
&lt;br /&gt;
WoeUSB does nothing fancy, but it &#039;&#039;&#039;does&#039;&#039;&#039; work. It will create a filesystem, FAT32 or NTFS (better use NTFS, FAT32 has its limits). It creates normal filesystems and so on. Just make sure to copy in the BIOS update file, usually an exe file, to run when Windows is up and running.&lt;br /&gt;
&lt;br /&gt;
===== Install BIOS =====&lt;br /&gt;
&lt;br /&gt;
Boot on the Windows USB thing and choose &#039;repair computer&#039; and then &#039;command prompt&#039;. Find the install file, and if you&#039;re lucky, you&#039;ll find it needs a 32bit OS, just like I did. Since the 64bit version doesn&#039;t include 32bit compatibility in the installer, revert to downloading the 32bit version of windows and start over. Pray to your favourite god(s) not to get across such machines again - it might help.&lt;br /&gt;
&lt;br /&gt;
= 3D printer stuff =&lt;br /&gt;
&lt;br /&gt;
== Hydrophilic filament ==&lt;br /&gt;
&lt;br /&gt;
Most popular filament types, including PLA, PETG, PP or PA (Polyamide, normally known as Nylon) and virtualy any filament type named [https://www.matterhackers.com/news/filament-and-water poly-something] (and thus with an acronym of P-something) are hydrophilic (also (somewhat incorrectly) called hydroscopic), meaning so long they&#039;re dryer than the atmosphere around them, they&#039;ll do their best to suck out the atmosphere&#039;s humidity. This is why most filament are shrink-wrapped with a small bag of silica gel in it. If such filament is exposed for normal humid air for some time, it&#039;ll become very hard to use. Most of my experience is with PLA, which can handle a bit (depending on make), but still not a lot. With PLA, if you end up with prints where the filament seems not to stick, it may help with a higher temperature. Otherwise, the filament must be [https://all3dp.com/2/how-to-dry-filament-pla-abs-and-nylon/ baked]. If you don&#039;t want to use your oven, try something like a [https://www.jula.no/catalog/hjem-og-husholdning/kjokkenmaskiner/mattilberedningsapparater/frukt-sopptorker/frukt-sopptorker-001641/#tab02 fruit and mushroom dryer]. Then get a good, sealble plastic box and add something like half a kilogram of [https://www.ebay.com/sch/sis.html?_nkw=1KG+Orange+Replacement+Desiccant+Indicating+Silica+Gel+Beads+for+Drawers%2C+Camera&amp;amp;_id=131938742628&amp;amp;&amp;amp;_trksid=p2057872.m2749.l2658 silica gel] to an old sock, tie it and put it in the your new dry box.&lt;br /&gt;
&lt;br /&gt;
Please note that ABS is hydrophobic, so you won&#039;t have to worry too much there. Also, remember that PA/Nylon is extremely hydrophilic. Even a couple of days in normal air humidity can ruin it completely and will require baking.&lt;br /&gt;
&lt;br /&gt;
== Upgrading the firmware on an Ender 3 ==&lt;br /&gt;
&lt;br /&gt;
This is about upgrading the firmware, and thus also flashing a bootloader to the Creality Ender 3 3D printer. Most of this is well documented on several place, like o [https://www.youtube.com/watch?v=fIl5X2ffdyo the video from Teaching tech] and elsewhere, but I&#039;ll just summarise some issues I had.&lt;br /&gt;
&lt;br /&gt;
=== Using an arduino Nano as a programmer ===&lt;br /&gt;
&lt;br /&gt;
The CR-10, Ender 3 and a few other printers from Creality come without a bootloader, so you&#039;ll need to flash one before upgrading the firmware. Well, strictly speakning, you don&#039;t need one, you can save those 8kB or so for other stuff and use a programmer to write the whole firmware, but then you&#039;ll need to wire up everything every time you want a new firmware, so in my world, you &#039;&#039;&#039;do&#039;&#039;&#039; need the bootloader, since it&#039;s easier. Note that some newer printers, like the CR-10S and possibly all newer ones, come with the bootloader already and thus won&#039;t need another.&lt;br /&gt;
&lt;br /&gt;
To install a bootloader, you&#039;ll need a programmer, and I didn&#039;t have one available. Having some el-cheapo china-copies of Ardinos around, I read I could use one and tried so. Although the docs mostly mention the Uno etc, it&#039;s just as simple with the Nano copy.&lt;br /&gt;
&lt;br /&gt;
So, grab an arduino, plug it to your machine with an USB cable, and, using the Arduino IDE, use the ArduinoISP sketch there (found under Examples) to burn the software needed for the arduino to work as a programmer. When this is done, connect a 10µF capacitor between RST and GND to stop it from resetting when used as a programmer. Connect the MOSI, MISO and SCK pins from the ICSP block (that little isolated 6-pin block on top of the ardu). See [https://www.arduino.cc/en/Tutorial/ArduinoISP here] for a pinout. Then find Vcc and GND either onthe ICSP block or elsewhere. Some sites say that on some boards you shouldn&#039;t use the pins on the ICSP block for this. I doubt it matters, though. Then connect another jumper wire from pin 10 on the ardu to work as the reset pin outwards to the chip being programmed (that is, on the printer). The ICSP jumper block pin layout is the same on the printer and on the ardu, and probably elsewhere. Sometimes [https://xkcd.com/927/ standardisation] actually works…&lt;br /&gt;
&lt;br /&gt;
See https://cloud.karlsbakk.net/index.php/s/zw48YJjzaf8Rc2F for a pic with the ardu (this wiki is broken atm, will fix it later)&lt;br /&gt;
&lt;br /&gt;
== Flashing the printer ==&lt;br /&gt;
&lt;br /&gt;
When the boot loader is in place, possibly after some wierd errors from during the process, the screen on the 3d printer will go blank and it&#039;ll behave like being bricked. This is ok. Now disconnect the wires and connect the USB cable between computer and printer, download the [https://www.th3dstudio.com/knowledgebase/th3d-unified-firmware-package/ TH3D unified firmware] and configure it for your particular needs. The video mentioned above describes this well. After flashing the new firmware, you&#039;ll probably get some timeouts and errors, since apparently it resets the printer after giving it the new firmware, but without notifying the flashing software of it doing so. If this happens, hold your breath and reboot the printer and check its tiny monitor - it should work. If it doesn&#039;t work, try to flash it again, and if that doesn&#039;t work, try flashing the programmer again yet another time, just for kicks.&lt;br /&gt;
&lt;br /&gt;
PS: I tried enabling &#039;&#039;&#039;MANUAL_MESH_LEVELING&#039;&#039;&#039;, which in the code says that &#039;&#039;If used with a 1284P board the bootscreen will be disabled to save space&#039;&#039;. This effectively disabled the whole thing, and apparently may be making the firmware image a wee bit too large for it to fit the 1284P on the ender. It works well without it, though.&lt;br /&gt;
&lt;br /&gt;
== And then… ==&lt;br /&gt;
&lt;br /&gt;
With the new firmware in place, the printer should work as before, although with thermal runaway protection to better avoid fires in case the shit hits the fan, and to allow for things like autolevelling. With any luck, [https://www.precisionpiezo.co.uk/ this thing] may be ready for use by the time you read this - it surely looks nice!&lt;br /&gt;
&lt;br /&gt;
roy&lt;/div&gt;</summary>
		<author><name>Roy</name></author>
	</entry>
	<entry>
		<id>https://wiki.malinux.no/index.php?title=Roy%27s_notes&amp;diff=147</id>
		<title>Roy&#039;s notes</title>
		<link rel="alternate" type="text/html" href="https://wiki.malinux.no/index.php?title=Roy%27s_notes&amp;diff=147"/>
		<updated>2020-01-24T20:02:19Z</updated>

		<summary type="html">&lt;p&gt;Roy: /* Linux on laptops */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= LVM, md and friends =&lt;br /&gt;
&lt;br /&gt;
== Linux&#039; Logical Volume Manager (LVM) ==&lt;br /&gt;
&lt;br /&gt;
=== LVM in general ===&lt;br /&gt;
&lt;br /&gt;
LVM is designed to be an abstraction layer on top of physical drives or RAID, typically [https://raid.wiki.kernel.org/index.php/RAID_setup mdraid] or [https://help.ubuntu.com/community/FakeRaidHowto fakeraid]. Keep in mind that fakeraid should be avoided unless you really need it, like in conjunction with dual-booting linux and windows on fakeraid. LVM broadly consists of three elements, the &amp;quot;physical&amp;quot; devices (PV), the volume group (VG) and the logical volume (LV). There can be multiple PVs, VGs and LVs, depending on requirement. More about this below. All commands are given as examples, and all of them can be fine-tuned using extra flags in need of so. In my experience, the defaults work well for most usecases.&lt;br /&gt;
&lt;br /&gt;
I&#039;m mentioning filesystem below too. Where I write ext4, the samme applies to ext2 and ext3.&lt;br /&gt;
&lt;br /&gt;
==== Create a PV ====&lt;br /&gt;
&lt;br /&gt;
A PV is the &amp;quot;physical&amp;quot; parts. This does not need to be a physical disk, but can also be another RAID, be it an mdraid, fakeraid, hardware raid, a virtual disk on a SAN or otherwisee or a partition on one of those. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#  These add three PVs, one on a drive (or hardware raid) and another two on mdraids.&lt;br /&gt;
pvcreate /dev/sdb&lt;br /&gt;
pvcreate /dev/md1 /dev/md2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For more information about pvcreate, see [https://linux.die.net/man/8/pvcreate the manual].&lt;br /&gt;
&lt;br /&gt;
==== Create a VG ====&lt;br /&gt;
&lt;br /&gt;
The volume group consists of one or more PVs grouped together on which LVs can be placed. If several PVs are grouped in a VG, it&#039;s generally a good idea to make sure these PVs have some sort of redundancy, as in mdraid/fakeraid or hwraid. Otherwise it will be like using a [https://en.wikipedia.org/wiki/RAID RAID-0] with a single point of failure on each of the independant drives. LVM has [https://unix.stackexchange.com/questions/150644/raiding-with-lvm-vs-mdraid-pros-and-cons  RAID code in it] as well, so you can use that. I haven&#039;t done so myself, as I generally stick to mraid. The reason is mdraid is, in my opinion older and more stable and has more users (meaning bugs are reported and fixed faster whenever they are found). That said, I beleive the actual RAID code used in LVM RAID are the same function calls as for mdraid, so it may not be much of a difference. I still stick with mdraid. To create a VG, run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create volume group my_vg&lt;br /&gt;
vgcreate my_vg /dev/md1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that if vgcreate is run with a PV (as /dev/md1 above) that is not defined as a PV (like above), this is done implicitly, so if you don&#039;t need any special flags to pvcreate, you can simply skip it and let vgcreate do that for you.&lt;br /&gt;
&lt;br /&gt;
==== Create an LV ====&lt;br /&gt;
&lt;br /&gt;
LVs can be compared to partitions, somehow, since they are bounderies of a fraction or all of that of a VG. The difference between them and a partition, however, is that they can be grown or shrunk easily and also moved around between PVs without downtime. This flexibility makes them superiour to partitions as your system can be changed without users noticing it. By default, an LV is alloated &amp;quot;thickly&amp;quot;, meaning all the data given to it, is allocated from the VG and thus the PV. The following makes a 100GB LV named &amp;quot;thicklv&amp;quot;. When making an LV, I usually allocate what&#039;s needed plus some more, but not everything, just to make sure it&#039;s space available for growth on any of the LVs on the VG, or new LVs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a thick provisioned LV named thicklv on the VG my_vg&lt;br /&gt;
lvcreate -n thicklv -L 100G my_vg&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After the LV is created, a filesystem can be placed on it unless it is meant to be used directly. The application for direct use include swap space, VM storage and certain database systems. Most of these will, however, work on filesystems too, although my testing has shown that on swap space, there is a significant performance gain for using dedicated storage without a filesystem. As for filesystems, most Linux users use either ext4 or xfs. Personally, I generally use XFS these days. See my notes below on filesystem choice.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a filesystem on the LV - this could have been mkfs -t ext4 or whatever filesystem you choose&lt;br /&gt;
mkfs -t xfs /dev/my_vg/thicklv&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then just edit /etc/fstab with correct data and run mount -a, and you should be all set.&lt;br /&gt;
&lt;br /&gt;
==== Create LVM cache ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
lvcreate -L 1G -n _cache_meta data /dev/md1&lt;br /&gt;
&lt;br /&gt;
lvcreate -l100%FREE -n _cache data /dev/md1&lt;br /&gt;
&lt;br /&gt;
# Some would want --cachemode writeback, but seriously, I wouldn&#039;t recommend it. Metadata or data can be easily corrupted in case of failure.&lt;br /&gt;
lvconvert --type cache-pool --cachemode writethrough --poolmetadata data/_cache_meta data/_cache&lt;br /&gt;
&lt;br /&gt;
lvconvert --type cache --cachepool data/_cache data/data&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Disabling LVM cache ====&lt;br /&gt;
&lt;br /&gt;
If you for some reason want to disable caching, this will do it cleanly and remove the LVs earlier created for caching the main device.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
lvconvert --uncache data/data&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Growing devices ====&lt;br /&gt;
&lt;br /&gt;
LVM objects can be grown and shrunk. If a PV resides on a RAID where a new drive has been added or otherwise grown, or on a partition or virtual disk that has been extended, the PV must be updated to reflect these changes. The following command will grow the PV to the maximum available on the underlying storage. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Resize the PV /dev/md (not the RAID, only the PV on the RAID) to its full size&lt;br /&gt;
pvresize /dev/md1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If a new PV is added, the VG can be grown to add the space on that in addition to what&#039;s there already. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Extend my_vg to include md2 and its space&lt;br /&gt;
vgextend my_vg /dev/md2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
With more space available in the VG, the LV can now be extended. Let&#039;s add another 50GB to it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Extend thicklv - add 50GB. If you know you won&#039;t need the space anywhere else, you may want to&lt;br /&gt;
# lvresize -l+100%FREE instead. Keep in mind the difference between -l (extents) and -L (bytes)&lt;br /&gt;
lvresize -L +50G my_vg/thicklv&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After the LV has grown, run &#039;&#039;xfs_growfs&#039;&#039; (xfs) or &#039;&#039;resize2fs&#039;&#039; (ext4) to make use of the new data.&lt;br /&gt;
&lt;br /&gt;
==== Rename system VG ====&lt;br /&gt;
&lt;br /&gt;
Some distros create VG names like those-from-a-sysadmin-with-a-well-developed-paranoia-not-to-hit-a-duplicate. Debian, for instance, uses names like &amp;quot;my-full-hostname-vg&amp;quot;. Personally, I don&#039;t like these, since if I were to move a disk or vdisk around to somewhere else, I&#039;d make sure not to add a disk named &#039;sys&#039; to an existing system. If you do, most distros will refuse to use the VGs with duplicate names, resulting in the OS not booting until either one is specified by its UUID or just one removed. As I&#039;m aware of this, I stick to the super-risky thing of all system VGs named &#039;sys&#039; and so on.&lt;br /&gt;
&lt;br /&gt;
If you do this, keep in mind that it may blow up your computer and take your girl- or boyfriend with it or even make either of them pregnant, allowing Trump to rule your life and generally make things suck. You&#039;re on your own!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Rename the VG&lt;br /&gt;
vgrename my-full-hostname-vg sys&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, in /boot/grub/grub.cfg, change the old lv path from something like &#039;/dev/mapper/debian--stretch--machine--vg-root&#039; to your new and fancy &#039;/dev/sys/root. Likewise, in /etc/fstab, change occurences of &#039;/dev/mapper/debian--stretch--machine--vg-&#039; (or similar) with &#039;/dev/sys/&#039;. Here, this was like this - the old ones commented out.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;fstab&amp;quot;&amp;gt;&lt;br /&gt;
#/dev/mapper/debian--stretch--box--vg-root      /               ext4            errors=remount-ro,discard       0       1&lt;br /&gt;
/dev/sys/root                                   /               ext4            errors=remount-ro,discard       0       1&lt;br /&gt;
# /boot was on /dev/vda1 during installation&lt;br /&gt;
UUID=myverylonguuidwithatonofgoodinfoinit       /boot           ext2            defaults                        0       2&lt;br /&gt;
#/dev/mapper/debian--stretch--box--vg-swap_1    none            swap            sw                              0       0&lt;br /&gt;
/dev/sys/swap_1                                 none            swap            sw                              0       0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Update /etc/initramfs-tools/conf.d/resume with similar data for swap.&lt;br /&gt;
&lt;br /&gt;
You might want to run &#039;update-initramfs -u -k all&#039; after this, but I&#039;m not sure if it&#039;s needed.&lt;br /&gt;
&lt;br /&gt;
Now, pray to the nearest god(s) and give it a reboot and it should (probably) work.&lt;br /&gt;
&lt;br /&gt;
After reboot, run &#039;&#039;&#039;swapoff -a&#039;&#039;&#039;, then &#039;&#039;&#039;mkswap /dev/sys/swap_1&#039;&#039;&#039; (or whatever it&#039;s called on your system) and &#039;&#039;&#039;swapon -a&#039;&#039;&#039; again. You may want to give it another reboot or two for kicks, but it should work well even without that.&lt;br /&gt;
&lt;br /&gt;
=== Migration tools ===&lt;br /&gt;
&lt;br /&gt;
At times, storage regimes change, new storage is added and sometimes it&#039;s not easy to migrate with the current hardware or its support systems. Once I had to migrate a 45TiB fileserver from one storage system to another, preferably without downtime. The server originally had three 15TiB PVs of which two were full and the third half full. I resorted to using [https://linux.die.net/man/8/pvmove pvmove] to just move the data on the PVs in use to a new PV. We started out with creating a new 50TiB PV, sde, and then to pvmove.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Attach /dev/sde to the VG my_vg&lt;br /&gt;
vgextend my_vg /dev/sde&lt;br /&gt;
&lt;br /&gt;
# Move the contents from /dev/sdb over to /dev/sde block by block. If a target is not given in pvmove,&lt;br /&gt;
# the contents of the source (sdb here) will be put somewhere else in the pool.&lt;br /&gt;
pvmove /dev/sdb /dev/sde&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This took a while (as in a week or so) - the pvmove command uses old code and logic (or at least did that when I migrated this in November 2016), but it affected performance on the server very little, so users didn&#039;t notice. After the first PV was migrated, I continued with the other two, one after the other, and after a month or so, it was migrated. We used this on a number of large fileservers, and it worked flawlessly. Before doing the production servers I also tried interrupting pvmove in various ways, including hard resets, and it just kept on after the reboot.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;NOTE:&#039;&#039;&#039;&#039;&#039; &#039;&#039;Even though it worked well for us, &#039;&#039;&#039;always&#039;&#039;&#039; keep a good backup before doing this. Things may go wrong, and without a good backup, you may be looking for a hard-to-find new job the next morning&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
==== mdadm workarounds ====&lt;br /&gt;
&lt;br /&gt;
===== Migrate from a mirror (raid-1) to raid-10 =====&lt;br /&gt;
&lt;br /&gt;
Create a mirror&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sdb /dev/sdc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
LVM (pv/vg/lv) on md0 (see above), put a filesystem on the lv and fill it with some data.&lt;br /&gt;
&lt;br /&gt;
Now, some months later, you want to change this to raid-10 to allow for the same amount of redundancy, but to allow more disks into the system.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mdadm --grow /dev/md0 --level=10&lt;br /&gt;
mdadm: Impossibly level change request for RAID1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So - no - doesn&#039;t work. But - we&#039;re on &lt;br /&gt;
&lt;br /&gt;
Since we&#039;re on lvm already, this&#039;ll be easy. If you&#039;re using filesystems directly on partitions, you can do this the same way, but without the pvmove part, using rsync or whateever you like instead. I&#039;d recommend using lvm for for the new raid, which should be rather obvious from this article. Now plug in a new drive and create a new raid10 on that one. If you two new drives, install both. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# change &amp;quot;missing&amp;quot; to the other device name if you installed two new drives&lt;br /&gt;
mdadm --create /dev/md1 --level=10 --raid-devices=2 /dev/vdd missing&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, as described above, just vgextend the vg, adding the new raid and run pvmove to move the data from the old pv (residing on the old raid1) to the new pv (on raid10). Afte rpvmove is finished (which may take awile, see above), just&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
vgreduce raidtest /dev/md0&lt;br /&gt;
pvremove /dev/md0&lt;br /&gt;
mdadm --stop /dev/md0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
…and your disk is free to be added to the new array. If the new raid is running in degraded mode (if you created it with just one drive), better don&#039;t wait too long, since you don&#039;t have redundancy. Just mdadm --add the devs.&lt;br /&gt;
&lt;br /&gt;
If you now have /dev/mdstat telling you your raid10 is active and have three drives, of which one is a spare, it should look something like this&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5] [raid4] [raid10]&lt;br /&gt;
md1 : active raid10 vdc[3](S) vdb[2] vdd[0]&lt;br /&gt;
      8380416 blocks super 1.2 2 near-copies [2/2] [UU]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Just mdadm --grow --raid-devices=3 /dev/md1&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;RAID section is not complete. I&#039;ll write more on migraing from raid10 to raid6 later. It&#039;s not straight forward, but easier than this one :)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== Thin provisioned LVs ===&lt;br /&gt;
&lt;br /&gt;
Thin provisioning on LVM is a method used for not allocating all the space given to an LV. For instance, if you have a 1TB VG and want to give an LV 500GB, although it currently only uses a fraction of that, a thin lv can be a good alternative. This will allow for adding a limit to how much it can use, but also to let it grow dynamically without manual work by the sysadmin. Thin provisioning adds another layer of abstaction by creating a special LV as a &#039;&#039;thin pool&#039;&#039; from which data is allocated to the &#039;&#039;thin volume(s)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== Create a thin pool ====&lt;br /&gt;
&lt;br /&gt;
Allocate 1TB to the thin pool to be used for thinly provisioned LVs. Keep in mind that the space allocated to the thin pool is in fact thick provisioned. Only the volumes put on &#039;&#039;thinpool&#039;&#039; are thin provisioned. This will create two hidden LVs, one for data and one for metadata. Normally the defaults will do, but check the manual if the data doesn&#039;t match the usual patterns (such as billions of files, resulting in huge amounts of metadata). I &#039;&#039;beleive&#039;&#039; the metadata part should be resizable at a later time if needed, but I have not tested it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a pool for thin LVs. Keep in mind that the pool itself is not thin provisioned, only the volumes residing on it&lt;br /&gt;
lvcreate --size 1T --type thin-pool --thinpool thinpool my_vg&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Create a thin volume ====&lt;br /&gt;
&lt;br /&gt;
You have the thinpool, now put a thin volume on it. It will allocate some space for metadata, but probably not much (a few megs, perhaps).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Now, create a volume with a virtual (-V) size of half a terabyte named thin_pool, but using the thinpool (-T) named thin_pool for storage&lt;br /&gt;
lvcreate -V 500G -T my_vg/thin_pool --name thinvol&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The new volume&#039;s device name will be /dev/thinvol. Now, create a filesystem on it, add to fstab and mount it. The &#039;&#039;&#039;df&#039;&#039;&#039; command will return available space according to the virtual size (-V), while lvs will show how much data is actually used on each of the thinly provisioned volumes.&lt;br /&gt;
&lt;br /&gt;
== Filesystem dilemmas ==&lt;br /&gt;
&lt;br /&gt;
=== XFS or ext4 or something else ===&lt;br /&gt;
The choice of filesystem varies for your use. Distros such as RHEL/CentOS has moved to XFS by default from v7. Debian/Ubuntu still sticks to ext4, like most other. I&#039;ll discuss my thoughts below on ext4 vs XFS and leave the other filesystems for later.&lt;br /&gt;
&lt;br /&gt;
==== ext4 ====&lt;br /&gt;
ext4 is probably the most used filesystem on linux as of writing. It&#039;s rock stable and has been extended by a lot of extensions since the original ext2. It still retains backward compatibility, being able to mount and fsck ext2 and ext3 with the ext4 driver. However, it doesn&#039;t handle large filesystems very well. If a filesystem is created for &amp;lt;16TiB, it cannot be grown to anything larger than 16TiB. This may have changed lately, though. One other issue is handling errors. If a large filesystem (say 10TiB) is damaged, an fsck may take several hours, leading to long downtime.&lt;br /&gt;
&lt;br /&gt;
==== XFS ====&lt;br /&gt;
XFS, originally developed by SGI some time in the bronze age, but has been worked on heavily after that. RHEL and Centos version 7 and forward, uses XFS as the default filesystem. It is quick, it scales well, but it lacks at least two things ext4 has. It cannot be shrunk (not that you normally need that, but nice if you have a typo or you need to change things). Also, it doesn&#039;t allow for automatic fsck on bootup. If something is messed up on the filesystem, you&#039;ll have to login as root on the console (not ssh), which might be an issue on some systems. The fsck equivalent, xfs_repair, is a *lot* faster than ext4&#039;s fsck, though.&lt;br /&gt;
&lt;br /&gt;
==== ZFS ====&lt;br /&gt;
ZFS is like a combination of RAID, LVM and a filesystem, supporting full checksumming, auto-healing (given sufficient redundancy), compression, encryption, replication, deduplication (if you&#039;re brave and have a &#039;&#039;ton&#039;&#039; of memory) and a lot more. It&#039;s a separate chapter and needs a lot more talk than paragraph here.&lt;br /&gt;
&lt;br /&gt;
== Low level disk handling ==&lt;br /&gt;
&lt;br /&gt;
This section is for low-level handling of disks, regardless of storage system elsewhere. These apply to mdraid, lvmraid and zfs and possibly other solutions, with the exception of individual drives on hwraid (and maybe fakeraid), since there, the drives are hidden from Linux (or whatever OS).&lt;br /&gt;
&lt;br /&gt;
=== S.M.A.R.T. and slow drives ===&lt;br /&gt;
Modern (that is, from about 1990 or later) have S.M.A.R.T. (or just smart, since it&#039;s easier to type) monitoring built in, meaning the disk&#039;s controller is monitoring itself. This is handy and will ideally tell you in advance that a drive is flakey or dying. Modern (2010+) smart monitoring is more or less the same. It can be trusted about 50% of the time. Usually, if smart detects an error, it&#039;s a real error. I don&#039;t think I&#039;ve seen it reporting a false positive, but others may know better. &lt;br /&gt;
&lt;br /&gt;
==== smartmontools ====&lt;br /&gt;
First, install smartmontool and run smartclt -H /dev/yourdisk (/dev/sda or something) to get a health report. Then perhaps run smartctl -a /dev/yourdisk and look for &#039;current pending sectors&#039; This should be zero. Also check the temperature, which normally should be much above 50.&lt;br /&gt;
&lt;br /&gt;
==== single, slow drive ====&lt;br /&gt;
What may happen, is smart not seeing anything and life goes on like before, only slower and less prouductive, without telling anyone. If you stubler over this issue, you&#039;ll probably see it during a large rsync/zfs send/receive or a resync/rebuild/resilver of the raid/zpool. During this, it feels like everything is slow and your RAID has turned into a RAIF (redundant array of inexpensive floppies). To check if you have a single drive messing up it all, check with &#039;&#039;&#039;iostat -x 2&#039;&#039;&#039;, having 2 being the delay between each measurement. Interrupt it with ctrl+x. If there&#039;s a rougue drive there, it should stand out like sdg below&lt;br /&gt;
&lt;br /&gt;
 avg-cpu:  %user   %nice %system %iowait  %steal   %idle&lt;br /&gt;
            0.38    0.00    1.75    0.00    0.00   97.87&lt;br /&gt;
&lt;br /&gt;
 Device            r/s     w/s     rkB/s     wkB/s   rrqm/s   wrqm/s  %rrqm  %wrqm r_await w_await aqu-sz rareq-sz wareq-sz  svctm  %util&lt;br /&gt;
 sda              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdb              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdc              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdd              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sde              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdf              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdg              3.50    0.00   2352.00      0.00     0.00     0.00   0.00   0.00 14306.29    0.00  13.85   672.00     0.00 285.71 100.00&lt;br /&gt;
 sdh              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
&lt;br /&gt;
In ZFS land, you should be able to get similar data with &#039;&#039;&#039;zpool iostat -v &amp;lt;pool&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Now you know the bad drive (sdg), pull it from the raid with &#039;&#039;&#039;mdadm --fail /dev/mdX /dev/sdX&#039;&#039;&#039;. Now test the drive&#039;s performance manually, just simply:&lt;br /&gt;
&lt;br /&gt;
 # hdparm -t /dev/sdg&lt;br /&gt;
 &lt;br /&gt;
 /dev/sdg:&lt;br /&gt;
  Timing buffered disk reads:   2 MB in  5.37 seconds = 381.46 kB/sec&lt;br /&gt;
&lt;br /&gt;
Bingo - nothing you&#039;d want to keep. For a good drive, it should be something like 100-200MB/s&lt;br /&gt;
&lt;br /&gt;
PS: Keep in mind that you have a degraded RAID by now in case you had a spare waiting for things to happen.&lt;br /&gt;
&lt;br /&gt;
Try to replace the cable and/or try the disk on another port/controller. If the result from hdparm persists, it&#039;s probably a bad cable&lt;br /&gt;
&lt;br /&gt;
So, then, just psycially locate the drive, pull it out, take out the discs and magnets and recycle the rest.&lt;br /&gt;
&lt;br /&gt;
=== &amp;quot;Unplug&amp;quot; drive from system ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Find the device unit&#039;s number with something like&lt;br /&gt;
find /sys/bus/scsi/devices/*/block/ -name sdd&lt;br /&gt;
# returning /sys/bus/scsi/devices/3:0:0:0/block/sdd here, &lt;br /&gt;
# meaning 3:0:0:0 is the SCSI device we&#039;re looking for.&lt;br /&gt;
&lt;br /&gt;
# Given this is the correct device, and you want to &#039;unplug&#039; it, do so by&lt;br /&gt;
echo 1 &amp;gt; /sys/bus/scsi/devices/3:0:0:0/delete&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Rescan disk controllers ===&lt;br /&gt;
If a drive is added and for some reason doesn&#039;t get detected, or is removed by the command above, it can be rediscovered with a sysfs command to the scsi host to which it is connected. Since there may be quite a few of these, an easy way is to just scan them all and check the output of &#039;&#039;&#039;dmesg -T&#039;&#039;&#039; after running it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Make a list of controllers and send a rescan message to each of them. It won&#039;t do anything &lt;br /&gt;
# for those where nothing has changed, but it will show new drives where they have been added.&lt;br /&gt;
for host_scan in /sys/class/scsi_host/host*/scan&lt;br /&gt;
do&lt;br /&gt;
  echo &#039;- - -&#039; &amp;gt; $host_scan&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Fail injection with debugfs ===&lt;br /&gt;
[https://lxadm.com/Using_fault_injection https://lxadm.com/Using_fault_injection]&lt;br /&gt;
&lt;br /&gt;
== mdadm stuff ==&lt;br /&gt;
=== Spare pools ===&lt;br /&gt;
In the old itmes, mdadm supported only a dedicated spare per md device, so if working with a large set of drives (20? 40?), where you&#039;d want to setup more raid sets to increase redundancy, you&#039;d dedicate a spare to each of the raid sets. This has changed (some time ago?), so in these modern, heathen days, you can change mdadm.conf, usually placed under /etc/mdadm, and add &#039;spare-group=somegroup&#039; where &#039;somegroup&#039; is a string identifying the spare group. After doing this, run &#039;&#039;&#039;update-initramfs -u&#039;&#039;&#039; and reboot and add a spare to one of the raid sets in the spare group, and md will use that or those spares for all the raidsets in that group.&lt;br /&gt;
&lt;br /&gt;
As some pointed out on #linux-raid @ irc.freenode.net, this feature is very badly documented, but as far as I can see, it works well.&lt;br /&gt;
&lt;br /&gt;
==== Example config ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create two raidsets&lt;br /&gt;
&lt;br /&gt;
mdadm --create /dev/md1 --level=6 --raid-devices=6 /dev/vd[efghij]&lt;br /&gt;
mdadm --create /dev/md2 --level=6 --raid-devices=6 /dev/vd[klmnop]&lt;br /&gt;
&lt;br /&gt;
# get their UUID etc&lt;br /&gt;
&lt;br /&gt;
mdadm --detail --scan&lt;br /&gt;
ARRAY /dev/md/1 metadata=1.2 name=raidtest:1 UUID=1a8cbdcb:f4092350:348b6b80:c054d74c&lt;br /&gt;
ARRAY /dev/md/2 metadata=1.2 name=raidtest:2 UUID=894b1b7c:cb7eba70:917d6033:ea5afd2b&lt;br /&gt;
&lt;br /&gt;
# Put those lines into /etc/mdadm/mdadm.conf and and add the spare-group&lt;br /&gt;
&lt;br /&gt;
ARRAY /dev/md/1 metadata=1.2 name=raidtest:1 spare-group=raidtest UUID=1a8cbdcb:f4092350:348b6b80:c054d74c&lt;br /&gt;
ARRAY /dev/md/2 metadata=1.2 name=raidtest:2 spare-group=raidtest UUID=894b1b7c:cb7eba70:917d6033:ea5afd2b&lt;br /&gt;
&lt;br /&gt;
# update the initramfs and reboot&lt;br /&gt;
&lt;br /&gt;
update-initramfs -u&lt;br /&gt;
reboot&lt;br /&gt;
&lt;br /&gt;
# add a spare drive to one of the raids&lt;br /&gt;
&lt;br /&gt;
mdadm --add /dev/md1 /dev/vdq&lt;br /&gt;
&lt;br /&gt;
# fail a drive on the other raid&lt;br /&gt;
&lt;br /&gt;
mdadm --fail /dev/md2 /dev/vdn&lt;br /&gt;
&lt;br /&gt;
# check /proc/mdstat to see md2 rebuilding with the spare from md1&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Recovery ===&lt;br /&gt;
&lt;br /&gt;
The other day, I came across a problem a user had on #linux-raid@irc.freenode.net. He had an old Qnap NAS that had died and tried plugging the drives in to his Linux machine and got various errors. The two-drive RAID-1 did not come up as it should, &#039;&#039;&#039;dmesg&#039;&#039;&#039; was full of errors from one of the drives (both connected on USB) and so forth.&lt;br /&gt;
&lt;br /&gt;
We went on and started by taking down the machine and just connecting one of the drives. I had him check what was assembled with&lt;br /&gt;
&lt;br /&gt;
 cat /proc/mdstat&lt;br /&gt;
&lt;br /&gt;
That returned /proc/md127 assembled, but LVM didn&#039;t find anything. So running a manual scan&lt;br /&gt;
&lt;br /&gt;
 pvscan --cache /dev/md127&lt;br /&gt;
&lt;br /&gt;
This made linux find the PV, VG and a couple of LVs, but probably because the mdraid was degraded, the LVs were deactivated, according to &#039;&#039;&#039;lvscan&#039;&#039;&#039;. Activating the one with a filesystem manually&lt;br /&gt;
&lt;br /&gt;
 lvchange -a y /dev/&amp;lt;vg&amp;gt;/&amp;lt;lv&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Substitute &amp;lt;vg&amp;gt; and &amp;lt;lv&amp;gt; with the names listed by vgs and lvs.&lt;br /&gt;
&lt;br /&gt;
This worked, and the filesystem on /dev/&amp;lt;vg&amp;gt;/&amp;lt;lv&amp;gt; could be mounted correctly.&lt;br /&gt;
&lt;br /&gt;
== Tuning ==&lt;br /&gt;
&lt;br /&gt;
While trying to compare a 12-disk RAID (8TB disks) to a hwraid, mdraid was slower, so we did a few things to speed things up:&lt;br /&gt;
&lt;br /&gt;
While testing with [https://linux.die.net/man/1/fio fio], monitor /sys/block/md0/md/stripe_cache_active, and see if it&#039;s close to /sys/block/md0/md/stripe_cache_size. If it is, double the size of the latter&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
echo 4096 &amp;gt; /sys/block/md0/md/stripe_cache_size&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Continue until stripe_cache_active stabilises, and then you&#039;ve found the limit you&#039;ll need. You may want to double that for good measure. &lt;br /&gt;
&lt;br /&gt;
(to be continued)&lt;br /&gt;
&lt;br /&gt;
== Links ==&lt;br /&gt;
&lt;br /&gt;
Below are a few links with useful info&lt;br /&gt;
&lt;br /&gt;
* [https://raid.wiki.kernel.org/index.php/Irreversible_mdadm_failure_recovery Irreversible mdadm failure recovery]&lt;br /&gt;
&lt;br /&gt;
= ZFS =&lt;br /&gt;
&lt;br /&gt;
ZFS can do a lot of things most filesystems or volume managers can&#039;t. It checksums all data and metadata and so long that the system uses ECC enabled memory (RAM), it will have complete control over the whole data set, and when (not if) an error occurs, it&#039;ll fix the issue without even throwing a warning. To fix the issue, you&#039;ll obviously need sufficient redundancy (mirrors or RAIDzN). &lt;br /&gt;
&lt;br /&gt;
== ZFS send/receive between machines ==&lt;br /&gt;
&lt;br /&gt;
ZFS has a send/receive mechanism that allows for snapshots to be sent over the wire to a receiving end. This can be a full filesystem, or an incremental change since last send/reveive. In a WAN scenario, you&#039;ll probably want to use VPN for this. On a controlled network, sending in cleartext is also possible. You may as well use ssh, but keep in mind that ssh was never designed to be used as a fullblown vpn solution and is just too slow or the task with large amounts of data. You may, though, use mbuffer, if on a loal LAN.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Allow traffic from the sending IP in whatever firewall interface you&#039;re using (if you&#039;re using a firewall at all, that is)&lt;br /&gt;
ufw allow from x.x.x.x&lt;br /&gt;
# &lt;br /&gt;
# Start the receiver first. This listens on port 9090, has a 1GB buffer,&lt;br /&gt;
    and uses 128kb chunks (same as zfs):&lt;br /&gt;
&lt;br /&gt;
mbuffer -s 128k -m 1G -I 9090 | zfs receive data/filesystem&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To be continued one day… See [https://everycity.co.uk/alasdair/2010/07/using-mbuffer-to-speed-up-slow-zfs-send-zfs-receive/ this] for some more. I&#039;ll get back with details on it.&lt;br /&gt;
&lt;br /&gt;
= General Linux system control =&lt;br /&gt;
&lt;br /&gt;
== Add a new CPU (core) ==&lt;br /&gt;
&lt;br /&gt;
If working with virtual machines, adding a new core can be useful if the VM is slow and the load is multithreaded or multiprocess. To do this, add a new CPU in the hypervisor (be it KVM or VMware or Hyper-V or whatever). Some hypervisors, like VMware, will activate it automatically if open-vm-tools is installed. Please note that open-vm-tools is for VMware only. I don&#039;t know of any such thing for KVM or other hypervisors (although I beleive VirtualBox has its own set of tools, but not as a package). If this doesn&#039;t work, run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
echo 1 &amp;gt; /sys/devices/system/cpu/cpuX/online&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where X is the CPU number you want to add. You can &#039;cat /sys/devices/system/cpu/cpuX/online&#039; to check if it&#039;s online.&lt;br /&gt;
&lt;br /&gt;
= Mount partitions on a disk image =&lt;br /&gt;
&lt;br /&gt;
Sometimes you&#039;ll have a disk image, either from recovering a bad drive after hours (or days or weeks) of ddrescue, and sometimes you just have a disk image from a virtual machine where you want to mount the partitions inside the image. There are three main methods of doing this, which are more or less synonmous, but some easier than the other.&lt;br /&gt;
&lt;br /&gt;
== Basics ==&lt;br /&gt;
&lt;br /&gt;
A disk image is usually like a disk, consisting of either a large filesystem, a PV or a partition table with one or partitions onto which resides a filesystem, a pv, swap or something else. If it&#039;s partitioned, and you want your operating system to mount a filesystem or allow it to see whatever LVM stuff lies on it, you need to isolate the partitions. &lt;br /&gt;
&lt;br /&gt;
== Manual mapping ==&lt;br /&gt;
&lt;br /&gt;
In the oldern days, this was done manually, something like this&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
root@mymachine:~# fdisk -l /dev/vda&lt;br /&gt;
Disk /dev/vda: 25 GiB, 26843545600 bytes, 52428800 sectors&lt;br /&gt;
Units: sectors of 1 * 512 = 512 bytes&lt;br /&gt;
Sector size (logical/physical): 512 bytes / 512 bytes&lt;br /&gt;
I/O size (minimum/optimal): 512 bytes / 512 bytes&lt;br /&gt;
Disklabel type: dos&lt;br /&gt;
Disk identifier: 0xc37b7ea5&lt;br /&gt;
&lt;br /&gt;
Device     Boot    Start      End  Sectors  Size Id Type&lt;br /&gt;
/dev/vda1  *        2048 50333311 50331264   24G 83 Linux&lt;br /&gt;
/dev/vda2       50333312 52426369  2093058 1022M  5 Extended&lt;br /&gt;
/dev/vda5       50333314 52426369  2093056 1022M 82 Linux swap / Solaris&lt;br /&gt;
root@mymachine:~#&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To calculate the start and end of each partition, you just take the start sector and multiply it by the sector size (512 bytes here) and you have the offset in bytes. After this, it&#039;s merely an losetup -o &amp;lt;offset&amp;gt; /dev/loopX &amp;lt;nameofimagefile&amp;gt; and you have the partition mapped to your /dev/loopX (having X being something typically 0-255. After this, just mount it or run pvscan/vgscan/lvscan to probe whatever lvm config is there, and you should be able to mount it like any other filesystem.&lt;br /&gt;
&lt;br /&gt;
== kpartx ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;kpartx&#039;&#039;&#039; does the same as above, more or less, just without so much hassle. Most of it should be automatic and easy to deal with, except it may fail to disconnect the loopback devices sometimes, so you may have to &#039;&#039;&#039;losetup -d&#039;&#039;&#039; them manually. See the manual, &#039;&#039;&#039;kpartx (8)&#039;&#039;&#039;. Please note that &#039;&#039;&#039;partx&#039;&#039;&#039; works similarly and I&#039;d guess the authors of the two tools are arguing a lot of which one&#039;s the best.&lt;br /&gt;
&lt;br /&gt;
== guestmount ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;guestmount&#039;&#039;&#039; is something similar again, but also supports file formats like &#039;&#039;&#039;qcow2&#039;&#039;&#039; and possibly other, proprietary filesystems like &#039;&#039;&#039;vmdk&#039;&#039;&#039; and &#039;&#039;&#039;vdi&#039;&#039;&#039;, but don&#039;t take my word for it - I haven&#039;t tested. Again, see the manual or just read up on the description [http://ask.xmodulo.com/mount-qcow2-disk-image-linux.html?fbclid=IwAR3snTeZvGzp9PLdX11EQhCfOpux6I93CiJ3A2pUomkkRLly9Xo4851mkTY here]. It seems rather trivial.&lt;br /&gt;
&lt;br /&gt;
= Linux on laptops =&lt;br /&gt;
&lt;br /&gt;
== Wifi with HP EliteBook 725/745 on Ubuntu ==&lt;br /&gt;
&lt;br /&gt;
The HP EliteBook 725/745 and similar are equipped with a BCM4352 wifi chip. As with a lot of other stuff from Broadcom, this lacks an open hardware description, so thus no open driver exist. The proper fix, is to replace the NIC with something with an open driver, but again, this isn&#039;t always possible, so a binary driver exists. In ubuntu, run, somehow connect the machine to the internet and run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install bcmwl-kernel-source&lt;br /&gt;
sudo modprobe wl&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you can&#039;t connect the machine to the internet, download the needed packages on another machine and put it on some usb storage. These packages should suffice:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# apt-cache depends bcmwl-kernel-source&lt;br /&gt;
bcmwl-kernel-source&lt;br /&gt;
  Depends: dkms&lt;br /&gt;
  Depends: linux-libc-dev&lt;br /&gt;
  Depends: libc6-dev&lt;br /&gt;
  Conflicts: &amp;lt;bcmwl-modaliases&amp;gt;&lt;br /&gt;
  Replaces: &amp;lt;bcmwl-modaliases&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then install manually with &#039;&#039;&#039;dpkg -i file1.deb file2.deb&#039;&#039;&#039; etc&lt;br /&gt;
&lt;br /&gt;
After this, ip/ifconfig/iwconfig shouldd see the new wifi nic, probably &#039;&#039;&#039;wlan0&#039;&#039;&#039;, but due to a [https://bugs.launchpad.net/ubuntu/+source/broadcom-sta/+bug/1343151 old, ignored bug], you won&#039;t find any wifi networks. This is because the driver from Broadcom apparently does not support interrupt remapping, commonly used on x64 machines. To turn this off, change &#039;&#039;&#039;/etc/default/grub&#039;&#039;&#039; and change the line &#039;&#039;&#039;GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;quiet splash&amp;quot;&#039;&#039;&#039;, adding intremap=off to the end before the quote: &#039;&#039;&#039;GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;quiet splash intremap=off&amp;quot;&#039;&#039;&#039;. Save the file and run &#039;&#039;&#039;sudo update-grub&#039;&#039;&#039; and reboot. After this, wifi should work well.&lt;br /&gt;
&lt;br /&gt;
== BIOS upgrade from Linux ==&lt;br /&gt;
&lt;br /&gt;
Generally, BIOS upgrades have been moved to the BIOS itself these days. This saves a lot of work and quite possibly lives after those who earier rammed their heads through walls, now can upgrade directly from the internet instead of using obscure operating systems best avoided. Sometimes, however, one must use these nevertheless. This is a quick run-through on your options.&lt;br /&gt;
&lt;br /&gt;
=== DOS ===&lt;br /&gt;
&lt;br /&gt;
Most non-automatic BIOS upgrades are installed from DOS. Doing a BIOS upgrade this way, is generally non-problematic. Just install a USB thingie with [https://www.freedos.org/ FreeDOS], copy your file(s) onto the thing and boot on it. The commandline is the same as old MS/DOS, except a wee bit more userfriendly, but not a lot.&lt;br /&gt;
&lt;br /&gt;
=== Windows ===&lt;br /&gt;
&lt;br /&gt;
Some macahines, like laptops from &#039;&#039;&#039;HP&#039;&#039;&#039;, may have BIOS upgrades that are made to be installed from Windows and won&#039;t run in FreeDOS or MS/DOS, instead throwing an error, saying &#039;&#039;&#039;This program cannot be run in DOS mode&#039;&#039;&#039;. This means you&#039;ll have to boot on a Windows rescue disc and do the job from there. Googling this, tells you it&#039;s quite easy, you just choose &#039;make rescue disc&#039; from Windows, and it&#039;s all good, except if you don&#039;t run Windows, that is. To remedy this problem, do as follows:&lt;br /&gt;
&lt;br /&gt;
==== Download Windows ====&lt;br /&gt;
&lt;br /&gt;
Since you don&#039;t run Windows and possibly don&#039;t have a spouse or friend around with such unhealthy habits either, you need to get it. It&#039;s quite easy - just google &#039;download windows&#039; and it&#039;ll send you to [https://www.microsoft.com/en-us/software-download/windows10ISO somewhere like this].&lt;br /&gt;
&lt;br /&gt;
==== Burn it! ====&lt;br /&gt;
&lt;br /&gt;
Now it&#039;s time to burn the installer on a DVD ROM. You&#039;ll need a double-layered one, since the OS is &amp;gt; 4.7GiB, but I&#039;m sure you have a ton of those lying around. Now, just place your optical medium in your optical drive and burn, baby, burn!&lt;br /&gt;
&lt;br /&gt;
==== Or make a USB thing? ====&lt;br /&gt;
&lt;br /&gt;
Not a lot of machines have optical drives these days, so you may want to use an USB pen drive or something instead. This is easy, just make the USB bootable with the Windows application Microsoft has made for this. Unfortunately, this only runs on Windows, and unlike stuff like Debian, where the &#039;&#039;&#039;iso&#039;&#039;&#039; file can be dd&#039;ed directly onto a USB drive to make it bootable, the Windows &#039;&#039;&#039;iso&#039;&#039;&#039;s don&#039;t come with this luxury. There are lots of methods to make bootable USB things from iso files out there, but the only thing most of them have in common, is that they generally don&#039;t work.&lt;br /&gt;
&lt;br /&gt;
===== WoeUSB =====&lt;br /&gt;
&lt;br /&gt;
After hours of swearing, it&#039;s nice to come across software like [https://github.com/slacka/WoeUSB WoeUSB]. It may not be perfect, it relies on a bunch of GUI stuff you&#039;ll never need and so on, but it &#039;&#039;&#039;&#039;&#039;works&#039;&#039;&#039;&#039;&#039;, and that&#039;s the important part! Just clone the repo and RTFM and it&#039;s all nice. It&#039;s slow, but hell, getting a windows machine and/or an optical drive might be slower.&lt;br /&gt;
&lt;br /&gt;
WoeUSB does nothing fancy, but it &#039;&#039;&#039;does&#039;&#039;&#039; work. It will create a filesystem, FAT32 or NTFS (better use NTFS, FAT32 has its limits). It creates normal filesystems and so on. Just make sure to copy in the BIOS update file, usually an exe file, to run when Windows is up and running.&lt;br /&gt;
&lt;br /&gt;
===== Install BIOS =====&lt;br /&gt;
&lt;br /&gt;
Boot on the Windows USB thing and choose &#039;repair computer&#039; and then &#039;command prompt&#039;. Find the install file, and if you&#039;re lucky, you&#039;ll find it needs a 32bit OS, just like I did. Since the 64bit version doesn&#039;t include 32bit compatibility in the installer, revert to downloading the 32bit version of windows and start over. Pray to your favourite god(s) not to get across such machines again - it might help.&lt;br /&gt;
&lt;br /&gt;
= 3D printer stuff =&lt;br /&gt;
&lt;br /&gt;
== Hydrophilic filament ==&lt;br /&gt;
&lt;br /&gt;
Most popular filament types, including PLA, PETG, PP or PA (Polyamide, normally known as Nylon) and virtualy any filament type named [https://www.matterhackers.com/news/filament-and-water poly-something] (and thus with an acronym of P-something) are hydrophilic (also (somewhat incorrectly) called hydroscopic), meaning so long they&#039;re dryer than the atmosphere around them, they&#039;ll do their best to suck out the atmosphere&#039;s humidity. This is why most filament are shrink-wrapped with a small bag of silica gel in it. If such filament is exposed for normal humid air for some time, it&#039;ll become very hard to use. Most of my experience is with PLA, which can handle a bit (depending on make), but still not a lot. With PLA, if you end up with prints where the filament seems not to stick, it may help with a higher temperature. Otherwise, the filament must be [https://all3dp.com/2/how-to-dry-filament-pla-abs-and-nylon/ baked]. If you don&#039;t want to use your oven, try something like a [https://www.jula.no/catalog/hjem-og-husholdning/kjokkenmaskiner/mattilberedningsapparater/frukt-sopptorker/frukt-sopptorker-001641/#tab02 fruit and mushroom dryer]. Then get a good, sealble plastic box and add something like half a kilogram of [https://www.ebay.com/sch/sis.html?_nkw=1KG+Orange+Replacement+Desiccant+Indicating+Silica+Gel+Beads+for+Drawers%2C+Camera&amp;amp;_id=131938742628&amp;amp;&amp;amp;_trksid=p2057872.m2749.l2658 silica gel] to an old sock, tie it and put it in the your new dry box.&lt;br /&gt;
&lt;br /&gt;
Please note that ABS is hydrophobic, so you won&#039;t have to worry too much there. Also, remember that PA/Nylon is extremely hydrophilic. Even a couple of days in normal air humidity can ruin it completely and will require baking.&lt;br /&gt;
&lt;br /&gt;
== Upgrading the firmware on an Ender 3 ==&lt;br /&gt;
&lt;br /&gt;
This is about upgrading the firmware, and thus also flashing a bootloader to the Creality Ender 3 3D printer. Most of this is well documented on several place, like o [https://www.youtube.com/watch?v=fIl5X2ffdyo the video from Teaching tech] and elsewhere, but I&#039;ll just summarise some issues I had.&lt;br /&gt;
&lt;br /&gt;
=== Using an arduino Nano as a programmer ===&lt;br /&gt;
&lt;br /&gt;
The CR-10, Ender 3 and a few other printers from Creality come without a bootloader, so you&#039;ll need to flash one before upgrading the firmware. Well, strictly speakning, you don&#039;t need one, you can save those 8kB or so for other stuff and use a programmer to write the whole firmware, but then you&#039;ll need to wire up everything every time you want a new firmware, so in my world, you &#039;&#039;&#039;do&#039;&#039;&#039; need the bootloader, since it&#039;s easier. Note that some newer printers, like the CR-10S and possibly all newer ones, come with the bootloader already and thus won&#039;t need another.&lt;br /&gt;
&lt;br /&gt;
To install a bootloader, you&#039;ll need a programmer, and I didn&#039;t have one available. Having some el-cheapo china-copies of Ardinos around, I read I could use one and tried so. Although the docs mostly mention the Uno etc, it&#039;s just as simple with the Nano copy.&lt;br /&gt;
&lt;br /&gt;
So, grab an arduino, plug it to your machine with an USB cable, and, using the Arduino IDE, use the ArduinoISP sketch there (found under Examples) to burn the software needed for the arduino to work as a programmer. When this is done, connect a 10µF capacitor between RST and GND to stop it from resetting when used as a programmer. Connect the MOSI, MISO and SCK pins from the ICSP block (that little isolated 6-pin block on top of the ardu). See [https://www.arduino.cc/en/Tutorial/ArduinoISP here] for a pinout. Then find Vcc and GND either onthe ICSP block or elsewhere. Some sites say that on some boards you shouldn&#039;t use the pins on the ICSP block for this. I doubt it matters, though. Then connect another jumper wire from pin 10 on the ardu to work as the reset pin outwards to the chip being programmed (that is, on the printer). The ICSP jumper block pin layout is the same on the printer and on the ardu, and probably elsewhere. Sometimes [https://xkcd.com/927/ standardisation] actually works…&lt;br /&gt;
&lt;br /&gt;
See https://cloud.karlsbakk.net/index.php/s/zw48YJjzaf8Rc2F for a pic with the ardu (this wiki is broken atm, will fix it later)&lt;br /&gt;
&lt;br /&gt;
== Flashing the printer ==&lt;br /&gt;
&lt;br /&gt;
When the boot loader is in place, possibly after some wierd errors from during the process, the screen on the 3d printer will go blank and it&#039;ll behave like being bricked. This is ok. Now disconnect the wires and connect the USB cable between computer and printer, download the [https://www.th3dstudio.com/knowledgebase/th3d-unified-firmware-package/ TH3D unified firmware] and configure it for your particular needs. The video mentioned above describes this well. After flashing the new firmware, you&#039;ll probably get some timeouts and errors, since apparently it resets the printer after giving it the new firmware, but without notifying the flashing software of it doing so. If this happens, hold your breath and reboot the printer and check its tiny monitor - it should work. If it doesn&#039;t work, try to flash it again, and if that doesn&#039;t work, try flashing the programmer again yet another time, just for kicks.&lt;br /&gt;
&lt;br /&gt;
PS: I tried enabling &#039;&#039;&#039;MANUAL_MESH_LEVELING&#039;&#039;&#039;, which in the code says that &#039;&#039;If used with a 1284P board the bootscreen will be disabled to save space&#039;&#039;. This effectively disabled the whole thing, and apparently may be making the firmware image a wee bit too large for it to fit the 1284P on the ender. It works well without it, though.&lt;br /&gt;
&lt;br /&gt;
== And then… ==&lt;br /&gt;
&lt;br /&gt;
With the new firmware in place, the printer should work as before, although with thermal runaway protection to better avoid fires in case the shit hits the fan, and to allow for things like autolevelling. With any luck, [https://www.precisionpiezo.co.uk/ this thing] may be ready for use by the time you read this - it surely looks nice!&lt;br /&gt;
&lt;br /&gt;
roy&lt;/div&gt;</summary>
		<author><name>Roy</name></author>
	</entry>
	<entry>
		<id>https://wiki.malinux.no/index.php?title=3D_printer_filaments_and_temperatures&amp;diff=146</id>
		<title>3D printer filaments and temperatures</title>
		<link rel="alternate" type="text/html" href="https://wiki.malinux.no/index.php?title=3D_printer_filaments_and_temperatures&amp;diff=146"/>
		<updated>2019-12-31T10:39:19Z</updated>

		<summary type="html">&lt;p&gt;Roy: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Roy&#039;s little table over filament types tested and concluded. This will hopefully grow over time.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!colspan=&amp;quot;6&amp;quot;|Filament types&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;Make&#039;&#039;&#039;&lt;br /&gt;
|&#039;&#039;&#039;Material&#039;&#039;&#039;&lt;br /&gt;
|&#039;&#039;&#039;Colour&#039;&#039;&#039;&lt;br /&gt;
|&#039;&#039;&#039;Type&#039;&#039;&#039;&lt;br /&gt;
|&#039;&#039;&#039;°C&#039;&#039;&#039;&lt;br /&gt;
|&#039;&#039;&#039;Comment&#039;&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
|3DNet&lt;br /&gt;
|PETG&lt;br /&gt;
|&lt;br /&gt;
|&lt;br /&gt;
|235&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
|3DNet&lt;br /&gt;
|PLA&lt;br /&gt;
|&lt;br /&gt;
|&lt;br /&gt;
|215&lt;br /&gt;
|Works well from around 200&lt;br /&gt;
|-&lt;br /&gt;
|3DNet&lt;br /&gt;
|PP&lt;br /&gt;
|Brown&lt;br /&gt;
|Wood&lt;br /&gt;
|215&lt;br /&gt;
|Higher temperature results in darker finish colour&lt;br /&gt;
|-&lt;br /&gt;
|Clas Ohlson&lt;br /&gt;
|PETG&lt;br /&gt;
|Black&lt;br /&gt;
|&lt;br /&gt;
|235&lt;br /&gt;
|Might be better with even higher temperature&lt;br /&gt;
|-&lt;br /&gt;
|Clas Ohlson&lt;br /&gt;
|PETG&lt;br /&gt;
|White&lt;br /&gt;
|&lt;br /&gt;
|240&lt;br /&gt;
|&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Roy</name></author>
	</entry>
	<entry>
		<id>https://wiki.malinux.no/index.php?title=3D_printer_filaments_and_temperatures&amp;diff=141</id>
		<title>3D printer filaments and temperatures</title>
		<link rel="alternate" type="text/html" href="https://wiki.malinux.no/index.php?title=3D_printer_filaments_and_temperatures&amp;diff=141"/>
		<updated>2019-12-29T15:26:56Z</updated>

		<summary type="html">&lt;p&gt;Roy: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Roy&#039;s little table over filament types tested and concluded. This will hopefully grow over time.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!colspan=&amp;quot;6&amp;quot;|Filament types&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;Make&#039;&#039;&#039;&lt;br /&gt;
|&#039;&#039;&#039;Material&#039;&#039;&#039;&lt;br /&gt;
|&#039;&#039;&#039;Colour&#039;&#039;&#039;&lt;br /&gt;
|&#039;&#039;&#039;Type&#039;&#039;&#039;&lt;br /&gt;
|&#039;&#039;&#039;°C&#039;&#039;&#039;&lt;br /&gt;
|&#039;&#039;&#039;Comment&#039;&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
|3DNet&lt;br /&gt;
|PETG&lt;br /&gt;
|&lt;br /&gt;
|&lt;br /&gt;
|235&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
|3DNet&lt;br /&gt;
|PLA&lt;br /&gt;
|&lt;br /&gt;
|&lt;br /&gt;
|200&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
|3DNet&lt;br /&gt;
|PP&lt;br /&gt;
|Brown&lt;br /&gt;
|Wood&lt;br /&gt;
|215&lt;br /&gt;
|Higher temperature results in darker finish colour&lt;br /&gt;
|-&lt;br /&gt;
|Clas Ohlson&lt;br /&gt;
|PETG&lt;br /&gt;
|Black&lt;br /&gt;
|&lt;br /&gt;
|235&lt;br /&gt;
|Might be better with even higher temperature&lt;br /&gt;
|-&lt;br /&gt;
|Clas Ohlson&lt;br /&gt;
|PETG&lt;br /&gt;
|White&lt;br /&gt;
|&lt;br /&gt;
|240&lt;br /&gt;
|&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Roy</name></author>
	</entry>
	<entry>
		<id>https://wiki.malinux.no/index.php?title=3D_printer_filaments_and_temperatures&amp;diff=140</id>
		<title>3D printer filaments and temperatures</title>
		<link rel="alternate" type="text/html" href="https://wiki.malinux.no/index.php?title=3D_printer_filaments_and_temperatures&amp;diff=140"/>
		<updated>2019-12-29T15:25:21Z</updated>

		<summary type="html">&lt;p&gt;Roy: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!colspan=&amp;quot;6&amp;quot;|Filament types&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;Make&#039;&#039;&#039;&lt;br /&gt;
|&#039;&#039;&#039;Material&#039;&#039;&#039;&lt;br /&gt;
|&#039;&#039;&#039;Colour&#039;&#039;&#039;&lt;br /&gt;
|&#039;&#039;&#039;Type&#039;&#039;&#039;&lt;br /&gt;
|&#039;&#039;&#039;°C&#039;&#039;&#039;&lt;br /&gt;
|&#039;&#039;&#039;Comment&#039;&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
|3DNet&lt;br /&gt;
|PETG&lt;br /&gt;
|&lt;br /&gt;
|&lt;br /&gt;
|235&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
|3DNet&lt;br /&gt;
|PLA&lt;br /&gt;
|&lt;br /&gt;
|&lt;br /&gt;
|200&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
|3DNet&lt;br /&gt;
|PP&lt;br /&gt;
|Brown&lt;br /&gt;
|Wood&lt;br /&gt;
|215&lt;br /&gt;
|Higher temperature results in darker finish colour&lt;br /&gt;
|-&lt;br /&gt;
|Clas Ohlson&lt;br /&gt;
|PETG&lt;br /&gt;
|Black&lt;br /&gt;
|&lt;br /&gt;
|235&lt;br /&gt;
|Might be better with even higher temperature&lt;br /&gt;
|-&lt;br /&gt;
|Clas Ohlson&lt;br /&gt;
|PETG&lt;br /&gt;
|White&lt;br /&gt;
|&lt;br /&gt;
|240&lt;br /&gt;
|&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Roy</name></author>
	</entry>
	<entry>
		<id>https://wiki.malinux.no/index.php?title=3D_printer_filaments_and_temperatures&amp;diff=137</id>
		<title>3D printer filaments and temperatures</title>
		<link rel="alternate" type="text/html" href="https://wiki.malinux.no/index.php?title=3D_printer_filaments_and_temperatures&amp;diff=137"/>
		<updated>2019-12-29T13:52:42Z</updated>

		<summary type="html">&lt;p&gt;Roy: Created page with &amp;quot;{| class=&amp;quot;wikitable&amp;quot; !colspan=&amp;quot;6&amp;quot;|Filament types |- |Clas Ohlson |PETG |Svart |235 |- |Clas Ohlson |PETG |Hvit |240 |- |3DNet |PETG | |235 |- |3DNet |PLA | |200 |}&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!colspan=&amp;quot;6&amp;quot;|Filament types&lt;br /&gt;
|-&lt;br /&gt;
|Clas Ohlson&lt;br /&gt;
|PETG&lt;br /&gt;
|Svart&lt;br /&gt;
|235&lt;br /&gt;
|-&lt;br /&gt;
|Clas Ohlson&lt;br /&gt;
|PETG&lt;br /&gt;
|Hvit&lt;br /&gt;
|240&lt;br /&gt;
|-&lt;br /&gt;
|3DNet&lt;br /&gt;
|PETG&lt;br /&gt;
|&lt;br /&gt;
|235&lt;br /&gt;
|-&lt;br /&gt;
|3DNet&lt;br /&gt;
|PLA&lt;br /&gt;
|&lt;br /&gt;
|200&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Roy</name></author>
	</entry>
	<entry>
		<id>https://wiki.malinux.no/index.php?title=Roy%27s_notes&amp;diff=136</id>
		<title>Roy&#039;s notes</title>
		<link rel="alternate" type="text/html" href="https://wiki.malinux.no/index.php?title=Roy%27s_notes&amp;diff=136"/>
		<updated>2019-12-28T00:26:10Z</updated>

		<summary type="html">&lt;p&gt;Roy: /* Rename system VG */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= LVM, md and friends =&lt;br /&gt;
&lt;br /&gt;
== Linux&#039; Logical Volume Manager (LVM) ==&lt;br /&gt;
&lt;br /&gt;
=== LVM in general ===&lt;br /&gt;
&lt;br /&gt;
LVM is designed to be an abstraction layer on top of physical drives or RAID, typically [https://raid.wiki.kernel.org/index.php/RAID_setup mdraid] or [https://help.ubuntu.com/community/FakeRaidHowto fakeraid]. Keep in mind that fakeraid should be avoided unless you really need it, like in conjunction with dual-booting linux and windows on fakeraid. LVM broadly consists of three elements, the &amp;quot;physical&amp;quot; devices (PV), the volume group (VG) and the logical volume (LV). There can be multiple PVs, VGs and LVs, depending on requirement. More about this below. All commands are given as examples, and all of them can be fine-tuned using extra flags in need of so. In my experience, the defaults work well for most usecases.&lt;br /&gt;
&lt;br /&gt;
I&#039;m mentioning filesystem below too. Where I write ext4, the samme applies to ext2 and ext3.&lt;br /&gt;
&lt;br /&gt;
==== Create a PV ====&lt;br /&gt;
&lt;br /&gt;
A PV is the &amp;quot;physical&amp;quot; parts. This does not need to be a physical disk, but can also be another RAID, be it an mdraid, fakeraid, hardware raid, a virtual disk on a SAN or otherwisee or a partition on one of those. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#  These add three PVs, one on a drive (or hardware raid) and another two on mdraids.&lt;br /&gt;
pvcreate /dev/sdb&lt;br /&gt;
pvcreate /dev/md1 /dev/md2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For more information about pvcreate, see [https://linux.die.net/man/8/pvcreate the manual].&lt;br /&gt;
&lt;br /&gt;
==== Create a VG ====&lt;br /&gt;
&lt;br /&gt;
The volume group consists of one or more PVs grouped together on which LVs can be placed. If several PVs are grouped in a VG, it&#039;s generally a good idea to make sure these PVs have some sort of redundancy, as in mdraid/fakeraid or hwraid. Otherwise it will be like using a [https://en.wikipedia.org/wiki/RAID RAID-0] with a single point of failure on each of the independant drives. LVM has [https://unix.stackexchange.com/questions/150644/raiding-with-lvm-vs-mdraid-pros-and-cons  RAID code in it] as well, so you can use that. I haven&#039;t done so myself, as I generally stick to mraid. The reason is mdraid is, in my opinion older and more stable and has more users (meaning bugs are reported and fixed faster whenever they are found). That said, I beleive the actual RAID code used in LVM RAID are the same function calls as for mdraid, so it may not be much of a difference. I still stick with mdraid. To create a VG, run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create volume group my_vg&lt;br /&gt;
vgcreate my_vg /dev/md1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that if vgcreate is run with a PV (as /dev/md1 above) that is not defined as a PV (like above), this is done implicitly, so if you don&#039;t need any special flags to pvcreate, you can simply skip it and let vgcreate do that for you.&lt;br /&gt;
&lt;br /&gt;
==== Create an LV ====&lt;br /&gt;
&lt;br /&gt;
LVs can be compared to partitions, somehow, since they are bounderies of a fraction or all of that of a VG. The difference between them and a partition, however, is that they can be grown or shrunk easily and also moved around between PVs without downtime. This flexibility makes them superiour to partitions as your system can be changed without users noticing it. By default, an LV is alloated &amp;quot;thickly&amp;quot;, meaning all the data given to it, is allocated from the VG and thus the PV. The following makes a 100GB LV named &amp;quot;thicklv&amp;quot;. When making an LV, I usually allocate what&#039;s needed plus some more, but not everything, just to make sure it&#039;s space available for growth on any of the LVs on the VG, or new LVs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a thick provisioned LV named thicklv on the VG my_vg&lt;br /&gt;
lvcreate -n thicklv -L 100G my_vg&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After the LV is created, a filesystem can be placed on it unless it is meant to be used directly. The application for direct use include swap space, VM storage and certain database systems. Most of these will, however, work on filesystems too, although my testing has shown that on swap space, there is a significant performance gain for using dedicated storage without a filesystem. As for filesystems, most Linux users use either ext4 or xfs. Personally, I generally use XFS these days. See my notes below on filesystem choice.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a filesystem on the LV - this could have been mkfs -t ext4 or whatever filesystem you choose&lt;br /&gt;
mkfs -t xfs /dev/my_vg/thicklv&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then just edit /etc/fstab with correct data and run mount -a, and you should be all set.&lt;br /&gt;
&lt;br /&gt;
==== Create LVM cache ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
lvcreate -L 1G -n _cache_meta data /dev/md1&lt;br /&gt;
&lt;br /&gt;
lvcreate -l100%FREE -n _cache data /dev/md1&lt;br /&gt;
&lt;br /&gt;
# Some would want --cachemode writeback, but seriously, I wouldn&#039;t recommend it. Metadata or data can be easily corrupted in case of failure.&lt;br /&gt;
lvconvert --type cache-pool --cachemode writethrough --poolmetadata data/_cache_meta data/_cache&lt;br /&gt;
&lt;br /&gt;
lvconvert --type cache --cachepool data/_cache data/data&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Disabling LVM cache ====&lt;br /&gt;
&lt;br /&gt;
If you for some reason want to disable caching, this will do it cleanly and remove the LVs earlier created for caching the main device.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
lvconvert --uncache data/data&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Growing devices ====&lt;br /&gt;
&lt;br /&gt;
LVM objects can be grown and shrunk. If a PV resides on a RAID where a new drive has been added or otherwise grown, or on a partition or virtual disk that has been extended, the PV must be updated to reflect these changes. The following command will grow the PV to the maximum available on the underlying storage. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Resize the PV /dev/md (not the RAID, only the PV on the RAID) to its full size&lt;br /&gt;
pvresize /dev/md1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If a new PV is added, the VG can be grown to add the space on that in addition to what&#039;s there already. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Extend my_vg to include md2 and its space&lt;br /&gt;
vgextend my_vg /dev/md2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
With more space available in the VG, the LV can now be extended. Let&#039;s add another 50GB to it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Extend thicklv - add 50GB. If you know you won&#039;t need the space anywhere else, you may want to&lt;br /&gt;
# lvresize -l+100%FREE instead. Keep in mind the difference between -l (extents) and -L (bytes)&lt;br /&gt;
lvresize -L +50G my_vg/thicklv&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After the LV has grown, run &#039;&#039;xfs_growfs&#039;&#039; (xfs) or &#039;&#039;resize2fs&#039;&#039; (ext4) to make use of the new data.&lt;br /&gt;
&lt;br /&gt;
==== Rename system VG ====&lt;br /&gt;
&lt;br /&gt;
Some distros create VG names like those-from-a-sysadmin-with-a-well-developed-paranoia-not-to-hit-a-duplicate. Debian, for instance, uses names like &amp;quot;my-full-hostname-vg&amp;quot;. Personally, I don&#039;t like these, since if I were to move a disk or vdisk around to somewhere else, I&#039;d make sure not to add a disk named &#039;sys&#039; to an existing system. If you do, most distros will refuse to use the VGs with duplicate names, resulting in the OS not booting until either one is specified by its UUID or just one removed. As I&#039;m aware of this, I stick to the super-risky thing of all system VGs named &#039;sys&#039; and so on.&lt;br /&gt;
&lt;br /&gt;
If you do this, keep in mind that it may blow up your computer and take your girl- or boyfriend with it or even make either of them pregnant, allowing Trump to rule your life and generally make things suck. You&#039;re on your own!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Rename the VG&lt;br /&gt;
vgrename my-full-hostname-vg sys&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, in /boot/grub/grub.cfg, change the old lv path from something like &#039;/dev/mapper/debian--stretch--machine--vg-root&#039; to your new and fancy &#039;/dev/sys/root. Likewise, in /etc/fstab, change occurences of &#039;/dev/mapper/debian--stretch--machine--vg-&#039; (or similar) with &#039;/dev/sys/&#039;. Here, this was like this - the old ones commented out.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;fstab&amp;quot;&amp;gt;&lt;br /&gt;
#/dev/mapper/debian--stretch--box--vg-root      /               ext4            errors=remount-ro,discard       0       1&lt;br /&gt;
/dev/sys/root                                   /               ext4            errors=remount-ro,discard       0       1&lt;br /&gt;
# /boot was on /dev/vda1 during installation&lt;br /&gt;
UUID=myverylonguuidwithatonofgoodinfoinit       /boot           ext2            defaults                        0       2&lt;br /&gt;
#/dev/mapper/debian--stretch--box--vg-swap_1    none            swap            sw                              0       0&lt;br /&gt;
/dev/sys/swap_1                                 none            swap            sw                              0       0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Update /etc/initramfs-tools/conf.d/resume with similar data for swap.&lt;br /&gt;
&lt;br /&gt;
You might want to run &#039;update-initramfs -u -k all&#039; after this, but I&#039;m not sure if it&#039;s needed.&lt;br /&gt;
&lt;br /&gt;
Now, pray to the nearest god(s) and give it a reboot and it should (probably) work.&lt;br /&gt;
&lt;br /&gt;
After reboot, run &#039;&#039;&#039;swapoff -a&#039;&#039;&#039;, then &#039;&#039;&#039;mkswap /dev/sys/swap_1&#039;&#039;&#039; (or whatever it&#039;s called on your system) and &#039;&#039;&#039;swapon -a&#039;&#039;&#039; again. You may want to give it another reboot or two for kicks, but it should work well even without that.&lt;br /&gt;
&lt;br /&gt;
=== Migration tools ===&lt;br /&gt;
&lt;br /&gt;
At times, storage regimes change, new storage is added and sometimes it&#039;s not easy to migrate with the current hardware or its support systems. Once I had to migrate a 45TiB fileserver from one storage system to another, preferably without downtime. The server originally had three 15TiB PVs of which two were full and the third half full. I resorted to using [https://linux.die.net/man/8/pvmove pvmove] to just move the data on the PVs in use to a new PV. We started out with creating a new 50TiB PV, sde, and then to pvmove.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Attach /dev/sde to the VG my_vg&lt;br /&gt;
vgextend my_vg /dev/sde&lt;br /&gt;
&lt;br /&gt;
# Move the contents from /dev/sdb over to /dev/sde block by block. If a target is not given in pvmove,&lt;br /&gt;
# the contents of the source (sdb here) will be put somewhere else in the pool.&lt;br /&gt;
pvmove /dev/sdb /dev/sde&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This took a while (as in a week or so) - the pvmove command uses old code and logic (or at least did that when I migrated this in November 2016), but it affected performance on the server very little, so users didn&#039;t notice. After the first PV was migrated, I continued with the other two, one after the other, and after a month or so, it was migrated. We used this on a number of large fileservers, and it worked flawlessly. Before doing the production servers I also tried interrupting pvmove in various ways, including hard resets, and it just kept on after the reboot.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;NOTE:&#039;&#039;&#039;&#039;&#039; &#039;&#039;Even though it worked well for us, &#039;&#039;&#039;always&#039;&#039;&#039; keep a good backup before doing this. Things may go wrong, and without a good backup, you may be looking for a hard-to-find new job the next morning&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
==== mdadm workarounds ====&lt;br /&gt;
&lt;br /&gt;
===== Migrate from a mirror (raid-1) to raid-10 =====&lt;br /&gt;
&lt;br /&gt;
Create a mirror&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sdb /dev/sdc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
LVM (pv/vg/lv) on md0 (see above), put a filesystem on the lv and fill it with some data.&lt;br /&gt;
&lt;br /&gt;
Now, some months later, you want to change this to raid-10 to allow for the same amount of redundancy, but to allow more disks into the system.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mdadm --grow /dev/md0 --level=10&lt;br /&gt;
mdadm: Impossibly level change request for RAID1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So - no - doesn&#039;t work. But - we&#039;re on &lt;br /&gt;
&lt;br /&gt;
Since we&#039;re on lvm already, this&#039;ll be easy. If you&#039;re using filesystems directly on partitions, you can do this the same way, but without the pvmove part, using rsync or whateever you like instead. I&#039;d recommend using lvm for for the new raid, which should be rather obvious from this article. Now plug in a new drive and create a new raid10 on that one. If you two new drives, install both. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# change &amp;quot;missing&amp;quot; to the other device name if you installed two new drives&lt;br /&gt;
mdadm --create /dev/md1 --level=10 --raid-devices=2 /dev/vdd missing&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, as described above, just vgextend the vg, adding the new raid and run pvmove to move the data from the old pv (residing on the old raid1) to the new pv (on raid10). Afte rpvmove is finished (which may take awile, see above), just&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
vgreduce raidtest /dev/md0&lt;br /&gt;
pvremove /dev/md0&lt;br /&gt;
mdadm --stop /dev/md0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
…and your disk is free to be added to the new array. If the new raid is running in degraded mode (if you created it with just one drive), better don&#039;t wait too long, since you don&#039;t have redundancy. Just mdadm --add the devs.&lt;br /&gt;
&lt;br /&gt;
If you now have /dev/mdstat telling you your raid10 is active and have three drives, of which one is a spare, it should look something like this&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5] [raid4] [raid10]&lt;br /&gt;
md1 : active raid10 vdc[3](S) vdb[2] vdd[0]&lt;br /&gt;
      8380416 blocks super 1.2 2 near-copies [2/2] [UU]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Just mdadm --grow --raid-devices=3 /dev/md1&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;RAID section is not complete. I&#039;ll write more on migraing from raid10 to raid6 later. It&#039;s not straight forward, but easier than this one :)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== Thin provisioned LVs ===&lt;br /&gt;
&lt;br /&gt;
Thin provisioning on LVM is a method used for not allocating all the space given to an LV. For instance, if you have a 1TB VG and want to give an LV 500GB, although it currently only uses a fraction of that, a thin lv can be a good alternative. This will allow for adding a limit to how much it can use, but also to let it grow dynamically without manual work by the sysadmin. Thin provisioning adds another layer of abstaction by creating a special LV as a &#039;&#039;thin pool&#039;&#039; from which data is allocated to the &#039;&#039;thin volume(s)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== Create a thin pool ====&lt;br /&gt;
&lt;br /&gt;
Allocate 1TB to the thin pool to be used for thinly provisioned LVs. Keep in mind that the space allocated to the thin pool is in fact thick provisioned. Only the volumes put on &#039;&#039;thinpool&#039;&#039; are thin provisioned. This will create two hidden LVs, one for data and one for metadata. Normally the defaults will do, but check the manual if the data doesn&#039;t match the usual patterns (such as billions of files, resulting in huge amounts of metadata). I &#039;&#039;beleive&#039;&#039; the metadata part should be resizable at a later time if needed, but I have not tested it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a pool for thin LVs. Keep in mind that the pool itself is not thin provisioned, only the volumes residing on it&lt;br /&gt;
lvcreate --size 1T --type thin-pool --thinpool thinpool my_vg&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Create a thin volume ====&lt;br /&gt;
&lt;br /&gt;
You have the thinpool, now put a thin volume on it. It will allocate some space for metadata, but probably not much (a few megs, perhaps).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Now, create a volume with a virtual (-V) size of half a terabyte named thin_pool, but using the thinpool (-T) named thin_pool for storage&lt;br /&gt;
lvcreate -V 500G -T my_vg/thin_pool --name thinvol&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The new volume&#039;s device name will be /dev/thinvol. Now, create a filesystem on it, add to fstab and mount it. The &#039;&#039;&#039;df&#039;&#039;&#039; command will return available space according to the virtual size (-V), while lvs will show how much data is actually used on each of the thinly provisioned volumes.&lt;br /&gt;
&lt;br /&gt;
== Filesystem dilemmas ==&lt;br /&gt;
&lt;br /&gt;
=== XFS or ext4 or something else ===&lt;br /&gt;
The choice of filesystem varies for your use. Distros such as RHEL/CentOS has moved to XFS by default from v7. Debian/Ubuntu still sticks to ext4, like most other. I&#039;ll discuss my thoughts below on ext4 vs XFS and leave the other filesystems for later.&lt;br /&gt;
&lt;br /&gt;
==== ext4 ====&lt;br /&gt;
ext4 is probably the most used filesystem on linux as of writing. It&#039;s rock stable and has been extended by a lot of extensions since the original ext2. It still retains backward compatibility, being able to mount and fsck ext2 and ext3 with the ext4 driver. However, it doesn&#039;t handle large filesystems very well. If a filesystem is created for &amp;lt;16TiB, it cannot be grown to anything larger than 16TiB. This may have changed lately, though. One other issue is handling errors. If a large filesystem (say 10TiB) is damaged, an fsck may take several hours, leading to long downtime.&lt;br /&gt;
&lt;br /&gt;
==== XFS ====&lt;br /&gt;
XFS, originally developed by SGI some time in the bronze age, but has been worked on heavily after that. RHEL and Centos version 7 and forward, uses XFS as the default filesystem. It is quick, it scales well, but it lacks at least two things ext4 has. It cannot be shrunk (not that you normally need that, but nice if you have a typo or you need to change things). Also, it doesn&#039;t allow for automatic fsck on bootup. If something is messed up on the filesystem, you&#039;ll have to login as root on the console (not ssh), which might be an issue on some systems. The fsck equivalent, xfs_repair, is a *lot* faster than ext4&#039;s fsck, though.&lt;br /&gt;
&lt;br /&gt;
==== ZFS ====&lt;br /&gt;
ZFS is like a combination of RAID, LVM and a filesystem, supporting full checksumming, auto-healing (given sufficient redundancy), compression, encryption, replication, deduplication (if you&#039;re brave and have a &#039;&#039;ton&#039;&#039; of memory) and a lot more. It&#039;s a separate chapter and needs a lot more talk than paragraph here.&lt;br /&gt;
&lt;br /&gt;
== Low level disk handling ==&lt;br /&gt;
&lt;br /&gt;
This section is for low-level handling of disks, regardless of storage system elsewhere. These apply to mdraid, lvmraid and zfs and possibly other solutions, with the exception of individual drives on hwraid (and maybe fakeraid), since there, the drives are hidden from Linux (or whatever OS).&lt;br /&gt;
&lt;br /&gt;
=== S.M.A.R.T. and slow drives ===&lt;br /&gt;
Modern (that is, from about 1990 or later) have S.M.A.R.T. (or just smart, since it&#039;s easier to type) monitoring built in, meaning the disk&#039;s controller is monitoring itself. This is handy and will ideally tell you in advance that a drive is flakey or dying. Modern (2010+) smart monitoring is more or less the same. It can be trusted about 50% of the time. Usually, if smart detects an error, it&#039;s a real error. I don&#039;t think I&#039;ve seen it reporting a false positive, but others may know better. &lt;br /&gt;
&lt;br /&gt;
==== smartmontools ====&lt;br /&gt;
First, install smartmontool and run smartclt -H /dev/yourdisk (/dev/sda or something) to get a health report. Then perhaps run smartctl -a /dev/yourdisk and look for &#039;current pending sectors&#039; This should be zero. Also check the temperature, which normally should be much above 50.&lt;br /&gt;
&lt;br /&gt;
==== single, slow drive ====&lt;br /&gt;
What may happen, is smart not seeing anything and life goes on like before, only slower and less prouductive, without telling anyone. If you stubler over this issue, you&#039;ll probably see it during a large rsync/zfs send/receive or a resync/rebuild/resilver of the raid/zpool. During this, it feels like everything is slow and your RAID has turned into a RAIF (redundant array of inexpensive floppies). To check if you have a single drive messing up it all, check with &#039;&#039;&#039;iostat -x 2&#039;&#039;&#039;, having 2 being the delay between each measurement. Interrupt it with ctrl+x. If there&#039;s a rougue drive there, it should stand out like sdg below&lt;br /&gt;
&lt;br /&gt;
 avg-cpu:  %user   %nice %system %iowait  %steal   %idle&lt;br /&gt;
            0.38    0.00    1.75    0.00    0.00   97.87&lt;br /&gt;
&lt;br /&gt;
 Device            r/s     w/s     rkB/s     wkB/s   rrqm/s   wrqm/s  %rrqm  %wrqm r_await w_await aqu-sz rareq-sz wareq-sz  svctm  %util&lt;br /&gt;
 sda              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdb              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdc              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdd              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sde              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdf              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdg              3.50    0.00   2352.00      0.00     0.00     0.00   0.00   0.00 14306.29    0.00  13.85   672.00     0.00 285.71 100.00&lt;br /&gt;
 sdh              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
&lt;br /&gt;
In ZFS land, you should be able to get similar data with &#039;&#039;&#039;zpool iostat -v &amp;lt;pool&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Now you know the bad drive (sdg), pull it from the raid with &#039;&#039;&#039;mdadm --fail /dev/mdX /dev/sdX&#039;&#039;&#039;. Now test the drive&#039;s performance manually, just simply:&lt;br /&gt;
&lt;br /&gt;
 # hdparm -t /dev/sdg&lt;br /&gt;
 &lt;br /&gt;
 /dev/sdg:&lt;br /&gt;
  Timing buffered disk reads:   2 MB in  5.37 seconds = 381.46 kB/sec&lt;br /&gt;
&lt;br /&gt;
Bingo - nothing you&#039;d want to keep. For a good drive, it should be something like 100-200MB/s&lt;br /&gt;
&lt;br /&gt;
PS: Keep in mind that you have a degraded RAID by now in case you had a spare waiting for things to happen.&lt;br /&gt;
&lt;br /&gt;
Try to replace the cable and/or try the disk on another port/controller. If the result from hdparm persists, it&#039;s probably a bad cable&lt;br /&gt;
&lt;br /&gt;
So, then, just psycially locate the drive, pull it out, take out the discs and magnets and recycle the rest.&lt;br /&gt;
&lt;br /&gt;
=== &amp;quot;Unplug&amp;quot; drive from system ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Find the device unit&#039;s number with something like&lt;br /&gt;
find /sys/bus/scsi/devices/*/block/ -name sdd&lt;br /&gt;
# returning /sys/bus/scsi/devices/3:0:0:0/block/sdd here, &lt;br /&gt;
# meaning 3:0:0:0 is the SCSI device we&#039;re looking for.&lt;br /&gt;
&lt;br /&gt;
# Given this is the correct device, and you want to &#039;unplug&#039; it, do so by&lt;br /&gt;
echo 1 &amp;gt; /sys/bus/scsi/devices/3:0:0:0/delete&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Rescan disk controllers ===&lt;br /&gt;
If a drive is added and for some reason doesn&#039;t get detected, or is removed by the command above, it can be rediscovered with a sysfs command to the scsi host to which it is connected. Since there may be quite a few of these, an easy way is to just scan them all and check the output of &#039;&#039;&#039;dmesg -T&#039;&#039;&#039; after running it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Make a list of controllers and send a rescan message to each of them. It won&#039;t do anything &lt;br /&gt;
# for those where nothing has changed, but it will show new drives where they have been added.&lt;br /&gt;
for host_scan in /sys/class/scsi_host/host*/scan&lt;br /&gt;
do&lt;br /&gt;
  echo &#039;- - -&#039; &amp;gt; $host_scan&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Fail injection with debugfs ===&lt;br /&gt;
[https://lxadm.com/Using_fault_injection https://lxadm.com/Using_fault_injection]&lt;br /&gt;
&lt;br /&gt;
== mdadm stuff ==&lt;br /&gt;
=== Spare pools ===&lt;br /&gt;
In the old itmes, mdadm supported only a dedicated spare per md device, so if working with a large set of drives (20? 40?), where you&#039;d want to setup more raid sets to increase redundancy, you&#039;d dedicate a spare to each of the raid sets. This has changed (some time ago?), so in these modern, heathen days, you can change mdadm.conf, usually placed under /etc/mdadm, and add &#039;spare-group=somegroup&#039; where &#039;somegroup&#039; is a string identifying the spare group. After doing this, run &#039;&#039;&#039;update-initramfs -u&#039;&#039;&#039; and reboot and add a spare to one of the raid sets in the spare group, and md will use that or those spares for all the raidsets in that group.&lt;br /&gt;
&lt;br /&gt;
As some pointed out on #linux-raid @ irc.freenode.net, this feature is very badly documented, but as far as I can see, it works well.&lt;br /&gt;
&lt;br /&gt;
==== Example config ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create two raidsets&lt;br /&gt;
&lt;br /&gt;
mdadm --create /dev/md1 --level=6 --raid-devices=6 /dev/vd[efghij]&lt;br /&gt;
mdadm --create /dev/md2 --level=6 --raid-devices=6 /dev/vd[klmnop]&lt;br /&gt;
&lt;br /&gt;
# get their UUID etc&lt;br /&gt;
&lt;br /&gt;
mdadm --detail --scan&lt;br /&gt;
ARRAY /dev/md/1 metadata=1.2 name=raidtest:1 UUID=1a8cbdcb:f4092350:348b6b80:c054d74c&lt;br /&gt;
ARRAY /dev/md/2 metadata=1.2 name=raidtest:2 UUID=894b1b7c:cb7eba70:917d6033:ea5afd2b&lt;br /&gt;
&lt;br /&gt;
# Put those lines into /etc/mdadm/mdadm.conf and and add the spare-group&lt;br /&gt;
&lt;br /&gt;
ARRAY /dev/md/1 metadata=1.2 name=raidtest:1 spare-group=raidtest UUID=1a8cbdcb:f4092350:348b6b80:c054d74c&lt;br /&gt;
ARRAY /dev/md/2 metadata=1.2 name=raidtest:2 spare-group=raidtest UUID=894b1b7c:cb7eba70:917d6033:ea5afd2b&lt;br /&gt;
&lt;br /&gt;
# update the initramfs and reboot&lt;br /&gt;
&lt;br /&gt;
update-initramfs -u&lt;br /&gt;
reboot&lt;br /&gt;
&lt;br /&gt;
# add a spare drive to one of the raids&lt;br /&gt;
&lt;br /&gt;
mdadm --add /dev/md1 /dev/vdq&lt;br /&gt;
&lt;br /&gt;
# fail a drive on the other raid&lt;br /&gt;
&lt;br /&gt;
mdadm --fail /dev/md2 /dev/vdn&lt;br /&gt;
&lt;br /&gt;
# check /proc/mdstat to see md2 rebuilding with the spare from md1&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Recovery ===&lt;br /&gt;
&lt;br /&gt;
The other day, I came across a problem a user had on #linux-raid@irc.freenode.net. He had an old Qnap NAS that had died and tried plugging the drives in to his Linux machine and got various errors. The two-drive RAID-1 did not come up as it should, &#039;&#039;&#039;dmesg&#039;&#039;&#039; was full of errors from one of the drives (both connected on USB) and so forth.&lt;br /&gt;
&lt;br /&gt;
We went on and started by taking down the machine and just connecting one of the drives. I had him check what was assembled with&lt;br /&gt;
&lt;br /&gt;
 cat /proc/mdstat&lt;br /&gt;
&lt;br /&gt;
That returned /proc/md127 assembled, but LVM didn&#039;t find anything. So running a manual scan&lt;br /&gt;
&lt;br /&gt;
 pvscan --cache /dev/md127&lt;br /&gt;
&lt;br /&gt;
This made linux find the PV, VG and a couple of LVs, but probably because the mdraid was degraded, the LVs were deactivated, according to &#039;&#039;&#039;lvscan&#039;&#039;&#039;. Activating the one with a filesystem manually&lt;br /&gt;
&lt;br /&gt;
 lvchange -a y /dev/&amp;lt;vg&amp;gt;/&amp;lt;lv&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Substitute &amp;lt;vg&amp;gt; and &amp;lt;lv&amp;gt; with the names listed by vgs and lvs.&lt;br /&gt;
&lt;br /&gt;
This worked, and the filesystem on /dev/&amp;lt;vg&amp;gt;/&amp;lt;lv&amp;gt; could be mounted correctly.&lt;br /&gt;
&lt;br /&gt;
== Tuning ==&lt;br /&gt;
&lt;br /&gt;
While trying to compare a 12-disk RAID (8TB disks) to a hwraid, mdraid was slower, so we did a few things to speed things up:&lt;br /&gt;
&lt;br /&gt;
While testing with [https://linux.die.net/man/1/fio fio], monitor /sys/block/md0/md/stripe_cache_active, and see if it&#039;s close to /sys/block/md0/md/stripe_cache_size. If it is, double the size of the latter&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
echo 4096 &amp;gt; /sys/block/md0/md/stripe_cache_size&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Continue until stripe_cache_active stabilises, and then you&#039;ve found the limit you&#039;ll need. You may want to double that for good measure. &lt;br /&gt;
&lt;br /&gt;
(to be continued)&lt;br /&gt;
&lt;br /&gt;
== Links ==&lt;br /&gt;
&lt;br /&gt;
Below are a few links with useful info&lt;br /&gt;
&lt;br /&gt;
* [https://raid.wiki.kernel.org/index.php/Irreversible_mdadm_failure_recovery Irreversible mdadm failure recovery]&lt;br /&gt;
&lt;br /&gt;
= ZFS =&lt;br /&gt;
&lt;br /&gt;
ZFS can do a lot of things most filesystems or volume managers can&#039;t. It checksums all data and metadata and so long that the system uses ECC enabled memory (RAM), it will have complete control over the whole data set, and when (not if) an error occurs, it&#039;ll fix the issue without even throwing a warning. To fix the issue, you&#039;ll obviously need sufficient redundancy (mirrors or RAIDzN). &lt;br /&gt;
&lt;br /&gt;
== ZFS send/receive between machines ==&lt;br /&gt;
&lt;br /&gt;
ZFS has a send/receive mechanism that allows for snapshots to be sent over the wire to a receiving end. This can be a full filesystem, or an incremental change since last send/reveive. In a WAN scenario, you&#039;ll probably want to use VPN for this. On a controlled network, sending in cleartext is also possible. You may as well use ssh, but keep in mind that ssh was never designed to be used as a fullblown vpn solution and is just too slow or the task with large amounts of data. You may, though, use mbuffer, if on a loal LAN.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Allow traffic from the sending IP in whatever firewall interface you&#039;re using (if you&#039;re using a firewall at all, that is)&lt;br /&gt;
ufw allow from x.x.x.x&lt;br /&gt;
# &lt;br /&gt;
# Start the receiver first. This listens on port 9090, has a 1GB buffer,&lt;br /&gt;
    and uses 128kb chunks (same as zfs):&lt;br /&gt;
&lt;br /&gt;
mbuffer -s 128k -m 1G -I 9090 | zfs receive data/filesystem&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To be continued one day… See [https://everycity.co.uk/alasdair/2010/07/using-mbuffer-to-speed-up-slow-zfs-send-zfs-receive/ this] for some more. I&#039;ll get back with details on it.&lt;br /&gt;
&lt;br /&gt;
= General Linux system control =&lt;br /&gt;
&lt;br /&gt;
== Add a new CPU (core) ==&lt;br /&gt;
&lt;br /&gt;
If working with virtual machines, adding a new core can be useful if the VM is slow and the load is multithreaded or multiprocess. To do this, add a new CPU in the hypervisor (be it KVM or VMware or Hyper-V or whatever). Some hypervisors, like VMware, will activate it automatically if open-vm-tools is installed. Please note that open-vm-tools is for VMware only. I don&#039;t know of any such thing for KVM or other hypervisors (although I beleive VirtualBox has its own set of tools, but not as a package). If this doesn&#039;t work, run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
echo 1 &amp;gt; /sys/devices/system/cpu/cpuX/online&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where X is the CPU number you want to add. You can &#039;cat /sys/devices/system/cpu/cpuX/online&#039; to check if it&#039;s online.&lt;br /&gt;
&lt;br /&gt;
= Mount partitions on a disk image =&lt;br /&gt;
&lt;br /&gt;
Sometimes you&#039;ll have a disk image, either from recovering a bad drive after hours (or days or weeks) of ddrescue, and sometimes you just have a disk image from a virtual machine where you want to mount the partitions inside the image. There are three main methods of doing this, which are more or less synonmous, but some easier than the other.&lt;br /&gt;
&lt;br /&gt;
== Basics ==&lt;br /&gt;
&lt;br /&gt;
A disk image is usually like a disk, consisting of either a large filesystem, a PV or a partition table with one or partitions onto which resides a filesystem, a pv, swap or something else. If it&#039;s partitioned, and you want your operating system to mount a filesystem or allow it to see whatever LVM stuff lies on it, you need to isolate the partitions. &lt;br /&gt;
&lt;br /&gt;
== Manual mapping ==&lt;br /&gt;
&lt;br /&gt;
In the oldern days, this was done manually, something like this&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
root@mymachine:~# fdisk -l /dev/vda&lt;br /&gt;
Disk /dev/vda: 25 GiB, 26843545600 bytes, 52428800 sectors&lt;br /&gt;
Units: sectors of 1 * 512 = 512 bytes&lt;br /&gt;
Sector size (logical/physical): 512 bytes / 512 bytes&lt;br /&gt;
I/O size (minimum/optimal): 512 bytes / 512 bytes&lt;br /&gt;
Disklabel type: dos&lt;br /&gt;
Disk identifier: 0xc37b7ea5&lt;br /&gt;
&lt;br /&gt;
Device     Boot    Start      End  Sectors  Size Id Type&lt;br /&gt;
/dev/vda1  *        2048 50333311 50331264   24G 83 Linux&lt;br /&gt;
/dev/vda2       50333312 52426369  2093058 1022M  5 Extended&lt;br /&gt;
/dev/vda5       50333314 52426369  2093056 1022M 82 Linux swap / Solaris&lt;br /&gt;
root@mymachine:~#&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To calculate the start and end of each partition, you just take the start sector and multiply it by the sector size (512 bytes here) and you have the offset in bytes. After this, it&#039;s merely an losetup -o &amp;lt;offset&amp;gt; /dev/loopX &amp;lt;nameofimagefile&amp;gt; and you have the partition mapped to your /dev/loopX (having X being something typically 0-255. After this, just mount it or run pvscan/vgscan/lvscan to probe whatever lvm config is there, and you should be able to mount it like any other filesystem.&lt;br /&gt;
&lt;br /&gt;
== kpartx ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;kpartx&#039;&#039;&#039; does the same as above, more or less, just without so much hassle. Most of it should be automatic and easy to deal with, except it may fail to disconnect the loopback devices sometimes, so you may have to &#039;&#039;&#039;losetup -d&#039;&#039;&#039; them manually. See the manual, &#039;&#039;&#039;kpartx (8)&#039;&#039;&#039;. Please note that &#039;&#039;&#039;partx&#039;&#039;&#039; works similarly and I&#039;d guess the authors of the two tools are arguing a lot of which one&#039;s the best.&lt;br /&gt;
&lt;br /&gt;
== guestmount ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;guestmount&#039;&#039;&#039; is something similar again, but also supports file formats like &#039;&#039;&#039;qcow2&#039;&#039;&#039; and possibly other, proprietary filesystems like &#039;&#039;&#039;vmdk&#039;&#039;&#039; and &#039;&#039;&#039;vdi&#039;&#039;&#039;, but don&#039;t take my word for it - I haven&#039;t tested. Again, see the manual or just read up on the description [http://ask.xmodulo.com/mount-qcow2-disk-image-linux.html?fbclid=IwAR3snTeZvGzp9PLdX11EQhCfOpux6I93CiJ3A2pUomkkRLly9Xo4851mkTY here]. It seems rather trivial.&lt;br /&gt;
&lt;br /&gt;
= Linux on laptops =&lt;br /&gt;
&lt;br /&gt;
== Wifi with HP EliteBook 725/745 on Ubuntu ==&lt;br /&gt;
&lt;br /&gt;
The HP EliteBook 725/745 and similar are equipped with a BCM4352 wifi chip. As with a lot of other stuff from Broadcom, this lacks an open hardware description, so thus no open driver exist. The proper fix, is to replace the NIC with something with an open driver, but again, this isn&#039;t always possible, so a binary driver exists. In ubuntu, run, somehow connect the machine to the internet and run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install bcmwl-kernel-source&lt;br /&gt;
sudo modprobe wl&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you can&#039;t connect the machine to the internet, download the needed packages on another machine and put it on some usb storage. These packages should suffice:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# apt-cache depends bcmwl-kernel-source&lt;br /&gt;
bcmwl-kernel-source&lt;br /&gt;
  Depends: dkms&lt;br /&gt;
  Depends: linux-libc-dev&lt;br /&gt;
  Depends: libc6-dev&lt;br /&gt;
  Conflicts: &amp;lt;bcmwl-modaliases&amp;gt;&lt;br /&gt;
  Replaces: &amp;lt;bcmwl-modaliases&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then install manually with &#039;&#039;&#039;dpkg -i file1.deb file2.deb&#039;&#039;&#039; etc&lt;br /&gt;
&lt;br /&gt;
After this, ip/ifconfig/iwconfig shouldd see the new wifi nic, probably &#039;&#039;&#039;wlan0&#039;&#039;&#039;, but due to a [https://bugs.launchpad.net/ubuntu/+source/broadcom-sta/+bug/1343151 old, ignored bug], you won&#039;t find any wifi networks. This is because the driver from Broadcom apparently does not support interrupt remapping, commonly used on x64 machines. To turn this off, change &#039;&#039;&#039;/etc/default/grub&#039;&#039;&#039; and change the line &#039;&#039;&#039;GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;quiet splash&amp;quot;&#039;&#039;&#039;, adding intremap=off to the end before the quote: &#039;&#039;&#039;GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;quiet splash intremap=off&amp;quot;&#039;&#039;&#039;. Save the file and run &#039;&#039;&#039;sudo update-grub&#039;&#039;&#039; and reboot. After this, wifi should work well.&lt;br /&gt;
&lt;br /&gt;
= 3D printer stuff =&lt;br /&gt;
&lt;br /&gt;
== Hydrophilic filament ==&lt;br /&gt;
&lt;br /&gt;
Most popular filament types, including PLA, PETG, PP or PA (Polyamide, normally known as Nylon) and virtualy any filament type named [https://www.matterhackers.com/news/filament-and-water poly-something] (and thus with an acronym of P-something) are hydrophilic (also (somewhat incorrectly) called hydroscopic), meaning so long they&#039;re dryer than the atmosphere around them, they&#039;ll do their best to suck out the atmosphere&#039;s humidity. This is why most filament are shrink-wrapped with a small bag of silica gel in it. If such filament is exposed for normal humid air for some time, it&#039;ll become very hard to use. Most of my experience is with PLA, which can handle a bit (depending on make), but still not a lot. With PLA, if you end up with prints where the filament seems not to stick, it may help with a higher temperature. Otherwise, the filament must be [https://all3dp.com/2/how-to-dry-filament-pla-abs-and-nylon/ baked]. If you don&#039;t want to use your oven, try something like a [https://www.jula.no/catalog/hjem-og-husholdning/kjokkenmaskiner/mattilberedningsapparater/frukt-sopptorker/frukt-sopptorker-001641/#tab02 fruit and mushroom dryer]. Then get a good, sealble plastic box and add something like half a kilogram of [https://www.ebay.com/sch/sis.html?_nkw=1KG+Orange+Replacement+Desiccant+Indicating+Silica+Gel+Beads+for+Drawers%2C+Camera&amp;amp;_id=131938742628&amp;amp;&amp;amp;_trksid=p2057872.m2749.l2658 silica gel] to an old sock, tie it and put it in the your new dry box.&lt;br /&gt;
&lt;br /&gt;
Please note that ABS is hydrophobic, so you won&#039;t have to worry too much there. Also, remember that PA/Nylon is extremely hydrophilic. Even a couple of days in normal air humidity can ruin it completely and will require baking.&lt;br /&gt;
&lt;br /&gt;
== Upgrading the firmware on an Ender 3 ==&lt;br /&gt;
&lt;br /&gt;
This is about upgrading the firmware, and thus also flashing a bootloader to the Creality Ender 3 3D printer. Most of this is well documented on several place, like o [https://www.youtube.com/watch?v=fIl5X2ffdyo the video from Teaching tech] and elsewhere, but I&#039;ll just summarise some issues I had.&lt;br /&gt;
&lt;br /&gt;
=== Using an arduino Nano as a programmer ===&lt;br /&gt;
&lt;br /&gt;
The CR-10, Ender 3 and a few other printers from Creality come without a bootloader, so you&#039;ll need to flash one before upgrading the firmware. Well, strictly speakning, you don&#039;t need one, you can save those 8kB or so for other stuff and use a programmer to write the whole firmware, but then you&#039;ll need to wire up everything every time you want a new firmware, so in my world, you &#039;&#039;&#039;do&#039;&#039;&#039; need the bootloader, since it&#039;s easier. Note that some newer printers, like the CR-10S and possibly all newer ones, come with the bootloader already and thus won&#039;t need another.&lt;br /&gt;
&lt;br /&gt;
To install a bootloader, you&#039;ll need a programmer, and I didn&#039;t have one available. Having some el-cheapo china-copies of Ardinos around, I read I could use one and tried so. Although the docs mostly mention the Uno etc, it&#039;s just as simple with the Nano copy.&lt;br /&gt;
&lt;br /&gt;
So, grab an arduino, plug it to your machine with an USB cable, and, using the Arduino IDE, use the ArduinoISP sketch there (found under Examples) to burn the software needed for the arduino to work as a programmer. When this is done, connect a 10µF capacitor between RST and GND to stop it from resetting when used as a programmer. Connect the MOSI, MISO and SCK pins from the ICSP block (that little isolated 6-pin block on top of the ardu). See [https://www.arduino.cc/en/Tutorial/ArduinoISP here] for a pinout. Then find Vcc and GND either onthe ICSP block or elsewhere. Some sites say that on some boards you shouldn&#039;t use the pins on the ICSP block for this. I doubt it matters, though. Then connect another jumper wire from pin 10 on the ardu to work as the reset pin outwards to the chip being programmed (that is, on the printer). The ICSP jumper block pin layout is the same on the printer and on the ardu, and probably elsewhere. Sometimes [https://xkcd.com/927/ standardisation] actually works…&lt;br /&gt;
&lt;br /&gt;
See https://cloud.karlsbakk.net/index.php/s/zw48YJjzaf8Rc2F for a pic with the ardu (this wiki is broken atm, will fix it later)&lt;br /&gt;
&lt;br /&gt;
== Flashing the printer ==&lt;br /&gt;
&lt;br /&gt;
When the boot loader is in place, possibly after some wierd errors from during the process, the screen on the 3d printer will go blank and it&#039;ll behave like being bricked. This is ok. Now disconnect the wires and connect the USB cable between computer and printer, download the [https://www.th3dstudio.com/knowledgebase/th3d-unified-firmware-package/ TH3D unified firmware] and configure it for your particular needs. The video mentioned above describes this well. After flashing the new firmware, you&#039;ll probably get some timeouts and errors, since apparently it resets the printer after giving it the new firmware, but without notifying the flashing software of it doing so. If this happens, hold your breath and reboot the printer and check its tiny monitor - it should work. If it doesn&#039;t work, try to flash it again, and if that doesn&#039;t work, try flashing the programmer again yet another time, just for kicks.&lt;br /&gt;
&lt;br /&gt;
PS: I tried enabling &#039;&#039;&#039;MANUAL_MESH_LEVELING&#039;&#039;&#039;, which in the code says that &#039;&#039;If used with a 1284P board the bootscreen will be disabled to save space&#039;&#039;. This effectively disabled the whole thing, and apparently may be making the firmware image a wee bit too large for it to fit the 1284P on the ender. It works well without it, though.&lt;br /&gt;
&lt;br /&gt;
== And then… ==&lt;br /&gt;
&lt;br /&gt;
With the new firmware in place, the printer should work as before, although with thermal runaway protection to better avoid fires in case the shit hits the fan, and to allow for things like autolevelling. With any luck, [https://www.precisionpiezo.co.uk/ this thing] may be ready for use by the time you read this - it surely looks nice!&lt;br /&gt;
&lt;br /&gt;
roy&lt;/div&gt;</summary>
		<author><name>Roy</name></author>
	</entry>
	<entry>
		<id>https://wiki.malinux.no/index.php?title=Roy%27s_notes&amp;diff=135</id>
		<title>Roy&#039;s notes</title>
		<link rel="alternate" type="text/html" href="https://wiki.malinux.no/index.php?title=Roy%27s_notes&amp;diff=135"/>
		<updated>2019-12-28T00:05:49Z</updated>

		<summary type="html">&lt;p&gt;Roy: /* LVM in general */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= LVM, md and friends =&lt;br /&gt;
&lt;br /&gt;
== Linux&#039; Logical Volume Manager (LVM) ==&lt;br /&gt;
&lt;br /&gt;
=== LVM in general ===&lt;br /&gt;
&lt;br /&gt;
LVM is designed to be an abstraction layer on top of physical drives or RAID, typically [https://raid.wiki.kernel.org/index.php/RAID_setup mdraid] or [https://help.ubuntu.com/community/FakeRaidHowto fakeraid]. Keep in mind that fakeraid should be avoided unless you really need it, like in conjunction with dual-booting linux and windows on fakeraid. LVM broadly consists of three elements, the &amp;quot;physical&amp;quot; devices (PV), the volume group (VG) and the logical volume (LV). There can be multiple PVs, VGs and LVs, depending on requirement. More about this below. All commands are given as examples, and all of them can be fine-tuned using extra flags in need of so. In my experience, the defaults work well for most usecases.&lt;br /&gt;
&lt;br /&gt;
I&#039;m mentioning filesystem below too. Where I write ext4, the samme applies to ext2 and ext3.&lt;br /&gt;
&lt;br /&gt;
==== Create a PV ====&lt;br /&gt;
&lt;br /&gt;
A PV is the &amp;quot;physical&amp;quot; parts. This does not need to be a physical disk, but can also be another RAID, be it an mdraid, fakeraid, hardware raid, a virtual disk on a SAN or otherwisee or a partition on one of those. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#  These add three PVs, one on a drive (or hardware raid) and another two on mdraids.&lt;br /&gt;
pvcreate /dev/sdb&lt;br /&gt;
pvcreate /dev/md1 /dev/md2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For more information about pvcreate, see [https://linux.die.net/man/8/pvcreate the manual].&lt;br /&gt;
&lt;br /&gt;
==== Create a VG ====&lt;br /&gt;
&lt;br /&gt;
The volume group consists of one or more PVs grouped together on which LVs can be placed. If several PVs are grouped in a VG, it&#039;s generally a good idea to make sure these PVs have some sort of redundancy, as in mdraid/fakeraid or hwraid. Otherwise it will be like using a [https://en.wikipedia.org/wiki/RAID RAID-0] with a single point of failure on each of the independant drives. LVM has [https://unix.stackexchange.com/questions/150644/raiding-with-lvm-vs-mdraid-pros-and-cons  RAID code in it] as well, so you can use that. I haven&#039;t done so myself, as I generally stick to mraid. The reason is mdraid is, in my opinion older and more stable and has more users (meaning bugs are reported and fixed faster whenever they are found). That said, I beleive the actual RAID code used in LVM RAID are the same function calls as for mdraid, so it may not be much of a difference. I still stick with mdraid. To create a VG, run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create volume group my_vg&lt;br /&gt;
vgcreate my_vg /dev/md1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that if vgcreate is run with a PV (as /dev/md1 above) that is not defined as a PV (like above), this is done implicitly, so if you don&#039;t need any special flags to pvcreate, you can simply skip it and let vgcreate do that for you.&lt;br /&gt;
&lt;br /&gt;
==== Create an LV ====&lt;br /&gt;
&lt;br /&gt;
LVs can be compared to partitions, somehow, since they are bounderies of a fraction or all of that of a VG. The difference between them and a partition, however, is that they can be grown or shrunk easily and also moved around between PVs without downtime. This flexibility makes them superiour to partitions as your system can be changed without users noticing it. By default, an LV is alloated &amp;quot;thickly&amp;quot;, meaning all the data given to it, is allocated from the VG and thus the PV. The following makes a 100GB LV named &amp;quot;thicklv&amp;quot;. When making an LV, I usually allocate what&#039;s needed plus some more, but not everything, just to make sure it&#039;s space available for growth on any of the LVs on the VG, or new LVs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a thick provisioned LV named thicklv on the VG my_vg&lt;br /&gt;
lvcreate -n thicklv -L 100G my_vg&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After the LV is created, a filesystem can be placed on it unless it is meant to be used directly. The application for direct use include swap space, VM storage and certain database systems. Most of these will, however, work on filesystems too, although my testing has shown that on swap space, there is a significant performance gain for using dedicated storage without a filesystem. As for filesystems, most Linux users use either ext4 or xfs. Personally, I generally use XFS these days. See my notes below on filesystem choice.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a filesystem on the LV - this could have been mkfs -t ext4 or whatever filesystem you choose&lt;br /&gt;
mkfs -t xfs /dev/my_vg/thicklv&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then just edit /etc/fstab with correct data and run mount -a, and you should be all set.&lt;br /&gt;
&lt;br /&gt;
==== Create LVM cache ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
lvcreate -L 1G -n _cache_meta data /dev/md1&lt;br /&gt;
&lt;br /&gt;
lvcreate -l100%FREE -n _cache data /dev/md1&lt;br /&gt;
&lt;br /&gt;
# Some would want --cachemode writeback, but seriously, I wouldn&#039;t recommend it. Metadata or data can be easily corrupted in case of failure.&lt;br /&gt;
lvconvert --type cache-pool --cachemode writethrough --poolmetadata data/_cache_meta data/_cache&lt;br /&gt;
&lt;br /&gt;
lvconvert --type cache --cachepool data/_cache data/data&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Disabling LVM cache ====&lt;br /&gt;
&lt;br /&gt;
If you for some reason want to disable caching, this will do it cleanly and remove the LVs earlier created for caching the main device.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
lvconvert --uncache data/data&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Growing devices ====&lt;br /&gt;
&lt;br /&gt;
LVM objects can be grown and shrunk. If a PV resides on a RAID where a new drive has been added or otherwise grown, or on a partition or virtual disk that has been extended, the PV must be updated to reflect these changes. The following command will grow the PV to the maximum available on the underlying storage. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Resize the PV /dev/md (not the RAID, only the PV on the RAID) to its full size&lt;br /&gt;
pvresize /dev/md1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If a new PV is added, the VG can be grown to add the space on that in addition to what&#039;s there already. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Extend my_vg to include md2 and its space&lt;br /&gt;
vgextend my_vg /dev/md2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
With more space available in the VG, the LV can now be extended. Let&#039;s add another 50GB to it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Extend thicklv - add 50GB. If you know you won&#039;t need the space anywhere else, you may want to&lt;br /&gt;
# lvresize -l+100%FREE instead. Keep in mind the difference between -l (extents) and -L (bytes)&lt;br /&gt;
lvresize -L +50G my_vg/thicklv&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After the LV has grown, run &#039;&#039;xfs_growfs&#039;&#039; (xfs) or &#039;&#039;resize2fs&#039;&#039; (ext4) to make use of the new data.&lt;br /&gt;
&lt;br /&gt;
==== Rename system VG ====&lt;br /&gt;
&lt;br /&gt;
Some distros create VG names like those-from-a-sysadmin-with-a-well-developed-paranoia-not-to-hit-a-duplicate. Debian, for instance, uses names like &amp;quot;my-full-hostname-vg&amp;quot;. Personally, I don&#039;t like these, since if I were to move a disk or vdisk around to somewhere else, I&#039;d make sure not to add a disk named &#039;sys&#039; to an existing system. If you do, most distros will refuse to use the VGs with duplicate names, resulting in the OS not booting until either one is specified by its UUID or just one removed. As I&#039;m aware of this, I stick to the super-risky thing of all system VGs named &#039;sys&#039; and so on.&lt;br /&gt;
&lt;br /&gt;
If you do this, keep in mind that it may blow up your computer and take your girl- or boyfriend with it or even make either of them pregnant, allowing Trump to rule your life and generally make things suck. You&#039;re on your own!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Rename the VG&lt;br /&gt;
vgrename my-full-hostname-vg sys&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, in /boot/grub/grub.cfg, change the old lv path from something like &#039;/dev/mapper/debian--stretch--machine--vg-root&#039; to your new and fancy &#039;/dev/sys/root. Likewise, in /etc/fstab, change occurences of &#039;/dev/mapper/debian--stretch--machine--vg-&#039; (or similar) with &#039;/dev/sys/&#039;. Here, this was like this - the old ones commented out.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;fstab&amp;quot;&amp;gt;&lt;br /&gt;
#/dev/mapper/debian--stretch--box--vg-root      /               ext4            errors=remount-ro,discard       0       1&lt;br /&gt;
/dev/sys/root                                   /               ext4            errors=remount-ro,discard       0       1&lt;br /&gt;
# /boot was on /dev/vda1 during installation&lt;br /&gt;
UUID=myverylonguuidwithatonofgoodinfoinit       /boot           ext2            defaults                        0       2&lt;br /&gt;
#/dev/mapper/debian--stretch--box--vg-swap_1    none            swap            sw                              0       0&lt;br /&gt;
/dev/sys/swap_1                                 none            swap            sw                              0       0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You might want to run &#039;update-initramfs -u -k all&#039; after this, but I&#039;m not sure if it&#039;s needed.&lt;br /&gt;
&lt;br /&gt;
Now, pray to the nearest god(s) and give it a reboot and it should (probably) work.&lt;br /&gt;
&lt;br /&gt;
=== Migration tools ===&lt;br /&gt;
&lt;br /&gt;
At times, storage regimes change, new storage is added and sometimes it&#039;s not easy to migrate with the current hardware or its support systems. Once I had to migrate a 45TiB fileserver from one storage system to another, preferably without downtime. The server originally had three 15TiB PVs of which two were full and the third half full. I resorted to using [https://linux.die.net/man/8/pvmove pvmove] to just move the data on the PVs in use to a new PV. We started out with creating a new 50TiB PV, sde, and then to pvmove.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Attach /dev/sde to the VG my_vg&lt;br /&gt;
vgextend my_vg /dev/sde&lt;br /&gt;
&lt;br /&gt;
# Move the contents from /dev/sdb over to /dev/sde block by block. If a target is not given in pvmove,&lt;br /&gt;
# the contents of the source (sdb here) will be put somewhere else in the pool.&lt;br /&gt;
pvmove /dev/sdb /dev/sde&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This took a while (as in a week or so) - the pvmove command uses old code and logic (or at least did that when I migrated this in November 2016), but it affected performance on the server very little, so users didn&#039;t notice. After the first PV was migrated, I continued with the other two, one after the other, and after a month or so, it was migrated. We used this on a number of large fileservers, and it worked flawlessly. Before doing the production servers I also tried interrupting pvmove in various ways, including hard resets, and it just kept on after the reboot.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;NOTE:&#039;&#039;&#039;&#039;&#039; &#039;&#039;Even though it worked well for us, &#039;&#039;&#039;always&#039;&#039;&#039; keep a good backup before doing this. Things may go wrong, and without a good backup, you may be looking for a hard-to-find new job the next morning&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
==== mdadm workarounds ====&lt;br /&gt;
&lt;br /&gt;
===== Migrate from a mirror (raid-1) to raid-10 =====&lt;br /&gt;
&lt;br /&gt;
Create a mirror&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sdb /dev/sdc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
LVM (pv/vg/lv) on md0 (see above), put a filesystem on the lv and fill it with some data.&lt;br /&gt;
&lt;br /&gt;
Now, some months later, you want to change this to raid-10 to allow for the same amount of redundancy, but to allow more disks into the system.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mdadm --grow /dev/md0 --level=10&lt;br /&gt;
mdadm: Impossibly level change request for RAID1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So - no - doesn&#039;t work. But - we&#039;re on &lt;br /&gt;
&lt;br /&gt;
Since we&#039;re on lvm already, this&#039;ll be easy. If you&#039;re using filesystems directly on partitions, you can do this the same way, but without the pvmove part, using rsync or whateever you like instead. I&#039;d recommend using lvm for for the new raid, which should be rather obvious from this article. Now plug in a new drive and create a new raid10 on that one. If you two new drives, install both. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# change &amp;quot;missing&amp;quot; to the other device name if you installed two new drives&lt;br /&gt;
mdadm --create /dev/md1 --level=10 --raid-devices=2 /dev/vdd missing&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, as described above, just vgextend the vg, adding the new raid and run pvmove to move the data from the old pv (residing on the old raid1) to the new pv (on raid10). Afte rpvmove is finished (which may take awile, see above), just&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
vgreduce raidtest /dev/md0&lt;br /&gt;
pvremove /dev/md0&lt;br /&gt;
mdadm --stop /dev/md0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
…and your disk is free to be added to the new array. If the new raid is running in degraded mode (if you created it with just one drive), better don&#039;t wait too long, since you don&#039;t have redundancy. Just mdadm --add the devs.&lt;br /&gt;
&lt;br /&gt;
If you now have /dev/mdstat telling you your raid10 is active and have three drives, of which one is a spare, it should look something like this&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5] [raid4] [raid10]&lt;br /&gt;
md1 : active raid10 vdc[3](S) vdb[2] vdd[0]&lt;br /&gt;
      8380416 blocks super 1.2 2 near-copies [2/2] [UU]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Just mdadm --grow --raid-devices=3 /dev/md1&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;RAID section is not complete. I&#039;ll write more on migraing from raid10 to raid6 later. It&#039;s not straight forward, but easier than this one :)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== Thin provisioned LVs ===&lt;br /&gt;
&lt;br /&gt;
Thin provisioning on LVM is a method used for not allocating all the space given to an LV. For instance, if you have a 1TB VG and want to give an LV 500GB, although it currently only uses a fraction of that, a thin lv can be a good alternative. This will allow for adding a limit to how much it can use, but also to let it grow dynamically without manual work by the sysadmin. Thin provisioning adds another layer of abstaction by creating a special LV as a &#039;&#039;thin pool&#039;&#039; from which data is allocated to the &#039;&#039;thin volume(s)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== Create a thin pool ====&lt;br /&gt;
&lt;br /&gt;
Allocate 1TB to the thin pool to be used for thinly provisioned LVs. Keep in mind that the space allocated to the thin pool is in fact thick provisioned. Only the volumes put on &#039;&#039;thinpool&#039;&#039; are thin provisioned. This will create two hidden LVs, one for data and one for metadata. Normally the defaults will do, but check the manual if the data doesn&#039;t match the usual patterns (such as billions of files, resulting in huge amounts of metadata). I &#039;&#039;beleive&#039;&#039; the metadata part should be resizable at a later time if needed, but I have not tested it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a pool for thin LVs. Keep in mind that the pool itself is not thin provisioned, only the volumes residing on it&lt;br /&gt;
lvcreate --size 1T --type thin-pool --thinpool thinpool my_vg&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Create a thin volume ====&lt;br /&gt;
&lt;br /&gt;
You have the thinpool, now put a thin volume on it. It will allocate some space for metadata, but probably not much (a few megs, perhaps).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Now, create a volume with a virtual (-V) size of half a terabyte named thin_pool, but using the thinpool (-T) named thin_pool for storage&lt;br /&gt;
lvcreate -V 500G -T my_vg/thin_pool --name thinvol&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The new volume&#039;s device name will be /dev/thinvol. Now, create a filesystem on it, add to fstab and mount it. The &#039;&#039;&#039;df&#039;&#039;&#039; command will return available space according to the virtual size (-V), while lvs will show how much data is actually used on each of the thinly provisioned volumes.&lt;br /&gt;
&lt;br /&gt;
== Filesystem dilemmas ==&lt;br /&gt;
&lt;br /&gt;
=== XFS or ext4 or something else ===&lt;br /&gt;
The choice of filesystem varies for your use. Distros such as RHEL/CentOS has moved to XFS by default from v7. Debian/Ubuntu still sticks to ext4, like most other. I&#039;ll discuss my thoughts below on ext4 vs XFS and leave the other filesystems for later.&lt;br /&gt;
&lt;br /&gt;
==== ext4 ====&lt;br /&gt;
ext4 is probably the most used filesystem on linux as of writing. It&#039;s rock stable and has been extended by a lot of extensions since the original ext2. It still retains backward compatibility, being able to mount and fsck ext2 and ext3 with the ext4 driver. However, it doesn&#039;t handle large filesystems very well. If a filesystem is created for &amp;lt;16TiB, it cannot be grown to anything larger than 16TiB. This may have changed lately, though. One other issue is handling errors. If a large filesystem (say 10TiB) is damaged, an fsck may take several hours, leading to long downtime.&lt;br /&gt;
&lt;br /&gt;
==== XFS ====&lt;br /&gt;
XFS, originally developed by SGI some time in the bronze age, but has been worked on heavily after that. RHEL and Centos version 7 and forward, uses XFS as the default filesystem. It is quick, it scales well, but it lacks at least two things ext4 has. It cannot be shrunk (not that you normally need that, but nice if you have a typo or you need to change things). Also, it doesn&#039;t allow for automatic fsck on bootup. If something is messed up on the filesystem, you&#039;ll have to login as root on the console (not ssh), which might be an issue on some systems. The fsck equivalent, xfs_repair, is a *lot* faster than ext4&#039;s fsck, though.&lt;br /&gt;
&lt;br /&gt;
==== ZFS ====&lt;br /&gt;
ZFS is like a combination of RAID, LVM and a filesystem, supporting full checksumming, auto-healing (given sufficient redundancy), compression, encryption, replication, deduplication (if you&#039;re brave and have a &#039;&#039;ton&#039;&#039; of memory) and a lot more. It&#039;s a separate chapter and needs a lot more talk than paragraph here.&lt;br /&gt;
&lt;br /&gt;
== Low level disk handling ==&lt;br /&gt;
&lt;br /&gt;
This section is for low-level handling of disks, regardless of storage system elsewhere. These apply to mdraid, lvmraid and zfs and possibly other solutions, with the exception of individual drives on hwraid (and maybe fakeraid), since there, the drives are hidden from Linux (or whatever OS).&lt;br /&gt;
&lt;br /&gt;
=== S.M.A.R.T. and slow drives ===&lt;br /&gt;
Modern (that is, from about 1990 or later) have S.M.A.R.T. (or just smart, since it&#039;s easier to type) monitoring built in, meaning the disk&#039;s controller is monitoring itself. This is handy and will ideally tell you in advance that a drive is flakey or dying. Modern (2010+) smart monitoring is more or less the same. It can be trusted about 50% of the time. Usually, if smart detects an error, it&#039;s a real error. I don&#039;t think I&#039;ve seen it reporting a false positive, but others may know better. &lt;br /&gt;
&lt;br /&gt;
==== smartmontools ====&lt;br /&gt;
First, install smartmontool and run smartclt -H /dev/yourdisk (/dev/sda or something) to get a health report. Then perhaps run smartctl -a /dev/yourdisk and look for &#039;current pending sectors&#039; This should be zero. Also check the temperature, which normally should be much above 50.&lt;br /&gt;
&lt;br /&gt;
==== single, slow drive ====&lt;br /&gt;
What may happen, is smart not seeing anything and life goes on like before, only slower and less prouductive, without telling anyone. If you stubler over this issue, you&#039;ll probably see it during a large rsync/zfs send/receive or a resync/rebuild/resilver of the raid/zpool. During this, it feels like everything is slow and your RAID has turned into a RAIF (redundant array of inexpensive floppies). To check if you have a single drive messing up it all, check with &#039;&#039;&#039;iostat -x 2&#039;&#039;&#039;, having 2 being the delay between each measurement. Interrupt it with ctrl+x. If there&#039;s a rougue drive there, it should stand out like sdg below&lt;br /&gt;
&lt;br /&gt;
 avg-cpu:  %user   %nice %system %iowait  %steal   %idle&lt;br /&gt;
            0.38    0.00    1.75    0.00    0.00   97.87&lt;br /&gt;
&lt;br /&gt;
 Device            r/s     w/s     rkB/s     wkB/s   rrqm/s   wrqm/s  %rrqm  %wrqm r_await w_await aqu-sz rareq-sz wareq-sz  svctm  %util&lt;br /&gt;
 sda              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdb              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdc              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdd              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sde              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdf              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdg              3.50    0.00   2352.00      0.00     0.00     0.00   0.00   0.00 14306.29    0.00  13.85   672.00     0.00 285.71 100.00&lt;br /&gt;
 sdh              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
&lt;br /&gt;
In ZFS land, you should be able to get similar data with &#039;&#039;&#039;zpool iostat -v &amp;lt;pool&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Now you know the bad drive (sdg), pull it from the raid with &#039;&#039;&#039;mdadm --fail /dev/mdX /dev/sdX&#039;&#039;&#039;. Now test the drive&#039;s performance manually, just simply:&lt;br /&gt;
&lt;br /&gt;
 # hdparm -t /dev/sdg&lt;br /&gt;
 &lt;br /&gt;
 /dev/sdg:&lt;br /&gt;
  Timing buffered disk reads:   2 MB in  5.37 seconds = 381.46 kB/sec&lt;br /&gt;
&lt;br /&gt;
Bingo - nothing you&#039;d want to keep. For a good drive, it should be something like 100-200MB/s&lt;br /&gt;
&lt;br /&gt;
PS: Keep in mind that you have a degraded RAID by now in case you had a spare waiting for things to happen.&lt;br /&gt;
&lt;br /&gt;
Try to replace the cable and/or try the disk on another port/controller. If the result from hdparm persists, it&#039;s probably a bad cable&lt;br /&gt;
&lt;br /&gt;
So, then, just psycially locate the drive, pull it out, take out the discs and magnets and recycle the rest.&lt;br /&gt;
&lt;br /&gt;
=== &amp;quot;Unplug&amp;quot; drive from system ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Find the device unit&#039;s number with something like&lt;br /&gt;
find /sys/bus/scsi/devices/*/block/ -name sdd&lt;br /&gt;
# returning /sys/bus/scsi/devices/3:0:0:0/block/sdd here, &lt;br /&gt;
# meaning 3:0:0:0 is the SCSI device we&#039;re looking for.&lt;br /&gt;
&lt;br /&gt;
# Given this is the correct device, and you want to &#039;unplug&#039; it, do so by&lt;br /&gt;
echo 1 &amp;gt; /sys/bus/scsi/devices/3:0:0:0/delete&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Rescan disk controllers ===&lt;br /&gt;
If a drive is added and for some reason doesn&#039;t get detected, or is removed by the command above, it can be rediscovered with a sysfs command to the scsi host to which it is connected. Since there may be quite a few of these, an easy way is to just scan them all and check the output of &#039;&#039;&#039;dmesg -T&#039;&#039;&#039; after running it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Make a list of controllers and send a rescan message to each of them. It won&#039;t do anything &lt;br /&gt;
# for those where nothing has changed, but it will show new drives where they have been added.&lt;br /&gt;
for host_scan in /sys/class/scsi_host/host*/scan&lt;br /&gt;
do&lt;br /&gt;
  echo &#039;- - -&#039; &amp;gt; $host_scan&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Fail injection with debugfs ===&lt;br /&gt;
[https://lxadm.com/Using_fault_injection https://lxadm.com/Using_fault_injection]&lt;br /&gt;
&lt;br /&gt;
== mdadm stuff ==&lt;br /&gt;
=== Spare pools ===&lt;br /&gt;
In the old itmes, mdadm supported only a dedicated spare per md device, so if working with a large set of drives (20? 40?), where you&#039;d want to setup more raid sets to increase redundancy, you&#039;d dedicate a spare to each of the raid sets. This has changed (some time ago?), so in these modern, heathen days, you can change mdadm.conf, usually placed under /etc/mdadm, and add &#039;spare-group=somegroup&#039; where &#039;somegroup&#039; is a string identifying the spare group. After doing this, run &#039;&#039;&#039;update-initramfs -u&#039;&#039;&#039; and reboot and add a spare to one of the raid sets in the spare group, and md will use that or those spares for all the raidsets in that group.&lt;br /&gt;
&lt;br /&gt;
As some pointed out on #linux-raid @ irc.freenode.net, this feature is very badly documented, but as far as I can see, it works well.&lt;br /&gt;
&lt;br /&gt;
==== Example config ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create two raidsets&lt;br /&gt;
&lt;br /&gt;
mdadm --create /dev/md1 --level=6 --raid-devices=6 /dev/vd[efghij]&lt;br /&gt;
mdadm --create /dev/md2 --level=6 --raid-devices=6 /dev/vd[klmnop]&lt;br /&gt;
&lt;br /&gt;
# get their UUID etc&lt;br /&gt;
&lt;br /&gt;
mdadm --detail --scan&lt;br /&gt;
ARRAY /dev/md/1 metadata=1.2 name=raidtest:1 UUID=1a8cbdcb:f4092350:348b6b80:c054d74c&lt;br /&gt;
ARRAY /dev/md/2 metadata=1.2 name=raidtest:2 UUID=894b1b7c:cb7eba70:917d6033:ea5afd2b&lt;br /&gt;
&lt;br /&gt;
# Put those lines into /etc/mdadm/mdadm.conf and and add the spare-group&lt;br /&gt;
&lt;br /&gt;
ARRAY /dev/md/1 metadata=1.2 name=raidtest:1 spare-group=raidtest UUID=1a8cbdcb:f4092350:348b6b80:c054d74c&lt;br /&gt;
ARRAY /dev/md/2 metadata=1.2 name=raidtest:2 spare-group=raidtest UUID=894b1b7c:cb7eba70:917d6033:ea5afd2b&lt;br /&gt;
&lt;br /&gt;
# update the initramfs and reboot&lt;br /&gt;
&lt;br /&gt;
update-initramfs -u&lt;br /&gt;
reboot&lt;br /&gt;
&lt;br /&gt;
# add a spare drive to one of the raids&lt;br /&gt;
&lt;br /&gt;
mdadm --add /dev/md1 /dev/vdq&lt;br /&gt;
&lt;br /&gt;
# fail a drive on the other raid&lt;br /&gt;
&lt;br /&gt;
mdadm --fail /dev/md2 /dev/vdn&lt;br /&gt;
&lt;br /&gt;
# check /proc/mdstat to see md2 rebuilding with the spare from md1&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Recovery ===&lt;br /&gt;
&lt;br /&gt;
The other day, I came across a problem a user had on #linux-raid@irc.freenode.net. He had an old Qnap NAS that had died and tried plugging the drives in to his Linux machine and got various errors. The two-drive RAID-1 did not come up as it should, &#039;&#039;&#039;dmesg&#039;&#039;&#039; was full of errors from one of the drives (both connected on USB) and so forth.&lt;br /&gt;
&lt;br /&gt;
We went on and started by taking down the machine and just connecting one of the drives. I had him check what was assembled with&lt;br /&gt;
&lt;br /&gt;
 cat /proc/mdstat&lt;br /&gt;
&lt;br /&gt;
That returned /proc/md127 assembled, but LVM didn&#039;t find anything. So running a manual scan&lt;br /&gt;
&lt;br /&gt;
 pvscan --cache /dev/md127&lt;br /&gt;
&lt;br /&gt;
This made linux find the PV, VG and a couple of LVs, but probably because the mdraid was degraded, the LVs were deactivated, according to &#039;&#039;&#039;lvscan&#039;&#039;&#039;. Activating the one with a filesystem manually&lt;br /&gt;
&lt;br /&gt;
 lvchange -a y /dev/&amp;lt;vg&amp;gt;/&amp;lt;lv&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Substitute &amp;lt;vg&amp;gt; and &amp;lt;lv&amp;gt; with the names listed by vgs and lvs.&lt;br /&gt;
&lt;br /&gt;
This worked, and the filesystem on /dev/&amp;lt;vg&amp;gt;/&amp;lt;lv&amp;gt; could be mounted correctly.&lt;br /&gt;
&lt;br /&gt;
== Tuning ==&lt;br /&gt;
&lt;br /&gt;
While trying to compare a 12-disk RAID (8TB disks) to a hwraid, mdraid was slower, so we did a few things to speed things up:&lt;br /&gt;
&lt;br /&gt;
While testing with [https://linux.die.net/man/1/fio fio], monitor /sys/block/md0/md/stripe_cache_active, and see if it&#039;s close to /sys/block/md0/md/stripe_cache_size. If it is, double the size of the latter&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
echo 4096 &amp;gt; /sys/block/md0/md/stripe_cache_size&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Continue until stripe_cache_active stabilises, and then you&#039;ve found the limit you&#039;ll need. You may want to double that for good measure. &lt;br /&gt;
&lt;br /&gt;
(to be continued)&lt;br /&gt;
&lt;br /&gt;
== Links ==&lt;br /&gt;
&lt;br /&gt;
Below are a few links with useful info&lt;br /&gt;
&lt;br /&gt;
* [https://raid.wiki.kernel.org/index.php/Irreversible_mdadm_failure_recovery Irreversible mdadm failure recovery]&lt;br /&gt;
&lt;br /&gt;
= ZFS =&lt;br /&gt;
&lt;br /&gt;
ZFS can do a lot of things most filesystems or volume managers can&#039;t. It checksums all data and metadata and so long that the system uses ECC enabled memory (RAM), it will have complete control over the whole data set, and when (not if) an error occurs, it&#039;ll fix the issue without even throwing a warning. To fix the issue, you&#039;ll obviously need sufficient redundancy (mirrors or RAIDzN). &lt;br /&gt;
&lt;br /&gt;
== ZFS send/receive between machines ==&lt;br /&gt;
&lt;br /&gt;
ZFS has a send/receive mechanism that allows for snapshots to be sent over the wire to a receiving end. This can be a full filesystem, or an incremental change since last send/reveive. In a WAN scenario, you&#039;ll probably want to use VPN for this. On a controlled network, sending in cleartext is also possible. You may as well use ssh, but keep in mind that ssh was never designed to be used as a fullblown vpn solution and is just too slow or the task with large amounts of data. You may, though, use mbuffer, if on a loal LAN.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Allow traffic from the sending IP in whatever firewall interface you&#039;re using (if you&#039;re using a firewall at all, that is)&lt;br /&gt;
ufw allow from x.x.x.x&lt;br /&gt;
# &lt;br /&gt;
# Start the receiver first. This listens on port 9090, has a 1GB buffer,&lt;br /&gt;
    and uses 128kb chunks (same as zfs):&lt;br /&gt;
&lt;br /&gt;
mbuffer -s 128k -m 1G -I 9090 | zfs receive data/filesystem&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To be continued one day… See [https://everycity.co.uk/alasdair/2010/07/using-mbuffer-to-speed-up-slow-zfs-send-zfs-receive/ this] for some more. I&#039;ll get back with details on it.&lt;br /&gt;
&lt;br /&gt;
= General Linux system control =&lt;br /&gt;
&lt;br /&gt;
== Add a new CPU (core) ==&lt;br /&gt;
&lt;br /&gt;
If working with virtual machines, adding a new core can be useful if the VM is slow and the load is multithreaded or multiprocess. To do this, add a new CPU in the hypervisor (be it KVM or VMware or Hyper-V or whatever). Some hypervisors, like VMware, will activate it automatically if open-vm-tools is installed. Please note that open-vm-tools is for VMware only. I don&#039;t know of any such thing for KVM or other hypervisors (although I beleive VirtualBox has its own set of tools, but not as a package). If this doesn&#039;t work, run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
echo 1 &amp;gt; /sys/devices/system/cpu/cpuX/online&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where X is the CPU number you want to add. You can &#039;cat /sys/devices/system/cpu/cpuX/online&#039; to check if it&#039;s online.&lt;br /&gt;
&lt;br /&gt;
= Mount partitions on a disk image =&lt;br /&gt;
&lt;br /&gt;
Sometimes you&#039;ll have a disk image, either from recovering a bad drive after hours (or days or weeks) of ddrescue, and sometimes you just have a disk image from a virtual machine where you want to mount the partitions inside the image. There are three main methods of doing this, which are more or less synonmous, but some easier than the other.&lt;br /&gt;
&lt;br /&gt;
== Basics ==&lt;br /&gt;
&lt;br /&gt;
A disk image is usually like a disk, consisting of either a large filesystem, a PV or a partition table with one or partitions onto which resides a filesystem, a pv, swap or something else. If it&#039;s partitioned, and you want your operating system to mount a filesystem or allow it to see whatever LVM stuff lies on it, you need to isolate the partitions. &lt;br /&gt;
&lt;br /&gt;
== Manual mapping ==&lt;br /&gt;
&lt;br /&gt;
In the oldern days, this was done manually, something like this&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
root@mymachine:~# fdisk -l /dev/vda&lt;br /&gt;
Disk /dev/vda: 25 GiB, 26843545600 bytes, 52428800 sectors&lt;br /&gt;
Units: sectors of 1 * 512 = 512 bytes&lt;br /&gt;
Sector size (logical/physical): 512 bytes / 512 bytes&lt;br /&gt;
I/O size (minimum/optimal): 512 bytes / 512 bytes&lt;br /&gt;
Disklabel type: dos&lt;br /&gt;
Disk identifier: 0xc37b7ea5&lt;br /&gt;
&lt;br /&gt;
Device     Boot    Start      End  Sectors  Size Id Type&lt;br /&gt;
/dev/vda1  *        2048 50333311 50331264   24G 83 Linux&lt;br /&gt;
/dev/vda2       50333312 52426369  2093058 1022M  5 Extended&lt;br /&gt;
/dev/vda5       50333314 52426369  2093056 1022M 82 Linux swap / Solaris&lt;br /&gt;
root@mymachine:~#&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To calculate the start and end of each partition, you just take the start sector and multiply it by the sector size (512 bytes here) and you have the offset in bytes. After this, it&#039;s merely an losetup -o &amp;lt;offset&amp;gt; /dev/loopX &amp;lt;nameofimagefile&amp;gt; and you have the partition mapped to your /dev/loopX (having X being something typically 0-255. After this, just mount it or run pvscan/vgscan/lvscan to probe whatever lvm config is there, and you should be able to mount it like any other filesystem.&lt;br /&gt;
&lt;br /&gt;
== kpartx ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;kpartx&#039;&#039;&#039; does the same as above, more or less, just without so much hassle. Most of it should be automatic and easy to deal with, except it may fail to disconnect the loopback devices sometimes, so you may have to &#039;&#039;&#039;losetup -d&#039;&#039;&#039; them manually. See the manual, &#039;&#039;&#039;kpartx (8)&#039;&#039;&#039;. Please note that &#039;&#039;&#039;partx&#039;&#039;&#039; works similarly and I&#039;d guess the authors of the two tools are arguing a lot of which one&#039;s the best.&lt;br /&gt;
&lt;br /&gt;
== guestmount ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;guestmount&#039;&#039;&#039; is something similar again, but also supports file formats like &#039;&#039;&#039;qcow2&#039;&#039;&#039; and possibly other, proprietary filesystems like &#039;&#039;&#039;vmdk&#039;&#039;&#039; and &#039;&#039;&#039;vdi&#039;&#039;&#039;, but don&#039;t take my word for it - I haven&#039;t tested. Again, see the manual or just read up on the description [http://ask.xmodulo.com/mount-qcow2-disk-image-linux.html?fbclid=IwAR3snTeZvGzp9PLdX11EQhCfOpux6I93CiJ3A2pUomkkRLly9Xo4851mkTY here]. It seems rather trivial.&lt;br /&gt;
&lt;br /&gt;
= Linux on laptops =&lt;br /&gt;
&lt;br /&gt;
== Wifi with HP EliteBook 725/745 on Ubuntu ==&lt;br /&gt;
&lt;br /&gt;
The HP EliteBook 725/745 and similar are equipped with a BCM4352 wifi chip. As with a lot of other stuff from Broadcom, this lacks an open hardware description, so thus no open driver exist. The proper fix, is to replace the NIC with something with an open driver, but again, this isn&#039;t always possible, so a binary driver exists. In ubuntu, run, somehow connect the machine to the internet and run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install bcmwl-kernel-source&lt;br /&gt;
sudo modprobe wl&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you can&#039;t connect the machine to the internet, download the needed packages on another machine and put it on some usb storage. These packages should suffice:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# apt-cache depends bcmwl-kernel-source&lt;br /&gt;
bcmwl-kernel-source&lt;br /&gt;
  Depends: dkms&lt;br /&gt;
  Depends: linux-libc-dev&lt;br /&gt;
  Depends: libc6-dev&lt;br /&gt;
  Conflicts: &amp;lt;bcmwl-modaliases&amp;gt;&lt;br /&gt;
  Replaces: &amp;lt;bcmwl-modaliases&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then install manually with &#039;&#039;&#039;dpkg -i file1.deb file2.deb&#039;&#039;&#039; etc&lt;br /&gt;
&lt;br /&gt;
After this, ip/ifconfig/iwconfig shouldd see the new wifi nic, probably &#039;&#039;&#039;wlan0&#039;&#039;&#039;, but due to a [https://bugs.launchpad.net/ubuntu/+source/broadcom-sta/+bug/1343151 old, ignored bug], you won&#039;t find any wifi networks. This is because the driver from Broadcom apparently does not support interrupt remapping, commonly used on x64 machines. To turn this off, change &#039;&#039;&#039;/etc/default/grub&#039;&#039;&#039; and change the line &#039;&#039;&#039;GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;quiet splash&amp;quot;&#039;&#039;&#039;, adding intremap=off to the end before the quote: &#039;&#039;&#039;GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;quiet splash intremap=off&amp;quot;&#039;&#039;&#039;. Save the file and run &#039;&#039;&#039;sudo update-grub&#039;&#039;&#039; and reboot. After this, wifi should work well.&lt;br /&gt;
&lt;br /&gt;
= 3D printer stuff =&lt;br /&gt;
&lt;br /&gt;
== Hydrophilic filament ==&lt;br /&gt;
&lt;br /&gt;
Most popular filament types, including PLA, PETG, PP or PA (Polyamide, normally known as Nylon) and virtualy any filament type named [https://www.matterhackers.com/news/filament-and-water poly-something] (and thus with an acronym of P-something) are hydrophilic (also (somewhat incorrectly) called hydroscopic), meaning so long they&#039;re dryer than the atmosphere around them, they&#039;ll do their best to suck out the atmosphere&#039;s humidity. This is why most filament are shrink-wrapped with a small bag of silica gel in it. If such filament is exposed for normal humid air for some time, it&#039;ll become very hard to use. Most of my experience is with PLA, which can handle a bit (depending on make), but still not a lot. With PLA, if you end up with prints where the filament seems not to stick, it may help with a higher temperature. Otherwise, the filament must be [https://all3dp.com/2/how-to-dry-filament-pla-abs-and-nylon/ baked]. If you don&#039;t want to use your oven, try something like a [https://www.jula.no/catalog/hjem-og-husholdning/kjokkenmaskiner/mattilberedningsapparater/frukt-sopptorker/frukt-sopptorker-001641/#tab02 fruit and mushroom dryer]. Then get a good, sealble plastic box and add something like half a kilogram of [https://www.ebay.com/sch/sis.html?_nkw=1KG+Orange+Replacement+Desiccant+Indicating+Silica+Gel+Beads+for+Drawers%2C+Camera&amp;amp;_id=131938742628&amp;amp;&amp;amp;_trksid=p2057872.m2749.l2658 silica gel] to an old sock, tie it and put it in the your new dry box.&lt;br /&gt;
&lt;br /&gt;
Please note that ABS is hydrophobic, so you won&#039;t have to worry too much there. Also, remember that PA/Nylon is extremely hydrophilic. Even a couple of days in normal air humidity can ruin it completely and will require baking.&lt;br /&gt;
&lt;br /&gt;
== Upgrading the firmware on an Ender 3 ==&lt;br /&gt;
&lt;br /&gt;
This is about upgrading the firmware, and thus also flashing a bootloader to the Creality Ender 3 3D printer. Most of this is well documented on several place, like o [https://www.youtube.com/watch?v=fIl5X2ffdyo the video from Teaching tech] and elsewhere, but I&#039;ll just summarise some issues I had.&lt;br /&gt;
&lt;br /&gt;
=== Using an arduino Nano as a programmer ===&lt;br /&gt;
&lt;br /&gt;
The CR-10, Ender 3 and a few other printers from Creality come without a bootloader, so you&#039;ll need to flash one before upgrading the firmware. Well, strictly speakning, you don&#039;t need one, you can save those 8kB or so for other stuff and use a programmer to write the whole firmware, but then you&#039;ll need to wire up everything every time you want a new firmware, so in my world, you &#039;&#039;&#039;do&#039;&#039;&#039; need the bootloader, since it&#039;s easier. Note that some newer printers, like the CR-10S and possibly all newer ones, come with the bootloader already and thus won&#039;t need another.&lt;br /&gt;
&lt;br /&gt;
To install a bootloader, you&#039;ll need a programmer, and I didn&#039;t have one available. Having some el-cheapo china-copies of Ardinos around, I read I could use one and tried so. Although the docs mostly mention the Uno etc, it&#039;s just as simple with the Nano copy.&lt;br /&gt;
&lt;br /&gt;
So, grab an arduino, plug it to your machine with an USB cable, and, using the Arduino IDE, use the ArduinoISP sketch there (found under Examples) to burn the software needed for the arduino to work as a programmer. When this is done, connect a 10µF capacitor between RST and GND to stop it from resetting when used as a programmer. Connect the MOSI, MISO and SCK pins from the ICSP block (that little isolated 6-pin block on top of the ardu). See [https://www.arduino.cc/en/Tutorial/ArduinoISP here] for a pinout. Then find Vcc and GND either onthe ICSP block or elsewhere. Some sites say that on some boards you shouldn&#039;t use the pins on the ICSP block for this. I doubt it matters, though. Then connect another jumper wire from pin 10 on the ardu to work as the reset pin outwards to the chip being programmed (that is, on the printer). The ICSP jumper block pin layout is the same on the printer and on the ardu, and probably elsewhere. Sometimes [https://xkcd.com/927/ standardisation] actually works…&lt;br /&gt;
&lt;br /&gt;
See https://cloud.karlsbakk.net/index.php/s/zw48YJjzaf8Rc2F for a pic with the ardu (this wiki is broken atm, will fix it later)&lt;br /&gt;
&lt;br /&gt;
== Flashing the printer ==&lt;br /&gt;
&lt;br /&gt;
When the boot loader is in place, possibly after some wierd errors from during the process, the screen on the 3d printer will go blank and it&#039;ll behave like being bricked. This is ok. Now disconnect the wires and connect the USB cable between computer and printer, download the [https://www.th3dstudio.com/knowledgebase/th3d-unified-firmware-package/ TH3D unified firmware] and configure it for your particular needs. The video mentioned above describes this well. After flashing the new firmware, you&#039;ll probably get some timeouts and errors, since apparently it resets the printer after giving it the new firmware, but without notifying the flashing software of it doing so. If this happens, hold your breath and reboot the printer and check its tiny monitor - it should work. If it doesn&#039;t work, try to flash it again, and if that doesn&#039;t work, try flashing the programmer again yet another time, just for kicks.&lt;br /&gt;
&lt;br /&gt;
PS: I tried enabling &#039;&#039;&#039;MANUAL_MESH_LEVELING&#039;&#039;&#039;, which in the code says that &#039;&#039;If used with a 1284P board the bootscreen will be disabled to save space&#039;&#039;. This effectively disabled the whole thing, and apparently may be making the firmware image a wee bit too large for it to fit the 1284P on the ender. It works well without it, though.&lt;br /&gt;
&lt;br /&gt;
== And then… ==&lt;br /&gt;
&lt;br /&gt;
With the new firmware in place, the printer should work as before, although with thermal runaway protection to better avoid fires in case the shit hits the fan, and to allow for things like autolevelling. With any luck, [https://www.precisionpiezo.co.uk/ this thing] may be ready for use by the time you read this - it surely looks nice!&lt;br /&gt;
&lt;br /&gt;
roy&lt;/div&gt;</summary>
		<author><name>Roy</name></author>
	</entry>
	<entry>
		<id>https://wiki.malinux.no/index.php?title=Bcachefs&amp;diff=134</id>
		<title>Bcachefs</title>
		<link rel="alternate" type="text/html" href="https://wiki.malinux.no/index.php?title=Bcachefs&amp;diff=134"/>
		<updated>2019-12-24T19:15:50Z</updated>

		<summary type="html">&lt;p&gt;Roy: /* Installation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[https://bcachefs.org/ Bcachefs] is a spinoff from the [https://bcache.evilpiepirate.org/ bcache] project whose idea is to allow for using SSDs or NVMs for caching slower storage as of that of spinning drives. Bcachefs builds on top of bcache, sharing 80% of its code, creating a new copy-on-write filesystem comparible with ZFS and Btrfs, allowing for snapshot, encryption, sending/receiving data, full checksumming of all data and metadata. As of writing (2012-12-24), bcachefs is in early development and requires recompiling a patched kernel on a newer distro version. According to the bcachefs-tools&#039; INSTALL document, the current distros (or later) are recommended&lt;br /&gt;
&lt;br /&gt;
* Debian Buster&lt;br /&gt;
* Ubuntu 20.04&lt;br /&gt;
* Fedora (bleeding edge)&lt;br /&gt;
* Arch: install bcachefs-tools-git from the AUR&lt;br /&gt;
&lt;br /&gt;
This is a quick run-though for setting up Bcachefs on Debian Buster and lists what you&#039;ll need.&lt;br /&gt;
&lt;br /&gt;
= Installation =&lt;br /&gt;
&lt;br /&gt;
* Grab the latest debian buster iso (currently alpha) and install it somewhere. Better keep this separate on a VM or a separate machine. You&#039;ll need about 40GB in total for the sources and the installed kernel+drivers with debug symbols and all, varying on what&#039;s compiled in. YMMV&lt;br /&gt;
* Upgrade to the newest packages and install the stuff needed to compile new kernel.&lt;br /&gt;
* Download the sources for both kernel and userspace&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# apt update&lt;br /&gt;
# apt dist-upgrade&lt;br /&gt;
# apt install -y pkg-config bc bison build-essential flex libaio-dev libblkid-dev \&lt;br /&gt;
        libelf-dev libkeyutils-dev liblz4-dev libscrypt-dev libsodium-dev libssl-dev \&lt;br /&gt;
        liburcu-dev libzstd-dev ncurses-dev uuid-dev valgrind zlib1g-dev&lt;br /&gt;
# mkdir -p /root/src/git&lt;br /&gt;
# cd /root/src/git&lt;br /&gt;
# git clone https://evilpiepirate.org/git/bcachefs.git&lt;br /&gt;
# git clone https://evilpiepirate.org/git/bcachefs-tools.git&lt;br /&gt;
# cd bcachefs-tools&lt;br /&gt;
# make all install&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Userspace tools in place, you now need the kernel. A quick way to start off is to copy an existing kernel config and start out with that. This will save you time walking through the kernel config manually (it&#039;s rather big). However, the usual distro kernels normally support almost everything in the known computer universe, so you&#039;ll be bound to compile a ton of stuff you&#039;ll never end up using. This will eat more disk space, but won&#039;t hurt more than that.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# cd /root/src/git/bcachefs&lt;br /&gt;
# cp /boot/config-`uname -r` .config&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If this is Debian or perhaps Ubuntu (not sure), you&#039;ll need to remove some trusted keys in the config&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# sed &#039;s/^CONFIG_SYSTEM_TRUSTED_KEYS=.*/CONFIG_SYSTEM_TRUSTED_KEYS=&amp;quot;&amp;quot;/&#039; -i .config&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then run &#039;make menuconfig&#039;, choose &#039;Filesystems&#039; and scroll down to &#039;bcachefs filesystem support&#039; and press M, then &amp;lt;exit&amp;gt; until it asks if you want to save, and do so. Then, run &#039;make ; make install modules_install&#039;. This will take a long time. If you have multiple cores, use -j to allow for multiple, parallel jobs. For instance, if you have eight cores, run &#039;make -j9&#039; to fork out nine jobs - one extra since something is bound to be hanging, waiting for I/O. Keep in mind that multiple jobs also requires more memory, so monitor the system when running this.&lt;/div&gt;</summary>
		<author><name>Roy</name></author>
	</entry>
	<entry>
		<id>https://wiki.malinux.no/index.php?title=Bcachefs&amp;diff=133</id>
		<title>Bcachefs</title>
		<link rel="alternate" type="text/html" href="https://wiki.malinux.no/index.php?title=Bcachefs&amp;diff=133"/>
		<updated>2019-12-24T18:56:23Z</updated>

		<summary type="html">&lt;p&gt;Roy: Created page with &amp;quot;[https://bcachefs.org/ Bcachefs] is a spinoff from the [https://bcache.evilpiepirate.org/ bcache] project whose idea is to allow for using SSDs or NVMs for caching slower stor...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[https://bcachefs.org/ Bcachefs] is a spinoff from the [https://bcache.evilpiepirate.org/ bcache] project whose idea is to allow for using SSDs or NVMs for caching slower storage as of that of spinning drives. Bcachefs builds on top of bcache, sharing 80% of its code, creating a new copy-on-write filesystem comparible with ZFS and Btrfs, allowing for snapshot, encryption, sending/receiving data, full checksumming of all data and metadata. As of writing (2012-12-24), bcachefs is in early development and requires recompiling a patched kernel on a newer distro version. According to the bcachefs-tools&#039; INSTALL document, the current distros (or later) are recommended&lt;br /&gt;
&lt;br /&gt;
* Debian Buster&lt;br /&gt;
* Ubuntu 20.04&lt;br /&gt;
* Fedora (bleeding edge)&lt;br /&gt;
* Arch: install bcachefs-tools-git from the AUR&lt;br /&gt;
&lt;br /&gt;
This is a quick run-though for setting up Bcachefs on Debian Buster and lists what you&#039;ll need.&lt;br /&gt;
&lt;br /&gt;
= Installation =&lt;br /&gt;
&lt;br /&gt;
* Grab the latest debian buster iso (currently alpha) and install it somewhere.&lt;br /&gt;
* Upgrade to the newest packages and install the stuff needed to compile new kernel.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# apt update&lt;br /&gt;
# apt dist-upgrade&lt;br /&gt;
# apt install -y pkg-config bc bison build-essential flex libaio-dev libblkid-dev \&lt;br /&gt;
        libelf-dev libkeyutils-dev liblz4-dev libscrypt-dev libsodium-dev libssl-dev \&lt;br /&gt;
        liburcu-dev libzstd-dev ncurses-dev uuid-dev valgrind zlib1g-dev&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Roy</name></author>
	</entry>
	<entry>
		<id>https://wiki.malinux.no/index.php?title=Roy%27s_notes&amp;diff=132</id>
		<title>Roy&#039;s notes</title>
		<link rel="alternate" type="text/html" href="https://wiki.malinux.no/index.php?title=Roy%27s_notes&amp;diff=132"/>
		<updated>2019-11-06T13:31:43Z</updated>

		<summary type="html">&lt;p&gt;Roy: /* mdadm stuff */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= LVM, md and friends =&lt;br /&gt;
&lt;br /&gt;
== Linux&#039; Logical Volume Manager (LVM) ==&lt;br /&gt;
&lt;br /&gt;
=== LVM in general ===&lt;br /&gt;
&lt;br /&gt;
LVM is designed to be an abstraction layer on top of physical drives or RAID, typically [https://raid.wiki.kernel.org/index.php/RAID_setup mdraid] or [https://help.ubuntu.com/community/FakeRaidHowto fakeraid]. Keep in mind that fakeraid should be avoided unless you really need it, like in conjunction with dual-booting linux and windows on fakeraid. LVM broadly consists of three elements, the &amp;quot;physical&amp;quot; devices (PV), the volume group (VG) and the logical volume (LV). There can be multiple PVs, VGs and LVs, depending on requirement. More about this below. All commands are given as examples, and all of them can be fine-tuned using extra flags in need of so. In my experience, the defaults work well for most usecases.&lt;br /&gt;
&lt;br /&gt;
I&#039;m mentioning filesystem below too. Where I write ext4, the samme applies to ext2 and ext3.&lt;br /&gt;
&lt;br /&gt;
==== Create a PV ====&lt;br /&gt;
&lt;br /&gt;
A PV is the &amp;quot;physical&amp;quot; parts. This does not need to be a physical disk, but can also be another RAID, be it an mdraid, fakeraid, hardware raid, a virtual disk on a SAN or otherwisee or a partition on one of those. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#  These add three PVs, one on a drive (or hardware raid) and another two on mdraids.&lt;br /&gt;
pvcreate /dev/sdb&lt;br /&gt;
pvcreate /dev/md1 /dev/md2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For more information about pvcreate, see [https://linux.die.net/man/8/pvcreate the manual].&lt;br /&gt;
&lt;br /&gt;
==== Create a VG ====&lt;br /&gt;
&lt;br /&gt;
The volume group consists of one or more PVs grouped together on which LVs can be placed. If several PVs are grouped in a VG, it&#039;s generally a good idea to make sure these PVs have some sort of redundancy, as in mdraid/fakeraid or hwraid. Otherwise it will be like using a [https://en.wikipedia.org/wiki/RAID RAID-0] with a single point of failure on each of the independant drives. LVM has [https://unix.stackexchange.com/questions/150644/raiding-with-lvm-vs-mdraid-pros-and-cons  RAID code in it] as well, so you can use that. I haven&#039;t done so myself, as I generally stick to mraid. The reason is mdraid is, in my opinion older and more stable and has more users (meaning bugs are reported and fixed faster whenever they are found). That said, I beleive the actual RAID code used in LVM RAID are the same function calls as for mdraid, so it may not be much of a difference. I still stick with mdraid. To create a VG, run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create volume group my_vg&lt;br /&gt;
vgcreate my_vg /dev/md1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that if vgcreate is run with a PV (as /dev/md1 above) that is not defined as a PV (like above), this is done implicitly, so if you don&#039;t need any special flags to pvcreate, you can simply skip it and let vgcreate do that for you.&lt;br /&gt;
&lt;br /&gt;
==== Create an LV ====&lt;br /&gt;
&lt;br /&gt;
LVs can be compared to partitions, somehow, since they are bounderies of a fraction or all of that of a VG. The difference between them and a partition, however, is that they can be grown or shrunk easily and also moved around between PVs without downtime. This flexibility makes them superiour to partitions as your system can be changed without users noticing it. By default, an LV is alloated &amp;quot;thickly&amp;quot;, meaning all the data given to it, is allocated from the VG and thus the PV. The following makes a 100GB LV named &amp;quot;thicklv&amp;quot;. When making an LV, I usually allocate what&#039;s needed plus some more, but not everything, just to make sure it&#039;s space available for growth on any of the LVs on the VG, or new LVs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a thick provisioned LV named thicklv on the VG my_vg&lt;br /&gt;
lvcreate -n thicklv -L 100G my_vg&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After the LV is created, a filesystem can be placed on it unless it is meant to be used directly. The application for direct use include swap space, VM storage and certain database systems. Most of these will, however, work on filesystems too, although my testing has shown that on swap space, there is a significant performance gain for using dedicated storage without a filesystem. As for filesystems, most Linux users use either ext4 or xfs. Personally, I generally use XFS these days. See my notes below on filesystem choice.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a filesystem on the LV - this could have been mkfs -t ext4 or whatever filesystem you choose&lt;br /&gt;
mkfs -t xfs /dev/my_vg/thicklv&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then just edit /etc/fstab with correct data and run mount -a, and you should be all set.&lt;br /&gt;
&lt;br /&gt;
==== Create LVM cache ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
lvcreate -L 1G -n _cache_meta data /dev/md1&lt;br /&gt;
&lt;br /&gt;
lvcreate -l100%FREE -n _cache data /dev/md1&lt;br /&gt;
&lt;br /&gt;
# Some would want --cachemode writeback, but seriously, I wouldn&#039;t recommend it. Metadata or data can be easily corrupted in case of failure.&lt;br /&gt;
lvconvert --type cache-pool --cachemode writethrough --poolmetadata data/_cache_meta data/_cache&lt;br /&gt;
&lt;br /&gt;
lvconvert --type cache --cachepool data/_cache data/data&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Disabling LVM cache ====&lt;br /&gt;
&lt;br /&gt;
If you for some reason want to disable caching, this will do it cleanly and remove the LVs earlier created for caching the main device.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
lvconvert --uncache data/data&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Growing devices ====&lt;br /&gt;
&lt;br /&gt;
LVM objects can be grown and shrunk. If a PV resides on a RAID where a new drive has been added or otherwise grown, or on a partition or virtual disk that has been extended, the PV must be updated to reflect these changes. The following command will grow the PV to the maximum available on the underlying storage. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Resize the PV /dev/md (not the RAID, only the PV on the RAID) to its full size&lt;br /&gt;
pvresize /dev/md1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If a new PV is added, the VG can be grown to add the space on that in addition to what&#039;s there already. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Extend my_vg to include md2 and its space&lt;br /&gt;
vgextend my_vg /dev/md2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
With more space available in the VG, the LV can now be extended. Let&#039;s add another 50GB to it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Extend thicklv - add 50GB. If you know you won&#039;t need the space anywhere else, you may want to&lt;br /&gt;
# lvresize -l+100%FREE instead. Keep in mind the difference between -l (extents) and -L (bytes)&lt;br /&gt;
lvresize -L +50G my_vg/thicklv&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After the LV has grown, run &#039;&#039;xfs_growfs&#039;&#039; (xfs) or &#039;&#039;resize2fs&#039;&#039; (ext4) to make use of the new data.&lt;br /&gt;
&lt;br /&gt;
=== Migration tools ===&lt;br /&gt;
&lt;br /&gt;
At times, storage regimes change, new storage is added and sometimes it&#039;s not easy to migrate with the current hardware or its support systems. Once I had to migrate a 45TiB fileserver from one storage system to another, preferably without downtime. The server originally had three 15TiB PVs of which two were full and the third half full. I resorted to using [https://linux.die.net/man/8/pvmove pvmove] to just move the data on the PVs in use to a new PV. We started out with creating a new 50TiB PV, sde, and then to pvmove.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Attach /dev/sde to the VG my_vg&lt;br /&gt;
vgextend my_vg /dev/sde&lt;br /&gt;
&lt;br /&gt;
# Move the contents from /dev/sdb over to /dev/sde block by block. If a target is not given in pvmove,&lt;br /&gt;
# the contents of the source (sdb here) will be put somewhere else in the pool.&lt;br /&gt;
pvmove /dev/sdb /dev/sde&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This took a while (as in a week or so) - the pvmove command uses old code and logic (or at least did that when I migrated this in November 2016), but it affected performance on the server very little, so users didn&#039;t notice. After the first PV was migrated, I continued with the other two, one after the other, and after a month or so, it was migrated. We used this on a number of large fileservers, and it worked flawlessly. Before doing the production servers I also tried interrupting pvmove in various ways, including hard resets, and it just kept on after the reboot.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;NOTE:&#039;&#039;&#039;&#039;&#039; &#039;&#039;Even though it worked well for us, &#039;&#039;&#039;always&#039;&#039;&#039; keep a good backup before doing this. Things may go wrong, and without a good backup, you may be looking for a hard-to-find new job the next morning&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
==== mdadm workarounds ====&lt;br /&gt;
&lt;br /&gt;
===== Migrate from a mirror (raid-1) to raid-10 =====&lt;br /&gt;
&lt;br /&gt;
Create a mirror&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sdb /dev/sdc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
LVM (pv/vg/lv) on md0 (see above), put a filesystem on the lv and fill it with some data.&lt;br /&gt;
&lt;br /&gt;
Now, some months later, you want to change this to raid-10 to allow for the same amount of redundancy, but to allow more disks into the system.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mdadm --grow /dev/md0 --level=10&lt;br /&gt;
mdadm: Impossibly level change request for RAID1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So - no - doesn&#039;t work. But - we&#039;re on &lt;br /&gt;
&lt;br /&gt;
Since we&#039;re on lvm already, this&#039;ll be easy. If you&#039;re using filesystems directly on partitions, you can do this the same way, but without the pvmove part, using rsync or whateever you like instead. I&#039;d recommend using lvm for for the new raid, which should be rather obvious from this article. Now plug in a new drive and create a new raid10 on that one. If you two new drives, install both. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# change &amp;quot;missing&amp;quot; to the other device name if you installed two new drives&lt;br /&gt;
mdadm --create /dev/md1 --level=10 --raid-devices=2 /dev/vdd missing&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, as described above, just vgextend the vg, adding the new raid and run pvmove to move the data from the old pv (residing on the old raid1) to the new pv (on raid10). Afte rpvmove is finished (which may take awile, see above), just&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
vgreduce raidtest /dev/md0&lt;br /&gt;
pvremove /dev/md0&lt;br /&gt;
mdadm --stop /dev/md0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
…and your disk is free to be added to the new array. If the new raid is running in degraded mode (if you created it with just one drive), better don&#039;t wait too long, since you don&#039;t have redundancy. Just mdadm --add the devs.&lt;br /&gt;
&lt;br /&gt;
If you now have /dev/mdstat telling you your raid10 is active and have three drives, of which one is a spare, it should look something like this&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5] [raid4] [raid10]&lt;br /&gt;
md1 : active raid10 vdc[3](S) vdb[2] vdd[0]&lt;br /&gt;
      8380416 blocks super 1.2 2 near-copies [2/2] [UU]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Just mdadm --grow --raid-devices=3 /dev/md1&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;RAID section is not complete. I&#039;ll write more on migraing from raid10 to raid6 later. It&#039;s not straight forward, but easier than this one :)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== Thin provisioned LVs ===&lt;br /&gt;
&lt;br /&gt;
Thin provisioning on LVM is a method used for not allocating all the space given to an LV. For instance, if you have a 1TB VG and want to give an LV 500GB, although it currently only uses a fraction of that, a thin lv can be a good alternative. This will allow for adding a limit to how much it can use, but also to let it grow dynamically without manual work by the sysadmin. Thin provisioning adds another layer of abstaction by creating a special LV as a &#039;&#039;thin pool&#039;&#039; from which data is allocated to the &#039;&#039;thin volume(s)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== Create a thin pool ====&lt;br /&gt;
&lt;br /&gt;
Allocate 1TB to the thin pool to be used for thinly provisioned LVs. Keep in mind that the space allocated to the thin pool is in fact thick provisioned. Only the volumes put on &#039;&#039;thinpool&#039;&#039; are thin provisioned. This will create two hidden LVs, one for data and one for metadata. Normally the defaults will do, but check the manual if the data doesn&#039;t match the usual patterns (such as billions of files, resulting in huge amounts of metadata). I &#039;&#039;beleive&#039;&#039; the metadata part should be resizable at a later time if needed, but I have not tested it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a pool for thin LVs. Keep in mind that the pool itself is not thin provisioned, only the volumes residing on it&lt;br /&gt;
lvcreate --size 1T --type thin-pool --thinpool thinpool my_vg&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Create a thin volume ====&lt;br /&gt;
&lt;br /&gt;
You have the thinpool, now put a thin volume on it. It will allocate some space for metadata, but probably not much (a few megs, perhaps).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Now, create a volume with a virtual (-V) size of half a terabyte named thin_pool, but using the thinpool (-T) named thin_pool for storage&lt;br /&gt;
lvcreate -V 500G -T my_vg/thin_pool --name thinvol&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The new volume&#039;s device name will be /dev/thinvol. Now, create a filesystem on it, add to fstab and mount it. The &#039;&#039;&#039;df&#039;&#039;&#039; command will return available space according to the virtual size (-V), while lvs will show how much data is actually used on each of the thinly provisioned volumes.&lt;br /&gt;
&lt;br /&gt;
== Filesystem dilemmas ==&lt;br /&gt;
&lt;br /&gt;
=== XFS or ext4 or something else ===&lt;br /&gt;
The choice of filesystem varies for your use. Distros such as RHEL/CentOS has moved to XFS by default from v7. Debian/Ubuntu still sticks to ext4, like most other. I&#039;ll discuss my thoughts below on ext4 vs XFS and leave the other filesystems for later.&lt;br /&gt;
&lt;br /&gt;
==== ext4 ====&lt;br /&gt;
ext4 is probably the most used filesystem on linux as of writing. It&#039;s rock stable and has been extended by a lot of extensions since the original ext2. It still retains backward compatibility, being able to mount and fsck ext2 and ext3 with the ext4 driver. However, it doesn&#039;t handle large filesystems very well. If a filesystem is created for &amp;lt;16TiB, it cannot be grown to anything larger than 16TiB. This may have changed lately, though. One other issue is handling errors. If a large filesystem (say 10TiB) is damaged, an fsck may take several hours, leading to long downtime.&lt;br /&gt;
&lt;br /&gt;
==== XFS ====&lt;br /&gt;
XFS, originally developed by SGI some time in the bronze age, but has been worked on heavily after that. RHEL and Centos version 7 and forward, uses XFS as the default filesystem. It is quick, it scales well, but it lacks at least two things ext4 has. It cannot be shrunk (not that you normally need that, but nice if you have a typo or you need to change things). Also, it doesn&#039;t allow for automatic fsck on bootup. If something is messed up on the filesystem, you&#039;ll have to login as root on the console (not ssh), which might be an issue on some systems. The fsck equivalent, xfs_repair, is a *lot* faster than ext4&#039;s fsck, though.&lt;br /&gt;
&lt;br /&gt;
==== ZFS ====&lt;br /&gt;
ZFS is like a combination of RAID, LVM and a filesystem, supporting full checksumming, auto-healing (given sufficient redundancy), compression, encryption, replication, deduplication (if you&#039;re brave and have a &#039;&#039;ton&#039;&#039; of memory) and a lot more. It&#039;s a separate chapter and needs a lot more talk than paragraph here.&lt;br /&gt;
&lt;br /&gt;
== Low level disk handling ==&lt;br /&gt;
&lt;br /&gt;
This section is for low-level handling of disks, regardless of storage system elsewhere. These apply to mdraid, lvmraid and zfs and possibly other solutions, with the exception of individual drives on hwraid (and maybe fakeraid), since there, the drives are hidden from Linux (or whatever OS).&lt;br /&gt;
&lt;br /&gt;
=== S.M.A.R.T. and slow drives ===&lt;br /&gt;
Modern (that is, from about 1990 or later) have S.M.A.R.T. (or just smart, since it&#039;s easier to type) monitoring built in, meaning the disk&#039;s controller is monitoring itself. This is handy and will ideally tell you in advance that a drive is flakey or dying. Modern (2010+) smart monitoring is more or less the same. It can be trusted about 50% of the time. Usually, if smart detects an error, it&#039;s a real error. I don&#039;t think I&#039;ve seen it reporting a false positive, but others may know better. &lt;br /&gt;
&lt;br /&gt;
==== smartmontools ====&lt;br /&gt;
First, install smartmontool and run smartclt -H /dev/yourdisk (/dev/sda or something) to get a health report. Then perhaps run smartctl -a /dev/yourdisk and look for &#039;current pending sectors&#039; This should be zero. Also check the temperature, which normally should be much above 50.&lt;br /&gt;
&lt;br /&gt;
==== single, slow drive ====&lt;br /&gt;
What may happen, is smart not seeing anything and life goes on like before, only slower and less prouductive, without telling anyone. If you stubler over this issue, you&#039;ll probably see it during a large rsync/zfs send/receive or a resync/rebuild/resilver of the raid/zpool. During this, it feels like everything is slow and your RAID has turned into a RAIF (redundant array of inexpensive floppies). To check if you have a single drive messing up it all, check with &#039;&#039;&#039;iostat -x 2&#039;&#039;&#039;, having 2 being the delay between each measurement. Interrupt it with ctrl+x. If there&#039;s a rougue drive there, it should stand out like sdg below&lt;br /&gt;
&lt;br /&gt;
 avg-cpu:  %user   %nice %system %iowait  %steal   %idle&lt;br /&gt;
            0.38    0.00    1.75    0.00    0.00   97.87&lt;br /&gt;
&lt;br /&gt;
 Device            r/s     w/s     rkB/s     wkB/s   rrqm/s   wrqm/s  %rrqm  %wrqm r_await w_await aqu-sz rareq-sz wareq-sz  svctm  %util&lt;br /&gt;
 sda              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdb              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdc              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdd              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sde              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdf              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
 sdg              3.50    0.00   2352.00      0.00     0.00     0.00   0.00   0.00 14306.29    0.00  13.85   672.00     0.00 285.71 100.00&lt;br /&gt;
 sdh              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00&lt;br /&gt;
&lt;br /&gt;
In ZFS land, you should be able to get similar data with &#039;&#039;&#039;zpool iostat -v &amp;lt;pool&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Now you know the bad drive (sdg), pull it from the raid with &#039;&#039;&#039;mdadm --fail /dev/mdX /dev/sdX&#039;&#039;&#039;. Now test the drive&#039;s performance manually, just simply:&lt;br /&gt;
&lt;br /&gt;
 # hdparm -t /dev/sdg&lt;br /&gt;
 &lt;br /&gt;
 /dev/sdg:&lt;br /&gt;
  Timing buffered disk reads:   2 MB in  5.37 seconds = 381.46 kB/sec&lt;br /&gt;
&lt;br /&gt;
Bingo - nothing you&#039;d want to keep. For a good drive, it should be something like 100-200MB/s&lt;br /&gt;
&lt;br /&gt;
PS: Keep in mind that you have a degraded RAID by now in case you had a spare waiting for things to happen.&lt;br /&gt;
&lt;br /&gt;
Try to replace the cable and/or try the disk on another port/controller. If the result from hdparm persists, it&#039;s probably a bad cable&lt;br /&gt;
&lt;br /&gt;
So, then, just psycially locate the drive, pull it out, take out the discs and magnets and recycle the rest.&lt;br /&gt;
&lt;br /&gt;
=== &amp;quot;Unplug&amp;quot; drive from system ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Find the device unit&#039;s number with something like&lt;br /&gt;
find /sys/bus/scsi/devices/*/block/ -name sdd&lt;br /&gt;
# returning /sys/bus/scsi/devices/3:0:0:0/block/sdd here, &lt;br /&gt;
# meaning 3:0:0:0 is the SCSI device we&#039;re looking for.&lt;br /&gt;
&lt;br /&gt;
# Given this is the correct device, and you want to &#039;unplug&#039; it, do so by&lt;br /&gt;
echo 1 &amp;gt; /sys/bus/scsi/devices/3:0:0:0/delete&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Rescan disk controllers ===&lt;br /&gt;
If a drive is added and for some reason doesn&#039;t get detected, or is removed by the command above, it can be rediscovered with a sysfs command to the scsi host to which it is connected. Since there may be quite a few of these, an easy way is to just scan them all and check the output of &#039;&#039;&#039;dmesg -T&#039;&#039;&#039; after running it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Make a list of controllers and send a rescan message to each of them. It won&#039;t do anything &lt;br /&gt;
# for those where nothing has changed, but it will show new drives where they have been added.&lt;br /&gt;
for host_scan in /sys/class/scsi_host/host*/scan&lt;br /&gt;
do&lt;br /&gt;
  echo &#039;- - -&#039; &amp;gt; $host_scan&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Fail injection with debugfs ===&lt;br /&gt;
[https://lxadm.com/Using_fault_injection https://lxadm.com/Using_fault_injection]&lt;br /&gt;
&lt;br /&gt;
== mdadm stuff ==&lt;br /&gt;
=== Spare pools ===&lt;br /&gt;
In the old itmes, mdadm supported only a dedicated spare per md device, so if working with a large set of drives (20? 40?), where you&#039;d want to setup more raid sets to increase redundancy, you&#039;d dedicate a spare to each of the raid sets. This has changed (some time ago?), so in these modern, heathen days, you can change mdadm.conf, usually placed under /etc/mdadm, and add &#039;spare-group=somegroup&#039; where &#039;somegroup&#039; is a string identifying the spare group. After doing this, run &#039;&#039;&#039;update-initramfs -u&#039;&#039;&#039; and reboot and add a spare to one of the raid sets in the spare group, and md will use that or those spares for all the raidsets in that group.&lt;br /&gt;
&lt;br /&gt;
As some pointed out on #linux-raid @ irc.freenode.net, this feature is very badly documented, but as far as I can see, it works well.&lt;br /&gt;
&lt;br /&gt;
==== Example config ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create two raidsets&lt;br /&gt;
&lt;br /&gt;
mdadm --create /dev/md1 --level=6 --raid-devices=6 /dev/vd[efghij]&lt;br /&gt;
mdadm --create /dev/md2 --level=6 --raid-devices=6 /dev/vd[klmnop]&lt;br /&gt;
&lt;br /&gt;
# get their UUID etc&lt;br /&gt;
&lt;br /&gt;
mdadm --detail --scan&lt;br /&gt;
ARRAY /dev/md/1 metadata=1.2 name=raidtest:1 UUID=1a8cbdcb:f4092350:348b6b80:c054d74c&lt;br /&gt;
ARRAY /dev/md/2 metadata=1.2 name=raidtest:2 UUID=894b1b7c:cb7eba70:917d6033:ea5afd2b&lt;br /&gt;
&lt;br /&gt;
# Put those lines into /etc/mdadm/mdadm.conf and and add the spare-group&lt;br /&gt;
&lt;br /&gt;
ARRAY /dev/md/1 metadata=1.2 name=raidtest:1 spare-group=raidtest UUID=1a8cbdcb:f4092350:348b6b80:c054d74c&lt;br /&gt;
ARRAY /dev/md/2 metadata=1.2 name=raidtest:2 spare-group=raidtest UUID=894b1b7c:cb7eba70:917d6033:ea5afd2b&lt;br /&gt;
&lt;br /&gt;
# update the initramfs and reboot&lt;br /&gt;
&lt;br /&gt;
update-initramfs -u&lt;br /&gt;
reboot&lt;br /&gt;
&lt;br /&gt;
# add a spare drive to one of the raids&lt;br /&gt;
&lt;br /&gt;
mdadm --add /dev/md1 /dev/vdq&lt;br /&gt;
&lt;br /&gt;
# fail a drive on the other raid&lt;br /&gt;
&lt;br /&gt;
mdadm --fail /dev/md2 /dev/vdn&lt;br /&gt;
&lt;br /&gt;
# check /proc/mdstat to see md2 rebuilding with the spare from md1&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Recovery ===&lt;br /&gt;
&lt;br /&gt;
The other day, I came across a problem a user had on #linux-raid@irc.freenode.net. He had an old Qnap NAS that had died and tried plugging the drives in to his Linux machine and got various errors. The two-drive RAID-1 did not come up as it should, &#039;&#039;&#039;dmesg&#039;&#039;&#039; was full of errors from one of the drives (both connected on USB) and so forth.&lt;br /&gt;
&lt;br /&gt;
We went on and started by taking down the machine and just connecting one of the drives. I had him check what was assembled with&lt;br /&gt;
&lt;br /&gt;
 cat /proc/mdstat&lt;br /&gt;
&lt;br /&gt;
That returned /proc/md127 assembled, but LVM didn&#039;t find anything. So running a manual scan&lt;br /&gt;
&lt;br /&gt;
 pvscan --cache /dev/md127&lt;br /&gt;
&lt;br /&gt;
This made linux find the PV, VG and a couple of LVs, but probably because the mdraid was degraded, the LVs were deactivated, according to &#039;&#039;&#039;lvscan&#039;&#039;&#039;. Activating the one with a filesystem manually&lt;br /&gt;
&lt;br /&gt;
 lvchange -a y /dev/&amp;lt;vg&amp;gt;/&amp;lt;lv&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Substitute &amp;lt;vg&amp;gt; and &amp;lt;lv&amp;gt; with the names listed by vgs and lvs.&lt;br /&gt;
&lt;br /&gt;
This worked, and the filesystem on /dev/&amp;lt;vg&amp;gt;/&amp;lt;lv&amp;gt; could be mounted correctly.&lt;br /&gt;
&lt;br /&gt;
== Tuning ==&lt;br /&gt;
&lt;br /&gt;
While trying to compare a 12-disk RAID (8TB disks) to a hwraid, mdraid was slower, so we did a few things to speed things up:&lt;br /&gt;
&lt;br /&gt;
While testing with [https://linux.die.net/man/1/fio fio], monitor /sys/block/md0/md/stripe_cache_active, and see if it&#039;s close to /sys/block/md0/md/stripe_cache_size. If it is, double the size of the latter&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
echo 4096 &amp;gt; /sys/block/md0/md/stripe_cache_size&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Continue until stripe_cache_active stabilises, and then you&#039;ve found the limit you&#039;ll need. You may want to double that for good measure. &lt;br /&gt;
&lt;br /&gt;
(to be continued)&lt;br /&gt;
&lt;br /&gt;
== Links ==&lt;br /&gt;
&lt;br /&gt;
Below are a few links with useful info&lt;br /&gt;
&lt;br /&gt;
* [https://raid.wiki.kernel.org/index.php/Irreversible_mdadm_failure_recovery Irreversible mdadm failure recovery]&lt;br /&gt;
&lt;br /&gt;
= ZFS =&lt;br /&gt;
&lt;br /&gt;
ZFS can do a lot of things most filesystems or volume managers can&#039;t. It checksums all data and metadata and so long that the system uses ECC enabled memory (RAM), it will have complete control over the whole data set, and when (not if) an error occurs, it&#039;ll fix the issue without even throwing a warning. To fix the issue, you&#039;ll obviously need sufficient redundancy (mirrors or RAIDzN). &lt;br /&gt;
&lt;br /&gt;
== ZFS send/receive between machines ==&lt;br /&gt;
&lt;br /&gt;
ZFS has a send/receive mechanism that allows for snapshots to be sent over the wire to a receiving end. This can be a full filesystem, or an incremental change since last send/reveive. In a WAN scenario, you&#039;ll probably want to use VPN for this. On a controlled network, sending in cleartext is also possible. You may as well use ssh, but keep in mind that ssh was never designed to be used as a fullblown vpn solution and is just too slow or the task with large amounts of data. You may, though, use mbuffer, if on a loal LAN.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Allow traffic from the sending IP in whatever firewall interface you&#039;re using (if you&#039;re using a firewall at all, that is)&lt;br /&gt;
ufw allow from x.x.x.x&lt;br /&gt;
# &lt;br /&gt;
# Start the receiver first. This listens on port 9090, has a 1GB buffer,&lt;br /&gt;
    and uses 128kb chunks (same as zfs):&lt;br /&gt;
&lt;br /&gt;
mbuffer -s 128k -m 1G -I 9090 | zfs receive data/filesystem&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To be continued one day… See [https://everycity.co.uk/alasdair/2010/07/using-mbuffer-to-speed-up-slow-zfs-send-zfs-receive/ this] for some more. I&#039;ll get back with details on it.&lt;br /&gt;
&lt;br /&gt;
= General Linux system control =&lt;br /&gt;
&lt;br /&gt;
== Add a new CPU (core) ==&lt;br /&gt;
&lt;br /&gt;
If working with virtual machines, adding a new core can be useful if the VM is slow and the load is multithreaded or multiprocess. To do this, add a new CPU in the hypervisor (be it KVM or VMware or Hyper-V or whatever). Some hypervisors, like VMware, will activate it automatically if open-vm-tools is installed. Please note that open-vm-tools is for VMware only. I don&#039;t know of any such thing for KVM or other hypervisors (although I beleive VirtualBox has its own set of tools, but not as a package). If this doesn&#039;t work, run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
echo 1 &amp;gt; /sys/devices/system/cpu/cpuX/online&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where X is the CPU number you want to add. You can &#039;cat /sys/devices/system/cpu/cpuX/online&#039; to check if it&#039;s online.&lt;br /&gt;
&lt;br /&gt;
= Mount partitions on a disk image =&lt;br /&gt;
&lt;br /&gt;
Sometimes you&#039;ll have a disk image, either from recovering a bad drive after hours (or days or weeks) of ddrescue, and sometimes you just have a disk image from a virtual machine where you want to mount the partitions inside the image. There are three main methods of doing this, which are more or less synonmous, but some easier than the other.&lt;br /&gt;
&lt;br /&gt;
== Basics ==&lt;br /&gt;
&lt;br /&gt;
A disk image is usually like a disk, consisting of either a large filesystem, a PV or a partition table with one or partitions onto which resides a filesystem, a pv, swap or something else. If it&#039;s partitioned, and you want your operating system to mount a filesystem or allow it to see whatever LVM stuff lies on it, you need to isolate the partitions. &lt;br /&gt;
&lt;br /&gt;
== Manual mapping ==&lt;br /&gt;
&lt;br /&gt;
In the oldern days, this was done manually, something like this&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
root@mymachine:~# fdisk -l /dev/vda&lt;br /&gt;
Disk /dev/vda: 25 GiB, 26843545600 bytes, 52428800 sectors&lt;br /&gt;
Units: sectors of 1 * 512 = 512 bytes&lt;br /&gt;
Sector size (logical/physical): 512 bytes / 512 bytes&lt;br /&gt;
I/O size (minimum/optimal): 512 bytes / 512 bytes&lt;br /&gt;
Disklabel type: dos&lt;br /&gt;
Disk identifier: 0xc37b7ea5&lt;br /&gt;
&lt;br /&gt;
Device     Boot    Start      End  Sectors  Size Id Type&lt;br /&gt;
/dev/vda1  *        2048 50333311 50331264   24G 83 Linux&lt;br /&gt;
/dev/vda2       50333312 52426369  2093058 1022M  5 Extended&lt;br /&gt;
/dev/vda5       50333314 52426369  2093056 1022M 82 Linux swap / Solaris&lt;br /&gt;
root@mymachine:~#&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To calculate the start and end of each partition, you just take the start sector and multiply it by the sector size (512 bytes here) and you have the offset in bytes. After this, it&#039;s merely an losetup -o &amp;lt;offset&amp;gt; /dev/loopX &amp;lt;nameofimagefile&amp;gt; and you have the partition mapped to your /dev/loopX (having X being something typically 0-255. After this, just mount it or run pvscan/vgscan/lvscan to probe whatever lvm config is there, and you should be able to mount it like any other filesystem.&lt;br /&gt;
&lt;br /&gt;
== kpartx ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;kpartx&#039;&#039;&#039; does the same as above, more or less, just without so much hassle. Most of it should be automatic and easy to deal with, except it may fail to disconnect the loopback devices sometimes, so you may have to &#039;&#039;&#039;losetup -d&#039;&#039;&#039; them manually. See the manual, &#039;&#039;&#039;kpartx (8)&#039;&#039;&#039;. Please note that &#039;&#039;&#039;partx&#039;&#039;&#039; works similarly and I&#039;d guess the authors of the two tools are arguing a lot of which one&#039;s the best.&lt;br /&gt;
&lt;br /&gt;
== guestmount ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;guestmount&#039;&#039;&#039; is something similar again, but also supports file formats like &#039;&#039;&#039;qcow2&#039;&#039;&#039; and possibly other, proprietary filesystems like &#039;&#039;&#039;vmdk&#039;&#039;&#039; and &#039;&#039;&#039;vdi&#039;&#039;&#039;, but don&#039;t take my word for it - I haven&#039;t tested. Again, see the manual or just read up on the description [http://ask.xmodulo.com/mount-qcow2-disk-image-linux.html?fbclid=IwAR3snTeZvGzp9PLdX11EQhCfOpux6I93CiJ3A2pUomkkRLly9Xo4851mkTY here]. It seems rather trivial.&lt;br /&gt;
&lt;br /&gt;
= Linux on laptops =&lt;br /&gt;
&lt;br /&gt;
== Wifi with HP EliteBook 725/745 on Ubuntu ==&lt;br /&gt;
&lt;br /&gt;
The HP EliteBook 725/745 and similar are equipped with a BCM4352 wifi chip. As with a lot of other stuff from Broadcom, this lacks an open hardware description, so thus no open driver exist. The proper fix, is to replace the NIC with something with an open driver, but again, this isn&#039;t always possible, so a binary driver exists. In ubuntu, run, somehow connect the machine to the internet and run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install bcmwl-kernel-source&lt;br /&gt;
sudo modprobe wl&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you can&#039;t connect the machine to the internet, download the needed packages on another machine and put it on some usb storage. These packages should suffice:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# apt-cache depends bcmwl-kernel-source&lt;br /&gt;
bcmwl-kernel-source&lt;br /&gt;
  Depends: dkms&lt;br /&gt;
  Depends: linux-libc-dev&lt;br /&gt;
  Depends: libc6-dev&lt;br /&gt;
  Conflicts: &amp;lt;bcmwl-modaliases&amp;gt;&lt;br /&gt;
  Replaces: &amp;lt;bcmwl-modaliases&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then install manually with &#039;&#039;&#039;dpkg -i file1.deb file2.deb&#039;&#039;&#039; etc&lt;br /&gt;
&lt;br /&gt;
After this, ip/ifconfig/iwconfig shouldd see the new wifi nic, probably &#039;&#039;&#039;wlan0&#039;&#039;&#039;, but due to a [https://bugs.launchpad.net/ubuntu/+source/broadcom-sta/+bug/1343151 old, ignored bug], you won&#039;t find any wifi networks. This is because the driver from Broadcom apparently does not support interrupt remapping, commonly used on x64 machines. To turn this off, change &#039;&#039;&#039;/etc/default/grub&#039;&#039;&#039; and change the line &#039;&#039;&#039;GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;quiet splash&amp;quot;&#039;&#039;&#039;, adding intremap=off to the end before the quote: &#039;&#039;&#039;GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;quiet splash intremap=off&amp;quot;&#039;&#039;&#039;. Save the file and run &#039;&#039;&#039;sudo update-grub&#039;&#039;&#039; and reboot. After this, wifi should work well.&lt;br /&gt;
&lt;br /&gt;
= 3D printer stuff =&lt;br /&gt;
&lt;br /&gt;
== Hydrophilic filament ==&lt;br /&gt;
&lt;br /&gt;
Most popular filament types, including PLA, PETG, PP or PA (Polyamide, normally known as Nylon) and virtualy any filament type named [https://www.matterhackers.com/news/filament-and-water poly-something] (and thus with an acronym of P-something) are hydrophilic (also (somewhat incorrectly) called hydroscopic), meaning so long they&#039;re dryer than the atmosphere around them, they&#039;ll do their best to suck out the atmosphere&#039;s humidity. This is why most filament are shrink-wrapped with a small bag of silica gel in it. If such filament is exposed for normal humid air for some time, it&#039;ll become very hard to use. Most of my experience is with PLA, which can handle a bit (depending on make), but still not a lot. With PLA, if you end up with prints where the filament seems not to stick, it may help with a higher temperature. Otherwise, the filament must be [https://all3dp.com/2/how-to-dry-filament-pla-abs-and-nylon/ baked]. If you don&#039;t want to use your oven, try something like a [https://www.jula.no/catalog/hjem-og-husholdning/kjokkenmaskiner/mattilberedningsapparater/frukt-sopptorker/frukt-sopptorker-001641/#tab02 fruit and mushroom dryer]. Then get a good, sealble plastic box and add something like half a kilogram of [https://www.ebay.com/sch/sis.html?_nkw=1KG+Orange+Replacement+Desiccant+Indicating+Silica+Gel+Beads+for+Drawers%2C+Camera&amp;amp;_id=131938742628&amp;amp;&amp;amp;_trksid=p2057872.m2749.l2658 silica gel] to an old sock, tie it and put it in the your new dry box.&lt;br /&gt;
&lt;br /&gt;
Please note that ABS is hydrophobic, so you won&#039;t have to worry too much there. Also, remember that PA/Nylon is extremely hydrophilic. Even a couple of days in normal air humidity can ruin it completely and will require baking.&lt;br /&gt;
&lt;br /&gt;
== Upgrading the firmware on an Ender 3 ==&lt;br /&gt;
&lt;br /&gt;
This is about upgrading the firmware, and thus also flashing a bootloader to the Creality Ender 3 3D printer. Most of this is well documented on several place, like o [https://www.youtube.com/watch?v=fIl5X2ffdyo the video from Teaching tech] and elsewhere, but I&#039;ll just summarise some issues I had.&lt;br /&gt;
&lt;br /&gt;
=== Using an arduino Nano as a programmer ===&lt;br /&gt;
&lt;br /&gt;
The CR-10, Ender 3 and a few other printers from Creality come without a bootloader, so you&#039;ll need to flash one before upgrading the firmware. Well, strictly speakning, you don&#039;t need one, you can save those 8kB or so for other stuff and use a programmer to write the whole firmware, but then you&#039;ll need to wire up everything every time you want a new firmware, so in my world, you &#039;&#039;&#039;do&#039;&#039;&#039; need the bootloader, since it&#039;s easier. Note that some newer printers, like the CR-10S and possibly all newer ones, come with the bootloader already and thus won&#039;t need another.&lt;br /&gt;
&lt;br /&gt;
To install a bootloader, you&#039;ll need a programmer, and I didn&#039;t have one available. Having some el-cheapo china-copies of Ardinos around, I read I could use one and tried so. Although the docs mostly mention the Uno etc, it&#039;s just as simple with the Nano copy.&lt;br /&gt;
&lt;br /&gt;
So, grab an arduino, plug it to your machine with an USB cable, and, using the Arduino IDE, use the ArduinoISP sketch there (found under Examples) to burn the software needed for the arduino to work as a programmer. When this is done, connect a 10µF capacitor between RST and GND to stop it from resetting when used as a programmer. Connect the MOSI, MISO and SCK pins from the ICSP block (that little isolated 6-pin block on top of the ardu). See [https://www.arduino.cc/en/Tutorial/ArduinoISP here] for a pinout. Then find Vcc and GND either onthe ICSP block or elsewhere. Some sites say that on some boards you shouldn&#039;t use the pins on the ICSP block for this. I doubt it matters, though. Then connect another jumper wire from pin 10 on the ardu to work as the reset pin outwards to the chip being programmed (that is, on the printer). The ICSP jumper block pin layout is the same on the printer and on the ardu, and probably elsewhere. Sometimes [https://xkcd.com/927/ standardisation] actually works…&lt;br /&gt;
&lt;br /&gt;
See https://cloud.karlsbakk.net/index.php/s/zw48YJjzaf8Rc2F for a pic with the ardu (this wiki is broken atm, will fix it later)&lt;br /&gt;
&lt;br /&gt;
== Flashing the printer ==&lt;br /&gt;
&lt;br /&gt;
When the boot loader is in place, possibly after some wierd errors from during the process, the screen on the 3d printer will go blank and it&#039;ll behave like being bricked. This is ok. Now disconnect the wires and connect the USB cable between computer and printer, download the [https://www.th3dstudio.com/knowledgebase/th3d-unified-firmware-package/ TH3D unified firmware] and configure it for your particular needs. The video mentioned above describes this well. After flashing the new firmware, you&#039;ll probably get some timeouts and errors, since apparently it resets the printer after giving it the new firmware, but without notifying the flashing software of it doing so. If this happens, hold your breath and reboot the printer and check its tiny monitor - it should work. If it doesn&#039;t work, try to flash it again, and if that doesn&#039;t work, try flashing the programmer again yet another time, just for kicks.&lt;br /&gt;
&lt;br /&gt;
PS: I tried enabling &#039;&#039;&#039;MANUAL_MESH_LEVELING&#039;&#039;&#039;, which in the code says that &#039;&#039;If used with a 1284P board the bootscreen will be disabled to save space&#039;&#039;. This effectively disabled the whole thing, and apparently may be making the firmware image a wee bit too large for it to fit the 1284P on the ender. It works well without it, though.&lt;br /&gt;
&lt;br /&gt;
== And then… ==&lt;br /&gt;
&lt;br /&gt;
With the new firmware in place, the printer should work as before, although with thermal runaway protection to better avoid fires in case the shit hits the fan, and to allow for things like autolevelling. With any luck, [https://www.precisionpiezo.co.uk/ this thing] may be ready for use by the time you read this - it surely looks nice!&lt;br /&gt;
&lt;br /&gt;
roy&lt;/div&gt;</summary>
		<author><name>Roy</name></author>
	</entry>
</feed>