How To Have a Data Center On Your Laptop using Hyper-V

How To Have a Data Center On Your Laptop using Hyper-V

Status
Done
Created
Nov 20, 2024 10:03 AM
Tags
DevOps
Desription:
🐧
Set up and simulate a mini data center on your laptop using Hyper-V. Learn to configure a local internal network, deploy and manage virtual machines, and experiment with server setups without dedicated hardware. Perfect for someone that is exploring virtualization and IT infrastructure basics as well as geeks that want cheap home lab.
Tech Stack:
Windows Hyper-V, Ubuntu Server, Windows PowerShell
Features:
  • Local network simulation within Hyper-V
  • Deployment of an Ubuntu Server virtual machine (VM)
  • Resource allocation and management for VMs
  • Network and system monitoring setup on a local environment
Learning Path:
  1. Virtualization concepts and Hyper-V basics
  1. Setting up virtual networks (Internal/private)
  1. Installing and configuring an Ubuntu Server VM
  1. Managing resources and snapshots in Hyper-V
  1. Understanding basic network configurations for simulated environments
Goal:
By the end of this guide, you’ll have a functioning “data center” simulation running on your laptop, providing foundational skills for working with virtual machines and network environments.

Table of Contents

Part 1: Setting up Hyper-V and a Local Network

Step 1: Enable Hyper-V on Windows

To get started, ensure that Hyper-V is enabled on your laptop. Hyper-V is a built-in feature in Windows 10/11 Pro, Enterprise, and Education editions. It is also available on any version of Windows Server.
  1. Open Control Panel > Programs > Turn Windows features on or off.
  1. Locate and check Hyper-V along with Hyper-V Management Tools and Hyper-V Platform.
  1. Click OK, and restart your computer when prompted.
    1. notion image

Step 2: Open Hyper-V Manager

After the restart, launch Hyper-V Manager:
  1. Press Win + S , type Hyper-V Manager, and open the application
    1. notion image
  1. Click on Connect to Server and select Local computer then press OK
    1. notion image

Step 3: Create a Virtual Switch for Internal Networking

To simulate a data center, you’ll set up an internal network that allos communication between your virtual machines (VMs) as well as between your laptop to VMs.
  1. In Hyper-V Manager, click on Virtual Switch Manager from the right-hand menu.
    1. notion image
  1. Select Internal, and click Create Virtual Switch
    1. notion image
  1. Name the switch (e.g., Internal ) and leave other options as default. Click OK.
    1. notion image
  1. In case of connecting VMs to external network such as Wi-Fi for Internet access, add another virtual network swtich with type of External.
    1. notion image
  1. Select network adapters you want this virtual network switch to connect with. In this guide I’m going to use Wi-Fi network adapters available on my laptop.
    1. notion image
  1. Name the switch (e.g. EXTERNAL-WIFI ). Click Apply.

Step 4: Configure the Host's IP Address on the Internal Network

Once the internal virtual switch is set up, we can setup a static IP address on our host machine’s virtual network adapter to establish communication between the host and virtual machines.
  1. Open Control Panel > Network and Internet > Network and Sharing Center. Click Change adapter settings from the left-hand menu.
    1. notion image
  1. You’ll see a new network adapter corresponding to the internal virtual switch (e.g., vEthernet (Internal)).
    1. notion image
  1. Right-click the adapter and select Properties. Select Internet Protocol Version 4 (TCP/IPv4) and click Properties.
    1. notion image
  1. Choose Use the following IP address, and enter the following:
    1. IP address: 10.32.1.1 (or any address range that not used by other interface like Wi-Fi)
    2. Subnet mask: 255.255.255.0 (this is /24 in slash notation which mean can afford to have 256 host connected which more than enough for local VM)
    3. Leave the Default gateway blank
    4. Click OK to apply the settings.
      notion image
  1. Open a command prompt and run ipconfig . Look for the new virtual adapter, and ensure the IP address is correctly assigned.
We’ll leave test connectivity to VMs later after we set up the VM. Make sure the VM is attached with Internal network adapter and set the IP address manually using same range.

Part 2: Create and Configure an Ubuntu Server VM

