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 / 问题 / 768985
Accepted
Bertrand125
Bertrand125
Asked: 2024-02-11 00:08:00 +0800 CST2024-02-11 00:08:00 +0800 CST 2024-02-11 00:08:00 +0800 CST

Debian Linux live 系统 toram:无法打开 /dev/shm 设备

  • 772

我编写了一个shell脚本来从硬盘安装创建一个squashfs live系统,以便让Linux系统仅在内存中运行。

但是当我运行toram live系统时,dmesg中出现以下错误:

systemd[1]: Failed to open /dev/shm device, ignoring: Inappropriate ioctl for device

尽管出现这个错误,toram live 系统似乎运行没有问题。

仅当在已安装的 Linux 上仅创建一个用户时,该脚本才有效,因为 squashfs 不支持 ACL,但目录 /media/username/ 需要 ACL。

这是脚本:

    #!/bin/bash
    
    # Destination directory:
    DEST=$HOME/squashfs
    
    sudo mkdir -p ${DEST}
    
    # Copying installation in destination directory:
    sudo rsync --progress --specials --perms -av -lXEog --delete / ${DEST} --one-file-system \
    --exclude=/proc/* --exclude=/tmp/* --exclude=/dev/* \
    --exclude=/sys/* --exclude=/boot/* \
    --exclude=/etc/mtab --exclude=${DEST}
    
    # Make /media/username ownership to the user, because squashfs doesn't support ACL
    MEDIA="$USER:$USER $DEST/media/$USER"
    sudo chown $MEDIA
    
    # Remove links to mounted drives in destination directory /media/username/:
    MEDIA="$DEST/media/$USER"
    sudo rm -f $MEDIA/*
    
    # Remove unwanted entries in fstab of the future live system: 
    sudo sed -i '/\/boot\/efi/d' ${DEST}/etc/fstab 
    sudo sed -i '/swap/d' ${DEST}/etc/fstab 
    sudo sed -i '/UUID=.*\ \/\ /d' ${DEST}/etc/fstab
    
    # Mount special files in order to chroot:
    sudo mount -o bind /proc ${DEST}/proc
    sudo mount -o bind /dev ${DEST}/dev
    sudo mount -o bind /dev/pts ${DEST}/dev/pts
    sudo mount -o bind /sys ${DEST}/sys
    sudo cp /etc/resolv.conf ${DEST}/etc/resolve.conf
    
    # upgrade the chrooted system, and install live-boot package 
    # as well as the lastest kernel: 
    sudo chroot ${DEST} apt-get update
    sudo chroot ${DEST} apt-get upgrade
    sudo chroot ${DEST} apt-get remove linux-image*
    sudo chroot ${DEST} apt-get install live-boot
    sudo chroot ${DEST} apt-get install linux-image-amd64
    sudo chroot ${DEST} apt-get clean
    sudo chroot ${DEST} apt clean
    
    # Umount the special files:
    sudo umount ${DEST}/proc
    sudo umount ${DEST}/dev/pts
    sudo umount ${DEST}/dev
    sudo umount ${DEST}/sys
    
    # Delete unwanted files:
    [ -n "$DEST" ] && sudo find ${DEST}/var/mail ${DEST}/var/lock ${DEST}/var/backups ${DEST}/var/tmp -type f -exec rm {} \;

    # Delete only OLD log files:
    [ -n "$DEST" ] && sudo find ${DEST}/var/log -type f -iregex '.*\.[0-9].*' -exec rm -v {} \;
    [ -n "$DEST" ] && sudo find ${DEST}/var/log -type f -iname '*.gz' -exec rm -v {} \;
    
    # Clean current log files:
    [ -n "$DEST" ] && sudo find ${DEST}/var/log -type f | while read file; do echo -n '' | sudo tee $file; done
    
    # Clean Pakcage cache:
    [ -n "$DEST" ] && sudo rm -v ${DEST}/var/cache/apt/archives/*.deb
    
    # Remove old kernel and initrd in the partition where will be installed the live system: 
    sudo rm -f /media/$USER/LIVE/live/initrd.img*
    sudo rm -f /media/$USER/LIVE/live/vmlinuz*    
    
    # Copy new kernel and initrd in the partition where will be installed the live system: 
    sudo mv -f ${DEST}/boot/initrd.img* /media/$USER/LIVE/live/initrd.img
    sudo mv -f ${DEST}/boot/vmlinuz* /media/$USER/LIVE/live/vmlinuz
    
    # Remove old shquashfs in the partition where will be installed the live system: 
    sudo rm -f /media/$USER/LIVE/live/filesystem.squashfs
    
    # Make the new squashfs:
    sudo mksquashfs ${DEST} /media/$USER/LIVE/live/filesystem.squashfs -xattrs -processors 4 -noappend -always-use-fragments

`/media/$USER/LIVE/` is where the live system partition is mounted.
   
Then I boot the live system placed on a partition with the kernel options: `toram boot=live`

编辑:

当我运行df命令时,它告诉我/dev/shm已安装在/run/live/medium.

该命令mount | grep medium告诉我它/dev/shm也安装在/usr/lib/live/mount/medium.

系统似乎在 RAM 中保存了一个包含 squashfs 的分区的副本。

当我想卸载时/run/live/medium,它告诉我这是不可能的,因为the target is active。但我已经成功卸载了/usr/lib/live/mount/medium。

所以我想知道这些问题是否有联系,是否有办法卸载/run/live/medium?

linux
  • 3 3 个回答
  • 141 Views

3 个回答

  • Voted
  1. spoutnik
    2024-02-11T01:09:56+08:002024-02-11T01:09:56+08:00

    /dev/shm通常是 tmpfs 或 ramdisk,因此从非常规环境中安装它可能会出现问题。systemd正确地忽略了这一点,因为这不是问题,因为您在完整 ramdisk 环境中不需要 ramdisk fs。

    • 2
  2. Best Answer
    Jan Schär
    2024-04-11T05:16:59+08:002024-04-11T05:16:59+08:00

    这是由实时启动中的错误引起的。该错误已在上游修复,但发布还需要一些时间。同时,您可以忽略错误日志(它是无害的)。或者你可以自己修补:

    if [ -f ${DEST}/lib/live/boot/9990-toram-todisk.sh ]; then
      sed -i 's|dev="/dev/shm"|dev="tmpfs"|g' ${DEST}/lib/live/boot/9990-toram-todisk.sh
    fi
    

    bug解释:live-boot挂载一个tmpfs/dev/shm作为设备名。但 tmpfs 实际上没有底层设备,因此您可以使用任何内容作为设备名称。通常,tmpfs使用。如果/dev/shm使用 ,这会使 systemd 感到困惑,因为它尝试/dev/shm作为设备打开,但由于/dev/shm不是设备而失败。

    • 1
  3. eyoung100
    2024-02-15T04:42:28+08:002024-02-15T04:42:28+08:00

    为什么不通过在中添加以下 2 个命令来消除错误# Mount Special Files Section

    sudo test -L /dev/shm && sudo rm /dev/shm && sudo mkdir /dev/shm sudo chmod 1777 /dev/shm

    请参阅:Gentoo Wiki:安装必要的文件系统

    我还可以建议使用上面链接中的命令仅输入一次 chroot 吗?

    • 0

相关问题

  • 有没有办法让 ls 只显示某些目录的隐藏文件?

  • 使用键盘快捷键启动/停止 systemd 服务 [关闭]

  • 需要一些系统调用

  • astyle 不会更改源文件格式

  • 通过标签将根文件系统传递给linux内核

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