ãããã£ãŠãããªãããŒãªæ¹æ³ã§ãã¹ãŠãsshã§å®è¡ããå¿ èŠããããŸãã äž»ãªã¢ã€ãã¢ã¯ãæ°ããä»®æ³ãã·ã³ã§ã«ãŒããã¡ã€ã«ã·ã¹ãã ãã¢ã³ããŠã³ãããå€ãä»®æ³ãã·ã³ãããã¡ã€ã«/ã€ã¡ãŒãžãã¢ããããŒãããgrubèšå®ãæŽæ°ãããããã¯ãŒã¯ãšfstabèšå®ãæŽæ°ããåèµ·åããããšã§ãã
æåã®ã¹ãããã§æãæçœãªã ã¢ã³ããŠã³ãããããšãã§ããŸã/ã©ã€ãã·ã¹ãã ã§ã¯ãããã¯éå±ã§ã¯ãããŸãããæ¬ç©ã§ãã sshãµãŒããŒãšããã€ãã®ãŠãŒãã£ãªãã£ãinitramdiskã«è¿œå ãããããããã¹ãŠãå®è¡ããæ¹ãã¯ããã«ç°¡åã§ãã OSã®ããŒãã®ãã®æ®µéã§ã¯ãã«ãŒãã·ã¹ãã ã¯ãŸã ããŠã³ããããŠããŸããã
å®éãèšäºå šäœã¯ãramdiskã«sshãµãŒããŒãå«ããããã®ãŠãŒãã£ãªãã£ãš2ã€ã®è§£æãããäŸã®ãã¢ã§ãã
DebianãµãŒããŒãæºä»®æ³åã䜿çšããŠXenããDigital Oceanã«ç§»è¡ããŸãã
DigitalOceanä»®æ³ãã·ã³ã«ã¯ãä»®æ³ãã·ã³èªäœããã«ãŒãã«ãå€æŽããæ©èœãããããšãéèŠã§ãïŒDigitalOceanã³ã³ãããŒã«ããã«ã®[ã«ãŒãã«]ã¿ãã§ã¯ããã¹ãå ã®ã«ãŒãã«ãå€æŽããããã«èšè¿°ããå¿ èŠããããŸãïŒã
Xenã®ãœãŒã¹ïŒ
ãã®ãããªãã¢ããŒãžãæã€nginxããããŸã
ã¹ããã1.移è¡ã®ããã®ãœãŒã¹ãµãŒããŒã®æºå
ãœãŒã¹ãµãŒããŒããªãã«ããŠãã€ããŒãã€ã¶ãŒãããã¡ã€ã«/ã€ã¡ãŒãžãæäŸããã ãã§ã¯äœãæºåã§ããŸããããããã¯é¢çœããªããããã«ãœãŒã¹ã¯ä»®æ³ãã·ã³ã§ã¯ãªããã¢ã¡ã¿ã«äžã«ããå¯èœæ§ããããŸãã ãããã£ãŠãæåã®æé ã¯ãã«ãŒããã¡ã€ã«ã·ã¹ãã ïŒããã³ãæ¥ç¶ãããŠããFSïŒããå ŽåïŒïŒãèªã¿åãå°çšã§åããŠã³ãããããšã§ãã èªã¿åãå°çšã§ã®åããŠã³ãã¯ãå®å šã«ã¢ã³ããŠã³ããããããã¯ããã«ç°¡åã§ã-äœããæžã蟌ãããšãã§ããããŒã¢ã³ãéä»ãããã ãã§ååã§ãã
/etc/init.d/nginx stop apt-get install lsof rsync lsof /
æ®ã£ãŠãããã®ãèŠãŸãã FDåãwãŸãã¯uã§çµããè¡ã«èå³ããããŸã
ãããrsyslogã¯æ®ã£ã
kill 6288 mount -o remount,ro /
ãããæ©èœããå Žåããããè¯ãå Žåãããã§ãªãå Žåã¯ã誰ãæžã蟌ã¿ã®ããã«ãã¡ã€ã«ãéãããŸãŸã«ããŠããããæ¢ãç¶ããŸãã ååãšããŠãè¿œå ã§ã€ã³ã¹ããŒã«ããããã¹ãŠã®ããŒã¢ã³ãšsyslogããªãã«ããŸãã
æé 2.移è¡å ãµãŒããŒã§ã«ãŒãFSãã¢ã³ããŠã³ããã
åä¿¡è ã¯Ubuntu 16.04ã«ãªããŸãã çè«çã«ã¯ã転éåã«åä¿¡è ãäœããããã¯çµ¶å¯Ÿã«éèŠã§ã¯ãããŸããã ãããã¯ãã¹ãŠäžæžããããŸããinitramdiskèšå®ãèªååãããŠãŒãã£ãªãã£ã¯ãubuntu / debianã§åäœããŸãã
ãããã£ãŠãDigitalOceanã§äœæãããã°ããã®ubuntu 16.04ã¯æ¬¡ã®ãšããã§ãã
apt-get install -y git dropbear && \ git clone https://github.com/roginvs/early-ssh && \ cd early-ssh && \ ./build_deb.sh && \ dpkg -i early-ssh*.deb && \ sed -ie 's/DISABLED=1/DISABLED=0/' /etc/early-ssh/early-ssh.conf && \ update-initramfs -u && \ reboot
åä¿¡è ã®IPã¢ãã¬ã¹ã«pingãéä¿¡ããTTLã§è¿œè·¡ããŸãã åçã®TLLãå€æŽããããšããã«ãããã¯initramdiskãèµ·åããæ¥ç¶ãåŸ æ©ããŠããããšãæå³ããŸãã ããã©ã«ãã§ã¯ã15ç§åŸã«èª°ãæ¥ç¶ããŠããªãå ŽåãããŠã³ããŒãã¯ããã«é·ããªããŸãã
sshçµç±ã§æ¥ç¶ããŠã·ã§ã«ãååŸããŸãã ç§ã®å Žåãã«ãŒãèªèšŒã¯ããŒããšã§ãããsshd_configã«ããã¹ã¯ãŒããªãã®PermitRootLoginããå«ãŸããŠããå Žåã§ãïŒinitbramdiskã«ã¯sshdã§ã¯ãªãdropbearãããããïŒãã¹ã¯ãŒãã§æ©èœããŸãã
å®éã1ã€ã®ã»ã¯ã·ã§ã³ã
ã¹ããã3.ããŒã¿è»¢é
ddïŒåä¿¡è ã®ãã£ã¹ã¯ã®ãµã€ãºããœãŒã¹ããå°ãããªãå Žåã¯åœç¶ïŒãŸãã¯rsyncã䜿çšããŠããã¹ãŠã®ããŒã¿ã転éã§ããŸãã ddã¯ããã¡ã€ã«ã·ã¹ãã ã«ç©ºã容éãååã«ãªãå ŽåããŸãã¯å€ãã®å°ããªãã¡ã€ã«ãããå Žåã«é©ããŠããŸãã
ddããsshãžã®ãªãã·ã§ã³ïŒ
dd if=/dev/xvda2 bs=65536 | ssh root@198.199.127.149 'dd of=/dev/vda1 bs=65536'
dd if=/dev/xvda2 bs=65536 | ssh root@198.199.127.149 'dd of=/dev/vda1 bs=65536'
æå·åãªãã§ddã䜿çšããããå§çž®ã䜿çšãããªãã·ã§ã³ïŒ
# nc -q 1 -l 8000 | gzip -d | dd bs=65536 of=/dev/vda1 # dd if=/dev/xvda2 bs=65536 | gzip | nc -q 1 198.199.127.149 8000
é£ã®ã³ã³ãœãŒã«ãããä¿¡å·USR1ãåžžã«ddã«éä¿¡ããŠãç¶æ³ã確èªã§ããŸãã
while true; do kill -USR1 `pidof dd`; sleep 10; done
rsyncã䜿çšãããªãã·ã§ã³ïŒ
ã¬ã·ãŒããŒã§ããã¡ã€ã«ã·ã¹ãã ãåäœæããŠããŠã³ãããŸãã
mkfs.ext3 /dev/vda1 mkdir /mnt mount /dev/vda1 /mnt
ãœãŒã¹ãext3ã§ãããšããçç±ã ãã§ãext4ã§ã¯ãªãext3ãã¡ã€ã«ã·ã¹ãã ã 次ã«ããœãŒã¹ãµãŒããŒããïŒ
rsync -aAXv --one-file-system --progress / root@198.199.127.149:/mnt/
ïŒæåŸã®ã¹ã©ãã·ã¥ã«æ³šæããŠãã ããã
ã¹ããã4.ã«ãŒãã«ã®ç¢ºèªã/ etc / fstabã®ç¢ºèªããããã¯ãŒã¯ã®æ§æãgrubèšå®ã®æŽæ°
ã¬ã·ãŒããŒã§ãæ°ããã³ããŒãããã¡ã€ã«ã·ã¹ãã ãããŠã³ãããããã«chrootãäœæããŸãã
mount /dev/vda1 /mnt mount -o bind /dev/ /mnt/dev/ mount -o bind /proc/ /mnt/proc/ mount -o bind /sys/ /mnt/sys/ chroot /mnt PATH=$PATH:/usr/sbin bash
ã«ãŒãã«ãã€ã³ã¹ããŒã«ãããŠããããšã確èªããŸãïŒãœãŒã¹OSãæºä»®æ³åãåããxenã«ãã£ãå Žåã«å¿ èŠã§ãïŒ
apt-cache search linux-image apt-get install linux-image-3.16.0-4-amd64 dpkg-reconfigure linux-image-3.16.0-4-amd64
/ etc / network / interfacesã®ãããã¯ãŒã¯èšå®ãæŽæ°ãã
nano /etc/network/interfaces
ããã«ã¯å°ããªèœãšãç©ŽããããŸãïŒå Žåã«ãã£ãŠã¯ãäžéšã®ã³ã¢ã§ã¯ãã€ã³ã¿ãŒãã§ã€ã¹ãç°ãªãæ¹æ³ã§åŒã³åºãããšãã§ããŸãã ããšãã°ãUbuntuã§ã¯ens3ãšåŒã°ããDebianã«ãŒãã«ã§ã¯æ¢ã«eth0ã§ãã 念ã®ãããäž¡æ¹ã®ãªãã·ã§ã³ã®ã¬ã³ãŒããäœæããããšããå§ãããŸãã ãŸãã¯ã/ etc / default / grubã«ã«ãŒââãã«èšå®ãè¿œå ããŠãensåã䜿çšããªãããã«ããããšãã§ããŸãïŒGRUB_CMDLINE_LINUXè¡ã眮ãæã/è¿œå ããŸãïŒã
... GRUB_CMDLINE_LINUX="net.ifnames=0 biosdevname=0" ...
+ãã¡ã€ã«/etc/udev/rules.d/70-persistent-net.rulesãåé€ããŠãã«ãŒãã«ãeth0ãšã®ã€ã³ã¿ãŒãã§ãŒã¹ã®èªã¿åããéå§ããããã«ããŸã
/ etc / fstabå ã®ã«ãŒãfsïŒããã€ã¹ã¯vda1ãšåŒã°ããã¹ã¯ãããåé€ããŸãïŒ
nano /etc/fstab
blkidããUUIDãèŠã€ããŠå ¥åããããšãã§ããŸãã
UUID="66bd1995-a4e5-418f-a1f7-0ec2f81ac017" / ext4 errors=remount-ro 0 1
ããŠãããŒãããŒããŒïŒ
apt-get install grub2 grub-install /dev/vda update-grub2
ãã¹ãŠããã¹ãŠãã¢ã³ããŠã³ãããŠåèµ·åã§ããŸãã
exit # bash exit # chroot cd / umount /mnt/dev umount /mnt/proc umount /mnt/sys umount /mnt reboot
åèµ·ååŸãæ°ããIPã§WebããŒãžãéãããšã確èªããŸãã
DigitalOceanã«Windows Server 2012r2ãã€ã³ã¹ããŒã«ãã
ã¹ããã1.ãœãŒã¹ã®æºå
Windowsã§ã¯ãäºæ ã¯ããå°ãè€éãªã®ã§ãæåã«VmWareã§ä»®æ³ãã·ã³ãäœæããããããã€ããŒãã€ã¶ãŒãã転éããŸããã ã€ã³ã¹ããŒã«äžã圌ã¯OSãLinuxãLsi SASãã£ã¹ã¯ãã©ã€ããŒã«ãªãããšã瀺ããŸããã
ã€ã³ã¹ããŒã«ãããWindowsãµãŒããŒã¯ã移è¡ã®ããã«æºåããå¿ èŠããããŸãã
KVMã®ãã©ã€ããŒãããŠã³ããŒããã
fedorapeople.org/groups/virt/virtio-win/direct-downloads/stable-virtio/virtio-win.isoïŒhttps://pve.proxmox.com/wiki/Windows_VirtIO_Drivers ïŒãããŠã³ããŒãããããŒã«ã解åããåinfã«ã€ã³ã¹ããŒã«ããŸãããŒãžã§ã³å®è¡çšã®ãã¡ã€ã«
PnPUtil -i -a <InfName> .inf
ïŒãŸãã¯ããã«çã®ããã«
forfiles / S / M * .inf / C "cmd / c pnputil -i -a @Path"ïŒ
æŸèæã®éæ³
æŸèæã¯ãè¯ãæ¹æ³ã§unattended.xmlãä»ããŠå®è¡ããå¿ èŠãããããã§ãã ãã¡ã€ã«cïŒ\ firstrun.batãäœæããããã«ä»¥äžãèšè¿°ããŸããåæã«ãmac / ip / mask / gateway / passwordãä»®æ³ã¬ã·ãŒããŒã«ãããã®ã«çœ®ãæããŸãã
@Echo Off :: Mac is in Windows format (dashes)! SET MAC=00-50-56-9E-B8-57 SET IP=192.168.2.85 SET MASK=255.255.255.0 SET GW=192.168.2.1 SET ADMINPW=QWEasd123 echo Started >> c:\firstrun.log date /T >> c:\firstrun.log time /T >> c:\firstrun.log ipconfig /all >> c:\firstrun.log echo "Start to search network interface" >> c:\firstrun.log :start_loop For /f "delims=, tokens=1,3 skip=1" %%a In ('getmac /V /FO CSV') Do ( IF /I %%b == "%MAC%" ( echo "Found card" >> firstrun.log echo %%a >> firstrun.log netsh interface ip set address %%a static %IP% %MASK% %GW% 10 netsh interface ip add dns %%a 8.8.8.8 goto :end_loop ) ) ping 127.0.0.1 goto :start_loop :end_loop net user Administrator %ADMINPW% reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server" /v fDenyTSConnections /t REG_DWORD /d 0 /f NetSh Advfirewall set allprofiles state off reg delete "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Setup\State" /v ImageState /f reg add "HKEY_LOCAL_MACHINE\SYSTEM\Setup" /v OOBEInProgress /t REG_DWORD /d 0 /f reg add "HKEY_LOCAL_MACHINE\SYSTEM\Setup" /v RestartSetup /t REG_DWORD /d 0 /f reg add "HKEY_LOCAL_MACHINE\SYSTEM\Setup" /v SetupPhase /t REG_DWORD /d 0 /f reg add "HKEY_LOCAL_MACHINE\SYSTEM\Setup" /v SetupType /t REG_DWORD /d 0 /f reg delete "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run" /v DigitalOceanHack /f echo "Ok, reboot" >> c:\firstrun.log shutdown -r -t 20
次ã«ãã³ã³ãœãŒã«ã§ãã®ã¹ã¯ãªãããèªåå®è¡ã«è¿œå ããç£æ»ã§sysprepãå®è¡ããŸãã
reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run" /v DigitalOceanHack /t REG_SZ /d "C:\firstrun.bat" /f %WINDIR%\system32\sysprep\sysprep /generalize /audit /shutdown
ã€ã¡ãŒãžã®æºåãæŽãã次ã®èµ·åæã«ããèªäœã®æ§æãéå§ãããŸãã
sysprepãªãã§å®è¡ã§ããŸã
æçµã·ã£ããããŠã³ãå®è¡ãããåã«ãWindows 10ãESXiããKVMã«è»¢éããŸããïŒããã€ã¹ãããŒãžã£ãŒ-> IDE ATA / ATAPIã³ã³ãããŒã©ãŒ->åå³åŽã§ãã©ã€ããŒãœãããŠã§ã¢ã®æŽæ°->ã³ã³ãã¥ãŒã¿ãŒã®åç
§...->éžæããŠãã ãã...->ãStandart ... ãïŒãã¡ããããäºææ§ã®ããããŒããŠã§ã¢ã衚瀺ããããã§ãã¯ããã¯ã¹ã¯åé€ãããŸããïŒã
æ£åžžã«èµ·åããŸããã
æ£åžžã«èµ·åããŸããã
ã¹ããã2.ãœãŒã¹ã§ã«ãŒãFSãã¢ã³ããŠã³ãããããŒãã£ã·ã§ã³ãåããŒãã£ã·ã§ã³ããŸã
åã®äŸã®ããã«ramdiskãèµ·åããã«ãŒãFSã移åãããã£ã¹ã¯ã®å é ã«æ°ããããŒãã£ã·ã§ã³ãäœæããgrubèšå®ãæŽæ°ããŸãã
e2fsck -f /dev/vda1 resize2fs /dev/vda1 25G fdisk /dev/vda Command: d Command: n Select (default p): p Partition number: 1 First sector: 2048 Last sector: +716799 ### Windows = 716800 1 Command: n Select (default p): p Partition number: 2 First sector: 718848 Last sector: +32833535 ### 1 Command: n Select (default p): p Partition number: 3 First sector: 73400320 ### 25 = 52428800 125829120 . Last sector: +52428799 # 25 - 1 Command: t Partition number: 1 Partition type: 7 Command: t Partition number: 2 Partition type: 7 Command: a Partition number: 1 Command: a Partition number: 3 Command: w
æåã®ã»ã¯ã·ã§ã³ã¯Windowsçšã«èµ·åå¯èœã350 MBã2çªç®ã¯Windowsèªäœã3çªç®ã¯ããããLinuxã§ãã ãããã®æ°åã®ç±æ¥ã¯æ¬¡ã®ã¹ãããã§æããã«ãªããŸãããä»ã®ãšãããæåã«ã©ã³ãã ãªãµã€ãºã®2ã€ã®ããŒãã£ã·ã§ã³ãäœæããŠïŒæåŸã®ã»ã¯ã¿ãŒãWindowsã€ã¡ãŒãžã®ãµã€ãºããå°ãããªããªãããã«ïŒãã€ã¡ãŒãžãUbuntuãã¡ã€ã«ã·ã¹ãã ã«ã³ããŒããããšãã«Ubuntuããããããåäœæã§ããŸãã æçµçã«ãWindowsã®ããŒãã£ã·ã§ã³ã¯ããœãŒã¹ã€ã¡ãŒãžãšåãå Žæã«åããµã€ãºã§ããããšãéèŠã§ãã
äžæçã«vmdkãã¡ã€ã«ãããã«çœ®ãã®ã§ãã«ãŒãFSã«å€ããæ®ããŸããã çè«çã«ã¯ããã€ããä»ããŠã»ã¯ã·ã§ã³ã«ããã«æžã蟌ãããšãã§ããŸãã
次ã«ã/ dev / vda3ã®2048ã»ã¯ã¿ãŒããå§ãŸã/ dev / vdaã§25GBã®UbuntuïŒãŸã ãã£ã¹ã¯ã®å é ã«ããïŒãã³ããŒããŸãã
dd if=/dev/vda bs=4096 skip=256 count=6553600 of=/dev/vda3
ïŒãããã¯ã512ã§ã¯ãªã4096ã§ãããããã¹ããããšã«ãŠã³ãã¯8ååæžãããŸãïŒ
å¿ èŠã«å¿ããŠãgrubèšå®ãæŽæ°ãã/ etc / fstabãç·šéããŠãã ããïŒ/ dev / vda1ã/ dev / vda3ã«çœ®ãæããŠãã ããïŒïŒ
mkdir /mnt mount /dev/vda3 /mnt mount -o bind /dev/ /mnt/dev/ mount -o bind /proc/ /mnt/proc/ mount -o bind /sys/ /mnt/sys/ chroot /mnt PATH=$PATH:/usr/sbin grub-install /dev/vda update-grub2 nano /etc/fstab exit cd / umount /mnt/dev umount /mnt/proc umount /mnt/sys umount /mnt reboot
ã¹ããã3.äœããã®æ¹æ³ã§ãvmdkãã¡ã€ã«ãæ°ããããŒããããubuntuã«ã³ããŒããŸã
ããŠãvmdkãã¡ã€ã«ãããã«ãã£ã¹ã¯ã€ã¡ãŒãžãè¡šãå ŽåïŒããã§ãªãå Žåã¯ããqemu-img convert -p -f vmdk original.vmdk -O raw Converted.rawããä»ããŠrawã«å€æããå¿ èŠããããŸãïŒ
fdisk Windows2012r2.vmdk
ããã§ãå®éã«ã¯ã/ dev / vda1ããã³/ dev / vda2ã®å€ã¯åã®ã¹ãããããã®ãã®ã§ãã
Windowsãç»åããã»ã¯ã·ã§ã³ã«ã³ããŒããŸãã
dd bs=4096 skip=256 count=89600 if=Windows2012r2.vmdk of=/dev/vda1 dd bs=4096 skip=89856 count=4104192 if=Windows2012r2.vmdk of=/dev/vda2
ïŒã¹ããããšã«ãŠã³ãã8åã«æ¡å€§ãããŸãïŒ
/ dev / vda1ãš/ dev / vda2ãããŠã³ãããŠããã¹ãŠãæ£åžžã§ããããšã確èªããå¿ èŠã«å¿ããŠcrutchã¹ã¯ãªããã®èšå®ã調æŽããŠãã ããã
GRUBãæŽæ°ãã圌ãWindowsãèŠãããšã確èªããŸãã
update-grub2
次ã«ã次ã®åèµ·åã®ããã«Windowsããªã³ã«ããŸããäœãåé¡ãçºçããå Žåã«äŸ¿å©ã§ããä»®æ³ãã·ã³ããªãã«ããŠãªã³ã«ããããšã§æ»ãããšãã§ããŸã
grub-reboot 2 reboot
ãªããªã sysprep + crutchã¹ã¯ãªããã䜿çšããŠã€ã¡ãŒãžãæºåãããšãWindowsã¯æ°åééã§2ååèµ·åããŸãã ã€ãŸã ããã«2åãubuntuã«ãã°ã€ã³ããŠæåŸã®2ã€ã®ã³ãã³ããå®è¡ããå¿ èŠããããŸãã
ã¹ããã4.ããã©ã«ãã§WindowsãããŒããã
grubã®ããã©ã«ãã«ãŠã£ã³ããŠãå«ãã代ããã«ãåçŽã«/etc/rc.localã«è¿œå ããããšããå§ãããŸãã
sleep 60 && grub-reboot 2 && reboot &
-Windowsã®èªã¿èŸŒã¿ãåæ¢ããå ŽåãUbuntuã«ãã°ã€ã³ããŠãkillall sleepãããæéã確ä¿ã§ããŸãã
åèµ·ååŸãRDPã§ã¢ã¯ã»ã¹ã§ããŸãã
åç §ïŒ
Digital Oceanã«Linuxãã£ã¹ããªãã¥ãŒã·ã§ã³ãã€ã³ã¹ããŒã«ããŸã