Expand root filesystem using CLI parted & reize2fs

October 29, 2017 Leave a comment

You could login using headless mode (headless mode means that you don’t have a display connect and you login with ssh from any other system) and use these steps to expand your root partition and file system on a Raspberry Pi running Pedora (fedora remix):
– backup your system in case of a misstake!
– use “fdisk /dev/mmcblk0” to view your partitions.
– use “parted” to delete the partition and then recreate it but with a larger size. (don’t worry, the data will remain)
– reboot to activate the partition changes.
– use “resize2fs /dev/mmclk0p2” to enlarge the root file system.
– use e2fsck -f /dev/mmcblk0p2 to perform a file system check.
– use “df -h” to check results.

Before you extend your root partition and filesystem you should know how big your rootfs is and how much space is available:

[root@raspi ~]# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/root       1.6G  1.5G   53M  97% /
/dev/mmcblk0p1   50M   18M   33M  35% /boot
[root@raspi ~]#

Determine the storage devices:

[root@raspi ~]# ll /dev/mm*
brw-rw---- 1 root disk 179, 0 Jun  3 13:22 /dev/mmcblk0
brw-rw---- 1 root disk 179, 1 Jun  3 13:21 /dev/mmcblk0p1
brw-rw---- 1 root disk 179, 2 Jun  3 13:21 /dev/mmcblk0p2
[root@raspi ~] 

Check the partition table:

[root@raspi ~] fdisk /dev/mmcblk0
Welcome to fdisk (util-linux 2.22.1).

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/mmcblk0: 16.0 GB, 16012804096 bytes, 31275008 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 identifier: 0x000622ba

        Device Boot      Start         End      Blocks   Id  System
/dev/mmcblk0p1   *        2048      104447       51200    c  W95 FAT32 (LBA)
/dev/mmcblk0p2          104448     3494304     1694928+  83  Linux

Command (m for help): q

[root@raspi ~]#

So the SD card has 31275008 (16GB) sectors and the last one in use is 3494304 (1.6GB).
Print the partition table with “parted”:

[root@raspi ~]# parted /dev/mmcblk0
GNU Parted 3.1
Using /dev/mmcblk0
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) unit chs                                                         
(parted) print                                                            
Model: SD  (sd/mmc)
Disk /dev/mmcblk0: 1946,198,43
Sector size (logical/physical): 512B/512B
BIOS cylinder,head,sector geometry: 1946,255,63.  Each cylinder is 8225kB.
Partition Table: msdos
Disk Flags: 

Number  Start     End        Type     File system  Flags
 1      0,32,32   6,127,56   primary  fat16        boot, lba
 2      6,127,57  217,130,9  primary  ext4
(parted)

So the disk ends at 1946,198,43 cylinder,head,sector and the current root partition ends at 217,130,9.

Note: “fdisk” displays the partition info in 512 bytes blocks and “parted” displays the cylinder,head,sector geometry. Each cylinder is 8225kB.

Now remove the second partition and recreate it larger.

Note: If you have a third swap or other partition that you don’t need any longer, you can remove that one too and use the disk space to extend you.

Removing the partition will only change the partition table and not the data. Creating a new partition will write a new start and end point in the partition table.

Be careful: If you make a misstake, you lose you root partition data:
(Ignore the warning.)

(parted) rm 2                                                             
Error: Partition(s) 2 on /dev/mmcblk0 have been written, but we have been unable to inform the kernel of the change, probably because it/they are in use.  As a result, the old partition(s) will
remain in use.  You should reboot now before making further changes.
Ignore/Cancel? i                                                          
(parted)

And check whether the partition was removed:

(parted) print                                                            
Model: SD  (sd/mmc)
Disk /dev/mmcblk0: 1946,198,43
Sector size (logical/physical): 512B/512B
BIOS cylinder,head,sector geometry: 1946,255,63.  Each cylinder is 8225kB.
Partition Table: msdos
Disk Flags: 

Number  Start    End       Type     File system  Flags
 1      0,32,32  6,127,56  primary  fat16        boot, lba

(parted) 

Now the second partition is removed. Do not reboot your system before you have created the new partition! Other wise you lose your root file system.

The new partition must start at the same position where the old root partition did start and it ends where you like. It must have at least the same size as current partition and it may not exceed the end of the disk (in my case 1946,198,43).
(Ignore the warning.)

(parted) mkpart primary 6,127,57  1946,198,43
Error: Partition(s) 2 on /dev/mmcblk0 have been written, but we have been unable to inform the kernel of the change, probably because it/they are in use.  As a result, the old partition(s) will
remain in use.  You should reboot now before making further changes.
Ignore/Cancel? i                                                          
(parted)

And check whether the partition was created:

(parted) print                                                            
Model: SD  (sd/mmc)
Disk /dev/mmcblk0: 1946,198,43
Sector size (logical/physical): 512B/512B
BIOS cylinder,head,sector geometry: 1946,255,63.  Each cylinder is 8225kB.
Partition Table: msdos
Disk Flags: 

Number  Start     End          Type     File system  Flags
 1      0,32,32   6,127,56     primary  fat16        boot, lba
 2      6,127,57  1946,198,43  primary  ext4

(parted) quit                                                             
Information: You may need to update /etc/fstab.

[root@raspi ~]# 

Be carefull: The kernel is not aware yet of the new partition size. You must reboot your system before you do any thing else.

[root@raspi ~]# reboot

Check the new partition size after the reboot:

[root@raspi ~]# fdisk /dev/mmcblk0
Welcome to fdisk (util-linux 2.22.1).

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/mmcblk0: 16.0 GB, 16012804096 bytes, 31275008 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 identifier: 0x000622ba

        Device Boot      Start         End      Blocks   Id  System
/dev/mmcblk0p1   *        2048      104447       51200    c  W95 FAT32 (LBA)
/dev/mmcblk0p2          104448    31275007    15585280   83  Linux

Command (m for help): quit
[root@raspi ~]# 

Now the partition is larger, but the root file system has still the old size. Re-size the root filesystem:

[root@raspi ~]# resize2fs /dev/mmcblk0p2 
resize2fs 1.42.3 (14-May-2012)
Filesystem at /dev/mmcblk0p2 is mounted on /; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 1
The filesystem on /dev/mmcblk0p2 is now 3896320 blocks long.

[root@raspi ~]

The root file system is now extended.
Then check the file system for errors:

[root@raspi ~]# e2fsck -f /dev/mmcblk0p2
e2fsck 1.42.3 (14-May-2012)
/dev/mmcblk0p2 is mounted.  


WARNING!!!  The filesystem is mounted.   If you continue you ***WILL***
cause ***SEVERE*** filesystem damage.


Do you really want to continue<n>? yes
rootfs: recovering journal
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
Free blocks count wrong (3453563, counted=3453559).
Fix<y>? yes

rootfs: ***** FILE SYSTEM WAS MODIFIED *****
rootfs: ***** REBOOT LINUX *****
rootfs: 63775/952000 files (0.1% non-contiguous), 442761/3896320 blocks
[root@raspi ~]# 

The file system is free of errors.
Finaly check the file systems size and the available space:

[root@raspi ~]# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/root        15G  1.5G   13G  11% /
/dev/mmcblk0p1   50M   18M   33M  35% /boot
[root@raspi ~]#

It has lots of free space available and it is ready to use.

Advertisements
Categories: Linux Tags: ,

Coffee Waves

December 30, 2016 Leave a comment

First Wave ~1960’s

Coffee grew among the masses and the general consumer was able to easily access coffee daily at home or at the office.

Instant coffee, like those from Folgers, Maxwell and Nestle became popular.

Taste of First Wave coffee was weak and had lots of acidity. It was quantity over quality so folks had to put ton of cream and sugar in their coffee to make up for the taste.

First Wave = Coffee to consume

Second Wave ~ Late 1960’s

Starbucks brought higher quality coffees and espresso based drinks to the masses.

People started learning about coffee beans and how it’s brewed (French Press etc.)

Second Wave = Coffee to enjoy

Third Wave ~ 1990’s

Coffee drinkers became interested in the character of the coffee itself: where it’s from, how it’s created, who trades it, who roasts it and how it’s brewed.

Adding to espresso drinks, hand drip coffees (with carefully chosen tools) became very popular during the Third Wave.

High quality beans aka Specialty coffees and light roasts are distinctive features of the Third Wave. People started enjoying coffee like a wine or craft beer.

Third Wave = Coffee to appreciate

So what’s the Fourth Wave going to be??

Categories: coffee Tags: , ,

RANCID for interfaces err-disable

December 30, 2016 Leave a comment

*This script is for RANCID only.

  1. Edit the file /usr/local/rancid/bin/rancid
  2. Add the following line
     	{'show variables boot'		=> 'ShowBoot'},
     	{'show flash'			=> 'ShowFlash'},
     	{'show cdp neighbors detail'	=> 'ShowCDPNeighborsDetail'},
    +	{'show interfaces status err-disabled'	=> 'ShowStatErrDis'},
     	{'dir /all nvram:'		=> 'DirSlotN'},
     	{'dir /all bootflash:'		=> 'DirSlotN'},
     	{'dir /all slot0:'		=> 'DirSlotN'},
  3. Add the sub routine
    # A test routine for parsing the output of "show interfaces status err-disabled"
    +sub ShowStatErrDis {
    +    print STDERR "    In ShowStatErrDis: $_" if ($debug);	
    +
    +    while (<INPUT>) {
    +        tr/\015//d;
    +        last if (/^$prompt/);
    +        next if (/^(\s*|\s*$cmd\s*)$/);
    +        return(1) if /^\s*\^\s*$/;
    +        return(1) if /Line has invalid autocommand /;
    +        return(1) if /(Invalid input detected|Type help or )/;
    +        return(-1) if (/command authorization failed/i);
    +        # the pager can not be disabled per-session on the PIX
    +        if (/^(<-+ More -+>)/) {
    +            my($len) = length($1);
    +            s/^$1\s{$len}//;
    +        }
    +        ProcessHistory("COMMENTS","keysort","IO","!SISED: $_");
    +    }
    +    ProcessHistory("COMMENTS","keysort","IO","!\n");
    +    return(0);
    +}

