2018年2月12日月曜日

VagrantでRStudio、Debian Stretch/9.3、Xfceデスクトップ環境のLive CDを作成するための仮想マシンを構築する

以下のVagrantfileを使用して、RStudio、Debian Stretch/9.3、Xfceデスクトップ環境のLive CDを作成するための仮想マシンを構築する事ができます。Live CDのイメージはVagrantfileと同じディレクトリに作成されます(debian-live.iso)。Live CDから起動後、ユーザdebian、パスワードdebianでログインします。
USBスティックから起動したい場合は、rufusなどを使用してisoイメージからブート可能なUSBドライブを作成します。

Vagrantfile
VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.vm.box = "bento/debian-9.3"
  config.vm.hostname = "db93livecdxfcerstudio"
config.vm.network "public_network", ip:"192.168.1.118", :netmask => "255.255.255.0"
  config.vm.provider :virtualbox do |vbox|
     vbox.name = "db93livecdxfcerstudio"
     vbox.gui = true
     vbox.cpus = 4
     vbox.memory = 4096
  end
  config.vm.provision "shell", inline: <<-SHELL
apt-get update
#DEBIAN_FRONTEND=noninteractive apt-get -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" upgrade

apt-get -y install task-japanese locales
sed -i -e 's/# ja_JP.UTF-8 UTF-8/ja_JP.UTF-8 UTF-8/' /etc/locale.gen
locale-gen
#locale-gen
update-locale LANG=ja_JP.UTF-8
#localectl set-locale LANG=ja_JP.UTF-8
localectl set-keymap jp106
apt-get update

# install tools
apt-get -y install debootstrap syslinux isolinux squashfs-tools genisoimage memtest86+ rsync network-manager

# create an image
mkdir -p /home/vagrant/livecd
debootstrap --arch=amd64 --variant=minbase stretch /home/vagrant/livecd/chroot http://ftp.jp.debian.org/debian/


cat << EOF >> /home/vagrant/livecd/chroot/chr.sh
#!/bin/sh
echo "debian-live" > /etc/hostname
apt-get update
DEBIAN_FRONTEND=noninteractive apt-get -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" upgrade
apt-get --no-install-recommends --yes --force-yes install \
  linux-image-amd64 live-boot systemd-sysv net-tools wireless-tools \
  vim tasksel sudo dialog locales
tasksel --task-packages standard

#apt-get update
DEBIAN_FRONTEND=noninteractive -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" apt-get -y install task-japanese
locale-gen
sed -i -e 's/# ja_JP.UTF-8 UTF-8/ja_JP.UTF-8 UTF-8/' /etc/locale.gen
locale-gen
update-locale LANG=ja_JP.UTF-8
localectl set-locale LANG=ja_JP.UTF-8
localectl set-keymap jp106
apt-get update
cat << EOS > /etc/default/keyboard
XKBMODEL="pc106"
XKBLAYOUT="jp"
XKBVARIANT=""
XKBOPTIONS=""
BACKSPACE="guess"
EOS

mkdir -p /home/debian
groupadd debian
useradd -g debian -d /home/debian debian
chown debian:debian /home/debian
echo 'debian:debian' | chpasswd
echo 'debian    ALL=(ALL) ALL' >> /etc/sudoers

cat << EOS > /home/debian/.xsessionrc
export GTK_IM_MODULE=fcitx
export QT_IM_MODULE=fcitx
export XMODIFIERS="@im=fcitx"
sed -i -e "s/^EnabledIMList.*$/EnabledIMList=fcitx-keyboard-jp:True,mozc:True,fcitx-keyboard-us:False/" /home/debian/.config/fcitx/profile
fcitx -r -d
EOS

DEBIAN_FRONTEND=noninteractive apt-get -y  --no-install-recommends -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" install task-xfce-desktop fcitx-tools network-manager-gnome fonts-ipafont gnome-icon-theme firefox-esr
apt-get -y install fcitx-mozc
im-config -n fcitx


# install R
echo "deb https://cran.rstudio.com/bin/linux/ubuntu $(lsb_release -cs)/" | sudo tee -a /etc/apt/sources.list
gpg --keyserver keyserver.ubuntu.com --recv-key E084DAB9
gpg -a --export E084DAB9 | sudo apt-key add -
apt-get update
apt-get -y install r-base
apt-get -y install libjpeg62
apt-get -y install wget
wget https://download1.rstudio.org/rstudio-xenial-1.1.383-amd64.deb
dpkg -i rstudio-xenial-1.1.383-amd64.deb

# create shortcut for RStudio
cat << EOF > /usr/share/applications/rstudio.desktop

[Desktop Entry]
Version=1.0
Type=Application
Terminal=false
Exec=sh -c "/usr/bin/rstudio"
Name=RStudio
Icon=/usr/lib/rstudio/www/images/favicon.ico
Categories=Development;
EOF
chmod +x /usr/share/applications/rstudio.desktop


systemctl set-default graphical.target

EOF
chmod +x /home/vagrant/livecd/chroot/chr.sh
chroot /home/vagrant/livecd/chroot /chr.sh

mkdir -p /home/vagrant/livecd/image/live
mkdir -p /home/vagrant/livecd/image/isolinux

cd /home/vagrant/livecd
mksquashfs chroot image/live/filesystem.squashfs -e boot
cp chroot/boot/vmlinuz-*-amd64 image/live/vmlinuz1
cp chroot/boot/initrd.img-*-amd64 image/live/initrd1


cat << EOF >> /home/vagrant/livecd/image/isolinux/isolinux.cfg
UI menu.c32

prompt 0
menu title Debian Live

timeout 120

label Debian Live
menu label ^Debian Live
menu default
kernel /live/vmlinuz1
append initrd=/live/initrd1 boot=live

label hdt
menu label ^Hardware Detection Tool (HDT)
kernel hdt.c32
text help
HDT displays low-level information about the systems hardware.
endtext

label memtest86+
menu label ^Memory Failure Detection (memtest86+)
kernel /live/memtest
EOF


cd /home/vagrant/livecd/image/
cp /usr/lib/ISOLINUX/isolinux.bin isolinux/
cp /usr/lib/syslinux/modules/bios/menu.c32 isolinux/
cp /usr/lib/syslinux/modules/bios/hdt.c32 isolinux/
cp /usr/lib/syslinux/modules/bios/ldlinux.c32 isolinux/
cp /usr/lib/syslinux/modules/bios/libutil.c32 isolinux/
cp /usr/lib/syslinux/modules/bios/libmenu.c32 isolinux/
cp /usr/lib/syslinux/modules/bios/libcom32.c32 isolinux/
cp /usr/lib/syslinux/modules/bios/libgpl.c32 isolinux/
cp /usr/share/misc/pci.ids isolinux/
cp /boot/memtest86+.bin live/memtest


genisoimage \
  -rational-rock \
  -volid "Debian LiveCD" \
  -cache-inodes \
  -joliet \
  -hfs \
  -full-iso9660-filenames \
  -b isolinux/isolinux.bin \
  -c isolinux/boot.cat \
  -no-emul-boot \
  -boot-load-size 4 \
  -boot-info-table \
  -output /vagrant/debian-live.iso \
  /home/vagrant/livecd/image


init 5
SHELL
end

○RStudioの画面


○関連情報
・RStudioに関する他の記事はこちらを参照してください。

0 件のコメント:

コメントを投稿