2015年11月5日木曜日

make a real machine from qemu image (仮想環境で作ったopenbsdを実環境で動かす)


i am greatly helped by openbsd fellows , especially 
tar over ssh   (thanks to Benny Lofgren)ん下
and 
install boot      (thanks to Jan Vlach).


(referrence 1) about qemu
    http://qemuandopenbsd.blogspot.jp/2015/09/qemu.html


in Japanese
夢(kvm)の中ではうまくいった。 じゃあこれを現実のハードデスクで 具現化したいとおもわないだろうか。
でも 霊界と現世との間では cpは通じない。
ただ sshという霊界トンネルをとおれば いけるのだ。
そのため tar over ssh を使う。
ただし 夢を見ながら 夢をコピーするので変質がおこる恐れもなきにしもあらずだ。

linuxの場合は うまい具合に qemu-nbdがあり、 これを使えば 夢からさめた後で コピーするので変質はおこらない。 同じのが openbsdにもあればなあと嘆く。 devつくてね


概略はこうだ 。
まず arch linuxをたちあげ 、
それから kvm guestとしてopenbsd.qcow2をたちあげる。
そして make world (正確には follow current)をする。
そしたら、openbsd.qcow2ができる。
linuxは openbsdのファイルシステムを認識できないので 、
一旦 linuxからもopenbsdからも読み書き可能なext2へコピーする。
次はopenbsdを立ち上げ ext2 から例えば /home/user-fogeへ openbsd.qcow2を コピーし、
これをopenbsd の qemu guestとして立ち上げる。
openbsdなので 他のドライブのopenbsdファイルシステムは認識するので
この他のドライブへ tar over sshで 写す。
これで終了だ!





i prepare 4 story .
i pactice and scceed  
            1st and 2nd and 3rd  story .


i have not practice   4th story yet .
but i guess it is perhaps OK .
 


1st story -----------------------
first overall view

 



i intend to install  [i386 openbsd] on the sd0a area.
i write this story .



1) on rental server

                       rental server (openbsd) is running at sd1a

mount /dev/sd0a /MNT



2)boot bohdi

A) install kvm 0penbsd

 qemu-system-i386 -hda Q30.img -enable-kvm  -cdrom install58.iso -boot d -m 1024
( install58.iso is i386 snapshots   ) 


B) run kvm 0penbsd
qemu-system-i386 -enable-kvm -m 1024 -hda Q30.img   -net nic,macaddr=52:54:00:12:11:11 -net tap,ifname=tap0,script=/etc/qemu-ifup 


C) cd /; tar cvpf -   .  | ssh root@1.2.3.4     "cd /MNT ;  tar xpf -"



3) again on rental server

rewite /MNT/etc/fstab          <- disklabel sd0
 
installboot -r /MNT sd0


4)boot rental server by grub2


i can boot i386 openbsd of sd0a !







2nd story: ----------- for openbsd
1) run linux
     make kvm.img in sdb1 (ext2)   




 2)run openbsd
# mount_ext2fs /dev/sd1i /EXT2/

because of the weak ext2fs
# cp      /EXT2/OpenBSD-current.img   ./
# umount  /EXT2

# mount /dev/sd1a /MNT/

#qemu-system-x86_64 -m $1 -hda $2 -net nic,vlan=1,model=e1000,macaddr=fe:e1:ba:d3:e7:11 -net tap,vlan=1

# ssh -l tuyosi 192.168.100.115 (192.168.100.115 is kvm guest address)



