Too often I figure out how to do this or that on Linux systems and in my haste to complete whatever task I've been assigned this "How To" knowledge gets lost. So here, I will begin posting little odds and ends in hopes of not needing to re-research past efforts for Linux tips, tricks, hacks, and other good to know things. If you find yourself here and know of smaller, faster, better ways of doing any of this please let me know - only through cooperation can we all get better.
Monday, August 25, 2014
Updating the default system editor - Debian
Friday, August 8, 2014
Resize Logical Volumes within a Volume Group (LVM2 on Debian 7)
OK, I needed room on `/` to accommodate mongoDB journaling files. I have debian 7 (Wheezy) running in a virtual machine with a separate /home partition.
To get the space I needed I planned to take 5Gb from /home and add it to /.
So, as root, show me my Physical Volume:
root@rev0:~# pvdisplayShow me my Logical Volumes at a high level using lvs:
--- Physical volume ---
PV Name /dev/sda5
VG Name rev0
PV Size 89.76 GiB / not usable 2.00 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 22978
Free PE 0
Allocated PE 22978
PV UUID KBuU17-GOD4-8ckZ-EaJG-aurI-9ufl-oeUCNy
root@rev0:~# lvsReduce the size of my /home LV using lvreduce (-5G = reduce by 5Gb):
LV VG Attr LSize Pool Origin Data% Move Log Copy% Convert
home rev0 -wi-ao-- 77.19g
root rev0 -wi-ao-- 4.31g
swap_1 rev0 -wi-ao-- 3.25g
NOTE: the LV path (/dev/rev0/home) can be found with the lvdisplay command which is illustrated below.)
root@rev0:~# lvreduce -L-5G /dev/rev0/homeNow add the newly available disk to root (/) using lvextend (conversely +5G here means grow by 5Gb):
WARNING: Reducing active and open logical volume to 72.19 GiB
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce home? [y/n]: y
Reducing logical volume home to 72.19 GiB
Logical volume home successfully resized
root@rev0:~# lvextend -L+5G /dev/rev0/rootGOTCHA! Now here's what got me the first go round, the LV has now increased in size but the file system there remains at it's previous size. So we need to grow the file system to fit the LV using resize2fs:
Extending logical volume root to 14.31 GiB
Logical volume root successfully resized
root@rev0:~# resize2fs /dev/rev0/rootAnd when this is all done we can see the 5Gb shift from home to root:
resize2fs 1.42.5 (29-Jul-2012)
Filesystem at /dev/rev0/root is mounted on /; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 1
Performing an on-line resize of /dev/rev0/root to 3751936 (4k) blocks.
The filesystem on /dev/rev0/root is now 3751936 blocks long.
root@rev0:~# lvsOr the more verbose:
LV VG Attr LSize Pool Origin Data% Move Log Copy% Convert
home rev0 -wi-ao-- 72.19g
root rev0 -wi-ao-- 14.31g
swap_1 rev0 -wi-ao-- 3.25g
root@rev0:~# lvdisplay
--- Logical volume ---
LV Path /dev/rev0/root
LV Name root
VG Name rev0
LV UUID PA6izC-GU9D-eG9C-Ji9v-8avn-u7ng-dsLlPc
LV Write Access read/write
LV Creation host, time rev0, 2014-08-07 07:40:00 -0500
LV Status available
# open 1
LV Size 14.31 GiB
Current LE 3664
Segments 2
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 254:0
--- Logical volume ---
LV Path /dev/rev0/swap_1
***Swap omitted here***
--- Logical volume ---
LV Path /dev/rev0/home
LV Name home
VG Name rev0
LV UUID 0omdas-WNXb-17Sc-cfpZ-gRV0-i2G5-tHPV7L
LV Write Access read/write
LV Creation host, time rev0, 2014-08-07 07:40:00 -0500
LV Status available
# open 1
LV Size 72.19 GiB
Current LE 18481
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 254:2
And now I have sufficient space on root for my journaling files. Again, this was done fast and in a pinch, but it got the job done and may help others in a similar circumstance...
This should work for all flavors of *nix set up with LVM2.
FIN
Change Directory and list contents in single command.
Using an editor of your choosing open your .bashrc or .bash_profile and add the following lines:
# User defined functionsNote: In the above I have aliased `ll` as -> alias ll='ls -ASlh'
function cdl { cd $1 && echo $PWD && ll; }
Note: You can name this whatever you choose, I just think `cdl` made sense.
Note: You can omit the echo $PWD if you don't care to see the directory path in the output. So you could do something as simple as:
# User defined functionsSave and close and then
function cdl { cd $1 && ls; }
bkarels@rev0:~$ source ~/.bashrcNow you can use cdl (or whatever you've named it to change directory and immediately ls the contents.
Example:
bkarels@rev0:~$ cdl foo/
/home/bkarels/fooThe above example was done on Debian 7 (Wheezy) but should work on all flavors of *nix and OSX.
total 328K
-rw------- 1 bkarels bkarels 156K Aug 8 09:39 sample0
-rw------- 1 bkarels bkarels 6.9K Aug 8 08:47 someFile27
-rw-r--r-- 1 bkarels bkarels 4.1K Aug 7 12:07 sayWhat
drwx------ 6 bkarels bkarels 4.0K Aug 8 07:37 killWindows.exe
FIN
Tuesday, April 1, 2014
Quick & Dirty Add User to SUDOERs (*nix)
[myuser@machine ~]$ su -
Password:
[root@machine ~]# visudo
This will open your sudoers file for editing. visudo will protect you from some, but not nearly all mistakes. So, for this quick dirty example search for the following section:
## Allow root to run any commands anywhereThen, add the following directly below it:
root ALL=(ALL) ALL
myuser ALL=(ALL) ALLThe end result should look like:
## Allow root to run any commands anywhereNOTE: The above is separated by TABS so you would type it as follows:
root ALL=(ALL) ALL
myuser ALL=(ALL) ALL
myuser[TAB]ALL=(ALL)[TAB]ALL
Save & close (:wq)
[root@machine ~]# exit
[myuser@machine ~]$ sudo someCommand
FIN
Wednesday, March 5, 2014
Connect to SMB share with terminal - Fedora20
The non-gui way to connect to your SMB share. There is likely 1000 small variations of how to do this, but this is a very simple method to get you on to the path to bigger, better, cooler...
From a terminal:
[user@localhost user] $ cd /mnt
[user@localhost mnt] $ sudo mkdir shareExample
[user@localhost mnt] $ sudo mount -o username=user //theShareLocation/shareName /mnt/shareExample/
You will likely be prompted for your passwd...
[user@localhost mnt] $ cd /mnt/shareExample
[user@localhost shareExample] $ look around, do stuff...
NOTE: If you're accessing a SMB share on windows you will like need to connect using:
[user@localhost mnt]$ sudo mount -t smbfs -o username=username //theShareLocation/shareName /mnt/shareExample/
...and when you're done:
[user@localhost mnt]$ sudo umount /mnt/shareExample
This should work on all flavors of *nix, done here on Fedora20 as that is what I'm using at the moment.
FIN