Extend AWS RHEL 6 instance root file system size

AWS: Free tier t2.micro 2 instance A and B

OS: RHEL 6.6

root FS: Ext4

Filesystem      Size  Used Avail Use% Mounted on
/dev/xvda1      5.8G  4.1G  1.5G  74% /

Using: AWS CLI (They can be done easily from aws console with web ui)

Task: Root file system of instance B from 6G to available space.

Disclaimer: Please be careful while performing these steps as they are too risk and can cause loss of entire system.

Steps:

  1.  Stop the instance B #aws ec2 stop-instances –instance-ids <instance B ID>
  2. Detach the root volume from instance B  #aws ec2 detach-volume –volume-id=”vol-xxxxxxxxx”
  3. Create snashot (For recovery in case you last the file system while doing below steps) $aws ec2 create-snapshot –volume-id “vol-xxxxxxxxx” –description “instance B root vol backup”

–Note: This is an extremly important to create snapshot for the safety to recover

  1. Attach to Instance A #aws ec2 attach-volume –volume-id=”vol-0d61acbe3bff8d115″ –instance-id=”i-05c133fd050dbd04d” –device=”/dev/sdf”
  2. Connect to the instance A through ssh $ssh -i “mykey.pem” ec2-user@<public ip of instanc A>
  3. Use command “lsblk” to verify the list of devices $sudo lsblk
    NAME    MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
    xvda    202:0    0  10G  0 disk
    └─xvda1 202:1    0   6G  0 part /
    xvdb    202:16   0  10G  0 disk /hadoop
    xvdf    202:80   0  30G  0 disk
    └─xvdf1 202:81   0  6G  0 part
  4.  Using parted, recreated the 6G partition xvdf1 to 10G $sudo parted /dev/xvdf
  5.  Change units to sectors (parted) unit s
  6. Print the current partion
    (parted) print
    Model: Xen Virtual Block Device (xvd)
    Disk /dev/xvdf: 62914560s
    Sector size (logical/physical): 512B/512B
    Partition Table: gpt
    Number Start End Size File system Name Flags
    1 2048s 12584959s 12582912s ext4 ext4 boot
  7. Delete the partion (parted) rm 1
  8. Create new partition (parted) mkpart ext4 2048s 100%  Warning: You requested a partition from 2048s to 62914559s. The closest location we can manage is 2048s to 20971486s.Is this still acceptable to you?Yes/No? Yes
  9. Print New Partition and verify(parted) print
    Model: Xen Virtual Block Device (xvd)
    Disk /dev/xvdf: 62914560s
    Sector size (logical/physical): 512B/512B
    Partition Table: gpt

    Number Start End Size File system Name Flags
    1 2048s 20971486s 20969439s ext4 ext4

  10. Make it bootable  (parted) set 1 boot on
  11. Quit from parted (parted) quit
  12. Run e2fsck $sudo e2fsck -f /dev/xvdf1
    e2fsck 1.41.12 (17-May-2010)
    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: 58700/393216 files (0.1% non-contiguous), 631205/1572864 blocks
  13.  Extend using resize2fs command $sudo resize2fs /dev/xvdf1
    resize2fs 1.41.12 (17-May-2010)
    Resizing the filesystem on /dev/xvdf1 to 2621179 (4k) blocks.
    The filesystem on /dev/xvdf1 is now 2621179 blocks long.
  14. Verify attaching the extended partition $sudo mount -t ext4 /dev/xvdf1 /mnt
  15. Verify the file system with ls and $sudo df -h /mnt
    Filesystem Size Used Avail Use% Mounted on
    /dev/xvdf1 9.8G 2.2G 7.1G 24% /mnt

Now detach the ebs volume from instance A and attach it to instance B as root device i.e. “/dev/sda”

16. aws ec2 detach-volume –volume-id=”vol-*********”

17. aws ec2 attach-volume –volume-id=”vol-*********” –instance-id=”Instance B id” –device=”/dev/sda1
Note: attaching device as /dev/sda1 is import, as aws treats that as root device.

18. Start the instance B

aws ec2 start-instances –instance-id=”Instance B id”

19. Connect to the instance B through ssh and check file system size.

$ssh -i “mykey.pem” ec2-user@<public ip of instanc B>

df -h
Filesystem Size Used Avail Use% Mounted on
/dev/xvda1 9.8G 2.2G 7.1G 24% /
tmpfs 498M 0 498M 0% /dev/shm

 

 

——————————————————————————————————-

RHEL 7 – Notes: NTP:Chronyd

Update ntp server in RHEL7 using new chronyd.service

vi /etc/chrony.conf
systemctl restart chronyd.service
systemctl enable chronyd.service
chronyc sources -v
#timedatectl
Local time: Tue 2015-12-22 04:21:22 EST
Universal time: Tue 2015-12-22 09:21:22 UTC
RTC time: Tue 2015-12-22 09:21:22
Time zone: America/New_York (EST, -0500)
NTP enabled: yes
NTP synchronized: yes
RTC in local TZ: no
DST active: no
Last DST change: DST ended at
Sun 2015-11-01 01:59:59 EDT
Sun 2015-11-01 01:00:00 EST
Next DST change: DST begins (the clock jumps one hour forward) at
Sun 2016-03-13 01:59:59 EST
Sun 2016-03-13 03:00:00 EDT

#timedatectl list-timezones
Africa/Abidjan
Africa/Accra
Africa/Addis_Ababa
Africa/Algiers
Africa/Asmara
Africa/Bamako

#How to change time zone

#timedatectl
Local time: Tue 2015-12-22 04:23:16 EST
Universal time: Tue 2015-12-22 09:23:16 UTC
RTC time: Tue 2015-12-22 09:23:15
       Time zone: America/New_York (EST, -0500)