# and on this qemu guest
rm -rf /usr/src/*
rm -rf /usr/obj/*
rm -rf /usr/xobj/*
rm -rf /usr/xenocara/*


cd /; tar cvpf -   .  | ssh root@192.168.100.101  "cd /MNT ;  tar xpf -"
                                (192.168.100.101 is kvm host address)
  and agein return to  qemu host
a)  rewite /MNT/etc/fstab   
       disklabel sd1
 
cat /MNT/etc/fstab   
9f39539222428a90.b none swap sw
#9f39539222428a90.a / ffs rw 1 1
#duid: 183119b913f9d677
183119b913f9d677.a / ffs rw 1 1
 
b)  installboot -r /MNT sd1


halt -p
boot by grun2

snapshots and sd1a appear , success!


 
3rd story  : for Linux




this gray part is written for japanese .     
the writing in english is later .
qemu-nbd をつかったものをかきます。
debiandog でしてます。

sda1はdebiandogで sda4に sda1にあるイメージTC.imgを実装します
したがってtinycoreのqemu イメージ /TC.imgはできた後の作業です。

    aptitude install  qemu-nbd

    # modprobe nbd max_part=8


    # qemu-nbd --connect=/dev/nbd0   /TC.img     

    # mount /dev/nbd0p1 /KVM

    mount  /dev/sda4  /MNT/
   (cd /KVM ; tar cvpf - .)|(cd /MNT ; tar xpf -)


     # umount /KVM
     # qemu-nbd --disconnect /dev/nbd0

     # umount /MNT

        edit /boot/grub/grub.cfg in /dev/sda1

 menuentry ' tc' {
 set root='hd0,msdos4'
 linux /tce/boot/vmlinuz
 initrd /tce/boot/core.gz

}

以上です。





on kvm host, lxle
mount  /dev/sdb1  /MNT

on  kvm guest , bean
cd /; tar cvpf -   .  | ssh root@192.168.100.101    "cd /MNT ;  tar xpf -"



again
on  kvm host, lxle
        edit /boot/grub/grub.cfg in /dev/sda1
menuentry 'bean' {
    set root='(hd1,msdos1)'
    linux    /boot/vmlinuz-3.2.0-89-generic root=UUID=d88f3df3-769d-4f79-b22a-8c2864cd555f ro  
    initrd    /boot/initrd.img-3.2.0-89-generic
}



another Linux specific method : 
this method is very secure because BEAN is not runnning .
[tar over ssh] method is copy running image to a partition , so there may be problems , so i think . 

on kvm host, lxle

    aptitude install  qemu-nbd

    # modprobe nbd max_part=8
    # qemu-nbd --connect=/dev/nbd0   /BEAN.img     # mount /dev/nbd0p1 /KVM



  mount  /dev/sda4  /MNT/
 (cd /mnt/kvm ; tar cvpf - .)|(cd /MNT/ ; tar xpf -)


edit    /MNT/etc/fstab

     # umount /KVM
     # qemu-nbd --disconnect /dev/nbd0

     # umount /MNT

        edit /boot/grub/grub.cfg in /dev/sda1
 menuentry ' tc' {
 set root='hd0,msdos4'
 linux /tce/boot/vmlinuz
 initrd /tce/boot/core.gz
}


apparently , changing sdb1 for sda3 is OK in Linux.
namely , 1 drive is OK ,
               but this setting does not fit to openbsd
               because  in openbsd 1 drive  should have only  1 openbsd file system .
                                 
perhaps other combination is possible .
 for example  kvm host is arch , and kvm guest is debian.
 but i did not try it yet .

about arch's qemu ,   see
   http://hatahata50.blogspot.jp/2015/10/arch-linux-qemu.html
                                                                                 (written in japanese)

real example is here !
http://qemuandopenbsd.blogspot.jp/2015/11/bohdi-arch20qcow2.html



the 4th story----------- only plan



archlinux machine is kvm supported intel machine
and
openbsd machine is i386 machine.

i386 machine cannot compile sources
                          becase of it's poor memory (256MB)


so
compaling current sources should be done on amd64 fast  PC
and
only binaly should be exported to old i386 machine .


why kvm ? -> if following current fails  , i only erase the kvm image file .
                and if succeed , back up is easy to copy  the kvm image file .
                openbsd lacks kvm module  , so openbsd's qemu is slow  .
            



overall view is next .

hub looks like internet .



i use 3 colours.

192.168.100.106

 

192.168.100.101 *about arch's kvm :
                               http://hatahata50.blogspot.jp/2015/10/arch-linux-qemu.html


192.168.100.116

1) on openbsd= 192.168.100.106
 mount /dev/sd1a  /MNT


2)on archlinux=192.168.100.101

a)boot archlinux

qemu-image create -f qcow2 OpenBSD-current.img 30G

B)install
qemu-system-i386 -m 1024 -hda OpenBSD-current.img -cdrom install58.iso(i386 current) -boot d   -net nic,vlan=1,model=e1000,macaddr=fe:e1:ba:d3:e7:11 -net tap,vlan=1


c)run
qemu-system-i386 -m 1024 -hda OpenBSD-current.img -net nic,vlan=1,model=e1000,macaddr=fe:e1:ba:d3:e7:11 -net tap,vlan=1

and
ssh -l tuyosi  192.168.100.106


3)on kvm's openbsd=192.168.100.116


when the follwing current is  finished (reboot and 2)'s run and ssh  )

ssh  root@192.168.100.106   "tar cvpf    -  /      | tar  xpf     - -C  /MNT

or
ssh  root@192.168.100.106   "tar czpf    -  /      | tar  xzpf     - -C  /MNT

or original is
ssh root@192.168.100.106   "tar czpf - / " | tar xzpf - -C /MNT

or

from ML
cd /; tar cfz -   | ssh root@real_machine        "cd /MNT;    tavfpz -"
correct miss typing 
cd /; tar cvpf -   .  | ssh root@192.168.100.106  "cd /MNT ;  tar xpf -"




4) on openbsd= 192.168.100.106

rewite /MNT/etc/fstab  <- disklabel wd1
 
 
installboot -r /MNT wd1
 
 

5) boot by grub2

 







Impossible Dream Don Quixote)

To dream the impossible dream
To fight  the unbeatable foe
To bear with unbearable sorrow
To run where the brave dare not go

To right the unrightable wrong
To love pure and chaste from a far
To try when your arms are too weary
To reach the unreachable star

This is my quest to follow that star
No matter how hopeless, no matter how far
To fight for the right
Without question or pause
To be willing to march
Into hell for a heavenly cause

And I know if I’ll only be true
To this glorious quest
That my heart will lie peaceful and calm
When I’m laid to my rest

And the world will be better for this
That one man, scorned and covered with scars
Still strove with his last ounce of courage
To reach the unreachable star
The fight the unbeatable foe
To dream the impossible dream


以下日本語で書きます。
 qemu~KVM にて 他のCPUをエミュレートしてコンパイルができます。
  失敗すれば KVMはファイルなので 消せばよい。
  成功すれば そのimage ファイルをコピーすれば バックアップできる。

また
cd /; tar cvpf -   .  | ssh root@1.2.3.4     "cd /MNT ;  tar xpf -"
にて実機に バイナリを送れます。
ということは x86_64 マシンさえあれば 純粋i386を作れます。

  32bit版では、2の32乗・・・つまり、約4GBのメモリが扱えるのに対して、
  64bit版では(理論上)2の64乗・・・つまり、16エクサバイトと言う
       とてつもなく大きなメモリが取り扱える事になりますが

CPU i386 、 メモリ  64MB ではコンパイル自体が無理です。



もちろん sparc64、powerPCもエミュレートできます。
その心は
http://gihyo.jp/dev/serial/01/vm_work/0001?page=2
仮想マシン上で動作するOSは
「そこに本物のハードウェアがある」と錯覚した状態で動作するため,使用するOS側に別途変更を加える必要がない点が魅力ですが,そのかわりに仮想マシンの実装は複雑になりがちです。
VMware,Hyper-V,KVMXenなどの主要な仮想マシンソフトウェアは,完全仮想化の方式をとっています。
 
 
よく考えると 
x86_64つまりamd64は i386を実行できるのだ。
だから 
なにもKVMの上でなくとも 純粋i386コーディングができるかは別として 実機でやればよい。
それで 
openbsdには amd64とi386の間にしか効かない
            kvm moduleがないのも頷ける。
 
したがって 
amd64の上で powepcを動かすとか(kvm効かないよ
危険なOSをkvm で動かすとか
linuxをしながら openbdのcurrentをKVMで追うとか
debug(自分の駄目ソースを実行したらOS自体まで壊した; 極例は rm -rf /
とかに使うべきだろう。 



ただ、もしも もしも
100Gメモリ core9な 64ビットPC で
純粋i386 OSを   純粋i386コンパイラーで
make world し 、 それを 
貧弱な i386 machine(CPUセレロン メモリ514M) に
実装できたら カ イ カ ン
その心は そのi386 machine には できないから。
なお 32bit PCでは メモリは 2の32乗で 4Gが限界
64bitでは さらに4Gx2x2x2.......x2(32回)なので まあ無限ですね。
 
 
linuxを起動し 、最初に openbsd current のイメージをコピーする。
それから openbsd current を kvm guestでたちあげて 
もっと新しいソースを追っかけている。
そして うまくいったらそれを 外付けHDDに実装してたしかめている。


fdisk -e sd1
edit 3

disklabel -E sd1
newfs sd1a
 
 
 https://www.youtube.com/watch?v=bqmWOSV--mE&spfreload=10


Korean soldier when the Vietnam War was added to the sexual assault 
against Vietnamese women .
But there is no apology from South Korea to Vietnam for this thing.
https://en.wikipedia.org/wiki/Phong_Nh%E1%BB%8B_and_Phong_Nh%E1%BA%A5t_massacre
 
 



https://www.youtube.com/watch?v=2oLmlYSJEy0
The term Lai Dai Han is a Vietnamese term for a mixed ancestry person 
born to a South Korean father 
and 
a Vietnamese mother (including the victims of Korean soldiers) 
during the Vietnam War
 
 Lai Dai Han often live at the margins of Vietnamese society. 
The South Korean government has not released an official statement 
regarding the sexual violence that took place during the Vietnam War.

0 件のコメント:

コメントを投稿