The problem#
You know how to make a bootable flash drive, but you want to actually use it to install a permanent operating system (OS) onto your computer.
The solution#
Luckily, modern OS installs are very straightforward. Just download the installation image (e.g. Debian Linux or Windows 11), put it on a flash drive, boot off it, and click "Next" a few times and wait a bit. The defaults will usually erase all data on the computer, but if it's a new computer, there's nothing to erase.
Of course, you can make things more complicated if you don't like the defaults, have a special situation, or just want to know more precisely what's going on.
The details#
What does it mean to install an OS?#
An operating system consists of a kernel and a collection of userspace programs run on top of that kernel. Saying an operating system is installed on a computer means that when we turn on the computer it loads that operating system. That is, it loads the kernel and the kernel in turn runs the programs you want, usually presenting a login screen for a desktop computer.
The "it" loading the kernel is called a bootloader, most commonly GRUB or BOOTMGR (Windows). The bootloader is in turn is loaded by the computer's firmware (usually UEFI on modern computers) which has minimal support for reading disks sufficient to locate the bootloader and run it. On UEFI systems, this means reading a FAT partition called the EFI system partition; the old way put the bootloader in a special place at the start of the disk before any partition. The firmware uses settings stored in an NVRAM chip on the motherboard to decide precisely where and on which disk to look for the bootloader. The bootloader can then include enough code to know how to read more of the disk as necessary to load the kernel.
Therefore, for an OS to be installed, every link in that chain has to be present: the actual OS kernel and programs have to be on the disk, there has to be a bootload capable of loading that kernel, and the firmware has to be properly configured to use that bootloader.
Fixing the bootloader#
The actual impact of this for installing an OS is that it's insufficient
to simply have the files that make up the OS on a disk; you also have
to make sure the bootloader is set up correctly. Normally the OS
installer handles this for you and you never need to know about it.
But if you're transferring (or copying) a drive from an old computer
or just doing things more manually, since UEFI stores some of the
information about where to find the bootloader in NVRAM, you may need
to fix them using grub-install
on Linux (detailed
instructions) or BCDBoot on Windows (detailed
instructions; more info).
Transferring an existing install#
One option is to not do a fresh install of an OS and instead reuse an existing OS install. If you're keeping your old drive, this may be as simple as putting the old drive into the new computer. If you're upgrading to a new drive (presumably larger), you can transfer the data over, either at the block level or the filesystem level.
Block level copy#
If you want to simply copy every byte from your old drive to your new
drive, you can use dd
. Something like
dd if=/dev/sdOLD of=/dev/sdNEW bs=1M status=progress
On one hand, this has the benefit of not needing to figure out how to recreate the partition table and bootloader setup (although you may still need to follow the instructions above to fix the bootloader anyway). But your new drive is likely bigger, so you'll have to resize partitions anyway. And this will copy all of the empty space as well, so may be much slower if the drive is not actually full.
Filesystem level copy#
On Linux, recreating the partition structure (I usually use
cfdisk
, but whatever partition manager you like the user
interface of is fine) on the new drive and copying each partition as
root
with rsync -avhx
should work. Make sure you also copy the EFI
system partition correctly, including setting its type.
Linux install without an installer#
In the interest of knowing more of the of details, I sometimes do Linux installs using debootstrap, which does the absolute minimum to create a Debian Linux install. The documentation walks through the other steps needed to actually turn that into a useable installation including setting up the partitions beforehand and setting up the bootloader and installing additional packages afterward.
Windows#
The normal way to install Windows on a new computer is to put the installer on a flash drive and boot off that flash drive. But if you are unable to do so for some reason (for instance, you only have a very small flash drive that won't fix the installer), you can also use a Windows live USB like Hiren’s BootCD PE and mount the ISO and run the installer from there.
Also note that that download link does not require you to pay for Windows. At some point Microsoft will want your money, but they are happy to wait until after you've completed the install to collect.
Comments
Have something to add? Post a comment by sending an email to comments@aweirdimagination.net. You may use Markdown for formatting.
There are no comments yet.