Benutzer:Klaus Piotrik Qais Felli-Littmann/Arch Linux bei Kimsufi via Qemu

Diese Anleitung basiert auf einem Forumpost von heise.

# Set the language environment
export LANGUAGE=C;export LC_ALL=C;export LANG=C

# Booting the rescue systems gives you a complete linux system that is running on your server without using your harddisk.

# First get the network data of your server: ifconfig and save network data like IP, gateway, mac, etc.
root@rescue:~# ifconfig
eth0      Link encap:Ethernet  '''HWaddr 38:60:77:3e:f2:58'''  
          '''inet addr:37.59.29.XXX'''  Bcast:37.59.29.255  Mask:255.255.255.0
          inet6 addr: fe80::3a60:77ff:fe3e:f258/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:90360 errors:0 dropped:0 overruns:0 frame:0
          TX packets:24816 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:115106829 (109.7 MiB)  TX bytes:4129029 (3.9 MiB)
          Interrupt:20 Memory:fe500000-fe520000 

root@rescue:~# netstat -nr
Kernel IP routing table
Destination     '''Gateway'''         Genmask         Flags   MSS Window  irtt Iface
0.0.0.0         '''37.59.29.254'''    0.0.0.0         UG        0 0          0 eth0
37.59.29.0      0.0.0.0         255.255.255.0   U         0 0          0 eth0

#Part of dmesg:
root@rescue:~# dmesg
e1000e: eth0 NIC Link is Up 100 Mbps Full Duplex, Flow Control: None
e1000e 0000:00:19.0 eth0: 10/100 speed: disabling TSO
IPv6: ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready
Sending DHCP requests .., OK
IP-Config: Got DHCP answer from 37.59.29.252, '''my address is 37.59.29.XXX'''
IP-Config: Complete:
     device=eth0, hwaddr=38:60:77:3e:f2:58, ipaddr=37.59.29.XXX, mask=255.255.255.0, gw=37.59.29.254
     host=37.59.29.164, domain=, nis-domain=(none)
     bootserver=37.59.1.237, rootserver=37.59.1.237, rootpath=/home/pub/bsd-rescue
     nameserver0=213.186.33.99

# Second step is to get rid of the network drives, because they are read-only
root@rescue:~# top
KiB Mem:  16331460 total,   558884 used, 15772576 free,    62896 buffers
KiB Swap:        0 total,        0 used,   522236 free,   215728 cached
swapon /dev/sdb3    # use your own swap

root@rescue:~# mdadm /dev/md2 --fail /dev/sda2 --remove /dev/sda2
mdadm: set /dev/sda2 faulty in /dev/md2
mdadm: hot removed /dev/sda2 from /dev/md2

# Create partition for rescue system and new install
fdisk -u /dev/sda       # neue Partition in Größe von 30GB sollte ausreichen
n 6 default +30G
p
/dev/sda1   *        4096     1050623      523264   fd  Linux raid autodetect
/dev/sda2         1050624    42991615    20970496   fd  Linux raid autodetect
/dev/sda3        42991616    59766783     8387584   fd  Linux raid autodetect    # wrong partition type
/dev/sda4        59766784  1953509375   946871296    f  W95 Ext'd (LBA)
/dev/sda5        59768832   121204735    30717952   fd  Linux raid autodetect
/dev/sda6       121206784   184121343    31457280   83  Linux
t 3 82   # Linux swap
t 2 83
w

partprobe

mkfs.ext4 /dev/sda2
mkfs.ext4 /dev/sda6

mount  /dev/sda2 /mnt # use 10GB as recovery system 
rsync -avHAXS --dry-run --exclude=/mnt --exclude=/proc --exclude=/dev --exclude=/sys --exclude=/run --progress / /mnt

root@rescue:~# unlink /mnt/boot
root@rescue:~# unlink /mnt/opt 
root@rescue:~# unlink /mnt/usr
root@rescue:~# mv /mnt/nfs/boot /mnt/boot
root@rescue:~# mv /mnt/nfs/opt /mnt/opt 
root@rescue:~# mv /mnt/nfs/usr /mnt/usr

