Some GNS3 appliance images are not configured to use the ttyS0 as the default output method, VNC and graphical are the only access methods available. Even after the appliance once booted in the GNS3 network topology, there hardly a way to change the boot optioons of its underlaying operating system. Nowadays in the year 2023, the underlaying OS is mostly linux. Linux is cheap, available and has everything on board needed for advanced IP networking.
Now, using linux NBD network block device it is possible to mount partitions and alter files without the necessity to boot the underlaying operating system.
This is how to re-configure a existing and shipped QEMU image, and add the ttyS0 serial output as the default output method.
The example QEMU image used in this article is a Huawei USG6000V1 virtual firewall appliance. The name of its QEMU image is hda.qcow2.
Preparation tasks
Verify the filesize and md5sum of the used image before changing anything. This will get important later.
user@host ~ % ls -lah hda.qcow2
-rw-r--r-- 1 user user 670M Feb 29 2016 hda.qcow2
user@host /tmp % md5sum hda.qcow2
270540eef614462a79ce1257e2c28238 hda.qcow2
Copy
Copy the image to the /tmp directory
Load NBD
Load the linux nbd module
Connect
Connect the qcow2 guest image to nbd0 module
Create mount point
Create a temporary local mount point for the partition
Mount
Mount the 0-th nbd device containint the 1-st partition
File operation
Review the currently set booting parameters of the appliance before changing them:
PROMPT 1
TIMEOUT 50
DEFAULT normal
SERIAL 0
LABEL normal
LINUX /boot/vmlinux
INITRD /boot/busybox-initrd-static
APPEND root=LABEL=HW_VFW_ROOT rw
LABEL serial
LINUX /boot/vmlinux
INITRD /boot/busybox-initrd-static
APPEND root=LABEL=HW_VFW_ROOT rw console=ttyS0
Change default boot options
Change the DEFAULT normal
to DEFAULT serial
Alter the file using sed editor, Following line will replace the setting:
Verify the change has been applied to the file:
PROMPT 1
TIMEOUT 50
DEFAULT serial
SERIAL 0
LABEL normal
LINUX /boot/vmlinux
INITRD /boot/busybox-initrd-static
APPEND root=LABEL=HW_VFW_ROOT rw
LABEL serial
LINUX /boot/vmlinux
INITRD /boot/busybox-initrd-static
APPEND root=LABEL=HW_VFW_ROOT rw console=ttyS0
Umount
Umount the image
Disconnect
Disconnect the nbd0 device
A successful disconnection notification will appear in the prompt.
Verification
Now, after the image has been altered, verify how much the image has grown:
user@host /tmp % ls -lah hda.qcow2
-rw-r--r-- 1 user user 670M Jul 5 18:21 hda.qcow2
user@host /tmp % md5sum hda.qcow2
da2d73be483ec2e5e4d3d83bf5fe3e76 hda.qcow2
We barely resized the image, not even 1MB has been added to the image size. Image md5sum is now different too.
This is something you should know if using linux nbd module
Depending on the used application and amount of operations done on the mounted nbd partition, the filesize of the resulting qcow2 image will vary. This is what I have noticed that during usage. This is the reason why sed
is used instead of any other editor to change the file. It is to limit the amount of applied file operations to a absolute minimum. The less, the better.
Result
Now import the new image to GNS3. Do not boot this image yet outside of its emulator, the filesize will grow already if you boot it outside, due to applied tasks within the image. It is minimal, but stil, files are getting created, logs are getting written during its inital boot sequence.
The Web management Interface is sticked to the GigabitEthernet0/0/0, with a default RFC1918 IP address 192.168.1.1/24. Review the bootlog sequence|/documents/USG6000V1_console_init_bootlog.log]] messages, you will discover this IP address range in a section. Out Of Band management bound to a physical interface.
The Huawei USG default username and password are the same for both management interfaces, HTTPS and CLI.
username: admin
password: Admin@123
On the initial login the prompt will ask force you to change the default passowrd right on.
The finally booted USG6000V1 VRP prompt using ttyS0 serial line output in GNS3 showing VRP version and interface information:
*************************************************************************
* Copyright (C) 2014-2015 Huawei Technologies Co., Ltd. *
* All rights reserved. *
* Without the owner's prior written consent, *
* no decompiling or reverse-engineering shall be allowed. *
*************************************************************************
<USG6000V1>dis ver
Huawei Versatile Routing Platform Software
VRP (R) Software, Version 5.160 (USG6000V1 V500R001C10)
Copyright (C) 2014-2015 Huawei Technologies Co., Ltd
USG6000V1 uptime is 0 week, 0 day, 0 hour, 1 minute
IPS Signature Database Version : 2015081904
IPS Engine Version : V200R002C10SPC021
AV Signature Database Version :
SA Signature Database Version : 2015072900
C&C Domain Name Database Version :
Location Database Version : 2014010414
<USG6000V1>display interface brief
PHY: Physical
*down: administratively down
(l): loopback
(s): spoofing
(b): BFD down
(d): Dampening Suppressed
InUti/OutUti: input utility/output utility
Interface PHY Protocol InUti OutUti inErrors outErrors
GigabitEthernet0/0/0 up up 0% 0% 0 0
GigabitEthernet1/0/0 up down 0% 0% 0 0
NULL0 up up(s) 0% 0% 0 0
Virtual-if0 up up(s) -- -- 0 0
<USG6000V1>
This method can be used on all virtual images, or network operating system distribtuions. The amount of partitions using nbd0
will vary. Some available images have micromanaged partitions depending on purpose and system update stategy. There are images having up to 10 different partitions. This ends up in having nbd0p1
- nbd0p11
availble.
It is possible to mount several images at same time using the linux nbd kernel module. Each mounted image has a nbd suffix index: f.e.: nbd1
, nbd2
, nbd
N.