how do you mount and format /dev/sda to a different /dev/ name?

10,413

Solution 1

Careful! The advice given so far ignores the fact that it appears you have a disk partitioned using lvm. Formatting this may loose data!

Try the commands lvdisplay, pvdisplay, vgdisplay.

You can create an lvm volume without partitioning the drive. It may already be configured and mounted at that location.

Checked the /etc/fstab file and it has the line: /dev/vbackup/lvbackup /backups xfs defaults 1 2

I’m guessing this means the /backups folder is mounted to this device /dev/vbackup /lvbackup

No, the drive /dev/sda is added as a physical volume in the volume group "vbackup". The logical volume "lvbackup" has been created in this volume group. The logical volume ("/dev/vbackup/lvbackup") is mounted on the folder /backups.

If it's not formatted (which I suspect it already is), you would format the logical volume mkfs.xfs /dev/vbackup/lvbackup, then mount it.

I repeat - Do not partition the drive with fdisk. Do not format the drive with mkfs. I strongly suspect it's already formatted and mounted. It's running lvm on the raw drive, and so isn't partitioned either.

Read up on lvm.

If it's already configured, but just didn't come up with the raid controller, try this:

vgchange -a y

mount /backups

Alternatively... Due warnings aside, let's assume you have a new (replacement?) drive and you want it to mount in place of the old drive. Here's the commands you'd use to replicate the prior config (as best I can tell from fstab.)

pvcreate /dev/sda

vgcreate vbackup /dev/sda

lvcreate -L 900G -n lvbackup vbackup

vgchange -a y

mkfs.xfs /dev/vbackup/lvbackup

mount /dev/vbackup/lvbackup /backups

Good luck!

Solution 2

Simpler way to use parted. Assuming the drive to partition is /dev/sda: To create partition start GNU parted as follows:

parted /dev/sda
Creates a new gpt disklabel
mklabel gpt
Create 4GB partition size:
mkpart primary 0 4G
Quit and save the changes:
quit
Use mkfs to format file system:
sudo mkfs.xfs /dev/sda1
Mount it :
sudo mkdir /backup && sudo mount -t xfs /dev/sda1 /backup

Solution 3

When we boot the computer and login, I run “fdisk –l” and it lists all the hda partitions.

OK

No /dev/sda.

If I run “modprobe 3w-9xxx” and then run “fdisk –l” again, it shows all the hda1 through hda7 partitions with a single /dev/sda

Hm, when you loaded the appropriate kernel module the device /dev/sda showed up, so far so good. If you don't see /dev/sda1, etc. it means your drive is not partitioned yet.

Obviously the /dev/sda isn’t mounted to a folder, nor is it formatted.

Maybe, but there is no way to learn that from fdisk -l. What does mount say?

I checked the /etc/fstab file and it has the line: /dev/vbackup/lvbackup /backups xfs defaults 1 2

/dev/vbackup/lvbackup is another story, but let's see.

I’m guessing this means the /backups folder is mounted to this device /dev/vbackup /lvbackup

I'd say the device /dev/vbackup/lvbackup will be mounted to the directory /backups either at boot or if you do mount -a. I doesn't say that it is currently mounted. Use either /etc/mtab or mount to find that out.

I know you need to format the drive using “mkfs.xfs –f /dev/sda”

You usually want to format a partition like /dev/sda1 and not /dev/sda.

but I forget what to do beyond that as far as getting the drive properly mounted to a different device name? Any ideas?

Actually you can't mount a drive to a device name. The device name is created by the system for you, either at start up or when the driver is loaded. You can influence this but it has nothing to do with mounting.

Solution 4

You need to use fdisk to partition it, the different numbers (ie /dev/sda1) are for different partitions. Here is a link to a partitioning tutorial using fdisk.

Then once you have the partitions, you can use the mkfs programs to create the filesystem on that partition. Once you have done that, you can mount it.

Share:
10,413

Related videos on Youtube

phill
Author by

phill

Programming server admin stuff with vbscript, powershell, php, and c#.

Updated on September 17, 2022

Comments

  • phill
    phill almost 2 years

    We have linux box running fedora. It has a small laptop hard drive running the OS and a 3ware RAID controller running 3 SATA drives RAID 5.

    When we boot the computer and login, I run “fdisk –l” and it lists all the hda partitions. No /dev/sda. If I run “modprobe 3w-9xxx” and then run “fdisk –l” again, it shows all the hda1 through hda7 partitions with a single /dev/sda Obviously the /dev/sda isn’t mounted to a folder, nor is it formatted.

    I checked the /etc/fstab file and it has the line: /dev/vbackup/lvbackup /backups xfs defaults 1 2

    I’m guessing this means the /backups folder is mounted to this device /dev/vbackup /lvbackup

    I know you need to format the drive using “mkfs.xfs –f /dev/sda” but I forget what to do is get /dev/sda to be /dev/vbackup/lvbackup to be mounted to /backups

    Thanks in advance

    here is the output for the /var/log/messages file

    Aug 7 kernel: 3ware 9000 Storage Controller device driver for Linux v2.26.05.003-2.6.21. 
    Aug 7 kernel: ACPI: PCI Interrupt 0000:04:0c.0[A] -> GSI 16 (level, low) -> IRQ 18 
    Aug 7 kernel: 3w-9xxx: scsi1: Found a 3ware 9000 Storage Controller at -xfc5ffc00, IRQ: 18 
    Aug 7 kernel: 3w-9xxx: scsi1: Firmware FE9X 2.08.00.006, BIOS BE9X 2.03.01.052, Ports: 8. 
    Aug 7 kernel: scsi 1:0:0:0: Direct-Access AMCC 9500S-8 DISK 2.08 PQ: 0 ANSI: 3 
    Aug 7 kernel: sd 1:0:0:0: [sda] 1953083392 512-byte hardwaresectors (999979 MB) 
    Aug 7 kernel: sd 1:0:0:0: [sda] Write Protect is off 
    Aug 7 kernel: sd 1:0:0:0: [sda] Write cache: enabled, read cache disabled, doesn't support DPO or FUA 
    Aug 7 kernel: sd 1:0:0:0: [sda] 1953083392 512-byte hardware sectors (999979 MB) 
    Aug 7 kernel: sd 1:0:0:0: [sda] Write Protect is off 
    Aug 7 kernel: sd 1:0:0:0: [sda] Write cache: enabled, read cache disabled, doesn't support DPO or FUA 
    Aug 7 kernel: sd 1:0:0:0: [sda] Write cache: enabled, read cache: disabled, doesn't support DPO or FUA 
    Aug 7 kernel: sd 1:0:0:0: sda : unknown partition table 
    Aug 7 kernel: sd 1:0:0:0: sd 1:0:0:0: [sda] Attached SCSI disk 
    Aug 7 kernel: sd 1:0:0:0: sd 1:0:0:0: Attached scsi generic sg0 type 0 
    Aug 7 scsi.agent[3511]: disk at /devices/pci0000:00/0000:00:1e.0/0000:03:02.0/0000:04:0c.0/host1/target1:0:0/1:0:0:0 
    Aug 7 kernel: XFS mounting filesystem sda 
    

    Blockquote

    • Ludwig Weinzierl
      Ludwig Weinzierl almost 15 years
      See the answer of jmanning2k, it doesn't deserve to buried.
  • phill
    phill almost 15 years
    i ran fdisk /dev/sda and it now mounts to /backups.. once I run fdisk, won't I need to run mkfs.xfs ? I thought its supposed to say /dev/sda1 after running fdisk?
  • phill
    phill almost 15 years
    yea i'm using the w and it says its syncing disks and won't be effective until a reboot or something
  • phill
    phill almost 15 years
    now that i rebooted, ran modprobe 3w-9xxx, and then 'fdisk -l', it says Disk /dev/sda doesn't contain a valid partition table
  • Kyle Brandt
    Kyle Brandt almost 15 years
    what distro? I might start by adding the module so it is loaded at boot...
  • Kyle Brandt
    Kyle Brandt almost 15 years
    Also, any additional error messages from the demsg command or in /var/log/messages ?
  • phill
    phill almost 15 years
    i guess i was arbitrary about what i'm trying to accomplish. the /dev/sda is supposed to be /dev/vbackup/lvbackup which is mounted to the backups folder. i guess my question is what do i need to do to make the /dev/sda into /dev/vbackup/lvbackup so the fstab can mount this device to /backups ? thanks in advance
  • phill
    phill almost 15 years
    fedora.. when i run demsg it says "bash: demsg: command not found" .. i'll put what was in the /var/log/messages file above
  • Ludwig Weinzierl
    Ludwig Weinzierl almost 15 years
    @phill: Ah OK, /dev/vbackup/lvbackup is a device that belongs to the logical volume manager (LVM). I haven't worked with LVM and I don't know how to configure it, sorry.
  • Ludwig Weinzierl
    Ludwig Weinzierl almost 15 years
    @phill: In my opinion you'll need to format the logical unit: sudo mkfs.xfs /dev/vbackup/lvbackup instead of sudo mkfs.xfs /dev/sda. But as I said, I never used LVM, so be careful.
  • Pooja
    Pooja almost 15 years
    Should be 'dmesg', but the above output is useful.
  • Ludwig Weinzierl
    Ludwig Weinzierl almost 15 years
    +1 Now we get closer to a helpful answer.
  • phill
    phill almost 15 years
    thats ok.. i don't need the data.. i just deleted and recreated the RAID Arrary and followed the commands assuming the drive is a new replacement. I got as far as the "lvcreate -L -n lvbackup vbackup" however it throws an error saying "invalid argument -n, error parsing of command line"
  • phill
    phill almost 15 years
    figured it out.. "lvcreate -L 900GB -n lvbackup vbackup .. That solutions helps.. just gotta figure out how to test this..
  • Pooja
    Pooja almost 15 years
    sorry I had <size>, but sf ate it as html