Hot answers tagged

216

For disk I/O trending there are a few options. My personal favorite is the sar command from sysstat. By default, it gives output like this: 09:25:01 AM CPU %user %nice %system %iowait %steal %idle 09:35:01 AM all 0.11 0.00 0.01 0.00 0.00 99.88 09:45:01 AM all 0.12 0.00 0.01 0.00 ...


126

with lsblk For instance, the command sudo lsblk -o name,mountpoint,label,size,uuid outputs: NAME MOUNTPOINT LABEL SIZE UUID sda 1.4T ├─sda1 /boot boot 953M f557b9f0-edb5-42bb-94d8-27bc03c3c2c7 ├─sda2 ...


102

Have a look at iotop. Or iodump, if that's more down your way of thinking. Note: This requires at least kernel 2.6.20 to work.


87

I like dstat. It can show totals and statistics per disk and even md-devices (RAID), also can use colors for better overview: $ dstat -tdD total,sda,sdb,sdc,md1 60 ----system---- -dsk/total----dsk/sda-----dsk/sdb-----dsk/sdc-----dsk/md1-- time | read writ: read writ: read writ: read writ: read writ 08-11 22:08:17|3549k 277k: 144k 28k: 851k ...


80

Unmount any filesystems on the disk. (umount ...) Deactivate any LVM groups. (vgchange -an) Make sure nothing is using the disk for anything. Once you've done that, it should be safe to unplug. If you want to be extra cautious, do echo 1 > /sys/block/(whatever)/device/delete first. That'll unregister the device from the kernel, so you know nothing's ...


68

if I turn off the computer immediately after I edit and save a file, my changes will be most likely lost? They might be. I wouldn't say "most likely", but the likelihood depends on a lot of things. An easy way to increase performance of file writes, is for the OS to just cache the data, tell (lie to) the application the write went through, and then ...


61

If you are using systemd then use udisksctl utility with power-off option: power-off Arranges for the drive to be safely removed and powered off. On the OS side this includes ensuring that no process is using the drive, then requesting that in-flight buffers and caches are committed to stable storage. I would recommend first to unmount all ...


49

You can also run the following command using du : ~# du -Pshx /* 2>/dev/null The -s option summarizes and displays total for each argument. h prints Mio, Gio, etc. x = stay in one filesystem (very useful). P = don't follow symlinks (which could cause files to be counted twice for instance). Be careful, the /root directory will not be shown, you have to ...


48

Just from files on your computer (assuming a recent kernel) you can ask /sys/block/sda/stat or /proc/diskstats. It will need some translating, however. But it's nice for a quick and dirty check.


43

iostat is part of the sysstat package, which is able to show overall iops if desired, or show them separated by reads/writes. Run iostat with the -d flag to only show the device information page, and -x for detailed information (separate read/write stats). You can specify the device you want information for by simply adding it afterwards on the command ...


38

dd if=/dev/zero of=/dev/sda bs=4096 count=4096 Q: why 4096 is particularly used for counter? This will zero out the first 16 MiB of the drive. 16 MiB is probably more than enough to nuke any "start of disk" structures while being small enough that it won't take very long. dd if=/dev/zero of=/dev/sda bs=512 count=4096 seek=$(expr blockdev --getsz /dev/...


36

If you are looking for partitioning information you can use fdisk or parted. If you are more interested into how the various partitions are associated with the mount points try lsblk which I often use as: lsblk -o "NAME,MAJ:MIN,RM,SIZE,RO,FSTYPE,MOUNTPOINT,UUID" to include UUID info. And finally smartctl -a /dev/yourdrive gives you detailed info like: ==...


34

Another option is to use: sudo iotop -aoP -a Will show accumulated output -o Will only output -P Will only show processes instead of threads This program will tell you how much a process has written to disk and read from disk since iotop was started.


28

mount -o remount,size=5G /tmp/


26

The simple answer to the question in the title is "Yes". But what you really want to do is the next step, which is getting the existing data mirrored. It's possible to convert the existing disk, but it's risky, as mentioned, due the the metadata location. Much better to create an empty (broken) mirror with the new disk and copy the existing data onto it. ...


25

There is a blkid command which may be what you are looking for. Results are similar to the following: $ sudo blkid /dev/mapper/vg_rootdisk-lv_var /dev/mapper/vg_rootdisk-lv_var: LABEL="LV_VAR" UUID="08520908-03cd-4e42-a4e4-0f5a771be16c" TYPE="ext4" One other option is to use the udevadm command, which likely will give you far more than you need: $ sudo ...


25

Assuming you're on Linux. Try: sudo /lib/udev/scsi_id --page=0x80 --whitelisted --device=/dev/sdc or: cat /sys/block/sdc/device/{vendor,model} You can also get information (including labels) from the filesystems on the different partitions with sudo blkid /dev/sdc1 The pathid will help to determine the type of device: readlink -f /sys/class/block/sdc/...


16

This will erase the first 4096*4096=16MB and last 512*4096=2MB of your hard drive, which contain important structures useful for recovery. I assume this code was posted maliciously. I've never encounter a situation where explicitly specifying a count other than 1 was useful. I have erased the first block if I wanted to ensure I wasn't leaving any traces of ...


14

I wrote one-liner based on Tobi Hahn answer. For example, you want to know what device stands for ata3: ata=3; ls -l /sys/block/sd* | grep $(grep $ata /sys/class/scsi_host/host*/unique_id | awk -F'/' '{print $5}') It will produce something like this lrwxrwxrwx 1 root root 0 Jan 15 15:30 /sys/block/sde -> ../devices/pci0000:00/0000:00:1f.5/host2/...


14

umount is perfectly safe for the disk. Once you've done that you have successfully unmounted the filesystem and you needn't worry along those lines. The primary difference between eject and umount doesn't concern the disk at all - rather it is about the USB port's 5v power output. After umount you can still see your disk listed in lsblk because it is still ...


14

You can use lshw: sudo lshw -c disk But for newer kernels, i would suggest the portable and stable way of reading from sysfs: /sys/block/sd*/device/*


14

There is an extremely simple way to prove that it cannot be true that file edits are always directly saved to disk, namely the fact that there are filesystems that aren't backed by a disk in the first place. If a filesystem doesn't have a disk in the first place, then it cannot possibly write the changes to disk, ever. Some examples are: tmpfs, a file ...


13

ls (shows individual partitions though) # ls /dev/sd* /dev/sda /dev/sda1 ls (just disks, ignore partitions) # ls /dev/sd*[a-z] /dev/sda fdisk # fdisk -l 2>/dev/null |awk '/^Disk \//{print substr($2,0,length($2)-1)}' /dev/xvda


13

cat stops if it encounters a read or write error. If you’re concerned there might be unreadable sectors on your source drive, you should look at tools such as ddrescue.


12

Try to use this command: e2label /dev/sda2


12

As a general rule, physical access to the machine is all that's ever needed to compromise it. You are, after all, trusting that what the machine tells you is true; a person with physical access can void that trust. Consider that an attacker with physical access can theoretically do anything (including installation of hardware/firmware rootkits, etc). If the ...


12

Finalized bash sample There is a little part of a script I wrote to create and install live usb key, (dual boot ubuntu - debian): The very first part USBKEYS=... is the answer to this question In short, this: list removable devices, driven by sd and having non zero size. Note This script use dialog which seem not installed by default on Ubuntu. But ...


12

That's what's supposed to happen. There are two colloquial uses of the term "disk" or "drive" in play here: the first one refers to a physical device such as a usb stick. The second refers to a filesystem partition, of which there may be several on one physical device. Device nodes like /dev/sda refer to the first sense (physical devices); device nodes ...


12

jbd2 is a kernel thread that updates the filesystem journal. Tracing filesystem or disk activity with the process that caused it is difficult because the activities of many processes are combined together. For example, if two processes are reading from the same file at the same time, which process would the read be accounted against? If two processes write ...


Only top voted, non community-wiki answers of a minimum length are eligible