User Tools

Site Tools


proxmox:lxc:lxc-template

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
proxmox:lxc:lxc-template [2020/05/25 14:21] – [Select an Image] chuckproxmox:lxc:lxc-template [2022/01/14 12:47] (current) – [Modifying or Updating] chuck
Line 9: Line 9:
  
 =====Select an Image===== =====Select an Image=====
-  * SSH into Proxmox:<code> +  * SSH into Proxmox:<code bash
-[user@localpc]$ ssh proxmox+ssh proxmox
 </code> </code>
-  * List available system images:<code> +  * List available system images (change sas-storage to wherever they are stored on your system eg. local):<code bash> 
-# Check local images first (change sas-storage to wherever they are stored on your system eg. local) +sudo pveam list sas-storage 
-[user@proxmox]$ sudo pveam list sas-storage +</code> 
- +    If what we want isn't there, update container template database:<code bash> 
-If what we want isn't there, update container template database +sudo pveam update 
-[user@proxmox]$ sudo pveam update +</code> 
- +    List available images:<code bash> 
-List available images +sudo pveam available 
-[user@proxmox]$ sudo pveam available +</code> 
- +    * You can also filter the output:<code bash> 
-# or filter output like so+sudo pveam available --section system
-[user@proxmox]$ sudo pveam available --section system+
 </code> </code>
-  * Download the image:<code> +  * Download the image:<code bash
-[user@proxmox]$ sudo pveam download sas-storage debian-10.0-standard_10.0-1_amd64.tar.gz+sudo pveam download sas-storage debian-10.0-standard_10.0-1_amd64.tar.gz
 </code> </code>
   * See ''%%man pveam%%'' for more details.   * See ''%%man pveam%%'' for more details.
Line 34: Line 33:
 =====Create the Container===== =====Create the Container=====
 Now we need to create the container that we will be updating and adding our programs to. Note that you will need to modify the following command to match your system. Now we need to create the container that we will be updating and adding our programs to. Note that you will need to modify the following command to match your system.
-  * Create a container:<code> +  * Create a container:<code bash
-[user@proxmox]$ sudo pct create 250 sas-storage:vztmpl/debian-10.0-standard_10.0-1_amd64.tar.gz \ +sudo pct create 250 sas-storage:vztmpl/debian-10.0-standard_10.0-1_amd64.tar.gz \ 
---storage sas-lvm --rootfs volume=sas-lvm:16 \ +  --storage sas-lvm --rootfs volume=sas-lvm:16 \ 
---ostype debian --arch amd64 --password insecure --unprivileged 1 \ +  --ostype debian --arch amd64 --password insecure --unprivileged 1 \ 
---cores 1 --memory 1024 --swap 1024 \ +  --cores 1 --memory 1024 --swap 1024 \ 
---hostname lxc-template --searchdomain local.lan --nameserver xxx.xxx.xxx.x \ +  --hostname lxc-template --searchdomain local.lan --nameserver xxx.xxx.xxx.x \ 
---net0 name=eth0,bridge=vmbrxx,ip=dhcp,gw=xxx.xxx.xx.x,type=veth \ +  --net0 name=eth0,bridge=vmbrxx,ip=dhcp,gw=xxx.xxx.xx.x,type=veth \ 
---start true+  --start true
 </code> </code>
   * See ''%%man pct%%'' for more information.   * See ''%%man pct%%'' for more information.
Line 50: Line 49:
 Here's where we update/add programs/configure it to our liking. Here's where we update/add programs/configure it to our liking.
  
-  * Enter the container:<code> +  * Enter the container:<code bash
-[user@proxmox]$ sudo pct enter 250+sudo pct enter 250
 </code> </code>
-  * Do stuff:<code> +  * Do stuff
-# Update the apt cache +    * Update the system:<code bash
-[root@lxc]# apt update +apt update && apt upgrade 
- +</code> 
-# Upgrade the packages +    Install some packages:<code bash> 
-[root@lxc]# apt upgrade +apt install curl git screen stow unattended-upgrades vim 
- +</code> 
-Install some packages +    Set Vim as default editor:<code bash> 
-[root@lxc]# apt install curl git screen stow unattended-upgrades vim +update-alternatives --set editor /usr/bin/vim.basic
- +
-Set Vim as default editor +
-[root@lxc]# update-alternatives --set editor /usr/bin/vim.basic +
- +
-# Create user +
-[root@lxc]# adduser user +
- +
-# Switch to user +
-[root@lxc]# su - user +
- +
-# Clone dotfiles +
-[user@lxc]$ git clone https://path.to/dotfiles ~/.dotfiles +
- +
-# Stow the dotfiles +
-[user@lxc]$ stow dotfiles +
- +
-# Create ~/.ssh directory +
-[user@lxc]$ mkdir ~/.ssh +
- +
-# Create ~/.ssh/authorized_keys file +
-# And so on....+
 </code> </code>
