Showing posts with label linux. Show all posts
Showing posts with label linux. Show all posts

Monday, January 4, 2016

How to add a new hard drive with LVM


Let's assume you want to add a new disk (physical or virtual) in your Linux
system, so you will surely have to shutdown your system, add the desired hard
drive and and then boot the system.
After that you are 6 step away from adding your new hard drive.

1. Listing hard disk drives

Here for instance I have added a new 2GiB hard drive, naturally now the second (new)
hard drive on my system is named /dev/sdb, so let's show all disk present in the system :

# fdisk -l
Disk /dev/sdb: 2 GiB, 2147483648 bytes, 4194304 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/sda: 8 GiB, 8589934592 bytes, 16777216 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 Disklabel type: dos Disk identifier: 0x0003e22d Device     Boot Start      End  Sectors Size Id Type /dev/sda1  *     2048 16777215 16775168   8G 8e Linux LVM Disk /dev/mapper/system-swap: 2 GiB, 2147483648 bytes, 4194304 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/system-root: 6 GiB, 6434062336 bytes, 12566528 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

2. Creating a new partition

So now we will create a new partition that will take the entire hard drive and
labeled it as a LVM partition with fdisk:
# fdisk /dev/sdb Welcome to fdisk (util-linux 2.25). 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. Created a new DOS disklabel with disk identifier 0xa86da927. Command (m for help): p Disk /dev/sdb: 2 GiB, 2147483648 bytes, 4194304 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 Disklabel type: dos Disk identifier: 0xa86da927 Command (m for help): n Partition type
   p   primary (0 primary, 0 extended, 4 free)    e   extended (container for logical partitions) Select (default p): p Partition number (1-4, default 1): First sector (2048-4194303, default 2048): Last sector, +sectors or +size{K,M,G,T,P} (2048-4194303, default 4194303): Created a new partition 1 of type 'Linux' and of size 2 GiB. Command (m for help): p Disk /dev/sdb: 2 GiB, 2147483648 bytes, 4194304 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 Disklabel type: dos Disk identifier: 0xa86da927 Device     Boot Start     End Sectors Size Id Type /dev/sdb1        2048 4194303 4192256   2G 83 Linux Command (m for help): t Selected partition 1 Hex code (type L to list all codes): 8e Changed type of partition 'Linux' to 'Linux LVM'.
Command (m for help): w The partition table has been altered. Calling ioctl() to re-read partition table. Syncing disks.

3. Format your new partition
Format your new partition with the desired File System, here I will use ext4:
# mkfs.ext4 /dev/sdb1

4. Listing the LVM layout
So now let's add our new partition to our existing LVM layout: But first let's show the existing LVM layout :
# pvs   PV         VG     Fmt  Attr PSize PFree   /dev/sda1  system lvm2 a--  8.00g 4.00m
# vgs   VG     #PV #LV #SN Attr   VSize VFree   system   1   2   0 wz--n- 8.00g 4.00m
# lvs   LV   VG     Attr      LSize Pool Origin Data%  Move Log Cpy%Sync Convert   root system -wi-ao--- 5.99g   swap system -wi-ao--- 2.00g

5. Adding the new partition to LVM

Initialize the partition for use by LVM :
# pvcreate /dev/sdb1   Physical volume "/dev/sdb1" successfully created

Add the new partition to the existing "system" Volume Group:
# vgextend system /dev/sdb1   Volume group "system" successfully extended

for adding all free space to Logical Volume "root"
# lvextend -l +100%FREE /dev/system/root   Extending logical volume root to 7.99 GiB   Logical volume root successfully resized

or for extending the logical volume to a specific amount (replace x by the desired amount of GiB)
# lvextend -L xG /dev/system/root

for adding one more GiB to the logical volume
lvextend -L+1G /dev/system/root

6. Resizing the Filesystem
For ext Filesystems:
# resize2fs /dev/system/root

