AWS
Importing Vm to Aws

Procedure Manual: Importing a Virtual Machine to AWS Using VMware Workstation

Preparation Steps:

Prerequisites

  1. Install the AWS CLI

  2. Configure the AWS CLI

    • Run the following command to configure:
      aws configure
  3. Create an AWS Role for VM Importing

    • Create a role with a trust policy. Add the following JSON code to trust-policy.json:
      {
          "Version": "2012-10-17",
          "Statement": [
              {
                  "Effect": "Allow",
                  "Principal": { "Service": "vmie.amazonaws.com" },
                  "Action": "sts:AssumeRole",
                  "Condition": {
                      "StringEquals": {
                          "sts:ExternalId": "vmimport"
                      }
                  }
              }
          ]
      }
    • Run the following command:
      aws iam create-role --role-name vmimport --assume-role-policy-document "file://C:\Users\user\Desktop\AWS\json\trust-policy.json"
  4. Attach a Policy to the AWS Role

    • Create a policy document. Add the following JSON code to role-policy.json:
      {
          "Version": "2012-10-17",
          "Statement": [
              {
                  "Effect": "Allow",
                  "Action": [
                      "s3:GetBucketLocation",
                      "s3:GetObject",
                      "s3:ListBucket"
                  ],
                  "Resource": [
                      "arn:aws:s3:::hwtechnet-import-export-bucket",
                      "arn:aws:s3:::hwtechnet-import-export-bucket/*"
                  ]
              },
              {
                  "Effect": "Allow",
                  "Action": [
                      "s3:GetBucketLocation",
                      "s3:GetObject",
                      "s3:ListBucket",
                      "s3:PutObject",
                      "s3:GetBucketAcl"
                  ],
                  "Resource": [
                      "arn:aws:s3:::amzn-s3-demo-export-bucket",
                      "arn:aws:s3:::amzn-s3-demo-export-bucket/*"
                  ]
              },
              {
                  "Effect": "Allow",
                  "Action": [
                      "ec2:ModifySnapshotAttribute",
                      "ec2:CopySnapshot",
                      "ec2:RegisterImage",
                      "ec2:Describe*"
                  ],
                  "Resource": "*"
              }
          ]
      }
    • Run the following command:
      aws iam put-role-policy --role-name vmimport --policy-name vmimport --policy-document "file://C:\Users\user\Desktop\AWS\json\role-policy.json"

Important Steps

  1. Export the Current VM to an OVA File

    • In VMware Workstation, go to File > Export and save the file with the .ova extension.
  2. Create an S3 Bucket for Import-Export

    • Create an S3 bucket named hwtechnet-import-export-bucket and upload the OVA file to the bucket.
  3. Run the AWS Command to Create an Image

    • Add the following JSON to containers.json:
      {
          "ImportImageTasks": [
              {
                  "ImportTaskId": "import-ami-01234567890abcdef",
                  "ImageId": "ami-1234567890EXAMPLE",
                  "SnapshotDetails": [
                      {
                          "DiskImageSize": 705638400.0,
                          "Format": "ova",
                          "SnapshotId": "snap-111222333444aaabb",
                          "Status": "completed",
                          "UserBucket": {
                              "S3Bucket": "amzn-s3-demo-import-bucket",
                              "S3Key": "vms/my-server-vm.ova"
                          }
                      }
                  ],
                  "Status": "completed"
              }
          ]
      }
    • Run the following command:
      aws ec2 import-image --description "My server VM" --disk-containers "file://C:\Users\user\Desktop\AWS\json\containers.json"
    • After running the command, the task will be in a pending state. Keep the output for reference.
  4. Monitor the Create Image Progress

    • To monitor the progress of the import task, refer to the documentation Monitor and Import Image Task (opens in a new tab).
    • Use the following command (replace import-ami-1234567890abcdef0 with your actual ImportTaskId):
      aws ec2 describe-import-image-tasks --import-task-ids import-ami-1234567890abcdef0

    Possible States:

    • active — The import task is in progress.
    • deleting — The import task is being canceled.
    • deleted — The import task is canceled.
    • updating — Import status is updating.
    • validating — The imported image is being validated.
    • validated — The imported image was validated.
    • converting — The imported image is being converted into an AMI.
    • completed — The import task is completed and the AMI is ready to use.
  5. Create an Instance from the Uploaded Image

    • In the AWS Management Console, go to AMIs, select the created AMI, and proceed to launch an instance.

PNET Baremetal Manual

This guide walks you through installing and setting up Ubuntu 18.04 for PNET Lab on bare metal hardware, including installation, root access configuration, PNET Lab installation, and troubleshooting common issues.


Step 1: Download and Install Ubuntu 18.04

  1. Download Ubuntu 18.04:

  2. Install Ubuntu:

    • Boot from the Ubuntu 18.04 ISO and follow the installation instructions.
    • Important: During installation, make sure to select the option to install OpenSSH to enable remote management over SSH.
    • When partitioning, allocate all available disk space to ubuntu_lv.

Step 2: Configure Root Access

  1. Login as the user created during installation:

    • Once the installation is complete, log in with the username and password you set during the Ubuntu installation.
  2. Switch to the root user:

    • Run the following command to gain root privileges:
      sudo -i
  3. Set the root password:

    • Set a password for the root account by executing:
      passwd
  4. Enable root login via SSH:

    • Run the following command to allow root access over SSH:
      sed -i -e "s/.*PermitRootLogin .*/PermitRootLogin yes/" /etc/ssh/sshd_config
    • Restart the SSH service:
      service sshd restart
  5. Delete the user created during installation:

    • Log out and log back in using the root account. Then delete the original user account:
      userdel [username]

Step 3: Add the PNET Lab Repository

  1. Open /etc/apt/sources.list:

    • Use a text editor to open the sources list file:
      nano /etc/apt/sources.list
  2. Add the following repository to the end of the file:

    deb [trusted=yes] http://repo.pnetlab.com ./
  3. Save and exit the text editor.


Step 4: Install PNET Lab

  1. Ensure internet connectivity:

    • Confirm that your server can access the internet by checking DNS configuration:
      echo "nameserver 8.8.8.8" > /etc/resolv.conf
  2. Update the package list:

    • Run the following command to update the package lists:
      apt-get update
  3. Remove Netplan (if installed):

    • PNET Lab doesn't support Netplan, so you need to remove it:
      apt-get purge netplan.io
  4. Install PNET Lab:

    • Run the following command to install PNET Lab:
      apt-get install pnetlab -y
  5. Handle installation errors:

    • If there is an error during installation, try running the commands again:
      apt-get update
      apt-get install pnetlab -y
  6. Reboot the system:

    • After installation, reboot the server to apply all changes:
      reboot

Step 5: Upgrade PNET Lab to the Latest Version

  1. Follow the upgrade guide:

Troubleshooting

If you encounter issues during installation or when trying to install PNET Lab, here are common errors and their solutions:

  1. Error: 404 Not Found

    E: Failed to fetch http://repo.pnetlab.com/./en_US  404  Not Found
    E: Failed to fetch http://repo.pnetlab.com/./en  404  Not Found
    • Solution: Ensure that the repository URL in /etc/apt/sources.list is correct. It should be:
      deb [trusted=yes] http://repo.pnetlab.com ./
    • After editing, run:
      apt-get update
  2. Error: Unmet Dependencies

    The following packages have unmet dependencies:
    pnetlab : Conflicts: netplan.io but 0.99-0ubuntu3~18.04.5 is to be installed
    E: Unable to correct problems, you have held broken packages.
    • Solution: This error usually occurs if Netplan is still installed or conflicts exist. Ensure you run the following commands:
      apt-get purge netplan.io
      apt-get install pnetlab -y
    • If the error persists, you might need to fix broken packages:
      apt-get install -f
  3. Error: Package Removal Warnings

    dpkg: warning: while removing netplan.io, directory '/etc/netplan' not empty so not removed
    • Solution: This is a warning rather than an error. If you want to remove the directory, you can do so manually:
      rm -rf /etc/netplan
  4. General Package Management Issues

    • If you experience other issues with package management (e.g., held packages), you can try:
      apt-get autoremove
    • This command will remove unnecessary packages that may be causing conflicts.
  5. Check Network Connectivity

    • If you encounter issues reaching the repository, verify your network configuration and ensure you have internet access by pinging an external server:
      ping -c 4 google.com

Conclusion

You have now installed and configured Ubuntu 18.04 and PNET Lab on bare metal. Follow the upgrade instructions to keep PNET Lab up to date, and refer to the troubleshooting section for common issues that may arise during installation or operation. Your system will be ready for network simulation tasks.