Tag: linux

Create LABEL for filesystems in Linux

Create LABEL for filesystems in Linux

LABEL is used in /etc/fstab and system boot, such as cmdline.txt and grub, to allow the mounting identify the filesystem..

In order to allow system recognize the LABEL, blkid needs to show the filesystem has the LABEL.

Assign LABEL during filesystem creation

vfat

mkfs.vfat -n "label" /dev/XXX

ext4

mkfs.ext4 -L "label" /dev/XXX

btrfs

mkfs.btrfs -L "label" /dev/XXX

Change LABEL

LABEL can be changed after filesystem created.

swap

swaplabel -L "new label" /dev/XXX using util-linux

ext2/3/4

e2label /dev/XXX "new label" using e2fsprogs

btrfs

btrfs filesystem label /dev/XXX "new label" using btrfs-progs

reiserfs

reiserfstune -l "new label" /dev/XXX using reiserfsprogs

jfs

jfs_tune -L "new label" /dev/XXX using jfsutils

xfs

xfs_admin -L "new label" /dev/XXX using xfsprogs

fat/vfat

fatlabel /dev/XXX "new label" using dosfstools
mlabel -i /dev/XXX ::"new label" using mtools

exfat

tune.exfat -L "new label" /dev/XXX using exfatprogs
exfatlabel /dev/XXX "new label" using exfatprogs or exfat-utils

ntfs

ntfslabel /dev/XXX "new label" using ntfs-3g

udf

udflabel /dev/XXX "new label" using udftools

crypto_LUKS (LUKS2 only)

cryptsetup config --label="new label" /dev/XXX using cryptsetup

References

Persistent block device naming
How do I change the "label" reported by lsblk? [duplicate]

Overlay Filesystem Basic

Overlay Filesystem Basic

Overlay filesystem merges lower and upper directories into merged directory.

Mount writable

mount -t overlay overlay -o lowerdir=/lower1:/lower2:/lower3,upperdir=/upper,workdir=/work /merged

The above example will have the order:

/upper
/lower1
/lower2
/lower3

  • The lower directory can be read-only or could be an overlay itself.
  • The upper directory is normally writable.
  • The work directory is used to prepare files as they are switched between the layers, it needs to be an empty directory on the same filesystem mount as the upper directory.
  • All changes in the merged directory are still reflected in upper.
  • New files created in lower and upper will be shown in merged.
  • All files before opened directory, the content is still mapped according to layer.
  • All files after opened in merged directory, the content will not be reflected in merged directory.

Mount read-only

To mount as read only, no upper and work directory are required.

mount -t overlay overlay -o lowerdir=/lower1:/lower2 /merged

Whiteout files

Whiteout is to simulate a file removed from upper layer directory. It is created as a character device with 0/0 device number.

Opaque directories

Opaque is to simulate a directory removed from upper layer directory. It is made by setting the xattr “trusted.overlay.opaque” to “y”.

References

Overlay filesystem
Overlay Filesystem
Explaining OverlayFS – What it Does and How it Works

Hot swapable Keychron keyboard issues

Hot swapable Keychron keyboard issues

Just got Keychron keyboard, with hot swap, which can easily switch between two Mac machines easily. Some issues struggle me for a while.

No eject button

The major difference between normal Mac keyboard and Keychron keyboard is reject button, so need to use another combination of keys for sleep instead, which uses power button. But my old iMac power button has issue as well.

Then when I put iMac to sleep, then try to switch to Mac Mini, the keyboard wakes iMac up. To overcome this issue, I tried to use mouse, but I can not move the mouse as well, it also wakes iMac up.

After search internet, people give a solution, that is using mouse to sleep, then lift it up, after that make it upside down. Then I did the same thing, except switch it off, because my mouse got light.

Switch between MacOS and Windows or Linux

Because of the switching between MacOS and Windows or Linux via a physical button, it isn't that easy, and the manual mentions do not do it often, otherwise, can cause issue.

References

Shortcut key to make my macbook sleep?

Options restrict in one filesystem

Options restrict in one filesystem

There are quite number of tasks may want to be executed in one filesystem, this is important during troubleshooting, especially for root directory (/).

find

Restrict find command only looking entries within one filesystem, use option -xdev

find /usr -xdev ...

du

Restrict du command only calculate for one filesystem, use option -x

du -cshx /

tar

Restrict tar command only archive files in one filesystem, use option --one-file-system

tar --one-file-system -czvf /tmp/root.tgz /

Process Listening on a Particular Port in Linux

Process Listening on a Particular Port in Linux

These commands might not workable in some Unix like systems.

Using netstat

netstat -ltnp
netstat -peanut

lsof

lsof -i :80

fuser

fuser 80/tcp

ss


ss -nlp
``

## References

[3 Ways to Find Out Which Process Listening on a Particular Port](https://www.tecmint.com/find-out-which-process-listening-on-a-particular-port/)

Remove empty directories recursively

Remove empty directories recursively

Use find command

Use following command can remove empty directories which may have empty directories in them. The -depth will sort the output according to the depth of directories.

find . -type d -depth -exec rmdir {} \;

Note: Just ignore error due to directory not empty

Use rmdir command

First, need to know how deep of your directory, then can run following command

rmdir */*/*/*
rmdir */*/*
rmdir */*
rmdir *

Note: This can cause too many arguments error or command line too long error for large directory.