Moez Bouhlel @lejenome

Recently, I needed to setup a new Windows system for use in an Internship project. Like the old setup which was described on an older post, I needed to have access to the same Windows from inside Qemu and from dual-boot for performance reseasons. But instead of requiring to install Windows two times (once directly on PC as host and the other inside Qemu) which caused some issues including slow filesystem operations when booting as host system, I did an update to setup instructions this time.

For the virtual machine, we will use Qemu/KVM with Ovmf EFI bios.

First, Install Windows directly on your PC then reboot back to Linux. Check that loop and linear modules are loaded:

sudo modprobe loop
sudo modprobe linear

New, we need to create a virtual RAID disk for Qemu that will hold our physical Windows partition. As we will use GPT partitions table schema, we will allocate few megabytes efi1 for GPT metadata (34 Sectors) and for EFI partition before Windows partition and one megabyte efi2 after Windows partition for GPT secondary metadata (even we need just 34 Sectors, we will use one megabyte for best RAID performance)

dd if=/dev/zero of=efi1 bs=1M count=100
dd if=/dev/zero of=efi2 bs=1M count=1

Now that we have efi1 file of 100 MB (100 * 1M) and efi2 of 1 MB. Next, we create a loopback devices from both files:

sudo losetup -f efi1
sudo losetup -f efi2

We will assume that the assigned devices are /dev/loop0 and /dev/loop1 for efi1 and efi2 respectively. To check the assigned devices, type:

losetup -a

Next, we will merge the loopback devices and the real Windows partition into a single linear RAID disk image (We will assume that the windows partition is /dev/sda2):

sudo mdadm --build --verbose /dev/md0 --chunk=512 --level=linear --raid-devices=3 /dev/loop0 /dev/sda2 /dev/loop1

Time to create the partitions table of the new RAID disk reusing the same physical Windows partition. For this step, we will use parted utility. You can use other tool of your choose.

Partition your virtual RAID disk:

sudo parted /dev/md0
(parted) unit s
(parted) mktable gpt
(parted) mkpart primary fat32 2048 204799    # depends on size of efi1 file
(parted) mkpart primary ntfs 204800 -2049    # depends on size of efi1 and efi2 files
(parted) set 1 boot on
(parted) set 1 esp on
(parted) set 2 msftdata on
(parted) name 1 EFI
(parted) name 2 Windows
(parted) quit

Your final layout will have 2 partitions; Windows partition /dev/md0p2 and EFI partition /dev/md0p1. The EFI partition need to be formatted.

sudo mkfs.msdos -F 32 -n EFI /dev/md0p1

Now let add Windows boot entry to the virtual RAID disk.

Boot to Windows live DVD from inside Qemu virtual machine with /dev/md0 as disk after changing /dev/md0 owner to the current user and installing Ovmf EFI bios, which in my case, it is available at /usr/share/ovmf/ovmf_x64.bin.

chown $USER:$USER /dev/md0  # We need to change the owner of md0
qemu-system-x86_64 \
    -bios /usr/share/ovmf/ovmf_x64.bin \
    -drive file=/dev/md0,media=disk,format=raw \
    -cpu host -enable-kvm -m 2G \
    -cdrom /path/to/windows.iso

Press Shift+F10 when Windows installer starts to open the terminal. We need to assign letter to EFI volume (partition).

diskpart
DISKPART> list disk
DISKPART> select disk 0    # Select the disk
DISKPART> list volume      # Find EFI volume (partition) number
DISKPART> select volume 2  # Select EFI volume
DISKPART> assign letter=B  # Assign B: to EFI volume
DISKPART> exit

Finally, we create BCD boot entry for Windows partition on the same terminal.

bcdboot C:\Windows /s B: /f ALL

Now, you are ready to boot to Windows from inside Qemu.

qemu-system-x86_64 \
    -bios /usr/share/ovmf/ovmf_x64.bin \
    -drive file=/dev/md0,media=disk,format=raw \
    -cpu host -enable-kvm -m 2G

After each Linux system reboot, you need to create the loopback devices, merge the partitions into the RAID disk and change the owner of the device before launching the virtual machine. You can find the script I use as reference.

Credit to Arch Linux Wiki. Enjoy!

Recently, I wanted to add a feedback form to my resume page to help my friends review it. I was using GitHub pages to host my static web site and I didn't want to host the server side of the feedback on a different server. So I was looking for a simple solution that works well with my static website. Most of the available ones were either paid or have too many unneeded features.

At the end, I decided to use my Slack team to receive feedbacks. It does not require any third-party library or any server side code. And it's very simple to implement:

  1. Create a Slack team if you don't have one.
  2. Add an Incoming Webhook URL to a channel on your team. It's a simple URL that you can send feedbacks to.
  3. Finally, add your client side implementation. This is a simple one:
1 <form id="feedback">
2     <textarea name="text" required></textarea>
3     <input type="submit" value="send feedback"></input>
4 </form>
 1 let form = document.getElementById("feedback");
 2 form.addEventListener("submit", function(e) {
 3     e.preventDefault();
 4     fetch(YOUR_WEBHOOK_URL, {
 5         method: "POST", // You should use POST method
 6         body: JSON.stringify({
 7             text: form.text.value, // the feedback message
 8             parse: "none", // tell Slack it's not a formated text
 9         });
10     });
11 });

