• Skip to main content

Uly.me

cloud engineer

  • Home
  • About
  • Archives

device

Filter Output of LSBLK

November 20, 2020

Here’s one way to display block devices, mountpoints and size using lsblk.

lsblk -a -p -n -d -e 230 -o NAME,MOUNTPOINT,SIZE

lsblk -a -p -n -d -e 230 -o NAME,MOUNTPOINT,SIZE

Here are the options.

  • -a = list all empty devices
  • -p = print full device paths
  • -d = do not print holder devices or slaves
  • -e = exclude devices as by a comma-separate list
  • -o = specify which columns to print, e.g. NAME,MOUNTPOINT,SIZE

The output.

/dev/sda             30G
/dev/sdb /data       50G

/dev/sda 30G /dev/sdb /data 50G

Here’s the man page.

Filed Under: Linux Tagged With: block, device, list, lsblk

GCP Identify Your Disks

September 16, 2020

Here’s how to identify your disks on the system to cross check with GCP Dashboard.

ls -l /dev/disk/by-id

ls -l /dev/disk/by-id

Result:

[root@servername ~]# ls -l /dev/disk/by-id
total 0
lrwxrwxrwx. 1 root root  9 Sep 15 05:30 google-boot -> ../../sda
lrwxrwxrwx. 1 root root 10 Sep 15 05:30 google-boot-part1 -> ../../sda1
lrwxrwxrwx. 1 root root  9 Sep 15 05:30 google-persistent-disk-1 -> ../../sdb
lrwxrwxrwx. 1 root root  9 Sep 15 05:30 scsi-0Google_PersistentDisk_boot -> ../../sda
lrwxrwxrwx. 1 root root 10 Sep 15 05:30 scsi-0Google_PersistentDisk_boot-part1 -> ../../sda1
lrwxrwxrwx. 1 root root  9 Sep 15 05:30 scsi-0Google_PersistentDisk_persistent-disk-1 -> ../../sdb

[root@servername ~]# ls -l /dev/disk/by-id total 0 lrwxrwxrwx. 1 root root 9 Sep 15 05:30 google-boot -> ../../sda lrwxrwxrwx. 1 root root 10 Sep 15 05:30 google-boot-part1 -> ../../sda1 lrwxrwxrwx. 1 root root 9 Sep 15 05:30 google-persistent-disk-1 -> ../../sdb lrwxrwxrwx. 1 root root 9 Sep 15 05:30 scsi-0Google_PersistentDisk_boot -> ../../sda lrwxrwxrwx. 1 root root 10 Sep 15 05:30 scsi-0Google_PersistentDisk_boot-part1 -> ../../sda1 lrwxrwxrwx. 1 root root 9 Sep 15 05:30 scsi-0Google_PersistentDisk_persistent-disk-1 -> ../../sdb

Filed Under: Cloud Tagged With: device, disks, gcp, identify, name, volume

Force Umount if Busy

September 16, 2019

If device is busy and you can’t umount it, try it with -l option (lazy unmount). Or you can force it.

# standard
umount /mnt/data
# lazy umount
umount -l /mnt/data
# force
umount -f /mnt/data

# standard umount /mnt/data # lazy umount umount -l /mnt/data # force umount -f /mnt/data

Lazy unmount is safer since it will detach immediately and clean up all references to the file system. Force is a bit more drastic.

Filed Under: Linux Tagged With: busy, device, force, lazy, umount, unable

Detect Device, OS, Browser

March 12, 2014

If you like to deliver specific content to a certain device type, you can use PHP’s server environment settings to know what type of device, operating systems, and browser type is being used. The server environment setting we are interested in is ‘HTTP_USER_AGENT.’ This index contains a string that is given off by the user agent, the browser in this case. All devices pass down pieces of information identifying themselves, including the type of device, operating system, and browser that is being used.

If we were to look for an iPad for example, we need to perform the following commands:

$iPad   = stripos($_SERVER['HTTP_USER_AGENT'],"iPad");
if ($iPad) { 
  echo 'This is an iPad'; 
} else { 
  echo 'This is not'; 
}