Cisco 2960 enable routing

November 14, 2014 Leave a comment

1) Enable SDM routing.

Switch(config)#sdm prefer lanbase-routing

2) Save config & reload.
3) Enable IP routing

Switch(config)#ip routing

Categories: Cisco, Switch Tags: ,

Cisco Catalyst Password Reset

October 23, 2014 Leave a comment

In the event that you forgot any remote login password, there is no way to recover the password but there is away to change the password and retail all the configuration.

1) Put the switch in ROMmon state.
2) Initialize the switch with command flash_init
3) Rename the flash:config.text file to flash:config.text.renamed
4) Boot the switch.
5) After rebooting, the switch is back to factory setting, copy the renamed config file to the running config.
6) Amend the remote password, save and reload.

Categories: Cisco, Switch Tags: , ,

RANCID for mass configuration changes

April 21, 2014 Leave a comment

*This script is for RANCID only.

1) mkdir device-lists in rancid homedir.
2) create a file with list of devices (one per line), save the file as syslog-changes.dl into device-lists folder.
3) mkdir change-scripts in rancid homedir.
4) create a file with the changes (as the way you type them in switches), save the file as syslog-changes.cs into change-scripts folder.
5) create a file config-push.sh and save it into etc folder under rancid homedir.
6) copy and paste the following scripts into the file config-push.sh that you had created on step 5.
7) command to test the script, sh config-push.sh

#!/usr/local/bin/bash
#
# The purpose of this script is to automate configuration changes to a
# large number of devices. The script identifies the device list, as well
# as the change script, and then pushes the changes one by one.
#

CLOGINPATH=”/usr/local/rancid/bin/clogin” 
CREDENTIALS=”/usr/local/rancid/.cloginrc” 
DEVICELISTPATH=”/usr/local/rancid/device-lists/” 
CHANGESCRIPTPATH=”/usr/local/rancid/change-scripts/” 
CHANGELOG=”/usr/local/rancid/var/logs/changelog-`date +%m-%d-%Y`.log” 

clear 
echo “=====[ Rancid Config Push Script ]=====” 
echo “” 
echo “Please enter the proposed device list:” 
echo “`ls $DEVICELISTPATH`” 
echo “————————————–” 
echo -n “> ” 
read DEVICELIST 

if [ -f $DEVICELISTPATH$DEVICELIST ] 
then 
echo “” 
echo “Device List = \”./device-lists/$DEVICELIST\” (confirmed)” 
else 
echo “” 
echo “Device list = \”./device-lists/$DEVICELIST\” (does not exist!)” 
echo “Aborting…” 
echo “” 
exit 
fi 

echo “” 
echo “Please enter name of change script:” 
echo “`ls $CHANGESCRIPTPATH | grep -v “.sh” | grep -v “device-lists”`” 
echo “———————————–” 
echo -n “> ” 
read CHANGESCRIPT 

if [ -f $CHANGESCRIPTPATH$CHANGESCRIPT ] 
then 
echo “” 
echo “Change Script = \”./change-scripts/$CHANGESCRIPT\” (confirmed)” 
echo “” 
else 
echo “Device list = \”./change-scripts/$CHANGESCRIPT\” (does not exist!)” 
echo “Aborting…” 
echo “” 
exit 
fi 

echo “– Proposed Changes –” 
echo “`cat $CHANGESCRIPTPATH$CHANGESCRIPT`” 
echo “– Proposed Changes –” 
echo “” 
echo “Are you sure you want to proceed? If so, type \”yes\”:” 
echo -n “> ” 
read AREYOUSURE 

if [ $AREYOUSURE != “yes” ] 
then 
echo “” 
echo “Aborting…” 
echo “” 
exit 
else 
echo “” 
echo “Implementing Changes…” 
echo “” 
fi 

#for i in `cat $DEVICELISTPATH$DEVICELIST` 
# do echo “===[ $i ]===”
# $CLOGINPATH -f $CREDENTIALS -x $CHANGESCRIPTPATH$CHANGESCRIPT $i
#done 

for DEVICE in `cat $DEVICELISTPATH$DEVICELIST` 
do 
echo “===[ $DEVICE ]===” 
echo “” >> $CHANGELOG 
echo “===[ $DEVICE ]===” >> $CHANGELOG 
echo “” >> $CHANGELOG 
OUTPUT=`$CLOGINPATH -f $CREDENTIALS -x $CHANGESCRIPTPATH$CHANGESCRIPT $DEVICE` 
echo “$OUTPUT” >> $CHANGELOG 
done 

Categories: Cisco, Linux, Switch Tags: , ,

Cisco switch test cable distance

March 4, 2014 Leave a comment

Command to test cable length that is connected to Cisco switch.

Cisco-Switch# test cable-diagnostics tdr interface [interface-number]
Cisco-Switch# show cable-diagnostics tdr interface [interface-number]

The command above not only shows connected device to the switch port, it also calculate open end cable that is connected to switch port.

Categories: Cisco, Switch Tags: , , ,