How to install Debian on your physical drive without a LiveCD
What you need:
- A Linux system
VirtualBox or VMware (tested using VirtualBox)
First, make sure you have at least 10-15 GB of free space on your hard drive (https://www.debian.org/releases/stable/amd64/ch03s04.html.en). Also make sure you have around double to triple that amount free on whatever partition you store your data.
Download your preferred Debian ISO and install Debian on a virtual hard drive (VMware or VirtualBox). Allocating 10-15 GB for the virtual hard drive should be good enough. Modify your VM to boot off the ISO and install Debian per your wishes.
After installing Debian, find out where your virtual hard drive is located. Then convert that file to an img file. With VirtualBox, the command is [1]: VBoxManage internalcommands converttoraw your-virtualbox-disk.vdi ./debian.img
Next, extract your boot partition to another img file. To do this, first look at your partition layout of the img file [2]:
sfdisk -l debian.img
Your output should look something like this:
Device Boot Start End Sectors Size Id Type debian.img1 * 2048 40136703 40134656 19.1G 83 Linux debian.img2 40138750 41940991 1802242 880M 5 Extended debian.img5 40138752 41940991 1802240 880M 82 Linux swap / Solaris
Find your boot partition (the line marked with the star), and then feed its "start" and 'sectors" values into the "skip" and "count" parameters below, respectively [2]: dd if=debian.img of=debianpartition.img skip=start count=sectors
Mount your partition image as a loop device [2]:
mount -t ext4 -o loop debianpartition.img tempfolder
Using gparted or whatever utility you want, create a ext4 partition at least 15 GB big on your physical hard drive. Then, mount it on your filesystem:
mount /dev/sdaX /media/Debian
Afterwards, use rsync to move the files in the loop device to the mounted empty ext4 partition [3]. Don't use cp because it doesn't preserve file attributes. rsync -aAXHv --exclude={"/dev/*","/proc/*","/sys/*","/tmp/*","/run/*","/mnt/*","/media/*","/lost+found"} ./tempfolder/ /media/Debian
Unmount the loop device with umount ./tempfolder. Run blkid and save the mounted ext4 partition's UUID for later. Then chroot into the partition: LANG=C.UTF-8 chroot /media/Debian /bin/bash
Because Debian was installed initially in the virtual machine, the partition's UUID changed during the migration. One way to fix this should be to manually replace every mention of the old UUID in /boot/grub/grub.cfg with the new UUID that you found by running blkid (not tested). However, emptying /boot/grub/grub.cfg works just as well. Afterwards, go to /etc/fstab and change the UUID of the root partition as well. You should also comment out any other partitions (such as the swap partition) that weren't migrated, or at least update them to point at existing partitions on your physical hard drive.
Exit the chroot-ed filesystem (with exit), and run update-grub. Your new Debian partition should be detected.
If you're done, be sure to unmount your Debian partition. You can also go ahead and remove your virtual machine and the img files if you want to.
Note: If you want to fully migrate to Debian, reboot your computer, select the Debian partition in your grub menu and boot it, and then run update-grub and grub-install /dev/sda.
Credit: Thanks to cruncher on the Debian IRC channel for helping me figure out the UUID and update-grub problem.
Related
Boot the Debian installer from a hard drive: https://www.debian.org/releases/stable/amd64/ch05s01.html.en