Increase the partition size of a Unix VM in XenServer

Distribution: Ubuntu 18.04

This is how I increased the disk partition size of my Ubuntu virtual machine running in XenServer.

Using fdisk, view the partition information, delete the old partition, add a new partition with extended size, save the partition. This is the workflow followed below. Pls note that the partition will not be commited, until you confirm.


# fdisk /dev/xvda
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help): p

Disk /dev/xvda: 429.5 GB, 429496729600 bytes, 838860800 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000b3935

Device Boot Start End Blocks Id System
/dev/xvda1 * 2048 2099199 1048576 83 Linux
/dev/xvda2 2099200 419430399 208665600 8e Linux LVM

Command (m for help): d
Partition number (1,2, default 2): 2
Partition 2 is deleted

Command (m for help): p

Disk /dev/xvda: 429.5 GB, 429496729600 bytes, 838860800 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000b3935

Device Boot Start End Blocks Id System
/dev/xvda1 * 2048 2099199 1048576 83 Linux

Command (m for help): ^C
# fdisk /dev/xvda
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help): p

Disk /dev/xvda: 429.5 GB, 429496729600 bytes, 838860800 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000b3935

Device Boot Start End Blocks Id System
/dev/xvda1 * 2048 2099199 1048576 83 Linux
/dev/xvda2 2099200 419430399 208665600 8e Linux LVM

Command (m for help): m
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
g create a new empty GPT partition table
G create an IRIX (SGI) partition table
l list known partition types
m print this menu
n add a new partition
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition's system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)

Command (m for help): p

Disk /dev/xvda: 429.5 GB, 429496729600 bytes, 838860800 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000b3935

Device Boot Start End Blocks Id System
/dev/xvda1 * 2048 2099199 1048576 83 Linux
/dev/xvda2 2099200 419430399 208665600 8e Linux LVM

Command (m for help): d
Partition number (1,2, default 2):
Partition 2 is deleted

Command (m for help): n
Partition type:
p primary (1 primary, 0 extended, 3 free)
e extended
Select (default p): p
Partition number (2-4, default 2):
First sector (2099200-838860799, default 2099200):
Using default value 2099200
Last sector, +sectors or +size{K,M,G} (2099200-838860799, default 838860799):
Using default value 838860799
Partition 2 of type Linux and of size 399 GiB is set

Command (m for help): p

Disk /dev/xvda: 429.5 GB, 429496729600 bytes, 838860800 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000b3935

Device Boot Start End Blocks Id System
/dev/xvda1 * 2048 2099199 1048576 83 Linux
/dev/xvda2 2099200 838860799 418380800 83 Linux

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
# fdisk -l

Disk /dev/xvda: 429.5 GB, 429496729600 bytes, 838860800 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000b3935

Device Boot Start End Blocks Id System
/dev/xvda1 * 2048 2099199 1048576 83 Linux
/dev/xvda2 2099200 838860799 418380800 83 Linux

Disk /dev/mapper/cl_mgr-root: 53.7 GB, 53687091200 bytes, 104857600 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk /dev/mapper/cl_mgr-swap: 3892 MB, 3892314112 bytes, 7602176 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk /dev/mapper/cl_mgr-home: 156.1 GB, 156086829056 bytes, 304857088 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

Docker Commands to start/stop containers

Getting docker images

To search for available images in the repository..