unlink /mnt/var/backups;cp -r /nfs/var/backups /mnt/var/backups
unlink /mnt/var/cache;cp -r /nfs/var/cache /mnt/var/cache
unlink /mnt/var/lib;cp -r /nfs/var/lib /mnt/var/lib
cp -r /run /mnt/run
unlink /mnt/var/lock;ln -s /mnt/run/lock
unlink /mnt/var/run;ln -s /mnt/run /mnt/var/run


# KiB Mem:  16331460 total,  2450864 used, 13880596 free,    26188 buffers
# KiB Swap:   522236 total,        0 used,   522236 free,  2075168 cached
sync; echo 3 > /proc/sys/vm/drop_caches
# KiB Mem:  16331460 total,   289492 used, 16041968 free,      132 buffers
# KiB Swap:   522236 total,        0 used,   522236 free,    91132 cached

mount -B /mnt/var/cache /var/cache
mount -B /mnt/var/lib /var/lib
mount -B /mnt/usr /usr

# Now our linux system is mounted rw

mkdir /mnt/proc;mount -B /proc /mnt/proc
mkdir /mnt/sys;mount -B /sys /mnt/sys

# download windows iso into /mnt 
# wget http://domain.tld/yourwindows.iso #adjust as necessary
mkdir /mnt/md2
mount /dev/md2 /mnt/md2
cd /mnt/md2
wget http://archlinux.mirrors.ovh.net/archlinux/iso/2014.02.01/archlinux-2014.02.01-dual.iso

# use QEMU from wheezy backports
# enable wheezy-backports

apt-get update
apt-get -t wheezy backports install qemu # take over 200MB

root@ns333XXXX:~# df -h
Filesystem                                              Size  Used Avail Use% Mounted on
rootfs                                                   20G  6.7G   13G  36% /
udev                                                     10M     0   10M   0% /dev
tmpfs                                                   1.6G  392K  1.6G   1% /run
/dev/disk/by-uuid/37ffbf7c-be5b-4d75-86df-c66413401dd3   20G  6.7G   13G  36% /
tmpfs                                                   5.0M     0  5.0M   0% /run/lock
tmpfs                                                   3.2G     0  3.2G   0% /run/shm
/dev/md5                                                 29G  1.4G   27G   5% /mnt/fedora


# Now use qemu
apt-get install squashfs-tools
qemu -cpu qemu64 -smp 2 -vnc :0 -m 2048 -usbdevice tablet -k en-us -cdrom  -hda /dev/sda -hdb /dev/sdb 

-cpu (CPU Type)
-smp (# of Processors)
-vnc (use VNC as monitor output)
:0 (means use vncdisplay :0 = 5900 port, :1 = 5901 port, etc)
-m (amount of memory)
-usbdevice (useful with VNC)
-k (keyboard format)
-cdrom (image file)
-hda (first hdd -> using physical HDD)
-hdb (second hdd -> using physical HDD)

[update] qemu-system-x86_64 -vnc :0 -m 2048 -usbdevice tablet -k en-us -cdrom /mnt/yourwindows.iso -hda /dev/sda -hdb /dev/sdb # to get 64-bit mode on Atom D2550 CPU [/update]

On your client maschine you can use the following command to tunnel vnc through ssh to safely access your headless qemu session

vncviewer -via root@yourip localhost:0

-via (login to your server through ssh, using user root and standard ssh port)
-localhost:0 (ssh makes remoteserver be localhost for you, :0 means connecting to port 5900 on remote server, :1 would mean connecting through port 5901, etc)



I use this method to unsquash my linux backup

apt-get install squashfs-tools
#--allow-unauthenticated
wget http:myimage
mkdir /mnt/md
cat /proc/mdstat # see raid devices
mount /dev/md1 /mnt/md
usquashfs -f -d /mnt/md /mnt/squash.file
mount -B /dev /mnt/md/dev
mount -B /sys /mnt/md/sys
mount -B /proc /mnt/md/proc
chroot /mnt/md
update system, like passworts, ip addresses, network mac, etc.


links: 
http://doc.opensuse.org/products/dra...u.running.html
http://wiki.qemu.org/download/qemu-doc.html
http://www.linux-kvm.com/content/tip...-using-vnc-kvm
http://www.ducea.com/2009/03/08/mdadm-cheat-sheet/