Basically they are two methods how to install Linux Core. The first option is to use a Linux Core installation script that comes with tc-install extension. One should take this option as installation process is interactive and automated thanks to the installation script. The second method is manual installation of Core Linux and will be described in the tutorial.
The installation steps provided below have been tested for x86 and x86-64 Linux Core 6.x and they show step-by-step installation on Qemu virtual machine.
If you prefer automated Core Linux installation using an installation script, check this tutorial. Qemu installation on Fedora Linux is shown here.
Linux Core Live x86 and x86-64 ISO images can be downloaded from Tinycore webpage. I have created the script download_core64.sh that downloads the latest CorePure64 ISO image. Afterwards it creates a vmdk disk and starts the Qemu virtual machine with attached vmdk disk and CorePure ISO image.
1. Create Qemu Disk
x86
$ /usr/local/bin/qemu-img create -f qcow2 linux-core.img 200M
x86-64
$ /usr/local/bin/qemu-img create -f qcow2 corepure64.img 200M
2. Start Qemu Virtual Machine with Attached Live ISO Core Image
x86
$ /usr/local/bin/qemu-system-i386 -boot d -cdrom Core.iso -hda linux-core.img
x86-64
$ /usr/local/bin/qemu-system-x86 -boot d -cdrom Core.iso -hda corepure64.img
3. Install Syslinux Extension
$ tce-load -wi syslinux
4. Create New Partition Ext4 Type
$ sudo fdisk /dev/sda
n Add new partition
p primary partition
Partition number (1-4): 1
First cylinder (1-25, default 1): ENTER
Last cylinder (1-25, default 25): ENTER
a toggle a bootable flag
Partition number (1-4): 1
w write table to the disk and exit
$ mkfs.ext4 /dev/sda1
5. Install Boot Sector
$ dd if=/usr/local/share/syslinux/mbr.bin of=/dev/sda
6. Rebuild /etc/fstab and Mount Partition /dev/sda1
$ sudo rebuildfstab
$ mount /mnt/sda1
7. Mount CDROM and Copy Files core.gz and vmlinuz to /mnt/sda1/boot
$ sudo mkdir -p /mnt/sda1/boot/extlinux
x86
$ mount /mnt/sr0
$ sudo cp -pr /mnt/sr0/boot/* /mnt/sda1/boot
x86-64
$ mount /mnt/sdb
$ sudo cp -pr /mnt/sdb/boot/* /mnt/sda1/boot
8. Install Boot Loader
$ sudo extlinux --install /mnt/sda1/boot/extlinux
9. Create Menu Config File
x86
$ sudo vi /mnt/sda1/boot/extlinux/extlinux.conf
DEFAULT core
LABEL core
KERNEL /boot/vmlinuz
APPEND initrd=/boot/core.gz quiet
x86-64
$ sudo vi /mnt/sda1/boot/extlinux/extlinux.conf
DEFAULT core64
LABEL core64
KERNEL /boot/vmlinuz64
APPEND initrd=/boot/corepure64.gz quiet
10. Create Directory for Storing Extension and Setup Proper Ownership
$ sudo mkdir /mnt/sda1/tce
$ sudo chown tc:staff /mnt/sda1/tce
$ touch /mnt/sda1/tce/mydata.tgz
11. Shutdown Core
Shutdown core and start it with the command below.
x86
$ /usr/local/bin/qemu-system-i386 -boot c -hda linux-core.img
x86-64
$ /usr/local/bin/qemu-system-x86_64 -boot c -hda CorePure64.img
Remastering Linux Core For Redirecting Output To Serial Port
This part discuss remastering of Linux Core for redirecting the CLI output to a serial port. Qemu can redirect a serial port of a guest virtual machine to the telnet server that it starts on the host machine. Thanks to it everyone can connect to a virtual machine even the virtual guest is not configured for accepting remote connection (ssh, telnet). This feature is very handy specially in a test environment where security is not an issue.
For example, the Qemu command -serial telnet:0.0.0.0:3000,server,nowait starts a telnet sever on a host machine and redirects a serial port of Qemu guest virtual machine to the server. The telnet server is listening for incoming connection to its IP address with destination TCP port 3000.
Note: Remastering is shown for 32 bit version of Core Linux. Remastering steps for 64 bit Core distribution are identical except that the core64 and vmlinux64 keywords must be used.
1. Edit Menu Config File
$ sudo vi /mnt/sda1/boot/extlinux/extlinux.conf
DEFAULT core
LABEL core
KERNEL /boot/vmlinuz console=ttyS0,38400n8
APPEND initrd=/boot/core.gz quiet
2. Extract File core.gz
$ mkdir -p /home/tc/temp/extract
$ sudo cp /mnt/sda1/boot/core.gz /home/tc/temp/
$ cd /home/tc/temp/extract/
$ zcat ../core.gz | sudo cpio -i -H newc -d
3. Disable Autologin for tty1 and add ttyS0
Autologin is useful when you do not want prompt user for login credentials. Unfortunately Core Linux hangs up after boot when autologin is in use and output is redirect to a serial port. For this reason we are going to disable autologin for tty1 and ttyS0.
Picture 1 - Core Randomly Hangs Up when Autologin is Used
$ sudo vi ./etc/inittab
#tty1::respawn:/sbin/getty -nl /sbin/autologin 38400 tty1
tty1::respawn:/sbin/getty 38400 tty1
ttyS0::respawn:/sbin/getty 38400 ttyS0
4. Display Login Credentials
If you use Linux Core for testing it might by helpful to display login credentials when autologin is not used. Add the following lines to the file ./etc/issue.
$ sudo vi ./etc/issue
Login to Core Linux
Username "tc", password is not set
5. Edit /etc/securetty to Allow Root Login to Serial Port ttyS0
Uncomment line #ttyS0
$ sudo vi ./etc/securetty
ttyS0
6. Pack File core.gz
$ sudo su
$ cd /home/tc/temp/extract/
$ find | cpio -o -H newc | gzip -2 > /mnt/sda1/boot/core.gz
$ cd /home/tc
$ rm -rf /home/tc/temp
7. Test If Output Is Redirected to Serial Port
Shutdown Core Linux Qemu virtual machine.
$ sudo halt
$ /usr/local/bin/qemu-system-i386 -boot c -hda linux-core.img -serial telnet:127.0.0.1:3000,server,nowait
Connect to serial port of Core using a telnet command.
$ telnet 127.0.0.1 3000
Man your a complete Geek !!! Overall A great website ..... thanks for your great shares in such details, even a noob can understand ....
Hello Brezular,
Thank you for this comprehensive guide.
I was able to build a Tiny Core Linux 7.0 image following this guide. The only problem I am facing is that, the output on the serial console doesn't show up until the login prompt is displayed. In your pre-built images, I can see the output right from booting. Can you please provide a hint on how to do that?
Output is sent to serial port during booting when Core is remastered for it. You can see the output of your Qemu Core VM during its boot if you tell Qemu to redirect its output to serial port with this command sequence-serial telnet:0.0.0.0:3000,server,nowait. Then you can simply connect to the serial port with command telnet 127.0.0.1 3000 and you will see the boot process.
I ran the same qemu command on both machines, your machine (linux-core-4.7.7.img) and my machine (nm.img). Your machine directs the output to the serial console from the beginning, while mine waits until the login prompt is displayed. I don't know why.
The following video shows the output:
https://www.youtube.com/watch?v=ZPIHk1jEVJc
I am not sure what do you mean by remastering. I have installed Tiny Core using the standard installation tool. I only modified the etc/inittab, etc/securetty, the extlinux.conf and the etc/issue files inside core.gz.
OK I figured it out. I have edited the /mnt/sda1/tce/boot/extlinux/extlinux.conf and changed the order of kernel boot parameters. Here is how the file looks like:
DEFAULT core
LABEL core
KERNEL /tce/boot/vmlinuz
APPEND initrd=/tce/boot/core.gz console=ttyS0,9600n8 quiet host=nm waitusb=5:UUID="b1e14660-dd53-407a-858e-04e50c84af9b" tce=UUID="b1e14660-dd53-407a-858e-04e50c84af9b"
Previously, the second line was:
KERNEL /tce/boot/vmlinuz console=ttyS0,9600n8
References:
http://www.tldp.org/HOWTO/Remote-Serial-Console-HOWTO/configure-kernel-syslinux.html
http://www.tldp.org/HOWTO/Remote-Serial-Console-HOWTO/configure-kernel.html
Thanks a lot for your help.
You're a genius, man! Thank you for sharing!
I was looking for a way to create my own Tiny Core QEMU guest for gns3 and your article solved my problem (console redirection)