AWS how to shrink EBS volume ext4

EBS volume

Please find a step by step guide to shrink an EBS volume with ext4 on it:

1) Stop source instance;

2) Create snapshot of the root volume [1];

3) From the snapshot, create a second volume, in the same availability zone as your instance (you will have to attach it later) [2]. This will be your pristine source;

4) Create new empty EBS volume (not based on a snapshot), with smaller size, in the same availability zone – from AWS console: Volumes; Create Volume; Snapshot == No Snapshot; IMPORTANT – size should be large enough to hold all the files from the source file system and in accordance to your needed new size. (I created a volume of 6GB in my case);

5) Start instance (I suggest you to create a new temporary one from Amazon Ami);

6) Attach both volumes (source volume and destination volume) to the new instance while taking note of the block devices names you assign for them in the AWS console (/dev/sdX)
7) ssh into the new instance and run these commands as root:

# fdisk -l
WARNING: fdisk GPT support is currently new, and therefore in an experimental phase. Use at your own discretion.

Disk /dev/xvda: 8589 MB, 8589934592 bytes, 16777216 sectors   <<==== root device for temporary instance
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: gpt

#         Start          End    Size  Type            Name
1         4096     16777182      8G  Linux filesyste Linux
128         2048         4095      1M  BIOS boot parti BIOS Boot Partition

Disk /dev/xvdf: 10.7 GB, 10737418240 bytes, 20971520 sectors     <<==== SOURCE VOLUME
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: 0x0003c444

Device Boot      Start         End      Blocks   Id  System
/dev/xvdf1   *        2048    20970332    10484142+  83  Linux

Disk /dev/xvdg: 6442 MB, 6442450944 bytes, 12582912 sectors          <<==== DESTINATION VOLUME
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

# fdisk /dev/xvdg
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.

Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0x4e1fdbb9.

Command (m for help): n
Partition type:
p   primary (0 primary, 0 extended, 4 free)
e   extended
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-10485759, default 2048): <<================ PRESS ENTER
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-10485759, default 10485759): +5G  <<====== CHOOSE THE NEW SIZE (I suggest it to be your volume size minus one gb. In my case 6GB volume = 5GB partition)
Partition 1 of type Linux and of size 4.7 GiB is set

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

Calling ioctl() to re-read partition table.
Syncing disks.

# mkdir /source

# e2fsck -f /dev/xvdf1
e2fsck 1.42.9 (28-Dec-2013)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/xvdf1: 54916/655360 files (0.1% non-contiguous), 549657/2621035 blocks

8) We now resize the source filesystem in accordance to the size of the new partition /dev/xvdg1 that we created before minus 1GB (5GB partition = 4GB filesystem).

# resize2fs /dev/xvdf1 4G
resize2fs 1.42.9 (28-Dec-2013)
Resizing the filesystem on /dev/xvdf1 to 1048576 (4k) blocks.
The filesystem on /dev/xvdf1 is now 1048576 blocks long.   <<==== REMEMBER THIS NUMBER OF BLOCKS

9) Clone MBR

# dd if=/dev/xvdf of=/dev/xvdg bs=446 count=1
1+0 records in
1+0 records out
446 bytes (446 B) copied, 0.00197664 s, 226 kB/s

10) Now it is time to do some math to copy the data with dd. We need to calculate the number of chunks (using the number of blocks from the resize2fs output we had before). This really depends on the size you have choosen before (point 8):
blocks*4/(chunk_size_in_mb*1024) – round up a bit for safety
I suggest to choose 16MB as chunk_size_in_mb
In my case then:
1048576 * 4 / 16 * 1024  = 256   <<==== 256 is the number that I use below, in your case you need to use yours which depends on the size of your filesystem (point 8)

# dd if=/dev/xvdf1 ibs=16M of=/dev/xvdg1 obs=16M count=256 <<===== change 256 with the outcome of your calculation
256+0 records in
256+0 records out
4294967296 bytes (4.3 GB) copied, 86.8375 s, 49.5 MB/s

11) Just to make sure that dd worked fine

# resize2fs /dev/xvdg1 4G  <<======= size that you have chosen at point 8
resize2fs 1.42.9 (28-Dec-2013)
The filesystem is already 1048576 blocks long.  Nothing to do!

