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

Sunday, June 16, 2019

fstab and UUID for device identification, docker and friends

https://help.ubuntu.com/community/Fstab

on my VirtualBox Centos7:

cat /etc/fstab

/dev/mapper/cl-root / xfs defaults 0 0
UUID=70139d85-209e-4997-9d06-af6659221021 /boot xfs defaults 0 0
/dev/mapper/cl-swap swap swap defaults 0 0

this is:
[Device] [Mount Point] [File System Type] [Options] [Dump] [Pass]


ls -l /dev/disk/by-uuid/
total 0
lrwxrwxrwx. 1 root root 9 Jun 14 17:41 2019-05-13-13-58-35-65 -> ../../sr0
lrwxrwxrwx. 1 root root 10 Jun 14 17:41 27882150-dbcf-44a5-8461-a7e16020ee6f -> ../../dm-1
lrwxrwxrwx. 1 root root 10 Jun 14 17:41 70139d85-209e-4997-9d06-af6659221021 -> ../../sda1
lrwxrwxrwx. 1 root root 10 Jun 14 17:41 96e9a0f9-2b77-4cfc-be6e-f4c982e57123 -> ../../dm-0
lrwxrwxrwx. 1 root root 10 Jun 15 19:08 fdad3ac1-1c70-4371-8f9e-72ab7f0167df -> ../../dm-3


blkid
/dev/sr0: UUID="2019-05-13-13-58-35-65" LABEL="VBox_GAs_6.0.8" TYPE="iso9660"


on the host VM:

mount | sort

cgroup on /sys/fs/cgroup/blkio type cgroup (rw,nosuid,nodev,noexec,relatime,blkio)
cgroup on /sys/fs/cgroup/cpu,cpuacct type cgroup (rw,nosuid,nodev,noexec,relatime,cpuacct,cpu)
cgroup on /sys/fs/cgroup/cpuset type cgroup (rw,nosuid,nodev,noexec,relatime,cpuset)
cgroup on /sys/fs/cgroup/devices type cgroup (rw,nosuid,nodev,noexec,relatime,devices)
cgroup on /sys/fs/cgroup/freezer type cgroup (rw,nosuid,nodev,noexec,relatime,freezer)
cgroup on /sys/fs/cgroup/hugetlb type cgroup (rw,nosuid,nodev,noexec,relatime,hugetlb)
cgroup on /sys/fs/cgroup/memory type cgroup (rw,nosuid,nodev,noexec,relatime,memory)
cgroup on /sys/fs/cgroup/net_cls,net_prio type cgroup (rw,nosuid,nodev,noexec,relatime,net_prio,net_cls)
cgroup on /sys/fs/cgroup/perf_event type cgroup (rw,nosuid,nodev,noexec,relatime,perf_event)
cgroup on /sys/fs/cgroup/pids type cgroup (rw,nosuid,nodev,noexec,relatime,pids)
cgroup on /sys/fs/cgroup/systemd type cgroup (rw,nosuid,nodev,noexec,relatime,xattr,release_agent=/usr/lib/systemd/systemd-cgroups-agent,name=systemd)
configfs on /sys/kernel/config type configfs (rw,relatime)
debugfs on /sys/kernel/debug type debugfs (rw,relatime)
/dev/mapper/cl-root on / type xfs (rw,relatime,seclabel,attr2,inode64,noquota)
/dev/mapper/docker-253:0-34242903-3869b9e3d61005155d7ce7222280b67d4c034537b462d76016409d74c39c403b on /var/lib/docker/devicemapper/mnt/3869b9e3d61005155d7ce7222280b67d4c034537b462d76016409d74c39c403b type xfs (rw,relatime,seclabel,nouuid,attr2,inode64,logbsize=64k,sunit=128,swidth=128,noquota)
devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,seclabel,gid=5,mode=620,ptmxmode=000)
/dev/sda1 on /boot type xfs (rw,relatime,seclabel,attr2,inode64,noquota)
/dev/sr0 on /run/media/centos/VBox_GAs_6.0.8 type iso9660 (ro,nosuid,nodev,relatime,uid=1000,gid=1000,iocharset=utf8,mode=0400,dmode=0500,uhelper=udisks2)
devtmpfs on /dev type devtmpfs (rw,nosuid,seclabel,size=3989408k,nr_inodes=997352,mode=755)
fusectl on /sys/fs/fuse/connections type fusectl (rw,relatime)
gvfsd-fuse on /run/user/1000/gvfs type fuse.gvfsd-fuse (rw,nosuid,nodev,relatime,user_id=1000,group_id=1000)
hugetlbfs on /dev/hugepages type hugetlbfs (rw,relatime,seclabel)
mqueue on /dev/mqueue type mqueue (rw,relatime,seclabel)
nfsd on /proc/fs/nfsd type nfsd (rw,relatime)
proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
proc on /run/docker/netns/9c46943f17e7 type proc (rw,nosuid,nodev,noexec,relatime)
pstore on /sys/fs/pstore type pstore (rw,nosuid,nodev,noexec,relatime)
securityfs on /sys/kernel/security type securityfs (rw,nosuid,nodev,noexec,relatime)
selinuxfs on /sys/fs/selinux type selinuxfs (rw,relatime)
shm on /var/lib/docker/containers/55284026cd2880cf08c45e66754fcf8011c9cf3227f1564022afad7807cbee27/mounts/shm type tmpfs (rw,nosuid,nodev,noexec,relatime,seclabel,size=65536k)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw,relatime)
sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime,seclabel)
systemd-1 on /proc/sys/fs/binfmt_misc type autofs (rw,relatime,fd=31,pgrp=1,timeout=0,minproto=5,maxproto=5,direct,pipe_ino=13854)
tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev,seclabel)
tmpfs on /run type tmpfs (rw,nosuid,nodev,seclabel,mode=755)
tmpfs on /run/user/1000 type tmpfs (rw,nosuid,nodev,relatime,seclabel,size=801028k,mode=700,uid=1000,gid=1000)
tmpfs on /sys/fs/cgroup type tmpfs (ro,nosuid,nodev,noexec,seclabel,mode=755)


on the docker centos7 container:

mount | sort

/dev/mapper/cl-root on /etc/hostname type xfs (rw,relatime,seclabel,attr2,inode64,noquota)
/dev/mapper/cl-root on /etc/hosts type xfs (rw,relatime,seclabel,attr2,inode64,noquota)
/dev/mapper/cl-root on /etc/resolv.conf type xfs (rw,relatime,seclabel,attr2,inode64,noquota)
/dev/mapper/docker-253:0-34242903-3869b9e3d61005155d7ce7222280b67d4c034537b462d76016409d74c39c403b on / type xfs (rw,relatime,seclabel,nouuid,attr2,inode64,logbsize=64k,sunit=128,swidth=128,noquota)
cgroup on /sys/fs/cgroup/blkio type cgroup (ro,nosuid,nodev,noexec,relatime,blkio)
cgroup on /sys/fs/cgroup/cpu,cpuacct type cgroup (ro,nosuid,nodev,noexec,relatime,cpuacct,cpu)
cgroup on /sys/fs/cgroup/cpuset type cgroup (ro,nosuid,nodev,noexec,relatime,cpuset)
cgroup on /sys/fs/cgroup/devices type cgroup (ro,nosuid,nodev,noexec,relatime,devices)
cgroup on /sys/fs/cgroup/freezer type cgroup (ro,nosuid,nodev,noexec,relatime,freezer)
cgroup on /sys/fs/cgroup/hugetlb type cgroup (ro,nosuid,nodev,noexec,relatime,hugetlb)
cgroup on /sys/fs/cgroup/memory type cgroup (ro,nosuid,nodev,noexec,relatime,memory)
cgroup on /sys/fs/cgroup/net_cls,net_prio type cgroup (ro,nosuid,nodev,noexec,relatime,net_prio,net_cls)
cgroup on /sys/fs/cgroup/perf_event type cgroup (ro,nosuid,nodev,noexec,relatime,perf_event)
cgroup on /sys/fs/cgroup/pids type cgroup (ro,nosuid,nodev,noexec,relatime,pids)
cgroup on /sys/fs/cgroup/systemd type cgroup (ro,nosuid,nodev,noexec,relatime,xattr,release_agent=/usr/lib/systemd/systemd-cgroups-agent,name=systemd)
devpts on /dev/console type devpts (rw,nosuid,noexec,relatime,seclabel,gid=5,mode=620,ptmxmode=666)
devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,seclabel,gid=5,mode=620,ptmxmode=666)
mqueue on /dev/mqueue type mqueue (rw,nosuid,nodev,noexec,relatime,seclabel)
proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
proc on /proc/bus type proc (ro,relatime)
proc on /proc/fs type proc (ro,relatime)
proc on /proc/irq type proc (ro,relatime)
proc on /proc/sys type proc (ro,relatime)
proc on /proc/sysrq-trigger type proc (ro,relatime)
shm on /dev/shm type tmpfs (rw,nosuid,nodev,noexec,relatime,seclabel,size=65536k)
sysfs on /sys type sysfs (ro,nosuid,nodev,noexec,relatime,seclabel)
tmpfs on /dev type tmpfs (rw,nosuid,seclabel,size=65536k,mode=755)
tmpfs on /proc/acpi type tmpfs (ro,relatime,seclabel)
tmpfs on /proc/asound type tmpfs (ro,relatime,seclabel)
tmpfs on /proc/kcore type tmpfs (rw,nosuid,seclabel,size=65536k,mode=755)
tmpfs on /proc/keys type tmpfs (rw,nosuid,seclabel,size=65536k,mode=755)
tmpfs on /proc/sched_debug type tmpfs (rw,nosuid,seclabel,size=65536k,mode=755)
tmpfs on /proc/scsi type tmpfs (ro,relatime,seclabel)
tmpfs on /proc/timer_list type tmpfs (rw,nosuid,seclabel,size=65536k,mode=755)
tmpfs on /proc/timer_stats type tmpfs (rw,nosuid,seclabel,size=65536k,mode=755)
tmpfs on /sys/firmware type tmpfs (ro,relatime,seclabel)
tmpfs on /sys/fs/cgroup type tmpfs (ro,nosuid,nodev,noexec,relatime,seclabel,mode=755)


one can notice lot of differences in the VM and the container mounts, notably all the cgroup in docker are ro while in vm they are rw. Some mounts "/dev/mapper/cl-root on /etc/*" in docker


What is tmpfs? https://en.wikipedia.org/wiki/Tmpfs

What is xfs? https://en.wikipedia.org/wiki/XFS

What is FUSE (fusectl) ? https://en.wikipedia.org/wiki/Filesystem_in_Userspace#Examples






Tuesday, January 2, 2018

Linux misc (iptables, dig, rpm)

echo $LANG
en_US.UTF-8

CTRL-SHIFT-U allows you to enter the 4 letters for a Unicode character (eg 03bb is greek lambda)

localectl

System Locale: LANG=en_US.UTF-8
VC Keymap: it
X11 Layout: it,us
X11 Variant: ,

to change locale:
localectl set-locale LANG=fr_FR.utf8

cat /etc/locale.conf
LANG="en_US.UTF-8"

list all available language packs:
yum langavailable

list installed language packs:
yum langlist


iptables tutorial instructions: https://www.howtogeek.com/177621/the-beginners-guide-to-iptables-the-linux-firewall/

sudo iptables -L -v
sudo iptables -F
sudo cat /etc/sysconfig/iptables


network:
dig
systemctl status firewalld
systemctl status NetworkManager



history: remove line numbers by adding to .bash_profile
HISTTIMEFORMAT="$(echo -e '\r\e[K')"

#rpm list all packages
rpm -qa | grep ansible
#this installs 1.1 without removing 1.0 if exists
rpm -ivh some-package-1.1
#this updates (if existing) 1.0 to 1.1
rpm -Uvh some-package-1.1



Tuesday, December 19, 2017

systemd

Really interesting reading https://en.wikipedia.org/wiki/Systemd


For instance, I didn't know that systemd has PID = 1

ps -ef | grep systemd
root 1 0 0 Dec16 ? 00:10:38 /usr/lib/systemd/systemd --switched-root --system --deserialize 2