For btrfs File System: Please note that btrfs has the built-in ability to add new hard drive to a mounted filesystem. Thus for performance optimization you could use btrfs without the LVM layer. So adding a btrfs filesystem to LVM is still doable as below.
# btrfs filesystem show Label: none  uuid: 71e5c18b-ed4b-475a-9669-b2ee31769351     Total devices 1 FS bytes used 4.67GiB     devid    1 size 5.99GiB used 5.99GiB path /dev/mapper/system-root   Btrfs v3.18.2+20150430

Where 1 is the devid number, you can specify an amount but "max" also possible and this will use all remaining free space on the device.
# btrfs filesystem resize devid:amount /mount-point

# btrfs filesystem resize 1:max /   Resize '/' of '1:max'

# btrfs filesystem show   Label: none  uuid: 71e5c18b-ed4b-475a-9669-b2ee31769351       Total devices 1 FS bytes used 4.67GiB       devid    1 size 7.99GiB used 5.99GiB path /dev/mapper/system-root   Btrfs v3.18.2+20150430

Thursday, May 21, 2015

X Forwarding issue with Mac OS X

If you try to remote access a Linux application from your Mac, you will certainly face the following issue : Forwarded X application window will be limited to the two thirds of your screen.
So you won't be able to drag the window out of the two thirds of the screen.

The issue has been reported here https://xquartz.macosforge.org/trac/ticket/2116, the workaround is to disable the "Displays have separate Spaces" option in Mission Control Preferences on your Mac.

Wednesday, March 18, 2015

Installing Virtualbox Guest Additions on SUSE Linux Enterprise Server 12 and 15

 This article is not a complete and detailed how to, but will covered the subtlety of installing and using the Virtualbox Guest Additions (or Virtualbox Tools) on SUSE Linux Enterprise Server 12 SPX and SUSE Linux Enterprise Server 15 SPX.

Requirement:
Packages : gcc make kernel-default-devel
And of course you need to add the CD image of the Virtualbox Guest Additions in your SLES Virtual Machine :
Devices -> Insert Guest Additions CD image

Step :
1) Mount the cd image:
# mount /dev/sr0 /mnt


2) Install the package requirement:
# zypper in gcc kernel-default-devel

3) Enable "unsupported modules" to be loaded in the SLES's kernel:
Edit /etc/modprobe.d/10-unsupported-modules.conf
and set: allow_unsupported_modules 1
 
4) Run the Virtualbox Guest Additions installation script:
# cd /mnt
# ./VBoxLinuxAdditions.run
Verifying archive integrity... All good.
Uncompressing VirtualBox 5.0.14 Guest Additions for Linux............
VirtualBox Guest Additions installer
Copying additional installer modules ...
Installing additional modules ...
Removing existing VirtualBox non-DKMS kernel modules                  done
Building the VirtualBox Guest Additions kernel modules
Building the main Guest Additions module                              done
Building the shared folder support module                             done
Building the OpenGL support module                                    done
Doing non-kernel setup of the Guest Additions                         done
You should restart your guest to make sure the new modules are actually used

Installing the Window System drivers
Installing X.Org Server 1.15 modules                                  done
Setting up the Window System to use the Guest Additions               done
You may need to restart the hal service and the Window System (or just restart
the guest system) to enable the Guest Additions.

Installing graphics libraries and desktop services components         done

5) You can now reboot your system and check the if the new modules are used:
# reboot
and then after the reboot: 
# lsmod | grep vbox vboxsf                 47920  0 vboxvideo              12669  1 drm                   322623  2 vboxvideo vboxguest             298126  3 vboxsf

6) VoilĂ  !

Tuesday, December 2, 2014

Cleaning /tmp on openSUSE 13.2

In the past openSUSE used an automated task to clean the content of /tmp. Long story short even before systemd arrival, a group of users complains about it on the openSUSE mailinglist, so the automated task (a cron job) for cleaning /tmp as been disabled.
Now that we used systemd by default on openSUSE, it has also been decided to disable this task in the systemd configuration.

So since you can have a /tmp greater than 1G in size with file older than 1 years, here is my simple solution :  install tmpwatch.

