Category Archives: Linux

Removing lost physical volumes from a volume group

Removing lost physical volumes from a volume group

LVM
LVM

If you get this crazy message and you are lucky that all data are on the other disk, then you can use this steps.

Get the status of the physical volumes:

pvs
  Couldn't find device with uuid Lxx4Mu-37Ie-3Y2d-kXJe-hd6v-ynUI-pa1zxc.
  PV             VG        Fmt  Attr PSize   PFree  
  /dev/sda2      vg_system lvm2 a--u  99.61g   2.93g
  unknown device vg_system lvm2 a-mu 100.00g 100.00g

Get the status of the volume groups:

vgs
  Couldn't find device with uuid Lxx4Mu-37Ie-3Y2d-kXJe-hd6v-ynUI-pa1zxc.
  VG        #PV #LV #SN Attr   VSize   VFree  
  vg_system   2   5   0 wz-pn- 199.60g 102.92g

Get the status of the logical volumes and the devices:

lvs -a -o +devices
  Couldn't find device with uuid Lxx4Mu-37Ie-3Y2d-kXJe-hd6v-ynUI-pa1zxc.
  LV      VG        Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert Devices         
  lv_home vg_system -wi-ao---- 53.71g                                                     /dev/sda2(0)    
  lv_root vg_system -wi-ao---- 14.65g                                                     /dev/sda2(13750)
  lv_swap vg_system -wi-ao----  3.91g                                                     /dev/sda2(17500)
  lv_tmp  vg_system -wi-ao----  4.88g                                                     /dev/sda2(18500)
  lv_var  vg_system -wi-ao---- 19.53g                                                     /dev/sda2(19750)

Now you can use the test option to try to remove the unknown device from the volume group:

vgreduce --test vg_system --removemissing
  TEST MODE: Metadata will NOT be updated and volumes will not be (de)activated.
  Couldn't find device with uuid Lxx4Mu-37Ie-3Y2d-kXJe-hd6v-ynUI-pa1zxc.
  Wrote out consistent volume group vg_system

Now remove it and write the change:

vgreduce vg_system --removemissing
  Couldn't find device with uuid Lxx4Mu-37Ie-3Y2d-kXJe-hd6v-ynUI-pa1zxc.
  Wrote out consistent volume group vg_system

You can see the error message is away:

root@tvhvma-psz111: [~]# vgs
  VG        #PV #LV #SN Attr   VSize  VFree
  vg_system   1   5   0 wz--n- 99.61g 2.93g

Now you can add the device again.

Add the physical volume:

pvcreate /dev/sdb1 
  Physical volume "/dev/sdb1" successfully created

Show the status from the physical volumes:

pvs
  PV         VG        Fmt  Attr PSize   PFree  
  /dev/sda2  vg_system lvm2 a--u  99.61g   2.93g
  /dev/sdb1            lvm2 ---- 100.00g 100.00g

Show the status from the volume group:

vgs
  VG        #PV #LV #SN Attr   VSize  VFree
  vg_system   1   5   0 wz--n- 99.61g 2.93g

Add the physical volume to the volume group:

vgextend vg_system /dev/sdb1
  Volume group "vg_system" successfully extended

Now you can see the aktiv physical volume:

pvs
  PV         VG        Fmt  Attr PSize   PFree  
  /dev/sda2  vg_system lvm2 a--u  99.61g   2.93g
  /dev/sdb1  vg_system lvm2 a--u 100.00g 100.00g

Show the status from the group and you can see now is more space.

vgs
  VG        #PV #LV #SN Attr   VSize   VFree  
  vg_system   2   5   0 wz--n- 199.60g 102.92g

Thunderbird 45 fix paragraph (two lines)

Thunderbird 45 fix paragraph (two lines)

If you update to the new Thunderbird version, the implemented a new “function”. If you press enter, you get two lines. This is very ugly and irritating for me.

To disable this, please go to the settings, composition and disable “When using paragraph format, the enter key creates a new paragraph”

thunderbird 45 fix
thunderbird 45 fix

Now you can press enter and it will be normal again.

Ubuntu upgrade from 14.04 to 16.04

Ubuntu upgrade from 14.04 to 16.04

logo-ubuntu
logo-ubuntu

To upgrade from Ubuntu 14.04 to 16.04, you can use the ubuntu tool update-manager. This tool make a clean upgrade from the system.

Please before update your system.

sudo apt-get update
sudo apt-get dist-upgrade

If you are done with the upgrade, install the update-manager-core.

sudo apt-get install update-manager-core

Now upgrade to the new ubuntu release.

sudo do-release-upgrade -d

Raspberry Pi ntp server gps

raspberry pi ntp server gps

RASPBERRY PI NTP SERVER GPS
RASPBERRY PI NTP SERVER GPS

You need:

stty -F /dev/ttyAMA0 raw 9600 cs8 clocal -cstopb

test gps

cat /dev/ttyAMA0

gpsmon

gpsmon
gpsmon

(eg, remove console=ttyAMA0,115200 and if there, kgdboc=ttyAMA0,115200) /boot/cmdline.txt

dwc_otg.lpm_enable=0 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait

Install ntp package

apt-get install ntp gpsd

/etc/default/gpsd

# Default settings for the gpsd init script and the hotplug wrapper.

# Start the gpsd daemon automatically at boot time
START_DAEMON="true"

# Use USB hotplugging to add new USB devices automatically to the daemon
USBAUTO="false"

# Devices gpsd should collect to at boot time.
# They need to be read/writeable, either by user gpsd or the group dialout.
DEVICES="/dev/ttyAMA0"

# Other options you want to pass to gpsd
GPSD_OPTIONS="-b -n"

/lib/systemd/system/gpsd.service

#ExecStart=/usr/sbin/gpsd -N $GPSD_OPTIONS $DEVICES
ExecStart=/usr/sbin/gpsd -N -b -n /dev/ttyAMA0

/usr/local/bin/leap-seconds.sh

#!/bin/sh
cd /etc/ntp
wget https://www.ietf.org/timezones/data/leap-seconds.list &> /dev/null
service ntp restart &> /dev/null

/etc/cron.d/ntp

0 0 31 6,12 * root /usr/local/bin/leap-seconds.sh
mkdir /etc/ntp

download the leap-seconds.list the first time

/usr/local/bin/leap-seconds.sh

/etc/ntp.conf

driftfile /var/lib/ntp/ntp.drift
leapfile /etc/ntp/leap-seconds.list

# Enable this if you want statistics to be logged.
statsdir /var/log/ntpstats/

statistics loopstats peerstats clockstats
filegen loopstats file loopstats type day enable
filegen peerstats file peerstats type day enable
filegen clockstats file clockstats type day enable

# pool
server 0.ch.pool.ntp.org iburst
server 1.ch.pool.ntp.org iburst
server 2.ch.pool.ntp.org iburst
server 3.ch.pool.ntp.org iburst


# HW GPS
server 127.127.28.0 iburst
fudge 127.127.28.0 flag1 1 flag2 0 time2 0.600 refid GPS

# Access control configuration; see /usr/share/doc/ntp-doc/html/accopt.html for
# details.  The web page 
# might also be helpful.
#
# Note that "restrict" applies to both servers and clients, so a configuration
# that might be intended to block requests from certain clients could also end
# up blocking replies from your own upstream servers.

# By default, exchange time with everybody, but don't allow configuration.
restrict -4 default kod notrap nomodify nopeer noquery
restrict -6 default kod notrap nomodify nopeer noquery

# Local users may interrogate the ntp server more closely.
restrict 127.0.0.1
restrict ::1

# Clients from this (example!) subnet have unlimited access, but only if
# cryptographically authenticated.
restrict 172.23.0.0 mask 255.255.0.0 notrust

# If you want to provide time to your local subnet, change the next line.
# (Again, the address is an example only.)
#broadcast 192.168.123.255

# If you want to listen to time broadcasts on your local subnet, de-comment the
# next lines.  Please do this only if you trust everybody on the network!
#disable auth
#broadcastclient

Tricks:

query and synchronize against a pool

ntpdate -q 0.ch.pool.ntp.org 1.ch.pool.ntp.org

/etc/udev/rules.d/99-com.rules
KERNEL==”ttyAMA0″, SYMLINK+=”gps0″
KERNEL==”pps0″, SYMLINK+=”gpspps0″

The NTP status codes that ntpq is showing you are on this list, yours is showing an “*” which means you aren’t using the PPS, just the serial output of the GPS chip. You might want to look into that as the PPS is probably going to give you better time accuracy.

o = pps peer
* = sys peer
# = too distant
+ = selected
x = false ticker
– = discarded

