output
stringlengths 9
26.3k
| input
stringlengths 26
29.8k
| instruction
stringlengths 14
159
|
---|---|---|
I don't work with OpenSuse, but as I know, there is no logs on trashcan.
But if content of a directory change, His modification time have to change too.
At all, there is a few possibility to restore something, but:You have to stop immediatly your disk activity (in root: mount -o remount,ro /home if /home is the mountpoint of partition)
You have to know what you want to restore, there is a few tools for doing that job, but you have to inform them about what to search for.
If / (root) is the partition to work on, you have to use another way, like live-usb in order to be able to work on read-only partition.
Preferably copy whole partition to another before of working on.Modifying Trashcan behaviour to ask him to make log is possible too, but this depend on which desktop environment you are using.
There are essentially two widely used file-manager:nautilus on gnome
konqueror on kdeI use nautilus. Running gconf-editor, searching for trash (including key names), there are no log, nor empty trash command. So if you're using gnome's nautilus, there are 2 ways:using inotify (inotifywait) for monitoring the gnome's trash directory, than moving every new entry to a hidden directory, before empty trash could be run by user.
patching nautilus from source for adding such a feature. (Or pay a programmer to do this) and send your modif to nautilus's maintener as a suggest.
|
I didn't lock the screen on my OpenSuse Linux and let my girlfriend do all evil things when I was sleeping. Is there a way to find out if she deleted any files from my PC?
I was looking at the "Date Modified" timestamp of my folders and then I tried to delete something and that date didn't change. I was also looking at logs in /var/log, but I don't know where exactly to look and also haven't found anything.
I think she deleted files by moving them to the trash can and then emptying the trash can and I think that this procedure will be in some log.
|
How to find last deleted files on OpenSuse?
|
This problem was actually being caused by having a .Trash-1000 folder on the external drive itself, with all the contents I was seeing in Nautilus within it.
In order to delete these files, I had to remount that drive as writable:
sudo mount -o remount,rw /partition/identifier /mount/pointAfter this point, I was able to rm -rf .Trash-1000/ on the drive, and the files were no longer visible as part of the Trash within Nautilus.
|
When browsing to trash:/// in Nautilus, I see a long list of files and directories that I recognize and remember placing in the trash. However, attempting to delete them from Nautilus either results in a Preparing message indefinitely, or an error message Error while deleting. You do not have sufficient permissions to delete the file "_____".
I've already emptied ~/.local/share/Trash/files as my regular user, and that directory does not exist as the root user.
I've downloaded the trash tool from the AUR to confirm my findings: running trash -l or trash -e as my regular user and root both confirm that the trash can is empty.
I can clearly see that it is not empty though. I'm able to browse through the directories using nautilus and open these files.
How can I locate these files in order to permanently delete them?
|
Nautilus shows files in Trash, can't be located on cli
|
The system doesn't seem to have an appropriate icon theme. End users who have installed from standard CD/DVD bootable image of any distro should not face this problem.
That "PDF icon"
No, that is not a "PDF icon" but rather a fallback icon provided by Xfce component (Xfdesktop). One way to discover this icon is to use find command with *fallback* as keyword.
$ find /usr/share/pixmaps/* -name *fallback*
/usr/share/pixmaps/xfdesktop/xfdesktop-fallback-icon.pngIn Debian or Ubuntu, user can also use dpkg command to search with fallback as keyword then use grep filter the result for appropriate file name extension (usually PNG image, hence .png).
$ dpkg --search fallback | grep .png
xfdesktop4-data: /usr/share/pixmaps/xfdesktop/xfdesktop-fallback-icon.pngExisting icon theme
To find out currently installed icon themes, run ls /usr/share/icons in Terminal. The following is example output for Xubuntu 14.04 (uses Xfce 4.10 with official Xubuntu icon theme and goodies).
$ ls /usr/share/icons
Adwaita gmusicbrowser.png mini
default gnome redglass
DMZ-Black handhelds ubuntu-mono-dark
DMZ-White hicolor ubuntu-mono-light
elementary-xfce HighContrast whiteglass
elementary-xfce-dark Humanity xchat.xpm
elementary-xfce-darker Humanity-Dark
elementary-xfce-darkest largeElse, run xfce4-appearance-settings and see "Icons" tab.
Additional icon theme
If Xfce was installed by minimal packages, which is without packages of recommends or suggests, then user must install any additional icon theme afterwards.
Depending on which icon theme user has installed, the trash can icon will appear differently. The following screenshot shows two icon themes in Xubuntu 14.04.The default icon theme in Xubuntu 14.04 with dark icon theme on panel is "elementary Xfce dark" (left) and another icon theme is "Humanity".
Although not shown above, Xfce uses an icon theme called "Tango". This is recommended by meta-package for Xfce desktop environment and is included by default in Debian Xfce.
Anyway, user should install any icon theme to see the trash can icon.
|
On the desktop in Xfce 4.10, the trash can icon seems to be replaced by a pdf icon.How can I replace it by a trash can icon?
|
How to obtain a trash can icon on the dektop (Xfce)
|
The problem is the ghost trash folder in this extra account. When you open Disk Usage Analyzer as a regular user you see a mismatch between the space occupied and what is shown in next screen. In the image below is shown a partition with 48.9 GB and with only 5.7 GB free.but when you click in the / folder the screen shown only 21.6 GB of space used and no information about /root/ folder.Opening Disk Usage Analyzer from the terminal as a superuser you can actually see what's inside the root folder, and you'll find a ghost trash folder full of files that you deleted some time ago and that somehow went into this ghost folder that doesn't get emptied.
su
baobab /root/You can empty this ghost folder with the command below in superuser mode
rm -r /root/.local/share/Trash/files/*and problem solved!
|
In Debian the /root/ directory is so big but du show nothing inside it. root account is just a supervisor/administrator/superuser user, there is no folder for this account in home directory. This extra account created just for supervision is installed by default in Debian.
|
du report wrong usage and root folder is so big
|
ffmpeg seems to have a new option -to in the documentation:-to position (input/output)
Stop writing the output or reading the input at position. position
must be a time duration specification, see (ffmpeg-utils)the Time
duration section in the ffmpeg-utils(1) manual.
-to and -t are mutually exclusive and -t has priority.Sample command with two time formats
ffmpeg -i file.mkv -ss 20 -to 40 -c copy file-2.mkv
ffmpeg -i file.mkv -ss 00:00:20 -to 00:00:40 -c copy file-2.mkvThis should create a copy (file-2.mkv) of file.mkv from the 20 second mark to the 40 second mark.
|
I have an FFmpeg command to trim audio:
ffmpeg -ss 01:43:46 -t 00:00:44.30 -i input.mp3 output.mp3The problem I have with this command is that option -t requires a duration (in seconds) from 01:43:46. I want to trim audio using start/stop times, e.g. between 01:43:46 and 00:01:45.02.
Is this possible?
|
Trim audio file using start and stop times
|
TRIM does at least three things:minimize write amplification
prevent long-term performance degradation
irrecoverably delete your dataNow it depends where your priorities are.
For 1), you should not be using fstrim at all, but make use of the discard option of your filesystem. Only if everything is trimmed instantly will the SSD stop copying no longer needed bits of data around. In practice though, it has been shown that preventing write amplification is not that important since SSD are fine with lots of writes.
For 2), using fstrim weekly or even monthly is completely fine. There is no need to use instant discard, or to trim daily - that would be a short-term measure, but this is about keeping the SSD happy in the long-term. But it also depends on your usage: if your filesystem is always full and sees lots of writes, you might need to trim more regularly than if you tend to have lots of free space and not that much writes in your filesystems.
For 3), you should not be using any kind of trim at all. Basically if you expect to be human, making errors, having accidents - like you just deleted your photo collection, whoops - recovery tools like photorec won't work after TRIM because with TRIM everything is gone forever.
From a pure data recovery point of view, SSD is a huge headache. There's too much trim happening in Linux, even without asking you (mkfs implies trim, lvremove/lvresize/... might if issue_discards, some partitioners might be having ideas, ...). Suddenly previously reversible actions become irreversible, all for the sake of getting a few more points in some filesystem benchmark...
If you decide on fstrim you should know where the cron job is located so you can disable it when you have an accident, that way you get a compromise between 2) and 3). In general with SSD you should make sure you have good backups, they are even more important than with HDD since you have lesser chance of recovery on SSD.
|
There are different sources and different practices are suggested. I found the following proposals how often one should run fstrim.run weekly by cron
run daily by cron
run at each bootWhat is the optimal option and why? Ubuntu 14.04 uses the first option by default.
|
SSD: how often should I do fstrim?
|
I suggest using a different testing method. hdparm is a bit weird as it gives device addresses rather than filesystem addresses, and it doesn't say which device those addresses relate to (e.g. it resolves partitions, but not devicemapper targets, etc.). Much easier to use something that sticks with filesystem addresses, that way it's consistent (maybe except for non-traditional filesystems like zfs/btrfs).
Create a test file: (not random on purpose)
# yes | dd iflag=fullblock bs=1M count=1 of=trim.test Get the address, length and blocksize: (exact command depends on filefrag version)
# filefrag -s -v trim.test
File size of trim.test is 1048576 (256 blocks, blocksize 4096)
ext logical physical expected length flags
0 0 34048 256 eof
trim.test: 1 extent foundGet the device and mountpoint:
# df trim.test
/dev/mapper/something 32896880 11722824 20838512 37% /mount/pointWith this set up, you have a file trim.test filled with yes-pattern on /dev/mapper/something at address 34048 with length of 256 blocks of 4096 bytes.
Reading that from the device directly should produce the yes-pattern:
# dd bs=4096 skip=34048 count=256 if=/dev/mapper/something | hexdump -C
00000000 79 0a 79 0a 79 0a 79 0a 79 0a 79 0a 79 0a 79 0a |y.y.y.y.y.y.y.y.|
*
00100000If TRIM is enabled, this pattern should change when you delete the file. Note that caches need to be dropped also, otherwise dd will not re-read the data from disk.
# rm trim.test
# sync
# fstrim -v /mount/point/ # when not using 'discard' mount option
# echo 1 > /proc/sys/vm/drop_caches
# dd bs=4096 skip=34048 count=256 if=/dev/mapper/something | hexdump -COn most SSD that would result in a zero pattern:
00000000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
*
00100000If encryption is involved, you will see a random pattern instead:
00000000 1f c9 55 7d 07 15 00 d1 4a 1c 41 1a 43 84 15 c0 |..U}....J.A.C...|
00000010 24 35 37 fe 05 f7 43 93 1e f4 3c cc d8 83 44 ad |$57...C...<...D.|
00000020 46 80 c2 26 13 06 dc 20 7e 22 e4 94 21 7c 8b 2c |F..&... ~"..!|.,|That's because physically trimmed, the crypto layer reads zeroes and decrypts those zeroes to "random" data.
If the yes-pattern persists, most likely no trimming has been done.
|
I tried to setup TRIM with LVM and dm-crypt on ubuntu 13.04 following this tutorial:
http://blog.neutrino.es/2013/howto-properly-activate-trim-for-your-ssd-on-linux-fstrim-lvm-and-dmcrypt/
See the notes about my configuration and my testing procedure below.
QuestionsIs there a reliable test if TRIM works properly?
Is my test routine wrong or is my TRIM not working?
If it's not working: what is wrong with my setup?
How can I debug TRIM for my setup and make TRIM work?Configuration
Here ist my configuration:
cat /etc/crypttab
sda3_crypt UUID=[...] none luks,discardand
cat /etc/lvm/lvm.conf
# [...]
devices {
# [ ... ]
issue_discards = 1
# [ ... ]
}
# [...]The SSD is a Samsung 840 Pro.
Here is my test-procedure
To test the setup I just did sudo fstrim -v / which resulted in
/: [...] bytes were trimmed
Doing this again resulted in /: 0 bytes were trimmed which seems to make sense and indicated that TRIM seems to work.
However then I did this test:
dd if=/dev/urandom of=tempfile count=100 bs=512k oflag=direct
sudo hdparm --fibmap tempfile tempfile:
filesystem blocksize 4096, begins at LBA 0; assuming 512 byte sectors.
byte_offset begin_LBA end_LBA sectors
0 5520384 5521407 1024
524288 5528576 5529599 1024
1048576 5523456 5525503 2048
2097152 5607424 5619711 12288
8388608 5570560 5603327 32768
25165824 5963776 5980159 16384
33554432 6012928 6029311 16384
41943040 6275072 6291455 16384
50331648 6635520 6639615 4096sync
sudo hdparm --read-sector 5520384 /dev/sda /dev/sda:
reading sector 5520384: succeeded
7746 4e11 bf42 0c93 25d3 2825 19fd 8eda
bd93 8ec6 9942 bb98 ed55 87eb 53e1 01d5
c61a 3f52 19a1 0ae5 0798 c6e2 39d9 771a
b89f 3fc5 e786 9b1d 3452 d5d7 9479 a80d
114a 7528 a79f f475 57dc aeaf 25f4 998c
3dd5 b44d 23bf 77f3 0ad9 8688 6518 28ee
81db 1473 08b5 befe 8f2e 5b86 c84e c7d2
1bdd 1065 6a23 fd0f 2951 d879 e823 021b
fa84 b9c1 eadd 9154 c9f4 2ebe cd70 64ec
75a8 4d93 c8fa 3174 7277 1ffb e858 5eca
7586 8b2e 9dbc ab12 40ab eb17 8187 e67d
5e0d 0005 5867 b924 5cfd 6723 9e4a 6f5f
99a4 a3b0 eeac 454a 83b6 c528 1106 6682
ca77 4edf 2180 bf0c b175 fabb 3d4b 37e2
b834 9e3e 82f2 2fdd 2c6a c6ca 873f e71e
f979 160f 5778 356f 2aea 6176 46b6 72b9
f76e ee51 979c 326b 1436 7cfe f677 bfcd
4c3c 9e11 4747 45c1 4bb2 4137 03a1 e4c8
e9dd 43b4 a3b4 ce1b d218 4161 bf64 727b
75d8 dcc2 e14c ebec 2126 25da 0300 12bd
6b1a 28b3 824f 3911 c960 527d 97cd de1b
9f08 9a8e dcdc e65f 1875 58ca be65 82bf
e844 50b8 cc1b 7466 58b8 e708 bd3d c01f
64fb 9317 a77a e43b 671f e1fb e328 93a9
c9c7 291c 56e0 c6c1 f011 b94d 9dc7 71e6
c8b1 5720 b8c9 b1a6 14f1 7299 9122 912b
312a 0f2f a31a 8bf9 9f8c 54e6 96f3 60b8
04a7 7dc9 3caa db0a a837 e5d7 2752 b477
c22d 7598 44e1 84e9 25d4 5db5 9f19 f73b
85a0 c656 373a ec34 55fb e1fc 124e 4674
1ba8 1a84 6aa4 7cb5 455e f416 adc6 a125
c4d4 8323 4eee 2493 2920 4e38 524c 1981sudo rm tempfile
sync
sudo fstrim /
sync
sudo hdparm --read-sector 5520384 /dev/sda/dev/sda:
reading sector 5520384: succeeded
7746 4e11 bf42 0c93 25d3 2825 19fd 8eda
bd93 8ec6 9942 bb98 ed55 87eb 53e1 01d5
c61a 3f52 19a1 0ae5 0798 c6e2 39d9 771a
b89f 3fc5 e786 9b1d 3452 d5d7 9479 a80d
114a 7528 a79f f475 57dc aeaf 25f4 998c
3dd5 b44d 23bf 77f3 0ad9 8688 6518 28ee
81db 1473 08b5 befe 8f2e 5b86 c84e c7d2
1bdd 1065 6a23 fd0f 2951 d879 e823 021b
fa84 b9c1 eadd 9154 c9f4 2ebe cd70 64ec
75a8 4d93 c8fa 3174 7277 1ffb e858 5eca
7586 8b2e 9dbc ab12 40ab eb17 8187 e67d
5e0d 0005 5867 b924 5cfd 6723 9e4a 6f5f
99a4 a3b0 eeac 454a 83b6 c528 1106 6682
ca77 4edf 2180 bf0c b175 fabb 3d4b 37e2
b834 9e3e 82f2 2fdd 2c6a c6ca 873f e71e
f979 160f 5778 356f 2aea 6176 46b6 72b9
f76e ee51 979c 326b 1436 7cfe f677 bfcd
4c3c 9e11 4747 45c1 4bb2 4137 03a1 e4c8
e9dd 43b4 a3b4 ce1b d218 4161 bf64 727b
75d8 dcc2 e14c ebec 2126 25da 0300 12bd
6b1a 28b3 824f 3911 c960 527d 97cd de1b
9f08 9a8e dcdc e65f 1875 58ca be65 82bf
e844 50b8 cc1b 7466 58b8 e708 bd3d c01f
64fb 9317 a77a e43b 671f e1fb e328 93a9
c9c7 291c 56e0 c6c1 f011 b94d 9dc7 71e6
c8b1 5720 b8c9 b1a6 14f1 7299 9122 912b
312a 0f2f a31a 8bf9 9f8c 54e6 96f3 60b8
04a7 7dc9 3caa db0a a837 e5d7 2752 b477
c22d 7598 44e1 84e9 25d4 5db5 9f19 f73b
85a0 c656 373a ec34 55fb e1fc 124e 4674
1ba8 1a84 6aa4 7cb5 455e f416 adc6 a125
c4d4 8323 4eee 2493 2920 4e38 524c 1981This seems to indicate that TRIM doesn't work. Since
sudo hdparm -I /dev/sda | grep -i TRIM
* Data Set Management TRIM supported (limit 8 blocks)
* Deterministic read ZEROs after TRIMEdit
Here is the output of sudo dmsetup table
lubuntu--vg-root: 0 465903616 linear 252:0 2048
lubuntu--vg-swap_1: 0 33308672 linear 252:0 465905664
sda3_crypt: 0 499222528 crypt aes-xts-plain64 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0 8:3 4096 1 allow_discardsHere is my /etc/fstab:
# <file system> <mount point> <type> <options> <dump> <pass>
/dev/mapper/lubuntu--vg-root / ext4 errors=remount-ro 0 1
# /boot was on /dev/sda2 during installation
UUID=f700d855-96d0-495e-a480-81f52b965bda /boot ext2 defaults 0 2
# /boot/efi was on /dev/sda1 during installation
UUID=2296-2E49 /boot/efi vfat defaults 0 1
/dev/mapper/lubuntu--vg-swap_1 none swap sw 0 0
# tmp
tmpfs /tmp tmpfs nodev,nosuid,noexec,mode=1777 0 0 Edit:
I finally reported it as a bug in https://bugs.launchpad.net/ubuntu/+source/lvm2/+bug/1213631
Hope somebody will find a solution there or at least test the setup and verify the bug.
Update
Now it works, see accepted answer.
|
Trim with LVM and dm-crypt
|
You can combine GNU tail and head:
tail -c +26 file | head -c -2will output the contents of file starting at byte 26, and stopping two bytes (minus two -2) before the end. (-c operates on bytes, not characters.)
|
I have a file, that has trash (binary header and footer) at the beginning and end of the file. I would like to know how to nuke these bytes. For an example, let's assume 25 bytes from the beginning. And, 2 bytes from the end.
I know I can use truncate and dd, but truncate doesn't work with a stream and it seems kind of cludgey to run two commands on the hard file. It would be nicer if truncate, knowing how big the file was, could cat the file to dd. Or, if there was a nicer way to do this?
|
How do I trim bytes from the beginning and end of a file?
|
If you have a recent enough version of util-linux, it contains the tool blkdiscard which is able to TRIM entire devices, or ranges within a device using --offset and --length options.
Please note: blkdiscard is dangerous, if you let it TRIM the wrong regions, your data is gone!
So you can figure out the unpartitioned (free) regions of your partition table and then TRIM them using this tool. For msdos and gpt partitions, parted provides the free regions like so:
# parted -m /dev/sda unit b print free | grep ':free;'
1:17408B:1048575B:1031168B:free;
1:64022904832B:64023240191B:335360B:free;Add a loop to it...
while IFS=: read -ra FREE
do
echo blkdiscard --offset ${FREE[1]%%B} --length ${FREE[3]%%B} /dev/sda
done < <(parted -m /dev/sda unit b print free | grep ':free;')which prints
blkdiscard --offset 17408 --length 1031168 /dev/sda
blkdiscard --offset 64022904832 --length 335360 /dev/sdaVerify that this output is correct for you, add additional options if you like (verbose?), and finally remove the echo so it will be actually executed, and you should be set.
The second command of that example actually fails because the length is too small - it may be worth checking inside the loop, ignore regions smaller than 1MB as they're unlikely to be successfully trimmed.If you are using LVM instead of partitions, you can create a LV for the unoccupied space and trim that:
lvcreate -l100%FREE -n blkdiscard SSD-VG
blkdiscard -v /dev/SSD-VG/blkdiscard
lvremove SSD-VG/blkdiscardIf you set issue_discards = 1 in your lvm.conf, you can skip the blkdiscard call as LVM will issue the TRIM on lvremove by itself.
|
I have a drive (SD card) with a few ext4 partitions but also some unallocated space. The fstrim utility can only work within a filesystem. Before I reinvent the wheel and write one, is there another utility that can TRIM the unallocated space (or that can TRIM an explicitly specified range)?
I can verify that the majority of the unallocated space on the device is not currently known to be free by the controller, as I've observed that, on this particular card, reads to trimmed space return 0's, but a scan of the device shows plenty of garbage data left over.
Edit: I am having an issue using hdparm. The example below discards the first sector, but I am seeing the same results regardless of the range I specify. fstrim has no issues on the device:
root@ubuntu:~# hdparm --please-destroy-my-drive --trim-sector-ranges 0:1 --verbose /dev/mmcblk0 /dev/mmcblk0:
trimming 1 sectors from 1 ranges
outgoing cdb: 85 0d 06 00 01 00 01 00 00 00 00 00 00 40 06 00
outgoing_data:
00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00ioctl(fd,SG_IO): Invalid argument
FAILED: Invalid argumentI am investigating further but does anybody have any insight?
|
Utility to TRIM unallocated space on drive
|
You can check the device’s maximum discard sizes, e.g.
$ cat /sys/block/X/queue/discard_max_hw_bytes(replacing X as appropriate).
If this shows a value greater than 0, the device supports discards:A
discard_max_hw_bytes value of 0 means that the device does not
support discard functionality.The maximum supported discard size is indicated by discard_max_bytes in the same directory; this can be smaller than the hardware-supported value to limit discard latencies (and can be written to to change the limit):While discard_max_hw_bytes is the hardware limit for the
device, this setting is the software limit. Some devices exhibit
large latencies when large discards are issued, setting this
value lower will make Linux issue smaller discards and
potentially help reduce latencies induced by large discard
operations.This works on many different block devices, not just disks: loop devices, device mapper devices, etc.
|
fstrim requires the Linux block device to be mounted, and it is not very verbose. blkdiscard could tell, but also that would require a write operation.
Can I somehow tell if a block device supports trimming/discarding, without actually trying to trim/discard something on it?
|
How can I tell if a Linux block device is trimmable or not?
|
TRIM is a command that needs to be sent for individual blocks. I have asked the question before (What is the recommended way to empty a SSD?) and it is suggested to use ATA Secure Erase, a command that is sent to the device to clear all data.
|
Will a standard fresh linux (Ubuntu 11.10 to be exact) install and drive re-format (full) successfully TRIM my SSD, or do I need to do something extra?
I know that ext4 will TRIM blocks on erase when I specify the discard option, but I want to start with a completely TRIMmed drive if possible.
|
Will formatting my drive TRIM my SSD?
|
Two things here:fstrim trims all the data that is unallocated in the filesystem (well, not really all the data, only the data blocks that are not allocated, I don't think the unused parts of the inode table or the parts of not-completely used blocks are trimmed), regardless of whether discard is in used or not. fstrim cannot know which of those unallocated blocks have been "trimmed" or not already in the past, but it (actually the kernel, all the fstrim work is done in the FITRIM ioctl) does however keep track of which block group have been trimmed and will not trim them again if there hasn't been any unallocation in that block group since then, unless you're requesting a FITRIM with a smaller minimum extent length (from checking the ext4 code, it may be different for other file systems) which explains why you get 0 on the next run.
Note that it doesn't harm to trim a block that has already been trimmed. That's just telling the SSD again that it can do whatever it wants with it (like erase it so it can be ready to use again for something else).In df output, the "available" value doesn't take into account the space that is "reserved" for root, you'll notice that 206 - 76 is 130G, not 118G. 12G (about 5%) are reserved. See tunefs -m to change how much is reserved.
|
When I installed my SSD I just mounted with discard and didn't sweat it. However today I was reading about the pros and cons of using fstrim instead and decided to run the program to get an idea of how long it would actually take (still with my partitions mounted with discard). The command took several minutes on both my root and home partitions. For my home partition I used -v and got this:
$ sudo fstrim -v /home
/home: 137494052864 bytes were trimmedThis is more than the amount of free space on the partition!
$ df -h /home
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 206G 78G 118G 40% /homeSubsequent runs finish in less than a second, eg:
$ sudo fstrim -v /home
/home: 0 bytes were trimmedSurely if I have always had the partition mounted with discard, fstrim should not trim a large amount of data like that? The discard option is definitely enabled, here are the relevant fstab lines:
UUID=xxxxxxxx... / ext4 noatime,discard,errors=remount-ro 0 1
UUID=xxxxxxxx... /home ext4 noatime,discard,errors=remount-ro 0 2And mount output lines:
/dev/disk/by-uuid/xxxxxxxx... on / type ext4 (rw,noatime,discard,errors=remount-ro,stripe=128,data=ordered)
/dev/sda2 on /home type ext4 (rw,noatime,discard,errors=remount-ro,stripe=128,data=ordered)The SSD is a TOSHIBA THNSNS256GMCP. Why does this happen?
|
fstrim trims more than half of partition size even though partition mounted with discard
|
as @meuh pointed out in the comment, I need to run the test on my EXT4 partition, while I tried it on my /tmp
SOLVED!
PS: following the test result, I can confirm that the drive on my XPS 9343 (Samsung PM851 M.2 2280 256GB, firmware revision: EXT25D0Q) supports TRIM command, even if dmesg reports NCQ Send/Recv Log not supported
|
I have Linux installed on a Dell XPS 9343 with an Samsung PM851 SSD.
I recently read that many SSDs don't support TRIM operations.
So I'd like to check if discard option effectively works on my system.
At first step, I tried to simply run sudo fstrim --verbose --all and it reported 41GB trimmed; this makes me fear because I was expecting a really little value because I have the continuously TRIM enabled (see above); in fact, if I re-run that command again I get O bytes trimmed. Is it normal? even if I have the discard option in the /etc/fstab?
PS: I tried to follow the proposed solution here but it stucks on the second command due to trim.test: FIBMAP unsupported.
PS2: it's a flat SSD (no LVM or RAID) with GPT and EXT4 filesystem
|
How do I check TRIM?
|
You are losing the spaces when you expand $line. Put double quotes around your variable expansion and you'll preserve the spaces:
$ cat dept.dat | while read line
> do
> echo "$line"
> echo "$line" | cut -c 12-29"
> done
department: customer service section: A
customer service
department: marketing section: A
marketing
department: finance section: A
finance
|
I have a data file, the content is as follows:
department: customer service section: A
department: marketing section: A
department: finance section: AWhen I read each line, I would extract the department name using cut command. Unfortunately, the program will automatically trim all redundant space and thus I cut the department name incorrectly.
cat dept.dat | while read line
do
echo $line
echo $line | cut -c 12-29
donee.g. the original line is:
department: marketing section: AWhile the program treats this line as:
department: marketing section: AHow can I read the line without trimming all the redundant space?
|
Unix: how to read line's original content from file
|
If the filesystem is mounted with discard, then deleting files will automatically cause the TRIM command to be issued. This often has a negative performance impact, so it's generally better not to use that mount option and to instead run fstrim periodically, which will work as long as all the block device layers support it (for example, if you're using LUKS for encryption, you'll need to use cryptsetup --allow-discards). Unless you use this mount option, the TRIM command will not be automatically sent by the filesystem driver when you unlink files.
You could also try mounting with nodiscard. Although this is the default and usually unnecessary, it is possible that your filesystem had continuous TRIM support added to its default options set through tune2fs -o discard /dev/sda1. You can remove it with tune2fs -o ^discard /dev/sda1.
You might be able to find out what the issue is by using the debugfs utility to first list the actual blocks within a file before you delete it, and then directly access those blocks after deletion to see if they have been zeroed or return undisturbed but unallocated data.
Here's a shell script to test whether debugfs can read the contents of a deleted file using its block number:
#!/bin/shfile=test_file
echo "Current date: $(date)" > "$file"; sync
# Get the device of our test file, for example "/dev/sda1"
device=$(df -P "$file" | awk 'END{print $1}')
# The block of the file's contents, stat gets the inode number
block=$(sudo debugfs -R "blocks <$(stat -c %i "$file")>" "$device")
rm $file; sync
# Read the contents of the deleted file, -D bypasses the buffer cache
sudo debugfs -D -R "block_dump $block" "$device"
|
I was wondering whether mounting an SSD using the discard option (documented in man mount) is actually required for ATA TRIM to be sent to the SSD's controller.
The evidence is a bit circumstantial: Whether or not I mount a partition with discard on a SanDisk SSD PLUS, deleted files can't be restored by running TestDisk moments after the deletion. File paths are intact, but file content is gone. From this I suspect that TRIM ran on the SSD and made the file contents irrecoverable.
Looking at systemctl list-timers, there doesn't seem to be a unit that runs fstrim.
Does the kernel send TRIM after file deletion although the partition is not mounted with discard? Or is it another reason why TestDisk reliably can't restore files from the SSD?I'm on Arch Linux 5.12.3.
findmnt tells me this about the partitions and their mount options:
TARGET SOURCE FSTYPE OPTIONS
/ /dev/sda3 ext4 rw,relatime
└─/sda1 /dev/sda1 ext4 rw,relatime,lazytime,discard
|
Is mounting with "discard" needed for TRIM?
|
Sure, just give it more output files:
ffmpeg -i input.mp3 -ss S -to E -c copy output1.mp3 -ss S -to E -c copy output2.mp3 …Options after the input file actually pertain to the output file (so the -c, -ss and -to options are for the output file). And you can have multiple output files.
(Unlike the segments muxer, you can have overlapping output this way if you want. Or different codecs, or metadata. But @Gyan's answer with the segment muxer is easier if its restrictions are OK for you).
|
So far I have been using the following command to split an audio file from S to E:
ffmpeg -i input.mp3 -ss S -to E -c copy output.mp3Due to the fact that I need to split an audio file into multiple segments, each having a different length, I have to use the above command multiple times for only a single file.
So, is there a way to split a single audio file into multiple segments using ffmpeg, but using only a single command?
Note that the segments are not of the same length.
|
Trim an audio file into multiple segments using `ffmpeg` with a single command
|
Yes, as it is visible the manual of the swapon command, it has a discard option. It would be meaningless if the linux swap wouldn't support it. Of course the underlying device should support trimming.
|
The question appears if we want to use a swap partition on an SSD drive. I think, it would be better (for the SSD) if the deallocated swap space could be trimmed, because trimming the not used blocks enables the underlying SSD electronics to tune its wear leveling.
Google seems silent on the matter.
Alternatively, a regular blkdiscard command (and re-creating the swap space with mkswap) would be a feasible workaround, although it would be sub-optimal.
|
Do Linux swap partitions support trimming?
|
jpegtran can't losslessly cut at any finer increment than the Minimum Coded Unit size, which varies depending on the channel and the chroma sampling mode. It's going to be 8×8, 16×8, or 16×16.
This means the minimum cut size must be an even multiple of 8 or 16, depending on the way the image was encoded. The exceptions are the right and bottom edge when the image dimensions are not an even multiple of 8 or 16px. In that case, you have partial blocks on the right and/or bottom edges. For example, a 17×17 pixel image could have 1px cut from its right or bottom edges, but not 2px from those edges, nor 1px from the top and left edges.
Anything else requires re-encoding of the cut blocks.
Quoting from the manual:...lossless crop is restricted by the current JPEG format: the upper left corner of the selected region must fall on an iMCU boundary. If this does not hold for the given crop parameters, we silently move the upper left corner up and/or left to make it so, simultaneously increasing the region dimensions to keep the lower right crop corner unchanged. (Thus, the output image covers at least the requested region, but may cover more.)
|
I have a 1400x1400 image in which I want to trim 4 pixels to the left, 1 at the bottom and, to keep square proportions, 3 from the top. The problem is, whenever I perform a crop with jpegtran, pixels get removed from the bottom-right, no matter what I do. For instance, testing just the left part, I tried:
jpegtran -perfect -crop 1396x1400+0+0 -outfile crop.jpg image.jpgbut that just removes 4 pixels from the right;
jpegtran -perfect -crop 1396x1400-4+0 -outfile crop.jpg image.jpgand that again removes 4 pixels from the right;
jpegtran -perfect -crop 1396x1400+4+0 -outfile crop.jpg image.jpgand that does not remove any pixels at all; more in general,
jpegtran -perfect -crop 1396x1400+x+0 -outfile crop.jpg image.jpgjpegtran -perfect -crop 1396x1400-x+0 -outfile crop.jpg image.jpgwith x between 0 and 4, does respectively remove 4-x and x pixels from the right. With x higher than 5, obviously gives an error. I couldn't achieve any left trim. Can anyone help me?
I'm using jpegtran from libjpeg-turbo version 1.4.2 (build 20151205) on an Arch Linux x86_64 system.
|
jpegtran - losslessly crop left portion of image
|
Just use --assume-clean and don't even sync in the first place.
Once you create your RAID, the first thing you do is mkfs... and mkfs TRIMs by default without even asking (unless you use -E nodiscard or similar) and your RAID sync is already gone at this point anyway.
Basically it's impossible to keep a mixed SSD+HDD RAID in sync as long as TRIM affects only one side. Even with SSD+SSD RAID, a TRIM will likely cause differences if it's different SSD models or different partition offsets.
It's not a problem as long as it only affects "free space". The actual data itself will still be in sync and thus redundancy is provided.
If the SSD ever fails or you decide to replace the HDD with another SSD later on, that's where you get the full sync on SSD since that's the only way md knows how to do things. md does not record TRIM commands and thus remember "free" regions to speed up syncing; it is also not smart enough to TRIM (and thereby zero) the target SSD and only write non-zero data. Maybe when SSD become more common such features will be added to speed up resyncs.
Even so it's not something you should worry too much about; TRIM is a long-term measure, your filesystem will see TRIM during regular use, so over time even a fully written SSD will see enough trimmed areas.
|
I need to configure a RAID-1 on one SSD and one HDD. Both SSD and HDD has some preinstalled software, which I don't need so both can be fully wiped if that is any advantage.
My research so far lead me to the --write-mostly option, which I understand that I should be using on the HDD such that read operations will get the full speed of the SSD.
But it is not clear to me, how to ensure the TRIM command is properly used.
I read warnings about mdadm writing to every sector of the device during setup leaving the SSD with no spare sectors regardless of any TRIM performed before setting up the raid.
Am I better off first creating the RAID degraded with the SSD as the only device and then adding the HDD, such that only the HDD gets written to?
What would I need to do to the SSD before setting up the RAID, such that any needed TRIM has been performed? The SSD has preinstalled software (that I don't need), which means I don't know which sectors has been previously written.
In case it is of any relevance, the SSD is 128GB and is in dmesg output mentioned as SAMSUNG MZ7LF128HCP-00000, FXT0101Q by the ata layer and SAMSUNG MZ7LF128 101Q PQ by the sd layer.
|
Configuring a mdadm RAID-1 on SSD and HDD
|
I don't know if ext4 actually stores it anywhere. Other filesystems certainly don't.
ext4 avoids what it already trimmed in the current session only - while it's still mounted. Once you reboot or re-mount the filesystem, it just TRIMs empty space all over again.
So this could be an in-memory structure that isn't stored at all. I didn't dive into the very fine source code to find out.
A little test:
# truncate -s 1G /dev/shm/foobar.img
# losetup --find --show /dev/shm/foobar.img
/dev/loop9
# mkfs.ext4 /dev/loop9
# mkdir /mnt/loopGiven a 1G filesystem, let's mount and trim it:
# mount /dev/loop9 /mnt/loop/
# fstrim -v /mnt/loop
/mnt/loop: 973.4 MiB (1020678144 bytes) trimmed
# fstrim -v /mnt/loop
/mnt/loop: 0 B (0 bytes) trimmedSo it first trims all... that alone is already suspicious, after all: mkfs already trimmed too (ouch), so it should know it's still empty and trimmed, right? Well, if it knows, it doesn't care:
# umount /mnt/loop
# mount /dev/loop9 /mnt/loop
# fstrim -v /mnt/loop
/mnt/loop: 973.4 MiB (1020678144 bytes) trimmedSo after re-mount, it just trims all free space again.
When creating and deleting files, it's not pinpoint precision either:
# dd bs=1M count=10 if=/dev/zero of=/mnt/loop/zerofile
10+0 records in
10+0 records out
10485760 bytes (10 MB, 10 MiB) copied, 0.0124641 s, 841 MB/s
# sync
# rm /mnt/loop/zerofile
# fstrim -v /mnt/loop
/mnt/loop: 117.5 MiB (123203584 bytes) trimmedSo, writing 10M causes a re-trim of 117M. It just doesn't mean anything.
Only the SSD itself really knows what's currently trimmed and what not, and when asked to trim an already trimmed area, it should simply do nothing. So no harm done and no need to really store this information in the filesystem.
|
It is recommended to enable a TRIM cron job which run once every week.
When the fstrim command is called the filesystem will sent TRIM information to the drive to discard deleted data (I hope I get it right)
So far so good, this is described many places.
But I cannot find any information about how/where those TRIM information are "stored" in the filesystem between the fstrim commands?
And can those TRIM information be "cleared" in some way so the SSD will not get the information of all the pages/blocks that has to be discarded?
Or will the fstrim command compare the filesystem and the SSD in regards to which data is actually deleted?
|
How does the filesystem (ext4) "store" TRIM information?
|
It is a common misunderstanding to worry about the sizes reported by fstrim.
It really doesn't mean anything. Just ignore it.
fstrim just issues the appropriate ioctl, everything else is the decision of the filesystem, and filesystems behave very differently. For example, ext4 tries to avoid trimming the same things over and over, so you will see 0 bytes trimmed. xfs doesn't care and trims everything that's free, so you'll always see <roughly free space> bytes trimmed. Other filesystems may do other things, it all depends on how the filesystem chose to implement the FITRIM syscall logic, if it's implemented at all.
As long as the amount of data trimmed is not larger than free space, you should be fine regardless of what fstrim (the filesystem, really) reports.
In the end only the SSD itself really knows what's currently trimmed and what not. Trimming already trimmed blocks does not cause any harm whatsoever.
Don't make conclusions based on x bytes trimmed as reported by fstrim.
If you want to verify that data was trimmed, you have to check raw data on the disk. ( https://unix.stackexchange.com/a/85880/30851 ) but that method might not work for btrfs, I have never tried.
|
I have an SSD disk with several partitions. One of them is has a btrfs volume, mounted as /home, which holds an ecryptfs home directory.
When I trim the volumes, it seems that fstrim doesn't trim data blocks on such volume - why? Below you can see all the informations about the setup, and the procedure I follow, with comments.
$ cat /etc/fstab:
UUID=xxx / ext4 errors=remount-ro 0 1
UUID=yyy /media/vfio ext4 defaults 0 2
UUID=zzz /home btrfs defaults 0 2$ mount | grep sda:
/dev/sda5 on / type ext4 (rw,relatime,errors=remount-ro,data=ordered)
/dev/sda1 on /media/vfio type ext4 (rw,relatime,stripe=32721,data=ordered)
/dev/sda2 on /home type btrfs (rw,relatime,ssd,space_cache,subvolid=5,subvol=/)$ ls -la /home /home/myuser/.Private # summary:
/home:
.ecryptfs
myuser/home/myuser/.Private -> /home/.ecryptfs/myuser/.Private$ df -h:
Filesystem Size Used Avail Use% Mounted on
/dev/sda5 16G 11G 4,7G 69% /
/dev/sda1 93G 52G 36G 60% /media/vfio
/dev/sda2 828G 542G 286G 66% /home
/home/myuser/.Private 828G 542G 286G 66% /home/myuserI execute fstrim on all the volumes, for the first time.
$ fstrim -va:
/home/myuser: 286,4 GiB (307518836736 bytes) trimmed
/home: 286,4 GiB (307485450240 bytes) trimmed
/media/vfio: 40,4 GiB (43318886400 bytes) trimmed
/: 5,4 GiB (5822803968 bytes) trimmedIt seems that fstrim runs twice on the /home tree, due to the additional ecryptfs mount. This would be ok (I could avoid it by running an fstrim with specific mountpoints). The problem is that trimming /home is not working as expected, as each run finds and trims the same amount of data.
This is shown by a further run.
$ fstrim -v / (this is ok):
/: 0 B (0 bytes) trimmed$ fstrim -v /home (this isn't ok):
/home: 286,4 GiB (307478061056 bytes) trimmedNote that the sda2 (/home) trimming takes some time to run, so it's actually doing something.
|
Why fstrim appears not to trim data blocks on btrfs (+ecrypts)?
|
I finally found the time to try the answer suggested by @Mario G., but it seemed extremely cumbersome. I need to do this many dozens of times. I read the documentation of ffmpeg and found it much more powerful than avconv, including fading for audio and video, so the solution is
ffmpeg -i input.mts -map 0:0 -map 0:3 -ss 0:0:07 -to 0:59:57.5 -vf 'fade=t=in:st=7:d=2,fade=t=out:st=3595.5:d=2,crop=out_h=692' -af 'afade=t=in:st=7:d=2,afade=t=out:st=3595.5:d=2' out.movSo the st= and d= parameters for the fade take times in seconds, no need for converting to frames.
I also discovered the -to option to take the end time directly instead of calculating the length.
This command does all stepschannel selection with -map,
trimming with -ss and -to,
video fading with -vf option fade=t=in and fade=t=out,
audio fading with -af option afade=t=in and afade=t=out and
cropping with -vf option crop=in a single step.
|
I'm using avconv for trimming and converting videos. Let's say I want to drop the first 7 and last 2.5 seconds of the video stream and one audio stream of an one-hour mts file:
avconv -i input.mts -map 0:0 -map 0:3 -ss 0:0:07 -t 0:59:50.5 out.movThis works so far, but now I want to add two seconds of fading in and out at the beginning and the end by adding:
-vf fade=type=in:start_frame=350:nb_frames=100 -vf fade=type=out:start_frame=178750:nb_frames=100Those frames are calculated with the 50 fps that avconv reports for the video source. But there is neither fading in nor out.
1) What goes wrong with the video fading and how to do it right?
2) How to add audio fading. There seems to be an -afade option. but I don't find it documented.
Alternatively, you can propose a different tool for this goal (trim and fade video and audio), preferrably available as package for Debian 8.
|
trim and fade in/out video and audio with avconv (or different tool)
|
MB_wrtn increased 102574 MB. Does that mean fstrim is writing 102574 MB = 100.2 GB to my disk ?Yes, it means exactly that. fstrim essentially looks at every single block of your block device and decides if the block is being used by the filesystem (that is, contains important data):block is in use: ignore it.
block is not in use: send an ATA TRIM command for this block to the underlying block device.When it's done, the amount of trimmed blocks should always be equivalent to the free space on the filesystem. fstrim TRIMs each free block every time you run it, regardless if it already has been TRIMmed in the past, so it won't become faster if you run it more often.
The kernel probably considers the TRIM command like a write command, so every executed TRIM command counts as a 4k write command.Trim is supposed to "mark" the pages that do not contain valid data, not writing them."Marking" blocks as trimmed is equivalent to "writing" them, because their contents change. If you'd accidentally TRIM the wrong block, you would lose data - just as writing zeros to the wrong block causes you to lose data.
|
I have a new samsung ssd in my new notebook. I tuned up everything to avoid writings in the disk (firefox profiles and /var/log in memory), I'm using a ext4 fs with relatime and I use fstrim once a day to TRIM my ssd.
I monitor disk load with iostat -dhm. Before running fstrim the command iostat shown
Device: tps MB_read/s MB_wrtn/s MB_read MB_wrtn
sda
4.97 0.05 0.59 1856 20924after trimming /home
# fstrim -v /home
/home: 100.2 GiB (107555401728 bytes) trimmedìostat shows
Device: tps MB_read/s MB_wrtn/s MB_read MB_wrtn
sda
5.91 0.05 3.51 1859 123498MB_wrtn increased 102574 MB.
Does that mean fstrim is writing 102574 MB = 100.2 GB to my disk ?
Trim is supposed to "mark" the pages that do not contain valid data, not writing them.
I guess iostat saw the operation made by fstrim as writing (even if it is not a writing). What do you think? Is there a better way to monitor my disk?
Note: Using iotop is not an answer, because it doesn't show the amount of data of processes that were killed. Thus, iotop measurement
is inexact.
|
fstrim and iostat
|
You're looking for fallocate's FALLOC_FL_PUNCH_HOLE. It's then up to the filesystem to discard/trim/unmap those blocks. I believe ext4 will do so.
For example, you'd do something like this to discard 2MiB starting 1MiB in:
err = fallocate(fd, FALLOC_FL_PUNCH_HOLE|FALLOC_FL_KEEP_SIZE, 1048576, 2097152);
if (0 != err) {
/* handle error */
}On success, future reads of those bytes should give 0s.
[Note: POSIX doesn't have a way to do this. The above fallocate is Linux-specific. But you tagged your question Linux, so hopefully that's OK.]
|
For an SSD, I can open the row device and discard a range of pages using ioctl() with BLKDISCARD command.
My question is
for an open file, how to discard a range of data? and Is that depends on the implementation of the underlying filesystem?
|
How to discard/TRIM a range in an open file ?
|
fstrim should run on "mountpoint", so you need to have devices mounted. But you only need to call it once per physical device. So if 2 mountpoints are on the same device with btrfs, you only need to call fstrim on one mountpoint.
Finding this answer:
https://forums.gentoo.org/viewtopic-t-1003980-view-previous.html?sid=a51dab49787e5b7b6c2fa4aa7c1a5e44
I do it like this :
#!/bin/sh
LOG=/var/log/fstrim.log
echo "===" $(date -R) "===" >> $LOG
for d in $(lsblk -o MOUNTPOINT,FSTYPE | grep -E 'btrfs' | awk '{print $1}'); do
fstrim -v $d 2>&1 >> $LOG
doneThis script is placed in /etc/cron.weekly/fstrim and set executable:
sudo chmod +x /etc/cron.weekly/fstrimThe script makes use of lsblk that list block devices. I'm searching "btrfs" devices and I launch fstrim on it.
|
I am using btrfs and have mounted several subvolumes (but not btrfs root). It resides on SSD partition, so I would like to use fstrim. Should I call fstrim on each mountpoint (corresponding with different subvolume each) ? Or do I need to have btrfs root mounted and run fstrim on this mountpoint?
|
How to run SSD trim fstrim on btrfs when mounted multiple subvolumes?
|
I found the solution.
I tried fstrim with explicit statements of the partitions as a weekly cronjob shortly after I posted the answer but didn't know whether it was safe. Furthermore, I didn't know whether someone would have a better answer. Therefore, I didn't post it as an answer myself.
I just looked at the contents of the folder /etc/cron.weekly where I placed a file containing the command because I wanted to execute it manually after filling my entire disk with data today and having deleted a lot of it a few minutes ago. I didn't remember the command, so I just went where I put it. However, after executing ll I found 2 files with names leading me to believe that it was my script.
The other file wasn't put there by me so it's almost certainly delivered with Ubuntu. It's called fstrim and these are its contents:
#!/bin/sh
# trim all mounted file systems which support it
/sbin/fstrim --all || trueAfter deleting my own script, I executed the script which came with Ubuntu because its clearly better. It felt like it took about a minute to execute which is what I'd expect from it trimming 36 GB. When I executed it a second time, it returned immediately, indicating that it did actually trim the first time.
I already sha256summed all the files in my home folder before trimming the first time, sha256summed all of them after the first trim, and found no unexpected changes (well, obviously, the contents of ~/.cache and ~/.mozilla changed as I used Firefox in the meantime) when comparing the files containing the sha256sums via Meld. I therefore concluded that it's probably safe.
|
I have a Samsung PRO Series SSD. Linux deactivates Trim for this SSD because it deletes the wrong data when asynchronous Trim is used (firmware bug).
Is it possible to activate synchronous Trim for it without activating asynchronous Trim, too?
My laptop in which I use this SSD only runs 1 operating system: Ubuntu 16.04. It's a LTS system so it only runs LTS kernels. The currently kernel is 4.4.0-57-generic.
Regarding firmware updates: A lot of users report that the firmware update failed for them. Furthermore, Samsung only offers its update software for Windows for the SSD I have. Its Linux version only supports certain business SSDs, the Windows version only certain consumer SSDs. Unfortunately, I don't have business SSD (and no Windows installation which I'm frankly rather glad about, most of the time). There seems to be a way to do the update anyways but it's rather hacky. To top it all off, I don't even know whether the firmware update fixes the problem.
|
Enabling Synchronous TRIM Only
|
Your Ubuntu is running inside a kvm virtual machine with AMD-Vi so it should not be running fstrim.
The fstrim service runs on a timer so as root:
rm /var/lib/systemd/timers/stamp-fstrim.timer
systemctl stop fstrim.service fstrim.timer
systemctl disable fstrim.service fstrim.timer
systemctl mask fstrim.service fstrim.timer
|
I have a Linux (Ubuntu 18, kernel 4.15) desktop booting from an M2 nvme disk.
Once a week, it will crash around midnight. The relevant log file output from /var/log/syslog.* is below:Jul 16 00:00:00 rabbitcruncher systemd[1]: Starting Discard unused blocks...
Jul 16 00:00:00 rabbitcruncher kernel: [559644.954267] nvme 0000:41:00.0: AMD-Vi: Event logged [IO_PAGE_FAULT domain=0x0014 address=0x0000000000000000 flags=0x0000]
Jul 16 00:00:00 rabbitcruncher kernel: [559644.975805] nvme nvme0: async event result 00010300
Jul 16 00:00:30 rabbitcruncher kernel: [559675.338834] nvme nvme0: controller is down; will reset: CSTS=0x3, PCI_STATUS=0x1010
Jul 16 00:00:31 rabbitcruncher kernel: [559675.621182] nvme 0000:41:00.0: AMD-Vi: Event logged [IO_PAGE_FAULT domain=0x0014 address=0x0000000000000000 flags=0x0000]
Jul 16 00:01:01 rabbitcruncher kernel: [559706.346300] nvme nvme0: controller is down; will reset: CSTS=0x3, PCI_STATUS=0x1010
Jul 16 00:01:01 rabbitcruncher kernel: [559706.378641] nvme nvme0: Identify namespace failed
Jul 16 13:39:24 rabbitcruncher systemd-fsck[962]: /dev/nvme0n1p1: 12 files, 1186/130812 clusters
Jul 16 13:39:24 rabbitcruncher kernel: [ 1.052853] nvme nvme0: pci function 0000:41:00.0
Jul 16 13:39:24 rabbitcruncher kernel: [ 1.285806] nvme0n1: p1 p2
Jul 16 13:39:24 rabbitcruncher kernel: [ 5.036910] EXT4-fs (nvme0n1p2): mounted filesystem with ordered data mode. Opts: (null)
Jul 16 13:39:24 rabbitcruncher kernel: [ 5.318742] EXT4-fs (nvme0n1p2): re-mounted. Opts: errors=remount-roI understand the "Discard unused blocks" means that Linux is trying to run fstrim. However, I have disabled fstrim using systemctl but it still happens!systemctl status fstrim.service
● fstrim.service - Discard unused blocks
Loaded: loaded (/lib/systemd/system/fstrim.service; static; vendor preset: enabled)
Active: inactive (dead)I'm at a loss for what to do to fix this problem. Could anyone offer advice?
|
nvme fstrim causing crash on linux, disabling with systemctl doesn't help
|
On Linux the following would work:
xsel | sed ':rep /-$/ {N; s/-\n//; b rep}' | xsel -iOn OSX I am largely guessing (although the sed script should work ok). pbcopy seems to the the command to use. Assuming there is a selection buffer on OSX and pbcopy works from it by default, this might work:
pbpaste | sed ':rep /-$/ {N; s/-\n//; b rep}' | pbcopyLooking at the online man page, it seems there are a number of 'pasteboards' that it can work with:
-pboard {general | ruler | find | font}
specifies which pasteboard to copy to or paste from. If no pasteboard is
given, the general pasteboard will be used by default.I have no idea which one (if any) is the one you want and I can't see any further documentation (although I haven't looked too deep). You could experiment with pbpaste -pboard xxx and see what comes out. There is a good chance one is for highlighted text while the other is for text copied with Cmd-C. Given a working option, you would just add it to both pbpaste and pbcopy.
The other thing that may go wrong is that pbcopy has issues reading and writing to the same pasteboard in at the same time. The simplest solution would be to use a non standard Unix utility called sponge. It is part of moreutils. Again Linux-centrically:
pbpaste | sed ':rep /-$/ {N; s/-\n//; b rep}' | sponge | pbcopyOtherwise use a variable:
selection=$(pbpaste | sed ':rep /-$/ {N; s/-\n//; b rep}')
echo "$selection" | pbcopyUpdate
Assuming Automator uses the stdout of the shell script, you would just select the to stdin option (this is where the data arrives if it is piped to the script). The the shell script would simply be:
#!/bin/sh
sed ':rep /-$/ {N; s/-\n//; b rep}'
|
I'm running Mac OS 10.9 and I use the Text to Speech feature which allows you to use a hotkey that reads selected text in any application. I use this feature for reading out-loud PDF documents in Preview (Apple's PDF viewer).
The problem is that the selected text usually has word-break hyphens. The result is the Text to Speech feature doesn't read out the text properly.
Example:Question:
Can you write me a short bash shell script that removes hyphens from the text in the clipboard? I will use automator too, so I can assign a hotkey, and to send the script's output to the Speak Text feature.
Edit: (in reply to goldilocks's comment) Automator allows me to copy selected text to the clipboard followed by a shell script followed by the Speak Text feature. See image below.2nd Edit: in fact there might be a more concise way of accomplishing this:under the 'Pass input' option there is a 'as argument' option. I'm not sure whether this means I can skip the 'copy to clipboard' action in the first image, but I thought I'd mention it just in case.
|
fetch clipboard text and remove hyphens
|
\1 is the right syntax for referring to capture group 1; \\1 means you want the literal text \1. So change \\1 to \1, and then you need to put parentheses around the part you actually want to capture. This should work:
sed -i 's@id="</b>\([[:digit:]]\+\)<b>"@id="\1"@g' ~/edit.txt
|
I have some text like:
Blablabla <b>[intlink id="</b>2204<b>" type="page"] BlalalaI want replace it for remove the </b> and <b>, keeping the id="number". So it should result like:
Blablabla <b>[intlink id="2204" type="page"] BlalalaI try with:
sed -i 's@id="</b>[[:digit:]]\+<b>"@id="{1}"@g' ~/edit.txt
Blablabla <b>[intlink id="{1}" type="page"] BlalalaAlso I try with:
sed -i 's@id="</b>[[:digit:]]\+<b>"@id="\\1"@g' ~/edit.txtBut I get:
Blablabla <b>[intlink id="\1" type="page"] BlalalaSo, how I can keep the id number text in the regex digit?
|
Sed: replace text keeping digit occurrence
|
It turned out, LUK2 can permanently store metadata in the header.
It is possible to enable allow-discards and store in the partition itself (without any further configuration -e.g., kernel parameters) with the command:
cryptsetup --allow-discards --persistent refresh rootEvidently, I issued this command in the past enabling the discarding option.
It is possible to remove the flag with:
cryptsetup --persistent refresh roothttps://man7.org/linux/man-pages/man8/cryptsetup.8.htmlRefreshing the device without any optional parameter will refresh
the device with default setting (respective to device type).
|
I have the following partition table:
NAME
nvme0n1
├─nvme0n1p1 part /boot
└─nvme0n1p2 part
└─crypt crypt
├─crypt-swap lvm [SWAP]
├─crypt-root lvm /
└─crypt-home lvm /homeAs the drive is an SSD, I would like to perform TRIM command in order to increase performance/lifetime of the disk itself.
In particular, I would like to enable periodic TRIM.
Because the second partition (i.e., nvme0n1p2) is encrypted, TRIM will be inhibited because of security implications (https://wiki.archlinux.org/title/Dm-crypt/Specialties#Discard/TRIM_support_for_solid_state_drives_(SSD)).
However, it is possible to enable TRIM on encrypted partition by configuring encrypt on the opening.
As I my partition is opened at kernel boot, I've modified kernel parameters (i.e., allow-discards):
cryptdevice=/dev/sdaX:root:allow-discards(Note that the partition naming and volume name are not relevant in the above snippet.).
By doing that, I was indeed successfully able to run TRIM command on the disk:
# cryptsetup luksDump /dev/nvme0n1p2 | grep Flags
Flags: allow-discardsAnd:
# fstrim ...
/home: [..] trimmed on ...
/: [..] trimmed onSo far, so good.The problem arose when I tried to restore to the original state.
I have removed the kernel parameter allow-discards, but Flags on partition still shows allow-discards and fstrim command successfully complete its job.How is that possible?
How to restore denying of discards on the encrypted partition?
|
Disable allow-discards on encrypted partition
|
So apparently because swap is not considered as a normal filesystem, it will not be trimmed when fstrim is run manually. But it appears that the Linux kernel does the trimming for the swap when it is mounted automatically when the underlying device supports the operation. This is referenced in the Fedora project docs:The Linux swap code will issue TRIM commands to TRIM-enabled devices, and there is no option to control this behaviour. One can also see it in the kernel code itself here. So I am not sure how it interacts with encryption but I assume that swap trimming doesn't require any additional configuration (eg in fstab) as long as /etc/crypttab and lvm.conf are set up as in the question above which enables trimming on the LUKS and LVM levels.
|
I have set up an encrypted swap partition following this guide. My /etc/crypttab is set up like this (note the discard option on swap):
rootfs UUID=<UUID_root> none luks,discard
swap UUID=<UUID_swap> /dev/urandom swap,offset=2048,cipher=aes-xts-plain64,size=512,discardI also have allow_discards=1 in /etc/lvm/lvm.conf. However, when I do a manual trim, the swap doesn't trim:
#sudo /sbin/fstrim -av
/media/win: 670.4 GiB (719872700416 bytes) trimmed
/boot/efi: 221.8 MiB (232525824 bytes) trimmed
/boot: 291 MiB (305152000 bytes) trimmed
/: 221.7 GiB (237996343296 bytes) trimmedhow do I make it trim?On a related note, why is /media/win being trimmed? This is a NTFS partition on a hard drive (not SSD) automounted by Linux so why is TRIM enabled on a hard drive? In fact, when I print lsblk -D, I have /dev/sda (my HDD) showing non-zero values for DISC_GRAN and DISC_MAX, indicating that TRIM is enabled. Why is that?
|
fstrim does not trim swap
|
Yes. I concluded this for myself for reasons described in this answer.
|
I updated the firmware of my Samsung 840 Pro to the newest version (DXM06B0Q). This SSD (along with many other Samsung SSDs) had a bug where it deletes arbitrary data if asynchronous TRIM is used. Can I now enable TRIM safely?
|
Is TRIM on Samsung 840 Pro with firmware version DXM06B0Q safe?
|
If you use discard, you don't need fstrim.timer, which basically means "automatically run fstrim for you from time to time". discard does not "continue" anything, it just means that TRIM would be triggered when files are deleted.
In other words, if certain files were deleted while the filesystem is mounted with nodiscard, the logical blocks that were used by them will not be TRIM'd even if you mount the filesystem with discard later (unless some new files that were made to "re-use" those logical blocks are now being deleted as well).
fstrim on the other hand, regardless of being run from a timer or manually by you, would tell the filesystem driver that all the logical blocks that are not currently used can be TRIM'd.
That's why you may want to run fstrim once before (after is fine too) you start using discard. Or blkdiscard before (after is not fine) you format the partition. (Many mkfs programs would by default trigger the equivalent anyway though.)
|
It used to be that properly enabling TRIM for SSDs on Linux involved two steps:Running fstrim once, to take care of all the "untrimmed" blocks to date, then
Setting the discard flag in fstab (so the trimming would continue).I'm a little behind the times. Now I'm seeing things about an fstrim.timer service that is included in newer Linux distributions, and I'm seeing conflicting information about which combination of fstrim.timer, fstrim, and discard to use.
My question is, on modern Linuxes (modern at the time of this writing), what's the preferred way to enable TRIM on an SSD? Is it just to enable fstrim.timer and let it do its thing? Is the usage of the discard flag no longer necessary?
If it matters I'm specifically interested in Ubuntu >= 22 (Jammy) and Debian >= 10 (Buster).
|
Correct way to enable TRIM on recent Debian/Ubuntu
|
To check the status of TRIM timer
sudo systemctl status fstrim.timerYou would get something like this:
● fstrim.timer - Discard unused blocks once a week
Loaded: loaded (/lib/systemd/system/fstrim.timer; enabled; vendor preset: enabled)
Active: active (waiting) since Mon 2022-01-10 06:36:56 CET; 31min left
Trigger: Mon 2022-01-17 00:00:00 CET; 6 days left
Triggers: ● fstrim.service
Docs: man:fstrimTo disable the periodic TRIM (TRIM timer)
sudo systemctl disable fstrim.timerAfter reboot, you will get the status as follows:
● fstrim.timer - Discard unused blocks once a week
Loaded: loaded (/lib/systemd/system/fstrim.timer; disabled; vendor preset: enabled)
Active: inactive (dead)
Trigger: n/a
Triggers: ● fstrim.service
Docs: man:fstrimTo manually invoke TRIM (on all mounted FS)
sudo fstrim --allFurther reading:fstrim man page #1
fstrim man page #2
Does SSD Trim actually increase the lifespan? (Quora)
|
I rarely ever write anything (large) to SSDs on many machines of my own, an example could be the use of one laptop as a TV viewer only, another my mother's laptop, which she uses just for banking. (If it matters, I use Linux Mint on all machines.)
Therefore it comes as annoying the weekly TRIM, as it takes a rather long time. But how to disable it?
|
How to disable TRIM on SSD(s) under Linux Mint?
|
$ awk -F"/" '!seen[$1]++ {print $1}' findint.txt
Eth1
Eth101
Eth103
Gi0To get the output all in one comma-separated line, you could set the output separator ORS to , however you'd need to make a special case for the the last value; a simpler way is to pipe the output of awk to paste:
awk -F"/" '!seen[$1]++ {print $1}' findint.txt | paste -sd,
|
Trying to do the following,
I have txt file which as the data of the interfaces.
Eth1/15 desc01 1
Eth101/1/11 desc01 1
Eth101/1/16 desc01 1
Eth103/1/21 desc01 1
Eth1/2 desc01 1
Eth1/24 desc01 1
Eth103/1/5 desc01 1
Gi0/1 desc01 1
Gi0/0/1 desc01 1
Gi0/1/1 desc01 1Wanted to find out the common Interface type
Expected results:
If / contains twice then count the matching, else just Gi0 or Eth1
Eth1, Eth101/1, Eth103/1, Gi0, Gi0/0, Gi0/1
I tried using the AWK, what but not getting the results.
cat findint.txt | egrep 'Eth|Gi' | awk -F"/" '{print $1}'
I tried following
cat findint.txt | egrep 'Eth|Gi' | \
awk '{print substr($1, 0, length($1)-2)}' | sort -u
Results, some values are repeated which I don't.
Expected Results:
Eth1, Eth101/1, Eth103/1, Gi0, Gi0/0, Gi0/1
|
Group items from column using awk
|
BTRFS supports multiple devices, so what you can do is use btrfs fi show to get the list of block devices. Then use cryptsetup status to check if a given device is a LUKS container. If it is the command will output the underlining device.
I wouldn't call this script-friendly, since you'll have to parse the output, but it should work.
|
I'm running Arch Linux (systemd) on several systems. Some have SSD storage, others have nvme storage devices and some use rotational HDD's. Some systems use dm-crypt to encrypt the filesystem. All systems run btrfs on /.
I wish to have a bash script determine the physical device which hosts the root filesystem (/). The purpose is to check if that block device supports trim, and if so, to then take some action if fstrim.timer is not enabled on the system.
If we know that / is on /dev/sda for example, we can check hdparm -I /dev/sda | grep TRIM to find out if trim is supported. If so, I can do systemctl enable fstrim.timer.
But on an encrypted system, / is reported as being on /dev/mapper/cryptoroot or something similar, and I am not finding a script-friendly way to map that back to the physical block device (e.g., /dev/sda) to determine if it supports trim.
My understanding is that SSD's generally benefit from having periodic trim run, while NVMe devices may not.
For non-encrypted situations, these questions are relevant:
How do I find on which physical device a folder is located?
Find out what device /dev/root represents in Linux?
https://unix.stackexchange.com/a/431968/15010
|
Find physical block device of root filesystem on an encrypted filesystem?
|
Official docs state: https://www.virtualbox.org/manual/ch08.html#vboxmanage-storageattach
VBoxManage storageattach <UUID> --nonrotational:This switch allows to enable the non-rotational flag for virtual hard disks. Some guests (i.e. Windows 7+) treat such disks like SSDs and don't perform disk fragmentation on such media.VBoxManage storageattach <UUID> --discard:This switch enables the auto-discard feature for the virtual hard disks. This specifies that a VDI image will be shrunk in response to the trim command from the guest OS. The following requirements must be met:
The disk format must be VDI.
The size of the cleared area must be at least 1MB.
VirtualBox will only trim whole 1MB blocks. The VDIs themselves are organized into 1MB blocks, so this will only work if the space being TRIM-ed is at least a 1MB contiguous block at a 1MB boundary. On Windows, occasional defrag (with "defrag.exe /D"), or under Linux running "btrfs filesystem defrag" as a background cron job may be beneficial.
Notes: the Guest OS must be configured to issue trim command, and typically this means that the guest OS is made to 'see' the disk as an SSD. Ext4 supports -o discard mount flag; OSX probably requires additional settings. Windows ought to automatically detect and support SSDs - at least in versions 7, 8 and 10. Linux exFAT driver (courtesy of Samsung) supports the trim command.
It is unclear whether Microsoft's implementation of exFAT supports this feature, even though that file system was originally designed for flash.
Alternatively, there are ad hoc methods to issue trim, e.g. Linux fstrim command, part of util-linux package. Earlier solutions required a user to zero out unused areas, e.g. using zerofree, and explicitly compact the disk - only possible when the VM is offline.So storage defined as:
<AttachedDevice discard="true" nonrotational="true" type="HardDisk">with FS like Ext4 / Btrfs / JFS / XFS / F2FS / VFAT mounted with -o discard should work...
UPDATE TRIM support in VirtualBox is still unstable: https://www.virtualbox.org/ticket/16795
See also https://superuser.com/questions/646559/virtualbox-and-ssds-trim-command-support
|
I like to use dynamically allocated images in VirtualBox.
It is preferred way if you like to distribute you image (remember Vagrant?).
What Linux FS can reclaim unused blocks to VirtualBox when dynamically allocated image is used?
I saw that users run:
sudo dd if=/dev/zero of=/EMPTY bs=1M || : ; rm -f /EMPTYto shrink VDI images.
Also we all know about TRIM ATA command for SSD drives (discard option for mount)...
|
What FS can reclaim unused blocks to VirtualBox when dynamically allocated image is used?
|
Finally found out that I was issuing the wrong command on receiver's side.
Receive command shall be : cat < /dev/ttyUSB0 > file_b64
Summary
To receive from remote :
Host side | Remote side
|
| #Encode to base64
| cat file | base64 > file_b64
|
| #Send after timeout
| (sleep 10; cat file_b64 > /dev/ttyS0) &
|
#############################################################
### Exit minicom but keep configuration (ctrlA-Z, then Q) ###
#############################################################
|
#Receive file |
cat < /dev/ttyUSB0 > file_b64 |
|
#Decode file |
cat file_b64 | base64 -di > file |
|
I have an embedded Linux on a custom board and I would like to send and receive file over its serial port.
The only way to communicate with this device is over serial and the device offers a console on this serial port.
This board doesn't have kermit neither busybox rx nor lrzsz.
- Sending file to remote
I was able to send file to the board following this thread.
Host side Remote sidecat file | base64 > file_b64
cat > file_b64
minicom's ctrlA-S => send 'file_b64'
cat file_b64 | base64 --decode > file- Getting file from remote
Now I would like to retrieve a file from remote system.
Minicom has a tool for receiving files but as I only have the serial port's console using minicom to issue commands on remote side, I can't find how to do it.
I have tried using kermit on host side but it seems that I also needs to have kermit on the remote side.EDIT:
I have also tried to reverse the sending method but with no success as i receive nothing from serial port on host side.
Host side Remote side cat file | base64 > file_b64
(sleep 10; cat file_b64 > /dev/ttyS0) &
minicom's ctrlA-X => exit minicom
cat /dev/ttyUSB0 > file_b64Can't use minicom's receive tool cause it only support xmodem, ymodem, zmodem and kermit tranfers and not ascii.Is there a way to retrieve files from remote without having to type commands into its console?
|
Retrieve file over serial without kermit and lrzsz
|
I'm quite confident the problem is that the Pi does not have an RS232 interface, while the display has.
The Pi has an (LV-)UART interface, its TX-pin outputs 0V for a logical 0 and 3.3V for a logical 1. This is quite easy to implement, since 3.3V is already available on the Pi. But this only works for communications on a single PCB or within a single device.
For communication between devices over longer distances, a system less prone to interfering signals like RS232 is used. While the logical structure of the waveform (bitrate, timing, start-, stop-, parity- and data-bits) is the same as for UART, the voltage levels are -15V...-3V for a logical 1 and +15V...+3V for a logical 0. This means, there are not only higher (and negative) voltages, their meaning is also inverted.
So, if the display expects RS232 levels and gets that 3.3V levels from the Pi, it mostly doesn't recognize the data, and if it does, it's often just garbage.
And of course, if you connect RX and TX of the same interface, you get what you expect.
But: If the RS232 TX output is not current limited, it could even damage your Pi!
There are UART to RS232 converter boards out there, but if you like to solder, the boards just contain a MAX3232 (plus four capacitors). This IC also generates the higher (and negative) voltage levels from the 3.3V supply voltage from the Pi.
The more common is the MAX232 (guess why it's called so), but it is for 5V, not 3.3V operation.Finally, because the UART and the RS232 use the same logical structure, it's often not distinguished between both of them, especially by software (programmers). They are often also just called "serial interface", though there are other interfaces like I²C and SPI, which are a type of serial interface, but never considered to be "the" serial interface.
|
I have a Display that I want to write to. This is possible over the serial port. When I use a USB to RS-232 Converter, that thing works like a charm. I even tried using only the RX, TX and GND wires of the serial converter, and it still works. Now I want to use this Display in a small case paired with a Raspberry Pi, so i don't have any space left for the big USB-RS-232 converter.
I have tried using the internal serial port of the Raspberry. It is set to 9600 baud using $ sudo stty -F /dev/ttyAMA0 9600. But when I connect it to the display, it only shows up garbage and normal control-commands (that were working using the RS-232 converter) don't work either.
Using $ sudo minicom -b 9600 -o -D /dev/ttyAMA0 and looping the GPIOs TX to RX, it shows up the right characters in the minicom console.
Now looping the GPIO-Serial-Port to the USB-RS-232 Converter's RX and TX pins and connecting ground and opening both ports in minicom with baud set to 9600, only sometimes shows some output on the other terminal, but when it shows any output, it is also just garbage.
|
RaspberryPi serial port
|
The solution is to modify /etc/ttys on the guest. On amd64, it has the following defaults:
#
# $FreeBSD: head/sbin/init/ttys.amd64 338454 2018-09-04 15:48:13Z brd $
# @(#)ttys 5.1 (Berkeley) 4/17/89
#
# This file specifies various information about terminals on the system.
# It is used by several different programs. Common entries for the
# various columns include:
#
# name The name of the terminal device.
#
# getty The program to start running on the terminal. Typically a
# getty program, as the name implies. Other common entries
# include none, when no getty is needed, and xdm, to start the
# X Window System.
#
# type The initial terminal type for this port. For hardwired
# terminal lines, this will contain the type of terminal used.
# For virtual consoles, the correct type is typically xterm.
# Other common values include dialup for incoming modem ports, and
# unknown when the terminal type cannot be predetermined.
#
# status Must be on or off. If on, init will run the getty program on
# the specified port. If the word "secure" appears, this tty
# allows root login.
#
# name getty type status comments
#
# If console is marked "insecure", then init will ask for the root password
# when going to single-user mode.
console none unknown off secure
#
ttyv0 "/usr/libexec/getty Pc" xterm onifexists secure
# Virtual terminals
ttyv1 "/usr/libexec/getty Pc" xterm onifexists secure
ttyv2 "/usr/libexec/getty Pc" xterm onifexists secure
ttyv3 "/usr/libexec/getty Pc" xterm onifexists secure
ttyv4 "/usr/libexec/getty Pc" xterm onifexists secure
ttyv5 "/usr/libexec/getty Pc" xterm onifexists secure
ttyv6 "/usr/libexec/getty Pc" xterm onifexists secure
ttyv7 "/usr/libexec/getty Pc" xterm onifexists secure
ttyv8 "/usr/local/bin/xdm -nodaemon" xterm off secure
# Serial terminals
# The 'dialup' keyword identifies dialin lines to login, fingerd etc.
ttyu0 "/usr/libexec/getty 3wire" vt100 onifconsole secure
ttyu1 "/usr/libexec/getty 3wire" vt100 onifconsole secure
ttyu2 "/usr/libexec/getty 3wire" vt100 onifconsole secure
ttyu3 "/usr/libexec/getty 3wire" vt100 onifconsole secure
# Dumb console
dcons "/usr/libexec/getty std.9600" vt100 off secureAs you can see, the status of every ttyu terminal device is set to onifconsole secure (the secure part is irrelevant here). It means that this those terminal devices are only turned on if they act as a console. In order to make it possible to access those devices from the host we just need to replace onifconsole with onifexists.
In my particular case, I had to replace the following line:
ttyu1 "/usr/libexec/getty 3wire" vt100 onifconsole securewith:
ttyu1 "/usr/libexec/getty 3wire" vt100 ifexists secureAs a result, it is now possible to connect to the guest system using the second console:
# cu -l /dev/nmdm1A
Password:
Connected
FreeBSD/amd64 (testvm) (ttyu1)
login: root
Password:
Last login: Fri Jun 26 19:59:40 on ttyu1
FreeBSD 12.1-RELEASE r354233 GENERIC
Welcome to FreeBSD!
|
Background
I'm running FreeBSD 12.1-RELEASE as a host for bhyve virtual machines.
I have a FreeBSD 12.1-RELEASE guest running inside a VM. I would like to have two TTY-class devices configured for it.
According to the manual page, in order to start the VM with two TTY-class devices I have to start bhyve with command-line options similar to those: -l com1,/dev/nmdm0B -l com2,/dev/nmdm1B. Then I should be able to connect to the guest via those two nullmodem terminals with cu -l /dev/nmdm0A and cu -l /dev/nmdm1A.
Problem
The first command works as expected: cu -l /dev/nmdm0A shows me the main console of the guest.
The second command, however, attaches to the guest, but shows nothing. I would expect to show me a login prompt as if switched to another TTY.
What am I missing?Additional detailsThe guest is a fresh installation of FreeBSD.The output of dmesg | grep uart on the guest is as follows:
uart0: <16550 or compatible> port 0x3f8-0x3ff irq 4 flags 0x10 on acpi0
uart0: console (115200,n,8,1)
uart1: <16550 or compatible> port 0x2f8-0x2ff irq 3 on acpi0I've tried setting hint.uart.1.flags first to 0x10 and then to 0x80 (although this one is for kernel debuggers from what I understand from uart(4)) and rebooted after each change. It didn't work.Referenceshttps://bsdjhb.blogspot.com/2018/10/using-bhyve-for-freebsd-development.html
https://gist.github.com/landonf/d00a15ede7d5ccb0e371
|
How to active the second console to a FreeBSD guest running in bhyve?
|
You can certainly put an intervening socat in the way, and use its logging facilities. For example,
socat -v /dev/ttyUSB0,b19200,raw PTY,link=$HOME/myserial,raw,echo=0 2>logfile &
minicom -p $(readlink $HOME/myserial)This will log the data read in each direction, shown by ">" or "<":
< 2017/07/14 14:33:58.210584 length=3 from=0 to=2
hi
> 2017/07/14 14:33:58.214745 length=3 from=0 to=2
hi
|
I am currently trying to log all communication from and to /dev/ttyUSB0 and simultaneously be able to connect minicom/screen to the same device for interaction.
I tried a couple of tools and tutorials but they all seem to occupy the device, so I can not connect to it with a terminal program.
Then I came across socat. It sounds promising, though it is able to redirect the /dev/ttyUSB0 to a PTS and log the transfered data to a file.
The idea is:
HW - /dev/ttyUSB0 <---> socat/logging <---> /dev/ptyX <---> minicom
Has anyone done this before?
Any help is appreciated.
Chris
|
socat - UART logging and redirecting
|
My config on Orange Pi Zero for UART on mainline kernel:
overlay_prefix=sun8i-h3
overlays=usbhost2 usbhost3 uart1 uart2Both UARTs work fine.
$ uname -a
Linux orangepizero 4.13.16-sunxi #20 SMP Fri Nov 24 19:50:07 CET 2017 armv7l armv7l armv7l GNU/Linux
|
I want to use UART1 or 2 (see picture) on the Orange Pi zero. But when I try to open the port with screen /dev/ttyS1
Screen terminates.
I found here that I needed to add "overlays=sun8i-h3-uart1" in /boot/armbianEnv.txt but someone on that forum said that that feature is not yet supported. I tried, but I still have the same problem.
Any suggestions?uname -a
Linux orangepizero 4.11.9-sun8i #1 SMP Thu Jul 13 16:09:43 CEST 2017
armv7l armv7l armv7l GNU/Linux
|
How to use UART pins on Orange Pi zero?
|
I'm sure someone is still doing this, but back in the days before stuff like ILO/DRAC/etc. became cheap and ubiquitous, the best way to get "out of band" access to the console in case of emergencies or an oops was over the serial port. You would mount a Terminal Server in the rack, then run cables to the serial port of your servers. Some BIOSs supported console redirection to the serial port (for example VA Linux and SuperMicro servers in the 1999+ timeframe).
The 8250/16550 UARTS were some of the most popular serial port chips at the time, meaning that they would be the best supported under Linux, and all of them used the 8250 kernel driver (there were many more models in that series that all used the same driver).
I suspect that a lot of SoC designs intended to be used by linux built 8250/16550 compatible UARTs into them because it was the easy button--well documented and a well tested driver. Although hopefully they built the later multibyte buffer versions (of course even "slow" processors by todays standards can service a serial interrupt far more often than a 115k serial port can receive it). IIRC the Mac had a serial port used for Local/Apple Talk (Can't remember which was the protocol and which was the hardware) that did 248k. Still, that was back when CPUs did 60Mhz.
This is probably the best answer for the difference between MMIO and Port I/O: https://en.wikipedia.org/wiki/Memory-mapped_I/O I don't understand that level well enough to boil it down.
The above link will probably answer what is for these purposes, but basically it's a memory address.
|
I first found this by investigating parameters for earlycon but found that the options for console look almost identical. Both are present below and were taken from this source:
From documentation for console we have:
console= [KNL] Output console device and options. tty<n> Use the virtual console device <n>. ttyS<n>[,options]
ttyUSB0[,options]
Use the specified serial port. The options are of
the form "bbbbpnf", where "bbbb" is the baud rate,
"p" is parity ("n", "o", or "e"), "n" is number of
bits, and "f" is flow control ("r" for RTS or
omit it). Default is "9600n8". See Documentation/serial-console.txt for more
information. See
Documentation/networking/netconsole.txt for an
alternative. uart[8250],io,<addr>[,options]
uart[8250],mmio,<addr>[,options]
uart[8250],mmio16,<addr>[,options]
uart[8250],mmio32,<addr>[,options]
uart[8250],0x<addr>[,options]
Start an early, polled-mode console on the 8250/16550
UART at the specified I/O port or MMIO address,
switching to the matching ttyS device later.
MMIO inter-register address stride is either 8-bit
(mmio), 16-bit (mmio16), or 32-bit (mmio32).
If none of [io|mmio|mmio16|mmio32], <addr> is assumed
to be equivalent to 'mmio'. 'options' are specified in
the same format described for ttyS above; if unspecified,
the h/w is not re-initialized. hvc<n> Use the hypervisor console device <n>. This is for
both Xen and PowerPC hypervisors. If the device connected to the port is not a TTY but a braille
device, prepend "brl," before the device type, for instance
console=brl,ttyS0
For now, only VisioBraille is supported.From documentation for earlycon we have:
earlycon= [KNL] Output early console device and options. When used with no options, the early console is
determined by the stdout-path property in device
tree's chosen node. cdns,<addr>
Start an early, polled-mode console on a cadence serial
port at the specified address. The cadence serial port
must already be setup and configured. Options are not
yet supported. uart[8250],io,<addr>[,options]
uart[8250],mmio,<addr>[,options]
uart[8250],mmio32,<addr>[,options]
uart[8250],mmio32be,<addr>[,options]
uart[8250],0x<addr>[,options]
Start an early, polled-mode console on the 8250/16550
UART at the specified I/O port or MMIO address.
MMIO inter-register address stride is either 8-bit
(mmio) or 32-bit (mmio32 or mmio32be).
If none of [io|mmio|mmio32|mmio32be], <addr> is assumed
to be equivalent to 'mmio'. 'options' are specified
in the same format described for "console=ttyS<n>"; if
unspecified, the h/w is not initialized. pl011,<addr>
pl011,mmio32,<addr>
Start an early, polled-mode console on a pl011 serial
port at the specified address. The pl011 serial port
must already be setup and configured. Options are not
yet supported. If 'mmio32' is specified, then only
the driver will use only 32-bit accessors to read/write
the device registers. meson,<addr>
Start an early, polled-mode console on a meson serial
port at the specified address. The serial port must
already be setup and configured. Options are not yet
supported. msm_serial,<addr>
Start an early, polled-mode console on an msm serial
port at the specified address. The serial port
must already be setup and configured. Options are not
yet supported. msm_serial_dm,<addr>
Start an early, polled-mode console on an msm serial
dm port at the specified address. The serial port
must already be setup and configured. Options are not
yet supported. smh Use ARM semihosting calls for early console. s3c2410,<addr>
s3c2412,<addr>
s3c2440,<addr>
s3c6400,<addr>
s5pv210,<addr>
exynos4210,<addr>
Use early console provided by serial driver available
on Samsung SoCs, requires selecting proper type and
a correct base address of the selected UART port. The
serial port must already be setup and configured.
Options are not yet supported. lpuart,<addr>
lpuart32,<addr>
Use early console provided by Freescale LP UART driver
found on Freescale Vybrid and QorIQ LS1021A processors.
A valid base address must be provided, and the serial
port must already be setup and configured. armada3700_uart,<addr>
Start an early, polled-mode console on the
Armada 3700 serial port at the specified
address. The serial port must already be setup
and configured. Options are not yet supported.An example of the usage is:
earlycon=uart8250,0x21c0500
My questions are: Why is there a reference to the 8250/16550 physical hardware? Has this old implementation molded into an interface specification for modern designs? That is, are we still using the drivers for UART that were compatible when these comms devices were external to the SoC?
If MMIO is Memory Mapped IO, what is "normal" IO referring to in this context?
What is the <addr> parameter? Is this the beginning of the UART configuration registers for the specific SoC you are running this kernel on? Do most UART configuration registers conform to a specific register layout such that a generic UART driver may appropriately configure the hardware?
|
Kernel parameters "console" and "earlycon" refer to old hardware?
|
You would first disable getty running on your serial port device /dev/ttyS0 (or whatever it is named for your hardware) to free it (for example, by editing /etc/inittab and running telinit q - if you managed to steer away from systemd) and then you would run pppd(8) on it (either manually with appropriate parameters or via additional tools like wvdial)
|
I am about to start working on an embedded system which runs kernel v2.6.x.
It is configured to use its serial line as a TTY (accessible via e.g. minicom, stty), but I want to run IP over the serial line so that I can run multiple multiplexed sessions over the link (e.g. via UDP/TCP or SSH).
I don't have much more information about the boards yet (will post more when the documentation arrives), but assuming that the kernel provides reasonable abstraction over the hardware - what would be the process to configure it to run PPP or (C)SLIP over the serial link in place of TTY?
|
How to configure embedded kernel to use serial line for PPP instead of TTY
|
It looks like you might be a bit confused about how this all works.
First, /dev/ttyACM0 does not represent the USB link, or even the USB endpoint for whatever serial adapter you have connected, it represents the UART inside the adapter that handles the serial communications. Data you read from it will not include any USB headers or framing, just like data you read from /dev/ttyS0 will not include any PCI Express headers or framing. Setting the baud rate on these affects the hardware that it represents, not the bus it's connected to, so this won't do anything to the USB connection.
Second, the baud rate is a hardware setting, not a software one. When you call stty to set it on a serial port, that is telling the kernel to tell the hardware to change what baud rate it is trying to receive data at. This means in particular that any data that was received prior to this change will either be bogus (because it wasn't interpreted correctly by the hardware, sometimes the case if the baud rates are close to each other or exact harmonics), or completely lost (because the hardware just didn't accept it, the more likely case on modern hardware).
If you plan on reading data from a serial line, you need to have the baud rate set correctly prior to any data being transmitted by the other end. This also means that changing the baud rate won't change how the kernel interprets the data. If the data is already buffered in the kernel, then it's not going to change just because you change the baud rate (although it is good practice after changing the baud rate to drain the kernel buffers so that you know any future data is good).
So, to clarify, the correct method to get data out of a USB to serial adapter without using special software is to:Set the baud rate during system startup. For a USB to serial adapter, this should probably be a udev rule so that it gets set when the device gets plugged in too.
Use cat (or od if you need the byte values instead of text) to read data. This will return the exact data that is received by the USB to serial adapter (assuing the adapter doesn't do special processing).
|
Sometimes I just need to read from a serial device, so I skip the complexities of minicom or screen and just cat. However, this only works if I first set the baud rate of the terminal using stty <baud> before attempting to open the file.
This data is likely already (or can be) buffered in the kernel and, in this case, was received using a UART to USB bridge. USB transfer rates are fixed for a given standard, so setting the baud rate can only affect the interpretation of the data. Given my lack of insight into what this data might look like wrapped in USB packets, I am unsure how to visualize the "interpretation" of USB packet data at some fixed read rate (baud rate).
$ stty 115200
$ cat /dev/ttyACM0What is really going on here? I understand the implications of this setting in hardware, but what does it mean in userspace software?
|
What are the implications of setting the baud rate of a terminal from userspace?
|
echo -n "1" >&5 did the trick for me. Seems like uboot doesn´t want to get a newline, otherwise it behaves weird.
Thanks a lot for your help!
Here is the "complete" script, maybe it is helpful for someone.
#!/bin/bash
tty=/dev/ttyUSB0
exec 4<$tty 5>$tty
stty -F $tty 115200 -brkint -icrnl -imaxbel iutf8 -isig -icanon -iexten -echo -echoe -echok -echoctl -echoketftp_client_ip="10.10.30.111"
tftp_server_ip="10.10.30.1"
tftp_file="test.file"while [ "$firstword" != "Please" ]; do # wait for bootmenu to apear
read -e output <&4
firstword=$(echo "$output" | cut -f1 -d" ")
echo "$output"
done
#printf "\t\n ***** ***** gotcha! ***** ***** \n\n"
sleep 0.5# DONT SEND NEWLINEs - otherwise uboot doesn´t recognize commands !!!!!
echo -n "1" >&5 # echo '1' for taking boot option 1
printf "\t\n ***** ***** echo '1' ***** ***** \n\n"
# MUST TO WAIT FOR DELAY - try to fix that by "emulate" RETURN button?
sleep 5#input TFTP-client IP
for((i=0;i<20;i++)); do
echo -ne "\b \b" >&5 #erase characters
sleep 0.05
done
printf "%s\r" "$tftp_client_ip" >&5#input TFTP-server IP
for((i=0;i<20;i++)); do
echo -ne "\b \b" >&5 #erase characters
sleep 0.05
done
printf "%s\r" "$tftp_server_ip" >&5#input TFTP-file
printf "%s\r" "$tftp_file" >&5while true; do #just for debugging...
read -e output <&4
echo "$output"
done# router should boot to RAM with "$tftp_file"
|
I try to use a bash script to watch the serial-port for a specific string. If this string is shown, some commands should be send back to the connected device. It´s a router I am connected to. It is a router I am connected to and I want to send the commands, after the uboot-menu has appeared.
When using minicom with a ftdi-USB-UART-device directly (no with the script) everything works. "It works" in that case means:Bootmenu is shown while a time is counting down, the device is
waiting for input until I enter a number or the countdown is over.
I am able to send a command/enter a number.
The router "boots" into the selected option. (in my case - the system
starts tftp-bootmode where I could input stuff liker server IP and so
on...)Now, when I use the script. The router does not care about inpu also the countdown is not runnig. It just boots directly into the default option. Same behavior when using minicom + /dev/ttyAMA0 on a raspberry pi (ftdi device otherwise works as described).
I am thinking that in my script, there are some parameters missing. Maybe I have to choose special options for stty?
Or do I have to send a special "control character" right at the beginning, for the router to recognize that "there is someone out there who is able to send me some commands"?
I am able to detect the string I am searching for, but as I said before - the router doesn´t recognize the command(s) send:
#!/bin/bash
tty=/dev/ttyUSB0
exec 4<$tty 5>$tty
stty -F $tty 115200 -echowhile [ "${output}" != "Please choose the operation:" ]; do #wait for bootmenu to appear
read output <&4
echo "$output"
done
printf "\t\n ***** gotcha! ***** \n\n" #bootmenu is showingecho -e "\x31" >&5 # echo '1' for taking boot option 1
printf "\t\n ***** echo '1' ***** \n\n"while true; do #just for debugging (was command received?)...
read output <&4
echo "$output"
done#commands for setting Target-IP, TFTP-Server-IP-address should follow here... Many thanks in advance :-)
|
Bash script - Watch serial-port for specific string, then send back commands
|
strace is not likely to give you the necessary level of detail; you will probably need SystemTap, sysdig, or similar kernel-level debugging to better show when what is happening. For example with SystemTap installed and all the necessary debuginfo and setup details taken care of one could start with:
probe begin
{
printf("%-16s %s\n", "TIME", "WHAT");
}probe tty.{ioctl,receive}
{
if (pid() != target()) next;
printf("%d ttyx %s\n", gettimeofday_us(), name);
}probe tty.poll
{
if (pid() != target()) next;
printf("%d ttypoll %s\n", gettimeofday_us(), file_name);
}probe tty.{read,write}
{
if (pid() != target()) next;
printf("%d ttyio %s %d\n", gettimeofday_us(), file_name, nr);
}probe syscall.{read,write,epoll_*}
{
if (pid() != target()) next;
printf("%d syscall %s\tenter\n", gettimeofday_us(), name);
}probe syscall.{read,write,epoll_*}.return
{
if (pid() != target()) next;
printf("%d syscall %s\treturn\n", gettimeofday_us(), name);
}and run that via
$ sudo stap -x "$(pidof ...)" filecontainingtheabovecode.stpwhich for a serial test program and an attached Arduino for me shows:
TIME WHAT
1516997916648359 syscall read enter
1516997916648366 ttyio ttyACM0 4096
1516997916652456 syscall read return
1516997916652465 syscall read enter
1516997916652470 ttyio ttyACM0 4096
1516997916656459 syscall read return
1516997916656497 syscall write enter
1516997916656503 ttyio 4 21
1516997916656511 syscall write return
...You may also need to consult the SystemTap tapsets documentation for other probe points of interest (scheduler, I/O scheduler, IRQs?) if the above does not show where the delay is. And possibly to compare timings against the old version of the code/driver/system...
|
Using an oscilloscope and toggling some pins I sometimes see latencies of 1-2 seconds from when an 8-byte UART packet is transmitted to when a blocking read returns. The packets are 1 second part with a few milliseconds of jitter. I also measured timing to the system calls (see below) using strace and the results agreed with my I/O measurements.
I'm trying to determine if this latency is in the UART driver or if other tasks are bumping my task which has a niceness value of -20. The reason I'm wondering about the driver is that an earlier version of this code reliably used the UART to transmit packets that were ~26 kB each second (the driver buffer is 4 kB).
The process is a Python script that is using pyserial. In this failing case strace reports the time between epoll_wait and clock_gettime as more than 3 seconds.
0.000883 epoll_ctl(3, EPOLL_CTL_ADD, 7, {EPOLLIN, {u32=7, u64=8589934599}}) = -1 EEXIST (File exists)
0.000681 clock_gettime(CLOCK_MONOTONIC, {92406, 209555006}) = 0
0.000655 epoll_wait(3, {}, 64, 98) = 0
3.004082 clock_gettime(CLOCK_MONOTONIC, {92409, 214251206}) = 0The repeated actions are: Receive 8-byte packet to request Linux to read N number of bytes via SPI. Perform the SPI. Read 8-byte packet to see if the SPI request completed successfully. The SPI transfer takes about 40 ms. The healthy pattern is ~40 ms between request packet and result packet. And ~960 ms until it receives the next request.
Duchess: strace -r -e read -p 7564
Process 7564 attached
0.000000 read(7, "\355\336\255\336\20d\0\0", 8) = 8
0.049142 read(7, "\255\336\355\336\1\0\0\0", 8) = 8
0.950381 read(7, "\355\336\255\336\20d\0\0", 8) = 8
0.050035 read(7, "\255\336\355\336\1\0\0\0", 8) = 8
0.949962 read(7, "\355\336\255\336\20d\0\0", 8) = 8
0.049601 read(7, "\255\336\355\336\1\0\0\0", 8) = 8
0.950417 read(7, "\355\336\255\336\20d\0\0", 8) = 8
0.049654 read(7, "\255\336\355\336\1\0\0\0", 8) = 8
0.950507 read(7, "\355\336\255\336\20d\0\0", 8) = 80.950516 read(7, "\355\336\255\336\20d\0\0", 8) = 8 [SPI Request]
0.049944 read(7, "\255\336\355\336\1\0\0\0", 8) = 8 [Success]
2.196903 read(7, "\355\336\255\336\20d\0\0", 8) = 8 [SPI Request]
0.048876 read(7, "\255\336\355\336\0\0\0\0", 8) = 8 [Failure]
0.015570 read(7, "\355\336\255\336\20d\0\0", 8) = 8 [SPI Request]
0.053889 read(7, "\255\336\355\336\0\0\0\0", 8) = 8 [Failure]
0.634720 read(7, "\355\336\255\336\20d\0\0", 8) = 8 [SPI Request]
0.050070 read(7, "\255\336\355\336\1\0\0\0", 8) = 8 [Success]
|
How can I determine if a latency is due to a driver or the scheduler?
|
A UART (Universal Asynchronous Receiver Transmitter) is not a protocol, it's a piece of hardware capable of receiving and transmitting data over a serial interface. I presume you are selecting some design block for your FPGA design implementing an UART.
|
When I write programs for my own FPGA, I must select UART to emulate a terminal and for my FPGA design but I don't know exactly what that means.
I believe that UART is a basic serial transmission protocol, isn't it? And is that the protocol between the program and the terminal and therefore I must choose UART from my programming environment?
|
What is the relation between UART and the tty?
|
NOTE: This answer is assuming LinuxWhere, in general, can I find the expanded names of devices under /dev?The devices have no "expanded names", but
udevadm info -a /dev/ttyPSxwill tell you a lot of interesting info about them.
If you don't have udev, you can get the type, major and minor of the device, look it up via /sys/dev, and get the same information from the /sys/devices/ files:
devinfo(){
local p=$(readlink -f $(ls -l "$1" | sed 's@^\(.\)[^,]* \([0-9][0-9]*\), *\([0-9][0-9]*\).*@/sys/dev/\1*/\2:\3@'))
while true; do
case $p in
/sys/devices/*)
if [ -f "$p/uevent" ]; then
echo ">>> $p"; cat "$p/uevent"; echo
fi
p=${p%/*};;
*)
break;;
esac
done
}[prompt] devinfo /dev/ttyMT1
>>> /sys/devices/soc/11003000.apuart1/tty/ttyMT1
MAJOR=204
MINOR=210
DEVNAME=ttyMT1>>> /sys/devices/soc/11003000.apuart1
DRIVER=mtk-uart
OF_NAME=apuart1
OF_FULLNAME=/soc/apuart1@11003000
OF_COMPATIBLE_0=mediatek,mt6735-uart
OF_COMPATIBLE_N=1
MODALIAS=of:Napuart1T<NULL>Cmediatek,mt6735-uart>>> /sys/devices/soc
OF_NAME=soc
OF_FULLNAME=/soc
OF_COMPATIBLE_0=simple-bus
OF_COMPATIBLE_N=1
MODALIAS=of:NsocT<NULL>Csimple-busNB: Not all linux systems have usable stat, awk or even sed programs. This kludge is something that seems to work on some linux devices, like my desktop, router, phone and dashcam. In older androids, sed is a broken POS which isn't even able to cope with echo pee | sed s/e/a/ (it will print papee).
|
What does PS in ttyPS* stands for?
Where, in general, can I find the expanded names of devices under /dev?
|
What does PS in ttyPS* stands for?
|
Concerning the output from Linux (and not your bootloader, i.e. U-Boot or possible something before that), you would simply change the console= command line parameter, see http://elinux.org/Serial_console and https://www.kernel.org/doc/Documentation/admin-guide/kernel-parameters.txt.
|
previously thank you for watching this post.
I have tried to run linux on odroidxu4 and of course the logs are written through uart2 (this uart seems default in odroidxu4)
But what I'm trying to do is changing the linux to write the logs with uart0 not the uart2.
I tried to change the default uart port from 2 to 0 by modifying the code in common/serial.c in u-boot
and also tried to change the menuconfig in linux like below :kernel hacking => Kernel low-level debugging functions
choose in "Kernel low-level debugging port" to "Use S3C UART 0 for low-level debug"But it didn't work.
please let me know if there's another way to change the dafault uart from 2 to 0 that i missed
thank you.
|
odroidxu4 changing default uart2 to uart0
|
Upgrade your kernel to a newer kernel. There were issues with this driver in the earlier kernels.
|
I have a sama5d36 device running Debian jessie (kernel 4.1.10) with a DMA USART. To get the DMA USART to output correctly I had to turn off ECHO and ONLCR.
stty -F /dev/ttyS2 -echo -onlcr speed 115200If I do a test where I send a bunch of bytes, I will receive 2048 bytes and then it stops receiving until I restart.
cat testLines > /dev/ttyS2
cat < /dev/ttyS2Here is the output of /proc/tty/driver/atmel_serial
2: uart:ATMEL_SERIAL mmio:0xF0020000 irq:31 tx:2185 rx:2048 DSR|CD|RIHere is my stty output (stty -F /dev/ttyS2 -a):
atmel_usart f0020000.serial: using dma0chan4 for rx DMA transfers
atmel_usart f0020000.serial: using dma0chan5 for tx DMA transfers
speed 115200 baud; rows 0; columns 0; line = 0;
intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = <undef>;
eol2 = <undef>; swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R;
werase = ^W; lnext = ^V; flush = ^O; min = 1; time = 0;
-parenb -parodd -cmspar cs8 hupcl -cstopb cread clocal -crtscts
-ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl ixon -ixoff
-iuclc -ixany -imaxbel -iutf8
opost -olcuc -ocrnl -onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0
isig icanon iexten -echo echoe echok -echonl -noflsh -xcase -tostop -echoprt
echoctl echokeThe DMA buffer for atmel_serial is 512 bytes.
Any insight?
Update: Further playing has demonstrated that the serial will write more than 2048 bytes but it freezes after 2048 bytes and then will only write once 2048 bytes have been written. Looking at atmel_serial.c in the kernel it looks like the ring buffer is set for 1024. So I am still confused why 2048 bytes is significant.
|
serial DMA pausing after 2048 bytes
|
In order to make use of the M.2's UART interface, this interface needs to be implemented on the motherboard's M.2 slot.
According to the Wikipedia article the M.2 E key slot supports the following interfaces:2 of PCIe×1, USB2.0, I2C, SDIO, UART, PCM and CNViSo, the UART interface will work as long as it is implemented on the interface by the motherboard's manufacturer and if it is not implemented then there is no way to make use of it.
The information regarding whether it is implemented or not could be found in the board's manual or confirmed with the board's manufacturer.
|
I have a motherboard (AIMB-218) with an M2 E key slot and according to the documentation of the said motherboard the M2 slot supports UART.
I am trying to use a wireless module (Wi-Fi + Bluetooth), which has a UART interface for controlling the Bluetooth adapter. Its documentation says that the Wi-Fi interface works using the PCIe bus and the Bluetooth uses UART interface.
I have booted a Linux Ubuntu on this system, but the UART interface does not show up in the /dev folder (there are only few ttyS* entries which correspond to serial ports present on the motherboard) nor the Bluetooth controller appears in the system in any other way - the bluetoothctl does not list any HCI devices.
The wireless module's chip is 88W8997 and the manufacturer claims it is supported by the Linux kernel.
My question is: How to make use of the UART interface of the card connected to the M2 slot?
|
How to make use of an M2 PCIe card UART interface?
|
Find the answer in Xilinx forum.
It is indeed a problem with the console.
https://forums.xilinx.com/t5/Embedded-Linux/quot-Warning-unable-to-open-an-initial-console-quot-Under/m-p/1117002
It seems that its kernel code has not been fully updated, which makes some new parameters not fully set.
|
My problem is my linux is success for boot but there is no more boot message output to uart(ttyPS0) after "Starting kernel...".As you can see in the pic, there is a lot of boot message in dmesg but they are not showing when linux was booting.
The bootargs is passed by uEnv.txt:
bootcmd=run adi_sdboot
adi_sdboot=echo Copying Linux from SD to RAM... && fatload mmc 0 0x3000000 ${kernel_image} && fatload mmc 0 0x2A00000 ${devicetree_image} && if fatload mmc 0 0x2000000 ${ramdisk_image}; then bootm 0x3000000 0x2000000 0x2A00000; else bootm 0x3000000 - 0x2A00000; fi
bootargs=console=ttyPS0,115200 root=/dev/mmcblk0p2 rw earlyprintk debug rootfstype=ext4 rootwait
fdt_high=0x2D000000I have tested whether ttyPS0 is working properly and dmesg shows that it has registered.Also, it can be echo.I doubt if it's the console problem.Or I just missing the CONFIG which I don't know?
---------------------------------Update--------------------------------------
Since I change the linux kernel to the success version.
I think the problem is console setting.
Here is the boot message in the success version linux.
You can see console has been set to ttyPS0 at 0.7sec.
U-Boot 2019.01-gf736b0f-dirty (Feb 17 2021 - 15:27:50 +0800)CPU: Zynq 7z035
Silicon: v3.1
Model: MTI Phased Antenna platform...
DRAM: ECC disabled 1 GiB
MMC: mmc@e0100000: 0
Loading Environment from SPI Flash... SF: Detected n25q256a with page size 256 Bytes, erase size 4 KiB, total 32 MiB
OK
In: serial@e0001000
Out: serial@e0001000
Err: serial@e0001000
Net: ZYNQ GEM: e000b000, phyaddr c, interface rgmii-id
eth0: ethernet@e000b000
405 bytes read in 6 ms (65.4 KiB/s)
Importing environment from SD ...
Hit any key to stop autoboot: 0
Copying Linux from SD to RAM...
3704008 bytes read in 214 ms (16.5 MiB/s)
11887 bytes read in 14 ms (829.1 KiB/s)
** Unable to read file uramdisk.image.gz **
## Booting kernel from Legacy Image at 03000000 ...
Image Name: Linux-4.14.0-xilinx-g42d8052-dir
Image Type: ARM Linux Kernel Image (uncompressed)
Data Size: 3703944 Bytes = 3.5 MiB
Load Address: 00008000
Entry Point: 00008000
Verifying Checksum ... OK
## Flattened Device Tree blob at 02a00000
Booting using the fdt blob at 0x2a00000
Loading Kernel Image ... OK
Loading Device Tree to 2cffa000, end 2cfffe6e ... OKStarting kernel ...[ 0.000000] Booting Linux on physical CPU 0x0
[ 0.000000] Linux version 4.14.0-xilinx-g42d8052-dirty (jazz.chou@mtisdi) (gcc version 6.2.1 20161114 (Linaro GCC Snapshot 6.2-2016.11)) #3 SMP PREEMPT Tue Mar 30 17:51:20 CST 2021
[ 0.000000] CPU: ARMv7 Processor [413fc090] revision 0 (ARMv7), cr=18c5387d
[ 0.000000] CPU: PIPT / VIPT nonaliasing data cache, VIPT aliasing instruction cache
[ 0.000000] OF: fdt: Machine model: hases-Array-Controller with Zynq Platform (Z-7035)
[ 0.000000] Memory policy: Data cache writealloc
[ 0.000000] cma: Reserved 700 MiB at 0x01000000
[ 0.000000] On node 0 totalpages: 262144
[ 0.000000] free_area_init_node: node 0, pgdat c0935180, node_mem_map ef69a000
[ 0.000000] Normal zone: 1536 pages used for memmap
[ 0.000000] Normal zone: 0 pages reserved
[ 0.000000] Normal zone: 196608 pages, LIFO batch:31
[ 0.000000] HighMem zone: 65536 pages, LIFO batch:15
[ 0.000000] random: fast init done
[ 0.000000] percpu: Embedded 16 pages/cpu @ef670000 s35084 r8192 d22260 u65536
[ 0.000000] pcpu-alloc: s35084 r8192 d22260 u65536 alloc=16*4096
[ 0.000000] pcpu-alloc: [0] 0 [0] 1
[ 0.000000] Built 1 zonelists, mobility grouping on. Total pages: 260608
[ 0.000000] Kernel command line: console=ttyPS0,115200 root=/dev/mmcblk0p2 rw earlyprintk debug rootfstype=ext4 rootwait
[ 0.000000] PID hash table entries: 4096 (order: 2, 16384 bytes)
[ 0.000000] Dentry cache hash table entries: 131072 (order: 7, 524288 bytes)
[ 0.000000] Inode-cache hash table entries: 65536 (order: 6, 262144 bytes)
[ 0.000000] Memory: 312124K/1048576K available (5120K kernel code, 215K rwdata, 1472K rodata, 1024K init, 150K bss, 19652K reserved, 716800K cma-reserved, 262144K highmem)
[ 0.000000] Virtual kernel memory layout:
[ 0.000000] vector : 0xffff0000 - 0xffff1000 ( 4 kB)
[ 0.000000] fixmap : 0xffc00000 - 0xfff00000 (3072 kB)
[ 0.000000] vmalloc : 0xf0800000 - 0xff800000 ( 240 MB)
[ 0.000000] lowmem : 0xc0000000 - 0xf0000000 ( 768 MB)
[ 0.000000] pkmap : 0xbfe00000 - 0xc0000000 ( 2 MB)
[ 0.000000] modules : 0xbf000000 - 0xbfe00000 ( 14 MB)
[ 0.000000] .text : 0xc0008000 - 0xc0600000 (6112 kB)
[ 0.000000] .init : 0xc0800000 - 0xc0900000 (1024 kB)
[ 0.000000] .data : 0xc0900000 - 0xc0935d80 ( 216 kB)
[ 0.000000] .bss : 0xc0935d80 - 0xc095b644 ( 151 kB)
[ 0.000000] Preemptible hierarchical RCU implementation.
[ 0.000000] RCU restricting CPUs from NR_CPUS=4 to nr_cpu_ids=2.
[ 0.000000] Tasks RCU enabled.
[ 0.000000] RCU: Adjusting geometry for rcu_fanout_leaf=16, nr_cpu_ids=2
[ 0.000000] NR_IRQS: 16, nr_irqs: 16, preallocated irqs: 16
[ 0.000000] efuse mapped to f0800000
[ 0.000000] slcr mapped to f0802000
[ 0.000000] L2C: platform modifies aux control register: 0x72360000 -> 0x72760000
[ 0.000000] L2C: DT/platform modifies aux control register: 0x72360000 -> 0x72760000
[ 0.000000] L2C-310 erratum 769419 enabled
[ 0.000000] L2C-310 enabling early BRESP for Cortex-A9
[ 0.000000] L2C-310 full line of zeros enabled for Cortex-A9
[ 0.000000] L2C-310 ID prefetch enabled, offset 1 lines
[ 0.000000] L2C-310 dynamic clock gating enabled, standby mode enabled
[ 0.000000] L2C-310 cache controller enabled, 8 ways, 512 kB
[ 0.000000] L2C-310: CACHE_ID 0x410000c8, AUX_CTRL 0x76760001
[ 0.000000] zynq_clock_init: clkc starts at f0802100
[ 0.000000] Zynq clock init
[ 0.000011] sched_clock: 64 bits at 333MHz, resolution 3ns, wraps every 4398046511103ns
[ 0.000033] clocksource: arm_global_timer: mask: 0xffffffffffffffff max_cycles: 0x4ce07af025, max_idle_ns: 440795209040 ns
[ 0.000063] Switching to timer-based delay loop, resolution 3ns
[ 0.000163] clocksource: ttc_clocksource: mask: 0xffff max_cycles: 0xffff, max_idle_ns: 537538477 ns
[ 0.000198] timer #0 at f080a000, irq=17
[ 0.000683] Console: colour dummy device 80x30
[ 0.000710] Calibrating delay loop (skipped), value calculated using timer frequency.. 666.66 BogoMIPS (lpj=3333333)
[ 0.000728] pid_max: default: 32768 minimum: 301
[ 0.000873] Mount-cache hash table entries: 2048 (order: 1, 8192 bytes)
[ 0.000890] Mountpoint-cache hash table entries: 2048 (order: 1, 8192 bytes)
[ 0.001444] CPU: Testing write buffer coherency: ok
[ 0.001648] CPU0: thread -1, cpu 0, socket 0, mpidr 80000000
[ 0.040353] Setting up static identity map for 0x100000 - 0x100060
[ 0.060313] Hierarchical SRCU implementation.
[ 0.100312] smp: Bringing up secondary CPUs ...
[ 0.170656] CPU1: thread -1, cpu 1, socket 0, mpidr 80000001
[ 0.170767] smp: Brought up 1 node, 2 CPUs
[ 0.170786] SMP: Total of 2 processors activated (1333.33 BogoMIPS).
[ 0.170795] CPU: All CPU(s) started in SVC mode.
[ 0.171754] devtmpfs: initialized
[ 0.174641] VFP support v0.3: implementor 41 architecture 3 part 30 variant 9 rev 4
[ 0.174948] clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 19112604462750000 ns
[ 0.174971] futex hash table entries: 512 (order: 3, 32768 bytes)
[ 0.209069] pinctrl core: initialized pinctrl subsystem
[ 0.210393] NET: Registered protocol family 16
[ 0.222379] DMA: preallocated 256 KiB pool for atomic coherent allocations
[ 0.223651] cpuidle: using governor menu
[ 0.230644] hw-breakpoint: found 5 (+1 reserved) breakpoint and 1 watchpoint registers.
[ 0.230660] hw-breakpoint: maximum watchpoint size is 4 bytes.
[ 0.230784] zynq-ocm f800c000.ocmc: ZYNQ OCM pool: 256 KiB @ 0xf0840000
[ 0.231207] zynq-pinctrl 700.pinctrl: zynq pinctrl initialized
[ 0.231672] e0000000.serial: ttyPS1 at MMIO 0xe0000000 (irq = 25, base_baud = 6249999) is a xuartps
[ 0.232248] e0001000.serial: ttyPS0 at MMIO 0xe0001000 (irq = 26, base_baud = 6249999) is a xuartps
**[ 0.753431] console [ttyPS0] enabled**
[ 0.772447] vgaarb: loaded
[ 0.775590] SCSI subsystem initialized
[ 0.779539] media: Linux media interface: v0.10
[ 0.785151] Linux video capture interface: v2.00
[ 0.789847] pps_core: LinuxPPS API ver. 1 registered
[ 0.794834] pps_core: Software ver. 5.3.6 - Copyright 2005-2007 Rodolfo Giometti <[emailprotected]>
[ 0.804019] PTP clock support registered
[ 0.807986] EDAC MC: Ver: 3.0.0
[ 0.811660] FPGA manager framework
[ 0.815283] fpga-region fpga-full: FPGA Region probed
[ 0.821481] clocksource: Switched to clocksource arm_global_timer
[ 0.837146] NET: Registered protocol family 2
[ 0.842198] TCP established hash table entries: 8192 (order: 3, 32768 bytes)
[ 0.849336] TCP bind hash table entries: 8192 (order: 4, 65536 bytes)
[ 0.855946] TCP: Hash tables configured (established 8192 bind 8192)
[ 0.862415] UDP hash table entries: 512 (order: 2, 16384 bytes)
[ 0.868367] UDP-Lite hash table entries: 512 (order: 2, 16384 bytes)
[ 0.874922] NET: Registered protocol family 1
[ 0.879616] RPC: Registered named UNIX socket transport module.
[ 0.885570] RPC: Registered udp transport module.
[ 0.890261] RPC: Registered tcp transport module.
[ 0.894985] RPC: Registered tcp NFSv4.1 backchannel transport module.
[ 0.901421] PCI: CLS 0 bytes, default 64
[ 0.905858] hw perfevents: no interrupt-affinity property for /pmu@f8891000, guessing.
[ 0.913984] hw perfevents: enabled with armv7_cortex_a9 PMU driver, 7 counters available
[ 0.923882] workingset: timestamp_bits=30 max_order=18 bucket_order=0
[ 0.931009] jffs2: version 2.2. (NAND) (SUMMARY) © 2001-2006 Red Hat, Inc.
[ 0.938890] bounce: pool size: 64 pages
[ 0.942749] io scheduler noop registered
[ 0.946665] io scheduler deadline registered
[ 0.950981] io scheduler cfq registered (default)
[ 0.955792] io scheduler mq-deadline registered
[ 0.960319] io scheduler kyber registered
[ 0.966769] dma-pl330 f8003000.dmac: Loaded driver for PL330 DMAC-241330
[ 0.973504] dma-pl330 f8003000.dmac: DBUFF-128x8bytes Num_Chans-8 Num_Peri-4 Num_Events-16
[ 0.982783] uartlite 43c40000.uartlite_0: No serial alias passed. Using the first free id
[ 0.990954] uartlite 43c40000.uartlite_0: Checking id 0
[ 0.996278] 43c40000.uartlite_0: ttyUL0 at MMIO 0x43c40000 (irq = 46, base_baud = 0) is a uartlite
[ 1.014136] brd: module loaded
[ 1.024416] loop: module loaded
[ 1.029832] m25p80 spi0.0: SPI-NOR-UniqueID 10447300199200051c0020008a8eb87c57
[ 1.037374] m25p80 spi0.0: n25q256a (32768 Kbytes)
[ 1.042222] 6 ofpart partitions found on MTD device spi0.0
[ 1.047701] Creating 6 MTD partitions on "spi0.0":
[ 1.052522] 0x000000000000-0x0000000e0000 : "qspi-fsbl-uboot"
[ 1.059193] 0x0000000e0000-0x000000100000 : "qspi-uboot-env"
[ 1.065749] 0x000000100000-0x000000600000 : "qspi-linux"
[ 1.072011] 0x000000600000-0x000000620000 : "qspi-device-tree"
[ 1.078696] 0x000000620000-0x000001300000 : "qspi-rootfs"
[ 1.084957] 0x000001300000-0x000002000000 : "qspi-bitstream"
[ 1.092039] libphy: Fixed MDIO Bus: probed
[ 1.098599] CAN device driver interface
[ 1.142310] libphy: MACB_mii_bus: probed
[ 1.148821] macb e000b000.ethernet eth0: Cadence GEM rev 0x00020118 at 0xe000b000 irq 28 (aa:99:75:dd:1d:61)
[ 1.158696] TI DP83867 e000b000.ethernet-ffffffff:0c: attached PHY driver [TI DP83867] (mii_bus:phy_addr=e000b000.ethernet-ffffffff:0c, irq=POLL)
[ 1.172061] e1000e: Intel(R) PRO/1000 Network Driver - 3.2.6-k
[ 1.177882] e1000e: Copyright(c) 1999 - 2015 Intel Corporation.
[ 1.184986] i2c /dev entries driver
...
Mount failed for selinuxfs on /sys/fs/selinux: No such file or directory
[ 1.914702] init: hwclock main process (648) terminated with status 1
* Setting up X socket directories... [ OK ]
* STARTDISTCC is set to false in /etc/default/distcc
* /usr/bin/distccd not starting
pidof: can't get program name from /proc/1569/stat * Not starting NFS kernel daemon: no support in current kernel.
* Starting IIO Daemon iiod [ OK ]Last login: Wed Mar 31 10:25:51 CST 2021 from 172.16.250.61 on pts/1
Welcome to Linaro 14.04 (GNU/Linux 4.14.0-xilinx-g42d8052-dirty armv7l) * Documentation: https://wiki.analog.com/ https://ez.analog.com/root@sdi01:~#And these are boot message show by wrong kernel.
U-Boot 2019.01-gf736b0f-dirty (Feb 17 2021 - 15:27:50 +0800)CPU: Zynq 7z035
Silicon: v3.1
Model: MTI Phased Antenna platform...
DRAM: ECC disabled 1 GiB
MMC: mmc@e0100000: 0
Loading Environment from SPI Flash... SF: Detected n25q256a with page size 256 Bytes, erase size 4 KiB, total 32 MiB
OK
In: serial@e0001000
Out: serial@e0001000
Err: serial@e0001000
Net: ZYNQ GEM: e000b000, phyaddr c, interface rgmii-id
eth0: ethernet@e000b000
405 bytes read in 6 ms (65.4 KiB/s)
Importing environment from SD ...
Hit any key to stop autoboot: 0
Copying Linux from SD to RAM...
3828064 bytes read in 231 ms (15.8 MiB/s)
11887 bytes read in 14 ms (829.1 KiB/s)
** Unable to read file uramdisk.image.gz **
## Booting kernel from Legacy Image at 03000000 ...
Image Name: Linux-5.4.0-xilinx-g282eb80-dirt
Image Type: ARM Linux Kernel Image (uncompressed)
Data Size: 3828000 Bytes = 3.7 MiB
Load Address: 00008000
Entry Point: 00008000
Verifying Checksum ... OK
## Flattened Device Tree blob at 02a00000
Booting using the fdt blob at 0x2a00000
Loading Kernel Image ... OK
Loading Device Tree to 2cffa000, end 2cfffe6e ... OKStarting kernel ...Last login: Wed Mar 31 10:50:00 CST 2021 from 172.16.49.210 on pts/0
Welcome to Linaro 14.04 (GNU/Linux 5.4.0-xilinx-g282eb80-dirty armv7l) * Documentation: https://wiki.analog.com/ https://ez.analog.com/root@sdi01:~#And here is it's dmesg
root@sdi01:~# dmesg
[ 0.000000] Booting Linux on physical CPU 0x0
[ 0.000000] Linux version 5.4.0-xilinx-g282eb80-dirty (jazz.chou@mtisdi) (gcc version 6.2.1 20161114 (Linaro GCC Snapshot 6.2-2016.11)) #27 SMP PREEMPT Wed Mar 31 09:45:50 CST 2021
[ 0.000000] CPU: ARMv7 Processor [413fc090] revision 0 (ARMv7), cr=18c5387d
[ 0.000000] CPU: PIPT / VIPT nonaliasing data cache, VIPT aliasing instruction cache
[ 0.000000] OF: fdt: Machine model: hases-Array-Controller with Zynq Platform (Z-7035)
[ 0.000000] Memory policy: Data cache writealloc
[ 0.000000] cma: Reserved 700 MiB at 0x01000000
[ 0.000000] On node 0 totalpages: 262144
[ 0.000000] Normal zone: 1536 pages used for memmap
[ 0.000000] Normal zone: 0 pages reserved
[ 0.000000] Normal zone: 196608 pages, LIFO batch:63
[ 0.000000] HighMem zone: 65536 pages, LIFO batch:15
[ 0.000000] percpu: Embedded 15 pages/cpu s31820 r8192 d21428 u61440
[ 0.000000] pcpu-alloc: s31820 r8192 d21428 u61440 alloc=15*4096
[ 0.000000] pcpu-alloc: [0] 0 [0] 1
[ 0.000000] Built 1 zonelists, mobility grouping on. Total pages: 260608
[ 0.000000] Kernel command line: console=ttyPS0,115200 root=/dev/mmcblk0p2 rw earlyprintk debug rootfstype=ext4 rootwait
[ 0.000000] Dentry cache hash table entries: 131072 (order: 7, 524288 bytes, linear)
[ 0.000000] Inode-cache hash table entries: 65536 (order: 6, 262144 bytes, linear)
[ 0.000000] mem auto-init: stack:off, heap alloc:off, heap free:off
[ 0.000000] Memory: 310180K/1048576K available (6144K kernel code, 168K rwdata, 1596K rodata, 1024K init, 1136K bss, 21596K reserved, 716800K cma-reserved, 262144K highmem)
[ 0.000000] rcu: Preemptible hierarchical RCU implementation.
[ 0.000000] rcu: RCU restricting CPUs from NR_CPUS=4 to nr_cpu_ids=2.
[ 0.000000] Tasks RCU enabled.
[ 0.000000] rcu: RCU calculated value of scheduler-enlistment delay is 10 jiffies.
[ 0.000000] rcu: Adjusting geometry for rcu_fanout_leaf=16, nr_cpu_ids=2
[ 0.000000] NR_IRQS: 16, nr_irqs: 16, preallocated irqs: 16
[ 0.000000] efuse mapped to (ptrval)
[ 0.000000] slcr mapped to (ptrval)
[ 0.000000] L2C: platform modifies aux control register: 0x72360000 -> 0x72760000
[ 0.000000] L2C: DT/platform modifies aux control register: 0x72360000 -> 0x72760000
[ 0.000000] L2C-310 erratum 769419 enabled
[ 0.000000] L2C-310 enabling early BRESP for Cortex-A9
[ 0.000000] L2C-310 full line of zeros enabled for Cortex-A9
[ 0.000000] L2C-310 ID prefetch enabled, offset 1 lines
[ 0.000000] L2C-310 dynamic clock gating enabled, standby mode enabled
[ 0.000000] L2C-310 cache controller enabled, 8 ways, 512 kB
[ 0.000000] L2C-310: CACHE_ID 0x410000c8, AUX_CTRL 0x76760001
[ 0.000000] random: get_random_bytes called from start_kernel+0x268/0x41c with crng_init=0
[ 0.000000] zynq_clock_init: clkc starts at (ptrval)
[ 0.000000] Zynq clock init
[ 0.000010] sched_clock: 64 bits at 333MHz, resolution 3ns, wraps every 4398046511103ns
[ 0.000033] clocksource: arm_global_timer: mask: 0xffffffffffffffff max_cycles: 0x4ce07af025, max_idle_ns: 440795209040 ns
[ 0.000064] Switching to timer-based delay loop, resolution 3ns
[ 0.000705] Console: colour dummy device 80x30
[ 0.000740] Calibrating delay loop (skipped), value calculated using timer frequency.. 666.66 BogoMIPS (lpj=3333333)
[ 0.000758] pid_max: default: 32768 minimum: 301
[ 0.000957] Mount-cache hash table entries: 2048 (order: 1, 8192 bytes, linear)
[ 0.000977] Mountpoint-cache hash table entries: 2048 (order: 1, 8192 bytes, linear)
[ 0.001754] CPU: Testing write buffer coherency: ok
[ 0.001794] CPU0: Spectre v2: using BPIALL workaround
[ 0.002042] CPU0: thread -1, cpu 0, socket 0, mpidr 80000000
[ 0.060255] Setting up static identity map for 0x100000 - 0x100060
[ 0.080205] rcu: Hierarchical SRCU implementation.
[ 0.120206] smp: Bringing up secondary CPUs ...
[ 0.200594] CPU1: thread -1, cpu 1, socket 0, mpidr 80000001
[ 0.200603] CPU1: Spectre v2: using BPIALL workaround
[ 0.200757] smp: Brought up 1 node, 2 CPUs
[ 0.200771] SMP: Total of 2 processors activated (1333.33 BogoMIPS).
[ 0.200780] CPU: All CPU(s) started in SVC mode.
[ 0.201339] devtmpfs: initialized
[ 0.204893] VFP support v0.3: implementor 41 architecture 3 part 30 variant 9 rev 4
[ 0.205318] clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 19112604462750000 ns
[ 0.205342] futex hash table entries: 512 (order: 3, 32768 bytes, linear)
[ 0.245307] pinctrl core: initialized pinctrl subsystem
[ 0.246528] NET: Registered protocol family 16
[ 0.248652] DMA: preallocated 256 KiB pool for atomic coherent allocations
[ 0.249997] cpuidle: using governor menu
[ 0.258363] hw-breakpoint: found 5 (+1 reserved) breakpoint and 1 watchpoint registers.
[ 0.258377] hw-breakpoint: maximum watchpoint size is 4 bytes.
[ 0.258521] zynq-ocm f800c000.ocmc: ZYNQ OCM pool: 256 KiB @ 0x(ptrval)
[ 0.259144] e0000000.serial: ttyPS1 at MMIO 0xe0000000 (irq = 24, base_baud = 6249999) is a xuartps
[ 0.259728] e0001000.serial: ttyPS0 at MMIO 0xe0001000 (irq = 25, base_baud = 6249999) is a xuartps
[ 0.269195] vgaarb: loaded
[ 0.269625] SCSI subsystem initialized
[ 0.269943] pps_core: LinuxPPS API ver. 1 registered
[ 0.269955] pps_core: Software ver. 5.3.6 - Copyright 2005-2007 Rodolfo Giometti <[emailprotected]>
[ 0.269989] PTP clock support registered
[ 0.270031] EDAC MC: Ver: 3.0.0
[ 0.270603] FPGA manager framework
[ 0.271597] clocksource: Switched to clocksource arm_global_timer
[ 0.281765] thermal_sys: Registered thermal governor 'step_wise'
[ 0.282093] NET: Registered protocol family 2
[ 0.282784] tcp_listen_portaddr_hash hash table entries: 512 (order: 0, 6144 bytes, linear)
[ 0.282825] TCP established hash table entries: 8192 (order: 3, 32768 bytes, linear)
[ 0.282931] TCP bind hash table entries: 8192 (order: 4, 65536 bytes, linear)
[ 0.283078] TCP: Hash tables configured (established 8192 bind 8192)
[ 0.283182] UDP hash table entries: 512 (order: 2, 16384 bytes, linear)
[ 0.283236] UDP-Lite hash table entries: 512 (order: 2, 16384 bytes, linear)
[ 0.283468] NET: Registered protocol family 1
[ 0.284075] RPC: Registered named UNIX socket transport module.
[ 0.284088] RPC: Registered udp transport module.
[ 0.284097] RPC: Registered tcp transport module.
[ 0.284105] RPC: Registered tcp NFSv4.1 backchannel transport module.
[ 0.284121] PCI: CLS 0 bytes, default 64
[ 0.284736] hw perfevents: no interrupt-affinity property for /pmu@f8891000, guessing.
[ 0.284964] hw perfevents: enabled with armv7_cortex_a9 PMU driver, 7 counters available
[ 0.286492] workingset: timestamp_bits=30 max_order=18 bucket_order=0
[ 0.287499] jffs2: version 2.2. (NAND) (SUMMARY) \xffffffc2\xffffffa9\xffffffa9 2001-2006 Red Hat, Inc.
[ 0.287774] bounce: pool size: 64 pages
[ 0.287796] io scheduler mq-deadline registered
[ 0.287807] io scheduler kyber registered
[ 0.288216] zynq-pinctrl 700.pinctrl: zynq pinctrl initialized
[ 0.291331] dma-pl330 f8003000.dmac: Loaded driver for PL330 DMAC-241330
[ 0.291351] dma-pl330 f8003000.dmac: DBUFF-128x8bytes Num_Chans-8 Num_Peri-4 Num_Events-16
[ 0.292146] uartlite 43c40000.uartlite_0: No serial alias passed. Using the first free id
[ 0.292162] uartlite 43c40000.uartlite_0: Checking id 0
[ 0.292245] 43c40000.uartlite_0: ttyUL0 at MMIO 0x43c40000 (irq = 46, base_baud = 0) is a uartlite
[ 0.302259] brd: module loaded
[ 0.311663] loop: module loaded
[ 0.313613] spi-nor spi0.0: SPI-NOR-UniqueID 10447300199200051c0020008a8eb87c57
[ 0.313631] spi-nor spi0.0: found n25q256ax1, expected n25q256a
[ 0.313955] spi-nor spi0.0: n25q256ax1 (32768 Kbytes)
[ 0.314018] 6 fixed-partitions partitions found on MTD device spi0.0
[ 0.314029] Creating 6 MTD partitions on "spi0.0":
[ 0.314043] 0x000000000000-0x0000000e0000 : "qspi-fsbl-uboot"
[ 0.321572] 0x0000000e0000-0x000000100000 : "qspi-uboot-env"
[ 0.331167] 0x000000100000-0x000000600000 : "qspi-linux"
[ 0.332712] 0x000000600000-0x000000620000 : "qspi-device-tree"
[ 0.334218] 0x000000620000-0x000001300000 : "qspi-rootfs"
[ 0.341605] 0x000001300000-0x000002000000 : "qspi-bitstream"
[ 0.351996] libphy: Fixed MDIO Bus: probed
[ 0.353096] CAN device driver interface
[ 0.354423] libphy: MACB_mii_bus: probed
[ 0.770619] TI DP83867 e000b000.ethernet-ffffffff:0c: attached PHY driver [TI DP83867] (mii_bus:phy_addr=e000b000.ethernet-ffffffff:0c, irq=POLL)
[ 0.770644] macb e000b000.ethernet eth0: Cadence GEM rev 0x00020118 at 0xe000b000 irq 27 (aa:99:75:dd:1d:61)
[ 0.771007] e1000e: Intel(R) PRO/1000 Network Driver - 3.2.6-k
[ 0.771017] e1000e: Copyright(c) 1999 - 2015 Intel Corporation.
[ 0.772095] i2c /dev entries driver
[ 0.773324] cdns-wdt f8005000.watchdog: Xilinx Watchdog Timer with timeout 10s
[ 0.773664] EDAC MC: ECC not enabled
[ 0.773852] Xilinx Zynq CpuIdle Driver started
[ 0.774335] sdhci: Secure Digital Host Controller Interface driver
[ 0.774345] sdhci: Copyright(c) Pierre Ossman
[ 0.774353] sdhci-pltfm: SDHCI platform and OF driver helper
[ 0.810218] mmc0: SDHCI controller on e0100000.sdhci [e0100000.sdhci] using ADMA
[ 0.810636] ledtrig-cpu: registered to indicate activity on CPUs
[ 0.810866] clocksource: ttc_clocksource: mask: 0xffff max_cycles: 0xffff, max_idle_ns: 537538477 ns
[ 0.811037] timer #0 at (ptrval), irq=40
[ 0.812987] axi_sysid 43c80000.axi-sysid-0: AXI System ID core version (1.01.a) found
[ 0.813169] axi_sysid 43c80000.axi-sysid-0: [VKU0_L01] [sys rom custom string placeholder] on [X03PA] git branch <master> git <36b40b9583905cf886c4f1b15685b4b4e0f83578> clean [2021-03-17 01:43:55] UTC
[ 0.813812] fpga_manager fpga0: Xilinx Zynq FPGA Manager registered
[ 0.814529] NET: Registered protocol family 10
[ 0.815737] Segment Routing with IPv6
[ 0.815843] sit: IPv6, IPv4 and MPLS over IPv4 tunneling driver
[ 0.816591] NET: Registered protocol family 17
[ 0.816613] can: controller area network core (rev 20170425 abi 9)
[ 0.816682] NET: Registered protocol family 29
[ 0.816695] can: raw protocol (rev 20170425)
[ 0.816705] can: broadcast manager protocol (rev 20170425 t)
[ 0.816720] can: netlink gateway (rev 20190810) max_hops=1
[ 0.817090] Registering SWP/SWPB emulation handler
[ 0.828568] hctosys: unable to open rtc device (rtc0)
[ 0.828583] of_cfs_init
[ 0.828691] of_cfs_init: OK
**[ 0.829022] Warning: unable to open an initial console.**
[ 0.829265] Waiting for root device /dev/mmcblk0p2...
[ 0.852554] mmc0: new high speed SDHC card at address aaaa
[ 0.863276] mmcblk0: mmc0:aaaa SC16G 14.8 GiB
[ 0.878214] mmcblk0: p1 p2 p3
[ 0.895177] EXT4-fs (mmcblk0p2): mounted filesystem with ordered data mode. Opts: (null)
[ 0.895250] VFS: Mounted root (ext4 filesystem) on device 179:2.
[ 0.903222] devtmpfs: mounted
[ 0.906895] Freeing unused kernel memory: 1024K
[ 0.921886] Run /sbin/init as init process
[ 1.010577] random: fast init done
[ 1.195747] random: init: uninitialized urandom read (12 bytes read)
[ 1.320142] init: hwclock main process (48) terminated with status 1
[ 1.487392] random: mountall: uninitialized urandom read (12 bytes read)
[ 2.399692] systemd-udevd[144]: starting version 204
[ 2.564875] random: lsb_release: uninitialized urandom read (24 bytes read)
[ 4.795052] init: idmapd main process (368) terminated with status 1
[ 4.795139] init: idmapd main process ended, respawning
[ 5.508193] init: Failed to open system console: No such device
[ 5.514923] init: Failed to open system console: No such deviceThere is no "console [ttyPS0] enabled" but "WARNING: unable to open an initial console" at 0.8sec.
I have try remove the /dev/console and remake by mdnod but it did not work.
How can I fix it?
|
The linux boot message in dmesg doesn't output to uart
|
Solved my problem, so I thought I'd share. It turned out that TX/RX were flipped in the schematic for the PCB, and I didn't figure this out until I checked the data sheet for the processor.
So, USART vs. UART is a non-issue, and setserial -g /dev/ttyS1 returning undefined was an irrelevant distraction. Thus, to solve similar problems, verify device tree addresses (which were correct in my case) and verify pinouts on the hardware level (try swapping TX/RX even if you think they're correct). Also refer to the answers linked in my question.
|
I'm trying to set up a USART serial port on a custom board with a SAMA5D36 processor, but I am unable to read in data from a connected device. When I run setserial -g /dev/ttyS1 I get the following output:
/dev/ttyS1, UART: undefined, Port: 0x0000, IRQ: 22
Now, I have seen a similar question (linked here), but the solutions haven't worked for me. I'm wondering, can I not set the port up this way because it's USART not UART? Or does that not really make a difference?
As far as I can tell, the device tree is correctly setting up the port in the kernel, and I have configured the port as well as I can using stty. Any suggestions?
|
Linux USART Serial Port
|
This error can be caused by unison upgrade or corrupted file. Removing the archives from ~/.unison should help in this case.
(If you have created preferences files, e.g. ~/.unison/myjob.prf, obviously don't delete those.)
However, it might be necessary to synchronize the contents manually before the first run (if there were any changes after the automatic synchronization stopped working).
Alternatively, it may be fixed by removing only the files with 0 byte (the sync cache ones that may be emtpy) at ~/.unison. Also this option -ignorearchives can be used to ignore any files there; so for specific run cases it is useful, like a "profile" that we create on the command line itself.
|
the few last days I am getting this exception when running unison:
"End_of_file exception raised in loading archive" (this indicates a bug!)
it does not help a bit, I cannot find answer elsewhere on google, ppl talk about it but seem not be able to solve?
I checked my files, there are broken symlinks but that never was a problem before..
the full command is basically:
unison "$PATH1" "$PATH2"
-links false
-fastcheck true
-times
-retry 2
-follow "Regex .*"
-force "$PATH1"
-nodeletion "$PATH1"
-nodeletion "$PATH2"
-batch
-ui text
|
unison "end of file exception"
|
As @marcus-müller pointed out, this functionality is broadly referenced as 'roaming user profiles', and it is primarily built around two pillars:User credentials
User $HOME directoriesThe first one is commonly addressed with centralized systems such as LDAP+Kerberos and with SSSD on the client.
The second one can be addressed using NFSv4 and krb5/krb5i/krb5p, but it can result in sluggishness if your client is on WiFi or in a remote location.
If you want to move away from a centralized $HOME for your users, but do not want to give up the flexibility of a centralized setup entirely, a workaround could be:Upon login, run a rsync script to (create the local $HOME if it does not exist and) bi-directionally sync the local $HOME with the central $HOME
Upon logout, run a rsync script to upload all local changes to the central $HOME
Optionally, perform intermittent syncsGDM can be setup to run scripts at login (/etc/gdm/PostLogin/Default) and logout (/etc/gdm/PostSession/Default). A cronjob or systemd timer can be set up for the intermittent syncs.
Some caveats I have thought of:Try to limit the size of the $HOME directories, e.g. with quota and a separate directory where the users can store shared documents (which can still be shared over NFS without the penalty of overall sluggishness)
Optimize the rsync scripts to omit cache and tmp directories (or maybe simply relocate the $XDG_CACHE_HOME and $XDG_DATA_HOME outside of $HOME)/EDIT: I have published a shell script to help synchronise the local $HOME with the remote $HOME: https://github.com/zenlord/vagabond.sh - feel free to comment :)
|
For over a decade now I have been working in a full Debian environment in my small office (currently 1 server, 7 users, 3 desktops, 4 laptops). Authentication is based on Kerberos, user profiles are managed in LDAP, and $HOME is served to all of the clients over NFSv4 with the help of pam_mount or autofs. This setup is very much ok for desktop users working on the local lan.
Two years ago, I started using the same setup for laptop users. The WiFi connection caused some additional sluggishness, and for sure once the users tried to use the laptop outside of the office, things got really slow. Optimizing $XDG_{CACHE,DATA,CONFIG}_HOME and looking into specific optimizations for Firefox on NFS made things a bit better.
I'm now thinking of moving the $HOMES to the laptops+desktops. It is nice that a user can switch devices if one goes down, but that only happens once in a while. Sacrificing this flexibility for a faster day-to-day user experience seems like a good decision. If I could bi-directionally sync the local $HOME to the central server on startup and shutdown, there probably wouldn't be a tradeoff at all...'unison' seems like a good candidate for keeping the local $HOME in
sync with a central copy, but it seems to require exact same versions
between server and client, and that I cannot commit to.
'lsyncd' seems to be a very good candidate, but I don't seem to find any user
stories using the tool for their $HOME directories...
I even had a brief look at 'GlusterFS', but that seems like it's a non-trivial replacement.
Anyone has any experience and maybe best practices to share? I don't mind a bit of experimenting, but I'm afraid I'm missing some obvious downsides to the above... Thx!
|
Centralized $HOME for roaming devices - sync instead of NFS?
|
I just ran into this problem myself, and it took quite a bit of searching to find the answer! So here it is, and it works for me.
To use multiple versions of unison, install unison-all. Then...
Using multiple versions of Unison on the client
Choose a specific version to run by appending the version number, like so:
unison-2.40 ...Or, if you want to run the latest version, you can simply type:
unisonUsing multiple versions of Unison on the server
Instruct the client version of Unison to invoke the matching version of Unison on the server using the -addversionno tag, like so:
unison -addversionnoFor futher details
and if you still get an
Fatal error: Received unexpected header from the serversee this solution.
|
I have two machines. One with unison v. 2.40 (Debian Jessie) and a new one (Debian Stretch) where I installed package unison-all, which brought in unison versions 2.32, 2.40 and 2.48. However, I was unable to make my 2.40 work against the new machine, since it only presented v. 2.48. No matter what I do, I get:
expected "Unison 2.40\n" but received "Unison 2.48\n\000\000\000\000\017",I worked around the issue by removing unison-all and installing v. 2.40 explicitly, but I wonder what to do if I ever want to use two concurrent versions of unison on this machine.
|
How to use multiple versions of unison on one system?
|
As hinted at by this macports.org ticket, the problem lies in having used two different major versions of OCaml (3.12 vs 4.0) in compilation on the two machines. Either use the same binary on both machines or (as was the case for me due to different architectures) recompile unison with identical OCaml versions.
(Side note: The Windows version compiled by Karl M requires OCaml 3.12)
|
When trying to sync two paths (one of which is remote) via ssh, unison fails withFatal error: Internal error: New archives are not identical.while syncing via a network mount works just fine.
While unison -debug all yields no indication on the possible error, having it use ssh -v causes a lot ofchannel 0: bad ext dataerrors. However, both machines run the same version of unison (2.40.63).
|
How to fix unison failing with "Fatal error: Internal error: New archives are not identical" for identical paths?
|
You're mixing Unison versions 2.48.3 and 2.48.4. Unison is very finicky about this since the developer changes the format of the Unison archive files even between minor versions. Anyways, the versions of Unison should match between all your machines. I would skip the app store, and compile/install 2.48.3 manually on your Ubuntu machine.
Furthermore, you've got to make sure that you're using the same version of oCaml to compile the same version of Unison on each machine ;)
|
I have two machines that one runs Ubuntu 18.04 and the other one Ubuntu 20.04. I want to use Unison to sync files between them but there are some issues. Firstly, because I sync with another machine too, I compiled from source Unison 2.48.3. Then in the Ubuntu 18.04, I installed from the Ubuntu software Unison 2.48.4 and so I did with Ubuntu 20.04. After setting them up properly, from the command line of Ubuntu 18.04 I run
unison-2.48.4-gtk
and try to sync. Although everything works fine, i.e. it finds the machine and the directory then I get the message:
Fatal error during unmarshaling (input value:ill-formed message) possibly because client and serer have been compiled with different versions of OCaml compiler.
In the 20.04, I checked the version of OCaml but apparently it returned nothing (even though I had installed unison from app store).
On the 18.04 the version is 4.05.0.
Any ideas on what I can do?
|
Unison and version/compiler conflicts
|
When you compile Unison from source, there is a separate executable unison-fsmonitor that is created. When you run this unison-fsmonitor it prints VERSION 1 and then waits as expected. Just compile Unison on your VM and use that executable instead of the fsmonitor.py script.
You can see in the change-log for Unison 2.48.3 that they created a new file-watcher utility. It's not clear to me why fsmonitor.py is included in this release if you are supposed to use the new utility. Or maybe the new utility and the python script actually perform different tasks ... ?
|
I'm trying to sync a folder in my host OSX to a VM running Ubuntu. (laravel/homestead). This is the command I run on my host:
$ unison ssh://[emailprotected]//home/vagrant/www ~/unison/www -repeat watch
which produces the following output
Contacting server...
Connected [...]
Looking for changes
Waiting for changes from server
Fatal error: Server: Unexpected response 'Usage: unison-fsmonitor [options] root [path] [path]...' from the filesystem watcher (expected VERSION)On my localhost:
$ unison -version
unison version 2.48.3
$ unison-fsmonitor
VERSION 1On my VM:
$ unison -version
unison version 2.48.3
$ unison-fsmonitor
Usage: unison-fsmonitor [options] root [path] [path]...
This program monitors file system changes on all given (relative to root) paths
and dumps paths (relative to root) files to a file. When launched, this file is
recreated. While running new events are added. This can be read by UNISON
to trigger a sync on these files. If root is a valid unison profile, we attempt
to read all the settings from there.For my localhost, I installed unison via homebrew, and downloaded the unox.py file from github and installed it to /usr/local/bin/unison-fsmonitor.
For my VM, I used ppa:eugenesan/ppa for unison, and downloaded the source for version 2.48.3 from the unison website to get a copy of fsmonitor.py, which I placed under /usr/bin/unison-fsmonitor.
Unison without -repeat watch works without issues.
I get the same output if I try to run the same command (reversing the ssh) form inside the VM. I've read that the unison-fsmonitor should comply with the protocol described in /src/fswatch.ml and this doesn't seem to be the case for the default fsmonitor.py script. Am I missing something? Is there another script that should be used for the unison-fsmonitor executable instead?
|
Running `unison -repeat watch` yields filesystem watcher error
|
In case anyone runs into the same issue as I did in the future - unison doesn't work with extended file attributes. One way to go around it is the copyprog + copythreshold=0 hack (see the profile in the original question), but this doesn't solve the problem of unison not noticing changes in xattr's. As I mentioned in one of the comments, even changing the modification time of the file won't make unison sync modified xattr's. Not only that, but it will even erase them the next time that file has its content changed.
The only way I could get bi-directional syncing with extended file attributes to work is to use bsync, change it by adding -X flag to rsync arguments AND change modification time of the file.
This is far from the ideal solution: changing modification time of the file, no Windows support, Python 3 dependency, last commit was last year etc, but that's the only software I found that does the job.
|
I have two machines, one Debian, one Ubuntu, both on ext4 with extended file attributes enabled in fstab. getfattr and setfattr are installed and work perfectly on both machines locally. However, unison (version 2.40.102) doesn't sync extended file attributes by default.
I googled around and found this blog post with profile settings that are supposed to enable extended attribute sync. So, I changed my profile, and now it looks something like this:
root=/path/to/dir
root=ssh://[emailprotected]//path/to/dir2
auto=true
batch=true
perms=0
rsync=true
maxthreads=1
retry=3
confirmbigdeletes=false
copythreshold=0
copyprog = rsync -aX --rsh='ssh -p 22' --inplace --compress
copyprogrest = rsync -aX --rsh='ssh -p 22' --partial --inplace --compress
copyquoterem = true
copymax = 1This profile syncs extended attributes for new files, but when I change extended attributes on a file that has already been synced and execute unison I get:
Nothing to do: replicas have not changed since last sync.Everything else syncs perfectly, but unison is unaware of the changes in extended attributes. I also tried disabling fastcheck, hoping it would make it check the files in more detail; didn't work. I tried rsync'ing in one direction and it worked perfectly. But I need bi-directional syncing so I'm stuck with unison.
I have looked through the official manual but it only mentions extended file attributes in passing. So my question is this: can this be done with unison? Am I missing something simple here? Alternatively, are there other open source tools that can achieve this? (I'm aware of bsync and bitpocket, but in my preliminary tests they also fail to notice extended file attribute changes).
|
Unison and extended file attributes
|
Reasons I am running Unison as a cron job rather than with -repeat (presumably as a systemd service)I would actually suggest that systemd is a perfect fit for when you want "cron but single instance". You don't need to keep it as a long-running service - you can use systemd timers in a cron-like manner while taking advantage of systemd to manage instances.Define a systemd service of Type=exec. This service will be considered active until the process exits. Use the same command line you currently use with cron.
Define a systemd timer to start the service previously defined. This can be set to happen either at a clock (calendar) time (OnCalendar=), or after a period (OnUnitActiveSec= would be relative to last service start time, OnUnitInactiveSec= would be relative to last service stop time). Personally, I like calendar since it's more predictable and won't drift.
Enable and start the timer. Don't enable the service, you don't want it running independently of the timer.
The timer will start the service on schedule. The service manager will ensure only one instance of the service is active. If the service is still running when the timer next fires, it will simply not do anything.Sample unit files to run Unison as SOMEUSER with profile SOMEPROFILE (except for their .service and .timer suffixes, both unit files must have the same name):
unison.service:
[Unit]
Description=Unison SOMEUSER@SOMEPROFILE
After=network.target[Service]
User=SOMEUSER
# Type=simple may be used on older versions
Type=exec
# may be relative to the service's root directory specified by RootDirectory=, or the special value "~"
WorkingDirectory=~
# systemd may insist on an absolute path for the executable
# Run unison with -terse to prevent cluttering the system journal
ExecStart=/usr/bin/unison -auto -batch -ui text -terse SOMEPROFILE
Restart=nounison.timer (fires daily at 13:37; for OnCalendar syntax see man 5 systemd.time, section Calendar Events):
[Unit]
Description=Daily unison SOMEUSER@SOMEPROFILE[Timer]
OnCalendar=*-*-* 13:37[Install]
WantedBy=timers.targetDrop these two unit files into /etc/systemd/system/, then run:
sudo systemctl enable unison.timer
sudo systemctl start unison.timerYou can test the setup by running sudo systemctl start unison.service – this requires only the service unit, not the timer unit. This is also a way to start sync out of schedule. Unison output will be written to the system journal with unison as a tag.
|
I have a setup in which I sync files between two Linux servers using Unison over an SSH connection. This is implemented by running the following command via cron:
unison -auto -batch PROFILEChanges to the fileset happen almost exclusively on one side (the other system is an off-site replica). They mostly take place through another Unison sync run (triggered manually) with a client machine, and can be from a few hours to a few weeks apart. Thus, conflicts between the two machine are not much of a concern in practice, and a delay of up to 24 hours for changes to get propagated to the other side is acceptable.
Reasons I am running Unison as a cron job rather than with -repeat (presumably as a systemd service) are:Predictable sync times, as the cron job is scheduled at a time when I am not expecting any manual sync operations from the third machine (whereas, say, -repeat 86400 would drift by the duration of the sync operation).
Changes mostly happen on server A, while the server-to-server sync job is triggered by server B (is it is easier network-wise if server B initiates the connection). Thus, as I understand, -repeat watch would not pick up most of the changes and even with -repeat watch+TIME, I’d be relying on TIME almost exclusively (correct me if I missed something).When changes do happen, they are usually low in volume. Occasionally, however, the data volume to be transferred is such that a single Unison run lasts several times as long as the interval between two Unison cron jobs (bandwidth between the systems is somewhat constrained). That would mean one Unison process is still running when cron launches the next one on the same set of files.
I take it that Unison has lock mechanisms in place, which presumably prevent the “new” process from messing with anything the “old” one is working on (but correct me if I’m wring or have missed something). But I’m wondering what the second Unison process would do in that case – I have observed it does not exit but stays around. Does that mean the second process would wait for the first to finish and only then start synchronization (which would then only include files that changed while the first sync was in progress and therefore failed to sync on the first run)?
Is it safe to launch a second Unison process while another one is still running on the same profile? (If not, what is a recommended way to prevent two concurrent Unison instances if, and only if, they are at risk of interfering with each other?)
What about the resource overhead of unison -repeat wait+TIME vs. occasionally having multiple Unison instances queued up, one running and the others waiting for it to finish?
|
Unison via cron, how to deal with one job still running as the next one starts
|
Per @Freddy's comment, the key is to compile unison from source on CentOS:
yum install ocaml ocaml-camlp4-devel ctags ctags-etagscd ~
wget http://www.seas.upenn.edu/~bcpierce/unison//download/releases/stable/unison-2.48.4.tar.gz
tar xvfz unison-2.48.4.tar.gz
cd src
makesudo cp -v unison /usr/local/sbin/
sudo cp -v unison /usr/bin/cd ~
rm -fr srcThen you will be able to run unison:
On the local server, go to the desired location, then test it with
unison -testServer . ssh://myuser@myremotehost//path/to/data/To do the real thing, simply remove -testServer from above. It's also a good idea to tmux before doing so.
|
I am trying to sync data between an Ubuntu instance and a CentOS 7 instance. It's like a bi-directional rsync so I thought unison would be the best tool. I installed it on both instances but when I tried to connect them I received an error because the versions are different:
unison -testServer . ssh://myuser@myremotehost/efs/home/
Contacting server...
myuser@myremotehost's password:
Fatal error: Received unexpected header from the server:
expected "Unison 2.48\n" but received "Unison 2.40\n\000\000\000\000\017",
which differs at "Unison 2.40".
This can happen because you have different versions of Unison
installed on the client and server machines, or because
your connection is failing and somebody is printing an error
message, or because your remote login shell is printing
something itself before starting Unison.So I tried to make the versions match but when I look I only see the one version available on Ubuntu.
myuser@mylocalhost:/nas/$ apt policy unison
unison:
Installed: 2.48.4-1ubuntu1
Candidate: 2.48.4-1ubuntu1
Version table:
*** 2.48.4-1ubuntu1 500
500 http://us.archive.ubuntu.com/ubuntu bionic/universe amd64 Packages
100 /var/lib/dpkg/statusAnd when I look on CentOS 7 I don't see any versions
$ yum --showduplicates list unison
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: d36uatko69830t.cloudfront.net
* epel: mirror.prgmr.com
* extras: d36uatko69830t.cloudfront.net
* updates: d36uatko69830t.cloudfront.net
Error: No matching Packages to listHowever, I can install it with no problem:
$ sudo yum install unison
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: d36uatko69830t.cloudfront.net
* epel: d2lzkl7pfhq30w.cloudfront.net
* extras: d36uatko69830t.cloudfront.net
* updates: d36uatko69830t.cloudfront.net
Package unison240-gtk-2.40.128-5.el7.x86_64 already installed and latest version
Nothing to doAm I doing something wrong with finding the versions? How can I make them match?
The local host is:
myuser@mylocalhost:/nas$ cat /etc/*release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=18.04The remote host is:
$ cat /etc/*release
CentOS Linux release 7.6.1810 (Core)
|
How do I run unison between Ubuntu and CentOS 7
|
Use Regex instead of Path when you need to match an arbitrary directory depth.
ignore = Name *.ext
ignorenot = Regex .*/dir_I_want_to_sync/.*\.ext
|
I am trying to perform a sync using Unison (2.40.102) where I want to ignore all files with a specific extension, say *.ext, but not ignore the files with this extension if they are in a specific subfolder.
Folder structure:
main_dir
|file.ext
|...
|--sub_dir_1
|more_files.ext
|...
|--sub_dir_2
|even_more_files.ext
|...
|--dir_I_want_to_sync
|sync_this_file1.ext
|...
|sync_this_fileN.ext
|--some_arbitrarily_named_dir
|also_sync_this.ext
|...
|--more_arbitrarily_named_dirs_with_ext_files_in_them
|...As the folder structure is not constant, I cannot just ignore only specific paths, but have to do this very generally. My idea was to first ignore all the files with the extension *.ext and then un-ignore the ones below dir_I_want_to_sync.
However, that is were I am failing to find the right command...
The relevant parts of my profile file look like this:
# Ignore all files with extension *.ext
ignore = Name {.,}*{.ext}# Try to not ignore the files within the subdirectory (NOT WORKING)
ignorenot = Path */dir_I_want_to_sync/* # 1)
ignorenot = Name */dir_I_want_to_sync/{*/}*{.ext} # 2)Remarks:
1) Does not do anything, because the files are ignored by their filename, not their path
2) Was meant to reverse the ignore on all the files in dir_I_want_to_sync, but it does not catch all subfolders.
Is there any way to apply the ignorenot = Name ... to a file regardless of how deep it is in the directory structure, as long as it is below a directory with a specific name?
(I hope, this was not too confusing. I am happy to clarify!)
|
Unison: Ignore all files with *.ext, except those in a specific subdirectory
|
If you're always synchronizing in the same direction, use rsync. If you're synchronizing in both directions, use unison. Unison supports both Linux and windows; the documentation explains how to set it up under Windows (you'll need an SSH client as well).
To synchronize between more than two locations, choose one as the master and synchronize every other location with the master. Here, set up both the workstation and the laptop to synchronize with the Freebox.
You'll need to have a unison binary on the Freebox. Since it runs Linux and has an x86 processor, if it doesn't have unison already, you can copy the binary from any 32-bit Linux installation.
|
I want to synchronize my personal document repository between my different computers in my home. Today this folder is under a dedicated partition of the hard drive of a dual boot workstation.
My configuration is the following one:Dual boot Workstation running Ubuntu 11 and windows Xp (the documents are simply shared using the dedicated partition)
Laptop running Ubuntu 12.04 (Today no access to the documents)
A freebox with an external hard drive pluged to itWhat I want is to be able to synchronize this document folder also with the laptop and in addition to have a "backup" of this on the hard drive attached to the freebox.
What tools should I use for this (rsync, unison, others?)
|
Backup and synchronization
|
You could create a config file for ssh(~/.ssh/config) with the content
Host UnisonHost
HostName 192.168.1.102
User usernameand then call unison with UnisonHost:
unison /var/www ssh://UnisonHost/var/www
|
I am trying to set up Unison and am testing the connection. I run this command from the documentation:
unison /var/www ssh://192.168.1.102//var/wwwbut it tries to log into the remote server using my local machine's username. I've tried several things, but nothing works. I've tried adding username@ssh... and also searched for flags to use, but found none.
|
Unison - login over ssh with different username at remote server
|
copythreshold = 1024Then unison changes files bigger than 1Mb in place using rsync instead of completely re-transferring.
|
I'm using Unison to synchronize my music collection to a few different sources, namely a couple computers over SSH and a hard drive.
One thing I've noticed is that SSH updates are incredibly fast in comparison to hard drive syncs, possibly because rsync (or whatever's running under the hood) is only moving what's changed. Add that to the fact that I can run multiple SSH copy actions at once and copying to a local USB hard drive is left in the dust, as it only copies one file at a time and overwrites the entire file every time.
When changing the encoding of ID3v1 tags (for compatibility tests), my entire ~5000 file music library changes needs to be backed up to the other computers and hard drive.
Is there any way for me to:increase the number of simultaneous copies; and
only copying the parts of the files that have changed? Here's my Unison profile:
# Unison preferences
batch = false
confirmbigdel = true
copymax = 10
logfile = .unison/unison-music.log
maxthreads = 30
perms = 0
sortbysize = trueroot = /home/me/Music
root = /media/truecrypt1/media/music
|
Decreasing hard drive sync time with Unison
|
There's the preference times, give it a try. The doc mentions modification time, but doesn't say anything about creation time, so you'll have to test the exact behaviour, which may also depend on the filesystem type.
|
unison is a very useful tool to synchronize filesystems, for instance between different machines. It detects conflicts and asks the user about them before actually copying anything (user then decides which version of the file to copy into the other, or whether to ignore changes for the conflicting file altogether).
In that respect, it serves a specific purpose that cannot be fulfilled by rsync, which only copies files in one direction and thus mirrors one filesystem into another.
However, whereas rsync somehow manages to preserve file creation dates, unison does not. This can be a drawback if the purpose of synchronizing is to be able to switch working between say a desktop and a laptop while wanting to preserve the exact same filesystem, creation dates and all.
So the question is: is there some way to coax unison into preserving file creation dates like rsync does? (nothing to that effect appears in any obvious way in the documentation pointed to by the link in the first word of this question)
|
Can unison be made to preserve file creation dates?
|
I have always used Unison in a star topology to synchronise my four machines. The reason for this is that it is not a versioning file system (like git for example), but rather a synchronisation tool.
If you do opt for a distributed topology (which you will have to set by creating a configuration file for each device and synchronising all), you will undoubtedly end up doing a large amount of manual conflict resolution, which will be grim. This will certainly be the case unless you make only extremely basic changes to the files on the system and only on one device at a time.
So, suggestions:Rent a cheap virtual server with enough storage space for the data that you want to synchronise.
Try the distributed topology and see whether it causes too many problems to be usable.
|
I have a handful of devices, and am considering keeping them in sync with Unison.
The devices are not running all the time, they are switched off a few hours per day, not necessarily at the same time. None of the devices is running 24 hours a day. So I need real peer-to-peer, for instance see how a change (marked as *) propagates from A to B,C,D even though none has been running during all syncs:
A-on* B-on C-off D-off
A-on* B-on* C-off D-off
A-off* B-on* C-off D-off
A-off* B-on* C-on D-off
A-off* B-on* C-on* D-off
A-off* B-off* C-on* D-off
A-off* B-off* C-on* D-on
A-off* B-off* C-on* D-on*Unfortunately, the Unison user manual recommends a star topology for more than 2 machines:Using Unison to Synchronize More Than Two Machines
Unison is designed for synchronizing pairs of replicas. However, it is possible to use it to keep larger groups of machines in sync by performing multiple pairwise synchronizations.
If you need to do this, the most reliable way to set things up is to organize the machines into a “star topology,” with one machine designated as the “hub” and the rest as “spokes,” and with each spoke machine synchronizing only with the hub. The big advantage of the star topology is that it eliminates the possibility of confusing “spurious conflicts” arising from the fact that a separate archive is maintained by Unison for every pair of hosts that it synchronizes.Despite that, is there any way to achieve real peer-to-peer with Unison?
|
How to configure Unison for real peer-to-peer?
|
As it turned out in the discussion regarding the bug report -addversionno currently truncates the version info at the minor number.
I had installed
unison-2.48.3at the server and client (by copying the binary), but -addversionno was looking for
unison-2.48which did not exist.
As a workaround I created the symbolic link unison-2.48 pointing to unison-2.48.3.
ln -s unison-2.48.3 unison-2.48Now it works as expected.
|
Following instructions in How to use multiple versions of unison on one system? I have used
unison -addversionnoto sync a Debian and Raspbian system, but received this error
Contacting server...
Fatal error: Received unexpected header from the server:
expected "Unison 2.48\n" but received "bash: unison-2.48: command not found\n",
which differs at "b".
.
:It seems like the same versions are found but misinterpreted as incompatible.
What can I do to get it working?
I have also filed a bug on GitHub.
|
unison -addversionno Received unexpected header from the server
|
Somehow, this issue went away. I'm not sure which of the following fixed it, but here's what I did:Deleted my local replica and the archive files under ~/.unison
Uninstalled then reinstalled unison locally (the same version, 2.48.4)
Added force = ssh://username@my-remote-server//home to the config to mirror the remote server
Once it had synced, I removed the force config option and started as usualNow, for whatever reason and despite the version mismatch, the permissions are working fine.
|
If I modify a local file, unison syncs that file but it removes all permissions on the destination server, leaving only the following permissions:
-rw-------My local config contains the switches which should tell unison to ignore file permissions:
~/.unison/my-server.prf
perms = 0
dontchmod = trueI start unison with the following command:
unison -ui text -repeat watch my-serverMy local unison is version 2.48.4, remote is 2.48.3
|
Unison is ignoring local config and overriding remote file permissions
|
If I understand your intention correctly, all you need to do is to append a trailing slash to your first argument of rsync. That is, instead of writing
rsync -zrahvWt --remove-source-files ~/Documents/test3/source-DRV ~/Documents/test3/dest-Twrite
rsync -zrahvWt --remove-source-files ~/Documents/test3/source-DRV/ ~/Documents/test3/dest-TEdit
I have modified the above commands according to the OP's comments in regard of answering his/her own question.
With regards to the parameters of rsync:-z: compress file data during the transfer
-r: recursive: To copy the folders under the current folder and its files, not just the files under the current folder
-a: preserve almost everything (dates, permissions, etc.)
-h: output numbers in a human-readable format
-v: verbose: to print more details of the process on the screen
-W: copy the whole file, not update the difference of data only.More details can be found by running man 1 rsync.
|
It's been many hours reading and reading everywhwere.. testing rsync, Grsync, and Unison.. with no hope!
The normal way of rsync copying/synchronizing files between two local folders is to "copy the whole folder itself! - not the contents as thought! - nothing else!
To experiment with, I made two folders with different names on same root. When got this result, I separated them and gave the source the same name of destination in case this was the cause.rsync -zrahvWnt --delete-after ~/Documents/test3/source-DRV ~/Documents/test3/dest-TI also used ALL possible options in Unison.. no hope! Same result!
"Resolve conflicts in favor of first root"
"Propagate Right to left"
"Right to left"
None worked differently! All gave same result: Copy the "whole" folder "inside" the other folder!
What I want basically is very simple:Check for missing files in the Target that are in the source.
Move - preferable, but copy is ok
only missing files from the source to the Target folder.
Do nothing to files that are identical in size, date and found in both folders.This will result in a "Complete Folder" - which is the destination, and a "Useless Folder" which is the source, to be deleted manually no problem.[Edit:] While implementing the solution, I found that I've used the -n option, which makes "dry run".. that's probably another reason why nothing worked. I removed it and everything went as expected!
|
How to move missing files only from source to target folder
|
You can test if the output of the script (i.e. rc file) is a terminal if not; if it is it should be safe to output text, and if not a terminal don't output anything:
if [ -t 0 ]; then
# check your jobs here and print any info you want to see
fi
|
Recently my Unison started throwing up some strange error whenever I tried to sync between my laptop and my PC. I realized that I had added a line in bashrc that would print my pending tasks whenever I would open a terminal.
The line added in my bashrc:
task list #this command comes from a small utility called taskwarriorThe error is here:
Received unexpected header from the server:
expected "Unison 2.40\n" but received "\nID Proj Age Description\n-- -------- --- -----------------------------\n 2 11d Do the research work\n 3 Life 11d Get stickynotes from stationary\n 1 Technical 11d Fix the error\n\n3 tasks\n",
which differs at "\n".
This can happen because you have different versions of Unison
installed on the client and server machines, or because
your connection is failing and somebody is printing an error
message, or because your remote login shell is printing
something itself before starting Unison.As mentioned in the error log, my login shell is printing something itself before starting Unison. This is indeed the root of the problem.
So, now I have 2 questions:How do I make my bashrc to print "task-list" message AFTER the Unison header? Alternatively, can I make the ssh sessions to load separate RC file so that the "task-list" is not printed at all?
Will it be safe to print anything at all? I mean if I am somehow manage to print my task-list after the Unison header, is their any chance of data corruption during syncing, due to the additional information in the header? PS: Unison uses ssh for communication between the two systems.
|
Separate bashrc file for ssh sessions to avoid Unison Errors
|
No, you can't tell the newer version of Unison to pretend to be an old version. This is a notorious feature of Unison; the format of the archive file (that keeps track of everything being synced to improve efficiency) gets changed improved in each new version. So Unison versions across machines have to match precisely.
Since 2.40 is an older version I'm not sure if it would be in the Ubuntu repos. You could compile and install it from source, or try one of these pre-compiled binaries.
|
I have a small Debian ARM box with unison-2.40 installed. And a Ubuntu laptop which seems to have unison-2.48
I want to sync them with unison. But the the Ubuntu (which is newer) doesn't seem to recognise being explicitly asked to work with 2.40 (using -addversionno )
Is it possible to persuade 2.48 to pretend to be 2.40 or is there a Ubuntu package with 2.40 in it so I can sync these two machines?
|
Syncing between machines with different versions of Unison
|
Lost connection with the server does not necessarily mean a network issue – it can also mean that the remote Unison instance terminated the connection for whatever reason. (Because Unison is designed to work with different SSH backends, there is no reliable way to get any more detail about why the connection ended.)
Since at least Unison 2.52, the GUI should display any error messages from the server.
For those on an older version, running unison in text mode, i.e.
unison <profile> -ui textwhere <profile> equals any profile (*.prf file in your local .unison dir, minus the .prf extension), will give you a detailed error message.
Here, the lines after Contacting server and before Fatal error: Lost connection with the server are the errors we got from the remote system: it tried to create a dir at ~/.unison (because there was no dir at that path) but failed because there was another filesystem object at that path.
In this case, ~/.unison on the server was a broken symlink, as I had placed the .unison dir on a different filesystem than the home dir. The solution was to fix that symlink (i.e. recreate the dir at the path the symlink points to).
|
I have just rebuilt my file server after it suffered disk corruption. When I tried to re-sync data using Unison, I got the error messageLost connection with the serverI retried from the command line and got:
~$ unison someprofile -ui text
Contacting server...
Unison failed: Fatal error: Error in creating unison directory /home/user/.unison:
File exists [mkdir(/home/user/.unison)]
Fatal error: Lost connection with the serverI can open an SSH connection to the server. Both client and server run the same Unison version. What’s up here?
|
Unison over SSH, connection with server lost although SSH works
|
The software itself can only sync 2 folders/computers.
So what the documentation tells you is to setup so that one computer is in the center and every other syncs to it.
computer1 <--2way sync --> hub_computer <--2way sync --> computer2
^
|
|
2way sync
|
|
⌄might be easier to use syncthing
computer3
|
I need to sync 3 computers between each other in same way as Dropbox does e.g. if file changed on one pc others reflect this change as well. So i have choosen Unison. And found that it works perfect for 2 computers and how about 3 or more ? I tried to specify 3 roots in confg file but it does not work in such way and expects only 2 roots.
After few searches found this statement:Using Unison to Synchronize More Than Two Machines Unison is designed
for synchronizing pairs of replicas. However, it is possible to use it
to keep larger groups of machines in sync by performing multiple
pairwise synchronizations.
If you need to do this, the most reliable way to set things up is to
organize the machines into a “star topology,” with one machine
designated as the “hub” and the rest as “spokes,” and with each spoke
machine synchronizing only with the hub. The big advantage of the star
topology is that it eliminates the possibility of confusing “spurious
conflicts” arising from the fact that a separate archive is maintained
by Unison for every pair of hosts that it synchronizes.But i didn't find any working example where more than 3 pcs making syncing.
Below sample config which produce error once run - "Fatal error: Wrong number of roots: 2 expected, but 3 provided"
# Roots of the synchronization
root = /home/dem/testsync/
root = ssh://[emailprotected]//home/pc1/testsync/
root = ssh://[emailprotected]//home/pc2/testsync/auto=true
batch=true
confirmbigdel=true
fastcheck=true
prefer=newer
times=true
|
Sync muliple PCs with Unison
|
user@host is how SSH defines who it attempts to authenticate as (user) and where it should do that (host)
The user
This can be any local user account on the desktop and/or laptop you are connecting to. This user will need to be able to login to that machine via ssh and have full permissions to all the directories you are trying to sync.
You can view the current users available on your box in or the gui or cat /etc/passwd in a terminal.
You may want to add a user to Fedora specifically for your unison. Maybe sync?.
You will probably want to set up SSH key's between the two boxes.
The host
The host is the IP address or hostname component of the connection. In your case this will be the public IP of your desktop or laptop. Most likely your desktop as that will probably be more stable than your laptop IP which will roam around depending on where you are connected.
To find the current public IP of your laptop or desktop:
curl -s http://wtfismyip.com/textThis IP address will probably change over time, depending on your ISP, which can be a bit of a pain. You can get a dynamic DNS name from someone like NoIP to get around this. The ssh connection would become something like [emailprotected] and the DNS name whatver.no-ip.org will resolve to whatever machine is running the NoIP client.
You will most likely have a NAT router at home for your internet connection that you will need to port forward ssh through (TCP port 22) for all this to work.
Note
By the way, unless you really want to figure this out, it might be easier using one of the standard file hosts like Dropbox who provide a linux client or Google Drive via insync or gdfuse. They do all the hosting then, you just run the client that sits in the background and syncs.
|
I have a desktop at home, and a laptop that I take with me to places away from home, both have Fedora 20 installed. I edit the same files on either machine, and would like to be able to synchronise these files over the Internet to keep them identical, and avoid the error prone task of trying to repeat the same edits on the other one. It seems that using unison and ssh are the way to go, (but if there is a more straightforward method, I would be happy to use that instead, not diff and patch though) but what I have failed to discover is how to find out the identification details as in this extract from a document on how to use unison:
$ unison -testServer /home/ravisaive/Desktop ssh://172.16.25.125//home/ravisaive/DesktopThe document is: Unison – An Ultimate Local/Remote File Synchronization Tool for Linux
By Avishek Kumar Under: Backups On: March 21, 2014
So my question is, please: how do I obtain or define the equivalents of the 172.16.25.125 for my two machines? In other "how to do it" articles I see plink@plonk as the form of the identifiers, is this easier, and again how do I discover or define them?
Please, I would like an answer that is suitable for my completely novice status on this topic, not the sort that only experts can understand. Please insult my intelligence.A Final plea:
I have asked similar questions to this on the Internet and here, and cannot get an answer to what seems to me to be a straightforward question. Here is another quotation, about OpenSSH (From Fedora Wiki, SSH)
"The Default fedora setup for the ssh client works just fine for a basic
ssh server setup, like the one above. The syntax is even pretty basic,
command options username @ address or IP. An example follows.
ssh [emailprotected] "In my slow dim-witted way I just cannot see where the "[emailprotected]" comes from. Perhaps it is so obvious that I shouldn't need to ask, but I can't see it for myself. Please can someone explain this for me?
|
How do I get the information I need in order to use unison and ssh to synchronise files
|
As of Unison 2.40 (the latest version as I write), Unison doesn't support any file that isn't a regular file, a directory, or a symbolic link. Prior versions aborted the transfer upon encountering special files; since 2.40 these files are ignored. In 2.40.65, you don't get to see the name of ignored files in the first synchronization but it is displayed in subsequent synchronizations. So you could run Unison manually once, then parse its output to detect special files.
The other options are to patch Unison, or to look for special files manually and copy them.
One method to synchronize these files would be to keep a repository of them. For example, make a parallel hierarchy that encodes the special files with normal files, let Unison synchronize that, and decode the parallel hierarchy back after synchronization. Before running unison, on each side:
mkdir -p .pipes .sockets
find . -type p -exec sh -c '
mkdir -p ".pipes/${0%/*}";
touch -r "$0" ".pipes/$0"; chmod -r "$0" ".pipes/$0"
' {} \;
find . -type s -exec sh -c '
mkdir -p ".sockets/${0%/*}";
touch -r "$0" ".sockets/$0"; chmod -r "$0" ".sockets/$0"
' {} \;After running unison:
(cd .pipes &&
find -type f -exec sh -c '
[ -p "../$0" ] && exit;
mkfifo "../$0";
touch -r "$0" "../$0"; chmod -r "$0" "../$0"
' {} \;)
find -type p -exec '[ -e ".pipes/$0" ] || rm "$0"' {} \;
(cd .sockets &&
find -type f -exec sh -c '
[ -S "../$0" ] && exit;
python -c "import os, sys; os.mknod(sys.argv[1], 0140000)" "../$0";
touch -r "$0" "../$0"; chmod -r "$0" "../$0"
' {} \;)
find -type s -exec '[ -e ".sockets/$0" ] || rm "$0"' {} \;(Warning: untested code. Assumes GNU tools (which includes any non-embedded Linux).)
I think this is more complex than warranted. There are very few applications that rely on a named pipe or socket existing: most create them as needed. Dropbox is the first case I've ever heard of. So I think I'd go for an ad hoc approach: skip the sockets when synchronizing, and create them for Dropbox as part of your new account creation procedure (together with the Unison profile creation and whatever else you do).
|
I'm using Unison to synchronize my home across several computers, and I've addressed everything but this.
The Dropbox configuration is partially skipped, and as a result Dropbox thinks there is no configuration and goes through the configuration wizard again.
Here's the output from Unison related to dropbox:
Reconciling changes
<-?-- dir .dropbox
<---- dir .dropbox-dist
<---- dir .dropbox-dist-new
[BGN] Copying .dropbox from /home/.nfs/jorge.suarez/linux-home to /home/remoto/jorge.suarez
[END] Copying .dropbox
[BGN] Copying .dropbox-dist from /home/.nfs/jorge.suarez/linux-home to /home/remoto/jorge.suarez
[END] Copying .dropbox-dist
[BGN] Copying .dropbox-dist-new from /home/.nfs/jorge.suarez/linux-home to /home/remoto/jorge.suarez
[END] Copying .dropbox-dist-new
partially transferred: .dropboxHere's the original contents of the directory:
$ ls -lah
total 22M
drwx------ 3 jorge.suarez users 3,9K 2013-01-25 21:39 .
drwxr-xr-x 43 jorge.suarez users 3,9K 2013-01-25 21:40 ..
srw------- 1 jorge.suarez users 0 2013-01-25 21:39 command_socket
-rw------- 1 jorge.suarez users 3,0K 2013-01-25 21:39 config.db
-rw------- 1 jorge.suarez users 20K 2013-01-25 21:39 config.dbx
-rw------- 1 jorge.suarez users 66K 2013-01-25 21:39 deleted.dbx
-rw------- 1 jorge.suarez users 4 2013-01-25 21:39 dropbox.pid
-rw------- 1 jorge.suarez users 2,0M 2013-01-25 21:39 filecache.dbx
-rw------- 1 jorge.suarez users 89 2013-01-25 21:39 host.db
-rw------- 1 jorge.suarez users 221 2013-01-25 21:39 host.dbx
-rw------- 1 jorge.suarez users 81 2013-01-25 21:39 hostkeys
srw------- 1 jorge.suarez users 0 2013-01-25 21:39 iface_socket
drwx------ 2 jorge.suarez users 3,9K 2013-01-25 21:39 l
-rw------- 1 jorge.suarez users 13K 2013-01-25 21:39 photo.dbx
-rw------- 1 jorge.suarez users 20M 2013-01-25 21:39 sigstore.dbx
-rw------- 1 jorge.suarez users 232 2013-01-25 21:39 unlink.dbAnd the synchronized one, just before Dropbox gets a chance to be launched:
$ ls -lah
total 22M
drwx------ 3 jorge.suarez users 4,0K Xan 25 22:09 .
drwx------ 43 jorge.suarez users 4,0K Xan 25 22:10 ..
-rw------- 1 jorge.suarez users 3,0K Xan 25 22:09 config.db
-rw------- 1 jorge.suarez users 20K Xan 25 22:09 config.dbx
-rw------- 1 jorge.suarez users 66K Xan 25 22:09 deleted.dbx
-rw------- 1 jorge.suarez users 4 Xan 25 22:09 dropbox.pid
-rw------- 1 jorge.suarez users 2,0M Xan 25 22:09 filecache.dbx
-rw------- 1 jorge.suarez users 89 Xan 25 22:09 host.db
-rw------- 1 jorge.suarez users 221 Xan 25 22:09 host.dbx
-rw------- 1 jorge.suarez users 81 Xan 25 22:09 hostkeys
drwx------ 2 jorge.suarez users 4,0K Xan 25 22:09 l
-rw------- 1 jorge.suarez users 13K Xan 25 22:09 photo.dbx
-rw------- 1 jorge.suarez users 20M Xan 25 22:09 sigstore.dbx
-rw------- 1 jorge.suarez users 232 Xan 25 22:09 unlink.dbIt seems iface_socket and command_socket are skipped because they are socket files. Is there anything I can do about this?
As a workaround, I could just parse the Unison output and create the socket files by hand. That should fix this particular issue, but the problem would remain for other socket files since the Unison output doesn't contain the name of the skipped files.
|
Unison can't synchronize Dropbox configuration (socket files)
|
Generally, “lost connection with the server” indicates that either the remote Unison process OR ssh exited with an error. (Since Unison needs to be compatible with different SSH implementations, getting more granular information out of it would be very complex to implement.)
Current versions of Unison (since at least 2.52) should display all error messages from the server, also in the GUI. On versions that do not, run:
unison <profile> -ui textThis will launch the text UI and attempt sync. You should get some output like the following:
Contacting server...
(...)
Fatal error: Lost connection with the serverThe lines between the first and the last one shown here are the output from the remote Unison process. They will give an indication of what went wrong.
In my case, as far as I remember, the remote Unison process crashed due to data corruption on the server disk.
|
I have a file server running Raspbian and a workstation running Ubuntu MATE 16.04. I use Unison to keep my home directory in sync. I’ve set it up to use a SSH connection.
The workstation runs Unison 2.48; the server has multiple versions (including 2.48). I’ve successfully propagated a couple of changes from the workstation to the server that way.
Now I’ve changed a file on the server. Unison looks for changes and correctly suggests updating the local copy with the file from the server.
However, when I click Go, I get the following error:
Fatal errorLost connection with the server.Unison settings are as follows:
# Unison preferences
label = Home dir
root = /home/me
root = ssh://me@fileserver//srv/file/me
sshargs = -C
addversionno = true
dontchmod = true
perms = 0
path = Documents
path = PicturesGeneral configuration problems (missing Unison version on server, wrong path etc.) are unlikely as changes are being detected and I have synchronized data various times (always workstation to server). It’s just the server-to-workstation scenario that fails.
I decided to “sacrifice” my edits to the new file and chose to replace the server version with the outdated local one. Surprisingly, that sync run completed successfully—everything works unless there are changes on the server side.
What’s happening here?
|
Connection with server lost when using Unison over SSH
|
I've determined an answer to my question, but it's a bit of a pain.
First, I changed the entry in my local ~/.ssh/config file so that it looks like this:
Host pod
User root
SetEnv UNISONLOCALHOSTNAME=pod
Hostname 184.26.5.182
Port 10666That's very easy, of course. But this won't work, however, unless sshd is configured in the container to allow the incoming ssh client to perform this SetEnv command. sshd is not configured to allow this by default. Consequently, I'll have to write a script that I can invoke on the container every time I spin it up, which does the following before I run unison on my desktop computer:Add the line AcceptEnv UNISONLOCALHOSTNAME onto the end of the container's /etc/ssh/sshd_config.
Tell the container's sshd to reload its config file by doingkill -HUP `cat /var/run/sshd.pid`ALTERNATIVELY:
And a bit more easily, I can just have a script modify /root/.bashrc in the container to have
export UNISONLOCALHOSTNAME=podplaced at the top of /root/.bashrc. (It wasn't working when I placed it at the bottom of the .bashrc because it turns out that there is code in the .bashrc that exits early if the shell is not interactive.)
Unfortunately, I can't just edit the .bashrc once and be done with it since the root filesystem is reinitialized every time the container is started up. So this rewriting of /root/.bashrc has to either be done by a script that I either keep on the persistent filesystem that the cloud service provides. Or I can do the editing of the container's .bashrc via a local script on my desktop that uses ssh and scp to make the change.
|
I'd like to use Unison to sync a directory between my desktop computer and a container that lives in the cloud. I have this kind of working with Unison, but the problem I'm seeing is that every time I spin up the container, it can have a different hostname and IP number, and sshd will be running on a different port number.
To make this mostly transparent to me, every time I spin up the container, I edit my ~/.ssh/config file like so:
Host pod
User root
Hostname 184.26.5.182
Port 10666I replace the IP number and port number accordingly.
Once I've done this, I can log into the container using ssh pod, etc. I can run scripts that rsync stuff around with no problem, even though they have the host alias "pod" hardwired into them. (If I knew how to make rsync do a bidirectional sync with deletions, then I'd just use that, but I'm pretty sure that that is not possible.)
My Unison config file looks like this:
root = /Users/me/path/to/dir
root = ssh://pod//path/to/dir
ignore = Path subdir1
ignore = Path subdir2Unfortunately, this does not work great because every time I spin up the container, I get a different port number (the IP number doesn't usually change), and Unison considers this to be a fresh sync. Which is not at all what I want.
Is there a way to tell Unison to ignore the fact that the remote container seems to have changed to a different computer, and to just trust that my "pod" host alias can be relied on for host identity?
|
Using Unison to sync my desktop computer with a container in the cloud
|
Cause
Using Unison over the network greatly speeds up synchronization across the network (as files are scanned for changes locally rather than over the network), but it requires matching Unison versions on both ends. As Unison relies on some OCaml libraries to do the synchronization, and as these libraries are apparently not guaranteed to be stable across OCaml versions, both ends need to be running not only the same Unison version, but the same Unison version built with the same OCaml version. (Yes, that is a bummer, and the Unison project has multiple issues on this: #375 is about the protocol being dependent on the OCaml version used for the build; it is currently being worked on but still open as of Unison 2.51.3. #407 is about the assumption that the wire protocol changes with every version.)
As far as I can see, Raspbian 9 (Stretch) ships with OCaml 4.02, Ubuntu 18.04 ships with OCaml 4.05, and Ubuntu 20.04 ships with OCaml 4.08. Presumably Unison gets build on the default OCaml version for the platform, but 2.48 doesn’t tell us that yet (later versions report their OCaml version). While apparently 4.05 happens to be compatible with 4.02, a compatibility-breaking change seems to have been introduced by 4.08.
The Unison project offers some binaries from their CI, and later versions allow choosing between different OCaml versions. Unfortunately, this is not available for the armhf architecture, and not yet for Unison 2.48, so that doesn’t help here.
Short-term solution (available right now)
For the moment, downgrading Unison on the Ubuntu machine to the version that shipped with 18.04 worked for me. (The package has minimal dependencies, other than a minimum version of libc.)
Grab unison-gtk_2.48.4-1ubuntu1_amd64 from the Ubuntu repos (this is the release that ships with 18.04; 20.04 has unison-gtk_2.48.4-4ubuntu1_amd64), and install it with:
sudo dpkg -i ~/Downloads/unison-gtk_2.48.4-1ubuntu1_amd64.debIn order to prevent the updater from undoing your changes on its next run, put the package on hold:
sudo apt-mark hold unison-gtk(If you decide to upgrade in the future, re-running this command with unhold will undo this, allowing the package to be upgraded again.)
You may have to delete your Unison cache—~/.unison/ar* and ~/.unison/fp*—on both ends.
For now, Unison will work again.
Short-to-mid-term solution (~mid-2021)
The upcoming Debian 11 (Bullseye) includes Unison 2.51. The way to go would then be to update the file server to Debian 11 and Unison 2.51, and for any workstation grab a binary build from Unison’s CI, with the matching program and OCaml version. Given the previous release cycles of Debian, it’s somewhat realistic for Bullseye to be released sometime in early/mid 2021.
Mid-to-long-term solution (2022–2023)
As I understood the corresponding issue, removing OCaml version dependencies from the wire protocol is just around the corner. The way to go would then to just have matching Unison versions on both ends (provided it is a version that has eliminated the dependency). It will probably take a while for your favorite distro to carry such a version after it is released, though—we’re probably talking about sometime between April 2022 and mid-2023.
Long-term solution
The Unison team are also working on assigning wire protocol version numbers separately from program versions, so several versions will eventually share the same version of the wire protocol, as long as the protocol does not indeed change. Once that happens, even different Unison versions will be able to work together, as long as both use the same protocol version.
Update as of 2024
Unison versions 2.52 and higher are compatible between each other. They are also compatible with 2.51 and 2.48, as long as both Unison versions were built against the same OCaml version. On Unison 2.51, unison -version will tell you what OCaml version Unison was built with. On 2.48, you will have to guess. If that version came from your OS repo, then the OCaml version on the repo is your best bet.
So, your best bet is to upgrade to Unison 2.52 or higher on both ends. If you can do that only on one end, you can upgrade just that end but ensure both ends were built against the same OCaml version.
See chapter 3 of the Unison manual on upgrading.
|
I have a file server running Raspbian 9, and use Unison over SSH to sync my home dir between these two.
This has worked well for the two years I was on Ubuntu 18.04, but after upgrading to Ubuntu 20.04, syncing over SSH aborts with an unmarshaling error, claiming the two Unison versions (local and remote) were built with different OCaml versions.
Unison version is 2.48 on all systems involved (pre and post upgrade).
What gives?
|
Unison with Raspbian file server no longer works after upgrading my laptop to Ubuntu 20.04
|
Yeah, the versions of Unison that you are running have to be identical. This is because the format for the archive file that Unison uses to keep track of stuff is improved changed in each new version.
Why not just install Unison from source? I would recommend installing 2.48 on your raspberry. You can download the source for Unison 2.48.3 here, and see instructions on how to compile and install it here. In fact I would recommending compiling and installing Unison from source on your desktop running Ubuntu too. This way you will avoid any unexpected hiccups if Ubuntu decides to update its Unison package, and also you can ensure that they are both compiled with the same version of OCaml, which has been an issue before.
It is also important to note that you will probably have to compile into bytecode instead of native code on your raspberry. You can do this by setting Native=false in the Makefile. See my answer here for more info.
|
On my raspberry pi computers:
pi@mizu:~ $ unison -version
unison version 2.40.102On my desktop ubuntu 16.04 xenial:
kayd@Trunk:~$ unison -version
unison version 2.48.3When trying to synchronize:
kayd@Trunk:~$ unison . ssh://pi@mizu/.
...
Fatal error: Received unexpected header from the server:
expected "Unison 2.48\n" but received "Unison 2.40\n\000\000\000\000\017",
which differs at "Unison 2.40".A related post 1 ask me to install unison-all, which I did, but it contains only version 2.48:
kayd@Trunk:~$ ls -l /usr/bin/unison*
lrwxrwxrwx 1 root root 24 Mai 20 22:15 /usr/bin/unison -> /etc/alternatives/unison
lrwxrwxrwx 1 root root 13 Mär 18 16:10 /usr/bin/unison-2.48 -> unison-2.48.3
-rwxr-xr-x 1 root root 2169968 Mär 18 16:10 /usr/bin/unison-2.48.3
lrwxrwxrwx 1 root root 13 Mär 18 16:10 /usr/bin/unison-latest-stable -> unison-2.48.3The two options I see:finding a PPA containing 2.40 for xenial
finding a PPA containing 2.48 for raspberryboth have been unsuccessful so far.
Based on the answer below from User mapierce271 I looked into compiling it myself, but it seems to turn out to be a bit of a nightmare. The very last post in the unison dev mailing list e.g. states "The new OCaml 4.03 release made a small incompatible change to a library. I've fixed version 2.48 so that it will compile with either 4.02 or 4.03 and made a new release." and "P.S. I've also added a bit of hopefully better error reporting when the dreaded 'ocaml 4.02.1 not compatible with ocaml 4.02.2' failure is encountered at runtime. I did this just now, so if you've already grabbed the source tarball please do it again." which leads me to the conclusion that everything is highly fragile and will likely break if anything is updated even with a minor revision number changes. Having many computers to synchronize, one or another is regularly updated.
|
How to install Unison 2.40 on Ubuntu 16.04 xenial (to resolve "Fatal error: Received unexpected header")
|
Backup your ~/.asoundrc - if you have one - and add the following, to a new ~/.asoundrc:
pcm.!default {
type plug
slave {
pcm "hw:0,0"
}
}
|
I have a USB audio device, configured as the default device at card 0.
I have a 3rd party application that is attempting to play wav files, which fail with the following:
Playing WAVE 'sound.wav' : Signed 16 bit Little Endian, Rate 44100 Hz, Mono
aplay: set_params:1239: Channels count non availableIf I try to manually play the very same wav, I get no error but also no sound:
aplay sound.wav
Playing WAVE 'sound.wav' : Signed 16 bit Little Endian, Rate 44100 Hz, MonoIf I specify device plughw:0,0, the sound plays correctly!
aplay -D plughw:0,0 sound.wav
Playing WAVE 'sound.wav' : Signed 16 bit Little Endian, Rate 44100 Hz, MonoI have tried various attemps at configuring ~/.asoundrc to set plughw:0,0 as the default, without success.
How can I apply the -D plughw:0,0 be default to all sound playback?
|
ALSA set plughw as default
|
This is easy to solve.
Issue: Your microphone is not getting enough power. The Raspberry Pi USB ports have issues supplying enough amps to USB devices that need more than power than USB memory cards.
Solution: Get an active USB hub (powered hub plugged into a power source like an outlet.) The hub will power the microphone.
|
On my RasPi board, Debian Linux, the USB microphone occasionally gets locked up such that nothing can use it. The microphone has a LED which is usually flashing, when it's locked, it turns off.
The utility arecord describes it as follows:
card 1: Device [DYNEX USB MIC Device], device 0:USB Audio [USB Audio]
Subdevices: 1/1
Subdevice #0: subdevice #0When the microphone stops working, arecord gives diagnostics like this:
> arecord -D plughw:1,0 > recording.wav
Recording WAVE 'stdin' : Unsigned 8 bit, Rate 8000 Hz, Mono
arecord: set_params:1145: Unable to install hw_params:
ACCESS: RW_INTERLEAVED
FORMAT: U8
etc...Unplugging and plugging the microphone fixes it, only because the current dip forces the RasPi to reboot! Not an ideal situation.
Is there a way to fix this from the command line or a C executable?
I also tried using ioctl(fd, USBDEVFS_RESET, 0) using the output from lsusb to provide the bus and device number. That turns the LED back on, but it's overkill. The device has to be re-setup using alsamixer.
|
RasPi - USB microphone locks up
|
1) USB audio devices are handled by the ALSA kernel drivers, and those react automatically to the vendor:product identifier of the USB device (or the generic interface). None of the drivers you'd normally use would use a devstr. You don't say why you need this string, but you are probably doing it wrong.
2) The example contents of your devstr are the USB path as shown in /sys/bus/usb/devices. It's impossible to derive it from your information, but you can derive it from lsusb -t if you can't find the device directly.
3) Please edit question with output of dmesg that appears after you plugin the device.
4) Very likely you are missing the correct ALSA drivers. If you haven't, update your kernel to the newest version.
Edit
What should happen is that the module snd-usb-audio is loaded based on the class of the USB device. What instead happens according your dmesg is that the device is recognized as a Human Interface Device, which is odd, unless it has buttons or similar that it represents in this way in addition to the sound function.
Please edit question with output of lsusb -vd 0d8c:0012, so we can see if it has a descriptor with an audio class. Also, verify that your kernel includes the module snd-usb-audio, and modinfo snd-usb-audio includes these two
alias: usb:v*p*d*dc*dsc*dp*ic01isc01ip*in*
alias: usb:v*p*d*dc*dsc*dp*ic01isc03ip*in*lines.
Edit
Assuming the duplicate lines at the end of your output are a copy&paste error: This looks like a standard USB soundcard, and should be automatically handled by snd-usb-audio. I just double checked with my USB soundcard, it looks like this driver doesn't produce messages on successful initialization. Please edit question with output of cat /proc/asound/cards/ to see if it was picked up.
If it wasn't, the only guess I have is that you somehow messed up your module dependencies, though I don't know what you did, and you didnt' say (but "(I have an unnamed software where) the configuration while requires ..." sounds somewhat ominous). If that should be the case, you can try a manual modprobe snd-usb-audio; you can try to fix it with depmod, or you can re-install (or upgrade, while you are at it) your kernel.
If that doesn't help, I'm out of ideas.
|
I have hardware to interact with that uses USB. It is a USB sound card The configuration file requires something like this:
devstr=1-1.3.1:1.0lsusb looks like this:
Bus 001 Device 004: ID 0d8c:0012 C-Media Electronics, Inc.
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp. SMSC9512/9514 Fast Ethernet Adapter
Bus 001 Device 002: ID 0424:9514 Standard Microsystems Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hubI need this device Bus 001 Device 004: ID 0d8c:0012 C-Media Electronics, Inc. to to be referenced in the configuration file.
UPDATE
Here is /var/log/messages (after a reboot)
Nov 17 12:33:52 44249 kernel: [ 3.658983] usb 1-1.2: New USB device found, idVendor=0d8c, idProduct=0012
Nov 17 12:33:52 44249 kernel: [ 3.671869] usb 1-1.2: New USB device strings: Mfr=1, Product=2, SerialNumber=0
Nov 17 12:33:52 44249 kernel: [ 3.685433] usb 1-1.2: Product: USB Audio Device
Nov 17 12:33:52 44249 kernel: [ 3.694574] usb 1-1.2: Manufacturer: C-Media Electronics Inc.
Nov 17 12:33:52 44249 kernel: [ 3.710586] input: C-Media Electronics Inc. USB Audio Device as /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2:1.3/0003:0D8C:0012.0001/input/input0
Nov 17 12:33:52 44249 kernel: [ 3.790955] hid-generic 0003:0D8C:0012.0001: input,hidraw0: USB HID v1.00 Device [C-Media Electronics Inc. USB Audio Device] on usb-3f980000.usb-1.2/input3END UPDATE
UPDATE 2 output of lsusb -vd 0d8c:0012
root@44249:~# lsusb -vd 0d8c:0012Bus 001 Device 004: ID 0d8c:0012 C-Media Electronics, Inc.
Device Descriptor:
bLength 18
bDescriptorType 1
bcdUSB 1.10
bDeviceClass 0 (Defined at Interface level)
bDeviceSubClass 0
bDeviceProtocol 0
bMaxPacketSize0 8
idVendor 0x0d8c C-Media Electronics, Inc.
idProduct 0x0012
bcdDevice 1.00
iManufacturer 1 C-Media Electronics Inc.
iProduct 2 USB Audio Device
iSerial 0
bNumConfigurations 1
Configuration Descriptor:
bLength 9
bDescriptorType 2
wTotalLength 253
bNumInterfaces 4
bConfigurationValue 1
iConfiguration 0
bmAttributes 0x80
(Bus Powered)
MaxPower 100mA
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 0
bAlternateSetting 0
bNumEndpoints 0
bInterfaceClass 1 Audio
bInterfaceSubClass 1 Control Device
bInterfaceProtocol 0
iInterface 0
AudioControl Interface Descriptor:
bLength 10
bDescriptorType 36
bDescriptorSubtype 1 (HEADER)
bcdADC 1.00
wTotalLength 100
bInCollection 2
baInterfaceNr( 0) 1
baInterfaceNr( 1) 2
AudioControl Interface Descriptor:
bLength 12
bDescriptorType 36
bDescriptorSubtype 2 (INPUT_TERMINAL)
bTerminalID 1
wTerminalType 0x0101 USB Streaming
bAssocTerminal 0
bNrChannels 2
wChannelConfig 0x0003
Left Front (L)
Right Front (R)
iChannelNames 0
iTerminal 0
AudioControl Interface Descriptor:
bLength 12
bDescriptorType 36
bDescriptorSubtype 2 (INPUT_TERMINAL)
bTerminalID 2
wTerminalType 0x0201 Microphone
bAssocTerminal 0
bNrChannels 1
wChannelConfig 0x0001
Left Front (L)
iChannelNames 0
iTerminal 0
AudioControl Interface Descriptor:
bLength 9
bDescriptorType 36
bDescriptorSubtype 3 (OUTPUT_TERMINAL)
bTerminalID 6
wTerminalType 0x0301 Speaker
bAssocTerminal 0
bSourceID 9
iTerminal 0
AudioControl Interface Descriptor:
bLength 9
bDescriptorType 36
bDescriptorSubtype 3 (OUTPUT_TERMINAL)
bTerminalID 7
wTerminalType 0x0101 USB Streaming
bAssocTerminal 0
bSourceID 8
iTerminal 0
AudioControl Interface Descriptor:
bLength 7
bDescriptorType 36
bDescriptorSubtype 5 (SELECTOR_UNIT)
bUnitID 8
bNrInPins 1
baSource( 0) 10
iSelector 0
AudioControl Interface Descriptor:
bLength 10
bDescriptorType 36
bDescriptorSubtype 6 (FEATURE_UNIT)
bUnitID 9
bSourceID 15
bControlSize 1
bmaControls( 0) 0x01
Mute Control
bmaControls( 1) 0x02
Volume Control
bmaControls( 2) 0x02
Volume Control
iFeature 0
AudioControl Interface Descriptor:
bLength 9
bDescriptorType 36
bDescriptorSubtype 6 (FEATURE_UNIT)
bUnitID 10
bSourceID 2
bControlSize 1
bmaControls( 0) 0x43
Mute Control
Volume Control
Automatic Gain Control
bmaControls( 1) 0x00
iFeature 0
AudioControl Interface Descriptor:
bLength 9
bDescriptorType 36
bDescriptorSubtype 6 (FEATURE_UNIT)
bUnitID 13
bSourceID 2
bControlSize 1
bmaControls( 0) 0x03
Mute Control
Volume Control
bmaControls( 1) 0x00
iFeature 0
AudioControl Interface Descriptor:
bLength 13
bDescriptorType 36
bDescriptorSubtype 4 (MIXER_UNIT)
bUnitID 15
bNrInPins 2
baSourceID( 0) 1
baSourceID( 1) 13
bNrChannels 2
wChannelConfig 0x0003
Left Front (L)
Right Front (R)
iChannelNames 0
bmControls 0x00
iMixer 0
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 1
bAlternateSetting 0
bNumEndpoints 0
bInterfaceClass 1 Audio
bInterfaceSubClass 2 Streaming
bInterfaceProtocol 0
iInterface 0
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 1
bAlternateSetting 1
bNumEndpoints 1
bInterfaceClass 1 Audio
bInterfaceSubClass 2 Streaming
bInterfaceProtocol 0
iInterface 0
AudioStreaming Interface Descriptor:
bLength 7
bDescriptorType 36
bDescriptorSubtype 1 (AS_GENERAL)
bTerminalLink 1
bDelay 1 frames
wFormatTag 1 PCM
AudioStreaming Interface Descriptor:
bLength 14
bDescriptorType 36
bDescriptorSubtype 2 (FORMAT_TYPE)
bFormatType 1 (FORMAT_TYPE_I)
bNrChannels 2
bSubframeSize 2
bBitResolution 16
bSamFreqType 2 Discrete
tSamFreq[ 0] 48000
tSamFreq[ 1] 44100
Endpoint Descriptor:
bLength 9
bDescriptorType 5
bEndpointAddress 0x01 EP 1 OUT
bmAttributes 9
Transfer Type Isochronous
Synch Type Adaptive
Usage Type Data
wMaxPacketSize 0x00c8 1x 200 bytes
bInterval 1
bRefresh 0
bSynchAddress 0
AudioControl Endpoint Descriptor:
bLength 7
bDescriptorType 37
bDescriptorSubtype 1 (EP_GENERAL)
bmAttributes 0x01
Sampling Frequency
bLockDelayUnits 1 Milliseconds
wLockDelay 1 Milliseconds
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 2
bAlternateSetting 0
bNumEndpoints 0
bInterfaceClass 1 Audio
bInterfaceSubClass 2 Streaming
bInterfaceProtocol 0
iInterface 0
Interface Descriptor:
bLength 9
bDescriptorType 4Bus 001 Device 004: ID 0d8c:0012 C-Media Electronics, Inc.
Device Descriptor:
bLength 18
bDescriptorType 1
bcdUSB 1.10
bDeviceClass 0 (Defined at Interface level)
bDeviceSubClass 0
bDeviceProtocol 0
bMaxPacketSize0 8
idVendor 0x0d8c C-Media Electronics, Inc.
idProduct 0x0012
bcdDevice 1.00
iManufacturer 1 C-Media Electronics Inc.
iProduct 2 USB Audio Device
iSerial 0
bNumConfigurations 1
Configuration Descriptor:
bLength 9
bDescriptorType 2
wTotalLength 253
bNumInterfaces 4
bConfigurationValue 1
iConfiguration 0
bmAttributes 0x80
(Bus Powered)
MaxPower 100mA
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 0
bAlternateSetting 0
bNumEndpoints 0
bInterfaceClass 1 Audio
bInterfaceSubClass 1 Control Device
bInterfaceProtocol 0
iInterface 0
AudioControl Interface Descriptor:
bLength 10
bDescriptorType 36
bDescriptorSubtype 1 (HEADER)
bcdADC 1.00
wTotalLength 100
bInCollection 2
baInterfaceNr( 0) 1
baInterfaceNr( 1) 2
AudioControl Interface Descriptor:
bLength 12
bDescriptorType 36
bDescriptorSubtype 2 (INPUT_TERMINAL)
bTerminalID 1
wTerminalType 0x0101 USB Streaming
bAssocTerminal 0
bNrChannels 2
wChannelConfig 0x0003
Left Front (L)
Right Front (R)
iChannelNames 0
iTerminal 0
AudioControl Interface Descriptor:
bLength 12
bDescriptorType 36
bDescriptorSubtype 2 (INPUT_TERMINAL)
bTerminalID 2
wTerminalType 0x0201 Microphone
bAssocTerminal 0
bNrChannels 1
wChannelConfig 0x0001
Left Front (L)
iChannelNames 0
iTerminal 0
AudioControl Interface Descriptor:
bLength 9
bDescriptorType 36
bDescriptorSubtype 3 (OUTPUT_TERMINAL)
bTerminalID 6
wTerminalType 0x0301 Speaker
bAssocTerminal 0
bSourceID 9END UPDATE
Any pointers?
Thank you
Danny
|
Figuring out USB devices
|
Well, I've got an answer to #2, found over at the Ubuntu stack exchange:
sudo sh -c "echo 0 > /sys/bus/usb/devices/<devId>/authorized"
sudo sh -c "echo 1 > /sys/bus/usb/devices/<devId>/authorized"where devId can be figured out (in my case, since I'll always know the exact expected product name) by inspecting /sys/bus/usb/devices/*/product
|
I have a USB microphone that works fine, up until I reboot my system. After that, it doesn't work at all until I unplug it and replug it. Based on my (limited) understanding of the components involved, I think that ALSA isn't detecting the mic on boot (possibly because the appropriate module hasn't been loaded during the USB scan at system boot). So, my question is,
How can I either,Configure ALSA to look for USB devices when it gets initialized,
Manually trigger ALSA to check for USB devices in a script I can
run at boot, or
Make sure snd-usb-audio is loaded before the
initial scan for devices?I'm running a modified RHEL4 distribution, if that matters. If there's more information you need, ask and I'll add it.
From looking at /var/log/messages, here's what I see at boot with the mic plugged in:
Mar 28 08:19:04 foobar kernel: usb 6-2: new full speed USB device using uhci_hcd and address 3
Mar 28 08:19:04 foobar kernel: usb 6-2: New USB device found, idVendor=08bb, idProduct=2912
Mar 28 08:19:04 foobar kernel: usb 6-2: New USB device strings: Mfr=1, Product=2, SerialNumber=0
Mar 28 08:19:04 foobar kernel: usb 6-2: Product: USB audio CODEC
Mar 28 08:19:04 foobar kernel: usb 6-2: Manufacturer: Burr-Brown from TI
Mar 28 08:19:04 foobar kernel: usb 6-2: configuration #1 chosen from 1 choiceIf I later unplug the mic, I get a single line in messages:
Mar 28 15:10:52 foobar kernel: usb 6-2: USB disconnect, address 3After boot, when I plug in the mic, I get the same output as above, but with one additional line:
Mar 28 15:11:12 foobar kernel: usb 6-2: new full speed USB device using uhci_hcd and address 4
Mar 28 15:11:12 foobar kernel: usb 6-2: New USB device found, idVendor=08bb, idProduct=2912
Mar 28 15:11:12 foobar kernel: usb 6-2: New USB device strings: Mfr=1, Product=2, SerialNumber=0
Mar 28 15:11:12 foobar kernel: usb 6-2: Product: USB audio CODEC
Mar 28 15:11:12 foobar kernel: usb 6-2: Manufacturer: Burr-Brown from TI
Mar 28 15:11:12 foobar kernel: usb 6-2: configuration #1 chosen from 1 choice
Mar 28 15:11:12 foobar kernel: usbcore: registered new interface driver snd-usb-audio
|
Alsa not detecting USB microphone on system boot
|
Fortunately it had nothing to do with the error about the GVC mixer, because I could not find any information on that problem except the source code itself. Eventually I stumbled upon this issue on GitHub that states the same problem. It had to do with Alsa having bad support for USB audio devices and PulseAudio not being enabled in my build of Firefox. Luckily in NixOS a pull request has been made to make it possible to enable this in Firefox, by enabling nixpkgs.config.pulseaudio.
|
After changing my desktop from Arch Linux to NixOS, playing HTML5 videos in Firefox has become buggy. They will fast forward when you play them, but only when using the USB audio adapter. Pulseaudio is used and ALSA is configured to use pulseaudio as well. A few solutions I found stated that I had to install pavucontrol and disable all other audio adapters and try to change the output from digital to analog, none of which made a difference. When I connect my speakers to the built-in adapter, the problem is resolved, the HTML5 videos in Firefox will play as they should. The only error message I got was that an assertion failed about it not being a GVC mixer. Which I could source back to the following code:
g_return_val_if_fail (GVC_IS_MIXER_CARD (card), 0);However I do not know whether this is the real cause, or how to resolve it, but since it worked fine on Arch Linux, it should be fixable.
|
USB audio adapter causes HTML5 videos in Firefox to fast forward
|
There is no suchlist of supported controlssince… whatever control element appropriately exposed by the device can be taken into account by amixer, v.g listed by the amixer scontrols command and accessible on the graphical interface via some button, slider or list according to its type (BOOLEAN, INTEGER or ENUM respectively) by calling alsalib's snd_ctl* functions.
These control elements can get different sort of properties (min/max values, step size, list of possible values)
From amixer's side, there is absolutely nothing specific to usb audio class 2 devices.
These control elements are defined by the driver in struct snd_ctl_elem_info objects of the like
static int snd_myctl_mono_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
{
uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
uinfo->count = 1;
uinfo->value.integer.min = 0;
uinfo->value.integer.max = 1;
return 0;
}for what would be a boolean control element.
Cf hereabove link for more details on control elements as well as the ALSA Kernel API Documentation for official documentation and detailed examples of sound drivers code.
Some alsa drivers can help by pre-defining (v.g. not restricting to some exhaustive list) some controls, for what concerns the usb_audio driver specifically :
enum {
USB_FEATURE_NONE = 0,
USB_FEATURE_MUTE = 1,
USB_FEATURE_VOLUME,
USB_FEATURE_BASS,
USB_FEATURE_MID,
USB_FEATURE_TREBLE,
USB_FEATURE_GEQ,
USB_FEATURE_AGC,
USB_FEATURE_DELAY,
USB_FEATURE_BASSBOOST,
USB_FEATURE_LOUDNESS
};
|
I am currently developing a usb soundcard that is usb audio class 2 compliant.
In my current setup I have audio and mute controls for several channels working in alsamixer.
The USB audio class 2 spec also supports a lot of other controls such as bass, mid, treble, equalizers, effects, etc. I have been trying to find a list of controls supported by alsamixer but the documentation does not mention any specifics on what kind of controls are supported.
If someone has a list with supported controls or an alternative command-line program that would be greatly appreciated.
|
alsamixer / amixer supported usb audio class 2 controls
|
After I blacklisted snd-hda-intel and rebooted everything worked perfectly out of the box.
|
So my onboard sound-card died and I bought a new small usb one.
With windows it works perfectly, but on my debian testing not so much.
It isn't detected by my audio system, and I cannot choose the device in the alsamixer application.
Which component of my system handles the soundcard-detection and where should I look for the answer?
$ [23:40:17] simon@tuna :~
> lspci -v | grep Audio
00:1b.0 Audio device: Intel Corporation 82801JI (ICH10 Family) HD Audio Controller
01:00.1 Audio device: Advanced Micro Devices, Inc. [AMD/ATI] RV770 HDMI Audio [Radeon HD 4850/4870]
$ [23:41:48] simon@tuna :~
> lsusb | grep Audio
Bus 003 Device 002: ID 0d8c:000c C-Media Electronics, Inc. Audio Adapter
$ [23:41:51] simon@tuna :~
> cat /proc/asound/cards
0 [HDMI ]: HDA-Intel - HDA ATI HDMI
HDA ATI HDMI at 0xfe8fc000 irq 46
2 [Intel ]: HDA-Intel - HDA Intel
HDA Intel at 0xfe7f8000 irq 45
$ [23:42:14] simon@tuna :~
> uname -r
3.16.0-4-amd64regards
edit:
$ [00:14:03] simon@tuna :~
> cat /proc/asound/modules
0 snd_hda_intel
2 snd_hda_intel
$ [00:22:33] simon@tuna :~
> lsmod | grep snd
snd_usb_audio 135354 0
snd_usbmidi_lib 23388 1 snd_usb_audio
snd_rawmidi 26806 1 snd_usbmidi_lib
snd_seq_device 13132 1 snd_rawmidi
snd_hda_codec_realtek 67127 1
snd_hda_codec_generic 63181 1 snd_hda_codec_realtek
snd_hda_codec_hdmi 45118 1
snd_hda_intel 26327 2
snd_hda_controller 26646 1 snd_hda_intel
snd_hda_codec 104463 5 snd_hda_codec_realtek,snd_hda_codec_hdmi,snd_hda_codec_generic,snd_hda_intel,snd_hda_controller
snd_hwdep 13148 2 snd_usb_audio,snd_hda_codec
snd_pcm 88662 5 snd_usb_audio,snd_hda_codec_hdmi,snd_hda_codec,snd_hda_intel,snd_hda_controller
snd_timer 26614 1 snd_pcm
snd 65244 16 snd_hda_codec_realtek,snd_usb_audio,snd_hwdep,snd_timer,snd_hda_codec_hdmi,snd_pcm,snd_rawmidi,snd_hda_codec_generic,snd_usbmidi_lib,snd_hda_codec,snd_hda_intel,snd_seq_device
soundcore 13026 2 snd,snd_hda_codec
usbcore 195340 6 uhci_hcd,snd_usb_audio,snd_usbmidi_lib,ehci_hcd,ehci_pci,usbhid
$ [00:24:34] simon@tuna :~
> cat /etc/modprobe.d/alsa-base.conf
options snd_hda_intel index=1
options snd_hda_intel index=2
options snd_usb_audio index=0edit2:
$ [22:18:13] simon@tuna :~
> lsusb
Bus 008 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 006 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 004 Device 003: ID 046d:c041 Logitech, Inc. G5 Laser Mouse
Bus 004 Device 002: ID 046a:0021 Cherry GmbH CyMotion Expert Combo
Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 007 Device 003: ID 18d1:4e22 Google Inc. Nexus S (debug)
Bus 007 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 003 Device 002: ID 0d8c:000c C-Media Electronics, Inc. Audio Adapter
Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 001 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hubEDIT solved:
After I blacklisted snd-hda-intel and rebooted everything worked perfectly out of the box...
|
Alsa not detecting my soundcard
|
This is possible with the ttable option of the route plugin, which is also integrated in the plug plugin:
pcm.MyLittleDevice {
type plug
slave {
pcm "hw:1"
channels 16
}
ttable [
[ 0 0 0 0 1 1 0 0 0 0 0 0 1 1 0 0 ]
[ 0 0 1 1 0 0 0 0 0 0 1 1 0 0 0 0 ]
]
}To reduce the volume, replace the 1s with smaller values.
|
The details of my setup are as follows:
Built-in Intel HD card (card0), to which all my existing applications use by default. Generally stereo output going out to the card from stereo files and streaming applications.
I've now added a USB sound card (card1: xCORE-200, from XMOS) and have a non-standard array of 8 outputs: 4 tweeters, 4 speakers. They are symmetrical, so that 2 tweeters/2 speakers on the Left side and 2 tweeters/2 speakers on the Right side. The channel array looks like this:
[0, 1, FrontRightTweeter, RearRightTweeter, LeftRearTweeter, LeftFrontTweeter, 6, 7, 8, 9, RightFrontSpeaker, RightRearSpeaker, LeftRearSpeaker, LeftFrontSpeaker, 14, 15]
The crossover is already handled, so I would like to simply remap all stereo sources so that the Left goes to the whole new Left side and the Right goes to the whole new Right side.
Also, from manual testing I've always had to significantly lower the volume (by ~90%) of the source to get a reasonable level out of my new speaker setup. So I need to be able to do this on the fly as well.
I've looked at several examples using ALSA via .asoundrc and PulseAudio modules, and I can't seem to connect all the pieces together successfully - especially going from fewer channel sources to more channels (it's usually the other way around). I'm looking for either an example .asoundrc or PulseAudio module config (whichever makes more sense) that can achieve the channel remapping and volume lowering that I'm shooting for. Thanks!
|
How do I use ALSA or PulseAudio to remap stereo source to an 8-channel PCM and lower the volume?
|
Option 1: Use madplay to play the mp3 instead (sudo apt-get install madplay)
In this case, it seems my USB Audio would only play audio at 48KHz, whereas the mp3s I was trying to play were actually at 44.1KHz
It seems that mpg321 would try to play the audio at 44.1KHz anyways even though my USB Audio didn't support it, so it ended up playing it about 10% too quickly, and consequently at a higher pitch.
madplay seems to handle this scenario appropriately, and plays the audio as you'd expect to hear it.
EDIT:
Option 2: @derobert also has a solution in a comment below for how to get mpg321 to work properly in this scenario:"You could also try using the plughw device instead of hw, e.g., mpg321 -o alsa -a plughw:0,0 …. That should get ALSA to insert a sample-rate converter."I still prefer Option 1 since it's simpler to write, but nice to know how to get mpg321 to work as well if you need it!
|
I'm trying to play an mp3 file on a Raspberry PI via USB Audio (iLuv Compact Speakers) and mpg321.
For some reason, it's playing the audio just a little bit too fast, and at a higher pitch than it should be.
If I play the audio through the headphone jack of the Raspberry PI instead, it plays the audio regularly.
How can I get it to play audio as it should sound through USB Audio?
|
mpg321 playing too fast, at high pitch, via USB Audio
|
I found this on Github, a set of pulseaudio profiles which might make it work.
However, whilst stereo output was relatively easy to achieve for me, the mic didn't work for me at first
(loopback with the nari hardware wheel works, muting via nari / audiomixer but audiolevels always stay at 0, mint [emailprotected], pulseaudio 11.1)
Turned out that somehow my other usb-soundcard interfered with it, detatching it before booting solved the problem but not during runtime. Weirdly, this seemed to also affect my VMware Setup (low level driver handover, Ubuntu20, pulseaudio 13.99 also not working- not Windows VM however)
further troubleshooting links:https://github.com/Sapd/HeadsetControl/blob/master/README.md
https://github.com/openrazer/openrazer/issues/724
https://wiki.archlinux.org/index.php/PulseAudio/Troubleshooting
https://wiki.parabola.nu/PulseAudio/Troubleshooting#PulseAudio_uses_wrong_microphone
|
The question itself may not be very explanatory. Let me try and clarify it a bit.
I'm running Pop!_OS 20.04 LTS on a PC. I'm also using a pair of Wireless USB headphones (Razer Nari) with two outputs.
What I am trying to achieve is to have STEREO output for my headphones. There are 2 outputs (one for 'gaming' and one for 'chat'. The 'gaming' one is stereo (at least on Windows) and the 'chat' one is mono (again, at least on Windows).
My issue is that I can't set pulseaudio to use stereo for my headphones' analog output (the gaming one).
In Sound Settings, I have "Analog Output - Razer Nari" and "Multichannel Output - Razer Nari". Each of them is tied to a mode on my headphones (note the game and chat icons in this photo). They both work when I switch to them from Sound settings but they are both MONO.When switching to Analog Output, I see in pavucontrol that for Razer Nari, the Profile changes to Mono Output + Mono Input. (photo here)
When switching to Multichannel Output, I see in pavucontrol that for Razer Nari, the Profile changes to Multichannel Output + Mono Input. (photo here)Either way, the sound coming out is mono, as well as it's confirmed when pressing the test button in Sound Settings (screenshot for multichannel / screenshot for analog output).
What I've tried so far:switching USB ports;
resettings pulse settings with sudo dpkg-reconfigure pulse;
uninstalling pulseEffects;
resetting pulseEffects with sudo dpkg-reconfigure pulseeffects;
removing all user configurations of pulse and pulseeffects from ~/.config/pulse and ~/.config/pulseeffectsHow can I force PulseEffects to use what I want or manually set my headphones to what channel(s) I want?
|
How to make pulseaudio recognize my usb headphones as stereo instead of mono?
|
Have you tried changing the sample rate of the file you're playing?
|
I'm on a system with Linux Kernel v5.10.4, and facing an issue where during audio playback through ALSA (aplay). The kernel spams the following log for the duration of the playback and no audio is heard:
xhci-hcd f2500000.usb3: WARN Event TRB for slot 3 ep 1 with no TDs queued?
xhci-hcd f2500000.usb3: WARN Event TRB for slot 3 ep 1 with no TDs queued?
xhci-hcd f2500000.usb3: WARN Event TRB for slot 3 ep 1 with no TDs queued?
...I've tried resetting (power off/on) the USB audio card, but the xhci-hcd is in the same error state.
The issue resolves if I reset the USB hub.
The issue resolves if I reboot the system.
I'm able to reproduce the issue by doing speaker-test for more than 4 periods. The issue doesn't occur with shorter periods.I do not know how to troubleshoot whether this is a driver issue or a hardware issue.Do I need a xhci driver update to fix the issue?
Any mitigation to restart / recover the driver (without rebooting or resetting the entire USB hub)?Warn log in source driver v5.10.4
snd-usb-audio is present in the kernel.
Found a related post but the mentioned fix was done in kernel v4.15
|
USB Host controller: xhci-hcd Event TRB with no TDs queued spam during audio playback
|
I could not find a way to make that device appear. But there is a fallback solution: Sending PA through Jack:
pactl load-module module-jack-sink channels=2
pactl load-module module-jack-source channels=2Then run Jack, e.g. QJackCtl, and you then set, for example in VLC, the pulse audio output device to 'Jack sink'.
|
So following some suggestions, I tried:
$ aplay -l | grep card
card 0: PCH [HDA Intel PCH], device 0: CX20724 Analog [CX20724 Analog]
card 0: PCH [HDA Intel PCH], device 3: HDMI 0 [HDMI 0]
card 0: PCH [HDA Intel PCH], device 7: HDMI 1 [HDMI 1]
card 1: ml1 [sonible ml:1], device 0: USB Audio [USB Audio]The last device is the one I want. I doesn't show up in Pulse Audio:I randomly try names:
$ pactl load-module module-alsa-sink device=ml:1
Failure: Module initialization failed$ pactl load-module module-alsa-sink device=ml1
Failure: Module initialization failed$ pactl load-module module-alsa-sink device=hw:1
Failure: Module initialization failedNone of this works. This is a class-compliant stereo USB sound cards, works fine in Jack.I'm trying again with PA info:
$ pactl info
Server String: /run/user/1000/pulse/native
Library Protocol Version: 32
Server Protocol Version: 32
Is Local: yes
Client Index: 12
Tile Size: 65472
User Name: me
Host Name: debian
Server Name: pulseaudio
Server Version: 10.0
Default Sample Specification: s16le 2ch 44100Hz
Default Channel Map: front-left,front-right
Default Sink: alsa_output.pci-0000_00_1f.3.analog-stereo
Default Source: alsa_input.pci-0000_00_1f.3.analog-stereo
Cookie: 0ea3:acfe$ pactl list short sources
0 alsa_output.usb-sonible_ml_1_V000014_sonible_ml_1-00.analog-stereo.monitor module-alsa-card.c s16le 2ch 44100Hz SUSPENDED
1 alsa_output.pci-0000_00_1f.3.analog-stereo.monitor module-alsa-card.c s16le 2ch 48000Hz IDLE
2 alsa_input.pci-0000_00_1f.3.analog-stereo module-alsa-card.c s16le 2ch 48000Hz SUSPENDED$ pactl load-module module-alsa-sink device=alsa_output.usb-sonible_ml_1_V000014_sonible_ml_1-00.analog-stereo.monitor
Failure: Module initialization failed$ sudo pactl load-module module-alsa-sink device=alsa_output.usb-sonible_ml_1_V000014_sonible_ml_1-00.analog-stereo.monitor
Connection failure: Connection refused
pa_context_connect() failed: Connection refused
|
Debian/Gnome: Cannot use USB audio device in Pulse Audio
|
Are you aware of the standalone "lame", which you can choose version to download:
https://sourceforge.net/projects/lame/files/lame/3.95/
... but then you need to compile it ;-p
$ uname -a
... 20.04.1-Ubuntu ... x86_64 GNU/Linux
$ tar -xvf lame-3.95.tar.gz
$ cd lame-3.95/
$ ./configure 2>&1 > log.txt
$ make all 2>&1 >> log.txt
$ grep -E 'fail|erro' log.txt | wc -l
1
$ grep -E 'fail|erro' log.txt
checking for library containing strerror... none required
$ ./frontend/lame --help
LAME version 3.95 (http://www.mp3dev.org/)usage: ./frontend/lame [options] <infile> [outfile] <infile> and/or <outfile> can be "-", which means stdin/stdout.RECOMMENDED:
lame -h input.wav output.mp3OPTIONS:
-b bitrate set the bitrate, default 128 kbps
-f fast mode (lower quality)
-h higher quality, but a little slower. Recommended.
-m mode (s)tereo, (j)oint, (m)ono
default is (j) or (s) depending on bitrate
-V n quality setting for VBR. default n=4 --preset type type must be "medium", "standard", "extreme", "insane",
or a value for an average desired bitrate and depending
on the value specified, appropriate quality settings will
be used.
"--preset help" gives more info on these --longhelp full list of options... now you need to have your "mp3"-file as WAV as you're about to run this; I'd guess sox or ffmpeg can create that, one file at a time...I would like to make it scriptable to encode a lot of files recursively.Now, go to www.tldp.org and read the Bash guides, there is one for beginners, then another one named "Advanced".
|
I wish to convert the encoder of some audio files. The problem is that my car can't reproduce audio files encoded with LAME3.99.5; it's an issue with some Volvo cars. The problem is with USB and CD.
The encoder needs to be LAME3.95 or less, or another encoder. What command should I use to achieve this? I would like to make it scriptable to encode a lot of files recursively.
I'm trying SoX and ffmpeg with no luck.
|
Convert encode of audio files
|
I don't see anything obvious, but two ideas:The USB device has two configurations, though from the information displayed about them, they seem to be identical. So I do not know what they are for. You could try to switch to the other one (with usb_modeswitch, unload kernel modules first) and see if that changes anythingYou are streaming 24 bits in 4 bytes, if I read the descriptors correctly. If the generic USB Audio driver picks out the wrong 3 bytes, you could end up with a most significant byte of zero, which would restrict the level to 12.5% (matching your observed 15%).
You can verify this by recording (e.g. parecord) to some file (WAV or raw) in 24-bit format, and examining it with a hex editor. If the MSB of all samples is zero, even when you produce a volume that clips on Mac or Windows, that would make this very likely.
In addition, you can use wireshark to capture the USB packets, so you can compare if they do have an additional third byte in the samples that doesn't make it into the recorded data.In that case, it's a bug in the driver, so please file a bug report on the ALSA kernel list.Quick excurse on use cases: Normally people buy something like the M-track 8 to record with multiple mics, e.g. a band where ever member has one or two mics (vocals + instrument). In that case, you'd just get all 8 channels from Pulseaudio (disabling downmixing), and your DAW would select which channels you'd actually record.
Often you'd even completely disable Pulseaudio for that, as it only adds latency, and go directly to ALSA, or use Jack instead of Pulseaudio."I want my laptop to play into my 7.1 surround speakers or my stereo headphone. Then if I make a conference call, I just want people to hear me.Ok, so you have a single mic, and that's all you have in the use case. You also want to keep Pulseaudio, as you don't have latency issues, and you are using the 8 channels mainly for output.
So have a look at the module-remap-source and do something like
load-module module-remap-source master=alsa_input.usb-MTRACK.analog-stereo channels=1 master_channel_map=front-left channel_map=monowhere front-left is the channel you have your mic on, and MTRACK is replaced with the actual name of your M-Track source (use e.g. pactl list short). Then record from the new source.
If the only actual problem was that Pulseaudio was downmixing all 8 channels to stereo and reducing the level with that, the you should be good now.
If there's still another problem, please test recording all 8 channels without Pulseaudio and only with ALSA as described in the comments, so we can rule out Pulseaudio and see if the problem is in the ALSA drivers.
|
I got an M-track 8 audio device (8 I/Os). It works fine for playback. However, the microphone (48 volt XLR mics) barely make any sound. When recording, they cap out at 15% volume in any application.According to the mixer spectrum analyser, they are working totally fine.
If I redirect the m-track input to the analog output and record it using the built-in mic, then it works correctly
If I record in macOS or Windows, it works correctly.So the problem is somewhere in ALSA or the driver. This is a normal USB audio class device, so the driver is very unlikely to be the problem (reproduced in Gentoo, Ubuntu 20.04 and Ubuntu 18.04 live-usb).alsamixer show all inputs are at 100%
pavucontrol shows all inputs at 100%
I tried adding some .asoundrc configs to force 96kHz and it did nothing
The problem has nothing to do with mic boost. The signal is ultra weakamixer -c2:
Simple mixer control 'Mic',0
Capabilities: cvolume cswitch
Capture channels: Front Left - Front Right - Rear Left - Rear Right - Front Center - Woofer - Side Left - Side Right
Limits: Capture 0 - 127
Front Left: Capture 127 [100%] [0.00dB] [on]
Front Right: Capture 127 [100%] [0.00dB] [on]
Rear Left: Capture 127 [100%] [0.00dB] [on]
Rear Right: Capture 127 [100%] [0.00dB] [on]
Front Center: Capture 127 [100%] [0.00dB] [on]
Woofer: Capture 127 [100%] [0.00dB] [on]
Side Left: Capture 127 [100%] [0.00dB] [on]
Side Right: Capture 127 [100%] [0.00dB] [on]
Simple mixer control 'Mic',1
Capabilities: cvolume cvolume-joined cswitch cswitch-joined
Capture channels: Mono
Limits: Capture 0 - 127
Mono: Capture 127 [100%] [0.00dB] [on]
Simple mixer control 'M-Audio M-Track Eight',0
Capabilities: pvolume pswitch
Playback channels: Front Left - Front Right - Rear Left - Rear Right - Front Center - Woofer - Side Left - Side Right
Limits: Playback 0 - 127
Mono:
Front Left: Playback 121 [95%] [-6.00dB] [on]
Front Right: Playback 121 [95%] [-6.00dB] [on]
Rear Left: Playback 127 [100%] [0.00dB] [on]
Rear Right: Playback 127 [100%] [0.00dB] [on]
Front Center: Playback 127 [100%] [0.00dB] [on]
Woofer: Playback 127 [100%] [0.00dB] [on]
Side Left: Playback 127 [100%] [0.00dB] [on]
Side Right: Playback 127 [100%] [0.00dB] [on]
Simple mixer control 'M-Audio M-Track Eight',1
Capabilities: pvolume pvolume-joined pswitch pswitch-joined
Playback channels: Mono
Limits: Playback 0 - 127
Mono: Playback 127 [100%] [0.00dB] [on]lsusb -vv -d 0763:4003
Bus 001 Device 049: ID 0763:4003 M-Audio
Couldn't open device, some information will be missing
Device Descriptor:
bLength 18
bDescriptorType 1
bcdUSB 2.00
bDeviceClass 239 Miscellaneous Device
bDeviceSubClass 2
bDeviceProtocol 1 Interface Association
bMaxPacketSize0 64
idVendor 0x0763 M-Audio
idProduct 0x4003
bcdDevice 1.05
iManufacturer 1
iProduct 3
iSerial 0
bNumConfigurations 2
Configuration Descriptor:
bLength 9
bDescriptorType 2
wTotalLength 0x0148
bNumInterfaces 4
bConfigurationValue 1
iConfiguration 0
bmAttributes 0x80
(Bus Powered)
MaxPower 500mA
Interface Association:
bLength 8
bDescriptorType 11
bFirstInterface 0
bInterfaceCount 3
bFunctionClass 1 Audio
bFunctionSubClass 0
bFunctionProtocol 32
iFunction 0
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 0
bAlternateSetting 0
bNumEndpoints 0
bInterfaceClass 1 Audio
bInterfaceSubClass 1 Control Device
bInterfaceProtocol 32
iInterface 3
AudioControl Interface Descriptor:
bLength 9
bDescriptorType 36
bDescriptorSubtype 1 (HEADER)
bcdADC 2.00
bCategory 8
wTotalLength 0x00a7
bmControls 0x00
AudioControl Interface Descriptor:
bLength 8
bDescriptorType 36
bDescriptorSubtype 10 (CLOCK_SOURCE)
bClockID 41
bmAttributes 3 Internal programmable clock
bmControls 0x07
Clock Frequency Control (read/write)
Clock Validity Control (read-only)
bAssocTerminal 0
iClockSource 9
AudioControl Interface Descriptor:
bLength 8
bDescriptorType 36
bDescriptorSubtype 11 (CLOCK_SELECTOR)
bClockID 40
bNrInPins 1
baCSourceID(0) 41
bmControls 0x03
Clock Selector Control (read/write)
iClockSelector 8
AudioControl Interface Descriptor:
bLength 17
bDescriptorType 36
bDescriptorSubtype 2 (INPUT_TERMINAL)
bTerminalID 2
wTerminalType 0x0101 USB Streaming
bAssocTerminal 0
bCSourceID 40
bNrChannels 8
bmChannelConfig 0x00000000
iChannelNames 19
bmControls 0x0000
iTerminal 6
AudioControl Interface Descriptor:
bLength 42
bDescriptorType 36
bDescriptorSubtype 6 (FEATURE_UNIT)
bUnitID 10
bSourceID 2
bmaControls(0) 0x0000000f
Mute Control (read/write)
Volume Control (read/write)
bmaControls(1) 0x0000000f
Mute Control (read/write)
Volume Control (read/write)
bmaControls(2) 0x0000000f
Mute Control (read/write)
Volume Control (read/write)
bmaControls(3) 0x0000000f
Mute Control (read/write)
Volume Control (read/write)
bmaControls(4) 0x0000000f
Mute Control (read/write)
Volume Control (read/write)
bmaControls(5) 0x0000000f
Mute Control (read/write)
Volume Control (read/write)
bmaControls(6) 0x0000000f
Mute Control (read/write)
Volume Control (read/write)
bmaControls(7) 0x0000000f
Mute Control (read/write)
Volume Control (read/write)
bmaControls(8) 0x0000000f
Mute Control (read/write)
Volume Control (read/write)
iFeature 0
AudioControl Interface Descriptor:
bLength 12
bDescriptorType 36
bDescriptorSubtype 3 (OUTPUT_TERMINAL)
bTerminalID 20
wTerminalType 0x0301 Speaker
bAssocTerminal 0
bSourceID 10
bCSourceID 40
bmControls 0x0000
iTerminal 0
AudioControl Interface Descriptor:
bLength 17
bDescriptorType 36
bDescriptorSubtype 2 (INPUT_TERMINAL)
bTerminalID 1
wTerminalType 0x0201 Microphone
bAssocTerminal 0
bCSourceID 40
bNrChannels 8
bmChannelConfig 0x00000000
iChannelNames 19
bmControls 0x0000
iTerminal 0
AudioControl Interface Descriptor:
bLength 42
bDescriptorType 36
bDescriptorSubtype 6 (FEATURE_UNIT)
bUnitID 11
bSourceID 1
bmaControls(0) 0x0000000f
Mute Control (read/write)
Volume Control (read/write)
bmaControls(1) 0x0000000f
Mute Control (read/write)
Volume Control (read/write)
bmaControls(2) 0x0000000f
Mute Control (read/write)
Volume Control (read/write)
bmaControls(3) 0x0000000f
Mute Control (read/write)
Volume Control (read/write)
bmaControls(4) 0x0000000f
Mute Control (read/write)
Volume Control (read/write)
bmaControls(5) 0x0000000f
Mute Control (read/write)
Volume Control (read/write)
bmaControls(6) 0x0000000f
Mute Control (read/write)
Volume Control (read/write)
bmaControls(7) 0x0000000f
Mute Control (read/write)
Volume Control (read/write)
bmaControls(8) 0x0000000f
Mute Control (read/write)
Volume Control (read/write)
iFeature 0
AudioControl Interface Descriptor:
bLength 12
bDescriptorType 36
bDescriptorSubtype 3 (OUTPUT_TERMINAL)
bTerminalID 22
wTerminalType 0x0101 USB Streaming
bAssocTerminal 0
bSourceID 11
bCSourceID 40
bmControls 0x0000
iTerminal 7
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 1
bAlternateSetting 0
bNumEndpoints 0
bInterfaceClass 1 Audio
bInterfaceSubClass 2 Streaming
bInterfaceProtocol 32
iInterface 4
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 1
bAlternateSetting 1
bNumEndpoints 2
bInterfaceClass 1 Audio
bInterfaceSubClass 2 Streaming
bInterfaceProtocol 32
iInterface 4
AudioStreaming Interface Descriptor:
bLength 16
bDescriptorType 36
bDescriptorSubtype 1 (AS_GENERAL)
bTerminalLink 2
bmControls 0x00
bFormatType 1
bmFormats 0x00000001
PCM
bNrChannels 8
bmChannelConfig 0x00000000
iChannelNames 11
AudioStreaming Interface Descriptor:
bLength 6
bDescriptorType 36
bDescriptorSubtype 2 (FORMAT_TYPE)
bFormatType 1 (FORMAT_TYPE_I)
bSubslotSize 4
bBitResolution 24
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x01 EP 1 OUT
bmAttributes 5
Transfer Type Isochronous
Synch Type Asynchronous
Usage Type Data
wMaxPacketSize 0x0400 1x 1024 bytes
bInterval 1
AudioStreaming Endpoint Descriptor:
bLength 8
bDescriptorType 37
bDescriptorSubtype 1 (EP_GENERAL)
bmAttributes 0x00
bmControls 0x00
bLockDelayUnits 2 Decoded PCM samples
wLockDelay 0x0008
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x81 EP 1 IN
bmAttributes 17
Transfer Type Isochronous
Synch Type None
Usage Type Feedback
wMaxPacketSize 0x0004 1x 4 bytes
bInterval 4
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 2
bAlternateSetting 0
bNumEndpoints 0
bInterfaceClass 1 Audio
bInterfaceSubClass 2 Streaming
bInterfaceProtocol 32
iInterface 5
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 2
bAlternateSetting 1
bNumEndpoints 1
bInterfaceClass 1 Audio
bInterfaceSubClass 2 Streaming
bInterfaceProtocol 32
iInterface 5
AudioStreaming Interface Descriptor:
bLength 16
bDescriptorType 36
bDescriptorSubtype 1 (AS_GENERAL)
bTerminalLink 22
bmControls 0x00
bFormatType 1
bmFormats 0x00000001
PCM
bNrChannels 8
bmChannelConfig 0x00000000
iChannelNames 19
AudioStreaming Interface Descriptor:
bLength 6
bDescriptorType 36
bDescriptorSubtype 2 (FORMAT_TYPE)
bFormatType 1 (FORMAT_TYPE_I)
bSubslotSize 4
bBitResolution 24
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x82 EP 2 IN
bmAttributes 5
Transfer Type Isochronous
Synch Type Asynchronous
Usage Type Data
wMaxPacketSize 0x0400 1x 1024 bytes
bInterval 1
AudioStreaming Endpoint Descriptor:
bLength 8
bDescriptorType 37
bDescriptorSubtype 1 (EP_GENERAL)
bmAttributes 0x00
bmControls 0x00
bLockDelayUnits 2 Decoded PCM samples
wLockDelay 0x0008
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 3
bAlternateSetting 0
bNumEndpoints 0
bInterfaceClass 254 Application Specific Interface
bInterfaceSubClass 1 Device Firmware Update
bInterfaceProtocol 1
iInterface 10
Device Firmware Upgrade Interface Descriptor:
bLength 9
bDescriptorType 33
bmAttributes 7
Will Not Detach
Manifestation Tolerant
Upload Supported
Download Supported
wDetachTimeout 250 milliseconds
wTransferSize 64 bytes
bcdDFUVersion 1.10
Configuration Descriptor:
bLength 9
bDescriptorType 2
wTotalLength 0x0148
bNumInterfaces 4
bConfigurationValue 1
iConfiguration 0
bmAttributes 0x80
(Bus Powered)
MaxPower 500mA
Interface Association:
bLength 8
bDescriptorType 11
bFirstInterface 0
bInterfaceCount 3
bFunctionClass 1 Audio
bFunctionSubClass 0
bFunctionProtocol 32
iFunction 0
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 0
bAlternateSetting 0
bNumEndpoints 0
bInterfaceClass 1 Audio
bInterfaceSubClass 1 Control Device
bInterfaceProtocol 32
iInterface 3
AudioControl Interface Descriptor:
bLength 9
bDescriptorType 36
bDescriptorSubtype 1 (HEADER)
bcdADC 2.00
bCategory 8
wTotalLength 0x00a7
bmControls 0x00
AudioControl Interface Descriptor:
bLength 8
bDescriptorType 36
bDescriptorSubtype 10 (CLOCK_SOURCE)
bClockID 41
bmAttributes 3 Internal programmable clock
bmControls 0x07
Clock Frequency Control (read/write)
Clock Validity Control (read-only)
bAssocTerminal 0
iClockSource 9
AudioControl Interface Descriptor:
bLength 8
bDescriptorType 36
bDescriptorSubtype 11 (CLOCK_SELECTOR)
bClockID 40
bNrInPins 1
baCSourceID(0) 41
bmControls 0x03
Clock Selector Control (read/write)
iClockSelector 8
AudioControl Interface Descriptor:
bLength 17
bDescriptorType 36
bDescriptorSubtype 2 (INPUT_TERMINAL)
bTerminalID 2
wTerminalType 0x0101 USB Streaming
bAssocTerminal 0
bCSourceID 40
bNrChannels 8
bmChannelConfig 0x00000000
iChannelNames 19
bmControls 0x0000
iTerminal 6
AudioControl Interface Descriptor:
bLength 42
bDescriptorType 36
bDescriptorSubtype 6 (FEATURE_UNIT)
bUnitID 10
bSourceID 2
bmaControls(0) 0x0000000f
Mute Control (read/write)
Volume Control (read/write)
bmaControls(1) 0x0000000f
Mute Control (read/write)
Volume Control (read/write)
bmaControls(2) 0x0000000f
Mute Control (read/write)
Volume Control (read/write)
bmaControls(3) 0x0000000f
Mute Control (read/write)
Volume Control (read/write)
bmaControls(4) 0x0000000f
Mute Control (read/write)
Volume Control (read/write)
bmaControls(5) 0x0000000f
Mute Control (read/write)
Volume Control (read/write)
bmaControls(6) 0x0000000f
Mute Control (read/write)
Volume Control (read/write)
bmaControls(7) 0x0000000f
Mute Control (read/write)
Volume Control (read/write)
bmaControls(8) 0x0000000f
Mute Control (read/write)
Volume Control (read/write)
iFeature 0
AudioControl Interface Descriptor:
bLength 12
bDescriptorType 36
bDescriptorSubtype 3 (OUTPUT_TERMINAL)
bTerminalID 20
wTerminalType 0x0301 Speaker
bAssocTerminal 0
bSourceID 10
bCSourceID 40
bmControls 0x0000
iTerminal 0
AudioControl Interface Descriptor:
bLength 17
bDescriptorType 36
bDescriptorSubtype 2 (INPUT_TERMINAL)
bTerminalID 1
wTerminalType 0x0201 Microphone
bAssocTerminal 0
bCSourceID 40
bNrChannels 8
bmChannelConfig 0x00000000
iChannelNames 19
bmControls 0x0000
iTerminal 0
AudioControl Interface Descriptor:
bLength 42
bDescriptorType 36
bDescriptorSubtype 6 (FEATURE_UNIT)
bUnitID 11
bSourceID 1
bmaControls(0) 0x0000000f
Mute Control (read/write)
Volume Control (read/write)
bmaControls(1) 0x0000000f
Mute Control (read/write)
Volume Control (read/write)
bmaControls(2) 0x0000000f
Mute Control (read/write)
Volume Control (read/write)
bmaControls(3) 0x0000000f
Mute Control (read/write)
Volume Control (read/write)
bmaControls(4) 0x0000000f
Mute Control (read/write)
Volume Control (read/write)
bmaControls(5) 0x0000000f
Mute Control (read/write)
Volume Control (read/write)
bmaControls(6) 0x0000000f
Mute Control (read/write)
Volume Control (read/write)
bmaControls(7) 0x0000000f
Mute Control (read/write)
Volume Control (read/write)
bmaControls(8) 0x0000000f
Mute Control (read/write)
Volume Control (read/write)
iFeature 0
AudioControl Interface Descriptor:
bLength 12
bDescriptorType 36
bDescriptorSubtype 3 (OUTPUT_TERMINAL)
bTerminalID 22
wTerminalType 0x0101 USB Streaming
bAssocTerminal 0
bSourceID 11
bCSourceID 40
bmControls 0x0000
iTerminal 7
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 1
bAlternateSetting 0
bNumEndpoints 0
bInterfaceClass 1 Audio
bInterfaceSubClass 2 Streaming
bInterfaceProtocol 32
iInterface 4
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 1
bAlternateSetting 1
bNumEndpoints 2
bInterfaceClass 1 Audio
bInterfaceSubClass 2 Streaming
bInterfaceProtocol 32
iInterface 4
AudioStreaming Interface Descriptor:
bLength 16
bDescriptorType 36
bDescriptorSubtype 1 (AS_GENERAL)
bTerminalLink 2
bmControls 0x00
bFormatType 1
bmFormats 0x00000001
PCM
bNrChannels 8
bmChannelConfig 0x00000000
iChannelNames 11
AudioStreaming Interface Descriptor:
bLength 6
bDescriptorType 36
bDescriptorSubtype 2 (FORMAT_TYPE)
bFormatType 1 (FORMAT_TYPE_I)
bSubslotSize 4
bBitResolution 24
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x01 EP 1 OUT
bmAttributes 5
Transfer Type Isochronous
Synch Type Asynchronous
Usage Type Data
wMaxPacketSize 0x0400 1x 1024 bytes
bInterval 1
AudioStreaming Endpoint Descriptor:
bLength 8
bDescriptorType 37
bDescriptorSubtype 1 (EP_GENERAL)
bmAttributes 0x00
bmControls 0x00
bLockDelayUnits 2 Decoded PCM samples
wLockDelay 0x0008
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x81 EP 1 IN
bmAttributes 17
Transfer Type Isochronous
Synch Type None
Usage Type Feedback
wMaxPacketSize 0x0004 1x 4 bytes
bInterval 4
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 2
bAlternateSetting 0
bNumEndpoints 0
bInterfaceClass 1 Audio
bInterfaceSubClass 2 Streaming
bInterfaceProtocol 32
iInterface 5
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 2
bAlternateSetting 1
bNumEndpoints 1
bInterfaceClass 1 Audio
bInterfaceSubClass 2 Streaming
bInterfaceProtocol 32
iInterface 5
AudioStreaming Interface Descriptor:
bLength 16
bDescriptorType 36
bDescriptorSubtype 1 (AS_GENERAL)
bTerminalLink 22
bmControls 0x00
bFormatType 1
bmFormats 0x00000001
PCM
bNrChannels 8
bmChannelConfig 0x00000000
iChannelNames 19
AudioStreaming Interface Descriptor:
bLength 6
bDescriptorType 36
bDescriptorSubtype 2 (FORMAT_TYPE)
bFormatType 1 (FORMAT_TYPE_I)
bSubslotSize 4
bBitResolution 24
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x82 EP 2 IN
bmAttributes 5
Transfer Type Isochronous
Synch Type Asynchronous
Usage Type Data
wMaxPacketSize 0x0400 1x 1024 bytes
bInterval 1
AudioStreaming Endpoint Descriptor:
bLength 8
bDescriptorType 37
bDescriptorSubtype 1 (EP_GENERAL)
bmAttributes 0x00
bmControls 0x00
bLockDelayUnits 2 Decoded PCM samples
wLockDelay 0x0008
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 3
bAlternateSetting 0
bNumEndpoints 0
bInterfaceClass 254 Application Specific Interface
bInterfaceSubClass 1 Device Firmware Update
bInterfaceProtocol 1
iInterface 10
Device Firmware Upgrade Interface Descriptor:
bLength 9
bDescriptorType 33
bmAttributes 7
Will Not Detach
Manifestation Tolerant
Upload Supported
Download Supported
wDetachTimeout 250 milliseconds
wTransferSize 64 bytes
bcdDFUVersion 1.10pacmd list-sources inputs:
index: 16
name: <alsa_output.usb-M-Audio_M-Track_Eight-00.analog-surround-71.monitor>
driver: <module-alsa-card.c>
flags: DECIBEL_VOLUME LATENCY DYNAMIC_LATENCY
state: RUNNING
suspend cause: (none)
priority: 1040
volume: front-left: 65536 / 100% / 0.00 dB, front-right: 65536 / 100% / 0.00 dB, rear-left: 65536 / 100% / 0.00 dB, rear-right: 65536 / 100% / 0.00 dB, front-center: 65536 / 100% / 0.00 dB, lfe: 65536 / 100% / 0.00 dB, side-left: 65536 / 100% / 0.00 dB, side-right: 65536 / 100% / 0.00 dB
balance 0.00
base volume: 65536 / 100% / 0.00 dB
volume steps: 65537
muted: no
current latency: 0.00 ms
max rewind: 11 KiB
sample spec: s32le 8ch 44100Hz
channel map: front-left,front-right,rear-left,rear-right,front-center,lfe,side-left,side-right
Surround 7.1
used by: 5
linked by: 5
configured latency: 40.00 ms; range is 8.00 .. 743.04 ms
monitor_of: 7
card: 5 <alsa_card.usb-M-Audio_M-Track_Eight-00>
module: 27
properties:
device.description = "Monitor of M-Track Eight Analog Surround 7.1"
device.class = "monitor"
alsa.card = "2"
alsa.card_name = "M-Track Eight"
alsa.long_card_name = "M-Audio M-Track Eight at usb-0000:00:14.0-5.4, high speed"
alsa.driver_name = "snd_usb_audio"
device.bus_path = "pci-0000:00:14.0-usb-0:5.4:1.0"
sysfs.path = "/devices/pci0000:00/0000:00:14.0/usb1/1-5/1-5.4/1-5.4:1.0/sound/card2"
udev.id = "usb-M-Audio_M-Track_Eight-00"
device.bus = "usb"
device.vendor.id = "0763"
device.vendor.name = "M-Audio"
device.product.id = "4003"
device.product.name = "M-Track Eight"
device.serial = "M-Audio_M-Track_Eight"
device.string = "2"
module-udev-detect.discovered = "1"
device.icon_name = "audio-card-usb"Here is a recording:
parecord -r --format=s24le --file-format=wav ./foo.wavfile ./foo.wav./foo.wav: RIFF (little-endian) data, WAVE audio, Microsoft PCM, 24 bit, stereo 44100 HzThe sound is from the mic and is clipped on the device (vu-meter red bar is shown).
|
My USB audio input channels max_out/clips at ~15%
|
The USB ports found on computer monitors are usually those of a
built-in USB hub: you would have to connect the monitor's hub to your
computer using a USB cable for it to work. Then any device, sound card
or anything else, should work as if it were connected directly to the
computer.
|
I have a monitor with 2 USB ports that I connect through HDMI to my laptop. How do I make a USB sound card work with those ports? My system is Ubuntu 14.04.
|
How to use usb ports on a monitor for sound [closed]
|
As others have said, this is because the stdin of sh has been redirected to read from the pipe, it is not connected to the terminal as it would normally be. One thing you can do to get around this is to use /dev/tty to force the script to read from the terminal. Eg:
#!/bin/shread -p "Are you sure [Y/n]?" line </dev/tty
case "$line" in
y|Y) echo "confirmed"
;;
*) echo "not confirmed"
;;
esacNormally you would only do this if you specifically want to prevent people from scripting the input, eg:
echo Y | sh confirmation.shThis would still read from the terminal even though the user might expect this to automatically input Y at the prompt. It is common for programs that expect a password to do this.
|
Let's assume I have a file named confirmation.sh with the following content:
#!/bin/bash
echo -n "Are you sure [Y/n]? "
read line
case "$line" in
n|N) echo "smth"
;;
y|Y) echo "smth"
;;
esacand I want to run this script in the following way:
cat confirmation.sh | shI see Are you sure [Y/n]? and the script is interrupted. What's the problem?
|
How to read user input from a pipe?
|
You can't do that in your while. You need to use another file descriptor
Try the following version :
#!/bin/bash
#Returns the misspelled words
#ispell -l < file#define vars
ISPELL_OUTPUT_FILE="output.tmp";
INPUT_FILE=$1ispell -l < $INPUT_FILE > $ISPELL_OUTPUT_FILE;#echo a new line for give space between command
#and the output generated
echo "";while read -r -u9 line;
do
echo "'$line' is misspelled. Press "Enter" to keep";
read -p "this spelling, or type a correction here: " USER_INPUT; if [ "$USER_INPUT" != "" ]
then
echo "INPUT: $USER_INPUT";
fi echo ""; #echo a new line
done 9< $ISPELL_OUTPUT_FILE;rm "$ISPELL_OUTPUT_FILE"See How to keep other commands from "eating" the input
NOTESUSE MORE QUOTES! They are vital. See http://mywiki.wooledge.org/Quotes and http://wiki.bash-hackers.org/syntax/words
bash is not C or Perl, no need to put ; on each end lines
|
For class I need to write a Bash script that will take the output from ispell and when I try and request user input inside the while loop it just saves the next line of the file as the user input.
How could I go about requesting user input in the while loop?
#!/bin/bash
#Returns the misspelled words
#ispell -l < file#define vars
ISPELL_OUTPUT_FILE="output.tmp";
INPUT_FILE=$1ispell -l < $INPUT_FILE > $ISPELL_OUTPUT_FILE;#echo a new line for give space between command
#and the output generated
echo "";while read line;
do
echo "'$line' is misspelled. Press "Enter" to keep";
read -p "this spelling, or type a correction here: " USER_INPUT; if [ $USER_INPUT != "" ]
then
echo "INPUT: $USER_INPUT";
fi echo ""; #echo a new line
done < $ISPELL_OUTPUT_FILE;rm $ISPELL_OUTPUT_FILE;
|
Requesting user input while reading file line by line
|
To do that, you'd have to read character by character, not line by line.
Why? The shell very likely uses the standard C library function read()
to read the data that the user is typing in, and that function returns
the number of bytes actually read. If it returns zero, that means it has
encountered EOF (see the read(2) manual; man 2 read). Note that EOF
isn't a character but a condition, i.e. the condition "there is nothing
more to be read", end-of-file.
Ctrl+D sends an end-of-transmission character
(EOT, ASCII character code 4, $'\04' in bash) to the terminal
driver. This has the effect of sending whatever there is to send to the
waiting read() call of the shell.
When you press Ctrl+D halfway through
entering the text on a line, whatever you have typed so far is
sent to the shell1. This means that if you enter
Ctrl+D twice after having typed something on
a line, the first one will send some data, and the second one will
send nothing, and the read() call will return zero and the shell
interpret that as EOF. Likewise, if you press Enter followed
by Ctrl+D, the shell gets EOF at once as there
wasn't any data to send.
So how to avoid having to type Ctrl+D twice?
As I said, read single characters. When you use the read shell
built-in command, it probably has an input buffer and asks read() to
read a maximum of that many characters from the input stream (maybe 16
kb or so). This means that the shell will get a bunch of 16 kb chunks
of input, followed by a chunk that may be less than 16 kb, followed by
zero bytes (EOF). Once encountering the end of input (or a newline, or a
specified delimiter), control is returned to the script.
If you use read -n 1 to read a single character, the shell will use
a buffer of a single byte in its call to read(), i.e. it will sit in
a tight loop reading character by character, returning control to the
shell script after each one.
The only issue with read -n is that it sets the terminal to "raw
mode", which means that characters are sent as they are without any
interpretation. For example, if you press Ctrl+D,
you'll get a literal EOT character in your string. So we have to check
for that. This also has the side-effect that the user will be unable to edit the line before submitting it to the script, for example by pressing Backspace, or by using Ctrl+W (to delete the previous word) or Ctrl+U (to delete to the beginning of the line).
To make a long story short: The following is the final loop that your
bash script needs to do to read a line of input, while at the same time
allowing the user to interrupt the input at any time by pressing
Ctrl+D:
while true; do
line='' while IFS= read -r -N 1 ch; do
case "$ch" in
$'\04') got_eot=1 ;&
$'\n') break ;;
*) line="$line$ch" ;;
esac
done printf 'line: "%s"\n' "$line" if (( got_eot )); then
break
fi
doneWithout going into too much detail about this:IFS= clears the IFS variable. Without this, we would not be able to read spaces. I use read -N instead of read -n, otherwise we wouldn't be able to detect newlines. The -r option to read enables us to read backslashes properly.
The case statement acts on each read character ($ch). If an EOT ($'\04') is detected, it sets got_eot to 1 and then falls through to the break statement which gets it out of the inner loop. If a newline ($'\n') is detected, it just breaks out of the inner loop. Otherwise it adds the character to the end of the line variable.
After the loop, the line is printed to standard output. This would be where you call your script or function that uses "$line". If we got here by detecting an EOT, we exit the outermost loop.1 You may test this by running cat >file in one terminal
and tail -f file in another, and then enter a partial line into the
cat and press Ctrl+D to see what happens in the
output of tail.For ksh93 users: The loop above will read a carriage return character rather than a newline character in ksh93, which means that the test for $'\n' will need to change to a test for $'\r'. The shell will also display these as ^M.
To work around this:stty_saved="$( stty -g )"
stty -echoctl# the loop goes here, with $'\n' replaced by $'\r'stty "$stty_saved"You might also want to output a newline explicitly just before the break to get exactly the same behaviour as in bash.
|
This script takes the user input line after line, and executes myfunction on every line
#!/bin/bash
SENTENCE=""while read word
do
myfunction $word"
done
echo $SENTENCETo stop the input, the user has to press [ENTER] and then Ctrl+D.
How can I rebuild my script to end only with Ctrl+D and process the line where Ctrl+D was pressed.
|
How to read the user input line by line until Ctrl+D and include the line where Ctrl+D was typed
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.