Difference between revisions of "Vnx-rootfslxc"

From VNX
Jump to: navigation, search
(Basic installation)
 
(18 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{Title|How to create a LXC Ubuntu/Debian root filesystem for VNX}}
+
{{Title|How to create a LXC Ubuntu root filesystem for VNX}}
  
 
== Basic installation ==
 
== Basic installation ==
  
Follow this procedure to create a LXC Ubuntu/Debian based root filesystem for VNX. The procedure has been tested over Ubuntu 13.10.  
+
Follow this procedure to create a Ubuntu based LXC root filesystem for VNX. The procedure has been tested with Ubuntu versions from 13.10 to 18.04.  
  
 
<ul>
 
<ul>
 
<li>Create the rootfs with:</li>
 
<li>Create the rootfs with:</li>
  lxc-create -t ubuntu -n vnx_rootfs_lxc_ubuntu-13.10
+
  lxc-create -t ubuntu -n vnx_rootfs_lxc_ubuntu-18.04
Note1: Change "ubuntu" by "debian" in case you want to create a Debian rootfs. The default username/password is ubuntu/ubuntu.<br>
+
Note1: The default username/password is ubuntu/ubuntu.<br>
Note2: use linux32 command to create a 32 bits image from a 64 bits machine, that is:
+
Note2: This method creates an image with the same architecture (32 or 64 bits) as the host. To create a 32 bits image in a 64 bits host, the only method known to work is to follow the procedure described in this page inside a KVM 32 bits virtual machine.
linux32 lxc-create -t debian -n vnx_rootfs_lxc_debian
 
 
<li>Move the rootfs to VNX filesystems directory:</li>
 
<li>Move the rootfs to VNX filesystems directory:</li>
  mv /var/lib/lxc/vnx_rootfs_lxc_ubuntu-13.10/ /usr/share/vnx/filesystems/
+
  mv /var/lib/lxc/vnx_rootfs_lxc_ubuntu-18.04/ /usr/share/vnx/filesystems/
<li>Edit the rootfs configuration file (/usr/share/vnx/filesystems/vnx_rootfs_lxc_ubuntu-13.10-v025/config) to reflect the directory change:</li>
+
<li>If using Ubuntu 17.10 or newer (lxc version 2.1 or newer), convert the configuration file to old config format (VNX converts back to the newer format if needed when starting containers):</li>
  lxc.rootfs = /usr/share/vnx/filesystems/vnx_rootfs_lxc_ubuntu-13.10/rootfs
+
lxc.rootfs.path -> lxc.rootfs
  lxc.mount  = /usr/share/vnx/filesystems/vnx_rootfs_lxc_ubuntu-13.10/fstab
+
lxc.uts.name -> lxc.utsname
 +
lxc.net.0.type -> lxc.network.type
 +
lxc.net.0.link -> lxc.network.link
 +
lxc.net.0.flags -> lxc.network.flags
 +
lxc.net.0.hwaddr -> lxc.network.hwaddr
 +
<li>Edit the rootfs configuration file (/usr/share/vnx/filesystems/vnx_rootfs_lxc_ubuntu-16.04/config) to reflect the directory change:</li>
 +
  lxc.rootfs = /usr/share/vnx/filesystems/vnx_rootfs_lxc_ubuntu-16.04/rootfs
 +
  lxc.mount  = /usr/share/vnx/filesystems/vnx_rootfs_lxc_ubuntu-16.04/fstab
 +
<li>Create fstab file (if not created):</li>
 +
touch vnx_rootfs_lxc_ubuntu-16.04/fstab
 
<li>Start the new rootfs to configure it and install new software:</li>
 
<li>Start the new rootfs to configure it and install new software:</li>
  lxc-start -n vnx_rootfs_lxc_ubuntu-13.10-v025 -f /usr/share/vnx/filesystems/vnx_rootfs_lxc_ubuntu-13.10/config
+
  lxc-start -n vnx -F -f /usr/share/vnx/filesystems/vnx_rootfs_lxc_ubuntu-16.04/config
 
<li>Once the VM has started, make login (ubuntu/ubuntu) and:</li>
 
<li>Once the VM has started, make login (ubuntu/ubuntu) and:</li>
 
<ul>
 
<ul>
Line 27: Line 35:
 
  sudo apt-get update
 
  sudo apt-get update
 
  sudo apt-get dist-upgrade
 
  sudo apt-get dist-upgrade
  sudo apt-get install aptsh openssh-server traceroute telnet nmap apache2 wget tcpdump
+
  sudo apt-get install aptsh openssh-server traceroute telnet nmap apache2 wget tcpdump net-tools ifupdown
 +
update-rc.d -f apache2 remove  # to avoid automatic start
 +
systemctl disable apache2      # in newer systems
 
<li>Change VM name in hosts and hostname files:</li>
 
<li>Change VM name in hosts and hostname files:</li>
 
  sudo vi /etc/hosts        # change name to vnx
 
  sudo vi /etc/hosts        # change name to vnx
 
  sudo vi /etc/hostname      #    "
 
  sudo vi /etc/hostname      #    "
 +
<li>Enable root access through textual consoles with:</li>
 +
echo "pts/0" >> /etc/securetty
 +
echo "pts/1" >> /etc/securetty
 +
echo "pts/2" >> /etc/securetty
 +
echo "pts/3" >> /etc/securetty
 
<li>'''Important:''' edit /etc/network/interfaces and coment "inet dhcp" lines to avoid delays at startup. Besides, edit /etc/init/failsafe.conf and change all "sleep XX" commands to "sleep 1".
 
<li>'''Important:''' edit /etc/network/interfaces and coment "inet dhcp" lines to avoid delays at startup. Besides, edit /etc/init/failsafe.conf and change all "sleep XX" commands to "sleep 1".
 