tmpwatch is a simple package, which install the following daily cron job :

cat /etc/cron.daily/tmpwatch
#! /bin/sh
flags=-umc
/usr/sbin/tmpwatch "$flags" -x /tmp/.X11-unix -x /tmp/.XIM-unix \
        -x /tmp/.font-unix -x /tmp/.ICE-unix -x /tmp/.Test-unix 10d /tmp
/usr/sbin/tmpwatch "$flags" 30d /var/tmp
for d in /var/{cache/man,catman}/{cat?,X11R6/cat?,local/cat?}; do
    if [ -d "$d" ]; then
        /usr/sbin/tmpwatch "$flags" -f 30d "$d"
    fi
done

And here we go, tmpwatch will  recursively removes files which haven't been accessed for 10 days in /tmp and 30 days in /var/tmp.

Tuesday, April 8, 2014

egrep tips : only matching

In a file SLES11SP3.html which each line look like this  : 
<img src="sles11SP3_files/unknown.gif" alt="[   ]"> <a href="https://suse/sle-11-x86_64/rpm/x86_64/3ddiag-0.742-32.25.x86_64.rpm">3ddiag-0.742-32.25.x86_64.rpm</a>                                           23-Feb-2009 12:53   18K  <img src="sles11SP3_files/unknown.gif" alt="[   ]"> <a href="https://suse/sle-11-x86_64/rpm/x86_64/ConsoleKit-0.2.10-64.65.1.x86_64.rpm">ConsoleKit-0.2.10-64.65.1.x86_64.rpm</a>                                    27-May-2011 03:49   79K  <img src="sles11SP3_files/unknown.gif" alt="[   ]"> <a href="https://suse/sle-11-x86_64/rpm/x86_64/ConsoleKit-32bit-0.2.10-64.65.1.x86_64.rpm">ConsoleKit-32bit-0.2.10-64.65.1.x86_64.rpm</a>                              27-May-2011 03:49   15K  <img src="sles11SP3_files/unknown.gif" alt="[   ]"> <a href="https://suse/sle-11-x86_64/rpm/x86_64/ConsoleKit-doc-0.2.10-64.13.6.x86_64.rpm">ConsoleKit-doc-0.2.10-64.13.6.x86_64.rpm</a>                                11-May-2010 17:08   18K  <img src="sles11SP3_files/unknown.gif" alt="[   ]"> <a href="https://suse/sle-11-x86_64/rpm/x86_64/ConsoleKit-x11-0.2.10-64.65.1.x86_64.rpm">ConsoleKit-x11-0.2.10-64.65.1.x86_64.rpm</a>

And I want to match only the rpm name, and have the following output :
3ddiag-0.742-32.25.x86_64.rpm ConsoleKit-0.2.10-64.65.1.x86_64.rpm ConsoleKit-32bit-0.2.10-64.65.1.x86_64.rpm ConsoleKit-doc-0.2.10-64.13.6.x86_64.rpm ConsoleKit-x11-0.2.10-64.65.1.x86_64.rpm

It's easy with egrep :
# egrep -o ">\w.*\.rpm" SLES11SP3SAP.html

Let's explain the options used in this command line,
So from the man page of egrep :
-o, --only-matching
              Print only the matched (non-empty) parts of a matching line, with each such part on a separate output line.

">\w.*\.rpm" will match the part in bold :
<img src="sles11SP3_files/unknown.gif" alt="[   ]"> <a href="https://suse/sle-11-x86_64/rpm/x86_64/ConsoleKit-x11-0.2.10-64.65.1.x86_64.rpm">ConsoleKit-x11-0.2.10-64.65.1.x86_64.rpm</a>

Tuesday, February 11, 2014

Installing Aurora/Nightly version of Firefox on openSUSE

- First be sure to get the correct architecture version of Aurora/Nightly for your current Linux system architecture.

You will find the Linux 32 and 64 bits version of Aurora here : http://www.mozilla.org/en-US/firefox/aurora/all/
And Nightly here :
http://nightly.mozilla.org/