12) Now please detach the new shrinked volume (DESTINATION -> /dev/sdg) and attach it to the original instance with device as /dev/sda1

13) Start the old instance and try to ssh in.

14) Check that everything is working fine and in case it does, repeat the procedure for each instance.

Note that the instance will automatically expand the size of the filesystem in order to occupy 100% of the space in the EBS volume

imapd: Failed to connect to socket /tmp/fam–

mailToday, when I was migrating my mail server I encountered a quite-annoying problem. In my syslog I had this error, which slowed down my imap server:

imapd: Failed to connect to socket /tmp/fam--

Looking for an answer to this annoying problem I found the solution which requires to install this library to fix the problem: libfam0

Once installed it, restart courier-imap and everything will start working fine.

Spacewalk + Ubuntu

[Sat Sep 28 13:08:44 2013] rhn_register Warning: haldaemon or messagebus service not running. Cannot probe hardware and DMI information.

[Sat Sep 28 13:08:58 2013] rhn_register
Traceback (most recent call last):
File "/usr/share/rhn/up2date_client/", line 951, in run
File "/usr/share/rhn/up2date_client/", line 487, in sendPackages
s.registration.add_packages(systemId, packageList)
File "/usr/share/rhn/up2date_client/", line 63, in __call__
return rpcServer.doCall(method, *args, **kwargs)
File "/usr/share/rhn/up2date_client/", line 196, in doCall
ret = method(*args, **kwargs)
File "/usr/lib/python2.7/", line 1224, in __call__
return self.__send(self.__name, args)
File "/usr/share/rhn/up2date_client/", line 37, in _request1
ret = self._request(methodname, params)
File "/usr/lib/python2.7/dist-packages/rhn/", line 377, in _request
request = self._req_body(self._strip_characters(params), methodname)
File "/usr/lib/python2.7/dist-packages/rhn/", line 232, in _req_body
return xmlrpclib.dumps(params, methodname, encoding=self._encoding)
File "/usr/lib/python2.7/", line 1085, in dumps
data = m.dumps(params)
File "/usr/lib/python2.7/", line 632, in dumps
dump(v, write)
File "/usr/lib/python2.7/", line 654, in __dump
f(self, value, write)
File "/usr/lib/python2.7/", line 714, in dump_array
dump(v, write)
File "/usr/lib/python2.7/", line 654, in __dump
f(self, value, write)
File "/usr/lib/python2.7/", line 735, in dump_struct
dump(v, write)
File "/usr/lib/python2.7/", line 654, in __dump
f(self, value, write)
File "/usr/lib/python2.7/", line 658, in dump_nil
raise TypeError, "cannot marshal None unless allow_none is enabled"
: cannot marshal None unless allow_none is enabled


vi /usr/lib/python2.7/

def dump_nil (self, value, write):
#if not self.allow_none:
# raise TypeError, “cannot marshal None unless allow_none is enabled”
dispatch[NoneType] = dump_nil


Openstack error deleting instances

If you have a power loss and for whatever reasons you had paused an instance, you won’t be able to unpause it and therefore to delete it. Here you can find the solution:

check instances IDs:

# nova list


# mysql nova -p

mysql> update instances set vm_state=”active” where uuid=’instance_id’;

# nova delete instance_id

There you go!

Openstack add image

Find ready images about mainstream distributions:

Download it

wget your_distro

source .bashrc

glance add --os_username=$NOVA_USERNAME --os_password=$NOVA_PASSWORD --os_tenant_name=$NOVA_TENANT_NAME --os_auth_url= name="Ubuntu 13" is_public=true container_format=bare disk_format=img2 < your_distro_downloaded


Nova-compute Error


Failed to schedule_run_instance: No valid host was found. Is the appropriate service running?

nova-manage service list

nova-scheduler nova-controller nova enabled :-) 2013-09-26 12:42:27
nova-consoleauth nova-controller nova enabled :-) 2013-09-26 12:42:27
nova-compute nova-controller nova enabled XXX 2013-09-26 12:42:27
nova-network nova-controller nova enabled :-) 2013-09-26 12:42:21
nova-volume nova-controller nova enabled :-) 2013-09-26 12:42:28

