Commands tagged partition (26)

  • Yields entries in the form of "/dev/hda1" etc. Use this if you are on a new system and don't know how the storage hardware (ide, sata, scsi, usb - with ever changing descriptors) is connected and which partitions are available. Far better than using "fdisk -l" on guessed device descriptors. Show Sample Output


    13
    hwinfo --block --short
    Schneckentreiber · 2009-04-24 11:13:31 10
  • Shows the UUID of the given partition (here /dev/sda7). Doesn't need to be root. Show Sample Output


    9
    blkid /dev/sda7
    lineak · 2010-09-05 12:20:45 6
  • Suppose you made a backup of your hard disk with dd: dd if=/dev/sda of=/mnt/disk/backup.img This command enables you to mount a partition from inside this image, so you can access your files directly. Substitute PARTITION=1 with the number of the partition you want to mount (returned from sfdisk -d yourfile.img). Show Sample Output


    8
    INFILE=/path/to/your/backup.img; MOUNTPT=/mnt/foo; PARTITION=1; mount "$INFILE" "$MOUNTPT" -o loop,offset=$[ `/sbin/sfdisk -d "$INFILE" | grep "start=" | head -n $PARTITION | tail -n1 | sed 's/.*start=[ ]*//' | sed 's/,.*//'` * 512 ]
    Alanceil · 2009-03-06 21:29:13 11

  • 8
    lsblk -o name,size
    justsomeguy · 2022-03-04 04:29:47 372
  • See size of partitions as human readable and get extra informations about hdd and partitions Show Sample Output


    5
    parted /dev/sda print
    mesuutt · 2012-06-05 09:11:06 3
  • Instead of calculating the offset and providing an offset option to mount, let lomount do the job for you by just providing the partition number you would like to loop mount.


    4
    lomount -diskimage /path/to/your/backup.img -partition 1 /mnt/foo
    olorin · 2009-07-22 11:32:52 16

  • 4
    losetup /dev/loop0 harddrive.img; kpartx -a -v /dev/loop0; mount /dev/mapper/loop0p1 /mountpoint/
    oernii3 · 2010-10-30 11:52:11 7
  • Shows all block devices in a tree with descruptions of what they are.


    4
    lsblk -o NAME,TYPE,FSTYPE,LABEL,SIZE,MODEL,MOUNTPOINT
    BasketCase · 2012-09-12 15:30:25 4
  • It is the same but more faster real 0m0,007s user 0m0,011s sys 0m0,000s with my solution real 0m0,038s user 0m0,044s sys 0m0,000s with your solution :) Show Sample Output


    3
    lsblk | grep -v part | awk '{print $1 "\t" $4}'
    gecco · 2022-01-11 13:31:04 230

  • 2
    sfdisk -d /dev/sda | sed 's/sda/sdb/g' | sfdisk /dev/sdb
    kobayashison · 2009-12-22 23:35:30 4
  • Reports all local partitions having more than 90% usage. Just add it in a crontab and you'll get a mail when a disk is full. (sending mail to the root user must work for that) Show Sample Output


    2
    df -l | grep -e "9.%" -e "100%"
    dooblem · 2010-04-26 17:57:54 3
  • The above command assumes the lost data is on /dev/sda and you previously issued the following command to mount _another_ disk or partition (/dev/sdb1) on /recovery sudo mount /dev/sdb1 /recovery If you don't do this, the data could be overwrited! foremost is a very powerful carving tool. By default foremost recovers all known file types. If you want to reduce the amount of files that are recovered you can specify the file type you are looking for. Read the man page to know the available file types. i.e to recover JPEG pictures append to foremost the switch -tjpg


    2
    sudo foremost -i /dev/sda -o /recovery
    vlan7 · 2010-08-19 22:27:41 6
  • Necessary for fsck for example. The remount functionality follows the standard way how the mount command works with options from fstab. It means the mount command doesn't read fstab (or mtab) only when a device and dir are fully specified. After this call all old mount options are replaced and arbitrary stuff from fstab is ignored, except the loop= option which is internally generated and maintained by the mount command. It does not change device or mount point.


    2
    mount -o remount,ro /dev/foo /
    vlan7 · 2010-10-30 03:51:53 6
  • `blkid` is an interface to libuuid - it can read Device Mapper, EVMS, LVM, MD, and regular block devices. -c /dev/null - Do not use cached output from /etc/blkid.tab or /etc/blkid/blkid.tab (RHEL) -i - Display I/O Limits (aka I/O topology) information (not available in RHEL) -p - Low-level superblock probing mode (not available in RHEL) Show Sample Output


    2
    blkid -c /dev/null
    mhs · 2012-09-12 13:34:41 7
  • lsblk | grep mountpoint Show Sample Output


    2
    lsblk | grep <mountpoint>
    totti · 2014-02-05 09:41:00 8
  • Use lsbk (list block) and jq (to manipulate a JSON on the command line) to display partition information: Show Sample Output


    2
    lsblk --json | jq -c '.blockdevices[]|[.name,.size]'
    mikhail · 2021-12-22 22:31:07 275

  • 1
    sfdisk -d /dev/sda | sfdisk /dev/sdb
    wincus · 2010-02-03 14:49:07 4
  • To get most of you HDD/SSD driver you need to make sure you partition are aligned, if not the speed penalty can be up to 50% slower! this simple one liner will check to see if each partition start sector is divided by 512 you need to change sda with your driver if you find the one of your partitions is not aligned use gparted to move the start sector of the partition to be divided of 512 Show Sample Output


    1
    fdisk -l /dev/sda | grep -E sda[0-9]+ | sed s/*// | awk '{printf ("%s %f ",$1,$2/512); if($2%512){ print "BAD" }else {print "Good"} }' | column -t
    The_IceMan_Blog · 2012-05-18 08:34:36 5
  • Show the UUID-based alternate device names of ZEVO-related partitions on Darwin/OS X. Adapted from the lines by dbrady at http://zevo.getgreenbytes.com/forum/viewtopic.php?p=700#p700 and following the disk device naming scheme at http://zevo.getgreenbytes.com/wiki/pmwiki.php?n=Site.DiskDeviceNames Show Sample Output


    1
    ls /dev/disk* | xargs -n 1 -t sudo zdb -l | grep GPTE_
    grahamperrin · 2012-10-06 20:19:45 5

  • 1
    mount -o sb=98304 /dev/sda5 /mnt/data5
    rugina · 2013-06-25 08:50:44 10
  • XX is your device partition number like /dev/sdc1 . to see how many inodes your partition have type: df --inodes (or df -i) Default formatting with ext4 would create small inode count for the new partition if you need big count of inodes is the fstype news the correct one. in debian you can see which fstype exists as template in: vim /etc/mke2fs.conf if you format default ext for a partition size with 1TB you would get 1 Million inodes (not enough for backupStorages) but if you format with fstype news you would get hunderd of millions of inodes for the partition. you have tune /etc/sysctl.conf also with following sysconfig parameters fs.file-max = XXX fs.nr_open = XXX where XXX is the count of max inodes for whole system


    1
    mkfs.ext4 -T news /dev/sdcXX
    aysadk · 2019-07-02 13:31:23 37
  • Creates a single primary partition starting at sector 0 and extending to the end of the disk. Use with care.


    0
    echo "0,,L" | sfdisk /dev/sdX
    twobitsprite · 2012-04-09 18:36:24 5
  • Another alternative to blkid, lsblk, file -s, cat /proc/paritions, fdisk -l, etc.. Show Sample Output


    0
    fsarchvier probe simple
    0xFF · 2013-04-28 10:16:18 6

  • 0
    sudo dumpe2fs /dev/sda1 | grep superblock
    rugina · 2013-06-25 08:48:49 182

  • -1
    diskutil list
    grahamperrin · 2012-10-06 21:18:27 6
  •  1 2 > 

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands


Check These Out

Find usb device in realtime
Using this command you can track a moment when usb device was attached.

Convert a string to

Play ISO/DVD-files and activate dvd-menu and mouse menu clicks.

check open ports without netstat or lsof

Which processes are listening on a specific port (e.g. port 80)
swap out "80" for your port of interest. Can use port number or named ports e.g. "http"

Show the UUID of a filesystem or partition
Shows the UUID of the given partition (here /dev/sda7). Doesn't need to be root.

Convert CSV to JSON
Replace 'csv_file.csv' with your filename.

memcache affinity: queries local memcached for stats, calculates hit/get ratio and prints it out.
queries local memcached for stats, calculates hit/get ratio and prints it out.

get you public ip address

remote-pbzip2 and transfer a directory to local file


Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: