1
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Virtualbox + pxe boot の続きメモ - virtual box付属dhcp+tftpでpxe boot

Last updated at Posted at 2018-10-28

1からやるとするとこの手順。

概要

  1. pxe server
    2. virtualbox付属のdhcp(TFTP)からpxe司令を出す。
    3. インストールディスクイメージをinternetから取ると遅いので、ローカルにftpを立てとくと早い。
    4. ftpアドレスは pxelinux.cfg/defaultの中で指定する
    5. kickstartはhttp経由で配信しないといけないので、ftpサーバでhttpdも起動しとく
    6. このhttpアドレスも pxelinux.cfg/default で指定する
  2. virtualbox
    2. vm作成スクリプト叩けばおわり

手順

  1. mac側のvirtual box dhcpにpxe bootをセット
    2. git clone https://github.com/defunctzombie/virtualbox-pxe-boot/blob/master/README.md
    3. cent imageからこのfileを取り出してこの場所に

       ```ruby
    

MacPro-3:~ shinichi$ ll ~/Library/VIrtualBox/TFTP/installers/centos7/*
-r--r--r-- 1 shinichi staff 441B 9 25 22:21 /Users/shinichi/Library/VIrtualBox/TFTP/installers/centos7/TRANS.TBL
-rw-r--r-- 1 shinichi staff 50M 9 26 01:41 /Users/shinichi/Library/VIrtualBox/TFTP/installers/centos7/initrd.img
-rwxr-xr-x 1 shinichi staff 5.9M 9 26 01:41 /Users/shinichi/Library/VIrtualBox/TFTP/installers/centos7/vmlinuz
```

3. pxelinux.cfg/defaultを置く
MacPro-3:~ shinichi$ cat ~/Library/VIrtualBox/TFTP/pxelinux.cfg/default
PROMPT 0
NOESCAPE 0
ALLOWOPTIONS 0
TIMEOUT 100

DEFAULT menu.c32

menu title ########## PXE Boot Menu ##########

label 1
        MENU DEFAULT
	menu label ^1) Install CentOS 7 x64 w/Local FTP + Kickstart
	kernel installers/centos7/vmlinuz
	append initrd=installers/centos7/initrd.img method=ftp://192.168.0.73/pub/ ks=http://192.168.0.73/kickstart/cent7-kickstart.cfg devfs=nomount ramdisk_size=131072 ip=dhcp lang=en_US keymap=us hostname=cent75

label 1
	menu label ^1) Install CentOS 7 x64 w/Local Repo
	kernel installers/centos7/vmlinuz
	append initrd=installers/centos7/initrd.img method=ftp://192.168.0.73/pub/ devfs=nomount

label 2
	menu label ^2) Install CentOS 7 x64 w/ internet http://mirror.centos.org Repo
	kernel installers/centos7/vmlinuz
	append initrd=installers/centos7/initrd.img method=http://mirror.centos.org/centos/7/os/x86_64/ devfs=nomount ip=dhcp

配信サーバの設定

事前に用意したcent7を利用

  1. ftp/httpdを用意しておく
    2. cent installer iso を DL
    3. /var/ftp/pub にmount, /var/ftp/pub/ks.cfg を置いておく
    4.
  2. /var/ftp/pub に iso image中身を配置

mkdir -p /ks/image
cd /ks
mount -t iso9660 -o loop CentOS-7-x86_64-Minimal-1804.iso /mnt
cp -RT /mnt /kc/image
cat >> /ks/image/isolinux/isolinux.cfg <<EOL

label autorun
  menu label ^KIckStartAutoRun
  menu default
  kernel vmlinuz
  append initrd=initrd.img inst.stage2=cdrom: inst.ks=cdrom:

EOL
cp /root/ks.cfg /kc/image
ksvalidator image/ks.cfg
#mkisofs -v -r -J -o ../CentOS-7-x86_64-Minimal-1804-kuji-ks.iso -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table .
  1. それをftp/http経由で配信する

yum install -y vsftpd httpd

rm -rf /var/ftp/pub
ln -s /ks/image /var/ftp/pub
ln -s /ks/image /var/www/html/pub

cat << EOF > /etc/vsftpd/vsftpd.conf
anonymous_enable=YES
local_enable=YES
write_enable=YES
local_umask=022
anon_upload_enable=YES
anon_mkdir_write_enable=YES
dirmessage_enable=YES
xferlog_enable=YES
connect_from_port_20=YES
xferlog_std_format=YES
listen=YES
listen_ipv6=NO

pam_service_name=vsftpd
userlist_enable=YES
tcp_wrappers=YES
EOF

systemctl enable vsftpd
systemctl restart vsftpd
systemctl enable httpd
systemctl start httpd

netstat -ntp

curl ftp://localhost/pub/ks.cfg
curl localhost/pub/ks.cfg

vm作成script 改善版

いろいろ直した


## kuji create vm and pxe boot

# How to use
# $ this.sh vm-name

if [[ -z $1 ]]; then
  echo Give me VM name as arg1. quit.
  exit 1
else
  VM=$1
fi

# virtual box の pxe boot 用dhcpのリンク付
ln -s ~/Library/VIrtualBox/TFTP/pxelinux.0 ~/Library/VIrtualBox/TFTP/$VM.pxe

####### virtual box VM作成

which VBoxManage

VboxManage list vms | grep $VM

# create disk(VDI)
VBoxManage createhd --filename $VM.vdi --size 40000

VBoxManage list hdds | grep vdi

VBoxManage list ostypes | grep Red

# Create VM
VBoxManage createvm --name $VM --ostype "RedHat_64" --register

VboxManage list vms | grep $VM

# Create SATA Controller
VBoxManage storagectl $VM --name "SATA Controller" --add sata --controller IntelAHCI --portcount 2

# Create the first disk
VBoxManage storageattach $VM --storagectl "SATA Controller" --port 0 --device 0 --type hdd --medium $VM.vdi --nonrotational on

# Create IDE Controller
#VBoxManage storagectl $VM --name "IDE Controller" --add ide --portcount 2

# Create DVD drive
#VBoxManage storageattach $VM --storagectl "IDE Controller" --port 0 --device 0 --type dvddrive --medium emptydrive

## Other settings
# multicore対応 I/O APICを有効化
VBoxManage modifyvm $VM --ioapic on
# cpu, memory
VBoxManage modifyvm $VM --cpus 8
VBoxManage modifyvm $VM --memory 8192 --vram 256

### NICの設定
# NIC1: 内部ネットワーク(virtual box 付属dhcp/ これがpxe bootしてくれる)
VBoxManage modifyvm $VM --nic1 nat

# NIC2: bridge adapter 作成
VBoxManage modifyvm $VM --nic2 bridged --bridgeadapter2 "en1: Ethernet 2"

# bootオーダーをnetwork優先に
VBoxManage modifyvm $VM --boot1 disk --boot2 net --boot3 none --boot4 none

# clipboard/drag and drop 有効
VBoxManage modifyvm $VM --clipboard bidirectional
VBoxManage modifyvm $VM --draganddrop bidirectional

# start
VBoxManage startvm $VM

まだ成功してないけど理論的には行くはず

1
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?