- Then uncompress the archive in /opt/aurora or /opt/nightly :
mkdir /opt/aurora && tar -xjvf firefox-29.0a2.en-US.linux-x86_64.tar.bz2 -C /opt/aurora

- Now you can execute your "developer's version" of Firefox with :
/opt/aurora/firefox &

You might experience the following plugin error :
No plugin found or Install Flashplayer : file not found

To resolve this issue you have to do the following on a 64 bits system :
ln -s /usr/lib64/browser-plugins/ /home/USER/.mozilla/plugins

Monday, January 27, 2014

What's the installation date of my Linux system ?

Well there is no "standard way" to know the installation date of you Linux system, so you could use one of these command :
- The idea is to retrieve the creation date of your root filesystem or /boot :
# sudo dumpe2fs -h /dev/mapper/VolGrp00-LogVol00 | grep "Filesystem created:" or # sudo dumpe2fs -h /dev/sda3 | grep "Filesystem created:" Filesystem created:       Mon Oct 29 11:44:51 2012

- Or by showing the oldest package installation date :
# sudo rpm -qa --last | tail -1                  
gpg-pubkey-307e3d54-4be01a65                  Mon 29 Oct 2012 11:45:27 AM CET

- Or the password information of your current user :
# sudo passwd -S user | tail -1 | awk '{print $3}'
10/29/2012

- And finally the creation date of the oldest configuration file/folder :
# ls -lct /etc | tail -1 | awk '{print $6, $7, $8}'
Oct 29 2012

Monday, November 18, 2013

Activate/Deactivate wifi on openSUSE asks for administrator password

I was very annoyed by the behavior of Network Manager in openSUSE 12. Every time I want to enable/disable the wifi and want to automatically connect to my prefered wifi spot, the system asks for the administrator password...

This can be changed by editing the file /etc/polkit-default-privs.local and add :

org.freedesktop.NetworkManager.enable-disable-wifi            yes

then run the command :
# set_polkit_default_privs 

So now current logged user can enable or disable the wifi connection without the administrator password... Enjoy.

Wednesday, November 13, 2013

VIM tips

Vim in read-only mode : view

Did you know that vim has a read-only mode ?
Just use :
# view myfile.txt

Searching for the current word :

In normal mode, move the cursor to any word. Press * to search forwards for the next occurrence of that word, or press # to search backwards.

 Delete "empty" lines : 

Sometime you can be annoyed by "empty" lines which contains no character in your file, to delete them you can use :
:g/^$/d

:g will execute a command on lines which match a regex. The regex is "empty line"  (start with nothing and end with nothing) and the command is :d for delete

Delete "blank" lines : 

Beside "empty" line, you might want to delete lines which contains only whitespaces characters (spaces/tabs) in your file :
:g/^\s*$/d

Visual block editing :

Activate the visual block mode :
CTRL+v
Insert Mode before every line of the block :
SHIFT+i
Apply the insert :
ESC

Wednesday, November 6, 2013

Process tracking on Linux

Some useful tricks to track a process running in your Linux system.

How to track in real time a specific process by his name :

The top command is very useful to see what's going on in your system, but sometimes there is too much processes monitored, so here is a trick to show only "procname1" and "procname2" in top :

# top -p $(pgrep procname1 | xargs echo | sed -e 's/ /, /g') -p $(pgrep procname2 | xargs echo | sed -e 's/ /, /g')

Example with :
# top -p $(pgrep httpd | xargs echo | sed -e 's/ /, /g') -p $(pgrep nfs| xargs echo | sed -e 's/ /, /g')


How to track any processes waiting for disk I/O :  

# watch -n 1 "(ps aux | awk '\$8 ~ /D/ { print \$0 }')"

Example :



How to find out which processes are swapping  :  

# for i in /proc/*/status ; do awk '/VmSwap|Name/{printf $2 " " $3}END{ print ""}' $i; done | sort -k 2 -n -r | less

Example :