Live USB from Debian

To install Windows 7, you need to create a live USB since it is very hard to find compact disc in 2018 anymore. From Debian system however, it is not a easy path. I attempted the conventional Linux way of dd command, unetbootin etc: none of them work out as expected. However, using grub as a bootloader to chain-load the installer's bootloader is definitely working without additional software installations!

Grab the Windows 7 ISO Image

The very first step is to download the Windows 7 ISO file from Microsoft. You can download it here:

It will take a very long time depending on your network connection since all OS ISO files are big!

Setup USB Stick

Identify the Stick Drive

The easiest way is to use lsblk command. This will list out all the partitions accordingly. Find and select the partition containing the root directory.

$ lsblk
NAME           MAJ:MIN RM   SIZE RO TYPE  MOUNTPOINT          
sda              8:0    0 931.5G  0 disk                      
├─sda1           8:1    0   243M  0 part                      
├─sda2           8:2    0     1K  0 part                      
└─sda5           8:5    0 931.3G  0 part                      
  └─sda5_crypt 254:0    0 931.3G  0 crypt                     
    ├─<lvm-name>-root                              
    │          254:1    0    28G  0 lvm   /
    ├─<lvm-name>-swap_1
    │          254:2    0  11.9G  0 lvm   [SWAP]
    └─<lvm-name>-home
               254:3    0 891.4G  0 lvm   /home
sdb              8:16   1  28.7G  0 disk  
└─sdb1           8:17   1   250M  0 part  /mnt/bootloader

In the example above, we can see /dev/sdb is our target device.


Unmount the USB Drive

If you notice, the USB drive is mounted on a specified path. You'll need to un-mount all of the partitions from that device before proceeding to install. To do that, we use the umount <path> command. Based on the example above, since we got 1 partition (/dev/sdb1), it is:

$ umount <MOUNTPOINT>

Based on the example above, it is:

$ umount /mnt/bootloader


Reformat USB Stick

You can now reformat the USB device with gparted. First, you install gparted software:

$ sudo apt install gparted -y
$ sudo gparted

Then follow the following steps:

  1. Look for your USB device at the top right corner.
  2. Re-write the device partition table to msdos. This will erase all the contents in the stick.
  3. Right click on the partition and then create the entire partition to ntfs.
  4. Select "Apply" button at the tool bar to start the reformat.
  5. Right click on the partition and label the partition with a unique name of your choice, e.g. WIN7STICK. Remember the name as we need it later.
  6. Select "Apply" button at the tool bar to label it.
  7. Right click on the partition and select "Manage Flag". Check the "boot" to make the partition bootable. Press OK to close the menu.
  8. If "Apply" button is available, select "Apply" button at the tool bar to do whatever that is leftover.
  9. Once done, exit gparted. You're done with the device formatting.


Mount the USB Drive

You can now mount the USB drive back again. Either you can open your file manager to perform an auto-mount. The guide here is for those who wants to perform manual mounting instead.

$ mkdir destination
$ mount /dev/<your USB device partition> ./destination

So, following the example above, you should get:

$ mkdir destination
$ mount /dev/sdb1 ./destination


Mount the Installer ISO

Now you should mount the Installer ISO. We need to copy all the files across into the USB drive. You need root access for this to work:

$ mkdir origin
$ sudo mount -o loop /path/to/your/windowInstaller.iso ./origin


Copy the files

With everything in place, you can begin the copy process. It takes time so get a cup of coffee. The last step is optional, where I use the diff program to check the differences between the 2 directories. It should not throw any output.

$ cp -r ./origin/* ./destination/.
$ sync
$ diff  --brief --recursive ./origin ./destination        # Optional.
$


Unmount the Installer ISO

After a successful copying, you can unmount it. You might need root access. Just try it out.

$ sudo umount /dev/<partition name>
$ rm -r ./origin

Based on the example, it is:

$ sudo umount /dev/sdb1
$ rm -r ./origin

If you receive a warning or error that the device is busy, use lsblk again to find and unmount the mount path instead of using the partition name.



Install Grub Boot-loader

With every in place, it's time to install grub bootloader. You definitely need root access for this. Be extra careful because this step can destroy a storage drive if you provide the wrong <target_device>. Use legacy boot:

$ sudo grub-install --target=i386-pc --boot-directory="./destination/boot" /dev/<target_device>

Following the example above, we get:

$ sudo grub-install --target=i386-pc --boot-directory="./destination/boot" /dev/sdb


Create the Grub Chainloading Configuration File

Now, fire up your text editor and create a file at ./destination/boot/grub/grub.cfg with the following contents:

default=1
timeout=15
color_normal=light-cyan/dark-gray
menu_color_normal=black/light-cyan
menu_color_highlight=white/black

menuentry "Start Windows Installation" {
    insmod ntfs
    insmod search_label
    search --no-floppy --set=root --label <USB_drive_label> --hint hd0,msdos1
    ntldr /bootmgr
    boot
}

menuentry "Boot from the first hard drive" {
    insmod ntfs
    insmod chain
    insmod part_msdos
    insmod part_gpt
    set root=(hd1)
    chainloader +1
    boot
}

Replace the bolded <USB_drive_label> with the label you gave to the USB drive. If we follow the example above, it was the WIN7STICK. Once done. Save it.


Unmount the USB Drive

With everything in place, you can now unmount the USB drive safely.

$ sync
$ umount ./destination
$ rm -r ./destination


Remove the USB Stick

You have the USB Installer stick ready. Feel free to use it and install your Windows.

That's all about creating a USB stick for Windows 7 Installer. Keep in mind that Windows7 is a retired legacy operating system so it won't work or boot on most modern laptop, especially those from Intel i3, i5, and so on. You need to find a legacy hardware to support it.