You are not logged in.

#1 2011-04-17 04:09:26

qq405165798
Member
Registered: 2010-11-03
Posts: 17

how to umount all partitions of a mobile disk.

My HDD is mounted by hal automatically.
Is there any way to umount all partitions of a HDD  like
`umount /dev/sdb` ?

I knew it can be umounted by
umount /dev/sdb1
umount /dev/sdb2
...

but it is too trouble while there are a lot of partitions.


$> fdisk -l

Disk /dev/sda: 40.0 GB, 40007761920 bytes
255 heads, 63 sectors/track, 4864 cylinders, total 78140160 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00188bff

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *          63    20482874    10241406    7  HPFS/NTFS/exFAT
/dev/sda2        20482999    73079684    26298343    f  W95 Ext'd (LBA)
/dev/sda3        74718315    78140159     1710922+   7  HPFS/NTFS/exFAT
/dev/sda4        73079685    74718314      819315   83  Linux
/dev/sda5        20483001    49881824    14699412   83  Linux
/dev/sda6        49881888    51311609      714861   82  Linux swap / Solaris
/dev/sda7        51311673    73079684    10884006    7  HPFS/NTFS/exFAT

Partition table entries are not in disk order

Disk /dev/sdb: 160.0 GB, 160041885696 bytes
255 heads, 63 sectors/track, 19457 cylinders, total 312581808 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0001a915

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1   *        2048    20510719    10254336   83  Linux
/dev/sdb2        20510779   312576704   146032963    f  W95 Ext'd (LBA)
/dev/sdb5        20510781    21494969      492094+  82  Linux swap / Solaris
/dev/sdb6        21495033    29800574     4152771    7  HPFS/NTFS/exFAT
/dev/sdb7        29800638   155846564    63022963+   7  HPFS/NTFS/exFAT
/dev/sdb8       155846628   312576704    78365038+   7  HPFS/NTFS/exFAT
$> sudo umount /dev/sdb
umount: /dev/sdb: not mounted

Last edited by qq405165798 (2011-04-17 04:13:34)

Offline

#2 2011-04-17 04:27:32

rockin turtle
Member
From: Montana, USA
Registered: 2009-10-22
Posts: 227

Re: how to umount all partitions of a mobile disk.

I believe that discs are mounted according to your /etc/fstab file.  If you don't want a partition to be mounted at boot, then remove/comment out the entry in that file.  For example

#
# /etc/fstab: static file system information
#
# <file system>        <dir>         <type>    <options>          <dump> <pass>
devpts                 /dev/pts      devpts    defaults            0      0
shm                    /dev/shm      tmpfs     nodev,nosuid        0      0

/dev/sdb1              /media/usb  auto    rw,user,noauto,unhide   0      0
/dev/cdrom             /media/cd   auto    ro,user,noauto,unhide   0      0
/dev/dvd               /media/dvd  auto    ro,user,noauto,unhide   0      0

/dev/sda1    /boot        ext2    defaults    0    1
/dev/sda5    /        ext4    defaults    0    1
/dev/sda6    /usr        ext4    defaults    0    1
/dev/sda7    /home        ext4    defaults    0    1
/dev/sda8    swap        swap    defaults    0    0
#/dev/sda9    /extra        ext4    defaults    0    1

In this case, /dev/sda9 would not be mounted at boot as it is commented out.

In any case, I believe you can unmount your partitions by doing

$ umount /dev/sdb?

Offline

#3 2011-04-17 04:40:22

jlindgren
Member
Registered: 2011-02-27
Posts: 256

Re: how to umount all partitions of a mobile disk.

for n in /dev/sdb* ; do umount $n ; done

Offline

#4 2011-04-17 14:42:32

qq405165798
Member
Registered: 2010-11-03
Posts: 17

Re: how to umount all partitions of a mobile disk.

rockin turtle wrote:

I believe that discs are mounted according to your /etc/fstab file.  If you don't want a partition to be mounted at boot, then remove/comment out the entry in that file.  For example

#
# /etc/fstab: static file system information
#
# <file system>        <dir>         <type>    <options>          <dump> <pass>
devpts                 /dev/pts      devpts    defaults            0      0
shm                    /dev/shm      tmpfs     nodev,nosuid        0      0

/dev/sdb1              /media/usb  auto    rw,user,noauto,unhide   0      0
/dev/cdrom             /media/cd   auto    ro,user,noauto,unhide   0      0
/dev/dvd               /media/dvd  auto    ro,user,noauto,unhide   0      0

/dev/sda1    /boot        ext2    defaults    0    1
/dev/sda5    /        ext4    defaults    0    1
/dev/sda6    /usr        ext4    defaults    0    1
/dev/sda7    /home        ext4    defaults    0    1
/dev/sda8    swap        swap    defaults    0    0
#/dev/sda9    /extra        ext4    defaults    0    1

In this case, /dev/sda9 would not be mounted at boot as it is commented out.

In any case, I believe you can unmount your partitions by doing

$ umount /dev/sdb?

Thanks a lot!

I used to deal with HDD by mount -a and umount -a which configure is /etc/fstab,
but it is trouble when I need deal with my friends HDDs. You know it is bother to edit the /etc/fstab.

Offline

#5 2011-04-17 14:48:34

qq405165798
Member
Registered: 2010-11-03
Posts: 17

Re: how to umount all partitions of a mobile disk.

jlindgren wrote:

for n in /dev/sdb* ; do umount $n ; done

It seems the only way.Thank you.

Last edited by qq405165798 (2011-04-17 18:06:41)

Offline

#6 2016-06-18 00:24:08

jmss
Member
From: Lisboa, Portugal
Registered: 2006-10-24
Posts: 42

Re: how to umount all partitions of a mobile disk.

Shouldn't it be:

for p in `ls /dev/sdb?`; do umount $p; done

?


João M. S. Silva

Offline

#7 2016-06-18 00:28:09

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,424
Website

Re: how to umount all partitions of a mobile disk.

jmss wrote:

Shouldn't it be:

for p in `ls /dev/sdb?`; do umount $p; done

?

No. For any number of reasons, but parsing ls is the most egregious.

Also, don't necrobump: https://wiki.archlinux.org/index.php/Co … bumping.22



Closing


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

Board footer

Powered by FluxBB