1

If I attach a hard drive to the system, and I want the system to recognize this device as a /dev/sde device rather than the default /dev/sdb. How should I do that?

Thanks.

return 0
  • 195
  • 1
  • 2
  • 10
  • Any hard drive, or just a specific one? – MariusMatutiae Dec 11 '13 at 19:13
  • @MariusMatutiae Not the main one that contains OS. Just the other hard drives. – return 0 Dec 11 '13 at 19:17
  • 1
    note that sda,sdb, ...sde are not types of devices, just differant instances of the same type of device. Additionally I would recommend that you try to avoid ever refering to a disk device by `/dev/sd*` because they can change and you cannot manually map them. instead refer to the UUID for the volumes on it. – Frank Thomas Dec 11 '13 at 19:18
  • @FrankThomas: Now my system gives me random block assignment (e.g. /dev/sdb), but I specifically want the assignment to be e.g. /dev/sde. How do I do that? – return 0 Dec 11 '13 at 19:20
  • It is my understanding that you cannot. I may be wrong, but I've looked for that answer for years, and if it exists, its not exactly in plain sight. you can always hack and compile your own version of the kernel that does, but beyond the compilation, it's well out of my depth. – Frank Thomas Dec 11 '13 at 19:26
  • 1
    I think we may be of more help if you give a "why", since there is not a common reason people would need to do that. Normally, you would use `UUID` (as @FrankThomas suggested) and specify where to mount it (since you don't access a drive by the `dev` path outside of mounting and/or `dd`ing). What's your end goal, why do you want it to be `sde`? Perhaps if the goal isn't just because, we could help find a workable solution to accomplish the task. – nerdwaller Dec 11 '13 at 19:27
  • Not a good idea: consider what might happen if you plugged in **two** hard drives. – MariusMatutiae Dec 11 '13 at 19:48

2 Answers2

3

Actually, there is a way to do this: it involves udev, and it is the simplest possible use of its rules.

Create a file /etc/udev/rules.d/10-local.rules and insert into it this single line:

  KERNEL=="sd?1", NAME="my_hdd1"

This rule simply takes anything which would be called sda1, or sdb1, or sdc1,... and renames it to a name of your choice, in this case `my_hdd1'. The device node will appear at

  /dev/my_hdd1

If you wish you can do this with devices, not with partitions, whichever you like best:

  KERNEL=="sd?", NAME="my_hdd"

The above rules will be applied to the first disk to be discovered, which is normally the root disk, /dev/sda. If you prefer to continue calling this disk /dev/sda, but you wish to apply this rule to all other disks, then these rules become:

   KERNEL=="sd[b-z]", NAME="my_hdd"
   KERNEL=="sd[b-z]1", NAME="my_hdd1"

again as per your wishes.

Restart udev, or reboot, and that's it.

MariusMatutiae
  • 46,990
  • 12
  • 80
  • 129
  • I have critical things in my harddrives now, so I won't be able to test this. Hopefully someone can test this and comment about how it goes :) – return 0 Dec 12 '13 at 19:58
0

Unfortunately, the order of the drive under the /dev/sdX naming scheme are created based on the bus (bus-based naming). That is why "persistent naming methods" are very helpful, as they uniquely identify any given device on any number of occasions.

There are four schemes for persistent naming:

  1. Label
  2. UUID
  3. ID/Path

Here is a good source about Persistent block device naming

As I said in my comment, if you provide a why, you may get better answers that actually deal with your root issue instead of simply wanting things to be mounted in different places, there's few times you need to actually use the /dev/sdX identifier.

nerdwaller
  • 17,054
  • 2
  • 44
  • 44