AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / unix / 问题

问题[portability](unix)

Martin Hope
Lingfeng Fu
Asked: 2022-06-07 01:23:15 +0800 CST

如何休眠 Linux To Go 到磁盘并在不同的设备上恢复它?

  • 0

我的 Linux 安装在便携式 SSD 上,因此我可以轻松切换设备(家里的笔记本电脑,办公室的台式机),而无需考虑任何同步问题。这称为 Linux To Go。

已经很不错了,但还能更好吗?

要在工作流程中切换设备,我必须(优雅地)退出所有应用程序,完全关闭操作系统,然后分离并连接 SSD,启动操作系统,等待其通电,最后重新打开所有需要恢复的应用程序我的工作。

现在我想找到一种方法来实现“暂停和恢复”,而不是这样的“停止和重新启动”。我希望操作系统内存能够在不同的设备上持续存在。

似乎休眠是一个潜在的解决方案。也许我可以通过休眠操作系统将内存保存在交换分区中,然后分离并连接 SSD,启动操作系统,很快,内存就会恢复,这样我就可以继续我的工作流程了。

但经过一番谷歌搜索后,我找不到任何关于跨多个设备休眠的教程/博客。

如何休眠 Linux To Go 到磁盘并在不同的设备上恢复它?或者,这根本不可能?

hibernate portability
  • 1 个回答
  • 37 Views
Martin Hope
Vlastimil Burián
Asked: 2022-02-13 04:09:16 +0800 CST

terminfo/termcap `tput bold`/`tput md`:粗体文本的可移植性

  • 0

假设我的一个便携式 shell 脚本中有以下颜色支持:

#!/bin/sh

set -o nounset

tput_init_linux () { set_fg_color='tput setaf'; reset_color=$(tput sgr0 2>/dev/null); }
tput_init_bsd   () { set_fg_color='tput AF';    reset_color=$(tput me 2>/dev/null);   }
tput_init_none  () { set_fg_color=':';          reset_color=;                         }

if tput setaf 1 >/dev/null 2>&1; then tput_init_linux || tput_init_none;
elif tput AF 1  >/dev/null 2>&1; then tput_init_bsd   || tput_init_none;
else tput_init_none; fi

no_color () { printf '%s' "$reset_color"; }

colorize ()
{
    #tput bold
    case "$1" in
        (red)     $set_fg_color 1 ;;
        (green)   $set_fg_color 2 ;;
        (yellow)  $set_fg_color 3 ;;
        (blue)    $set_fg_color 4 ;;
        (magenta) $set_fg_color 5 ;;
        (cyan)    $set_fg_color 6 ;;
        (white)   $set_fg_color 7 ;;
        (*) printf '%s\n' "[ERROR] This color ('$1') is not supported by the colorize() function. Quiting!" >&2; exit 1 ;;
    esac
}

print_ok     () { colorize green;  printf '%s' '[OK] ';        no_color; }
print_notice () { colorize cyan;   printf '%s' '[NOTICE] ';    no_color; }
print_debug  () { colorize yellow; printf '%s' '[DEBUG] ' >&2; no_color; }
print_error  () { colorize red;    printf '%s' '[ERROR] ' >&2; no_color; }

一个相当愚蠢的使用示例如下:

grub_config_file=/boot/grub/grub.cfg
readonly grub_config_file

if [ ! -f "$grub_config_file" ]; then
    print_error; printf '%s\n' "GRUB config file not found at $grub_config_file. Aborting!" >&2
    exit 1
else
    print_ok; printf '%s\n' "GRUB config file was found at $grub_config_file. Searching for Windows..."
fi

现在,我的问题是关于粗体文本。

具体来说,我不确定 terminfo/termcap tput bold/tput md是否可移植,如果不是,粗体文本的限制是什么?

感谢您的时间。

colors portability
  • 1 个回答
  • 118 Views
Martin Hope
ceremcem
Asked: 2018-09-01 23:20:52 +0800 CST

是什么让 Linux 发行版具有可移植性?

  • 6

什么可能会阻止我从笔记本电脑上拆下当前的硬盘并购买一台新笔记本电脑,安装磁盘并从我离开的地方继续?换句话说,是什么阻止了我当前的 Debian 9 安装被算作可移植?

  • 如果 Grub 条目使用实体引用(UUID 是正确的解决方案,而不是/dev/sdaXor (hd0,1))
  • 如果新笔记本电脑的 CPU 架构支持我的安装(在本例中为 x64)

新笔记本电脑应该会启动(在我的情况下正在启动)。

在最坏的情况下,驱动程序可能会丢失,但我的意图是创建一个名为的脚本switch-to-new-hardware.sh,它将安装:

  • 显卡驱动程序(如果可以,如果需要)
  • NIC(eth、wifi)卡驱动程序(如果需要)
  • 声卡驱动
  • ...

切换到新硬件时应该考虑什么?

system-installation portability
  • 2 个回答
  • 153 Views
Martin Hope
Guy
Asked: 2018-01-21 12:46:12 +0800 CST

如何以可移植的方式在文件之间更改 AWK 中的 RS 变量

  • 2

在查看另一个问题时,我遇到了一个我通常无法为 awk 解决的问题,如果 awk 程序需要两个文件(即,将第一个文件中的条目读取到数组中进行比较,这通常是这种情况)是什么处理文件之间更改 RS 的最佳方法?

给定以下文件:

~$> cat awktest1.txt 
111 112 113 114|121 122 123 124|131 132 133 134|141 142 143 144
 ~$> cat awktest2.txt 
211 212 213 214

221 222 223 224

231 232 233 234

241 242 243 244

如果我想运行以下命令,作为一个基本示例:

#! /usr/bin/awk -f

# awktest.awk file1 file2
# cant swap RS between files

BEGIN { RS="|" }

NR>ONR && ONR==1 { RS="" }
{ print $1 "." $2 "." $3 "." $4 }

# will work with with, but this is GNU only.
# ENDFILE { RS="" }
END { print "\nfinal $0: \n" $0 }

然后RS在读取第二个文件的第一条记录后发生变化,所以在这个(诚然人为的例子)中,输出是:

~$>./awktest.awk awktest1.txt awktest2.txt 
111.112.113.114
121.122.123.124
131.132.133.134
141.142.143.144
211.212.213.214

final $0:
211 212 213 214

221 222 223 224

231 232 233 234

241 242 243 244

第二个文件的所有内容都作为一条记录读取,而不是 4 条。显然,在这个例子中,在 awk 之前解决问题很简单,但是在 awk 中有什么方法吗?

awk portability
  • 1 个回答
  • 883 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    模块 i915 可能缺少固件 /lib/firmware/i915/*

    • 3 个回答
  • Marko Smith

    无法获取 jessie backports 存储库

    • 4 个回答
  • Marko Smith

    如何将 GPG 私钥和公钥导出到文件

    • 4 个回答
  • Marko Smith

    我们如何运行存储在变量中的命令?

    • 5 个回答
  • Marko Smith

    如何配置 systemd-resolved 和 systemd-networkd 以使用本地 DNS 服务器来解析本地域和远程 DNS 服务器来解析远程域?

    • 3 个回答
  • Marko Smith

    dist-upgrade 后 Kali Linux 中的 apt-get update 错误 [重复]

    • 2 个回答
  • Marko Smith

    如何从 systemctl 服务日志中查看最新的 x 行

    • 5 个回答
  • Marko Smith

    Nano - 跳转到文件末尾

    • 8 个回答
  • Marko Smith

    grub 错误:你需要先加载内核

    • 4 个回答
  • Marko Smith

    如何下载软件包而不是使用 apt-get 命令安装它?

    • 7 个回答
  • Martin Hope
    user12345 无法获取 jessie backports 存储库 2019-03-27 04:39:28 +0800 CST
  • Martin Hope
    Carl 为什么大多数 systemd 示例都包含 WantedBy=multi-user.target? 2019-03-15 11:49:25 +0800 CST
  • Martin Hope
    rocky 如何将 GPG 私钥和公钥导出到文件 2018-11-16 05:36:15 +0800 CST
  • Martin Hope
    Evan Carroll systemctl 状态显示:“状态:降级” 2018-06-03 18:48:17 +0800 CST
  • Martin Hope
    Tim 我们如何运行存储在变量中的命令? 2018-05-21 04:46:29 +0800 CST
  • Martin Hope
    Ankur S 为什么 /dev/null 是一个文件?为什么它的功能不作为一个简单的程序来实现? 2018-04-17 07:28:04 +0800 CST
  • Martin Hope
    user3191334 如何从 systemctl 服务日志中查看最新的 x 行 2018-02-07 00:14:16 +0800 CST
  • Martin Hope
    Marko Pacak Nano - 跳转到文件末尾 2018-02-01 01:53:03 +0800 CST
  • Martin Hope
    Kidburla 为什么真假这么大? 2018-01-26 12:14:47 +0800 CST
  • Martin Hope
    Christos Baziotis 在一个巨大的(70GB)、一行、文本文件中替换字符串 2017-12-30 06:58:33 +0800 CST

热门标签

linux bash debian shell-script text-processing ubuntu centos shell awk ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve