{"id":119,"date":"2023-12-17T12:34:47","date_gmt":"2023-12-17T12:34:47","guid":{"rendered":"http:\/\/192.168.8.136\/wordpress\/?p=119"},"modified":"2024-01-19T02:22:17","modified_gmt":"2024-01-19T02:22:17","slug":"rpi-nas-part-4-usb-hub","status":"publish","type":"post","link":"https:\/\/mpr-projects.com\/index.php\/2023\/12\/17\/rpi-nas-part-4-usb-hub\/","title":{"rendered":"RPi NAS: Part 4 USB Hub"},"content":{"rendered":"\n<p>Our data has safely reached the RPi via some network connection. Before we can save it onto a hard- or solid-state drive we have to think about how those drives will be connected to the Raspberry Pi.<\/p>\n\n\n<p>This post is part of a series about building a Network-Attached Storage (NAS) with redundancy using a Raspberry Pi (RPi). See <a href=\"https:\/\/mpr-projects.com\/index.php\/2023\/11\/13\/building-a-raspberry-pi-nas-with-data-redundancy-part-1-overview\/#RPi_NAS_Post_List\" data-type=\"post\" data-id=\"8\">here<\/a> for a list of all posts in this series.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\" style=\"margin-top:var(--wp--preset--spacing--30);margin-bottom:var(--wp--preset--spacing--30)\"\/>\n\n\n\n<p>I&#8217;m sure you&#8217;ve noticed that we have two USB 3 ports available on the Raspberry Pi 4b\/5 but we want to connect four drives (and maybe more in the future). So we&#8217;ll have to use a USB hub to connect all drives. The first important point is to make sure that we use a <strong>USB 3<\/strong> hub (a USB 2 hub will work but it will be <em>very<\/em> slow).<\/p>\n\n\n\n<p>My setup contains a 4TB 3.5&#8243; WD Elements HDD and three 2TB 2.5&#8243; WD Elements HDDs. I&#8217;ll also test a 1TB Samsung SSD. Your setup will probably be different so you&#8217;ll have to adjust the power requirements we&#8217;ll estimate below for your situation.<\/p>\n\n\n\n<p>In my setup the 3.5&#8243; HDD is self-powered but the SSD and the 2.5&#8243; HDDs are not. Each of the three 2.5&#8243; HDDs consumes up to 3W, for a total of 9W<sup data-fn=\"98985971-dfb7-4d72-9782-d0468f519896\" class=\"fn\"><a href=\"#98985971-dfb7-4d72-9782-d0468f519896\" id=\"98985971-dfb7-4d72-9782-d0468f519896-link\">1<\/a><\/sup>. The RPi can provide at most 6W (1.2A) via USB so the USB hub has to be powered. We may also want to use the SSD so we&#8217;ll include it in this calculation. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Power Requirements for the USB Hub<\/h2>\n\n\n\n<p>How much power the USB hub has to provide will depend on the exact configuration of our NAS. We&#8217;ll certainly use the three 2.5&#8243; HDDs. Let&#8217;s assume for now that we&#8217;ll also use the SSD. The Raspberry Pi could be powered by its own power supply or it could be powered by the USB hub. Let&#8217;s assume for now that the RPi will be powered from the USB hub. Thus, an upper limit for the power necessary for our hardware is given in the following table.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th class=\"has-text-align-left\" data-align=\"left\">Device<\/th><th class=\"has-text-align-center\" data-align=\"center\">Required Power<br>(W Peak)<\/th><th class=\"has-text-align-center\" data-align=\"center\">Required Power<br>(W Average)<\/th><\/tr><\/thead><tbody><tr><td class=\"has-text-align-left\" data-align=\"left\">3 x 2.5&#8243; HDD<\/td><td class=\"has-text-align-center\" data-align=\"center\">9<\/td><td class=\"has-text-align-center\" data-align=\"center\">5<\/td><\/tr><tr><td class=\"has-text-align-left\" data-align=\"left\">1 x SSD<\/td><td class=\"has-text-align-center\" data-align=\"center\">2<\/td><td class=\"has-text-align-center\" data-align=\"center\">2<\/td><\/tr><tr><td class=\"has-text-align-left\" data-align=\"left\">1 x Raspberry Pi 4b<\/td><td class=\"has-text-align-center\" data-align=\"center\">8<\/td><td class=\"has-text-align-center\" data-align=\"center\">7<\/td><\/tr><\/tbody><tfoot><tr><td class=\"has-text-align-left\" data-align=\"left\">Sum<\/td><td class=\"has-text-align-center\" data-align=\"center\">19<\/td><td class=\"has-text-align-center\" data-align=\"center\">14<\/td><\/tr><\/tfoot><\/table><figcaption class=\"wp-element-caption\">Required power in Watt, rounded up to whole numbers.<\/figcaption><\/figure>\n\n\n\n<p>Thus, any USB hub that can provide at least 19W of power will certainly be sufficient for the current hardware of our NAS.<\/p>\n\n\n\n<p>The numbers above are rounded up to whole numbers. For a more detailed look at the power consumption of our final NAS have a look at <a href=\"https:\/\/mpr-projects.com\/index.php\/2023\/12\/19\/rpi-nas-extras-power-consumption\/\" data-type=\"post\" data-id=\"71\">this post<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">USB Hub Comparison<\/h2>\n\n\n\n<p>I&#8217;ve tested five different USB hubs, from cheapest to most expensive:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th class=\"has-text-align-left\" data-align=\"left\">Name<\/th><th class=\"has-text-align-center\" data-align=\"center\">EUR<\/th><\/tr><\/thead><tbody><tr><td class=\"has-text-align-left\" data-align=\"left\">NOVOO Ultra Slim R5 Lite<sup data-fn=\"7e482751-a181-4347-bc6f-9857fe919f88\" class=\"fn\"><a href=\"#7e482751-a181-4347-bc6f-9857fe919f88\" id=\"7e482751-a181-4347-bc6f-9857fe919f88-link\">2<\/a><\/sup><\/td><td class=\"has-text-align-center\" data-align=\"center\">10<\/td><\/tr><tr><td class=\"has-text-align-left\" data-align=\"left\">Vansuny USB Hub Aktiv 3.0 (24W)<\/td><td class=\"has-text-align-center\" data-align=\"center\">19<\/td><\/tr><tr><td class=\"has-text-align-left\" data-align=\"left\">Atolla USB Hub Aktiv 3.0 (20W)<\/td><td class=\"has-text-align-center\" data-align=\"center\">25<\/td><\/tr><tr><td class=\"has-text-align-left\" data-align=\"left\">CSL &#8211; USB Hub 3.2 Gen1 (36W)<\/td><td class=\"has-text-align-center\" data-align=\"center\">40<\/td><\/tr><tr><td class=\"has-text-align-left\" data-align=\"left\">Anker 60W 7-Port USB 3.0 (60W)<\/td><td class=\"has-text-align-center\" data-align=\"center\">65<\/td><\/tr><\/tbody><\/table><figcaption class=\"wp-element-caption\">Euro prices are from when I bought the hubs. Some of the prices seem to change quite frequently. For example, when I returned the Atolla it would have cost EUR 32 to buy.<\/figcaption><\/figure>\n\n\n\n<p>The good news is that if your drive is correctly recognized as a USB 3 device, when connected via a USB hub, then all of them performed equally well in my <em>dd<\/em> tests<sup data-fn=\"582a7490-abb5-49c7-80de-de9c5ac53ed3\" class=\"fn\"><a href=\"#582a7490-abb5-49c7-80de-de9c5ac53ed3\" id=\"582a7490-abb5-49c7-80de-de9c5ac53ed3-link\">3<\/a><\/sup>.<\/p>\n\n\n\n<p>The not so good news is that not all of them reliably recognized my drives as USB 3 devices. The NOVOO, Atolla and the CSL frequently mistook them for USB 2 devices. When that happens any copying is limited to at most 480Mb\/s (60MB\/s). That&#8217;s the theoretical maximum. In my tests I got actual write speeds of roughly 30MB\/s. Repeated unplugging and reinserting worked but that&#8217;s rather cumbersome. So those three devices had to go back.<\/p>\n\n\n\n<p>Both the Vansuny and the Anker reliably recognized my HDDs as USB 3 devices (and they don&#8217;t vary much in terms of transfer speed). Their difference is really in the number of devices they can connect and in the power they can supply.<\/p>\n\n\n\n<p>The Anker has seven ports and is rated for 60W. It has an additional three ports for fast USB charging. If you want to connect a lot of hard drives or use it to power other USB devices then it&#8217;s probably really good. For my specific purpose it felt like it was too much. So that too went back.<\/p>\n\n\n\n<p>The Vansuny has four ports (+two charging ports) and runs with 12V\/2A (=24W), which is sufficient for my setup. So I&#8217;ll be using the Vansunny. There&#8217;s also a version with six ports (+two charging ports) which provides 36W, for those of you who want to add more drives.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Speed Penalty<\/h2>\n\n\n\n<p>There is a little problem with using a USB hub with the Raspberry Pi 4b. To illustrate it let&#8217;s do a quick test. Let&#8217;s connect one of the HDDs directly to the RPi and run the following command.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code>dd if=\/dev\/zero of=nas_mnt\/tempfile bs=1M count=4096 conv=fdatasync status=progress<\/code><\/code><\/pre>\n\n\n\n<p>The <em>dd<\/em> command was not made for speed tests and we&#8217;re not really using it for that but just to illustrate a point<sup data-fn=\"399e6e5a-93e2-4040-af96-376be21261cd\" class=\"fn\"><a href=\"#399e6e5a-93e2-4040-af96-376be21261cd\" id=\"399e6e5a-93e2-4040-af96-376be21261cd-link\">4<\/a><\/sup>. The source of the data we&#8217;re copying is <em>\/dev\/zero<\/em> which provides a constant stream of zeros. This is useful as a source because it can be created very quickly so it won&#8217;t limit the speed of the copy process. Put differently, the speed we can obtain will only be limited by the device we&#8217;re writing to (the HDDs) and by the connection (the USB Hub).  We write 4096 blocks of 1MB each for a total of 4GiB. The option <em>conv=fdatasnyc<\/em> tells <em>dd<\/em> to only return when the data has been written to the disk. Otherwise it would return while some of the data is still in a cache of the disk, which would inflate write speeds.<\/p>\n\n\n\n<p>Let&#8217;s do to the actual test. First we connect a 2.5&#8243; HDD directly to the RPi and copy data to it with the previous command. When it has finished we write down how long it took. Ideally we run the command repeatedly and report the average of our observations. Then we disconnect the HDD, reconnect it via the USB hub and do the same process again. Finally, we&#8217;ll do the same again with the 3.5&#8243; HDD. We get the following results:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th class=\"has-text-align-left\" data-align=\"left\">Device<\/th><th class=\"has-text-align-center\" data-align=\"center\">Direct Connection<br>MB\/s<\/th><th class=\"has-text-align-center\" data-align=\"center\">Via USB Hub<br>MB\/s<\/th><\/tr><\/thead><tbody><tr><td class=\"has-text-align-left\" data-align=\"left\">3.5&#8243; HDD<\/td><td class=\"has-text-align-center\" data-align=\"center\">159<\/td><td class=\"has-text-align-center\" data-align=\"center\">103<\/td><\/tr><tr><td class=\"has-text-align-left\" data-align=\"left\">2.5&#8243; HDD<\/td><td class=\"has-text-align-center\" data-align=\"center\">103<\/td><td class=\"has-text-align-center\" data-align=\"center\">96<\/td><\/tr><\/tbody><\/table><figcaption class=\"wp-element-caption\">The <em>dd<\/em> command was run six times. The first run was discarded. The reported numbers are the average of the remaining five runs, rounded to the next whole number.<\/figcaption><\/figure>\n\n\n\n<p>What happened here? Copying via the USB Hub is slower than without it, especially for the 3.5&#8243; HDD<sup data-fn=\"70dbdd9b-19a8-46f3-ab30-f5790a574977\" class=\"fn\"><a href=\"#70dbdd9b-19a8-46f3-ab30-f5790a574977\" id=\"70dbdd9b-19a8-46f3-ab30-f5790a574977-link\">5<\/a><\/sup>.<\/p>\n\n\n\n<p>It turns out that <em>write bursting<\/em> is disabled when a RPi 4b talks to drives behind a USB hub due to the risk of data corruption (see <a href=\"https:\/\/forums.raspberrypi.com\/viewtopic.php?t=359261&amp;sid=290238d463be0d7b8e2302b63a958654\">here<\/a> for more information). Apparently this is not an issue for the Raspberry Pi 5.<\/p>\n\n\n\n<p>Note, if you get even slower speeds, maybe of the order of 30MB\/s, make sure that your HDD is recognized as a USB 3 device! As mentioned above, some hubs frequently mistake USB 3 capable HDDs as USB 2 devices. To check if it&#8217;s recognized correctly run<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>lsusb -t<\/code><\/pre>\n\n\n\n<p>and make sure that in the line referring to your HDD (<em>Class=Mass Storage<\/em>) it says 5000M, not 480M!<\/p>\n\n\n\n<p>So that&#8217;s it for this post. You should now have enough information to choose a USB Hub that&#8217;s suitable for your NAS! In the next post we&#8217;ll look more closely at HDDs and SSDs.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>Footnotes:<\/p>\n\n\n<ol class=\"wp-block-footnotes\"><li id=\"98985971-dfb7-4d72-9782-d0468f519896\">The 3W represent the peak consumption during spin-up of the disks. During normal operation consumption is lower. However, we should consider the peak consumption in our estimate because when the RPi boots it will also spin up all connected disks, so the peak consumption of all three drives happens roughly at the same time. <a href=\"#98985971-dfb7-4d72-9782-d0468f519896-link\" aria-label=\"Jump to footnote reference 1\">\u21a9\ufe0e<\/a><\/li><li id=\"7e482751-a181-4347-bc6f-9857fe919f88\">I tested this one later, after the original tests with the other four hubs. It doesn&#8217;t have a power supply included but you can add your own by connecting it to the USB-C port. Apart from not reliably recognizing devices as USB 3, when the external power is connected then the hard drives were not recognized at all. I tried with a few different power sources (Laptop PSU, Raspberry Pi PSU, USB charger, and a powerbank) but that made no difference. <a href=\"#7e482751-a181-4347-bc6f-9857fe919f88-link\" aria-label=\"Jump to footnote reference 2\">\u21a9\ufe0e<\/a><\/li><li id=\"582a7490-abb5-49c7-80de-de9c5ac53ed3\">I haven&#8217;t described those tests here because they were among the first tests I did and after restructuring and rewriting these posts I misplaced the actual numbers. There&#8217;s not much to the tests though. I&#8217;m just copying data from the Raspberry Pi to the 3.5&#8243; HDD, which is connected via the respective USB hubs. Then I compare the speed reported by <em>dd<\/em> across the USB hubs. The speeds were roughly identical but much lower than the theoretical maximum of 5Gb\/s (=625MB\/s).  <a href=\"#582a7490-abb5-49c7-80de-de9c5ac53ed3-link\" aria-label=\"Jump to footnote reference 3\">\u21a9\ufe0e<\/a><\/li><li id=\"399e6e5a-93e2-4040-af96-376be21261cd\">Yes, you&#8217;re right this is a speed test, but for the purpose of this illustration <em>dd<\/em> is perfectly appropriate. <a href=\"#399e6e5a-93e2-4040-af96-376be21261cd-link\" aria-label=\"Jump to footnote reference 4\">\u21a9\ufe0e<\/a><\/li><li id=\"70dbdd9b-19a8-46f3-ab30-f5790a574977\">The numbers for the 2.5&#8243; HDD actually look quite good in this test. When I did a slightly different test earlier the 2.5&#8243; HDD experienced a much larger drop. <a href=\"#70dbdd9b-19a8-46f3-ab30-f5790a574977-link\" aria-label=\"Jump to footnote reference 5\">\u21a9\ufe0e<\/a><\/li><\/ol>","protected":false},"excerpt":{"rendered":"<p>Our data has safely reached the RPi via some network connection. Before we can save it onto a hard- or solid-state drive we have to think about how those drives will be connected to the Raspberry Pi. I&#8217;m sure you&#8217;ve noticed that we have two USB 3 ports available on the Raspberry Pi 4b\/5 but [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":755,"comment_status":"open","ping_status":"open","sticky":false,"template":"wp-custom-template-single-with-sidebar-1","format":"standard","meta":{"_eb_attr":"","footnotes":"[{\"content\":\"The 3W represent the peak consumption during spin-up of the disks. During normal operation consumption is lower. However, we should consider the peak consumption in our estimate because when the RPi boots it will also spin up all connected disks, so the peak consumption of all three drives happens roughly at the same time.\",\"id\":\"98985971-dfb7-4d72-9782-d0468f519896\"},{\"content\":\"I tested this one later, after the original tests with the other four hubs. It doesn't have a power supply included but you can add your own by connecting it to the USB-C port. Apart from not reliably recognizing devices as USB 3, when the external power is connected then the hard drives were not recognized at all. I tried with a few different power sources (Laptop PSU, Raspberry Pi PSU, USB charger, and a powerbank) but that made no difference.\",\"id\":\"7e482751-a181-4347-bc6f-9857fe919f88\"},{\"content\":\"I haven't described those tests here because they were among the first tests I did and after restructuring and rewriting these posts I misplaced the actual numbers. There's not much to the tests though. I'm just copying data from the Raspberry Pi to the 3.5\\\" HDD, which is connected via the respective USB hubs. Then I compare the speed reported by <em>dd<\/em> across the USB hubs. The speeds were roughly identical but much lower than the theoretical maximum of 5Gb\/s (=625MB\/s). \",\"id\":\"582a7490-abb5-49c7-80de-de9c5ac53ed3\"},{\"content\":\"Yes, you're right this is a speed test, but for the purpose of this illustration <em>dd<\/em> is perfectly appropriate.\",\"id\":\"399e6e5a-93e2-4040-af96-376be21261cd\"},{\"content\":\"The numbers for the 2.5\\\" HDD actually look quite good in this test. When I did a slightly different test earlier the 2.5\\\" HDD experienced a much larger drop.\",\"id\":\"70dbdd9b-19a8-46f3-ab30-f5790a574977\"}]"},"categories":[3,10],"tags":[9,7,4,5],"class_list":["post-119","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux","category-projects","tag-data-safety","tag-greyhole","tag-linux","tag-raspberry-pi"],"_links":{"self":[{"href":"https:\/\/mpr-projects.com\/index.php\/wp-json\/wp\/v2\/posts\/119","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mpr-projects.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mpr-projects.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mpr-projects.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mpr-projects.com\/index.php\/wp-json\/wp\/v2\/comments?post=119"}],"version-history":[{"count":9,"href":"https:\/\/mpr-projects.com\/index.php\/wp-json\/wp\/v2\/posts\/119\/revisions"}],"predecessor-version":[{"id":1439,"href":"https:\/\/mpr-projects.com\/index.php\/wp-json\/wp\/v2\/posts\/119\/revisions\/1439"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/mpr-projects.com\/index.php\/wp-json\/wp\/v2\/media\/755"}],"wp:attachment":[{"href":"https:\/\/mpr-projects.com\/index.php\/wp-json\/wp\/v2\/media?parent=119"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mpr-projects.com\/index.php\/wp-json\/wp\/v2\/categories?post=119"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mpr-projects.com\/index.php\/wp-json\/wp\/v2\/tags?post=119"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}