service libvirt-bin restart

Openstack: Error no domain for instance

If you encour in this error: CRITICAL nova [-] Domain not found: no domain with matching name 'instance-00000004'


var/lib/nova/instances/instance-0000000a# virsh define libvirt.xml

Domain instance-0000000a defined from libvirt.xml


#ls /etc/libvirt/qemu

Instance-0000000a.xml instance-0000000b.xml instance-0000000c.xml network

Stackopen glance authentication problem

# With the addition of Keystone, to use an openstack cloud you should
# authenticate against keystone, which returns a **Token** and **Service
# Catalog**. The catalog contains the endpoint for all services the
# user/tenant has access to - including nova, glance, keystone, swift.
# *NOTE*: Using the 2.0 *auth api* does not mean that compute api is 2.0. We
# will use the 1.1 *compute api*
export OS_AUTH_URL=http://localhost:5000/v2.0

# With the addition of Keystone we have standardized on the term **tenant**
# as the entity that owns the resources.
export OS_TENANT_ID=UUID_OF_THE_TENANT=09abcbd7ab01427ea0f59031f0de79e6
export OS_TENANT_NAME=admin

# In addition to the owning entity (tenant), openstack stores the entity
# performing the action as the **user**.
export OS_USERNAME=admin

# With Keystone you pass the keystone password.
echo "Please enter your OpenStack Password: "

source adminrc

Eucalyptus problems

There are a couple of problems that I faced while I was installing Eucalyptus all in one box:

First of all, if you try to install it by USB you need to set a web server repository on a machine in order that he can fetch the files otherwise you will not be able to install it.

Second problem, if you have problems to install images and you have:

eustore-install-image -t ./euca-centos6.4-ec2user-2013.07.12-x86_64.tgz -b centos --debug -s centos6.4 -a x86_64
2013-09-21 18:17:50,594 InstallImage [DEBUG]:request_params: {'tarball': './euca-centos6.4-ec2user-2013.07.12-x86_64.tgz', 'bucket': 'centos', 'description': 'centos6.4', 'dir': '/tmp', 'architecture': 'x86_64'}
2013-09-21 18:17:50,595 InstallImage [DEBUG]:Using access key provided by client.
2013-09-21 18:17:50,595 InstallImage [DEBUG]:Using secret key provided by client.
2013-09-21 18:17:50,596 InstallImage [DEBUG]:Using access key provided by client.
2013-09-21 18:17:50,597 InstallImage [DEBUG]:Using secret key provided by client.
2013-09-21 18:17:50,597 InstallImage [DEBUG]:Method: POST
2013-09-21 18:17:50,597 InstallImage [DEBUG]:Path: /services/Euare/
2013-09-21 18:17:50,597 InstallImage [DEBUG]:Data:
2013-09-21 18:17:50,597 InstallImage [DEBUG]:Headers: {}
2013-09-21 18:17:50,597 InstallImage [DEBUG]:Host:
2013-09-21 18:17:50,597 InstallImage [DEBUG]:Params: {'Action': 'ListAccountAliases', 'Version': '2010-05-08'}
2013-09-21 18:17:50,598 InstallImage [DEBUG]:establishing HTTP connection: kwargs={'timeout': 70}
2013-09-21 18:17:50,598 InstallImage [DEBUG]:Token: None
2013-09-21 18:17:50,599 InstallImage [DEBUG]:CanonicalRequest:


2013-09-21 18:17:50,599 InstallImage [DEBUG]:StringToSign:
2013-09-21 18:17:50,599 InstallImage [DEBUG]:Signature:
2013-09-21 18:17:50,611 InstallImage [DEBUG]:404 Not Foundunknownunknown
2013-09-21 18:17:50,612 InstallImage [ERROR]:404 Not Found
2013-09-21 18:17:50,612 InstallImage [ERROR]:404 Not Foundunknownunknown
Error(404 Not Found): unknown

Than what you need to is to upgrade Euca2ools:

To install Euca2ools on RHEL 6 or CentOS 6 using Eucalyptus-provided packages:

Install the EPEL package repository:
yum install

Install the euca2ools package repository:
yum install

Install the euca2ools package:
yum install euca2ools