-  * Bonus points if you have an Ansible playbook to run the commands.+    * Create user:<code bash> 
 +adduser user 
 +</code> 
 +    * Switch to user:<code bash> 
 +su - user 
 +</code> 
 +    * Clone dotfiles:<code bash> 
 +git clone https://path.to/dotfiles ~/.dotfiles 
 +</code> 
 +    * Stow the dotfiles:<code bash> 
 +stow dotfiles 
 +</code> 
 +    * Create ''%%~/.ssh%%'' directory:<code bash> 
 +mkdir ~/.ssh 
 +</code> 
 +    * Create ''%%~/.ssh/authorized_keys%%'' file with your pubkey 
 +    * And so on.... 
 +    * Bonus points if you have an Ansible playbook to run the commands!
  
 ---- ----
Line 91: Line 86:
 In order to turn the container into a template, we need to delete the network interface then create a backup. In order to turn the container into a template, we need to delete the network interface then create a backup.
   * From proxmox (not inside the container):   * From proxmox (not inside the container):
-  * Remove the network interface:<code> +  * Remove the network interface:<code bash
-[user@proxmox]$ sudo pct set 250 --delete net0+sudo pct set 250 --delete net0
 </code> </code>
-  * Create a backup:<code> +  * Create a backup:<code bash
-[user@proxmox]$ vzdump 250 --mode stop --compress gzip --dumpdir /media/sas/data/template/cache/+vzdump 250 --mode stop --compress gzip --dumpdir /media/sas/data/template/cache/
 </code> </code>
-  * The new file will be located in:<code>+  * The new file will be located in:<code bash>
 /media/sas/data/template/cache /media/sas/data/template/cache
 </code> </code>
-  * You can leave it as is or rename it to something:<code> +  * You can leave it as is or rename it to something
-[user@proxmox]$ cd /media/sas/data/template/cache +    * Change directories:<code bash
- +cd /media/sas/data/template/cache 
-[user@proxmox]$ sudo mv new_vz_dump.tar.gz custom_debian_10.4.tar.gz+</code> 
 +    * Rename it:<code bash> 
 +sudo mv new_vz_dump.tar.gz custom_debian_10.4.tar.gz
 </code> </code>
   * See ''%%man vzdump%%'' for info.   * See ''%%man vzdump%%'' for info.
Line 116: Line 113:
 =====Modifying or Updating===== =====Modifying or Updating=====
 It's really easy to modify the container when a new version of the OS is released or you want to add something to your templates. It's really easy to modify the container when a new version of the OS is released or you want to add something to your templates.
-  * Create a container with your custom file:<code> +  * Create a container with your custom file:<code bash
-[user@proxmox]$ sudo pct create 250 sas-storage:vztmpl/custom_debian_10.4.tar.gz \ +sudo pct create 250 sas-storage:vztmpl/custom_debian_10.4.tar.gz \ 
---storage sas-lvm --rootfs volume=sas-lvm:16 \ +  --storage sas-lvm --rootfs volume=sas-lvm:16 \ 
---ostype debian --arch amd64 --password insecure --unprivileged 1 \ +  --ostype debian --arch amd64 --password insecure --unprivileged 1 \ 
---cores 1 --memory 1024 --swap 1024 \ +  --cores 1 --memory 1024 --swap 1024 \ 
---hostname lxc-template --searchdomain local.lan --nameserver xxx.xxx.xxx.x \ +  --hostname lxc-template --searchdomain local.lan --nameserver xxx.xxx.xxx.x \ 
---net0 name=eth0,bridge=vmbrxx,ip=dhcp,gw=xxx.xxx.xxx.x,type=veth \ +  --net0 name=eth0,bridge=vmbrxx,ip=dhcp,gw=xxx.xxx.xxx.x,type=veth \ 
---start true+  --start true
 </code> </code>
-  * Enter the container:<code> +  * Enter the container:<code bash
-[user@proxmox]$ sudo pct enter 250+sudo pct enter 250
 </code> </code>
-  * Do stuff:<code> +  * Do stuff
-# Update/Upgrade +    * Update the system:<code bash
-# Install new stuff +apt update && apt upgrade
-# Add new dotfiles+
 </code> </code>
-  * Exit back to Proxmox:<code>+    * Install some packages 
 +    * Add new dotfiles 
 +    * And so on.. 
 +  * Exit back to Proxmox:<code bash>
 exit exit
 </code> </code>
-  * Remove the network device:<code> +  * Remove the network device:<code bash
-[user@proxmox]$ sudo pct set 250 --delete net0+sudo pct set 250 --delete net0
 </code> </code>
-  * Create the backup:<code> +  * Create the backup:<code bash
-[user@proxmox]$ vzdump 250 --mode stop --compress gzip --dumpdir /media/sas/data/template/cache/+vzdump 250 --mode stop --compress gzip --dumpdir /media/sas/data/template/cache/
 </code> </code>
-  * Rename the backup if you like:<code> +  * You can leave it as is or rename it to something: 
-[user@proxmox]$ cd /media/sas/data/template/cache +    * Change directories:<code bash
- +cd /media/sas/data/template/cache 
-[user@proxmox]$ sudo mv new_vz_dump.tar.gz custom_debian_10.5.tar.gz+</code> 
 +    * Rename it:<code bash> 
 +sudo mv new_vz_dump.tar.gz custom_debian_10.5.tar.gz
 </code> </code>
  
proxmox/lxc/lxc-template.1590416466.txt.gz · Last modified: by chuck