$ docker search centos
NAME                               DESCRIPTION                                     STARS               OFFICIAL            AUTOMATED
centos                             The official build of CentOS.                   4585                [OK]
ansible/centos7-ansible            Ansible on Centos7                              115                                     [OK]
jdeathe/centos-ssh                 CentOS-6 6.10 x86_64 / CentOS-7 7.5.1804 x86…   99                                      [OK]
consol/centos-xfce-vnc             Centos container with "headless" VNC session…   60                                      [OK]
imagine10255/centos6-lnmp-php56    centos6-lnmp-php56                              44                                      [OK]
tutum/centos                       Simple CentOS docker image with SSH access      43
centos/mysql-57-centos7            MySQL 5.7 SQL database server                   38
gluster/gluster-centos             Official GlusterFS Image [ CentOS-7 +  Glust…   32                                      [OK]
openshift/base-centos7             A Centos7 derived base image for Source-To-I…   31
centos/python-35-centos7           Platform for building and running Python 3.5…   28
centos/postgresql-96-centos7       PostgreSQL is an advanced Object-Relational …   26
kinogmt/centos-ssh                 CentOS with SSH                                 22                                      [OK]
openshift/jenkins-2-centos7        A Centos7 based Jenkins v2.x image for use w…   14
pivotaldata/centos-gpdb-dev        CentOS image for GPDB development. Tag names…   7
openshift/mysql-55-centos7         DEPRECATED: A Centos7 based MySQL v5.5 image…   6
openshift/jenkins-1-centos7        DEPRECATED: A Centos7 based Jenkins v1.x ima…   4
openshift/wildfly-101-centos7      A Centos7 based WildFly v10.1 image for use …   4
darksheer/centos                   Base Centos Image -- Updated hourly             3                                       [OK]
pivotaldata/centos                 Base centos, freshened up a little with a Do…   2
blacklabelops/centos               CentOS Base Image! Built and Updates Daily!     1                                       [OK]
pivotaldata/centos-mingw           Using the mingw toolchain to cross-compile t…   1
jameseckersall/sonarr-centos       Sonarr on CentOS 7                              0                                       [OK]
pivotaldata/centos-gcc-toolchain   CentOS with a toolchain, but unaffiliated wi…   0
smartentry/centos                  centos with smartentry                          0                                       [OK]
pivotaldata/centos7-build          CentosOS 7 image for GPDB compilation           0

To download the image from the search results..

$ docker pull centos
Using default tag: latest
latest: Pulling from library/centos
256b176beaff: Pull complete
Digest: sha256:6f6d986d425aeabdc3a02cb61c02abb2e78e57357e92417d6d58332856024faf
Status: Downloaded newer image for centos:latest

After downloading the image, we may run the instance.

$ docker run centos

Now, we have downloaded many images. To see the list of images..

$ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
centos              latest              5182e96772bf        10 days ago         200MB
ubuntu              latest              735f80812f90        2 weeks ago         83.5MB
hello-world         latest              2cb0d9787c4d        5 weeks ago         1.85kB

To run an interactive shell of centos, lets run it.

$ docker run -it centos
[root@53771652af4a /]# hostname
53771652af4a
[root@53771652af4a /]# id
uid=0(root) gid=0(root) groups=0(root)

Customizing the containers

Let’s modify this container a bit. For example. following is how we install net-tools package

[root@53771652af4a /]# ifconfig
bash: ifconfig: command not found
[root@53771652af4a /]# yum install net-tools
Loaded plugins: fastestmirror, ovl
Determining fastest mirrors
* base: mirror.0x.sg
* extras: mirror.0x.sg
* updates: mirror.0x.sg
base | 3.6 kB 00:00:00
extras | 3.4 kB 00:00:00
updates | 3.4 kB 00:00:00
(1/4): base/7/x86_64/group_gz | 166 kB 00:00:00
(2/4): extras/7/x86_64/primary_db | 174 kB 00:00:00
(3/4): base/7/x86_64/primary_db | 5.9 MB 00:00:00
(4/4): updates/7/x86_64/primary_db | 5.0 MB 00:00:01
Resolving Dependencies
--> Running transaction check
---> Package net-tools.x86_64 0:2.0-0.22.20131004git.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

======================================================================================================================================================
Package Arch Version Repository Size
======================================================================================================================================================
Installing:
net-tools x86_64 2.0-0.22.20131004git.el7 base 305 k

Transaction Summary
======================================================================================================================================================
Install 1 Package

Total download size: 305 k
Installed size: 917 k
Is this ok [y/d/N]: y
Downloading packages:
warning: /var/cache/yum/x86_64/7/base/packages/net-tools-2.0-0.22.20131004git.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
Public key for net-tools-2.0-0.22.20131004git.el7.x86_64.rpm is not installed
net-tools-2.0-0.22.20131004git.el7.x86_64.rpm | 305 kB 00:00:00
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
Importing GPG key 0xF4A80EB5:
Userid : "CentOS-7 Key (CentOS 7 Official Signing Key) "
Fingerprint: 6341 ab27 53d7 8a78 a7c2 7bb1 24c6 a8a7 f4a8 0eb5
Package : centos-release-7-5.1804.1.el7.centos.x86_64 (@Updates)
From : /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
Is this ok [y/N]: y
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : net-tools-2.0-0.22.20131004git.el7.x86_64 1/1
Verifying : net-tools-2.0-0.22.20131004git.el7.x86_64 1/1

Installed:
net-tools.x86_64 0:2.0-0.22.20131004git.el7

Complete!
[root@53771652af4a /]# ifconfig
eth0: flags=4163 mtu 1500
inet 172.17.0.3 netmask 255.255.0.0 broadcast 172.17.255.255
ether 02:42:ac:11:00:03 txqueuelen 0 (Ethernet)
RX packets 8448 bytes 12601933 (12.0 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 4833 bytes 321266 (313.7 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

lo: flags=73 mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
loop txqueuelen 1000 (Local Loopback)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

Similarly I have installed openssh server as well. As we customized our container now, we need to commit it to retain the updated copy. To commit it, lets exit the container shell and execute the following command from the docker machine.

$ docker commit -m "added net-tools and ssh server" -a "pandian" 53771652af4a pandian/centos_ssh
sha256:7f019be4424c070511efb90e357b720333df5d80f845de6a7d569b94ac829fd7

To get the container id, you may use docker ps command as below.

$ docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                      PORTS               NAMES
53771652af4a        centos              "/bin/bash"         27 minutes ago      Exited (0) 7 minutes ago                        relaxed_vaughan
f6ed55b0451c        centos              "/bin/bash"         33 minutes ago      Exited (0) 33 minutes ago                       relaxed_rosalind
462658ae9e5a        ubuntu              "bash"              15 hours ago        Up 15 hours                                     inspiring_mahavira
1aebd1e64faa        ubuntu              "bash"              15 hours ago        Exited (127) 15 hours ago                       gracious_banach
ff56bc579e04        hello-world         "/hello"            15 hours ago        Exited (0) 15 hours ago                         distracted_lamarr
e209861d337d        hello-world         "/hello"            15 hours ago        Exited (0) 15 hours ago                         laughing_ramanujan

As we commited our image, lets see the image list now. the repository has the updated image.

$ docker images
REPOSITORY           TAG                 IMAGE ID            CREATED             SIZE
pandian/centos_ssh   latest              7f019be4424c        25 minutes ago      294MB
centos               latest              5182e96772bf        10 days ago         200MB
ubuntu               latest              735f80812f90        3 weeks ago         83.5MB
hello-world          latest              2cb0d9787c4d        5 weeks ago         1.85kB

Starting and stopping instances

Here is the way we stop the instances.

$ docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
462658ae9e5a        ubuntu              "bash"              15 hours ago        Up 15 hours                             inspiring_mahavira
$ docker stop 462658ae9e5a
462658ae9e5a

To start the instance the instance customized by us..

$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
pandian/centos_ssh latest 7f019be4424c 43 minutes ago 294MB
centos latest 5182e96772bf 10 days ago 200MB
ubuntu latest 735f80812f90 3 weeks ago 83.5MB
hello-world latest 2cb0d9787c4d 5 weeks ago 1.85kB
$ docker run -it pandian/centos_ssh
[root@d66d18a06066 /]# ifconfig
eth0: flags=4163 mtu 1500
inet 172.17.0.2 netmask 255.255.0.0 broadcast 172.17.255.255
ether 02:42:ac:11:00:02 txqueuelen 0 (Ethernet)
RX packets 25 bytes 3024 (2.9 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

lo: flags=73 mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
loop txqueuelen 1000 (Local Loopback)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

 

Docker – Setup

I am drafting the step-by-steps to install Docker in this post.

VM Setup

I created a new Ubuntu VM 16.04 in my Xen Server with manual network setup. Hence I have given a static IP to this new VM.

I Installed the xentools using the following commands. This is not required if you do not want to install it.


sudo mount /dev/dvd /media
sudo /media/pandian/XenServer\ Tools/Linux/install.sh

 

After successful installation of xentools, a reboot of VM is required.

Install SSH demon.


sudo apt update

sudo apt upgrade

sudo apt-get install openssh-server

sudo apt-get install curl

 

Add the GPG of docker repository.


curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

 

Add Docker repository to ubuntu sources and install Docker from docker repo, instead of default ubuntu repo.


sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"

sudo apt-get update

apt-cache policy docker-ce

sudo apt-get install -y docker-ce

sudo systemctl status docker

Docker is now installed and started.

But it needs sudo to run docker command.


$ docker info
Got permission denied while trying to connect to the Docker daemon socket at uniial unix /var/run/docker.sock: connect: permission denied
$ sudo docker info

Hence, add the unix user to docker group to avoid it. Here is how we shall do it. Credit goes to digitalocean.


~$ sudo usermod -aG docker ${USER}
~$ su - ${USER}
Password:
~$ id -nG
pandian adm cdrom sudo dip plugdev lpadmin sambashare docker

$ id
uid=1000(pandian) gid=1000(pandian) groups=1000(pandian),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),113(lpadmin),128(sambashare),999(docker)

So the user has been added to docker group. id confirms the same. Now it is the time to run our first hello-world container. As we do not have this image locally, it is downloaded from docker repository.


~$ docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
9db2ca6ccae0: Pull complete
Digest: sha256:4b8ff392a12ed9ea17784bd3c9a8b1fa3299cac44aca35a85c90c5e3c7afacdc
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
(amd64)
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
https://hub.docker.com/

For more examples and ideas, visit:
https://docs.docker.com/engine/userguide/

 

 

 

No Spring WebApplicationInitializer types detected on classpath

Wah, what a stupid error it was!

My Spring web app, which was running smoothly, refused to start. I don’t find any logs in log4j or tomcat log. Only clue I had was –

No Spring WebApplicationInitializer types detected on classpath

Here is how I solved it –

  1. Stop the tomcat
  2. Clean and build all eclipse projects
  3. Goto server tab and select the tomcat server. Press clean. Press clean work directory.
  4. Right click on the tomcat and remove it.
  5. Delete the tomcat from the eclipse run times
  6. Add tomcat server to the eclipse servers again
  7. Start the application