How to rename /dev/sdax(partitions) in Linux

18,504
  • Unmount the partition:

    # umount /part
    
  • Rename the directory after making sure it's not mounted:

    # mountpoint /part &>/dev/null || mv /part /best_name_ever
    
  • Edit /etc/fstab to replace /part with /best_name_ever

  • Remount the partition:

    mount /best_name_ever
    

The # is of course meant to represent your root prompt, not actual input to be typed in.

To test the safety of this solution or any other one on dummy data

The following instructions are (in part) stolen from Virtual Filesystem: Building A Linux Filesystem From An Ordinary File.

  • Create an ordinary file with a size of 20 MB (for example):

    $ dd if=/dev/zero of=dummy_fs bs=1k count=20480 # 20480 = 20 * 1024
    
  • Create an ext4 filesystem on your file:

    $ /sbin/mkfs -t ext4 dummy_fs       
    mke2fs 1.42.5 (29-Jul-2012)
    dummy_fs is not a block special device.
    Proceed anyway? (y,n) y
    ... # Output of mkfs
    
  • Mount the filesystem image, create some dummy data on it and test the solution:

    # mkdir /tmp/testmount
    # mount -o loop dummy_fs /tmp/testmount
    # touch /tmp/testmount/{blah,bleh} # Create dummy data
    # ls /tmp/testmount
    blah bleh lost+found
    # umount /tmp/testmount
    # mountpoint /tmp/testmount &>/dev/null || mv /tmp/testmount /tmp/sexy_name
    # mount -o loop dummy_fs /tmp/sexy_name
    # ls /tmp/sexy_name # to ensure your data is intact:
    blah bleh lost+found
    
Share:
18,504

Related videos on Youtube

MLSC
Author by

MLSC

Updated on September 18, 2022

Comments

  • MLSC
    MLSC over 1 year

    I made a partition like /part on my machine with some important data...

    But I can't stand the name of it...

    I want a clear solution to resolve it and change the name of it to for example /test...

    As you see this is my /etc/fstab information:

    # /etc/fstab: static file system information.
    #
    # Use 'blkid' to print the universally unique identifier for a
    # device; this may be used with UUID= as a more robust way to name devices
    # that works even if disks are added and removed. See fstab(5).
    #
    # <file system> <mount point>   <type>  <options>       <dump>  <pass>
    proc            /proc           proc    nodev,noexec,nosuid 0       0
    # / was on /dev/sda5 during installation
    UUID=a21a99c4-e5b4-4197-ac5e-80d0fab1f30c /               ext4    errors=remount-ro 0       1
    # /home was on /dev/sda6 during installation
    UUID=2e37d833-ca34-4fa7-a5d8-a4423a5af9bc /home           ext4    defaults          0       2
    # /part was on /dev/sda7 during installation
    UUID=47e6e0b1-0e57-4184-a378-375b9ce315c5 /part           ext4    defaults          0       2
    # swap was on /dev/sda1 during installation
    UUID=485e9f78-4dce-4404-af4e-f43985525264 none            swap    sw                0       0
    

    The point is: My information are important and I scare to manipulate it without being sure... I want a safe solution...

    How is it possible?

    • PersianGulf
      PersianGulf about 10 years
      to watching which dev is used, apply: ls /dev/disk/by-uuid/[the-given-uuid] -l
    • MLSC
      MLSC about 10 years
      @Mohsen Pahlevanzadeh thank you but I didn't understand the strange the-given-uuid part
    • PersianGulf
      PersianGulf about 10 years
      for example for /part , your should use : ls -l /dev/disk/by-uuid/47e6e0b1-0e57-4184-a378-375b9ce315c5
    • PersianGulf
      PersianGulf about 10 years
      You wrote scare, i introduce it because i think you have problem with uuid.
  • Jeff Hewitt
    Jeff Hewitt about 10 years
    @MortezaLSC I will write a more detailed explanation in a bit.
  • Jeff Hewitt
    Jeff Hewitt about 10 years
    @MortezaLSC Please see if this explanation helps.
  • Jeff Hewitt
    Jeff Hewitt about 10 years
    @MortezaLSC You're very welcome. I'm glad I could help :)