[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[Libguestfs] [PATCH] Converter: Update xvc0 console to ttyS0



This change updates a guest which uses Xen's xvc0 to use ttyS0 instead. In a
related change, it also makes a console a 'standard device' will always be
configured.
---
 lib/Sys/VirtV2V/Converter.pm       |    5 +++-
 lib/Sys/VirtV2V/Converter/Linux.pm |   46 ++++++++++++++++++++++++++++++++++++
 2 files changed, 50 insertions(+), 1 deletions(-)

diff --git a/lib/Sys/VirtV2V/Converter.pm b/lib/Sys/VirtV2V/Converter.pm
index 8d46502..45038ee 100644
--- a/lib/Sys/VirtV2V/Converter.pm
+++ b/lib/Sys/VirtV2V/Converter.pm
@@ -75,6 +75,7 @@ use constant KVM_XML_VIRTIO => "
     <video>
       <model type='cirrus' vram='9216' heads='1'/>
     </video>
+    <console type='pty'/>
   </devices>
 </domain>
 ";
@@ -98,6 +99,7 @@ use constant KVM_XML_NOVIRTIO => "
     <video>
       <model type='cirrus' vram='9216' heads='1'/>
     </video>
+    <console type='pty'/>
   </devices>
 </domain>
 ";
@@ -240,7 +242,8 @@ sub _configure_default_devices
     my ($input_devices) = $default_dom->findnodes('/domain/devices');
 
     # Add new default devices from default XML
-    foreach my $input ($input_devices->findnodes('input | video | graphics')) {
+    foreach my $input ($input_devices->findnodes('input | video | '.
+                                                 'graphics | console')) {
         my $new = $input->cloneNode(1);
         $new->setOwnerDocument($devices->getOwnerDocument());
         $devices->appendChild($new);
diff --git a/lib/Sys/VirtV2V/Converter/Linux.pm b/lib/Sys/VirtV2V/Converter/Linux.pm
index 96e37a4..df7c969 100644
--- a/lib/Sys/VirtV2V/Converter/Linux.pm
+++ b/lib/Sys/VirtV2V/Converter/Linux.pm
@@ -112,6 +112,7 @@ sub convert
     my $virtio = $guestos->supports_virtio($kernel);
 
     # Configure the rest of the system
+    _configure_console($g);
     _configure_display_driver($guestos, $virtio);
     $guestos->remap_block_devices($devices, $virtio);
     _configure_kernel_modules($guestos, $desc, $virtio);
@@ -193,6 +194,51 @@ sub _configure_kernel_modules
     }
 }
 
+# We configure a console on ttyS0. Make sure existing console references use it.
+sub _configure_console
+{
+    my ($g) = @_;
+
+    # Look for gettys which use xvc0
+    foreach my $augpath ($g->aug_match("/files/etc/inittab/*/process")) {
+        my $proc = $g->aug_get($augpath);
+
+        # If the process mentions xvc0, change it to ttyS0
+        if ($proc =~ /\bxvc0\b/) {
+            $proc =~ s/\bxvc0\b/ttyS0/g;
+            $g->aug_set($augpath, $proc);
+        }
+    }
+
+    # Replace any mention of xvc0 in /etc/securetty with ttyS0
+    my $size = 0;
+    my @lines = ();
+
+    foreach my $line ($g->read_lines('/etc/securetty')) {
+        if($line eq "xvc0") {
+            $line = "ttyS0";
+        }
+
+        $size += length($line) + 1;
+        push(@lines, $line);
+    }
+
+    $g->write_file('/etc/securetty', join("\n", @lines)."\n", $size);
+
+    # Update any kernel console lines
+    foreach my $augpath
+        ($g->aug_match("/files/boot/grub/menu.lst/title/kernel/console"))
+    {
+        my $console = $g->aug_get($augpath);
+        if ($console =~ /\bxvc0\b/) {
+            $console =~ s/\bxvc0\b/ttyS0/g;
+            $g->aug_set($augpath, $console);
+        }
+    }
+
+    $g->aug_save();
+}
+
 sub _configure_display_driver
 {
     my ($guestos, $virtio) = @_;
-- 
1.6.6.1


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]