</ul>
 
</ul>
 +
<li>Disable auto-upgrades if enabled:</li>
 +
sed -i -e 's/"1"/"0"/g' /etc/apt/apt.conf.d/20auto-upgrades
 +
<li>Delete the "mesg n" command in root's .profile to avoid the nasty message
 +
"mesg: ttyname failed: No such device" when executing commands with lxc-attach:</li>
 +
sed -i '/^mesg n/d' /root/.profile
 +
<li>Exit and login again with user vnx/xxxx to delete ubuntu user:</li>
 +
sudo deluser ubuntu
 
<li>Stop the VM with:</li>
 
<li>Stop the VM with:</li>
 
  halt
 
  halt
 +
 +
<li>If you want to pack the root filesystem into a tar file, use the following command:</li>
 +
tar --numeric-owner -czpf vnx_rootfs_lxc_ubuntu-16.04-v025.tgz vnx_rootfs_lxc_ubuntu-16.04-v025
 
<li>Optionally, create a short link to the rootfs:</li>
 
<li>Optionally, create a short link to the rootfs:</li>
 
  cd /usr/share/vnx/filesystems
 
  cd /usr/share/vnx/filesystems
  ln -s vnx_rootfs_lxc_ubuntu-13.10 rootfs_lxc
+
  ln -s vnx_rootfs_lxc_ubuntu-16.04 rootfs_lxc
 
</ul>
 
</ul>

Latest revision as of 01:36, 28 August 2019

How to create a LXC Ubuntu root filesystem for VNX

Basic installation

Follow this procedure to create a Ubuntu based LXC root filesystem for VNX. The procedure has been tested with Ubuntu versions from 13.10 to 18.04.

  • Create the rootfs with:
  • lxc-create -t ubuntu -n vnx_rootfs_lxc_ubuntu-18.04
    

    Note1: The default username/password is ubuntu/ubuntu.
    Note2: This method creates an image with the same architecture (32 or 64 bits) as the host. To create a 32 bits image in a 64 bits host, the only method known to work is to follow the procedure described in this page inside a KVM 32 bits virtual machine.

  • Move the rootfs to VNX filesystems directory:
  • mv /var/lib/lxc/vnx_rootfs_lxc_ubuntu-18.04/ /usr/share/vnx/filesystems/
    
  • If using Ubuntu 17.10 or newer (lxc version 2.1 or newer), convert the configuration file to old config format (VNX converts back to the newer format if needed when starting containers):
  • lxc.rootfs.path -> lxc.rootfs
    lxc.uts.name -> lxc.utsname
    lxc.net.0.type -> lxc.network.type
    lxc.net.0.link -> lxc.network.link
    lxc.net.0.flags -> lxc.network.flags
    lxc.net.0.hwaddr -> lxc.network.hwaddr
    
  • Edit the rootfs configuration file (/usr/share/vnx/filesystems/vnx_rootfs_lxc_ubuntu-16.04/config) to reflect the directory change:
  • lxc.rootfs = /usr/share/vnx/filesystems/vnx_rootfs_lxc_ubuntu-16.04/rootfs
    lxc.mount  = /usr/share/vnx/filesystems/vnx_rootfs_lxc_ubuntu-16.04/fstab
    
  • Create fstab file (if not created):
  • touch vnx_rootfs_lxc_ubuntu-16.04/fstab
    
  • Start the new rootfs to configure it and install new software:
  • lxc-start -n vnx -F -f /usr/share/vnx/filesystems/vnx_rootfs_lxc_ubuntu-16.04/config
    
  • Once the VM has started, make login (ubuntu/ubuntu) and:
    • Add VNX user and change the passwords:
    • sudo adduser vnx
      sudo adduser vnx sudo
      sudo passwd root
      
    • Update and install software:
    • sudo apt-get update
      sudo apt-get dist-upgrade
      sudo apt-get install aptsh openssh-server traceroute telnet nmap apache2 wget tcpdump net-tools ifupdown
      update-rc.d -f apache2 remove   # to avoid automatic start
      systemctl disable apache2       # in newer systems
      
    • Change VM name in hosts and hostname files:
    • sudo vi /etc/hosts         # change name to vnx
      sudo vi /etc/hostname      #     "
      
    • Enable root access through textual consoles with:
    • echo "pts/0" >> /etc/securetty
      echo "pts/1" >> /etc/securetty
      echo "pts/2" >> /etc/securetty
      echo "pts/3" >> /etc/securetty
      
    • Important: edit /etc/network/interfaces and coment "inet dhcp" lines to avoid delays at startup. Besides, edit /etc/init/failsafe.conf and change all "sleep XX" commands to "sleep 1".
  • Disable auto-upgrades if enabled:
  • sed -i -e 's/"1"/"0"/g' /etc/apt/apt.conf.d/20auto-upgrades
    
  • Delete the "mesg n" command in root's .profile to avoid the nasty message "mesg: ttyname failed: No such device" when executing commands with lxc-attach:
  • sed -i '/^mesg n/d' /root/.profile
    
  • Exit and login again with user vnx/xxxx to delete ubuntu user:
  • sudo deluser ubuntu
    
  • Stop the VM with:
  • halt
    
  • If you want to pack the root filesystem into a tar file, use the following command:
  • tar --numeric-owner -czpf vnx_rootfs_lxc_ubuntu-16.04-v025.tgz vnx_rootfs_lxc_ubuntu-16.04-v025
    
  • Optionally, create a short link to the rootfs:
  • cd /usr/share/vnx/filesystems
    ln -s vnx_rootfs_lxc_ubuntu-16.04 rootfs_lxc