ubuntu, updated

Format and mount

Put a file system on a partition or volume, mount it, and make the mount survive reboots with /etc/fstab.

Add a new data disk: the full recipe

lsblk                                                # 1. find the disk, e.g. sdb
sudo parted -s /dev/sdb mklabel gpt mkpart data ext4 0% 100%   # 2. one partition
sudo mkfs.ext4 -L data /dev/sdb1                     # 3. format (label "data")
sudo mkdir -p /data                                  # 4. create the mount point
sudo blkid /dev/sdb1                                 # 5. copy the UUID
sudoedit /etc/fstab                                  # 6. add a line (below)
sudo systemctl daemon-reload && sudo mount -a        # 7. mount everything from fstab
df -h /data                                          # 8. check

For LVM, use /dev/data-vg/data-lv instead of /dev/sdb1 (see LVM volumes).

Formatting

File systemCommand
ext4sudo mkfs.ext4 -L LABEL /dev/sdb1
XFSsudo mkfs.xfs -L LABEL /dev/sdb1
exFAT (USB sticks)sudo mkfs.exfat /dev/sdb1
Swapsudo mkswap /dev/sdb2 && sudo swapon /dev/sdb2

Formatting erases everything on the device. Not sure which one to pick? File systems compared.

/etc/fstab

Each line is one mount that happens at boot:

# device                                    mount point  type  options          dump  pass
UUID=3f2a9c1e-7b4d-4e1a-9c2f-1a2b3c4d5e6f   /data        ext4  defaults,nofail  0     2
/dev/data-vg/logs-lv                        /var/log/app xfs   defaults         0     2
FieldMeaning
deviceUse UUID=... for partitions (stable), or the /dev/VG/LV path for LVM
optionsdefaults is fine. Add nofail for disks that may be missing, so boot doesn’t stop. Add noatime to save writes.
dumpAlways 0
passOrder of the file system check at boot: 0 none, 1 root only, 2 everything else

Always test before rebooting. A broken fstab line can drop the server into emergency mode:

sudo findmnt --verify          # checks fstab for errors
sudo mount -a                  # mounts everything; errors show up now, not at boot

Mount and unmount by hand

WhatCommand
Mount (until reboot)sudo mount /dev/sdb1 /data
Mount everything in fstabsudo mount -a
Unmountsudo umount /data
Remount read-onlysudo mount -o remount,ro /data
Mount an ISOsudo mount -o loop file.iso /mnt
Network share (SMB)sudo mount -t cifs //server/share /mnt -o username=USER (needs cifs-utils)

“target is busy”

You can’t unmount while something uses the folder, even a shell that has cd’d into it.

sudo fuser -vm /data          # who uses it?
sudo lsof +f -- /data         # same, more detail

Stop those processes (or cd out), then unmount again.

§ home
~/knubertus/home/
1,1 Top