Lvm

使用邏輯卷,如何修改預設的 lvs 輸出?

  • December 3, 2020

隨著lvs我得到預設輸出:

~$ sudo lvs
 LV                     VG       Attr       LSize  Pool Origin  Data%  Meta%  Move Log Cpy%Sync Convert
 pre_upgrade_2020-10-31 rpi.vg06 swi-a-s---  2,19g      root.lv 64,37
 pre_upgrade_2020-12-02 rpi.vg06 swi-a-s--- <2,20g      root.lv 0,02
 root.lv                rpi.vg06 owi-aos---  3,00g

但這不是我最感興趣的。我想得到:

~$ sudo lvs -o lv_full_name,lv_attr,origin,lv_size,seg_size_pe,data_percent,lv_time -O lv_time
 LV                              Attr       Origin  LSize  SSize Data%  CTime
 rpi.vg06/root.lv                owi-aos---          3,00g   768        2020-04-05 22:34:46 +0200
 rpi.vg06/pre_upgrade_2020-10-31 swi-a-s--- root.lv  2,19g   561 64,37  2020-10-31 20:52:45 +0100
 rpi.vg06/pre_upgrade_2020-12-02 swi-a-s--- root.lv <2,20g   562 0,02   2020-12-02 23:15:47 +0100

命令有點長,不好記。我嘗試使用別名,但sudo不知道使用者別名。有沒有辦法將 lvs 配置為預設輸出sudo lvs?也許在一個*.conf*rc文件中?

預設lvs輸出可以更改/etc/lvm/lvm.conf。找到該report部分並將lvs_cols值更改為要在lvs輸出中看到的列。

# Configuration section report.
# LVM report command output formatting.
# This configuration section has an automatic default value.
report {
...
       # Configuration option report/lvs_cols.
       # List of columns to report for 'lvs' command.
       # See 'lvs -o help' for the list of possible fields.
       # This configuration option has an automatic default value.
       lvs_cols = lv_full_name,lv_attr,origin,lv_size,seg_size_pe,data_percent,lv_time
...
}
$ sudo lvs
 LV          Attr       Origin LSize   SSize  Data%  CTime                     
 fedora/home -wi-ao----        852,64g 218277        2019-06-07 14:08:45 +0200 
 fedora/root -wi-ao----         69,98g  17916        2019-06-07 14:08:48 +0200 
 fedora/swap -wi-ao----          7,86g   2013        2019-06-07 14:08:45 +0200

引用自:https://unix.stackexchange.com/questions/622642