How to replace faulty sdb drive

my SDB drive is failing and I have a replacement drive. ( I’ll admit the I’m a novice (or worst) when it comes to Ubuntu)

how do i move all of the SDB drive structure to the new drive.
Note: SDB was setup as a raid drive but I needed the second drive somewhere else and stopped the raid but there maybe some raid parameters left,
also the main use of SDB is to contain a samba share, and a MySql database. all important data is backed up.

  1. I’ll try to look up how install a new drive in the server but in the past when I post drive issues, I would get replies like “why did you us LVM” or " we should have used LVM" I’ve have several drive issues

  2. do I just mount the new drive as SDC and use a Copy or something like it, if so how do i rename the sdc to sdb, when done?
    or
    do this in reverse rename sdb to sdc add new drive as sdb and copy C to B

  3. I dont think i can clone the drive , i believe that cloneing will as mark the bad sectors on sdc with those marked on sdb , or am i wrong.

TIA
TR

2:

The disk won’t be mounted at /sdb, thats just what the device driver calls it. If you look in /etc/fstab you’ll see its mountpoint. Note it may not even be in there under /dev/sdb because the new style is to refer to drives by more useful identifiers.

If you add another disk and format it with gnome-disks, you can also select a mount point for it. IIRC gnome-disks uses UUID’s to identify disks, so it doesn’t matter if they are /dev/sdc, /dev/hda or anything else

Then as root you can use cp -a $source $destination to copy everything from one mount point to another.

Finally you can edit the fstab to mount the new disk in the location the old was mounted, comment out the old mount line and remove the disk, place it in the cupboard under the sink at your dads house and tell your wife that you’ve done a off site system backup

One more word of caution:

“contain a samba share, and a MySql database”.

If Mysql is busy accessing the drive when you do your copy then you might end up with inconsistent files. Shut down any services that might be accessing the drive

When you set up the raid.

  1. did you use Mdadm? ZFS? or other type. in other words what command did you use to assemble the RAID.
  2. What raid level did you use 1 2 5 6 or mirror.

Without know how or what type/ level Raid is used. No one can give you clear concise answers.
In order to help you we collectively need more information.
But usually if mdadm was used it’s REALLY simple method to fix or ZFS, or even LVM but the commands to replace the drives are completely different.
But in order to assist you we need that information I apologize in advance if this comes across as crass or rude. But your posting is vague.
If your unsure even if you could post a hyperlink to what guide you used to create / assemble the drives would assist in your assistance. If nothing else type into your system lsblk and paste it in here that will help in effectively assisting you.
Besides we all have started where you are right now. So I’m simply actually trying to help you.

Example I use ZFS if I have a failing drive I can hook up the drive and issue sudo zpool replace /dev/by-uuid “dying drive” /dev/by-uuid “new drive” Then ZFS will start to replace the drive automatically … Mdadm the commands are simalr but not the same…
no cloning needed … No renaming of drives … nothing… just wait for the system to rebuild

(oh and if you disconnected the drive sdb in a linux system and plug in the new drive into the same connection 99% of the time linux reports it as sdb automactically )

wiil, thanks for this information, this will help me install the new drive with less issues.

Again thanks TR

