[{"data":1,"prerenderedAt":898},["ShallowReactive",2],{"$f2kpws2ma6aiec":3},{"title":4,"date":5,"tags":6,"categories":9,"draft":11,"_id":12,"slug":13,"path":14,"document":15,"excerpt":896,"readingTimeMinutes":897},"Create a Persistent Arch Linux Bootable USB with Vagrant","2020-01-09T00:00:00.000Z",[7,8],"vagrant","archlinux",[10],"linux",false,"content:blog:persistent-archlinux-usb","persistent-archlinux-usb","\u002Fblog\u002Fpersistent-archlinux-usb",{"frontmatter":16,"meta":17,"nodes":18},{},{},[19,23,27,32,61,65,70,81,107,114,129,159,221,228,239,399,403,411,416,432,504,508,518,544,558,584,588,625,668,672,681,710,729,743,762,765,771,775,792,810,814,873,876,878,880,882,884,886,888,890,892,894],[20,21,22],"p",{},"When installing a linux distribution, it is common for the instructions to have\nthe user create a bootable USB, boot from the device, and proceed with the\ninstallation procedure from that live medium. However, this blog post will\noutline an alternative approach where a virtual machine created with Vagrant\nwill be used in favor of the live medium.",[24,25,26],null,{},"more",[28,29,31],"h1",{"id":30},"preface","Preface",[20,33,34,35,39,40,60],{},"The original intention was to use Docker for this process -- leveraging the\n",[36,37,38],"code",{},"--device"," flag and mounting the target USB device in the Docker container,\nbut the underlying hypervisor in Docker Desktop for Mac does not support this.\n",[41,42,46,51,52,51,56],"sup",{"$":43},{"html":44,"block":45},1,0,[47,48,50],"a",{"href":49},"https:\u002F\u002Fdocs.docker.com\u002Fdocker-for-mac\u002Fdocker-toolbox\u002F","1"," ",[47,53,55],{"href":54},"https:\u002F\u002Fgithub.com\u002Fmoby\u002Fhyperkit","2",[47,57,59],{"href":58},"https:\u002F\u002Fgithub.com\u002Fdocker\u002Ffor-mac\u002Fissues\u002F900","3"," While there are workarounds using Docker\nMachine, Vagrant felt like the path of least resistance.",[28,62,64],{"id":63},"instructions","Instructions",[66,67,69],"h2",{"id":68},"create-an-arch-linux-virtual-machine-with-vagrant","Create an Arch Linux Virtual Machine with Vagrant",[20,71,72,73,80],{},"Get the latest Arch Linux image ",[41,74,76],{"$":75},{"html":44,"block":45},[47,77,79],{"href":78},"https:\u002F\u002Fapp.vagrantup.com\u002Farchlinux\u002Fboxes\u002Farchlinux","4"," from the Vagrant Cloud Box\nCatalog.",[82,83,86],"pre",{"language":84,"class":85},"bash","shiki shiki-themes tokyo-night dark:tokyo-night",[36,87,89],{"class":88},"language-bash",[90,91,94,97,101,104],"span",{"class":92,"style":93},"line","display: inline",[90,95,7],{"style":96},"color:#C0CAF5",[90,98,100],{"style":99},"color:#9ECE6A"," box",[90,102,103],{"style":99}," add",[90,105,106],{"style":99}," archlinux\u002Farchlinux",[20,108,109,110,113],{},"Determine the USB vendor information for the thumb-drive that we will\npass-through to the virtual machine. Using the ",[36,111,112],{},"VBoxManage"," utility that comes\nwith Virtual Box, list the devices, and make note of the Vendor and Product ID.",[82,115,116],{"language":84,"class":85},[36,117,118],{"class":88},[90,119,120,123,126],{"class":92,"style":93},[90,121,122],{"style":96}," VBoxManage",[90,124,125],{"style":99}," list",[90,127,128],{"style":99}," usbhost",[20,130,131,132,135,136,139,140,151,152,155,156,158],{},"Create a ",[36,133,134],{},"Vagrantfile"," with ",[36,137,138],{},"archlinx\u002Farchlinux"," as the target box, and the USB\ndevice information that is passed through. ",[41,141,143,51,147],{"$":142},{"html":44,"block":45},[47,144,146],{"href":145},"https:\u002F\u002Fantonyjepson.wordpress.com\u002F2012\u002F01\u002F26\u002Fquickly-attaching-usb-devices-to-virtualbox-guests-using-vboxmanage\u002F","5",[47,148,150],{"href":149},"https:\u002F\u002Fgist.github.com\u002Fdscape\u002F7d829c0c116ef419f963","6"," Vagrant\noffers a handy customization parameter ",[36,153,154],{},"vb.customize"," that calls the\n",[36,157,112],{}," command under-the-hood, allowing one to enable the guest machine\nto access the host machine's USB devices.",[82,160,162],{"language":161,"class":85},"txt",[36,163,165,170,171,170,176,170,181,170,186,170,191,170,196,170,201,170,206,170,211,170,216],{"class":164},"language-txt",[90,166,167],{"class":92,"style":93},[90,168,169],{},"# -*- mode: ruby -*-","\n",[90,172,173],{"class":92,"style":93},[90,174,175],{},"# vi: set ft=ruby :",[90,177,178],{"class":92,"style":93},[90,179,180],{},"",[90,182,183],{"class":92,"style":93},[90,184,185],{},"Vagrant.configure(\"2\") do |config|",[90,187,188],{"class":92,"style":93},[90,189,190],{},"  config.vm.box = \"archlinux\u002Farchlinux\"",[90,192,193],{"class":92,"style":93},[90,194,195],{},"  config.vm.provider \"virtualbox\" do |vb|",[90,197,198],{"class":92,"style":93},[90,199,200],{},"    vb.name = \"archlinux\"",[90,202,203],{"class":92,"style":93},[90,204,205],{},"    vb.customize ['modifyvm', :id, '--usb', 'on']",[90,207,208],{"class":92,"style":93},[90,209,210],{},"    vb.customize ['usbfilter', 'add', '1', '--target', :id, '--name', 'SanDisk Ultra Fit', '--vendorid', '0x0781', '--productid', '0x5583']",[90,212,213],{"class":92,"style":93},[90,214,215],{},"  end",[90,217,218],{"class":92,"style":93},[90,219,220],{},"end",[20,222,223,224,227],{},"When virtual machine is brought up, the ",[36,225,226],{},"usbfilter"," is applied, and the guest\nis able to access to the host machine's USB device that was specified in the\nfilter.",[20,229,230,231,234,235,238],{},"Start the machine, ",[36,232,233],{},"ssh"," into the guest, and list the devices to confirm that\nthe USB device is available (see: ",[36,236,237],{},"\u002Fdev\u002Fsdb",").",[82,240,241],{"language":84,"class":85},[36,242,243,170,254,170,263,170,279,170,302,170,323,170,344,170,364,170,382],{"class":88},[90,244,245,248,251],{"class":92,"style":93},[90,246,247],{"style":96},"$",[90,249,250],{"style":99}," vagrant",[90,252,253],{"style":99}," up",[90,255,256,258,260],{"class":92,"style":93},[90,257,247],{"style":96},[90,259,250],{"style":99},[90,261,262],{"style":99}," ssh",[90,264,265,269,273,276],{"class":92,"style":93},[90,266,268],{"style":267},"color:#89DDFF","[",[90,270,272],{"style":271},"color:#A9B1D6","vagrant@archlinux ",[90,274,275],{"style":267},"~]",[90,277,278],{"style":271},"$ lsblk",[90,280,281,284,287,290,293,296,299],{"class":92,"style":93},[90,282,283],{"style":96},"NAME",[90,285,286],{"style":99},"   MAJ:MIN",[90,288,289],{"style":99}," RM",[90,291,292],{"style":99},"  SIZE",[90,294,295],{"style":99}," RO",[90,297,298],{"style":99}," TYPE",[90,300,301],{"style":99}," MOUNTPOINT",[90,303,304,307,310,314,317,320],{"class":92,"style":93},[90,305,306],{"style":96},"sda",[90,308,309],{"style":99},"      8:0",[90,311,313],{"style":312},"color:#FF9E64","    0",[90,315,316],{"style":99},"   20G",[90,318,319],{"style":312},"  0",[90,321,322],{"style":99}," disk",[90,324,325,328,331,333,336,338,341],{"class":92,"style":93},[90,326,327],{"style":96},"├─sda1",[90,329,330],{"style":99},"   8:1",[90,332,313],{"style":312},[90,334,335],{"style":99},"  1.9G",[90,337,319],{"style":312},[90,339,340],{"style":99}," part",[90,342,343],{"style":271}," [SWAP]",[90,345,346,349,352,354,357,359,361],{"class":92,"style":93},[90,347,348],{"style":96},"└─sda2",[90,350,351],{"style":99},"   8:2",[90,353,313],{"style":312},[90,355,356],{"style":99}," 18.1G",[90,358,319],{"style":312},[90,360,340],{"style":99},[90,362,363],{"style":99}," \u002F",[90,365,366,369,372,375,378,380],{"class":92,"style":93},[90,367,368],{"style":96},"sdb",[90,370,371],{"style":99},"      8:16",[90,373,374],{"style":312},"   1",[90,376,377],{"style":99}," 28.7G",[90,379,319],{"style":312},[90,381,322],{"style":99},[90,383,384,387,390,392,395,397],{"class":92,"style":93},[90,385,386],{"style":96},"└─sdb1",[90,388,389],{"style":99},"   8:17",[90,391,374],{"style":312},[90,393,394],{"style":99},"    8G",[90,396,319],{"style":312},[90,398,340],{"style":99},[66,400,402],{"id":401},"install-arch-linux-on-the-usb-drive","Install Arch Linux on the USB Drive",[20,404,405,406,410],{},"The ",[47,407,409],{"href":408},"https:\u002F\u002Fwiki.archlinux.org\u002Findex.php\u002FInstallation_guide","Arch Linux Installation Guide"," outlines the installation procedure in\ngreat detail -- the following steps follow this closely with a few alteration\ndue to installing onto removable media.",[412,413,415],"h3",{"id":414},"install-arch-linux-on-the-usb-drive-partition-the-disk-uefi-with-gpt","Partition the Disk (UEFI with GPT)",[82,417,418],{"language":84,"class":85},[36,419,420],{"class":88},[90,421,422,424,427,429],{"class":92,"style":93},[90,423,268],{"style":267},[90,425,426],{"style":271},"root@archlinux ",[90,428,275],{"style":267},[90,430,431],{"style":271},"# fdisk \u002Fdev\u002Fsdb",[82,433,434],{"language":161,"class":85},[36,435,436,170,441,170,446,170,451,170,456,170,461,170,466,170,471,170,476,170,480,170,485,170,490,170,495,170,499],{"class":164},[90,437,438],{"class":92,"style":93},[90,439,440],{},"Command (m for help): p",[90,442,443],{"class":92,"style":93},[90,444,445],{},"Disk \u002Fdev\u002Fsdb: 28.66 GiB, 30752636928 bytes, 60063744 sectors",[90,447,448],{"class":92,"style":93},[90,449,450],{},"Disk model: Ultra Fit",[90,452,453],{"class":92,"style":93},[90,454,455],{},"Units: sectors of 1 * 512 = 512 bytes",[90,457,458],{"class":92,"style":93},[90,459,460],{},"Sector size (logical\u002Fphysical): 512 bytes \u002F 512 bytes",[90,462,463],{"class":92,"style":93},[90,464,465],{},"I\u002FO size (minimum\u002Foptimal): 512 bytes \u002F 512 bytes",[90,467,468],{"class":92,"style":93},[90,469,470],{},"Disklabel type: gpt",[90,472,473],{"class":92,"style":93},[90,474,475],{},"Disk identifier: E1D6C445-1B79-AB4D-A442-FA4AD6DF4ECC",[90,477,478],{"class":92,"style":93},[90,479,180],{},[90,481,482],{"class":92,"style":93},[90,483,484],{},"Device       Start      End  Sectors  Size Type",[90,486,487],{"class":92,"style":93},[90,488,489],{},"\u002Fdev\u002Fsdb1     2048  1050623  1048576  512M EFI System",[90,491,492],{"class":92,"style":93},[90,493,494],{},"\u002Fdev\u002Fsdb2  1050624 60063710 59013087 28.1G Linux filesystem",[90,496,497],{"class":92,"style":93},[90,498,180],{},[90,500,501],{"class":92,"style":93},[90,502,503],{},"Filesystem\u002FRAID signature on partition 1 will be wiped.",[412,505,507],{"id":506},"install-arch-linux-on-the-usb-drive-format-the-partitions","Format the Partitions",[20,509,510,511],{},"The UEFI specification mandates support for FAT file-systems, and FAT32 is\nrecommended for removable media. ",[41,512,514],{"$":513},{"html":44,"block":45},[47,515,517],{"href":516},"https:\u002F\u002Fwiki.archlinux.org\u002Findex.php\u002FEFI_system_partition#Format_the_partition","7",[82,519,520],{"language":84,"class":85},[36,521,522,170,533],{"class":88},[90,523,524,526,528,530],{"class":92,"style":93},[90,525,268],{"style":267},[90,527,426],{"style":271},[90,529,275],{"style":267},[90,531,532],{"style":271},"# pacman -Sy dosfstools",[90,534,535,537,539,541],{"class":92,"style":93},[90,536,268],{"style":267},[90,538,426],{"style":271},[90,540,275],{"style":267},[90,542,543],{"style":271},"# mkfs.fat -F32 \u002Fdev\u002Fsdb1",[20,545,546,547,550,551],{},"As for the root partition, it is recommended to use ",[36,548,549],{},"ext4"," without a journal to\nreduce the reads and writes to the file-system as this is detrimental to the\nflash-based USB drive. ",[41,552,554],{"$":553},{"html":44,"block":45},[47,555,557],{"href":556},"https:\u002F\u002Fwiki.archlinux.org\u002Findex.php\u002FInstall_Arch_Linux_on_a_USB_key#Installation_tweaks","8",[82,559,560],{"language":84,"class":85},[36,561,562],{"class":88},[90,563,564,566,568,570,573,576,579,581],{"class":92,"style":93},[90,565,268],{"style":267},[90,567,426],{"style":271},[90,569,275],{"style":267},[90,571,572],{"style":271},"# mkfs.ext4 -O ",[90,574,575],{"style":267},"\"",[90,577,578],{"style":99},"^has_journal",[90,580,575],{"style":267},[90,582,583],{"style":271}," \u002Fdev\u002Fsdb2",[412,585,587],{"id":586},"install-arch-linux-on-the-usb-drive-mount-the-partitions-and-bootstrap-the-environment","Mount the Partitions and Bootstrap the Environment",[82,589,590],{"language":84,"class":85},[36,591,592,170,603,170,614],{"class":88},[90,593,594,596,598,600],{"class":92,"style":93},[90,595,268],{"style":267},[90,597,426],{"style":271},[90,599,275],{"style":267},[90,601,602],{"style":271},"# mount \u002Fdev\u002Fsdb2 \u002Fmnt",[90,604,605,607,609,611],{"class":92,"style":93},[90,606,268],{"style":267},[90,608,426],{"style":271},[90,610,275],{"style":267},[90,612,613],{"style":271},"# mkdir -p \u002Fmnt\u002Fboot\u002Fefi",[90,615,616,618,620,622],{"class":92,"style":93},[90,617,268],{"style":267},[90,619,426],{"style":271},[90,621,275],{"style":267},[90,623,624],{"style":271},"# mount \u002Fdev\u002Fsdb1 \u002Fmnt\u002Fboot\u002Fefi",[82,626,627],{"language":84,"class":85},[36,628,629,170,640,170,651],{"class":88},[90,630,631,633,635,637],{"class":92,"style":93},[90,632,268],{"style":267},[90,634,426],{"style":271},[90,636,275],{"style":267},[90,638,639],{"style":271},"# pacman -S arch-install-scripts",[90,641,642,644,646,648],{"class":92,"style":93},[90,643,268],{"style":267},[90,645,426],{"style":271},[90,647,275],{"style":267},[90,649,650],{"style":271},"# pacstrap \u002Fmnt base linux linux-firmware",[90,652,653,655,657,659,662,665],{"class":92,"style":93},[90,654,268],{"style":267},[90,656,426],{"style":271},[90,658,275],{"style":267},[90,660,661],{"style":271},"# genfstab -U \u002Fmnt ",[90,663,664],{"style":267},">>",[90,666,667],{"style":271}," \u002Fmnt\u002Fetc\u002Ffstab",[412,669,671],{"id":670},"install-arch-linux-on-the-usb-drive-configure-the-new-environment","Configure the New Environment",[82,673,674],{"class":85},[36,675,676],{},[90,677,678],{"class":92,"style":93},[90,679,680],{},"[root@archlinux ~]# arch-chroot \u002Fmnt",[82,682,683],{"class":85},[36,684,685,170,690,170,695,170,700,170,705],{},[90,686,687],{"class":92,"style":93},[90,688,689],{},"[root@archlinux \u002F]# ln -sf \u002Fusr\u002Fshare\u002Fzoneinfo\u002FUS\u002FEastern \u002Fetc\u002Flocaltime",[90,691,692],{"class":92,"style":93},[90,693,694],{},"[root@archlinux \u002F]# hwclock --systohc",[90,696,697],{"class":92,"style":93},[90,698,699],{},"[root@archlinux \u002F]# sed -i 's\u002F#en_US.UTF-8\u002Fen_US.UTF-8\u002F' \u002Fetc\u002Flocale.gen",[90,701,702],{"class":92,"style":93},[90,703,704],{},"[root@archlinux \u002F]# locale-gen",[90,706,707],{"class":92,"style":93},[90,708,709],{},"[root@archlinux \u002F]# echo \"LANG=en_US.UTF-8\" > \u002Fetc\u002Flocale.conf",[82,711,712],{"class":85},[36,713,714,170,719,170,724],{},[90,715,716],{"class":92,"style":93},[90,717,718],{},"[root@archlinux \u002F]# hostnamectl set-hostname usb",[90,720,721],{"class":92,"style":93},[90,722,723],{},"[root@archlinux \u002F]# echo \"127.0.0.1        localhost\" >> \u002Fetc\u002Fhosts",[90,725,726],{"class":92,"style":93},[90,727,728],{},"[root@archlinux \u002F]# echo \"::1              localhost\" >> \u002Fetc\u002Fhosts",[20,730,731,732,735,736],{},"Note, one difference here from a standard installation is that the\n",[36,733,734],{},"--removable"," flag is specified when installing the GRUB bootloader.\n",[41,737,739],{"$":738},{"html":44,"block":45},[47,740,742],{"href":741},"https:\u002F\u002Fwiki.archlinux.org\u002Findex.php\u002FGRUB#UEFI_systems","10",[82,744,745],{"class":85},[36,746,747,170,752,170,757],{},[90,748,749],{"class":92,"style":93},[90,750,751],{},"[root@archlinux \u002F]# pacman -S grub",[90,753,754],{"class":92,"style":93},[90,755,756],{},"[root@archlinux \u002F]# grub-install --target=x86_64-efi --efi-directory=\u002Fboot\u002Fefi  --removable --recheck",[90,758,759],{"class":92,"style":93},[90,760,761],{},"[root@usb \u002F]# grub-mkconfig -o \u002Fboot\u002Fgrub\u002Fgrub.cfg",[20,763,764],{},"Shutdown the virtual machine, restart the host machine, and boot the newly\ncreated Arch Linux thumb-drive!",[20,766,767,770],{},[768,769],"tada",{},":",[66,772,774],{"id":773},"side-note","Side-note",[20,776,777,778,781,782,784,785],{},"It was attempted to use the ",[36,779,780],{},"controlvm usbattach"," command to pass the USB\ndevice to the guest machine, but this did not work as it expects the virtual\nmachine to already be running, and the ",[36,783,154],{}," option runs prior to\nbooting the machine. ",[41,786,788],{"$":787},{"html":44,"block":45},[47,789,791],{"href":790},"https:\u002F\u002Fwww.vagrantup.com\u002Fdocs\u002Fvirtualbox\u002Fconfiguration.html#vboxmanage-customizations","11",[82,793,794],{"language":161,"class":85},[36,795,796,170,801,170,805],{"class":164},[90,797,798],{"class":92,"style":93},[90,799,800],{},"Command: [\"controlvm\", \"060a716b-1965-49e2-bc56-12beed5df716\", \"usbattach36fc9e60-c465-11cf-8056-444553540000\"]",[90,802,803],{"class":92,"style":93},[90,804,180],{},[90,806,807],{"class":92,"style":93},[90,808,809],{},"Stderr: VBoxManage.exe: error: Machine '060a716b-1965-49e2-bc56-12beed5df716' is not currently running.",[66,811,813],{"id":812},"references","References",[815,816,817,823,828,833,838,843,848,853,858,863,868],"ol",{},[818,819,820],"li",{},[47,821,822],{"href":49},"Docker Desktop on Mac vs. Docker Toolbox",[818,824,825],{},[47,826,827],{"href":54},"GitHub - HyperKit",[818,829,830],{},[47,831,832],{"href":58},"GitHub - Docker for Mac - Issue #900",[818,834,835],{},[47,836,837],{"href":78},"Vagrant Cloud - Arch Linux",[818,839,840],{},[47,841,842],{"href":145},"Attaching USB Devices to VirtualBox Guests using VBoxManage",[818,844,845],{},[47,846,847],{"href":149},"GitHub Gist - Vagrant USB Filter",[818,849,850],{},[47,851,852],{"href":516},"Arch Linux Wiki - EFI System Partition - Format Partitions",[818,854,855],{},[47,856,857],{"href":556},"Arch Linux Wiki - Arch Linux on USB - Installation Tweaks",[818,859,860],{},[47,861,862],{"href":408},"Arch Linux Wiki - Installation Guide",[818,864,865],{},[47,866,867],{"href":741},"Arch Linux Wiki - GRUB - UEFI Systems",[818,869,870],{},[47,871,872],{"href":790},"Vagrant VBoxManage Customizations ",[874,875],"component",{},[874,877],{},[874,879],{},[874,881],{},[874,883],{},[874,885],{},[874,887],{},[874,889],{},[874,891],{},[874,893],{},[874,895],{},"When installing a linux distribution, it is common for the instructions to have the user create a bootable USB, boot from the device, and proceed with the installation procedure from that live medium. However, this blog post will outline an alternative approach where a virtual machine created with Vagrant will be used in favor of the live medium.",4,1790648870526]