Step 5: Create a New Virtual Machine

  1. Prepare an Ubuntu Server ISO. We’re going to download the latest ISO from official Ubuntu website: Ubuntu Downloads.
  1. Open Hyper-V Manager. In the right-hand panel, click New > Virtual Machine to launch the New Virtual Machine Wizard. Click Next to proceed with the setup.
    1. notion image
  1. Enter a name for the virtual machine (e.g., Ubuntu-Server). Specify the location where you want to store the VM files or leave it at the default.
    1. notion image
  1. Choose Generation 2 for most modern Linux distributions, as it supports UEFI and secure boot features. If unsure, you can select Generation 1 for broader compatibility.
    1. notion image
  1. Allocate memory for the VM (e.g., 2048 MB or more, depending on your system’s resources and requirements). Check Use Dynamic Memory since we’re running this VM on laptop that have limited memory capacity.
    1. notion image
  1. On Configure Networking, leave it Not Connected that we’ll going to set it up after we create the VM before running later.
    1. notion image
  1. Choose Create a virtual hard disk and specify:
    1. Name: (e.g., Ubuntu-Server.vhdx).
    2. Size: Allocate at least 20 GB (adjust based on your requirements).
    3. notion image
  1. Choose Install an operating system from a bootable CD/DVD ROM. Select Image file (.iso) and browse to the Ubuntu Server ISO you downloaded earlier.
  1. Review the configuration summary and click Finish to create the virtual machine.
    1. notion image
  1. Right click on the VM we created (ubuntu-server) and click Settings.
  1. Click Add Hardware and select Network Adapter. Click Add.
    1. notion image
  1. Choose Internal on Virtual Switch. Then click Apply.
  1. Add another virtual switch and choose your EXTERNAL-WIFI . Click Apply then click OK.

Step 6: Start and Install Ubuntu Server

  1. In Hyper-V Manager, right-click the newly created VM and select Start. Once started, click Connect to open the VM console.
    1. notion image
       
  1. The VM will boot into the Ubuntu Servr installation wizard. Follow the prompts to set up Ubuntu Server.
    1. Choose your language and keyboard layout.
      1. notion image
    2. Configure the network interface (you can manually set a static IP later if needed). For now we just let the Internal network interface disabled and let the EXTERNAL-WIFI network interface to be automatic.
      1. notion image
    3. Partition the disk (use the default options unless you have specific requirements).
      1. notion image
    4. Create a user account and set up SSH for remote access.
      1. notion image
        notion image
  1. Once the installation is complete, remove the ISO from the VM’s settings to avoid booting into the installer again. Restart the VM to complete the process.
    1. notion image

Step 7: Configure Static IP for Ubuntu Server

To make so we can communicate with VM via internal network, configure a static IP for the Ubuntu Server.
  1. Log in to the server using the credentials you created during installation.
  1. Run command: ip -br address , you will see the interface name of the Internal and EXTERNAL WI-FI
    1. notion image
      Here we see the eth1 that already have IP address, which it is the EXTERNAL-WiFi interface we enabled at installation. Meanwhile the eth0 is the Internal interface that we will set as static IP.
  1. Edit the Netplan configuration:
    1. Run the command:
      1. sudo vim /etc/netplan/01-netcfg.yaml
    2. Update the file with the following. As you can see we set the eth0 interface which corresponding
      1. network: version: 2 ethernets: eth0: addresses: - 10.32.1.2/24 eth1: dhcp4: true
    3. Apply the configuration by run following command:
      1. sudo netplan apply
    4. Test the network configuration by pinging the host machine
      1. ping 10.32.1
        (Optional) If pinging to host network not works, perhaps you must allow ICMP on your Windows firewall.
        Open Windows Defender Firewall and select Advanced Settings in the sidebar. Switch to Inbound Ulres via the Getting Started page on the sidebar. Find the rule named “Core Networkign Diagnostics - ICMP Echo Request (ICMPv4-In)” with Profile of “Private,Public” or “Domain” if you’re on a corporate domain. Right-click the rule and Enable Rule. Do the same for the IPv6 version.
        notion image
        The ping from Ubuntu-Server to Windows host IP address should works.
        $ ping 10.32.1.1 PING 10.32.1.1 (10.32.1.1) 56(84) bytes of data. 64 bytes from 10.32.1.1: icmp_seq=1 ttl=128 time=0.281 ms 64 bytes from 10.32.1.1: icmp_seq=2 ttl=128 time=0.389 ms 64 bytes from 10.32.1.1: icmp_seq=3 ttl=128 time=0.784 ms 64 bytes from 10.32.1.1: icmp_seq=4 ttl=128 time=0.451 ms 64 bytes from 10.32.1.1: icmp_seq=5 ttl=128 time=0.685 ms 64 bytes from 10.32.1.1: icmp_seq=6 ttl=128 time=0.559 ms ^C --- 10.32.1.1 ping statistics --- 6 packets transmitted, 6 received, 0% packet loss, time 5112ms rtt min/avg/max/mdev = 0.281/0.524/0.784/0.171 ms
        The same also works if we ping from the Windows host to Ubuntu-Server:
        > ping 10.32.1.2 Pinging 10.32.1.2 with 32 bytes of data: Reply from 10.32.1.2: bytes=32 time<1ms TTL=64 Reply from 10.32.1.2: bytes=32 time<1ms TTL=64 Reply from 10.32.1.2: bytes=32 time<1ms TTL=64 Reply from 10.32.1.2: bytes=32 time<1ms TTL=64 Ping statistics for 10.32.1.2: Packets: Sent = 4, Received = 4, Lost = 0 (0% loss), Approximate round trip times in milli-seconds: Minimum = 0ms, Maximum = 0ms, Average = 0ms
