Configuring an external USB drive with LVM

Published: Thursday, Feb 28, 2008 Last modified: Monday, Apr 8, 2024

Seagate Freeagent Desktop 500GB External Hard drive 7200RPM 8MB USB2.0

For 69GBP from Amazon.co.uk. So that’s about 15 pence for Gigabyte. Quite good value!

Plug it in:

scsi 3:0:0:0: Direct-Access     Seagate  FreeAgentDesktop 100F PQ: 0 ANSI: 4

sd 3:0:0:0: [sdb] 976773168 512-byte hardware sectors (500108 MB)

sd 3:0:0:0: [sdb] Write Protect is off

sd 3:0:0:0: [sdb] Mode Sense: 1c 00 00 00

sd 3:0:0:0: [sdb] Assuming drive cache: write through

sd 3:0:0:0: [sdb] 976773168 512-byte hardware sectors (500108 MB)

sd 3:0:0:0: [sdb] Write Protect is off

sd 3:0:0:0: [sdb] Mode Sense: 1c 00 00 00

sd 3:0:0:0: [sdb] Assuming drive cache: write through

 sdb: sdb1

sd 3:0:0:0: [sdb] Attached SCSI disk

In my case it’s sdb. You need to be super careful and USE THE RIGHT DISK!

Prime the disk:

x61:~% sudo pvcreate /dev/sdb

  Device /dev/sdb not found (or ignored by filtering).

x61:~% sudo pvcreate /dev/sdb1

  Physical volume "/dev/sdb1" successfully created

Should show up now:

x61:~% sudo pvscan

  PV /dev/sda5   VG x61   lvm2 [111.55 GB / 4.00 MB free]

  PV /dev/sdb1            lvm2 [465.76 GB]

  Total: 2 [577.31 GB] / in use: 1 [111.55 GB] / in no VG: 1 [465.76 GB]

Now we need a Volume Group:

x61:~% sudo vgcreate seagate /dev/sdb1

  Volume group "seagate" successfully created

x61:~% sudo vgscan

  Reading all physical volumes.  This may take a while...

  Found volume group "seagate" using metadata type lvm2

  Found volume group "x61" using metadata type lvm2

Ok, lets create the Logical Volume:

x61:~% sudo lvcreate -l 100%FREE -next3 seagate

  Logical volume "ext3" created

x61:~% sudo lvscan

  ACTIVE            '/dev/seagate/ext3' [465.76 GB] inherit

  ACTIVE            '/dev/x61/root' [16.68 GB] inherit

  ACTIVE            '/dev/x61/swap_1' [2.59 GB] inherit

  ACTIVE            '/dev/x61/home' [80.00 GB] inherit

  ACTIVE            '/dev/x61/crypt' [12.27 GB] inherit

Ok, now lets create an ext3 partition on there:

x61:~% sudo mkfs.ext3 /dev/seagate/ext3

mke2fs 1.40.6 (09-Feb-2008)

Warning: 256-byte inodes not usable on older systems

Filesystem label=

OS type: Linux

Block size=4096 (log=2)

Fragment size=4096 (log=2)

30531584 inodes, 122095616 blocks

6104780 blocks (5.00%) reserved for the super user

First data block=0

Maximum filesystem blocks=0

3727 block groups

32768 blocks per group, 32768 fragments per group

8192 inodes per group

Superblock backups stored on blocks:

		32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,

		4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968,

		102400000


Writing inode tables: done

Creating journal (32768 blocks): done

Writing superblocks and filesystem accounting information: done


This filesystem will be automatically checked every 25 mounts or

180 days, whichever comes first.  Use tune2fs -c or -i to override.

Ok, lets test it out:

x61:~% sudo mkdir /mnt/sg

x61:~% sudo mount /dev/seagate/ext3 /mnt/sg

x61:~% df -h | grep sg

					  459G  199M  435G   1% /mnt/sg

x61:~% ll /mnt/sg

total 24K

drwxr-xr-x 3 root root 4.0K 2008-02-28 16:41 ./

drwxr-xr-x 8 root root 4.0K 2008-02-28 16:50 ../

drwx------ 2 root root  16K 2008-02-28 16:41 lost+found/

SO 500G becomes about 435G….

So putting into my slug, I found I needed to make it ACTIVE by:

slug:~% sudo lvscan

  inactive          '/dev/seagate/ext3' [465.76 GB] inherit

slug:~% sudo lvchange -a y /dev/seagate/ext3

slug:~% sudo lvscan

  ACTIVE            '/dev/seagate/ext3' [465.76 GB] inherit

Ok lets share this guy:

slug:~% egrep seagate /etc/exports

/media/seagate 192.168.1.*(insecure,rw,async,no_root_squash,no_subtree_check,nohide)

slug:~% egrep seagate /etc/fstab

/dev/seagate/ext3 /media/seagate auto   rw,user,auto  0       0

Problems, bugs, I wish this didn’t happen:

sd 1:0:0:0: Device not ready: <6>: Current: sense key=0x2

	ASC=0x4 ASCQ=0x2

end_request: I/O error, dev sdb, sector 12807

Buffer I/O error on device dm-0, logical block 1545

lost page write due to I/O error on dm-0

sd 1:0:0:0: Device not ready: <6>: Current: sense key=0x2

	ASC=0x4 ASCQ=0x2

end_request: I/O error, dev sdb, sector 12807

Buffer I/O error on device dm-0, logical block 1545

lost page write due to I/O error on dm-0

sd 1:0:0:0: Device not ready: <6>: Current: sense key=0x2

I have noticed when initially mounting and using the device, you can see these scary messages. The OS can decide to remount the device as readonly and then you’ll know things are going wrong. To rectifiy the situation I simply unmount and mount the disk again and watch the logs with tail -f /var/log/messages.

Ok, I found the fix for external Seagate USB hard drives!