Improvements:

You can add more entries to the send JSON. Check Slack documentation for more details. The most useful ones are username and icon_emoji.

You can set different a username and different a icon_emoji entry for every page. For example, you send this JSON from your resume page:

1 {
2     "text"       : "THE FEEDBACK MESSAGE",
3     "parse"      : "none",
4     "username"   : "resume",
5     "icon_emoji" : ":briefcase:"
6 }

This is a list of useful websites and tools to check for Computer Science students.

Challenges:

Algorithms and Programming

System development and administration

Other

  • DevPost: Online and in-person challenges with prizes to win.

Tutorials:

Usefull tools:

  • GitHub: #1 Online project hosting service.
  • Could9: Full-featured development environment, in the cloud.
  • Zeal: offline documentation for 195+ programming languages and APIs.
  • DevDocs: Online APIs documentation.

Freelancer & Money:

Update: A new version of the articale with better solution is available here.

Even Linux is my main system, I frequently need to use Windows for school homework when Mono does not support desired features. Running Windows inside a virtual machine is always enough expect few cases. The best solution was to setup a single windows system accessible from both the virtual machine and from the physical dual boot.

For the virtual machine, we will use Qemu/KVM with Virtio devices and a disk partition for Windows.

First, you need to install Windows on your PC to get the boot entry with right configurations (I couldn't find a work around BCD boot entry issue other than this one). Then reboot to your Linux system to reinstall Windows on the same partition but using the virtual machine this time.

Before we start, check that loop and linear modules are loaded:

sudo modprobe loop
sudo modprobe linear

Because the virtual machine need whole disk with both the Windows partition and the EFI partition, We need to create a virtual RAID. Let's create a small file to hold the EFI partition:

dd if=/dev/zero of=efi count=200000

Now you have efi file of 100 MB (200000 * 512 Bytes). Next, we create a loopback device from the file:

sudo losetup -f efi

It will assign the first available loopback device to the file. We will assume that the assigned device is /dev/loop0. To check the assigned device:

losetup -a

Next, we will merge the loopback device and the real Windows partition into a single linear RAID disk image (We will assume that the windows partition is /dev/sda2):

sudo mdadm --build --verbose /dev/md0 --chunk=16 --level=linear --raid-devices=2 /dev/loop0 /dev/sda2

Time to create the partitions table of the new RAID disk with reusing the same physical Windows partition. For this step, we will use _parted_ utility. You can use other tools on your own. We need to get the size of real Windows partition on sectors.

sudo parted /dev/sda unit s print

Partition your virtual RAID disk:

sudo parted /dev/md0
(parted) unit s
(parted) mktable gpt
(parted) mkpart primary ntfs -WINDOW_PARITION_SIZE -1
(parted) mkpart primary fat32 0 -WINDOW_PARITION_SIZE
(parted) quit

Your final layout will have 2 partitions; Windows partition /dev/md0p1 and EFI partition /dev/md0p2. You may get few warning messages when creating partitions, ignore them. The new partitions need to be formatted.

sudo mkfs.ntfs -f -L Windows -C /dev/md0p1
sudo mkfs.msdos -F 32 -n EFI /dev/md0p2

Now, you are ready to launch the virtual machine and reinstall Windows. Change /dev/md0 owner to the same user _Qemu_ is running as and install _ovmf_ EFI bios for _Qemu_, in my case, it will be available at /usr/share/ovmf/ovmf_x64.bin.

qemu-system-x86_64 \
    -enable-kvm \
    -bios /usr/share/ovmf/ovmf_x64.bin \
    -drive file=/dev/md0,media=disk,format=raw \
    -netdev user,id=windowsnic,hostname=windowshost \
    -device virtio-net,netdev=windowsnic \
    -cpu host \
    -m 2G \
    -vga qxl \
    -usbdevice tablet

Adapt _Qemu_ script to your use case. You may need to download and install Virtio drivers on your guest machine. After each reboot, you need to create the loopback device, merge the two partitions into the RAID disk and change the owner of the device.

Credit to Arch Linux Wiki. Enjoy!

This is our check list for any member interested to join the training:

Tools

For Windows Users

You can choose your preferred Text Editor or IDE to write python code, or you can pick one of our recommendation list:

  • PyCharm
  • IDLE3 (already integrated with Python installer)
  • Visual Studio + Python Tools extension
  • Ninja-IDE
  • PyDev
  • Netbeans >= 8.1 + Python plugin

For Linux (Ubuntu) Users

  • Python 3 (should be already installed, use python3 command instead of python)
  • Git

You can choose your preferred Text Editor or IDE or one of our suggestion list:

  • PyCharm
  • Vim / emacs / nano / ed (or cat command if you want)
  • IDLE3
  • Ninga-IDE
  • Netbeans >= 8.1 + Python plugin
  • IPython3 (Jupyter console)

Other (We will keep it for Saturday)

We will use the Django Framework on the training. To install Django, you need to use the pip command (already integrated on Python Windows installer, or install python3-pip for Ubuntu users). Launch your console (cmd on Windows), and run:

pip install Django

Requirements

We will use GitHub to host our projects code. To be able to join the development, every member is required to create a GitHub account and send us his profile link on email (mtcfss@outlook.com).

Keep in mind that GitHub is #1 code hosting service and you will mostly keep using it outside our training on future.