Your Ubuntu Server VM is now installed, connected to the internal network, and ready for further configuration. In the next part, we’ll explore managing resources and monitoring the virtualzied environment.

Part 3: Managing Resources the Virtualized Environment

Once your VMs is up and running, the next step is to learn how to efficiently manage resources and monitor your virtualized environment. This includes allocating CPU and memory resoruces, and taking snapshots.

Step 8: Managing VM Resources in Hyper-V

  1. Adjust CPU and Memory Allocation.
    1. Open Hyper-V Manager
    2. Before set the resources allocation, you need to shut down your VM. Right-click the VM and select Turn off…
    3. Right-click the Ubuntu VM and select Settings.
    4. Under Processor, adjust the number of virtual processors based on your laptop’s capabilities. A single processor is sufficient for basic tasks; increase it if your server needs more computing power.
      1. notion image
    5. Under Memory, increase or decreae the RAM allocation to optimize performance. Ensure you don’t allocate more memory than your host systen can support. You can also use Dynamic Memory capability from Hyper-V to set minimum request allocated and maximum limitation of memory to this VM. If all done, click Apply.
      1. notion image
  1. Configure Virtual Hard Disk
    1. To expand the VM’s storage, go to Hard Drive under IDE Controller
    2. Select the VM’s hard disk (.vhdx file). Click Edit
      1. notion image
    3. The .vhdx file is automatically selected on Locate disk page and cannot be changed. On Choose Action, you can select either Compact to reduceing size or combining elementr to optimize storage, Convert to changing data or files format, or Expand to increase the capacity of the virtual hard disks. Let’s choose Expand for demonstration.
      1. notion image
    4. On the next page, you will input the new size of the virtual hard disk you want. The size must be greater than current size which mean the virtual hard disk can’t be shrink in any case. Let’s input some reasonable number.
      1. notion image
    5. Review the summary and click Finish.
  1. Set automatic start and stop actions
    1. In the Settings menu for the VM, navigate to Automatic Stop Action
    2. Configure the VM to Save the VM state or Turn off the VM when the host shuts down. The save VM state is useful so the works being done on VM will be continue when VM start again. It is done by using the disk space to save VM memory
      1. notion image
        Click Apply

Step 9: Taking Snapshots for Backup

Snapshots allow us to save the state of the VM at a specific point in time, making it easy to roll back if needed.
  1. Create a Snaphot
    1. In Hyper-V Manager, right-click the UBuntu VM and select Checkpoint. It will create checkpoint at the time when it clicked.
      1. notion image
    2. Name the snapshot for referece (e.g., Network Configured or any description to explain the state of VM)
      1. notion image
  1. Restore a Snapshot
    1. To revert to a previous state, select the VM, click Checkpoints, and choose the desired snapshot
    2. Click Apply to restore the VM to that state. This will delete all files made after the snapshot or retrieve any files that exist at the snapshot time including any configurations.
      1. notion image

Conclusion

This guide helps you transform your laptop into a fuctional mini data center using Hyper-V, providing a hands-on approac to learnign virtualization and IT infrastructure. By following the steps, you’ll gain practical experience in setting up virtual networks, deploying and configuring an Ubuntu Server virtual machine, and simulating server environments — all without dedicated hardware. This is ideal for beginners exploring the foundations of system administration or enthusiasts building cost-effective home labs. Mastering these skills lays the groundwork for advanced IT infrastructure projects and virtualization management. 🐧