{"id":619,"date":"2019-08-11T16:16:40","date_gmt":"2019-08-11T15:16:40","guid":{"rendered":"https:\/\/notiz.comanet.xyz\/?p=619"},"modified":"2019-08-11T16:16:40","modified_gmt":"2019-08-11T15:16:40","slug":"raspberry-pi-4-usb-boot-config-guide-for-ssd-flash-drives","status":"publish","type":"post","link":"https:\/\/notiz.comanet.xyz\/?p=619","title":{"rendered":"Raspberry Pi 4 USB Boot Config Guide for SSD \/ Flash Drives"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">USB Boot Instructions<\/h2>\n\n\n\n<ol class=\"wp-block-list\"><li><strong>Prepare Bootloader SD Card<\/strong> \u2013  Image your SD card with the latest Raspbian 10 \u201cBuster\u201d release (I prefer Raspbian Lite) however you would normally do it.<\/li><li><strong>Prepare SSD \/ Flash Drive<\/strong> \u2013 Image your SSD or Flash Drive.  Make sure you create the empty file named \u201cssh\u201d on the boot partition of <strong>both drives<\/strong>.<\/li><li><strong>Boot \/ Update Raspberry Pi<\/strong> \u2013 Start up your Raspberry Pi with only the SD card in the slot. <strong>After <\/strong>the Pi boots to plug in your SSD \/ Flash drive.<br>Type \u201csudo apt-get update &amp;&amp; sudo apt-get dist-upgrade\u201d to update the system and firmware.<\/li><li><strong>Run sudo blkid<\/strong> \u2013 With your SSD \/ Flash drive plugged in type the command \u201csudo blkid\u201d (example below)<\/li><li><strong>Identify drive<\/strong> \u2013 Your list will contain \/dev\/mmcblk0p1 and 2 (SD card) and your SSD \/ Flash drive (usually\/dev\/sda1 and 2).<br>We\n are looking for the PARTUUID of your flash \/ SSD drive\u2019s second \npartition (rootfs).  This will end with -02.  Here is an example:<br><strong>\/dev\/sda2<\/strong>: LABEL=\u201drootfs\u201d UUID=\u201d638417fb-7220-47b1-883c-e6fee02f51ac\u201d TYPE=\u201dext4\u2033 <strong>PARTUUID=\u201d0634f60c-02\u2033<\/strong><br>Save or white a note somewhere of the values for both drives.  We will use both PARTUUIDs for \/dev\/sda* and dev\/mmcblk* later.<\/li><li><strong>Edit \/boot\/cmdline.txt<\/strong> \u2013 First make a backup by typing: sudo cp \/boot\/cmdline.txt \/boot\/cmdline.txt.bak<br>Now\n type \u201csudo nano \/boot\/cmdline.txt\u201d \u2013 Change your boot command to load \nthe partition from the SSD \/ Flash drive instead of your SD card.<br><strong>Before<\/strong>: dwc_otg.lpm_enable=0 console=serial0,115200 console=tty1 root=<strong>PARTUUID=af1800e7-01<\/strong> rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait<br><strong>After<\/strong>: dwc_otg.lpm_enable=0 console=serial0,115200 console=tty1 root=<strong>PARTUUID=0634f60c-02<\/strong> rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait<\/li><li><strong>Reboot Pi<\/strong> \u2013 If your Pi won\u2019t boot put your micro SD into a computer and restore \/boot\/cmdline.txt.bak to get back into the Pi.<br><strong>Note<\/strong>:\n the first boot with your SSD \/ Flash drive will be slow the first time \nas it runs fsck on the drive and other first boot configuration. <br>It \ncan take over a minute or two sometimes for really big drives so give it\n a little bit of time here before assuming it didn\u2019t work<\/li><li><strong>Update fstab<\/strong>\n \u2013 Change \/etc\/fstab entry for \/boot to point to the SD card to ensure \nthat firmware and bootloader updates retrieved \u2014 detailed \nexample\/instructions in section below<\/li><li><strong>Resize file system<\/strong>\n \u2013 Upon first startup the size of your root (\/) filesystem partition \nwill only be 1.8G no matter how big your drive is \u2014 see section below \nfor detailed example\/instructions<\/li><\/ol>\n\n\n\n<p> Your system will now be \nrunning completely from your USB drive!  To verify this, run the command\n \u201cfindmnt -n -o SOURCE\u201d \/  to ensure your root partition has switched \nover as shown below to \/dev\/sda2 instead of \/dev\/mmcblk0p2.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">pi@raspberrypi:~ $ findmnt -n -o SOURCE \/\n\/dev\/sda2<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Updating fstab<\/h2>\n\n\n\n<p>Right now your fstab file on \nthe USB drive is automounting the \/boot\/ partition from the USB drive \neven though it isn\u2019t being used.  We need to update this to your SD card\n so that firmware\/bootloader updates are actually utilized.<\/p>\n\n\n\n<p>The current file will look similar to this:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">cat \/etc\/fstab\nproc                  \/proc           proc    defaults          0       0\nPARTUUID=<strong>0634f60c-01<\/strong>  \/<strong>boot           <\/strong>vfat    defaults          0       2\nPARTUUID=<strong>0634f60c-02<\/strong>  \/               ext4    defaults,noatime  0       1<\/pre>\n\n\n\n<p>We\n want to change the \/boot partition (ending with -01 to load our SD \ncards PARTUUID instead of the USB drive.  After making the change my \n\/etc\/fstab file looks like this:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">proc                  \/proc           proc    defaults          0       0\nPARTUUID=<strong>af1800e7-01<\/strong>  \/<strong>boot           <\/strong>vfat    defaults          0       2\nPARTUUID=<strong>0634f60c-02<\/strong>  \/               ext4    defaults,noatime  0       1<\/pre>\n\n\n\n<p>Make\n sure the SD card and new drive both have a blank \u201cssh\u201d file if you want\n to keep SSH enabled.  Switching bootloaders will often work fine but if\n you forget this step you\u2019ll try to connect to your Pi and think it\u2019s \ndown when really it just isn\u2019t listening for SSH after changing the \nbootloader without recreating it.<\/p>\n\n\n\n<p>ot.  After reboot typing: \u201cdf \n-H\u201d should show \/boot\/ as being the SD card again (mmcblk0).  Now we can\n be sure that any updates to the \/boot\/ partition from apt-get are \napplying to our system.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Resizing Filesystem<\/h2>\n\n\n\n<p>By default the\n partition on the SSD \/ Flash drive will only be 1.8G.  The Pi expands \nthis automatically on micro SD drives but we will need to do it \nourselves for a SSD \/ Flash drive.  To do this we need to expand the \npartition and then resize the file system.<\/p>\n\n\n\n<p>First let\u2019s open fdisk and print the partitions:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">pi@raspberrypi:~ $ sudo fdisk \/dev\/sda\n\nWelcome to fdisk (util-linux 2.33.1).\nChanges will remain in memory only, until you decide to write them.\nBe careful before using the write command.\nCommand (m for help): <strong>p<\/strong>\n\nDisk \/dev\/sda: 238.5 GiB, 256060514304 bytes, 500118192 sectors\nDisk model: 2115\nUnits: sectors of 1 * 512 = 512 bytes\nSector size (logical\/physical): 512 bytes \/ 512 bytes\nI\/O size (minimum\/optimal): 512 bytes \/ 33553920 bytes\nDisklabel type: dos\nDisk identifier: 0x0634f60c\nDevice     Boot  Start     End Sectors  Size Id Type\n\/dev\/sda1         8192  532480  524289  256M  c W95 FAT32 (LBA)\n<strong>\/dev\/sda2       540672 4292607 3751936  1.8G 83 Linux<\/strong><\/pre>\n\n\n\n<p>There is the line we need.  Our start value for \/dev\/sda2 (rootfs) is <strong>540672<\/strong>.\n  Next we need to remove and recreate the partition as a larger size.  \nIf you make any mistakes during this command just close fdisk by \npressing q.  The changes won\u2019t be written to disk.  If you mess up any \nof the commands the drive will no longer boot and you\u2019ll have to start \nover again so be careful!<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Command (m for help): <strong>d<\/strong>\nPartition number (1,2, default 2): <strong>2<\/strong>\nPartition 2 has been deleted.\nCommand (m for help): <strong>n<\/strong>\nPartition type\n    p   primary (1 primary, 0 extended, 3 free)\n    e   extended (container for logical partitions)\nSelect (default p): <strong>p<\/strong>\nPartition number (2-4, default 2): <strong>2<\/strong>\nFirst sector (532481-500118191, default 589815): <strong>540672<\/strong> <strong>(enter the start value exactly as it was, the default will be wrong)<\/strong>\nLast sector, +\/-sectors or +\/-size{K,M,G,T,P} (540672-500118191, default 500118191): <strong>(press enter to accept default which is the full disk)<\/strong>\nCreated a new partition 2 of type 'Linux' and of size 238.2 GiB.\nPartition #2 contains a ext4 signature.\nDo you want to remove the signature? [Y]es\/[N]o: <strong>n<\/strong> <strong>(don't remove signature)<\/strong><\/pre>\n\n\n\n<p>If\n everything went well then type \u201cw\u201d and press enter.  Otherwise press \n\u201cq\u201d to quit and try again.  Once you enter \u201cw\u201d the changes will be \npermanently written to disk!<\/p>\n\n\n\n<p>Now reboot the system.  Type \u201cdf -h\u201d to view the current disk:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">pi@raspberrypi:~ $ df -h\nFilesystem      Size  Used Avail Use% Mounted on\n<strong>\/dev\/root       1.8G  1.2G  450M  73% \/<\/strong>\ndevtmpfs        866M     0  866M   0% \/dev\ntmpfs           995M     0  995M   0% \/dev\/shm\ntmpfs           995M  8.4M  987M   1% \/run\ntmpfs           5.0M  4.0K  5.0M   1% \/run\/lock\ntmpfs           995M     0  995M   0% \/sys\/fs\/cgroup\n\/dev\/sda1       253M   40M  213M  16% \/boot\ntmpfs           199M     0  199M   0% \/run\/user\/1000<\/pre>\n\n\n\n<p>We can see \nour disk is still 1.8G even after resizing the partition.  That\u2019s \nbecause we still have one more step!  We need to resize the filesystem \nto fill our new partition space.  For this we will use \u201csudo resize2fs \n\/dev\/sda2\u201d:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo resize2fs \/dev\/sda2\nresize2fs 1.44.5 (15-Dec-2018)\nFilesystem at \/dev\/sda2 is mounted on \/; on-line resizing required\nold_desc_blocks = 1, new_desc_blocks = 15\nThe filesystem on \/dev\/sda2 is now 62447190 (4k) blocks long.<\/pre>\n\n\n\n<p>Now let\u2019s check df -h again:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Filesystem      Size  Used Avail Use% Mounted on\n<strong>\/dev\/root       235G  1.2G  224G   1% \/<\/strong>\ndevtmpfs        866M     0  866M   0% \/dev\ntmpfs           995M     0  995M   0% \/dev\/shm\ntmpfs           995M  8.4M  987M   1% \/run\ntmpfs           5.0M  4.0K  5.0M   1% \/run\/lock\ntmpfs           995M     0  995M   0% \/sys\/fs\/cgroup\n\/dev\/sda1       253M   40M  213M  16% \/boot\ntmpfs           199M     0  199M   0% \/run\/user\/1000<\/pre>\n\n\n\n<p>And that\u2019s it!  You will now be using all of your space on your SSD \/ Flash drive.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>USB Boot Instructions Prepare Bootloader SD Card \u2013 Image your SD card with the latest Raspbian 10 \u201cBuster\u201d release (I prefer Raspbian Lite) however you would normally do it. Prepare SSD \/ Flash Drive \u2013 Image your SSD or Flash Drive. Make sure you create the empty file named \u201cssh\u201d on the boot partition of&#8230;<\/p>\n","protected":false},"author":1,"featured_media":620,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,6],"tags":[],"class_list":["post-619","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-how-to-s","category-linux"],"_links":{"self":[{"href":"https:\/\/notiz.comanet.xyz\/index.php?rest_route=\/wp\/v2\/posts\/619","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/notiz.comanet.xyz\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/notiz.comanet.xyz\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/notiz.comanet.xyz\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/notiz.comanet.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=619"}],"version-history":[{"count":1,"href":"https:\/\/notiz.comanet.xyz\/index.php?rest_route=\/wp\/v2\/posts\/619\/revisions"}],"predecessor-version":[{"id":621,"href":"https:\/\/notiz.comanet.xyz\/index.php?rest_route=\/wp\/v2\/posts\/619\/revisions\/621"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/notiz.comanet.xyz\/index.php?rest_route=\/wp\/v2\/media\/620"}],"wp:attachment":[{"href":"https:\/\/notiz.comanet.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=619"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/notiz.comanet.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=619"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/notiz.comanet.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=619"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}