I installed a second disk for my system. It´s and old but usable ext3 formatted disk which includes Ubuntu. I want to reformat this drive but before doing so (via command line) I want to be sure that is indeed the new extra drive. I followed this guide but I don´t want to alter the "new" drive partition until I´m sure is the correct one. What command can I use to determine which disk the system booted? (The system now holds three drives: two IDE (master is the boot, slave is the "new" and also a SATA disk)
2 Answers
sudo fdisk -l | grep 'Disk /'
The above command will list your connected disks with details about them and their sizes. You can determine the name of the disk you want to reformat from there, if you know its size. If you want to see a less detailed version of the output, do sudo fdisk -l | grep 'Disk /' instead.
But to answer your question, if you want to determine which disk the system booted on, you can do this:
mount | grep -E '(/|/boot) ' | awk '{print $1,$2,$3}'
This lists all mounted partitions (mount), looks for the boot and/or root partitions (grep -E '(/|/boot) '), then filters the output to only show the disk and partition number and the mount point it is mounted on (awk '{print $1,$2,$3}'). The output will be something like /dev/sda2 on /boot. That means /dev/sda is the disk that the system booted from.
- 32,273
This might not be the most accurate way to do this but a really quick easy way is to grep for the mount point that ends with / (a slash) from the output of df -h.
So that would be: df -h | grep '/$'
Alternatively, If you wanted just the device name you could:
df -h | grep '/$' | sed 's/\(^\/dev\/\w*\).*/\1/'
/bootpartition, that would be considered the disk the system booted from, right? – Alaa Ali Oct 27 '14 at 20:13