Filters
Zo zoek je
  • Gewone woorden vinden namen, teksten en voorbeelden.
  • "twee woorden" vindt precies die zin.
  • --naam of -x vindt een optie.
  • #woord zoekt alleen in commando's.
  • @grep vindt lessen en labs die grep gebruiken.
  • Filters: cat:network · in:labs · in:notes · level:rhcsa · ch:8 · root:yes. Zet ! voor een woord om het weg te laten. OR tussen woorden betekent één ervan.
  • ↑ ↓ bewegen · Enter openen · Esc sluiten · / zoeken

Hoofdstuk 14Naam in de cursus: Accessing Removable Media

Use USB disks, ISO files and other removable media

To read a USB stick, a DVD or an ISO file, Linux must mount it: hang its file system into a folder of the tree. The desktop does it for you; on a server you do it by hand. This chapter shows how to find the new device, mount it, read it, and remove it safely.

  • 7 Lessen
  • 17 Commando's
  • 1 Labs

Dit deel is nog niet vertaald. Je ziet de Engelse tekst.

$ als gewone gebruiker# als root (of met sudo)

Vaardigheden in dit hoofdstuk

  • USB-schijven en ISO-bestanden koppelen en ontkoppelen

14.1

Understand mounting

A file system becomes visible only when it is mounted on a folder (the mount point). After umount the folder is just an empty folder again.

findmnt /
TARGET SOURCE                FSTYPE OPTIONS
/      /dev/mapper/rhel-root xfs    rw,relatime,seclabel
df -h
lsblk
NAME          MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTS
vda           252:0    0   20G  0 disk
├─vda1        252:1    0    1G  0 part /boot
└─vda2        252:2    0   19G  0 part
  ├─rhel-root 253:0    0   17G  0 lvm  /
  └─rhel-swap 253:1    0    2G  0 lvm  [SWAP]
sda             8:0    1 14.6G  0 disk
└─sda1          8:1    1 14.6G  0 part

The RM column = 1 means removable. Here sda1 is a USB stick that is not mounted yet.

14.2

Find the new device

Plug the device in, then ask the kernel which name it got.

lsblk -f
NAME   FSTYPE LABEL   UUID                                 MOUNTPOINTS
sda
└─sda1 vfat   BACKUP  4A3C-1F2E
blkid /dev/sda1
/dev/sda1: LABEL="BACKUP" UUID="4A3C-1F2E" TYPE="vfat" PARTUUID="0e4c1d2a-01"
journalctl -k -n 15
dmesg -w
NameUsually is
/dev/sda, /dev/sdb …USB disks and sticks (also SATA/SAS disks)
/dev/sda1The first partition on that disk
/dev/sr0The DVD / CD drive
/dev/nvme0n1An NVMe SSD
/dev/vdaA virtual disk in a KVM machine

Let op

Names like sda can change from boot to boot. Before you write to a disk, check it with lsblk -f (size, label) — writing to the wrong disk destroys data.

14.3

Mount by hand on a server

Make a folder, then mount DEVICE FOLDER. mount finds the file system type by itself.

mkdir -p /mnt/usb
mount /dev/sda1 /mnt/usb
ls /mnt/usb
findmnt /mnt/usb
mount -o ro /dev/sda1 /mnt/usb
mount -o uid=1000,gid=1000 /dev/sda1 /mnt/usb
mount LABEL=BACKUP /mnt/usb
OptionUse it when
-o roYou only want to read (safe for evidence or old disks)
-o uid=…,gid=…A vfat/exfat stick has no Linux owners; give the files to a user
-t TYPEmount can not guess the type
LABEL= / UUID=Mount by name or ID instead of the changing device name

Notitie

RHEL can read vfat (FAT32), ext4, xfs and ISO 9660 (CD/DVD) out of the box. NTFS is not part of RHEL.

14.4

Mount it in the desktop

In GNOME, a plugged-in stick is mounted for you under /run/media/USER/LABEL. Without root rights, the tool udisksctl does the same on the command line.

udisksctl mount -b /dev/sda1
Mounted /dev/sda1 at /run/media/student/BACKUP
ls /run/media/student/BACKUP
udisksctl unmount -b /dev/sda1
Unmounted /dev/sda1.
udisksctl power-off -b /dev/sda

udisksctl power-off stops the whole stick, so it is safe to pull it out.

14.5

Read an ISO file without a DVD

An ISO file is a full DVD image. Mount it with a loop device to read the files inside.

mkdir -p /mnt/iso
mount -o loop,ro rhel-10.0-x86_64-dvd.iso /mnt/iso
ls /mnt/iso
AppStream  BaseOS  EFI  EULA  GPL  images  isolinux  media.repo
losetup -l
umount /mnt/iso

Op het werk

A RHEL DVD ISO has the BaseOS and AppStream repositories inside. Mounted under /mnt/iso, it can be a local repository for servers without internet: see Use a local repository.

14.6

Remove the media safely

Always umount before you pull the stick out. Linux keeps data in memory and writes it later — pulling too early loses data.

sync
umount /mnt/usb
umount /dev/sda1
umount: /mnt/usb: target is busy.
lsof /mnt/usb
COMMAND  PID    USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
bash    4321 student  cwd    DIR    8,1     4096    1 /mnt/usb
fuser -vm /mnt/usb
eject /dev/sr0

"target is busy" means a program still uses a file or a shell is in that folder. Find it with lsof or fuser -vm, close it (or cd away), then try again.

Onthoud

umount (not "unmount") takes the folder or the device. After umount you can remove the media.

14.7

Prepare a stick for Linux and Windows

To give files to people with other systems, format a stick with vfat (FAT32). Formatting erases everything on it.

lsblk -f /dev/sda
umount /dev/sda1
wipefs -a /dev/sda1
mkfs.vfat -n SHARE /dev/sda1
mount /dev/sda1 /mnt/usb

Let op

Double-check the device name. mkfs on /dev/vda2 instead of /dev/sda1 deletes your server. For disks that stay in the server (partitions, /etc/fstab), see Manage basic storage.

Oefenen

Alle commando's in dit hoofdstuk