[![MIT license](http://img.shields.io/badge/license-MIT-brightgreen.svg)](http://opensource.org/licenses/MIT)

curl HTTP-header only

curl HTTP-header only

-I, --head
              (HTTP/FTP/FILE) Fetch the HTTP-header only! HTTP-servers feature the command HEAD which this uses to get nothing but the header of a document. When used on an FTP or FILE file, curl displays the file size and last modification time only.
root@vh01 ~ # curl -I https://git.safematix.com 
HTTP/1.1 302 Found
Server: nginx
Date: Sun, 08 Nov 2015 15:51:31 GMT
Content-Type: text/html; charset=utf-8
Connection: keep-alive
Status: 302 Found
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1; mode=block
X-Content-Type-Options: nosniff
Location: https://git.safematix.com/users/sign_in
Cache-Control: no-cache
Set-Cookie: _gitlab_session=08f48dd9e9a254b8ef0531f16e58963c; path=/; expires=Sun, 15 Nov 2015 15:51:31 -0000; secure; HttpOnly
Set-Cookie: request_method=HEAD; path=/
X-Request-Id: 20f8f32e-79ca-4bdd-97c0-092e70e39abc
X-Runtime: 0.007302
X-Frame-Options: DENY
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
Strict-Transport-Security: max-age=31536000; includeSubDomains; preload
Public-Key-Pins: pin-sha256="tqbNSQH3NzwHzRVt1iYPI4cncKFhKQRCDrt8nt4mqhE="; pin-sha256="5C8kvU039KouVrl52D0eZSGf4Onjo4Khs8tmyTlV3nU="; max-age=5184000; includeSubDomains

Too many authentication failures for root

Too many authentication failures for root

If you get the following error, the most reason is, that you have to many ssh keys.

“Received disconnect from 172.23.23.23: 2: Too many authentication failures for root”

This is easy to fix for password authentication

ssh -o PubkeyAuthentication=no safematix@172.23.23.23

This is easy to fix for a other key

ssh -i .ssh/keyfile safematix@172.23.23.23

inxi – a full featured system information script

inxi – a full featured system information script

inxi
inxi

inxi -F -xxx

System:    Host: chz01vh01 Kernel: 3.19.0-30-generic x86_64 (64 bit, gcc: 4.8.2) Console: tty 2 Distro: Ubuntu 14.04 trusty
Machine:   Mobo: ASUSTeK model: SABERTOOTH 990FX version: Rev 1.xx serial: ***********
           Bios: American Megatrends version: 1604 date: 10/16/2012
CPU:       Octa core AMD FX-8150 Eight-Core (-MCP-) cache: 16384 KB flags: (lm nx sse sse2 sse3 sse4_1 sse4_2 sse4a ssse3 svm) bmips: 57788.9 
           Clock Speeds: 1: 3611.805 MHz 2: 3611.805 MHz 3: 3611.805 MHz 4: 3611.805 MHz 5: 3611.805 MHz 6: 3611.805 MHz 7: 3611.805 MHz 8: 3611.805 MHz
Graphics:  Card: Failed to Detect Video Card! 
           X-Vendor: N/A driver: N/A tty size: 117x31 Advanced Data: N/A for root out of X
Network:   Card-1: Realtek RTL8111/8168/8411 PCI Express Gigabit Ethernet Controller 
           driver: r8169 ver: 2.3LK-NAPI port: 9000 bus-ID: 09:00.0 chip-ID: 10ec:8168
           IF: eth0 state: down mac: ************
           Card-2: Intel 82572EI Gigabit Ethernet Controller (Copper) 
           driver: e1000e ver: 2.3.2-k port: c000 bus-ID: 05:00.0 chip-ID: 8086:107d
           IF: p11p1 state: up speed: 1000 Mbps duplex: full mac: ************
           Card-3: Intel 82572EI Gigabit Ethernet Controller (Copper) 
           driver: e1000e ver: 2.3.2-k port: a000 bus-ID: 08:00.0 chip-ID: 8086:10b9
           IF: eth2 state: down mac: ************
           Card-4: Intel 82574L Gigabit Network Connection 
           driver: e1000e ver: 2.3.2-k port: b000 bus-ID: 06:00.0 chip-ID: 8086:10d3
           IF: p13p1 state: up speed: 1000 Mbps duplex: full mac: ************
Drives:    HDD Total Size: 34006.7GB (22.5% used)
           1: id: /dev/sda model: WDC_WD30EFRX size: 3000.6GB serial: WD-************ temp: 24C 
           2: id: /dev/sdb model: WDC_WD30EFRX size: 3000.6GB serial: WD-************ temp: 23C 
           3: id: /dev/sdc model: WDC_WD30EFRX size: 3000.6GB serial: WD-************ temp: 23C 
           4: id: /dev/sdd model: WDC_WD30EFRX size: 3000.6GB serial: WD-************ temp: 24C 
           5: id: /dev/sde model: WDC_WD30EFRX size: 3000.6GB serial: WD-************ temp: 24C 
           6: id: /dev/sdf model: WDC_WD30EFRX size: 3000.6GB serial: WD-************ temp: 24C 
           7: id: /dev/sdg model: WDC_WD40EFRX size: 4000.8GB serial: WD-************ temp: 28C 
           8: id: /dev/sdh model: WDC_WD40EFRX size: 4000.8GB serial: WD-************ temp: 29C 
           9: id: /dev/sdi model: WDC_WD40EFRX size: 4000.8GB serial: WD-************ temp: 28C 
           10: id: /dev/sdj model: WDC_WD40EFRX size: 4000.8GB serial: WD-************ temp: 29C 
Partition: ID: / size: 3.8G used: 516M (14%) fs: xfs ID: /usr size: 3.8G used: 783M (21%) fs: xfs 
           ID: /var size: 14G used: 3.9G (29%) fs: xfs ID: /tmp size: 4.6G used: 9.4M (1%) fs: ext2 
           ID: /boot size: 923M used: 44M (5%) fs: ext3 ID: swap-1 size: 8.00GB used: 0.00GB (0%) fs: swap 
           ID: swap-2 size: 8.00GB used: 0.00GB (0%) fs: swap ID: swap-3 size: 8.00GB used: 0.00GB (0%) fs: swap 
           ID: swap-4 size: 8.00GB used: 0.00GB (0%) fs: swap 
RAID:      System: supported: raid1 raid6 raid5 raid4 linear multipath raid0 raid10 
           Device-1: /dev/md1 - active components: online: sdj4[1] sdi4[3] sdg4[5] sdh4[4]
           Info: raid: 1 report: 4/4 UUUU blocks: 927603520 chunk size: N/A super blocks: 1.2
           Device-2: /dev/md0 - active components: online: sdi2[0] sdj2[1] sdh2[4] sdg2[5]
           Info: raid: 1 report: 4/4 UUUU blocks: 976320 chunk size: N/A super blocks: 1.2
           Device-3: /dev/md2 - active components: online: sdg5[10] sdj5[9] sdi5[8] sdh5[11] sdb1[0] sdc1[2] sde1[4] sdf1[5] sdd1[3] sda1[1]
           Info: raid: 6 report: 10/10 UUUUUUUUUU blocks: 23441068032 chunk size: 512k super blocks: 1.2 algorithm: 2
           Unused Devices: none
Sensors:   System Temperatures: cpu: 27.9C mobo: N/A 
           Fan Speeds (in rpm): cpu: N/A 
Info:      Processes: 296 Uptime: 2 days Memory: 5484.8/11897.6MB Runlevel: 2 Gcc sys: N/A 
           Client: Shell (zsh 5.0.2 running in tty 2) inxi: 1.9.17

Raspberry Pi – reading system values

Raspberry Pi – reading system values

Raspberry Pi
Raspberry Pi

To read the system values and status, you can use the tool vcgencmd.

To list the version

vcgencmd version

Oct 11 2015 16:16:21 
Copyright (c) 2012 Broadcom
version cdea693c2a4280e4855643dc7840392d915f19b8 (clean) (release)

To list all parameters

vcgencmd commands

commands="vcos, ap_output_control, ap_output_post_processing, vchi_test_init, vchi_test_exit, pm_set_policy, pm_get_status, pm_show_stats, pm_start_logging, pm_stop_logging, version, commands, set_vll_dir, led_control, set_backlight, set_logging, get_lcd_info, set_bus_arbiter_mode, cache_flush, otp_dump, test_result, codec_enabled, get_camera, get_mem, measure_clock, measure_volts, scaling_kernel, scaling_sharpness, get_hvs_asserts, measure_temp, get_config, hdmi_ntsc_freqs, hdmi_adjust_clock, hdmi_status_show, hvs_update_fields, pwm_speedup, force_audio, hdmi_stream_channels, hdmi_channel_map, display_power, read_ring_osc, memtest, dispmanx_list, get_rsts, schmoo, render_bar, disk_notify, inuse_notify, sus_suspend, sus_status, sus_is_enabled, sus_stop_test_thread, egl_platform_switch, mem_validate, mem_oom, mem_reloc_stats, file, vctest_memmap, vctest_start, vctest_stop, vctest_set, vctest_get"

To get the running config

vcgencmd get_config int

arm_freq=900
config_hdmi_boost=5
disable_commandline_tags=2
disable_l2cache=1
emmc_pll_core=1
force_eeprom_read=1
force_pwm_open=1
framebuffer_ignore_alpha=1
framebuffer_swap=1
hdmi_force_cec_address=65535
over_voltage_avs=0x1b774
pause_burst_frames=1
program_serial_random=1
sdram_freq=450
temp_limit=85

To get the memory for the system

vcgencmd get_mem arm

arm=944M

To get the memory for the gpu

vcgencmd get_mem gpu

gpu=64M

List processor temperature

vcgencmd measure_temp

temp=34.7'C

To get the volt

vcgencmd measure_volts

volt=1.2000V

To get the cpu clock in Hz

vcgencmd measure_clock arm

frequency(45)=600000000

How to grow RAID+LUKS+lvm+xfs

How to grow RAID+LUKS+lvm+xfs
clone partition table, add disk to mdraid, resize mdraid, cryptsetup and Volume Group

luks
luks

If you like to add a new disk to mdadm raid, you should clone the partition layout.

sgdisk -R /dev/sdY /dev/sdX
sgdisk -G /dev/sdY

The first command copies the partition table of sdX to sdY (be careful not to mix these up). The second command randomizes the GUID on the disk and all the partitions. This is only necessary if the disks are to be used in the same machine, otherwise it’s unnecessary.

Add new disks to raid:

mdadm --add /dev/sdb1 

Grow the raid:

mdadm --grow --raid-devices=9 --backup-file=/tmp/grow_md2.bak /dev/md2

Information of reshape:

cat /proc/mdstat                                                                                                                                                                                                                                                                                     
Personalities : [raid1] [raid6] [raid5] [raid4] [linear] [multipath] [raid0] [raid10] 
md1 : active raid1 sdg4[5] sdh4[4] sdi4[3] sdj4[1]
      927603520 blocks super 1.2 [4/3] [UUU_]
      	resync=DELAYED
      
md0 : active raid1 sdg2[5] sdi2[0] sdh2[4] sdj2[1]
      976320 blocks super 1.2 [4/3] [UUU_]
      	resync=DELAYED
      
md2 : active raid6 sdg5[10](S) sdi5[8] sdj5[9] sdh5[11] sdd1[3] sdb1[0] sdf1[5] sdc1[2] sde1[4] sda1[1]
      20510934528 blocks super 1.2 level 6, 512k chunk, algorithm 2 [10/9] [UUUUUUUU_U]
      [====>................]  reshape = 20.2% (592765952/2930133504) finish=3123.9min speed=12469K/sec
      
unused devices: 

Speed up the rebuild or reshape:

If you only have 1000, you should set to a higher value.

cat /proc/sys/dev/raid/speed_limit_min                                                                                                                                                                                                                                                           
1000

Set the speed_limit_min to 50000.

echo 50000 > /proc/sys/dev/raid/speed_limit_min

Resize the partition with parted:

parted /dev/md2 resizepart

Resize the LUKS partition:

cryptsetup resize cryptvg

Show the status from the LUKS partition:

cryptsetup status cryptvg

Show the status from the physical volume:

pvdisplay

Resize the physical volume

pvresize /dev/mapper/cryptvg 

Show the status from the volume group:

vgs

Resize the xfs filesystem:

xfs_growfs /dev/cryptvg/test

Tricks

Detail information of the mdadm raid.

mdadm --detail /dev/md1

If you have a problem with the raid:

mdadm --stop /dev/md2
mdadm --assemble /dev/md2  /dev/sdh5 /dev/sdb1 /dev/sde1 /dev/sdc1 /dev/sdf1 /dev/sdd1 /dev/sda1 /dev/sdi5 /dev/sdg5
mdadm --run /dev/md2

If it now work, force:

mdadm --assemble --run --force  /dev/md2 /dev/sdb1 /dev/sde1 /dev/sdc1 /dev/sdf1 /dev/sdd1 /dev/sda1 /dev/sdi5 /dev/sdg5 /dev/sdh5

Disk status

mdadm --examine /dev/sd*