{"id":210,"date":"2011-12-29T09:49:13","date_gmt":"2011-12-29T15:49:13","guid":{"rendered":"http:\/\/www.alandmoore.com\/blog\/?p=210"},"modified":"2011-12-29T09:49:13","modified_gmt":"2011-12-29T15:49:13","slug":"how-to-install-debian-offline","status":"publish","type":"post","link":"https:\/\/alandmoore.com\/blog\/2011\/12\/29\/how-to-install-debian-offline\/","title":{"rendered":"How to  install Debian offline"},"content":{"rendered":"<p>When tinkering with old computers, there is little about an operating system quite as endearing as flexibility at install time. \u00a0The &#8220;<a title=\"DEBIAN!!\" href=\"http:\/\/www.debian.org\">Universal Operating System<\/a>&#8221; is no slouch in this regard; the Debian installer will work quite happily from CD, DVD, USB drive, \u00a0PXE boot (my personal fav), and even a <a title=\"debian.exe.  Who'da thunkit?\" href=\"http:\/\/www.goodbye-windows.com\/downloads\/debian\/\">Windows executable<\/a>.<\/p>\n<p>But what if none of those is an option? \u00a0Suppose you&#8217;re stuck with a system with no optical media, no USB boot, no PXE boot, and no OS? \u00a0Can we get Debian on such a machine?<\/p>\n<p>You bet we can! \u00a0<!--more--><\/p>\n<h2>Tools<\/h2>\n<p>Of course, we can&#8217;t do it without some extra tools. \u00a0So here are some things we&#8217;re going to need:<\/p>\n<ul>\n<li>A working system (laptop, desktop, netbook, etc) running some kind of Debian-based OS (Debian, Ubuntu, Mint, Mepis, etc).<\/li>\n<li>A USB hard drive enclosure, or some way to mount the target computer&#8217;s hard drive on the working system.<\/li>\n<li>A broadband internet connection<\/li>\n<li>Probably a phillips-head screwdriver.<\/li>\n<li>A distinct lack of discomfort with the command-line, or at least command-line package management.<\/li>\n<\/ul>\n<div><\/div>\n<h2>Pre-prep<\/h2>\n<p>Before we can install, we need access to the target system&#8217;s hard drive on our working system. \u00a0So open up the case and remove the hard drive (this is where the screwdriver probably comes in).<\/p>\n<div style=\"width: 310px\" class=\"wp-caption alignleft\"><a href=\"http:\/\/en.wikipedia.org\/wiki\/Disk_enclosure\"><img loading=\"lazy\" decoding=\"async\" title=\"Hard disk enclosure, courtesy of wikipedia\" src=\"http:\/\/upload.wikimedia.org\/wikipedia\/commons\/thumb\/e\/e2\/Usb_firewire_hard_disk_enclosure.jpg\/300px-Usb_firewire_hard_disk_enclosure.jpg\" alt=\"Hard disk enclosure\" width=\"300\" height=\"227\" \/><\/a><p class=\"wp-caption-text\">A hard drive in a typical USB enclosure, courtesy of Wikipedia<\/p><\/div>\n<p>Next, we need to attach that hard drive to our working system. \u00a0Since we&#8217;re probably installing on an old computer here (read: PATA\/IDE drive) and our working system is probably a newer computer (read: SATA connectors only) or laptop (read: no connectors), this is where the USB enclosure comes in. \u00a0These devices are cheap ($20-$30 US), so there&#8217;s no reason not to have one if you do this kind of tinkering often.<\/p>\n<p>Once the drive is installed in the enclosure, hook it in to your working computer.<\/p>\n<h3 style=\"clear: both;\">A <em>critically important<\/em> bit of information<\/h3>\n<p>At this point, we need to figure out which <strong>device name<\/strong> is assigned to the attached drive. \u00a0Depending on your distribution and desktop environment, and if there are any partitions on the drive, you may see a the device listed in your file manager or get a pop-up notification about new devices. \u00a0If not, you probably need to check dmesg, or run &#8220;sudo fdisk -l&#8221; to determine what the device name is.<\/p>\n<p>If you have only one hard drive in your system, the device name is <em>probably<\/em>\u00a0going to be &#8220;\/dev\/sdb&#8221;, but <strong>make sure you know absolutely for certain<\/strong>\u00a0before moving on with this procedure. \u00a0Using the wrong device name will at best just not work, and at worst destroy data on your working system.<\/p>\n<p>For the purposes of this article, I&#8217;m going to assume the device name is &#8220;\/dev\/sdb&#8221;. \u00a0If you see that in any commands, replace it with the device name you find here.<\/p>\n<h3>Install packages<\/h3>\n<p>The most important package we&#8217;ll need (which is probably not already on your system) is\u00a0<strong>debootstrap<\/strong>. \u00a0 It should be readily available in your Debian\/Ubuntu repositories, so go ahead and install it now. \u00a0Depending on what tools you prefer for partitioning drives, you also might want to grab <strong>gparted<\/strong>\u00a0while you&#8217;re mucking about in the package manager.<\/p>\n<h2>Installation<\/h2>\n<h3>\u00a0Step 1: partition and format the drive<\/h3>\n<p>Our first step is to create a root partition on this drive and format it appropriately. \u00a0You can use any partitioning tool you feel comfortable with, such as fdisk or cfdisk; but if you&#8217;re new to this you might want to stick with friendly, graphical gparted.<\/p>\n<div id=\"attachment_213\" style=\"width: 220px\" class=\"wp-caption alignright\"><a href=\"https:\/\/alandmoore.com\/blog2\/wp-content\/uploads\/2011\/12\/gparted1.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-213\" class=\" wp-image-213 \" title=\"Gparted blank disk\" src=\"https:\/\/alandmoore.com\/blog2\/wp-content\/uploads\/2011\/12\/gparted1-300x211.png\" alt=\"Gparted blank disk\" width=\"210\" height=\"148\" srcset=\"https:\/\/alandmoore.com\/blog\/wp-content\/uploads\/2011\/12\/gparted1-300x211.png 300w, https:\/\/alandmoore.com\/blog\/wp-content\/uploads\/2011\/12\/gparted1.png 859w\" sizes=\"auto, (max-width: 210px) 100vw, 210px\" \/><\/a><p id=\"caption-attachment-213\" class=\"wp-caption-text\">Gparted with a blank disk<\/p><\/div>\n<p>Depending on the size of your disk, and how much you plan to install on this system, you want to create a root partition of at least 3 GB and at most 20 GB. \u00a0If you&#8217;ve no interest in making a separate home partition or dual-booting this computer, go ahead an use the whole drive minus a GB or so for swap.<\/p>\n<p>Choose ext4 for the formatting (or your favorite filesystem, if you care about such things), and then make sure to create an appropriately-sized swap partition.<\/p>\n<p>My partitioned drive is shown here (click for larger image):<\/p>\n<div id=\"attachment_214\" style=\"width: 220px\" class=\"wp-caption alignleft\"><a href=\"https:\/\/alandmoore.com\/blog2\/wp-content\/uploads\/2011\/12\/gparted2.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-214\" class=\" wp-image-214  \" title=\"Partitioned Drive\" src=\"https:\/\/alandmoore.com\/blog2\/wp-content\/uploads\/2011\/12\/gparted2-300x211.png\" alt=\"Partitioned Drive\" width=\"210\" height=\"148\" srcset=\"https:\/\/alandmoore.com\/blog\/wp-content\/uploads\/2011\/12\/gparted2-300x211.png 300w, https:\/\/alandmoore.com\/blog\/wp-content\/uploads\/2011\/12\/gparted2.png 859w\" sizes=\"auto, (max-width: 210px) 100vw, 210px\" \/><\/a><p id=\"caption-attachment-214\" class=\"wp-caption-text\">This is the partitioned drive. Note the &quot;flags&quot; field<\/p><\/div>\n<p>&nbsp;<\/p>\n<p>One important note: \u00a0it&#8217;s critical here to set the <strong>boot flag<\/strong>\u00a0on the root partition. \u00a0Without this, some machines just won&#8217;t boot. \u00a0In gparted, just right-click the partition after it&#8217;s been created and select &#8220;manage flags&#8221;. \u00a0Then check the &#8220;boot&#8221; option and apply.<\/p>\n<h3 style=\"clear: both;\">Step 2: create the base install<\/h3>\n<p>Now that our drive is formatted, we need to put some data on it. \u00a0Most of what follows will need root priveleges, so either log in as root (if your distro will do that), or prepend all these steps with sudo.<\/p>\n<ol>\n<li>Mount the drive. \u00a0I&#8217;m mounting it to \/media\/sdb1 here:\n<pre lang=\"bash\">mkdir \/media\/sdb1 && mount \/dev\/sdb1 \/media\/sdb1<\/pre>\n<\/li>\n<li>CD to the mount point. \u00a0Now we&#8217;re going to run the debootstrap command. \u00a0This cool little command downloads and sets up a nearly-complete install of Debian in any directory we specify. \u00a0We can specify any release or architecture as well. \u00a0Here we&#8217;ll specify the <strong>stable<\/strong>\u00a0release on an <strong>i386<\/strong>\u00a0architecture:\n<pre lang=\"bash\">debootstrap --arch=i386 stable \/media\/sdb1\/<\/pre>\n<p>This usually take a while to run, depending on connection speed and other factors.<\/li>\n<li>The man page for debootstrap lists a ton of other options, such as options to use certain templates, use local APT mirrors, exclude or include a list of packages, etc. \u00a0Read through it as you wait for the system to finish downloading. \u00a0 When debootstrap finishes, move on to the next step.<\/li>\n<\/ol>\n<h3>Step 3: install a kernel and bootloader<\/h3>\n<p>The debootstrap command creates a base install, but doesn&#8217;t actually install a kernel or bootloader. \u00a0This may seem odd, but there are reasons for it I won&#8217;t go into right now. \u00a0Not a problem, though, we just need to install them.<\/p>\n<h4>Chroot<\/h4>\n<p>The first thing we need to do is get into the new environment so we can run commands in it. \u00a0This is where the <strong>chroot\u00a0<\/strong>command comes in. \u00a0If you&#8217;ve never used chroot before, it&#8217;s a little brain-bending. \u00a0What we&#8217;re going to do is <em>ch<\/em>ange the <em>root<\/em>\u00a0of our shell to a new directory, so that whatever commands or \u00a0actions we take are done as if this new directory is the root of the filesystem and everything above it is invisible.<\/p>\n<p>Of course, that also makes certain important directories like \/proc, \/dev, and \/sys unavailable, so we need to deal with that too. \u00a0The following sequence of commands takes care of all that (run as root, of course):<\/p>\n<pre lang=\"bash\">cd \/media\/sdb1\r\nmount --bind \/proc proc\r\nmount --bind \/dev dev\r\nmount --bind \/sys sys\r\nchroot .<\/pre>\n<p>You might notice at this point that the prompt has changed, and now you&#8217;re in your new environment. You can verify this by examining \/etc\/issue (to view the OS &amp; release) or \/boot (which should be empty). You can now run aptitude to install packages.<\/p>\n<h4>Installing packages<\/h4>\n<p>Let&#8217;s start with our kernel and bootloader:<\/p>\n<pre lang=\"bash\">aptitude update\r\naptitude install linux-image-486 grub-pc<\/pre>\n<p>Make sure you install grub to the correct device! In my case this was \/dev\/sdb, of course. Also, note that I installed the 486 kernel image; if your target computer is a Pentium II or newer, you can install the 686 kernel instead. If you decided to do a different architecture (64 bit, for example), substitute the appropriate kernel.<\/p>\n<p>At this point, you can use aptitude to install any other software you want on the system; if the target hardware is unlikely to have network capability, this would be a good time to do so. Also, unless you&#8217;re certain there are free drivers for all the hardware in the target system, you might want to take a moment to install the debian non-free firmware packages:<\/p>\n<ol>\n<ol>\n<li>Open \/etc\/apt\/sources.list in nano or vi. \u00a0You should see a single line containing the location of the repository mirror.<\/li>\n<li>At the end of the line after &#8220;main&#8221; add &#8220;non-free contrib&#8221; separated by spaces.<\/li>\n<li>Save and close the file, then run:\n<pre lang=\"bash\">aptitude update &amp;&amp; aptitude install firmware-linux-nonfree<\/pre>\n<\/li>\n<\/ol>\n<\/ol>\n<h3>Step 4: Final fixes and tweaks<\/h3>\n<p>Before we can reboot into our glorious new system, there are a few things we have to set up. \u00a0You&#8217;ll need to still be in the chroot environment for these things, so if you exited out, get back in and do the following:<\/p>\n<h4>Set root password<\/h4>\n<p>Root&#8217;s going to need a password, otherwise there&#8217;ll be no logging in to this system when it boots. \u00a0So as root (which you are by default when you chroot), issue the <strong>passwd<\/strong> command and follow the prompts to set \u00a0the password. If you wish, you can use the <strong>adduser<\/strong> command at this point to add non-root users to the system. \u00a0Might not be a bad idea.<\/p>\n<h4>Create fstab<\/h4>\n<p>This is (potentially) one of the trickier parts of the process: creating the \/etc\/fstab file. \u00a0Fortunately, you can probably just copy what I have below and 99% of the time for a single-disk system it&#8217;s going to work just fine, so open the chroot&#8217;s \/etc\/fstab in your favorite text editor and paste this in:<\/p>\n<pre>#This mounts the root partition\r\n\/dev\/sda1   \/  ext4   defaults,noatime 0 1\r\n\r\n#This is the swap partition\r\n\/dev\/sda2   none swap  sw 0  0<\/pre>\n<p>This assumes you followed the same partitioning scheme I did above, with the first partition for the OS and the second for swap. If not, adjust accordingly. Do take note that I specified &#8220;sda&#8221; here instead of &#8220;sdb&#8221;; once the drive is put back in the other system, it will take on the name &#8220;sda&#8221; since it will likely be the first and only drive detected.<\/p>\n<h4>Exit and cleanup<\/h4>\n<p>We should be done with the chroot at this point, so get out of it by typing &#8220;exit&#8221;. Then clean up with the following commands:<\/p>\n<pre lang=\"bash\">cd\r\numount \/media\/sdb1\/proc\r\numount \/media\/sdb1\/sys\r\numount \/media\/sdb1\/dev\r\nsync\r\numount \/media\/sdb1<\/pre>\n<h3>Step 5: test<\/h3>\n<p>At this point, you should be ready to roll with the install. If your working system has adequate specs for virtualization, you might want to test the install before you go to all the trouble of putting the drive back in the target computer.<\/p>\n<p><strong>Qemu<\/strong> is a good, simple virtualization tool that&#8217;s readily available in any Debian-based OS. If you have it installed, test your installation with this command (must be run as root\/sudo):<\/p>\n<pre lang=\"bash\">qemu -hda \/dev\/sdb<\/pre>\n<p>If all has gone well, you should soon see a GRUB screen, followed shortly by a login prompt. If it looks good and logs in, you&#8217;re ready to go!<\/p>\n<h3>Step 6: Humpty-Dumpty back together again<\/h3>\n<p>If you&#8217;ve made it this far, put that drive back in the original computer and boot it up. If you&#8217;ve been trying this in real life, let me know how it worked out for you!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>When tinkering with old computers, there is little about an operating system quite as endearing as flexibility at install time. \u00a0The &#8220;Universal Operating System&#8221; is no slouch in this regard; the Debian installer will work quite happily from CD, DVD, USB drive, \u00a0PXE boot (my personal fav), and even a Windows executable. But what if [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6,21,5],"tags":[15,20,22,14,19,13,34],"class_list":["post-210","post","type-post","status-publish","format-standard","hentry","category-floss","category-old-computers-technology","category-technology","tag-debian","tag-how-to","tag-instructional","tag-linux","tag-old-computers","tag-pointless-geekery","tag-practical-tech"],"_links":{"self":[{"href":"https:\/\/alandmoore.com\/blog\/wp-json\/wp\/v2\/posts\/210","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/alandmoore.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/alandmoore.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/alandmoore.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/alandmoore.com\/blog\/wp-json\/wp\/v2\/comments?post=210"}],"version-history":[{"count":21,"href":"https:\/\/alandmoore.com\/blog\/wp-json\/wp\/v2\/posts\/210\/revisions"}],"predecessor-version":[{"id":234,"href":"https:\/\/alandmoore.com\/blog\/wp-json\/wp\/v2\/posts\/210\/revisions\/234"}],"wp:attachment":[{"href":"https:\/\/alandmoore.com\/blog\/wp-json\/wp\/v2\/media?parent=210"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/alandmoore.com\/blog\/wp-json\/wp\/v2\/categories?post=210"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/alandmoore.com\/blog\/wp-json\/wp\/v2\/tags?post=210"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}