I’m assuming your system is a actual server without a GUI so the command line is all that you have
After posting earlier I went to fix supper for my wife. At which point it dawned on me that you posted on Ubuntu Forums before the shift over here.

  1. welcome here.
  2. If I recall correctly you had a working system on the linux box. and then a need arose and you pulled a drive from your array and transferred that drive to the other machine. Thus putting your array for a extended time in a degraded status. (so I’m thinking you basically had a mirror, which means both drives contained the data, but with you pulling one drive means all the data is now on just one drive
    Lesson learned … Luckily all is actually not lost.

First put the new drive in … then type lsblk if I recall the details you shared it should show up as sdc.
As of right now the new drive is not mounted , partitioned or even formatted which means you can’t read write or access it. in order to do so… have no fear it is actually easy
partition the drive…
sudo fdisk /dev/sdc
once the command prompt returns
type “n” <<for new partition
then “p” or just press enter for primary
then it will ask for partition number just use 1 partition which is the default so you can type 1 or just press enter.
then you will see that fdisk is asking for type the default is linux just press enter at this point.
Once that is done look /check to ensure the partition is the way you desire. press p that will display the drive geometry if all looks well
then you can press w to write the changes that will cause fdisk to write the changes to the new drive, or you can press q to quit which will not write or change the drive allowing you to start all over again. but to save the changes you must write to the drive with the w command at the prompt.
once it completes the write press q to exit fdisk. this will leave you with a drive with 1 partition. type lsblk again now it will show sdc the direct below that sdc1 (the 1 is the partition)
now to format the partition

sudo mkfs.ext4 /dev/sdc1

this will be in a ext4 format readable by linux, not windows. (what I mean here is if you plugged the drive directly to your windows machine, not over a samba share it will be readable from a samba share)
if you desire to format in another format
typing sudo mkfs will display all available types of formatting that can be done.
just replace ext4 with your choice but I would stay with ext4 .
at this point we hace partitioned and formatted the drive the only thing left to do is mount it so we can copy your data… This part is easy
we have to have a mount point to mount /dev/sdc1 to
if you type sudo cd / this will put you in the root directory
type ls when in the root directory you should see a directory /mnt for ease of you and me let’s go there and make adirectory under there.
so

sudo cd /mnt

make a directory under /mnt

sudo mkdir save

now this makes a new mount point to mount sdc1 to, now we can mount it with

sudo mount /dev/sdc1 /mnt/save

outside the long and hopefully not so long copy process we are almost there.
Let’s go back to the home directory type

cd ~

~ is used for home in lieu of typing home / will get you to the root directory.
now because all drives must be mounted you have to know the mount point for the drive that was used with your “raid” or mirror sdb… aka where the data is in the directory as we are writing from one mount point (directory) to another mount point (directory)
Where that is will change the command below

sudo cp -r --verbose /where/thedata/is  /mnt/save

/where/thedata/is = the actual directory of the data you want to save /mnt/save is the directory or mount point of the sdc1 drive…
sudo = superuser aka root
cp = copy
-r =means recursive so it will copy the directory structure exactly with all files
–verbose = simply causes it display progress as it writes … without it the screen stays blank until the write is completed.
Once completed you can unmount the drive and disconnect it preserving your data. but if youy desire to do this don’t be in the directory that the drive is mounted in or it will complain it is busy. The command to unmount a drive is easy

sudo umount /dev/sdc1   (or the drive you wish to take off line)

here you can remove the drive if that is your desire
As if I recall your break out I would completely redo your system and layout. And choose a simpler layout. If you desire a raid I would look at the linux default mdadm or even zfs, LVM is not a bad choice either. But they all require attention and must be maintained. If your not wanting to do that I would just mount the drives I planned on using to a mount point. It will show up in the system as a drive directory without drive redundancy … a directory as one big drive so to speak… If you desire redundancy research the differing ones (types of RAID Solutions) and pick one. But backup your data because RAID (Redundant Array Independent Disk) is not a backup. Many take offense to that statement and really shouldn’t. Nothing replaces backups except more back ups. RAID allows you to replace a drive that is failing. nothing more nothing less it must be coupled with backups.
It is not meant as nothing but advice.

at this point YOU can unmount the lvm contained in /etc/fstab and replace it with the new drive. By editing the /etc/fstab.

P.S as advised from wiil — stop all services before doing this , hopefully all will work out. please ask questions somebody will be more than happy to help.
(also remember we all started out where you are so none of us look down on what you have done thus far it is a learning process. NO one knows it all)

sgt-mike

Thanks this info will help alot.

TR

@sgt-mike

your instructions were excellent, and I was able to install and copy the data to the new drive in less than 5 minute. ( would have been faster but I need new computer glasses and had to really look at the instruction more than a couple of times to be sure.)

Again Thanks.

TR

I’m so happy that it worked for you. :smiley:
Hopefully you get your system configured to suit you and your needs without much hassle.
if you have questions etc etc please post and ask many on here will be happy to help /assist you.