How to Set Default Audio in Ubuntu

 

ref:https://how.wtf/how-to-set-default-audio-in-ubuntu.html

Using the pactl command, setting default audio in Ubuntu is straightforward. For startup persistence, Ubuntu Startup Applications comes in handy.

pactl is the cli entry for the PulseAudio sound server and will be used in this tutorial.

List all input and output audio

List audio outputs:

1pactl list short sinks
11	alsa_output.pci-0000_06_00.6.HiFi__hw_Generic__sink	module-alsa-card.c	s16le 2ch 48000Hz	RUNNING

List audio inputs:

1pactl list short sources
11	alsa_input.usb-Blue_Microphones_Yeti_Stereo_Microphone_797_2019_02_24_60522-00.analog-stereo	module-alsa-card.c	s16le 2ch 44100Hz	SUSPENDED
22	alsa_input.pci-0000_06_00.6.HiFi__hw_Generic__source	module-alsa-card.c	s16le 2ch 44100Hz	SUSPENDED
33	alsa_input.pci-0000_06_00.6.HiFi__hw_acp__source	module-alsa-card.c	s32le 2ch 48000Hz	SUSPENDED

Take note of the devices listed in the output.

Set default input and output audio

Command to set default audio output:

1pactl set-default-sink <device>

Example usage:

1pactl set-default-sink alsa_output.pci-0000_06_00.6.HiFi__hw_Generic__sink

Command to set default audio input:

1pactl set-default-source <device>

Example usage:

1pactl set-default-source alsa_input.usb-Blue_Microphones_Yeti_Stereo_Microphone_797_2019_02_24_60522-00.analog-stereo

Persist command on start/restart

Persisting audio output:

  1. Open the application named “Startup Applications” (should be preinstalled)
  2. Click “Add” button in the upper right hand corner
  3. Enter a command name such as: “Set default audio output” in the Name: field
  4. Place the pactl set-default-sink <device> command in the Command: field
  5. Click “Add” button in the bottom right hand corner of the prompt

Persisting audio input:

  1. Click “Add” button in the upper right hand corner
  2. Enter a command name such as: “Set default audio input” in the Name: field
  3. Place the pactl set-default-source <device> command in the Command: field
  4. Click “Add” button in the bottom right hand corner of the prompt

在移动硬盘盒上启用SSD的Trim功能

来源:https://www.ichenfu.com/2022/10/05/enable-trim-on-usb-attached-scsi-ssds/

 

最近折腾了一小段时间的PCDN,家里刚好有一个闲置的JetsonNano和一块闲置的SSD,刚好可以跑跑PCDN,每天挣个宽带钱。具体跑的哪家,就不说了,说说在这过程中遇到的一个小问题:一般来说,PCDN或者类似的业务,对磁盘的写入压力还是比较大的,虽然可能平均的写入带宽并不高,但是也架不住每天读写的时间相当长,虽然我这块SSD是闲置的,但好歹是个传家宝,不管怎么说,还是有那么点点心疼的,肯定是不太希望哪天这SSD被写坏了。

在这种场景下,尽可能延长SSD的写入寿命就很重要了,而方法之一呢,就是想办法把SSD的Trim命令给用上。

用上Trim命令之前,可以先简单了解一下背后的逻辑,具体的可以参考Wiki,简单来说呢,因为SSD依赖垃圾回收机制来平衡NAND的磨损,但是呢具体到一整个LBA空间,只有文件系统知道哪些数据块是有效数据,所以就需要通过Trim命令,建立文件系统空闲空间和SSD底层数据块的关联,从而让SSD的主控更好的进行垃圾回收操作,一般来说,合理的使用Trim,可以有效的提高SSD的性能和寿命。当然了,Trim命令是ATA指令集里的,也就是SATA接口SSD才会有,对于SCSI以及SAS接口SSD,还有NVMe SSD来说,也有相应的UNMAPDeallocate指令,作用都是一样的。

一般来说,在Linux下,一个设备是否支持Trim操作,可以通过lsblk --discard进行查看,当输出中的DISC-GRANDISC-MAX列不为0时,说明这个设备是支持Trim操作的:

