分享交流
合作共赢!

KVM基础使用方法总结【五】——cirros启动加速【亲测可用】

一、简介

cirros官方下载地址:https://download.cirros-cloud.net/

由于cirros映像封装了busybox拥有linux的各项功能,具有体积小,功能全的特点,常常被用来做网络等方面功能的测试使用。但是官方提供的映像文件在使用过程中,因为加载了一些cloud、网络等模块,启动速度特别慢(约20分钟,显示如下)。所以使用起来很不方便,现在我们做一些系统调整加快启动速度(调整后10秒启动)。

currently loaded modules: 8139cp 8390 9pnet 9pnet_virtio drm drm_kms_helper e1000 failover fb_sys_fops hid hid_generic ip_tables isofs mii ne2k_pci net_failover nls_ascii nls_iso8859_1 nls_utf8 pcnet32 qemu_fw_cfg syscopyarea sysfillrect sysimgblt ttm usbhid virtio_blk virtio_gpu virtio_input virtio_net virtio_rng virtio_scsi x_tables 
Initializing random number generator... done.
Starting acpid: OK
Starting network: udhcpc: started, v1.29.3
udhcpc: sending discover
udhcpc: sending select for 192.168.122.56
udhcpc: lease of 192.168.122.56 obtained, lease time 3600
OK
checking http://169.254.169.254/2009-04-04/instance-id
failed 1/20: up 6.44. request failed
failed 2/20: up 55.49. request failed
failed 3/20: up 104.54. request failed
failed 4/20: up 153.59. request failed
failed 5/20: up 202.65. request failed
failed 6/20: up 251.70. request failed
failed 7/20: up 300.77. request failed
failed 8/20: up 349.82. request failed
failed 9/20: up 398.87. request failed
failed 10/20: up 447.93. request failed
failed 11/20: up 496.99. request failed
failed 12/20: up 546.02. request failed
failed 13/20: up 595.07. request failed
failed 14/20: up 644.13. request failed
failed 15/20: up 693.17. request failed
failed 16/20: up 742.23. request failed
failed 17/20: up 791.26. request failed
failed 18/20: up 840.32. request failed
failed 19/20: up 889.39. request failed
failed 20/20: up 938.47. request failed
failed to read iid from metadata. tried 20
failed to get instance-id of datasource
Top of dropbear init script
Starting dropbear sshd: failed to get instance-id of datasource
mkdir: can't create directory '/etc/dropbear': No such file or directory
WARN: generating key of type rsa failed!
WARN: generating key of type ecdsa failed!
OK
GROWROOT: NOCHANGE: partition 1 is size 210911. it cannot be grown
/dev/root resized successfully [took 0.11s]
=== system information ===
Platform: Red Hat KVM
Container: none
Arch: i686
CPU(s): 1 @ 1799.999 MHz
Cores/Sockets/Threads: 1/1/1
Virt-type:
RAM Size: 425MB
Disks:
NAME MAJ:MIN SIZE LABEL MOUNTPOINT
sda 8:0 117440512
sda1 8:1 107986432 cirros-rootfs /
sda15 8:15 8388608
=== sshd host keys ===
-----BEGIN SSH HOST KEY KEYS-----
Failed reading '/etc/dropbear/dropbear_rsa_host_key'
Failed reading '/etc/dropbear/dropbear_ecdsa_host_key'
-----END SSH HOST KEY KEYS-----
=== network info ===
if-info: lo,up,127.0.0.1,8,,
if-info: eth0,up,192.168.122.56,24,fe80::5054:ff:fe76:a51b/64,
ip-route:default via 192.168.122.1 dev eth0
ip-route:192.168.122.0/24 dev eth0 scope link src 192.168.122.56
ip-route6:fe80::/64 dev eth0 metric 256
ip-route6:ff00::/8 dev eth0 metric 256
=== datasource: None None ===
=== cirros: current=0.5.1 uptime=988.75 ===
____ ____ ____
/ __/ __ ____ ____ / __ \/ __/
/ /__ / // __// __// /_/ /\ \
\___//_//_/ /_/ \____/___/
http://cirros-cloud.net


login as 'cirros' user. default password: 'gocubsgo'. use 'sudo' for root.
cirros login:

二、更改官方映像文件

1.修改配置文件/boot/grub/menu.lst

# vi /boot/grub/menu.lst

如下,添加内容”no_timer_check noapic”

default         0
timeout 0
hiddenmenu

title Linux Kernel
# Note, the root entry will be hd0,0 in disk image, but hd0 in partition
# it is changed on disk image creation.
root (hd0,0)
# FS_LABEL
kernel /vmlinuz LABEL=cirros-rootfs ro console=tty1 console=ttyS0 no_timer_check noapic
initrd /initrd.img
EOF

2.关闭DHCP服务

默认cirros启动会自动获取 DHCP,20次检查失败之后才能进入系统,这是系统启动慢的主要原因。编辑/etc/rc3.d/S40-network文件,将/sbin/ifup -a注释掉即可。

# vi /etc/rc3.d/S40-network

#!/bin/sh
#
# Start the network....
#

# Debian ifupdown needs the /run/network lock directory
mkdir -p /run/network

case "$1" in
start)
printf "Starting network: "
#/sbin/ifup -a
[ $? = 0 ] && echo "OK" || echo "FAIL"
;;
stop)
printf "Stopping network: "
/sbin/ifdown -a
[ $? = 0 ] && echo "OK" || echo "FAIL"
;;
restart|reload)
"$0" stop
"$0" start
;;
*)
echo "Usage: $0 {start|stop|restart}"
exit 1
esac

exit $?

3.移除cirros关联服务

# cd /etc/rc3.d/

# mv *cirros* /opt/
# ls -l
total 0
lrwxrwxrwx 1 root root 20 Aug 20 03:51 S01-logging -> ../init.d/S01logging
lrwxrwxrwx 1 root root 22 Aug 20 03:51 S10-load-modules -> ../init.d/load-modules
lrwxrwxrwx 1 root root 20 Aug 20 03:51 S20-urandom -> ../init.d/S20urandom
lrwxrwxrwx 1 root root 15 Aug 20 03:51 S21-acpid -> ../init.d/acpid
lrwxrwxrwx 1 root root 20 Aug 20 03:51 S40-network -> ../init.d/S40network
lrwxrwxrwx 1 root root 21 Aug 20 03:51 S50-dropbear -> ../init.d/S50dropbear
lrwxrwxrwx 1 root root 18 Aug 20 03:51 S55-resizefs -> ../init.d/resizefs
lrwxrwxrwx 1 root root 14 Aug 20 03:51 S99-logo -> ../init.d/logo

4.自定义提示信息

编辑配置文件/etc/issue,编写提示信息显示给登录用户。

# vi /etc/issue

三、总结

按此方法制作好的映像文件启动速度非常快,10秒钟左右就可以启动,大家可以试试!我这里制作好的镜像如下,有兴趣的话可以从文末点击”立即支付“下载使用(包含下面三种cirros映像文件和启动脚本)。

[root@node02 opt]# ll -h
total 86M
-rw-r--r--. 1 qemu qemu 14M Aug 20 11:09 cirros-zhangqiongjie.com-0.3.6-i386-disk.img
-rw-r--r--. 1 qemu qemu 34M Aug 20 12:41 cirros-zhangqiongjie.com-0.5.1-i386-disk.img
-rw-r--r--. 1 qemu qemu 38M Aug 20 12:40 cirros-zhangqiongjie.com-0.5.1-x86_64-disk.img

资源下载价格3.99立即支付
注意:本站少数资源收集于网络,如涉及版权等问题请及时与站长联系,我们会在第一时间内与您协商解决。如非特殊说明,本站所有资源解压密码均为:zhangqiongjie.com。 作者:1923002089
赞(1) 打赏
未经允许不得转载:琼杰笔记 » KVM基础使用方法总结【五】——cirros启动加速【亲测可用】

评论 抢沙发

评论前必须登录!

 

分享交流,合作共赢!

联系我们加入QQ群

觉得文章有用就打赏一下文章作者

非常感谢你的打赏,我们将继续给力更多优质内容,让我们一起创建更加美好的网络世界!

支付宝扫一扫打赏

微信扫一扫打赏