and that other daemons like journald, logind and networkd (if running), have parent PID = 1

ps -ef | grep journald
root 499 1 0 Dec16 ? 00:02:41 /usr/lib/systemd/systemd-journald


ps -ef | grep logind
root 727 1 0 Dec16 ? 00:01:00 /usr/lib/systemd/systemd-logind



Wednesday, March 4, 2015

Oracle Unbreakable Linux vs Oracle Enterprise Linux vs Oracle Linux

I was really confused by all these product names... how are they different, and what is what?
It turns out that the reality is much simpler: the "Enterprise" qualifier is no longer used - just say "Oracle Linux" - although in the documentation the term "Oracle Enterprise Linux" is still widely used.
Also, the "Unbreakable" qualifier (honestly, a bit bumptious and uppish) is used only to refer to the KERNEL, and not to the OS itself...
Please refer to the following articles for more details:
http://www.oracle.com/us/technologies/linux/product/specifications/index.html

https://en.wikipedia.org/wiki/Oracle_Linux

http://www.oracle.com/technetwork/server-storage/linux/technologies/uek-overview-2043074.html



Sunday, November 16, 2014

Linux Certification LPIC

Really awesome resource, much better than any other training material seen so far: http://lpic2.unix.nl/index.html

I am considering taking Linux administration certification - there is an amazing amount of tricks I am totally unaware of, much to my shame
More here https://www.lpi.org/linux-certifications/entry-level-credential/linux-essentials

Wednesday, July 30, 2014

setfacl and getfacl in action

I had no clue that in Linux you can grant specific access rights to an individual user on a file/folder, using setfacl:
[root@osb-vagrant opt]# umask
0022
[root@osb-vagrant opt]# cd /opt
[root@osb-vagrant opt]# mkdir pippo
[root@osb-vagrant opt]# ls -ltra
...
drwxr-xr-x   2 root root 4096 Jul 30 11:36 pippo
...
[root@osb-vagrant opt]# getfacl /opt/pippo
# file: pippo
# owner: root
# group: root
user::rwx
group::r-x
other::r-x


Since I have umask 0022, when I create a directory it's as per defaults read only for all other users. For instance, user "soa" can't create a file in /opt/pippo:

[soa@osb-vagrant pippo]$ cd /opt/pippo
[soa@osb-vagrant pippo]$ touch ciao.txt
touch: cannot touch `ciao.txt': Permission denied


But this can be changed!

[root@osb-vagrant opt]# setfacl -m u:soa:rwx /opt/pippo
[root@osb-vagrant opt]# getfacl /opt/pippo
getfacl: Removing leading '/' from absolute path names
# file: opt/pippo
# owner: root
# group: root
user::rwx
user:soa:rwx
group::r-x
mask::rwx
other::r-x


notice here the new element "user:soa:rwx".

At this point, user "soa" can create a file in /opt/pippo ! But no other user can...

See also http://www.computerhope.com/unix/usetfacl.htm for more advanced examples.

In Puppet:

exec {'/usr/bin/setfacl -R -dm u::rwx,g::rwx,o::rwx /zdata/':
      require => Mount["${inbound_messages_path}"],
}





Tuesday, May 13, 2014

Monitoring CPU usage of a WebLogic server over time

you can either use top, where PID is the Managed Server's processid:
top -b -p $PID

or ps:
ps -p $PID  -o %cpu | tail -n +2


Unfortunately collectd doesn't seem to be able to collect CPU usage for a specific user or PID.



Tuesday, November 19, 2013

whoami vs who am i

ok this is like Linux 101:
[root@osb-vagrant ~]# who am i
root     pts/1        2013-11-19 11:01 (10.0.2.2)
[root@osb-vagrant ~]# whoami
root
[root@osb-vagrant ~]# sudo -u soa whoami
soa
[root@osb-vagrant ~]# sudo -u soa who am i
root     pts/1        2013-11-19 11:01 (10.0.2.2)


So if you allow some user to sudo a command, and you want to log who that user is, you should use "who am i" and not "whoami".

Tuesday, October 29, 2013

Deleting a million directories in Linux

This morning a component went ballistic and created more than a million folders under /path/to/myfolder, until the file system was completely full.
this command was showing 100% of Inodes used:
watch df -i /opt/oracle/domains/osbpr1do/shared/apps/fileadapter/controlDir/fileftp/controlFiles
You could delete folder/files in several way, most of them VERY inefficient:
#this takes forever and deletes also the parent folder
rm -rf /path/to/myfolder

#this funnily fails with "file not found", most likely because there are 
#special characters like a equal sign = in the folder name
find /path/to/myfolder -type d -mtime +5 -exec ls -ltr {} \;

#of course I have tried also with quotes, with same result
find /path/to/myfolder -type d -mtime +5 -exec ls -ltr "{}" \;

#I have tried deleting only subsets
rm -rf /opt/oracle/domains/osbpr1do/shared/apps/fileadapter/controlDir/fileftp/controlFiles/a*
#but the problem is that the shell expands the a*, and this can resolve to too many argumnent
#so the command fails


#this is very simple but deletes also 
find /path/to/myfolder/ -type d -delete

then I read this article and I tested this:
rsync -av --delete --remove-source-files /tmp/empty/ /path/to/myfolder/

where /tmp/empty/ is an empty folder, and it works like magic. Reading around it says that this is due to the fact that rsync has a LIFO way of reading file system info, rather than FIFO.

Saturday, October 26, 2013

Linux directory read and execute bits

file pippo.txt is in /vagrant/one/two, and it belongs to root, just like directories one and two.
[root@osb-vagrant vagrant]# ls -Rlt /vagrant
/vagrant:
total 4
drwxr-xr-x 3 root root 4096 Oct 26 08:29 one

/vagrant/one:
total 4
drwxr-x--x 2 root root 4096 Oct 26 08:29 two

/vagrant/one/two:
total 0
-rw-r--r-- 1 root root 0 Oct 26 08:29 pippo.txt


Question: will user vagrant be able to do ls /vagrant/one/two?
Answer: NO
[vagrant@osb-vagrant vagrant]$ ls /vagrant/one/two/
ls: cannot open directory /vagrant/one/two/: Permission denied
Why not? Because the "two" read bit is not set. It is set on "one" however". The "read" bit for a folder means "let me list its content". However, user vagrant can "cat /vagrant/one/two/pippo.txt", because the read bit is set on pippo.txt, and the execute bit is set on "two".
If I remove the execute bit on "two":
chmod 770 /vagrant/one/two
ls -ltr /vagrant/one/two
total 0
-rw-r--r-- 1 root root 0 Oct 26 08:29 pippo.txt

then I even lose the right to view pippo.txt content, although the file itself is readable for vagrant.
[vagrant@osb-vagrant vagrant]$ cat /vagrant/one/two/pippo.txt
cat: /vagrant/one/two/pippo.txt: Permission denied


To recap: execute bit on a folder allows me to "traverse it". read bit on a folder allows me to view its content. This is very un-intuitive and derives from an overloaded use of bits which were originally meant for files. Files and directories are totally different beasts, so they should be modeled differently.

How about deleting files? It's not enough that you have "write" access to the file: you should also have execute access to the folder.

See also these excellent tutorials http://www.hackinglinuxexposed.com/articles/20030417.html http://www.hackinglinuxexposed.com/articles/20030424.html

Wednesday, February 6, 2013

Remote compare directories, diff for Linux: rsync --dry-run

Plenty of examples here:

http://www.thegeekstuff.com/2010/09/rsync-command-examples/

Priceless is the option dry-run:

rsync -v --dry-run /home/soa/obelix/scripts/ /tmp/DELETEME



ls /tmp/TEST01/
pippo2.txt pippo.txt


ls /tmp/TEST02/
pippo2.txt


rsync -avz --dry-run --progress --delete /tmp/TEST02/ /tmp/TEST01/
sending incremental file list
./
deleting pippo.txt
pippo2.txt


rsync -avz --dry-run --progress --delete /tmp/TEST01/ /tmp/TEST02/
sending incremental file list
./
pippo.txt
pippo2.txt


So rsync can be used to detect extra files in one directory by using the --delete option, but you should run it twice.

I find rsync very hard to use and it doesn't really behave as I expect it. Forget it.

Let me look into how to use Beyond Compare with remote Linux directories.

Beyond Compare supports SFTP.


Saturday, May 19, 2012

Troubleshooting a "server down" or a "filesystem full"

Server myserver down:
ping myserver
ssh myuser@myserver


check if Hyperic monitoring agent is running:
ps -eaf|grep agent|grep java|grep -v grep

For a file system full or about to be full:

df –k
cd filesystemName
du 2> /dev/null | sort -nr | cut -f2- | xargs du -hs 2> /dev/null | more

(see http://serverfault.com/questions/62411/how-can-i-sort-du-h-output-by-size)

Saturday, February 18, 2012

vsftpd on Linux RedHat

homepage
https://security.appspot.com/vsftpd.html

download here
https://security.appspot.com/downloads/vsftpd-2.3.5.tar.gz

copied to Linux server
gunzip vsftpd-2.3.5.tar.gz
tar xvf vsftpd-2.3.5.tar
cd vsftpd-2.3.5

/lib/libcap.so.1: could not read symbols: File in wrong format

http://www.andreaswacker.com/blog/2009/01/23/sysdeputilc162-error-expected-declaration-specifiers-or-before-capset/

vi vsf_findlibs.sh


# Look for libcap (capabilities)
#if locate_library /lib/libcap.so.1; then
# echo "/lib/libcap.so.1";
if locate_library /lib/libcap.so.2; then
echo "/lib/libcap.so.2";
else
locate_library /usr/lib/libcap.so && echo "-lcap";
locate_library /lib/libcap.so && echo "-lcap";
locate_library /lib64/libcap.so && echo "-lcap";
fi


I still get

gcc -o vsftpd main.o utility.o prelogin.o ftpcmdio.o postlogin.o privsock.o tunables.o ftpdataio.o secbuf.o ls.o postprivparent.o logging.o str.o netstr.o sysstr.o strlist.o banner.o filestr.o parseconf.o secutil.o ascii.o oneprocess.o twoprocess.o privops.o standalone.o hash.o tcpwrap.o ipaddrparse.o access.o features.o readwrite.o opts.o ssl.o sslslave.o ptracesandbox.o ftppolicy.o sysutil.o sysdeputil.o -Wl,-s `./vsf_findlibs.sh`
/usr/bin/ld: cannot find -lcap
collect2: ld returned 1 exit status
make: *** [vsftpd] Error 1



Ok I give up for now....

Friday, February 10, 2012

Linux file creation and modification date

touch myfile.txt

ls -ltr

-rw-rw-r-- 1 soa soa 0 Feb 10 11:24 myfile.txt

this is the MODIFICATION DATE (which at the beginning is same as creation date)

if you later modify the file, there is no way (in Linux) to retrieve the creation date. You will always get the modification time.

"ls -lact --full-time" will not help

stat myfile.txt will not help

http://bloggerdigest.blogspot.com/2006/10/using-ls-command-by-examples.html gives a good list of ls options

Wednesday, July 20, 2011

How to tell which flavour of Linux I am running

When you telnet, you get it all:

login as: a087
*---------------------------------------*
Host: blahost
Company: ACME
Type: PHYSICAL
Zone: INTRANET
Environment: PRODUCTION
Location: Block

In case of problems, contact
linux@acme.com

*---------------------------------------*
a087@acme.com's password:
Last login: Tue Jul 19 17:20:14 2011 from bla.acme.com
Welcome to blahost.
This system is managed by Puppet 2.6.7.

Running Red Hat Enterprise Linux Server release 5.6 (Tikanga).



also, uname -a tells you a lot:

Linux blahost 2.6.18-238.1.1.el5 #1 SMP Tue Jan 4 13:32:19 EST 2011 x86_64 x86_64 x86_64 GNU/Linux


and in case of RedHat

cat /etc/redhat-release
Red Hat Enterprise Linux Server release 5.6 (Tikanga)

otherwise just do
ls /etc/*release