Linux: Difference between revisions

From Han Wiki
Jump to navigation Jump to search
→‎Volume group: adding a new disk to LVM
Line 134: Line 134:
|}
|}


=== Adding a new disk to a LVM ===
<source lang="console">
[root@chara mhan]# lsblk
NAME                  MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda                    8:0    0 238.5G  0 disk
└─sda1                  8:1    0 238.5G  0 part
  ├─centos_chara-root 253:0    0    2T  0 lvm  /
  └─centos_chara-home 253:2    0  200G  0 lvm  /home
sdb                    8:16  0 119.2G  0 disk
├─sdb1                  8:17  0  200M  0 part /boot/efi
├─sdb2                  8:18  0    1G  0 part /boot
└─sdb3                  8:19  0  118G  0 part
  ├─centos_chara-root 253:0    0    2T  0 lvm  /
  └─centos_chara-swap 253:1    0  7.9G  0 lvm  [SWAP]
sdc                    8:32  0  1.8T  0 disk
└─sdc1                  8:33  0  1.8T  0 part
  └─centos_chara-root 253:0    0    2T  0 lvm  /
sdd                    8:48  0 931.5G  0 disk
└─sdd1                  8:49  0 931.5G  0 part
sr0                    11:0    1  1024M  0 rom
[root@chara mhan]# fdisk /dev/sdd
Welcome to fdisk (util-linux 2.32.1).
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 0x8d7dc33f.
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-1953525167, default 2048):
Last sector, +sectors or +size{K,M,G,T,P} (2048-1953525167, default 1953525167):
Created a new partition 1 of type 'Linux' and of size 931.5 GiB.
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.
[root@chara mhan]# pvcreate /dev/sdd1
  Physical volume "/dev/sdd1" successfully created.
[root@chara mhan]# vgs
  VG          #PV #LV #SN Attr  VSize  VFree
  centos_chara  3  3  0 wz--n- <2.17t    0
[root@chara mhan]# vgextend centos_chara /dev/sdd1
  Volume group "centos_chara" successfully extended
[root@chara mhan]# lvdisplay | grep Path
  LV Path                /dev/centos_chara/swap
  LV Path                /dev/centos_chara/root
  LV Path                /dev/centos_chara/home
[root@chara mhan]# lvresize -l +100%free /dev/centos_chara/root
  Size of logical volume centos_chara/root changed from 1.96 TiB (514983 extents) to 2.87 TiB (753449 extents).
  Logical volume centos_chara/root successfully resized.
[root@chara mhan]# df -h | grep root
/dev/mapper/centos_chara-root  2.0T  1.9T  89G  96% /
[root@chara mhan]# grep root /etc/mtab
/dev/mapper/centos_chara-root / xfs rw,relatime,attr2,inode64,noquota 0 0
[root@chara mhan]# df -h
Filesystem                    Size  Used Avail Use% Mounted on
devtmpfs                      7.8G    0  7.8G  0% /dev
tmpfs                          7.8G  176K  7.8G  1% /dev/shm
tmpfs                          7.8G  9.3M  7.8G  1% /run
tmpfs                          7.8G    0  7.8G  0% /sys/fs/cgroup
/dev/mapper/centos_chara-root  2.0T  1.9T  89G  96% /
/dev/sdb2                    1014M  293M  722M  29% /boot
/dev/mapper/centos_chara-home  200G  103G  98G  52% /home
/dev/sdb1                      200M  11M  190M  6% /boot/efi
tmpfs                          1.6G  4.0K  1.6G  1% /run/user/1000
[root@chara mhan]# xfs_growfs /
meta-data=/dev/mapper/centos_chara-root isize=512    agcount=161, agsize=3276800 blks
        =                      sectsz=512  attr=2, projid32bit=1
        =                      crc=1        finobt=0, sparse=0, rmapbt=0
        =                      reflink=0
data    =                      bsize=4096  blocks=527342592, imaxpct=25
        =                      sunit=0      swidth=0 blks
naming  =version 2              bsize=4096  ascii-ci=0, ftype=1
log      =internal log          bsize=4096  blocks=6400, version=2
        =                      sectsz=512  sunit=0 blks, lazy-count=1
realtime =none                  extsz=4096  blocks=0, rtextents=0
data blocks changed from 527342592 to 771531776
[root@chara mhan]# df -h
Filesystem                    Size  Used Avail Use% Mounted on
devtmpfs                      7.8G    0  7.8G  0% /dev
tmpfs                          7.8G  176K  7.8G  1% /dev/shm
tmpfs                          7.8G  9.3M  7.8G  1% /run
tmpfs                          7.8G    0  7.8G  0% /sys/fs/cgroup
/dev/mapper/centos_chara-root  2.9T  1.9T 1020G  66% /
/dev/sdb2                    1014M  293M  722M  29% /boot
/dev/mapper/centos_chara-home  200G  103G  98G  52% /home
/dev/sdb1                      200M  11M  190M  6% /boot/efi
tmpfs                          1.6G  4.0K  1.6G  1% /run/user/1000
[root@chara mhan]#
</source>


=== Links ===
=== Links ===

Revision as of 19:23, 6 July 2020


System

Description Command
Boot into CLI mode sudo systemctl set-default multi-user.target
Boot into desktop mode sudo systemctl set-default graphical.target
Detach a job from the current session sudo rsync templates/* whatever/ &
jobs
disown -h %1

SSH

Description Command
Create private/public SSH key file using 2048 bit encryption and with a comment. The command creates files under ~/.ssh folder. ssh-keygen -b 2048 -C user@host.domain
Push public SSH key to a server ssh-copy-id -p 41111 -i ~/.ssh/id_rsa.pub mhan@remote.server.com
Reset (SELinux) permissions related to SSH. This may be needed if all else fails to correct the issue of system not accepting public keys. restorecon -R -v ~/.ssh

SSH


Tunneling

Say I'm trying to access 10.101.1.10 server via SSH which is behind a restrictive firewall through 64.106.170.61. The first command will map the port 50010 of the local machine to port 22 of 10.101.1.10 that is accessible from 64.106.170.61.

Description Command Distro
Create a SSH tunnel & connect via port 50010 $ ssh -L 50010:10.101.1.10:22 mhan@64.106.170.61
$ ssh -p 50010 127.0.0.1

Disk

Description Command
Check if GRUB is installed on a partition (e.g. /dev/sda) sudo dd bs=512 count=1 if=/dev/sda 2>/dev/null | strings

Search

LVM

Physical volume

Description Command
Initialize for use as LVM physical volume. pvcreate /dev/sdb1
Scanning for block devices. lvmdiskscan
Display the physical volumes. pvdisplay
Show all physical devices. pvscan
Prevent allocation of physical extents on the free space of one or more physical volumes. pvchange -x n /dev/sdb1
Resize. pvresize
Remove LVM label. pvremove

Volume group

Description Command
Create a volume group. vgcreate vg1 /dev/sdb1 /dev/sdc1
Add a physical volume to a volume group. vgextend vg1 /dev/sdd1
Display volume group. vgdisplay new_vg
Scan disks for volume groups. vgscan
Remove a physical volume from a volume group. vgreduce group_name /dev/sdc1
Change the maximum number of logical volumes of volume group vg00 to 128. vgchange -l 128 /dev/vg00
Activate or deactivate a volume group. vgchange -a n my_volume_group
Remove a volume group. vgremove officevg
Split the physical volumes of a volume group and create a new volume group. $ vgsplit bigvg smallvg /dev/ram15
Volume group "smallvg" successfully split from "bigvg"
Merge the inactive volume group my_vg into the active or inactive volume group databases giving verbose runtime information. vgmerge -v databases my_vg
Change the name of a volume group. vgrename vg02 my_volume_group


Adding a new disk to a LVM

[root@chara mhan]# lsblk
NAME                  MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda                     8:0    0 238.5G  0 disk
└─sda1                  8:1    0 238.5G  0 part
  ├─centos_chara-root 253:0    0     2T  0 lvm  /
  └─centos_chara-home 253:2    0   200G  0 lvm  /home
sdb                     8:16   0 119.2G  0 disk
├─sdb1                  8:17   0   200M  0 part /boot/efi
├─sdb2                  8:18   0     1G  0 part /boot
└─sdb3                  8:19   0   118G  0 part
  ├─centos_chara-root 253:0    0     2T  0 lvm  /
  └─centos_chara-swap 253:1    0   7.9G  0 lvm  [SWAP]
sdc                     8:32   0   1.8T  0 disk
└─sdc1                  8:33   0   1.8T  0 part
  └─centos_chara-root 253:0    0     2T  0 lvm  /
sdd                     8:48   0 931.5G  0 disk
└─sdd1                  8:49   0 931.5G  0 part
sr0                    11:0    1  1024M  0 rom

[root@chara mhan]# fdisk /dev/sdd

Welcome to fdisk (util-linux 2.32.1).
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 0x8d7dc33f.

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-1953525167, default 2048):
Last sector, +sectors or +size{K,M,G,T,P} (2048-1953525167, default 1953525167):

Created a new partition 1 of type 'Linux' and of size 931.5 GiB.

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.
[root@chara mhan]# pvcreate /dev/sdd1
  Physical volume "/dev/sdd1" successfully created.
[root@chara mhan]# vgs
  VG           #PV #LV #SN Attr   VSize  VFree
  centos_chara   3   3   0 wz--n- <2.17t    0
[root@chara mhan]# vgextend centos_chara /dev/sdd1
  Volume group "centos_chara" successfully extended
[root@chara mhan]# lvdisplay | grep Path
  LV Path                /dev/centos_chara/swap
  LV Path                /dev/centos_chara/root
  LV Path                /dev/centos_chara/home
[root@chara mhan]# lvresize -l +100%free /dev/centos_chara/root
  Size of logical volume centos_chara/root changed from 1.96 TiB (514983 extents) to 2.87 TiB (753449 extents).
  Logical volume centos_chara/root successfully resized.
[root@chara mhan]# df -h | grep root
/dev/mapper/centos_chara-root  2.0T  1.9T   89G  96% /
[root@chara mhan]# grep root /etc/mtab
/dev/mapper/centos_chara-root / xfs rw,relatime,attr2,inode64,noquota 0 0
[root@chara mhan]# df -h
Filesystem                     Size  Used Avail Use% Mounted on
devtmpfs                       7.8G     0  7.8G   0% /dev
tmpfs                          7.8G  176K  7.8G   1% /dev/shm
tmpfs                          7.8G  9.3M  7.8G   1% /run
tmpfs                          7.8G     0  7.8G   0% /sys/fs/cgroup
/dev/mapper/centos_chara-root  2.0T  1.9T   89G  96% /
/dev/sdb2                     1014M  293M  722M  29% /boot
/dev/mapper/centos_chara-home  200G  103G   98G  52% /home
/dev/sdb1                      200M   11M  190M   6% /boot/efi
tmpfs                          1.6G  4.0K  1.6G   1% /run/user/1000
[root@chara mhan]# xfs_growfs /
meta-data=/dev/mapper/centos_chara-root isize=512    agcount=161, agsize=3276800 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=0, rmapbt=0
         =                       reflink=0
data     =                       bsize=4096   blocks=527342592, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0, ftype=1
log      =internal log           bsize=4096   blocks=6400, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 527342592 to 771531776
[root@chara mhan]# df -h
Filesystem                     Size  Used Avail Use% Mounted on
devtmpfs                       7.8G     0  7.8G   0% /dev
tmpfs                          7.8G  176K  7.8G   1% /dev/shm
tmpfs                          7.8G  9.3M  7.8G   1% /run
tmpfs                          7.8G     0  7.8G   0% /sys/fs/cgroup
/dev/mapper/centos_chara-root  2.9T  1.9T 1020G  66% /
/dev/sdb2                     1014M  293M  722M  29% /boot
/dev/mapper/centos_chara-home  200G  103G   98G  52% /home
/dev/sdb1                      200M   11M  190M   6% /boot/efi
tmpfs                          1.6G  4.0K  1.6G   1% /run/user/1000
[root@chara mhan]#

Links

Users

UID or GID

Description Command
Check UID. id -u username
Check GID. id -g username
Check all of the groups a user belongs to. id -G username
Check UID and all of the groups a user belongs to. id username

File

Permissions

Letter Number
r 4
w 2
x 1
rw- 6
r-x 5
rwx 7

Audio

ALSA (Advanced Linux Sound Architecture)

Setting default output device

Ref: StackExchange/superuser: How to make Alsa pick a preferred sound device automatically?

List all audio cards you have:

$ cat /proc/asound/cards
 0 [PCH            ]: HDA-Intel - HDA Intel PCH                                                                                                                
                      HDA Intel PCH at 0xf7530000 irq 41                                                                                                       
 1 [NVidia         ]: HDA-Intel - HDA NVidia                                                                                                                   
                      HDA NVidia at 0xf7080000 irq 17                                                                                                          
 2 [SoundBar       ]: USB-Audio - Dell AC511 USB SoundBar                                                                                                      
                      Dell Dell AC511 USB SoundBar at usb-0000:00:14.0-4, full speed

Get ALSA identifiers of those:

$ aplay -l | awk -F \: '/,/{print $2}' | awk '{print $1}' | uniq                                                                                 
PCH                                                                                                                                                            
NVidia                                                                                                                                                         
SoundBar

Update /etc/asound.conf:

pcm.!default {
        type hw
        card SoundBar
}

ctl.!default {
        type hw
        card SoundBar
}

I found that the numeric identifier for these cards and change on reboot. That may be related to how the hardware detection works on Linux, and the order changes time to time. So I've used the string identifier instead -- seems to stick better than a numeric value.


PulseAudio

Restart pulseaudio. Do not sudo for this.

$ pulseaudio -k && pulseaudio -D

List sinks.

$ pacmd list-sinks
1 sink(s) available.
  * index: 0
        name: <alsa_output.usb-Dell_Dell_AC511_USB_SoundBar-00-SoundBar.analog-stereo>
        driver: <module-alsa-card.c>
        flags: HARDWARE HW_MUTE_CTRL HW_VOLUME_CTRL DECIBEL_VOLUME LATENCY DYNAMIC_LATENCY
        state: SUSPENDED
        suspend cause: IDLE 
        priority: 9049
        volume: front-left: 26202 /  40% / -23.89 dB,   front-right: 26202 /  40% / -23.89 dB
                balance 0.00
        base volume: 107931 / 165% / 13.00 dB
        volume steps: 65537
        muted: no
        current latency: 0.00 ms
        max request: 0 KiB
        max rewind: 0 KiB
        monitor source: 0
        sample spec: s16le 2ch 44100Hz
        channel map: front-left,front-right
                     Stereo
        used by: 0
        linked by: 0
        configured latency: 0.00 ms; range is 0.50 .. 2000.00 ms
        card: 1 <alsa_card.usb-Dell_Dell_AC511_USB_SoundBar-00-SoundBar>
        module: 7
        properties:
                alsa.resolution_bits = "16"
                device.api = "alsa"
                device.class = "sound"
                alsa.class = "generic"
                alsa.subclass = "generic-mix"
                alsa.name = "USB Audio"
                alsa.id = "USB Audio"
                alsa.subdevice = "0"
                alsa.subdevice_name = "subdevice #0"
                alsa.device = "0"
                alsa.card = "0"
                alsa.card_name = "Dell AC511 USB SoundBar"
                alsa.long_card_name = "Dell Dell AC511 USB SoundBar at usb-0000:00:14.0-4, full speed"
                alsa.driver_name = "snd_usb_audio"
                device.bus_path = "pci-0000:00:14.0-usb-0:4:1.0"
                sysfs.path = "/devices/pci0000:00/0000:00:14.0/usb3/3-4/3-4:1.0/sound/card0"
                udev.id = "usb-Dell_Dell_AC511_USB_SoundBar-00-SoundBar"
                device.bus = "usb"
                device.vendor.id = "413c"
                device.vendor.name = "Dell Computer Corp."
                device.product.id = "a503"
                device.product.name = "Dell AC511 USB SoundBar"
                device.serial = "Dell_Dell_AC511_USB_SoundBar"
                device.string = "front:0"
                device.buffering.buffer_size = "352800"
                device.buffering.fragment_size = "176400"
                device.access_mode = "mmap+timer"
                device.profile.name = "analog-stereo"
                device.profile.description = "Analog Stereo"
                device.description = "Dell AC511 USB SoundBar Analog Stereo"
                alsa.mixer_name = "USB Mixer"
                alsa.components = "USB413c:a503"
                module-udev-detect.discovered = "1"
                device.icon_name = "audio-card-usb"
        ports:
                analog-output: Analog Output (priority 9900, latency offset 0 usec, available: unknown)
                        properties:

        active port: <analog-output>


Networking

How To Use Nmap to Scan for Open Ports on your VPS

Description Command Distro
Scan a network for connected computers $ sudo nmap -sP 129.24.22.0/24

Firewall

Description Command Distro
Open a firewall port $ sudo ufw allow 55301
Open a firewall port $ sudo firewall-cmd --zone=public --add-port=55301/tcp --permanent
$ sudo firewall-cmd --reload
  • Last tested on CentOS 7.7.1908 (2020-04-21)
Close a firewall port $ sudo ufw deny 55301
Close a firewall port $ sudo firewall-cmd --zone=public --remove-port=55301/tcp --permanent
$ sudo firewall-cmd --reload
  • Last tested on CentOS 7.7.1908 (2020-04-21)

Security

  • GnuPG - GNU's implementation of PGP, aka GPG
  • EncFS - encrypt files and folders


Links

Miscellaneous