jetson-nano:chenfu:# lsblk --discard
NAME        DISC-ALN DISC-GRAN DISC-MAX DISC-ZERO
sda                0        0B       0B         0
mmcblk1            0        4M      76M         0
└─mmcblk1p1        0        4M      76M         0

比如在我这个JetsonNano上,可以看到我外接的这块SSD硬盘,对应sda设备是不支持Trim的,但是mmcblk1这个设备,也就是装系统用的一个小的MicroSD卡是支持的。

那么问题来了,针对上面的输出,sda这块盘是不支持Trim的,那怎么样才能让他支持呢?

首先需要明确的是,因为这块盘是我通过一块USB移动硬盘盒转接到板子上的,也就意味着这块硬盘并没有用原生的SATA接口(当然这块开发版本身也不支持SATA接口)。而对于移动硬盘盒而言,将SATA口转换成USB口,会需要一个桥接芯片进行协议的转换,那么桥接芯片是否支持Trim命令的转换,就显得非常重要了。对于一些老的移动硬盘盒,大多使用的是Mass Storage Class Bulk-Only Transport (BOT)这个协议,但是对于一些比较新的桥接芯片,基本都会支持一个新的叫做USB Attached SCSI Protocol (UASP) 的新协议。所以我也查了一些资料,同样也是结合产品页的一些宣传,买了一个支持UAS协议的移动硬盘盒,根据评论看,这个硬盘盒是支持Trim的,但是大部分用户似乎都是在Windows下进行测试的,在Linux下是否真的支持,是否需要新版本内核或者驱动的支持还不知道。

等硬盘盒到手,插上之后系统lsusb看了一下:

jetson-nano:~:% lsusb
Bus 002 Device 002: ID 174c:225c ASMedia Technology Inc. Ugreen Storage Device

VendorId是0x174c,也就是ASMedia公司的桥接芯片,但是225c这个ProductId并没有在USB ID数据库里查到,不过从数据库里看0x1153这个ProductId对应ASM1153这款芯片来说,那225c应该是对应着ASM225CM这个芯片?从目前的资料看,这个芯片理论上是支持Trim的,至少可以通过刷新固件来解决支持的问题。

然而系统识别出sda之后,lsblk --discard依然提示不支持Trim。

于是又搜索了一些资料,终于在Arch的SSD Wiki里找到了一些信息:

其实现在一些USB转SATA芯片(如VL715、VL716等)以及在外接NVMe硬盘盒(如IB-1817M-C31)中使用的USB转PCIe芯片(如 智微(JMicron) JMS583 )支持类似TRIM的命令。这些命令可通过 USB Attached SCSI 驱动程序(在Linux下称为”uas”)发送。然而内核可能不会自动检测到并启用这一功能。

会不会是因为芯片是支持的,但是系统默认没有开启呢?于是按Wiki里的说法,使用sg_readcap -l /dev/sda命令读取设备的标志位:

jetson-nano:chenfu:# sg_readcap -l /dev/sda
Read Capacity results:
   Protection: prot_en=0, p_type=0, p_i_exponent=0
   Logical block provisioning: lbpme=0, lbprz=0
   Last LBA=937703087 (0x37e436af), Number of logical blocks=937703088
   Logical block length=512 bytes
   Logical blocks per physical block exponent=0
   Lowest aligned LBA=0
Hence:
   Device size: 480103981056 bytes, 457862.8 MiB, 480.10 GB

发现Logical block provisioning: lbpme=0, lbprz=0其中lbpme=0,因为LBPME位为0,所以内核默认是不会开启DISCARD的支持。针对这种情况,还需要继续通过sg_vpd -a /dev/sda命令查询设备支持的命令情况:

jetson-nano:chenfu:# sg_vpd -a /dev/sda
Supported VPD pages VPD page:
  ...
Unit serial number VPD page:
  Unit serial number: 704108E11D02

Device Identification VPD page:
  Addressed logical unit:
    designator type: NAA,  code set: Binary
      0x5000000000000001

Block limits VPD page (SBC):
  Write same non-zero (WSNZ): 0
  ...

Block device characteristics VPD page (SBC):
  Non-rotating medium (e.g. solid state)
  ...
Logical block provisioning VPD page (SBC):
  Unmap command supported (LBPU): 1
  Write same (16) with unmap bit supported (LBPWS): 0
  Write same (10) with unmap bit supported (LBPWS10): 0
  Logical block provisioning read zeros (LBPRZ): 0
  Anchored LBAs supported (ANC_SUP): 0
  Threshold exponent: 0 [threshold sets not supported]
  Descriptor present (DP): 0
  Minimum percentage: 0 [not reported]
  Provisioning type: 0 (not known or fully provisioned)
  Threshold percentage: 0 [percentages not supported]

可以发现在Logical block provisioning VPD page (SBC)段下,有Unmap command supported (LBPU): 1,说明设备本身是支持Unmap指令的,因为前面说到,ATA中的Trim其实就是对应的SCSI中的UNMAP,所以支持UNMAP也就是支持了Trim,当然这中间的转换过程,应该是有硬盘盒的主控来完成。

那既然在物理上是支持Trim的,那剩下的就是逻辑上怎么启用的问题了,先看下目前内核识别的设备的provisioning_mode:

jetson-nano:chenfu:# cat /sys/block/sda/device/scsi_disk/0:0:0:0/provisioning_mode
full

可以发现输出是full,也就是说内核当前是没有检测到设备支持Trim特性,解决方法也比较简单,直接echo unmap到这个文件:

jetson-nano:chenfu:# echo unmap > /sys/block/sda/device/scsi_disk/0:0:0:0/provisioning_mode
jetson-nano:chenfu:# lsblk --discard
NAME        DISC-ALN DISC-GRAN DISC-MAX DISC-ZERO
sda                0      512B       4G         0
mmcblk1            0        4M      76M         0
└─mmcblk1p1        0        4M      76M         0

可以看到,强制指定provisioning_mode为unmap之后,lsblk --discard的输出已经提示sda设备支持Trim了。

最后,为了能让这个特性可以在插入硬盘盒的时候自动生效,可以手动编写一个Udev的规则文件:

echo 'ACTION=="add|change", ATTRS{idVendor}=="174c", ATTRS{idProduct}=="225c", SUBSYSTEM=="scsi_disk", ATTR{provisioning_mode}="unmap"' >>/etc/udev/rules.d/10-uas-discard.rules

也就是说,当有idVendor为174c,idProduct为225c的设备(也就是我的这个硬盘盒)连接的时候,自动设置provisioning_mode为unmap。

图形界面都是中文,终端也是中文 tty的控制台是英文显示

 

ref:https://blog.csdn.net/wangchengjiea/article/details/116378241

 

 

首先图形界面都是中文,终端也是中文
tty的控制台是英文显示
方法如下:

#sudo vim /etc/default/locale
中文设置为:
LANG=”zh_CN.UTF-8″
LANGUAGE=”zh_CN:zh”

修改为:
LANG=”en_US.UTF-8″
LANGUAGE=”en_US:en”

将相应的zh改成en,将CN改成US

然后需要重启生效。

记住重点!!!
重启,重启生效,

————————————————
版权声明:本文为CSDN博主「石头ym」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/wangchengjiea/article/details/116378241

xfce4 thunar添加搜索选项

 

ref:https://www.reddit.com/r/xfce/comments/94qwuo/when_is_thunar_finally_getting_a_search_file/

You can create a shortcut in Thunar’s right click menu via the “Edit” -> “Configure custom actions…” menu.

  • Name: Search files...

  • Command: catfish --path=%f

  • File pattern: *

  • Appears if selection contains: Directories

vmware modules不能在新内核更新解决方法

ref:https://communities.vmware.com/t5/VMware-Workstation-Pro/VMware-16-2-3-not-working-on-Ubuntu-22-04-LTS/td-p/2905535

cd /usr/lib/vmware/modules/source
git clone https://github.com/mkubecek/vmware-host-modules
cd vmware-host-modules
git checkout workstation-16.2.4
make
tar -cf vmnet.tar vmnet-only
tar -cf vmmon.tar vmmon-only
mv vmnet.tar /usr/lib/vmware/modules/source/
mv vmmon.tar /usr/lib/vmware/modules/source/
vmware-modconfig --console --install-all

ubuntu 查看usb设备

查看 USB 设备 使用的是哪个串口

ls -l /dev/ttyUSB*

查看 USB 设备 是不是存储设备
Linux下查看usb设备信息,常常使用lsusb命令

$lsusb

Bus 002 Device 125: ID 0781:5567 SanDisk Corp. Cruzer Blade
$lsusb -t

Port 1: Dev 125, If 0, Class=Mass Storage, Driver=usb-storage, 480M

Class=Mass Storage,说明我的设备是大容量存储设备。

我优盘的ID 是 0781:5567,如果我要查它的详细信息(包括它是否是存储设备),可以用命令:

$sudo lsusb -d 0781:5567 -v

过滤信息,用下面的命令:

$sudo lsusb -d 0781:5567 -v |grep -i storage

得到结果

bInterfaceClass 8 Mass Storage

Mass Storage,说明该设备是存储设备。

 

Extend the life of your SSD drive with fstrim

原文:https://opensource.com/article/20/2/trim-solid-state-storage-linux

 

Over the past decade, solid-state drives (SSD) have brought about a new way of managing storage. SSDs have benefits like silent and cooler operation and a faster interface spec, compared to their elder spinning ancestors. Of course, new technology brings with it new methods of maintenance and management. SSDs have a feature called TRIM. This is essentially a method for reclaiming unused blocks on the device, which may have been previously written, but no longer contain valid data and therefore, can be returned to the general storage pool for reuse. Opensource.com’s Don Watkins first wrote about TRIM in his 2017 article “Solid-state drives in Linux: Enabling TRIM for SSDs.”

 

If you have been using this feature on your Linux system, then you are probably familiar with the two methods described below.

The old ways

Discard

I initially enabled this with the discard option to the mount command. The configuration is placed into the /etc/fstab file for each file system.

# cat /etc/fstab
UUID=3453g54-6628-2346-8123435f  /home  xfs  defaults,discard   0 0

The discard option enables automatic online TRIM. There has recently been debate on whether this is the best method due to possible negative performance impacts. Using this option causes a TRIM to be initiated every time new data is written to the drive. This may introduce additional activity that interferes with storage performance.

Cron

I removed the discard option from the fstab file. Then I created a cron job to call the command on a scheduled basis.

# crontab -l
@midnight /usr/bin/trim

This is the method I used most recently on my Ubuntu Linux systems until I learned about another way.

A new TRIM service

I recently discovered that a systemd service for TRIM exists. Fedora introduced this into their distribution in version 30, and, although it is not enabled by default in versions 30 and 31, it is planned to be in version 32. If you’re working on Fedora Workstation 31 and you want to begin using this feature, you can enable it very easily. I’ll also show you how to test it below. This service is not unique to Fedora. The existence and status will depend on an individual distribution basis.

Test

I like to test first, to better understand what is happening behind the scenes. I do this by opening a terminal and issuing the command that the service is configured to call.

/usr/sbin/fstrim --fstab --verbose --quiet

The –help argument to fstrim will describe these and other arguments.

$ sudo /usr/sbin/fstrim --help

Usage:
 fstrim [options] <mount point>

Discard unused blocks on a mounted filesystem.

Options:
 -a, --all           trim all supported mounted filesystems
 -A, --fstab         trim all supported mounted filesystems from /etc/fstab
 -o, --offset <num>  the offset in bytes to start discarding from
 -l, --length <num>  the number of bytes to discard
 -m, --minimum <num> the minimum extent length to discard
 -v, --verbose       print number of discarded bytes
     --quiet         suppress error messages
 -n, --dry-run       does everything, but trim

 -h, --help          display this help
 -V, --version       display version

So, now I can see that the systemd service is configured to run the trim on all supported mounted filesystems in my /etc/fstab file –fstab and print the number of discarded bytes –verbose but suppress any error messages that might occur –quiet. Knowing these options is helpful for testing. For instance, I can start with the safest one, which is the dry run. I’ll also leave off the quiet argument so I can determine if any errors will occur with my drive setup.

$ sudo /usr/sbin/fstrim --fstab --verbose --dry-run

This will simply show what the fstrim command will do based on the file systems that it finds configured in your /etc/fstab file.

$ sudo /usr/sbin/fstrim --fstab --verbose