NTP enabled: yes
NTP synchronized: yes
RTC in local TZ: no
DST active: no
Last DST change: DST ended at
Sun 2015-11-01 01:59:59 EDT
Sun 2015-11-01 01:00:00 EST
Next DST change: DST begins (the clock jumps one hour forward) at
Sun 2016-03-13 01:59:59 EST
Sun 2016-03-13 03:00:00 EDT

# timedatectl set-timezone Asia/Singapore

# timedatectl
Local time: Tue 2015-12-22 17:23:29 SGT
Universal time: Tue 2015-12-22 09:23:29 UTC
RTC time: Tue 2015-12-22 09:23:29
Time zone: Asia/Singapore (SGT, +0800)
NTP enabled: yes
NTP synchronized: yes
RTC in local TZ: no
DST active: n/a

RHEL 7 – Notes: Journalctl

Journalctl to view system logs:

===========================

journalctl -n
journalctl -n 5
journalctl -p err
journalctl –since today
journalctl –since “2015-12-22 02:00:00” –until “2015-12-22 03:00:00”
journalctl -o verbose

journalctl _PID=1

journalctl -b (since last reboot if they were made persistent)

 

How to make persistent:

mkdir /var/log/journal

chown root:systemd-journal /var/log/journal

chmod 2755 /var/log/journal

kilall -USR1 systemd-journald

 

How to drop cache in Linux

echo 3 > /proc/sys/vm/drop_caches

https://www.kernel.org/doc/Documentation/sysctl/vm.txthttps://www.kernel.org/doc/Documentation/sysctl/vm.txthttps://www.kernel.org/doc/Documentation/sysctl/vm.txthttps://www.kernel.org/doc/Documentation/sysctl/vm.txthttps://www.kernel.org/doc/Documentation/sysctl/vm.txthttps://www.kernel.org/doc/Documentation/sysctl/vm.txthttps://www.kernel.org/doc/Documentation/sysctl/vm.txthttps://www.kernel.org/doc/Documentation/sysctl/vm.txthttps://www.kernel.org/doc/Documentation/sysctl/vm.txt
drop_caches

Writing to this will cause the kernel to drop clean caches, as well as
reclaimable slab objects like dentries and inodes.  Once dropped, their
memory becomes free.

To free pagecache:
	echo 1 > /proc/sys/vm/drop_caches
To free reclaimable slab objects (includes dentries and inodes):
	echo 2 > /proc/sys/vm/drop_caches
To free slab objects and pagecache:
	echo 3 > /proc/sys/vm/drop_caches

 

Linux: XFS vs EXT4

XFS:                   EXT4

max supported file system size: 500 TB – 50TB

single largest file: 500TB – 16TB

Default File System: RHEL 7 – RHEL 6

Performance:  Good on systems with large CPU, cores, less cpu extensive.- ext4: workloads like single threaded,singdle disk with synchronous updates

Online Extend file system: Yes – Yes

Offline Reducing File System: No – No

 

Connecting to wifi through command prompt in Linux (nmcli)

To connect to wifi with a password

#nmcli d wifi conn MyWifi password ‘xxxxxxx’ iface wlan0

MyWifi is SSID name, replace this with your wifi name (SSID name). Keep your password in place of ‘xxxxxx’

wlan0 interface for wifi network, this you can find with ifconfig command or nmcli command.

To disconnect wifi

# nmcli d disconnect iface wlan0

To see network status

# nmcli d status
DEVICE     TYPE              STATE
eth0       802-3-ethernet    unavailable
wlan0      802-11-wireless   disconnected

To See list of available wifi networks

#nmcli d list

nmcli has 3 OBJECTs
nm              NetworkManager’s status
c[onnection]    NetworkManager’s connections
d[evice]        devices managed by NetworkManager

1. Network Manager (nm)

(COMMAND := { status | permissions | enable | sleep | wifi | wwan }
# nmcli nm status
RUNNING         STATE           WIFI-HARDWARE   WIFI       WWAN-HARDWARE   WWAN
running         disconnected    enabled         enabled    enabled         enabled

# nmcli nm wifi off

# ifconfig wlan0
wlan0     Link encap:Ethernet  HWaddr xx:xx:xx:xx:xx:xx
BROADCAST MULTICAST  MTU:1500  Metric:1
RX packets:95213298 errors:0 dropped:0 overruns:0 frame:0
TX packets:87755319 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:88153431076 (88.1 GB)  TX bytes:73877643984 (73.8 GB)

# nmcli nm wifi on

# ifconfig wlan0
wlan0     Link encap:Ethernet  HWaddr xx:xx:xx:xx:xx:xx
UP BROADCAST MULTICAST  MTU:1500  Metric:1
RX packets:95213298 errors:0 dropped:0 overruns:0 frame:0
TX packets:87755319 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:88153431076 (88.1 GB)  TX bytes:73877643984 (73.8 GB)

2. Network Managers Connection (c)

(COMMAND := { list | status | up | down | delete })

How to list available network manager connections

#nmcli c list

How to delete one of the network manager connection from the list using uuid

# nmcli c delete uuid 58be4adb-a360-46cc-xxxx-8868a8cfxxxx

3. Network device (d)

DRBD (Distributed Replicated Block Device) a low cost HA solution (alternate to SRDF)

Some of the key features

  • DRBD® refers to block devices designed as a building block to form high availability (HA) clusters. This is done by mirroring a whole block device via an assigned network. DRBD can be understood as network based raid-1
  •     DRBD® available under the terms of The GNU General Public License v2
  • Fully synchronous, memory synchronous or asynchronous modes of operation

Reference:
http://drbd.linbit.com/home/what-is-drbd/

http://drbd.linbit.com/users-guide/

http://en.wikipedia.org/wiki/Distributed_Replicated_Block_Device