Index: uspace/srv/bd/vbd/disk.c
===================================================================
--- uspace/srv/bd/vbd/disk.c	(revision c02d098887d0049fec4eb72260cc0efa28e1a0d4)
+++ uspace/srv/bd/vbd/disk.c	(revision 6439741620402fb497bcd0eb81871ad3a7ab81f5)
@@ -62,4 +62,8 @@
 static int vbds_bsa_translate(vbds_part_t *, aoff64_t, size_t, aoff64_t *);
 
+static int vbds_part_svc_register(vbds_part_t *);
+static int vbds_part_svc_unregister(vbds_part_t *);
+static int vbds_part_indices_update(vbds_disk_t *);
+
 static vbd_part_id_t vbds_part_id = 1;
 
@@ -138,5 +142,4 @@
 	service_id_t psid = 0;
 	label_part_info_t lpinfo;
-	char *name;
 	int rc;
 
@@ -150,24 +153,4 @@
 		log_msg(LOG_DEFAULT, LVL_ERROR, "Out of memory.");
 		return ENOMEM;
-	}
-
-	if (lpinfo.pkind != lpk_extended) {
-		/* XXX Proper service name */
-		rc = asprintf(&name, "%sp%u", disk->svc_name, lpart->index);
-		if (rc < 0) {
-			log_msg(LOG_DEFAULT, LVL_ERROR, "Out of memory.");
-			return ENOMEM;
-		}
-
-		rc = loc_service_register(name, &psid);
-		if (rc != EOK) {
-			log_msg(LOG_DEFAULT, LVL_ERROR, "Failed registering "
-			    "service %s.", name);
-			free(name);
-			free(part);
-			return EIO;
-		}
-
-		free(name);
 	}
 
@@ -183,4 +166,10 @@
 	part->bds.sarg = part;
 
+	if (lpinfo.pkind != lpk_extended) {
+		rc = vbds_part_svc_register(part);
+		if (rc != EOK)
+			return EIO;
+	}
+
 	list_append(&part->ldisk, &disk->parts);
 	list_append(&part->lparts, &vbds_parts);
@@ -207,5 +196,5 @@
 
 	if (part->svc_id != 0) {
-		rc = loc_service_unregister(part->svc_id);
+		rc = vbds_part_svc_unregister(part);
 		if (rc != EOK)
 			return EIO;
@@ -533,4 +522,10 @@
 	}
 
+	rc = vbds_part_indices_update(disk);
+	if (rc != EOK) {
+		log_msg(LOG_DEFAULT, LVL_ERROR, "Error updating partition indices");
+		goto error;
+	}
+
 	rc = vbds_part_add(disk, lpart, &part);
 	if (rc != EOK) {
@@ -581,4 +576,10 @@
 	}
 
+	rc = vbds_part_indices_update(disk);
+	if (rc != EOK) {
+		log_msg(LOG_DEFAULT, LVL_ERROR, "Error updating partition indices");
+		return EIO;
+	}
+
 	return EOK;
 }
@@ -707,4 +708,85 @@
 }
 
+/** Register service for partition */
+static int vbds_part_svc_register(vbds_part_t *part)
+{
+	char *name;
+	service_id_t psid;
+	int idx;
+	int rc;
+
+	idx = part->lpart->index;
+
+	rc = asprintf(&name, "%sp%u", part->disk->svc_name, idx);
+	if (rc < 0) {
+		log_msg(LOG_DEFAULT, LVL_ERROR, "Out of memory.");
+		return ENOMEM;
+	}
+
+	rc = loc_service_register(name, &psid);
+	if (rc != EOK) {
+		log_msg(LOG_DEFAULT, LVL_ERROR, "Failed registering "
+		    "service %s.", name);
+		free(name);
+		free(part);
+		return EIO;
+	}
+
+	free(name);
+	part->svc_id = psid;
+	part->reg_idx = idx;
+	return EOK;
+}
+
+/** Unregister service for partition */
+static int vbds_part_svc_unregister(vbds_part_t *part)
+{
+	int rc;
+
+	rc = loc_service_unregister(part->svc_id);
+	if (rc != EOK)
+		return EIO;
+
+	part->svc_id = 0;
+	part->reg_idx = 0;
+	return EOK;
+}
+
+/** Update service names for any partition whose index has changed. */
+static int vbds_part_indices_update(vbds_disk_t *disk)
+{
+	label_part_info_t lpinfo;
+	int rc;
+
+	log_msg(LOG_DEFAULT, LVL_NOTE, "vbds_part_indices_update()");
+
+	/* First unregister services for partitions whose index has changed */
+	list_foreach(disk->parts, ldisk, vbds_part_t, part) {
+		if (part->svc_id != 0 && part->lpart->index != part->reg_idx) {
+			rc = vbds_part_svc_unregister(part);
+			if (rc != EOK) {
+				log_msg(LOG_DEFAULT, LVL_NOTE, "Error "
+				    "un-registering partition.");
+				return EIO;
+			}
+		}
+	}
+
+	/* Now re-register those services under the new indices */
+	list_foreach(disk->parts, ldisk, vbds_part_t, part) {
+		label_part_get_info(part->lpart, &lpinfo);
+		if (part->svc_id == 0 && lpinfo.pkind != lpk_extended) {
+			rc = vbds_part_svc_register(part);
+			if (rc != EOK) {
+				log_msg(LOG_DEFAULT, LVL_NOTE, "Error "
+				    "re-registering partition.");
+				return EIO;
+			}
+		}
+	}
+
+	return EOK;
+}
+
 /** @}
  */