$iPad = stripos($_SERVER['HTTP_USER_AGENT'],"iPad"); if ($iPad) { echo 'This is an iPad'; } else { echo 'This is not'; }

Other Devices

$user_agent = $_SERVER['HTTP_USER_AGENT'];
 
$iPad   = stripos($user_agent,"iPad");
$iPod   = stripos($user_agent,"iPod");
$iPhone = stripos($user_agent,"iPhone");
$webOS  = stripos($user_agent,"webOS");
$BlackBerry = stripos($user_agent,"BlackBerry");
$RimTablet= stripos($user_agent,"RIM Tablet");
 
if (stripos($user_agent,"Android") && stripos($user_agent,"mobile")) { 
  $Android = true;
} elseif(stripos($user_agent,"Android")){
  $AndroidTablet = true;
}
 
if ($AndroidTablet) {
  echo 'This is an Android Tablet';
} else {
  echo 'This is not an Android Tablet';
}

$user_agent = $_SERVER['HTTP_USER_AGENT']; $iPad = stripos($user_agent,"iPad"); $iPod = stripos($user_agent,"iPod"); $iPhone = stripos($user_agent,"iPhone"); $webOS = stripos($user_agent,"webOS"); $BlackBerry = stripos($user_agent,"BlackBerry"); $RimTablet= stripos($user_agent,"RIM Tablet"); if (stripos($user_agent,"Android") && stripos($user_agent,"mobile")) { $Android = true; } elseif(stripos($user_agent,"Android")){ $AndroidTablet = true; } if ($AndroidTablet) { echo 'This is an Android Tablet'; } else { echo 'This is not an Android Tablet'; }

Detect OS Type

$user_agent = $_SERVER['HTTP_USER_AGENT'];
 
if (preg_match('/linux/i', $user_agent)) { $platform = 'linux'; }
if (preg_match('/macintosh|mac os x/i', $user_agent)) { $platform = 'mac'; }
if (preg_match('/windows|win32/i', $user_agent)) { $platform = 'windows'; }
 
if ($platform == 'windows') {
  // do something
}

$user_agent = $_SERVER['HTTP_USER_AGENT']; if (preg_match('/linux/i', $user_agent)) { $platform = 'linux'; } if (preg_match('/macintosh|mac os x/i', $user_agent)) { $platform = 'mac'; } if (preg_match('/windows|win32/i', $user_agent)) { $platform = 'windows'; } if ($platform == 'windows') { // do something }

Detect Browser Type

$user_agent = $_SERVER['HTTP_USER_AGENT'];
 
if (preg_match('/MSIE/i',$user_agent)) { $browser = 'Internet Explorer'; }
if (preg_match('/Firefox/i',$user_agent)) { $browser = 'Mozilla Firefox'; }
if (preg_match('/Chrome/i',$user_agent)) { $browser = 'Google Chrome'; }
if (preg_match('/Safari/i',$user_agent)) { $browser = 'Apple Safari'; }
if (preg_match('/Opera/i',$user_agent)) { $browser = 'Opera'; }
if (preg_match('/Netscape/i',$user_agent)) { $browser = 'Netscape'; }
 
if ($browser == 'Google Chrome') {
  // do something
}

$user_agent = $_SERVER['HTTP_USER_AGENT']; if (preg_match('/MSIE/i',$user_agent)) { $browser = 'Internet Explorer'; } if (preg_match('/Firefox/i',$user_agent)) { $browser = 'Mozilla Firefox'; } if (preg_match('/Chrome/i',$user_agent)) { $browser = 'Google Chrome'; } if (preg_match('/Safari/i',$user_agent)) { $browser = 'Apple Safari'; } if (preg_match('/Opera/i',$user_agent)) { $browser = 'Opera'; } if (preg_match('/Netscape/i',$user_agent)) { $browser = 'Netscape'; } if ($browser == 'Google Chrome') { // do something }

With the sample code above, you can pretty much single out any device and deliver specific content to it.

Filed Under: PHP Tagged With: browser, device, os

  • Home
  • About
  • Archives

Copyright © 2023