This will now send the TRIM operation to the drive and report on the number of discarded bytes from each file system. Below is an example after my recent fresh install of Fedora on a new NVME SSD.

/home: 291.5 GiB (313011310592 bytes) trimmed on /dev/mapper/wkst-home
/boot/efi: 579.2 MiB (607301632 bytes) trimmed on /dev/nvme0n1p1
/boot: 787.5 MiB (825778176 bytes) trimmed on /dev/nvme0n1p2
/: 60.7 GiB (65154805760 bytes) trimmed on /dev/mapper/wkst-root

Enable

Fedora Linux implements systemd timer service, scheduled to run on a weekly basis. To check the existence and current status, run systemctl status.

$ sudo systemctl status fstrim.timer

Now, enable the service.

$ sudo systemctl enable fstrim.timer

Verify

Then you can verify that the timer is enabled by listing all of the timers.

$ sudo systemctl list-timers --all

The following line referring to the fstrim.timer will appear. Notice that the timer actually activates fstrim.service. This is from where the actual fstrim is called. The time-related fields show n/a because the service has just been enabled and has not run yet.

NEXT   LEFT    LAST   PASSED   UNIT           ACTIVATES
n/a    n/a     n/a    n/a      fstrim.timer   fstrim.service

Conclusion

This service seems like the best way to run TRIM on your drives. It is much simpler than having to create your own crontab entry to call the fstrim command. It is also safer not having to edit the fstab file. It has been interesting to watch the evolution of solid-state storage technology and nice to know that it appears Linux is moving toward a standard and safe way to implement it.

grub定制

grub customizer

ppa

https://launchpad.net/~danielrichter2007/+archive/ubuntu/grub-customizer

grub显示菜单:

GRUB_TIMEOUT_STYLE设置为menu

 

局域网cups共享打印机

https://www.cups.org/doc/sharing.html

Printer Sharing

This document discusses several ways to configure printer sharing.

The Basics

A “server” is any machine that communicates directly to a printer. A “client” is any machine that sends print jobs to a server for final printing. Clients can also be servers if they communicate directly with any printers of their own.

By default, CUPS uses the Internet Printing Protocol (IPP) to send jobs from a client to a server. When printing to legacy print servers you may also use the Line Printer Daemon (LPD) protocol when printing to older UNIX-based servers or Server Message Block (SMB) when printing to Windows® servers.

Clients can automatically discover and access shared printers via DNS Service Discovery (DNS-SD a.k.a. Bonjour®). SMB browsing can also be used to manually discover and access shared printers when Samba is installed.

Configuring the Server

You must enable printer sharing on the server before clients can print through it. The simplest way to do this is to use the cupsctl(8) command on the server:

cupsctl --share-printers

By default, the above command will allow printing from other clients on the same subnet as your server. To allow printing from any subnet, use the following command instead:

cupsctl --share-printers --remote-any

How to force fsck to check filesystem after system reboot on Linux

原文:https://linuxconfig.org/how-to-force-fsck-to-check-filesystem-after-system-reboot-on-linux

This article will explain a procedure on how to force fsck to perform a filesystem check on the next system reboot or force filesystem check for any desired number of system reboots whether it is root or non-root mount point.

Let’s start with discussion about some tools which can be used to obtain filesystem information and configurations which control filesystem check after system reboot. The tool which we are going to discuss is tune2fs filesystem managing utility. Using tune2fs we can export some important information related to filesystem health check. The following linux command will tell as when was the last time the filesystem /dev/sdX was checked:

# tune2fs -l /dev/sdbX | grep Last\ c
Last checked:             Sun Dec 13 09:14:22 2015

Anther useful information which can be retrieved by tune2fs command relates to how many times our /dev/sdX filesystem was mounted:

# tune2fs -l /dev/sdbX | grep Mount
Mount count:              157

 

and lastly how many mounts are allowed to pass before filesystem check is forced:

# tune2fs -l /dev/sdbX | grep Max
Maximum mount count:      -1

From the above outputs we can establish the following information summary. The /dev/sdbX filesystem was last checked on Sun Dec 13 09:14:22 2015. Since the last check, this filesystem was mounted 157 times and maximum amount of mounts before next filesystem fsck check. In the above case the value -1 means that fsck is disabled.



Now, that we have learned about some tune2fs basics let’s discuss PASS system configuration option found in /etc/fstab file containing all on boot mountable partitions and their relevant mount options.

# blkid | grep sdb1
/dev/sdb1: UUID="c6e22f63-e63c-40ed-bf9b-bb4a10f2db66" TYPE="ext2"
# grep c6e22f63-e63c-40ed-bf9b-bb4a10f2db66 /etc/fstab
UUID=c6e22f63-e63c-40ed-bf9b-bb4a10f2db66 /mnt            ext2    errors=remount-ro 0      0

We have used blkid command to retrieve UUID for a given partition and then used the retrieved partition UUID to get a relevant information related to /dev/sdb1 partition from /etc/fstbab.
The last column that is a column 6, aka fsck PASS column is used by fsck to determine whether fsck should check filesystem before it is mounted and in which order given partitions in /etc/fstab should be checked. Possible entries for fstab PASS column are 0,1 and 2.

  1. 0 – disabled, that is do not check filesystem
  2. 1 – partition with this PASS value has a higher priority and is check first. This value is usually set to root / partition
  3. 2 – partitions with this PASS value will be checked last

The connection between fstab PASS value, last checked value and number of mounts value is as follows:
During the system boot the first value which is checked is fstab PASS value. If this value is 0 that not other values are checked ( exemption .. see “Force fsck for root partition” below ) and the fsck will NOT perform filesystem check. If the PASS value found in /etc/fstab is any other than 0, that is 1 or 2 then values of maximum mounts and total mounts are checked. If the value of maximum mounts is greater or equal to total number of mounts value then fsck’s filesytem check will be performed. Few examples:

FSCK DISABLED
fstab PASS: 1
Maximum mount count:      -1
Mount count:              157
----
FSCK DISABLED
fstab PASS: 0
Maximum mount count:      -1
Mount count:              157
----
FSCK ON NEXT REBOOT
fstab PASS: 1 or 2
Maximum mount count:      1
Mount count:              157
----
FSCK DISABLED
fstab PASS: 0
Maximum mount count:      1
Mount count:              1
----
FSCK ON NEXT REBOOT
fstab PASS: 1 or 2
Maximum mount count:      1
Mount count:              1
----
NO FSCK ON NEXT REBOOT
fstab PASS: 1 or 2
Maximum mount count:      200
Mount count:              157


Force fsck for root partition

The simplest way to force fsck filesystem check on a root partition eg. /dev/sda1 is to create an empty file called forcefsck in the partition’s root directory.

# touch /forcefsck

This empty file will temporarily override any other settings and force fsck to check the filesystem on the next system reboot. Once the filesystem is checked the forcefsck file will be removed thus next time you reboot your filesystem will NOT be checked again. To enable more permanent solution and force filesystem check on every reboot we need to manipulate filesystem’s “Maximum mount count” parameter. The following linux command will ensure that filesystem /dev/sdb1 is checked every time your Linux system reboots. Please note that for this to happen the fsck’s PASS value in /etc/fstab must be set to a positive integer as discussed above.

# tune2fs -c 1 /dev/sdb1

alternatively we can set fsck after every 10 reboots:

# tune2fs -c 10 /dev/sdb1

Force fsck for all other non-root partitions

As oppose to root partition creating empty forcefsck file will NOT trigger partition check on reboot. The only way to force fsck on all other non-root partitions is to manipulate filesystem’s “Maximum mount count” parameter and PASS value within /etc/fstab configuration file. To force filesystem check on non-root partition change fsck’s PASS value in /etc/fstab to value 2. For example:

UUID=c6e22f63-e63c-40ed-bf9b-bb4a10f2db66 /mnt            ext2    errors=remount-ro 0      2

and change maximum mounts filesystem parameter to a positive integer, depending on how many times you wish to allow a specified filesystem to be mounted without being checked. Force fsck on every reboot:

# tune2fs -c 1 /dev/sdb1

alternatively we can set fsck to check filesystem after every 5 reboots:

# tune2fs -c 5 /dev/sdb1

To disable fsck run:

# tune2fs -c 0 /dev/sdb1
OR
# tune2fs -c -1 /dev/sdb1

Which will set the filesystem’s “Maximum mount count” parameter to -1