User Tools

Site Tools


devices-and-file-system

Devices & File Systems


DEVICES
cat /proc/devices displays character and block devices currently configured, sorted by their major numbers
lshw / lshal prints detailed information about the recognized hardware and its configuration
lspci prints information about PCI buses and devices connected to them, -v detailed output
lsusb prints information about USB buses and devices connected to them, -v detailed output
lsof / lsof <file / device> lists all / particular open files (devices) - their names, a program being used, PID, a user's name, a file descriptor, a file type, the major and minor number of the device, a file size in B and an i-node number, -l prints UID, -p <PID> sorted by given process, -u <user> sorted by given user, -r <n> refreshes the list every n seconds
$ lsof /dev/cdrom
$ lsof /dev/snd/*
$ lsof -p $$
(prints open files from the current shell)
iotop displays I/O disk usage, the speed of read and written data and a detailed, interactive list of all running processes in the system (the output changes according to the current state), -o active processes only, -u <user> processes of a particular user, -p <PID> a particular process only, q quits the program
iostat displays I/O disk usage and the speed of read and written data, -p <device> specifies a particular disk and its partitions
hdparm <device / partition> prints or sets parameters of a particular ATA / SATA device
smartctl <device> -a prints detailed information about a device status (supporting SMART technology) in order to avoid its failure, -s <on / off> activates / deactivates SMART, -t <short / long> executes short / long test
# smartctl -s on -t long /dev/sda
badblocks <device / partition> searches a device for bad blocks, -b <n> specifies the size of blocks in B (1024 by default), -i <file> skips testing a list of already existing known bad blocks contained in the file, -v detailed output
# badblocks -vb 4096 /dev/sda2 > bad_blocks
blockdev (<options>) <command> <device / partition> prints or sets a device features, -v detailed output, --setro sets "read-only" permissions, --setrw sets "read-write" permissions, --getsize prints the number of sectors per a device
mdadm <mode> <raid_device> (<options>) (<component_device>) manages software RAID (virtual) devices; useful modes are: --create creates software RAID, --grow changes the size or shape of an active array, --add adds a physical device, --fail marks a physical device as faulty and deactivates it (useful when testing RAID 1 or RAID 5, but not RAID 0), --remove removes a physical device (must not be active), --detail prints detailed information about a RAID device, --stop deactivates a raid device, --assemble activates a pre-existing raid device, --scan applies a particular operation to all arrays listed in /etc/mdadm.conf; -v detailed output
# mdadm --create /dev/md1 --level=1 --raid-devices=2 /dev/sd{b,c}1
(creates software RAID 1 including /dev/sdb1 and sdc1)
# mdadm --grow /dev/md1 --raid-devices=3
# mdadm --add /dev/md1 /dev/sdd1
# mdadm --stop /dev/md1
# mdadm --assemble --scan
cat /etc/mdadm.conf prints configuration information about mdX RAID devices
cat /proc/mdstat prints the current status of mdX RAID devices
sync synchronizes data buffered in memory with a disk
eject (<device>) ejects removable media, -t inserts removable media
$ eject (-t) / eject (-t) /dev/cdrom


FILE SYSTEM & SWAP
cat /proc/partitions displays partitions` names, the number of physical disk blocks contained in the particular partition and the major and minor numbers of the devices
fdisk <device / partition> prints the number of cylinders on a disk and with the option m displays a menu for working with the partition table: p prints the partition table, n creates a new partition, l prints all available types of partitions, t changes the type of a partition, d removes a partition, q exit, w saves a new partition table + exit; -l lists the partition table for the specified device, if no device is given, all mounted devices are used, -u prints sizes in sectors instead of cylinders
# fdisk -lu /dev/sdb
partprobe informs the OS of partition table changes, -s prints a summary of devices and their partitions
mkfs <partition> / <LV> creates a file system on the particular partition (the partition must be unmounted), -t <FS> specifies the type of the FS, -c checks the device for bad blocks, -v detailed output
# mkfs -ct ext3 /dev/sdb2
mke2fs <partition> / <LV> creates an ext2, ext3, ext4 file system on the particular partition (the partition must be unmounted), -b <n> specifies the block size in B, -c checks the device for bad blocks, -i <n> specifies the number of bytes per i-node, -t <FS> specifies the type of the FS, -L <volume_label> sets a volume label of the FS, -v detailed output
# mke2fs -cvt ext4 /dev/sdb2
# mkfs.ext4 /dev/mapper/centosvg-weblv
mkfs.xfs <partition> / <LV> creates an xfs file system on the particular partition (the partition must be unmounted), -b size=<n> specifies the block size in B (4096 B by default), -L <volume_label> sets a volume label of the FS
mkisofs <directory> creates an ISO 9660 file system (file .iso) from a particular directory, -J Joliet extention (the contents is readable in windows), -r RockRidge extention (the contents is readable in linux / unix), -o <file> defines an output file
$ mkisofs -J -r -o test.iso test
xfs_info <FS> displays xfs filesystem information
e2label <partition> (<volume_label>) prints or sets a volume label of the partition with an ext2, ext3 or ext4 file system
# e2label /dev/sdb1 dbdisk1
xfs_admin alters parameters of an xfs filesystem, -L <volume_label> <partition> sets a volume label of the partition with an xfs file system
tune2fs <partition> alters parameters of an ext2, ext3, ext4 file system, -l lists the contents of the FS superblock, -L <volume_label> changes a volume label of the FS, -j adds an ext3 journal to the ext2 FS (the partition must be unmounted; the permanent setup requires changing "ext2" to "ext3" in /etc/fstab), -O (^)<feature> sets or when using "^" character clears a particular feature of the FS, -o (^)<mount_option> sets or when using "^" character clears a particular mount option of the FS
# tune2fs -j /dev/sdb1
# tune2fs -O ^has_journal /dev/sdb1
(converts an ext3 FS back to ext2)
# tune2fs -o acl /dev/sdb1
resize2fs <partition> (<size>) changes (enlarges or shrinks) an ext2, ext3, ext4 file system size on the particular partition to the required value (the FS must be mounted), if the size is not specified when enlarging the FS, the partition maximum size is automatically used (if the FS spreads over the whole partition and is needed to be enlarged, the underlying partition must be expanded first; if the partition is to be shrinked, it must be unmounted first, checked by "fsck" program, the FS size reduced first and then the partition size can be finally shrinked, but it must not be smaller than the new size of the FS), -p prints a percentage completion bars
# resize2fs /dev/sdb3 500M
# resize2fs -p /dev/vg00/homelv 200G
xfs_growfs <FS> enlarges an xfs file system size (the FS cannot be shrinked and must be mounted), -D <size> specifies the FS size (if the size is not specified, the partition maximum size is automatically used)
fsck <partition> checks the FS and eventually repairs founded errors (the FS must be unmounted, "/" in "read-only" mode), -A checks subsequently all the file systems specified in /etc/fstab (it is executed automatically at the system startup), -R skips the root FS, -a repairs errors automatically without any confirmation, -r interactive mode, -t <FS> specifies the FS type, -V detailed output
# fsck (-t ext3) /dev/sdb1
e2fsck <partition> checks an ext2, ext3, ext4 file system and eventually repairs founded errors (the FS must be unmounted, "/" in "read-only" mode), -c checks the device for bad blocks, -f forces checking even if the FS seems to be clean, -p repairs errors automatically without any confirmation, -v detailed output
# e2fsck -vc /dev/sdb1
xfs_repair <partition> checks an xfs file system and eventually repairs founded errors (the FS must be unmounted, "/" in "read-only" mode), -n prints possible errors only (without altering the FS)
debugfs (<partition>) interactively examines or alters an ext2, ext3, ext4 file system, -w opens the FS in "read-write" mode; open <partition> opens the FS for a check / editing, close leaves the FS, icheck <block> prints an i-node number using the particular block, ncheck <i-node> prints the path to the given i-node (file), quit quits the program
xfs_db <partition> interactively examines or alters an xfs file system
cat /proc/filesystems displays a list of the file system types currently supported by the kernel
cat /etc/fstab lists defined file systems - a device / partition name or UUID, mount point, FS type, mount options (see "mount" command), backup by "dump" program ("0" = no, "1" = yes) and check order of the FS by "fsck" program at the system startup ("0" = no check, "1" = first order (for FS "/"), "2"-"9" other orders)
cat /etc/mtab / cat /proc/mounts lists currently mounted file systems
df (<directory / FS / partition>) displays information about used and available disk space on the particular partition in kB, if it is not specified, all currently mounted FS are shown, -m in MB, -i lists inode information instead of block usage, -h well-arranged output, -P uses the POSIX output format
$ df -P | awk '+$5 >= 90 {print}'
(prints FS usage equal to or greater than 90%)
mkswap <partition> creates a swap area for virtual memory, -L <volume_label> sets a volume label
swapon <partition> activates a swap area (to ensure permanent activation, the swap partition must be specified in /etc/fstab with "auto" option), -a activates all swap partitions specified in /etc/fstab, -s displays active swap partitions (data from /proc/swaps), -v detailed output
swapoff <partition> deactivates a swap area
cat /proc/swaps displays active swap partitions
mount
mount (<device / partition / (NFS_server:)FS>) (<directory>)
displays currently mounted file systems (data from /etc/mtab)
mounts a particular FS, -a all FS in /etc/fstab with "auto" option, -L <label> according to a given label, -U <UUID> according to a UUID, -t <FS> specifies the FS type, -n without writing in /etc/mtab (e.g. if /etc should be mounted as read-only FS), -o <attribute> specifies comma separated mount options (e.g. remount remounts an already-mounted FS ro read-only, rw read-write, (no)dev allows (not) character and block devices to access the FS, (a)sync allows (not) a synchronous read / write access to the FS, (no)auto mounts (not) FS automatically, users any user is allowed to mount and unmount the FS, (no)user allows (not) an ordinary user to mount the FS (and only this user is allowed to unmount it again), usrquota / grpquota allows users' / groups' disk usage and limits on the FS (the attribute must exist in /etc/fstab), (no)acl allows (not) extended ACL permissions for ext2, ext3 or ext4 FS, (no)atime updates (not) i-node access time for each access to the FS, (no)suid allows (not) setuid and setgid permissions for executable files, (no)exec allows (not) execution of binary files on the FS, defaults = rw, suid, dev, exec, auto, nouser, async)
$ mount /dev/fd0 / mount /mnt/floppy
(mount options for the particular device / partition must be specified in /etc/fstab)
$ mount -t iso9660 /dev/cdrom /mnt/cdrom
$ mount -t vfat /dev/sdc1 /mnt/flash
# mount -no remount,ro /
# mount server_01:/data /mnt/nfs
umount <directory / FS / device / partition> unmounts a file system
$ umount /mnt/flash
$ umount /dev/sdc1
showmount / showmount <host> prints a list of all hosts (clients) which are allowed to mount a local directory via NFS from the local / particular server (data from /etc/exports), -a prints hostnames or IP addresses of remote hosts and directories that are currently exported to them, -e prints a list of all exported directories and remote hosts which are allowed to mount them
exportfs (<options>) (<client>:<directory>) defines remote hosts (clients) and local directories that are supposed to be exported to them via NFS; (permanent setup in /etc/exports), -a exports all that is written in /etc/exports, -r repeats exporting of all items from /etc/exports (synchronizes /var/lib/nfs/etab with /etc/exports), -i ignores information in /etc/exports and uses options given on the command line only, -u <client>:<directory> cancels a particular export, with "-a" option it cancels exports of all the items in /etc/exports, -o specifies other options for exporting a local directory (the default options are sync,ro,root_squash,wdelay)
# exportfs -o rw client1:/usr/tmp
# exportfs -au
quota displays current user's disk usage and limits (quotas) on all mounted FS, -u <user> for a particular user, -g <group> for a particular group, -v detailed output
repquota <FS> prints a summary of the disk usage and quotas for the specified FS, -a on all mounted FS, -u reports quotas for users (by default), -g reports quotas for groups, -v detailed output
quotacheck <FS> checks quota information (maximum size of available disk space in i-nodes or in 1-kB blocks for users or groups) on the given FS with "usrquota" or "grpquota" attribute in /etc/fstab (before the scan the FS is mounted in "read-only" mode, then again in "read-write" mode), -a checks all mounted FS except for NFS, -c performs a new scan and creates aquota.user / aquota.group files (ignores existing quota files), -u checks user quotas (by default), -g checks group quotas, -v detailed output, -i interactive mode
# quotacheck -cvug /home
(activates quotas on a particular FS)
edquota <user / group> sets quotas by editing aquota.user or aquota.group files, -u edits user quotas, -g edits group quotas, -p <example> according to an example (user), -f <FS> only for the given FS, -t sets a maximum period (in units of seconds, minutes, hours or days), during of which a "soft limit" can be exceeded up to the value called a "hard limit" (if this period is not specified, the maximum value = "soft limit")
# edquota -p tim `awk -F: '$3 > 499 {print $1}' /etc/passwd`
setquota <user / group> sets quotas directly from the command line, -u edits user quotas, -g edits group quotas, -p <example> according to an example (user), -a for all mounted FS with a parameter "usrquota" / "grpquota" set up, -t sets a maximum period (in units of seconds, minutes, hours or days), during of which a "soft limit" can be exceeded up to the value called a "hard limit" (if this period is not specified, the maximum value = "soft limit")
# setquota -u tim 512 1024 0 0 /home
quotaon / quotaoff <FS> turns quotas on / off on a particular FS, -a on all mounted FS, -u for user quotas, -g for group quotas
dump <target> <source> backups ext2, ext3, ext4 file system (the partition must be unmounted, if it is mounted directly to "/", the system must be running on runlevel 1, which stops all the services using this partition, and the FS should be mounted in "read-only" mode), -<n> incremental backup level (values of 0 - 9, 0 = full backup), -u updates /etc/dumpdates (overview of performed backups), -a automatical size (data are being written up to an end of the tape), -f <target> a target file / device, -z gzip compression, -j bzip2 compression, -L <label> labels an archive, -M "multi-volume" backup (for archives bigger than 2 GB), -S determines the amount of space that is needed to perform the dump without actually doing it, -W prints the FS, which needs to be dumped (data from /etc/dumpdates and /etc/fstab)
# dump -0uf /tmp/home.bckp /home
# dump -0auf /dev/st0 -L Full_bckp_11-07-08 /
# dump -0uj 9 /home | dd bs=1024 of=/dev/rmt0
(received variable blocks of data are converted to blocks of the same size and saved on a tape)
restore <source> restores files or file systems from backups made with "dump" program into the working directory, -f <source> source file / device, -r newly formated FS, -x existing FS, -s <n> number of a backup (file), -i interactive mode, -t prints the contents of an archive, -v detailed output
# restore -rvf /dev/rmt0
(full FS recovery)
# restore -is 3 -f /dev/rmt0
(interactive recovery - single files can also be recovered)
photorec recovers lost data from a HDD or portable media of various types of FS; it works interactively and automatically detects the FS, a particular data format can also be recovered


LVM (logical volume manager) dynamic partitions management
pvcreate <PV> initializes a PV (physical disk or partition) for use by LVM
# pvcreate /dev/sda4
pvs prints information about all PVs in the system, their name, VG, attributes, size and free space
pvdisplay / pvdisplay <PV> displays detailed attributes of all PVs / particular PV, -m displays the mapping of physical extents (PEs) to logical volumes (LVs) and logical extents (LEs)
pvchange <PV> changes attributes of a PV, -x {y / n} enables / disables allocation of physical extents on the PV
pvresize <PV> resizes a PV
# pvresize --setphysicalvolumesize 40G /dev/sda1
# pvresize /dev/sda4
(expands the PV to get all free space on /dev/sda4)
pvmove <source_PV> (<target_PV>) moves data from one PV to another, if the target PV is not specified, data are moved to any free space within the particular VG
pvremove <PV> removes a PV from use by LVM
vgcreate <VG> <PV> creates a VG (virtual disk) using PVs previously configured for LVM, -s <size> sets the physical extent size on PVs of this VG (4MB by default)
# vgcreate root_vg /dev/sda1 /dev/sda2 /dev/sda3
vgs prints information about all VGs in the system, their name, number of PVs / LVs, number of copies, size and free space
vgdisplay / vgdisplay <VG> displays detailed attributes of all VGs / particular VG, -v including all the contained PVs and LVs
vgchange <VG> changes attributes of a VG, -a {y / n} activates / deactivates the VG
# vgchange -a n data_vg
vgrename <old_VG> <new_VG> renames a VG
# vgrename data_vg datavg
vgextend <VG> <PV> adds a PV to a VG
# vgextend vg00 /dev/sda4
vgreduce <VG> <PV> removes a PV from a VG (the PV must be empty)
vgexport <VG> exports a VG (makes it unknown to the system)
vgimport <VG> imports a VG (makes exported VGs known to the system)
vgremove <VG> removes a VG
lvcreate <LV> <VG> creates an LV (virtual partition), -n <LV> sets an LV name, -L <size> sets an LV size, -l <n> sets an LV size by allocating the number of logical extents, -m <n> sets a number of LV copies (creates a mirror of a linear LV), -p {r / w} sets read / read and write permissions
# lvcreate -n web_lv -L 10G datavg
lvs prints information about all LVs in the system, their name, VG, attributes, size and other information
lvdisplay / lvdisplay <LV / VG> displays detailed attributes of all LVs / particular LV or all LVs on the given VG, -m displays the mapping of logical extents (LEs) to physical volumes (PVs) and physical extents (PEs) and the type of the LV (linear, mirrored, snapshot)
lvchange <LV> changes attributes of an LV, -p {r / w} sets read / read and write permissions, -a {y / n} activates / deactivates the LV
# lvchange -a n datavg/web_lv
lvrename <old_LV> <new_LV> renames an LV
# lvrename datavg/web_lv datavg/weblv
lvresize <LV> changes an LV size, -L (+ / -)<size> sets, enlarges or shrinks an LV size to the required value in MB (M), GB (G), TB (T), PB (P), EB (E), -l <n> sets an LV size by allocating the number of logical extents (if the FS spreads over the whole LV and is needed to be enlarged, the underlying LV must be expanded first; if the LV is to be shrinked, it must be unmounted first, checked by "fsck" program, the FS size must be reduced first and then the LV size can be finally shrinked, but it must not be smaller than the new size of the FS), -r resizes the underlying file system
# lvresize -rL +200M vg00/rootlv
# lvresize -l +100%FREE /dev/VolGroup00/LogVol00
(extends the LV to occupy the remaining free space in the VG)
lvconvert <LV> changes the type of an LV, -m <n> sets a number of LV copies (creates a mirror of a linear LV), -s <source_LV> <target_LV> creates a snapshot of an LV
# lvconvert -s vg00/lvol1 vg00/lvol2
lvremove <LV> removes an LV
Last modified: 2018/07/01 23:33 by Miroslav Bernát

visits: